@clober/v2-sdk 0.0.3-b → 0.0.4
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/dist/cjs/apis/currency.js +3 -7
- package/dist/cjs/apis/currency.js.map +1 -1
- package/dist/cjs/apis/market.js +3 -3
- package/dist/cjs/apis/market.js.map +1 -1
- package/dist/cjs/apis/open-order.js +5 -5
- package/dist/cjs/apis/open-order.js.map +1 -1
- package/dist/cjs/approval.js +4 -4
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/call.js +75 -76
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/client.js +14 -0
- package/dist/cjs/constants/client.js.map +1 -0
- package/dist/cjs/signature.js +6 -10
- package/dist/cjs/signature.js.map +1 -1
- package/dist/cjs/utils/approval.js +3 -8
- package/dist/cjs/utils/approval.js.map +1 -1
- package/dist/cjs/utils/build-transaction.js +4 -8
- package/dist/cjs/utils/build-transaction.js.map +1 -1
- package/dist/cjs/utils/decorator.js +13 -0
- package/dist/cjs/utils/decorator.js.map +1 -0
- package/dist/cjs/utils/unit.js +3 -7
- package/dist/cjs/utils/unit.js.map +1 -1
- package/dist/cjs/view.js +16 -20
- package/dist/cjs/view.js.map +1 -1
- package/dist/esm/apis/currency.js +4 -8
- package/dist/esm/apis/currency.js.map +1 -1
- package/dist/esm/apis/market.js +3 -3
- package/dist/esm/apis/market.js.map +1 -1
- package/dist/esm/apis/open-order.js +5 -5
- package/dist/esm/apis/open-order.js.map +1 -1
- package/dist/esm/approval.js +4 -3
- package/dist/esm/approval.js.map +1 -1
- package/dist/esm/call.js +75 -69
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/constants/client.js +10 -0
- package/dist/esm/constants/client.js.map +1 -0
- package/dist/esm/signature.js +7 -10
- package/dist/esm/signature.js.map +1 -1
- package/dist/esm/utils/approval.js +3 -8
- package/dist/esm/utils/approval.js.map +1 -1
- package/dist/esm/utils/build-transaction.js +5 -9
- package/dist/esm/utils/build-transaction.js.map +1 -1
- package/dist/esm/utils/decorator.js +9 -0
- package/dist/esm/utils/decorator.js.map +1 -0
- package/dist/esm/utils/unit.js +4 -8
- package/dist/esm/utils/unit.js.map +1 -1
- package/dist/esm/view.js +16 -15
- package/dist/esm/view.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/apis/currency.d.ts +1 -1
- package/dist/types/apis/currency.d.ts.map +1 -1
- package/dist/types/apis/market.d.ts +1 -1
- package/dist/types/apis/market.d.ts.map +1 -1
- package/dist/types/apis/open-order.d.ts +2 -2
- package/dist/types/apis/open-order.d.ts.map +1 -1
- package/dist/types/approval.d.ts +5 -2
- package/dist/types/approval.d.ts.map +1 -1
- package/dist/types/call.d.ts +47 -19
- package/dist/types/call.d.ts.map +1 -1
- package/dist/types/constants/client.d.ts +5 -0
- package/dist/types/constants/client.d.ts.map +1 -0
- package/dist/types/signature.d.ts +7 -3
- package/dist/types/signature.d.ts.map +1 -1
- package/dist/types/type.d.ts +3 -0
- package/dist/types/type.d.ts.map +1 -1
- package/dist/types/utils/approval.d.ts +1 -1
- package/dist/types/utils/approval.d.ts.map +1 -1
- package/dist/types/utils/build-transaction.d.ts +2 -3
- package/dist/types/utils/build-transaction.d.ts.map +1 -1
- package/dist/types/utils/decorator.d.ts +6 -0
- package/dist/types/utils/decorator.d.ts.map +1 -0
- package/dist/types/utils/unit.d.ts +1 -1
- package/dist/types/utils/unit.d.ts.map +1 -1
- package/dist/types/view.d.ts +30 -13
- package/dist/types/view.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-transaction.js","sourceRoot":"","sources":["../../../src/utils/build-transaction.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"build-transaction.js","sourceRoot":"","sources":["../../../src/utils/build-transaction.ts"],"names":[],"mappings":";;;AAAA,+BAIa;AAGb,gDAAyD;AAElD,MAAM,gBAAgB,GAAG,KAAK,EACnC,OAAkB,EAClB,IAA0D,EACpC,EAAE;IACxB,MAAM,IAAI,GAAG,IAAA,yBAAkB,EAAC,IAAI,CAAC,CAAA;IACrC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxC,4BAAmB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;YACvC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI;YACJ,EAAE,EAAE,IAAI,CAAC,OAAO;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;SACxB,CAAC;QACF,4BAAmB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE;KAC3C,CAAC,CAAA;IACF,OAAO;QACL,GAAG;QACH,QAAQ;QACR,IAAI;QACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;QACvB,EAAE,EAAE,IAAI,CAAC,OAAO;QAChB,IAAI,EAAE,IAAI,CAAC,OAAO;KACnB,CAAA;AACH,CAAC,CAAA;AAtBY,QAAA,gBAAgB,oBAsB5B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorator = void 0;
|
|
4
|
+
const client_1 = require("../constants/client");
|
|
5
|
+
function decorator(fn) {
|
|
6
|
+
return async (args) => {
|
|
7
|
+
const { chainId, options } = args;
|
|
8
|
+
(0, client_1.buildPublicClient)(chainId, options.rpcUrl);
|
|
9
|
+
return fn(args);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.decorator = decorator;
|
|
13
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/utils/decorator.ts"],"names":[],"mappings":";;;AACA,gDAAuD;AAEvD,SAAgB,SAAS,CAMvB,EAA8B;IAC9B,OAAO,KAAK,EAAE,IAAU,EAAE,EAAE;QAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAG5B,CAAA;QACD,IAAA,0BAAiB,EAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QAC1C,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;IACjB,CAAC,CAAA;AACH,CAAC;AAfD,8BAeC"}
|
package/dist/cjs/utils/unit.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateUnit = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const client_1 = require("../constants/client");
|
|
6
6
|
const _abi = [
|
|
7
7
|
{
|
|
8
8
|
inputs: [],
|
|
@@ -18,15 +18,11 @@ const _abi = [
|
|
|
18
18
|
type: 'function',
|
|
19
19
|
},
|
|
20
20
|
];
|
|
21
|
-
const calculateUnit = async (chainId, quote
|
|
21
|
+
const calculateUnit = async (chainId, quote) => {
|
|
22
22
|
if ((0, viem_1.isAddressEqual)(quote.address, viem_1.zeroAddress)) {
|
|
23
23
|
return 10n ** 12n;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
27
|
-
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
28
|
-
});
|
|
29
|
-
const totalSupply = await publicClient.readContract({
|
|
25
|
+
const totalSupply = await client_1.cachedPublicClients[chainId].readContract({
|
|
30
26
|
address: quote.address,
|
|
31
27
|
abi: _abi,
|
|
32
28
|
functionName: 'totalSupply',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../src/utils/unit.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../src/utils/unit.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAIlD,gDAAyD;AAEzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEH,MAAM,aAAa,GAAG,KAAK,EAAE,OAAkB,EAAE,KAAe,EAAE,EAAE;IACzE,IAAI,IAAA,qBAAc,EAAC,KAAK,CAAC,OAAO,EAAE,kBAAW,CAAC,EAAE,CAAC;QAC/C,OAAO,GAAG,IAAI,GAAG,CAAA;IACnB,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,4BAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAClE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAA;IACF,OAAO,CACL,GAAG;QACH,MAAM,CAAC,WAAW,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CACxE,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,aAAa,iBAazB"}
|
package/dist/cjs/view.js
CHANGED
|
@@ -6,11 +6,12 @@ const market_1 = require("./apis/market");
|
|
|
6
6
|
const prices_1 = require("./utils/prices");
|
|
7
7
|
const price_1 = require("./constants/price");
|
|
8
8
|
const open_order_1 = require("./apis/open-order");
|
|
9
|
-
const
|
|
9
|
+
const decorator_1 = require("./utils/decorator");
|
|
10
|
+
exports.getMarket = (0, decorator_1.decorator)(async ({ chainId, token0, token1, }) => {
|
|
10
11
|
if ((0, viem_1.isAddressEqual)(token0, token1)) {
|
|
11
12
|
throw new Error('Token0 and token1 must be different');
|
|
12
13
|
}
|
|
13
|
-
const market = await (0, market_1.fetchMarket)(chainId, [token0, token1]
|
|
14
|
+
const market = await (0, market_1.fetchMarket)(chainId, [token0, token1]);
|
|
14
15
|
return {
|
|
15
16
|
chainId,
|
|
16
17
|
quote: market.quote,
|
|
@@ -22,10 +23,9 @@ const getMarket = async (chainId, token0, token1, options) => {
|
|
|
22
23
|
asks: market.asks,
|
|
23
24
|
askBookOpen: market.askBookOpen,
|
|
24
25
|
};
|
|
25
|
-
};
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
28
|
-
const market = await (0, market_1.fetchMarket)(chainId, [inputToken, outputToken], options?.rpcUrl);
|
|
26
|
+
});
|
|
27
|
+
exports.getExpectedOutput = (0, decorator_1.decorator)(async ({ chainId, inputToken, outputToken, amountIn, options, }) => {
|
|
28
|
+
const market = await (0, market_1.fetchMarket)(chainId, [inputToken, outputToken]);
|
|
29
29
|
const isBid = (0, viem_1.isAddressEqual)(market.quote.address, inputToken);
|
|
30
30
|
const rawLimitPrice = options && options.limitPrice
|
|
31
31
|
? (0, prices_1.parsePrice)(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
|
|
@@ -51,10 +51,9 @@ const getExpectedOutput = async (chainId, inputToken, outputToken, amountIn, opt
|
|
|
51
51
|
spendAmount,
|
|
52
52
|
})),
|
|
53
53
|
};
|
|
54
|
-
};
|
|
55
|
-
exports.
|
|
56
|
-
const
|
|
57
|
-
const market = await (0, market_1.fetchMarket)(chainId, [inputToken, outputToken], options?.rpcUrl);
|
|
54
|
+
});
|
|
55
|
+
exports.getExpectedInput = (0, decorator_1.decorator)(async ({ chainId, inputToken, outputToken, amountOut, options, }) => {
|
|
56
|
+
const market = await (0, market_1.fetchMarket)(chainId, [inputToken, outputToken]);
|
|
58
57
|
const isBid = (0, viem_1.isAddressEqual)(market.quote.address, inputToken);
|
|
59
58
|
const rawLimitPrice = options && options.limitPrice
|
|
60
59
|
? (0, prices_1.parsePrice)(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
|
|
@@ -80,14 +79,11 @@ const getExpectedInput = async (chainId, inputToken, outputToken, amountOut, opt
|
|
|
80
79
|
spendAmount,
|
|
81
80
|
})),
|
|
82
81
|
};
|
|
83
|
-
};
|
|
84
|
-
exports.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return (0, open_order_1.fetchOpenOrders)(chainId, userAddress, options?.rpcUrl);
|
|
91
|
-
};
|
|
92
|
-
exports.getOpenOrders = getOpenOrders;
|
|
82
|
+
});
|
|
83
|
+
exports.getOpenOrder = (0, decorator_1.decorator)(async ({ chainId, id, }) => {
|
|
84
|
+
return (0, open_order_1.fetchOpenOrder)(chainId, id);
|
|
85
|
+
});
|
|
86
|
+
exports.getOpenOrders = (0, decorator_1.decorator)(async ({ chainId, userAddress, }) => {
|
|
87
|
+
return (0, open_order_1.fetchOpenOrders)(chainId, userAddress);
|
|
88
|
+
});
|
|
93
89
|
//# sourceMappingURL=view.js.map
|
package/dist/cjs/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":";;;AAAA,+BAA8D;AAE9D,0CAA2C;AAG3C,2CAA2C;AAC3C,6CAA6C;AAC7C,kDAAmE;
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":";;;AAAA,+BAA8D;AAE9D,0CAA2C;AAG3C,2CAA2C;AAC3C,6CAA6C;AAC7C,kDAAmE;AAEnE,iDAA6C;AAoBhC,QAAA,SAAS,GAAG,IAAA,qBAAS,EAChC,KAAK,EAAE,EACL,OAAO,EACP,MAAM,EACN,MAAM,GAMP,EAAmB,EAAE;IACpB,IAAI,IAAA,qBAAc,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,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AAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CACrD;QACD,WAAW,EAAE,IAAA,kBAAW,EACtB,WAAW,EACX,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CACrD;QACD,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAChC,CAAC,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,WAAW;YACX,WAAW;SACZ,CAAC,CACH;KACF,CAAA;AACH,CAAC,CACF,CAAA;AAkBY,QAAA,YAAY,GAAG,IAAA,qBAAS,EACnC,KAAK,EAAE,EACL,OAAO,EACP,EAAE,GAKH,EAAsB,EAAE;IACvB,OAAO,IAAA,2BAAc,EAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC,CACF,CAAA;AAkBY,QAAA,aAAa,GAAG,IAAA,qBAAS,EACpC,KAAK,EAAE,EACL,OAAO,EACP,WAAW,GAKZ,EAAwB,EAAE;IACzB,OAAO,IAAA,4BAAe,EAAC,OAAO,EAAE,WAAW,CAAC,CAAA;AAC9C,CAAC,CACF,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isAddressEqual, zeroAddress } from 'viem';
|
|
2
|
+
import { cachedPublicClients } from '../constants/client';
|
|
3
3
|
const _abi = [
|
|
4
4
|
{
|
|
5
5
|
inputs: [],
|
|
@@ -41,7 +41,7 @@ const _abi = [
|
|
|
41
41
|
type: 'function',
|
|
42
42
|
},
|
|
43
43
|
];
|
|
44
|
-
export const fetchCurrency = async (chainId, address
|
|
44
|
+
export const fetchCurrency = async (chainId, address) => {
|
|
45
45
|
if (isAddressEqual(address, zeroAddress)) {
|
|
46
46
|
return {
|
|
47
47
|
address: zeroAddress,
|
|
@@ -50,11 +50,7 @@ export const fetchCurrency = async (chainId, address, rpcUrl) => {
|
|
|
50
50
|
decimals: 18,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
const
|
|
54
|
-
chain: CHAIN_MAP[chainId],
|
|
55
|
-
transport: rpcUrl ? http(rpcUrl) : http(),
|
|
56
|
-
});
|
|
57
|
-
const [{ result: name }, { result: symbol }, { result: decimals }] = await publicClient.multicall({
|
|
53
|
+
const [{ result: name }, { result: symbol }, { result: decimals }] = await cachedPublicClients[chainId].multicall({
|
|
58
54
|
contracts: [
|
|
59
55
|
{
|
|
60
56
|
address,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/apis/currency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/apis/currency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAIlD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,QAAQ;gBACtB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,QAAQ;aACf;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,QAAQ;gBACtB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,QAAQ;aACf;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,OAAO;aACd;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEV,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,OAAkB,EAClB,OAAsB,EACH,EAAE;IACrB,IAAI,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QACzC,OAAO;YACL,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,EAAE;SACb,CAAA;IACH,CAAC;IAED,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAChE,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;QAC3C,SAAS,EAAE;YACT;gBACE,OAAO;gBACP,GAAG,EAAE,IAAI;gBACT,YAAY,EAAE,MAAM;aACrB;YACD;gBACE,OAAO;gBACP,GAAG,EAAE,IAAI;gBACT,YAAY,EAAE,QAAQ;aACvB;YACD;gBACE,OAAO;gBACP,GAAG,EAAE,IAAI;gBACT,YAAY,EAAE,UAAU;aACzB;SACF;KACF,CAAC,CAAA;IACJ,OAAO;QACL,OAAO;QACP,IAAI,EAAE,IAAI,IAAI,SAAS;QACvB,MAAM,EAAE,MAAM,IAAI,SAAS;QAC3B,QAAQ,EAAE,QAAQ,IAAI,EAAE;KACzB,CAAA;AACH,CAAC,CAAA"}
|
package/dist/esm/apis/market.js
CHANGED
|
@@ -10,7 +10,7 @@ const getBooks = async (chainId, baseTokenAddress, quoteTokenAddress) => {
|
|
|
10
10
|
quoteTokenAddress: quoteTokenAddress.toLowerCase(),
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
-
export async function fetchMarket(chainId, tokenAddresses
|
|
13
|
+
export async function fetchMarket(chainId, tokenAddresses) {
|
|
14
14
|
if (tokenAddresses.length !== 2) {
|
|
15
15
|
throw new Error('Invalid token pair');
|
|
16
16
|
}
|
|
@@ -19,8 +19,8 @@ export async function fetchMarket(chainId, tokenAddresses, rpcUrl) {
|
|
|
19
19
|
tokenAddresses[1],
|
|
20
20
|
]);
|
|
21
21
|
const [quoteCurrency, baseCurrency, { data: { books: bidBooks }, }, { data: { books: askBooks }, },] = await Promise.all([
|
|
22
|
-
fetchCurrency(chainId, quoteTokenAddress
|
|
23
|
-
fetchCurrency(chainId, baseTokenAddress
|
|
22
|
+
fetchCurrency(chainId, quoteTokenAddress),
|
|
23
|
+
fetchCurrency(chainId, baseTokenAddress),
|
|
24
24
|
getBooks(chainId, quoteTokenAddress, baseTokenAddress),
|
|
25
25
|
getBooks(chainId, baseTokenAddress, quoteTokenAddress),
|
|
26
26
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/apis/market.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAW,MAAM,eAAe,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,QAAQ,GAAG,KAAK,EACpB,OAAkB,EAClB,gBAA+B,EAC/B,iBAAgC,EAChC,EAAE;IACF,OAAO,aAAa,CAKlB,OAAO,EACP,UAAU,EACV,sWAAsW,EACtW;QACE,gBAAgB,EAAE,gBAAgB,CAAC,WAAW,EAAE;QAChD,iBAAiB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C,IAAI,CAAC,IAAI,CAAC;wBACvB,IAAI;wBACJ,SAAS;qBACE,CAAA;gBACf,CAAC,CAAC;qBACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACnD,CAAC,CAAA;QACJ,CAAC,CAAC;KACH,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -15,7 +15,7 @@ const getOpenOrders = async (chainId, userAddress) => {
|
|
|
15
15
|
userAddress: userAddress.toLowerCase(),
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
|
-
export async function fetchOpenOrders(chainId, userAddress
|
|
18
|
+
export async function fetchOpenOrders(chainId, userAddress) {
|
|
19
19
|
const { data: { openOrders }, } = await getOpenOrders(chainId, userAddress);
|
|
20
20
|
const currencies = await Promise.all(openOrders
|
|
21
21
|
.map((openOrder) => [
|
|
@@ -24,17 +24,17 @@ export async function fetchOpenOrders(chainId, userAddress, rpcUrl) {
|
|
|
24
24
|
])
|
|
25
25
|
.flat()
|
|
26
26
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
27
|
-
.map((address) => fetchCurrency(chainId, address
|
|
27
|
+
.map((address) => fetchCurrency(chainId, address)));
|
|
28
28
|
return openOrders.map((openOrder) => toOpenOrder(chainId, currencies, openOrder));
|
|
29
29
|
}
|
|
30
|
-
export async function fetchOpenOrder(chainId, id
|
|
30
|
+
export async function fetchOpenOrder(chainId, id) {
|
|
31
31
|
const { data: { openOrder }, } = await getOpenOrder(chainId, id);
|
|
32
32
|
if (!openOrder) {
|
|
33
33
|
throw new Error(`Open order not found: ${id}`);
|
|
34
34
|
}
|
|
35
35
|
const currencies = await Promise.all([
|
|
36
|
-
fetchCurrency(chainId, getAddress(openOrder.book.base.id)
|
|
37
|
-
fetchCurrency(chainId, getAddress(openOrder.book.quote.id)
|
|
36
|
+
fetchCurrency(chainId, getAddress(openOrder.book.base.id)),
|
|
37
|
+
fetchCurrency(chainId, getAddress(openOrder.book.quote.id)),
|
|
38
38
|
]);
|
|
39
39
|
return toOpenOrder(chainId, currencies, openOrder);
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-order.js","sourceRoot":"","sources":["../../../src/apis/open-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,YAAY,GAAG,KAAK,EAAE,OAAkB,EAAE,OAAe,EAAE,EAAE;IACjE,OAAO,aAAa,CAKlB,OAAO,EACP,cAAc,EACd,8OAA8O,EAC9O;QACE,OAAO;KACR,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,KAAK,EACzB,OAAkB,EAClB,WAA0B,EAC1B,EAAE;IACF,OAAO,aAAa,CAKlB,OAAO,EACP,eAAe,EACf,yQAAyQ,EACzQ;QACE,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE;KACvC,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAkB,EAClB,WAA0B
|
|
1
|
+
{"version":3,"file":"open-order.js","sourceRoot":"","sources":["../../../src/apis/open-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;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HAIN_MAP } from './constants/chain';
|
|
3
3
|
import { CONTRACT_ADDRESSES } from './constants/addresses';
|
|
4
4
|
import { fetchIsApprovedForAll } from './utils/approval';
|
|
5
|
+
import { decorator } from './utils/decorator';
|
|
5
6
|
const _abi = [
|
|
6
7
|
{
|
|
7
8
|
inputs: [
|
|
@@ -48,8 +49,8 @@ const _abi = [
|
|
|
48
49
|
* mnemonicToAccount('legal ...')
|
|
49
50
|
* )
|
|
50
51
|
*/
|
|
51
|
-
export const setApprovalOfOpenOrdersForAll = async (chainId, account, options) => {
|
|
52
|
-
const isApprovedForAll = await fetchIsApprovedForAll(chainId, account.address
|
|
52
|
+
export const setApprovalOfOpenOrdersForAll = decorator(async ({ chainId, account, options, }) => {
|
|
53
|
+
const isApprovedForAll = await fetchIsApprovedForAll(chainId, account.address);
|
|
53
54
|
if (isApprovedForAll) {
|
|
54
55
|
return undefined;
|
|
55
56
|
}
|
|
@@ -66,5 +67,5 @@ export const setApprovalOfOpenOrdersForAll = async (chainId, account, options) =
|
|
|
66
67
|
functionName: 'setApprovalForAll',
|
|
67
68
|
args: [CONTRACT_ADDRESSES[chainId].Controller, true],
|
|
68
69
|
});
|
|
69
|
-
};
|
|
70
|
+
});
|
|
70
71
|
//# sourceMappingURL=approval.js.map
|
package/dist/esm/approval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAa,IAAI,EAAqB,MAAM,MAAM,CAAA;AAE7E,OAAO,EAAa,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EA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B,CAAC,OAAO,CAAE,CAAC,WAAW;QACjD,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,mBAAmB;QACjC,IAAI,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,EAAE,IAAI,CAAC;KACtD,CAAC,CAAA;AACJ,CAAC,CACF,CAAA"}
|
package/dist/esm/call.js
CHANGED
|
@@ -14,6 +14,7 @@ import { toBookId } from './utils/book-id';
|
|
|
14
14
|
import { MAKE_ORDER_PARAMS_ABI, TAKE_ORDER_PARAMS_ABI, } from './abis/core/params-abi';
|
|
15
15
|
import { Action } from './constants/action';
|
|
16
16
|
import { fetchIsApprovedForAll } from './utils/approval';
|
|
17
|
+
import { decorator } from './utils/decorator';
|
|
17
18
|
/**
|
|
18
19
|
* Build a transaction to open a market.
|
|
19
20
|
*
|
|
@@ -32,11 +33,11 @@ import { fetchIsApprovedForAll } from './utils/approval';
|
|
|
32
33
|
* '0x0000000000000000000000000000000000000000'
|
|
33
34
|
* )
|
|
34
35
|
*/
|
|
35
|
-
export const openMarket = async (chainId, inputToken, outputToken,
|
|
36
|
-
const market = await fetchMarket(chainId, [inputToken, outputToken]
|
|
36
|
+
export const openMarket = decorator(async ({ chainId, inputToken, outputToken, }) => {
|
|
37
|
+
const market = await fetchMarket(chainId, [inputToken, outputToken]);
|
|
37
38
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
38
39
|
if ((isBid && !market.bidBookOpen) || (!isBid && !market.askBookOpen)) {
|
|
39
|
-
const unit = await calculateUnit(chainId, isBid ? market.quote : market.base
|
|
40
|
+
const unit = await calculateUnit(chainId, isBid ? market.quote : market.base);
|
|
40
41
|
return buildTransaction(chainId, {
|
|
41
42
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
42
43
|
abi: CONTROLLER_ABI,
|
|
@@ -57,10 +58,10 @@ export const openMarket = async (chainId, inputToken, outputToken, options) => {
|
|
|
57
58
|
],
|
|
58
59
|
getDeadlineTimestampInSeconds(),
|
|
59
60
|
],
|
|
60
|
-
}
|
|
61
|
+
});
|
|
61
62
|
}
|
|
62
63
|
return undefined;
|
|
63
|
-
};
|
|
64
|
+
});
|
|
64
65
|
/**
|
|
65
66
|
* Places a limit order on the specified chain for trading tokens.
|
|
66
67
|
*
|
|
@@ -108,13 +109,8 @@ export const openMarket = async (chainId, inputToken, outputToken, options) => {
|
|
|
108
109
|
* '4000.01', // price at 4000.01 (ETH/USDC)
|
|
109
110
|
* )
|
|
110
111
|
*/
|
|
111
|
-
export const limitOrder = async (chainId, userAddress, inputToken, outputToken, amount, price, options) => {
|
|
112
|
-
const
|
|
113
|
-
signature: undefined,
|
|
114
|
-
postOnly: false,
|
|
115
|
-
rpcUrl: undefined,
|
|
116
|
-
};
|
|
117
|
-
const market = await fetchMarket(chainId, [inputToken, outputToken], rpcUrl);
|
|
112
|
+
export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, outputToken, amount, price, options, }) => {
|
|
113
|
+
const market = await fetchMarket(chainId, [inputToken, outputToken]);
|
|
118
114
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
119
115
|
if ((isBid && !market.bidBookOpen) || (!isBid && !market.askBookOpen)) {
|
|
120
116
|
throw new Error(`
|
|
@@ -132,23 +128,24 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
132
128
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
133
129
|
const quoteAmount = parseUnits(amount, isBid ? market.quote.decimals : market.base.decimals);
|
|
134
130
|
const [unit, { result }] = await Promise.all([
|
|
135
|
-
calculateUnit(chainId, isBid ? market.quote : market.base
|
|
136
|
-
getExpectedOutput(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
: {
|
|
142
|
-
|
|
143
|
-
}
|
|
131
|
+
calculateUnit(chainId, isBid ? market.quote : market.base),
|
|
132
|
+
getExpectedOutput({
|
|
133
|
+
chainId,
|
|
134
|
+
inputToken,
|
|
135
|
+
outputToken,
|
|
136
|
+
amountIn: amount,
|
|
137
|
+
options: {
|
|
138
|
+
...options,
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
144
141
|
]);
|
|
145
142
|
const isETH = isAddressEqual(inputToken, zeroAddress);
|
|
146
|
-
const permitParamsList = signature && !isETH
|
|
143
|
+
const permitParamsList = options?.signature && !isETH
|
|
147
144
|
? [
|
|
148
145
|
{
|
|
149
146
|
token: inputToken,
|
|
150
147
|
permitAmount: quoteAmount,
|
|
151
|
-
signature,
|
|
148
|
+
signature: options.signature,
|
|
152
149
|
},
|
|
153
150
|
]
|
|
154
151
|
: [];
|
|
@@ -158,7 +155,7 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
158
155
|
quoteAmount,
|
|
159
156
|
hookData: zeroHash,
|
|
160
157
|
};
|
|
161
|
-
if (postOnly === true || result.length === 0) {
|
|
158
|
+
if (options?.postOnly === true || result.length === 0) {
|
|
162
159
|
return buildTransaction(chainId, {
|
|
163
160
|
chain: CHAIN_MAP[chainId],
|
|
164
161
|
account: userAddress,
|
|
@@ -172,7 +169,7 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
172
169
|
getDeadlineTimestampInSeconds(),
|
|
173
170
|
],
|
|
174
171
|
value: isETH ? quoteAmount : 0n,
|
|
175
|
-
}
|
|
172
|
+
});
|
|
176
173
|
}
|
|
177
174
|
else if (result.length === 1) {
|
|
178
175
|
// take and make
|
|
@@ -199,7 +196,7 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
199
196
|
getDeadlineTimestampInSeconds(),
|
|
200
197
|
],
|
|
201
198
|
value: isETH ? quoteAmount : 0n,
|
|
202
|
-
}
|
|
199
|
+
});
|
|
203
200
|
}
|
|
204
201
|
else {
|
|
205
202
|
// take x n and make
|
|
@@ -242,9 +239,9 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
242
239
|
getDeadlineTimestampInSeconds(),
|
|
243
240
|
],
|
|
244
241
|
value: isETH ? quoteAmount : 0n,
|
|
245
|
-
}
|
|
242
|
+
});
|
|
246
243
|
}
|
|
247
|
-
};
|
|
244
|
+
});
|
|
248
245
|
/**
|
|
249
246
|
* Executes a market order on the specified chain for trading tokens.
|
|
250
247
|
*
|
|
@@ -290,13 +287,8 @@ export const limitOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
290
287
|
* '0.13', // 0.13 ETH
|
|
291
288
|
* )
|
|
292
289
|
*/
|
|
293
|
-
export const marketOrder = async (chainId, userAddress, inputToken, outputToken, amount, options) => {
|
|
294
|
-
const
|
|
295
|
-
signature: undefined,
|
|
296
|
-
rpcUrl: undefined,
|
|
297
|
-
limitPrice: undefined,
|
|
298
|
-
};
|
|
299
|
-
const market = await fetchMarket(chainId, [inputToken, outputToken], rpcUrl);
|
|
290
|
+
export const marketOrder = decorator(async ({ chainId, userAddress, inputToken, outputToken, amount, options, }) => {
|
|
291
|
+
const market = await fetchMarket(chainId, [inputToken, outputToken]);
|
|
300
292
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
301
293
|
if ((isBid && !market.bidBookOpen) || (!isBid && !market.askBookOpen)) {
|
|
302
294
|
throw new Error(`
|
|
@@ -309,21 +301,25 @@ export const marketOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
309
301
|
)
|
|
310
302
|
`);
|
|
311
303
|
}
|
|
312
|
-
const rawLimitPrice = parsePrice(Number(limitPrice ?? '0'), market.quote.decimals, market.base.decimals);
|
|
304
|
+
const rawLimitPrice = parsePrice(Number(options?.limitPrice ?? '0'), market.quote.decimals, market.base.decimals);
|
|
313
305
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
314
306
|
const quoteAmount = parseUnits(amount, isBid ? market.quote.decimals : market.base.decimals);
|
|
315
|
-
const { result } = await getExpectedOutput(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
:
|
|
307
|
+
const { result } = await getExpectedOutput({
|
|
308
|
+
chainId,
|
|
309
|
+
inputToken,
|
|
310
|
+
outputToken,
|
|
311
|
+
amountIn: amount,
|
|
312
|
+
options: {
|
|
313
|
+
...options,
|
|
314
|
+
},
|
|
315
|
+
});
|
|
320
316
|
const isETH = isAddressEqual(inputToken, zeroAddress);
|
|
321
|
-
const permitParamsList = signature && !isETH
|
|
317
|
+
const permitParamsList = options?.signature && !isETH
|
|
322
318
|
? [
|
|
323
319
|
{
|
|
324
320
|
token: inputToken,
|
|
325
321
|
permitAmount: quoteAmount,
|
|
326
|
-
signature,
|
|
322
|
+
signature: options.signature,
|
|
327
323
|
},
|
|
328
324
|
]
|
|
329
325
|
: [];
|
|
@@ -345,8 +341,8 @@ export const marketOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
345
341
|
getDeadlineTimestampInSeconds(),
|
|
346
342
|
],
|
|
347
343
|
value: isETH ? quoteAmount : 0n,
|
|
348
|
-
}
|
|
349
|
-
};
|
|
344
|
+
});
|
|
345
|
+
});
|
|
350
346
|
/**
|
|
351
347
|
* Claims specified open order for settlement.
|
|
352
348
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -371,9 +367,14 @@ export const marketOrder = async (chainId, userAddress, inputToken, outputToken,
|
|
|
371
367
|
* openOrders.map((order) => order.id)
|
|
372
368
|
* )
|
|
373
369
|
*/
|
|
374
|
-
export const claimOrder = async (chainId, userAddress, id, options) => {
|
|
375
|
-
return claimOrders(
|
|
376
|
-
|
|
370
|
+
export const claimOrder = decorator(async ({ chainId, userAddress, id, options, }) => {
|
|
371
|
+
return claimOrders({
|
|
372
|
+
chainId,
|
|
373
|
+
userAddress,
|
|
374
|
+
ids: [id],
|
|
375
|
+
options: { ...options },
|
|
376
|
+
});
|
|
377
|
+
});
|
|
377
378
|
/**
|
|
378
379
|
* Claims specified open orders for settlement.
|
|
379
380
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -398,11 +399,8 @@ export const claimOrder = async (chainId, userAddress, id, options) => {
|
|
|
398
399
|
* openOrders.map((order) => order.id)
|
|
399
400
|
* )
|
|
400
401
|
*/
|
|
401
|
-
export const claimOrders = async (chainId, userAddress, ids, options) => {
|
|
402
|
-
const
|
|
403
|
-
rpcUrl: undefined,
|
|
404
|
-
};
|
|
405
|
-
const isApprovedForAll = await fetchIsApprovedForAll(chainId, userAddress, options?.rpcUrl);
|
|
402
|
+
export const claimOrders = decorator(async ({ chainId, userAddress, ids, options, }) => {
|
|
403
|
+
const isApprovedForAll = await fetchIsApprovedForAll(chainId, userAddress);
|
|
406
404
|
if (!isApprovedForAll) {
|
|
407
405
|
throw new Error(`
|
|
408
406
|
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
@@ -413,12 +411,15 @@ export const claimOrders = async (chainId, userAddress, ids, options) => {
|
|
|
413
411
|
)
|
|
414
412
|
`);
|
|
415
413
|
}
|
|
416
|
-
const openOrders = (await getOpenOrders(chainId, userAddress,
|
|
414
|
+
const openOrders = (await getOpenOrders({ chainId, userAddress, options: { ...options } })).filter((order) => ids.includes(order.id));
|
|
417
415
|
if (openOrders.length === 0) {
|
|
418
416
|
throw new Error(`No claimable open orders found for ${userAddress}`);
|
|
419
417
|
}
|
|
420
418
|
const tokensToSettle = openOrders
|
|
421
|
-
.map((order) => [
|
|
419
|
+
.map((order) => [
|
|
420
|
+
order.outputCurrency.address,
|
|
421
|
+
order.inputCurrency.address,
|
|
422
|
+
])
|
|
422
423
|
.flat()
|
|
423
424
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
424
425
|
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
@@ -437,8 +438,8 @@ export const claimOrders = async (chainId, userAddress, ids, options) => {
|
|
|
437
438
|
[],
|
|
438
439
|
getDeadlineTimestampInSeconds(),
|
|
439
440
|
],
|
|
440
|
-
}
|
|
441
|
-
};
|
|
441
|
+
});
|
|
442
|
+
});
|
|
442
443
|
/**
|
|
443
444
|
* Cancels specified open order if the order is not fully filled.
|
|
444
445
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -463,9 +464,14 @@ export const claimOrders = async (chainId, userAddress, ids, options) => {
|
|
|
463
464
|
* openOrders.map((order) => order.id)
|
|
464
465
|
* )
|
|
465
466
|
*/
|
|
466
|
-
export const cancelOrder = async (chainId, userAddress, id, options) => {
|
|
467
|
-
return cancelOrders(
|
|
468
|
-
|
|
467
|
+
export const cancelOrder = decorator(async ({ chainId, userAddress, id, options, }) => {
|
|
468
|
+
return cancelOrders({
|
|
469
|
+
chainId,
|
|
470
|
+
userAddress,
|
|
471
|
+
ids: [id],
|
|
472
|
+
options: { ...options },
|
|
473
|
+
});
|
|
474
|
+
});
|
|
469
475
|
/**
|
|
470
476
|
* Cancels specified open orders if orders are not fully filled.
|
|
471
477
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -490,11 +496,8 @@ export const cancelOrder = async (chainId, userAddress, id, options) => {
|
|
|
490
496
|
* openOrders.map((order) => order.id)
|
|
491
497
|
* )
|
|
492
498
|
*/
|
|
493
|
-
export const cancelOrders = async (chainId, userAddress, ids, options) => {
|
|
494
|
-
const
|
|
495
|
-
rpcUrl: undefined,
|
|
496
|
-
};
|
|
497
|
-
const isApprovedForAll = await fetchIsApprovedForAll(chainId, userAddress, options?.rpcUrl);
|
|
499
|
+
export const cancelOrders = decorator(async ({ chainId, userAddress, ids, options, }) => {
|
|
500
|
+
const isApprovedForAll = await fetchIsApprovedForAll(chainId, userAddress);
|
|
498
501
|
if (!isApprovedForAll) {
|
|
499
502
|
throw new Error(`
|
|
500
503
|
import { setApprovalOfOpenOrdersForAll } from '@clober/v2-sdk'
|
|
@@ -505,12 +508,15 @@ export const cancelOrders = async (chainId, userAddress, ids, options) => {
|
|
|
505
508
|
)
|
|
506
509
|
`);
|
|
507
510
|
}
|
|
508
|
-
const openOrders = (await getOpenOrders(chainId, userAddress,
|
|
511
|
+
const openOrders = (await getOpenOrders({ chainId, userAddress, options: { ...options } })).filter((order) => ids.includes(order.id) && order.cancelable);
|
|
509
512
|
if (openOrders.length === 0) {
|
|
510
513
|
throw new Error(`No cancelable open orders found for ${userAddress}`);
|
|
511
514
|
}
|
|
512
515
|
const tokensToSettle = openOrders
|
|
513
|
-
.map((order) => [
|
|
516
|
+
.map((order) => [
|
|
517
|
+
order.outputCurrency.address,
|
|
518
|
+
order.inputCurrency.address,
|
|
519
|
+
])
|
|
514
520
|
.flat()
|
|
515
521
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
516
522
|
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
@@ -530,6 +536,6 @@ export const cancelOrders = async (chainId, userAddress, ids, options) => {
|
|
|
530
536
|
[],
|
|
531
537
|
getDeadlineTimestampInSeconds(),
|
|
532
538
|
],
|
|
533
|
-
}
|
|
534
|
-
};
|
|
539
|
+
});
|
|
540
|
+
});
|
|
535
541
|
//# sourceMappingURL=call.js.map
|