From 2f0837ac99a3c848acbb5701260c2e963264c353 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Tue, 19 Dec 2023 14:15:55 -0800 Subject: [PATCH 01/38] feat(handlefi): initialize plugin from template --- packages/handlefi/CHANGELOG.md | 0 packages/handlefi/README.md | 0 packages/handlefi/package.json | 49 ++++++++++++++++++++++++++ packages/handlefi/src/HandleFi.test.ts | 12 +++++++ packages/handlefi/src/HandleFi.ts | 36 +++++++++++++++++++ packages/handlefi/src/index.ts | 19 ++++++++++ packages/handlefi/tsconfig.build.json | 16 +++++++++ packages/handlefi/tsconfig.json | 5 +++ packages/registry/package.json | 1 + packages/registry/src/index.ts | 2 ++ pnpm-lock.yaml | 27 ++++++++++++++ 11 files changed, 167 insertions(+) create mode 100644 packages/handlefi/CHANGELOG.md create mode 100644 packages/handlefi/README.md create mode 100644 packages/handlefi/package.json create mode 100644 packages/handlefi/src/HandleFi.test.ts create mode 100644 packages/handlefi/src/HandleFi.ts create mode 100644 packages/handlefi/src/index.ts create mode 100644 packages/handlefi/tsconfig.build.json create mode 100644 packages/handlefi/tsconfig.json diff --git a/packages/handlefi/CHANGELOG.md b/packages/handlefi/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/handlefi/README.md b/packages/handlefi/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/handlefi/package.json b/packages/handlefi/package.json new file mode 100644 index 000000000..69ff0aac2 --- /dev/null +++ b/packages/handlefi/package.json @@ -0,0 +1,49 @@ +{ + "name": "@rabbitholegg/questdk-plugin-handlefi", + "version": "1.0.0-alpha.0", + "type": "module", + "exports": { + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts" + }, + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "packageManager": "pnpm@8.3.1", + "description": "", + "scripts": { + "bench": "vitest bench", + "bench:ci": "CI=true vitest bench", + "build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", + "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap", + "clean": "rimraf dist", + "format": "rome format . --write", + "lint": "rome check .", + "lint:fix": "pnpm lint --apply", + "test": "vitest dev", + "test:cov": "vitest dev --coverage", + "test:ci": "CI=true vitest --coverage", + "test:ui": "vitest dev --ui" + }, + "keywords": [], + "author": "", + "license": "ISC", + "types": "./dist/types/index.d.ts", + "typings": "./dist/types/index.d.ts", + "devDependencies": { + "@types/node": "^20.8.7", + "@vitest/coverage-v8": "^0.33.0", + "rimraf": "^5.0.5", + "rome": "^12.1.3", + "ts-node": "^10.9.1", + "tsconfig": "workspace:*", + "typescript": "^5.2.2", + "vitest": "^0.33.0" + }, + "dependencies": { + "@rabbitholegg/questdk": "2.0.0-alpha.28", + "viem": "^1.16.6" + } +} diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts new file mode 100644 index 000000000..539867ffb --- /dev/null +++ b/packages/handlefi/src/HandleFi.test.ts @@ -0,0 +1,12 @@ +import { apply } from '@rabbitholegg/questdk/filter' +import { describe, expect, test } from 'vitest' + +describe('Given the handlefi plugin', () => { + describe('When handling the swap action', () => { + describe('should return a valid action filter', () => {}) + + describe('should pass filter with valid transactions', () => {}) + + describe('should not pass filter with invalid transactions', () => {}) + }) +}) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts new file mode 100644 index 000000000..3c8e34722 --- /dev/null +++ b/packages/handlefi/src/HandleFi.ts @@ -0,0 +1,36 @@ +import { + type TransactionFilter, + type SwapActionParams, + compressJson, +} from '@rabbitholegg/questdk' +import { type Address } from 'viem' + +export const swap = async ( + swap: SwapActionParams, +): Promise => { + const { + chainId, + contractAddress, + tokenIn, + tokenOut, + amountIn, + amountOut, + recipient, + } = swap + + return compressJson({ + chainId: 0, // The chainId of the source chain + to: 0x0, // The contract address of the bridge + input: {}, // The input object is where we'll put the ABI and the parameters + }) +} + +export const getSupportedTokenAddresses = async ( + _chainId: number, +): Promise => { + return [] +} + +export const getSupportedChainIds = async (): Promise => { + return [] +} diff --git a/packages/handlefi/src/index.ts b/packages/handlefi/src/index.ts new file mode 100644 index 000000000..5825c8560 --- /dev/null +++ b/packages/handlefi/src/index.ts @@ -0,0 +1,19 @@ +import { + type IActionPlugin, + PluginActionNotImplementedError, +} from '@rabbitholegg/questdk' + +import { + swap, + getSupportedChainIds, + getSupportedTokenAddresses, +} from './HandleFi.js' + +export const HandleFi: IActionPlugin = { + pluginId: 'handlefi', + getSupportedTokenAddresses, + getSupportedChainIds, + swap, + bridge: async () => new PluginActionNotImplementedError(), + mint: async () => new PluginActionNotImplementedError(), +} diff --git a/packages/handlefi/tsconfig.build.json b/packages/handlefi/tsconfig.build.json new file mode 100644 index 000000000..2e27369d5 --- /dev/null +++ b/packages/handlefi/tsconfig.build.json @@ -0,0 +1,16 @@ +{ + "extends": "tsconfig/base.json", + "include": ["src"], + "exclude": [ + "src/**/*.test.ts", + "src/**/*.test-d.ts", + "src/**/*.bench.ts", + "src/_test", + "scripts/**/*" + ], + "compilerOptions": { + "resolveJsonModule": true, + "sourceMap": true, + "rootDir": "./src" + } +} diff --git a/packages/handlefi/tsconfig.json b/packages/handlefi/tsconfig.json new file mode 100644 index 000000000..c76405177 --- /dev/null +++ b/packages/handlefi/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "tsconfig/base.json", + "include": ["src/**/*", "src/chain-data.ts"], + "exclude": ["dist", "build", "node_modules"] +} diff --git a/packages/registry/package.json b/packages/registry/package.json index 9fe080ed1..bd4ab1ab7 100644 --- a/packages/registry/package.json +++ b/packages/registry/package.json @@ -68,6 +68,7 @@ "@rabbitholegg/questdk-plugin-woofi": "workspace:*", "@rabbitholegg/questdk-plugin-sushi": "workspace:*", "@rabbitholegg/questdk-plugin-treasure": "workspace:*", + "@rabbitholegg/questdk-plugin-handlefi": "workspace:*", "viem": "^1.16.6" } } diff --git a/packages/registry/src/index.ts b/packages/registry/src/index.ts index 00dcff266..393fb6e67 100644 --- a/packages/registry/src/index.ts +++ b/packages/registry/src/index.ts @@ -36,6 +36,7 @@ import { Synapse } from '@rabbitholegg/questdk-plugin-synapse' import { WooFi } from '@rabbitholegg/questdk-plugin-woofi' import { Sushi } from '@rabbitholegg/questdk-plugin-sushi' import { Treasure } from '@rabbitholegg/questdk-plugin-treasure' +import { HandleFi } from '@rabbitholegg/questdk-plugin-handlefi' import { ENTRYPOINT } from './contract-addresses' export const plugins: Record = { @@ -63,6 +64,7 @@ export const plugins: Record = { [WooFi.pluginId]: WooFi, [Sushi.pluginId]: Sushi, [Treasure.pluginId]: Treasure, + [HandleFi.pluginId]: HandleFi, } export const getPlugin = (pluginId: string) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f8e48d7f4..59d8a9acd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -204,6 +204,31 @@ importers: typescript: 5.1.6 vitest: 0.33.0 + packages/handlefi: + specifiers: + '@rabbitholegg/questdk': 2.0.0-alpha.28 + '@types/node': ^20.8.7 + '@vitest/coverage-v8': ^0.33.0 + rimraf: ^5.0.5 + rome: ^12.1.3 + ts-node: ^10.9.1 + tsconfig: workspace:* + typescript: ^5.2.2 + viem: ^1.16.6 + vitest: ^0.33.0 + dependencies: + '@rabbitholegg/questdk': 2.0.0-alpha.28_typescript@5.3.2 + viem: 1.19.11_typescript@5.3.2 + devDependencies: + '@types/node': 20.10.3 + '@vitest/coverage-v8': 0.33.0_vitest@0.33.0 + rimraf: 5.0.5 + rome: 12.1.3 + ts-node: 10.9.1_xy5pmmm77qgfdfg5jflxsqkm74 + tsconfig: link:../tsconfig + typescript: 5.3.2 + vitest: 0.33.0 + packages/hop: specifiers: '@hop-protocol/core': 0.0.1-beta.182 @@ -401,6 +426,7 @@ importers: '@rabbitholegg/questdk-plugin-camelot': workspace:* '@rabbitholegg/questdk-plugin-connext': workspace:* '@rabbitholegg/questdk-plugin-gmx': workspace:* + '@rabbitholegg/questdk-plugin-handlefi': workspace:* '@rabbitholegg/questdk-plugin-hop': workspace:* '@rabbitholegg/questdk-plugin-hyphen': workspace:* '@rabbitholegg/questdk-plugin-okutrade': workspace:* @@ -436,6 +462,7 @@ importers: '@rabbitholegg/questdk-plugin-camelot': link:../camelot '@rabbitholegg/questdk-plugin-connext': link:../connext '@rabbitholegg/questdk-plugin-gmx': link:../gmx + '@rabbitholegg/questdk-plugin-handlefi': link:../handlefi '@rabbitholegg/questdk-plugin-hop': link:../hop '@rabbitholegg/questdk-plugin-hyphen': link:../hyphen '@rabbitholegg/questdk-plugin-okutrade': link:../okutrade From 9a79531dc414b6f5a8c9fb0a26907b37c59d7454 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 20:50:13 -0800 Subject: [PATCH 02/38] feat(handlefi): add abi for various functions --- packages/handlefi/src/abi.ts | 645 +++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 packages/handlefi/src/abi.ts diff --git a/packages/handlefi/src/abi.ts b/packages/handlefi/src/abi.ts new file mode 100644 index 000000000..9c054c0a9 --- /dev/null +++ b/packages/handlefi/src/abi.ts @@ -0,0 +1,645 @@ +export const V2_ROUTER_ABI = [ + { + inputs: [ + { internalType: 'address[]', name: '_path', type: 'address[]' }, + { internalType: 'uint256', name: '_amountIn', type: 'uint256' }, + { internalType: 'uint256', name: '_minOut', type: 'uint256' }, + { internalType: 'address', name: '_receiver', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swap', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address[]', name: '_path', type: 'address[]' }, + { internalType: 'uint256', name: '_minOut', type: 'uint256' }, + { internalType: 'address', name: '_receiver', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapETHToTokens', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address[]', name: '_path', type: 'address[]' }, + { internalType: 'uint256', name: '_amountIn', type: 'uint256' }, + { internalType: 'uint256', name: '_minOut', type: 'uint256' }, + { internalType: 'address payable', name: '_receiver', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapTokensToETH', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] + +export const PARASWAP_ABI = [ + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'address[]', name: 'callees', type: 'address[]' }, + { internalType: 'bytes', name: 'exchangeData', type: 'bytes' }, + { + internalType: 'uint256[]', + name: 'startIndexes', + type: 'uint256[]', + }, + { internalType: 'uint256[]', name: 'values', type: 'uint256[]' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.SimpleData', + name: 'data', + type: 'tuple', + }, + ], + name: 'simpleBuy', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'address[]', name: 'callees', type: 'address[]' }, + { internalType: 'bytes', name: 'exchangeData', type: 'bytes' }, + { + internalType: 'uint256[]', + name: 'startIndexes', + type: 'uint256[]', + }, + { internalType: 'uint256[]', name: 'values', type: 'uint256[]' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.SimpleData', + name: 'data', + type: 'tuple', + }, + ], + name: 'simpleSwap', + outputs: [ + { internalType: 'uint256', name: 'receivedAmount', type: 'uint256' }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { + components: [ + { + internalType: 'uint256', + name: 'fromAmountPercent', + type: 'uint256', + }, + { + components: [ + { internalType: 'address', name: 'to', type: 'address' }, + { + internalType: 'uint256', + name: 'totalNetworkFee', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'adapter', + type: 'address', + }, + { + internalType: 'uint256', + name: 'percent', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'networkFee', + type: 'uint256', + }, + { + components: [ + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + { + internalType: 'address', + name: 'targetExchange', + type: 'address', + }, + { + internalType: 'uint256', + name: 'percent', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'payload', + type: 'bytes', + }, + { + internalType: 'uint256', + name: 'networkFee', + type: 'uint256', + }, + ], + internalType: 'struct Utils.Route[]', + name: 'route', + type: 'tuple[]', + }, + ], + internalType: 'struct Utils.Adapter[]', + name: 'adapters', + type: 'tuple[]', + }, + ], + internalType: 'struct Utils.Path[]', + name: 'path', + type: 'tuple[]', + }, + ], + internalType: 'struct Utils.MegaSwapPath[]', + name: 'path', + type: 'tuple[]', + }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.MegaSwapSellData', + name: 'data', + type: 'tuple', + }, + ], + name: 'megaSwap', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { + components: [ + { internalType: 'address', name: 'to', type: 'address' }, + { + internalType: 'uint256', + name: 'totalNetworkFee', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'adapter', + type: 'address', + }, + { internalType: 'uint256', name: 'percent', type: 'uint256' }, + { + internalType: 'uint256', + name: 'networkFee', + type: 'uint256', + }, + { + components: [ + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + { + internalType: 'address', + name: 'targetExchange', + type: 'address', + }, + { + internalType: 'uint256', + name: 'percent', + type: 'uint256', + }, + { internalType: 'bytes', name: 'payload', type: 'bytes' }, + { + internalType: 'uint256', + name: 'networkFee', + type: 'uint256', + }, + ], + internalType: 'struct Utils.Route[]', + name: 'route', + type: 'tuple[]', + }, + ], + internalType: 'struct Utils.Adapter[]', + name: 'adapters', + type: 'tuple[]', + }, + ], + internalType: 'struct Utils.Path[]', + name: 'path', + type: 'tuple[]', + }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.SellData', + name: 'data', + type: 'tuple', + }, + ], + name: 'multiSwap', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + components: [ + { internalType: 'bytes32', name: 'poolId', type: 'bytes32' }, + { + internalType: 'uint256', + name: 'assetInIndex', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'assetOutIndex', + type: 'uint256', + }, + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'bytes', name: 'userData', type: 'bytes' }, + ], + internalType: 'struct IBalancerV2Vault.BatchSwapStep[]', + name: 'swaps', + type: 'tuple[]', + }, + { internalType: 'address[]', name: 'assets', type: 'address[]' }, + { + components: [ + { internalType: 'address', name: 'sender', type: 'address' }, + { + internalType: 'bool', + name: 'fromInternalBalance', + type: 'bool', + }, + { + internalType: 'address payable', + name: 'recipient', + type: 'address', + }, + { internalType: 'bool', name: 'toInternalBalance', type: 'bool' }, + ], + internalType: 'struct IBalancerV2Vault.FundManagement', + name: 'funds', + type: 'tuple', + }, + { internalType: 'int256[]', name: 'limits', type: 'int256[]' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'address', name: 'vault', type: 'address' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectBalancerV2', + name: 'data', + type: 'tuple', + }, + ], + name: 'directBalancerV2GivenInSwap', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + components: [ + { internalType: 'bytes32', name: 'poolId', type: 'bytes32' }, + { + internalType: 'uint256', + name: 'assetInIndex', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'assetOutIndex', + type: 'uint256', + }, + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'bytes', name: 'userData', type: 'bytes' }, + ], + internalType: 'struct IBalancerV2Vault.BatchSwapStep[]', + name: 'swaps', + type: 'tuple[]', + }, + { internalType: 'address[]', name: 'assets', type: 'address[]' }, + { + components: [ + { internalType: 'address', name: 'sender', type: 'address' }, + { + internalType: 'bool', + name: 'fromInternalBalance', + type: 'bool', + }, + { + internalType: 'address payable', + name: 'recipient', + type: 'address', + }, + { internalType: 'bool', name: 'toInternalBalance', type: 'bool' }, + ], + internalType: 'struct IBalancerV2Vault.FundManagement', + name: 'funds', + type: 'tuple', + }, + { internalType: 'int256[]', name: 'limits', type: 'int256[]' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'address', name: 'vault', type: 'address' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectBalancerV2', + name: 'data', + type: 'tuple', + }, + ], + name: 'directBalancerV2GivenOutSwap', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'address', name: 'exchange', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'int128', name: 'i', type: 'int128' }, + { internalType: 'int128', name: 'j', type: 'int128' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'enum Utils.CurveSwapType', + name: 'swapType', + type: 'uint8', + }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bool', name: 'needWrapNative', type: 'bool' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectCurveV1', + name: 'data', + type: 'tuple', + }, + ], + name: 'directCurveV1Swap', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'address', name: 'exchange', type: 'address' }, + { internalType: 'address', name: 'poolAddress', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'uint256', name: 'i', type: 'uint256' }, + { internalType: 'uint256', name: 'j', type: 'uint256' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'enum Utils.CurveSwapType', + name: 'swapType', + type: 'uint8', + }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bool', name: 'needWrapNative', type: 'bool' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectCurveV2', + name: 'data', + type: 'tuple', + }, + ], + name: 'directCurveV2Swap', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'address', name: 'exchange', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bytes', name: 'path', type: 'bytes' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectUniV3', + name: 'data', + type: 'tuple', + }, + ], + name: 'directUniV3Buy', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { internalType: 'address', name: 'fromToken', type: 'address' }, + { internalType: 'address', name: 'toToken', type: 'address' }, + { internalType: 'address', name: 'exchange', type: 'address' }, + { internalType: 'uint256', name: 'fromAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'toAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'expectedAmount', type: 'uint256' }, + { internalType: 'uint256', name: 'feePercent', type: 'uint256' }, + { internalType: 'uint256', name: 'deadline', type: 'uint256' }, + { internalType: 'address payable', name: 'partner', type: 'address' }, + { internalType: 'bool', name: 'isApproved', type: 'bool' }, + { + internalType: 'address payable', + name: 'beneficiary', + type: 'address', + }, + { internalType: 'bytes', name: 'path', type: 'bytes' }, + { internalType: 'bytes', name: 'permit', type: 'bytes' }, + { internalType: 'bytes16', name: 'uuid', type: 'bytes16' }, + ], + internalType: 'struct Utils.DirectUniV3', + name: 'data', + type: 'tuple', + }, + ], + name: 'directUniV3Swap', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, +] + +export const HPSM2_ABI = [ + { + inputs: [ + { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, + { internalType: 'address', name: 'peggedTokenAddress', type: 'address' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'deposit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, + { internalType: 'address', name: 'peggedTokenAddress', type: 'address' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] + +export const HLP_CURVE_V2_ABI = [ + { + stateMutability: 'nonpayable', + type: 'function', + name: 'exchange_underlying', + inputs: [ + { name: 'i', type: 'int128' }, + { name: 'j', type: 'int128' }, + { name: '_dx', type: 'uint256' }, + { name: '_min_dy', type: 'uint256' }, + ], + outputs: [{ name: '', type: 'uint256' }], + gas: 1323223, + }, +] From 8e3ea3d4c2f79cadf33d069ee47a587aaaeb64fc Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 20:50:39 -0800 Subject: [PATCH 03/38] chore(pnpm): install curve api package --- packages/handlefi/package.json | 1 + pnpm-lock.yaml | 88 ++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/packages/handlefi/package.json b/packages/handlefi/package.json index 69ff0aac2..f67808010 100644 --- a/packages/handlefi/package.json +++ b/packages/handlefi/package.json @@ -43,6 +43,7 @@ "vitest": "^0.33.0" }, "dependencies": { + "@curvefi/api": "^2.53.5", "@rabbitholegg/questdk": "2.0.0-alpha.28", "viem": "^1.16.6" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59d8a9acd..2a325709d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -206,6 +206,7 @@ importers: packages/handlefi: specifiers: + '@curvefi/api': ^2.53.5 '@rabbitholegg/questdk': 2.0.0-alpha.28 '@types/node': ^20.8.7 '@vitest/coverage-v8': ^0.33.0 @@ -217,6 +218,7 @@ importers: viem: ^1.16.6 vitest: ^0.33.0 dependencies: + '@curvefi/api': 2.53.5 '@rabbitholegg/questdk': 2.0.0-alpha.28_typescript@5.3.2 viem: 1.19.11_typescript@5.3.2 devDependencies: @@ -1109,6 +1111,20 @@ packages: dependencies: '@jridgewell/trace-mapping': 0.3.9 + /@curvefi/api/2.53.5: + resolution: {integrity: sha512-HEKZBrx+METfCJ4cz+Zg/Gs0LFxlwtPS+PewU6qhBZyBbrTetYZ4avQbYPPdnyXUfVQ9xWYPLR6G86QcJB47Pg==} + dependencies: + axios: 0.21.4 + bignumber.js: 9.1.2 + ethcall: 6.0.2_ethers@6.9.0 + ethers: 6.9.0 + memoizee: 0.4.15 + transitivePeerDependencies: + - bufferutil + - debug + - utf-8-validate + dev: false + /@esbuild/android-arm/0.16.17: resolution: {integrity: sha512-N9x1CMXVhtWEAMS7pNNONyA14f71VPQN9Cnavj1XQh6T7bskqiLLrSca4O0Vr8Wdcga943eThxnVp3JLnBMYtw==} engines: {node: '>=12'} @@ -3264,6 +3280,14 @@ packages: - zod dev: false + /abi-coder/5.0.0_ethers@6.9.0: + resolution: {integrity: sha512-Kpyv/AhAaIaVJiJ6S/xqoTsiJrfSMc3QsBCiRDqic3o1CZNKGR3CIeT1K/1VZ7Wk5uSwsOAxQcke1TVUEz+usg==} + peerDependencies: + ethers: ^6.0.0 + dependencies: + ethers: 6.9.0 + dev: false + /abitype/0.8.11_typescript@5.1.6: resolution: {integrity: sha512-bM4v2dKvX08sZ9IU38IN5BKmN+ZkOSd2oI4a9f0ejHYZQYV6cDr7j+d95ga0z2XHG36Y4jzoG5Z7qDqxp7fi/A==} peerDependencies: @@ -3691,6 +3715,14 @@ packages: resolution: {integrity: sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==} dev: false + /axios/0.21.4: + resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} + dependencies: + follow-redirects: 1.15.3 + transitivePeerDependencies: + - debug + dev: false + /axios/0.26.1: resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} dependencies: @@ -5052,6 +5084,15 @@ packages: ext: 1.7.0 dev: false + /es6-weak-map/2.0.3: + resolution: {integrity: sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==} + dependencies: + d: 1.0.1 + es5-ext: 0.10.62 + es6-iterator: 2.0.3 + es6-symbol: 3.1.3 + dev: false + /esbuild/0.16.17: resolution: {integrity: sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==} engines: {node: '>=12'} @@ -5291,6 +5332,16 @@ packages: xhr-request-promise: 0.1.3 dev: false + /ethcall/6.0.2_ethers@6.9.0: + resolution: {integrity: sha512-FyaKLlxtaVt+kRmhzDG3YfW4VxqasxZE2CDSfylMVp8kCxsBikzFE1BO90yAMGdjdwaX0kHlvjWSxKRpiEcI4w==} + peerDependencies: + ethers: ^6.0.0 + dependencies: + '@types/node': 20.10.3 + abi-coder: 5.0.0_ethers@6.9.0 + ethers: 6.9.0 + dev: false + /ethereum-block-by-date/1.4.9: resolution: {integrity: sha512-BsU2uwrfEpBZ+99j2Bk7OjoLi4BhTQ2IpEw2xaGyzqdfL/ibO8YJj7+oLBsdjJL11V7uhSxF+miAE7voI9dUOA==} dependencies: @@ -5443,6 +5494,13 @@ packages: number-to-bn: 1.7.0 dev: false + /event-emitter/0.3.5: + resolution: {integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==} + dependencies: + d: 1.0.1 + es5-ext: 0.10.62 + dev: false + /event-target-shim/5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -6562,6 +6620,10 @@ packages: resolution: {integrity: sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==} engines: {node: '>=0.10.0'} + /is-promise/2.2.2: + resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} + dev: false + /is-regex/1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -7093,6 +7155,12 @@ packages: engines: {node: '>=12'} dev: true + /lru-queue/0.1.0: + resolution: {integrity: sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==} + dependencies: + es5-ext: 0.10.62 + dev: false + /ltgt/2.2.1: resolution: {integrity: sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==} dev: false @@ -7163,6 +7231,19 @@ packages: safe-buffer: 5.2.1 dev: false + /memoizee/0.4.15: + resolution: {integrity: sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==} + dependencies: + d: 1.0.1 + es5-ext: 0.10.62 + es6-weak-map: 2.0.3 + event-emitter: 0.3.5 + is-promise: 2.2.2 + lru-queue: 0.1.0 + next-tick: 1.1.0 + timers-ext: 0.1.7 + dev: false + /meow/6.1.1: resolution: {integrity: sha512-3YffViIt2QWgTy6Pale5QpopX/IvU3LPL03jOTqp6pGj3VjesdO/U8CuHMKpnQr4shCNCM5fd5XFFvIIl6JBHg==} engines: {node: '>=8'} @@ -9418,6 +9499,13 @@ packages: engines: {node: '>=0.10.0'} dev: false + /timers-ext/0.1.7: + resolution: {integrity: sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==} + dependencies: + es5-ext: 0.10.62 + next-tick: 1.1.0 + dev: false + /tiny-invariant/1.3.1: resolution: {integrity: sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==} dev: false From 2074c83634fb7a4675c3e76f2ad021a124d9e8da Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 20:52:22 -0800 Subject: [PATCH 04/38] feat(handlefi): clone utils file --- packages/handlefi/src/utils.ts | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 packages/handlefi/src/utils.ts diff --git a/packages/handlefi/src/utils.ts b/packages/handlefi/src/utils.ts new file mode 100644 index 000000000..a8d1d8b98 --- /dev/null +++ b/packages/handlefi/src/utils.ts @@ -0,0 +1,69 @@ +import type { ActionParams, FilterOperator } from '@rabbitholegg/questdk' +import type { Address, Hash } from 'viem' + +export enum Chains { + ARBITRUM_ONE = 42161, + AVALANCHE = 43114, +} + +interface Transaction { + chainId: number + from: Address + hash?: Hash + input: string + to: Address + value: string +} + +export interface TestCase { + transaction: Transaction + params: T + description: string +} + +export type TestParams = { + transaction: Transaction + params: T +} + +/** + * Creates a test case object for a given action and transaction. + * + * This function takes a `TestParams` object that includes both a `Transaction` and + * `ActionParams`, a description of the test case, and an optional set of overrides + * for the action parameters. It returns a `TestCase` object that contains the transaction, + * the combined action parameters with any overrides applied, and the description. + * + * @param {TestParams} testParams - An object containing the transaction and action parameters. + * @param {string} description - A brief description of the test case. + * @param {Partial} [overrides] - Optional overrides for the action parameters. + * @returns {TestCase} A test case object with the transaction, params, and description. + */ +export function createTestCase( + testParams: TestParams, + description: string, + overrides: Partial = {}, +): TestCase { + return { + transaction: testParams.transaction, + params: { ...testParams.params, ...overrides }, + description, + } +} + +export const buildV2PathQuery = (tokenIn?: string, tokenOut?: string) => { + // v2 paths are formatted as [, ] + const conditions: FilterOperator[] = [] + + if (tokenIn) { + conditions.push({ $first: tokenIn }) + } + + if (tokenOut) { + conditions.push({ $last: tokenOut }) + } + + return { + $and: conditions, + } +} From 3c81ab219de77bb9b9c4e7b8e4fdad866eb2b397 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 21:01:53 -0800 Subject: [PATCH 05/38] feat(handlefi): add contract and token addresses to constants file --- packages/handlefi/src/constants.ts | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packages/handlefi/src/constants.ts diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts new file mode 100644 index 000000000..1b4ce06af --- /dev/null +++ b/packages/handlefi/src/constants.ts @@ -0,0 +1,33 @@ +// Swap Contract Addresses +const AUGUSTUS_SWAPPER = '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57' +const V2_ROUTER = '0x434b5245f6Fe54D0C9F881d55c2Ba27fe7132d89' +const HPSM2_CONTRACT = '0x0f330a53874cea3e5a0dee5d291c49275fdc3260' +const HLP_CURVE_CONTRACT = '0x559844b1Df66e247F83Ba58bc39fa488A1AF1093' +const HLP_BALANCER_CONTRACT = '0x9bDc4094860C97d9e5f1C18C4602a4a907d0a916' +const HANDLE_FRAX_BP = '0xab174ffa530c888649c44c4d21c849bbaabc723f' +const HANDLE_3POOL = '0xd0dd5d76cf0fc06dabc48632735566dca241a35e' + +export const SWAP_CONTRACTS = [ + AUGUSTUS_SWAPPER, + V2_ROUTER, + HPSM2_CONTRACT, + HLP_CURVE_CONTRACT, + HLP_BALANCER_CONTRACT, + HANDLE_FRAX_BP, + HANDLE_3POOL, +] + +// Token Addresses +const FX_USD = '0x8616E8EA83f048ab9A5eC513c9412Dd2993bcE3F' +const FOREX = '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b' +const ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548' +const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' +const WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1' + +export const TOKEN_ADDRESSES = [ + FX_USD, + FOREX, + ARB, + USDC, + WETH +] \ No newline at end of file From 9ad79b64fadbbc6f7787d0641bbc32b816d42fa2 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 22:19:11 -0800 Subject: [PATCH 06/38] feat(handlefi): add arbitrum chain id to constants --- packages/handlefi/src/constants.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts index 1b4ce06af..19b13b010 100644 --- a/packages/handlefi/src/constants.ts +++ b/packages/handlefi/src/constants.ts @@ -1,3 +1,6 @@ +// Chains +export const ARBITRUM_ONE = 42161 + // Swap Contract Addresses const AUGUSTUS_SWAPPER = '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57' const V2_ROUTER = '0x434b5245f6Fe54D0C9F881d55c2Ba27fe7132d89' @@ -18,11 +21,11 @@ export const SWAP_CONTRACTS = [ ] // Token Addresses +export const WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1' const FX_USD = '0x8616E8EA83f048ab9A5eC513c9412Dd2993bcE3F' const FOREX = '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b' const ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548' const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' -const WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1' export const TOKEN_ADDRESSES = [ FX_USD, From 31e54f3b6ba57885c3bca59e32a934a808ff2704 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 22:20:10 -0800 Subject: [PATCH 07/38] test(handlefi): setup test cases for paraswap routes --- packages/handlefi/src/HandleFi.test.ts | 28 +++++- packages/handlefi/src/test-transactions.ts | 107 +++++++++++++++++++++ 2 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 packages/handlefi/src/test-transactions.ts diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts index 539867ffb..b520cc7ac 100644 --- a/packages/handlefi/src/HandleFi.test.ts +++ b/packages/handlefi/src/HandleFi.test.ts @@ -1,12 +1,34 @@ import { apply } from '@rabbitholegg/questdk/filter' import { describe, expect, test } from 'vitest' +import { swap } from './HandleFi' +import { passingTestCases, failingTestCases } from './test-transactions' describe('Given the handlefi plugin', () => { describe('When handling the swap action', () => { - describe('should return a valid action filter', () => {}) + describe('should return a valid action filter', () => { + test('', () => { + expect(true).to.be.true + }) + }) - describe('should pass filter with valid transactions', () => {}) + describe('should pass filter with valid transactions', () => { + passingTestCases.forEach((testCase) => { + const { transaction, description, params } = testCase + test(description, async () => { + const filter = await swap(params) + expect(apply(transaction, filter)).to.be.true + }) + }) + }) - describe('should not pass filter with invalid transactions', () => {}) + describe('should not pass filter with invalid transactions', () => { + failingTestCases.forEach((testCase) => { + const { transaction, description, params } = testCase + test(description, async () => { + const filter = await swap(params) + expect(apply(transaction, filter)).to.be.false + }) + }) + }) }) }) diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts new file mode 100644 index 000000000..3d65d70de --- /dev/null +++ b/packages/handlefi/src/test-transactions.ts @@ -0,0 +1,107 @@ +import { + type SwapActionParams, + GreaterThanOrEqual, +} from '@rabbitholegg/questdk' +import { parseUnits } from 'viem' +import { createTestCase, type TestParams } from './utils' +import { ARBITRUM_ONE } from './constants' + +export const PARASWAP_SIMPLESWAP: TestParams = { + transaction: { + chainId: 42161, + from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', + hash: '0xfe3d97d0132b73fa9cfcb4ea4fe7eafdc70bae19a1912b14a46356420866f7e9', + input: '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000110a310000000000000000000000000000000000000000000000000000000000112d4f00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd1000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000065842857e5365097d06f420e915f1f8fb8777c3e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000000000000000108a9059cbb000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000e3ea36e8f91d5537dc20382000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000000001000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee57000000000000000000000000d5b927956057075377263aab7f8afc12f85100db00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000001080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x912CE59144191C1204E64559FE8253a0e49E6548', // ARB + tokenOut: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDC + amountIn: GreaterThanOrEqual(parseUnits('1', 18)), + amountOut: GreaterThanOrEqual(parseUnits('1.11', 6)), + recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + } +} + +export const PARASWAP_MULTISWAP: TestParams = { + transaction: { + chainId: 42161, + from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', + hash: '0x4345c0080add9f7e06db72efc82b5dafc045618d9b8369be68586401f4fc7911', + input: '0xa94e78ef0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf6034200000000000000000000000000000000000000000000000029a2241af62c0000000000000000000000000000000000000000000000000000239da6ab876c8d5300000000000000000000000000000000000000000000000023e70aa1250b1880000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd10000000000000000000000000000000000000000000000000000000000000160000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e0000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000006584240629e09fed404b4c03ad7c8d37697b223800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000320000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000658d0a25000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006000000000000000000000000d0dd5d76cf0fc06dabc48632735566dca241a35e000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x539bde0d7dbd336b79148aa742883198bbf60342', // MAGIC + tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + amountIn: GreaterThanOrEqual(parseUnits('3', 18)), + amountOut: GreaterThanOrEqual(parseUnits('2.51', 18)), + recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + } +} + +export const PARASWAP_UNI_V3: TestParams = { + transaction: { + chainId: 42161, + from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', + hash: '0xdc4f726560293b41a0ee72048e2d94970a45a046d88447444dab8bc54cb25a94', + input: '0xa6886da90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf60342000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000e592427a0aece92de3edee1f18e0157c058615640000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000a90764f1672a2ca0000000000000000000000000000000000000000000000000aa63b29581ed266010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000658404ab000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220e2986323ad904dbf827dc23846a7149700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710912ce59144191c1204e64559fe8253a0e49e65480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x539bde0d7dbd336b79148aa742883198bbf60342', // MAGIC + tokenOut: '0x912ce59144191c1204e64559fe8253a0e49e6548', // fxUSD + amountIn: GreaterThanOrEqual(parseUnits('1', 18)), + amountOut: GreaterThanOrEqual(parseUnits('0.74', 18)), + recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + } +} + +export const PARASWAP_FAIL: TestParams = { + transaction: { + chainId: 42161, + from: '0x9a1385dded2c1c00b8ac11e6597e86f3879a3403', + to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', + hash: '0x87724762847aa87653a3ee3b06ea0ea2ea2c0bf5a08012d9fc005fdc9241b7d1', + input: '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d77b108d4f6cefaa0cae9506a934e825becca46e000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000387c2a870000000000000000000000000000000000000000000000000000000038c4d48d00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003e00000000000000000000000009a1385dded2c1c00b8ac11e6597e86f3879a3403000000000000000000000000353d2d14bb674892910685520ac040f560ccbc0601000000000000000000000000000000000000000000000000000000000313880000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000006583dc2b4c450c4adba14732a0cf0aa7d765f4b90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001f721e2e82f6676fce4ea07a5958cf098d339e180000000000000000000000000000000000000000000000000000000000000124c04b8d59000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee5700000000000000000000000000000000000000000000000000000000658d11fb00000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000028d77b108d4f6cefaa0cae9506a934e825becca46eff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + } +} + +export const passingTestCases = [ + createTestCase(PARASWAP_SIMPLESWAP, 'when routed through paraswap (simpleswap)'), + createTestCase(PARASWAP_MULTISWAP, 'when routed through paraswap (multiswap)'), + createTestCase(PARASWAP_UNI_V3, 'when routed through paraswap (uniV3Swap)'), +] + +export const failingTestCases = [ + createTestCase(PARASWAP_FAIL, 'when using paraswap route not referred by handlefi') +] + +/* + transaction: { + chainId: 42161, + from: '', + to: '', + hash: '', + input: '', + amount: '', + }, + params: { + chainId: 42161, + tokenIn: '', + tokenOut: '', + amountIn: GreaterThanOrEqual(parseUnits('', 18)), + amountOut: GreaterThanOrEqual(parseUnits('', 18)), + recipient: '', + } +*/ \ No newline at end of file From 6b1249a44ac63923ef88103319cc3f786343c292 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 20 Dec 2023 22:20:39 -0800 Subject: [PATCH 08/38] feat(handlefi): create input filter for paraswap routes --- packages/handlefi/src/HandleFi.ts | 21 ++++---- packages/handlefi/src/input-filters.ts | 69 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 packages/handlefi/src/input-filters.ts diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 3c8e34722..3916f1716 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -4,24 +4,21 @@ import { compressJson, } from '@rabbitholegg/questdk' import { type Address } from 'viem' +import { ARBITRUM_ONE, SWAP_CONTRACTS } from './constants' +import { getParaSwapFilter } from './input-filters' export const swap = async ( swap: SwapActionParams, ): Promise => { - const { - chainId, - contractAddress, - tokenIn, - tokenOut, - amountIn, - amountOut, - recipient, - } = swap return compressJson({ - chainId: 0, // The chainId of the source chain - to: 0x0, // The contract address of the bridge - input: {}, // The input object is where we'll put the ABI and the parameters + chainId: ARBITRUM_ONE, + to: { + $or: SWAP_CONTRACTS.map((address) => address.toLowerCase()), + }, + input: { + $or: [getParaSwapFilter(swap)], + }, }) } diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts new file mode 100644 index 000000000..15c5015f2 --- /dev/null +++ b/packages/handlefi/src/input-filters.ts @@ -0,0 +1,69 @@ +import { type SwapActionParams } from '@rabbitholegg/questdk' +import { zeroAddress } from 'viem' +import { buildV2PathQuery } from './utils' +import { PARASWAP_ABI } from './abi' + +export function getParaSwapFilter(params: SwapActionParams) { + const { tokenIn, tokenOut, amountIn, amountOut } = params + const internalEthAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' + const tokenInUsed = tokenIn === zeroAddress ? internalEthAddress : tokenIn + const tokenOutUsed = tokenOut === zeroAddress ? internalEthAddress : tokenOut + + return { + $abi: PARASWAP_ABI, + $or: [ + { + // simpleswap, directUniV3Swap, directCurveSwap + data: { + fromToken: tokenInUsed, + fromAmount: amountIn, + toAmount: amountOut, + toToken: tokenOutUsed, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + // multiswap + data: { + fromToken: tokenInUsed, + fromAmount: amountIn, + toAmount: amountOut, + path: { + $last: { + to: tokenOutUsed, + }, + }, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + // megaswap + data: { + fromToken: tokenInUsed, + fromAmount: amountIn, + toAmount: amountOut, + path: { + $last: { + path: { + $last: { + to: tokenOutUsed, + }, + }, + }, + }, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + // directBalancerV2 + data: { + assets: buildV2PathQuery(tokenIn, tokenOut), + fromAmount: amountIn, + toAmount: amountOut, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + ], + } as const + +} From 3d618e1fa2bdb044ffd364bb3a05bed08d13e26b Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 21:27:02 -0800 Subject: [PATCH 09/38] refactor(handlefi): convert buildpathquery function to return different cases --- packages/handlefi/src/utils.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/handlefi/src/utils.ts b/packages/handlefi/src/utils.ts index a8d1d8b98..d8c55744d 100644 --- a/packages/handlefi/src/utils.ts +++ b/packages/handlefi/src/utils.ts @@ -1,5 +1,5 @@ import type { ActionParams, FilterOperator } from '@rabbitholegg/questdk' -import type { Address, Hash } from 'viem' +import { getAddress, type Address, type Hash } from 'viem' export enum Chains { ARBITRUM_ONE = 42161, @@ -51,16 +51,26 @@ export function createTestCase( } } -export const buildV2PathQuery = (tokenIn?: string, tokenOut?: string) => { +export const buildV2PathQueryWithCase = ( + addressCase: 'lower' | 'checksum', + tokenIn?: string, + tokenOut?: string, +) => { // v2 paths are formatted as [, ] const conditions: FilterOperator[] = [] if (tokenIn) { - conditions.push({ $first: tokenIn }) + conditions.push({ + $first: + addressCase === 'lower' ? tokenIn.toLowerCase() : getAddress(tokenIn), + }) } if (tokenOut) { - conditions.push({ $last: tokenOut }) + conditions.push({ + $last: + addressCase === 'lower' ? tokenOut.toLowerCase() : getAddress(tokenOut), + }) } return { From ef2676340e721ddd58f088194c69f5b7fde8c2ff Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 21:28:30 -0800 Subject: [PATCH 10/38] feat(handlefi): add V2 router filter --- packages/handlefi/src/HandleFi.ts | 8 ++-- packages/handlefi/src/input-filters.ts | 20 +++++++-- packages/handlefi/src/test-transactions.ts | 47 +++++++++++++++++++++- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 3916f1716..28badc44b 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -3,21 +3,23 @@ import { type SwapActionParams, compressJson, } from '@rabbitholegg/questdk' -import { type Address } from 'viem' +import { zeroAddress, type Address } from 'viem' import { ARBITRUM_ONE, SWAP_CONTRACTS } from './constants' -import { getParaSwapFilter } from './input-filters' +import { getParaSwapFilter, getV2RouterFilter } from './input-filters' export const swap = async ( swap: SwapActionParams, ): Promise => { + console.log(swap.amountIn) return compressJson({ chainId: ARBITRUM_ONE, + value: swap.tokenIn === zeroAddress ? swap.amountIn : undefined, to: { $or: SWAP_CONTRACTS.map((address) => address.toLowerCase()), }, input: { - $or: [getParaSwapFilter(swap)], + $or: [getParaSwapFilter(swap), getV2RouterFilter(swap)], }, }) } diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 15c5015f2..4cabdc79c 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,7 +1,8 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' import { zeroAddress } from 'viem' -import { buildV2PathQuery } from './utils' -import { PARASWAP_ABI } from './abi' +import { buildV2PathQueryWithCase } from './utils' +import { PARASWAP_ABI, V2_ROUTER_ABI } from './abi' +import { WETH } from './constants' export function getParaSwapFilter(params: SwapActionParams) { const { tokenIn, tokenOut, amountIn, amountOut } = params @@ -57,7 +58,7 @@ export function getParaSwapFilter(params: SwapActionParams) { { // directBalancerV2 data: { - assets: buildV2PathQuery(tokenIn, tokenOut), + assets: buildV2PathQueryWithCase('lower', tokenIn, tokenOut), fromAmount: amountIn, toAmount: amountOut, partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', @@ -65,5 +66,18 @@ export function getParaSwapFilter(params: SwapActionParams) { }, ], } as const +} +export function getV2RouterFilter(params: SwapActionParams) { + const { tokenIn, tokenOut, amountIn, amountOut, recipient } = params + const ethIn = tokenIn === zeroAddress + const tokenInUsed = tokenIn === zeroAddress ? WETH : tokenIn + const tokenOutUsed = tokenOut === zeroAddress ? WETH : tokenOut + return { + $abi: V2_ROUTER_ABI, + _path: buildV2PathQueryWithCase('checksum', tokenInUsed, tokenOutUsed), + _amountIn: ethIn ? undefined : amountIn, + _minOut: amountOut, + _receiver: recipient, + } as const } diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 3d65d70de..5f7d6ec8e 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -2,10 +2,12 @@ import { type SwapActionParams, GreaterThanOrEqual, } from '@rabbitholegg/questdk' -import { parseUnits } from 'viem' +import { parseEther, parseUnits, zeroAddress } from 'viem' import { createTestCase, type TestParams } from './utils' import { ARBITRUM_ONE } from './constants' + +// Paraswap Test Txs export const PARASWAP_SIMPLESWAP: TestParams = { transaction: { chainId: 42161, @@ -56,7 +58,7 @@ export const PARASWAP_UNI_V3: TestParams = { params: { chainId: ARBITRUM_ONE, tokenIn: '0x539bde0d7dbd336b79148aa742883198bbf60342', // MAGIC - tokenOut: '0x912ce59144191c1204e64559fe8253a0e49e6548', // fxUSD + tokenOut: '0x912ce59144191c1204e64559fe8253a0e49e6548', // ARB amountIn: GreaterThanOrEqual(parseUnits('1', 18)), amountOut: GreaterThanOrEqual(parseUnits('0.74', 18)), recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', @@ -77,10 +79,51 @@ export const PARASWAP_FAIL: TestParams = { } } +// V2 router +export const V2_ROUTER_ETH_TOKENS: TestParams = { + transaction: { + chainId: 42161, + from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + to: '0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89', + hash: '0x0e01ef19061c3e16bfa91f48c9120ae408ac8014015f714a80e73b9ae7a61429', + input: '0x481e17e300000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000001ec9ef3426a30660000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000033fe26fca00000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584848d000000000000000000000000000000000000000000000000000000006584848d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584846f000000000000000000000000000000000000000000000000000000006584846f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000082423b14e6f1a36dc93726f5b2878680533e8f946a794d588287ecb8b923ff8ec35f25548c1c04a9320609350c0f49a3529cf3593d9189e5c3c9817f9b98cc58781c2afb0ef760759ceb8c931dbb1f5530ceea061db5c053da826fd7470386eaf85b35dcbee6a27cca94f9d5891317bd625a92221973fd79f06346b21874d6b3a5391b000000000000000000000000000000000000000000000000000000000000', + value: '1000000000000000', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: zeroAddress, // ETH + tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + amountIn: GreaterThanOrEqual(parseEther('0.001')), + amountOut: GreaterThanOrEqual(parseUnits('2.2185', 18)), + recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + } +} + +export const V2_ROUTER_TOKENS_ETH: TestParams = { + transaction: { + chainId: 42161, + from: '0x4806032267387c9e6aab509b497a765d0aca7f61', + to: '0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89', + hash: '0x506705b15f164d17d8a14c4a7504643c4d3790ed61d25de39aef759502ebbbe5', + input: '0xcccc6e0500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000064d7deb5b8f2ecaa000000000000000000000000000000000000000000000000000cb289cf449be90000000000000000000000004806032267387c9e6aab509b497a765d0aca7f6100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000068e296000000000000000000000000000000000000000000000000000000033b29150ff000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496f700000000000000000000000000000000000000000000000000000000658496f7000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000000827b0b81d2992c30d41e44cb7d3c48cbc682e52f739acc06217340cd7c6dd7435f0298b07426b238ed56bbfe6515b3b4a74e88c49e82411af83c71f8602c8441ad1b7d48ebbc834a4caec4a123f65296ed2899d3714c541ec4b7948692001f31b83804576d033737b13423174d19a75e262095d956ad0c4e32a55f52110481dace381c000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x116172b2482c5dc3e6f445c16ac13367ac3fcd35', // fxEUR + tokenOut: zeroAddress, // ETH + amountIn: GreaterThanOrEqual(parseUnits('7.26', 18)), + amountOut: GreaterThanOrEqual(parseEther('0.0035')), + recipient: '0x4806032267387c9e6aab509b497a765d0aca7f61', + } +} + export const passingTestCases = [ createTestCase(PARASWAP_SIMPLESWAP, 'when routed through paraswap (simpleswap)'), createTestCase(PARASWAP_MULTISWAP, 'when routed through paraswap (multiswap)'), createTestCase(PARASWAP_UNI_V3, 'when routed through paraswap (uniV3Swap)'), + createTestCase(V2_ROUTER_ETH_TOKENS, 'when routed through V2 router (ETH To Tokens)'), + createTestCase(V2_ROUTER_TOKENS_ETH, 'when routed through V2 router (Tokens To ETH)'), ] export const failingTestCases = [ From 99011fe3bd155add06bb9320ad6f9120b2771aa9 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 22:28:55 -0800 Subject: [PATCH 11/38] feat(handlefi): add methods for HPSM2 contract --- packages/handlefi/src/HandleFi.ts | 13 ++++++-- packages/handlefi/src/input-filters.ts | 30 ++++++++++++++++-- packages/handlefi/src/test-transactions.ts | 37 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 28badc44b..48626602e 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -5,12 +5,15 @@ import { } from '@rabbitholegg/questdk' import { zeroAddress, type Address } from 'viem' import { ARBITRUM_ONE, SWAP_CONTRACTS } from './constants' -import { getParaSwapFilter, getV2RouterFilter } from './input-filters' +import { + getParaSwapFilter, + getV2RouterFilter, + getHPSM2Filter, +} from './input-filters' export const swap = async ( swap: SwapActionParams, ): Promise => { - console.log(swap.amountIn) return compressJson({ chainId: ARBITRUM_ONE, @@ -19,7 +22,11 @@ export const swap = async ( $or: SWAP_CONTRACTS.map((address) => address.toLowerCase()), }, input: { - $or: [getParaSwapFilter(swap), getV2RouterFilter(swap)], + $or: [ + getParaSwapFilter(swap), + getV2RouterFilter(swap), + getHPSM2Filter(swap), + ], }, }) } diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 4cabdc79c..8e336c0fe 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,7 +1,7 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' -import { zeroAddress } from 'viem' +import { getAddress, zeroAddress } from 'viem' import { buildV2PathQueryWithCase } from './utils' -import { PARASWAP_ABI, V2_ROUTER_ABI } from './abi' +import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI } from './abi' import { WETH } from './constants' export function getParaSwapFilter(params: SwapActionParams) { @@ -81,3 +81,29 @@ export function getV2RouterFilter(params: SwapActionParams) { _receiver: recipient, } as const } + +export function getHPSM2Filter(params: SwapActionParams) { + // Not using amount here since it is not possible to tell if the amount is amountIn or amountOut + const { tokenIn, tokenOut } = params + const tokenInAddress = tokenIn ? getAddress(tokenIn) : undefined + const tokenOutAddress = tokenOut ? getAddress(tokenOut) : undefined + + let inputs = {} + + if (tokenIn && tokenOut) { + inputs = { + fxTokenAddress: { $or: [tokenInAddress, tokenOutAddress] }, + peggedTokenAddress: { $or: [tokenInAddress, tokenOutAddress] }, + } + } else if (tokenIn || tokenOut) { + const address = tokenInAddress || tokenOutAddress + inputs = { + $or: [{ fxTokenAddress: address }, { peggedTokenAddress: address }], + } + } + + return { + $abi: HPSM2_ABI, + ...inputs, + } as const +} diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 5f7d6ec8e..b61d54469 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -118,12 +118,49 @@ export const V2_ROUTER_TOKENS_ETH: TestParams = { } } +// HPSM2 +export const HPSM2_WITHDRAW: TestParams = { + transaction: { + chainId: 42161, + from: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', + to: '0x0f330a53874cea3e5a0dee5d291c49275fdc3260', + hash: '0x0a720d80933a2110a07be10186b4ab55db12bdda4a100b282f455bf07eb580a0', + input: '0xd9caed120000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000692dcf0f3ed5fc5825', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', + } +} + +export const HPSM2_DEPOSIT: TestParams = { + transaction: { + chainId: 42161, + from: '0x0ffad609d35c4bef104ee245a9c4c891d463aa2a', + to: '0x0f330a53874cea3e5a0dee5d291c49275fdc3260', + hash: '0x8b880dd0805ed4767a9a770149bbe9402d44ae334374f2afef8bb5fd257585a8', + input: '0x8340f5490000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000000000003b9aca00', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', + } +} + export const passingTestCases = [ createTestCase(PARASWAP_SIMPLESWAP, 'when routed through paraswap (simpleswap)'), createTestCase(PARASWAP_MULTISWAP, 'when routed through paraswap (multiswap)'), createTestCase(PARASWAP_UNI_V3, 'when routed through paraswap (uniV3Swap)'), createTestCase(V2_ROUTER_ETH_TOKENS, 'when routed through V2 router (ETH To Tokens)'), createTestCase(V2_ROUTER_TOKENS_ETH, 'when routed through V2 router (Tokens To ETH)'), + createTestCase(HPSM2_WITHDRAW, 'when routed through HSPM2 contract (withdraw)'), + createTestCase(HPSM2_DEPOSIT, 'when routed through HSPM2 contract (deposit)'), ] export const failingTestCases = [ From 8cb286fbceee62d3ae48812eeaa1c7cbcceb9c8a Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 23:16:37 -0800 Subject: [PATCH 12/38] feat(handlefi): add support for HLP curve V2 routing --- packages/handlefi/src/HandleFi.ts | 3 +- packages/handlefi/src/abi.ts | 53 ++++++++ packages/handlefi/src/input-filters.ts | 30 +++- packages/handlefi/src/test-transactions.ts | 151 ++++++++++++++++----- 4 files changed, 204 insertions(+), 33 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 48626602e..9a1c0e06c 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -9,12 +9,12 @@ import { getParaSwapFilter, getV2RouterFilter, getHPSM2Filter, + getHlpCurveV2Filter, } from './input-filters' export const swap = async ( swap: SwapActionParams, ): Promise => { - console.log(swap.amountIn) return compressJson({ chainId: ARBITRUM_ONE, value: swap.tokenIn === zeroAddress ? swap.amountIn : undefined, @@ -26,6 +26,7 @@ export const swap = async ( getParaSwapFilter(swap), getV2RouterFilter(swap), getHPSM2Filter(swap), + getHlpCurveV2Filter(swap), ], }, }) diff --git a/packages/handlefi/src/abi.ts b/packages/handlefi/src/abi.ts index 9c054c0a9..516871387 100644 --- a/packages/handlefi/src/abi.ts +++ b/packages/handlefi/src/abi.ts @@ -629,6 +629,59 @@ export const HPSM2_ABI = [ ] export const HLP_CURVE_V2_ABI = [ + { + inputs: [ + { internalType: 'address', name: 'hlpCurveToken', type: 'address' }, + { internalType: 'address', name: 'tokenOut', type: 'address' }, + { internalType: 'address', name: 'receiver', type: 'address' }, + { internalType: 'uint256', name: 'minOut', type: 'uint256' }, + { internalType: 'address', name: 'metapoolFactory', type: 'address' }, + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapEthToCurveToken', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'hlpToken', type: 'address' }, + { internalType: 'address', name: 'hlpCurveToken', type: 'address' }, + { internalType: 'address', name: 'tokenOut', type: 'address' }, + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'address', name: 'receiver', type: 'address' }, + { internalType: 'uint256', name: 'minOut', type: 'uint256' }, + { internalType: 'address', name: 'metapoolFactory', type: 'address' }, + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapHlpTokenToCurveToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'peggedToken', type: 'address' }, + { internalType: 'address', name: 'fxToken', type: 'address' }, + { internalType: 'address', name: 'hlpToken', type: 'address' }, + { internalType: 'address', name: 'tokenOut', type: 'address' }, + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'address', name: 'receiver', type: 'address' }, + { internalType: 'uint256', name: 'minOut', type: 'uint256' }, + { internalType: 'address', name: 'metapoolFactory', type: 'address' }, + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapPeggedTokenToCurveToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] + +export const CURVE_FACTORY_ABI = [ { stateMutability: 'nonpayable', type: 'function', diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 8e336c0fe..fd61c6b40 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,7 +1,7 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' import { getAddress, zeroAddress } from 'viem' import { buildV2PathQueryWithCase } from './utils' -import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI } from './abi' +import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI, HLP_CURVE_V2_ABI } from './abi' import { WETH } from './constants' export function getParaSwapFilter(params: SwapActionParams) { @@ -107,3 +107,31 @@ export function getHPSM2Filter(params: SwapActionParams) { ...inputs, } as const } + +export function getHlpCurveV2Filter(params: SwapActionParams) { + const { tokenIn, tokenOut, amountIn, amountOut, recipient } = params + const minOut = tokenOut ? amountOut : undefined + if (tokenIn === zeroAddress) { + return { + $abi: HLP_CURVE_V2_ABI, + tokenOut, + minOut, + receiver: recipient, + } + } + return { + $abi: HLP_CURVE_V2_ABI, + tokenOut, + amountIn: tokenIn ? amountIn : undefined, + minOut, + receiver: recipient, + $or: [ + { + peggedToken: tokenIn, + }, + { + hlpToken: tokenIn, + }, + ], + } +} diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index b61d54469..50f89220c 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -6,7 +6,6 @@ import { parseEther, parseUnits, zeroAddress } from 'viem' import { createTestCase, type TestParams } from './utils' import { ARBITRUM_ONE } from './constants' - // Paraswap Test Txs export const PARASWAP_SIMPLESWAP: TestParams = { transaction: { @@ -14,7 +13,8 @@ export const PARASWAP_SIMPLESWAP: TestParams = { from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', hash: '0xfe3d97d0132b73fa9cfcb4ea4fe7eafdc70bae19a1912b14a46356420866f7e9', - input: '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000110a310000000000000000000000000000000000000000000000000000000000112d4f00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd1000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000065842857e5365097d06f420e915f1f8fb8777c3e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000000000000000108a9059cbb000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000e3ea36e8f91d5537dc20382000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000000001000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee57000000000000000000000000d5b927956057075377263aab7f8afc12f85100db00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000001080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + input: + '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000110a310000000000000000000000000000000000000000000000000000000000112d4f00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd1000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000065842857e5365097d06f420e915f1f8fb8777c3e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000000000000000108a9059cbb000000000000000000000000eff23b4be1091b53205e35f3afcd9c7182bf30620000000000000000000000000000000000000000000000000e3ea36e8f91d5537dc20382000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000e3ea36e8f91d5530000000000000000000000000000000000000000000000000000000000000001000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee57000000000000000000000000d5b927956057075377263aab7f8afc12f85100db00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000001080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', value: '0', }, params: { @@ -24,7 +24,7 @@ export const PARASWAP_SIMPLESWAP: TestParams = { amountIn: GreaterThanOrEqual(parseUnits('1', 18)), amountOut: GreaterThanOrEqual(parseUnits('1.11', 6)), recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', - } + }, } export const PARASWAP_MULTISWAP: TestParams = { @@ -33,7 +33,8 @@ export const PARASWAP_MULTISWAP: TestParams = { from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', hash: '0x4345c0080add9f7e06db72efc82b5dafc045618d9b8369be68586401f4fc7911', - input: '0xa94e78ef0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf6034200000000000000000000000000000000000000000000000029a2241af62c0000000000000000000000000000000000000000000000000000239da6ab876c8d5300000000000000000000000000000000000000000000000023e70aa1250b1880000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd10000000000000000000000000000000000000000000000000000000000000160000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e0000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000006584240629e09fed404b4c03ad7c8d37697b223800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000320000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000658d0a25000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006000000000000000000000000d0dd5d76cf0fc06dabc48632735566dca241a35e000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000', + input: + '0xa94e78ef0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf6034200000000000000000000000000000000000000000000000029a2241af62c0000000000000000000000000000000000000000000000000000239da6ab876c8d5300000000000000000000000000000000000000000000000023e70aa1250b1880000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd10000000000000000000000000000000000000000000000000000000000000160000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a010000000000000000000000000000000000000000000000000000000000401e0000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000006584240629e09fed404b4c03ad7c8d37697b223800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000320000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000658d0a25000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000369a2fdb910d432f0a07381a5e3d27572c876713000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006000000000000000000000000d0dd5d76cf0fc06dabc48632735566dca241a35e000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000', value: '0', }, params: { @@ -43,7 +44,7 @@ export const PARASWAP_MULTISWAP: TestParams = { amountIn: GreaterThanOrEqual(parseUnits('3', 18)), amountOut: GreaterThanOrEqual(parseUnits('2.51', 18)), recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', - } + }, } export const PARASWAP_UNI_V3: TestParams = { @@ -52,7 +53,8 @@ export const PARASWAP_UNI_V3: TestParams = { from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', hash: '0xdc4f726560293b41a0ee72048e2d94970a45a046d88447444dab8bc54cb25a94', - input: '0xa6886da90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf60342000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000e592427a0aece92de3edee1f18e0157c058615640000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000a90764f1672a2ca0000000000000000000000000000000000000000000000000aa63b29581ed266010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000658404ab000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220e2986323ad904dbf827dc23846a7149700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710912ce59144191c1204e64559fe8253a0e49e65480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + input: + '0xa6886da90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000539bde0d7dbd336b79148aa742883198bbf60342000000000000000000000000912ce59144191c1204e64559fe8253a0e49e6548000000000000000000000000e592427a0aece92de3edee1f18e0157c058615640000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000a90764f1672a2ca0000000000000000000000000000000000000000000000000aa63b29581ed266010000000000000000000000000000000000000000000000000000000000401e00000000000000000000000000000000000000000000000000000000658404ab000000000000000000000000fa2c1be677be4bec8851d1577b343f7060b51e3a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220e2986323ad904dbf827dc23846a7149700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b539bde0d7dbd336b79148aa742883198bbf60342002710912ce59144191c1204e64559fe8253a0e49e65480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', value: '0', }, params: { @@ -62,8 +64,8 @@ export const PARASWAP_UNI_V3: TestParams = { amountIn: GreaterThanOrEqual(parseUnits('1', 18)), amountOut: GreaterThanOrEqual(parseUnits('0.74', 18)), recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', - } -} + }, +} export const PARASWAP_FAIL: TestParams = { transaction: { @@ -71,22 +73,24 @@ export const PARASWAP_FAIL: TestParams = { from: '0x9a1385dded2c1c00b8ac11e6597e86f3879a3403', to: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', hash: '0x87724762847aa87653a3ee3b06ea0ea2ea2c0bf5a08012d9fc005fdc9241b7d1', - input: '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d77b108d4f6cefaa0cae9506a934e825becca46e000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000387c2a870000000000000000000000000000000000000000000000000000000038c4d48d00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003e00000000000000000000000009a1385dded2c1c00b8ac11e6597e86f3879a3403000000000000000000000000353d2d14bb674892910685520ac040f560ccbc0601000000000000000000000000000000000000000000000000000000000313880000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000006583dc2b4c450c4adba14732a0cf0aa7d765f4b90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001f721e2e82f6676fce4ea07a5958cf098d339e180000000000000000000000000000000000000000000000000000000000000124c04b8d59000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee5700000000000000000000000000000000000000000000000000000000658d11fb00000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000028d77b108d4f6cefaa0cae9506a934e825becca46eff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + input: + '0x54e3f31b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d77b108d4f6cefaa0cae9506a934e825becca46e000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000387c2a870000000000000000000000000000000000000000000000000000000038c4d48d00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003e00000000000000000000000009a1385dded2c1c00b8ac11e6597e86f3879a3403000000000000000000000000353d2d14bb674892910685520ac040f560ccbc0601000000000000000000000000000000000000000000000000000000000313880000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000006583dc2b4c450c4adba14732a0cf0aa7d765f4b90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001f721e2e82f6676fce4ea07a5958cf098d339e180000000000000000000000000000000000000000000000000000000000000124c04b8d59000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000def171fe48cf0115b1d80b88dc8eab59176fee5700000000000000000000000000000000000000000000000000000000658d11fb00000000000000000000000000000000000000000000019e1ae5ee6e872c7e3800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000028d77b108d4f6cefaa0cae9506a934e825becca46eff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', value: '0', }, params: { chainId: ARBITRUM_ONE, - } + }, } -// V2 router +// V2 router export const V2_ROUTER_ETH_TOKENS: TestParams = { transaction: { chainId: 42161, from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', to: '0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89', hash: '0x0e01ef19061c3e16bfa91f48c9120ae408ac8014015f714a80e73b9ae7a61429', - input: '0x481e17e300000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000001ec9ef3426a30660000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000033fe26fca00000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584848d000000000000000000000000000000000000000000000000000000006584848d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584846f000000000000000000000000000000000000000000000000000000006584846f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000082423b14e6f1a36dc93726f5b2878680533e8f946a794d588287ecb8b923ff8ec35f25548c1c04a9320609350c0f49a3529cf3593d9189e5c3c9817f9b98cc58781c2afb0ef760759ceb8c931dbb1f5530ceea061db5c053da826fd7470386eaf85b35dcbee6a27cca94f9d5891317bd625a92221973fd79f06346b21874d6b3a5391b000000000000000000000000000000000000000000000000000000000000', + input: + '0x481e17e300000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000001ec9ef3426a30660000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000033fe26fca00000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584848d000000000000000000000000000000000000000000000000000000006584848d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006584846f000000000000000000000000000000000000000000000000000000006584846f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000082423b14e6f1a36dc93726f5b2878680533e8f946a794d588287ecb8b923ff8ec35f25548c1c04a9320609350c0f49a3529cf3593d9189e5c3c9817f9b98cc58781c2afb0ef760759ceb8c931dbb1f5530ceea061db5c053da826fd7470386eaf85b35dcbee6a27cca94f9d5891317bd625a92221973fd79f06346b21874d6b3a5391b000000000000000000000000000000000000000000000000000000000000', value: '1000000000000000', }, params: { @@ -96,8 +100,8 @@ export const V2_ROUTER_ETH_TOKENS: TestParams = { amountIn: GreaterThanOrEqual(parseEther('0.001')), amountOut: GreaterThanOrEqual(parseUnits('2.2185', 18)), recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', - } -} + }, +} export const V2_ROUTER_TOKENS_ETH: TestParams = { transaction: { @@ -105,7 +109,8 @@ export const V2_ROUTER_TOKENS_ETH: TestParams = { from: '0x4806032267387c9e6aab509b497a765d0aca7f61', to: '0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89', hash: '0x506705b15f164d17d8a14c4a7504643c4d3790ed61d25de39aef759502ebbbe5', - input: '0xcccc6e0500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000064d7deb5b8f2ecaa000000000000000000000000000000000000000000000000000cb289cf449be90000000000000000000000004806032267387c9e6aab509b497a765d0aca7f6100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000068e296000000000000000000000000000000000000000000000000000000033b29150ff000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496f700000000000000000000000000000000000000000000000000000000658496f7000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000000827b0b81d2992c30d41e44cb7d3c48cbc682e52f739acc06217340cd7c6dd7435f0298b07426b238ed56bbfe6515b3b4a74e88c49e82411af83c71f8602c8441ad1b7d48ebbc834a4caec4a123f65296ed2899d3714c541ec4b7948692001f31b83804576d033737b13423174d19a75e262095d956ad0c4e32a55f52110481dace381c000000000000000000000000000000000000000000000000000000000000', + input: + '0xcccc6e0500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000064d7deb5b8f2ecaa000000000000000000000000000000000000000000000000000cb289cf449be90000000000000000000000004806032267387c9e6aab509b497a765d0aca7f6100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000116172b2482c5dc3e6f445c16ac13367ac3fcd3500000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000068e296000000000000000000000000000000000000000000000000000000033b29150ff000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496f700000000000000000000000000000000000000000000000000000000658496f7000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000658496d900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000000827b0b81d2992c30d41e44cb7d3c48cbc682e52f739acc06217340cd7c6dd7435f0298b07426b238ed56bbfe6515b3b4a74e88c49e82411af83c71f8602c8441ad1b7d48ebbc834a4caec4a123f65296ed2899d3714c541ec4b7948692001f31b83804576d033737b13423174d19a75e262095d956ad0c4e32a55f52110481dace381c000000000000000000000000000000000000000000000000000000000000', value: '0', }, params: { @@ -115,17 +120,18 @@ export const V2_ROUTER_TOKENS_ETH: TestParams = { amountIn: GreaterThanOrEqual(parseUnits('7.26', 18)), amountOut: GreaterThanOrEqual(parseEther('0.0035')), recipient: '0x4806032267387c9e6aab509b497a765d0aca7f61', - } -} + }, +} -// HPSM2 +// HPSM2 export const HPSM2_WITHDRAW: TestParams = { transaction: { chainId: 42161, from: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', to: '0x0f330a53874cea3e5a0dee5d291c49275fdc3260', hash: '0x0a720d80933a2110a07be10186b4ab55db12bdda4a100b282f455bf07eb580a0', - input: '0xd9caed120000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000692dcf0f3ed5fc5825', + input: + '0xd9caed120000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000692dcf0f3ed5fc5825', value: '0', }, params: { @@ -133,8 +139,8 @@ export const HPSM2_WITHDRAW: TestParams = { tokenIn: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', - } -} + }, +} export const HPSM2_DEPOSIT: TestParams = { transaction: { @@ -142,7 +148,8 @@ export const HPSM2_DEPOSIT: TestParams = { from: '0x0ffad609d35c4bef104ee245a9c4c891d463aa2a', to: '0x0f330a53874cea3e5a0dee5d291c49275fdc3260', hash: '0x8b880dd0805ed4767a9a770149bbe9402d44ae334374f2afef8bb5fd257585a8', - input: '0x8340f5490000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000000000003b9aca00', + input: + '0x8340f5490000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000000000003b9aca00', value: '0', }, params: { @@ -150,21 +157,103 @@ export const HPSM2_DEPOSIT: TestParams = { tokenIn: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', - } -} + }, +} + +// HlpCurveV2 +export const HLP_CURVE_V2_ETH_TO_CURVE: TestParams = { + transaction: { + chainId: 42161, + from: '0x29d7e0c5839715a2fe6670a248f471427104b266', + to: '0x559844b1df66e247f83ba58bc39fa488a1af1093', + hash: '0xd3ca60df5b415c5e4382b0fabc05197b1ccf31aa24f778bb81264f0cbfc96790', + input: + '0xfb6174e20000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000029d7e0c5839715a2fe6670a248f471427104b26600000000000000000000000000000000000000000000000000000000014b9790000000000000000000000000b17b674d9c5cb2e441f8e196a2f048a81355d031000000000000000000000000ab174ffa530c888649c44c4d21c849bbaabc723f00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000338cb982e00000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000656d4bc200000000000000000000000000000000000000000000000000000000656d4bc2000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000656d4ba400000000000000000000000000000000000000000000000000000000656d4ba4000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000008273932a003b1c7c539140675f2cca9827f1262c2e8b1de35846c643d1d4fd16b61fe38bfa71bf9247236095e397ccc048bbd58742dbbb8938900838c2c8625a511b6593f88a28d529a0c8da7054834fa595c083229e3575d10053c6127e3b29b690483a539636906c62f263a91d3ff9860a314eb478b27c3268933a40aff2680ef81b000000000000000000000000000000000000000000000000000000000000', + value: '10000000000000000', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: zeroAddress, // ETH + tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + amountIn: GreaterThanOrEqual(parseEther('0.01')), + amountOut: GreaterThanOrEqual(parseUnits('20', 6)), + recipient: '0x29d7e0c5839715a2fe6670a248f471427104b266', + }, +} + +export const HLP_CURVE_V2_PEGGED_TO_CURVE: TestParams = { + transaction: { + chainId: 42161, + from: '0x29d7e0c5839715a2fe6670a248f471427104b266', + to: '0x559844b1df66e247f83ba58bc39fa488a1af1093', + hash: '0x3fa25c7d7a069511570978ab80a33efd07d5f5436b593650cb547709e42ab483', + input: + '0x6b60bba8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000004c4b4000000000000000000000000029d7e0c5839715a2fe6670a248f471427104b26600000000000000000000000000000000000000000000000000000000004b06f5000000000000000000000000b17b674d9c5cb2e441f8e196a2f048a81355d031000000000000000000000000ab174ffa530c888649c44c4d21c849bbaabc723f000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000006567b9010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000006567b8e300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000004133eb56c191a220daa863c652d0ccec844c7211e858682671eb448209d3eabf9d334f75f7faf09134d9802b9ebc30fec937e885a215597dd12e0cec50733cde461b00000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0xaf88d065e77c8cc2239327c5edb3a432268e5831', // USDC + tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + amountIn: GreaterThanOrEqual(parseUnits('5', 6)), + amountOut: GreaterThanOrEqual(parseUnits('4.91', 6)), + recipient: '0x29d7e0c5839715a2fe6670a248f471427104b266', + }, +} + +export const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { + transaction: { + chainId: 42161, + from: '0x49908e05de9e1d559499b08042d1123a1daae6b4', + to: '0x559844b1df66e247f83ba58bc39fa488a1af1093', + hash: '0x819ec6afd60b26412e830feb80b5abe1dab1229fc6ef6a42224e59fb85385d51', + input: + '0xaa2a4e99000000000000000000000000398b09b68aec6c58e28ade6147dac2ecc67897370000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000b7e85e4a813dad6900000000000000000000000049908e05de9e1d559499b08042d1123a1daae6b4000000000000000000000000000000000000000000000000000000000091beb1000000000000000000000000b17b674d9c5cb2e441f8e196a2f048a81355d031000000000000000000000000ab174ffa530c888649c44c4d21c849bbaabc723f00000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000398b09b68aec6c58e28ade6147dac2ecc67897370000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000462c3270000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006576db75000000000000000000000000000000000000000000000000000000006576db750000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006576db57000000000000000000000000000000000000000000000000000000006576db57000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000008262a5a161621679746f538a2b7e13363697e5e2726eb9a46b7947e92a4b92d532779302cae8526271f6ea42384bc4aa34982060913b3fd20d9fd3d88dbadb84c91b898ee47331d840ba6d8db65df6ff0491c78b4e75b6a5a10fcdfff3a1249786fd2ad393afaf66cd151dd5e452592e72bab63a6bfd1ab4c0f2a0eb29da94db6b321c000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x3q98b09b68aec6c58e28ade6147dac2ecc6789737', // fxCAD + tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + amountIn: GreaterThanOrEqual(parseUnits('13.25', 18)), + amountOut: GreaterThanOrEqual(parseUnits('9.5', 6)), + recipient: '0x49908e05de9e1d559499b08042d1123a1daae6b4', + }, +} export const passingTestCases = [ - createTestCase(PARASWAP_SIMPLESWAP, 'when routed through paraswap (simpleswap)'), - createTestCase(PARASWAP_MULTISWAP, 'when routed through paraswap (multiswap)'), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap)', + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap)', + ), createTestCase(PARASWAP_UNI_V3, 'when routed through paraswap (uniV3Swap)'), - createTestCase(V2_ROUTER_ETH_TOKENS, 'when routed through V2 router (ETH To Tokens)'), - createTestCase(V2_ROUTER_TOKENS_ETH, 'when routed through V2 router (Tokens To ETH)'), - createTestCase(HPSM2_WITHDRAW, 'when routed through HSPM2 contract (withdraw)'), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens)', + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH)', + ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw)', + ), createTestCase(HPSM2_DEPOSIT, 'when routed through HSPM2 contract (deposit)'), + createTestCase(HLP_CURVE_V2_ETH_TO_CURVE, 'when routed through HLPcurveV2 contract (ETH to tokens)'), + createTestCase(HLP_CURVE_V2_PEGGED_TO_CURVE, 'when routed through HLPcurveV2 contract (Pegged to Curve)'), + createTestCase(HLP_CURVE_V2_TOKEN_TO_CURVE, 'when routed through HLPcurveV2 contract (Token to Curve)'), ] export const failingTestCases = [ - createTestCase(PARASWAP_FAIL, 'when using paraswap route not referred by handlefi') + createTestCase( + PARASWAP_FAIL, + 'when using paraswap route not referred by handlefi', + ), ] /* @@ -184,4 +273,4 @@ export const failingTestCases = [ amountOut: GreaterThanOrEqual(parseUnits('', 18)), recipient: '', } -*/ \ No newline at end of file +*/ From c479c9b78210582f5517694e562aac099b9df592 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 23:44:46 -0800 Subject: [PATCH 13/38] feat(handlefi): add support for swaps routed through HlpBalancer contract --- packages/handlefi/src/HandleFi.ts | 2 + packages/handlefi/src/abi.ts | 32 ++++++++++++++++ packages/handlefi/src/input-filters.ts | 16 +++++++- packages/handlefi/src/test-transactions.ts | 44 +++++++++++++++++++++- 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 9a1c0e06c..163b8c012 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -10,6 +10,7 @@ import { getV2RouterFilter, getHPSM2Filter, getHlpCurveV2Filter, + getHlpBalancerFilter, } from './input-filters' export const swap = async ( @@ -27,6 +28,7 @@ export const swap = async ( getV2RouterFilter(swap), getHPSM2Filter(swap), getHlpCurveV2Filter(swap), + getHlpBalancerFilter(swap), ], }, }) diff --git a/packages/handlefi/src/abi.ts b/packages/handlefi/src/abi.ts index 516871387..2b3b2c695 100644 --- a/packages/handlefi/src/abi.ts +++ b/packages/handlefi/src/abi.ts @@ -681,6 +681,38 @@ export const HLP_CURVE_V2_ABI = [ }, ] +export const HLP_BALANCER_ABI = [ + { + inputs: [ + { internalType: 'address', name: 'tokenIn', type: 'address' }, + { internalType: 'address', name: 'hlpBalancerToken', type: 'address' }, + { internalType: 'bytes32', name: 'poolId', type: 'bytes32' }, + { internalType: 'uint256', name: 'amountIn', type: 'uint256' }, + { internalType: 'uint256', name: 'minOut', type: 'uint256' }, + { internalType: 'address', name: 'receiver', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapBalancerToEth', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'hlpBalancerToken', type: 'address' }, + { internalType: 'address', name: 'tokenOut', type: 'address' }, + { internalType: 'bytes32', name: 'poolId', type: 'bytes32' }, + { internalType: 'uint256', name: 'minOut', type: 'uint256' }, + { internalType: 'address', name: 'receiver', type: 'address' }, + { internalType: 'bytes', name: 'signedQuoteData', type: 'bytes' }, + ], + name: 'swapEthToBalancer', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, +] + export const CURVE_FACTORY_ABI = [ { stateMutability: 'nonpayable', diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index fd61c6b40..e145e1e08 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,7 +1,7 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' import { getAddress, zeroAddress } from 'viem' import { buildV2PathQueryWithCase } from './utils' -import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI, HLP_CURVE_V2_ABI } from './abi' +import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI, HLP_CURVE_V2_ABI, HLP_BALANCER_ABI } from './abi' import { WETH } from './constants' export function getParaSwapFilter(params: SwapActionParams) { @@ -135,3 +135,17 @@ export function getHlpCurveV2Filter(params: SwapActionParams) { ], } } + +export function getHlpBalancerFilter(params: SwapActionParams) { + const { tokenIn, tokenOut, amountIn, amountOut, recipient } = params + const minOut = tokenOut ? amountOut : undefined + const ethUsedIn = tokenIn === zeroAddress + const tokenInput = ethUsedIn ? { tokenOut } : { tokenIn } + return { + $abi: HLP_BALANCER_ABI, + minOut, + amountIn: tokenIn && !ethUsedIn ? amountIn : undefined, + receiver: recipient, + ...tokenInput, + } +} diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 50f89220c..99d161425 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -213,7 +213,7 @@ export const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { }, params: { chainId: ARBITRUM_ONE, - tokenIn: '0x3q98b09b68aec6c58e28ade6147dac2ecc6789737', // fxCAD + tokenIn: '0x398b09b68aec6c58e28ade6147dac2ecc6789737', // fxCAD tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e amountIn: GreaterThanOrEqual(parseUnits('13.25', 18)), amountOut: GreaterThanOrEqual(parseUnits('9.5', 6)), @@ -221,6 +221,46 @@ export const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { }, } +export const HLP_BALANCER_TOKENS_ETH: TestParams = { + transaction: { + chainId: 42161, + from: '0xba216e52be5a93e8ba380a761811f3802fa6ed89', + to: '0x9bdc4094860c97d9e5f1c18c4602a4a907d0a916', + hash: '0xe497a8357fb2e62f26da4d01c8ca9570c2613cd55ff3cb89b37685d10aaa8f8e', + input: + '0x8775b592000000000000000000000000db298285fe4c5410b05390ca80e8fbe9de1f259b0000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f4f14d06cb1661ce1dc2a2f26a10a7cd94393b29c00020000000000000000009700000000000000000000000000000000000000000000003863504448e6bdb6d7000000000000000000000000000000000000000000000000001385b35810f088000000000000000000000000ba216e52be5a93e8ba380a761811f3802fa6ed8900000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000368e1254c00000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000065757b760000000000000000000000000000000000000000000000000000000065757b7600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000065757b580000000000000000000000000000000000000000000000000000000065757b58000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000276000000000000000000000000000000000000000000000000000000000000008262d1ee51a53236d3ebdbca285ca729bf4671de987335013f17a866f8d42e940a1f02af4df4669edfe6f85dec65c53e5a083be04f36223aa810fc9cfe59c519721ca6c0001d3c24b12f17da5277b9f6abe142906e059701e8272e8c04379beafa5553635cc7f588fcdc5cc72e4b4a65d044d4de6203e9a1fae08522a6e3000f83ed1c000000000000000000000000000000000000000000000000000000000000', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b', // FOREX + tokenOut: zeroAddress, // ETH + amountIn: GreaterThanOrEqual(parseUnits('1040', 18)), + amountOut: GreaterThanOrEqual(parseEther('0.0054')), + recipient: '0xba216e52be5a93e8ba380a761811f3802fa6ed89', + }, +} + +export const HLP_BALANCER_ETH_TOKENS: TestParams = { + transaction: { + chainId: 42161, + from: '0xac91c1a921f352d9fdee51320d7b91001c2b21c7', + to: '0x9bdc4094860c97d9e5f1c18c4602a4a907d0a916', + hash: '0x58afb2cc0908f7049700bc10bbd144dc12df7baa2ac616abd0f4eefb22012b73', + input: + '0x892eb1b10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000db298285fe4c5410b05390ca80e8fbe9de1f259b4f14d06cb1661ce1dc2a2f26a10a7cd94393b29c00020000000000000000009700000000000000000000000000000000000000000000190bf2e1dcbcaa1ed7b6000000000000000000000000ac91c1a921f352d9fdee51320d7b91001c2b21c700000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000008616e8ea83f048ab9a5ec513c9412dd2993bce3f000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000032722e46000000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000657fdbf300000000000000000000000000000000000000000000000000000000657fdbf3000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000657fdbd500000000000000000000000000000000000000000000000000000000657fdbd50000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027600000000000000000000000000000000000000000000000000000000000002760000000000000000000000000000000000000000000000000000000000000082aa27720eac78bf96077ea6dee2eb5f8d94f28b0a8d38c5210716231345a061dc3a2e661879dd39c22d6c507c466679097cefc991e3c62d576dfdd913f09986161bf2b7ff86af8641a694e6e0a57720a09ffa3969271180aa2a24913f5ba7e7e4c16eea7a19ac2f6d69377f0a8b961f606d9f135f2396e226621d9c1fe11c5264a51b000000000000000000000000000000000000000000000000000000000000', + value: '595000000000000000', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: zeroAddress, // ETH + tokenOut: '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b', // FOREX + amountIn: GreaterThanOrEqual(parseEther('0.595')), + amountOut: GreaterThanOrEqual(parseUnits('118270', 18)), + recipient: '0xac91c1a921f352d9fdee51320d7b91001c2b21c7', + }, +} + export const passingTestCases = [ createTestCase( PARASWAP_SIMPLESWAP, @@ -247,6 +287,8 @@ export const passingTestCases = [ createTestCase(HLP_CURVE_V2_ETH_TO_CURVE, 'when routed through HLPcurveV2 contract (ETH to tokens)'), createTestCase(HLP_CURVE_V2_PEGGED_TO_CURVE, 'when routed through HLPcurveV2 contract (Pegged to Curve)'), createTestCase(HLP_CURVE_V2_TOKEN_TO_CURVE, 'when routed through HLPcurveV2 contract (Token to Curve)'), + createTestCase(HLP_BALANCER_ETH_TOKENS, 'when routed through HLPBalancer contract (ETH to tokens)'), + createTestCase(HLP_BALANCER_TOKENS_ETH, 'when routed through HLPBalancer contract (Tokens to ETH)'), ] export const failingTestCases = [ From b3a66acf8d59ce61bb37e542432c7630f5044719 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Thu, 21 Dec 2023 23:45:18 -0800 Subject: [PATCH 14/38] chore(pnpm): format --- packages/handlefi/src/constants.ts | 8 +------ packages/handlefi/src/input-filters.ts | 8 ++++++- packages/handlefi/src/test-transactions.ts | 27 +++++++++++++++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts index 19b13b010..d3a9e2101 100644 --- a/packages/handlefi/src/constants.ts +++ b/packages/handlefi/src/constants.ts @@ -27,10 +27,4 @@ const FOREX = '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b' const ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548' const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' -export const TOKEN_ADDRESSES = [ - FX_USD, - FOREX, - ARB, - USDC, - WETH -] \ No newline at end of file +export const TOKEN_ADDRESSES = [FX_USD, FOREX, ARB, USDC, WETH] diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index e145e1e08..591659752 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,7 +1,13 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' import { getAddress, zeroAddress } from 'viem' import { buildV2PathQueryWithCase } from './utils' -import { PARASWAP_ABI, V2_ROUTER_ABI, HPSM2_ABI, HLP_CURVE_V2_ABI, HLP_BALANCER_ABI } from './abi' +import { + PARASWAP_ABI, + V2_ROUTER_ABI, + HPSM2_ABI, + HLP_CURVE_V2_ABI, + HLP_BALANCER_ABI, +} from './abi' import { WETH } from './constants' export function getParaSwapFilter(params: SwapActionParams) { diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 99d161425..3eaf3b3e5 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -241,7 +241,7 @@ export const HLP_BALANCER_TOKENS_ETH: TestParams = { }, } -export const HLP_BALANCER_ETH_TOKENS: TestParams = { +export const HLP_BALANCER_ETH_TOKENS: TestParams = { transaction: { chainId: 42161, from: '0xac91c1a921f352d9fdee51320d7b91001c2b21c7', @@ -284,11 +284,26 @@ export const passingTestCases = [ 'when routed through HSPM2 contract (withdraw)', ), createTestCase(HPSM2_DEPOSIT, 'when routed through HSPM2 contract (deposit)'), - createTestCase(HLP_CURVE_V2_ETH_TO_CURVE, 'when routed through HLPcurveV2 contract (ETH to tokens)'), - createTestCase(HLP_CURVE_V2_PEGGED_TO_CURVE, 'when routed through HLPcurveV2 contract (Pegged to Curve)'), - createTestCase(HLP_CURVE_V2_TOKEN_TO_CURVE, 'when routed through HLPcurveV2 contract (Token to Curve)'), - createTestCase(HLP_BALANCER_ETH_TOKENS, 'when routed through HLPBalancer contract (ETH to tokens)'), - createTestCase(HLP_BALANCER_TOKENS_ETH, 'when routed through HLPBalancer contract (Tokens to ETH)'), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens)', + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve)', + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve)', + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens)', + ), + createTestCase( + HLP_BALANCER_TOKENS_ETH, + 'when routed through HLPBalancer contract (Tokens to ETH)', + ), ] export const failingTestCases = [ From a3421ad0b1e419d42be81021e84826731f926ad1 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:34:04 -0800 Subject: [PATCH 15/38] feat(handlefi): add support for curve factory pool --- packages/handlefi/src/HandleFi.ts | 6 ++++- packages/handlefi/src/input-filters.ts | 27 ++++++++++++++++++++++ packages/handlefi/src/test-transactions.ts | 24 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 163b8c012..a09d81d00 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -11,14 +11,17 @@ import { getHPSM2Filter, getHlpCurveV2Filter, getHlpBalancerFilter, + getCurveV2FactoryFilter, } from './input-filters' export const swap = async ( swap: SwapActionParams, ): Promise => { + const { tokenIn, amountIn, recipient } = swap return compressJson({ chainId: ARBITRUM_ONE, - value: swap.tokenIn === zeroAddress ? swap.amountIn : undefined, + value: tokenIn === zeroAddress ? amountIn : undefined, + from: recipient, to: { $or: SWAP_CONTRACTS.map((address) => address.toLowerCase()), }, @@ -29,6 +32,7 @@ export const swap = async ( getHPSM2Filter(swap), getHlpCurveV2Filter(swap), getHlpBalancerFilter(swap), + getCurveV2FactoryFilter(swap), ], }, }) diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 591659752..9707bc22f 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -7,6 +7,7 @@ import { HPSM2_ABI, HLP_CURVE_V2_ABI, HLP_BALANCER_ABI, + CURVE_FACTORY_ABI, } from './abi' import { WETH } from './constants' @@ -155,3 +156,29 @@ export function getHlpBalancerFilter(params: SwapActionParams) { ...tokenInput, } } + +export function getCurveV2FactoryFilter(params: SwapActionParams) { + const { tokenIn, tokenOut, amountIn, amountOut } = params + + const i = !tokenIn + ? undefined + : tokenIn.toLowerCase() === '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f' + ? 0 // fxUSD + : null + + const j = !tokenOut + ? undefined + : tokenOut.toLowerCase() === '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' + ? 1 // FRAX + : tokenOut.toLowerCase() === '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' + ? 2 // USDC.e + : null + + return { + $abi: CURVE_FACTORY_ABI, + i, + j, + _dx: amountIn, + _min_dy: amountOut, + } +} diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 3eaf3b3e5..bedbb323e 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -261,6 +261,26 @@ export const HLP_BALANCER_ETH_TOKENS: TestParams = { }, } +export const CURVE_FACTORY_V2: TestParams = { + transaction: { + chainId: 42161, + from: '0x86d55a7c9e70ba692b9b9b8460f354034f9ec896', + to: '0xab174ffa530c888649c44c4d21c849bbaabc723f', + hash: '0x77bd0b3159930e1b11aa5fcbcad5bb90f0e8693ea3873219ec6eb8f6d9ee524d', + input: + '0xa6417ed6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000008f64fe4909d7f9a300000000000000000000000000000000000000000000000000000000009a80bd', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + amountIn: GreaterThanOrEqual(parseUnits('10', 18)), + amountOut: GreaterThanOrEqual(parseUnits('10', 6)), + recipient: '0x86d55a7c9e70ba692b9b9b8460f354034f9ec896', + }, +} + export const passingTestCases = [ createTestCase( PARASWAP_SIMPLESWAP, @@ -304,6 +324,10 @@ export const passingTestCases = [ HLP_BALANCER_TOKENS_ETH, 'when routed through HLPBalancer contract (Tokens to ETH)', ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract', + ), ] export const failingTestCases = [ From fccef74939ac69100328dee175b4f7ea65f45e48 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:34:40 -0800 Subject: [PATCH 16/38] chore(pnpm): remove curve api package --- packages/handlefi/package.json | 1 - pnpm-lock.yaml | 88 ---------------------------------- 2 files changed, 89 deletions(-) diff --git a/packages/handlefi/package.json b/packages/handlefi/package.json index f67808010..69ff0aac2 100644 --- a/packages/handlefi/package.json +++ b/packages/handlefi/package.json @@ -43,7 +43,6 @@ "vitest": "^0.33.0" }, "dependencies": { - "@curvefi/api": "^2.53.5", "@rabbitholegg/questdk": "2.0.0-alpha.28", "viem": "^1.16.6" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a325709d..59d8a9acd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -206,7 +206,6 @@ importers: packages/handlefi: specifiers: - '@curvefi/api': ^2.53.5 '@rabbitholegg/questdk': 2.0.0-alpha.28 '@types/node': ^20.8.7 '@vitest/coverage-v8': ^0.33.0 @@ -218,7 +217,6 @@ importers: viem: ^1.16.6 vitest: ^0.33.0 dependencies: - '@curvefi/api': 2.53.5 '@rabbitholegg/questdk': 2.0.0-alpha.28_typescript@5.3.2 viem: 1.19.11_typescript@5.3.2 devDependencies: @@ -1111,20 +1109,6 @@ packages: dependencies: '@jridgewell/trace-mapping': 0.3.9 - /@curvefi/api/2.53.5: - resolution: {integrity: sha512-HEKZBrx+METfCJ4cz+Zg/Gs0LFxlwtPS+PewU6qhBZyBbrTetYZ4avQbYPPdnyXUfVQ9xWYPLR6G86QcJB47Pg==} - dependencies: - axios: 0.21.4 - bignumber.js: 9.1.2 - ethcall: 6.0.2_ethers@6.9.0 - ethers: 6.9.0 - memoizee: 0.4.15 - transitivePeerDependencies: - - bufferutil - - debug - - utf-8-validate - dev: false - /@esbuild/android-arm/0.16.17: resolution: {integrity: sha512-N9x1CMXVhtWEAMS7pNNONyA14f71VPQN9Cnavj1XQh6T7bskqiLLrSca4O0Vr8Wdcga943eThxnVp3JLnBMYtw==} engines: {node: '>=12'} @@ -3280,14 +3264,6 @@ packages: - zod dev: false - /abi-coder/5.0.0_ethers@6.9.0: - resolution: {integrity: sha512-Kpyv/AhAaIaVJiJ6S/xqoTsiJrfSMc3QsBCiRDqic3o1CZNKGR3CIeT1K/1VZ7Wk5uSwsOAxQcke1TVUEz+usg==} - peerDependencies: - ethers: ^6.0.0 - dependencies: - ethers: 6.9.0 - dev: false - /abitype/0.8.11_typescript@5.1.6: resolution: {integrity: sha512-bM4v2dKvX08sZ9IU38IN5BKmN+ZkOSd2oI4a9f0ejHYZQYV6cDr7j+d95ga0z2XHG36Y4jzoG5Z7qDqxp7fi/A==} peerDependencies: @@ -3715,14 +3691,6 @@ packages: resolution: {integrity: sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==} dev: false - /axios/0.21.4: - resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} - dependencies: - follow-redirects: 1.15.3 - transitivePeerDependencies: - - debug - dev: false - /axios/0.26.1: resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} dependencies: @@ -5084,15 +5052,6 @@ packages: ext: 1.7.0 dev: false - /es6-weak-map/2.0.3: - resolution: {integrity: sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==} - dependencies: - d: 1.0.1 - es5-ext: 0.10.62 - es6-iterator: 2.0.3 - es6-symbol: 3.1.3 - dev: false - /esbuild/0.16.17: resolution: {integrity: sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==} engines: {node: '>=12'} @@ -5332,16 +5291,6 @@ packages: xhr-request-promise: 0.1.3 dev: false - /ethcall/6.0.2_ethers@6.9.0: - resolution: {integrity: sha512-FyaKLlxtaVt+kRmhzDG3YfW4VxqasxZE2CDSfylMVp8kCxsBikzFE1BO90yAMGdjdwaX0kHlvjWSxKRpiEcI4w==} - peerDependencies: - ethers: ^6.0.0 - dependencies: - '@types/node': 20.10.3 - abi-coder: 5.0.0_ethers@6.9.0 - ethers: 6.9.0 - dev: false - /ethereum-block-by-date/1.4.9: resolution: {integrity: sha512-BsU2uwrfEpBZ+99j2Bk7OjoLi4BhTQ2IpEw2xaGyzqdfL/ibO8YJj7+oLBsdjJL11V7uhSxF+miAE7voI9dUOA==} dependencies: @@ -5494,13 +5443,6 @@ packages: number-to-bn: 1.7.0 dev: false - /event-emitter/0.3.5: - resolution: {integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==} - dependencies: - d: 1.0.1 - es5-ext: 0.10.62 - dev: false - /event-target-shim/5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -6620,10 +6562,6 @@ packages: resolution: {integrity: sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==} engines: {node: '>=0.10.0'} - /is-promise/2.2.2: - resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} - dev: false - /is-regex/1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -7155,12 +7093,6 @@ packages: engines: {node: '>=12'} dev: true - /lru-queue/0.1.0: - resolution: {integrity: sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==} - dependencies: - es5-ext: 0.10.62 - dev: false - /ltgt/2.2.1: resolution: {integrity: sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==} dev: false @@ -7231,19 +7163,6 @@ packages: safe-buffer: 5.2.1 dev: false - /memoizee/0.4.15: - resolution: {integrity: sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==} - dependencies: - d: 1.0.1 - es5-ext: 0.10.62 - es6-weak-map: 2.0.3 - event-emitter: 0.3.5 - is-promise: 2.2.2 - lru-queue: 0.1.0 - next-tick: 1.1.0 - timers-ext: 0.1.7 - dev: false - /meow/6.1.1: resolution: {integrity: sha512-3YffViIt2QWgTy6Pale5QpopX/IvU3LPL03jOTqp6pGj3VjesdO/U8CuHMKpnQr4shCNCM5fd5XFFvIIl6JBHg==} engines: {node: '>=8'} @@ -9499,13 +9418,6 @@ packages: engines: {node: '>=0.10.0'} dev: false - /timers-ext/0.1.7: - resolution: {integrity: sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==} - dependencies: - es5-ext: 0.10.62 - next-tick: 1.1.0 - dev: false - /tiny-invariant/1.3.1: resolution: {integrity: sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==} dev: false From d43d311dc1b930220d30874a836eae436f67797e Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:34:59 -0800 Subject: [PATCH 17/38] chore(pnpm): format --- packages/handlefi/src/input-filters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 9707bc22f..bb9a8c5f3 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -168,7 +168,7 @@ export function getCurveV2FactoryFilter(params: SwapActionParams) { const j = !tokenOut ? undefined - : tokenOut.toLowerCase() === '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' + : tokenOut.toLowerCase() === '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' ? 1 // FRAX : tokenOut.toLowerCase() === '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' ? 2 // USDC.e From b24492a89bfb91f8027972561ba298584dbc2c8f Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:38:21 -0800 Subject: [PATCH 18/38] refactor(handlefi): assert address type on address array --- packages/handlefi/src/constants.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts index d3a9e2101..3720992a6 100644 --- a/packages/handlefi/src/constants.ts +++ b/packages/handlefi/src/constants.ts @@ -1,3 +1,5 @@ +import type { Address } from "viem" + // Chains export const ARBITRUM_ONE = 42161 @@ -27,4 +29,4 @@ const FOREX = '0xdb298285fe4c5410b05390ca80e8fbe9de1f259b' const ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548' const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' -export const TOKEN_ADDRESSES = [FX_USD, FOREX, ARB, USDC, WETH] +export const TOKEN_ADDRESSES = [FX_USD, FOREX, ARB, USDC, WETH] as Address[] From b59662b76464bc059d32744fdfae88a42f76bf09 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:38:46 -0800 Subject: [PATCH 19/38] feat(handlefi): implement helper functions --- packages/handlefi/src/HandleFi.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index a09d81d00..f0884f7ec 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -4,7 +4,7 @@ import { compressJson, } from '@rabbitholegg/questdk' import { zeroAddress, type Address } from 'viem' -import { ARBITRUM_ONE, SWAP_CONTRACTS } from './constants' +import { ARBITRUM_ONE, SWAP_CONTRACTS, TOKEN_ADDRESSES } from './constants' import { getParaSwapFilter, getV2RouterFilter, @@ -41,9 +41,9 @@ export const swap = async ( export const getSupportedTokenAddresses = async ( _chainId: number, ): Promise => { - return [] + return _chainId === ARBITRUM_ONE ? TOKEN_ADDRESSES : [] } export const getSupportedChainIds = async (): Promise => { - return [] + return [ARBITRUM_ONE] } From dcda9cd1138f585cf64d2487227f39ffdb2709ce Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:50:33 -0800 Subject: [PATCH 20/38] feat(handlefi): add support for swaps routed through curve 2pool --- packages/handlefi/src/input-filters.ts | 5 +++-- packages/handlefi/src/test-transactions.ts | 23 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index bb9a8c5f3..022d0d552 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -170,8 +170,9 @@ export function getCurveV2FactoryFilter(params: SwapActionParams) { ? undefined : tokenOut.toLowerCase() === '0x17fc002b466eec40dae837fc4be5c67993ddbd6f' ? 1 // FRAX - : tokenOut.toLowerCase() === '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' - ? 2 // USDC.e + : tokenOut.toLowerCase() === '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' || + tokenOut.toLowerCase() === '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' + ? 2 // USDC.e || USDT : null return { diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index bedbb323e..7597749df 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -156,7 +156,7 @@ export const HPSM2_DEPOSIT: TestParams = { chainId: ARBITRUM_ONE, tokenIn: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD - recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', + recipient: '0x0ffad609d35c4bef104ee245a9c4c891d463aa2a', }, } @@ -281,6 +281,26 @@ export const CURVE_FACTORY_V2: TestParams = { }, } +export const CURVE_FACTORY_2POOL: TestParams = { + transaction: { + chainId: 42161, + from: '0x0b8b2a4996627f9bf106e7b6d9540f1266841957', + to: '0xd0dd5d76cf0fc06dabc48632735566dca241a35e', + hash: '0xa7f8d500da701b028d037740a5f74a73eaaff7d344526484812e96ef354cae26', + input: + '0xa6417ed6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000008c1c0e211a8d8000000000000000000000000000000000000000000000000000000000000096c973', + value: '0', + }, + params: { + chainId: ARBITRUM_ONE, + tokenIn: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + tokenOut: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT + amountIn: GreaterThanOrEqual(parseUnits('10', 18)), + amountOut: GreaterThanOrEqual(parseUnits('9.65', 6)), + recipient: '0x0b8b2a4996627f9bf106e7b6d9540f1266841957', + }, +} + export const passingTestCases = [ createTestCase( PARASWAP_SIMPLESWAP, @@ -328,6 +348,7 @@ export const passingTestCases = [ CURVE_FACTORY_V2, 'when routed through curve factory v2 contract', ), + createTestCase(CURVE_FACTORY_2POOL, 'when routed through curve 2pool'), ] export const failingTestCases = [ From 52bf35e157715110e028e540a29adacf6546e0b1 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 00:50:50 -0800 Subject: [PATCH 21/38] chore(pnpm): format --- packages/handlefi/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts index 3720992a6..a30dc60c9 100644 --- a/packages/handlefi/src/constants.ts +++ b/packages/handlefi/src/constants.ts @@ -1,4 +1,4 @@ -import type { Address } from "viem" +import type { Address } from 'viem' // Chains export const ARBITRUM_ONE = 42161 From 905d134c22dfd1d2f8330b936f8615cfbc833fb9 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 11:27:33 -0800 Subject: [PATCH 22/38] test(handlefi): test valid action filter is returned --- packages/handlefi/src/HandleFi.test.ts | 186 ++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 2 deletions(-) diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts index b520cc7ac..e90c03ded 100644 --- a/packages/handlefi/src/HandleFi.test.ts +++ b/packages/handlefi/src/HandleFi.test.ts @@ -2,12 +2,194 @@ import { apply } from '@rabbitholegg/questdk/filter' import { describe, expect, test } from 'vitest' import { swap } from './HandleFi' import { passingTestCases, failingTestCases } from './test-transactions' +import { + PARASWAP_ABI, + V2_ROUTER_ABI, + HPSM2_ABI, + HLP_BALANCER_ABI, + HLP_CURVE_V2_ABI, + CURVE_FACTORY_ABI, +} from './abi' describe('Given the handlefi plugin', () => { describe('When handling the swap action', () => { describe('should return a valid action filter', () => { - test('', () => { - expect(true).to.be.true + test('when using convert fetaure on handlefi', async () => { + const { params } = passingTestCases[0] + const filter = await swap(params) + expect(filter).to.deep.equal({ + chainId: 42161, + from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + to: { + $or: [ + '0xdef171fe48cf0115b1d80b88dc8eab59176fee57', + '0x434b5245f6fe54d0c9f881d55c2ba27fe7132d89', + '0x0f330a53874cea3e5a0dee5d291c49275fdc3260', + '0x559844b1df66e247f83ba58bc39fa488a1af1093', + '0x9bdc4094860c97d9e5f1c18c4602a4a907d0a916', + '0xab174ffa530c888649c44c4d21c849bbaabc723f', + '0xd0dd5d76cf0fc06dabc48632735566dca241a35e', + ], + }, + input: { + $or: [ + { + $abi: PARASWAP_ABI, + $or: [ + { + data: { + fromToken: '0x912CE59144191C1204E64559FE8253a0e49E6548', + fromAmount: { + $gte: '1000000000000000000', + }, + toAmount: { + $gte: '1110000', + }, + toToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + data: { + fromToken: '0x912CE59144191C1204E64559FE8253a0e49E6548', + fromAmount: { + $gte: '1000000000000000000', + }, + toAmount: { + $gte: '1110000', + }, + path: { + $last: { + to: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + }, + }, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + data: { + fromToken: '0x912CE59144191C1204E64559FE8253a0e49E6548', + fromAmount: { + $gte: '1000000000000000000', + }, + toAmount: { + $gte: '1110000', + }, + path: { + $last: { + path: { + $last: { + to: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + }, + }, + }, + }, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + { + data: { + assets: { + $and: [ + { + $first: + '0x912ce59144191c1204e64559fe8253a0e49e6548', + }, + { + $last: '0xaf88d065e77c8cc2239327c5edb3a432268e5831', + }, + ], + }, + fromAmount: { + $gte: '1000000000000000000', + }, + toAmount: { + $gte: '1110000', + }, + partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + }, + }, + ], + }, + { + $abi: V2_ROUTER_ABI, + _path: { + $and: [ + { + $first: '0x912CE59144191C1204E64559FE8253a0e49E6548', + }, + { + $last: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + }, + ], + }, + _amountIn: { + $gte: '1000000000000000000', + }, + _minOut: { + $gte: '1110000', + }, + _receiver: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + }, + { + $abi: HPSM2_ABI, + fxTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + peggedTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + }, + { + $abi: HLP_CURVE_V2_ABI, + tokenOut: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + amountIn: { + $gte: '1000000000000000000', + }, + minOut: { + $gte: '1110000', + }, + receiver: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + $or: [ + { + peggedToken: '0x912CE59144191C1204E64559FE8253a0e49E6548', + }, + { + hlpToken: '0x912CE59144191C1204E64559FE8253a0e49E6548', + }, + ], + }, + { + $abi: HLP_BALANCER_ABI, + minOut: { + $gte: '1110000', + }, + amountIn: { + $gte: '1000000000000000000', + }, + receiver: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', + tokenIn: '0x912CE59144191C1204E64559FE8253a0e49E6548', + }, + { + $abi: CURVE_FACTORY_ABI, + i: null, + j: null, + _dx: { + $gte: '1000000000000000000', + }, + _min_dy: { + $gte: '1110000', + }, + }, + ], + }, + }) }) }) From ba0cbc9ea434e4c96cd7cb2a5d8c13fed750c8fa Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:15:51 -0800 Subject: [PATCH 23/38] refactor(handlefi): remove unused exports --- packages/handlefi/src/test-transactions.ts | 535 +++++++++++++++++++-- 1 file changed, 501 insertions(+), 34 deletions(-) diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 7597749df..385fbfcb0 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -7,7 +7,7 @@ import { createTestCase, type TestParams } from './utils' import { ARBITRUM_ONE } from './constants' // Paraswap Test Txs -export const PARASWAP_SIMPLESWAP: TestParams = { +const PARASWAP_SIMPLESWAP: TestParams = { transaction: { chainId: 42161, from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', @@ -27,7 +27,7 @@ export const PARASWAP_SIMPLESWAP: TestParams = { }, } -export const PARASWAP_MULTISWAP: TestParams = { +const PARASWAP_MULTISWAP: TestParams = { transaction: { chainId: 42161, from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', @@ -47,7 +47,7 @@ export const PARASWAP_MULTISWAP: TestParams = { }, } -export const PARASWAP_UNI_V3: TestParams = { +const PARASWAP_UNI_V3: TestParams = { transaction: { chainId: 42161, from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', @@ -67,7 +67,7 @@ export const PARASWAP_UNI_V3: TestParams = { }, } -export const PARASWAP_FAIL: TestParams = { +const PARASWAP_FAIL: TestParams = { transaction: { chainId: 42161, from: '0x9a1385dded2c1c00b8ac11e6597e86f3879a3403', @@ -83,7 +83,7 @@ export const PARASWAP_FAIL: TestParams = { } // V2 router -export const V2_ROUTER_ETH_TOKENS: TestParams = { +const V2_ROUTER_ETH_TOKENS: TestParams = { transaction: { chainId: 42161, from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', @@ -103,7 +103,7 @@ export const V2_ROUTER_ETH_TOKENS: TestParams = { }, } -export const V2_ROUTER_TOKENS_ETH: TestParams = { +const V2_ROUTER_TOKENS_ETH: TestParams = { transaction: { chainId: 42161, from: '0x4806032267387c9e6aab509b497a765d0aca7f61', @@ -124,7 +124,7 @@ export const V2_ROUTER_TOKENS_ETH: TestParams = { } // HPSM2 -export const HPSM2_WITHDRAW: TestParams = { +const HPSM2_WITHDRAW: TestParams = { transaction: { chainId: 42161, from: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', @@ -142,7 +142,7 @@ export const HPSM2_WITHDRAW: TestParams = { }, } -export const HPSM2_DEPOSIT: TestParams = { +const HPSM2_DEPOSIT: TestParams = { transaction: { chainId: 42161, from: '0x0ffad609d35c4bef104ee245a9c4c891d463aa2a', @@ -161,7 +161,7 @@ export const HPSM2_DEPOSIT: TestParams = { } // HlpCurveV2 -export const HLP_CURVE_V2_ETH_TO_CURVE: TestParams = { +const HLP_CURVE_V2_ETH_TO_CURVE: TestParams = { transaction: { chainId: 42161, from: '0x29d7e0c5839715a2fe6670a248f471427104b266', @@ -181,7 +181,7 @@ export const HLP_CURVE_V2_ETH_TO_CURVE: TestParams = { }, } -export const HLP_CURVE_V2_PEGGED_TO_CURVE: TestParams = { +const HLP_CURVE_V2_PEGGED_TO_CURVE: TestParams = { transaction: { chainId: 42161, from: '0x29d7e0c5839715a2fe6670a248f471427104b266', @@ -201,7 +201,7 @@ export const HLP_CURVE_V2_PEGGED_TO_CURVE: TestParams = { }, } -export const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { +const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { transaction: { chainId: 42161, from: '0x49908e05de9e1d559499b08042d1123a1daae6b4', @@ -221,7 +221,7 @@ export const HLP_CURVE_V2_TOKEN_TO_CURVE: TestParams = { }, } -export const HLP_BALANCER_TOKENS_ETH: TestParams = { +const HLP_BALANCER_TOKENS_ETH: TestParams = { transaction: { chainId: 42161, from: '0xba216e52be5a93e8ba380a761811f3802fa6ed89', @@ -241,7 +241,7 @@ export const HLP_BALANCER_TOKENS_ETH: TestParams = { }, } -export const HLP_BALANCER_ETH_TOKENS: TestParams = { +const HLP_BALANCER_ETH_TOKENS: TestParams = { transaction: { chainId: 42161, from: '0xac91c1a921f352d9fdee51320d7b91001c2b21c7', @@ -261,7 +261,7 @@ export const HLP_BALANCER_ETH_TOKENS: TestParams = { }, } -export const CURVE_FACTORY_V2: TestParams = { +const CURVE_FACTORY_V2: TestParams = { transaction: { chainId: 42161, from: '0x86d55a7c9e70ba692b9b9b8460f354034f9ec896', @@ -281,7 +281,7 @@ export const CURVE_FACTORY_V2: TestParams = { }, } -export const CURVE_FACTORY_2POOL: TestParams = { +const CURVE_FACTORY_2POOL: TestParams = { transaction: { chainId: 42161, from: '0x0b8b2a4996627f9bf106e7b6d9540f1266841957', @@ -349,6 +349,146 @@ export const passingTestCases = [ 'when routed through curve factory v2 contract', ), createTestCase(CURVE_FACTORY_2POOL, 'when routed through curve 2pool'), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap) using any', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HPSM2_DEPOSIT, + 'when routed through HSPM2 contract (deposit) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + HLP_BALANCER_TOKENS_ETH, + 'when routed through HLPBalancer contract (Tokens to ETH) using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool using any token', + { + tokenIn: undefined, + tokenOut: undefined, + amountIn: undefined, + amountOut: undefined, + }, + ), ] export const failingTestCases = [ @@ -356,23 +496,350 @@ export const failingTestCases = [ PARASWAP_FAIL, 'when using paraswap route not referred by handlefi', ), + createTestCase(V2_ROUTER_TOKENS_ETH, 'when chainId is incorrect', { + chainId: 324, + }), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap)', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HPSM2_DEPOSIT, + 'when routed through HSPM2 contract (deposit) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_BALANCER_TOKENS_ETH, + 'when routed through HLPBalancer contract (Tokens to ETH) and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool and tokenIn is not correct', + { + tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HPSM2_DEPOSIT, + 'when routed through HSPM2 contract (deposit) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool and tokenOut is not correct', + { + tokenOut: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', + }, + ), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool and amountOut is not sufficient', + { + amountOut: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')), + }, + ), ] - -/* - transaction: { - chainId: 42161, - from: '', - to: '', - hash: '', - input: '', - amount: '', - }, - params: { - chainId: 42161, - tokenIn: '', - tokenOut: '', - amountIn: GreaterThanOrEqual(parseUnits('', 18)), - amountOut: GreaterThanOrEqual(parseUnits('', 18)), - recipient: '', - } -*/ From 91bfbdc3e33478b72467070f017f3578050eb2ec Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:17:12 -0800 Subject: [PATCH 24/38] test(handlefi): test valid token addresses are returned for each valid chain --- packages/handlefi/src/HandleFi.test.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts index e90c03ded..9568fb73e 100644 --- a/packages/handlefi/src/HandleFi.test.ts +++ b/packages/handlefi/src/HandleFi.test.ts @@ -1,7 +1,8 @@ import { apply } from '@rabbitholegg/questdk/filter' import { describe, expect, test } from 'vitest' -import { swap } from './HandleFi' +import { swap, getSupportedTokenAddresses } from './HandleFi' import { passingTestCases, failingTestCases } from './test-transactions' +import { ARBITRUM_ONE } from './constants' import { PARASWAP_ABI, V2_ROUTER_ABI, @@ -212,5 +213,21 @@ describe('Given the handlefi plugin', () => { }) }) }) + + describe('should return a valid list of tokens for each supported chain', () => { + test(`for chainId: ${ARBITRUM_ONE}`, async () => { + const tokens = await getSupportedTokenAddresses(ARBITRUM_ONE) + const addressRegex = /^0x[a-fA-F0-9]{40}$/ + expect(tokens).to.be.an('array') + expect(tokens).to.have.length.greaterThan(0) + expect(tokens).to.have.length.lessThan(100) + tokens.forEach((token) => { + expect(token).to.match( + addressRegex, + `Token address ${token} is not a valid Ethereum address`, + ) + }) + }) + }) }) }) From f7b123030efbb5af9ad98a2c49f629988e913bc7 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:18:02 -0800 Subject: [PATCH 25/38] docs(handlefi): comment on curvev2 function --- packages/handlefi/src/input-filters.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 022d0d552..21d5b4dcd 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -160,6 +160,10 @@ export function getHlpBalancerFilter(params: SwapActionParams) { export function getCurveV2FactoryFilter(params: SwapActionParams) { const { tokenIn, tokenOut, amountIn, amountOut } = params + // There isnt really a good way to tell which pool you are in without knowing the contract address of the pool + // i will always be fxUSD (0) + // j can either be FRAX, USDC.e, or USDT (may get false posiitves here) + const i = !tokenIn ? undefined : tokenIn.toLowerCase() === '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f' From e4ceda2d0ce90ec0b0183423c4d5406900672bf1 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:18:47 -0800 Subject: [PATCH 26/38] fix(handlefi): use passed in chainId parameter --- packages/handlefi/src/HandleFi.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index f0884f7ec..165f7f783 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -17,9 +17,9 @@ import { export const swap = async ( swap: SwapActionParams, ): Promise => { - const { tokenIn, amountIn, recipient } = swap + const { chainId, tokenIn, amountIn, recipient } = swap return compressJson({ - chainId: ARBITRUM_ONE, + chainId, value: tokenIn === zeroAddress ? amountIn : undefined, from: recipient, to: { From d88bfca317628f1e49f1668e10a4293c603a7d7c Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:26:54 -0800 Subject: [PATCH 27/38] test(handlefi): test checksummed token addresses pass --- packages/handlefi/src/test-transactions.ts | 116 ++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 385fbfcb0..efd55cc6b 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -2,7 +2,7 @@ import { type SwapActionParams, GreaterThanOrEqual, } from '@rabbitholegg/questdk' -import { parseEther, parseUnits, zeroAddress } from 'viem' +import { parseEther, parseUnits, zeroAddress, getAddress, type Address } from 'viem' import { createTestCase, type TestParams } from './utils' import { ARBITRUM_ONE } from './constants' @@ -361,7 +361,7 @@ export const passingTestCases = [ ), createTestCase( PARASWAP_MULTISWAP, - 'when routed through paraswap (multiswap) using any', + 'when routed through paraswap (multiswap) using any token', { tokenIn: undefined, tokenOut: undefined, @@ -489,6 +489,118 @@ export const passingTestCases = [ amountOut: undefined, }, ), + createTestCase( + PARASWAP_SIMPLESWAP, + 'when routed through paraswap (simpleswap) using checksummed token addresses', + { + tokenIn: getAddress(PARASWAP_SIMPLESWAP.params.tokenIn as Address), + tokenOut: getAddress(PARASWAP_SIMPLESWAP.params.tokenOut as Address), + }, + ), + createTestCase( + PARASWAP_MULTISWAP, + 'when routed through paraswap (multiswap) using checksummed token addresses', + { + tokenIn: getAddress(PARASWAP_MULTISWAP.params.tokenIn as Address), + tokenOut: getAddress(PARASWAP_MULTISWAP.params.tokenOut as Address), + }, + ), + createTestCase( + PARASWAP_UNI_V3, + 'when routed through paraswap (uniV3Swap) using checksummed token addresses', + { + tokenIn: getAddress(PARASWAP_UNI_V3.params.tokenIn as Address), + tokenOut: getAddress(PARASWAP_UNI_V3.params.tokenOut as Address), + }, + ), + createTestCase( + V2_ROUTER_ETH_TOKENS, + 'when routed through V2 router (ETH To Tokens) using checksummed token addresses', + { + tokenIn: getAddress(V2_ROUTER_ETH_TOKENS.params.tokenIn as Address), + tokenOut: getAddress(V2_ROUTER_ETH_TOKENS.params.tokenOut as Address), + }, + ), + createTestCase( + V2_ROUTER_TOKENS_ETH, + 'when routed through V2 router (Tokens To ETH) using checksummed token addresses', + { + tokenIn: getAddress(V2_ROUTER_TOKENS_ETH.params.tokenIn as Address), + tokenOut: getAddress(V2_ROUTER_TOKENS_ETH.params.tokenOut as Address), + }, + ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw) using checksummed token addresses', + { + tokenIn: getAddress(HPSM2_WITHDRAW.params.tokenIn as Address), + tokenOut: getAddress(HPSM2_WITHDRAW.params.tokenOut as Address), + }, + ), + createTestCase( + HPSM2_DEPOSIT, + 'when routed through HSPM2 contract (deposit) using checksummed token addresses', + { + tokenIn: getAddress(HPSM2_DEPOSIT.params.tokenIn as Address), + tokenOut: getAddress(HPSM2_DEPOSIT.params.tokenOut as Address), + }, + ), + createTestCase( + HLP_CURVE_V2_ETH_TO_CURVE, + 'when routed through HLPcurveV2 contract (ETH to tokens) using checksummed token addresses', + { + tokenIn: getAddress(HLP_CURVE_V2_ETH_TO_CURVE.params.tokenIn as Address), + tokenOut: getAddress(HLP_CURVE_V2_ETH_TO_CURVE.params.tokenOut as Address), + }, + ), + createTestCase( + HLP_CURVE_V2_PEGGED_TO_CURVE, + 'when routed through HLPcurveV2 contract (Pegged to Curve) using checksummed token addresses', + { + tokenIn: getAddress(HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenIn as Address), + tokenOut: getAddress(HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenOut as Address), + }, + ), + createTestCase( + HLP_CURVE_V2_TOKEN_TO_CURVE, + 'when routed through HLPcurveV2 contract (Token to Curve) using checksummed token addresses', + { + tokenIn: getAddress(HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenIn as Address), + tokenOut: getAddress(HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenOut as Address), + }, + ), + createTestCase( + HLP_BALANCER_ETH_TOKENS, + 'when routed through HLPBalancer contract (ETH to tokens) using checksummed token addresses', + { + tokenIn: getAddress(HLP_BALANCER_ETH_TOKENS.params.tokenIn as Address), + tokenOut: getAddress(HLP_BALANCER_ETH_TOKENS.params.tokenOut as Address), + }, + ), + createTestCase( + HLP_BALANCER_TOKENS_ETH, + 'when routed through HLPBalancer contract (Tokens to ETH) using checksummed token addresses', + { + tokenIn: getAddress(HLP_BALANCER_TOKENS_ETH.params.tokenIn as Address), + tokenOut: getAddress(HLP_BALANCER_TOKENS_ETH.params.tokenOut as Address), + }, + ), + createTestCase( + CURVE_FACTORY_V2, + 'when routed through curve factory v2 contract using checksummed token addresses', + { + tokenIn: getAddress(CURVE_FACTORY_V2.params.tokenIn as Address), + tokenOut: getAddress(CURVE_FACTORY_V2.params.tokenOut as Address), + }, + ), + createTestCase( + CURVE_FACTORY_2POOL, + 'when routed through curve 2pool using any token', + { + tokenIn: getAddress(CURVE_FACTORY_2POOL.params.tokenIn as Address), + tokenOut: getAddress(CURVE_FACTORY_2POOL.params.tokenOut as Address), + }, + ), ] export const failingTestCases = [ From cf563f5fe68a18396bfdcef32f98973e86280da1 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:44:47 -0800 Subject: [PATCH 28/38] refactor(handlefi): split abi of hpsm2 --- packages/handlefi/src/abi.ts | 5 ++++- packages/handlefi/src/input-filters.ts | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/handlefi/src/abi.ts b/packages/handlefi/src/abi.ts index 2b3b2c695..484725b2a 100644 --- a/packages/handlefi/src/abi.ts +++ b/packages/handlefi/src/abi.ts @@ -603,7 +603,7 @@ export const PARASWAP_ABI = [ }, ] -export const HPSM2_ABI = [ +export const HPSM2_DEPOSIT_ABI = [ { inputs: [ { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, @@ -615,6 +615,9 @@ export const HPSM2_ABI = [ stateMutability: 'nonpayable', type: 'function', }, +] + +export const HPSM2_WITHDRAW_ABI = [ { inputs: [ { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 21d5b4dcd..a32c79b38 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -4,7 +4,8 @@ import { buildV2PathQueryWithCase } from './utils' import { PARASWAP_ABI, V2_ROUTER_ABI, - HPSM2_ABI, + HPSM2_DEPOSIT_ABI, + HPSM2_WITHDRAW_ABI, HLP_CURVE_V2_ABI, HLP_BALANCER_ABI, CURVE_FACTORY_ABI, @@ -91,7 +92,7 @@ export function getV2RouterFilter(params: SwapActionParams) { export function getHPSM2Filter(params: SwapActionParams) { // Not using amount here since it is not possible to tell if the amount is amountIn or amountOut - const { tokenIn, tokenOut } = params + const { tokenIn, tokenOut, amountIn, amountOut } = params const tokenInAddress = tokenIn ? getAddress(tokenIn) : undefined const tokenOutAddress = tokenOut ? getAddress(tokenOut) : undefined @@ -110,8 +111,18 @@ export function getHPSM2Filter(params: SwapActionParams) { } return { - $abi: HPSM2_ABI, - ...inputs, + $or: [ + { + $abi: HPSM2_DEPOSIT_ABI, + amount: amountIn, + ...inputs + }, + { + $abi: HPSM2_WITHDRAW_ABI, + amount: amountOut, + ...inputs + }, + ] } as const } From 6a906feb810636211467c316fa36c0bdcb07037f Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:46:31 -0800 Subject: [PATCH 29/38] test(handlefi): add split abi to filter test --- packages/handlefi/src/HandleFi.test.ts | 54 +++++++++++++++++++------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts index 9568fb73e..d9850fef4 100644 --- a/packages/handlefi/src/HandleFi.test.ts +++ b/packages/handlefi/src/HandleFi.test.ts @@ -6,7 +6,8 @@ import { ARBITRUM_ONE } from './constants' import { PARASWAP_ABI, V2_ROUTER_ABI, - HPSM2_ABI, + HPSM2_DEPOSIT_ABI, + HPSM2_WITHDRAW_ABI, HLP_BALANCER_ABI, HLP_CURVE_V2_ABI, CURVE_FACTORY_ABI, @@ -133,19 +134,44 @@ describe('Given the handlefi plugin', () => { _receiver: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', }, { - $abi: HPSM2_ABI, - fxTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, - peggedTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, + $or: [ + { + $abi: HPSM2_DEPOSIT_ABI, + amount: { + $gte: '1000000000000000000', + }, + fxTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + peggedTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + }, + { + $abi: HPSM2_WITHDRAW_ABI, + amount: { + $gte: '1110000', + }, + fxTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + peggedTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + }, + ], }, { $abi: HLP_CURVE_V2_ABI, From 4f8357db9a8bbf037b972cc77fd096660d1b71b1 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 18:59:32 -0800 Subject: [PATCH 30/38] feat(handlefi): unsplit abi and test amountIn on HPSM2 routed trades --- packages/handlefi/src/HandleFi.test.ts | 57 +++++++--------------- packages/handlefi/src/abi.ts | 5 +- packages/handlefi/src/input-filters.ts | 22 +++------ packages/handlefi/src/test-transactions.ts | 16 ++++++ 4 files changed, 40 insertions(+), 60 deletions(-) diff --git a/packages/handlefi/src/HandleFi.test.ts b/packages/handlefi/src/HandleFi.test.ts index d9850fef4..ad6c877da 100644 --- a/packages/handlefi/src/HandleFi.test.ts +++ b/packages/handlefi/src/HandleFi.test.ts @@ -6,8 +6,7 @@ import { ARBITRUM_ONE } from './constants' import { PARASWAP_ABI, V2_ROUTER_ABI, - HPSM2_DEPOSIT_ABI, - HPSM2_WITHDRAW_ABI, + HPSM2_ABI, HLP_BALANCER_ABI, HLP_CURVE_V2_ABI, CURVE_FACTORY_ABI, @@ -134,44 +133,22 @@ describe('Given the handlefi plugin', () => { _receiver: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1', }, { - $or: [ - { - $abi: HPSM2_DEPOSIT_ABI, - amount: { - $gte: '1000000000000000000', - }, - fxTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, - peggedTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, - }, - { - $abi: HPSM2_WITHDRAW_ABI, - amount: { - $gte: '1110000', - }, - fxTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, - peggedTokenAddress: { - $or: [ - '0x912CE59144191C1204E64559FE8253a0e49E6548', - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - ], - }, - }, - ], + $abi: HPSM2_ABI, + amount: { + $gte: '1000000000000000000', + }, + fxTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, + peggedTokenAddress: { + $or: [ + '0x912CE59144191C1204E64559FE8253a0e49E6548', + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + ], + }, }, { $abi: HLP_CURVE_V2_ABI, diff --git a/packages/handlefi/src/abi.ts b/packages/handlefi/src/abi.ts index 484725b2a..2b3b2c695 100644 --- a/packages/handlefi/src/abi.ts +++ b/packages/handlefi/src/abi.ts @@ -603,7 +603,7 @@ export const PARASWAP_ABI = [ }, ] -export const HPSM2_DEPOSIT_ABI = [ +export const HPSM2_ABI = [ { inputs: [ { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, @@ -615,9 +615,6 @@ export const HPSM2_DEPOSIT_ABI = [ stateMutability: 'nonpayable', type: 'function', }, -] - -export const HPSM2_WITHDRAW_ABI = [ { inputs: [ { internalType: 'address', name: 'fxTokenAddress', type: 'address' }, diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index a32c79b38..135bae0d5 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -4,8 +4,7 @@ import { buildV2PathQueryWithCase } from './utils' import { PARASWAP_ABI, V2_ROUTER_ABI, - HPSM2_DEPOSIT_ABI, - HPSM2_WITHDRAW_ABI, + HPSM2_ABI, HLP_CURVE_V2_ABI, HLP_BALANCER_ABI, CURVE_FACTORY_ABI, @@ -91,8 +90,8 @@ export function getV2RouterFilter(params: SwapActionParams) { } export function getHPSM2Filter(params: SwapActionParams) { - // Not using amount here since it is not possible to tell if the amount is amountIn or amountOut - const { tokenIn, tokenOut, amountIn, amountOut } = params + // amount is only for amountIn + const { tokenIn, tokenOut, amountIn } = params const tokenInAddress = tokenIn ? getAddress(tokenIn) : undefined const tokenOutAddress = tokenOut ? getAddress(tokenOut) : undefined @@ -111,18 +110,9 @@ export function getHPSM2Filter(params: SwapActionParams) { } return { - $or: [ - { - $abi: HPSM2_DEPOSIT_ABI, - amount: amountIn, - ...inputs - }, - { - $abi: HPSM2_WITHDRAW_ABI, - amount: amountOut, - ...inputs - }, - ] + $abi: HPSM2_ABI, + amount: amountIn, + ...inputs, } as const } diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index efd55cc6b..83a219fbb 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -138,6 +138,7 @@ const HPSM2_WITHDRAW: TestParams = { chainId: ARBITRUM_ONE, tokenIn: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD tokenOut: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e + amountIn: GreaterThanOrEqual(parseUnits('1940', 18)), recipient: '0x33e2bd5957c0236e88d750b12bbf32bfb8bb92fb', }, } @@ -156,6 +157,7 @@ const HPSM2_DEPOSIT: TestParams = { chainId: ARBITRUM_ONE, tokenIn: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e tokenOut: '0x8616e8ea83f048ab9a5ec513c9412dd2993bce3f', // fxUSD + amountIn: GreaterThanOrEqual(parseUnits('1000', 6)), recipient: '0x0ffad609d35c4bef104ee245a9c4c891d463aa2a', }, } @@ -912,6 +914,20 @@ export const failingTestCases = [ amountIn: GreaterThanOrEqual(parseEther('1000000')), }, ), + createTestCase( + HPSM2_WITHDRAW, + 'when routed through HSPM2 contract (withdraw) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')) + }, + ), + createTestCase( + HPSM2_DEPOSIT, + 'when routed through HSPM2 contract (deposit) and amountIn is not sufficient', + { + amountIn: GreaterThanOrEqual(parseEther('1000000')) + }, + ), createTestCase( HLP_CURVE_V2_ETH_TO_CURVE, 'when routed through HLPcurveV2 contract (ETH to tokens) and amountIn is not sufficient', From b049f2e4281495bf25339d9cfd20b0fe8481f034 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 19:29:47 -0800 Subject: [PATCH 31/38] docs(handlefi): add README.ms --- packages/handlefi/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/handlefi/README.md b/packages/handlefi/README.md index e69de29bb..a42fa5daf 100644 --- a/packages/handlefi/README.md +++ b/packages/handlefi/README.md @@ -0,0 +1,29 @@ +Limitations + +- amountOut may not be accurate due to some methods using `amountOutMin` which takes into account the amount of slippage set. +- amountOut will not be considered in the swap is routed through the HPSM2 contract. +- trades routed through curve V2 factory may have some false positives. Since there is not a really good way to tell what pool it is without having the contract address passed in as an argument. A false positive can occur if the tokenOut is selected as USDT and USDC.e is traded, and vice-versa. + +# HandleFi Plugin + +## Overview +HandleFi is a decentralised multi currency stablecoin protocol based on Arbitrum. They offer sevearl products including perpetual swaps, convert, staking, and fxTokens. + +### Swap Plugin + +The swap plugin tragets handlefis [convert feature](https://app.handle.fi/convert) which uses a mix of native contracts and external aggregators such as paraswap. + +##### Limitations +- amountOut may not be accurate due to some methods using `amountOutMin` which takes into account the amount of slippage set. +- amountOut will not be considered in the swap is routed through the HPSM2 contract. +- trades routed through curve V2 factory may have some false positives. Since there is not a really good way to tell what pool it is without having the contract address passed in as an argument. A false positive can occur if the tokenOut is selected as USDT and USDC.e is traded, and vice-versa. +- There should be no limitations with the current swap plugin. Everything should work as expected. + +##### Sample Transactions +- [Paraswap](https://dashboard.tenderly.co/tx/arbitrum/0xdc4f726560293b41a0ee72048e2d94970a45a046d88447444dab8bc54cb25a94) +- [V2Router](https://arbiscan.io/tx/0xb4e506b5373ce01c71518e9e0c3fefb87952ad3ab28362b69c083cbe63d56094) +- [hPSM2](https://arbiscan.io/tx/0x8b880dd0805ed4767a9a770149bbe9402d44ae334374f2afef8bb5fd257585a8) +- [routerHpsmHlpCurveV2](https://arbiscan.io/tx/0x819ec6afd60b26412e830feb80b5abe1dab1229fc6ef6a42224e59fb85385d51) +- [routerEthHlpBalancer](https://arbiscan.io/tx/0x58afb2cc0908f7049700bc10bbd144dc12df7baa2ac616abd0f4eefb22012b73) +- [curveFactory (fxUSD_FRAX)](https://arbiscan.io/tx/0x254e3dcea9a376f67340b9141c1c013aea5f1820de629847aa549c29cf4b599c) +- [curveFactory (fxUSD_3pool)](https://arbiscan.io/tx/0xa7f8d500da701b028d037740a5f74a73eaaff7d344526484812e96ef354cae26) \ No newline at end of file From 0e83a43c80792bba313ed5758d4f7c4224551d46 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 19:31:40 -0800 Subject: [PATCH 32/38] chore(pnpm): format --- packages/handlefi/src/test-transactions.ts | 34 ++++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/handlefi/src/test-transactions.ts b/packages/handlefi/src/test-transactions.ts index 83a219fbb..354c1bbf6 100644 --- a/packages/handlefi/src/test-transactions.ts +++ b/packages/handlefi/src/test-transactions.ts @@ -2,7 +2,13 @@ import { type SwapActionParams, GreaterThanOrEqual, } from '@rabbitholegg/questdk' -import { parseEther, parseUnits, zeroAddress, getAddress, type Address } from 'viem' +import { + parseEther, + parseUnits, + zeroAddress, + getAddress, + type Address, +} from 'viem' import { createTestCase, type TestParams } from './utils' import { ARBITRUM_ONE } from './constants' @@ -552,23 +558,33 @@ export const passingTestCases = [ 'when routed through HLPcurveV2 contract (ETH to tokens) using checksummed token addresses', { tokenIn: getAddress(HLP_CURVE_V2_ETH_TO_CURVE.params.tokenIn as Address), - tokenOut: getAddress(HLP_CURVE_V2_ETH_TO_CURVE.params.tokenOut as Address), + tokenOut: getAddress( + HLP_CURVE_V2_ETH_TO_CURVE.params.tokenOut as Address, + ), }, ), createTestCase( HLP_CURVE_V2_PEGGED_TO_CURVE, 'when routed through HLPcurveV2 contract (Pegged to Curve) using checksummed token addresses', { - tokenIn: getAddress(HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenIn as Address), - tokenOut: getAddress(HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenOut as Address), + tokenIn: getAddress( + HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenIn as Address, + ), + tokenOut: getAddress( + HLP_CURVE_V2_PEGGED_TO_CURVE.params.tokenOut as Address, + ), }, ), createTestCase( HLP_CURVE_V2_TOKEN_TO_CURVE, 'when routed through HLPcurveV2 contract (Token to Curve) using checksummed token addresses', { - tokenIn: getAddress(HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenIn as Address), - tokenOut: getAddress(HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenOut as Address), + tokenIn: getAddress( + HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenIn as Address, + ), + tokenOut: getAddress( + HLP_CURVE_V2_TOKEN_TO_CURVE.params.tokenOut as Address, + ), }, ), createTestCase( @@ -597,7 +613,7 @@ export const passingTestCases = [ ), createTestCase( CURVE_FACTORY_2POOL, - 'when routed through curve 2pool using any token', + 'when routed through curve 2pool using checksummed token addresses', { tokenIn: getAddress(CURVE_FACTORY_2POOL.params.tokenIn as Address), tokenOut: getAddress(CURVE_FACTORY_2POOL.params.tokenOut as Address), @@ -918,14 +934,14 @@ export const failingTestCases = [ HPSM2_WITHDRAW, 'when routed through HSPM2 contract (withdraw) and amountIn is not sufficient', { - amountIn: GreaterThanOrEqual(parseEther('1000000')) + amountIn: GreaterThanOrEqual(parseEther('1000000')), }, ), createTestCase( HPSM2_DEPOSIT, 'when routed through HSPM2 contract (deposit) and amountIn is not sufficient', { - amountIn: GreaterThanOrEqual(parseEther('1000000')) + amountIn: GreaterThanOrEqual(parseEther('1000000')), }, ), createTestCase( From 379e2aa813ef0592b23c67d34ef6f4d0eb90a88b Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 19:36:05 -0800 Subject: [PATCH 33/38] chore(pnpm): generate changes for handlefi swap plugin --- .changeset/gold-socks-dream.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/gold-socks-dream.md diff --git a/.changeset/gold-socks-dream.md b/.changeset/gold-socks-dream.md new file mode 100644 index 000000000..d20bf094d --- /dev/null +++ b/.changeset/gold-socks-dream.md @@ -0,0 +1,6 @@ +--- +"@rabbitholegg/questdk-plugin-handlefi": minor +"@rabbitholegg/questdk-plugin-registry": minor +--- + +add support for handlefi swap plugin to questdk From 2c1a6243e2223ad15918685af43a22b098a17878 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 19:38:39 -0800 Subject: [PATCH 34/38] docs(handlefi): typo --- packages/handlefi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/handlefi/README.md b/packages/handlefi/README.md index a42fa5daf..910d2dacb 100644 --- a/packages/handlefi/README.md +++ b/packages/handlefi/README.md @@ -7,7 +7,7 @@ Limitations # HandleFi Plugin ## Overview -HandleFi is a decentralised multi currency stablecoin protocol based on Arbitrum. They offer sevearl products including perpetual swaps, convert, staking, and fxTokens. +HandleFi is a decentralised multi currency stablecoin protocol based on Arbitrum. They offer several products including perpetual swaps, convert, staking, and fxTokens. ### Swap Plugin From e83fc3dcffb6ed79c2b759f05ffb382c833538c0 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Sat, 23 Dec 2023 19:41:07 -0800 Subject: [PATCH 35/38] docs(handlefi): typo --- packages/handlefi/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/handlefi/README.md b/packages/handlefi/README.md index 910d2dacb..7d0796c0e 100644 --- a/packages/handlefi/README.md +++ b/packages/handlefi/README.md @@ -15,9 +15,8 @@ The swap plugin tragets handlefis [convert feature](https://app.handle.fi/conver ##### Limitations - amountOut may not be accurate due to some methods using `amountOutMin` which takes into account the amount of slippage set. -- amountOut will not be considered in the swap is routed through the HPSM2 contract. +- amountOut will not be considered if the swap is routed through the HPSM2 contract. - trades routed through curve V2 factory may have some false positives. Since there is not a really good way to tell what pool it is without having the contract address passed in as an argument. A false positive can occur if the tokenOut is selected as USDT and USDC.e is traded, and vice-versa. -- There should be no limitations with the current swap plugin. Everything should work as expected. ##### Sample Transactions - [Paraswap](https://dashboard.tenderly.co/tx/arbitrum/0xdc4f726560293b41a0ee72048e2d94970a45a046d88447444dab8bc54cb25a94) From bd12f251b60b4f61955dde08f899e70abc5fa28d Mon Sep 17 00:00:00 2001 From: Mmackz Date: Tue, 2 Jan 2024 20:36:16 -0800 Subject: [PATCH 36/38] refactor(handlefi): pass partner as param to function --- packages/handlefi/src/HandleFi.ts | 9 +++++++-- packages/handlefi/src/constants.ts | 3 +++ packages/handlefi/src/input-filters.ts | 15 +++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/handlefi/src/HandleFi.ts b/packages/handlefi/src/HandleFi.ts index 165f7f783..4a3c4a1bd 100644 --- a/packages/handlefi/src/HandleFi.ts +++ b/packages/handlefi/src/HandleFi.ts @@ -4,7 +4,12 @@ import { compressJson, } from '@rabbitholegg/questdk' import { zeroAddress, type Address } from 'viem' -import { ARBITRUM_ONE, SWAP_CONTRACTS, TOKEN_ADDRESSES } from './constants' +import { + ARBITRUM_ONE, + SWAP_CONTRACTS, + TOKEN_ADDRESSES, + PARASWAP_PARTNER, +} from './constants' import { getParaSwapFilter, getV2RouterFilter, @@ -27,7 +32,7 @@ export const swap = async ( }, input: { $or: [ - getParaSwapFilter(swap), + getParaSwapFilter(swap, PARASWAP_PARTNER), getV2RouterFilter(swap), getHPSM2Filter(swap), getHlpCurveV2Filter(swap), diff --git a/packages/handlefi/src/constants.ts b/packages/handlefi/src/constants.ts index a30dc60c9..5087b9a16 100644 --- a/packages/handlefi/src/constants.ts +++ b/packages/handlefi/src/constants.ts @@ -30,3 +30,6 @@ const ARB = '0x912CE59144191C1204E64559FE8253a0e49E6548' const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' export const TOKEN_ADDRESSES = [FX_USD, FOREX, ARB, USDC, WETH] as Address[] + +// Paraswap Partner Address +export const PARASWAP_PARTNER = '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A' diff --git a/packages/handlefi/src/input-filters.ts b/packages/handlefi/src/input-filters.ts index 135bae0d5..eda8ab489 100644 --- a/packages/handlefi/src/input-filters.ts +++ b/packages/handlefi/src/input-filters.ts @@ -1,5 +1,5 @@ import { type SwapActionParams } from '@rabbitholegg/questdk' -import { getAddress, zeroAddress } from 'viem' +import { getAddress, zeroAddress, type Address } from 'viem' import { buildV2PathQueryWithCase } from './utils' import { PARASWAP_ABI, @@ -11,7 +11,10 @@ import { } from './abi' import { WETH } from './constants' -export function getParaSwapFilter(params: SwapActionParams) { +export function getParaSwapFilter( + params: SwapActionParams, + partner: Address | undefined, +) { const { tokenIn, tokenOut, amountIn, amountOut } = params const internalEthAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' const tokenInUsed = tokenIn === zeroAddress ? internalEthAddress : tokenIn @@ -27,7 +30,7 @@ export function getParaSwapFilter(params: SwapActionParams) { fromAmount: amountIn, toAmount: amountOut, toToken: tokenOutUsed, - partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + partner, }, }, { @@ -41,7 +44,7 @@ export function getParaSwapFilter(params: SwapActionParams) { to: tokenOutUsed, }, }, - partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + partner, }, }, { @@ -59,7 +62,7 @@ export function getParaSwapFilter(params: SwapActionParams) { }, }, }, - partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + partner, }, }, { @@ -68,7 +71,7 @@ export function getParaSwapFilter(params: SwapActionParams) { assets: buildV2PathQueryWithCase('lower', tokenIn, tokenOut), fromAmount: amountIn, toAmount: amountOut, - partner: '0xFa2c1bE677BE4BEc8851D1577B343F7060B51E3A', + partner, }, }, ], From 52ee8f0743ba0003fcd5606ea67c677c3a28be68 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Tue, 2 Jan 2024 20:36:30 -0800 Subject: [PATCH 37/38] chore(pnpm): regen lockfile --- pnpm-lock.yaml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9b1ddd56..fc6f5450c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -217,16 +217,16 @@ importers: viem: ^1.16.6 vitest: ^0.33.0 dependencies: - '@rabbitholegg/questdk': 2.0.0-alpha.28_typescript@5.3.2 - viem: 1.19.11_typescript@5.3.2 + '@rabbitholegg/questdk': 2.0.0-alpha.28_typescript@5.3.3 + viem: 1.21.0_typescript@5.3.3 devDependencies: - '@types/node': 20.10.3 + '@types/node': 20.10.5 '@vitest/coverage-v8': 0.33.0_vitest@0.33.0 rimraf: 5.0.5 rome: 12.1.3 - ts-node: 10.9.1_xy5pmmm77qgfdfg5jflxsqkm74 + ts-node: 10.9.2_7ln3lwozyybesesf4lghtaucbi tsconfig: link:../tsconfig - typescript: 5.3.2 + typescript: 5.3.3 vitest: 0.33.0 packages/hop: @@ -2410,7 +2410,7 @@ packages: optional: true dependencies: abitype: 0.9.10_typescript@5.1.6 - rimraf: 5.0.1 + rimraf: 5.0.5 typescript: 5.1.6 viem: 1.21.0_typescript@5.1.6 transitivePeerDependencies: @@ -2428,7 +2428,7 @@ packages: optional: true dependencies: abitype: 0.9.10_typescript@5.3.3 - rimraf: 5.0.1 + rimraf: 5.0.5 typescript: 5.3.3 viem: 1.21.0_typescript@5.3.3 transitivePeerDependencies: @@ -2493,7 +2493,7 @@ packages: resolution: {integrity: sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==} dependencies: '@noble/curves': 1.0.0 - '@noble/hashes': 1.3.0 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.5 dev: false @@ -2516,7 +2516,7 @@ packages: /@scure/bip39/1.2.0: resolution: {integrity: sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==} dependencies: - '@noble/hashes': 1.3.0 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.5 dev: false @@ -2788,6 +2788,7 @@ packages: /@types/node/20.4.5: resolution: {integrity: sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg==} + dev: true /@types/normalize-package-data/2.4.4: resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -2848,7 +2849,7 @@ packages: /@types/ws/8.5.10: resolution: {integrity: sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==} dependencies: - '@types/node': 20.4.5 + '@types/node': 20.10.5 dev: false /@uniswap/lib/4.0.1-alpha: @@ -8616,6 +8617,7 @@ packages: hasBin: true dependencies: glob: 10.3.10 + dev: true /rimraf/5.0.5: resolution: {integrity: sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==} @@ -8623,7 +8625,6 @@ packages: hasBin: true dependencies: glob: 10.3.10 - dev: true /ripemd160/2.0.2: resolution: {integrity: sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==} @@ -11132,7 +11133,7 @@ packages: /wide-align/1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} dependencies: - string-width: 1.0.2 + string-width: 4.2.3 dev: false optional: true From 4a116f7fc8d1f393ad0d174718bc7e64c59bf3b2 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Tue, 2 Jan 2024 20:37:00 -0800 Subject: [PATCH 38/38] refactor(handlefi): remove unused Chains enum from utils --- packages/handlefi/src/utils.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/handlefi/src/utils.ts b/packages/handlefi/src/utils.ts index d8c55744d..52f389726 100644 --- a/packages/handlefi/src/utils.ts +++ b/packages/handlefi/src/utils.ts @@ -1,11 +1,6 @@ import type { ActionParams, FilterOperator } from '@rabbitholegg/questdk' import { getAddress, type Address, type Hash } from 'viem' -export enum Chains { - ARBITRUM_ONE = 42161, - AVALANCHE = 43114, -} - interface Transaction { chainId: number from: Address