@galacticcouncil/sdk-next 0.25.0 → 0.26.0
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/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/types/api/ChainWatcher.d.ts +11 -0
- package/build/types/api/Papi.d.ts +2 -1
- package/build/types/api/index.d.ts +1 -0
- package/build/types/api/probe.d.ts +19 -0
- package/build/types/pool/PoolClient.d.ts +45 -1
- package/build/types/pool/PoolLog.d.ts +11 -0
- package/build/types/sor/TradeScheduler.d.ts +1 -1
- package/build/types/utils/async.d.ts +1 -0
- package/build/types/utils/calc.d.ts +38 -0
- package/build/types/utils/index.d.ts +2 -0
- package/build/types/utils/math.d.ts +0 -9
- package/package.json +3 -3
- package/build/types/api/utils.d.ts +0 -1
- package/build/types/sor/TradeRouter.utils.d.ts +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class ChainWatcher {
|
|
4
|
+
private static instance;
|
|
5
|
+
readonly bestBlock$: Observable<any>;
|
|
6
|
+
readonly finalizedBlock$: Observable<import("polkadot-api").BlockInfo>;
|
|
7
|
+
readonly connection$: Observable<"online" | "offline">;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(client: PolkadotClient): ChainWatcher;
|
|
10
|
+
private watched;
|
|
11
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PolkadotClient, TypedApi } from 'polkadot-api';
|
|
2
2
|
import { hydration } from '@galacticcouncil/descriptors';
|
|
3
|
+
import { ChainWatcher } from './ChainWatcher';
|
|
3
4
|
export declare abstract class Papi {
|
|
4
5
|
readonly client: PolkadotClient;
|
|
5
6
|
readonly api: TypedApi<typeof hydration>;
|
|
7
|
+
readonly watcher: ChainWatcher;
|
|
6
8
|
constructor(client: PolkadotClient);
|
|
7
|
-
protected log(message?: any, ...optionalParams: any[]): void;
|
|
8
9
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
type ConnState = 'online' | 'offline';
|
|
4
|
+
type Opts = {
|
|
5
|
+
intervalMs?: number;
|
|
6
|
+
rpcTimeoutMs?: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Periodically probes the node and exposes a derived
|
|
10
|
+
* online/offline state.
|
|
11
|
+
*
|
|
12
|
+
* @param client - polkadot client
|
|
13
|
+
* @param opts.intervalMs - probe interval
|
|
14
|
+
* @param opts.rpcTimeoutMs - rpc timeout
|
|
15
|
+
*
|
|
16
|
+
* @returns observable emitting connection state
|
|
17
|
+
*/
|
|
18
|
+
export declare function connectionProbe$(client: PolkadotClient, { intervalMs, rpcTimeoutMs }?: Opts): Observable<ConnState>;
|
|
19
|
+
export {};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { PolkadotClient } from 'polkadot-api';
|
|
2
|
-
import { Observable, Subscription } from 'rxjs';
|
|
2
|
+
import { Observable, OperatorFunction, Subscription } from 'rxjs';
|
|
3
3
|
import { BalanceClient } from '../client';
|
|
4
4
|
import { EvmClient } from '../evm';
|
|
5
5
|
import { PoolBase, PoolFees, PoolPair, PoolType } from './types';
|
|
6
6
|
import { PoolStore } from './PoolStore';
|
|
7
|
+
import { PoolLog } from './PoolLog';
|
|
7
8
|
export declare abstract class PoolClient<T extends PoolBase> extends BalanceClient {
|
|
8
9
|
protected evm: EvmClient;
|
|
9
10
|
protected store: PoolStore<T>;
|
|
11
|
+
protected log: PoolLog;
|
|
10
12
|
private shared$?;
|
|
13
|
+
private resync$;
|
|
14
|
+
private resyncAt;
|
|
15
|
+
private resyncPending;
|
|
11
16
|
private mem;
|
|
12
17
|
private memPoolsCache;
|
|
13
18
|
private memPools;
|
|
@@ -26,4 +31,43 @@ export declare abstract class PoolClient<T extends PoolBase> extends BalanceClie
|
|
|
26
31
|
protected hasErc20Asset(pool: PoolBase): boolean;
|
|
27
32
|
private hasValidAssets;
|
|
28
33
|
private updateBalances;
|
|
34
|
+
/**
|
|
35
|
+
* Invalidates the current seed, tears down all active writers,
|
|
36
|
+
* and rebuilds the store from scratch.
|
|
37
|
+
*
|
|
38
|
+
* - Increments `mem` to bust memoized seeds
|
|
39
|
+
* - Emits on `resync$` to restart the active cycle
|
|
40
|
+
* - Rate-limited by default to avoid resync storms
|
|
41
|
+
* - Use `force` for fatal, state-corrupting errors
|
|
42
|
+
*
|
|
43
|
+
* @param force - bypass the resync throttle
|
|
44
|
+
*/
|
|
45
|
+
private resync;
|
|
46
|
+
/**
|
|
47
|
+
* Schedules a resync on the next tick.
|
|
48
|
+
*
|
|
49
|
+
* - Ensures the current cycle tears down before resync
|
|
50
|
+
* - Dedup multiple requests occurring in the same tick
|
|
51
|
+
*
|
|
52
|
+
* @param force - forward the force flag to `resync`
|
|
53
|
+
*/
|
|
54
|
+
private requestResync;
|
|
55
|
+
/**
|
|
56
|
+
* Starts the connection and block watchdog.
|
|
57
|
+
*
|
|
58
|
+
* - Triggers a resync on offline → online recovery
|
|
59
|
+
* - Triggers a resync on block gap
|
|
60
|
+
* - Errors are swallowed and the watchdog re-subscribes (`repeat`)
|
|
61
|
+
*/
|
|
62
|
+
private startWatchdog;
|
|
63
|
+
/**
|
|
64
|
+
* Guards a watcher stream.
|
|
65
|
+
*
|
|
66
|
+
* - Logs any error and treats it as fatal
|
|
67
|
+
* - Schedules a forced resync
|
|
68
|
+
* - Outer re-sync cycle handles recovery
|
|
69
|
+
*
|
|
70
|
+
* @param tag - log prefix of the watcher
|
|
71
|
+
*/
|
|
72
|
+
protected watchGuard<T>(tag: string): OperatorFunction<T, T>;
|
|
29
73
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PoolType } from './types';
|
|
2
|
+
export declare class PoolLog {
|
|
3
|
+
private readonly type;
|
|
4
|
+
constructor(type: PoolType);
|
|
5
|
+
private prefix;
|
|
6
|
+
trace(label: string, ...args: any[]): void;
|
|
7
|
+
debug(label: string, ...args: any[]): void;
|
|
8
|
+
info(label: string, ...args: any[]): void;
|
|
9
|
+
error(label: string, ...args: any[]): void;
|
|
10
|
+
private pad;
|
|
11
|
+
}
|
|
@@ -28,7 +28,7 @@ export declare class TradeScheduler {
|
|
|
28
28
|
* @param asset - assetIn id
|
|
29
29
|
* @returns minimum order budget
|
|
30
30
|
*/
|
|
31
|
-
getMinimumOrderBudget(asset: number): Promise<bigint>;
|
|
31
|
+
getMinimumOrderBudget(asset: number, decimals: number): Promise<bigint>;
|
|
32
32
|
/**
|
|
33
33
|
* Calculate maximum number of trades for dca order execution.
|
|
34
34
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withTimeout<T>(p: Promise<T>, ms: number, label?: string): Promise<T>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multiply two fixed-point bigint values and rescale the result
|
|
3
|
+
* to the desired target decimals.
|
|
4
|
+
*
|
|
5
|
+
* This helper is fully generic and supports both scaling down
|
|
6
|
+
* (division) and scaling up (adding trailing zeroes).
|
|
7
|
+
*
|
|
8
|
+
* @param value - base value (native bigint)
|
|
9
|
+
* @param multiplier - multiplier value (native bigint)
|
|
10
|
+
* @param valueDecimals - decimals of the base value
|
|
11
|
+
* @param multiplierDecimals - decimals of the multiplier
|
|
12
|
+
* @param targetDecimals - desired decimals of the result
|
|
13
|
+
* @returns scaled multiplication result
|
|
14
|
+
*/
|
|
15
|
+
export declare function mulScaled(value: bigint, multiplier: bigint, valueDecimals: number, multiplierDecimals: number, targetDecimals: number): bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Multiply a value by a spot price and rescale the result
|
|
18
|
+
* to the desired target decimals.
|
|
19
|
+
*
|
|
20
|
+
* Spot price is assumed to be scaled by `RUNTIME_DECIMALS`
|
|
21
|
+
* (currently 18).
|
|
22
|
+
*
|
|
23
|
+
* @param value - base value (native bigint)
|
|
24
|
+
* @param spot - spot price (scaled by RUNTIME_DECIMALS)
|
|
25
|
+
* @param valueDecimals - decimals of the base value
|
|
26
|
+
* @param targetDecimals - desired decimals of the result
|
|
27
|
+
* @returns scaled spot multiplication result
|
|
28
|
+
*/
|
|
29
|
+
export declare function mulSpot(value: bigint, spot: bigint, valueDecimals: number, targetDecimals: number): bigint;
|
|
30
|
+
/**
|
|
31
|
+
* Get % fraction from native value
|
|
32
|
+
*
|
|
33
|
+
* @param value - native amount
|
|
34
|
+
* @param pct - percentage value (e.g. 0.5 = 0.5%)
|
|
35
|
+
* @param dp - safe decimals margin (2dp = 0.01%)
|
|
36
|
+
* @returns fraction of given amount
|
|
37
|
+
*/
|
|
38
|
+
export declare function getFraction(value: bigint, pct: number, dp?: number): bigint;
|
|
@@ -51,12 +51,3 @@ export declare function calculateSellFee(delta0Y: bigint, deltaY: bigint): numbe
|
|
|
51
51
|
* @param deltaX - the amount in, inclusive of fees
|
|
52
52
|
*/
|
|
53
53
|
export declare function calculateBuyFee(delta0X: bigint, deltaX: bigint): number;
|
|
54
|
-
/**
|
|
55
|
-
* Get % fraction from native value
|
|
56
|
-
*
|
|
57
|
-
* @param value - native amount
|
|
58
|
-
* @param pct - percentage value
|
|
59
|
-
* @param dp - safe decimals margin (2dp = 0.01%)
|
|
60
|
-
* @returns fraction of given amount
|
|
61
|
-
*/
|
|
62
|
-
export declare function getFraction(value: bigint, pct: number, dp?: number): bigint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galacticcouncil/sdk-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Galactic next gen sdk (papi)",
|
|
5
5
|
"author": "GalacticCouncil",
|
|
6
6
|
"repository": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"big.js": "^6.2.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@galacticcouncil/common": ">=0.
|
|
51
|
+
"@galacticcouncil/common": ">=0.3.0 <1.0.0",
|
|
52
52
|
"@galacticcouncil/descriptors": ">=1.7.0 <2.0.0",
|
|
53
|
-
"polkadot-api": "^1.23.
|
|
53
|
+
"polkadot-api": "^1.23.2",
|
|
54
54
|
"viem": "^2.38.3"
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getLogValue(value: any): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function calculateSwapAmount(amountIn: bigint, spot: bigint, decimalsIn: number, decimalsOut: number): bigint;
|