Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix(get-auctions): update getAuction to use existing active auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Oct 31, 2023
1 parent 8727242 commit 65577e7
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/actions/read/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,14 @@ export const getAuction = (
const { records, auctions, settings, fees, reserved } = state;
const formattedName = name.toLowerCase().trim();
const auction = auctions[formattedName];
const auctionSettings = settings.auctions;

if (!auction) {
const auctionSettings = settings.auctions;
const currentBlockTimestamp = new BlockTimestamp(
+SmartWeave.block.timestamp,
);
const currentBlockHeight = new BlockHeight(+SmartWeave.block.height);

const initialRegistrationFee = calculateRegistrationFee({
type,
name,
fees,
years: 1,
currentBlockTimestamp,
demandFactoring: state.demandFactoring,
});

// a stubbed auction object
const auctionObject = createAuctionObject({
auctionSettings,
Expand All @@ -55,15 +46,11 @@ export const getAuction = (
initiator: undefined,
});

const floorPrice =
initialRegistrationFee * auctionObject.settings.floorPriceMultiplier;
const startPrice = floorPrice * auctionObject.settings.startPriceMultiplier;

const prices = getAuctionPrices({
auctionSettings,
startHeight: currentBlockHeight, // set it to the current block height
startPrice,
floorPrice,
startPrice: auctionObject.startPrice,
floorPrice: auctionObject.floorPrice,
});

// existing record
Expand Down Expand Up @@ -93,25 +80,31 @@ export const getAuction = (
isActive: false,
isAvailableForAuction: isAvailableForAuction,
isRequiredToBeAuctioned: isRequiredToBeAuctioned,
minimumBid: floorPrice, // since its not active yet, the minimum bid is the floor price
minimumBid: auctionObject.floorPrice, // since its not active yet, the minimum bid is the floor price
...auctionObject,
prices,
},
};
}

const { startHeight, floorPrice, startPrice } = auction;
const expirationHeight = startHeight + auctionSettings.auctionDuration;
const {
startHeight,
floorPrice,
startPrice,
settings: existingAuctionSettings,
} = auction;
const expirationHeight =
startHeight + existingAuctionSettings.auctionDuration;
const isRequiredToBeAuctioned = isNameRequiredToBeAuction({
name: formattedName,
type: auction.type,
});

// get all the prices for the auction
const prices = getAuctionPrices({
auctionSettings,
auctionSettings: existingAuctionSettings,
startHeight: new BlockHeight(startHeight),
startPrice, // TODO: use IOTOken class
startPrice, // TODO: use IO class class
floorPrice,
});

Expand All @@ -121,14 +114,13 @@ export const getAuction = (
startPrice,
floorPrice,
currentBlockHeight: new BlockHeight(+SmartWeave.block.height),
decayInterval: auctionSettings.decayInterval,
decayRate: auctionSettings.decayRate,
decayInterval: existingAuctionSettings.decayInterval,
decayRate: existingAuctionSettings.decayRate,
});

return {
result: {
name: formattedName,
// TODO: inclusive or exclusive here
isActive: expirationHeight > +SmartWeave.block.height,
isAvailableForAuction: false,
isRequiredToBeAuctioned: isRequiredToBeAuctioned,
Expand Down

0 comments on commit 65577e7

Please sign in to comment.