diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..93e382a3 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +module.exports = { + moduleNameMapper: { + // force resolve `axios` mopdule as CommonJS + // axios@>1.0.0 breaks in jest otherwise + '^axios$': require.resolve('axios'), + }, +}; diff --git a/package.json b/package.json index ebd739b9..a5c921c9 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@size-limit/preset-small-lib": "^7.0.8", "@tsconfig/recommended": "^1.0.1", - "axios": "^0.27.2", + "axios": "^1.1.3", "dotenv": "^16.0.0", "dts-cli": "^1.5.1", "ethers": "^5.6.5", @@ -67,7 +67,7 @@ "web3": "^1.7.3" }, "peerDependencies": { - "axios": ">=0.25.0 <1.0.0", + "axios": ">=0.25.0 <2.0.0", "ethers": "^5.5.0", "web3": "^1.7.1" }, diff --git a/src/helpers/fetchers/axios.ts b/src/helpers/fetchers/axios.ts index d88abf2c..12de30ce 100644 --- a/src/helpers/fetchers/axios.ts +++ b/src/helpers/fetchers/axios.ts @@ -1,9 +1,11 @@ import type { FetcherFunction } from '../../types'; -import type AxiosStatic from 'axios'; +import type { AxiosStatic } from 'axios'; import { FetcherError } from '../misc'; +export type AxiosRequirement = Pick; + export const constructFetcher = - (axios: typeof AxiosStatic): FetcherFunction => + (axios: AxiosRequirement): FetcherFunction => async (params) => { try { const { data } = await axios.request(params); diff --git a/src/legacy/index.ts b/src/legacy/index.ts index c7206721..7638ec2e 100644 --- a/src/legacy/index.ts +++ b/src/legacy/index.ts @@ -1,4 +1,3 @@ -import type { AxiosStatic } from 'axios'; import type Web3 from 'web3'; import type { SendOptions } from 'web3-eth-contract'; import type { ContractTransaction } from '@ethersproject/contracts'; @@ -36,6 +35,7 @@ import type { } from '../methods/swap/transaction'; import type { AddressOrSymbol, Token, FetcherFunction } from '../types'; import type { Allowance } from '../methods/swap/balance'; +import type { AxiosRequirement } from '../helpers/fetchers/axios'; import { isDataWithError } from '../helpers/misc'; export type APIError = { @@ -53,7 +53,7 @@ type LegacyOptions = { web3Provider?: Web3; ethersDeps?: EthersProviderDeps; // need to be a provider with signer for approve requests account?: Address; - axios?: AxiosStatic; + axios?: AxiosRequirement; fetch?: Fetch; }; diff --git a/src/methods/limitOrders/helpers/types.ts b/src/methods/limitOrders/helpers/types.ts index ad345a8d..4cad9dd0 100644 --- a/src/methods/limitOrders/helpers/types.ts +++ b/src/methods/limitOrders/helpers/types.ts @@ -1,20 +1,9 @@ import type { OrderData } from './buildOrderData'; -export type LimitOrderStatus = - | 'open' - | 'filled' - | 'partiallyFilled' - | 'expired' - | 'canceled' - | 'unknown'; - export type LimitOrderType = 'LIMIT' | 'P2P'; -export type LimitOrder = LimitOrderFromApi & { - status: LimitOrderStatus; // `status` likely not available from API - amountFilled?: string; - transactionHashes?: string[]; -}; +export type LimitOrder = LimitOrderFromApi; + export type LimitOrderToSend = OrderData & { permitMakerAsset?: string; signature: string; @@ -34,7 +23,12 @@ export type LimitOrderApiResponse = { // display states such as EXPIRED and PARTIALLY_FILLLED derived on client side // returned by API but can be calculated too, EXPIRED == order.expiry < Date.now()/1000 // PARTIALLY_FILLED == order.fillableBalance < order.makerAmount && order.fillableBalance !== '0' -export type LimitOrderState = 'PENDING' | 'FULFILLED' | 'CANCELLED' | 'EXPIRED'; +export type LimitOrderState = + | 'DRAFT' + | 'PENDING' + | 'FULFILLED' + | 'CANCELLED' + | 'EXPIRED'; export type LimitOrderEvent = ''; diff --git a/src/methods/swap/transaction.ts b/src/methods/swap/transaction.ts index a3ae5db5..d6ba3c61 100644 --- a/src/methods/swap/transaction.ts +++ b/src/methods/swap/transaction.ts @@ -60,6 +60,8 @@ export type BuildTxInputBase = { srcToken: Address; destToken: Address; userAddress: Address; + /** @description used with referral link */ + referrer?: string; partner?: string; partnerAddress?: string; partnerFeeBps?: number; diff --git a/src/sdk/simple.ts b/src/sdk/simple.ts index db23ff0b..c4ef437c 100644 --- a/src/sdk/simple.ts +++ b/src/sdk/simple.ts @@ -37,7 +37,6 @@ import type { import type { EthersProviderDeps } from '../helpers'; import type Web3 from 'web3'; -import type AxiosStatic from 'axios'; import type { SwapSDKMethods } from './full'; import { BuildLimitOrderFunctions, @@ -90,6 +89,7 @@ import { } from '../methods/nftOrders'; import { constructSwapSDK } from '../methods/swap'; +import type { AxiosRequirement } from '../helpers/fetchers/axios'; export type SwapFetchMethods = GetBalancesFunctions & GetTokensFunctions & @@ -124,7 +124,7 @@ export type SimpleSDK = { export type FetcherOptions = | { - axios: typeof AxiosStatic; + axios: AxiosRequirement; } | { fetch: typeof fetch }; diff --git a/src/types.ts b/src/types.ts index afe03455..d54bb22e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -50,6 +50,8 @@ export interface ConstructFetchInput extends ConstructBaseInput { interface OverridesBase { from?: string; gasPrice?: string; + maxFeePerGas?: string; + maxPriorityFeePerGas?: string; gas?: number; value?: number | string; } diff --git a/tests/__snapshots__/limitOrders.test.ts.snap b/tests/__snapshots__/limitOrders.test.ts.snap index 3899c93e..756b7757 100644 --- a/tests/__snapshots__/limitOrders.test.ts.snap +++ b/tests/__snapshots__/limitOrders.test.ts.snap @@ -14,28 +14,26 @@ Object { "swapExchanges": Array [ Object { "data": Object { - "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", - "feeFactor": 10000, "gasUSD": "---", - "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", "path": Array [ - "0x6b175474e89094c44da98b954eedeac495271d0f", - "0x0d8775f648430679a709e98d2b0cb6250d2887ef", - ], - "pools": Array [ Object { - "address": "0x6929abD7931D0243777d3CD147fE863646A752ba", - "direction": false, - "fee": 30, + "fee": "500", + "tokenIn": "0x6b175474e89094c44da98b954eedeac495271d0f", + "tokenOut": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + }, + Object { + "fee": "3000", + "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "tokenOut": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", }, ], - "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", }, "destAmount": "6000000000000000000", - "exchange": "UniswapV2", + "exchange": "UniswapV3", "percent": 100, "poolAddresses": Array [ - "0x6929abD7931D0243777d3CD147fE863646A752ba", + "0x60594a405d53811d3BC4766596EFD80fd545A270", + "0xAE614a7a56cB79c04Df2aeBA6f5dAB80A39CA78E", ], "srcAmount": "---", }, @@ -51,7 +49,7 @@ Object { "destDecimals": 18, "destToken": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", "destUSD": "---", - "gasCost": "189300", + "gasCost": "206300", "gasCostUSD": "---", "hmac": "---", "maxImpactReached": false, diff --git a/tests/limitOrders.test.ts b/tests/limitOrders.test.ts index 77704060..855ae21f 100644 --- a/tests/limitOrders.test.ts +++ b/tests/limitOrders.test.ts @@ -941,6 +941,7 @@ describe('Limit Orders', () => { srcToken, destToken, userAddress: senderAddress, + options: { includeDEXS: ['UniswapV3'] }, }, [order] ); diff --git a/tests/nftOrders.test.ts b/tests/nftOrders.test.ts index 0fde1fc9..15db38b9 100644 --- a/tests/nftOrders.test.ts +++ b/tests/nftOrders.test.ts @@ -1111,16 +1111,12 @@ describe('NFT Orders', () => { "swapExchanges": Array [ Object { "data": Object { - "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", - "feeFactor": 10000, "gasUSD": "---", - "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", "path": "---", "pools": "---", - "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", }, "destAmount": "6000000000000000000", - "exchange": "UniswapV2", + "exchange": "UniswapV3", "percent": 100, "poolAddresses": Array [ "---", @@ -1139,7 +1135,7 @@ describe('NFT Orders', () => { "destDecimals": 18, "destToken": "0x4fabb145d64652a948d72533023f6e7a623c7c53", "destUSD": "---", - "gasCost": "276300", + "gasCost": "154300", "gasCostUSD": "---", "hmac": "---", "maxImpactReached": false, diff --git a/yarn.lock b/yarn.lock index 13ccaaea..349ac336 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2258,13 +2258,14 @@ axe-core@^4.3.5: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413" integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw== -axios@^0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== +axios@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35" + integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA== dependencies: - follow-redirects "^1.14.9" + follow-redirects "^1.15.0" form-data "^4.0.0" + proxy-from-env "^1.1.0" axobject-query@^2.2.0: version "2.2.0" @@ -4285,10 +4286,10 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3" integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg== -follow-redirects@^1.14.9: - version "1.15.0" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4" - integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== +follow-redirects@^1.15.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== foreach@^2.0.5: version "2.0.5" @@ -6807,6 +6808,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + psl@^1.1.28, psl@^1.1.33: version "1.8.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"