Skip to content

Commit

Permalink
default extra params for fusion in single object
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk committed Mar 1, 2024
1 parent 0de801c commit b070bfc
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import {AuctionCalculator} from '../auction-calculator'
import {Address} from '../address'

export class FusionOrder extends LimitOrder {
private static defaultExtra = {
allowPartialFills: true,
allowMultipleFills: true,
unwrapWETH: false,
enablePermit2: false,
orderExpirationDelay: 12n
}

public readonly fusionExtension: FusionExtension

constructor(
Expand Down Expand Up @@ -40,17 +48,25 @@ export class FusionOrder extends LimitOrder {
*/
orderExpirationDelay?: bigint
enablePermit2?: boolean
} = {}
} = FusionOrder.defaultExtra
) {
const allowPartialFills = extra.allowPartialFills ?? true
const allowMultipleFills = extra.allowMultipleFills ?? true
const unwrapWETH = extra.unwrapWETH ?? false
const enablePermit2 = extra.enablePermit2 ?? false
const {
allowPartialFills,
allowMultipleFills,
unwrapWETH,
enablePermit2,
orderExpirationDelay,
nonce,
permit
} = {
...FusionOrder.defaultExtra,
...extra
}

const deadline =
auctionDetails.auctionStartTime +
auctionDetails.duration +
(extra.orderExpirationDelay || 12n)
orderExpirationDelay

const makerTraits = MakerTraits.default()
.withExpiration(deadline)
Expand All @@ -59,7 +75,7 @@ export class FusionOrder extends LimitOrder {

if (makerTraits.isBitInvalidated()) {
assert(
extra.nonce !== undefined,
nonce !== undefined,
'Nonce required, when partial fill or multiple fill disallowed'
)
}
Expand All @@ -72,8 +88,8 @@ export class FusionOrder extends LimitOrder {
makerTraits.enablePermit2()
}

if (extra.nonce !== undefined) {
makerTraits.withNonce(extra.nonce)
if (nonce !== undefined) {
makerTraits.withNonce(nonce)
}

const extension = new FusionExtension(
Expand All @@ -82,8 +98,8 @@ export class FusionOrder extends LimitOrder {
postInteractionData
)

if (extra.permit) {
extension.withMakerPermit(orderInfo.makerAsset, extra.permit)
if (permit) {
extension.withMakerPermit(orderInfo.makerAsset, permit)
}

const builtExtension = extension.build()
Expand Down

0 comments on commit b070bfc

Please sign in to comment.