Skip to main content

Overview

The AuctionCalculator class is used to calculate taker amounts and auction rates during the lifecycle of a Fusion order. It helps determine how the exchange rate changes over time during the Dutch auction process.

Constructor

startTime
bigint
required
Auction start time as Unix timestamp in seconds
duration
bigint
required
Auction duration in seconds
initialRateBump
bigint
required
Initial rate bump from the end price (where 10,000,000 = 100%)
points
AuctionPoint[]
required
Array of auction points defining the rate curve
gasCost
AuctionGasCostInfo
Optional gas cost information for dynamic rate adjustments

Static Methods

fromAuctionData

Create an AuctionCalculator instance from AuctionDetails.
static fromAuctionData(details: AuctionDetails): AuctionCalculator
details
AuctionDetails
required
Auction details containing start time, duration, rate bump, and points
AuctionCalculator
Returns a new AuctionCalculator instance

calcInitialRateBump

Calculate the initial rate bump given start and end amounts.
static calcInitialRateBump(startAmount: bigint, endAmount: bigint): number
startAmount
bigint
required
Starting amount for the auction
endAmount
bigint
required
Ending amount for the auction
number
The initial rate bump value

calcAuctionTakingAmount

Calculate the taking amount for a given rate (static version).
static calcAuctionTakingAmount(takingAmount: bigint, rate: number): bigint
takingAmount
bigint
required
Base taking amount
rate
number
required
Current rate bump
bigint
The adjusted taking amount based on the rate

calcAuctionMakingAmount

Calculate the making amount for a given rate.
static calcAuctionMakingAmount(makingAmount: bigint, rate: number): bigint
makingAmount
bigint
required
Base making amount
rate
number
required
Current rate bump
bigint
The adjusted making amount based on the rate

baseFeeToGasPriceEstimate

Encode base fee as gas price estimate for AuctionGasCostInfo.
static baseFeeToGasPriceEstimate(baseFee: bigint): bigint
baseFee
bigint
required
Base fee in Wei
bigint
Gas price estimate (1000 = 1 Gwei)

calcGasBumpEstimate

Calculate gasBumpEstimate for AuctionGasCostInfo.
static calcGasBumpEstimate(
  endTakingAmount: bigint,
  gasCostInToToken: bigint
): bigint
endTakingAmount
bigint
required
Minimum return in destination token
gasCostInToToken
bigint
required
Gas cost in destination token
bigint
The gas bump estimate value

Instance Methods

calcRateBump

Calculate the rate bump at a specific time during the auction.
calcRateBump(time: bigint, blockBaseFee?: bigint): number
time
bigint
required
Auction timestamp in seconds
blockBaseFee
bigint
Block base fee in Wei. If provided, rate will be calculated as if order executed in block with this base fee
number
The rate bump at the specified time

calcAuctionTakingAmount

Calculate the taking amount for the current auction state.
calcAuctionTakingAmount(takingAmount: bigint, rate: number): bigint
takingAmount
bigint
required
Base taking amount
rate
number
required
Current rate bump from calcRateBump
bigint
The adjusted taking amount

Properties

finishTime
bigint
Get the auction finish time (startTime + duration)
RATE_BUMP_DENOMINATOR
bigint
Static constant: 10,000,000 (represents 100%)

Example

import {
  AuctionCalculator,
  AuctionDetails,
  Address
} from '@1inch/fusion-sdk'

const startTime = 1673548149n

const details = new AuctionDetails({
  duration: 180n, // in seconds
  startTime, // unix timestamp (in sec)
  initialRateBump: 50000,
  points: [
    {
      delay: 10, // relative to auction start time
      coefficient: 40000
    },
    {
      delay: 10, // relative to previous point
      coefficient: 40000
    }
  ]
})

const calculator = AuctionCalculator.fromAuctionData(details)

// Calculate rate at specific time
const rate = calculator.calcRateBump(startTime + 11n)
// => 40000

// Calculate taking amount with rate
const auctionTakingAmount = calculator.calcAuctionTakingAmount(
  1420000000n,
  rate
)
// => 1427105680

AuctionPoint

delay
number
required
Point in time of this point relative to the previous point (in seconds)
coefficient
number
required
Coefficient rate bump from the end of an auction

AuctionGasCostInfo

gasBumpEstimate
bigint
required
Rate bump to cover gas price. Defined as a ratio of gasCostInToToken to endTakingAmount. 10,000,000 means 100%
gasPriceEstimate
bigint
required
Gas price at estimation time. 1000 means 1 Gwei

Build docs developers (and LLMs) love