Skip to content

Commit

Permalink
feat: add useful getters (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk authored Mar 13, 2024
1 parent 60fb737 commit 55116f7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/auction-calculator/auction-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class AuctionCalculator {
/**
* @see https://github.com/1inch/limit-order-settlement/blob/1b6757eecb2574953b543821db6f7bbff5afee48/contracts/extensions/BaseExtension.sol#L56
*/
calcAuctionTakingAmount(takingAmount: bigint, rate: number): bigint {
public calcAuctionTakingAmount(takingAmount: bigint, rate: number): bigint {
const auctionTakingAmount =
(BigInt(takingAmount) * (BigInt(rate) + RATE_BUMP_DENOMINATOR)) /
RATE_BUMP_DENOMINATOR
Expand All @@ -62,7 +62,7 @@ export class AuctionCalculator {
* @param time auction timestamp in seconds
* @param blockBaseFee blockBaseFee in Wei, if passed, then rate will be calculated as if order executed in block with `blockBaseFee`
*/
calcRateBump(time: bigint, blockBaseFee = 0n): number {
public calcRateBump(time: bigint, blockBaseFee = 0n): number {
const gasBump = this.getGasPriceBump(blockBaseFee)
const auctionBump = this.getAuctionBump(time)

Expand Down
57 changes: 57 additions & 0 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import {AuctionCalculator} from '../auction-calculator'
import {add0x} from '../utils'
import {ZX} from '../constants'
import {calcTakingAmount} from '../utils/amounts'

export class FusionOrder {
private static defaultExtra = {
Expand Down Expand Up @@ -136,6 +137,37 @@ export class FusionOrder {
return this.inner.extension
}

get maker(): Address {
return this.inner.maker
}

get takerAsset(): Address {
return this.inner.takerAsset
}

get makerAsset(): Address {
return this.inner.makerAsset
}

get takingAmount(): bigint {
return this.inner.takingAmount
}

get makingAmount(): bigint {
return this.inner.makingAmount
}

get receiver(): Address {
return this.inner.receiver
}

/**
* Timestamp in sec
*/
get deadline(): bigint {
return this.inner.makerTraits.expiration() || 0n
}

static new(
/**
* Fusion extension address
Expand Down Expand Up @@ -275,4 +307,29 @@ export class FusionOrder {
this.fusionExtension.details
)
}

/**
* Calculates required taking amount for passed `makingAmount` at block time `time`
*
* @param makingAmount maker swap amount
* @param time execution time in sec
* @param blockBaseFee block fee in wei.
* */
public calcTakingAmount(
makingAmount: bigint,
time: bigint,
blockBaseFee = 0n
): bigint {
const takingAmount = calcTakingAmount(
makingAmount,
this.makingAmount,
this.takingAmount
)

const calculator = this.getCalculator()

const bump = calculator.calcRateBump(time, blockBaseFee)

return calculator.calcAuctionTakingAmount(takingAmount, bump)
}
}

0 comments on commit 55116f7

Please sign in to comment.