@atomiqlabs/sdk 1.3.19 → 2.1.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/LICENSE +201 -201
- package/README.md +545 -501
- package/dist/SmartChainAssets.d.ts +73 -59
- package/dist/SmartChainAssets.js +75 -55
- package/dist/SwapperFactory.d.ts +49 -0
- package/dist/SwapperFactory.js +84 -0
- package/dist/Utils.d.ts +11 -0
- package/dist/Utils.js +37 -0
- package/dist/fs-storage/FileSystemStorageManager.d.ts +15 -0
- package/dist/fs-storage/FileSystemStorageManager.js +60 -0
- package/dist/fs-storage/index.d.ts +1 -0
- package/dist/fs-storage/index.js +17 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +21 -20
- package/dist/storage/LocalStorageManager.d.ts +24 -0
- package/dist/storage/LocalStorageManager.js +68 -0
- package/package.json +31 -32
- package/src/SmartChainAssets.js +75 -0
- package/src/SmartChainAssets.ts +76 -62
- package/src/SwapperFactory.js +96 -0
- package/src/SwapperFactory.ts +171 -0
- package/src/Utils.js +37 -0
- package/src/Utils.ts +31 -0
- package/src/example/BrowserExample.js +199 -0
- package/src/example/BrowserExample.ts +141 -120
- package/src/example/NodeJSExample.js +206 -0
- package/src/example/NodeJSExample.ts +150 -120
- package/src/fs-storage/FileSystemStorageManager.ts +71 -0
- package/src/fs-storage/index.ts +1 -0
- package/src/index.js +21 -0
- package/src/index.ts +5 -4
- package/src/storage/LocalStorageManager.js +72 -0
- package/src/storage/LocalStorageManager.ts +81 -0
- package/dist/MultichainSwapper.d.ts +0 -46
- package/dist/MultichainSwapper.js +0 -83
- package/dist/chains/ChainInitializer.d.ts +0 -13
- package/dist/chains/ChainInitializer.js +0 -2
- package/dist/chains/solana/SolanaChainInitializer.d.ts +0 -41
- package/dist/chains/solana/SolanaChainInitializer.js +0 -60
- package/dist/chains/solana/SolanaChains.d.ts +0 -14
- package/dist/chains/solana/SolanaChains.js +0 -18
- package/dist/example/BrowserExample.d.ts +0 -1
- package/dist/example/BrowserExample.js +0 -104
- package/dist/example/NodeJSExample.d.ts +0 -1
- package/dist/example/NodeJSExample.js +0 -104
- package/src/MultichainSwapper.ts +0 -156
- package/src/chains/ChainInitializer.ts +0 -16
- package/src/chains/solana/SolanaChainInitializer.ts +0 -99
- package/src/chains/solana/SolanaChains.ts +0 -16
|
@@ -1,59 +1,73 @@
|
|
|
1
|
-
export declare const SmartChainAssets: {
|
|
2
|
-
readonly WBTC: {
|
|
3
|
-
readonly pricing: {
|
|
4
|
-
readonly binancePair: "WBTCBTC";
|
|
5
|
-
readonly okxPair: any;
|
|
6
|
-
readonly coinGeckoCoinId: "wrapped-bitcoin";
|
|
7
|
-
readonly coinPaprikaCoinId: "wbtc-wrapped-bitcoin";
|
|
8
|
-
readonly krakenPair: "WBTCXBT";
|
|
9
|
-
};
|
|
10
|
-
readonly name: "Wrapped BTC (Wormhole)";
|
|
11
|
-
};
|
|
12
|
-
readonly USDC: {
|
|
13
|
-
readonly pricing: {
|
|
14
|
-
readonly binancePair: "!BTCUSDC";
|
|
15
|
-
readonly okxPair: "!BTC-USDC";
|
|
16
|
-
readonly coinGeckoCoinId: "usd-coin";
|
|
17
|
-
readonly coinPaprikaCoinId: "usdc-usd-coin";
|
|
18
|
-
readonly krakenPair: "!XBTUSDC";
|
|
19
|
-
};
|
|
20
|
-
readonly name: "USD Circle";
|
|
21
|
-
};
|
|
22
|
-
readonly USDT: {
|
|
23
|
-
readonly pricing: {
|
|
24
|
-
readonly binancePair: "!BTCUSDT";
|
|
25
|
-
readonly okxPair: "!BTC-USDT";
|
|
26
|
-
readonly coinGeckoCoinId: "tether";
|
|
27
|
-
readonly coinPaprikaCoinId: "usdt-tether";
|
|
28
|
-
readonly krakenPair: "!XBTUSDT";
|
|
29
|
-
};
|
|
30
|
-
readonly name: "Tether USD";
|
|
31
|
-
};
|
|
32
|
-
readonly SOL: {
|
|
33
|
-
readonly pricing: {
|
|
34
|
-
readonly binancePair: "SOLBTC";
|
|
35
|
-
readonly okxPair: "SOL-BTC";
|
|
36
|
-
readonly coinGeckoCoinId: "solana";
|
|
37
|
-
readonly coinPaprikaCoinId: "sol-solana";
|
|
38
|
-
readonly krakenPair: "SOLXBT";
|
|
39
|
-
};
|
|
40
|
-
readonly name: "Solana";
|
|
41
|
-
};
|
|
42
|
-
readonly BONK: {
|
|
43
|
-
readonly pricing: {
|
|
44
|
-
readonly binancePair: "BONKUSDC;!BTCUSDC";
|
|
45
|
-
readonly okxPair: "BONK-USDT;!BTC-USDT";
|
|
46
|
-
readonly coinGeckoCoinId: "bonk";
|
|
47
|
-
readonly coinPaprikaCoinId: "bonk-bonk";
|
|
48
|
-
readonly krakenPair: "BONKUSD;!XXBTZUSD";
|
|
49
|
-
};
|
|
50
|
-
readonly name: "Bonk";
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
1
|
+
export declare const SmartChainAssets: {
|
|
2
|
+
readonly WBTC: {
|
|
3
|
+
readonly pricing: {
|
|
4
|
+
readonly binancePair: "WBTCBTC";
|
|
5
|
+
readonly okxPair: any;
|
|
6
|
+
readonly coinGeckoCoinId: "wrapped-bitcoin";
|
|
7
|
+
readonly coinPaprikaCoinId: "wbtc-wrapped-bitcoin";
|
|
8
|
+
readonly krakenPair: "WBTCXBT";
|
|
9
|
+
};
|
|
10
|
+
readonly name: "Wrapped BTC (Wormhole)";
|
|
11
|
+
};
|
|
12
|
+
readonly USDC: {
|
|
13
|
+
readonly pricing: {
|
|
14
|
+
readonly binancePair: "!BTCUSDC";
|
|
15
|
+
readonly okxPair: "!BTC-USDC";
|
|
16
|
+
readonly coinGeckoCoinId: "usd-coin";
|
|
17
|
+
readonly coinPaprikaCoinId: "usdc-usd-coin";
|
|
18
|
+
readonly krakenPair: "!XBTUSDC";
|
|
19
|
+
};
|
|
20
|
+
readonly name: "USD Circle";
|
|
21
|
+
};
|
|
22
|
+
readonly USDT: {
|
|
23
|
+
readonly pricing: {
|
|
24
|
+
readonly binancePair: "!BTCUSDT";
|
|
25
|
+
readonly okxPair: "!BTC-USDT";
|
|
26
|
+
readonly coinGeckoCoinId: "tether";
|
|
27
|
+
readonly coinPaprikaCoinId: "usdt-tether";
|
|
28
|
+
readonly krakenPair: "!XBTUSDT";
|
|
29
|
+
};
|
|
30
|
+
readonly name: "Tether USD";
|
|
31
|
+
};
|
|
32
|
+
readonly SOL: {
|
|
33
|
+
readonly pricing: {
|
|
34
|
+
readonly binancePair: "SOLBTC";
|
|
35
|
+
readonly okxPair: "SOL-BTC";
|
|
36
|
+
readonly coinGeckoCoinId: "solana";
|
|
37
|
+
readonly coinPaprikaCoinId: "sol-solana";
|
|
38
|
+
readonly krakenPair: "SOLXBT";
|
|
39
|
+
};
|
|
40
|
+
readonly name: "Solana";
|
|
41
|
+
};
|
|
42
|
+
readonly BONK: {
|
|
43
|
+
readonly pricing: {
|
|
44
|
+
readonly binancePair: "BONKUSDC;!BTCUSDC";
|
|
45
|
+
readonly okxPair: "BONK-USDT;!BTC-USDT";
|
|
46
|
+
readonly coinGeckoCoinId: "bonk";
|
|
47
|
+
readonly coinPaprikaCoinId: "bonk-bonk";
|
|
48
|
+
readonly krakenPair: "BONKUSD;!XXBTZUSD";
|
|
49
|
+
};
|
|
50
|
+
readonly name: "Bonk";
|
|
51
|
+
};
|
|
52
|
+
readonly ETH: {
|
|
53
|
+
readonly pricing: {
|
|
54
|
+
readonly binancePair: "ETHBTC";
|
|
55
|
+
readonly okxPair: "ETH-BTC";
|
|
56
|
+
readonly coinGeckoCoinId: "ethereum";
|
|
57
|
+
readonly coinPaprikaCoinId: "eth-ethereum";
|
|
58
|
+
readonly krakenPair: "XETHXXBT";
|
|
59
|
+
};
|
|
60
|
+
readonly name: "Ethereum";
|
|
61
|
+
};
|
|
62
|
+
readonly STRK: {
|
|
63
|
+
readonly pricing: {
|
|
64
|
+
readonly binancePair: "STRKUSDT;!BTCUSDT";
|
|
65
|
+
readonly okxPair: "STRK-USDT;!BTC-USDT";
|
|
66
|
+
readonly coinGeckoCoinId: "starknet";
|
|
67
|
+
readonly coinPaprikaCoinId: "strk-starknet";
|
|
68
|
+
readonly krakenPair: "STRKUSD;!XXBTZUSD";
|
|
69
|
+
};
|
|
70
|
+
readonly name: "Starknet";
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export type SmartChainAssetTickers = keyof typeof SmartChainAssets;
|
package/dist/SmartChainAssets.js
CHANGED
|
@@ -1,55 +1,75 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SmartChainAssets = void 0;
|
|
4
|
-
exports.SmartChainAssets = {
|
|
5
|
-
WBTC: {
|
|
6
|
-
pricing: {
|
|
7
|
-
binancePair: "WBTCBTC",
|
|
8
|
-
okxPair: null,
|
|
9
|
-
coinGeckoCoinId: "wrapped-bitcoin",
|
|
10
|
-
coinPaprikaCoinId: "wbtc-wrapped-bitcoin",
|
|
11
|
-
krakenPair: "WBTCXBT"
|
|
12
|
-
},
|
|
13
|
-
name: "Wrapped BTC (Wormhole)"
|
|
14
|
-
},
|
|
15
|
-
USDC: {
|
|
16
|
-
pricing: {
|
|
17
|
-
binancePair: "!BTCUSDC",
|
|
18
|
-
okxPair: "!BTC-USDC",
|
|
19
|
-
coinGeckoCoinId: "usd-coin",
|
|
20
|
-
coinPaprikaCoinId: "usdc-usd-coin",
|
|
21
|
-
krakenPair: "!XBTUSDC"
|
|
22
|
-
},
|
|
23
|
-
name: "USD Circle"
|
|
24
|
-
},
|
|
25
|
-
USDT: {
|
|
26
|
-
pricing: {
|
|
27
|
-
binancePair: "!BTCUSDT",
|
|
28
|
-
okxPair: "!BTC-USDT",
|
|
29
|
-
coinGeckoCoinId: "tether",
|
|
30
|
-
coinPaprikaCoinId: "usdt-tether",
|
|
31
|
-
krakenPair: "!XBTUSDT"
|
|
32
|
-
},
|
|
33
|
-
name: "Tether USD"
|
|
34
|
-
},
|
|
35
|
-
SOL: {
|
|
36
|
-
pricing: {
|
|
37
|
-
binancePair: "SOLBTC",
|
|
38
|
-
okxPair: "SOL-BTC",
|
|
39
|
-
coinGeckoCoinId: "solana",
|
|
40
|
-
coinPaprikaCoinId: "sol-solana",
|
|
41
|
-
krakenPair: "SOLXBT"
|
|
42
|
-
},
|
|
43
|
-
name: "Solana"
|
|
44
|
-
},
|
|
45
|
-
BONK: {
|
|
46
|
-
pricing: {
|
|
47
|
-
binancePair: "BONKUSDC;!BTCUSDC",
|
|
48
|
-
okxPair: "BONK-USDT;!BTC-USDT",
|
|
49
|
-
coinGeckoCoinId: "bonk",
|
|
50
|
-
coinPaprikaCoinId: "bonk-bonk",
|
|
51
|
-
krakenPair: "BONKUSD;!XXBTZUSD"
|
|
52
|
-
},
|
|
53
|
-
name: "Bonk"
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmartChainAssets = void 0;
|
|
4
|
+
exports.SmartChainAssets = {
|
|
5
|
+
WBTC: {
|
|
6
|
+
pricing: {
|
|
7
|
+
binancePair: "WBTCBTC",
|
|
8
|
+
okxPair: null,
|
|
9
|
+
coinGeckoCoinId: "wrapped-bitcoin",
|
|
10
|
+
coinPaprikaCoinId: "wbtc-wrapped-bitcoin",
|
|
11
|
+
krakenPair: "WBTCXBT"
|
|
12
|
+
},
|
|
13
|
+
name: "Wrapped BTC (Wormhole)"
|
|
14
|
+
},
|
|
15
|
+
USDC: {
|
|
16
|
+
pricing: {
|
|
17
|
+
binancePair: "!BTCUSDC",
|
|
18
|
+
okxPair: "!BTC-USDC",
|
|
19
|
+
coinGeckoCoinId: "usd-coin",
|
|
20
|
+
coinPaprikaCoinId: "usdc-usd-coin",
|
|
21
|
+
krakenPair: "!XBTUSDC"
|
|
22
|
+
},
|
|
23
|
+
name: "USD Circle"
|
|
24
|
+
},
|
|
25
|
+
USDT: {
|
|
26
|
+
pricing: {
|
|
27
|
+
binancePair: "!BTCUSDT",
|
|
28
|
+
okxPair: "!BTC-USDT",
|
|
29
|
+
coinGeckoCoinId: "tether",
|
|
30
|
+
coinPaprikaCoinId: "usdt-tether",
|
|
31
|
+
krakenPair: "!XBTUSDT"
|
|
32
|
+
},
|
|
33
|
+
name: "Tether USD"
|
|
34
|
+
},
|
|
35
|
+
SOL: {
|
|
36
|
+
pricing: {
|
|
37
|
+
binancePair: "SOLBTC",
|
|
38
|
+
okxPair: "SOL-BTC",
|
|
39
|
+
coinGeckoCoinId: "solana",
|
|
40
|
+
coinPaprikaCoinId: "sol-solana",
|
|
41
|
+
krakenPair: "SOLXBT"
|
|
42
|
+
},
|
|
43
|
+
name: "Solana"
|
|
44
|
+
},
|
|
45
|
+
BONK: {
|
|
46
|
+
pricing: {
|
|
47
|
+
binancePair: "BONKUSDC;!BTCUSDC",
|
|
48
|
+
okxPair: "BONK-USDT;!BTC-USDT",
|
|
49
|
+
coinGeckoCoinId: "bonk",
|
|
50
|
+
coinPaprikaCoinId: "bonk-bonk",
|
|
51
|
+
krakenPair: "BONKUSD;!XXBTZUSD"
|
|
52
|
+
},
|
|
53
|
+
name: "Bonk"
|
|
54
|
+
},
|
|
55
|
+
ETH: {
|
|
56
|
+
pricing: {
|
|
57
|
+
binancePair: "ETHBTC",
|
|
58
|
+
okxPair: "ETH-BTC",
|
|
59
|
+
coinGeckoCoinId: "ethereum",
|
|
60
|
+
coinPaprikaCoinId: "eth-ethereum",
|
|
61
|
+
krakenPair: "XETHXXBT"
|
|
62
|
+
},
|
|
63
|
+
name: "Ethereum"
|
|
64
|
+
},
|
|
65
|
+
STRK: {
|
|
66
|
+
pricing: {
|
|
67
|
+
binancePair: "STRKUSDT;!BTCUSDT",
|
|
68
|
+
okxPair: "STRK-USDT;!BTC-USDT",
|
|
69
|
+
coinGeckoCoinId: "starknet",
|
|
70
|
+
coinPaprikaCoinId: "strk-starknet",
|
|
71
|
+
krakenPair: "STRKUSD;!XXBTZUSD"
|
|
72
|
+
},
|
|
73
|
+
name: "Starknet"
|
|
74
|
+
}
|
|
75
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ChainData, BitcoinNetwork, BitcoinRpc, BaseTokenType, ChainType, StorageObject, IStorageManager } from "@atomiqlabs/base";
|
|
2
|
+
import { BtcToken, MempoolApi, SCToken, Swapper, SwapperOptions } from "@atomiqlabs/sdk-lib";
|
|
3
|
+
type ChainInitializer<O, C extends ChainType, T extends BaseTokenType> = {
|
|
4
|
+
chainId: ChainType["ChainId"];
|
|
5
|
+
chainType: ChainType;
|
|
6
|
+
initializer: (options: O, bitcoinRelay: BitcoinRpc<any>, network: BitcoinNetwork, storageCtor: <T extends StorageObject>(name: string) => IStorageManager<T>) => ChainData<C>;
|
|
7
|
+
tokens: T;
|
|
8
|
+
options: O;
|
|
9
|
+
};
|
|
10
|
+
type TokensDict<T extends ChainInitializer<any, any, any>> = {
|
|
11
|
+
[K in T["chainId"]]: {
|
|
12
|
+
[val in keyof T["tokens"]]: SCToken<K>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type GetAllTokens<T extends readonly ChainInitializer<any, any, any>[]> = (T extends readonly [infer First extends ChainInitializer<any, any, any>, ...infer Rest extends ChainInitializer<any, any, any>[]] ? TokensDict<First> & GetAllTokens<Rest> : unknown);
|
|
16
|
+
export type TokenResolverDict<T extends ChainInitializer<any, any, any>> = {
|
|
17
|
+
[K in T["chainId"]]: {
|
|
18
|
+
getToken: (address: string) => SCToken<K>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type GetAllTokenResolvers<T extends readonly ChainInitializer<any, any, any>[]> = (T extends readonly [infer First extends ChainInitializer<any, any, any>, ...infer Rest extends ChainInitializer<any, any, any>[]] ? TokenResolverDict<First> & GetAllTokenResolvers<Rest> : unknown);
|
|
22
|
+
type OptionsDict<T extends ChainInitializer<any, any, any>> = {
|
|
23
|
+
[K in T["chainId"]]: T["options"];
|
|
24
|
+
};
|
|
25
|
+
type GetAllOptions<T extends readonly ChainInitializer<any, any, any>[]> = (T extends readonly [infer First extends ChainInitializer<any, any, any>, ...infer Rest extends ChainInitializer<any, any, any>[]] ? OptionsDict<First> & GetAllOptions<Rest> : unknown);
|
|
26
|
+
type ChainTypeDict<T extends ChainInitializer<any, any, any>> = {
|
|
27
|
+
[K in T["chainId"]]: T["chainType"];
|
|
28
|
+
};
|
|
29
|
+
type ToMultichain<T extends readonly ChainInitializer<any, any, any>[]> = (T extends readonly [infer First extends ChainInitializer<any, any, any>, ...infer Rest extends ChainInitializer<any, any, any>[]] ? ChainTypeDict<First> & ToMultichain<Rest> : {});
|
|
30
|
+
export type MultichainSwapperOptions<T extends readonly ChainInitializer<any, any, any>[]> = SwapperOptions & {
|
|
31
|
+
chains: GetAllOptions<T>;
|
|
32
|
+
} & {
|
|
33
|
+
chainStorageCtor?: <T extends StorageObject>(name: string) => IStorageManager<T>;
|
|
34
|
+
pricingFeeDifferencePPM?: bigint;
|
|
35
|
+
mempoolApi?: MempoolApi;
|
|
36
|
+
};
|
|
37
|
+
export declare class SwapperFactory<T extends readonly ChainInitializer<any, any, any>[]> {
|
|
38
|
+
readonly initializers: T;
|
|
39
|
+
Tokens: GetAllTokens<T> & {
|
|
40
|
+
BITCOIN: {
|
|
41
|
+
BTC: BtcToken<false>;
|
|
42
|
+
BTCLN: BtcToken<true>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
TokenResolver: GetAllTokenResolvers<T>;
|
|
46
|
+
constructor(initializers: T);
|
|
47
|
+
newSwapper(options: MultichainSwapperOptions<T>): Swapper<ToMultichain<T>>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapperFactory = void 0;
|
|
4
|
+
const base_1 = require("@atomiqlabs/base");
|
|
5
|
+
const sdk_lib_1 = require("@atomiqlabs/sdk-lib");
|
|
6
|
+
const SmartChainAssets_1 = require("./SmartChainAssets");
|
|
7
|
+
const LocalStorageManager_1 = require("./storage/LocalStorageManager");
|
|
8
|
+
class SwapperFactory {
|
|
9
|
+
constructor(initializers) {
|
|
10
|
+
this.initializers = initializers;
|
|
11
|
+
this.Tokens = {
|
|
12
|
+
BITCOIN: sdk_lib_1.BitcoinTokens
|
|
13
|
+
};
|
|
14
|
+
this.TokenResolver = {};
|
|
15
|
+
this.initializers = initializers;
|
|
16
|
+
initializers.forEach(initializer => {
|
|
17
|
+
const addressMap = {};
|
|
18
|
+
this.Tokens[initializer.chainId] = {};
|
|
19
|
+
for (let ticker in initializer.tokens) {
|
|
20
|
+
const assetData = initializer.tokens[ticker];
|
|
21
|
+
this.Tokens[initializer.chainId][ticker] = addressMap[assetData.address] = {
|
|
22
|
+
chain: "SC",
|
|
23
|
+
chainId: initializer.chainId,
|
|
24
|
+
address: assetData.address,
|
|
25
|
+
name: SmartChainAssets_1.SmartChainAssets[ticker].name,
|
|
26
|
+
decimals: assetData.decimals,
|
|
27
|
+
displayDecimals: assetData.displayDecimals,
|
|
28
|
+
ticker
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
this.TokenResolver[initializer.chainId] = {
|
|
32
|
+
getToken: (address) => addressMap[address]
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
newSwapper(options) {
|
|
37
|
+
options.bitcoinNetwork ?? (options.bitcoinNetwork = base_1.BitcoinNetwork.MAINNET);
|
|
38
|
+
options.storagePrefix ?? (options.storagePrefix = "atomiqsdk-" + options.bitcoinNetwork + "-");
|
|
39
|
+
options.defaultTrustedIntermediaryUrl ?? (options.defaultTrustedIntermediaryUrl = options.bitcoinNetwork === base_1.BitcoinNetwork.MAINNET ?
|
|
40
|
+
"https://node3.gethopa.com:34100" :
|
|
41
|
+
"https://node3.gethopa.com:24100");
|
|
42
|
+
options.registryUrl ?? (options.registryUrl = options.bitcoinNetwork === base_1.BitcoinNetwork.MAINNET ?
|
|
43
|
+
"https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main" :
|
|
44
|
+
"https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main");
|
|
45
|
+
const mempoolApi = options.mempoolApi ?? new sdk_lib_1.MempoolApi(options.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET ?
|
|
46
|
+
[
|
|
47
|
+
"https://mempool.space/testnet/api/",
|
|
48
|
+
"https://mempool.fra.mempool.space/testnet/api/",
|
|
49
|
+
"https://mempool.va1.mempool.space/testnet/api/",
|
|
50
|
+
"https://mempool.tk7.mempool.space/testnet/api/"
|
|
51
|
+
] :
|
|
52
|
+
[
|
|
53
|
+
"https://mempool.space/api/",
|
|
54
|
+
"https://mempool.fra.mempool.space/api/",
|
|
55
|
+
"https://mempool.va1.mempool.space/api/",
|
|
56
|
+
"https://mempool.tk7.mempool.space/api/"
|
|
57
|
+
]);
|
|
58
|
+
const bitcoinRpc = new sdk_lib_1.MempoolBitcoinRpc(mempoolApi);
|
|
59
|
+
const pricingAssets = [];
|
|
60
|
+
Object.keys(SmartChainAssets_1.SmartChainAssets).forEach((ticker) => {
|
|
61
|
+
const chains = {};
|
|
62
|
+
for (let { tokens, chainId } of this.initializers) {
|
|
63
|
+
if (tokens[ticker] != null)
|
|
64
|
+
chains[chainId] = tokens[ticker];
|
|
65
|
+
}
|
|
66
|
+
const assetData = SmartChainAssets_1.SmartChainAssets[ticker];
|
|
67
|
+
pricingAssets.push({
|
|
68
|
+
...assetData.pricing,
|
|
69
|
+
chains,
|
|
70
|
+
ticker,
|
|
71
|
+
name: assetData.name
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
options.chainStorageCtor ?? (options.chainStorageCtor = (name) => new LocalStorageManager_1.LocalStorageManager(name));
|
|
75
|
+
const chains = {};
|
|
76
|
+
for (let { initializer, chainId } of this.initializers) {
|
|
77
|
+
if (options.chains[chainId] == null)
|
|
78
|
+
continue;
|
|
79
|
+
chains[chainId] = initializer(options.chains[chainId], bitcoinRpc, options.bitcoinNetwork, options.chainStorageCtor);
|
|
80
|
+
}
|
|
81
|
+
return new sdk_lib_1.Swapper(bitcoinRpc, chains, sdk_lib_1.RedundantSwapPrice.createFromTokenMap(options.pricingFeeDifferencePPM ?? 10000n, pricingAssets), pricingAssets, options);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SwapperFactory = SwapperFactory;
|
package/dist/Utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Token } from "@atomiqlabs/sdk-lib";
|
|
2
|
+
export declare function toHumanReadableString(amount: bigint, currencySpec: Token): string;
|
|
3
|
+
export declare function fromHumanReadableString(amount: string, currencySpec: Token): bigint;
|
|
4
|
+
/**
|
|
5
|
+
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
6
|
+
*
|
|
7
|
+
* @param timeout Milliseconds to wait
|
|
8
|
+
* @param abortReason Abort with this abort reason
|
|
9
|
+
* @param abortSignal Abort signal to extend
|
|
10
|
+
*/
|
|
11
|
+
export declare function timeoutSignal(timeout: number, abortReason?: any, abortSignal?: AbortSignal): AbortSignal;
|
package/dist/Utils.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timeoutSignal = exports.fromHumanReadableString = exports.toHumanReadableString = void 0;
|
|
4
|
+
const sdk_lib_1 = require("@atomiqlabs/sdk-lib");
|
|
5
|
+
function toHumanReadableString(amount, currencySpec) {
|
|
6
|
+
if (amount == null)
|
|
7
|
+
return null;
|
|
8
|
+
return (0, sdk_lib_1.toDecimal)(amount, currencySpec.decimals, undefined, currencySpec.displayDecimals);
|
|
9
|
+
}
|
|
10
|
+
exports.toHumanReadableString = toHumanReadableString;
|
|
11
|
+
function fromHumanReadableString(amount, currencySpec) {
|
|
12
|
+
if (amount === "" || amount == null)
|
|
13
|
+
return null;
|
|
14
|
+
return (0, sdk_lib_1.fromDecimal)(amount, currencySpec.decimals);
|
|
15
|
+
}
|
|
16
|
+
exports.fromHumanReadableString = fromHumanReadableString;
|
|
17
|
+
/**
|
|
18
|
+
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
19
|
+
*
|
|
20
|
+
* @param timeout Milliseconds to wait
|
|
21
|
+
* @param abortReason Abort with this abort reason
|
|
22
|
+
* @param abortSignal Abort signal to extend
|
|
23
|
+
*/
|
|
24
|
+
function timeoutSignal(timeout, abortReason, abortSignal) {
|
|
25
|
+
if (timeout == null)
|
|
26
|
+
return abortSignal;
|
|
27
|
+
const abortController = new AbortController();
|
|
28
|
+
const timeoutHandle = setTimeout(() => abortController.abort(abortReason || new Error("Timed out")), timeout);
|
|
29
|
+
if (abortSignal != null) {
|
|
30
|
+
abortSignal.addEventListener("abort", () => {
|
|
31
|
+
clearTimeout(timeoutHandle);
|
|
32
|
+
abortController.abort(abortSignal.reason);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return abortController.signal;
|
|
36
|
+
}
|
|
37
|
+
exports.timeoutSignal = timeoutSignal;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StorageObject, IStorageManager } from "@atomiqlabs/base";
|
|
2
|
+
/**
|
|
3
|
+
* StorageManager using local filesystem to persists data, creates a new file for every save object
|
|
4
|
+
*/
|
|
5
|
+
export declare class FileSystemStorageManager<T extends StorageObject> implements IStorageManager<T> {
|
|
6
|
+
private readonly directory;
|
|
7
|
+
data: {
|
|
8
|
+
[key: string]: T;
|
|
9
|
+
};
|
|
10
|
+
constructor(directory: string);
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
saveData(hash: string, object: T): Promise<void>;
|
|
13
|
+
removeData(hash: string): Promise<void>;
|
|
14
|
+
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileSystemStorageManager = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
/**
|
|
6
|
+
* StorageManager using local filesystem to persists data, creates a new file for every save object
|
|
7
|
+
*/
|
|
8
|
+
class FileSystemStorageManager {
|
|
9
|
+
constructor(directory) {
|
|
10
|
+
this.data = {};
|
|
11
|
+
this.directory = directory;
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
try {
|
|
15
|
+
await fs.mkdir(this.directory);
|
|
16
|
+
}
|
|
17
|
+
catch (e) { }
|
|
18
|
+
}
|
|
19
|
+
async saveData(hash, object) {
|
|
20
|
+
try {
|
|
21
|
+
await fs.mkdir(this.directory);
|
|
22
|
+
}
|
|
23
|
+
catch (e) { }
|
|
24
|
+
this.data[hash] = object;
|
|
25
|
+
const cpy = object.serialize();
|
|
26
|
+
await fs.writeFile(this.directory + "/" + hash + ".json", JSON.stringify(cpy));
|
|
27
|
+
}
|
|
28
|
+
async removeData(hash) {
|
|
29
|
+
const paymentHash = hash;
|
|
30
|
+
try {
|
|
31
|
+
if (this.data[paymentHash] != null)
|
|
32
|
+
delete this.data[paymentHash];
|
|
33
|
+
await fs.rm(this.directory + "/" + paymentHash + ".json");
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error("FileSystemStorageManager: removeData(): Error: ", e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async loadData(type) {
|
|
40
|
+
let files;
|
|
41
|
+
try {
|
|
42
|
+
files = await fs.readdir(this.directory);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.error("FileSystemStorageManager: loadData(): Error: ", e);
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const arr = [];
|
|
49
|
+
for (let file of files) {
|
|
50
|
+
const paymentHash = file.split(".")[0];
|
|
51
|
+
const result = await fs.readFile(this.directory + "/" + file);
|
|
52
|
+
const obj = JSON.parse(result.toString());
|
|
53
|
+
const parsed = new type(obj);
|
|
54
|
+
arr.push(parsed);
|
|
55
|
+
this.data[paymentHash] = parsed;
|
|
56
|
+
}
|
|
57
|
+
return arr;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.FileSystemStorageManager = FileSystemStorageManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FileSystemStorageManager";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./FileSystemStorageManager"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "@atomiqlabs/
|
|
3
|
-
export * from "
|
|
4
|
-
export * from "
|
|
1
|
+
export * from "@atomiqlabs/base";
|
|
2
|
+
export * from "@atomiqlabs/sdk-lib";
|
|
3
|
+
export * from "./SwapperFactory";
|
|
4
|
+
export * from "./Utils";
|
|
5
|
+
export * from "./storage/LocalStorageManager";
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("
|
|
18
|
-
__exportStar(require("@atomiqlabs/
|
|
19
|
-
__exportStar(require("
|
|
20
|
-
__exportStar(require("
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@atomiqlabs/base"), exports);
|
|
18
|
+
__exportStar(require("@atomiqlabs/sdk-lib"), exports);
|
|
19
|
+
__exportStar(require("./SwapperFactory"), exports);
|
|
20
|
+
__exportStar(require("./Utils"), exports);
|
|
21
|
+
__exportStar(require("./storage/LocalStorageManager"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IStorageManager, StorageObject } from "@atomiqlabs/base";
|
|
2
|
+
/**
|
|
3
|
+
* StorageManager using browser's local storage API
|
|
4
|
+
*/
|
|
5
|
+
export declare class LocalStorageManager<T extends StorageObject> implements IStorageManager<T> {
|
|
6
|
+
storageKey: string;
|
|
7
|
+
rawData: {
|
|
8
|
+
[hash: string]: any;
|
|
9
|
+
};
|
|
10
|
+
data: {
|
|
11
|
+
[hash: string]: T;
|
|
12
|
+
};
|
|
13
|
+
constructor(storageKey: string);
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
saveData(hash: string, object: T): Promise<void>;
|
|
16
|
+
saveDataArr(arr: {
|
|
17
|
+
id: string;
|
|
18
|
+
object: T;
|
|
19
|
+
}[]): Promise<void>;
|
|
20
|
+
removeData(hash: string): Promise<void>;
|
|
21
|
+
removeDataArr(hashArr: string[]): Promise<void>;
|
|
22
|
+
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
23
|
+
private save;
|
|
24
|
+
}
|