@atomiqlabs/chain-solana 13.3.0 → 13.5.6
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/solana/SolanaChainType.d.ts +1 -1
- package/dist/solana/SolanaChains.d.ts +5 -2
- package/dist/solana/SolanaChains.js +25 -13
- package/dist/solana/SolanaInitializer.d.ts +30 -4
- package/dist/solana/SolanaInitializer.js +105 -15
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +4 -2
- package/dist/solana/btcrelay/SolanaBtcRelay.js +7 -1
- package/dist/solana/chain/SolanaAction.d.ts +1 -1
- package/dist/solana/chain/SolanaAction.js +2 -2
- package/dist/solana/chain/SolanaChainInterface.d.ts +6 -1
- package/dist/solana/chain/SolanaChainInterface.js +30 -0
- package/dist/solana/events/SolanaChainEvents.d.ts +5 -1
- package/dist/solana/events/SolanaChainEvents.js +16 -6
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +39 -16
- package/dist/solana/events/SolanaChainEventsBrowser.js +96 -61
- package/dist/solana/swaps/SolanaSwapData.d.ts +50 -5
- package/dist/solana/swaps/SolanaSwapData.js +52 -8
- package/dist/solana/swaps/SolanaSwapModule.d.ts +4 -3
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +12 -6
- package/dist/solana/swaps/SolanaSwapProgram.js +73 -47
- package/dist/solana/swaps/modules/SwapClaim.js +2 -0
- package/dist/solana/swaps/modules/SwapInit.d.ts +10 -5
- package/dist/solana/swaps/modules/SwapInit.js +222 -85
- package/dist/solana/swaps/modules/SwapRefund.d.ts +8 -2
- package/dist/solana/swaps/modules/SwapRefund.js +38 -22
- package/dist/solana/swaps/v1/programIdl.json +945 -0
- package/dist/solana/swaps/v1/programTypes.d.ts +943 -0
- package/dist/solana/swaps/v1/programTypes.js +945 -0
- package/dist/solana/swaps/v2/programIdl.json +952 -0
- package/dist/solana/swaps/v2/programTypes.d.ts +950 -0
- package/dist/solana/swaps/v2/programTypes.js +952 -0
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/solana/SolanaChainType.ts +2 -2
- package/src/solana/SolanaChains.ts +29 -14
- package/src/solana/SolanaInitializer.ts +147 -25
- package/src/solana/btcrelay/SolanaBtcRelay.ts +10 -2
- package/src/solana/chain/SolanaAction.ts +2 -2
- package/src/solana/chain/SolanaChainInterface.ts +35 -1
- package/src/solana/events/SolanaChainEvents.ts +22 -11
- package/src/solana/events/SolanaChainEventsBrowser.ts +110 -67
- package/src/solana/swaps/SolanaSwapData.ts +95 -11
- package/src/solana/swaps/SolanaSwapModule.ts +5 -3
- package/src/solana/swaps/SolanaSwapProgram.ts +87 -43
- package/src/solana/swaps/modules/SolanaLpVault.ts +2 -2
- package/src/solana/swaps/modules/SwapClaim.ts +3 -1
- package/src/solana/swaps/modules/SwapInit.ts +227 -99
- package/src/solana/swaps/modules/SwapRefund.ts +38 -20
- package/src/solana/swaps/v2/programIdl.json +952 -0
- package/src/solana/swaps/v2/programTypes.ts +1899 -0
- /package/src/solana/swaps/{programIdl.json → v1/programIdl.json} +0 -0
- /package/src/solana/swaps/{programTypes.ts → v1/programTypes.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
* Initialize the Atomiq SDK with Solana network support:
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
|
-
* import {
|
|
45
|
+
* import {SolanaInitializerV2} from "@atomiqlabs/chain-solana";
|
|
46
46
|
* import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
|
|
47
47
|
*
|
|
48
48
|
* // Define chains that you want to support here
|
|
49
|
-
* const chains = [
|
|
49
|
+
* const chains = [SolanaInitializerV2] as const;
|
|
50
50
|
* type SupportedChains = typeof chains;
|
|
51
51
|
*
|
|
52
52
|
* const Factory = new SwapperFactory<SupportedChains>(chains);
|
package/dist/index.js
CHANGED
|
@@ -59,11 +59,11 @@ exports.SolanaSwapData = exports.SolanaChainEventsBrowser = exports.ConnectionWi
|
|
|
59
59
|
* Initialize the Atomiq SDK with Solana network support:
|
|
60
60
|
*
|
|
61
61
|
* ```ts
|
|
62
|
-
* import {
|
|
62
|
+
* import {SolanaInitializerV2} from "@atomiqlabs/chain-solana";
|
|
63
63
|
* import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
|
|
64
64
|
*
|
|
65
65
|
* // Define chains that you want to support here
|
|
66
|
-
* const chains = [
|
|
66
|
+
* const chains = [SolanaInitializerV2] as const;
|
|
67
67
|
* type SupportedChains = typeof chains;
|
|
68
68
|
*
|
|
69
69
|
* const Factory = new SwapperFactory<SupportedChains>(chains);
|
|
@@ -12,4 +12,4 @@ import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
|
12
12
|
* Type definition for the Solana chain implementation
|
|
13
13
|
* @category Chain Interface
|
|
14
14
|
*/
|
|
15
|
-
export type SolanaChainType = ChainType<"SOLANA", SolanaPreFetchData, SolanaPreFetchVerification, SolanaTx, SignedSolanaTx, SolanaSigner, Wallet, SolanaSwapData, SolanaSwapProgram
|
|
15
|
+
export type SolanaChainType<Version extends "v1" | "v2" = "v1"> = ChainType<"SOLANA", SolanaPreFetchData, SolanaPreFetchVerification, SolanaTx, SignedSolanaTx, SolanaSigner, Wallet, SolanaSwapData, SolanaSwapProgram<Version>, SolanaChainInterface, SolanaChainEventsBrowser, SolanaBtcRelay<any>, never, never, never>;
|
|
@@ -2,8 +2,11 @@ import { BitcoinNetwork } from "@atomiqlabs/base";
|
|
|
2
2
|
export declare const SolanaChains: {
|
|
3
3
|
[key in BitcoinNetwork]?: {
|
|
4
4
|
addresses: {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
[version in "v1" | "v2"]?: {
|
|
6
|
+
swapContract: string;
|
|
7
|
+
btcRelayContract: string;
|
|
8
|
+
};
|
|
7
9
|
};
|
|
10
|
+
clusterName: "mainnet-beta" | "devnet" | "testnet";
|
|
8
11
|
};
|
|
9
12
|
};
|
|
@@ -3,23 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SolanaChains = void 0;
|
|
4
4
|
const base_1 = require("@atomiqlabs/base");
|
|
5
5
|
exports.SolanaChains = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
[base_1.BitcoinNetwork.TESTNET4]: {
|
|
7
|
+
addresses: {
|
|
8
|
+
v1: {
|
|
9
|
+
swapContract: "7g6iDybm7XiiPidYwQ5DbuCREro39St52Xn7V3NV2EE4",
|
|
10
|
+
btcRelayContract: "CBYz9cgBG6v8kF19jhLk46gPRhY858NV1MfngzGzwgdX"
|
|
11
|
+
},
|
|
12
|
+
v2: {
|
|
13
|
+
swapContract: "8YiqJKjuS7zKPYoxdMFsfPpavPYCnu13Yx1CFqgV6o43",
|
|
14
|
+
btcRelayContract: "HKKJKW1jWh3DZptNSABZ4iKUvjxYvic4tb3qnqNvBZoF"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
clusterName: "devnet"
|
|
18
|
+
},
|
|
13
19
|
[base_1.BitcoinNetwork.TESTNET]: {
|
|
14
20
|
addresses: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
v1: {
|
|
22
|
+
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
23
|
+
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
clusterName: "devnet"
|
|
18
27
|
},
|
|
19
28
|
[base_1.BitcoinNetwork.MAINNET]: {
|
|
20
29
|
addresses: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
v1: {
|
|
31
|
+
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
32
|
+
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
clusterName: "mainnet-beta"
|
|
24
36
|
}
|
|
25
37
|
};
|
|
@@ -42,7 +42,7 @@ export type SolanaSwapperOptions = {
|
|
|
42
42
|
fees?: SolanaFees;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
|
-
* Initialize Solana chain integration
|
|
45
|
+
* Initialize Solana chain integration using the v1 as the default version of the contracts
|
|
46
46
|
*
|
|
47
47
|
* @param options Options for initializing the Solana chain
|
|
48
48
|
* @param bitcoinRpc Bitcoin RPC to use for bitcoin read access
|
|
@@ -53,16 +53,42 @@ export type SolanaSwapperOptions = {
|
|
|
53
53
|
*
|
|
54
54
|
* @category Chain Interface
|
|
55
55
|
*/
|
|
56
|
-
export declare function initializeSolana(options: SolanaSwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork, storageCtor: <T extends StorageObject>(name: string) => IStorageManager<T>): ChainData<SolanaChainType
|
|
56
|
+
export declare function initializeSolana(options: SolanaSwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork, storageCtor: <T extends StorageObject>(name: string) => IStorageManager<T>): ChainData<SolanaChainType<"v1">>;
|
|
57
|
+
/**
|
|
58
|
+
* Initialize Solana chain integration using the new v2 version as the default version of the contracts
|
|
59
|
+
*
|
|
60
|
+
* @param options Options for initializing the Solana chain
|
|
61
|
+
* @param bitcoinRpc Bitcoin RPC to use for bitcoin read access
|
|
62
|
+
* @param network Bitcoin network to use - determines Solana program addresses to use by default
|
|
63
|
+
* @param storageCtor Storage constructor used to create storage backend for ephemeral data submission accounts,
|
|
64
|
+
* i.e. accounts that are used to submit large amount of data to an instruction that would otherwise be bigger
|
|
65
|
+
* than the transaction size limit - used for submitting bitcoin transaction proofs for PrTLC swaps
|
|
66
|
+
*
|
|
67
|
+
* @category Chain Interface
|
|
68
|
+
*/
|
|
69
|
+
export declare function initializeSolanaV2(options: SolanaSwapperOptions, bitcoinRpc: BitcoinRpc<any>, network: BitcoinNetwork, storageCtor: <T extends StorageObject>(name: string) => IStorageManager<T>): ChainData<SolanaChainType<"v2">>;
|
|
57
70
|
/**
|
|
58
71
|
* Type definition for the Solana chain initializer
|
|
59
72
|
*
|
|
60
73
|
* @category Chain Interface
|
|
61
74
|
*/
|
|
62
|
-
export type SolanaInitializerType = ChainInitializer<SolanaSwapperOptions, SolanaChainType
|
|
75
|
+
export type SolanaInitializerType<Version extends "v1" | "v2" = "v1"> = ChainInitializer<SolanaSwapperOptions, SolanaChainType<Version>, SolanaAssetsType>;
|
|
63
76
|
/**
|
|
64
77
|
* Solana chain initializer instance, used in the SwapperFactory constructor in the SDK library
|
|
65
78
|
*
|
|
79
|
+
* Uses the legacy v1 version of the contract as the default exported version, this doesn't support the new
|
|
80
|
+
* v2 lightning network flow, use the {@link SolanaInitializerV2} to initialize the SDK with the v2
|
|
81
|
+
* contracts as the default, which do have an explicit support for new lightning network swap flow
|
|
82
|
+
*
|
|
83
|
+
* @category Chain Interface
|
|
84
|
+
*/
|
|
85
|
+
export declare const SolanaInitializer: SolanaInitializerType<"v1">;
|
|
86
|
+
/**
|
|
87
|
+
* Solana chain initializer instance, used in the SwapperFactory constructor in the SDK library
|
|
88
|
+
*
|
|
89
|
+
* Uses the new v2 version of the contracts as default exported version, supported the new lightning network
|
|
90
|
+
* swap flow.
|
|
91
|
+
*
|
|
66
92
|
* @category Chain Interface
|
|
67
93
|
*/
|
|
68
|
-
export declare const
|
|
94
|
+
export declare const SolanaInitializerV2: SolanaInitializerType<"v2">;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaInitializer = exports.initializeSolana = void 0;
|
|
3
|
+
exports.SolanaInitializerV2 = exports.SolanaInitializer = exports.initializeSolanaV2 = exports.initializeSolana = void 0;
|
|
4
4
|
const base_1 = require("@atomiqlabs/base");
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const SolanaChainInterface_1 = require("./chain/SolanaChainInterface");
|
|
@@ -36,6 +36,7 @@ const SolanaAssets = {
|
|
|
36
36
|
/**
|
|
37
37
|
* Initialize Solana chain integration
|
|
38
38
|
*
|
|
39
|
+
* @param version
|
|
39
40
|
* @param options Options for initializing the Solana chain
|
|
40
41
|
* @param bitcoinRpc Bitcoin RPC to use for bitcoin read access
|
|
41
42
|
* @param network Bitcoin network to use - determines Solana program addresses to use by default
|
|
@@ -45,34 +46,108 @@ const SolanaAssets = {
|
|
|
45
46
|
*
|
|
46
47
|
* @category Chain Interface
|
|
47
48
|
*/
|
|
48
|
-
function
|
|
49
|
+
function _initializeSolana(version, options, bitcoinRpc, network, storageCtor) {
|
|
49
50
|
const connection = typeof (options.rpcUrl) === "string" ?
|
|
50
51
|
new web3_js_1.Connection(options.rpcUrl) :
|
|
51
52
|
options.rpcUrl;
|
|
52
|
-
const solanaChainData = SolanaChains_1.SolanaChains[network];
|
|
53
|
-
if (solanaChainData == null)
|
|
54
|
-
throw new Error(`Unsupported bitcoin network for Solana: ${base_1.BitcoinNetwork[network]}`);
|
|
55
53
|
const Fees = options.fees ?? new SolanaFees_1.SolanaFees(connection, 200000, 4, 100);
|
|
56
54
|
const chainInterface = new SolanaChainInterface_1.SolanaChainInterface(connection, options.retryPolicy ?? { transactionResendInterval: 1000 }, Fees);
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const versionedContracts = {};
|
|
56
|
+
if (options.btcRelayContract || options.swapContract) {
|
|
57
|
+
// Initialize only that version
|
|
58
|
+
const btcRelayContractAddress = options.btcRelayContract ?? SolanaChains_1.SolanaChains[network]?.addresses[version]?.btcRelayContract;
|
|
59
|
+
const swapContractAddress = options.swapContract ?? SolanaChains_1.SolanaChains[network]?.addresses[version]?.swapContract;
|
|
60
|
+
if (btcRelayContractAddress == null)
|
|
61
|
+
throw new Error(`Unsupported bitcoin network for Solana, using default version ${version}: ${base_1.BitcoinNetwork[network]}, please pass a custom deployment btc relay program address!`);
|
|
62
|
+
if (swapContractAddress == null)
|
|
63
|
+
throw new Error(`Unsupported bitcoin network for Solana, using default version ${version}: ${base_1.BitcoinNetwork[network]}, please pass a custom deployment swap program address!`);
|
|
64
|
+
const btcRelay = new SolanaBtcRelay_1.SolanaBtcRelay(chainInterface, bitcoinRpc, btcRelayContractAddress);
|
|
65
|
+
const swapContract = new SolanaSwapProgram_1.SolanaSwapProgram(chainInterface, btcRelay, options.dataAccountStorage || storageCtor("solAccounts"), swapContractAddress, network, version);
|
|
66
|
+
versionedContracts[version] = {
|
|
67
|
+
btcRelay,
|
|
68
|
+
swapContract: swapContract,
|
|
69
|
+
swapDataConstructor: version === "v1" ? SolanaSwapData_1.SolanaSwapDataV1 : SolanaSwapData_1.SolanaSwapDataV2,
|
|
70
|
+
spvVaultContract: null,
|
|
71
|
+
spvVaultDataConstructor: null,
|
|
72
|
+
spvVaultWithdrawalDataConstructor: null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Initialize all versions
|
|
77
|
+
const solanaChainData = SolanaChains_1.SolanaChains[network];
|
|
78
|
+
if (solanaChainData == null)
|
|
79
|
+
throw new Error(`Unsupported bitcoin network for Solana: ${base_1.BitcoinNetwork[network]}, please pass a custom deployment program addresses!`);
|
|
80
|
+
for (let _version in solanaChainData.addresses) {
|
|
81
|
+
const version = _version;
|
|
82
|
+
const btcRelay = new SolanaBtcRelay_1.SolanaBtcRelay(chainInterface, bitcoinRpc, solanaChainData.addresses[version].btcRelayContract);
|
|
83
|
+
const swapContract = new SolanaSwapProgram_1.SolanaSwapProgram(chainInterface, btcRelay, options.dataAccountStorage || storageCtor("solAccounts"), solanaChainData.addresses[version].swapContract, network, version);
|
|
84
|
+
versionedContracts[version] = {
|
|
85
|
+
btcRelay,
|
|
86
|
+
swapContract: swapContract,
|
|
87
|
+
swapDataConstructor: version === "v1" ? SolanaSwapData_1.SolanaSwapDataV1 : SolanaSwapData_1.SolanaSwapDataV2,
|
|
88
|
+
spvVaultContract: null,
|
|
89
|
+
spvVaultDataConstructor: null,
|
|
90
|
+
spvVaultWithdrawalDataConstructor: null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const chainEvents = new SolanaChainEventsBrowser_1.SolanaChainEventsBrowser(connection, versionedContracts);
|
|
95
|
+
const defaults = versionedContracts[version];
|
|
96
|
+
if (defaults == null)
|
|
97
|
+
throw new Error(`Unsupported bitcoin network for Solana, using default version ${version}: ${base_1.BitcoinNetwork[network]}, please pass a custom deployment program addresses!`);
|
|
60
98
|
return {
|
|
61
99
|
chainId,
|
|
62
|
-
btcRelay,
|
|
63
|
-
swapContract,
|
|
64
|
-
chainEvents,
|
|
65
|
-
swapDataConstructor: SolanaSwapData_1.SolanaSwapData,
|
|
66
100
|
chainInterface,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
101
|
+
btcRelay: defaults.btcRelay,
|
|
102
|
+
swapContract: defaults.swapContract,
|
|
103
|
+
chainEvents,
|
|
104
|
+
swapDataConstructor: defaults.swapDataConstructor,
|
|
105
|
+
spvVaultContract: defaults.spvVaultContract,
|
|
106
|
+
spvVaultDataConstructor: defaults.spvVaultDataConstructor,
|
|
107
|
+
spvVaultWithdrawalDataConstructor: defaults.spvVaultWithdrawalDataConstructor,
|
|
108
|
+
defaultVersion: version,
|
|
109
|
+
versions: versionedContracts
|
|
70
110
|
};
|
|
71
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Initialize Solana chain integration using the v1 as the default version of the contracts
|
|
114
|
+
*
|
|
115
|
+
* @param options Options for initializing the Solana chain
|
|
116
|
+
* @param bitcoinRpc Bitcoin RPC to use for bitcoin read access
|
|
117
|
+
* @param network Bitcoin network to use - determines Solana program addresses to use by default
|
|
118
|
+
* @param storageCtor Storage constructor used to create storage backend for ephemeral data submission accounts,
|
|
119
|
+
* i.e. accounts that are used to submit large amount of data to an instruction that would otherwise be bigger
|
|
120
|
+
* than the transaction size limit - used for submitting bitcoin transaction proofs for PrTLC swaps
|
|
121
|
+
*
|
|
122
|
+
* @category Chain Interface
|
|
123
|
+
*/
|
|
124
|
+
function initializeSolana(options, bitcoinRpc, network, storageCtor) {
|
|
125
|
+
return _initializeSolana("v1", options, bitcoinRpc, network, storageCtor);
|
|
126
|
+
}
|
|
72
127
|
exports.initializeSolana = initializeSolana;
|
|
128
|
+
/**
|
|
129
|
+
* Initialize Solana chain integration using the new v2 version as the default version of the contracts
|
|
130
|
+
*
|
|
131
|
+
* @param options Options for initializing the Solana chain
|
|
132
|
+
* @param bitcoinRpc Bitcoin RPC to use for bitcoin read access
|
|
133
|
+
* @param network Bitcoin network to use - determines Solana program addresses to use by default
|
|
134
|
+
* @param storageCtor Storage constructor used to create storage backend for ephemeral data submission accounts,
|
|
135
|
+
* i.e. accounts that are used to submit large amount of data to an instruction that would otherwise be bigger
|
|
136
|
+
* than the transaction size limit - used for submitting bitcoin transaction proofs for PrTLC swaps
|
|
137
|
+
*
|
|
138
|
+
* @category Chain Interface
|
|
139
|
+
*/
|
|
140
|
+
function initializeSolanaV2(options, bitcoinRpc, network, storageCtor) {
|
|
141
|
+
return _initializeSolana("v2", options, bitcoinRpc, network, storageCtor);
|
|
142
|
+
}
|
|
143
|
+
exports.initializeSolanaV2 = initializeSolanaV2;
|
|
73
144
|
/**
|
|
74
145
|
* Solana chain initializer instance, used in the SwapperFactory constructor in the SDK library
|
|
75
146
|
*
|
|
147
|
+
* Uses the legacy v1 version of the contract as the default exported version, this doesn't support the new
|
|
148
|
+
* v2 lightning network flow, use the {@link SolanaInitializerV2} to initialize the SDK with the v2
|
|
149
|
+
* contracts as the default, which do have an explicit support for new lightning network swap flow
|
|
150
|
+
*
|
|
76
151
|
* @category Chain Interface
|
|
77
152
|
*/
|
|
78
153
|
exports.SolanaInitializer = {
|
|
@@ -82,3 +157,18 @@ exports.SolanaInitializer = {
|
|
|
82
157
|
tokens: SolanaAssets,
|
|
83
158
|
options: null
|
|
84
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Solana chain initializer instance, used in the SwapperFactory constructor in the SDK library
|
|
162
|
+
*
|
|
163
|
+
* Uses the new v2 version of the contracts as default exported version, supported the new lightning network
|
|
164
|
+
* swap flow.
|
|
165
|
+
*
|
|
166
|
+
* @category Chain Interface
|
|
167
|
+
*/
|
|
168
|
+
exports.SolanaInitializerV2 = {
|
|
169
|
+
chainId,
|
|
170
|
+
chainType: null,
|
|
171
|
+
initializer: initializeSolanaV2,
|
|
172
|
+
tokens: SolanaAssets,
|
|
173
|
+
options: null
|
|
174
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { PublicKey, Signer, Transaction } from "@solana/web3.js";
|
|
4
4
|
import { SolanaBtcStoredHeader } from "./headers/SolanaBtcStoredHeader";
|
|
5
|
-
import { BitcoinRpc, BtcBlock, BtcRelay } from "@atomiqlabs/base";
|
|
5
|
+
import { BitcoinNetwork, BitcoinRpc, BtcBlock, BtcRelay } from "@atomiqlabs/base";
|
|
6
6
|
import { SolanaProgramBase } from "../program/SolanaProgramBase";
|
|
7
7
|
import { SolanaAction } from "../chain/SolanaAction";
|
|
8
8
|
import { Buffer } from "buffer";
|
|
@@ -81,8 +81,10 @@ export declare class SolanaBtcRelay<B extends BtcBlock> extends SolanaProgramBas
|
|
|
81
81
|
* @param chainInterface Underlying chain interface to use for the Solana chain operations
|
|
82
82
|
* @param bitcoinRpc Bitcoin RPC instance to use for read access to the bitcoin blockchain
|
|
83
83
|
* @param programAddress Optional Solana on-chain program address, defaults to the cannonical deployment
|
|
84
|
+
* @param bitcoinNetwork
|
|
85
|
+
* @param contractVersion
|
|
84
86
|
*/
|
|
85
|
-
constructor(chainInterface: SolanaChainInterface, bitcoinRpc: BitcoinRpc<B>, programAddress?: string);
|
|
87
|
+
constructor(chainInterface: SolanaChainInterface, bitcoinRpc: BitcoinRpc<B>, programAddress?: string, bitcoinNetwork?: BitcoinNetwork, contractVersion?: "v1" | "v2");
|
|
86
88
|
/**
|
|
87
89
|
* Gets set of block commitments representing current main chain from the mainState
|
|
88
90
|
*
|
|
@@ -11,6 +11,7 @@ const SolanaAction_1 = require("../chain/SolanaAction");
|
|
|
11
11
|
const buffer_1 = require("buffer");
|
|
12
12
|
const BN = require("bn.js");
|
|
13
13
|
const SolanaFees_1 = require("../chain/modules/SolanaFees");
|
|
14
|
+
const SolanaChains_1 = require("../SolanaChains");
|
|
14
15
|
const MAX_CLOSE_IX_PER_TX = 10;
|
|
15
16
|
function serializeBlockHeader(e) {
|
|
16
17
|
return new SolanaBtcHeader_1.SolanaBtcHeader({
|
|
@@ -92,8 +93,13 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
92
93
|
* @param chainInterface Underlying chain interface to use for the Solana chain operations
|
|
93
94
|
* @param bitcoinRpc Bitcoin RPC instance to use for read access to the bitcoin blockchain
|
|
94
95
|
* @param programAddress Optional Solana on-chain program address, defaults to the cannonical deployment
|
|
96
|
+
* @param bitcoinNetwork
|
|
97
|
+
* @param contractVersion
|
|
95
98
|
*/
|
|
96
|
-
constructor(chainInterface, bitcoinRpc, programAddress) {
|
|
99
|
+
constructor(chainInterface, bitcoinRpc, programAddress, bitcoinNetwork, contractVersion) {
|
|
100
|
+
if (bitcoinNetwork != null && programAddress == null) {
|
|
101
|
+
programAddress = SolanaChains_1.SolanaChains[bitcoinNetwork]?.addresses[contractVersion ?? "v1"]?.btcRelayContract;
|
|
102
|
+
}
|
|
97
103
|
super(chainInterface, programIdl, programAddress);
|
|
98
104
|
/**
|
|
99
105
|
* PDA of the relay main state account.
|
|
@@ -13,7 +13,7 @@ export declare class SolanaAction {
|
|
|
13
13
|
private estimateFee;
|
|
14
14
|
addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]): void;
|
|
15
15
|
add(action: SolanaAction): this;
|
|
16
|
-
addAction(action: SolanaAction, index?: number): this;
|
|
16
|
+
addAction(action: SolanaAction, index?: number, noSignerCheck?: boolean): this;
|
|
17
17
|
tx(feeRate?: string, block?: {
|
|
18
18
|
blockhash: string;
|
|
19
19
|
blockHeight: number;
|
|
@@ -33,7 +33,7 @@ class SolanaAction {
|
|
|
33
33
|
add(action) {
|
|
34
34
|
return this.addAction(action);
|
|
35
35
|
}
|
|
36
|
-
addAction(action, index = this.instructions.length) {
|
|
36
|
+
addAction(action, index = this.instructions.length, noSignerCheck) {
|
|
37
37
|
if (action.firstIxBeforeComputeBudget) {
|
|
38
38
|
if (this.instructions.length > 0)
|
|
39
39
|
throw new Error("Tried to add firstIxBeforeComputeBudget action to existing action with instructions");
|
|
@@ -41,7 +41,7 @@ class SolanaAction {
|
|
|
41
41
|
}
|
|
42
42
|
if (this.firstIxBeforeComputeBudget && this.instructions.length > 0 && index === 0)
|
|
43
43
|
throw new Error("Tried adding to firstIxBeforeComputeBudget action on 0th index");
|
|
44
|
-
if (!action.mainSigner.equals(this.mainSigner))
|
|
44
|
+
if (!noSignerCheck && !action.mainSigner.equals(this.mainSigner))
|
|
45
45
|
throw new Error("Actions need to have the same signer!");
|
|
46
46
|
if (this.computeBudget == null && action.computeBudget != null)
|
|
47
47
|
this.computeBudget = action.computeBudget;
|
|
@@ -8,7 +8,7 @@ import { SolanaTokens } from "./modules/SolanaTokens";
|
|
|
8
8
|
import { SignedSolanaTx, SolanaTransactions, SolanaTx } from "./modules/SolanaTransactions";
|
|
9
9
|
import { SolanaSignatures } from "./modules/SolanaSignatures";
|
|
10
10
|
import { SolanaEvents } from "./modules/SolanaEvents";
|
|
11
|
-
import { ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
|
|
11
|
+
import { BitcoinNetwork, ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
|
|
12
12
|
import { SolanaSigner } from "../wallet/SolanaSigner";
|
|
13
13
|
import { Buffer } from "buffer";
|
|
14
14
|
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
@@ -153,6 +153,10 @@ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, Si
|
|
|
153
153
|
* @inheritDoc
|
|
154
154
|
*/
|
|
155
155
|
deserializeSignedTx(txData: string): Promise<Transaction>;
|
|
156
|
+
/**
|
|
157
|
+
* @inheritDoc
|
|
158
|
+
*/
|
|
159
|
+
getTxId(signedTX: SignedSolanaTx): Promise<string>;
|
|
156
160
|
/**
|
|
157
161
|
* @inheritDoc
|
|
158
162
|
*/
|
|
@@ -212,4 +216,5 @@ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, Si
|
|
|
212
216
|
* @inheritDoc
|
|
213
217
|
*/
|
|
214
218
|
wrapSigner(signer: Wallet): Promise<SolanaSigner>;
|
|
219
|
+
verifyNetwork(bitcoinNetwork: BitcoinNetwork): Promise<void>;
|
|
215
220
|
}
|
|
@@ -10,9 +10,18 @@ const SolanaTransactions_1 = require("./modules/SolanaTransactions");
|
|
|
10
10
|
const SolanaSignatures_1 = require("./modules/SolanaSignatures");
|
|
11
11
|
const SolanaEvents_1 = require("./modules/SolanaEvents");
|
|
12
12
|
const Utils_1 = require("../../utils/Utils");
|
|
13
|
+
const base_1 = require("@atomiqlabs/base");
|
|
13
14
|
const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
14
15
|
const SolanaSigner_1 = require("../wallet/SolanaSigner");
|
|
15
16
|
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
17
|
+
const SolanaChains_1 = require("../SolanaChains");
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const bs58 = require("bs58");
|
|
20
|
+
const CLUSTER_BY_GENESIS_HASH = {
|
|
21
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
22
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
23
|
+
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY": "testnet",
|
|
24
|
+
};
|
|
16
25
|
/**
|
|
17
26
|
* Main chain interface for interacting with Solana blockchain
|
|
18
27
|
* @category Chain Interface
|
|
@@ -140,6 +149,12 @@ class SolanaChainInterface {
|
|
|
140
149
|
deserializeSignedTx(txData) {
|
|
141
150
|
return Promise.resolve(this.Transactions.deserializeSignedTransaction(txData));
|
|
142
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* @inheritDoc
|
|
154
|
+
*/
|
|
155
|
+
getTxId(signedTX) {
|
|
156
|
+
return Promise.resolve(bs58.encode(signedTX.signature));
|
|
157
|
+
}
|
|
143
158
|
/**
|
|
144
159
|
* @inheritDoc
|
|
145
160
|
*/
|
|
@@ -234,5 +249,20 @@ class SolanaChainInterface {
|
|
|
234
249
|
wrapSigner(signer) {
|
|
235
250
|
return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
|
|
236
251
|
}
|
|
252
|
+
async verifyNetwork(bitcoinNetwork) {
|
|
253
|
+
const genesisHash = await this._connection.getGenesisHash();
|
|
254
|
+
const result = CLUSTER_BY_GENESIS_HASH[genesisHash];
|
|
255
|
+
if (result == null) {
|
|
256
|
+
this.logger.warn(`verifyNetwork(): Unknown cluster detected, genesis hash: ${genesisHash}`);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const deployment = SolanaChains_1.SolanaChains[bitcoinNetwork];
|
|
260
|
+
if (deployment == null) {
|
|
261
|
+
this.logger.warn(`verifyNetwork(): No Solana deployment is defined for ${base_1.BitcoinNetwork[bitcoinNetwork]}, the RPC check is skipped.`);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (deployment.clusterName !== result)
|
|
265
|
+
throw new Error(`Expected ${deployment.clusterName} Solana cluster for ${base_1.BitcoinNetwork[bitcoinNetwork]}, but got ${result}!`);
|
|
266
|
+
}
|
|
237
267
|
}
|
|
238
268
|
exports.SolanaChainInterface = SolanaChainInterface;
|
|
@@ -10,7 +10,11 @@ export declare class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
10
10
|
private readonly logFetchInterval;
|
|
11
11
|
private stopped;
|
|
12
12
|
private timeout?;
|
|
13
|
-
constructor(directory: string, connection: Connection,
|
|
13
|
+
constructor(directory: string, connection: Connection, contractVersions: SolanaSwapProgram | {
|
|
14
|
+
[version: string]: {
|
|
15
|
+
swapContract: SolanaSwapProgram;
|
|
16
|
+
};
|
|
17
|
+
}, logFetchInterval?: number);
|
|
14
18
|
/**
|
|
15
19
|
* Retrieves last signature & slot from filesystem
|
|
16
20
|
*
|
|
@@ -10,8 +10,8 @@ const LOG_FETCH_INTERVAL = 5 * 1000;
|
|
|
10
10
|
* any events
|
|
11
11
|
*/
|
|
12
12
|
class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrowser {
|
|
13
|
-
constructor(directory, connection,
|
|
14
|
-
super(connection,
|
|
13
|
+
constructor(directory, connection, contractVersions, logFetchInterval) {
|
|
14
|
+
super(connection, contractVersions);
|
|
15
15
|
this.stopped = true;
|
|
16
16
|
this.directory = directory;
|
|
17
17
|
this.logFetchInterval = logFetchInterval || LOG_FETCH_INTERVAL;
|
|
@@ -22,8 +22,18 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
22
22
|
* @private
|
|
23
23
|
*/
|
|
24
24
|
async getLastSignature() {
|
|
25
|
+
let txt;
|
|
26
|
+
try {
|
|
27
|
+
txt = (await fs.readFile(this.directory + BLOCKHEIGHT_FILENAME)).toString();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(txt);
|
|
34
|
+
}
|
|
35
|
+
catch (e) { }
|
|
25
36
|
try {
|
|
26
|
-
const txt = (await fs.readFile(this.directory + BLOCKHEIGHT_FILENAME)).toString();
|
|
27
37
|
const arr = txt.split(";");
|
|
28
38
|
if (arr.length < 2)
|
|
29
39
|
return {
|
|
@@ -44,8 +54,8 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
44
54
|
*
|
|
45
55
|
* @private
|
|
46
56
|
*/
|
|
47
|
-
saveLastSignature(
|
|
48
|
-
return fs.writeFile(this.directory + BLOCKHEIGHT_FILENAME,
|
|
57
|
+
saveLastSignature(lastState) {
|
|
58
|
+
return fs.writeFile(this.directory + BLOCKHEIGHT_FILENAME, JSON.stringify(lastState));
|
|
49
59
|
}
|
|
50
60
|
/**
|
|
51
61
|
* Polls for new events & processes them
|
|
@@ -56,7 +66,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
56
66
|
const lastSignature = await this.getLastSignature();
|
|
57
67
|
const result = await this.poll(lastSignature ?? undefined);
|
|
58
68
|
if (result != null) {
|
|
59
|
-
await this.saveLastSignature(result
|
|
69
|
+
await this.saveLastSignature(result);
|
|
60
70
|
}
|
|
61
71
|
}
|
|
62
72
|
async setupHttpPolling() {
|