@atomiqlabs/sdk 1.0.0-beta8 → 1.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.
|
@@ -25,10 +25,7 @@ export declare class MultichainSwapper extends Swapper<SdkMultichain> {
|
|
|
25
25
|
}
|
|
26
26
|
export declare const Tokens: {
|
|
27
27
|
[C in keyof Chains]: {
|
|
28
|
-
[T in keyof Chains[C]["Assets"]]: SCToken<
|
|
29
|
-
name: string;
|
|
30
|
-
decimals: number;
|
|
31
|
-
};
|
|
28
|
+
[T in keyof Chains[C]["Assets"]]: SCToken<C>;
|
|
32
29
|
};
|
|
33
30
|
} & {
|
|
34
31
|
BITCOIN: {
|
|
@@ -38,10 +35,7 @@ export declare const Tokens: {
|
|
|
38
35
|
};
|
|
39
36
|
export declare const TokenResolver: {
|
|
40
37
|
[C in keyof Chains]: {
|
|
41
|
-
getToken(address: string):
|
|
42
|
-
ticker: string;
|
|
43
|
-
name: string;
|
|
44
|
-
};
|
|
38
|
+
getToken(address: string): SCToken<C>;
|
|
45
39
|
};
|
|
46
40
|
};
|
|
47
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;
|
|
@@ -45,23 +47,18 @@ exports.Tokens = Object.assign(Object.assign({}, (0, Utils_1.objectMap)(Chains,
|
|
|
45
47
|
chainId: value.chainIdentifier,
|
|
46
48
|
address: assetData.address,
|
|
47
49
|
name: SmartChainAssets_1.SmartChainAssets[ticker].name,
|
|
48
|
-
decimals: assetData.decimals
|
|
50
|
+
decimals: assetData.decimals,
|
|
51
|
+
ticker
|
|
49
52
|
};
|
|
50
53
|
});
|
|
51
|
-
})), { BITCOIN:
|
|
52
|
-
|
|
53
|
-
chain: "BTC",
|
|
54
|
-
lightning: false
|
|
55
|
-
},
|
|
56
|
-
BTCLN: {
|
|
57
|
-
chain: "BTC",
|
|
58
|
-
lightning: true
|
|
59
|
-
}
|
|
60
|
-
} });
|
|
61
|
-
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) => {
|
|
62
56
|
const addressMap = {};
|
|
63
57
|
for (let ticker in value.assets) {
|
|
64
58
|
addressMap[value.assets[ticker].address] = {
|
|
59
|
+
chain: "SC",
|
|
60
|
+
chainId: value.chainIdentifier,
|
|
61
|
+
address: value.assets[ticker].address,
|
|
65
62
|
ticker,
|
|
66
63
|
name: SmartChainAssets_1.SmartChainAssets[ticker].name,
|
|
67
64
|
decimals: value.assets[ticker].decimals
|
|
@@ -70,4 +67,4 @@ exports.TokenResolver = (0, Utils_1.objectMap)(Chains, (value, key) => {
|
|
|
70
67
|
return {
|
|
71
68
|
getToken: (address) => addressMap[address]
|
|
72
69
|
};
|
|
73
|
-
});
|
|
70
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@atomiqlabs/sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types:": "./dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"/dist",
|
|
12
|
-
"/src"
|
|
13
|
-
],
|
|
14
|
-
"keywords": [
|
|
15
|
-
"Bitcoin",
|
|
16
|
-
"Cross-chain",
|
|
17
|
-
"Cryptocurrency",
|
|
18
|
-
"Bridge",
|
|
19
|
-
"Trustless"
|
|
20
|
-
],
|
|
21
|
-
"author": "adambor",
|
|
22
|
-
"license": "ISC",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"crosslightning-base": "7.
|
|
25
|
-
"crosslightning-sdk-base": "10.0
|
|
26
|
-
"crosslightning-solana": "7.
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/bn.js": "5.1.5",
|
|
30
|
-
"typescript": "4.9.5"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@atomiqlabs/sdk",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types:": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"/dist",
|
|
12
|
+
"/src"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"Bitcoin",
|
|
16
|
+
"Cross-chain",
|
|
17
|
+
"Cryptocurrency",
|
|
18
|
+
"Bridge",
|
|
19
|
+
"Trustless"
|
|
20
|
+
],
|
|
21
|
+
"author": "adambor",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"crosslightning-base": "7.1.0",
|
|
25
|
+
"crosslightning-sdk-base": "10.1.0",
|
|
26
|
+
"crosslightning-solana": "7.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/bn.js": "5.1.5",
|
|
30
|
+
"typescript": "4.9.5"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/MultichainSwapper.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BitcoinNetwork,
|
|
3
|
-
BtcToken, IndexedDBStorageManager,
|
|
2
|
+
BitcoinNetwork, BitcoinTokens,
|
|
3
|
+
BtcToken, IndexedDBStorageManager, isToken,
|
|
4
4
|
MempoolApi,
|
|
5
5
|
MempoolBitcoinRpc,
|
|
6
6
|
RedundantSwapPrice,
|
|
7
7
|
RedundantSwapPriceAssets,
|
|
8
8
|
SCToken,
|
|
9
9
|
Swapper,
|
|
10
|
-
SwapperOptions
|
|
10
|
+
SwapperOptions, Token
|
|
11
11
|
} from "crosslightning-sdk-base";
|
|
12
12
|
import {objectMap} from "crosslightning-sdk-base/dist/utils/Utils";
|
|
13
13
|
import {SdkSolana, SdkSolanaType} from "./chains/solana/SolanaChainInitializer";
|
|
@@ -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,14 +74,20 @@ 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
88
|
export const Tokens: {
|
|
80
89
|
[C in keyof Chains]: {
|
|
81
|
-
[T in keyof Chains[C]["Assets"]]: SCToken<
|
|
90
|
+
[T in keyof Chains[C]["Assets"]]: SCToken<C>
|
|
82
91
|
}
|
|
83
92
|
} & {
|
|
84
93
|
BITCOIN: {
|
|
@@ -93,36 +102,33 @@ export const Tokens: {
|
|
|
93
102
|
chainId: value.chainIdentifier,
|
|
94
103
|
address: assetData.address,
|
|
95
104
|
name: SmartChainAssets[ticker].name,
|
|
96
|
-
decimals: assetData.decimals
|
|
105
|
+
decimals: assetData.decimals,
|
|
106
|
+
ticker
|
|
97
107
|
}
|
|
98
108
|
});
|
|
99
109
|
}),
|
|
100
|
-
BITCOIN:
|
|
101
|
-
BTC: {
|
|
102
|
-
chain: "BTC",
|
|
103
|
-
lightning: false
|
|
104
|
-
},
|
|
105
|
-
BTCLN: {
|
|
106
|
-
chain: "BTC",
|
|
107
|
-
lightning: true
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
+
BITCOIN: BitcoinTokens
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
export const TokenResolver: {
|
|
113
114
|
[C in keyof Chains]: {
|
|
114
|
-
getToken(address: string):
|
|
115
|
+
getToken(address: string): SCToken<C>
|
|
115
116
|
}
|
|
116
|
-
} =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
ticker
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|
|
123
129
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
}
|
|
130
|
+
return {
|
|
131
|
+
getToken: (address: string) => addressMap[address]
|
|
132
|
+
};
|
|
133
|
+
})
|
|
134
|
+
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BitcoinRpc, ChainType } from "crosslightning-base";
|
|
2
|
-
import { BitcoinNetwork, CtorChainData } from "crosslightning-sdk-base";
|
|
3
|
-
export type SdkChainType = {
|
|
4
|
-
ChainType: ChainType;
|
|
5
|
-
Options: {};
|
|
6
|
-
Assets: {
|
|
7
|
-
[ticker: string]: {
|
|
8
|
-
address: string;
|
|
9
|
-
decimals: number;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type SdkChain<T extends SdkChainType> = {
|
|
14
|
-
getCtorData: (options: T["Options"], bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork) => CtorChainData<T["ChainType"]>;
|
|
15
|
-
assets: {
|
|
16
|
-
[ticker: string]: {
|
|
17
|
-
address: string;
|
|
18
|
-
decimals: number;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
chainIdentifier: string;
|
|
22
|
-
};
|