Skip to content

Commit

Permalink
chore: improvements for cross-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk committed Jun 25, 2024
1 parent 16284f5 commit 54af02d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/fusion-order/fusion-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export class FusionExtension {
public static decode(bytes: string): FusionExtension {
const extension = Extension.decode(bytes)

return FusionExtension.fromExtension(extension)
}

/**
* Create `FusionExtension` from `Extension`
*/
public static fromExtension(extension: Extension): FusionExtension {
const settlementContract = Address.fromFirstBytes(
extension.makingAmountData
)
Expand Down
31 changes: 17 additions & 14 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class FusionOrder {

private inner: LimitOrder

private constructor(
protected constructor(
/**
* Fusion extension address
* @see https://github.com/1inch/limit-order-settlement
Expand Down Expand Up @@ -72,7 +72,15 @@ export class FusionOrder {
orderExpirationDelay?: bigint
enablePermit2?: boolean
source?: string
} = FusionOrder.defaultExtra
} = FusionOrder.defaultExtra,
extension = new FusionExtension(
settlementExtensionContract,
auctionDetails,
postInteractionData,
extra.permit
? new Interaction(orderInfo.makerAsset, extra.permit)
: undefined
)
) {
const allowPartialFills =
extra.allowPartialFills ??
Expand All @@ -88,8 +96,6 @@ export class FusionOrder {
extra.orderExpirationDelay ??
FusionOrder.defaultExtra.orderExpirationDelay

const {nonce, permit} = extra

const deadline =
auctionDetails.startTime +
auctionDetails.duration +
Expand All @@ -103,7 +109,7 @@ export class FusionOrder {

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

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

/**
Expand All @@ -127,13 +133,6 @@ export class FusionOrder {
? settlementExtensionContract
: orderInfo.receiver

const extension = new FusionExtension(
settlementExtensionContract,
auctionDetails,
postInteractionData,
permit ? new Interaction(orderInfo.makerAsset, permit) : undefined
)

const builtExtension = extension.build()
const salt = LimitOrder.buildSalt(builtExtension, orderInfo.salt)
const saltWithInjectedTrackCode = orderInfo.salt
Expand Down Expand Up @@ -220,6 +219,10 @@ export class FusionOrder {
return this.inner.makerTraits.nonceOrEpoch()
}

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

static new(
/**
* Fusion extension address
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export {
ExtensionBuilder,
AmountMode,
getLimitOrderV4Domain,
LimitOrderContract
LimitOrderContract,
OrderInfoData,
EIP712TypedData,
MakerTraits
} from '@1inch/limit-order-sdk'
export * from './fusion-order/index'
export * from './auction-calculator/index'
Expand All @@ -18,6 +21,7 @@ export * from './sdk/index'
export * from './constants'
export * from './utils'
export * from './utils/amounts'
export * from './utils/time'
export * from './validations'
export * from './ws-api'
export * from './errors'
Expand Down

0 comments on commit 54af02d

Please sign in to comment.