@runesx/api-client 0.3.0 → 0.5.1
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/README.md +603 -418
- package/package.json +7 -7
- package/src/api.mjs +387 -4
- package/src/index.mjs +118 -12
- package/src/socket.mjs +204 -115
- package/src/store/coinStore.mjs +1 -1
- package/src/store/exchangeConfigStore.mjs +48 -0
- package/src/store/marketStore.mjs +57 -0
- package/src/store/orderbookStore.mjs +99 -0
- package/src/store/poolStore.mjs +1 -1
- package/src/store/userSharesStore.mjs +1 -1
- package/src/store/walletStore.mjs +1 -1
- package/src/utils/liquidityUtils.mjs +2 -3
- package/src/utils/priceUtils.mjs +2 -1
- package/src/utils/safeBigNumber.mjs +11 -0
- package/src/utils/swapUtils.mjs +1159 -129
- package/src/waitForStores.mjs +41 -6
- package/src/workers/swapWorker.mjs +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/utils/liquidityUtils.mjs
|
|
2
|
-
import { BigNumber } from '
|
|
3
|
-
|
|
2
|
+
import { SafeBigNumber as BigNumber } from './safeBigNumber.mjs';
|
|
4
3
|
import { getRunesPriceUSD, getTokenPriceInRunes } from './swapUtils.mjs';
|
|
5
4
|
|
|
6
5
|
export function normalizeTokenPairFrontend(coinA, coinB, pools) {
|
|
@@ -111,7 +110,7 @@ export function getPoolRatioFrontend(pool) {
|
|
|
111
110
|
return reserveADecimal.div(reserveBDecimal);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
export function estimateLiquidityFrontend({ coinA, coinB, amountA, amountB, pools
|
|
113
|
+
export function estimateLiquidityFrontend({ coinA, coinB, amountA, amountB, pools }) {
|
|
115
114
|
if ((amountA === null && amountB === null) || (amountA !== null && amountB !== null)) {
|
|
116
115
|
throw new Error('Provide either amountA or amountB, but not both or neither');
|
|
117
116
|
}
|
package/src/utils/priceUtils.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// src/utils/priceUtils.mjs
|
|
2
|
-
import { BigNumber } from 'bignumber.js';
|
|
3
2
|
|
|
4
3
|
import { getPools } from '../store/poolStore.mjs';
|
|
5
4
|
import { getCoinByTicker } from '../store/coinStore.mjs';
|
|
6
5
|
|
|
6
|
+
import { SafeBigNumber as BigNumber } from './safeBigNumber.mjs';
|
|
7
|
+
|
|
7
8
|
export function createPriceUtils() {
|
|
8
9
|
const getRunesPriceUSD = () => {
|
|
9
10
|
const pools = getPools();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/utils/safeBigNumber.mjs
|
|
2
|
+
// Isolated BigNumber constructor aligned with the backend's SafeBigNumber
|
|
3
|
+
// (runesx-api/src/utils/safeBigNumber.mjs). Uses the same DECIMAL_PLACES=40
|
|
4
|
+
// and EXPONENTIAL_AT=[-100, 100] configuration to ensure estimation arithmetic
|
|
5
|
+
// matches backend financial calculations.
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
7
|
+
|
|
8
|
+
export const SafeBigNumber = BigNumber.clone({
|
|
9
|
+
DECIMAL_PLACES: 40,
|
|
10
|
+
EXPONENTIAL_AT: [-100, 100],
|
|
11
|
+
});
|