@1stdex/first-sdk 1.0.31 → 1.0.32
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/calls/approval/{open-order.js → order-approval.js} +1 -1
- package/dist/cjs/calls/approval/order-approval.js.map +1 -0
- package/dist/cjs/calls/index.js +2 -2
- package/dist/cjs/calls/index.js.map +1 -1
- package/dist/cjs/calls/market/cancel.js +2 -2
- package/dist/cjs/calls/market/cancel.js.map +1 -1
- package/dist/cjs/calls/market/claim.js +2 -2
- package/dist/cjs/calls/market/claim.js.map +1 -1
- package/dist/cjs/entities/{open-order → order}/apis/index.js +39 -34
- package/dist/cjs/entities/order/apis/index.js.map +1 -0
- package/dist/cjs/entities/order/apis/operator.js.map +1 -0
- package/dist/cjs/entities/order/types.js.map +1 -0
- package/dist/cjs/entities/order/utils/order-id.js.map +1 -0
- package/dist/cjs/views/index.js +5 -6
- package/dist/cjs/views/index.js.map +1 -1
- package/dist/cjs/views/market/parse.js +1 -1
- package/dist/cjs/views/market/parse.js.map +1 -1
- package/dist/cjs/views/order-views.js +25 -0
- package/dist/cjs/views/order-views.js.map +1 -0
- package/dist/cjs/views/order.js +13 -4
- package/dist/cjs/views/order.js.map +1 -1
- package/dist/esm/calls/approval/{open-order.js → order-approval.js} +1 -1
- package/dist/esm/calls/approval/order-approval.js.map +1 -0
- package/dist/esm/calls/index.js +1 -1
- package/dist/esm/calls/index.js.map +1 -1
- package/dist/esm/calls/market/cancel.js +2 -2
- package/dist/esm/calls/market/cancel.js.map +1 -1
- package/dist/esm/calls/market/claim.js +2 -2
- package/dist/esm/calls/market/claim.js.map +1 -1
- package/dist/esm/entities/{open-order → order}/apis/index.js +39 -34
- package/dist/esm/entities/order/apis/index.js.map +1 -0
- package/dist/esm/entities/order/apis/operator.js.map +1 -0
- package/dist/esm/entities/order/types.js.map +1 -0
- package/dist/esm/entities/order/utils/order-id.js.map +1 -0
- package/dist/esm/views/index.js +1 -2
- package/dist/esm/views/index.js.map +1 -1
- package/dist/esm/views/market/parse.js +1 -1
- package/dist/esm/views/market/parse.js.map +1 -1
- package/dist/esm/views/order-views.js +70 -0
- package/dist/esm/views/order-views.js.map +1 -0
- package/dist/esm/views/order.js +38 -1
- package/dist/esm/views/order.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/calls/approval/{open-order.d.ts → order-approval.d.ts} +1 -1
- package/dist/types/calls/approval/order-approval.d.ts.map +1 -0
- package/dist/types/calls/index.d.ts +1 -1
- package/dist/types/calls/index.d.ts.map +1 -1
- package/dist/types/entities/{open-order → order}/apis/index.d.ts +6 -6
- package/dist/types/entities/order/apis/index.d.ts.map +1 -0
- package/dist/types/entities/order/apis/operator.d.ts.map +1 -0
- package/dist/types/entities/{open-order → order}/types.d.ts +2 -2
- package/dist/types/entities/order/types.d.ts.map +1 -0
- package/dist/types/entities/order/utils/order-id.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/views/index.d.ts +1 -2
- package/dist/types/views/index.d.ts.map +1 -1
- package/dist/types/views/order-views.d.ts +70 -0
- package/dist/types/views/order-views.d.ts.map +1 -0
- package/dist/types/views/order.d.ts +39 -0
- package/dist/types/views/order.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/calls/approval/open-order.js.map +0 -1
- package/dist/cjs/entities/open-order/apis/index.js.map +0 -1
- package/dist/cjs/entities/open-order/apis/operator.js.map +0 -1
- package/dist/cjs/entities/open-order/types.js.map +0 -1
- package/dist/cjs/entities/open-order/utils/order-id.js.map +0 -1
- package/dist/cjs/views/open-order.js +0 -13
- package/dist/cjs/views/open-order.js.map +0 -1
- package/dist/esm/calls/approval/open-order.js.map +0 -1
- package/dist/esm/entities/open-order/apis/index.js.map +0 -1
- package/dist/esm/entities/open-order/apis/operator.js.map +0 -1
- package/dist/esm/entities/open-order/types.js.map +0 -1
- package/dist/esm/entities/open-order/utils/order-id.js.map +0 -1
- package/dist/esm/views/open-order.js +0 -38
- package/dist/esm/views/open-order.js.map +0 -1
- package/dist/types/calls/approval/open-order.d.ts.map +0 -1
- package/dist/types/entities/open-order/apis/index.d.ts.map +0 -1
- package/dist/types/entities/open-order/apis/operator.d.ts.map +0 -1
- package/dist/types/entities/open-order/types.d.ts.map +0 -1
- package/dist/types/entities/open-order/utils/order-id.d.ts.map +0 -1
- package/dist/types/views/open-order.d.ts +0 -41
- package/dist/types/views/open-order.d.ts.map +0 -1
- /package/dist/cjs/entities/{open-order → order}/apis/operator.js +0 -0
- /package/dist/cjs/entities/{open-order → order}/types.js +0 -0
- /package/dist/cjs/entities/{open-order → order}/utils/order-id.js +0 -0
- /package/dist/esm/entities/{open-order → order}/apis/operator.js +0 -0
- /package/dist/esm/entities/{open-order → order}/types.js +0 -0
- /package/dist/esm/entities/{open-order → order}/utils/order-id.js +0 -0
- /package/dist/types/entities/{open-order → order}/apis/operator.d.ts +0 -0
- /package/dist/types/entities/{open-order → order}/utils/order-id.d.ts +0 -0
|
@@ -8,9 +8,9 @@ import { CONTRACT_ADDRESSES } from '../../../constants/chain-configs/addresses';
|
|
|
8
8
|
import { BOOK_MANAGER_ABI } from '../../../constants/abis/core/book-manager-abi';
|
|
9
9
|
import { fetchCurrencyMap } from '../../currency/apis';
|
|
10
10
|
import { fromOrderId } from '../utils/order-id';
|
|
11
|
-
const
|
|
12
|
-
const inputCurrency = currencies.find((c) => isAddressEqual(c.address, getAddress(
|
|
13
|
-
const outputCurrency = currencies.find((c) => isAddressEqual(c.address, getAddress(
|
|
11
|
+
const toOrder = (chainId, currencies, order) => {
|
|
12
|
+
const inputCurrency = currencies.find((c) => isAddressEqual(c.address, getAddress(order.book.quote.id)));
|
|
13
|
+
const outputCurrency = currencies.find((c) => isAddressEqual(c.address, getAddress(order.book.base.id)));
|
|
14
14
|
const { quoteTokenAddress } = getMarketId(chainId, [
|
|
15
15
|
inputCurrency.address,
|
|
16
16
|
outputCurrency.address,
|
|
@@ -18,12 +18,12 @@ const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
|
18
18
|
const isBid = isAddressEqual(quoteTokenAddress, inputCurrency.address);
|
|
19
19
|
const quote = isBid ? inputCurrency : outputCurrency;
|
|
20
20
|
const base = isBid ? outputCurrency : inputCurrency;
|
|
21
|
-
const tick = BigInt(
|
|
22
|
-
const unitAmount = BigInt(
|
|
23
|
-
const filledUnitAmount = BigInt(
|
|
24
|
-
const unitSize = BigInt(
|
|
25
|
-
const claimedUnitAmount = BigInt(
|
|
26
|
-
const claimableUnitAmount = BigInt(
|
|
21
|
+
const tick = BigInt(order.tick);
|
|
22
|
+
const unitAmount = BigInt(order.unitAmount);
|
|
23
|
+
const filledUnitAmount = BigInt(order.filledUnitAmount);
|
|
24
|
+
const unitSize = BigInt(order.book.unitSize);
|
|
25
|
+
const claimedUnitAmount = BigInt(order.claimedUnitAmount);
|
|
26
|
+
const claimableUnitAmount = BigInt(order.claimableUnitAmount);
|
|
27
27
|
// base amount type
|
|
28
28
|
const amount = isBid
|
|
29
29
|
? quoteToBase(tick, unitSize * unitAmount, false)
|
|
@@ -41,16 +41,16 @@ const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
|
41
41
|
: baseToQuote(invertedTick, unitSize * claimableUnitAmount, false);
|
|
42
42
|
const cancelable = unitSize * (unitAmount - filledUnitAmount); // same current open amount
|
|
43
43
|
return {
|
|
44
|
-
id:
|
|
45
|
-
user: getAddress(
|
|
44
|
+
id: order.id,
|
|
45
|
+
user: getAddress(order.owner),
|
|
46
46
|
isBid,
|
|
47
47
|
inputCurrency,
|
|
48
48
|
outputCurrency,
|
|
49
|
-
txHash:
|
|
50
|
-
createdAt: Number(
|
|
49
|
+
txHash: order.transaction.id,
|
|
50
|
+
createdAt: Number(order.timestamp),
|
|
51
51
|
price: formatPrice(toPrice(isBid ? tick : invertTick(tick)), quote.decimals, base.decimals),
|
|
52
52
|
tick: Number(tick),
|
|
53
|
-
orderIndex:
|
|
53
|
+
orderIndex: order.orderIndex,
|
|
54
54
|
amount: { currency: base, value: formatUnits(amount, base.decimals) },
|
|
55
55
|
filled: { currency: base, value: formatUnits(filled, base.decimals) },
|
|
56
56
|
claimed: {
|
|
@@ -69,21 +69,21 @@ const toOpenOrder = (chainId, currencies, openOrder) => {
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
const
|
|
73
|
-
const currencies =
|
|
74
|
-
.map((
|
|
72
|
+
const extractCurrenciesFromOrders = (orders) => {
|
|
73
|
+
const currencies = orders
|
|
74
|
+
.map((order) => {
|
|
75
75
|
return [
|
|
76
76
|
{
|
|
77
|
-
address: getAddress(
|
|
78
|
-
name:
|
|
79
|
-
symbol:
|
|
80
|
-
decimals: Number(
|
|
77
|
+
address: getAddress(order.book.base.id),
|
|
78
|
+
name: order.book.base.name,
|
|
79
|
+
symbol: order.book.base.symbol,
|
|
80
|
+
decimals: Number(order.book.base.decimals),
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
address: getAddress(
|
|
84
|
-
name:
|
|
85
|
-
symbol:
|
|
86
|
-
decimals: Number(
|
|
83
|
+
address: getAddress(order.book.quote.id),
|
|
84
|
+
name: order.book.quote.name,
|
|
85
|
+
symbol: order.book.quote.symbol,
|
|
86
|
+
decimals: Number(order.book.quote.decimals),
|
|
87
87
|
},
|
|
88
88
|
];
|
|
89
89
|
})
|
|
@@ -96,21 +96,26 @@ const extractCurrenciesFromOpenOrders = (openOrders) => {
|
|
|
96
96
|
return currencies;
|
|
97
97
|
};
|
|
98
98
|
export async function fetchOpenOrdersByUserAddressFromSubgraph(chainId, userAddress) {
|
|
99
|
-
const { data: {
|
|
100
|
-
const currencies =
|
|
101
|
-
return
|
|
99
|
+
const { data: { orders }, } = await Subgraph.get(chainId, 'getOpenOrdersByUserAddress', 'query getOpenOrdersByUserAddress($userAddress: String!) { orders(where: {owner: $userAddress, or: [{claimableUnitAmount_gt: "0"}, {cancelableUnitAmount_gt: "0"}]}, first: 1000) { id owner book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick transaction { id } timestamp unitAmount filledUnitAmount claimedUnitAmount claimableUnitAmount cancelableUnitAmount orderIndex } }', { userAddress: userAddress.toLowerCase() });
|
|
100
|
+
const currencies = extractCurrenciesFromOrders(orders);
|
|
101
|
+
return orders.map((order) => toOrder(chainId, currencies, order));
|
|
102
102
|
}
|
|
103
103
|
export async function fetchOpenOrderByOrderIdFromSubgraph(chainId, orderId) {
|
|
104
|
-
const { data: {
|
|
105
|
-
if (!
|
|
104
|
+
const { data: { order }, } = await Subgraph.get(chainId, 'getOpenOrder', 'query getOpenOrder($orderId: ID!) { order(id: $orderId) { id owner book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick transaction { id } timestamp unitAmount filledUnitAmount claimedUnitAmount claimableUnitAmount cancelableUnitAmount orderIndex } }', { orderId });
|
|
105
|
+
if (!order) {
|
|
106
106
|
throw new Error(`Open order not found: ${orderId}`);
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
const claimableUnitAmount = BigInt(order.claimableUnitAmount);
|
|
109
|
+
const cancelableUnitAmount = BigInt(order.cancelableUnitAmount);
|
|
110
|
+
if (claimableUnitAmount + cancelableUnitAmount === 0n) {
|
|
111
|
+
throw new Error(`Order is fully settled: ${orderId}`);
|
|
112
|
+
}
|
|
113
|
+
return toOrder(chainId, extractCurrenciesFromOrders([order]), order);
|
|
109
114
|
}
|
|
110
115
|
export async function fetchOpenOrdersByOrderIdsFromSubgraph(chainId, orderIds) {
|
|
111
|
-
const { data: {
|
|
112
|
-
const currencies =
|
|
113
|
-
return
|
|
116
|
+
const { data: { orders }, } = await Subgraph.get(chainId, 'getOpenOrders', 'query getOpenOrders($orderIds: [ID!]!) { orders(where: {id_in: $orderIds, or: [{claimableUnitAmount_gt: "0"}, {cancelableUnitAmount_gt: "0"}]}) { id owner book { id base { id name symbol decimals } quote { id name symbol decimals } unitSize } tick transaction { id } timestamp unitAmount filledUnitAmount claimedUnitAmount claimableUnitAmount cancelableUnitAmount orderIndex } }', { orderIds });
|
|
117
|
+
const currencies = extractCurrenciesFromOrders(orders);
|
|
118
|
+
return orders.map((order) => toOrder(chainId, currencies, order));
|
|
114
119
|
}
|
|
115
120
|
export const fetchOnChainOrders = async (publicClient, chainId, orderIds) => {
|
|
116
121
|
const result = await publicClient.multicall({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/entities/order/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,cAAc,EAEd,WAAW,GACZ,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+CAA+C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAwBhD,MAAM,OAAO,GAAG,CACd,OAAkB,EAClB,UAAsB,EACtB,KAAe,EACR,EAAE;IACT,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAW,EAAE,EAAE,CACpD,cAAc,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAC1D,CAAC;IACH,MAAM,cAAc,GAAG,UAAU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AAkB,EAClB,KAAoB;IAEpB,OAAO,YAAY,CAAC,YAAY,CAAC;QAC/B,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAE,CAAC,WAAW;QACjD,GAAG,EAAE,gBAAgB;QACrB,YAAY,EAAE,iBAAiB;QAC/B,IAAI,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,CAAC;KACvD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/entities/order/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-id.js","sourceRoot":"","sources":["../../../../../src/entities/order/utils/order-id.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAe,EAKf,EAAE;IACF,MAAM,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;IACjD,OAAO;QACL,MAAM,EAAE,OAAO,IAAI,GAAG;QACtB,IAAI,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QACrD,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAc,EACd,IAAY,EACZ,UAAkB,EACV,EAAE;IACV,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;IACxC,OAAO,UAAU,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;AACzD,CAAC,CAAC"}
|
package/dist/esm/views/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getMarket, getChartLogs, getLatestChartLog, getExpectedOutput, getExpectedInput, getMarketSnapshots, getMarketSnapshot, getQuoteToken, parseMakeOrderIdsFromReceipt, } from './market';
|
|
2
2
|
export { getPriceNeighborhood } from './tick';
|
|
3
|
-
export { getOpenOrder, getOpenOrders } from './
|
|
3
|
+
export { getOpenOrder, getOpenOrders, getOrderPositionValue } from './order';
|
|
4
4
|
export { getSubgraphEndpoint, getSubgraphBlockNumber, getSubgraphBlock, } from './subgraph';
|
|
5
5
|
export { getContractAddresses } from './address';
|
|
6
6
|
export { getCurrencies, getStableCurrencies, getLatestPriceMap, getDailyClosePriceMap, getLatestPrice, } from './currency';
|
|
@@ -9,5 +9,4 @@ export { getVault } from './vault';
|
|
|
9
9
|
export { getTradingBalance, getPortfolioBalance } from './balance';
|
|
10
10
|
export { isOrderOperatorApproved, checkTokenAllowances, needsVaultDeposit, getOrderSetupStatus, } from './setup';
|
|
11
11
|
export { getBookPositionValue } from './book';
|
|
12
|
-
export { getOrderPositionValue } from './order';
|
|
13
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/views/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/views/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseEventLogs } from 'viem';
|
|
2
2
|
import { BOOK_MANAGER_ABI } from '../../constants/abis/core/book-manager-abi';
|
|
3
|
-
import { toOrderId } from '../../entities/
|
|
3
|
+
import { toOrderId } from '../../entities/order/utils/order-id';
|
|
4
4
|
export const parseMakeOrderIdsFromReceipt = ({ market, transactionReceipt, }) => {
|
|
5
5
|
const logs = parseEventLogs({
|
|
6
6
|
abi: BOOK_MANAGER_ABI,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../src/views/market/parse.ts"],"names":[],"mappings":"A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AC,CAAC;aACtE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAC9C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACzD;KACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { fetchOpenOrderByOrderIdFromSubgraph, fetchOpenOrdersByUserAddressFromSubgraph, } from '../entities/order/apis';
|
|
2
|
+
import { fetchBookPositionValue } from '../entities/book/apis';
|
|
3
|
+
import { fromOrderId } from '../entities/order/utils/order-id';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the open order with the specified ID on the given chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {CHAIN_IDS} chainId The chain ID.
|
|
8
|
+
* @param {string} id The ID of the open order.
|
|
9
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
10
|
+
* @returns {Promise<Order>} Promise resolving to the open order object, or undefined if not found.
|
|
11
|
+
* @example
|
|
12
|
+
* import { getOpenOrder } from '@clober/v2-sdk'
|
|
13
|
+
*
|
|
14
|
+
* const openOrder = await getOpenOrder({
|
|
15
|
+
* chainId: 421614,
|
|
16
|
+
* id: '46223845323662364279893361453861711542636620039907198451770258805035840307200'
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
export const getOpenOrder = async ({ chainId, id, }) => {
|
|
20
|
+
return fetchOpenOrderByOrderIdFromSubgraph(chainId, id);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves open orders for the specified user on the given chain.
|
|
24
|
+
*
|
|
25
|
+
* @param {CHAIN_IDS} chainId The chain ID.
|
|
26
|
+
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
27
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
28
|
+
* @returns {Promise<Order[]>} Promise resolving to an array of open orders.
|
|
29
|
+
* @example
|
|
30
|
+
* import { getOpenOrders } from '@clober/v2-sdk'
|
|
31
|
+
*
|
|
32
|
+
* const openOrders = await getOpenOrders({
|
|
33
|
+
* chainId: 421614,
|
|
34
|
+
* userAddress: '0x5F79EE8f8fA862E98201120d83c4eC39D9468D49'
|
|
35
|
+
* })
|
|
36
|
+
*/
|
|
37
|
+
export const getOpenOrders = async ({ chainId, userAddress, }) => {
|
|
38
|
+
return fetchOpenOrdersByUserAddressFromSubgraph(chainId, userAddress);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Gets the USD value for an order position with given units.
|
|
42
|
+
*
|
|
43
|
+
* @param {CHAIN_IDS} chainId - chain id from {@link CHAIN_IDS}
|
|
44
|
+
* @param {string} orderId - The order ID as a string
|
|
45
|
+
* @param {bigint} units - The number of units
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<{ bookType: 'bids' | 'asks'; usdValue: string }>} An object containing:
|
|
48
|
+
* - bookType: 'bids' for bid books, 'asks' for ask books
|
|
49
|
+
* - usdValue: The USD value of the position as a string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* import { getOrderPositionValue } from '@clober/v2-sdk'
|
|
53
|
+
*
|
|
54
|
+
* const result = await getOrderPositionValue({
|
|
55
|
+
* chainId: 421614,
|
|
56
|
+
* orderId: '46223845323662364279893361453861711542636620039907198451770258805035840307200',
|
|
57
|
+
* units: 5n,
|
|
58
|
+
* })
|
|
59
|
+
* // returns { bookType: 'bids', usdValue: '1234.56' }
|
|
60
|
+
*/
|
|
61
|
+
export const getOrderPositionValue = async ({ chainId, orderId, units, }) => {
|
|
62
|
+
const { bookId, tick } = fromOrderId(BigInt(orderId));
|
|
63
|
+
return fetchBookPositionValue({
|
|
64
|
+
chainId,
|
|
65
|
+
bookId: bookId.toString(),
|
|
66
|
+
tick,
|
|
67
|
+
units,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=order-views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-views.js","sourceRoot":"","sources":["../../../src/views/order-views.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mCAAmC,EACnC,wCAAwC,GACzC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,EAAE,GAIH,EAAkB,EAAE;IACnB,OAAO,mCAAmC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,WAAW,GAIZ,EAAoB,EAAE;IACrB,OAAO,wCAAwC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,EAC1C,OAAO,EACP,OAAO,EACP,KAAK,GAKN,EAA4D,EAAE;IAC7D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,OAAO,sBAAsB,CAAC;QAC5B,OAAO;QACP,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;QACzB,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/esm/views/order.js
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
|
+
import { fetchOpenOrderByOrderIdFromSubgraph, fetchOpenOrdersByUserAddressFromSubgraph, } from '../entities/order/apis';
|
|
1
2
|
import { fetchBookPositionValue } from '../entities/book/apis';
|
|
2
|
-
import { fromOrderId } from '../entities/
|
|
3
|
+
import { fromOrderId } from '../entities/order/utils/order-id';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the open order with the specified ID on the given chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {CHAIN_IDS} chainId The chain ID.
|
|
8
|
+
* @param {string} id The ID of the open order.
|
|
9
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
10
|
+
* @returns {Promise<Order>} Promise resolving to the open order object, or undefined if not found.
|
|
11
|
+
* @example
|
|
12
|
+
* import { getOpenOrder } from '@clober/v2-sdk'
|
|
13
|
+
*
|
|
14
|
+
* const openOrder = await getOpenOrder({
|
|
15
|
+
* chainId: 421614,
|
|
16
|
+
* id: '46223845323662364279893361453861711542636620039907198451770258805035840307200'
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
export const getOpenOrder = async ({ chainId, id, }) => {
|
|
20
|
+
return fetchOpenOrderByOrderIdFromSubgraph(chainId, id);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves open orders for the specified user on the given chain.
|
|
24
|
+
*
|
|
25
|
+
* @param {CHAIN_IDS} chainId The chain ID.
|
|
26
|
+
* @param {`0x${string}`} userAddress The Ethereum address of the user.
|
|
27
|
+
* @param options {@link DefaultReadContractOptions} options.
|
|
28
|
+
* @returns {Promise<Order[]>} Promise resolving to an array of open orders.
|
|
29
|
+
* @example
|
|
30
|
+
* import { getOpenOrders } from '@clober/v2-sdk'
|
|
31
|
+
*
|
|
32
|
+
* const openOrders = await getOpenOrders({
|
|
33
|
+
* chainId: 421614,
|
|
34
|
+
* userAddress: '0x5F79EE8f8fA862E98201120d83c4eC39D9468D49'
|
|
35
|
+
* })
|
|
36
|
+
*/
|
|
37
|
+
export const getOpenOrders = async ({ chainId, userAddress, }) => {
|
|
38
|
+
return fetchOpenOrdersByUserAddressFromSubgraph(chainId, userAddress);
|
|
39
|
+
};
|
|
3
40
|
/**
|
|
4
41
|
* Gets the USD value for an order position with given units.
|
|
5
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/views/order.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/views/order.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mCAAmC,EACnC,wCAAwC,GACzC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,EAAE,GAIH,EAAkB,EAAE;IACnB,OAAO,mCAAmC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,WAAW,GAIZ,EAAoB,EAAE;IACrB,OAAO,wCAAwC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EAAE,EAC1C,OAAO,EACP,OAAO,EACP,KAAK,GAKN,EAA4D,EAAE;IAC7D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,OAAO,sBAAsB,CAAC;QAC5B,OAAO;QACP,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;QACzB,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC"}
|