Skip to content

Commit

Permalink
updates auction
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Dec 4, 2024
1 parent 49ea703 commit 11bb6c6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
15 changes: 8 additions & 7 deletions contracts/auctions/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::{
collection,
error::ContractError,
storage::{
generate_auction_id, get_admin, get_auction_by_id, get_auction_token, get_auctions,
get_auctions_by_seller_id, get_highest_bid, is_initialized, save_admin, save_auction_by_id,
save_auction_by_seller, save_auction_token, set_highest_bid, set_initialized, update_admin,
validate_input_params, Auction, AuctionStatus, HighestBid, ItemInfo,
generate_auction_id, get_admin_old, get_auction_by_id, get_auction_token, get_auctions,
get_auctions_by_seller_id, get_highest_bid, is_initialized, save_admin_old,
save_auction_by_id, save_auction_by_seller, save_auction_token, set_highest_bid,
set_initialized, update_admin, validate_input_params, Auction, AuctionStatus, HighestBid,
ItemInfo,
},
token,
};
Expand All @@ -30,7 +31,7 @@ impl MarketplaceContract {
return Err(ContractError::AlreadyInitialized);
}

save_admin(&env, &admin);
save_admin_old(&env, &admin);
save_auction_token(&env, auction_token);

set_initialized(&env);
Expand Down Expand Up @@ -424,7 +425,7 @@ impl MarketplaceContract {

#[allow(dead_code)]
pub fn update_admin(env: Env, new_admin: Address) -> Result<Address, ContractError> {
let old_admin = get_admin(&env)?;
let old_admin = get_admin_old(&env)?;
old_admin.require_auth();

env.events()
Expand All @@ -437,7 +438,7 @@ impl MarketplaceContract {

#[allow(dead_code)]
pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), ContractError> {
let admin: Address = get_admin(&env)?;
let admin: Address = get_admin_old(&env)?;
admin.require_auth();

env.deployer().update_current_contract_wasm(new_wasm_hash);
Expand Down
11 changes: 7 additions & 4 deletions contracts/auctions/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use soroban_sdk::{contracttype, log, panic_with_error, vec, Address, Env, Vec};
use soroban_sdk::{
contracttype, log, panic_with_error, symbol_short, vec, Address, Env, Symbol, Vec,
};

use crate::error::ContractError;

Expand All @@ -11,6 +13,7 @@ pub const LIFETIME_THRESHOLD: u32 = BUMP_AMOUNT - DAY_IN_LEDGERS;
// since we start counting from 1, default would be 1 as well
pub const DEFAULT_INDEX: u64 = 1;
pub const DEFAULT_LIMIT: u64 = 10;
pub const ADMIN: Symbol = symbol_short!("ADMIN");

#[contracttype]
#[derive(Clone)]
Expand Down Expand Up @@ -198,14 +201,14 @@ pub fn set_initialized(env: &Env) {
.set(&DataKey::IsInitialized, &true);
}

pub fn save_admin(env: &Env, admin: &Address) {
pub fn save_admin_old(env: &Env, admin: &Address) {
env.storage().persistent().set(&DataKey::Admin, &admin);
env.storage()
.persistent()
.extend_ttl(&DataKey::Admin, LIFETIME_THRESHOLD, BUMP_AMOUNT);
}

pub fn get_admin(env: &Env) -> Result<Address, ContractError> {
pub fn get_admin_old(env: &Env) -> Result<Address, ContractError> {
let admin = env
.storage()
.persistent()
Expand Down Expand Up @@ -237,7 +240,7 @@ pub fn get_highest_bid(env: &Env, auction_id: u64) -> Result<HighestBid, Contrac
.unwrap_or(HighestBid {
bid: 0,
// I know
bidder: get_admin(env)?,
bidder: get_admin_old(env)?,
});

env.storage()
Expand Down
28 changes: 20 additions & 8 deletions contracts/auctions/src/test/setup.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
use soroban_sdk::{testutils::Address as _, xdr::ToXdr, Address, Bytes, Env, String};
use soroban_sdk::{
testutils::Address as _, token::TokenClient, xdr::ToXdr, Address, Bytes, Env, FromVal, String,
};

use crate::{
collection::{self, Client},
contract::{MarketplaceContract, MarketplaceContractClient},
storage::ItemInfo,
token,
};

pub const WEEKLY: u64 = 604_800u64;
pub const DAY: u64 = 86_400u64;
pub const FOUR_HOURS: u64 = 14_400u64;
const TOKEN_WASM: &[u8] =
include_bytes!("../../../../target/wasm32-unknown-unknown/release/soroban_token_contract.wasm");

pub fn deploy_token_contract<'a>(env: &Env, admin: &Address) -> TokenClient<'a> {
let token_contract = env.register(
TOKEN_WASM,
(
admin,
7_u32,
String::from_val(env, &"name"),
String::from_val(env, &"symbol"),
),
);

pub fn deploy_token_contract<'a>(env: &Env, admin: &Address) -> token::Client<'a> {
token::Client::new(env, &env.register_stellar_asset_contract(admin.clone()))
TokenClient::new(env, &token_contract)
}

pub mod auctions_wasm {
Expand All @@ -28,8 +41,7 @@ pub fn generate_marketplace_and_collection_client<'a>(
name: Option<String>,
symbol: Option<String>,
) -> (MarketplaceContractClient<'a>, collection::Client<'a>) {
let mp_client =
MarketplaceContractClient::new(env, &env.register_contract(None, MarketplaceContract {}));
let mp_client = MarketplaceContractClient::new(env, &env.register(MarketplaceContract, ()));

mp_client.initialize(admin, auction_token);

Expand All @@ -38,7 +50,7 @@ pub fn generate_marketplace_and_collection_client<'a>(

let name = name.unwrap_or(alt_name);
let symbol = symbol.unwrap_or(alt_symbol);
let collection_addr = env.register_contract_wasm(None, collection::WASM);
let collection_addr = env.register(collection::WASM, ());

let collection_client = collection::Client::new(env, &collection_addr);
collection_client.initialize(admin, &name, &symbol);
Expand Down Expand Up @@ -83,7 +95,7 @@ pub fn create_and_initialize_collection<'a>(
let collection_addr = env
.deployer()
.with_address(Address::generate(env), salt)
.deploy(env.deployer().upload_contract_wasm(collection::WASM));
.deploy_v2(env.deployer().upload_contract_wasm(collection::WASM), ());

let collection_client = collection::Client::new(env, &collection_addr);
collection_client.initialize(seller, &collection_name, &collection_symbol);
Expand Down

0 comments on commit 11bb6c6

Please sign in to comment.