Skip to content

Commit

Permalink
feat: add decodedOneInchSwapArgs (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
iherger authored Sep 28, 2023
1 parent e57fd00 commit 447fbb3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-students-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@enzymefinance/sdk": patch
---

Add helper function to decode 1Inch data received from their API
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,67 @@ export function takeOrderDecode(encoded: Hex): TakeOrderArgs {
data,
};
}

const oneInchSwapArgsEncoding = [
{
name: "executor",
type: "address",
},
{
components: [
{
internalType: "address",
name: "srcToken",
type: "address",
},
{
internalType: "address",
name: "dstToken",
type: "address",
},
{
internalType: "address",
name: "srcReceiver",
type: "address",
},
{
internalType: "address",
name: "dstReceiver",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
{
internalType: "uint256",
name: "minReturnAmount",
type: "uint256",
},
{
internalType: "uint256",
name: "flags",
type: "uint256",
},
],
name: "orderDescription",
type: "tuple",
},
{ name: "unknown", type: "bytes" },
{
name: "data",
type: "bytes",
},
] as const;

export function decodedOneInchSwapArgs(encoded: Hex): TakeOrderArgs {
const [executor, orderDescription, , data] = decodeAbiParameters(oneInchSwapArgsEncoding, `0x${encoded.slice(10)}`);
const { srcToken, dstToken, srcReceiver, dstReceiver, amount, minReturnAmount, flags } = orderDescription;

return {
executor,
orderDescription: { srcToken, dstToken, srcReceiver, dstReceiver, amount, minReturnAmount, flags },
data,
};
}

0 comments on commit 447fbb3

Please sign in to comment.