Skip to content

Commit

Permalink
Merge pull request #74 from blend-capital/scaled-auctions
Browse files Browse the repository at this point in the history
allow scaled lot and bid to contain 0
  • Loading branch information
Ryang-21 authored Nov 7, 2024
2 parents d7b0e77 + 1c7d026 commit c83860d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blend-capital/blend-sdk",
"version": "2.1.1",
"version": "2.1.2",
"description": "Javascript SDK for the Blend Protocol",
"type": "module",
"scripts": {
Expand Down
8 changes: 2 additions & 6 deletions src/pool/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export class Auction {
remainingAuctionData.lot.set(assetId, remainingBase);
}
const scaledLot = FixedMath.mulFloor(baseFill, lotModifier, FixedMath.SCALAR_7);
if (scaledLot > 0n) {
scaledAuctionData.lot.set(assetId, BigInt(scaledLot));
}
scaledAuctionData.lot.set(assetId, BigInt(scaledLot));
}

for (const [assetId, amount] of Array.from(this.data.bid)) {
Expand All @@ -141,9 +139,7 @@ export class Auction {
remainingAuctionData.bid.set(assetId, remainingBase);
}
const scaledBid = FixedMath.mulCeil(baseFill, bidModifier, FixedMath.SCALAR_7);
if (scaledBid > 0n) {
scaledAuctionData.bid.set(assetId, BigInt(scaledBid));
}
scaledAuctionData.bid.set(assetId, BigInt(scaledBid));
}
let remainingAuction: Auction | undefined = undefined;
const scaledAuction: ScaledAuction = {
Expand Down
18 changes: 13 additions & 5 deletions test/pool/auction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('Auction', () => {
expect(scaledAuction.data.bid.size).toEqual(2);
expect(scaledAuction.data.bid.get('asset1')).toEqual(100_0000000n);
expect(scaledAuction.data.bid.get('asset2')).toEqual(200_0000001n);
expect(scaledAuction.data.lot.size).toEqual(0);
expect(scaledAuction.data.lot.size).toEqual(2);
expect(scaledAuction.data.lot.get('asset2')).toEqual(0n);
expect(scaledAuction.data.lot.get('asset3')).toEqual(0n);

// 100 blocks -> 100 percent, validate lot is rounded down
[scaledAuction] = auction.scale(223, 100);
Expand Down Expand Up @@ -76,15 +78,19 @@ describe('Auction', () => {
// 400 blocks -> 100 percent
[scaledAuction] = auction.scale(523, 100);
expect(scaledAuction.data.block).toEqual(123);
expect(scaledAuction.data.bid.size).toEqual(0);
expect(scaledAuction.data.bid.size).toEqual(2);
expect(scaledAuction.data.bid.get('asset1')).toEqual(0n);
expect(scaledAuction.data.bid.get('asset2')).toEqual(0n);
expect(scaledAuction.data.lot.size).toEqual(2);
expect(scaledAuction.data.lot.get('asset2')).toEqual(1_0000000n);
expect(scaledAuction.data.lot.get('asset3')).toEqual(5_0000001n);

// 500 blocks -> 100 percent (unchanged)
[scaledAuction] = auction.scale(623, 100);
expect(scaledAuction.data.block).toEqual(123);
expect(scaledAuction.data.bid.size).toEqual(0);
expect(scaledAuction.data.bid.size).toEqual(2);
expect(scaledAuction.data.bid.get('asset1')).toEqual(0n);
expect(scaledAuction.data.bid.get('asset2')).toEqual(0n);
expect(scaledAuction.data.lot.size).toEqual(2);
expect(scaledAuction.data.lot.get('asset2')).toEqual(1_0000000n);
expect(scaledAuction.data.lot.get('asset3')).toEqual(5_0000001n);
Expand All @@ -102,14 +108,16 @@ describe('Auction', () => {
expect(scaledAuction.data.block).toEqual(123);
expect(scaledAuction.data.bid.size).toEqual(1);
expect(scaledAuction.data.bid.get('asset1')).toEqual(1n);
expect(scaledAuction.data.lot.size).toEqual(0);
expect(scaledAuction.data.lot.size).toEqual(1);
expect(scaledAuction.data.lot.get('asset2')).toEqual(0n);

// 399 blocks -> 10 percent
[scaledAuction] = auction.scale(522, 10);
expect(scaledAuction.data.block).toEqual(123);
expect(scaledAuction.data.bid.size).toEqual(1);
expect(scaledAuction.data.bid.get('asset1')).toEqual(1n);
expect(scaledAuction.data.lot.size).toEqual(0);
expect(scaledAuction.data.lot.size).toEqual(1);
expect(scaledAuction.data.lot.get('asset2')).toEqual(0n);

// 399 blocks -> 100 percent
[scaledAuction] = auction.scale(522, 100);
Expand Down

0 comments on commit c83860d

Please sign in to comment.