@1stdex/first-sdk 1.0.92-beta.4 → 1.0.92-beta.5
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/views/book.js +7 -6
- package/dist/cjs/views/book.js.map +1 -1
- package/dist/esm/views/book.js +14 -13
- package/dist/esm/views/book.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/views/book.d.ts +8 -11
- package/dist/types/views/book.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/views/book.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTradeInfo = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const subgraph_1 = require("../constants/chain-configs/subgraph");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
@@ -11,8 +12,8 @@ const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
|
11
12
|
throw new Error(`Book not found: ${bookId}`);
|
|
12
13
|
}
|
|
13
14
|
const unitSize = BigInt(book.unitSize);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
15
|
+
const quoteAmountRaw = quoteUnits * unitSize;
|
|
16
|
+
const baseAmountRaw = (0, utils_1.quoteToBase)(tick, quoteAmountRaw, false);
|
|
16
17
|
const quoteCurrency = {
|
|
17
18
|
address: book.quote.id,
|
|
18
19
|
name: book.quote.name,
|
|
@@ -25,11 +26,11 @@ const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
|
25
26
|
symbol: book.base.symbol,
|
|
26
27
|
decimals: Number(book.base.decimals),
|
|
27
28
|
};
|
|
29
|
+
const quoteAmount = (0, viem_1.formatUnits)(quoteAmountRaw, quoteCurrency.decimals);
|
|
30
|
+
const baseAmount = (0, viem_1.formatUnits)(baseAmountRaw, baseCurrency.decimals);
|
|
28
31
|
return {
|
|
29
|
-
quoteCurrency,
|
|
30
|
-
|
|
31
|
-
baseCurrency,
|
|
32
|
-
baseAmount,
|
|
32
|
+
quote: { currency: quoteCurrency, value: quoteAmount },
|
|
33
|
+
base: { currency: baseCurrency, value: baseAmount },
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
exports.getTradeInfo = getTradeInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"book.js","sourceRoot":"","sources":["../../../src/views/book.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"book.js","sourceRoot":"","sources":["../../../src/views/book.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAGnC,kEAA+D;AAE/D,oCAAuC;AA0BhC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,GAMX,EAGE,EAAE;IAEH,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,GACf,GAAG,MAAM,mBAAQ,CAAC,GAAG,CAoBpB,OAAO,EACP,cAAc,EACd,2IAA2I,EAC3I;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,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAGvC,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC7C,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,IAAI,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;IAG/D,MAAM,aAAa,GAAa;QAC9B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,EAAmB;QACvC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;QACrB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;QACzB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;KACtC,CAAC;IAEF,MAAM,YAAY,GAAa;QAC7B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,EAAmB;QACtC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;QACpB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;QACxB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;KACrC,CAAC;IAGF,MAAM,WAAW,GAAG,IAAA,kBAAW,EAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxE,MAAM,UAAU,GAAG,IAAA,kBAAW,EAAC,aAAa,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAErE,OAAO;QACL,KAAK,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE;QACtD,IAAI,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE;KACpD,CAAC;AACJ,CAAC,CAAC;AA9EW,QAAA,YAAY,gBA8EvB"}
|
package/dist/esm/views/book.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatUnits } from 'viem';
|
|
1
2
|
import { Subgraph } from '../constants/chain-configs/subgraph';
|
|
2
3
|
import { quoteToBase } from '../utils';
|
|
3
4
|
/**
|
|
@@ -8,11 +9,9 @@ import { quoteToBase } from '../utils';
|
|
|
8
9
|
* @param {bigint} tick - The tick for the trade
|
|
9
10
|
* @param {bigint} quoteUnits - The number of quote units
|
|
10
11
|
*
|
|
11
|
-
* @returns {Promise<{
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
14
|
-
* - baseCurrency: The base currency information
|
|
15
|
-
* - baseAmount: The raw base token amount
|
|
12
|
+
* @returns {Promise<{ quote: CurrencyAmount; base: CurrencyAmount }>} An object containing:
|
|
13
|
+
* - quote: The quote currency and formatted amount
|
|
14
|
+
* - base: The base currency and formatted amount
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
18
17
|
* import { getTradeInfo } from '@1stdex/first-sdk'
|
|
@@ -23,7 +22,8 @@ import { quoteToBase } from '../utils';
|
|
|
23
22
|
* tick: 1000n,
|
|
24
23
|
* quoteUnits: 5n,
|
|
25
24
|
* })
|
|
26
|
-
*
|
|
25
|
+
* console.log(`Quote: ${result.quote.value} ${result.quote.currency.symbol}`)
|
|
26
|
+
* console.log(`Base: ${result.base.value} ${result.base.currency.symbol}`)
|
|
27
27
|
*/
|
|
28
28
|
export const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
29
29
|
// Fetch book data from subgraph
|
|
@@ -34,9 +34,9 @@ export const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
|
34
34
|
throw new Error(`Book not found: ${bookId}`);
|
|
35
35
|
}
|
|
36
36
|
const unitSize = BigInt(book.unitSize);
|
|
37
|
-
// Calculate amounts
|
|
38
|
-
const
|
|
39
|
-
const
|
|
37
|
+
// Calculate raw amounts
|
|
38
|
+
const quoteAmountRaw = quoteUnits * unitSize;
|
|
39
|
+
const baseAmountRaw = quoteToBase(tick, quoteAmountRaw, false);
|
|
40
40
|
// Build currency objects
|
|
41
41
|
const quoteCurrency = {
|
|
42
42
|
address: book.quote.id,
|
|
@@ -50,11 +50,12 @@ export const getTradeInfo = async ({ chainId, bookId, tick, quoteUnits, }) => {
|
|
|
50
50
|
symbol: book.base.symbol,
|
|
51
51
|
decimals: Number(book.base.decimals),
|
|
52
52
|
};
|
|
53
|
+
// Format amounts to strings
|
|
54
|
+
const quoteAmount = formatUnits(quoteAmountRaw, quoteCurrency.decimals);
|
|
55
|
+
const baseAmount = formatUnits(baseAmountRaw, baseCurrency.decimals);
|
|
53
56
|
return {
|
|
54
|
-
quoteCurrency,
|
|
55
|
-
|
|
56
|
-
baseCurrency,
|
|
57
|
-
baseAmount,
|
|
57
|
+
quote: { currency: quoteCurrency, value: quoteAmount },
|
|
58
|
+
base: { currency: baseCurrency, value: baseAmount },
|
|
58
59
|
};
|
|
59
60
|
};
|
|
60
61
|
//# sourceMappingURL=book.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"book.js","sourceRoot":"","sources":["../../../src/views/book.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"book.js","sourceRoot":"","sources":["../../../src/views/book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,GAMX,EAGE,EAAE;IACH,gCAAgC;IAChC,MAAM,EACJ,IAAI,EAAE,EAAE,IAAI,EAAE,GACf,GAAG,MAAM,QAAQ,CAAC,GAAG,CAoBpB,OAAO,EACP,cAAc,EACd,2IAA2I,EAC3I;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,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEvC,wBAAwB;IACxB,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC7C,MAAM,aAAa,GAAG,WAAW,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;IAE/D,yBAAyB;IACzB,MAAM,aAAa,GAAa;QAC9B,OAAO,EAAE,IAAI,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