Skip to content

Commit

Permalink
feat: add decodedOneInchSwapArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
iherger committed Sep 28, 2023
1 parent e57fd00 commit e2a16c8
Showing 1 changed file with 64 additions and 0 deletions.
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 e2a16c8

Please sign in to comment.