@clober/v2-sdk 0.0.5-0.dev → 0.0.5-6.dev
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/chart-logs.js +2 -2
- package/dist/cjs/apis/chart-logs.js.map +1 -1
- package/dist/cjs/apis/market.js +11 -12
- package/dist/cjs/apis/market.js.map +1 -1
- package/dist/cjs/apis/open-order.js +12 -12
- package/dist/cjs/apis/open-order.js.map +1 -1
- package/dist/cjs/approval.js +18 -11
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/call.js +113 -49
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/addresses.js +0 -5
- package/dist/cjs/constants/addresses.js.map +1 -1
- package/dist/cjs/constants/chain.js +0 -2
- package/dist/cjs/constants/chain.js.map +1 -1
- package/dist/cjs/constants/currency.js +3 -4
- package/dist/cjs/constants/currency.js.map +1 -1
- package/dist/cjs/constants/fee.js +0 -2
- package/dist/cjs/constants/fee.js.map +1 -1
- package/dist/cjs/constants/price.js +2 -1
- package/dist/cjs/constants/price.js.map +1 -1
- package/dist/cjs/constants/subgraph.js +4 -23
- package/dist/cjs/constants/subgraph.js.map +1 -1
- package/dist/cjs/constants/test-chain.js +2 -2
- package/dist/cjs/constants/test-chain.js.map +1 -1
- package/dist/cjs/constants/tick.js +6 -0
- package/dist/cjs/constants/tick.js.map +1 -0
- package/dist/cjs/model/book.js +23 -7
- package/dist/cjs/model/book.js.map +1 -1
- package/dist/cjs/model/market.js +7 -7
- package/dist/cjs/model/market.js.map +1 -1
- package/dist/cjs/signature.js +10 -6
- package/dist/cjs/signature.js.map +1 -1
- package/dist/cjs/utils/allowance.js +2 -3
- package/dist/cjs/utils/allowance.js.map +1 -1
- package/dist/cjs/utils/approval.js +2 -3
- package/dist/cjs/utils/approval.js.map +1 -1
- package/dist/cjs/utils/bigint.js +5 -1
- package/dist/cjs/utils/bigint.js.map +1 -1
- package/dist/cjs/utils/build-transaction.js +3 -4
- package/dist/cjs/utils/build-transaction.js.map +1 -1
- package/dist/cjs/utils/currency.js +8 -9
- package/dist/cjs/utils/currency.js.map +1 -1
- package/dist/cjs/utils/open.js +14 -3
- package/dist/cjs/utils/open.js.map +1 -1
- package/dist/cjs/utils/order.js +5 -7
- package/dist/cjs/utils/order.js.map +1 -1
- package/dist/cjs/utils/prices.js +17 -9
- package/dist/cjs/utils/prices.js.map +1 -1
- package/dist/cjs/utils/tick.js +12 -1
- package/dist/cjs/utils/tick.js.map +1 -1
- package/dist/cjs/utils/unit-size.js +8 -9
- package/dist/cjs/utils/unit-size.js.map +1 -1
- package/dist/cjs/utils.js +2 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/view.js +127 -36
- package/dist/cjs/view.js.map +1 -1
- package/dist/esm/apis/chart-logs.js +3 -3
- package/dist/esm/apis/chart-logs.js.map +1 -1
- package/dist/esm/apis/market.js +12 -13
- package/dist/esm/apis/market.js.map +1 -1
- package/dist/esm/apis/open-order.js +14 -14
- package/dist/esm/apis/open-order.js.map +1 -1
- package/dist/esm/approval.js +17 -12
- package/dist/esm/approval.js.map +1 -1
- package/dist/esm/call.js +111 -52
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/constants/addresses.js +0 -5
- package/dist/esm/constants/addresses.js.map +1 -1
- package/dist/esm/constants/chain.js +1 -3
- package/dist/esm/constants/chain.js.map +1 -1
- package/dist/esm/constants/currency.js +5 -4
- package/dist/esm/constants/currency.js.map +1 -1
- package/dist/esm/constants/fee.js +0 -2
- package/dist/esm/constants/fee.js.map +1 -1
- package/dist/esm/constants/price.js +1 -0
- package/dist/esm/constants/price.js.map +1 -1
- package/dist/esm/constants/subgraph.js +3 -22
- package/dist/esm/constants/subgraph.js.map +1 -1
- package/dist/esm/constants/test-chain.js +2 -2
- package/dist/esm/constants/test-chain.js.map +1 -1
- package/dist/esm/constants/tick.js +3 -0
- package/dist/esm/constants/tick.js.map +1 -0
- package/dist/esm/model/book.js +23 -7
- package/dist/esm/model/book.js.map +1 -1
- package/dist/esm/model/market.js +8 -8
- package/dist/esm/model/market.js.map +1 -1
- package/dist/esm/signature.js +10 -7
- package/dist/esm/signature.js.map +1 -1
- package/dist/esm/utils/allowance.js +2 -3
- package/dist/esm/utils/allowance.js.map +1 -1
- package/dist/esm/utils/approval.js +2 -3
- package/dist/esm/utils/approval.js.map +1 -1
- package/dist/esm/utils/bigint.js +2 -0
- package/dist/esm/utils/bigint.js.map +1 -1
- package/dist/esm/utils/build-transaction.js +3 -4
- package/dist/esm/utils/build-transaction.js.map +1 -1
- package/dist/esm/utils/currency.js +8 -9
- package/dist/esm/utils/currency.js.map +1 -1
- package/dist/esm/utils/open.js +14 -3
- package/dist/esm/utils/open.js.map +1 -1
- package/dist/esm/utils/order.js +6 -8
- package/dist/esm/utils/order.js.map +1 -1
- package/dist/esm/utils/prices.js +19 -11
- package/dist/esm/utils/prices.js.map +1 -1
- package/dist/esm/utils/tick.js +11 -1
- package/dist/esm/utils/tick.js.map +1 -1
- package/dist/esm/utils/unit-size.js +8 -9
- package/dist/esm/utils/unit-size.js.map +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/view.js +122 -38
- package/dist/esm/view.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/apis/chart-logs.d.ts.map +1 -1
- package/dist/types/apis/market.d.ts +2 -1
- package/dist/types/apis/market.d.ts.map +1 -1
- package/dist/types/apis/open-order.d.ts +4 -3
- package/dist/types/apis/open-order.d.ts.map +1 -1
- package/dist/types/approval.d.ts +2 -2
- package/dist/types/approval.d.ts.map +1 -1
- package/dist/types/call.d.ts +42 -12
- package/dist/types/call.d.ts.map +1 -1
- package/dist/types/constants/addresses.d.ts.map +1 -1
- package/dist/types/constants/chain.d.ts +1 -2
- package/dist/types/constants/chain.d.ts.map +1 -1
- package/dist/types/constants/currency.d.ts.map +1 -1
- package/dist/types/constants/fee.d.ts.map +1 -1
- package/dist/types/constants/price.d.ts +1 -0
- package/dist/types/constants/price.d.ts.map +1 -1
- package/dist/types/constants/subgraph.d.ts +2 -7
- package/dist/types/constants/subgraph.d.ts.map +1 -1
- package/dist/types/constants/tick.d.ts +3 -0
- package/dist/types/constants/tick.d.ts.map +1 -0
- package/dist/types/model/book.d.ts +14 -4
- package/dist/types/model/book.d.ts.map +1 -1
- package/dist/types/model/market.d.ts +14 -4
- package/dist/types/model/market.d.ts.map +1 -1
- package/dist/types/signature.d.ts +1 -1
- package/dist/types/signature.d.ts.map +1 -1
- package/dist/types/utils/allowance.d.ts +2 -2
- package/dist/types/utils/allowance.d.ts.map +1 -1
- package/dist/types/utils/approval.d.ts +2 -1
- package/dist/types/utils/approval.d.ts.map +1 -1
- package/dist/types/utils/bigint.d.ts +2 -0
- package/dist/types/utils/bigint.d.ts.map +1 -1
- package/dist/types/utils/build-transaction.d.ts +3 -3
- package/dist/types/utils/build-transaction.d.ts.map +1 -1
- package/dist/types/utils/currency.d.ts +3 -2
- package/dist/types/utils/currency.d.ts.map +1 -1
- package/dist/types/utils/open.d.ts +2 -1
- package/dist/types/utils/open.d.ts.map +1 -1
- package/dist/types/utils/order.d.ts +2 -1
- package/dist/types/utils/order.d.ts.map +1 -1
- package/dist/types/utils/prices.d.ts +4 -1
- package/dist/types/utils/prices.d.ts.map +1 -1
- package/dist/types/utils/tick.d.ts +1 -0
- package/dist/types/utils/tick.d.ts.map +1 -1
- package/dist/types/utils/unit-size.d.ts +2 -1
- package/dist/types/utils/unit-size.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/view.d.ts +47 -7
- package/dist/types/view.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/constants/client.js +0 -18
- package/dist/cjs/constants/client.js.map +0 -1
- package/dist/cjs/utils/bignumber.js +0 -9
- package/dist/cjs/utils/bignumber.js.map +0 -1
- package/dist/cjs/utils/decorator.js +0 -15
- package/dist/cjs/utils/decorator.js.map +0 -1
- package/dist/esm/constants/client.js +0 -14
- package/dist/esm/constants/client.js.map +0 -1
- package/dist/esm/utils/bignumber.js +0 -6
- package/dist/esm/utils/bignumber.js.map +0 -1
- package/dist/esm/utils/decorator.js +0 -11
- package/dist/esm/utils/decorator.js.map +0 -1
- package/dist/types/constants/client.d.ts +0 -5
- package/dist/types/constants/client.d.ts.map +0 -1
- package/dist/types/utils/bignumber.d.ts +0 -3
- package/dist/types/utils/bignumber.d.ts.map +0 -1
- package/dist/types/utils/decorator.d.ts +0 -6
- package/dist/types/utils/decorator.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/apis/market.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/apis/market.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,SAAS,GAAG,KAAK,EAAE,OAAkB,EAAE,MAAc,EAAE,EAAE;IAC7D,OAAO,QAAQ,CAAC,GAAG,CAWjB,OAAO,EACP,SAAS,EACT,iFAAiF,EACjF;QACE,MAAM;KACP,CACF,CAA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AE,WAAW,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CAAC;KAC5E,CAAC,CAAA;IAEF,OAAO,IAAI,MAAM,CAAC;QAChB,OAAO;QACP,MAAM,EAAE,CAAC,aAAa,EAAE,YAAY,CAAC;QACrC,OAAO;QACP,OAAO;KACR,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -2,27 +2,27 @@ import { formatUnits, getAddress, isAddressEqual } from 'viem';
|
|
|
2
2
|
import { getMarketId } from '../utils/market';
|
|
3
3
|
import { baseToQuote, quoteToBase } from '../utils/decimals';
|
|
4
4
|
import { formatPrice } from '../utils/prices';
|
|
5
|
-
import {
|
|
5
|
+
import { invertTick, toPrice } from '../utils/tick';
|
|
6
6
|
import { fetchCurrency } from '../utils/currency';
|
|
7
7
|
import { applyPercent } from '../utils/bigint';
|
|
8
8
|
import { MAKER_DEFAULT_POLICY } from '../constants/fee';
|
|
9
|
-
import {
|
|
9
|
+
import { Subgraph } from '../constants/subgraph';
|
|
10
10
|
const getOpenOrder = async (chainId, orderId) => {
|
|
11
|
-
return
|
|
11
|
+
return Subgraph.get(chainId, 'getOpenOrder', 'query getOpenOrder($orderId: ID!) { openOrder(id: $orderId) { id user book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick txHash createdAt unitAmount unitFilledAmount unitClaimedAmount unitClaimableAmount orderIndex } }', {
|
|
12
12
|
orderId,
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
const getOpenOrders = async (chainId, orderIds) => {
|
|
16
|
-
return
|
|
16
|
+
return Subgraph.get(chainId, 'getOpenOrders', 'query getOpenOrders($orderIds: [ID!]!) { openOrders(where: {id_in: $orderIds}) { id user book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick txHash createdAt unitAmount unitFilledAmount unitClaimedAmount unitClaimableAmount orderIndex } }', {
|
|
17
17
|
orderIds,
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
const getOpenOrdersByUserAddress = async (chainId, userAddress) => {
|
|
21
|
-
return
|
|
21
|
+
return Subgraph.get(chainId, 'getOpenOrdersByUserAddress', 'query getOpenOrdersByUserAddress($userAddress: String!) { openOrders(where: { user: $userAddress }) { id user book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick txHash createdAt unitAmount unitFilledAmount unitClaimedAmount unitClaimableAmount orderIndex } }', {
|
|
22
22
|
userAddress: userAddress.toLowerCase(),
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
-
export async function fetchOpenOrdersByUserAddress(chainId, userAddress) {
|
|
25
|
+
export async function fetchOpenOrdersByUserAddress(publicClient, chainId, userAddress) {
|
|
26
26
|
const { data: { openOrders }, } = await getOpenOrdersByUserAddress(chainId, userAddress);
|
|
27
27
|
const currencies = await Promise.all(openOrders
|
|
28
28
|
.map((openOrder) => [
|
|
@@ -31,21 +31,21 @@ export async function fetchOpenOrdersByUserAddress(chainId, userAddress) {
|
|
|
31
31
|
])
|
|
32
32
|
.flat()
|
|
33
33
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
34
|
-
.map((address) => fetchCurrency(chainId, address)));
|
|
34
|
+
.map((address) => fetchCurrency(publicClient, chainId, address)));
|
|
35
35
|
return openOrders.map((openOrder) => toOpenOrder(chainId, currencies, openOrder));
|
|
36
36
|
}
|
|
37
|
-
export async function fetchOpenOrder(chainId, id) {
|
|
37
|
+
export async function fetchOpenOrder(publicClient, chainId, id) {
|
|
38
38
|
const { data: { openOrder }, } = await getOpenOrder(chainId, id);
|
|
39
39
|
if (!openOrder) {
|
|
40
40
|
throw new Error(`Open order not found: ${id}`);
|
|
41
41
|
}
|
|
42
42
|
const currencies = await Promise.all([
|
|
43
|
-
fetchCurrency(chainId, getAddress(openOrder.book.base.id)),
|
|
44
|
-
fetchCurrency(chainId, getAddress(openOrder.book.quote.id)),
|
|
43
|
+
fetchCurrency(publicClient, chainId, getAddress(openOrder.book.base.id)),
|
|
44
|
+
fetchCurrency(publicClient, chainId, getAddress(openOrder.book.quote.id)),
|
|
45
45
|
]);
|
|
46
46
|
return toOpenOrder(chainId, currencies, openOrder);
|
|
47
47
|
}
|
|
48
|
-
export async function fetchOpenOrders(chainId, ids) {
|
|
48
|
+
export async function fetchOpenOrders(publicClient, chainId, ids) {
|
|
49
49
|
const { data: { openOrders }, } = await getOpenOrders(chainId, ids);
|
|
50
50
|
const currencies = await Promise.all(openOrders
|
|
51
51
|
.map((openOrder) => [
|
|
@@ -54,7 +54,7 @@ export async function fetchOpenOrders(chainId, ids) {
|
|
|
54
54
|
])
|
|
55
55
|
.flat()
|
|
56
56
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
57
|
-
.map((address) => fetchCurrency(chainId, address)));
|
|
57
|
+
.map((address) => fetchCurrency(publicClient, chainId, address)));
|
|
58
58
|
return openOrders.map((openOrder) => toOpenOrder(chainId, currencies, openOrder));
|
|
59
59
|
}
|
|
60
60
|
const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
@@ -81,7 +81,7 @@ const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
|
81
81
|
? quoteToBase(tick, unitSize * unitFilledAmount, false)
|
|
82
82
|
: unitSize * unitFilledAmount;
|
|
83
83
|
// each currency amount type
|
|
84
|
-
const invertedTick =
|
|
84
|
+
const invertedTick = invertTick(tick);
|
|
85
85
|
const claimed = isBid
|
|
86
86
|
? quoteToBase(tick, unitSize * unitClaimedAmount, false)
|
|
87
87
|
: baseToQuote(invertedTick, unitSize * unitClaimedAmount, false);
|
|
@@ -97,7 +97,7 @@ const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
|
97
97
|
outputCurrency,
|
|
98
98
|
txHash: openOrder.txHash,
|
|
99
99
|
createdAt: Number(openOrder.createdAt),
|
|
100
|
-
price: formatPrice(isBid ?
|
|
100
|
+
price: formatPrice(toPrice(isBid ? tick : invertTick(tick)), quote.decimals, base.decimals),
|
|
101
101
|
tick: Number(tick),
|
|
102
102
|
orderIndex: openOrder.orderIndex,
|
|
103
103
|
amount: { currency: base, value: formatUnits(amount, base.decimals) },
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"open-order.js","sourceRoot":"","sources":["../../../src/apis/open-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAgB,MAAM,MAAM,CAAA;AAG5E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,YAAY,GAAG,KAAK,EAAE,OAAkB,EAAE,OAAe,EAAE,EAAE;IACjE,OAAO,QAAQ,CAAC,GAAG,CAKjB,OAAO,EACP,cAAc,EACd,sQAAsQ,EACtQ;QACE,OAAO;KACR,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,KAAK,EAAE,OAAkB,EAAE,QAAkB,EAAE,EAAE;IACrE,OAAO,QAAQ,CAAC,GAAG,CAKjB,OAAO,EACP,eAAe,EACf,yRAAyR,EACzR;QACE,QAAQ;KACT,CACF,CAAA;AACH,CAAC,CAAA;A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 'viem';
|
|
1
|
+
import { createPublicClient, http, parseUnits } from 'viem';
|
|
2
2
|
import { CHAIN_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';
|
|
6
5
|
import { fetchAllowance } from './utils/allowance';
|
|
7
6
|
import { fetchCurrency } from './utils/currency';
|
|
8
7
|
/**
|
|
@@ -29,11 +28,15 @@ import { fetchCurrency } from './utils/currency';
|
|
|
29
28
|
* walletClient
|
|
30
29
|
* })
|
|
31
30
|
*/
|
|
32
|
-
export const setApprovalOfOpenOrdersForAll =
|
|
31
|
+
export const setApprovalOfOpenOrdersForAll = async ({ chainId, walletClient, options, }) => {
|
|
33
32
|
if (!walletClient.account) {
|
|
34
33
|
throw new Error('Account is not found');
|
|
35
34
|
}
|
|
36
|
-
const
|
|
35
|
+
const publicClient = createPublicClient({
|
|
36
|
+
chain: CHAIN_MAP[chainId],
|
|
37
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
38
|
+
});
|
|
39
|
+
const isApprovedForAll = await fetchIsApprovedForAll(publicClient, chainId, walletClient.account.address);
|
|
37
40
|
if (isApprovedForAll) {
|
|
38
41
|
return undefined;
|
|
39
42
|
}
|
|
@@ -64,7 +67,7 @@ export const setApprovalOfOpenOrdersForAll = decorator(async ({ chainId, walletC
|
|
|
64
67
|
functionName: 'setApprovalForAll',
|
|
65
68
|
args: [CONTRACT_ADDRESSES[chainId].Controller, true],
|
|
66
69
|
});
|
|
67
|
-
}
|
|
70
|
+
};
|
|
68
71
|
/**
|
|
69
72
|
* @dev This function relates with `viem` dependency
|
|
70
73
|
* Approves the specified amount of tokens for the given account on the specified chain.
|
|
@@ -92,17 +95,19 @@ export const setApprovalOfOpenOrdersForAll = decorator(async ({ chainId, walletC
|
|
|
92
95
|
* amount: '1000.123', // approve 1000.123 USDC
|
|
93
96
|
* })
|
|
94
97
|
*/
|
|
95
|
-
export const approveERC20 =
|
|
98
|
+
export const approveERC20 = async ({ chainId, walletClient, token, amount, options, }) => {
|
|
96
99
|
if (!walletClient.account) {
|
|
97
100
|
throw new Error('Account is not found');
|
|
98
101
|
}
|
|
102
|
+
const publicClient = createPublicClient({
|
|
103
|
+
chain: CHAIN_MAP[chainId],
|
|
104
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
105
|
+
});
|
|
99
106
|
const [currency, allowance] = await Promise.all([
|
|
100
|
-
fetchCurrency(chainId, token),
|
|
101
|
-
fetchAllowance(
|
|
107
|
+
fetchCurrency(publicClient, chainId, token),
|
|
108
|
+
fetchAllowance(publicClient, token, walletClient.account.address, CONTRACT_ADDRESSES[chainId].Controller),
|
|
102
109
|
]);
|
|
103
|
-
const value = amount
|
|
104
|
-
? parseUnits(amount, currency.decimals)
|
|
105
|
-
: 2n ** 256n - 1n;
|
|
110
|
+
const value = amount ? parseUnits(amount, currency.decimals) : 2n ** 256n - 1n;
|
|
106
111
|
if (allowance >= value) {
|
|
107
112
|
return undefined;
|
|
108
113
|
}
|
|
@@ -139,5 +144,5 @@ export const approveERC20 = decorator(async ({ chainId, walletClient, token, amo
|
|
|
139
144
|
functionName: 'approve',
|
|
140
145
|
args: [CONTRACT_ADDRESSES[chainId].Controller, value],
|
|
141
146
|
});
|
|
142
|
-
}
|
|
147
|
+
};
|
|
143
148
|
//# 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,UAAU,EAAgB,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAA;AAEzE,OAAO,E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AAA;IAC9E,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACvB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,YAAY,CAAC,aAAa,CAAC;QAChC,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC;QACzB,OAAO,EAAE,KAAK;QACd,GAAG,EAAE;YACH;gBACE,MAAM,EAAE;oBACN;wBACE,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,SAAS;qBAChB;oBACD;wBACE,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,OAAO;wBACb,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE;oBACP;wBACE,YAAY,EAAE,MAAM;wBACpB,IAAI,EAAE,EAAE;wBACR,IAAI,EAAE,MAAM;qBACb;iBACF;gBACD,eAAe,EAAE,YAAY;gBAC7B,IAAI,EAAE,UAAU;aACjB;SACO;QACV,YAAY,EAAE,SAAS;QACvB,IAAI,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,EAAE,KAAK,CAAC;KACvD,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/dist/esm/call.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatUnits, isAddressEqual, parseUnits, zeroAddress, zeroHash, } from 'viem';
|
|
1
|
+
import { createPublicClient, formatUnits, http, isAddressEqual, parseUnits, zeroAddress, zeroHash, } from 'viem';
|
|
2
2
|
import { CHAIN_MAP } from './constants/chain';
|
|
3
3
|
import { calculateUnitSize } from './utils/unit-size';
|
|
4
4
|
import { CONTROLLER_ABI } from './abis/core/controller-abi';
|
|
@@ -7,12 +7,11 @@ import { buildTransaction } from './utils/build-transaction';
|
|
|
7
7
|
import { CONTRACT_ADDRESSES } from './constants/addresses';
|
|
8
8
|
import { MAKER_DEFAULT_POLICY, TAKER_DEFAULT_POLICY } from './constants/fee';
|
|
9
9
|
import { fetchMarket } from './apis/market';
|
|
10
|
-
import { parsePrice } from './utils/prices';
|
|
11
|
-
import {
|
|
10
|
+
import { formatPrice, parsePrice } from './utils/prices';
|
|
11
|
+
import { invertTick, toPrice } from './utils/tick';
|
|
12
12
|
import { getExpectedInput, getExpectedOutput } from './view';
|
|
13
13
|
import { toBookId } from './utils/book-id';
|
|
14
14
|
import { fetchIsApprovedForAll } from './utils/approval';
|
|
15
|
-
import { decorator } from './utils/decorator';
|
|
16
15
|
import { fetchOrders } from './utils/order';
|
|
17
16
|
import { applyPercent } from './utils/bigint';
|
|
18
17
|
/**
|
|
@@ -35,13 +34,17 @@ import { applyPercent } from './utils/bigint';
|
|
|
35
34
|
* outputToken: '0x0000000000000000000000000000000000000000'
|
|
36
35
|
* })
|
|
37
36
|
*/
|
|
38
|
-
export const openMarket =
|
|
39
|
-
const
|
|
37
|
+
export const openMarket = async ({ chainId, userAddress, inputToken, outputToken, options, }) => {
|
|
38
|
+
const publicClient = createPublicClient({
|
|
39
|
+
chain: CHAIN_MAP[chainId],
|
|
40
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
41
|
+
});
|
|
42
|
+
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
40
43
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
41
44
|
if ((isBid && !market.bidBook.isOpened) ||
|
|
42
45
|
(!isBid && !market.askBook.isOpened)) {
|
|
43
|
-
const unitSize = await calculateUnitSize(chainId, isBid ? market.quote : market.base);
|
|
44
|
-
return buildTransaction(
|
|
46
|
+
const unitSize = await calculateUnitSize(publicClient, chainId, isBid ? market.quote : market.base);
|
|
47
|
+
return buildTransaction(publicClient, {
|
|
45
48
|
chain: CHAIN_MAP[chainId],
|
|
46
49
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
47
50
|
account: userAddress,
|
|
@@ -66,7 +69,7 @@ export const openMarket = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
66
69
|
}, options?.gasLimit);
|
|
67
70
|
}
|
|
68
71
|
return undefined;
|
|
69
|
-
}
|
|
72
|
+
};
|
|
70
73
|
/**
|
|
71
74
|
* Places a limit order on the specified chain for trading tokens.
|
|
72
75
|
*
|
|
@@ -81,6 +84,8 @@ export const openMarket = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
81
84
|
* @param {boolean} [options.postOnly] A boolean indicating whether the order is only to be made not taken.
|
|
82
85
|
* @param {string} [options.rpcUrl] The RPC URL of the blockchain.
|
|
83
86
|
* @param {number} [options.gasLimit] The gas limit to use for the transaction.
|
|
87
|
+
* @param {bigint} [options.makeTick] The tick for the make order.
|
|
88
|
+
* @param {bigint} [options.takeLimitTick] The tick for the take order.
|
|
84
89
|
* @param {boolean} [options.useSubgraph] A boolean indicating whether to use the subgraph for fetching orders.
|
|
85
90
|
* @returns {Promise<{ transaction: Transaction, result: { make: CurrencyFlow, take: CurrencyFlow, spent: CurrencyFlow }>}
|
|
86
91
|
* Promise resolving to the transaction object representing the limit order with the result of the order.
|
|
@@ -117,8 +122,18 @@ export const openMarket = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
117
122
|
* price: '4000.01', // price at 4000.01 (ETH/USDC)
|
|
118
123
|
* })
|
|
119
124
|
*/
|
|
120
|
-
export const limitOrder =
|
|
121
|
-
const
|
|
125
|
+
export const limitOrder = async ({ chainId, userAddress, inputToken, outputToken, amount, price, options, }) => {
|
|
126
|
+
const [roundingUpMakeBid, roundingDownMakeAsk, roundingDownTakenBid, roundingUpTakenAsk,] = [
|
|
127
|
+
options?.roundingUpMakeBid ? options.roundingUpMakeBid : false,
|
|
128
|
+
options?.roundingDownMakeAsk ? options.roundingDownMakeAsk : false,
|
|
129
|
+
options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
|
|
130
|
+
options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
|
|
131
|
+
];
|
|
132
|
+
const publicClient = createPublicClient({
|
|
133
|
+
chain: CHAIN_MAP[chainId],
|
|
134
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
135
|
+
});
|
|
136
|
+
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
122
137
|
const isBid = isAddressEqual(market.quote.address, inputToken);
|
|
123
138
|
const [inputCurrency, outputCurrency] = isBid
|
|
124
139
|
? [market.quote, market.base]
|
|
@@ -136,11 +151,11 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
136
151
|
})
|
|
137
152
|
`);
|
|
138
153
|
}
|
|
139
|
-
const
|
|
154
|
+
const { roundingDownTick, roundingUpTick } = parsePrice(Number(price), market.quote.decimals, market.base.decimals);
|
|
140
155
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
141
156
|
const quoteAmount = parseUnits(amount, inputCurrency.decimals);
|
|
142
|
-
const [unitSize, { takenAmount, spentAmount, bookId }] = await Promise.all([
|
|
143
|
-
calculateUnitSize(chainId, inputCurrency),
|
|
157
|
+
const [unitSize, { takenAmount, spentAmount, bookId, events }] = await Promise.all([
|
|
158
|
+
calculateUnitSize(publicClient, chainId, inputCurrency),
|
|
144
159
|
getExpectedOutput({
|
|
145
160
|
chainId,
|
|
146
161
|
inputToken,
|
|
@@ -157,13 +172,17 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
157
172
|
id: toBookId(chainId, inputToken, outputToken, unitSize),
|
|
158
173
|
tick: options?.makeTick
|
|
159
174
|
? Number(options.makeTick)
|
|
160
|
-
: Number(isBid
|
|
175
|
+
: Number(isBid
|
|
176
|
+
? roundingUpMakeBid
|
|
177
|
+
? roundingUpTick
|
|
178
|
+
: roundingDownTick
|
|
179
|
+
: invertTick(roundingDownMakeAsk ? roundingDownTick : roundingUpTick)),
|
|
161
180
|
quoteAmount,
|
|
162
181
|
hookData: zeroHash,
|
|
163
182
|
};
|
|
164
183
|
if (options?.postOnly === true || spentAmount === '0') {
|
|
165
184
|
return {
|
|
166
|
-
transaction: await buildTransaction(
|
|
185
|
+
transaction: await buildTransaction(publicClient, {
|
|
167
186
|
chain: CHAIN_MAP[chainId],
|
|
168
187
|
account: userAddress,
|
|
169
188
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -182,16 +201,21 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
182
201
|
amount: formatUnits(quoteAmount, inputCurrency.decimals),
|
|
183
202
|
currency: inputCurrency,
|
|
184
203
|
direction: 'in',
|
|
204
|
+
price: formatPrice(isBid
|
|
205
|
+
? toPrice(BigInt(makeParam.tick))
|
|
206
|
+
: toPrice(invertTick(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
185
207
|
},
|
|
186
208
|
spent: {
|
|
187
209
|
amount: '0',
|
|
188
210
|
currency: inputCurrency,
|
|
189
211
|
direction: 'in',
|
|
212
|
+
events: [],
|
|
190
213
|
},
|
|
191
214
|
taken: {
|
|
192
215
|
amount: '0',
|
|
193
216
|
currency: outputCurrency,
|
|
194
217
|
direction: 'out',
|
|
218
|
+
events: [],
|
|
195
219
|
},
|
|
196
220
|
},
|
|
197
221
|
};
|
|
@@ -199,7 +223,7 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
199
223
|
else {
|
|
200
224
|
// take and make
|
|
201
225
|
return {
|
|
202
|
-
transaction: await buildTransaction(
|
|
226
|
+
transaction: await buildTransaction(publicClient, {
|
|
203
227
|
chain: CHAIN_MAP[chainId],
|
|
204
228
|
account: userAddress,
|
|
205
229
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -212,9 +236,13 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
212
236
|
makeBookId: makeParam.id,
|
|
213
237
|
limitPrice: options?.takeLimitTick
|
|
214
238
|
? toPrice(options.takeLimitTick)
|
|
215
|
-
: isBid
|
|
216
|
-
?
|
|
217
|
-
|
|
239
|
+
: toPrice(isBid
|
|
240
|
+
? invertTick(roundingUpTakenAsk
|
|
241
|
+
? roundingUpTick
|
|
242
|
+
: roundingDownTick)
|
|
243
|
+
: roundingDownTakenBid
|
|
244
|
+
? roundingDownTick
|
|
245
|
+
: roundingUpTick),
|
|
218
246
|
tick: makeParam.tick,
|
|
219
247
|
quoteAmount,
|
|
220
248
|
takeHookData: zeroHash,
|
|
@@ -232,21 +260,32 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
232
260
|
amount: formatUnits(quoteAmount - parseUnits(spentAmount, inputCurrency.decimals), inputCurrency.decimals),
|
|
233
261
|
currency: inputCurrency,
|
|
234
262
|
direction: 'in',
|
|
263
|
+
price: formatPrice(isBid
|
|
264
|
+
? toPrice(BigInt(makeParam.tick))
|
|
265
|
+
: toPrice(invertTick(BigInt(makeParam.tick))), market.quote.decimals, market.base.decimals),
|
|
235
266
|
},
|
|
236
267
|
spent: {
|
|
237
268
|
amount: spentAmount,
|
|
238
269
|
currency: inputCurrency,
|
|
239
270
|
direction: 'in',
|
|
271
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
272
|
+
price,
|
|
273
|
+
amount: spentAmount,
|
|
274
|
+
})),
|
|
240
275
|
},
|
|
241
276
|
taken: {
|
|
242
277
|
amount: takenAmount,
|
|
243
278
|
currency: outputCurrency,
|
|
244
279
|
direction: 'out',
|
|
280
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
281
|
+
price,
|
|
282
|
+
amount: takenAmount,
|
|
283
|
+
})),
|
|
245
284
|
},
|
|
246
285
|
},
|
|
247
286
|
};
|
|
248
287
|
}
|
|
249
|
-
}
|
|
288
|
+
};
|
|
250
289
|
/**
|
|
251
290
|
* Executes a market order on the specified chain for trading tokens.
|
|
252
291
|
* If only `amountIn` is provided, spend the specified amount of input tokens.
|
|
@@ -288,14 +327,18 @@ export const limitOrder = decorator(async ({ chainId, userAddress, inputToken, o
|
|
|
288
327
|
* })
|
|
289
328
|
*
|
|
290
329
|
*/
|
|
291
|
-
export const marketOrder =
|
|
330
|
+
export const marketOrder = async ({ chainId, userAddress, inputToken, outputToken, amountIn, amountOut, options, }) => {
|
|
292
331
|
if (!amountIn && !amountOut) {
|
|
293
332
|
throw new Error('Either amountIn or amountOut must be provided');
|
|
294
333
|
}
|
|
295
334
|
else if (amountIn && amountOut) {
|
|
296
335
|
throw new Error('Only one of amountIn or amountOut can be provided');
|
|
297
336
|
}
|
|
298
|
-
const
|
|
337
|
+
const publicClient = createPublicClient({
|
|
338
|
+
chain: CHAIN_MAP[chainId],
|
|
339
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
340
|
+
});
|
|
341
|
+
const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
|
|
299
342
|
const isTakingBid = isAddressEqual(market.base.address, inputToken);
|
|
300
343
|
const [inputCurrency, outputCurrency] = isTakingBid
|
|
301
344
|
? [market.base, market.quote]
|
|
@@ -316,7 +359,7 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
316
359
|
const tokensToSettle = [inputToken, outputToken].filter((address) => !isAddressEqual(address, zeroAddress));
|
|
317
360
|
const isETH = isAddressEqual(inputToken, zeroAddress);
|
|
318
361
|
if (amountIn && !amountOut) {
|
|
319
|
-
const { bookId, takenAmount, spentAmount } = await getExpectedOutput({
|
|
362
|
+
const { bookId, takenAmount, spentAmount, events } = await getExpectedOutput({
|
|
320
363
|
chainId,
|
|
321
364
|
inputToken,
|
|
322
365
|
outputToken,
|
|
@@ -328,7 +371,7 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
328
371
|
});
|
|
329
372
|
const baseAmount = parseUnits(amountIn, inputCurrency.decimals);
|
|
330
373
|
return {
|
|
331
|
-
transaction: await buildTransaction(
|
|
374
|
+
transaction: await buildTransaction(publicClient, {
|
|
332
375
|
chain: CHAIN_MAP[chainId],
|
|
333
376
|
account: userAddress,
|
|
334
377
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -357,17 +400,25 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
357
400
|
amount: spentAmount,
|
|
358
401
|
currency: inputCurrency,
|
|
359
402
|
direction: 'in',
|
|
403
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
404
|
+
price,
|
|
405
|
+
amount: spentAmount,
|
|
406
|
+
})),
|
|
360
407
|
},
|
|
361
408
|
taken: {
|
|
362
409
|
amount: takenAmount,
|
|
363
410
|
currency: outputCurrency,
|
|
364
411
|
direction: 'out',
|
|
412
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
413
|
+
price,
|
|
414
|
+
amount: takenAmount,
|
|
415
|
+
})),
|
|
365
416
|
},
|
|
366
417
|
},
|
|
367
418
|
};
|
|
368
419
|
}
|
|
369
420
|
else if (!amountIn && amountOut) {
|
|
370
|
-
const { bookId, spentAmount, takenAmount } = await getExpectedInput({
|
|
421
|
+
const { bookId, spentAmount, takenAmount, events } = await getExpectedInput({
|
|
371
422
|
chainId,
|
|
372
423
|
inputToken,
|
|
373
424
|
outputToken,
|
|
@@ -386,7 +437,7 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
386
437
|
? baseAmount
|
|
387
438
|
: 2n ** 256n - 1n);
|
|
388
439
|
return {
|
|
389
|
-
transaction: await buildTransaction(
|
|
440
|
+
transaction: await buildTransaction(publicClient, {
|
|
390
441
|
chain: CHAIN_MAP[chainId],
|
|
391
442
|
account: userAddress,
|
|
392
443
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -413,11 +464,19 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
413
464
|
amount: spentAmount,
|
|
414
465
|
currency: inputCurrency,
|
|
415
466
|
direction: 'in',
|
|
467
|
+
events: events.map(({ price, spentAmount }) => ({
|
|
468
|
+
price,
|
|
469
|
+
amount: spentAmount,
|
|
470
|
+
})),
|
|
416
471
|
},
|
|
417
472
|
taken: {
|
|
418
473
|
amount: takenAmount,
|
|
419
474
|
currency: outputCurrency,
|
|
420
475
|
direction: 'out',
|
|
476
|
+
events: events.map(({ price, takenAmount }) => ({
|
|
477
|
+
price,
|
|
478
|
+
amount: takenAmount,
|
|
479
|
+
})),
|
|
421
480
|
},
|
|
422
481
|
},
|
|
423
482
|
};
|
|
@@ -425,7 +484,7 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
425
484
|
else {
|
|
426
485
|
throw new Error('Either amountIn or amountOut must be provided');
|
|
427
486
|
}
|
|
428
|
-
}
|
|
487
|
+
};
|
|
429
488
|
/**
|
|
430
489
|
* Claims specified open order for settlement.
|
|
431
490
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -453,7 +512,7 @@ export const marketOrder = decorator(async ({ chainId, userAddress, inputToken,
|
|
|
453
512
|
* id: openOrders.map((order) => order.id)
|
|
454
513
|
* })
|
|
455
514
|
*/
|
|
456
|
-
export const claimOrder =
|
|
515
|
+
export const claimOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
457
516
|
const { transaction, result } = await claimOrders({
|
|
458
517
|
chainId,
|
|
459
518
|
userAddress,
|
|
@@ -464,7 +523,7 @@ export const claimOrder = decorator(async ({ chainId, userAddress, id, options,
|
|
|
464
523
|
transaction,
|
|
465
524
|
result: result[0],
|
|
466
525
|
};
|
|
467
|
-
}
|
|
526
|
+
};
|
|
468
527
|
/**
|
|
469
528
|
* Claims specified open orders for settlement.
|
|
470
529
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -492,8 +551,12 @@ export const claimOrder = decorator(async ({ chainId, userAddress, id, options,
|
|
|
492
551
|
* ids: openOrders.map((order) => order.id)
|
|
493
552
|
* )
|
|
494
553
|
*/
|
|
495
|
-
export const claimOrders =
|
|
496
|
-
const
|
|
554
|
+
export const claimOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
555
|
+
const publicClient = createPublicClient({
|
|
556
|
+
chain: CHAIN_MAP[chainId],
|
|
557
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
558
|
+
});
|
|
559
|
+
const isApprovedForAll = await fetchIsApprovedForAll(publicClient, chainId, userAddress);
|
|
497
560
|
if (!isApprovedForAll) {
|
|
498
561
|
throw new Error(`
|
|
499
562
|
Set ApprovalForAll before calling this function.
|
|
@@ -505,18 +568,14 @@ export const claimOrders = decorator(async ({ chainId, userAddress, ids, options
|
|
|
505
568
|
})
|
|
506
569
|
`);
|
|
507
570
|
}
|
|
508
|
-
const orders = (await fetchOrders(chainId, ids.map((id) => BigInt(id)))).filter((order) => isAddressEqual(order.user, userAddress) &&
|
|
509
|
-
order.claimable.value !== '0');
|
|
571
|
+
const orders = (await fetchOrders(publicClient, chainId, ids.map((id) => BigInt(id)), !!(options && options.useSubgraph))).filter((order) => isAddressEqual(order.user, userAddress) && order.claimable.value !== '0');
|
|
510
572
|
const tokensToSettle = orders
|
|
511
|
-
.map((order) => [
|
|
512
|
-
order.inputCurrency.address,
|
|
513
|
-
order.outputCurrency.address,
|
|
514
|
-
])
|
|
573
|
+
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
515
574
|
.flat()
|
|
516
575
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
517
576
|
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
518
577
|
return {
|
|
519
|
-
transaction: await buildTransaction(
|
|
578
|
+
transaction: await buildTransaction(publicClient, {
|
|
520
579
|
chain: CHAIN_MAP[chainId],
|
|
521
580
|
account: userAddress,
|
|
522
581
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -541,7 +600,7 @@ export const claimOrders = decorator(async ({ chainId, userAddress, ids, options
|
|
|
541
600
|
return acc;
|
|
542
601
|
}, []),
|
|
543
602
|
};
|
|
544
|
-
}
|
|
603
|
+
};
|
|
545
604
|
/**
|
|
546
605
|
* Cancels specified open order if the order is not fully filled.
|
|
547
606
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -569,7 +628,7 @@ export const claimOrders = decorator(async ({ chainId, userAddress, ids, options
|
|
|
569
628
|
* id: openOrders.map((order) => order.id)
|
|
570
629
|
* })
|
|
571
630
|
*/
|
|
572
|
-
export const cancelOrder =
|
|
631
|
+
export const cancelOrder = async ({ chainId, userAddress, id, options, }) => {
|
|
573
632
|
const { transaction, result } = await cancelOrders({
|
|
574
633
|
chainId,
|
|
575
634
|
userAddress,
|
|
@@ -580,7 +639,7 @@ export const cancelOrder = decorator(async ({ chainId, userAddress, id, options,
|
|
|
580
639
|
transaction,
|
|
581
640
|
result: result[0],
|
|
582
641
|
};
|
|
583
|
-
}
|
|
642
|
+
};
|
|
584
643
|
/**
|
|
585
644
|
* Cancels specified open orders if orders are not fully filled.
|
|
586
645
|
* [IMPORTANT] Set ApprovalForAll before calling this function.
|
|
@@ -608,8 +667,12 @@ export const cancelOrder = decorator(async ({ chainId, userAddress, id, options,
|
|
|
608
667
|
* ids: openOrders.map((order) => order.id)
|
|
609
668
|
* })
|
|
610
669
|
*/
|
|
611
|
-
export const cancelOrders =
|
|
612
|
-
const
|
|
670
|
+
export const cancelOrders = async ({ chainId, userAddress, ids, options, }) => {
|
|
671
|
+
const publicClient = createPublicClient({
|
|
672
|
+
chain: CHAIN_MAP[chainId],
|
|
673
|
+
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
674
|
+
});
|
|
675
|
+
const isApprovedForAll = await fetchIsApprovedForAll(publicClient, chainId, userAddress);
|
|
613
676
|
if (!isApprovedForAll) {
|
|
614
677
|
throw new Error(`
|
|
615
678
|
Set ApprovalForAll before calling this function.
|
|
@@ -621,18 +684,14 @@ export const cancelOrders = decorator(async ({ chainId, userAddress, ids, option
|
|
|
621
684
|
})
|
|
622
685
|
`);
|
|
623
686
|
}
|
|
624
|
-
const orders = (await fetchOrders(chainId, ids.map((id) => BigInt(id)))).filter((order) => isAddressEqual(order.user, userAddress) &&
|
|
625
|
-
order.cancelable.value !== '0');
|
|
687
|
+
const orders = (await fetchOrders(publicClient, chainId, ids.map((id) => BigInt(id)), !!(options && options.useSubgraph))).filter((order) => isAddressEqual(order.user, userAddress) && order.cancelable.value !== '0');
|
|
626
688
|
const tokensToSettle = orders
|
|
627
|
-
.map((order) => [
|
|
628
|
-
order.inputCurrency.address,
|
|
629
|
-
order.outputCurrency.address,
|
|
630
|
-
])
|
|
689
|
+
.map((order) => [order.inputCurrency.address, order.outputCurrency.address])
|
|
631
690
|
.flat()
|
|
632
691
|
.filter((address, index, self) => self.findIndex((c) => isAddressEqual(c, address)) === index)
|
|
633
692
|
.filter((address) => !isAddressEqual(address, zeroAddress));
|
|
634
693
|
return {
|
|
635
|
-
transaction: await buildTransaction(
|
|
694
|
+
transaction: await buildTransaction(publicClient, {
|
|
636
695
|
chain: CHAIN_MAP[chainId],
|
|
637
696
|
account: userAddress,
|
|
638
697
|
address: CONTRACT_ADDRESSES[chainId].Controller,
|
|
@@ -658,5 +717,5 @@ export const cancelOrders = decorator(async ({ chainId, userAddress, ids, option
|
|
|
658
717
|
return acc;
|
|
659
718
|
}, []),
|
|
660
719
|
};
|
|
661
|
-
}
|
|
720
|
+
};
|
|
662
721
|
//# sourceMappingURL=call.js.map
|