Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add decodedOneInchSwapArgs #164

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to prefix names with oneInch within a file called OneInchV5

{
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to prefix names with oneInch within a file called OneInchV5

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,
};
}
Loading