Skip to content

Commit

Permalink
solana: fix carping constraint (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: A5 Pickle <[email protected]>
  • Loading branch information
a5-pickle and a5-pickle authored Jun 18, 2024
1 parent b00b375 commit 7a4e50a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub struct AuctionUpdated {
pub token_balance_before: u64,
pub amount_in: u64,
pub total_deposit: u64,
pub max_offer_price_allowed: u64,
pub max_offer_price_allowed: Option<u64>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct ImproveOffer<'info> {
require!(
offer_price
<= utils::auction::compute_min_allowed_offer(&active_auction.config, info),
< utils::auction::compute_min_allowed_offer(&active_auction.config, info),
MatchingEngineError::CarpingNotAllowed
);
Expand Down Expand Up @@ -144,7 +144,8 @@ pub fn improve_offer(ctx: Context<ImproveOffer>, offer_price: u64) -> Result<()>
token_balance_before: offer_token.amount,
amount_in: info.amount_in,
total_deposit: info.total_deposit(),
max_offer_price_allowed: utils::auction::compute_min_allowed_offer(config, info),
max_offer_price_allowed: utils::auction::compute_min_allowed_offer(config, info)
.checked_sub(1),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ pub fn place_initial_offer_cctp(
token_balance_before: ctx.accounts.offer_token.amount,
amount_in,
total_deposit: info.total_deposit(),
max_offer_price_allowed: utils::auction::compute_min_allowed_offer(config, info),
max_offer_price_allowed: utils::auction::compute_min_allowed_offer(config, info)
.checked_sub(1),
});

// Finally transfer tokens from the offer authority's token account to the
Expand Down
4 changes: 3 additions & 1 deletion solana/ts/src/idl/json/matching_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -3580,7 +3580,9 @@
},
{
"name": "max_offer_price_allowed",
"type": "u64"
"type": {
"option": "u64"
}
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion solana/ts/src/idl/ts/matching_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3586,7 +3586,9 @@ export type MatchingEngine = {
},
{
"name": "maxOfferPriceAllowed",
"type": "u64"
"type": {
"option": "u64"
}
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions solana/ts/src/matchingEngine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export type AuctionUpdated = {
tokenBalanceBefore: BN;
amountIn: BN;
totalDeposit: BN;
maxOfferPriceAllowed: BN;
maxOfferPriceAllowed: BN | null;
};

export type OrderExecuted = {
Expand Down Expand Up @@ -2525,7 +2525,7 @@ export class MatchingEngineProgram {

async computeMinOfferDelta(offerPrice: Uint64): Promise<bigint> {
const { minOfferDeltaBps } = await this.fetchAuctionParameters();
return (uint64ToBigInt(offerPrice) * BigInt(minOfferDeltaBps)) / FEE_PRECISION_MAX;
return (uint64ToBigInt(offerPrice) * BigInt(minOfferDeltaBps)) / FEE_PRECISION_MAX + 1n;
}

async computeNotionalSecurityDeposit(amountIn: Uint64, configId?: number) {
Expand Down

0 comments on commit 7a4e50a

Please sign in to comment.