@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,131 @@
|
|
|
1
|
+
import { API_URL, SwapSide } from '../../constants';
|
|
2
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
+
import type { DeltaPrice } from '../delta/getDeltaPrice';
|
|
4
|
+
import type {
|
|
5
|
+
ConstructFetchInput,
|
|
6
|
+
EnumerateLiteral,
|
|
7
|
+
RequestParameters,
|
|
8
|
+
OptimalRate,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
|
|
11
|
+
type TradeMode = 'delta' | 'market' | 'all';
|
|
12
|
+
// enable passing enum value by string
|
|
13
|
+
type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
|
|
14
|
+
|
|
15
|
+
export type QuoteParams<M extends TradeMode = TradeMode> = {
|
|
16
|
+
/** @description Source Token Address */
|
|
17
|
+
srcToken: string;
|
|
18
|
+
/** @description Destination Token Address */
|
|
19
|
+
destToken: string;
|
|
20
|
+
/** @description srcToken amount (in case of SELL) or destToken amount (in case of BUY), in wei */
|
|
21
|
+
amount: string;
|
|
22
|
+
/** @description Source Token Decimals. */
|
|
23
|
+
srcDecimals: number;
|
|
24
|
+
/** @description Destination Token Decimals */
|
|
25
|
+
destDecimals: number;
|
|
26
|
+
/** @description SELL or BUY */
|
|
27
|
+
side: SwapSideUnion;
|
|
28
|
+
/** @description User's Wallet Address */
|
|
29
|
+
userAddress?: string;
|
|
30
|
+
/** @description Partner string */
|
|
31
|
+
partner?: string;
|
|
32
|
+
/** @description Preferred mode for the trade. In case of "all", Delta pricing is returned, with Market as a fallback */
|
|
33
|
+
mode: M;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type QuoteQueryOptions = QuoteParams & {
|
|
37
|
+
chainId: number; // will return error from API on unsupported chains
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type FallbackReason = {
|
|
41
|
+
errorType: string;
|
|
42
|
+
details: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type QuoteWithMarketPrice = {
|
|
46
|
+
market: OptimalRate;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type QuoteWithDeltaPrice = {
|
|
50
|
+
delta: DeltaPrice;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type QuoteWithMarketPriceAsFallback = QuoteWithMarketPrice & {
|
|
54
|
+
fallbackReason: FallbackReason;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type QuoteResponse =
|
|
58
|
+
| QuoteWithDeltaPrice
|
|
59
|
+
| QuoteWithMarketPrice
|
|
60
|
+
| QuoteWithMarketPriceAsFallback;
|
|
61
|
+
|
|
62
|
+
interface GetQuoteFunc {
|
|
63
|
+
(
|
|
64
|
+
options: QuoteParams<'delta'>,
|
|
65
|
+
requestParams?: RequestParameters
|
|
66
|
+
): Promise<QuoteWithDeltaPrice>;
|
|
67
|
+
(
|
|
68
|
+
options: QuoteParams<'market'>,
|
|
69
|
+
requestParams?: RequestParameters
|
|
70
|
+
): Promise<QuoteWithMarketPrice>;
|
|
71
|
+
(options: QuoteParams<'all'>, requestParams?: RequestParameters): Promise<
|
|
72
|
+
QuoteWithDeltaPrice | QuoteWithMarketPriceAsFallback // "all" mode tries for deltaPrice and falls back to market priceRoute
|
|
73
|
+
>;
|
|
74
|
+
(
|
|
75
|
+
options: QuoteParams,
|
|
76
|
+
requestParams?: RequestParameters
|
|
77
|
+
): Promise<QuoteResponse>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type GetQuoteFunctions = {
|
|
81
|
+
getQuote: GetQuoteFunc;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const constructGetQuote = ({
|
|
85
|
+
apiURL = API_URL,
|
|
86
|
+
chainId,
|
|
87
|
+
fetcher,
|
|
88
|
+
}: ConstructFetchInput): GetQuoteFunctions => {
|
|
89
|
+
const pricesUrl = `${apiURL}/quote` as const;
|
|
90
|
+
|
|
91
|
+
function getQuote(
|
|
92
|
+
options: QuoteParams<'delta'>,
|
|
93
|
+
requestParams?: RequestParameters
|
|
94
|
+
): Promise<QuoteWithDeltaPrice>;
|
|
95
|
+
function getQuote(
|
|
96
|
+
options: QuoteParams<'market'>,
|
|
97
|
+
requestParams?: RequestParameters
|
|
98
|
+
): Promise<QuoteWithMarketPrice>;
|
|
99
|
+
function getQuote(
|
|
100
|
+
options: QuoteParams<'all'>,
|
|
101
|
+
requestParams?: RequestParameters
|
|
102
|
+
): Promise<QuoteWithDeltaPrice | QuoteWithMarketPriceAsFallback>;
|
|
103
|
+
function getQuote(
|
|
104
|
+
options: QuoteParams,
|
|
105
|
+
requestParams?: RequestParameters
|
|
106
|
+
): Promise<QuoteResponse>;
|
|
107
|
+
async function getQuote(
|
|
108
|
+
options: QuoteParams,
|
|
109
|
+
requestParams?: RequestParameters
|
|
110
|
+
): Promise<QuoteResponse> {
|
|
111
|
+
const search = constructSearchString<QuoteQueryOptions>({
|
|
112
|
+
...options,
|
|
113
|
+
chainId,
|
|
114
|
+
// side: SwapSide.SELL, // so far SELL side only for Delta
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const fetchURL = `${pricesUrl}/${search}` as const;
|
|
118
|
+
|
|
119
|
+
const data = await fetcher<QuoteResponse>({
|
|
120
|
+
url: fetchURL,
|
|
121
|
+
method: 'GET',
|
|
122
|
+
requestParams,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
getQuote,
|
|
130
|
+
};
|
|
131
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConstructFetchInput,
|
|
3
|
+
APIVersion,
|
|
4
|
+
RequestParameters,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
7
|
+
import { API_URL, DEFAULT_VERSION } from '../../constants';
|
|
8
|
+
|
|
9
|
+
type AdaptersAsStrings = string[];
|
|
10
|
+
|
|
11
|
+
export type GetAdaptersFunctions = {
|
|
12
|
+
getAdapters: (
|
|
13
|
+
requestParams?: RequestParameters
|
|
14
|
+
) => Promise<AdaptersAsStrings>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type SearchStringParams = {
|
|
18
|
+
network: number;
|
|
19
|
+
version?: APIVersion;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const constructGetAdapters = ({
|
|
23
|
+
apiURL = API_URL,
|
|
24
|
+
version = DEFAULT_VERSION,
|
|
25
|
+
chainId,
|
|
26
|
+
fetcher,
|
|
27
|
+
}: ConstructFetchInput): GetAdaptersFunctions => {
|
|
28
|
+
const getAdapters: GetAdaptersFunctions['getAdapters'] = async (
|
|
29
|
+
requestParams
|
|
30
|
+
): Promise<AdaptersAsStrings> => {
|
|
31
|
+
// always pass explicit type to make sure UrlSearchParams are correct
|
|
32
|
+
const query = constructSearchString<SearchStringParams>({
|
|
33
|
+
network: chainId,
|
|
34
|
+
version,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const fetchURL = `${apiURL}/adapters/list${query}` as const;
|
|
38
|
+
|
|
39
|
+
const data = await fetcher<AdaptersAsStrings>({
|
|
40
|
+
url: fetchURL,
|
|
41
|
+
method: 'GET',
|
|
42
|
+
requestParams,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return { getAdapters };
|
|
49
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { constructGetSpender } from './spender';
|
|
2
|
+
import type {
|
|
3
|
+
ConstructProviderFetchInput,
|
|
4
|
+
TxSendOverrides,
|
|
5
|
+
Address,
|
|
6
|
+
PriceString,
|
|
7
|
+
RequestParameters,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { ApproveToken, approveTokenMethodFactory } from '../../helpers/approve';
|
|
10
|
+
|
|
11
|
+
type ApproveTokenBulk<T> = (
|
|
12
|
+
amount: PriceString,
|
|
13
|
+
tokenAddresses: Address[],
|
|
14
|
+
overrides?: TxSendOverrides,
|
|
15
|
+
requestParams?: RequestParameters
|
|
16
|
+
) => Promise<Awaited<T>[]>;
|
|
17
|
+
|
|
18
|
+
export type ApproveTokenFunctions<T> = {
|
|
19
|
+
approveToken: ApproveToken<T>;
|
|
20
|
+
approveTokenBulk: ApproveTokenBulk<T>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// returns whatever `contractCaller` returns
|
|
24
|
+
// to allow for better versatility
|
|
25
|
+
export const constructApproveToken = <T>(
|
|
26
|
+
options: ConstructProviderFetchInput<T, 'transactCall'>
|
|
27
|
+
): ApproveTokenFunctions<T> => {
|
|
28
|
+
// getSpender is cached internally for the same instance of SDK
|
|
29
|
+
// so should persist across same apiUrl & network
|
|
30
|
+
const { getSpender } = constructGetSpender(options);
|
|
31
|
+
|
|
32
|
+
const approveToken: ApproveToken<T> = approveTokenMethodFactory<T>(
|
|
33
|
+
options.contractCaller,
|
|
34
|
+
getSpender
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const approveTokenBulk: ApproveTokenBulk<T> = async (
|
|
38
|
+
amount,
|
|
39
|
+
tokenAddresses,
|
|
40
|
+
overrides,
|
|
41
|
+
requestParams
|
|
42
|
+
) => {
|
|
43
|
+
return Promise.all(
|
|
44
|
+
tokenAddresses.map((tokenAddress) =>
|
|
45
|
+
approveToken(amount, tokenAddress, overrides, requestParams)
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return { approveToken, approveTokenBulk };
|
|
51
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { API_URL } from '../../constants';
|
|
2
|
+
import {
|
|
3
|
+
Token,
|
|
4
|
+
Address,
|
|
5
|
+
constructToken,
|
|
6
|
+
AddressOrSymbol,
|
|
7
|
+
} from '../../helpers/token';
|
|
8
|
+
import type {
|
|
9
|
+
ConstructFetchInput,
|
|
10
|
+
TokenApiResponse,
|
|
11
|
+
TokensApiResponse,
|
|
12
|
+
RequestParameters,
|
|
13
|
+
} from '../../types';
|
|
14
|
+
|
|
15
|
+
type GetBalances = (
|
|
16
|
+
userAddress: Address,
|
|
17
|
+
requestParams?: RequestParameters
|
|
18
|
+
) => Promise<Token[]>;
|
|
19
|
+
type GetBalance = (
|
|
20
|
+
userAddress: Address,
|
|
21
|
+
tokenAddressOrSymbol: AddressOrSymbol,
|
|
22
|
+
requestParams?: RequestParameters
|
|
23
|
+
) => Promise<Token | typeof NOT_FOUND_RESPONSE>;
|
|
24
|
+
|
|
25
|
+
export interface Allowance {
|
|
26
|
+
tokenAddress: Address;
|
|
27
|
+
allowance: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type GetAllowances = (
|
|
31
|
+
userAddress: Address,
|
|
32
|
+
tokenAddresses: Address[],
|
|
33
|
+
requestParams?: RequestParameters
|
|
34
|
+
) => Promise<Allowance[]>;
|
|
35
|
+
type GetAllowance = (
|
|
36
|
+
userAddress: Address,
|
|
37
|
+
tokenAddress: Address,
|
|
38
|
+
requestParams?: RequestParameters
|
|
39
|
+
) => Promise<Allowance | typeof NOT_FOUND_RESPONSE>;
|
|
40
|
+
|
|
41
|
+
export const isAllowance = (
|
|
42
|
+
arg: Awaited<ReturnType<GetAllowance>>
|
|
43
|
+
): arg is Allowance => {
|
|
44
|
+
return 'allowance' in arg;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type GetBalancesFunctions = {
|
|
48
|
+
getBalance: GetBalance;
|
|
49
|
+
getBalances: GetBalances;
|
|
50
|
+
getAllowance: GetAllowance;
|
|
51
|
+
getAllowances: GetAllowances;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const NOT_FOUND_RESPONSE = { message: 'Not Found' } as const;
|
|
55
|
+
|
|
56
|
+
export const constructGetBalances = ({
|
|
57
|
+
apiURL = API_URL,
|
|
58
|
+
chainId,
|
|
59
|
+
fetcher,
|
|
60
|
+
}: ConstructFetchInput): GetBalancesFunctions => {
|
|
61
|
+
const tokensUrl = `${apiURL}/users/tokens/${chainId}` as const;
|
|
62
|
+
|
|
63
|
+
const getBalances: GetBalances = async (userAddress, requestParams) => {
|
|
64
|
+
const fetchURL = `${tokensUrl}/${userAddress}` as const;
|
|
65
|
+
|
|
66
|
+
const data = await fetcher<TokensApiResponse>({
|
|
67
|
+
url: fetchURL,
|
|
68
|
+
method: 'GET',
|
|
69
|
+
requestParams,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const tokens = data.tokens.map(constructToken);
|
|
73
|
+
|
|
74
|
+
return tokens;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getBalance: GetBalance = async (
|
|
78
|
+
userAddress,
|
|
79
|
+
tokenAddressOrSymbol,
|
|
80
|
+
requestParams
|
|
81
|
+
) => {
|
|
82
|
+
const fetchURL =
|
|
83
|
+
`${tokensUrl}/${userAddress}/${tokenAddressOrSymbol}` as const;
|
|
84
|
+
|
|
85
|
+
const data = await fetcher<TokenApiResponse>({
|
|
86
|
+
url: fetchURL,
|
|
87
|
+
method: 'GET',
|
|
88
|
+
requestParams,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!data.token) {
|
|
92
|
+
return NOT_FOUND_RESPONSE;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return constructToken(data.token);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const getAllowances: GetAllowances = async (
|
|
99
|
+
userAddress,
|
|
100
|
+
tokenAddresses,
|
|
101
|
+
requestParams
|
|
102
|
+
) => {
|
|
103
|
+
const tokenAddressesLowercaseSet = new Set(
|
|
104
|
+
tokenAddresses.map((address) => address.toLowerCase())
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const balances = await getBalances(userAddress, requestParams);
|
|
108
|
+
|
|
109
|
+
const allowances: Allowance[] = balances
|
|
110
|
+
.filter((token) =>
|
|
111
|
+
tokenAddressesLowercaseSet.has(token.address.toLowerCase())
|
|
112
|
+
)
|
|
113
|
+
.map(({ address, allowance = '0' }) => ({
|
|
114
|
+
tokenAddress: address,
|
|
115
|
+
allowance,
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
return allowances;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getAllowance: GetAllowance = async (
|
|
122
|
+
userAddress,
|
|
123
|
+
tokenAddress,
|
|
124
|
+
requestParams
|
|
125
|
+
) => {
|
|
126
|
+
const balanceOrNotFound = await getBalance(
|
|
127
|
+
userAddress,
|
|
128
|
+
tokenAddress,
|
|
129
|
+
requestParams
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
if ('message' in balanceOrNotFound) {
|
|
133
|
+
return balanceOrNotFound;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { address, allowance = '0' } = balanceOrNotFound;
|
|
137
|
+
|
|
138
|
+
return { tokenAddress: address, allowance };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
getBalance,
|
|
143
|
+
getBalances,
|
|
144
|
+
getAllowance,
|
|
145
|
+
getAllowances,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PickKeys } from 'ts-essentials';
|
|
2
|
+
import type { RateOptions } from '../rates';
|
|
3
|
+
|
|
4
|
+
type StringArrKeys = PickKeys<RateOptions, string[] | undefined>;
|
|
5
|
+
|
|
6
|
+
type MinRateOptionsInput = Pick<RateOptions, StringArrKeys> &
|
|
7
|
+
Pick<RateOptions, 'partner'>;
|
|
8
|
+
|
|
9
|
+
type NormalizedRateOptions<
|
|
10
|
+
O extends MinRateOptionsInput,
|
|
11
|
+
T extends { options?: Partial<O> }
|
|
12
|
+
> = Partial<Record<StringArrKeys | 'partner', string>> &
|
|
13
|
+
Partial<Omit<O, StringArrKeys | 'partner'>> &
|
|
14
|
+
Omit<T, 'options'>;
|
|
15
|
+
|
|
16
|
+
export function normalizeRateOptions<
|
|
17
|
+
O extends MinRateOptionsInput,
|
|
18
|
+
T extends { options?: Partial<O> }
|
|
19
|
+
>({ options = {}, ...restInput }: T): NormalizedRateOptions<O, T> {
|
|
20
|
+
const {
|
|
21
|
+
excludeContractMethods,
|
|
22
|
+
includeContractMethods,
|
|
23
|
+
partner,
|
|
24
|
+
includeDEXS,
|
|
25
|
+
excludeDEXS,
|
|
26
|
+
excludePools,
|
|
27
|
+
...restOptions
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
const [
|
|
31
|
+
_includeDEXS,
|
|
32
|
+
_excludeDEXS,
|
|
33
|
+
_excludePools,
|
|
34
|
+
_excludeContractMethods,
|
|
35
|
+
_includeContractMethods,
|
|
36
|
+
] = [
|
|
37
|
+
includeDEXS,
|
|
38
|
+
excludeDEXS,
|
|
39
|
+
excludePools,
|
|
40
|
+
excludeContractMethods,
|
|
41
|
+
includeContractMethods,
|
|
42
|
+
// no "" empty string
|
|
43
|
+
].map((array) => array?.join(',') || undefined);
|
|
44
|
+
|
|
45
|
+
const transformed: Partial<Record<StringArrKeys | 'partner', string>> = {
|
|
46
|
+
excludeContractMethods: _excludeContractMethods,
|
|
47
|
+
includeContractMethods: _includeContractMethods,
|
|
48
|
+
partner,
|
|
49
|
+
includeDEXS: _includeDEXS,
|
|
50
|
+
excludeDEXS: _excludeDEXS,
|
|
51
|
+
excludePools: _excludePools,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return { ...transformed, ...restOptions, ...restInput };
|
|
55
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { constructPartialSDK, SDKConfig } from '../../sdk/partial';
|
|
2
|
+
import { constructGetAdapters, GetAdaptersFunctions } from './adapters';
|
|
3
|
+
import { ApproveTokenFunctions, constructApproveToken } from './approve';
|
|
4
|
+
import { constructGetBalances, GetBalancesFunctions } from './balance';
|
|
5
|
+
import { constructGetRate, GetRateFunctions } from './rates';
|
|
6
|
+
import { constructGetSpender, GetSpenderFunctions } from './spender';
|
|
7
|
+
import { constructSwapTx, GetSwapTxFunctions } from './swapTx';
|
|
8
|
+
import { constructGetTokens, GetTokensFunctions } from './token';
|
|
9
|
+
import { BuildTxFunctions, constructBuildTx } from './transaction';
|
|
10
|
+
|
|
11
|
+
export type SwapSDKMethods<TxResponse> = GetBalancesFunctions &
|
|
12
|
+
GetTokensFunctions &
|
|
13
|
+
GetSpenderFunctions &
|
|
14
|
+
ApproveTokenFunctions<TxResponse> &
|
|
15
|
+
BuildTxFunctions &
|
|
16
|
+
GetAdaptersFunctions &
|
|
17
|
+
GetRateFunctions &
|
|
18
|
+
GetSwapTxFunctions;
|
|
19
|
+
|
|
20
|
+
/** @description construct SDK with every Swap-related method, fetching from API and token approval */
|
|
21
|
+
export const constructSwapSDK = <TxResponse>(
|
|
22
|
+
config: SDKConfig<TxResponse>
|
|
23
|
+
): SwapSDKMethods<TxResponse> => {
|
|
24
|
+
const constructApproveTokenWithTxResponse = constructApproveToken<TxResponse>;
|
|
25
|
+
|
|
26
|
+
// include all available Swap methods
|
|
27
|
+
return constructPartialSDK(
|
|
28
|
+
config,
|
|
29
|
+
constructGetBalances,
|
|
30
|
+
constructGetTokens,
|
|
31
|
+
constructGetSpender,
|
|
32
|
+
constructApproveTokenWithTxResponse,
|
|
33
|
+
constructBuildTx,
|
|
34
|
+
constructGetAdapters,
|
|
35
|
+
constructGetRate,
|
|
36
|
+
constructSwapTx
|
|
37
|
+
);
|
|
38
|
+
};
|