Skip to content

Commit 083dea0

Browse files
committed
Merge branch 'feat/max-buy-quantity-per-tx-828' of https://github.com/dedukpe/accesslayer-contracts into feat/max-buy-quantity-per-tx-828
# Conflicts: # creator-keys/src/lib.rs # creator-keys/test_snapshots/test_sell_slippage_succeeds_when_proceeds_meet_or_exceed_min_proceeds.1.json
2 parents 4d1e60d + 60ef82e commit 083dea0

3 files changed

Lines changed: 264 additions & 92 deletions

File tree

creator-keys/src/events.rs

Lines changed: 81 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,61 @@ use soroban_sdk::{
3232
/// Event name for protocol trade fee collected on a buy or sell.
3333
pub const FEE_COLLECTED_EVENT_NAME: Symbol = symbol_short!("fee_coll");
3434

35+
/// Stable fee collection event payload for downstream indexers.
36+
///
37+
/// Event shape:
38+
/// - topics: `(FEE_COLLECTED_EVENT_NAME, treasury)`
39+
/// - data: `FeeCollectedEvent`
40+
///
41+
/// Emitted on every buy and sell once the protocol trade fee is configured,
42+
/// carrying the deducted amount and the treasury address that received it.
43+
#[derive(Clone, Debug, Eq, PartialEq)]
44+
#[contracttype]
45+
pub struct FeeCollectedEvent {
46+
/// Treasury address that received the fee.
47+
pub treasury: Address,
48+
/// Fee amount deducted from the trade.
49+
pub amount: i128,
50+
/// Ledger sequence number at the time of the trade.
51+
pub ledger: u32,
52+
}
53+
54+
/// Shared fee collected event topics tuple.
55+
pub fn fee_collected_topics(treasury: &Address) -> (Symbol, Address) {
56+
(FEE_COLLECTED_EVENT_NAME, treasury.clone())
57+
}
58+
3559
/// Event name for a sell rejected by the anti-flash-trade lockup window.
3660
pub const LOCKUP_BLOCKED_EVENT_NAME: Symbol = symbol_short!("lck_blk");
3761

62+
/// Stable lockup-blocked event payload for downstream indexers.
63+
///
64+
/// Event shape:
65+
/// - topics: `(LOCKUP_BLOCKED_EVENT_NAME, creator_id, seller)`
66+
/// - data: `LockupBlockedEvent`
67+
///
68+
/// Emitted when a sell is rejected because the seller's most recent buy for
69+
/// this creator falls inside the configured lockup window.
70+
#[derive(Clone, Debug, Eq, PartialEq)]
71+
#[contracttype]
72+
pub struct LockupBlockedEvent {
73+
/// Creator whose keys the seller attempted to sell.
74+
pub creator_id: Address,
75+
/// Seller whose sale was rejected.
76+
pub seller: Address,
77+
/// Ledger timestamp of the seller's most recent buy.
78+
pub last_buy_timestamp: u64,
79+
/// Timestamp at which the lockup expires (exclusive).
80+
pub unlock_at: u64,
81+
/// Ledger timestamp at rejection.
82+
pub current_timestamp: u64,
83+
}
84+
85+
/// Shared lockup blocked event topics tuple.
86+
pub fn lockup_blocked_topics(creator: &Address, seller: &Address) -> (Symbol, Address, Address) {
87+
(LOCKUP_BLOCKED_EVENT_NAME, creator.clone(), seller.clone())
88+
}
89+
3890
/// Event name for quorum threshold update.
3991
pub const QUORUM_UPDATED_EVENT_NAME: Symbol = symbol_short!("qrm_upd");
4092

@@ -1237,57 +1289,48 @@ pub struct RoyaltyUpdatedEvent {
12371289
pub fn royalty_updated_topics(creator: &Address) -> (Symbol, Address) {
12381290
(ROYALTY_UPDATED_EVENT_NAME, creator.clone())
12391291
}
1240-
/// Stable fee collection event payload for downstream indexers.
1241-
///
1242-
/// Event shape:
1243-
/// - topics: `(FEE_COLLECTED_EVENT_NAME, treasury)`
1244-
/// - data: `FeeCollectedEvent`
1245-
///
1246-
/// Emitted on every buy and sell once the protocol trade fee is configured,
1247-
/// carrying the deducted amount and the treasury address that received it.
1292+
1293+
// --- Auction events ---
1294+
1295+
/// Event name for auction purchase.
1296+
pub const AUCTION_PURCHASE_EVENT_NAME: Symbol = symbol_short!("auc_buy");
1297+
1298+
/// Stable auction purchase event payload.
12481299
#[derive(Clone, Debug, Eq, PartialEq)]
12491300
#[contracttype]
1250-
pub struct FeeCollectedEvent {
1251-
/// Treasury address that received the fee.
1252-
pub treasury: Address,
1253-
/// Fee amount deducted from the trade.
1254-
pub amount: i128,
1255-
/// Ledger sequence number at the time of the trade.
1301+
pub struct AuctionPurchaseEvent {
1302+
pub buyer: Address,
1303+
pub creator_id: Address,
1304+
pub quantity: u32,
1305+
pub price_paid: i128,
1306+
pub new_supply: u32,
1307+
pub auction_sold: u32,
12561308
pub ledger: u32,
12571309
}
12581310

1259-
/// Shared fee collected event topics tuple.
1260-
pub fn fee_collected_topics(treasury: &Address) -> (Symbol, Address) {
1261-
(FEE_COLLECTED_EVENT_NAME, treasury.clone())
1311+
/// Shared auction purchase event topics tuple.
1312+
pub fn auction_purchase_topics(creator: &Address, buyer: &Address) -> (Symbol, Address, Address) {
1313+
(AUCTION_PURCHASE_EVENT_NAME, creator.clone(), buyer.clone())
12621314
}
12631315

1264-
/// Stable lockup-blocked event payload for downstream indexers.
1265-
///
1266-
/// Event shape:
1267-
/// - topics: `(LOCKUP_BLOCKED_EVENT_NAME, creator_id, seller)`
1268-
/// - data: `LockupBlockedEvent`
1269-
///
1270-
/// Emitted when a sell is rejected because the seller's most recent buy for
1271-
/// this creator falls inside the configured lockup window.
1316+
/// Event name for auction configured.
1317+
pub const AUCTION_CONFIGURED_EVENT_NAME: Symbol = symbol_short!("auc_cfg");
1318+
1319+
/// Stable auction configured event payload.
12721320
#[derive(Clone, Debug, Eq, PartialEq)]
12731321
#[contracttype]
1274-
pub struct LockupBlockedEvent {
1275-
/// Creator whose keys the seller attempted to sell.
1322+
pub struct AuctionConfiguredEvent {
12761323
pub creator_id: Address,
1277-
/// Seller whose sale was rejected.
1278-
pub seller: Address,
1279-
/// Ledger timestamp of the seller's most recent buy.
1280-
pub last_buy_timestamp: u64,
1281-
/// Timestamp at which the lockup expires (exclusive).
1282-
pub unlock_at: u64,
1283-
/// Ledger timestamp at rejection.
1284-
pub current_timestamp: u64,
1324+
pub auction_supply: u32,
1325+
pub auction_price: i128,
1326+
pub ledger: u32,
12851327
}
12861328

1287-
/// Shared lockup blocked event topics tuple.
1288-
pub fn lockup_blocked_topics(creator: &Address, seller: &Address) -> (Symbol, Address, Address) {
1289-
(LOCKUP_BLOCKED_EVENT_NAME, creator.clone(), seller.clone())
1329+
/// Shared auction configured event topics tuple.
1330+
pub fn auction_configured_topics(creator: &Address) -> (Symbol, Address) {
1331+
(AUCTION_CONFIGURED_EVENT_NAME, creator.clone())
12901332
}
1333+
12911334
/// Event name for a new staking position created via `stake_keys_locked`.
12921335
pub const STAKE_EVENT_NAME: Symbol = symbol_short!("stake");
12931336

@@ -1525,33 +1568,6 @@ pub fn cooldown_blocked_topics(creator: &Address, wallet: &Address) -> (Symbol,
15251568
(COOLDOWN_BLOCKED_EVENT_NAME, creator.clone(), wallet.clone())
15261569
}
15271570

1528-
// ============================================================================
1529-
// Pre-launch auction (#FeatureError)
1530-
// ============================================================================
1531-
1532-
/// Event name for a key purchased during a pre-launch auction.
1533-
pub const AUCTION_PURCHASE_EVENT_NAME: Symbol = symbol_short!("auc_buy");
1534-
1535-
/// Stable auction purchase event payload for downstream indexers.
1536-
///
1537-
/// Emitted inside `buy_key` when the purchase is fulfilled at the fixed
1538-
/// auction price rather than the bonding curve price.
1539-
#[derive(Clone, Debug, Eq, PartialEq)]
1540-
#[contracttype]
1541-
pub struct AuctionPurchaseEvent {
1542-
pub buyer: Address,
1543-
pub creator_id: Address,
1544-
pub quantity: u32,
1545-
pub price_paid: i128,
1546-
pub new_supply: u32,
1547-
pub auction_sold: u32,
1548-
pub ledger: u32,
1549-
}
1550-
1551-
/// Shared auction purchase event topics tuple.
1552-
pub fn auction_purchase_topics(creator: &Address, buyer: &Address) -> (Symbol, Address, Address) {
1553-
(AUCTION_PURCHASE_EVENT_NAME, creator.clone(), buyer.clone())
1554-
}
15551571
// ============================================================================
15561572
// Co-creator removal (#791)
15571573
// ============================================================================
@@ -1616,32 +1632,6 @@ pub fn dividend_reinvested_topics(
16161632
// Pre-launch auction configuration (#790)
16171633
// ============================================================================
16181634

1619-
/// Event name for an auction being configured.
1620-
pub const AUCTION_CONFIGURED_EVENT_NAME: Symbol = symbol_short!("auc_cfg");
1621-
1622-
/// Stable auction configured event payload for downstream indexers.
1623-
///
1624-
/// Event shape:
1625-
/// - topics: `(AUCTION_CONFIGURED_EVENT_NAME, creator_id)`
1626-
/// - data: `AuctionConfiguredEvent`
1627-
///
1628-
/// Emitted inside `configure_auction` when a creator sets up a pre-launch auction.
1629-
#[derive(Clone, Debug, Eq, PartialEq)]
1630-
#[contracttype]
1631-
pub struct AuctionConfiguredEvent {
1632-
/// Address of the creator configuring the auction.
1633-
pub creator_id: Address,
1634-
/// Fixed price per key during the auction.
1635-
pub auction_price: i128,
1636-
/// Number of keys available in the auction.
1637-
pub auction_supply: u32,
1638-
}
1639-
1640-
/// Shared auction configured event topics tuple.
1641-
pub fn auction_configured_topics(creator: &Address) -> (Symbol, Address) {
1642-
(AUCTION_CONFIGURED_EVENT_NAME, creator.clone())
1643-
}
1644-
16451635
/// Event name for an auction being cancelled.
16461636
pub const AUCTION_CANCELLED_EVENT_NAME: Symbol = symbol_short!("auc_cxl");
16471637

creator-keys/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ impl CreatorKeysContract {
29952995

29962996
if total_price
29972997
.checked_add(key_price)
2998-
.map_or(true, |t| t > payment)
2998+
.is_none_or(|t| t > payment)
29992999
{
30003000
break;
30013001
}
@@ -3543,6 +3543,15 @@ impl CreatorKeysContract {
35433543
Ok(profile.supply)
35443544
}
35453545

3546+
/// Purchase multiple keys in a single transaction.
3547+
///
3548+
/// The buyer pays `payment` (total across all keys) and receives `quantity`
3549+
/// keys. Each key is priced along the bonding curve (or at the auction
3550+
/// price when in auction phase), and all per-key side-effects (fees,
3551+
/// dividends, TTL extension, events) are applied per key.
3552+
///
3553+
/// # Limits
3554+
///
35463555
/// Validates that `client_schema_version` is compatible with this deployment.
35473556
///
35483557
/// Returns `Ok(())` when the version matches the contract's current schema.
@@ -4845,6 +4854,7 @@ impl CreatorKeysContract {
48454854
creator_id: creator,
48464855
auction_price,
48474856
auction_supply,
4857+
ledger: env.ledger().sequence(),
48484858
},
48494859
);
48504860
Ok(())

0 commit comments

Comments
 (0)