@atomiqlabs/chain-solana 13.4.1 → 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 +4 -2
- package/dist/solana/SolanaChains.js +21 -11
- 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 +4 -0
- package/dist/solana/chain/SolanaChainInterface.js +8 -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 +22 -12
- 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 +9 -0
- 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,10 @@ 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
|
};
|
|
8
10
|
clusterName: "mainnet-beta" | "devnet" | "testnet";
|
|
9
11
|
};
|
|
@@ -3,24 +3,34 @@ 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
|
-
|
|
21
|
+
v1: {
|
|
22
|
+
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
23
|
+
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
24
|
+
}
|
|
17
25
|
},
|
|
18
26
|
clusterName: "devnet"
|
|
19
27
|
},
|
|
20
28
|
[base_1.BitcoinNetwork.MAINNET]: {
|
|
21
29
|
addresses: {
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
v1: {
|
|
31
|
+
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
32
|
+
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
33
|
+
}
|
|
24
34
|
},
|
|
25
35
|
clusterName: "mainnet-beta"
|
|
26
36
|
}
|
|
@@ -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;
|
|
@@ -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
|
*/
|
|
@@ -15,6 +15,8 @@ const SolanaAddresses_1 = require("./modules/SolanaAddresses");
|
|
|
15
15
|
const SolanaSigner_1 = require("../wallet/SolanaSigner");
|
|
16
16
|
const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
|
|
17
17
|
const SolanaChains_1 = require("../SolanaChains");
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const bs58 = require("bs58");
|
|
18
20
|
const CLUSTER_BY_GENESIS_HASH = {
|
|
19
21
|
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
20
22
|
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
@@ -147,6 +149,12 @@ class SolanaChainInterface {
|
|
|
147
149
|
deserializeSignedTx(txData) {
|
|
148
150
|
return Promise.resolve(this.Transactions.deserializeSignedTransaction(txData));
|
|
149
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* @inheritDoc
|
|
154
|
+
*/
|
|
155
|
+
getTxId(signedTX) {
|
|
156
|
+
return Promise.resolve(bs58.encode(signedTX.signature));
|
|
157
|
+
}
|
|
150
158
|
/**
|
|
151
159
|
* @inheritDoc
|
|
152
160
|
*/
|
|
@@ -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() {
|
|
@@ -4,7 +4,7 @@ import { IdlEvents } from "@coral-xyz/anchor";
|
|
|
4
4
|
import { SolanaSwapProgram } from "../swaps/SolanaSwapProgram";
|
|
5
5
|
import { Connection } from "@solana/web3.js";
|
|
6
6
|
import { InstructionWithAccounts, ProgramEvent } from "../program/modules/SolanaProgramEvents";
|
|
7
|
-
import { SwapProgram } from "../swaps/programTypes";
|
|
7
|
+
import { SwapProgram } from "../swaps/v1/programTypes";
|
|
8
8
|
/**
|
|
9
9
|
* Parsed event payload grouped by originating transaction metadata.
|
|
10
10
|
*
|
|
@@ -17,11 +17,11 @@ export type EventObject = {
|
|
|
17
17
|
signature: string;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Legacy current cursor of Solana event listener state.
|
|
21
21
|
*
|
|
22
22
|
* @category Events
|
|
23
23
|
*/
|
|
24
|
-
export type
|
|
24
|
+
export type SolanaLegacyEventListenerState = {
|
|
25
25
|
/**
|
|
26
26
|
* Last processed transaction's signature
|
|
27
27
|
*/
|
|
@@ -31,6 +31,14 @@ export type SolanaEventListenerState = {
|
|
|
31
31
|
*/
|
|
32
32
|
slot: number;
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Current cursor of Solana event listener state.
|
|
36
|
+
*
|
|
37
|
+
* @category Events
|
|
38
|
+
*/
|
|
39
|
+
export type SolanaEventListenerState = {
|
|
40
|
+
[version: string]: SolanaLegacyEventListenerState | null;
|
|
41
|
+
};
|
|
34
42
|
/**
|
|
35
43
|
* Solana on-chain event handler for front-end systems without access to fs, uses pure WS to subscribe, might lose
|
|
36
44
|
* out on some events if the network is unreliable, front-end systems should take this into consideration and not
|
|
@@ -38,7 +46,7 @@ export type SolanaEventListenerState = {
|
|
|
38
46
|
*
|
|
39
47
|
* @category Events
|
|
40
48
|
*/
|
|
41
|
-
export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapData, SolanaEventListenerState> {
|
|
49
|
+
export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapData, SolanaLegacyEventListenerState | SolanaEventListenerState> {
|
|
42
50
|
/**
|
|
43
51
|
* @internal
|
|
44
52
|
*/
|
|
@@ -50,11 +58,17 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
50
58
|
/**
|
|
51
59
|
* @internal
|
|
52
60
|
*/
|
|
53
|
-
protected readonly
|
|
61
|
+
protected readonly contractVersions: {
|
|
62
|
+
[version: string]: {
|
|
63
|
+
swapContract: SolanaSwapProgram;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
54
66
|
/**
|
|
55
67
|
* @internal
|
|
56
68
|
*/
|
|
57
|
-
protected eventListeners:
|
|
69
|
+
protected eventListeners: {
|
|
70
|
+
[version: string]: number[];
|
|
71
|
+
};
|
|
58
72
|
/**
|
|
59
73
|
* @internal
|
|
60
74
|
*/
|
|
@@ -62,21 +76,24 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
62
76
|
debug: (msg: string, ...args: any[]) => false | void;
|
|
63
77
|
info: (msg: string, ...args: any[]) => false | void;
|
|
64
78
|
warn: (msg: string, ...args: any[]) => false | void;
|
|
65
|
-
error: (msg: string, ...args: any[]) => false | void;
|
|
66
|
-
* @internal
|
|
67
|
-
*/
|
|
79
|
+
error: (msg: string, ...args: any[]) => false | void;
|
|
68
80
|
};
|
|
69
81
|
private readonly logFetchLimit;
|
|
70
82
|
private signaturesProcessing;
|
|
71
83
|
private processedSignatures;
|
|
72
84
|
private processedSignaturesIndex;
|
|
73
|
-
constructor(connection: Connection,
|
|
85
|
+
constructor(connection: Connection, contractVersions: SolanaSwapProgram | {
|
|
86
|
+
[version: string]: {
|
|
87
|
+
swapContract: SolanaSwapProgram;
|
|
88
|
+
};
|
|
89
|
+
}, logFetchLimit?: number);
|
|
74
90
|
private addProcessedSignature;
|
|
75
91
|
private isSignatureProcessed;
|
|
76
92
|
/**
|
|
77
93
|
* Parses EventObject from the transaction
|
|
78
94
|
*
|
|
79
95
|
* @param transaction
|
|
96
|
+
* @param version
|
|
80
97
|
* @private
|
|
81
98
|
* @returns {EventObject} parsed event object
|
|
82
99
|
*/
|
|
@@ -85,6 +102,7 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
85
102
|
* Fetches transaction from the RPC, parses it to even object & processes it through event handler
|
|
86
103
|
*
|
|
87
104
|
* @param signature
|
|
105
|
+
* @param version
|
|
88
106
|
* @private
|
|
89
107
|
* @returns {boolean} whether the operation was successful
|
|
90
108
|
*/
|
|
@@ -101,6 +119,7 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
101
119
|
*
|
|
102
120
|
* @param eventObject
|
|
103
121
|
* @param txoHash
|
|
122
|
+
* @param version
|
|
104
123
|
* @private
|
|
105
124
|
* @returns {() => Promise<SolanaSwapData>} getter to be passed to InitializeEvent constructor
|
|
106
125
|
*/
|
|
@@ -108,30 +127,32 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
108
127
|
/**
|
|
109
128
|
* @internal
|
|
110
129
|
*/
|
|
111
|
-
protected parseInitializeEvent(data: IdlEvents<SwapProgram>["InitializeEvent"], eventObject: EventObject): InitializeEvent<SolanaSwapData>;
|
|
130
|
+
protected parseInitializeEvent(data: IdlEvents<SwapProgram>["InitializeEvent"], eventObject: EventObject, version: string): InitializeEvent<SolanaSwapData>;
|
|
112
131
|
/**
|
|
113
132
|
* @internal
|
|
114
133
|
*/
|
|
115
|
-
protected parseRefundEvent(data: IdlEvents<SwapProgram>["RefundEvent"]): RefundEvent<SolanaSwapData>;
|
|
134
|
+
protected parseRefundEvent(data: IdlEvents<SwapProgram>["RefundEvent"], version: string): RefundEvent<SolanaSwapData>;
|
|
116
135
|
/**
|
|
117
136
|
* @internal
|
|
118
137
|
*/
|
|
119
|
-
protected parseClaimEvent(data: IdlEvents<SwapProgram>["ClaimEvent"]): ClaimEvent<SolanaSwapData>;
|
|
138
|
+
protected parseClaimEvent(data: IdlEvents<SwapProgram>["ClaimEvent"], version: string): ClaimEvent<SolanaSwapData>;
|
|
120
139
|
/**
|
|
121
140
|
* Processes event as received from the chain, parses it & calls event listeners
|
|
122
141
|
*
|
|
123
142
|
* @param eventObject
|
|
143
|
+
* @param version
|
|
124
144
|
* @internal
|
|
125
145
|
*/
|
|
126
|
-
protected processEvent(eventObject: EventObject): Promise<void>;
|
|
146
|
+
protected processEvent(eventObject: EventObject, version: string): Promise<void>;
|
|
127
147
|
/**
|
|
128
148
|
* Returns websocket event handler for specific event type
|
|
129
149
|
*
|
|
130
150
|
* @param name
|
|
151
|
+
* @param version
|
|
131
152
|
* @internal
|
|
132
153
|
* @returns event handler to be passed to program's addEventListener function
|
|
133
154
|
*/
|
|
134
|
-
protected getWsEventHandler<E extends "InitializeEvent" | "RefundEvent" | "ClaimEvent">(name: E): (data: IdlEvents<SwapProgram>[E], slotNumber: number, signature: string) => void;
|
|
155
|
+
protected getWsEventHandler<E extends "InitializeEvent" | "RefundEvent" | "ClaimEvent">(name: E, version: string): (data: IdlEvents<SwapProgram>[E], slotNumber: number, signature: string) => void;
|
|
135
156
|
/**
|
|
136
157
|
* Sets up event handlers listening for swap events over websocket
|
|
137
158
|
*
|
|
@@ -142,6 +163,7 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
142
163
|
* Gets all the new signatures from the last processed signature
|
|
143
164
|
*
|
|
144
165
|
* @param lastProcessedSignature
|
|
166
|
+
* @param version
|
|
145
167
|
* @private
|
|
146
168
|
*/
|
|
147
169
|
private getNewSignatures;
|
|
@@ -155,6 +177,7 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
155
177
|
* Processes signatures, fetches transactions & processes event through event handlers
|
|
156
178
|
*
|
|
157
179
|
* @param signatures
|
|
180
|
+
* @param version
|
|
158
181
|
* @private
|
|
159
182
|
* @returns {Promise<{signature: string, slot: number}>} latest processed transaction signature and slot height
|
|
160
183
|
*/
|
|
@@ -162,7 +185,7 @@ export declare class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapD
|
|
|
162
185
|
/**
|
|
163
186
|
* @inheritDoc
|
|
164
187
|
*/
|
|
165
|
-
poll(lastSignature?: SolanaEventListenerState): Promise<SolanaEventListenerState
|
|
188
|
+
poll(lastSignature?: SolanaLegacyEventListenerState | SolanaEventListenerState): Promise<SolanaEventListenerState>;
|
|
166
189
|
/**
|
|
167
190
|
* @inheritDoc
|
|
168
191
|
*/
|