From e2a16c8866d275e76f65031b3c49481966d08228 Mon Sep 17 00:00:00 2001 From: Ivan Herger Date: Thu, 28 Sep 2023 10:03:33 +0200 Subject: [PATCH 1/2] feat: add decodedOneInchSwapArgs --- .../IntegrationAdapters/OneInchV5.ts | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/packages/sdk/src/internal/Extensions/IntegrationAdapters/OneInchV5.ts b/packages/sdk/src/internal/Extensions/IntegrationAdapters/OneInchV5.ts index d821a88f..787b3783 100644 --- a/packages/sdk/src/internal/Extensions/IntegrationAdapters/OneInchV5.ts +++ b/packages/sdk/src/internal/Extensions/IntegrationAdapters/OneInchV5.ts @@ -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, + }; +} From 73cc7fd9ef01abf5ad88d0ca4ca18bae4a79ea7e Mon Sep 17 00:00:00 2001 From: Ivan Herger Date: Thu, 28 Sep 2023 10:05:24 +0200 Subject: [PATCH 2/2] chore: add changeset --- .changeset/clever-students-live.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clever-students-live.md diff --git a/.changeset/clever-students-live.md b/.changeset/clever-students-live.md new file mode 100644 index 00000000..1c7a46a5 --- /dev/null +++ b/.changeset/clever-students-live.md @@ -0,0 +1,5 @@ +--- +"@enzymefinance/sdk": patch +--- + +Add helper function to decode 1Inch data received from their API