@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,56 @@
|
|
|
1
|
+
import { DEFAULT_VERSION } from '../../constants';
|
|
2
|
+
import type { ConstructFetchInput, RequestParameters } from '../../types';
|
|
3
|
+
import { constructGetSpender } from '../swap/spender';
|
|
4
|
+
import {
|
|
5
|
+
buildOrderData,
|
|
6
|
+
BuildOrderDataInput,
|
|
7
|
+
SignableOrderData,
|
|
8
|
+
} from './helpers/buildOrderData';
|
|
9
|
+
export * from './helpers/buildOrderData';
|
|
10
|
+
|
|
11
|
+
export type BuildLimitOrderInput = Omit<
|
|
12
|
+
BuildOrderDataInput,
|
|
13
|
+
'chainId' | 'verifyingContract' | 'AugustusAddress' | 'AppVersion'
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
type BuildLimitOrder = (
|
|
17
|
+
buildLimitOrderParams: BuildLimitOrderInput,
|
|
18
|
+
requestParams?: RequestParameters
|
|
19
|
+
) => Promise<SignableOrderData>;
|
|
20
|
+
|
|
21
|
+
export type BuildLimitOrderFunctions = {
|
|
22
|
+
/** @description Build Orders that will be excuted through AugustusSwapper */
|
|
23
|
+
buildLimitOrder: BuildLimitOrder;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const constructBuildLimitOrder = (
|
|
27
|
+
options: ConstructFetchInput
|
|
28
|
+
): BuildLimitOrderFunctions => {
|
|
29
|
+
const { chainId } = options;
|
|
30
|
+
|
|
31
|
+
// getContracts is cached internally for the same instance of SDK
|
|
32
|
+
// so should persist across same apiUrl & network
|
|
33
|
+
const { getContracts } = constructGetSpender(options);
|
|
34
|
+
|
|
35
|
+
const buildLimitOrder: BuildLimitOrder = async (
|
|
36
|
+
buildLimitOrderParams,
|
|
37
|
+
requestParams
|
|
38
|
+
) => {
|
|
39
|
+
const { AugustusSwapper: AugustusAddress, AugustusRFQ: verifyingContract } =
|
|
40
|
+
await getContracts(requestParams);
|
|
41
|
+
|
|
42
|
+
const AppVersion = options.version ?? DEFAULT_VERSION;
|
|
43
|
+
|
|
44
|
+
return buildOrderData({
|
|
45
|
+
...buildLimitOrderParams,
|
|
46
|
+
chainId,
|
|
47
|
+
verifyingContract,
|
|
48
|
+
AugustusAddress,
|
|
49
|
+
AppVersion,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
buildLimitOrder,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { ExtractAbiMethodNames } from '../../helpers/misc';
|
|
2
|
+
import type {
|
|
3
|
+
ConstructProviderFetchInput,
|
|
4
|
+
RequestParameters,
|
|
5
|
+
TxSendOverrides,
|
|
6
|
+
} from '../../types';
|
|
7
|
+
import { constructGetSpender } from '../swap/spender';
|
|
8
|
+
|
|
9
|
+
export type CancelOrder<T> = (
|
|
10
|
+
orderHash: string,
|
|
11
|
+
overrides?: TxSendOverrides,
|
|
12
|
+
requestParams?: RequestParameters
|
|
13
|
+
) => Promise<T>;
|
|
14
|
+
|
|
15
|
+
export type CancelOrderBulk<T> = (
|
|
16
|
+
orderHashes: string[],
|
|
17
|
+
overrides?: TxSendOverrides,
|
|
18
|
+
requestParams?: RequestParameters
|
|
19
|
+
) => Promise<T>;
|
|
20
|
+
|
|
21
|
+
export type CancelLimitOrderFunctions<T> = {
|
|
22
|
+
cancelLimitOrder: CancelOrder<T>;
|
|
23
|
+
cancelLimitOrderBulk: CancelOrderBulk<T>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// much smaller than the whole AugustusRFQ_ABI
|
|
27
|
+
const MinAugustusRFQAbi = [
|
|
28
|
+
{
|
|
29
|
+
inputs: [
|
|
30
|
+
{
|
|
31
|
+
internalType: 'bytes32',
|
|
32
|
+
name: 'orderHash',
|
|
33
|
+
type: 'bytes32',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
name: 'cancelOrder',
|
|
37
|
+
outputs: [],
|
|
38
|
+
stateMutability: 'nonpayable',
|
|
39
|
+
type: 'function',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
inputs: [
|
|
43
|
+
{
|
|
44
|
+
internalType: 'bytes32[]',
|
|
45
|
+
name: 'orderHashes',
|
|
46
|
+
type: 'bytes32[]',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
name: 'cancelOrders',
|
|
50
|
+
outputs: [],
|
|
51
|
+
stateMutability: 'nonpayable',
|
|
52
|
+
type: 'function',
|
|
53
|
+
},
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
type AvailableMethods = ExtractAbiMethodNames<typeof MinAugustusRFQAbi>;
|
|
57
|
+
|
|
58
|
+
// returns whatever `contractCaller` returns
|
|
59
|
+
// to allow for better versatility
|
|
60
|
+
export const constructCancelLimitOrder = <T>(
|
|
61
|
+
options: ConstructProviderFetchInput<T, 'transactCall'>
|
|
62
|
+
): CancelLimitOrderFunctions<T> => {
|
|
63
|
+
// getAugustusRFQ is cached internally for the same instance of SDK
|
|
64
|
+
// so should persist across same apiUrl & network
|
|
65
|
+
const { getAugustusRFQ } = constructGetSpender(options);
|
|
66
|
+
|
|
67
|
+
const cancelLimitOrder: CancelOrder<T> = async (
|
|
68
|
+
orderHash,
|
|
69
|
+
overrides = {},
|
|
70
|
+
requestParams
|
|
71
|
+
) => {
|
|
72
|
+
const verifyingContract = await getAugustusRFQ(requestParams);
|
|
73
|
+
|
|
74
|
+
const res = await options.contractCaller.transactCall<AvailableMethods>({
|
|
75
|
+
// @CHECK if verifyingContract is the one we need to approve
|
|
76
|
+
// maybe a Proxy in-between
|
|
77
|
+
address: verifyingContract,
|
|
78
|
+
abi: MinAugustusRFQAbi,
|
|
79
|
+
contractMethod: 'cancelOrder',
|
|
80
|
+
args: [orderHash],
|
|
81
|
+
overrides,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return res;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const cancelLimitOrderBulk: CancelOrderBulk<T> = async (
|
|
88
|
+
orderHashes,
|
|
89
|
+
overrides = {},
|
|
90
|
+
requestParams
|
|
91
|
+
) => {
|
|
92
|
+
const verifyingContract = await getAugustusRFQ(requestParams);
|
|
93
|
+
|
|
94
|
+
const res = await options.contractCaller.transactCall<AvailableMethods>({
|
|
95
|
+
// @CHECK if verifyingContract is the one we need to approve
|
|
96
|
+
// maybe a Proxy in-between
|
|
97
|
+
address: verifyingContract,
|
|
98
|
+
abi: MinAugustusRFQAbi,
|
|
99
|
+
contractMethod: 'cancelOrders',
|
|
100
|
+
args: [orderHashes],
|
|
101
|
+
overrides,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return res;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
cancelLimitOrder,
|
|
109
|
+
cancelLimitOrderBulk,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type { ExtractAbiMethodNames } from '../../helpers/misc';
|
|
2
|
+
import type {
|
|
3
|
+
ConstructProviderFetchInput,
|
|
4
|
+
RequestParameters,
|
|
5
|
+
TxSendOverrides,
|
|
6
|
+
} from '../../types';
|
|
7
|
+
import type { OrderData } from './buildOrder';
|
|
8
|
+
import { constructGetSpender } from '../swap/spender';
|
|
9
|
+
import { sanitizeOrderData } from './helpers/misc';
|
|
10
|
+
import {
|
|
11
|
+
encodeDAIlikePermitFunctionInput,
|
|
12
|
+
encodeEIP_2612PermitFunctionInput,
|
|
13
|
+
} from '../common/orders/encoding';
|
|
14
|
+
|
|
15
|
+
export type FillOrderDirectlyFunctions<T> = {
|
|
16
|
+
fillOrderDirectly: FillOrderDirectly<T>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type TakerPermitEncodedInputParams = {
|
|
20
|
+
encodedPermitParams: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type TakerPermit1Data = {
|
|
24
|
+
signature: string;
|
|
25
|
+
deadline: number | bigint | string;
|
|
26
|
+
amount?: string;
|
|
27
|
+
isDaiPermit?: false;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type TakerDaiPermitData = {
|
|
31
|
+
signature: string;
|
|
32
|
+
expiry: number | bigint | string;
|
|
33
|
+
nonce: number | bigint | string;
|
|
34
|
+
isDaiPermit: true;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type TakerPermitObject =
|
|
38
|
+
| TakerPermitEncodedInputParams
|
|
39
|
+
| TakerPermit1Data
|
|
40
|
+
| TakerDaiPermitData;
|
|
41
|
+
|
|
42
|
+
export type FillOrderDirectly<T> = (
|
|
43
|
+
orderFillData: {
|
|
44
|
+
order: OrderData;
|
|
45
|
+
signature: string;
|
|
46
|
+
/** @description Permit1 data or DAI Permit data or Token.parmit() input params encoded; Permit by taker for Taker Asset with AugustusRFQ as spender */
|
|
47
|
+
takerPermit?: TakerPermitObject;
|
|
48
|
+
},
|
|
49
|
+
overrides?: TxSendOverrides,
|
|
50
|
+
requestParams?: RequestParameters
|
|
51
|
+
) => Promise<T>;
|
|
52
|
+
|
|
53
|
+
// much smaller than the whole AugustusRFQ_ABI
|
|
54
|
+
const MinAugustusRFQAbi = [
|
|
55
|
+
{
|
|
56
|
+
inputs: [
|
|
57
|
+
{
|
|
58
|
+
components: [
|
|
59
|
+
{
|
|
60
|
+
internalType: 'uint256',
|
|
61
|
+
name: 'nonceAndMeta',
|
|
62
|
+
type: 'uint256',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
internalType: 'uint128',
|
|
66
|
+
name: 'expiry',
|
|
67
|
+
type: 'uint128',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
internalType: 'address',
|
|
71
|
+
name: 'makerAsset',
|
|
72
|
+
type: 'address',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
internalType: 'address',
|
|
76
|
+
name: 'takerAsset',
|
|
77
|
+
type: 'address',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
internalType: 'address',
|
|
81
|
+
name: 'maker',
|
|
82
|
+
type: 'address',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
internalType: 'address',
|
|
86
|
+
name: 'taker',
|
|
87
|
+
type: 'address',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
internalType: 'uint256',
|
|
91
|
+
name: 'makerAmount',
|
|
92
|
+
type: 'uint256',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
internalType: 'uint256',
|
|
96
|
+
name: 'takerAmount',
|
|
97
|
+
type: 'uint256',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
internalType: 'struct AugustusRFQ.Order',
|
|
101
|
+
name: 'order',
|
|
102
|
+
type: 'tuple',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
internalType: 'bytes',
|
|
106
|
+
name: 'signature',
|
|
107
|
+
type: 'bytes',
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
name: 'fillOrder',
|
|
111
|
+
outputs: [],
|
|
112
|
+
stateMutability: 'nonpayable',
|
|
113
|
+
type: 'function',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
inputs: [
|
|
117
|
+
{
|
|
118
|
+
components: [
|
|
119
|
+
{
|
|
120
|
+
internalType: 'uint256',
|
|
121
|
+
name: 'nonceAndMeta',
|
|
122
|
+
type: 'uint256',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
internalType: 'uint128',
|
|
126
|
+
name: 'expiry',
|
|
127
|
+
type: 'uint128',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
internalType: 'address',
|
|
131
|
+
name: 'makerAsset',
|
|
132
|
+
type: 'address',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
internalType: 'address',
|
|
136
|
+
name: 'takerAsset',
|
|
137
|
+
type: 'address',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
internalType: 'address',
|
|
141
|
+
name: 'maker',
|
|
142
|
+
type: 'address',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
internalType: 'address',
|
|
146
|
+
name: 'taker',
|
|
147
|
+
type: 'address',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
internalType: 'uint256',
|
|
151
|
+
name: 'makerAmount',
|
|
152
|
+
type: 'uint256',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
internalType: 'uint256',
|
|
156
|
+
name: 'takerAmount',
|
|
157
|
+
type: 'uint256',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
internalType: 'struct AugustusRFQ.Order',
|
|
161
|
+
name: 'order',
|
|
162
|
+
type: 'tuple',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
internalType: 'bytes',
|
|
166
|
+
name: 'signature',
|
|
167
|
+
type: 'bytes',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
internalType: 'uint256',
|
|
171
|
+
name: 'takerTokenFillAmount',
|
|
172
|
+
type: 'uint256',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
internalType: 'address',
|
|
176
|
+
name: 'target',
|
|
177
|
+
type: 'address',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
internalType: 'bytes',
|
|
181
|
+
name: 'permitTakerAsset',
|
|
182
|
+
type: 'bytes',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
internalType: 'bytes',
|
|
186
|
+
name: 'permitMakerAsset',
|
|
187
|
+
type: 'bytes',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
name: 'partialFillOrderWithTargetPermit',
|
|
191
|
+
outputs: [
|
|
192
|
+
{
|
|
193
|
+
internalType: 'uint256',
|
|
194
|
+
name: 'makerTokenFilledAmount',
|
|
195
|
+
type: 'uint256',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
stateMutability: 'nonpayable',
|
|
199
|
+
type: 'function',
|
|
200
|
+
},
|
|
201
|
+
] as const;
|
|
202
|
+
|
|
203
|
+
type FillOrderMethods = ExtractAbiMethodNames<typeof MinAugustusRFQAbi>;
|
|
204
|
+
|
|
205
|
+
// returns whatever `contractCaller` returns
|
|
206
|
+
// to allow for better versatility
|
|
207
|
+
export function constructFillOrderDirectly<T>(
|
|
208
|
+
options: ConstructProviderFetchInput<T, 'transactCall'>
|
|
209
|
+
): FillOrderDirectlyFunctions<T> {
|
|
210
|
+
// getAugustusRFQ is cached internally for the same instance of SDK
|
|
211
|
+
// so should persist across same apiUrl & network
|
|
212
|
+
const { getAugustusRFQ } = constructGetSpender(options);
|
|
213
|
+
|
|
214
|
+
const fillOrderDirectly: FillOrderDirectly<T> = async (
|
|
215
|
+
{ order, signature, takerPermit },
|
|
216
|
+
overrides = {},
|
|
217
|
+
requestParams
|
|
218
|
+
) => {
|
|
219
|
+
const AugustusRFQ = await getAugustusRFQ(requestParams);
|
|
220
|
+
|
|
221
|
+
const sanitizedOrder = sanitizeOrderData(order);
|
|
222
|
+
|
|
223
|
+
if (!takerPermit) {
|
|
224
|
+
const res = await options.contractCaller.transactCall<FillOrderMethods>({
|
|
225
|
+
address: AugustusRFQ,
|
|
226
|
+
abi: MinAugustusRFQAbi,
|
|
227
|
+
contractMethod: 'fillOrder',
|
|
228
|
+
args: [sanitizedOrder, signature],
|
|
229
|
+
overrides,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
return res;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let permitTakerAsset: string;
|
|
236
|
+
if ('encodedPermitParams' in takerPermit) {
|
|
237
|
+
permitTakerAsset = takerPermit.encodedPermitParams;
|
|
238
|
+
} else if ('isDaiPermit' in takerPermit && takerPermit.isDaiPermit) {
|
|
239
|
+
// encoded DAI.permit() function params by taker with AugustusRFQ as spender
|
|
240
|
+
permitTakerAsset = encodeDAIlikePermitFunctionInput({
|
|
241
|
+
holder: order.taker,
|
|
242
|
+
spender: AugustusRFQ,
|
|
243
|
+
expiry: takerPermit.expiry,
|
|
244
|
+
nonce: takerPermit.nonce,
|
|
245
|
+
permitSignature: takerPermit.signature,
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
// encoded TakerAsset.permit() function params by taker with AugustusRFQ as spender, Permit1 only
|
|
249
|
+
permitTakerAsset = encodeEIP_2612PermitFunctionInput({
|
|
250
|
+
owner: order.taker,
|
|
251
|
+
spender: AugustusRFQ,
|
|
252
|
+
value: takerPermit.amount || order.takerAmount, // can use permit with a bigger value, fallback to exact Order takerAmount
|
|
253
|
+
deadline: takerPermit.deadline,
|
|
254
|
+
permitSignature: takerPermit.signature,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const res = await options.contractCaller.transactCall<FillOrderMethods>({
|
|
259
|
+
address: AugustusRFQ,
|
|
260
|
+
abi: MinAugustusRFQAbi,
|
|
261
|
+
contractMethod: 'partialFillOrderWithTargetPermit',
|
|
262
|
+
args: [
|
|
263
|
+
sanitizedOrder, // order
|
|
264
|
+
signature, // order.signature
|
|
265
|
+
order.takerAmount, // takerTokenFillAmount, can even partially fill
|
|
266
|
+
order.taker, // target
|
|
267
|
+
permitTakerAsset,
|
|
268
|
+
'0x', // permitMakerAsset, unused because hard to account for changing nonce for long running Orders
|
|
269
|
+
],
|
|
270
|
+
overrides,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return res;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
return { fillOrderDirectly };
|
|
277
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// @TODO getOrder, getOrders from API
|
|
2
|
+
// onchain from contract can't distinguish between filled or cancelled
|
|
3
|
+
import { API_URL } from '../../constants';
|
|
4
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
5
|
+
import type {
|
|
6
|
+
Address,
|
|
7
|
+
ConstructFetchInput,
|
|
8
|
+
RequestParameters,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import {
|
|
11
|
+
constructBaseFetchUrlGetter,
|
|
12
|
+
GetOrdersURLs,
|
|
13
|
+
GetOrderURL,
|
|
14
|
+
GetRequiredAllowanceURL as GetRequiredBalanceURL,
|
|
15
|
+
} from './helpers/misc';
|
|
16
|
+
import type {
|
|
17
|
+
LimitOrderFromApi,
|
|
18
|
+
LimitOrdersApiResponse,
|
|
19
|
+
LimitOrderType,
|
|
20
|
+
} from './helpers/types';
|
|
21
|
+
|
|
22
|
+
type PaginationParams = {
|
|
23
|
+
limit?: number;
|
|
24
|
+
offset?: number;
|
|
25
|
+
hideSmallBalances?: boolean;
|
|
26
|
+
orderBy?: 'createdAt' | 'updatedAt' | 'expiry';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// get orders by `maker` or `taker`
|
|
30
|
+
export type LimitOrdersUserParams = (
|
|
31
|
+
| { maker: Address; type: LimitOrderType }
|
|
32
|
+
| { taker: Address; type: LimitOrderType }
|
|
33
|
+
) &
|
|
34
|
+
PaginationParams;
|
|
35
|
+
|
|
36
|
+
export type GetRequiredAllowanceParams = {
|
|
37
|
+
maker: Address;
|
|
38
|
+
token?: Address;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type GetLimitOrderByHash = (
|
|
42
|
+
orderHash: string,
|
|
43
|
+
requestParams?: RequestParameters
|
|
44
|
+
) => Promise<LimitOrderFromApi>;
|
|
45
|
+
type GetLimitOrders = (
|
|
46
|
+
userParams: LimitOrdersUserParams,
|
|
47
|
+
requestParams?: RequestParameters
|
|
48
|
+
) => Promise<LimitOrdersApiResponse>;
|
|
49
|
+
|
|
50
|
+
type GetRequiredBalance = (
|
|
51
|
+
userParams: GetRequiredAllowanceParams,
|
|
52
|
+
requestParams?: RequestParameters
|
|
53
|
+
) => Promise<Record<string, string>>;
|
|
54
|
+
|
|
55
|
+
export type GetLimitOrdersFunctions = {
|
|
56
|
+
getLimitOrders: GetLimitOrders;
|
|
57
|
+
getLimitOrderByHash: GetLimitOrderByHash;
|
|
58
|
+
/**
|
|
59
|
+
* Gets fillableBalance for tokens from user's active orders.
|
|
60
|
+
* User needs to have enough balance & allowance to cover active orders before creating new orders.
|
|
61
|
+
* @param userParams - parameters to get allowance for active orders
|
|
62
|
+
* @param {string} userParams.maker - user to get required allowances for
|
|
63
|
+
* @param {string=} userParams.token - if given `token`, the mapping will contain that token address only
|
|
64
|
+
* @param {RequestParameters=} requestParams - requestParams passed to fetcher, can include {signal: AbortSignal, timeout: for axios, etc.}
|
|
65
|
+
* @returns `{Lowercase<Address> => wei number as string}` mapping of token to fillableBalance
|
|
66
|
+
*/
|
|
67
|
+
getRequiredBalance: GetRequiredBalance;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const constructGetLimitOrders = ({
|
|
71
|
+
apiURL = API_URL,
|
|
72
|
+
chainId,
|
|
73
|
+
fetcher,
|
|
74
|
+
}: ConstructFetchInput): GetLimitOrdersFunctions => {
|
|
75
|
+
const getBaseFetchURLByEntityType = constructBaseFetchUrlGetter({
|
|
76
|
+
apiURL,
|
|
77
|
+
chainId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const getLimitOrders: GetLimitOrders = async (userParams, requestParams) => {
|
|
81
|
+
const baseFetchURL = getBaseFetchURLByEntityType(userParams.type);
|
|
82
|
+
const userURL =
|
|
83
|
+
'maker' in userParams
|
|
84
|
+
? (`maker/${userParams.maker}` as const)
|
|
85
|
+
: (`taker/${userParams.taker}` as const);
|
|
86
|
+
|
|
87
|
+
const { offset, limit, hideSmallBalances, orderBy } = userParams;
|
|
88
|
+
const search = constructSearchString<PaginationParams>({
|
|
89
|
+
offset,
|
|
90
|
+
limit,
|
|
91
|
+
hideSmallBalances,
|
|
92
|
+
orderBy,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const fetchURL = `${baseFetchURL}/${userURL}${search}` as const;
|
|
96
|
+
|
|
97
|
+
const response = await fetcher<LimitOrdersApiResponse, GetOrdersURLs>({
|
|
98
|
+
url: fetchURL,
|
|
99
|
+
method: 'GET',
|
|
100
|
+
requestParams,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// without any extra calls, return what API returns
|
|
104
|
+
return response;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const getRequiredBalance: GetRequiredBalance = async (
|
|
108
|
+
userParams,
|
|
109
|
+
requestParams
|
|
110
|
+
) => {
|
|
111
|
+
const baseFetchURL = getBaseFetchURLByEntityType('fillablebalance');
|
|
112
|
+
const userURL = `${baseFetchURL}/${userParams.maker}` as const;
|
|
113
|
+
const fetchURL = userParams.token
|
|
114
|
+
? (`${userURL}/${userParams.token}` as const)
|
|
115
|
+
: userURL;
|
|
116
|
+
|
|
117
|
+
const response = await fetcher<
|
|
118
|
+
Record<string, string>,
|
|
119
|
+
GetRequiredBalanceURL
|
|
120
|
+
>({
|
|
121
|
+
url: fetchURL,
|
|
122
|
+
method: 'GET',
|
|
123
|
+
requestParams,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// without any extra calls, return what API returns
|
|
127
|
+
return response;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const getLimitOrderByHash: GetLimitOrderByHash = async (
|
|
131
|
+
orderHash,
|
|
132
|
+
requestParams
|
|
133
|
+
) => {
|
|
134
|
+
const baseFetchURL = getBaseFetchURLByEntityType();
|
|
135
|
+
const fetchURL = `${baseFetchURL}/${orderHash}` as const;
|
|
136
|
+
|
|
137
|
+
const order = await fetcher<LimitOrderFromApi, GetOrderURL>({
|
|
138
|
+
url: fetchURL,
|
|
139
|
+
method: 'GET',
|
|
140
|
+
requestParams,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return order;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
getLimitOrders,
|
|
148
|
+
getLimitOrderByHash,
|
|
149
|
+
getRequiredBalance,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ConstructFetchInput } from '../../types';
|
|
2
|
+
import { constructGetSpender, GetSpender } from '../swap/spender';
|
|
3
|
+
|
|
4
|
+
export type GetLimitOrdersContractFunctions = {
|
|
5
|
+
getLimitOrdersContract: GetSpender;
|
|
6
|
+
getTokenTransferProxy: GetSpender;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const constructGetLimitOrdersContract = (
|
|
10
|
+
options: ConstructFetchInput
|
|
11
|
+
): GetLimitOrdersContractFunctions => {
|
|
12
|
+
// analogous to getSpender() but for Limit Orders Contract = AugustusRFQ
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
getSpender: getTokenTransferProxy,
|
|
16
|
+
getAugustusRFQ: getLimitOrdersContract,
|
|
17
|
+
} = constructGetSpender(options);
|
|
18
|
+
|
|
19
|
+
return { getLimitOrdersContract, getTokenTransferProxy };
|
|
20
|
+
};
|