Skip to content

Commit

Permalink
fix(fusion-extension): correct permit decoding (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk authored Apr 12, 2024
1 parent 8a9e39d commit 48abf9e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@1inch/byte-utils": "2.2.1",
"@1inch/limit-order-sdk": "^4.8.3",
"@1inch/limit-order-sdk": "^4.8.4",
"@metamask/eth-sig-util": "^5.1.0",
"bn.js": "^5.2.1",
"ethers": "6.11.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions src/fusion-order/fusion-extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,55 @@ describe('FusionExtension', () => {
const fusionExtension = FusionExtension.decode(order.extension.encode())
expect(fusionExtension).toStrictEqual(order.fusionExtension)
})

it('should decode with permit', () => {
const extensionContract = new Address(
'0x8273f37417da37c4a6c3995e82cf442f87a25d9c'
)

const order = FusionOrder.new(
extensionContract,
{
makerAsset: new Address(
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
),
takerAsset: new Address(
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
),
makingAmount: 1000000000000000000n,
takingAmount: 1420000000n,
maker: new Address(
'0x00000000219ab540356cbb839cbe05303d7705fa'
),
salt: 10n
},
{
auction: new AuctionDetails({
duration: 180n,
startTime: 1673548149n,
initialRateBump: 50000,
points: [
{
coefficient: 20000,
delay: 12
}
]
}),
whitelist: [
{
address: new Address(
'0x00000000219ab540356cbb839cbe05303d7705fa'
),
allowFrom: 0n
}
],
resolvingStartTime: 1673548139n
},
{
permit: '0xdeadbeef'
}
)
const fusionExtension = FusionExtension.decode(order.extension.encode())
expect(fusionExtension).toStrictEqual(order.fusionExtension)
})
})
20 changes: 12 additions & 8 deletions src/fusion-order/fusion-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class FusionExtension {
constructor(
public readonly address: Address,
public readonly auctionDetails: AuctionDetails,
public readonly postInteractionData: SettlementPostInteractionData
public readonly postInteractionData: SettlementPostInteractionData,
public readonly makerPermit?: Interaction
) {
const detailsBytes = this.auctionDetails.encode()

Expand All @@ -25,6 +26,10 @@ export class FusionExtension {
.withPostInteraction(
new Interaction(this.address, this.postInteractionData.encode())
)

if (makerPermit) {
this.builder.withMakerPermit(makerPermit.target, makerPermit.data)
}
}

/**
Expand Down Expand Up @@ -54,19 +59,18 @@ export class FusionExtension {
const postInteractionData =
SettlementPostInteractionData.fromExtension(extension)

const permit = extension.hasMakerPermit
? Interaction.decode(extension.makerPermit)
: undefined

return new FusionExtension(
settlementContract,
auctionDetails,
postInteractionData
postInteractionData,
permit
)
}

withMakerPermit(tokenFrom: Address, permitData: string): this {
this.builder.withMakerPermit(tokenFrom, permitData)

return this
}

public build(): Extension {
return this.builder.build()
}
Expand Down
8 changes: 3 additions & 5 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Address,
EIP712TypedData,
Extension,
Interaction,
LimitOrder,
LimitOrderV4Struct,
MakerTraits,
Expand Down Expand Up @@ -127,13 +128,10 @@ export class FusionOrder {
const extension = new FusionExtension(
settlementExtensionContract,
auctionDetails,
postInteractionData
postInteractionData,
permit ? new Interaction(orderInfo.makerAsset, permit) : undefined
)

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

const builtExtension = extension.build()

this.inner = new LimitOrder(
Expand Down

0 comments on commit 48abf9e

Please sign in to comment.