@1stdex/first-sdk 1.0.92-beta.5 → 1.0.92
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/entities/book/apis/index.js +1 -3
- package/dist/cjs/entities/book/apis/index.js.map +1 -1
- package/dist/cjs/views/index.js +2 -2
- package/dist/cjs/views/index.js.map +1 -1
- package/dist/cjs/views/open-order.js +6 -1
- package/dist/cjs/views/open-order.js.map +1 -1
- package/dist/cjs/views/order.js +3 -15
- package/dist/cjs/views/order.js.map +1 -1
- package/dist/esm/entities/book/apis/index.js +0 -1
- package/dist/esm/entities/book/apis/index.js.map +1 -1
- package/dist/esm/views/index.js +2 -2
- package/dist/esm/views/index.js.map +1 -1
- package/dist/esm/views/open-order.js +17 -0
- package/dist/esm/views/open-order.js.map +1 -1
- package/dist/esm/views/order.js +0 -32
- package/dist/esm/views/order.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/entities/book/apis/index.d.ts +0 -1
- package/dist/types/entities/book/apis/index.d.ts.map +1 -1
- package/dist/types/views/index.d.ts +2 -2
- package/dist/types/views/index.d.ts.map +1 -1
- package/dist/types/views/open-order.d.ts +20 -0
- package/dist/types/views/open-order.d.ts.map +1 -1
- package/dist/types/views/order.d.ts +0 -29
- package/dist/types/views/order.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/entities/book/apis/position.js +0 -44
- package/dist/cjs/entities/book/apis/position.js.map +0 -1
- package/dist/esm/entities/book/apis/position.js +0 -54
- package/dist/esm/entities/book/apis/position.js.map +0 -1
- package/dist/types/entities/book/apis/position.d.ts +0 -11
- package/dist/types/entities/book/apis/position.d.ts.map +0 -1
|
@@ -2,6 +2,5 @@ import { PublicClient } from 'viem';
|
|
|
2
2
|
import { CHAIN_IDS } from '../../../constants/chain-configs/chain';
|
|
3
3
|
import { Currency } from '../../currency/types';
|
|
4
4
|
import { BookModel } from '../model';
|
|
5
|
-
export { fetchBookPositionValue } from './position';
|
|
6
5
|
export declare const fetchBook: (publicClient: PublicClient, chainId: CHAIN_IDS, quoteCurrency: Currency, baseCurrency: Currency, useSubgraph: boolean, includeDepths?: boolean) => Promise<BookModel>;
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/entities/book/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/entities/book/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC,eAAO,MAAM,SAAS,iBACN,YAAY,WACjB,SAAS,iBACH,QAAQ,gBACT,QAAQ,eACT,OAAO,kBACL,OAAO,KACrB,QAAQ,SAAS,CA+InB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getMarket, getChartLogs, getLatestChartLog, getExpectedOutput, getExpectedInput, getMarketSnapshots, getMarketSnapshot, getQuoteToken, parseMakeOrderIdsFromReceipt, getLimitOrderResult, getMakeOrderResult, } from './market';
|
|
2
2
|
export { getPriceNeighborhood } from './tick';
|
|
3
|
-
export { getOpenOrder, getOpenOrders, getCancelableOrders, getClaimableOrders, } from './open-order';
|
|
3
|
+
export { getOpenOrder, getOpenOrders, getCancelableOrders, getClaimableOrders, decodeOrderId, } from './open-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,7 +9,7 @@ export { getVault } from './vault';
|
|
|
9
9
|
export { getTradingBalance, getPortfolioBalance, getAllBalances, getRealTokenBalance, } from './balance';
|
|
10
10
|
export { checkTokenAllowances, needsVaultDeposit, getOrderSetupStatus, } from './setup';
|
|
11
11
|
export { getTradeInfo } from './book';
|
|
12
|
-
export { getOrder
|
|
12
|
+
export { getOrder } from './order';
|
|
13
13
|
export { getTradeHistory } from './trade-history';
|
|
14
14
|
export { getUserVolumeUSD } from './user-volume';
|
|
15
15
|
export { getCrossChainLZWithdrawalStatus } from './withdrawal';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","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,EAC5B,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","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,EAC5B,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,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,EACL,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,YAAY,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -84,4 +84,24 @@ export declare const getClaimableOrders: ({ chainId, userAddress, tokenAddresses
|
|
|
84
84
|
userAddress?: `0x${string}`;
|
|
85
85
|
tokenAddresses?: `0x${string}`[];
|
|
86
86
|
}) => Promise<OpenOrder[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Decodes an order ID into its constituent parts: book ID, tick, and index.
|
|
89
|
+
*
|
|
90
|
+
* @param {bigint} orderId The order ID to decode.
|
|
91
|
+
* @returns {{ bookId: bigint; tick: bigint; index: bigint }} Object containing the decoded book ID, tick, and index.
|
|
92
|
+
* @example
|
|
93
|
+
* import { decodeOrderId } from '@1stdex/first-sdk'
|
|
94
|
+
*
|
|
95
|
+
* const decoded = decodeOrderId({
|
|
96
|
+
* orderId: 46223845323662364279893361453861711542636620039907198451770258805035840307200n
|
|
97
|
+
* })
|
|
98
|
+
* // Returns: { bookId: 2503n, tick: 0n, index: 0n }
|
|
99
|
+
*/
|
|
100
|
+
export declare const decodeOrderId: ({ orderId, }: {
|
|
101
|
+
orderId: bigint;
|
|
102
|
+
}) => {
|
|
103
|
+
bookId: bigint;
|
|
104
|
+
tick: bigint;
|
|
105
|
+
index: bigint;
|
|
106
|
+
};
|
|
87
107
|
//# sourceMappingURL=open-order.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-order.d.ts","sourceRoot":"","sources":["../../../src/views/open-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"open-order.d.ts","sourceRoot":"","sources":["../../../src/views/open-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AASzD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,qBAGtB;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ,KAAG,QAAQ,SAAS,CAEpB,CAAC;AACF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,4CAIvB;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CAC9B,KAAG,QAAQ,SAAS,EAAE,CAMtB,CAAC;AACF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,8CAI7B;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,cAAc,CAAC,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;CAClC,KAAG,QAAQ,SAAS,EAAE,CAMtB,CAAC;AACF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,8CAI5B;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;CAClC,KAAG,QAAQ,SAAS,EAAE,CAEtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,iBAEvB;IACD,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG;IACF,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CAGf,CAAC"}
|
|
@@ -18,33 +18,4 @@ export declare const getOrder: ({ chainId, id, }: {
|
|
|
18
18
|
chainId: CHAIN_IDS;
|
|
19
19
|
id: string;
|
|
20
20
|
}) => Promise<Order>;
|
|
21
|
-
/**
|
|
22
|
-
* Gets the USD value for an order position with given units.
|
|
23
|
-
*
|
|
24
|
-
* @param {CHAIN_IDS} chainId - chain id from {@link CHAIN_IDS}
|
|
25
|
-
* @param {string} orderId - The order ID as a string
|
|
26
|
-
* @param {bigint} units - The number of units
|
|
27
|
-
*
|
|
28
|
-
* @returns {Promise<{ bookType: 'bids' | 'asks'; usdValue: string }>} An object containing:
|
|
29
|
-
* - bookType: 'bids' for bid books, 'asks' for ask books
|
|
30
|
-
* - usdValue: The USD value of the position as a string
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* import { getOrderPositionValue } from '@1stdex/first-sdk'
|
|
34
|
-
*
|
|
35
|
-
* const result = await getOrderPositionValue({
|
|
36
|
-
* chainId: 421614,
|
|
37
|
-
* orderId: '46223845323662364279893361453861711542636620039907198451770258805035840307200',
|
|
38
|
-
* units: 5n,
|
|
39
|
-
* })
|
|
40
|
-
* // returns { bookType: 'bids', usdValue: '1234.56' }
|
|
41
|
-
*/
|
|
42
|
-
export declare const getOrderPositionValue: ({ chainId, orderId, units, }: {
|
|
43
|
-
chainId: CHAIN_IDS;
|
|
44
|
-
orderId: string;
|
|
45
|
-
units: bigint;
|
|
46
|
-
}) => Promise<{
|
|
47
|
-
bookType: 'bids' | 'asks';
|
|
48
|
-
usdValue: string;
|
|
49
|
-
}>;
|
|
50
21
|
//# sourceMappingURL=order.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../../src/views/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../../src/views/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ,qBAGlB;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ,KAAG,QAAQ,KAAK,CAEhB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchBookPositionValue = void 0;
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const subgraph_1 = require("../../../constants/chain-configs/subgraph");
|
|
6
|
-
const utils_1 = require("../../../utils");
|
|
7
|
-
const market_id_1 = require("../../market/utils/market-id");
|
|
8
|
-
const fetchBookPositionValue = async ({ chainId, bookId, tick, units, }) => {
|
|
9
|
-
const { data: { book }, } = await subgraph_1.Subgraph.get(chainId, 'getBookForPositionValue', 'query getBookForPositionValue($bookId: ID!) { book(id: $bookId) { id unitSize base { id name symbol decimals priceUSD } quote { id name symbol decimals priceUSD } } }', {
|
|
10
|
-
bookId: bookId.toString(),
|
|
11
|
-
});
|
|
12
|
-
if (!book) {
|
|
13
|
-
throw new Error(`Book not found: ${bookId}`);
|
|
14
|
-
}
|
|
15
|
-
const baseAddress = (0, viem_1.getAddress)(book.base.id);
|
|
16
|
-
const quoteAddress = (0, viem_1.getAddress)(book.quote.id);
|
|
17
|
-
const unitSize = BigInt(book.unitSize);
|
|
18
|
-
const { quoteTokenAddress: marketQuoteAddress } = (0, market_id_1.getMarketId)(chainId, [
|
|
19
|
-
baseAddress,
|
|
20
|
-
quoteAddress,
|
|
21
|
-
]);
|
|
22
|
-
const isBidBook = (0, viem_1.isAddressEqual)(quoteAddress, marketQuoteAddress);
|
|
23
|
-
let usdValue;
|
|
24
|
-
let bookType;
|
|
25
|
-
if (isBidBook) {
|
|
26
|
-
const totalQuoteAmount = units * unitSize;
|
|
27
|
-
const totalBaseAmount = (0, utils_1.quoteToBase)(tick, totalQuoteAmount, false);
|
|
28
|
-
const baseAmount = new BigNumber(totalBaseAmount.toString()).div(new BigNumber(10).pow(Number(book.base.decimals)));
|
|
29
|
-
usdValue = baseAmount.times(book.base.priceUSD).toFixed();
|
|
30
|
-
bookType = 'bids';
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const totalBaseAmount = units * unitSize;
|
|
34
|
-
const baseAmount = new BigNumber(totalBaseAmount.toString()).div(new BigNumber(10).pow(Number(book.quote.decimals)));
|
|
35
|
-
usdValue = baseAmount.times(book.quote.priceUSD).toFixed();
|
|
36
|
-
bookType = 'asks';
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
bookType,
|
|
40
|
-
usdValue,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
exports.fetchBookPositionValue = fetchBookPositionValue;
|
|
44
|
-
//# sourceMappingURL=position.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../../../../src/entities/book/apis/position.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAGlD,wEAAqE;AACrE,0CAA6C;AAC7C,4DAA2D;AAEpD,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,GAMN,EAA4D,EAAE;IAE7D,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,GACf,GAAG,MAAM,mBAAQ,CAAC,GAAG,CAsBpB,OAAO,EACP,yBAAyB,EACzB,wKAAwK,EACxK;QACE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;KAC1B,CACF,CAAC;IAEF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,iBAAU,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7C,MAAM,YAAY,GAAG,IAAA,iBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAGvC,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,IAAA,uBAAW,EAAC,OAAO,EAAE;QACrE,WAAW;QACX,YAAY;KACb,CAAC,CAAC;IAGH,MAAM,SAAS,GAAG,IAAA,qBAAc,EAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAEnE,IAAI,QAAgB,CA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{ getMarketId } from '../../market/utils/market-id';
|
|
5
|
-
export const fetchBookPositionValue = async ({ chainId, bookId, tick, units, }) => {
|
|
6
|
-
// Fetch book data from subgraph
|
|
7
|
-
const { data: { book }, } = await Subgraph.get(chainId, 'getBookForPositionValue', 'query getBookForPositionValue($bookId: ID!) { book(id: $bookId) { id unitSize base { id name symbol decimals priceUSD } quote { id name symbol decimals priceUSD } } }', {
|
|
8
|
-
bookId: bookId.toString(),
|
|
9
|
-
});
|
|
10
|
-
if (!book) {
|
|
11
|
-
throw new Error(`Book not found: ${bookId}`);
|
|
12
|
-
}
|
|
13
|
-
const baseAddress = getAddress(book.base.id);
|
|
14
|
-
const quoteAddress = getAddress(book.quote.id);
|
|
15
|
-
const unitSize = BigInt(book.unitSize);
|
|
16
|
-
// Determine market quote token
|
|
17
|
-
const { quoteTokenAddress: marketQuoteAddress } = getMarketId(chainId, [
|
|
18
|
-
baseAddress,
|
|
19
|
-
quoteAddress,
|
|
20
|
-
]);
|
|
21
|
-
// Check if this is a bid book (book.quote == marketQuote) or ask book (book.base == marketQuote)
|
|
22
|
-
const isBidBook = isAddressEqual(quoteAddress, marketQuoteAddress);
|
|
23
|
-
let usdValue;
|
|
24
|
-
let bookType;
|
|
25
|
-
if (isBidBook) {
|
|
26
|
-
// Bid book: buying base with quote
|
|
27
|
-
// book.quote = market.quote, book.base = market.base
|
|
28
|
-
// units * unitSize = raw quote amount (in market.quote)
|
|
29
|
-
const totalQuoteAmount = units * unitSize;
|
|
30
|
-
// Convert quote to base using the tick price
|
|
31
|
-
const totalBaseAmount = quoteToBase(tick, totalQuoteAmount, false);
|
|
32
|
-
// Convert to human-readable base tokens
|
|
33
|
-
const baseAmount = new BigNumber(totalBaseAmount.toString()).div(new BigNumber(10).pow(Number(book.base.decimals)));
|
|
34
|
-
// USD value = base amount * base price USD
|
|
35
|
-
usdValue = baseAmount.times(book.base.priceUSD).toFixed();
|
|
36
|
-
bookType = 'bids';
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// Ask book: selling base for quote
|
|
40
|
-
// book.quote = market.base, book.base = market.quote (swapped!)
|
|
41
|
-
// units * unitSize = raw amount (in book's quote, which is market.base)
|
|
42
|
-
const totalBaseAmount = units * unitSize;
|
|
43
|
-
// Convert to human-readable base tokens (book.quote is market.base)
|
|
44
|
-
const baseAmount = new BigNumber(totalBaseAmount.toString()).div(new BigNumber(10).pow(Number(book.quote.decimals)));
|
|
45
|
-
// USD value = base amount * base price USD (book.quote is market.base)
|
|
46
|
-
usdValue = baseAmount.times(book.quote.priceUSD).toFixed();
|
|
47
|
-
bookType = 'asks';
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
bookType,
|
|
51
|
-
usdValue,
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=position.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../../../../src/entities/book/apis/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,GAMN,EAA4D,EAAE;IAC7D,gCAAgC;IAChC,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,GACf,GAAG,MAAM,QAAQ,CAAC,GAAG,CAsBpB,OAAO,EACP,yBAAyB,EACzB,wKAAwK,EACxK;QACE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;KAC1B,CACF,CAAC;IAEF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,mBAAmB,M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QAAQ,CAAC;QAEzC,oEAAoE;QACpE,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAC9D,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CACnD,CAAC;QAEF,uEAAuE;QACvE,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3D,QAAQ,GAAG,MAAM,CAAC;IACpB,CAAC;IAED,OAAO;QACL,QAAQ;QACR,QAAQ;KACT,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CHAIN_IDS } from '../../../constants/chain-configs/chain';
|
|
2
|
-
export declare const fetchBookPositionValue: ({ chainId, bookId, tick, units, }: {
|
|
3
|
-
chainId: CHAIN_IDS;
|
|
4
|
-
bookId: string;
|
|
5
|
-
tick: bigint;
|
|
6
|
-
units: bigint;
|
|
7
|
-
}) => Promise<{
|
|
8
|
-
bookType: 'bids' | 'asks';
|
|
9
|
-
usdValue: string;
|
|
10
|
-
}>;
|
|
11
|
-
//# sourceMappingURL=position.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../../../src/entities/book/apis/position.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAKnE,eAAO,MAAM,sBAAsB,sCAKhC;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,QAAQ;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CA2F1D,CAAC"}
|