Skip to content
18 changes: 18 additions & 0 deletions packages/contracts/oracle_marketplace/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@ pub enum OracleMarketplaceError {
OracleNotSelectedForCall = 11,
AlreadyRated = 12,
InvalidRating = 13,
/// Escrow for this call id already exists — call ids must be unique.
EscrowAlreadyExists = 14,
/// The call has already been resolved; it cannot be resolved twice.
EscrowAlreadyResolved = 15,
/// The call has been resolved but the bounty has not been settled yet.
EscrowNotSettled = 16,
/// Escrow amount is zero or negative — nothing to lock.
InvalidEscrowAmount = 17,
/// The address that called `resolve_call` is not the provider selected
/// for this call.
NotSelectedOracle = 18,
/// Slashing would push the provider below their own `min_stake`, which
/// would let a provider avoid being slashed by posting a tiny bond.
SlashBelowMinStake = 19,
/// Bond amount is not positive.
InvalidBond = 20,
/// Settlement amount exceeds what was escrowed.
SettlementOverflow = 21,
}
52 changes: 52 additions & 0 deletions packages/contracts/oracle_marketplace/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,55 @@ pub fn emit_oracle_rated(env: &Env, provider: &BytesN<32>, user: &Address, satis
(provider.clone(), user.clone(), satisfied),
);
}

/// A caller locked a bounty for a call.
pub fn emit_escrow_created(env: &Env, call_id: u64, caller: &Address, oracle: &BytesN<32>, amount: i128) {
env.events().publish(
("oracle_marketplace", "EscrowCreated"),
(call_id, caller.clone(), oracle.clone(), amount),
);
}

/// An escrowed bounty was paid out to the provider that answered correctly.
pub fn emit_escrow_settled(
env: &Env,
call_id: u64,
oracle: &BytesN<32>,
provider_amount: i128,
fee_amount: i128,
) {
env.events().publish(
("oracle_marketplace", "EscrowSettled"),
(call_id, oracle.clone(), provider_amount, fee_amount),
);
}

/// A provider answered inaccurately; part of their bond was slashed.
pub fn emit_bond_slashed(
env: &Env,
oracle: &BytesN<32>,
caller: &Address,
slashed: i128,
remaining_stake: i128,
) {
env.events().publish(
("oracle_marketplace", "BondSlashed"),
(oracle.clone(), caller.clone(), slashed, remaining_stake),
);
}

/// A provider topped their bond back up.
pub fn emit_bond_increased(env: &Env, oracle: &BytesN<32>, amount: i128, total_stake: i128) {
env.events().publish(
("oracle_marketplace", "BondIncreased"),
(oracle.clone(), amount, total_stake),
);
}

/// A provider withdrew bond after deregistering (subject to the cooldown).
pub fn emit_bond_withdrawn(env: &Env, oracle: &BytesN<32>, provider: &Address, amount: i128) {
env.events().publish(
("oracle_marketplace", "BondWithdrawn"),
(oracle.clone(), provider.clone(), amount),
);
}
Loading
Loading