@atomiqlabs/chain-solana 13.3.0 → 13.4.1
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/solana/SolanaChains.d.ts +1 -0
- package/dist/solana/SolanaChains.js +4 -2
- package/dist/solana/chain/SolanaChainInterface.d.ts +2 -1
- package/dist/solana/chain/SolanaChainInterface.js +22 -0
- package/package.json +2 -2
- package/src/solana/SolanaChains.ts +8 -3
- package/src/solana/chain/SolanaChainInterface.ts +26 -1
|
@@ -14,12 +14,14 @@ exports.SolanaChains = {
|
|
|
14
14
|
addresses: {
|
|
15
15
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
16
16
|
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
|
+
clusterName: "devnet"
|
|
18
19
|
},
|
|
19
20
|
[base_1.BitcoinNetwork.MAINNET]: {
|
|
20
21
|
addresses: {
|
|
21
22
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
22
23
|
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
23
|
-
}
|
|
24
|
+
},
|
|
25
|
+
clusterName: "mainnet-beta"
|
|
24
26
|
}
|
|
25
27
|
};
|
|
@@ -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";
|
|
@@ -212,4 +212,5 @@ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, Si
|
|
|
212
212
|
* @inheritDoc
|
|
213
213
|
*/
|
|
214
214
|
wrapSigner(signer: Wallet): Promise<SolanaSigner>;
|
|
215
|
+
verifyNetwork(bitcoinNetwork: BitcoinNetwork): Promise<void>;
|
|
215
216
|
}
|
|
@@ -10,9 +10,16 @@ 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
|
+
const CLUSTER_BY_GENESIS_HASH = {
|
|
19
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
20
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
21
|
+
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY": "testnet",
|
|
22
|
+
};
|
|
16
23
|
/**
|
|
17
24
|
* Main chain interface for interacting with Solana blockchain
|
|
18
25
|
* @category Chain Interface
|
|
@@ -234,5 +241,20 @@ class SolanaChainInterface {
|
|
|
234
241
|
wrapSigner(signer) {
|
|
235
242
|
return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
|
|
236
243
|
}
|
|
244
|
+
async verifyNetwork(bitcoinNetwork) {
|
|
245
|
+
const genesisHash = await this._connection.getGenesisHash();
|
|
246
|
+
const result = CLUSTER_BY_GENESIS_HASH[genesisHash];
|
|
247
|
+
if (result == null) {
|
|
248
|
+
this.logger.warn(`verifyNetwork(): Unknown cluster detected, genesis hash: ${genesisHash}`);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const deployment = SolanaChains_1.SolanaChains[bitcoinNetwork];
|
|
252
|
+
if (deployment == null) {
|
|
253
|
+
this.logger.warn(`verifyNetwork(): No Solana deployment is defined for ${base_1.BitcoinNetwork[bitcoinNetwork]}, the RPC check is skipped.`);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (deployment.clusterName !== result)
|
|
257
|
+
throw new Error(`Expected ${deployment.clusterName} Solana cluster for ${base_1.BitcoinNetwork[bitcoinNetwork]}, but got ${result}!`);
|
|
258
|
+
}
|
|
237
259
|
}
|
|
238
260
|
exports.SolanaChainInterface = SolanaChainInterface;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-solana",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.4.1",
|
|
4
4
|
"description": "Solana specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"author": "adambor",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@atomiqlabs/base": "^13.
|
|
29
|
+
"@atomiqlabs/base": "^13.4.0",
|
|
30
30
|
"@coral-xyz/anchor": "0.29.0",
|
|
31
31
|
"@noble/hashes": "^1.7.1",
|
|
32
32
|
"@solana/spl-token": "0.4.14",
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {BitcoinNetwork} from "@atomiqlabs/base";
|
|
2
2
|
|
|
3
|
-
export const SolanaChains: {[key in BitcoinNetwork]?: {
|
|
3
|
+
export const SolanaChains: {[key in BitcoinNetwork]?: {
|
|
4
|
+
addresses: {swapContract: string, btcRelayContract: string}
|
|
5
|
+
clusterName: "mainnet-beta" | "devnet" | "testnet"
|
|
6
|
+
}} = {
|
|
4
7
|
//TODO: Not deployed yet
|
|
5
8
|
// [BitcoinNetwork.TESTNET4]: {
|
|
6
9
|
// addresses: {
|
|
@@ -12,12 +15,14 @@ export const SolanaChains: {[key in BitcoinNetwork]?: {addresses: {swapContract:
|
|
|
12
15
|
addresses: {
|
|
13
16
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
14
17
|
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
15
|
-
}
|
|
18
|
+
},
|
|
19
|
+
clusterName: "devnet"
|
|
16
20
|
},
|
|
17
21
|
[BitcoinNetwork.MAINNET]: {
|
|
18
22
|
addresses: {
|
|
19
23
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
20
24
|
btcRelayContract: "3KHSHFpEK6bsjg3bqcxQ9qssJYtRCMi2S9TYVe4q6CQc"
|
|
21
|
-
}
|
|
25
|
+
},
|
|
26
|
+
clusterName: "mainnet-beta"
|
|
22
27
|
}
|
|
23
28
|
} as const;
|
|
@@ -7,12 +7,19 @@ import {SignedSolanaTx, SolanaTransactions, SolanaTx} from "./modules/SolanaTran
|
|
|
7
7
|
import {SolanaSignatures} from "./modules/SolanaSignatures";
|
|
8
8
|
import {SolanaEvents} from "./modules/SolanaEvents";
|
|
9
9
|
import {getLogger} from "../../utils/Utils";
|
|
10
|
-
import {ChainInterface, TransactionConfirmationOptions} from "@atomiqlabs/base";
|
|
10
|
+
import {BitcoinNetwork, ChainInterface, TransactionConfirmationOptions} from "@atomiqlabs/base";
|
|
11
11
|
import {SolanaAddresses} from "./modules/SolanaAddresses";
|
|
12
12
|
import {SolanaSigner} from "../wallet/SolanaSigner";
|
|
13
13
|
import {Buffer} from "buffer";
|
|
14
14
|
import {SolanaKeypairWallet} from "../wallet/SolanaKeypairWallet";
|
|
15
15
|
import {Wallet} from "@coral-xyz/anchor/dist/cjs/provider";
|
|
16
|
+
import {SolanaChains} from "../SolanaChains";
|
|
17
|
+
|
|
18
|
+
const CLUSTER_BY_GENESIS_HASH: Record<string, "mainnet-beta" | "devnet" | "testnet"> = {
|
|
19
|
+
"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d": "mainnet-beta",
|
|
20
|
+
"EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG": "devnet",
|
|
21
|
+
"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY": "testnet",
|
|
22
|
+
};
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* Retry policy configuration for Solana RPC calls
|
|
@@ -359,4 +366,22 @@ export class SolanaChainInterface implements ChainInterface<
|
|
|
359
366
|
return Promise.resolve(new SolanaSigner(signer));
|
|
360
367
|
}
|
|
361
368
|
|
|
369
|
+
async verifyNetwork(bitcoinNetwork: BitcoinNetwork): Promise<void> {
|
|
370
|
+
const genesisHash = await this._connection.getGenesisHash();
|
|
371
|
+
const result = CLUSTER_BY_GENESIS_HASH[genesisHash];
|
|
372
|
+
if(result==null) {
|
|
373
|
+
this.logger.warn(`verifyNetwork(): Unknown cluster detected, genesis hash: ${genesisHash}`);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const deployment = SolanaChains[bitcoinNetwork];
|
|
378
|
+
if(deployment==null) {
|
|
379
|
+
this.logger.warn(`verifyNetwork(): No Solana deployment is defined for ${BitcoinNetwork[bitcoinNetwork]}, the RPC check is skipped.`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if(deployment.clusterName!==result)
|
|
384
|
+
throw new Error(`Expected ${deployment.clusterName} Solana cluster for ${BitcoinNetwork[bitcoinNetwork]}, but got ${result}!`);
|
|
385
|
+
}
|
|
386
|
+
|
|
362
387
|
}
|