From e2a16c8866d275e76f65031b3c49481966d08228 Mon Sep 17 00:00:00 2001 From: Ivan Herger Date: Thu, 28 Sep 2023 10:03:33 +0200 Subject: [PATCH] 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, + }; +}