@galacticcouncil/sdk-next 1.0.0-beta.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.
Files changed (54) hide show
  1. package/README.md +141 -0
  2. package/build/index.cjs +1 -0
  3. package/build/index.mjs +1 -0
  4. package/build/types/api/Papi.d.ts +375 -0
  5. package/build/types/api/client.d.ts +2 -0
  6. package/build/types/api/index.d.ts +2 -0
  7. package/build/types/client/AssetClient.d.ts +24 -0
  8. package/build/types/client/BalanceClient.d.ts +17 -0
  9. package/build/types/client/index.d.ts +2 -0
  10. package/build/types/consts.d.ts +8 -0
  11. package/build/types/errors.d.ts +10 -0
  12. package/build/types/index.d.ts +8 -0
  13. package/build/types/pool/PoolClient.d.ts +25 -0
  14. package/build/types/pool/PoolContextProvider.d.ts +26 -0
  15. package/build/types/pool/PoolFactory.d.ts +4 -0
  16. package/build/types/pool/index.d.ts +7 -0
  17. package/build/types/pool/lbp/LbpMath.d.ts +7 -0
  18. package/build/types/pool/lbp/LbpPool.d.ts +49 -0
  19. package/build/types/pool/lbp/LbpPoolClient.d.ts +18 -0
  20. package/build/types/pool/lbp/index.d.ts +3 -0
  21. package/build/types/pool/omni/OmniMath.d.ts +19 -0
  22. package/build/types/pool/omni/OmniPool.d.ts +45 -0
  23. package/build/types/pool/omni/OmniPoolClient.d.ts +13 -0
  24. package/build/types/pool/omni/index.d.ts +3 -0
  25. package/build/types/pool/stable/StableMath.d.ts +14 -0
  26. package/build/types/pool/stable/StableSwap.d.ts +46 -0
  27. package/build/types/pool/stable/StableSwapClient.d.ts +16 -0
  28. package/build/types/pool/stable/index.d.ts +3 -0
  29. package/build/types/pool/types.d.ts +84 -0
  30. package/build/types/pool/xyk/XykMath.d.ts +12 -0
  31. package/build/types/pool/xyk/XykPool.d.ts +23 -0
  32. package/build/types/pool/xyk/XykPoolClient.d.ts +12 -0
  33. package/build/types/pool/xyk/index.d.ts +3 -0
  34. package/build/types/sor/Router.d.ts +66 -0
  35. package/build/types/sor/TradeRouter.d.ts +155 -0
  36. package/build/types/sor/TradeUtils.d.ts +12 -0
  37. package/build/types/sor/index.d.ts +4 -0
  38. package/build/types/sor/route/bfs.d.ts +37 -0
  39. package/build/types/sor/route/graph.d.ts +12 -0
  40. package/build/types/sor/route/index.d.ts +3 -0
  41. package/build/types/sor/route/suggester.d.ts +24 -0
  42. package/build/types/sor/types.d.ts +31 -0
  43. package/build/types/types.d.ts +40 -0
  44. package/build/types/utils/Queue.d.ts +13 -0
  45. package/build/types/utils/Stack.d.ts +15 -0
  46. package/build/types/utils/big.d.ts +3 -0
  47. package/build/types/utils/evm.d.ts +3 -0
  48. package/build/types/utils/format.d.ts +4 -0
  49. package/build/types/utils/index.d.ts +6 -0
  50. package/build/types/utils/json.d.ts +3 -0
  51. package/build/types/utils/math.d.ts +62 -0
  52. package/build/types/utils/traversal/bfs.d.ts +27 -0
  53. package/build/types/utils/xc.d.ts +1 -0
  54. package/package.json +53 -0
