@atomiqlabs/sdk 1.1.3 → 1.2.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 +501 -0
- package/dist/MultichainSwapper.d.ts +45 -41
- package/dist/MultichainSwapper.js +70 -70
- package/dist/SmartChainAssets.d.ts +54 -54
- package/dist/SmartChainAssets.js +50 -50
- package/dist/chains/ChainInitializer.d.ts +13 -13
- package/dist/chains/ChainInitializer.js +2 -2
- package/dist/chains/solana/SolanaChainInitializer.d.ts +42 -42
- package/dist/chains/solana/SolanaChainInitializer.js +60 -60
- package/dist/chains/solana/SolanaChains.d.ts +16 -16
- package/dist/chains/solana/SolanaChains.js +20 -20
- package/dist/example/BrowserExample.d.ts +1 -0
- package/dist/example/BrowserExample.js +104 -0
- package/dist/example/NodeJSExample.d.ts +1 -0
- package/dist/example/NodeJSExample.js +104 -0
- package/dist/example/test.d.ts +1 -0
- package/dist/example/test.js +28 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +20 -20
- package/package.json +32 -32
- package/src/MultichainSwapper.ts +139 -134
- package/src/SmartChainAssets.ts +57 -57
- package/src/chains/ChainInitializer.ts +16 -16
- package/src/chains/solana/SolanaChainInitializer.ts +101 -101
- package/src/chains/solana/SolanaChains.ts +18 -18
- package/src/example/BrowserExample.ts +120 -0
- package/src/example/NodeJSExample.ts +120 -0
- package/src/index.ts +4 -4
package/src/MultichainSwapper.ts
CHANGED
|
@@ -1,134 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BitcoinNetwork, BitcoinTokens,
|
|
3
|
-
BtcToken, IndexedDBStorageManager, isToken,
|
|
4
|
-
MempoolApi,
|
|
5
|
-
MempoolBitcoinRpc,
|
|
6
|
-
RedundantSwapPrice,
|
|
7
|
-
RedundantSwapPriceAssets,
|
|
8
|
-
SCToken,
|
|
9
|
-
Swapper,
|
|
10
|
-
SwapperOptions, Token
|
|
11
|
-
} from "@atomiqlabs/sdk-lib";
|
|
12
|
-
import {objectMap} from "@atomiqlabs/sdk-lib/dist/utils/Utils";
|
|
13
|
-
import {SdkSolana, SdkSolanaType} from "./chains/solana/SolanaChainInitializer";
|
|
14
|
-
import {SdkChain} from "./chains/ChainInitializer";
|
|
15
|
-
import * as BN from "bn.js";
|
|
16
|
-
import {SmartChainAssets} from "./SmartChainAssets";
|
|
17
|
-
import {IStorageManager, StorageObject} from "@atomiqlabs/base";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export type
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
options.
|
|
46
|
-
|
|
47
|
-
options.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
options
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ticker
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
BitcoinNetwork, BitcoinTokens,
|
|
3
|
+
BtcToken, IndexedDBStorageManager, isToken,
|
|
4
|
+
MempoolApi,
|
|
5
|
+
MempoolBitcoinRpc,
|
|
6
|
+
RedundantSwapPrice,
|
|
7
|
+
RedundantSwapPriceAssets,
|
|
8
|
+
SCToken,
|
|
9
|
+
Swapper,
|
|
10
|
+
SwapperOptions, Token
|
|
11
|
+
} from "@atomiqlabs/sdk-lib";
|
|
12
|
+
import {objectMap} from "@atomiqlabs/sdk-lib/dist/utils/Utils";
|
|
13
|
+
import {SdkSolana, SdkSolanaType} from "./chains/solana/SolanaChainInitializer";
|
|
14
|
+
import {SdkChain} from "./chains/ChainInitializer";
|
|
15
|
+
import * as BN from "bn.js";
|
|
16
|
+
import {SmartChainAssets} from "./SmartChainAssets";
|
|
17
|
+
import {IStorageManager, StorageObject} from "@atomiqlabs/base";
|
|
18
|
+
import {SwapperWithChain} from "@atomiqlabs/sdk-lib/dist/swaps/SwapperWithChain";
|
|
19
|
+
import {SwapperWithSigner} from "@atomiqlabs/sdk-lib/dist/swaps/SwapperWithSigner";
|
|
20
|
+
|
|
21
|
+
type Chains = {
|
|
22
|
+
"SOLANA": SdkSolanaType
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const Chains: {
|
|
26
|
+
[C in keyof Chains]: SdkChain<Chains[C]>
|
|
27
|
+
} = {
|
|
28
|
+
"SOLANA": SdkSolana
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export type SdkMultichain = { [C in keyof Chains]: Chains[C]["ChainType"] };
|
|
32
|
+
|
|
33
|
+
export type MultichainSwapperOptions = SwapperOptions & {
|
|
34
|
+
chains: {
|
|
35
|
+
[C in keyof Chains]: Chains[C]["Options"]
|
|
36
|
+
}
|
|
37
|
+
} & {
|
|
38
|
+
storageCtor?: <T extends StorageObject>(name: string) => IStorageManager<T>,
|
|
39
|
+
pricingFeeDifferencePPM?: BN
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export class MultichainSwapper extends Swapper<SdkMultichain> {
|
|
43
|
+
|
|
44
|
+
constructor(options: MultichainSwapperOptions) {
|
|
45
|
+
options.bitcoinNetwork ??= BitcoinNetwork.MAINNET;
|
|
46
|
+
options.storagePrefix ??= "atomiqsdk-"+options.bitcoinNetwork;
|
|
47
|
+
options.storageCtor ??= (name: string) => new IndexedDBStorageManager(name);
|
|
48
|
+
|
|
49
|
+
options.registryUrl ??= options.bitcoinNetwork===BitcoinNetwork.MAINNET ?
|
|
50
|
+
"https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main" :
|
|
51
|
+
"https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main";
|
|
52
|
+
|
|
53
|
+
const mempoolApi = new MempoolApi(
|
|
54
|
+
options.bitcoinNetwork===BitcoinNetwork.TESTNET ?
|
|
55
|
+
"https://mempool.space/testnet/api/" :
|
|
56
|
+
"https://mempool.space/api/"
|
|
57
|
+
);
|
|
58
|
+
const bitcoinRpc = new MempoolBitcoinRpc(mempoolApi);
|
|
59
|
+
|
|
60
|
+
const pricingAssets: (RedundantSwapPriceAssets<SdkMultichain>[number] & {ticker: string, name: string})[] = [];
|
|
61
|
+
Object.keys(SmartChainAssets).forEach((ticker) => {
|
|
62
|
+
const chains: any = {};
|
|
63
|
+
for(let chainId in Chains) {
|
|
64
|
+
if(Chains[chainId].assets[ticker]!=null) chains[chainId] = Chains[chainId].assets[ticker];
|
|
65
|
+
}
|
|
66
|
+
const assetData = SmartChainAssets[ticker];
|
|
67
|
+
pricingAssets.push({
|
|
68
|
+
...assetData.pricing,
|
|
69
|
+
chains,
|
|
70
|
+
ticker,
|
|
71
|
+
name: assetData.name
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const ctorChainData = objectMap(Chains, (value, key) => {
|
|
76
|
+
return value.getCtorData(options, bitcoinRpc, options.bitcoinNetwork);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
super(
|
|
80
|
+
bitcoinRpc,
|
|
81
|
+
ctorChainData,
|
|
82
|
+
RedundantSwapPrice.createFromTokenMap<SdkMultichain>(options.pricingFeeDifferencePPM ?? new BN(10000), pricingAssets),
|
|
83
|
+
pricingAssets,
|
|
84
|
+
options
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const Tokens: {
|
|
91
|
+
[C in keyof Chains]: {
|
|
92
|
+
[T in keyof Chains[C]["Assets"]]: SCToken<C>
|
|
93
|
+
}
|
|
94
|
+
} & {
|
|
95
|
+
BITCOIN: {
|
|
96
|
+
BTC: BtcToken<false>,
|
|
97
|
+
BTCLN: BtcToken<true>
|
|
98
|
+
}
|
|
99
|
+
} = {
|
|
100
|
+
...objectMap(Chains, (value, key) => {
|
|
101
|
+
return objectMap(value.assets, (assetData, ticker) => {
|
|
102
|
+
return {
|
|
103
|
+
chain: "SC",
|
|
104
|
+
chainId: value.chainIdentifier,
|
|
105
|
+
address: assetData.address,
|
|
106
|
+
name: SmartChainAssets[ticker].name,
|
|
107
|
+
decimals: assetData.decimals,
|
|
108
|
+
ticker
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}),
|
|
112
|
+
BITCOIN: BitcoinTokens
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const TokenResolver: {
|
|
116
|
+
[C in keyof Chains]: {
|
|
117
|
+
getToken(address: string): SCToken<C>
|
|
118
|
+
}
|
|
119
|
+
} = {
|
|
120
|
+
...objectMap(Chains, (value, key) => {
|
|
121
|
+
const addressMap: {[tokenAddress: string]: SCToken} = {};
|
|
122
|
+
for(let ticker in value.assets) {
|
|
123
|
+
addressMap[value.assets[ticker].address] = {
|
|
124
|
+
chain: "SC",
|
|
125
|
+
chainId: value.chainIdentifier,
|
|
126
|
+
address: value.assets[ticker].address,
|
|
127
|
+
ticker,
|
|
128
|
+
name: SmartChainAssets[ticker].name,
|
|
129
|
+
decimals: value.assets[ticker].decimals
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
getToken: (address: string) => addressMap[address]
|
|
134
|
+
};
|
|
135
|
+
})
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type SolanaSwapper = SwapperWithChain<SdkMultichain, "SOLANA">;
|
|
139
|
+
export type SolanaSwapperWithSigner = SwapperWithSigner<SdkMultichain, "SOLANA">;
|
package/src/SmartChainAssets.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
export const SmartChainAssets = {
|
|
3
|
-
WBTC: {
|
|
4
|
-
pricing: {
|
|
5
|
-
binancePair: "WBTCBTC",
|
|
6
|
-
okxPair: "$fixed-1",
|
|
7
|
-
coinGeckoCoinId: "wrapped-bitcoin",
|
|
8
|
-
coinPaprikaCoinId: "wbtc-wrapped-bitcoin"
|
|
9
|
-
},
|
|
10
|
-
name: "Wrapped BTC"
|
|
11
|
-
},
|
|
12
|
-
USDC: {
|
|
13
|
-
pricing: {
|
|
14
|
-
binancePair: "!BTCUSDC",
|
|
15
|
-
okxPair: "!BTC-USDC",
|
|
16
|
-
coinGeckoCoinId: "usd-coin",
|
|
17
|
-
coinPaprikaCoinId: "usdc-usd-coin"
|
|
18
|
-
},
|
|
19
|
-
name: "USD Circle"
|
|
20
|
-
},
|
|
21
|
-
USDT: {
|
|
22
|
-
pricing: {
|
|
23
|
-
binancePair: "!BTCUSDT",
|
|
24
|
-
okxPair: "!BTC-USDT",
|
|
25
|
-
coinGeckoCoinId: "tether",
|
|
26
|
-
coinPaprikaCoinId: "usdt-tether"
|
|
27
|
-
},
|
|
28
|
-
name: "Tether USD"
|
|
29
|
-
},
|
|
30
|
-
SOL: {
|
|
31
|
-
pricing: {
|
|
32
|
-
binancePair: "SOLBTC",
|
|
33
|
-
okxPair: "SOL-BTC",
|
|
34
|
-
coinGeckoCoinId: "solana",
|
|
35
|
-
coinPaprikaCoinId: "sol-solana"
|
|
36
|
-
},
|
|
37
|
-
name: "Solana"
|
|
38
|
-
},
|
|
39
|
-
BONK: {
|
|
40
|
-
pricing: {
|
|
41
|
-
binancePair: "BONKUSDC;!BTCUSDC",
|
|
42
|
-
okxPair: null,
|
|
43
|
-
coinGeckoCoinId: "bonk",
|
|
44
|
-
coinPaprikaCoinId: "bonk-bonk"
|
|
45
|
-
},
|
|
46
|
-
name: "Bonk"
|
|
47
|
-
}
|
|
48
|
-
} as const;
|
|
49
|
-
|
|
50
|
-
export type SmartChainAssetTickers = keyof typeof SmartChainAssets;
|
|
51
|
-
|
|
52
|
-
export type AssetData = {
|
|
53
|
-
[ticker in SmartChainAssetTickers]?: {
|
|
54
|
-
address: string,
|
|
55
|
-
decimals: number
|
|
56
|
-
}
|
|
57
|
-
};
|
|
1
|
+
|
|
2
|
+
export const SmartChainAssets = {
|
|
3
|
+
WBTC: {
|
|
4
|
+
pricing: {
|
|
5
|
+
binancePair: "WBTCBTC",
|
|
6
|
+
okxPair: "$fixed-1",
|
|
7
|
+
coinGeckoCoinId: "wrapped-bitcoin",
|
|
8
|
+
coinPaprikaCoinId: "wbtc-wrapped-bitcoin"
|
|
9
|
+
},
|
|
10
|
+
name: "Wrapped BTC"
|
|
11
|
+
},
|
|
12
|
+
USDC: {
|
|
13
|
+
pricing: {
|
|
14
|
+
binancePair: "!BTCUSDC",
|
|
15
|
+
okxPair: "!BTC-USDC",
|
|
16
|
+
coinGeckoCoinId: "usd-coin",
|
|
17
|
+
coinPaprikaCoinId: "usdc-usd-coin"
|
|
18
|
+
},
|
|
19
|
+
name: "USD Circle"
|
|
20
|
+
},
|
|
21
|
+
USDT: {
|
|
22
|
+
pricing: {
|
|
23
|
+
binancePair: "!BTCUSDT",
|
|
24
|
+
okxPair: "!BTC-USDT",
|
|
25
|
+
coinGeckoCoinId: "tether",
|
|
26
|
+
coinPaprikaCoinId: "usdt-tether"
|
|
27
|
+
},
|
|
28
|
+
name: "Tether USD"
|
|
29
|
+
},
|
|
30
|
+
SOL: {
|
|
31
|
+
pricing: {
|
|
32
|
+
binancePair: "SOLBTC",
|
|
33
|
+
okxPair: "SOL-BTC",
|
|
34
|
+
coinGeckoCoinId: "solana",
|
|
35
|
+
coinPaprikaCoinId: "sol-solana"
|
|
36
|
+
},
|
|
37
|
+
name: "Solana"
|
|
38
|
+
},
|
|
39
|
+
BONK: {
|
|
40
|
+
pricing: {
|
|
41
|
+
binancePair: "BONKUSDC;!BTCUSDC",
|
|
42
|
+
okxPair: null,
|
|
43
|
+
coinGeckoCoinId: "bonk",
|
|
44
|
+
coinPaprikaCoinId: "bonk-bonk"
|
|
45
|
+
},
|
|
46
|
+
name: "Bonk"
|
|
47
|
+
}
|
|
48
|
+
} as const;
|
|
49
|
+
|
|
50
|
+
export type SmartChainAssetTickers = keyof typeof SmartChainAssets;
|
|
51
|
+
|
|
52
|
+
export type AssetData = {
|
|
53
|
+
[ticker in SmartChainAssetTickers]?: {
|
|
54
|
+
address: string,
|
|
55
|
+
decimals: number
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {BitcoinRpc, ChainType} from "@atomiqlabs/base";
|
|
2
|
-
import {BitcoinNetwork, CtorChainData, SwapperOptions} from "@atomiqlabs/sdk-lib";
|
|
3
|
-
import {AssetData} from "../SmartChainAssets";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type SdkChainType = {
|
|
7
|
-
ChainType: ChainType,
|
|
8
|
-
Options: {},
|
|
9
|
-
Assets: AssetData
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type SdkChain<T extends SdkChainType> = {
|
|
13
|
-
getCtorData: (options: SwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork) => CtorChainData<T["ChainType"]>,
|
|
14
|
-
assets: AssetData,
|
|
15
|
-
chainIdentifier: string
|
|
16
|
-
};
|
|
1
|
+
import {BitcoinRpc, ChainType} from "@atomiqlabs/base";
|
|
2
|
+
import {BitcoinNetwork, CtorChainData, SwapperOptions} from "@atomiqlabs/sdk-lib";
|
|
3
|
+
import {AssetData} from "../SmartChainAssets";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type SdkChainType = {
|
|
7
|
+
ChainType: ChainType,
|
|
8
|
+
Options: {},
|
|
9
|
+
Assets: AssetData
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type SdkChain<T extends SdkChainType> = {
|
|
13
|
+
getCtorData: (options: SwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork) => CtorChainData<T["ChainType"]>,
|
|
14
|
+
assets: AssetData,
|
|
15
|
+
chainIdentifier: string
|
|
16
|
+
};
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SolanaBtcRelay,
|
|
3
|
-
SolanaChainType, SolanaFees, SolanaRetryPolicy,
|
|
4
|
-
SolanaSwapData,
|
|
5
|
-
SolanaSwapProgram,
|
|
6
|
-
StoredDataAccount
|
|
7
|
-
} from "@atomiqlabs/chain-solana";
|
|
8
|
-
import {
|
|
9
|
-
BitcoinNetwork,
|
|
10
|
-
CtorChainData
|
|
11
|
-
} from "@atomiqlabs/sdk-lib";
|
|
12
|
-
import {BitcoinRpc, IStorageManager} from "@atomiqlabs/base";
|
|
13
|
-
import {Connection} from "@solana/web3.js";
|
|
14
|
-
import {SolanaChains} from "./SolanaChains";
|
|
15
|
-
import {SolanaChainEventsBrowser} from "@atomiqlabs/chain-solana/dist/solana/events/SolanaChainEventsBrowser";
|
|
16
|
-
import {SdkChain} from "../ChainInitializer";
|
|
17
|
-
import {MultichainSwapperOptions} from "../../MultichainSwapper";
|
|
18
|
-
|
|
19
|
-
const chainId = "SOLANA" as const;
|
|
20
|
-
|
|
21
|
-
type SolanaSwapperOptions = {
|
|
22
|
-
rpcUrl: string | Connection,
|
|
23
|
-
dataAccountStorage?: IStorageManager<StoredDataAccount>,
|
|
24
|
-
retryPolicy?: SolanaRetryPolicy,
|
|
25
|
-
|
|
26
|
-
btcRelayContract?: string,
|
|
27
|
-
swapContract?: string,
|
|
28
|
-
|
|
29
|
-
trustedIntermediary?: string,
|
|
30
|
-
|
|
31
|
-
fees?: SolanaFees
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
function getSolanaCtorData(options: MultichainSwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork): CtorChainData<SolanaChainType> {
|
|
35
|
-
const connection = typeof(options.chains.SOLANA.rpcUrl)==="string" ?
|
|
36
|
-
new Connection(options.chains.SOLANA.rpcUrl) :
|
|
37
|
-
options.chains.SOLANA.rpcUrl;
|
|
38
|
-
|
|
39
|
-
const Fees = options.chains.SOLANA.fees ?? new SolanaFees(connection, 200000, 4, 100);
|
|
40
|
-
const btcRelay = new SolanaBtcRelay(connection, bitcoinRpc, options.chains.SOLANA.btcRelayContract ?? SolanaChains[network].addresses.btcRelayContract, Fees);
|
|
41
|
-
const swapContract = new SolanaSwapProgram(
|
|
42
|
-
connection,
|
|
43
|
-
btcRelay,
|
|
44
|
-
options.chains.SOLANA.dataAccountStorage || options.storageCtor("solAccounts"),
|
|
45
|
-
options.chains.SOLANA.swapContract ?? SolanaChains[network].addresses.swapContract,
|
|
46
|
-
options.chains.SOLANA.retryPolicy ?? {transactionResendInterval: 1000},
|
|
47
|
-
Fees
|
|
48
|
-
)
|
|
49
|
-
const chainEvents = new SolanaChainEventsBrowser(connection, swapContract);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
btcRelay,
|
|
53
|
-
swapContract,
|
|
54
|
-
chainEvents,
|
|
55
|
-
swapDataConstructor: SolanaSwapData,
|
|
56
|
-
defaultTrustedIntermediaryUrl: options.chains.SOLANA.trustedIntermediary ?? SolanaChains[network].trustedSwapForGasUrl,
|
|
57
|
-
//These are defined here to keep the data from old SolLightning-sdk, not needed for other chains
|
|
58
|
-
storage: {
|
|
59
|
-
toBtc: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-ToBTC"),
|
|
60
|
-
toBtcLn: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-ToBTCLN"),
|
|
61
|
-
fromBtc: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-FromBTC"),
|
|
62
|
-
fromBtcLn: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-FromBTCLN"),
|
|
63
|
-
lnForGas: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-LnForGas")
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const SolanaAssets = {
|
|
69
|
-
WBTC: {
|
|
70
|
-
address: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
|
|
71
|
-
decimals: 8
|
|
72
|
-
},
|
|
73
|
-
USDC: {
|
|
74
|
-
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
75
|
-
decimals: 6
|
|
76
|
-
},
|
|
77
|
-
USDT: {
|
|
78
|
-
address: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
79
|
-
decimals: 6
|
|
80
|
-
},
|
|
81
|
-
SOL: {
|
|
82
|
-
address: "So11111111111111111111111111111111111111112",
|
|
83
|
-
decimals: 9
|
|
84
|
-
},
|
|
85
|
-
BONK: {
|
|
86
|
-
address: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
|
|
87
|
-
decimals: 5
|
|
88
|
-
}
|
|
89
|
-
} as const;
|
|
90
|
-
|
|
91
|
-
export type SdkSolanaType = {
|
|
92
|
-
ChainType: SolanaChainType,
|
|
93
|
-
Options: SolanaSwapperOptions,
|
|
94
|
-
Assets: typeof SolanaAssets
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const SdkSolana: SdkChain<SdkSolanaType> = {
|
|
98
|
-
getCtorData: getSolanaCtorData,
|
|
99
|
-
assets: SolanaAssets,
|
|
100
|
-
chainIdentifier: chainId
|
|
101
|
-
} as const;
|
|
1
|
+
import {
|
|
2
|
+
SolanaBtcRelay,
|
|
3
|
+
SolanaChainType, SolanaFees, SolanaRetryPolicy,
|
|
4
|
+
SolanaSwapData,
|
|
5
|
+
SolanaSwapProgram,
|
|
6
|
+
StoredDataAccount
|
|
7
|
+
} from "@atomiqlabs/chain-solana";
|
|
8
|
+
import {
|
|
9
|
+
BitcoinNetwork,
|
|
10
|
+
CtorChainData
|
|
11
|
+
} from "@atomiqlabs/sdk-lib";
|
|
12
|
+
import {BitcoinRpc, IStorageManager} from "@atomiqlabs/base";
|
|
13
|
+
import {Connection} from "@solana/web3.js";
|
|
14
|
+
import {SolanaChains} from "./SolanaChains";
|
|
15
|
+
import {SolanaChainEventsBrowser} from "@atomiqlabs/chain-solana/dist/solana/events/SolanaChainEventsBrowser";
|
|
16
|
+
import {SdkChain} from "../ChainInitializer";
|
|
17
|
+
import {MultichainSwapperOptions} from "../../MultichainSwapper";
|
|
18
|
+
|
|
19
|
+
const chainId = "SOLANA" as const;
|
|
20
|
+
|
|
21
|
+
type SolanaSwapperOptions = {
|
|
22
|
+
rpcUrl: string | Connection,
|
|
23
|
+
dataAccountStorage?: IStorageManager<StoredDataAccount>,
|
|
24
|
+
retryPolicy?: SolanaRetryPolicy,
|
|
25
|
+
|
|
26
|
+
btcRelayContract?: string,
|
|
27
|
+
swapContract?: string,
|
|
28
|
+
|
|
29
|
+
trustedIntermediary?: string,
|
|
30
|
+
|
|
31
|
+
fees?: SolanaFees
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function getSolanaCtorData(options: MultichainSwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork): CtorChainData<SolanaChainType> {
|
|
35
|
+
const connection = typeof(options.chains.SOLANA.rpcUrl)==="string" ?
|
|
36
|
+
new Connection(options.chains.SOLANA.rpcUrl) :
|
|
37
|
+
options.chains.SOLANA.rpcUrl;
|
|
38
|
+
|
|
39
|
+
const Fees = options.chains.SOLANA.fees ?? new SolanaFees(connection, 200000, 4, 100);
|
|
40
|
+
const btcRelay = new SolanaBtcRelay(connection, bitcoinRpc, options.chains.SOLANA.btcRelayContract ?? SolanaChains[network].addresses.btcRelayContract, Fees);
|
|
41
|
+
const swapContract = new SolanaSwapProgram(
|
|
42
|
+
connection,
|
|
43
|
+
btcRelay,
|
|
44
|
+
options.chains.SOLANA.dataAccountStorage || options.storageCtor("solAccounts"),
|
|
45
|
+
options.chains.SOLANA.swapContract ?? SolanaChains[network].addresses.swapContract,
|
|
46
|
+
options.chains.SOLANA.retryPolicy ?? {transactionResendInterval: 1000},
|
|
47
|
+
Fees
|
|
48
|
+
)
|
|
49
|
+
const chainEvents = new SolanaChainEventsBrowser(connection, swapContract);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
btcRelay,
|
|
53
|
+
swapContract,
|
|
54
|
+
chainEvents,
|
|
55
|
+
swapDataConstructor: SolanaSwapData,
|
|
56
|
+
defaultTrustedIntermediaryUrl: options.chains.SOLANA.trustedIntermediary ?? SolanaChains[network].trustedSwapForGasUrl,
|
|
57
|
+
//These are defined here to keep the data from old SolLightning-sdk, not needed for other chains
|
|
58
|
+
storage: {
|
|
59
|
+
toBtc: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-ToBTC"),
|
|
60
|
+
toBtcLn: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-ToBTCLN"),
|
|
61
|
+
fromBtc: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-FromBTC"),
|
|
62
|
+
fromBtcLn: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-FromBTCLN"),
|
|
63
|
+
lnForGas: options.storageCtor("SOLv4-"+options.bitcoinNetwork+"-Swaps-LnForGas")
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const SolanaAssets = {
|
|
69
|
+
WBTC: {
|
|
70
|
+
address: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
|
|
71
|
+
decimals: 8
|
|
72
|
+
},
|
|
73
|
+
USDC: {
|
|
74
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
75
|
+
decimals: 6
|
|
76
|
+
},
|
|
77
|
+
USDT: {
|
|
78
|
+
address: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
79
|
+
decimals: 6
|
|
80
|
+
},
|
|
81
|
+
SOL: {
|
|
82
|
+
address: "So11111111111111111111111111111111111111112",
|
|
83
|
+
decimals: 9
|
|
84
|
+
},
|
|
85
|
+
BONK: {
|
|
86
|
+
address: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
|
|
87
|
+
decimals: 5
|
|
88
|
+
}
|
|
89
|
+
} as const;
|
|
90
|
+
|
|
91
|
+
export type SdkSolanaType = {
|
|
92
|
+
ChainType: SolanaChainType,
|
|
93
|
+
Options: SolanaSwapperOptions,
|
|
94
|
+
Assets: typeof SolanaAssets
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const SdkSolana: SdkChain<SdkSolanaType> = {
|
|
98
|
+
getCtorData: getSolanaCtorData,
|
|
99
|
+
assets: SolanaAssets,
|
|
100
|
+
chainIdentifier: chainId
|
|
101
|
+
} as const;
|