@atomiqlabs/sdk 4.0.0-beta.4 → 4.0.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.
@@ -1,73 +1,73 @@
1
- export declare const SmartChainAssets: {
2
- readonly WBTC: {
3
- readonly pricing: {
4
- readonly binancePair: "WBTCBTC";
5
- readonly okxPair: "WBTC-BTC";
6
- readonly coinGeckoCoinId: "wrapped-bitcoin";
7
- readonly coinPaprikaCoinId: "wbtc-wrapped-bitcoin";
8
- readonly krakenPair: "WBTCXBT";
9
- };
10
- readonly name: "Wrapped BTC (WBTC)";
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: "Ether";
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;
1
+ export declare const SmartChainAssets: {
2
+ readonly WBTC: {
3
+ readonly pricing: {
4
+ readonly binancePair: "WBTCBTC";
5
+ readonly okxPair: "WBTC-BTC";
6
+ readonly coinGeckoCoinId: "wrapped-bitcoin";
7
+ readonly coinPaprikaCoinId: "wbtc-wrapped-bitcoin";
8
+ readonly krakenPair: "WBTCXBT";
9
+ };
10
+ readonly name: "Wrapped BTC (WBTC)";
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: "Ether";
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;
@@ -1,75 +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: "WBTC-BTC",
9
- coinGeckoCoinId: "wrapped-bitcoin",
10
- coinPaprikaCoinId: "wbtc-wrapped-bitcoin",
11
- krakenPair: "WBTCXBT"
12
- },
13
- name: "Wrapped BTC (WBTC)"
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: "Ether"
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
- };
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: "WBTC-BTC",
9
+ coinGeckoCoinId: "wrapped-bitcoin",
10
+ coinPaprikaCoinId: "wbtc-wrapped-bitcoin",
11
+ krakenPair: "WBTCXBT"
12
+ },
13
+ name: "Wrapped BTC (WBTC)"
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: "Ether"
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
+ };
@@ -1,50 +1,50 @@
1
- import { ChainData, BitcoinNetwork, BitcoinRpc, BaseTokenType, ChainType, StorageObject, IStorageManager } from "@atomiqlabs/base";
2
- import { BtcToken, CustomPriceFunction, MempoolApi, MempoolBitcoinRpc, 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 | MempoolBitcoinRpc | string | string[];
36
- getPriceFn?: CustomPriceFunction;
37
- };
38
- export declare class SwapperFactory<T extends readonly ChainInitializer<any, any, any>[]> {
39
- readonly initializers: T;
40
- Tokens: GetAllTokens<T> & {
41
- BITCOIN: {
42
- BTC: BtcToken<false>;
43
- BTCLN: BtcToken<true>;
44
- };
45
- };
46
- TokenResolver: GetAllTokenResolvers<T>;
47
- constructor(initializers: T);
48
- newSwapper(options: MultichainSwapperOptions<T>): Swapper<ToMultichain<T>>;
49
- }
50
- export {};
1
+ import { ChainData, BitcoinNetwork, BitcoinRpc, BaseTokenType, ChainType, StorageObject, IStorageManager } from "@atomiqlabs/base";
2
+ import { BtcToken, CustomPriceFunction, MempoolApi, MempoolBitcoinRpc, 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 | MempoolBitcoinRpc | string | string[];
36
+ getPriceFn?: CustomPriceFunction;
37
+ };
38
+ export declare class SwapperFactory<T extends readonly ChainInitializer<any, any, any>[]> {
39
+ readonly initializers: T;
40
+ Tokens: GetAllTokens<T> & {
41
+ BITCOIN: {
42
+ BTC: BtcToken<false>;
43
+ BTCLN: BtcToken<true>;
44
+ };
45
+ };
46
+ TokenResolver: GetAllTokenResolvers<T>;
47
+ constructor(initializers: T);
48
+ newSwapper(options: MultichainSwapperOptions<T>): Swapper<ToMultichain<T>>;
49
+ }
50
+ export {};
@@ -1,105 +1,105 @@
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
- const registries = {
9
- [base_1.BitcoinNetwork.MAINNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main",
10
- [base_1.BitcoinNetwork.TESTNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main",
11
- [base_1.BitcoinNetwork.TESTNET4]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-testnet4.json?ref=main"
12
- };
13
- const trustedIntermediaries = {
14
- [base_1.BitcoinNetwork.MAINNET]: "https://node3.gethopa.com:34100",
15
- [base_1.BitcoinNetwork.TESTNET]: "https://node3.gethopa.com:24100"
16
- };
17
- const mempoolUrls = {
18
- [base_1.BitcoinNetwork.MAINNET]: [
19
- "https://mempool.space/api/",
20
- "https://mempool.fra.mempool.space/api/",
21
- "https://mempool.va1.mempool.space/api/",
22
- "https://mempool.tk7.mempool.space/api/"
23
- ],
24
- [base_1.BitcoinNetwork.TESTNET]: [
25
- "https://mempool.space/testnet/api/",
26
- "https://mempool.fra.mempool.space/testnet/api/",
27
- "https://mempool.va1.mempool.space/testnet/api/",
28
- "https://mempool.tk7.mempool.space/testnet/api/"
29
- ],
30
- [base_1.BitcoinNetwork.TESTNET4]: [
31
- "https://mempool.space/testnet4/api/",
32
- "https://mempool.fra.mempool.space/testnet4/api/",
33
- "https://mempool.va1.mempool.space/testnet4/api/",
34
- "https://mempool.tk7.mempool.space/testnet4/api/"
35
- ]
36
- };
37
- class SwapperFactory {
38
- constructor(initializers) {
39
- this.initializers = initializers;
40
- this.Tokens = {
41
- BITCOIN: sdk_lib_1.BitcoinTokens
42
- };
43
- this.TokenResolver = {};
44
- this.initializers = initializers;
45
- initializers.forEach(initializer => {
46
- const addressMap = {};
47
- this.Tokens[initializer.chainId] = {};
48
- for (let ticker in initializer.tokens) {
49
- const assetData = initializer.tokens[ticker];
50
- this.Tokens[initializer.chainId][ticker] = addressMap[assetData.address] = {
51
- chain: "SC",
52
- chainId: initializer.chainId,
53
- address: assetData.address,
54
- name: SmartChainAssets_1.SmartChainAssets[ticker].name,
55
- decimals: assetData.decimals,
56
- displayDecimals: assetData.displayDecimals,
57
- ticker
58
- };
59
- }
60
- this.TokenResolver[initializer.chainId] = {
61
- getToken: (address) => addressMap[address]
62
- };
63
- });
64
- }
65
- newSwapper(options) {
66
- options.bitcoinNetwork ?? (options.bitcoinNetwork = base_1.BitcoinNetwork.MAINNET);
67
- options.storagePrefix ?? (options.storagePrefix = "atomiqsdk-" + options.bitcoinNetwork + "-");
68
- options.defaultTrustedIntermediaryUrl ?? (options.defaultTrustedIntermediaryUrl = trustedIntermediaries[options.bitcoinNetwork]);
69
- options.registryUrl ?? (options.registryUrl = registries[options.bitcoinNetwork]);
70
- const mempoolApi = options.mempoolApi ?? new sdk_lib_1.MempoolBitcoinRpc(mempoolUrls[options.bitcoinNetwork]);
71
- const bitcoinRpc = mempoolApi instanceof sdk_lib_1.MempoolBitcoinRpc ? mempoolApi : new sdk_lib_1.MempoolBitcoinRpc(mempoolApi);
72
- const pricingAssets = [];
73
- Object.keys(SmartChainAssets_1.SmartChainAssets).forEach((ticker) => {
74
- const chains = {};
75
- for (let { tokens, chainId } of this.initializers) {
76
- if (tokens[ticker] != null)
77
- chains[chainId] = tokens[ticker];
78
- }
79
- const assetData = SmartChainAssets_1.SmartChainAssets[ticker];
80
- pricingAssets.push({
81
- ...assetData.pricing,
82
- chains,
83
- ticker,
84
- name: assetData.name
85
- });
86
- });
87
- options.chainStorageCtor ?? (options.chainStorageCtor = (name) => new LocalStorageManager_1.LocalStorageManager(name));
88
- const chains = {};
89
- for (let { initializer, chainId } of this.initializers) {
90
- if (options.chains[chainId] == null)
91
- continue;
92
- chains[chainId] = initializer(options.chains[chainId], bitcoinRpc, options.bitcoinNetwork, options.chainStorageCtor);
93
- }
94
- const swapPricing = options.getPriceFn != null ?
95
- new sdk_lib_1.SingleSwapPrice(options.pricingFeeDifferencePPM ?? 10000n, new sdk_lib_1.CustomPriceProvider(pricingAssets.map(val => {
96
- return {
97
- coinId: val.ticker,
98
- chains: val.chains
99
- };
100
- }), options.getPriceFn)) :
101
- sdk_lib_1.RedundantSwapPrice.createFromTokenMap(options.pricingFeeDifferencePPM ?? 10000n, pricingAssets);
102
- return new sdk_lib_1.Swapper(bitcoinRpc, chains, swapPricing, pricingAssets, options);
103
- }
104
- }
105
- exports.SwapperFactory = SwapperFactory;
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
+ const registries = {
9
+ [base_1.BitcoinNetwork.MAINNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main",
10
+ [base_1.BitcoinNetwork.TESTNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main",
11
+ [base_1.BitcoinNetwork.TESTNET4]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-testnet4.json?ref=main"
12
+ };
13
+ const trustedIntermediaries = {
14
+ [base_1.BitcoinNetwork.MAINNET]: "https://node3.gethopa.com:34100",
15
+ [base_1.BitcoinNetwork.TESTNET]: "https://node3.gethopa.com:24100"
16
+ };
17
+ const mempoolUrls = {
18
+ [base_1.BitcoinNetwork.MAINNET]: [
19
+ "https://mempool.space/api/",
20
+ "https://mempool.fra.mempool.space/api/",
21
+ "https://mempool.va1.mempool.space/api/",
22
+ "https://mempool.tk7.mempool.space/api/"
23
+ ],
24
+ [base_1.BitcoinNetwork.TESTNET]: [
25
+ "https://mempool.space/testnet/api/",
26
+ "https://mempool.fra.mempool.space/testnet/api/",
27
+ "https://mempool.va1.mempool.space/testnet/api/",
28
+ "https://mempool.tk7.mempool.space/testnet/api/"
29
+ ],
30
+ [base_1.BitcoinNetwork.TESTNET4]: [
31
+ "https://mempool.space/testnet4/api/",
32
+ "https://mempool.fra.mempool.space/testnet4/api/",
33
+ "https://mempool.va1.mempool.space/testnet4/api/",
34
+ "https://mempool.tk7.mempool.space/testnet4/api/"
35
+ ]
36
+ };
37
+ class SwapperFactory {
38
+ constructor(initializers) {
39
+ this.initializers = initializers;
40
+ this.Tokens = {
41
+ BITCOIN: sdk_lib_1.BitcoinTokens
42
+ };
43
+ this.TokenResolver = {};
44
+ this.initializers = initializers;
45
+ initializers.forEach(initializer => {
46
+ const addressMap = {};
47
+ this.Tokens[initializer.chainId] = {};
48
+ for (let ticker in initializer.tokens) {
49
+ const assetData = initializer.tokens[ticker];
50
+ this.Tokens[initializer.chainId][ticker] = addressMap[assetData.address] = {
51
+ chain: "SC",
52
+ chainId: initializer.chainId,
53
+ address: assetData.address,
54
+ name: SmartChainAssets_1.SmartChainAssets[ticker].name,
55
+ decimals: assetData.decimals,
56
+ displayDecimals: assetData.displayDecimals,
57
+ ticker
58
+ };
59
+ }
60
+ this.TokenResolver[initializer.chainId] = {
61
+ getToken: (address) => addressMap[address]
62
+ };
63
+ });
64
+ }
65
+ newSwapper(options) {
66
+ options.bitcoinNetwork ?? (options.bitcoinNetwork = base_1.BitcoinNetwork.MAINNET);
67
+ options.storagePrefix ?? (options.storagePrefix = "atomiqsdk-" + options.bitcoinNetwork + "-");
68
+ options.defaultTrustedIntermediaryUrl ?? (options.defaultTrustedIntermediaryUrl = trustedIntermediaries[options.bitcoinNetwork]);
69
+ options.registryUrl ?? (options.registryUrl = registries[options.bitcoinNetwork]);
70
+ const mempoolApi = options.mempoolApi ?? new sdk_lib_1.MempoolBitcoinRpc(mempoolUrls[options.bitcoinNetwork]);
71
+ const bitcoinRpc = mempoolApi instanceof sdk_lib_1.MempoolBitcoinRpc ? mempoolApi : new sdk_lib_1.MempoolBitcoinRpc(mempoolApi);
72
+ const pricingAssets = [];
73
+ Object.keys(SmartChainAssets_1.SmartChainAssets).forEach((ticker) => {
74
+ const chains = {};
75
+ for (let { tokens, chainId } of this.initializers) {
76
+ if (tokens[ticker] != null)
77
+ chains[chainId] = tokens[ticker];
78
+ }
79
+ const assetData = SmartChainAssets_1.SmartChainAssets[ticker];
80
+ pricingAssets.push({
81
+ ...assetData.pricing,
82
+ chains,
83
+ ticker,
84
+ name: assetData.name
85
+ });
86
+ });
87
+ options.chainStorageCtor ?? (options.chainStorageCtor = (name) => new LocalStorageManager_1.LocalStorageManager(name));
88
+ const chains = {};
89
+ for (let { initializer, chainId } of this.initializers) {
90
+ if (options.chains[chainId] == null)
91
+ continue;
92
+ chains[chainId] = initializer(options.chains[chainId], bitcoinRpc, options.bitcoinNetwork, options.chainStorageCtor);
93
+ }
94
+ const swapPricing = options.getPriceFn != null ?
95
+ new sdk_lib_1.SingleSwapPrice(options.pricingFeeDifferencePPM ?? 10000n, new sdk_lib_1.CustomPriceProvider(pricingAssets.map(val => {
96
+ return {
97
+ coinId: val.ticker,
98
+ chains: val.chains
99
+ };
100
+ }), options.getPriceFn)) :
101
+ sdk_lib_1.RedundantSwapPrice.createFromTokenMap(options.pricingFeeDifferencePPM ?? 10000n, pricingAssets);
102
+ return new sdk_lib_1.Swapper(bitcoinRpc, chains, swapPricing, pricingAssets, options);
103
+ }
104
+ }
105
+ exports.SwapperFactory = SwapperFactory;
package/dist/Utils.d.ts CHANGED
@@ -1,11 +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;
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;