@atomiqlabs/sdk 1.0.0-beta10 → 1.0.0-beta11
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/dist/MultichainSwapper.d.ts +5 -27
- package/dist/MultichainSwapper.js +7 -20
- package/package.json +2 -2
- package/src/MultichainSwapper.ts +37 -49
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BtcToken, SCToken, Swapper, SwapperOptions
|
|
1
|
+
import { BtcToken, SCToken, Swapper, SwapperOptions } from "crosslightning-sdk-base";
|
|
2
2
|
import { SdkSolanaType } from "./chains/solana/SolanaChainInitializer";
|
|
3
3
|
import { SdkChain } from "./chains/ChainInitializer";
|
|
4
4
|
import * as BN from "bn.js";
|
|
@@ -23,41 +23,19 @@ export type MultichainSwapperOptions = SwapperOptions & {
|
|
|
23
23
|
export declare class MultichainSwapper extends Swapper<SdkMultichain> {
|
|
24
24
|
constructor(options: MultichainSwapperOptions);
|
|
25
25
|
}
|
|
26
|
-
export type TokenExtended<C extends string = string, T extends string = string> = Token<C> & {
|
|
27
|
-
name: string;
|
|
28
|
-
decimals: number;
|
|
29
|
-
ticker: T;
|
|
30
|
-
};
|
|
31
|
-
export type SCTokenExtended<C extends string = string, T extends string = string> = SCToken<C> & {
|
|
32
|
-
name: string;
|
|
33
|
-
decimals: number;
|
|
34
|
-
ticker: T;
|
|
35
|
-
};
|
|
36
26
|
export declare const Tokens: {
|
|
37
27
|
[C in keyof Chains]: {
|
|
38
|
-
[T in keyof Chains[C]["Assets"]]: SCToken<C
|
|
39
|
-
name: string;
|
|
40
|
-
decimals: number;
|
|
41
|
-
ticker: T;
|
|
42
|
-
};
|
|
28
|
+
[T in keyof Chains[C]["Assets"]]: SCToken<C>;
|
|
43
29
|
};
|
|
44
30
|
} & {
|
|
45
31
|
BITCOIN: {
|
|
46
|
-
BTC: BtcToken<false
|
|
47
|
-
|
|
48
|
-
decimals: 8;
|
|
49
|
-
ticker: "BTC";
|
|
50
|
-
};
|
|
51
|
-
BTCLN: BtcToken<true> & {
|
|
52
|
-
name: "Bitcoin (lightning L2)";
|
|
53
|
-
decimals: 8;
|
|
54
|
-
ticker: "BTCLN";
|
|
55
|
-
};
|
|
32
|
+
BTC: BtcToken<false>;
|
|
33
|
+
BTCLN: BtcToken<true>;
|
|
56
34
|
};
|
|
57
35
|
};
|
|
58
36
|
export declare const TokenResolver: {
|
|
59
37
|
[C in keyof Chains]: {
|
|
60
|
-
getToken(address: string):
|
|
38
|
+
getToken(address: string): SCToken<C>;
|
|
61
39
|
};
|
|
62
40
|
};
|
|
63
41
|
export {};
|
|
@@ -29,12 +29,14 @@ class MultichainSwapper extends crosslightning_sdk_base_1.Swapper {
|
|
|
29
29
|
if (Chains[chainId].assets[ticker] != null)
|
|
30
30
|
chains[chainId] = Chains[chainId].assets[ticker];
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const assetData = SmartChainAssets_1.SmartChainAssets[ticker];
|
|
33
|
+
pricingAssets.push(Object.assign(Object.assign({}, assetData.pricing), { chains,
|
|
34
|
+
ticker, name: assetData.name }));
|
|
33
35
|
});
|
|
34
36
|
const ctorChainData = (0, Utils_1.objectMap)(Chains, (value, key) => {
|
|
35
37
|
return value.getCtorData(options, bitcoinRpc, options.bitcoinNetwork);
|
|
36
38
|
});
|
|
37
|
-
super(bitcoinRpc, ctorChainData, crosslightning_sdk_base_1.RedundantSwapPrice.createFromTokenMap((_e = options.pricingFeeDifferencePPM) !== null && _e !== void 0 ? _e : new BN(10000), pricingAssets), options);
|
|
39
|
+
super(bitcoinRpc, ctorChainData, crosslightning_sdk_base_1.RedundantSwapPrice.createFromTokenMap((_e = options.pricingFeeDifferencePPM) !== null && _e !== void 0 ? _e : new BN(10000), pricingAssets), pricingAssets, options);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
exports.MultichainSwapper = MultichainSwapper;
|
|
@@ -49,23 +51,8 @@ exports.Tokens = Object.assign(Object.assign({}, (0, Utils_1.objectMap)(Chains,
|
|
|
49
51
|
ticker
|
|
50
52
|
};
|
|
51
53
|
});
|
|
52
|
-
})), { BITCOIN:
|
|
53
|
-
|
|
54
|
-
chain: "BTC",
|
|
55
|
-
lightning: false,
|
|
56
|
-
decimals: 8,
|
|
57
|
-
name: "Bitcoin (on-chain)",
|
|
58
|
-
ticker: "BTC"
|
|
59
|
-
},
|
|
60
|
-
BTCLN: {
|
|
61
|
-
chain: "BTC",
|
|
62
|
-
lightning: true,
|
|
63
|
-
decimals: 8,
|
|
64
|
-
name: "Bitcoin (lightning L2)",
|
|
65
|
-
ticker: "BTCLN"
|
|
66
|
-
}
|
|
67
|
-
} });
|
|
68
|
-
exports.TokenResolver = (0, Utils_1.objectMap)(Chains, (value, key) => {
|
|
54
|
+
})), { BITCOIN: crosslightning_sdk_base_1.BitcoinTokens });
|
|
55
|
+
exports.TokenResolver = Object.assign({}, (0, Utils_1.objectMap)(Chains, (value, key) => {
|
|
69
56
|
const addressMap = {};
|
|
70
57
|
for (let ticker in value.assets) {
|
|
71
58
|
addressMap[value.assets[ticker].address] = {
|
|
@@ -80,4 +67,4 @@ exports.TokenResolver = (0, Utils_1.objectMap)(Chains, (value, key) => {
|
|
|
80
67
|
return {
|
|
81
68
|
getToken: (address) => addressMap[address]
|
|
82
69
|
};
|
|
83
|
-
});
|
|
70
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/sdk",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta11",
|
|
4
4
|
"description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"crosslightning-base": "7.0.0-beta1",
|
|
25
|
-
"crosslightning-sdk-base": "10.0.5-
|
|
25
|
+
"crosslightning-sdk-base": "10.0.5-beta12",
|
|
26
26
|
"crosslightning-solana": "7.0.0-beta4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
package/src/MultichainSwapper.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BitcoinNetwork,
|
|
3
|
-
BtcToken, IndexedDBStorageManager,
|
|
2
|
+
BitcoinNetwork, BitcoinTokens,
|
|
3
|
+
BtcToken, IndexedDBStorageManager, isToken,
|
|
4
4
|
MempoolApi,
|
|
5
5
|
MempoolBitcoinRpc,
|
|
6
6
|
RedundantSwapPrice,
|
|
@@ -55,15 +55,18 @@ export class MultichainSwapper extends Swapper<SdkMultichain> {
|
|
|
55
55
|
);
|
|
56
56
|
const bitcoinRpc = new MempoolBitcoinRpc(mempoolApi);
|
|
57
57
|
|
|
58
|
-
const pricingAssets: RedundantSwapPriceAssets<SdkMultichain> = [];
|
|
58
|
+
const pricingAssets: (RedundantSwapPriceAssets<SdkMultichain>[number] & {ticker: string, name: string})[] = [];
|
|
59
59
|
Object.keys(SmartChainAssets).forEach((ticker) => {
|
|
60
60
|
const chains: any = {};
|
|
61
61
|
for(let chainId in Chains) {
|
|
62
62
|
if(Chains[chainId].assets[ticker]!=null) chains[chainId] = Chains[chainId].assets[ticker];
|
|
63
63
|
}
|
|
64
|
+
const assetData = SmartChainAssets[ticker];
|
|
64
65
|
pricingAssets.push({
|
|
65
|
-
...
|
|
66
|
-
chains
|
|
66
|
+
...assetData.pricing,
|
|
67
|
+
chains,
|
|
68
|
+
ticker,
|
|
69
|
+
name: assetData.name
|
|
67
70
|
})
|
|
68
71
|
});
|
|
69
72
|
|
|
@@ -71,27 +74,25 @@ export class MultichainSwapper extends Swapper<SdkMultichain> {
|
|
|
71
74
|
return value.getCtorData(options, bitcoinRpc, options.bitcoinNetwork);
|
|
72
75
|
});
|
|
73
76
|
|
|
74
|
-
super(
|
|
77
|
+
super(
|
|
78
|
+
bitcoinRpc,
|
|
79
|
+
ctorChainData,
|
|
80
|
+
RedundantSwapPrice.createFromTokenMap<SdkMultichain>(options.pricingFeeDifferencePPM ?? new BN(10000), pricingAssets),
|
|
81
|
+
pricingAssets,
|
|
82
|
+
options
|
|
83
|
+
);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
export type TokenExtended<C extends string = string, T extends string = string> = Token<C> & {
|
|
80
|
-
name: string, decimals: number, ticker: T
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type SCTokenExtended<C extends string = string, T extends string = string> = SCToken<C> & {
|
|
84
|
-
name: string, decimals: number, ticker: T
|
|
85
|
-
};
|
|
86
|
-
|
|
87
88
|
export const Tokens: {
|
|
88
89
|
[C in keyof Chains]: {
|
|
89
|
-
[T in keyof Chains[C]["Assets"]]: SCToken<C>
|
|
90
|
+
[T in keyof Chains[C]["Assets"]]: SCToken<C>
|
|
90
91
|
}
|
|
91
92
|
} & {
|
|
92
93
|
BITCOIN: {
|
|
93
|
-
BTC: BtcToken<false
|
|
94
|
-
BTCLN: BtcToken<true>
|
|
94
|
+
BTC: BtcToken<false>,
|
|
95
|
+
BTCLN: BtcToken<true>
|
|
95
96
|
}
|
|
96
97
|
} = {
|
|
97
98
|
...objectMap(Chains, (value, key) => {
|
|
@@ -106,41 +107,28 @@ export const Tokens: {
|
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
109
|
}),
|
|
109
|
-
BITCOIN:
|
|
110
|
-
BTC: {
|
|
111
|
-
chain: "BTC",
|
|
112
|
-
lightning: false,
|
|
113
|
-
decimals: 8,
|
|
114
|
-
name: "Bitcoin (on-chain)",
|
|
115
|
-
ticker: "BTC"
|
|
116
|
-
},
|
|
117
|
-
BTCLN: {
|
|
118
|
-
chain: "BTC",
|
|
119
|
-
lightning: true,
|
|
120
|
-
decimals: 8,
|
|
121
|
-
name: "Bitcoin (lightning L2)",
|
|
122
|
-
ticker: "BTCLN"
|
|
123
|
-
}
|
|
124
|
-
}
|
|
110
|
+
BITCOIN: BitcoinTokens
|
|
125
111
|
};
|
|
126
112
|
|
|
127
113
|
export const TokenResolver: {
|
|
128
114
|
[C in keyof Chains]: {
|
|
129
|
-
getToken(address: string):
|
|
115
|
+
getToken(address: string): SCToken<C>
|
|
130
116
|
}
|
|
131
|
-
} =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
} = {
|
|
118
|
+
...objectMap(Chains, (value, key) => {
|
|
119
|
+
const addressMap: {[tokenAddress: string]: SCToken} = {};
|
|
120
|
+
for(let ticker in value.assets) {
|
|
121
|
+
addressMap[value.assets[ticker].address] = {
|
|
122
|
+
chain: "SC",
|
|
123
|
+
chainId: value.chainIdentifier,
|
|
124
|
+
address: value.assets[ticker].address,
|
|
125
|
+
ticker,
|
|
126
|
+
name: SmartChainAssets[ticker].name,
|
|
127
|
+
decimals: value.assets[ticker].decimals
|
|
128
|
+
}
|
|
141
129
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}
|
|
130
|
+
return {
|
|
131
|
+
getToken: (address: string) => addressMap[address]
|
|
132
|
+
};
|
|
133
|
+
})
|
|
134
|
+
};
|