Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions smart-contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions smart-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"contracts/dispute_resolution",
"contracts/oracle_manager",
"contracts/price_oracle",
"tests/integration",
]
resolver = "2"

Expand Down
16 changes: 10 additions & 6 deletions smart-contracts/contracts/agent_bidding/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ pub enum Error {
AuctionNotAbortable = 25,
/// An arithmetic operation overflowed while scoring bids.
ArithmeticOverflow = 26,
/// Contract instance has already been initialized.
/// Contract already initialized.
AlreadyInitialized = 27,
/// Contract is currently paused.
/// The contract is currently paused.
ContractPaused = 28,
/// Winner cannot claim refund via bond refund path.
/// The winning bidder cannot claim a refund on bond.
WinnerCannotClaimRefund = 29,
/// Refund has already been claimed for this bidder.
/// The refund has already been claimed.
RefundAlreadyClaimed = 30,
/// Claim window has expired.
/// The claim window for bond refund has expired.
ClaimWindowExpired = 31,
/// Bond has already been refunded.
/// Bond already refunded.
AlreadyRefunded = 32,
/// No payment asset (Stellar Asset Contract) has been configured.
AssetNotConfigured = 33,
Expand All @@ -93,4 +93,8 @@ pub enum Error {
InvalidAmount = 35,
/// The escrow has already been released or refunded.
EscrowAlreadySettled = 36,
/// The auction already has the maximum number of bidders.
MaxBiddersReached = 37,
/// The requested audit range is invalid.
InvalidAuditRange = 38,
}
59 changes: 47 additions & 12 deletions smart-contracts/contracts/agent_bidding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ mod errors;
pub mod gas;
#[cfg(test)]
mod property_tests;
#[cfg(test)]
mod tests;
mod types;

pub use errors::Error;
Expand All @@ -109,6 +111,7 @@ use soroban_sdk::{

/// Threshold (ledgers remaining) below which we extend.
const TTL_THRESHOLD: u32 = 100_000;
const TTL_EXTEND_TO: u32 = 535_680;
/// Target TTL after extension (~31 days at 5s ledgers).
const CONTRACT_VERSION: &str = "1.0.0";

Expand All @@ -129,18 +132,6 @@ fn require_admin(env: &Env) -> Result<Address, Error> {
Ok(admin)
}

fn require_not_paused(env: &Env) -> Result<(), Error> {
let paused: bool = env
.storage()
.instance()
.get(&DataKey::Paused)
.unwrap_or(false);
if paused {
return Err(Error::ContractPaused);
}
Ok(())
}

/// Extend TTL for a single persistent key, but only when it exists.
fn extend_ttl_for_key(env: &Env, key: &DataKey) {
if env.storage().persistent().has(key) {
Expand Down Expand Up @@ -239,6 +230,19 @@ fn scaled_ratio(numerator: i128, denominator: i128) -> Result<i128, Error> {
.ok_or(Error::ArithmeticOverflow)
}

fn require_not_paused(env: &Env) -> Result<(), Error> {
if env
.storage()
.instance()
.get(&DataKey::Paused)
.unwrap_or(false)
{
Err(Error::ContractPaused)
} else {
Ok(())
}
}

// ─── Token helpers ───────────────────────────────────────────────────────────

/// Decimals in which every `*_stroops` amount handled by this contract is
Expand Down Expand Up @@ -433,13 +437,44 @@ impl AgentBiddingContract {
env.storage().instance().get(&DataKey::Admin)
}

pub fn set_paused(env: Env, admin: Address, paused: bool) -> Result<(), Error> {
let stored_admin = require_admin(&env)?;
if admin != stored_admin {
return Err(Error::Unauthorized);
}
admin.require_auth();
env.storage().instance().set(&DataKey::Paused, &paused);
Ok(())
}

pub fn contract_version(env: Env) -> String {
env.storage()
.instance()
.get(&DataKey::Version)
.unwrap_or_else(|| String::from_str(&env, CONTRACT_VERSION))
}

pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>, new_version: String) -> Result<(), Error> {
let admin = require_admin(&env)?;
let old_version = Self::contract_version(env.clone());
env.deployer()
.update_current_contract_wasm(new_wasm_hash.clone());
env.storage()
.instance()
.set(&DataKey::Version, &new_version);
env.events().publish(
(symbol_short!("bidding"), symbol_short!("upgraded")),
(
old_version,
new_version,
new_wasm_hash,
admin,
env.ledger().sequence(),
),
);
Ok(())
}

// ── Creation ─────────────────────────────────────────────────────────

/// Initialise a new auction for `task_id`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn create_test_auction(

/// Recompute the commitment hash from plaintext fields.
/// Mirrors `compute_commitment` in the contract and `commitment_of`.
fn test_commitment(
pub(crate) fn test_commitment(
client: &AgentBiddingContractClient<'_>,
task_id: &Symbol,
bidder: &Address,
Expand Down
Loading
Loading