From b070bfc44c4039434071a0d57affb08e216c981a Mon Sep 17 00:00:00 2001 From: Vladimir Borovik Date: Fri, 1 Mar 2024 20:46:19 +0300 Subject: [PATCH] default extra params for fusion in single object --- src/fusion-order/fusion-order.ts | 38 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/fusion-order/fusion-order.ts b/src/fusion-order/fusion-order.ts index e9e65c3..d5d54d3 100644 --- a/src/fusion-order/fusion-order.ts +++ b/src/fusion-order/fusion-order.ts @@ -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( @@ -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) @@ -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' ) } @@ -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( @@ -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()