From 14d6ae1bfcf6f2b2d211e15b66690533e7f5394f Mon Sep 17 00:00:00 2001 From: nikoferro Date: Fri, 22 Mar 2024 10:49:07 +0100 Subject: [PATCH 1/4] feat: add base constants --- src/constants.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index b8a4243b..020abade 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -13,6 +13,7 @@ export const OPTIMISM_CHAIN_ID = toHex('10'); export const ZKSYNC_ERA_CHAIN_ID = toHex('324'); export const LINEA_CHAIN_ID = toHex('59144'); export const SWAPS_TESTNET_CHAIN_ID = toHex('1337'); +export const BASE_CHAIN_ID = toHex('8453'); export const CHAIN_ID_TO_NAME_MAP: { [key: string]: string } = { [ETH_CHAIN_ID]: 'ethereum', @@ -24,6 +25,7 @@ export const CHAIN_ID_TO_NAME_MAP: { [key: string]: string } = { [ZKSYNC_ERA_CHAIN_ID]: 'zksync', [LINEA_CHAIN_ID]: 'linea', [SWAPS_TESTNET_CHAIN_ID]: 'ethereum', + [BASE_CHAIN_ID]: 'base', }; //* APIs base urls @@ -50,6 +52,8 @@ export const ZKSYNC_ERA_SWAPS_CONTRACT_ADDRESS = '0xf504c1fe13d14df615e66dcd0abf39e60c697f34'; export const LINEA_SWAPS_CONTRACT_ADDRESS = '0x9dda6ef3d919c9bc8885d5560999a3640431e8e6'; +export const BASE_SWAPS_CONTRACT_ADDRESS = + '0x9dda6ef3d919c9bc8885d5560999a3640431e8e6'; export const WETH_CONTRACT_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; @@ -67,6 +71,8 @@ export const WETH_ZKSYNC_ERA_CONTRACT_ADDRESS = '0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91'; export const WETH_LINEA_CONTRACT_ADDRESS = '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f'; +export const WETH_BASE_CONTRACT_ADDRESS = + '0x4200000000000000000000000000000000000006'; export const SWAPS_WRAPPED_TOKENS_ADDRESSES: { [key: string]: string } = { [ETH_CHAIN_ID]: WETH_CONTRACT_ADDRESS, @@ -78,6 +84,7 @@ export const SWAPS_WRAPPED_TOKENS_ADDRESSES: { [key: string]: string } = { [OPTIMISM_CHAIN_ID]: WETH_OPTIMISM_CONTRACT_ADDRESS, [ZKSYNC_ERA_CHAIN_ID]: WETH_ZKSYNC_ERA_CONTRACT_ADDRESS, [LINEA_CHAIN_ID]: WETH_LINEA_CONTRACT_ADDRESS, + [BASE_CHAIN_ID]: WETH_BASE_CONTRACT_ADDRESS, }; export const SWAPS_CONTRACT_ADDRESSES: { [key: string]: string } = { @@ -90,6 +97,7 @@ export const SWAPS_CONTRACT_ADDRESSES: { [key: string]: string } = { [OPTIMISM_CHAIN_ID]: OPTIMISM_SWAPS_CONTRACT_ADDRESS, [ZKSYNC_ERA_CHAIN_ID]: ZKSYNC_ERA_SWAPS_CONTRACT_ADDRESS, [LINEA_CHAIN_ID]: LINEA_SWAPS_CONTRACT_ADDRESS, + [BASE_CHAIN_ID]: BASE_SWAPS_CONTRACT_ADDRESS, }; export const ALLOWED_CONTRACT_ADDRESSES: { [key: string]: string[] } = { @@ -129,6 +137,10 @@ export const ALLOWED_CONTRACT_ADDRESSES: { [key: string]: string[] } = { SWAPS_CONTRACT_ADDRESSES[LINEA_CHAIN_ID], SWAPS_WRAPPED_TOKENS_ADDRESSES[LINEA_CHAIN_ID], ], + [BASE_CHAIN_ID]: [ + SWAPS_CONTRACT_ADDRESSES[BASE_CHAIN_ID], + SWAPS_WRAPPED_TOKENS_ADDRESSES[BASE_CHAIN_ID], + ], }; //* Tokens @@ -180,6 +192,10 @@ export const LINEA_SWAPS_TOKEN_OBJECT: SwapsToken = { ...ETH_SWAPS_TOKEN_OBJECT, }; +export const BASE_SWAPS_TOKEN_OBJECT: SwapsToken = { + ...ETH_SWAPS_TOKEN_OBJECT, +}; + export const SWAPS_NATIVE_TOKEN_OBJECTS: { [key: string]: SwapsToken } = { [ETH_CHAIN_ID]: ETH_SWAPS_TOKEN_OBJECT, [SWAPS_TESTNET_CHAIN_ID]: ETH_SWAPS_TOKEN_OBJECT, @@ -190,6 +206,7 @@ export const SWAPS_NATIVE_TOKEN_OBJECTS: { [key: string]: SwapsToken } = { [OPTIMISM_CHAIN_ID]: OPTIMISM_SWAPS_TOKEN_OBJECT, [ZKSYNC_ERA_CHAIN_ID]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT, [LINEA_CHAIN_ID]: LINEA_SWAPS_TOKEN_OBJECT, + [BASE_CHAIN_ID]: BASE_SWAPS_TOKEN_OBJECT, }; //* Other From d9842086d2e8509db13105712b7c59f9c59eaeca Mon Sep 17 00:00:00 2001 From: nikoferro Date: Tue, 16 Apr 2024 14:48:38 +0200 Subject: [PATCH 2/4] fix: web3 import + better compiler options + dependencies list --- .eslintignore | 5 ++ .eslintrc | 73 ++++++++++++++++++++++++++++ .eslintrc.js | 78 ----------------------------- .prettierrc | 6 +++ .prettierrc.js | 8 --- package.json | 2 +- src/SwapsController.ts | 5 +- tsconfig.json | 9 ++-- yarn.lock | 108 +++++++++++++++++++++++++++++------------ 9 files changed, 172 insertions(+), 122 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc delete mode 100644 .eslintrc.js create mode 100644 .prettierrc delete mode 100644 .prettierrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..2a7d4513 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +node_modules +dist +coverage +*.test.ts + diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..8aeba5b2 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,73 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint", "jest"], + "overrides": [ + { + "files": ["*.ts"], + "extends": ["@metamask/eslint-config-typescript"] + }, + { + "files": ["*.d.ts"], + "parserOptions": { + "sourceType": "script" + } + }, + { + "files": ["*.js"], + "parserOptions": { + "sourceType": "script" + }, + "extends": ["@metamask/eslint-config-nodejs"] + }, + { + "files": ["*.test.ts", "*.test.js"], + "extends": ["@metamask/eslint-config-jest"] + }, + { + "files": ["src/SwapsController.ts"], + "rules": { + "accessor-pairs": "off", + "consistent-return": "off", + "no-async-promise-executor": "off", + "@typescript-eslint/prefer-optional-chain": "off", + "no-restricted-syntax": "off", + "import/no-named-as-default": "off", + } + }, + { + "files": ["src/SwapsController.test.ts"], + "rules": { + "no-new": "off" + } + }, + { + "files": ["src/swapsInterfaces.ts"], + "rules": { + "@typescript-eslint/naming-convention": "off" + } + }, + { + "files": ["src/swapsUtil.ts"], + "rules": { + "consistent-return": "off", + "no-negated-condition": "off", + "@typescript-eslint/naming-convention": "off" + } + }, + { + "files": ["src/swapsUtil.test.ts"], + "rules": { + "jest/require-to-throw-message": "off", + "@typescript-eslint/naming-convention": "off", + "no-restricted-globals": "off" + } + } + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:jest/recommended", + "@metamask/eslint-config" + ] +} diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index b71e8558..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,78 +0,0 @@ -module.exports = { - root: true, - - extends: ['@metamask/eslint-config'], - - overrides: [ - { - files: ['*.ts'], - extends: ['@metamask/eslint-config-typescript'], - }, - - { - files: ['*.d.ts'], - parserOptions: { - sourceType: 'script', - }, - }, - - { - files: ['*.js'], - parserOptions: { - sourceType: 'script', - }, - extends: ['@metamask/eslint-config-nodejs'], - }, - - { - files: ['*.test.ts', '*.test.js'], - extends: ['@metamask/eslint-config-jest'], - }, - - // TODO: Enable these - { - files: ['src/SwapsController.ts'], - rules: { - 'accessor-pairs': 'off', - 'consistent-return': 'off', - 'no-async-promise-executor': 'off', - '@typescript-eslint/prefer-optional-chain': 'off', - // ignoring this to avoid changing the controller interface - 'no-restricted-syntax': 'off', - }, - }, - { - files: ['src/SwapsController.test.ts'], - rules: { - 'no-new': 'off', - }, - }, - { - files: ['src/swapsInterfaces.ts'], - rules: { - // disabling this since enums affected are used in other controllers/clients - '@typescript-eslint/naming-convention': 'off', - }, - }, - { - files: ['src/swapsUtil.ts'], - rules: { - 'consistent-return': 'off', - 'no-negated-condition': 'off', - // disabling this since enums affected are used in other controllers/clients - '@typescript-eslint/naming-convention': 'off', - }, - }, - { - files: ['src/swapsUtil.test.ts'], - rules: { - 'jest/require-to-throw-message': 'off', - // disabling this since enums affected are used in other controllers/clients - '@typescript-eslint/naming-convention': 'off', - 'no-restricted-globals': 'off', - }, - }, - ], - - ignorePatterns: ['!.eslintrc.js', '!.prettierrc.js', 'dist/'], -}; diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..fa83705a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "quoteProps": "as-needed", + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all" +} diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index b2d98d2e..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,8 +0,0 @@ -// All of these are defaults except singleQuote, but we specify them -// for explicitness -module.exports = { - quoteProps: 'as-needed', - singleQuote: true, - tabWidth: 2, - trailingComma: 'all', -}; diff --git a/package.json b/package.json index ff65dc1e..e99512d7 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "@metamask/eslint-config-jest": "^12.1.0", "@metamask/eslint-config-nodejs": "^12.1.0", "@metamask/eslint-config-typescript": "^12.1.0", - "@metamask/ethjs-query": "0.5.3", "@types/ethereumjs-util": "^6.1.0", "@types/jest": "^26.0.22", "@types/node": "^20.10.4", @@ -64,6 +63,7 @@ "dependencies": { "@metamask/controllers": "^33.0.0", "@metamask/eth-query": "^4.0.0", + "@metamask/ethjs-query": "0.5.3", "@metamask/controller-utils": "^8.0.2", "@metamask/utils": "^8.3.0", "abort-controller": "^3.0.0", diff --git a/src/SwapsController.ts b/src/SwapsController.ts index 83458e1d..7f40c13a 100644 --- a/src/SwapsController.ts +++ b/src/SwapsController.ts @@ -22,7 +22,7 @@ import type { Hex } from '@metamask/utils'; import { Mutex } from 'async-mutex'; import { BigNumber } from 'bignumber.js'; import abiERC20 from 'human-standard-token-abi'; -import { Web3 } from 'web3'; +import * as web3 from 'web3'; import type { APIAggregatorMetadata, @@ -59,6 +59,9 @@ import { shouldEnableDirectWrapping, } from './swapsUtil'; +// hack to fix web3 import issue after transpiling +const Web3 = web3.Web3 === undefined ? web3.default : web3.Web3; + // Functions to determine type of the return value from GasFeeController /** diff --git a/tsconfig.json b/tsconfig.json index 1d9aa090..cc2c8502 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,20 @@ { "compilerOptions": { + "allowJs": true, "declaration": true, "declarationDir": "dist", "inlineSources": true, "esModuleInterop": true, - "lib": ["DOM", "ES2020"], + "forceConsistentCasingInFileNames": true, "module": "CommonJS", "moduleResolution": "Node", "noUnusedLocals": true, "noUnusedParameters": true, "outDir": "dist", - "rootDir": "./src", "sourceMap": true, "strict": true, - "target": "ES2017" + "target": "ESNext" }, - "include": ["src/**/*.ts", "src/**/*.test.ts"] + "include": ["src/**/*.ts"], + "exclude": ["src/**/*.test.ts", "node_modules"] } diff --git a/yarn.lock b/yarn.lock index 8567147c..84d7daaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6876,33 +6876,33 @@ web3-eth-accounts@^4.1.0, web3-eth-accounts@^4.1.1: web3-utils "^4.1.1" web3-validator "^2.0.4" -web3-eth-contract@^4.1.2, web3-eth-contract@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/web3-eth-contract/-/web3-eth-contract-4.2.0.tgz#73f70b19217cd4854211c05846f0c841763b3b29" - integrity sha512-K7bUypsomTs8/Oa0Lgvq5plsSB5afgKJ79NMuXxvC5jfV+AxNrQyKcr5Vd5yEGNqrdQuIPduGQa8DpuY+rMe1g== +web3-eth-contract@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/web3-eth-contract/-/web3-eth-contract-4.3.0.tgz#5cacbac25f9dbb27bea90ea99fea290e5ebd3f87" + integrity sha512-4fzSklA65zUn6SthU3T3tbVJacfP8/wkJmCuvmPaf2ZTFdnhsF96G5IQtCRf0+wASb4yk0A6IBvXZfk1B4R4HA== dependencies: web3-core "^4.3.2" web3-errors "^1.1.4" - web3-eth "^4.4.0" + web3-eth "^4.5.0" web3-eth-abi "^4.2.0" - web3-types "^1.3.1" - web3-utils "^4.1.1" - web3-validator "^2.0.4" + web3-types "^1.5.0" + web3-utils "^4.2.2" + web3-validator "^2.0.5" -web3-eth-ens@^4.0.8: - version "4.0.8" - resolved "https://registry.yarnpkg.com/web3-eth-ens/-/web3-eth-ens-4.0.8.tgz#f4e0a018ce6cc69e37007ee92063867feb5994f0" - integrity sha512-nj0JfeD45BbzVJcVYpUJnSo8iwDcY9CQ7CZhhIVVOFjvpMAPw0zEwjTvZEIQyCW61OoDG9xcBzwxe2tZoYhMRw== +web3-eth-ens@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/web3-eth-ens/-/web3-eth-ens-4.2.0.tgz#8734b034efd48a735f7052fef0205653a78b84cb" + integrity sha512-qYj34te2UctoObt8rlEIY/t2MuTMiMiiHhO2JAHRGqSLCQ7b8DM3RpvkiiSB0N0ZyEn+CetZqJCTYb8DNKBS/g== dependencies: "@adraffy/ens-normalize" "^1.8.8" - web3-core "^4.3.0" - web3-errors "^1.1.3" - web3-eth "^4.3.1" - web3-eth-contract "^4.1.2" + web3-core "^4.3.2" + web3-errors "^1.1.4" + web3-eth "^4.5.0" + web3-eth-contract "^4.3.0" web3-net "^4.0.7" - web3-types "^1.3.0" - web3-utils "^4.0.7" - web3-validator "^2.0.3" + web3-types "^1.5.0" + web3-utils "^4.2.2" + web3-validator "^2.0.5" web3-eth-iban@^4.0.7: version "4.0.7" @@ -6926,7 +6926,7 @@ web3-eth-personal@^4.0.8: web3-utils "^4.0.7" web3-validator "^2.0.3" -web3-eth@^4.3.1, web3-eth@^4.4.0: +web3-eth@^4.3.1: version "4.4.0" resolved "https://registry.yarnpkg.com/web3-eth/-/web3-eth-4.4.0.tgz#755c34a769109836d122a53b33814d63f9ec5a65" integrity sha512-HswKdzF44wUrciRAtEJaml9O7rDYDxElHmFs+27WcO3nel2zku+n0xs4e2ZAehfrCZ+05/y7TgnOZnaDU8Fb/A== @@ -6943,6 +6943,23 @@ web3-eth@^4.3.1, web3-eth@^4.4.0: web3-utils "^4.1.1" web3-validator "^2.0.4" +web3-eth@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/web3-eth/-/web3-eth-4.5.0.tgz#57f5cc020c9b3c4c20d0dacbd87eaa1a9d6c86c0" + integrity sha512-crisE46o/SHMVm+XHAXEaR8k76NCImq+hi0QQEJ+VaLZbDobI/Gvog1HwTukDUDRgnYSAFGqD0cTRyAwDurwpA== + dependencies: + setimmediate "^1.0.5" + web3-core "^4.3.2" + web3-errors "^1.1.4" + web3-eth-abi "^4.2.0" + web3-eth-accounts "^4.1.1" + web3-net "^4.0.7" + web3-providers-ws "^4.0.7" + web3-rpc-methods "^1.2.0" + web3-types "^1.5.0" + web3-utils "^4.2.1" + web3-validator "^2.0.4" + web3-net@^4.0.7: version "4.0.7" resolved "https://registry.yarnpkg.com/web3-net/-/web3-net-4.0.7.tgz#ed2c1bd700cf94be93a6dbd8bd8aa413d8681942" @@ -7020,6 +7037,15 @@ web3-rpc-methods@^1.1.3, web3-rpc-methods@^1.1.4: web3-types "^1.3.1" web3-validator "^2.0.3" +web3-rpc-methods@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/web3-rpc-methods/-/web3-rpc-methods-1.2.0.tgz#761dcb036ab16edb2b03e80c11e3f5df24690345" + integrity sha512-CWJ/g4I4WyYvLkf21wCZAehdhU/VjX/OAPHnqF5/FPDJlogOsOnGXHqi1Z5AP+ocdt395PNubd8jyMMJoYGSBA== + dependencies: + web3-core "^4.3.2" + web3-types "^1.5.0" + web3-validator "^2.0.4" + web3-types@^1.3.0, web3-types@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/web3-types/-/web3-types-1.3.1.tgz#cf6148ad46b68c5c89714613380b270d31e297be" @@ -7041,6 +7067,17 @@ web3-utils@^4.0.7, web3-utils@^4.1.0, web3-utils@^4.1.1: web3-types "^1.5.0" web3-validator "^2.0.4" +web3-utils@^4.2.1, web3-utils@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-4.2.2.tgz#8fb7c58cfc02d681f17d7806732ce9fb1170c338" + integrity sha512-z+4owWcnoB4EH8yWIL1FBeyqe+sXwaGxUDtVTNPTMf2oB5C+paCToZUdCV5Bi+M543zZEzlzNTabOD+OWNc7NA== + dependencies: + ethereum-cryptography "^2.0.0" + eventemitter3 "^5.0.1" + web3-errors "^1.1.4" + web3-types "^1.5.0" + web3-validator "^2.0.5" + web3-validator@^2.0.3, web3-validator@^2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/web3-validator/-/web3-validator-2.0.4.tgz#66f34c94f21a3c94d0dc2a2d30deb8a379825d38" @@ -7052,6 +7089,17 @@ web3-validator@^2.0.3, web3-validator@^2.0.4: web3-types "^1.3.1" zod "^3.21.4" +web3-validator@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/web3-validator/-/web3-validator-2.0.5.tgz#de1984bdb34f292251b86400dba7169700db0849" + integrity sha512-2gLOSW8XqEN5pw5jVUm20EB7A8SbQiekpAtiI0JBmCIV0a2rp97v8FgWY5E3UEqnw5WFfEqvcDVW92EyynDTyQ== + dependencies: + ethereum-cryptography "^2.0.0" + util "^0.12.5" + web3-errors "^1.1.4" + web3-types "^1.5.0" + zod "^3.21.4" + web3@^0.20.7: version "0.20.7" resolved "https://registry.yarnpkg.com/web3/-/web3-0.20.7.tgz#1605e6d81399ed6f85a471a4f3da0c8be57df2f7" @@ -7064,26 +7112,26 @@ web3@^0.20.7: xmlhttprequest "*" web3@^4.2.2: - version "4.4.0" - resolved "https://registry.yarnpkg.com/web3/-/web3-4.4.0.tgz#83e5906675608adf9a14841f257e441c9154a8c7" - integrity sha512-WcFA3RgE+cyM96MHLPs5Ec155nkYQuwhjk3JIhxcy6J1QrZK2zvKGzTQCCYHe3JhraduNTMbWy+EeNNGGji9+Q== + version "4.7.0" + resolved "https://registry.yarnpkg.com/web3/-/web3-4.7.0.tgz#d6cb8ff8653b92f26ddd6da0957999e61ae7f107" + integrity sha512-3g+1e7B/IW0Nw9WP1dotrZKWD9o5IBfl27dxEnE1LxBZBax6ZkviiAwf18utIhlNBD07RgI+PPfKDXxfDBlHWA== dependencies: web3-core "^4.3.2" web3-errors "^1.1.4" - web3-eth "^4.4.0" + web3-eth "^4.5.0" web3-eth-abi "^4.2.0" web3-eth-accounts "^4.1.1" - web3-eth-contract "^4.2.0" - web3-eth-ens "^4.0.8" + web3-eth-contract "^4.3.0" + web3-eth-ens "^4.2.0" web3-eth-iban "^4.0.7" web3-eth-personal "^4.0.8" web3-net "^4.0.7" web3-providers-http "^4.1.0" web3-providers-ws "^4.0.7" - web3-rpc-methods "^1.1.4" - web3-types "^1.3.1" - web3-utils "^4.1.1" - web3-validator "^2.0.4" + web3-rpc-methods "^1.2.0" + web3-types "^1.5.0" + web3-utils "^4.2.2" + web3-validator "^2.0.5" webidl-conversions@^3.0.0: version "3.0.1" From 5cf2793f4f07cf25a65548e0cefc219e7924fd95 Mon Sep 17 00:00:00 2001 From: nikoferro Date: Wed, 17 Apr 2024 11:05:11 +0200 Subject: [PATCH 3/4] fix: using BN.js to fix how BNtoHex is called --- package.json | 1 + src/swapsUtil.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cae6b954..8a976eb3 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "abort-controller": "^3.0.0", "async-mutex": "^0.4.1", "bignumber.js": "^9.0.1", + "bn.js": "^5.2.1", "human-standard-token-abi": "^2.0.0", "web3": "^4.2.2" }, diff --git a/src/swapsUtil.ts b/src/swapsUtil.ts index 1c639720..951feaed 100644 --- a/src/swapsUtil.ts +++ b/src/swapsUtil.ts @@ -9,6 +9,7 @@ import type { Transaction } from '@metamask/transaction-controller'; import type { Hex } from '@metamask/utils'; import { add0x } from '@metamask/utils'; import { BigNumber } from 'bignumber.js'; +import { BN } from 'bn.js'; import { ALLOWED_CONTRACT_ADDRESSES, @@ -283,8 +284,8 @@ export async function fetchTradesInfo( to: quote.trade.to, from: quote.trade.from, data: quote.trade.data, - amount: BNToHex(new BigNumber(quote.trade.value)), - gas: BNToHex(quote.maxGas || new BigNumber(MAX_GAS_LIMIT)), + amount: BNToHex(new BN(quote.trade.value)), + gas: BNToHex(new BN(quote.maxGas) || new BN(MAX_GAS_LIMIT)), }); return { From 6e7e0a2d3e1d85134c2e54c6992e4504c1ad1b16 Mon Sep 17 00:00:00 2001 From: Nicolas Ferro Date: Wed, 17 Apr 2024 12:03:43 +0200 Subject: [PATCH 4/4] Update tsconfig.json Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com> --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index cc2c8502..9c85930e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "outDir": "dist", "sourceMap": true, "strict": true, - "target": "ESNext" + "target": "ES2020" }, "include": ["src/**/*.ts"], "exclude": ["src/**/*.test.ts", "node_modules"]