@velora-dex/sdk 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +494 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/examples/customFetcher.d.ts +3 -0
- package/dist/examples/customFetcher.d.ts.map +1 -0
- package/dist/examples/delta.d.ts +2 -0
- package/dist/examples/delta.d.ts.map +1 -0
- package/dist/examples/ethersV6.d.ts +2 -0
- package/dist/examples/ethersV6.d.ts.map +1 -0
- package/dist/examples/limitOrders_all.d.ts +2 -0
- package/dist/examples/limitOrders_all.d.ts.map +1 -0
- package/dist/examples/limitOrders_partial.d.ts +2 -0
- package/dist/examples/limitOrders_partial.d.ts.map +1 -0
- package/dist/examples/limitOrders_postOrder.d.ts +2 -0
- package/dist/examples/limitOrders_postOrder.d.ts.map +1 -0
- package/dist/examples/partial.d.ts +2 -0
- package/dist/examples/partial.d.ts.map +1 -0
- package/dist/examples/quote.d.ts +2 -0
- package/dist/examples/quote.d.ts.map +1 -0
- package/dist/examples/sdk.d.ts +2 -0
- package/dist/examples/sdk.d.ts.map +1 -0
- package/dist/examples/simple.d.ts +2 -0
- package/dist/examples/simple.d.ts.map +1 -0
- package/dist/examples/simpleQuote.d.ts +2 -0
- package/dist/examples/simpleQuote.d.ts.map +1 -0
- package/dist/examples/viem.d.ts +2 -0
- package/dist/examples/viem.d.ts.map +1 -0
- package/dist/examples/wagmi.d.ts +43 -0
- package/dist/examples/wagmi.d.ts.map +1 -0
- package/dist/examples/web3.d.ts +2 -0
- package/dist/examples/web3.d.ts.map +1 -0
- package/dist/gas.d.ts +8 -0
- package/dist/gas.d.ts.map +1 -0
- package/dist/helpers/approve.d.ts +8 -0
- package/dist/helpers/approve.d.ts.map +1 -0
- package/dist/helpers/fetchers/axios.d.ts +5 -0
- package/dist/helpers/fetchers/axios.d.ts.map +1 -0
- package/dist/helpers/fetchers/fetch.d.ts +5 -0
- package/dist/helpers/fetchers/fetch.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/misc.d.ts +48 -0
- package/dist/helpers/misc.d.ts.map +1 -0
- package/dist/helpers/providers/ethers.d.ts +10 -0
- package/dist/helpers/providers/ethers.d.ts.map +1 -0
- package/dist/helpers/providers/ethersV6.d.ts +8 -0
- package/dist/helpers/providers/ethersV6.d.ts.map +1 -0
- package/dist/helpers/providers/helpers.d.ts +3 -0
- package/dist/helpers/providers/helpers.d.ts.map +1 -0
- package/dist/helpers/providers/viem.d.ts +23 -0
- package/dist/helpers/providers/viem.d.ts.map +1 -0
- package/dist/helpers/providers/web3.d.ts +9 -0
- package/dist/helpers/providers/web3.d.ts.map +1 -0
- package/dist/helpers/token.d.ts +38 -0
- package/dist/helpers/token.d.ts.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/methods/common/orders/buildOrderData.d.ts +27 -0
- package/dist/methods/common/orders/buildOrderData.d.ts.map +1 -0
- package/dist/methods/common/orders/encoding.d.ts +23 -0
- package/dist/methods/common/orders/encoding.d.ts.map +1 -0
- package/dist/methods/common/orders/misc.d.ts +27 -0
- package/dist/methods/common/orders/misc.d.ts.map +1 -0
- package/dist/methods/common/orders/signature.d.ts +9 -0
- package/dist/methods/common/orders/signature.d.ts.map +1 -0
- package/dist/methods/common/orders/types.d.ts +8 -0
- package/dist/methods/common/orders/types.d.ts.map +1 -0
- package/dist/methods/delta/approveForDelta.d.ts +8 -0
- package/dist/methods/delta/approveForDelta.d.ts.map +1 -0
- package/dist/methods/delta/buildCrosschainOrderBridge.d.ts +23 -0
- package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +1 -0
- package/dist/methods/delta/buildDeltaOrder.d.ts +49 -0
- package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/getBridgeInfo.d.ts +9 -0
- package/dist/methods/delta/getBridgeInfo.d.ts.map +1 -0
- package/dist/methods/delta/getDeltaContract.d.ts +9 -0
- package/dist/methods/delta/getDeltaContract.d.ts.map +1 -0
- package/dist/methods/delta/getDeltaOrders.d.ts +22 -0
- package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -0
- package/dist/methods/delta/getDeltaPrice.d.ts +58 -0
- package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -0
- package/dist/methods/delta/getMulticallHandlers.d.ts +9 -0
- package/dist/methods/delta/getMulticallHandlers.d.ts.map +1 -0
- package/dist/methods/delta/getPartnerFee.d.ts +16 -0
- package/dist/methods/delta/getPartnerFee.d.ts.map +1 -0
- package/dist/methods/delta/helpers/across.d.ts +22 -0
- package/dist/methods/delta/helpers/across.d.ts.map +1 -0
- package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +35 -0
- package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -0
- package/dist/methods/delta/helpers/composePermit.d.ts +5 -0
- package/dist/methods/delta/helpers/composePermit.d.ts.map +1 -0
- package/dist/methods/delta/helpers/misc.d.ts +3 -0
- package/dist/methods/delta/helpers/misc.d.ts.map +1 -0
- package/dist/methods/delta/helpers/types.d.ts +96 -0
- package/dist/methods/delta/helpers/types.d.ts.map +1 -0
- package/dist/methods/delta/index.d.ts +28 -0
- package/dist/methods/delta/index.d.ts.map +1 -0
- package/dist/methods/delta/isTokenSupportedInDelta.d.ts +8 -0
- package/dist/methods/delta/isTokenSupportedInDelta.d.ts.map +1 -0
- package/dist/methods/delta/postDeltaOrder.d.ts +23 -0
- package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -0
- package/dist/methods/delta/signDeltaOrder.d.ts +12 -0
- package/dist/methods/delta/signDeltaOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/approveForOrder.d.ts +12 -0
- package/dist/methods/limitOrders/approveForOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/buildOrder.d.ts +11 -0
- package/dist/methods/limitOrders/buildOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/cancelOrder.d.ts +9 -0
- package/dist/methods/limitOrders/cancelOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/fillOrderDirectly.d.ts +30 -0
- package/dist/methods/limitOrders/fillOrderDirectly.d.ts.map +1 -0
- package/dist/methods/limitOrders/getOrders.d.ts +39 -0
- package/dist/methods/limitOrders/getOrders.d.ts.map +1 -0
- package/dist/methods/limitOrders/getOrdersContract.d.ts +8 -0
- package/dist/methods/limitOrders/getOrdersContract.d.ts.map +1 -0
- package/dist/methods/limitOrders/helpers/buildOrderData.d.ts +43 -0
- package/dist/methods/limitOrders/helpers/buildOrderData.d.ts.map +1 -0
- package/dist/methods/limitOrders/helpers/misc.d.ts +9 -0
- package/dist/methods/limitOrders/helpers/misc.d.ts.map +1 -0
- package/dist/methods/limitOrders/helpers/types.d.ts +49 -0
- package/dist/methods/limitOrders/helpers/types.d.ts.map +1 -0
- package/dist/methods/limitOrders/index.d.ts +30 -0
- package/dist/methods/limitOrders/index.d.ts.map +1 -0
- package/dist/methods/limitOrders/postOrder.d.ts +10 -0
- package/dist/methods/limitOrders/postOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/signOrder.d.ts +7 -0
- package/dist/methods/limitOrders/signOrder.d.ts.map +1 -0
- package/dist/methods/limitOrders/transaction.d.ts +23 -0
- package/dist/methods/limitOrders/transaction.d.ts.map +1 -0
- package/dist/methods/nftOrders/approveForOrder.d.ts +12 -0
- package/dist/methods/nftOrders/approveForOrder.d.ts.map +1 -0
- package/dist/methods/nftOrders/buildOrder.d.ts +11 -0
- package/dist/methods/nftOrders/buildOrder.d.ts.map +1 -0
- package/dist/methods/nftOrders/cancelOrder.d.ts +8 -0
- package/dist/methods/nftOrders/cancelOrder.d.ts.map +1 -0
- package/dist/methods/nftOrders/getOrders.d.ts +18 -0
- package/dist/methods/nftOrders/getOrders.d.ts.map +1 -0
- package/dist/methods/nftOrders/getOrdersContract.d.ts +8 -0
- package/dist/methods/nftOrders/getOrdersContract.d.ts.map +1 -0
- package/dist/methods/nftOrders/helpers/buildOrderData.d.ts +52 -0
- package/dist/methods/nftOrders/helpers/buildOrderData.d.ts.map +1 -0
- package/dist/methods/nftOrders/helpers/misc.d.ts +13 -0
- package/dist/methods/nftOrders/helpers/misc.d.ts.map +1 -0
- package/dist/methods/nftOrders/helpers/types.d.ts +39 -0
- package/dist/methods/nftOrders/helpers/types.d.ts.map +1 -0
- package/dist/methods/nftOrders/index.d.ts +23 -0
- package/dist/methods/nftOrders/index.d.ts.map +1 -0
- package/dist/methods/nftOrders/postOrder.d.ts +10 -0
- package/dist/methods/nftOrders/postOrder.d.ts.map +1 -0
- package/dist/methods/nftOrders/signOrder.d.ts +7 -0
- package/dist/methods/nftOrders/signOrder.d.ts.map +1 -0
- package/dist/methods/nftOrders/transaction.d.ts +23 -0
- package/dist/methods/nftOrders/transaction.d.ts.map +1 -0
- package/dist/methods/quote/getQuote.d.ts +51 -0
- package/dist/methods/quote/getQuote.d.ts.map +1 -0
- package/dist/methods/swap/adapters.d.ts +8 -0
- package/dist/methods/swap/adapters.d.ts.map +1 -0
- package/dist/methods/swap/approve.d.ts +10 -0
- package/dist/methods/swap/approve.d.ts.map +1 -0
- package/dist/methods/swap/balance.d.ts +23 -0
- package/dist/methods/swap/balance.d.ts.map +1 -0
- package/dist/methods/swap/helpers/normalizeRateOptions.d.ts +12 -0
- package/dist/methods/swap/helpers/normalizeRateOptions.d.ts.map +1 -0
- package/dist/methods/swap/index.d.ts +13 -0
- package/dist/methods/swap/index.d.ts.map +1 -0
- package/dist/methods/swap/rates.d.ts +52 -0
- package/dist/methods/swap/rates.d.ts.map +1 -0
- package/dist/methods/swap/spender.d.ts +21 -0
- package/dist/methods/swap/spender.d.ts.map +1 -0
- package/dist/methods/swap/swapTx.d.ts +158 -0
- package/dist/methods/swap/swapTx.d.ts.map +1 -0
- package/dist/methods/swap/token.d.ts +8 -0
- package/dist/methods/swap/token.d.ts.map +1 -0
- package/dist/methods/swap/transaction.d.ts +115 -0
- package/dist/methods/swap/transaction.d.ts.map +1 -0
- package/dist/sdk/full.d.ts +17 -0
- package/dist/sdk/full.d.ts.map +1 -0
- package/dist/sdk/partial.d.ts +31 -0
- package/dist/sdk/partial.d.ts.map +1 -0
- package/dist/sdk/simple.d.ts +75 -0
- package/dist/sdk/simple.d.ts.map +1 -0
- package/dist/sdk.cjs.development.js +5182 -0
- package/dist/sdk.cjs.development.js.map +1 -0
- package/dist/sdk.cjs.production.min.js +2 -0
- package/dist/sdk.cjs.production.min.js.map +1 -0
- package/dist/sdk.esm.js +5102 -0
- package/dist/sdk.esm.js.map +1 -0
- package/dist/types.d.ts +161 -0
- package/dist/types.d.ts.map +1 -0
- package/docs/DELTA.md +207 -0
- package/package.json +126 -0
- package/src/constants.ts +16 -0
- package/src/examples/customFetcher.ts +44 -0
- package/src/examples/delta.ts +127 -0
- package/src/examples/ethersV6.ts +38 -0
- package/src/examples/limitOrders_all.ts +135 -0
- package/src/examples/limitOrders_partial.ts +171 -0
- package/src/examples/limitOrders_postOrder.ts +77 -0
- package/src/examples/partial.ts +34 -0
- package/src/examples/quote.ts +205 -0
- package/src/examples/sdk.ts +39 -0
- package/src/examples/simple.ts +44 -0
- package/src/examples/simpleQuote.ts +98 -0
- package/src/examples/viem.ts +120 -0
- package/src/examples/wagmi.ts +68 -0
- package/src/examples/web3.ts +32 -0
- package/src/gas.ts +7 -0
- package/src/helpers/approve.ts +60 -0
- package/src/helpers/fetchers/axios.ts +34 -0
- package/src/helpers/fetchers/fetch.ts +67 -0
- package/src/helpers/index.ts +27 -0
- package/src/helpers/misc.ts +160 -0
- package/src/helpers/providers/ethers.ts +192 -0
- package/src/helpers/providers/ethersV6.ts +121 -0
- package/src/helpers/providers/helpers.ts +36 -0
- package/src/helpers/providers/viem.ts +205 -0
- package/src/helpers/providers/web3.ts +154 -0
- package/src/helpers/token.ts +75 -0
- package/src/index.ts +425 -0
- package/src/methods/common/orders/buildOrderData.ts +29 -0
- package/src/methods/common/orders/encoding.ts +216 -0
- package/src/methods/common/orders/misc.ts +86 -0
- package/src/methods/common/orders/signature.ts +68 -0
- package/src/methods/common/orders/types.ts +13 -0
- package/src/methods/delta/approveForDelta.ts +38 -0
- package/src/methods/delta/buildCrosschainOrderBridge.ts +84 -0
- package/src/methods/delta/buildDeltaOrder.ts +192 -0
- package/src/methods/delta/getBridgeInfo.ts +38 -0
- package/src/methods/delta/getDeltaContract.ts +29 -0
- package/src/methods/delta/getDeltaOrders.ts +102 -0
- package/src/methods/delta/getDeltaPrice.ts +122 -0
- package/src/methods/delta/getMulticallHandlers.ts +44 -0
- package/src/methods/delta/getPartnerFee.ts +58 -0
- package/src/methods/delta/helpers/across.ts +255 -0
- package/src/methods/delta/helpers/buildDeltaOrderData.ts +153 -0
- package/src/methods/delta/helpers/composePermit.ts +76 -0
- package/src/methods/delta/helpers/misc.ts +32 -0
- package/src/methods/delta/helpers/types.ts +110 -0
- package/src/methods/delta/index.ts +146 -0
- package/src/methods/delta/isTokenSupportedInDelta.ts +54 -0
- package/src/methods/delta/postDeltaOrder.ts +50 -0
- package/src/methods/delta/signDeltaOrder.ts +41 -0
- package/src/methods/limitOrders/approveForOrder.ts +36 -0
- package/src/methods/limitOrders/buildOrder.ts +56 -0
- package/src/methods/limitOrders/cancelOrder.ts +111 -0
- package/src/methods/limitOrders/fillOrderDirectly.ts +277 -0
- package/src/methods/limitOrders/getOrders.ts +151 -0
- package/src/methods/limitOrders/getOrdersContract.ts +20 -0
- package/src/methods/limitOrders/helpers/buildOrderData.ts +121 -0
- package/src/methods/limitOrders/helpers/misc.ts +64 -0
- package/src/methods/limitOrders/helpers/types.ts +70 -0
- package/src/methods/limitOrders/index.ts +154 -0
- package/src/methods/limitOrders/postOrder.ts +74 -0
- package/src/methods/limitOrders/signOrder.ts +29 -0
- package/src/methods/limitOrders/transaction.ts +231 -0
- package/src/methods/nftOrders/approveForOrder.ts +79 -0
- package/src/methods/nftOrders/buildOrder.ts +52 -0
- package/src/methods/nftOrders/cancelOrder.ts +23 -0
- package/src/methods/nftOrders/getOrders.ts +84 -0
- package/src/methods/nftOrders/getOrdersContract.ts +24 -0
- package/src/methods/nftOrders/helpers/buildOrderData.ts +131 -0
- package/src/methods/nftOrders/helpers/misc.ts +92 -0
- package/src/methods/nftOrders/helpers/types.ts +50 -0
- package/src/methods/nftOrders/index.ts +139 -0
- package/src/methods/nftOrders/postOrder.ts +71 -0
- package/src/methods/nftOrders/signOrder.ts +29 -0
- package/src/methods/nftOrders/transaction.ts +234 -0
- package/src/methods/quote/getQuote.ts +131 -0
- package/src/methods/swap/adapters.ts +49 -0
- package/src/methods/swap/approve.ts +51 -0
- package/src/methods/swap/balance.ts +147 -0
- package/src/methods/swap/helpers/normalizeRateOptions.ts +55 -0
- package/src/methods/swap/index.ts +38 -0
- package/src/methods/swap/rates.ts +276 -0
- package/src/methods/swap/spender.ts +76 -0
- package/src/methods/swap/swapTx.ts +266 -0
- package/src/methods/swap/token.ts +35 -0
- package/src/methods/swap/transaction.ts +310 -0
- package/src/sdk/full.ts +54 -0
- package/src/sdk/partial.ts +107 -0
- package/src/sdk/simple.ts +429 -0
- package/src/types.ts +240 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API_URL,
|
|
3
|
+
DEFAULT_VERSION,
|
|
4
|
+
ContractMethodByName,
|
|
5
|
+
} from '../../constants';
|
|
6
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
7
|
+
import type {
|
|
8
|
+
ConstructFetchInput,
|
|
9
|
+
PriceRouteApiResponse,
|
|
10
|
+
Address,
|
|
11
|
+
AddressOrSymbol,
|
|
12
|
+
PriceString,
|
|
13
|
+
OptimalRate,
|
|
14
|
+
RequestParameters,
|
|
15
|
+
} from '../../types';
|
|
16
|
+
import { normalizeRateOptions } from './helpers/normalizeRateOptions';
|
|
17
|
+
|
|
18
|
+
type RateQueryParams = {
|
|
19
|
+
/**
|
|
20
|
+
* @description Source Token Address. Instead, **Token Symbol** could be used for tokens listed in the `/tokens` endpoint.
|
|
21
|
+
*/
|
|
22
|
+
srcToken: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description Source Token Decimals. (Can be omitted if Token Symbol is used in `srcToken`).
|
|
26
|
+
*/
|
|
27
|
+
srcDecimals?: number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @description Destination Token Address. Instead, **Token Symbol** could be used for tokens listed in the `/tokens` endpoint.
|
|
31
|
+
*/
|
|
32
|
+
destToken: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @description srcToken amount (in case of SELL) or destToken amount (in case of BUY). The amount should be in **WEI/Raw units** (eg. 1WBTC -> 100000000).
|
|
36
|
+
*/
|
|
37
|
+
amount: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description **SELL** or **BUY**. Default: `SELL`.
|
|
41
|
+
*/
|
|
42
|
+
side?: 'SELL' | 'BUY';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @description Network ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Fantom - 250, zkEVM - 1101, Base - 8453, Arbitrum - 42161, Avalanche - 43114). Default: `1`.
|
|
46
|
+
*/
|
|
47
|
+
network?: number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description If provided, **others** object is filled in the response with price quotes from other exchanges _(if available for comparison)_. Default: `false`.
|
|
51
|
+
*/
|
|
52
|
+
otherExchangePrices?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @description Comma Separated List of DEXs to include. **Supported DEXs:** UniswapV2, UniswapV3, Kyber, Bancor, AugustusRFQ, Oasis, Compound, Fulcrum, Balancer, MakerDAO, Chai, Aave, Aave2 and more. You can view all currently supported dexes filtered by chain [here](https://api.paraswap.io/adapters/list/1) eg: `UniswapV3,MakerDAO`.
|
|
56
|
+
*/
|
|
57
|
+
includeDEXS?: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @description Comma Separated List of DEXs to exclude. (from the list of DEXs mentioned above).
|
|
61
|
+
*/
|
|
62
|
+
excludeDEXS?: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @description Comma Separated List of Contract Methods to include in pricing (without spaces). View the list of the supported methods for [V5](https://developers.velora.xyz/api/velora-api/velora-market-api/master/api-v5#supported-methods) and [V6](https://developers.velora.xyz/api/velora-api/velora-market-api/master/api-v6.2#supported-methods) eg: `swapExactAmountIn,swapExactAmountInOnUniswapV2`.
|
|
66
|
+
*/
|
|
67
|
+
includeContractMethods?: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description Comma Separated List of Contract Methods to exclude from pricing (without spaces). View the list of the supported methods for [V5](https://developers.velora.xyz/api/velora-api/velora-market-api/master/api-v5#supported-methods) and [V6](https://developers.velora.xyz/api/velora-api/velora-market-api/master/api-v6.2#supported-methods).
|
|
71
|
+
*/
|
|
72
|
+
excludeContractMethods?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @description User's Wallet Address.
|
|
76
|
+
*/
|
|
77
|
+
userAddress?: string;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @description Dash (-) separated list of tokens (addresses or symbols from `/tokens`) to comprise the price route. _Max 4 tokens._ _**\*Note:**_ _If_ `_route_` _is specified, the response will only comprise of the route specified which might not be the optimal route._
|
|
81
|
+
*/
|
|
82
|
+
route?: string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @description Partner string.
|
|
86
|
+
*/
|
|
87
|
+
partner?: string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @description Destination Token Decimals. (Can be omitted if Token Symbol is used in `destToken`).
|
|
91
|
+
*/
|
|
92
|
+
destDecimals?: number;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @description In %. It's a way to bypass the API price impact check (default = 15%).
|
|
96
|
+
*/
|
|
97
|
+
maxImpact?: number;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @description Receiver's Wallet address. (Can be omitted if swapping tokens from and to same account).
|
|
101
|
+
*/
|
|
102
|
+
receiver?: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @description If the source token is a tax token, you should specify the tax amount in BPS. For example: for a token with a 5% tax, you should set it to 500 as `[(500/10000)*100=5%]`. Note: not all DEXs and contract methods support trading tax tokens, so we will filter those that don't.
|
|
106
|
+
*/
|
|
107
|
+
srcTokenTransferFee?: string;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @description If the destination token is a tax token, you should specify the tax amount in BPS. For example: for a token with a 5% tax, you should set it to 500 as `[(500/10000)*100=5%]`. Note: not all DEXs and contract methods support trading tax tokens, so we will filter those that don't.
|
|
111
|
+
*/
|
|
112
|
+
destTokenTransferFee?: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @description If the source token is a tax token, you should specify the tax amount in BPS. Some tokens only charge tax when swapped in/out DEXs and not on ordinary transfers.
|
|
116
|
+
*/
|
|
117
|
+
srcTokenDexTransferFee?: string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @description If the destination token is a tax token, you should specify the tax amount in BPS. Some tokens only charge tax when swapped in/out DEXs, not on ordinary transfers.
|
|
121
|
+
*/
|
|
122
|
+
destTokenDexTransferFee?: string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 5.
|
|
126
|
+
*/
|
|
127
|
+
version?: number | string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @description Specify that methods without fee support should be excluded from the price route. Default: `false`.
|
|
131
|
+
*/
|
|
132
|
+
excludeContractMethodsWithoutFeeModel?: boolean;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @description If tokens USD prices are not available, `Bad USD Price` error will be thrown. Use this param to skip this check. Default: `false`.
|
|
136
|
+
*/
|
|
137
|
+
ignoreBadUsdPrice?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* @description Exclude all RFQs from pricing, e.g.: AugustusRFQ, Hashflow. Default: false
|
|
140
|
+
*/
|
|
141
|
+
excludeRFQ?: boolean;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// more details in the docs https://developers.velora.xyz/api/velora-api/velora-market-api/get-rate-for-a-token-pair#query-parameters
|
|
145
|
+
export type RateOptions = {
|
|
146
|
+
excludeDEXS?: string[];
|
|
147
|
+
includeDEXS?: string[];
|
|
148
|
+
excludePools?: string[];
|
|
149
|
+
excludeContractMethods?: ContractMethodByName[];
|
|
150
|
+
includeContractMethods?: ContractMethodByName[];
|
|
151
|
+
partner?: string;
|
|
152
|
+
/** @description In %. It's a way to bypass the API price impact check (default = 15%) */
|
|
153
|
+
maxImpact?: number;
|
|
154
|
+
maxUSDImpact?: number;
|
|
155
|
+
otherExchangePrices?: boolean;
|
|
156
|
+
/** @description proceed with priceRoute building even when tokens don't have USD price. Default: false */
|
|
157
|
+
ignoreBadUsdPrice?: boolean;
|
|
158
|
+
/** @description Exclude all RFQs from pricing, e.g.: AugustusRFQ, Hashflow. Default: false */
|
|
159
|
+
excludeRFQ?: boolean;
|
|
160
|
+
/** @description Specify that methods without fee support should be excluded from the price route. Default: false */
|
|
161
|
+
excludeContractMethodsWithoutFeeModel?: boolean;
|
|
162
|
+
/** @description If the source token is a tax token, you should specify the tax amount in BPS. */
|
|
163
|
+
srcTokenTransferFee?: string;
|
|
164
|
+
/** @description If the destination token is a tax token, you should specify the tax amount in BPS. */
|
|
165
|
+
destTokenTransferFee?: string;
|
|
166
|
+
/** @description Some tokens only charge tax when swapped in/out DEXs and not on ordinary transfers. */
|
|
167
|
+
srcTokenDexTransferFee?: string;
|
|
168
|
+
/** @description Some tokens only charge tax when swapped in/out DEXs and not on ordinary transfers. */
|
|
169
|
+
destTokenDexTransferFee?: string;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
type CommonGetRateInput = {
|
|
173
|
+
amount: PriceString;
|
|
174
|
+
userAddress?: Address;
|
|
175
|
+
side?: 'SELL' | 'BUY';
|
|
176
|
+
options?: RateOptions;
|
|
177
|
+
srcDecimals?: number;
|
|
178
|
+
destDecimals?: number;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export type GetRateInput = CommonGetRateInput & {
|
|
182
|
+
srcToken: AddressOrSymbol;
|
|
183
|
+
destToken: AddressOrSymbol;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type GetRate = (
|
|
187
|
+
options: GetRateInput,
|
|
188
|
+
requestParams?: RequestParameters
|
|
189
|
+
) => Promise<OptimalRate>;
|
|
190
|
+
|
|
191
|
+
type GetRateByRouteInput = CommonGetRateInput & {
|
|
192
|
+
route: AddressOrSymbol[];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type GetRateByRoute = (
|
|
196
|
+
options: GetRateByRouteInput,
|
|
197
|
+
requestParams?: RequestParameters
|
|
198
|
+
) => Promise<OptimalRate>;
|
|
199
|
+
|
|
200
|
+
export type GetRateFunctions = {
|
|
201
|
+
getRate: GetRate;
|
|
202
|
+
getRateByRoute: GetRateByRoute;
|
|
203
|
+
};
|
|
204
|
+
const INVALID_ROUTE = 'Invalid Route';
|
|
205
|
+
|
|
206
|
+
export const constructGetRate = ({
|
|
207
|
+
apiURL = API_URL,
|
|
208
|
+
version = DEFAULT_VERSION,
|
|
209
|
+
chainId,
|
|
210
|
+
fetcher,
|
|
211
|
+
}: ConstructFetchInput): GetRateFunctions => {
|
|
212
|
+
const pricesUrl = `${apiURL}/prices` as const;
|
|
213
|
+
|
|
214
|
+
const getRate: GetRate = async (
|
|
215
|
+
{ srcToken, destToken, ...rest },
|
|
216
|
+
requestParams
|
|
217
|
+
) => {
|
|
218
|
+
const parsedOptions = normalizeRateOptions(rest);
|
|
219
|
+
|
|
220
|
+
// always pass explicit type to make sure UrlSearchParams are correct
|
|
221
|
+
const search = constructSearchString<Omit<RateQueryParams, 'route'>>({
|
|
222
|
+
srcToken,
|
|
223
|
+
destToken,
|
|
224
|
+
network: chainId,
|
|
225
|
+
version,
|
|
226
|
+
...parsedOptions,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
230
|
+
|
|
231
|
+
const data = await fetcher<PriceRouteApiResponse>({
|
|
232
|
+
url: fetchURL,
|
|
233
|
+
method: 'GET',
|
|
234
|
+
requestParams,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return data.priceRoute;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const getRateByRoute: GetRateByRoute = async (
|
|
241
|
+
{ route, ...rest },
|
|
242
|
+
requestParams
|
|
243
|
+
) => {
|
|
244
|
+
if (route.length < 2) {
|
|
245
|
+
throw new Error(INVALID_ROUTE);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const parsedOptions = normalizeRateOptions(rest);
|
|
249
|
+
|
|
250
|
+
const _route = route.join('-');
|
|
251
|
+
|
|
252
|
+
const search = constructSearchString<
|
|
253
|
+
Omit<RateQueryParams, 'srcToken' | 'destToken'>
|
|
254
|
+
>({
|
|
255
|
+
route: _route, // route can be used in place of srcToken+destToken
|
|
256
|
+
network: chainId,
|
|
257
|
+
version,
|
|
258
|
+
...parsedOptions,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
262
|
+
|
|
263
|
+
const data = await fetcher<PriceRouteApiResponse>({
|
|
264
|
+
url: fetchURL,
|
|
265
|
+
method: 'GET',
|
|
266
|
+
requestParams,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
return data.priceRoute;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
getRate,
|
|
274
|
+
getRateByRoute,
|
|
275
|
+
};
|
|
276
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { API_URL, DEFAULT_VERSION } from '../../constants';
|
|
2
|
+
import { constructSearchString, runOnceAndCache } from '../../helpers/misc';
|
|
3
|
+
import type {
|
|
4
|
+
ConstructFetchInput,
|
|
5
|
+
Address,
|
|
6
|
+
RequestParameters,
|
|
7
|
+
} from '../../types';
|
|
8
|
+
|
|
9
|
+
export type GetSpender = (
|
|
10
|
+
requestParams?: RequestParameters
|
|
11
|
+
) => Promise<Address>;
|
|
12
|
+
type GetContracts = (
|
|
13
|
+
requestParams?: RequestParameters
|
|
14
|
+
) => Promise<AdaptersContractsResult>;
|
|
15
|
+
|
|
16
|
+
export type GetSpenderFunctions = {
|
|
17
|
+
getSpender: GetSpender;
|
|
18
|
+
getAugustusSwapper: GetSpender;
|
|
19
|
+
getAugustusRFQ: GetSpender;
|
|
20
|
+
getContracts: GetContracts;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface AdaptersContractsResult {
|
|
24
|
+
AugustusSwapper: string;
|
|
25
|
+
TokenTransferProxy: string;
|
|
26
|
+
AugustusRFQ: string;
|
|
27
|
+
Executors: {
|
|
28
|
+
[key: `Executor${number}`]: string;
|
|
29
|
+
};
|
|
30
|
+
ParaswapDelta?: string; // only available on chains with Delta support
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const constructGetSpender = ({
|
|
34
|
+
apiURL = API_URL,
|
|
35
|
+
version = DEFAULT_VERSION,
|
|
36
|
+
chainId,
|
|
37
|
+
fetcher,
|
|
38
|
+
}: ConstructFetchInput): GetSpenderFunctions => {
|
|
39
|
+
const search = constructSearchString<{ network: number; version: string }>({
|
|
40
|
+
network: chainId,
|
|
41
|
+
version,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const fetchURL = `${apiURL}/adapters/contracts${search}` as const;
|
|
45
|
+
|
|
46
|
+
const _getContracts: GetContracts = async (requestParams) => {
|
|
47
|
+
const data = await fetcher<AdaptersContractsResult>({
|
|
48
|
+
url: fetchURL,
|
|
49
|
+
method: 'GET',
|
|
50
|
+
requestParams,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// cached for the same instance of `{getContracts, getSpender, getAugustusSwapper, getAugustusRFQ} = constructGetSpender()`
|
|
57
|
+
// so should persist across same apiUrl & network
|
|
58
|
+
const getContracts = runOnceAndCache(_getContracts);
|
|
59
|
+
|
|
60
|
+
const getSpender: GetSpender = async (requestParams) => {
|
|
61
|
+
const { TokenTransferProxy } = await getContracts(requestParams);
|
|
62
|
+
return TokenTransferProxy;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getAugustusSwapper: GetSpender = async (requestParams) => {
|
|
66
|
+
const { AugustusSwapper } = await getContracts(requestParams);
|
|
67
|
+
return AugustusSwapper;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const getAugustusRFQ: GetSpender = async (requestParams) => {
|
|
71
|
+
const { AugustusRFQ } = await getContracts(requestParams);
|
|
72
|
+
return AugustusRFQ;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return { getContracts, getSpender, getAugustusSwapper, getAugustusRFQ };
|
|
76
|
+
};
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API_URL,
|
|
3
|
+
DEFAULT_VERSION,
|
|
4
|
+
ContractMethodByName,
|
|
5
|
+
} from '../../constants';
|
|
6
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
7
|
+
import type {
|
|
8
|
+
ConstructFetchInput,
|
|
9
|
+
RequestParameters,
|
|
10
|
+
SwapApiResponse,
|
|
11
|
+
} from '../../types';
|
|
12
|
+
import { normalizeRateOptions } from './helpers/normalizeRateOptions';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Types for transaction parameters.
|
|
16
|
+
*/
|
|
17
|
+
type SwapQueryParams = {
|
|
18
|
+
/**
|
|
19
|
+
* @description Source Token Address. Instead, **Token Symbol** could be used for tokens listed in the `/tokens` endpoint.
|
|
20
|
+
*/
|
|
21
|
+
srcToken: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @description Source Token Decimals. (Can be omitted if Token Symbol is used in `srcToken`).
|
|
25
|
+
*/
|
|
26
|
+
srcDecimals?: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @description Destination Token Address. Instead, **Token Symbol** could be used for tokens listed in the `/tokens` endpoint.
|
|
30
|
+
*/
|
|
31
|
+
destToken: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description srcToken amount (in case of SELL) or destToken amount (in case of BUY). The amount should be in **WEI/Raw units** (eg. 1WBTC -> 100000000).
|
|
35
|
+
*/
|
|
36
|
+
amount: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @description **SELL** or **BUY**. Default: `SELL`.
|
|
40
|
+
*/
|
|
41
|
+
side: 'SELL' | 'BUY';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @description Network ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Fantom - 250, zkEVM - 1101, Base - 8453, Arbitrum - 42161, Avalanche - 43114). Default: `1`.
|
|
45
|
+
*/
|
|
46
|
+
network?: number;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @description Comma Separated List of DEXs to include. **Supported DEXs:** Uniswap, Kyber, Bancor, AugustusRFQ, Oasis, Compound, Fulcrum, 0x, MakerDAO, Chai, Aave, Aave2, MultiPath, MegaPath, Curve, Curve3, Saddle, IronV2, BDai, idle, Weth, Beth, UniswapV2, Balancer, 0xRFQt, SushiSwap, LINKSWAP, Synthetix, DefiSwap, Swerve, CoFiX, Shell, DODOV1, DODOV2, OnChainPricing, PancakeSwap, PancakeSwapV2, ApeSwap, Wbnb, acryptos, streetswap, bakeryswap, julswap, vswap, vpegswap, beltfi, ellipsis, QuickSwap, COMETH, Wmatic, Nerve, Dfyn, UniswapV3, Smoothy, PantherSwap, OMM1, OneInchLP, CurveV2, mStable, WaultFinance, MDEX, ShibaSwap, CoinSwap, SakeSwap, JetSwap, Biswap, BProtocol eg: `UniswapV3,0x`.
|
|
50
|
+
*/
|
|
51
|
+
includeDEXS?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @description Comma Separated List of DEXs to exclude. (from the list of DEXs mentioned above).
|
|
55
|
+
*/
|
|
56
|
+
excludeDEXS?: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @description Comma Separated List of Contract Methods to include without spaces. **Available values:** swapOnUniswap, buyOnUniswap, swapOnUniswapFork, buyOnUniswapFork, swapOnUniswapV2Fork, buyOnUniswapV2Fork, simpleBuy, simpleSwap, multiSwap, megaSwap, protectedMultiSwap, protectedMegaSwap, protectedSimpleSwap, protectedSimpleBuy, swapOnZeroXv2, swapOnZeroXv4, buy. eg: `simpleSwap,multiSwap`.
|
|
60
|
+
*/
|
|
61
|
+
includeContractMethods?: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @description Comma Separated List of Contract Methods to exclude without spaces. (from the list of contract methods mentioned above).
|
|
65
|
+
*/
|
|
66
|
+
excludeContractMethods?: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @description User's Wallet Address.
|
|
70
|
+
*/
|
|
71
|
+
userAddress: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @description Dash (-) separated list of tokens (addresses or symbols from `/tokens`) to comprise the price route. _Max 4 tokens._ _**\*Note:**_ _If_ `_route_` _is specified, the response will only comprise of the route specified which might not be the optimal route._
|
|
75
|
+
*/
|
|
76
|
+
route?: string;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @description Partner string.
|
|
80
|
+
*/
|
|
81
|
+
partner?: string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @description If provided it is used together with `partnerAddress`. Should be in basis points percentage. Look at `slippage` parameter description for understanding better. Eg: `200` (for 2% fee percent). Fees have to be claimed from the Fee Claimer contract unless `_isSurplusToUser_` or `_isDirectFeeTransfer_` are used.
|
|
85
|
+
*/
|
|
86
|
+
partnerFeeBps?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @description Address that will be entitled to claim fees or surplus. Fees have to be claimed from the Fee Claimer contract unless `_isSurplusToUser_` or `_isDirectFeeTransfer_` are used.
|
|
90
|
+
*/
|
|
91
|
+
partnerAddress?: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @description Allowed slippage percentage represented in basis points. _Eg:_ for **2.5%** slippage, set the value to **2.5 \* 100 = 250**; for 10% = 1000.
|
|
95
|
+
*/
|
|
96
|
+
slippage: number;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description Destination Token Decimals. (Can be omitted if Token Symbol is used in `destToken`).
|
|
100
|
+
*/
|
|
101
|
+
destDecimals?: number;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @description In %. It's a way to bypass the API price impact check (default = 15%).
|
|
105
|
+
*/
|
|
106
|
+
maxImpact?: number;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @description Receiver's Wallet address. (Can be omitted if swapping tokens from and to same account).
|
|
110
|
+
*/
|
|
111
|
+
receiver?: string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @description If the source token is a tax token, you should specify the tax amount in BPS. For example: for a token with a 5% tax, you should set it to 500 as `[(500/10000)*100=5%]`. Note: not all DEXs and contract methods support trading tax tokens, so we will filter those that don't.
|
|
115
|
+
*/
|
|
116
|
+
srcTokenTransferFee?: string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @description If the destination token is a tax token, you should specify the tax amount in BPS. For example: for a token with a 5% tax, you should set it to 500 as `[(500/10000)*100=5%]`. Note: not all DEXs and contract methods support trading tax tokens, so we will filter those that don't.
|
|
120
|
+
*/
|
|
121
|
+
destTokenTransferFee?: string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description If the source token is a tax token, you should specify the tax amount in BPS. Some tokens only charge tax when swapped in/out DEXs and not on ordinary transfers.
|
|
125
|
+
*/
|
|
126
|
+
srcTokenDexTransferFee?: string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description If the destination token is a tax token, you should specify the tax amount in BPS. Some tokens only charge tax when swapped in/out DEXs, not on ordinary transfers.
|
|
130
|
+
*/
|
|
131
|
+
destTokenDexTransferFee?: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 5.
|
|
135
|
+
*/
|
|
136
|
+
version?: number | string;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @description If tokens USD prices are not available, `Bad USD Price` error will be thrown. Use this param to skip this check. Default: `false`.
|
|
140
|
+
*/
|
|
141
|
+
ignoreBadUsdPrice?: boolean;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @description Specify if user should receive surplus instead of partner. Default: `false`.
|
|
145
|
+
*/
|
|
146
|
+
isSurplusToUser?: boolean;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @description Specify if fees should be sent directly to the partner instead of registering them on FeeClaimer. Default: `false`.
|
|
150
|
+
*/
|
|
151
|
+
isDirectFeeTransfer?: boolean;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @description Allows for capping the surplus at 1% maximum. Default: `true`.
|
|
155
|
+
*/
|
|
156
|
+
isCapSurplus?: boolean;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @description Allows to collect surplus. Works with `partnerAddress`. Default: `false`.
|
|
160
|
+
*/
|
|
161
|
+
takeSurplus?: boolean;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
type SwapTxInputFields =
|
|
165
|
+
| 'srcToken'
|
|
166
|
+
| 'destToken'
|
|
167
|
+
| 'amount'
|
|
168
|
+
| 'side'
|
|
169
|
+
| 'srcDecimals'
|
|
170
|
+
| 'destDecimals'
|
|
171
|
+
| 'userAddress'
|
|
172
|
+
| 'slippage';
|
|
173
|
+
type SwapTxInputListFields =
|
|
174
|
+
| 'includeDEXS'
|
|
175
|
+
| 'excludeDEXS'
|
|
176
|
+
| 'includeContractMethods'
|
|
177
|
+
| 'excludeContractMethods'
|
|
178
|
+
| 'route';
|
|
179
|
+
|
|
180
|
+
type SwapRateOptions = Omit<
|
|
181
|
+
SwapQueryParams,
|
|
182
|
+
SwapTxInputFields | SwapTxInputListFields | 'network' | 'version'
|
|
183
|
+
> & {
|
|
184
|
+
/**
|
|
185
|
+
* @description List of DEXs to include. **Supported DEXs:** Uniswap, Kyber, Bancor, AugustusRFQ, Oasis, Compound, Fulcrum, 0x, MakerDAO, Chai, Aave, Aave2, MultiPath, MegaPath, Curve, Curve3, Saddle, IronV2, BDai, idle, Weth, Beth, UniswapV2, Balancer, 0xRFQt, SushiSwap, LINKSWAP, Synthetix, DefiSwap, Swerve, CoFiX, Shell, DODOV1, DODOV2, OnChainPricing, PancakeSwap, PancakeSwapV2, ApeSwap, Wbnb, acryptos, streetswap, bakeryswap, julswap, vswap, vpegswap, beltfi, ellipsis, QuickSwap, COMETH, Wmatic, Nerve, Dfyn, UniswapV3, Smoothy, PantherSwap, OMM1, OneInchLP, CurveV2, mStable, WaultFinance, MDEX, ShibaSwap, CoinSwap, SakeSwap, JetSwap, Biswap, BProtocol eg: `UniswapV3,0x`.
|
|
186
|
+
*/
|
|
187
|
+
includeDEXS?: string[];
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @description List of DEXs to exclude. (from the list of DEXs mentioned above).
|
|
191
|
+
*/
|
|
192
|
+
excludeDEXS?: string[];
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @description List of Contract Methods to include without spaces. **Available values:** swapOnUniswap, buyOnUniswap, swapOnUniswapFork, buyOnUniswapFork, swapOnUniswapV2Fork, buyOnUniswapV2Fork, simpleBuy, simpleSwap, multiSwap, megaSwap, protectedMultiSwap, protectedMegaSwap, protectedSimpleSwap, protectedSimpleBuy, swapOnZeroXv2, swapOnZeroXv4, buy. eg: `simpleSwap,multiSwap`.
|
|
196
|
+
*/
|
|
197
|
+
includeContractMethods?: ContractMethodByName[];
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @description List of Contract Methods to exclude without spaces. (from the list of contract methods mentioned above).
|
|
201
|
+
*/
|
|
202
|
+
excludeContractMethods?: ContractMethodByName[];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
type SwapTxInput = Pick<SwapQueryParams, SwapTxInputFields> & {
|
|
206
|
+
/**
|
|
207
|
+
* @description List of tokens (addresses or symbols from `/tokens`) to comprise the price route. _Max 4 tokens._ _**\*Note:**_ _If_ `_route_` _is specified, the response will only comprise of the route specified which might not be the optimal route._
|
|
208
|
+
*/
|
|
209
|
+
route?: string[];
|
|
210
|
+
|
|
211
|
+
options?: SwapRateOptions;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export type SwapTxResult = SwapApiResponse;
|
|
215
|
+
|
|
216
|
+
export type GetSwapTxData = (
|
|
217
|
+
options: SwapTxInput,
|
|
218
|
+
requestParams?: RequestParameters
|
|
219
|
+
) => Promise<SwapTxResult>;
|
|
220
|
+
|
|
221
|
+
export type GetSwapTxFunctions = {
|
|
222
|
+
getSwapTxData: GetSwapTxData;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export const constructSwapTx = ({
|
|
226
|
+
apiURL = API_URL,
|
|
227
|
+
version = DEFAULT_VERSION,
|
|
228
|
+
chainId,
|
|
229
|
+
fetcher,
|
|
230
|
+
}: ConstructFetchInput): GetSwapTxFunctions => {
|
|
231
|
+
const pricesUrl = `${apiURL}/swap` as const;
|
|
232
|
+
|
|
233
|
+
const getSwapTxData: GetSwapTxData = async (
|
|
234
|
+
{ srcToken, destToken, amount, route, ...rest },
|
|
235
|
+
requestParams
|
|
236
|
+
) => {
|
|
237
|
+
const parsedOptions = normalizeRateOptions(rest);
|
|
238
|
+
|
|
239
|
+
const _route = route?.join('-');
|
|
240
|
+
|
|
241
|
+
// always pass explicit type to make sure UrlSearchParams are correct
|
|
242
|
+
const search = constructSearchString<SwapQueryParams>({
|
|
243
|
+
amount,
|
|
244
|
+
srcToken,
|
|
245
|
+
destToken,
|
|
246
|
+
route: _route,
|
|
247
|
+
network: chainId,
|
|
248
|
+
version,
|
|
249
|
+
...parsedOptions,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
253
|
+
|
|
254
|
+
const data = await fetcher<SwapApiResponse>({
|
|
255
|
+
url: fetchURL,
|
|
256
|
+
method: 'GET',
|
|
257
|
+
requestParams,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
return data;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
getSwapTxData,
|
|
265
|
+
};
|
|
266
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { API_URL } from '../../constants';
|
|
2
|
+
import { constructToken } from '../../helpers/token';
|
|
3
|
+
import type {
|
|
4
|
+
RequestParameters,
|
|
5
|
+
ConstructFetchInput,
|
|
6
|
+
Token,
|
|
7
|
+
TokensApiResponse,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
|
|
10
|
+
type GetTokens = (extra?: RequestParameters) => Promise<Token[]>;
|
|
11
|
+
|
|
12
|
+
export type GetTokensFunctions = {
|
|
13
|
+
getTokens: GetTokens;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const constructGetTokens = ({
|
|
17
|
+
apiURL = API_URL,
|
|
18
|
+
chainId,
|
|
19
|
+
fetcher,
|
|
20
|
+
}: ConstructFetchInput): GetTokensFunctions => {
|
|
21
|
+
const fetchURL = `${apiURL}/tokens/${chainId}` as const;
|
|
22
|
+
|
|
23
|
+
const getTokens: GetTokens = async (requestParams) => {
|
|
24
|
+
const data = await fetcher<TokensApiResponse>({
|
|
25
|
+
url: fetchURL,
|
|
26
|
+
method: 'GET',
|
|
27
|
+
requestParams,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const tokens = data.tokens.map(constructToken);
|
|
31
|
+
return tokens;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return { getTokens };
|
|
35
|
+
};
|