@@ -0,0 +1,40 @@
1
+ import { XcmV3Junctions } from '@galacticcouncil/descriptors';
2
+ export type Amount = {
3
+ amount: bigint;
4
+ decimals: number;
5
+ };
6
+ export interface AssetAmount {
7
+ id: number;
8
+ amount: bigint;
9
+ }
10
+ export interface AssetMetadata {
11
+ decimals: number;
12
+ symbol: string;
13
+ }
14
+ export type AssetType = 'StableSwap' | 'Bond' | 'Token' | 'External' | 'Erc20';
15
+ export interface Asset extends AssetMetadata {
16
+ id: number;
17
+ name: string;
18
+ icon: string;
19
+ type: AssetType;
20
+ existentialDeposit: bigint;
21
+ isSufficient: boolean;
22
+ location?: XcmV3Multilocation;
23
+ meta?: Record<string, string>;
24
+ isWhiteListed?: boolean;
25
+ }
26
+ export interface Bond extends Asset {
27
+ underlyingAssetId: number;
28
+ maturity: number;
29
+ }
30
+ export interface ExternalAsset extends AssetMetadata {
31
+ id: string;
32
+ origin: number;
33
+ name: string;
34
+ internalId: number;
35
+ isWhiteListed?: boolean;
36
+ }
37
+ export type XcmV3Multilocation = {
38
+ parents: number;
39
+ interior: XcmV3Junctions;
40
+ };
@@ -0,0 +1,13 @@
1
+ export interface IQueue<T> {
2
+ enqueue(item: T): void;
3
+ dequeue(): T | undefined;
4
+ size(): number;
5
+ }
6
+ export declare class Queue<T> implements IQueue<T> {
7
+ private capacity;
8
+ private storage;
9
+ constructor(capacity?: number);
10
+ enqueue(item: T): void;
11
+ dequeue(): T | undefined;
12
+ size(): number;
13
+ }
@@ -0,0 +1,15 @@
1
+ export interface IStack<T> {
2
+ push(item: T): void;
3
+ pop(): T | undefined;
4
+ peek(): T | undefined;
5
+ size(): number;
6
+ }
7
+ export declare class Stack<T> implements IStack<T> {
8
+ private capacity;
9
+ private storage;
10
+ constructor(capacity?: number);
11
+ push(item: T): void;
12
+ pop(): T | undefined;
13
+ peek(): T | undefined;
14
+ size(): number;
15
+ }
@@ -0,0 +1,3 @@
1
+ import { RoundingMode } from 'big.js';
2
+ export declare function toDecimal(amount: bigint, decimals: number, maxDecimal?: number, roundType?: RoundingMode): string;
3
+ export declare function toBigInt(amount: string | number, decimals: number): bigint;
@@ -0,0 +1,3 @@
1
+ export declare function convertFromH160(h160addr: string, ss58prefix?: number): string;
2
+ export declare function convertToH160(ss58addr: string): string;
3
+ export declare function isEvmAccount(ss58addr: string): boolean;
@@ -0,0 +1,4 @@
1
+ import { PoolFee } from '../pool';
2
+ export declare function toPct(fee: PoolFee): number;
3
+ export declare function toDecimals(fee: PoolFee): number;
4
+ export declare function fromPermill(permill: number): PoolFee;
@@ -0,0 +1,6 @@
1
+ export * as big from './big';
2
+ export * as evm from './evm';
3
+ export * as fmt from './format';
4
+ export * as json from './json';
5
+ export * as math from './math';
6
+ export * as xc from './xc';
@@ -0,0 +1,3 @@
1
+ export declare const findNestedKey: (obj: any, keyToFind: any) => any;
2
+ export declare const findNestedObj: (obj: any, keyToFind: any, valToFind: any) => any;
3
+ export declare const jsonFormatter: (_: any, nestedValue: any) => any;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Percentage Difference Formula
3
+ *
4
+ * (|๐‘‰1โˆ’๐‘‰2| / [(๐‘‰1+๐‘‰2)/2]) ร— 100
5
+ *
6
+ * This formula calculates the percentage difference by comparing
7
+ * the absolute difference between the two values with their <b>average</b>.
8
+ *
9
+ * Usage: It's used when you want to find the percentage difference between
10
+ * two quantities where both quantities are significant.
11
+ *
12
+ * @param v1 - 1st value
13
+ * @param v2 - 2nd value
14
+ * @returns Difference between two values in relation to their average
15
+ */
16
+ export declare function calculateDiffToAvg(v1: bigint, v2: bigint): number;
17
+ /**
18
+ * Percentage Difference Formula (Relative Change)
19
+ *
20
+ * ((Vfin-Vref) / Vref) * 100
21
+ *
22
+ * This formula calculates the percentage difference by comparing
23
+ * the absolute difference between the two values with the <b>reference value</b>.
24
+ *
25
+ * Usage: This formula isn't suitable for finding percentage differences
26
+ * when the values being compared are not reference and final values of the
27
+ * same quantity.
28
+ *
29
+ * @param vFin - final value
30
+ * @param vRef - reference value
31
+ * @returns Difference between a final value and a reference value in relation to the reference value
32
+ */
33
+ export declare function calculateDiffToRef(vFin: bigint, vRef: bigint): number;
34
+ /**
35
+ * The total fee paid for a โ€˜sellโ€™ transaction
36
+ * Suppose the trader is selling X for Y
37
+ *
38
+ * fee = 1 - (deltaY / delta0Y)
39
+ *
40
+ * @param delta0Y - the amount out if fees are zero
41
+ * @param deltaY - the amount out if the existing nonzero fees are included in the calculation
42
+ */
43
+ export declare function calculateSellFee(delta0Y: bigint, deltaY: bigint): number;
44
+ /**
45
+ * The total fee paid for a โ€˜buyโ€˜ transaction
46
+ * Suppose the trader is buying Y using X
47
+ *
48
+ * fee = (deltaX / delta0X) - 1
49
+ *
50
+ * @param delta0X - the amount in if fees are zero
51
+ * @param deltaX - the amount in, inclusive of fees
52
+ */
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;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Breadth First Search.
3
+ *
4
+ * - uses Queue to find the shortest path
5
+ * - slower than DFS (Depth First Search)
6
+ * - better when dst is closer to src
7
+ * - complexity O(N+E) where N are nodes and E are edges
8
+ */
9
+ export declare class Bfs {
10
+ /**
11
+ * Check if current node is already present in path
12
+ *
13
+ * @param x - current node
14
+ * @param path - path
15
+ * @returns true if node in path, otherwise false
16
+ */
17
+ isNotVisited(x: number, path: number[]): boolean;
18
+ /**
19
+ * Finding paths in graph from given source to destination
20
+ *
21
+ * @param g - routes graph containing nodes & corresponding edges
22
+ * @param src - source node
23
+ * @param dst - destination node
24
+ * @returns paths
25
+ */
26
+ findPaths(g: number[][], src: number, dst: number): number[][];
27
+ }
@@ -0,0 +1 @@
1
+ export declare function convertToId(xcAddress: string): number;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@galacticcouncil/sdk-next",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Galactic next gen sdk (papi)",
5
+ "author": "GalacticCouncil",
6
+ "repository": {
7
+ "directory": "packages/sdk-next",
8
+ "type": "git",
9
+ "url": "git+https://github.com/galacticcouncil/sdk.git"
10
+ },
11
+ "keywords": [
12
+ "hydration",
13
+ "basilisk",
14
+ "sdk",
15
+ "definitions",
16
+ "types"
17
+ ],
18
+ "bugs": {
19
+ "url": "https://github.com/galacticcouncil/sdk/issues"
20
+ },
21
+ "files": [
22
+ "build"
23
+ ],
24
+ "main": "./build/index.cjs",
25
+ "module": "./build/index.mjs",
26
+ "types": "./build/types/index.d.ts",
27
+ "scripts": {
28
+ "build": "npm run clean && node ./esbuild.dist.mjs",
29
+ "build:watch": "node ./esbuild.dev.mjs",
30
+ "postbuild": "tsc --emitDeclarationOnly --outDir build/types/",
31
+ "clean": "rimraf build",
32
+ "link": "npm ln",
33
+ "test": "NODE_NO_WARNINGS=1 jest"
34
+ },
35
+ "devDependencies": {
36
+ "@types/big.js": "^6.2.2"
37
+ },
38
+ "dependencies": {
39
+ "@galacticcouncil/descriptors": "^1.1.0",
40
+ "@galacticcouncil/math-lbp": "^1.0.0",
41
+ "@galacticcouncil/math-liquidity-mining": "^1.0.0",
42
+ "@galacticcouncil/math-omnipool": "^1.1.0",
43
+ "@galacticcouncil/math-stableswap": "^2.0.0",
44
+ "@galacticcouncil/math-xyk": "^1.0.0",
45
+ "@noble/hashes": "^1.6.1",
46
+ "@thi.ng/cache": "^2.1.35",
47
+ "@thi.ng/memoize": "^4.0.2",
48
+ "big.js": "^6.2.1"
49
+ },
50
+ "peerDependencies": {
51
+ "polkadot-api": "^1.10.0"
52
+ }
53
+ }