@atomiqlabs/chain-solana 10.0.0-dev.3 → 11.0.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/dist/index.d.ts +29 -29
- package/dist/index.js +45 -45
- package/dist/solana/SolanaChainType.d.ts +10 -10
- package/dist/solana/SolanaChainType.js +2 -2
- package/dist/solana/SolanaChains.d.ts +20 -20
- package/dist/solana/SolanaChains.js +25 -25
- package/dist/solana/SolanaInitializer.d.ts +18 -18
- package/dist/solana/SolanaInitializer.js +63 -63
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +228 -228
- package/dist/solana/btcrelay/SolanaBtcRelay.js +441 -441
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +29 -29
- package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +34 -34
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +46 -46
- package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +78 -78
- package/dist/solana/btcrelay/program/programIdl.json +671 -671
- package/dist/solana/chain/SolanaAction.d.ts +26 -26
- package/dist/solana/chain/SolanaAction.js +86 -86
- package/dist/solana/chain/SolanaChainInterface.d.ts +58 -58
- package/dist/solana/chain/SolanaChainInterface.js +112 -112
- package/dist/solana/chain/SolanaModule.d.ts +14 -14
- package/dist/solana/chain/SolanaModule.js +13 -13
- package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
- package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
- package/dist/solana/chain/modules/SolanaBlocks.d.ts +28 -28
- package/dist/solana/chain/modules/SolanaBlocks.js +72 -72
- package/dist/solana/chain/modules/SolanaEvents.d.ts +25 -25
- package/dist/solana/chain/modules/SolanaEvents.js +58 -58
- package/dist/solana/chain/modules/SolanaFees.d.ts +121 -121
- package/dist/solana/chain/modules/SolanaFees.js +379 -379
- package/dist/solana/chain/modules/SolanaSignatures.d.ts +23 -23
- package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
- package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
- package/dist/solana/chain/modules/SolanaSlots.js +68 -68
- package/dist/solana/chain/modules/SolanaTokens.d.ts +136 -136
- package/dist/solana/chain/modules/SolanaTokens.js +248 -248
- package/dist/solana/chain/modules/SolanaTransactions.d.ts +124 -124
- package/dist/solana/chain/modules/SolanaTransactions.js +332 -332
- package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
- package/dist/solana/events/SolanaChainEvents.js +256 -256
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +85 -85
- package/dist/solana/events/SolanaChainEventsBrowser.js +194 -194
- package/dist/solana/program/SolanaProgramBase.d.ts +40 -40
- package/dist/solana/program/SolanaProgramBase.js +43 -43
- package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
- package/dist/solana/program/SolanaProgramModule.js +11 -11
- package/dist/solana/program/modules/SolanaProgramEvents.d.ts +59 -59
- package/dist/solana/program/modules/SolanaProgramEvents.js +103 -103
- package/dist/solana/swaps/SolanaSwapData.d.ts +59 -59
- package/dist/solana/swaps/SolanaSwapData.js +267 -267
- package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
- package/dist/solana/swaps/SolanaSwapModule.js +11 -11
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +202 -202
- package/dist/solana/swaps/SolanaSwapProgram.js +470 -463
- package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
- package/dist/solana/swaps/SwapTypeEnum.js +42 -42
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +94 -94
- package/dist/solana/swaps/modules/SolanaDataAccount.js +231 -231
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +71 -71
- package/dist/solana/swaps/modules/SolanaLpVault.js +173 -173
- package/dist/solana/swaps/modules/SwapClaim.d.ts +129 -129
- package/dist/solana/swaps/modules/SwapClaim.js +291 -291
- package/dist/solana/swaps/modules/SwapInit.d.ts +217 -217
- package/dist/solana/swaps/modules/SwapInit.js +519 -519
- package/dist/solana/swaps/modules/SwapRefund.d.ts +82 -82
- package/dist/solana/swaps/modules/SwapRefund.js +252 -252
- package/dist/solana/swaps/programIdl.json +945 -945
- package/dist/solana/swaps/programTypes.d.ts +943 -943
- package/dist/solana/swaps/programTypes.js +945 -945
- package/dist/solana/wallet/SolanaKeypairWallet.d.ts +9 -9
- package/dist/solana/wallet/SolanaKeypairWallet.js +33 -33
- package/dist/solana/wallet/SolanaSigner.d.ts +10 -10
- package/dist/solana/wallet/SolanaSigner.js +16 -16
- package/dist/utils/Utils.d.ts +53 -53
- package/dist/utils/Utils.js +170 -170
- package/package.json +41 -41
- package/src/index.ts +36 -36
- package/src/solana/SolanaChainType.ts +25 -25
- package/src/solana/SolanaChains.ts +23 -23
- package/src/solana/SolanaInitializer.ts +102 -102
- package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -588
- package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +57 -57
- package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +102 -102
- package/src/solana/btcrelay/program/programIdl.json +670 -670
- package/src/solana/chain/SolanaAction.ts +108 -108
- package/src/solana/chain/SolanaChainInterface.ts +174 -174
- package/src/solana/chain/SolanaModule.ts +20 -20
- package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
- package/src/solana/chain/modules/SolanaBlocks.ts +78 -78
- package/src/solana/chain/modules/SolanaEvents.ts +56 -56
- package/src/solana/chain/modules/SolanaFees.ts +450 -450
- package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
- package/src/solana/chain/modules/SolanaSlots.ts +82 -82
- package/src/solana/chain/modules/SolanaTokens.ts +307 -307
- package/src/solana/chain/modules/SolanaTransactions.ts +370 -370
- package/src/solana/events/SolanaChainEvents.ts +299 -299
- package/src/solana/events/SolanaChainEventsBrowser.ts +256 -256
- package/src/solana/program/SolanaProgramBase.ts +79 -79
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +140 -140
- package/src/solana/swaps/SolanaSwapData.ts +379 -379
- package/src/solana/swaps/SolanaSwapModule.ts +16 -16
- package/src/solana/swaps/SolanaSwapProgram.ts +697 -692
- package/src/solana/swaps/SwapTypeEnum.ts +29 -29
- package/src/solana/swaps/modules/SolanaDataAccount.ts +307 -307
- package/src/solana/swaps/modules/SolanaLpVault.ts +215 -215
- package/src/solana/swaps/modules/SwapClaim.ts +389 -389
- package/src/solana/swaps/modules/SwapInit.ts +663 -663
- package/src/solana/swaps/modules/SwapRefund.ts +312 -312
- package/src/solana/swaps/programIdl.json +944 -944
- package/src/solana/swaps/programTypes.ts +1885 -1885
- package/src/solana/wallet/SolanaKeypairWallet.ts +36 -36
- package/src/solana/wallet/SolanaSigner.ts +23 -23
- package/src/utils/Utils.ts +180 -180
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
2
|
-
import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
3
|
-
export declare class SolanaKeypairWallet implements Wallet {
|
|
4
|
-
readonly payer: Keypair;
|
|
5
|
-
constructor(payer: Keypair);
|
|
6
|
-
get publicKey(): PublicKey;
|
|
7
|
-
signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
8
|
-
signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
|
|
9
|
-
}
|
|
1
|
+
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
2
|
+
import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
3
|
+
export declare class SolanaKeypairWallet implements Wallet {
|
|
4
|
+
readonly payer: Keypair;
|
|
5
|
+
constructor(payer: Keypair);
|
|
6
|
+
get publicKey(): PublicKey;
|
|
7
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
8
|
+
signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
|
|
9
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaKeypairWallet = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
class SolanaKeypairWallet {
|
|
6
|
-
constructor(payer) {
|
|
7
|
-
this.payer = payer;
|
|
8
|
-
}
|
|
9
|
-
get publicKey() {
|
|
10
|
-
return this.payer.publicKey;
|
|
11
|
-
}
|
|
12
|
-
signAllTransactions(txs) {
|
|
13
|
-
txs.forEach((tx) => {
|
|
14
|
-
if (tx instanceof web3_js_1.Transaction) {
|
|
15
|
-
tx.partialSign(this.payer);
|
|
16
|
-
}
|
|
17
|
-
else if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
18
|
-
tx.sign([this.payer]);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return Promise.resolve(txs);
|
|
22
|
-
}
|
|
23
|
-
signTransaction(tx) {
|
|
24
|
-
if (tx instanceof web3_js_1.Transaction) {
|
|
25
|
-
tx.partialSign(this.payer);
|
|
26
|
-
}
|
|
27
|
-
else if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
28
|
-
tx.sign([this.payer]);
|
|
29
|
-
}
|
|
30
|
-
return Promise.resolve(tx);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.SolanaKeypairWallet = SolanaKeypairWallet;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaKeypairWallet = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
class SolanaKeypairWallet {
|
|
6
|
+
constructor(payer) {
|
|
7
|
+
this.payer = payer;
|
|
8
|
+
}
|
|
9
|
+
get publicKey() {
|
|
10
|
+
return this.payer.publicKey;
|
|
11
|
+
}
|
|
12
|
+
signAllTransactions(txs) {
|
|
13
|
+
txs.forEach((tx) => {
|
|
14
|
+
if (tx instanceof web3_js_1.Transaction) {
|
|
15
|
+
tx.partialSign(this.payer);
|
|
16
|
+
}
|
|
17
|
+
else if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
18
|
+
tx.sign([this.payer]);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return Promise.resolve(txs);
|
|
22
|
+
}
|
|
23
|
+
signTransaction(tx) {
|
|
24
|
+
if (tx instanceof web3_js_1.Transaction) {
|
|
25
|
+
tx.partialSign(this.payer);
|
|
26
|
+
}
|
|
27
|
+
else if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
28
|
+
tx.sign([this.payer]);
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve(tx);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SolanaKeypairWallet = SolanaKeypairWallet;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
2
|
-
import { AbstractSigner } from "@atomiqlabs/base";
|
|
3
|
-
import { PublicKey, Signer } from "@solana/web3.js";
|
|
4
|
-
export declare class SolanaSigner implements AbstractSigner {
|
|
5
|
-
wallet: Wallet;
|
|
6
|
-
keypair?: Signer;
|
|
7
|
-
constructor(wallet: Wallet, keypair?: Signer);
|
|
8
|
-
getPublicKey(): PublicKey;
|
|
9
|
-
getAddress(): string;
|
|
10
|
-
}
|
|
1
|
+
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
|
|
2
|
+
import { AbstractSigner } from "@atomiqlabs/base";
|
|
3
|
+
import { PublicKey, Signer } from "@solana/web3.js";
|
|
4
|
+
export declare class SolanaSigner implements AbstractSigner {
|
|
5
|
+
wallet: Wallet;
|
|
6
|
+
keypair?: Signer;
|
|
7
|
+
constructor(wallet: Wallet, keypair?: Signer);
|
|
8
|
+
getPublicKey(): PublicKey;
|
|
9
|
+
getAddress(): string;
|
|
10
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaSigner = void 0;
|
|
4
|
-
class SolanaSigner {
|
|
5
|
-
constructor(wallet, keypair) {
|
|
6
|
-
this.wallet = wallet;
|
|
7
|
-
this.keypair = keypair;
|
|
8
|
-
}
|
|
9
|
-
getPublicKey() {
|
|
10
|
-
return this.wallet.publicKey;
|
|
11
|
-
}
|
|
12
|
-
getAddress() {
|
|
13
|
-
return this.wallet.publicKey.toString();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.SolanaSigner = SolanaSigner;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaSigner = void 0;
|
|
4
|
+
class SolanaSigner {
|
|
5
|
+
constructor(wallet, keypair) {
|
|
6
|
+
this.wallet = wallet;
|
|
7
|
+
this.keypair = keypair;
|
|
8
|
+
}
|
|
9
|
+
getPublicKey() {
|
|
10
|
+
return this.wallet.publicKey;
|
|
11
|
+
}
|
|
12
|
+
getAddress() {
|
|
13
|
+
return this.wallet.publicKey.toString();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.SolanaSigner = SolanaSigner;
|
package/dist/utils/Utils.d.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { PublicKey, Transaction } from "@solana/web3.js";
|
|
2
|
-
import * as BN from "bn.js";
|
|
3
|
-
export declare function timeoutPromise(timeoutMillis: number, abortSignal?: AbortSignal): Promise<void>;
|
|
4
|
-
export declare function onceAsync<T>(executor: () => Promise<T>): () => Promise<T>;
|
|
5
|
-
export declare function getLogger(prefix: string): {
|
|
6
|
-
debug: (msg: any, ...args: any[]) => void;
|
|
7
|
-
info: (msg: any, ...args: any[]) => void;
|
|
8
|
-
warn: (msg: any, ...args: any[]) => void;
|
|
9
|
-
error: (msg: any, ...args: any[]) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare function tryWithRetries<T>(func: () => Promise<T>, retryPolicy?: {
|
|
12
|
-
maxRetries?: number;
|
|
13
|
-
delay?: number;
|
|
14
|
-
exponential?: boolean;
|
|
15
|
-
}, errorAllowed?: (e: any) => boolean, abortSignal?: AbortSignal): Promise<T>;
|
|
16
|
-
export declare class SolanaTxUtils {
|
|
17
|
-
private static LOW_VALUE;
|
|
18
|
-
private static HIGH_VALUE;
|
|
19
|
-
/**
|
|
20
|
-
* Compact u16 array header size
|
|
21
|
-
* @param n elements in the compact array
|
|
22
|
-
* @returns size in bytes of array header
|
|
23
|
-
*/
|
|
24
|
-
private static compactHeader;
|
|
25
|
-
/**
|
|
26
|
-
* Compact u16 array size
|
|
27
|
-
* @param n elements in the compact array
|
|
28
|
-
* @param size bytes per each element
|
|
29
|
-
* @returns size in bytes of array
|
|
30
|
-
*/
|
|
31
|
-
private static compactArraySize;
|
|
32
|
-
/**
|
|
33
|
-
* Returns # number of non-compute budget related instructions
|
|
34
|
-
*
|
|
35
|
-
* @param tx
|
|
36
|
-
*/
|
|
37
|
-
static getNonComputeBudgetIxs(tx: Transaction): number;
|
|
38
|
-
/**
|
|
39
|
-
* @param tx a solana transaction
|
|
40
|
-
* @param feePayer the publicKey of the signer
|
|
41
|
-
* @returns size in bytes of the transaction
|
|
42
|
-
*/
|
|
43
|
-
static getTxSize(tx: Transaction, feePayer: PublicKey): number;
|
|
44
|
-
}
|
|
45
|
-
export declare function toClaimHash(paymentHash: string, nonce: bigint, confirmations: number): string;
|
|
46
|
-
export declare function fromClaimHash(claimHash: string): {
|
|
47
|
-
paymentHash: string;
|
|
48
|
-
nonce: BN;
|
|
49
|
-
confirmations: number;
|
|
50
|
-
};
|
|
51
|
-
export declare function toEscrowHash(paymentHash: string, sequence: BN): string;
|
|
52
|
-
export declare function toBN(value: bigint): BN;
|
|
53
|
-
export declare function toBigInt(value: BN): bigint;
|
|
1
|
+
import { PublicKey, Transaction } from "@solana/web3.js";
|
|
2
|
+
import * as BN from "bn.js";
|
|
3
|
+
export declare function timeoutPromise(timeoutMillis: number, abortSignal?: AbortSignal): Promise<void>;
|
|
4
|
+
export declare function onceAsync<T>(executor: () => Promise<T>): () => Promise<T>;
|
|
5
|
+
export declare function getLogger(prefix: string): {
|
|
6
|
+
debug: (msg: any, ...args: any[]) => void;
|
|
7
|
+
info: (msg: any, ...args: any[]) => void;
|
|
8
|
+
warn: (msg: any, ...args: any[]) => void;
|
|
9
|
+
error: (msg: any, ...args: any[]) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function tryWithRetries<T>(func: () => Promise<T>, retryPolicy?: {
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
delay?: number;
|
|
14
|
+
exponential?: boolean;
|
|
15
|
+
}, errorAllowed?: (e: any) => boolean, abortSignal?: AbortSignal): Promise<T>;
|
|
16
|
+
export declare class SolanaTxUtils {
|
|
17
|
+
private static LOW_VALUE;
|
|
18
|
+
private static HIGH_VALUE;
|
|
19
|
+
/**
|
|
20
|
+
* Compact u16 array header size
|
|
21
|
+
* @param n elements in the compact array
|
|
22
|
+
* @returns size in bytes of array header
|
|
23
|
+
*/
|
|
24
|
+
private static compactHeader;
|
|
25
|
+
/**
|
|
26
|
+
* Compact u16 array size
|
|
27
|
+
* @param n elements in the compact array
|
|
28
|
+
* @param size bytes per each element
|
|
29
|
+
* @returns size in bytes of array
|
|
30
|
+
*/
|
|
31
|
+
private static compactArraySize;
|
|
32
|
+
/**
|
|
33
|
+
* Returns # number of non-compute budget related instructions
|
|
34
|
+
*
|
|
35
|
+
* @param tx
|
|
36
|
+
*/
|
|
37
|
+
static getNonComputeBudgetIxs(tx: Transaction): number;
|
|
38
|
+
/**
|
|
39
|
+
* @param tx a solana transaction
|
|
40
|
+
* @param feePayer the publicKey of the signer
|
|
41
|
+
* @returns size in bytes of the transaction
|
|
42
|
+
*/
|
|
43
|
+
static getTxSize(tx: Transaction, feePayer: PublicKey): number;
|
|
44
|
+
}
|
|
45
|
+
export declare function toClaimHash(paymentHash: string, nonce: bigint, confirmations: number): string;
|
|
46
|
+
export declare function fromClaimHash(claimHash: string): {
|
|
47
|
+
paymentHash: string;
|
|
48
|
+
nonce: BN;
|
|
49
|
+
confirmations: number;
|
|
50
|
+
};
|
|
51
|
+
export declare function toEscrowHash(paymentHash: string, sequence: BN): string;
|
|
52
|
+
export declare function toBN(value: bigint): BN;
|
|
53
|
+
export declare function toBigInt(value: BN): bigint;
|
package/dist/utils/Utils.js
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toBigInt = exports.toBN = exports.toEscrowHash = exports.fromClaimHash = exports.toClaimHash = exports.SolanaTxUtils = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const BN = require("bn.js");
|
|
6
|
-
const buffer_1 = require("buffer");
|
|
7
|
-
const sha2_1 = require("@noble/hashes/sha2");
|
|
8
|
-
function timeoutPromise(timeoutMillis, abortSignal) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const timeout = setTimeout(resolve, timeoutMillis);
|
|
11
|
-
if (abortSignal != null)
|
|
12
|
-
abortSignal.addEventListener("abort", () => {
|
|
13
|
-
clearTimeout(timeout);
|
|
14
|
-
reject(new Error("Aborted"));
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
exports.timeoutPromise = timeoutPromise;
|
|
19
|
-
function onceAsync(executor) {
|
|
20
|
-
let promise;
|
|
21
|
-
return () => {
|
|
22
|
-
if (promise == null) {
|
|
23
|
-
promise = executor();
|
|
24
|
-
return promise;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return promise.catch(() => promise = executor());
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.onceAsync = onceAsync;
|
|
32
|
-
function getLogger(prefix) {
|
|
33
|
-
return {
|
|
34
|
-
debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args),
|
|
35
|
-
info: (msg, ...args) => global.atomiqLogLevel >= 2 && console.info(prefix + msg, ...args),
|
|
36
|
-
warn: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 1) && console.warn(prefix + msg, ...args),
|
|
37
|
-
error: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 0) && console.error(prefix + msg, ...args)
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
exports.getLogger = getLogger;
|
|
41
|
-
const logger = getLogger("Utils: ");
|
|
42
|
-
async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
|
|
43
|
-
retryPolicy = retryPolicy || {};
|
|
44
|
-
retryPolicy.maxRetries = retryPolicy.maxRetries || 5;
|
|
45
|
-
retryPolicy.delay = retryPolicy.delay || 500;
|
|
46
|
-
retryPolicy.exponential = retryPolicy.exponential == null ? true : retryPolicy.exponential;
|
|
47
|
-
let err = null;
|
|
48
|
-
for (let i = 0; i < retryPolicy.maxRetries; i++) {
|
|
49
|
-
try {
|
|
50
|
-
const resp = await func();
|
|
51
|
-
return resp;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
if (errorAllowed != null && errorAllowed(e))
|
|
55
|
-
throw e;
|
|
56
|
-
err = e;
|
|
57
|
-
logger.error("tryWithRetries(): error on try number: " + i, e);
|
|
58
|
-
}
|
|
59
|
-
if (abortSignal != null && abortSignal.aborted)
|
|
60
|
-
throw new Error("Aborted");
|
|
61
|
-
if (i !== retryPolicy.maxRetries - 1) {
|
|
62
|
-
await timeoutPromise(retryPolicy.exponential ? retryPolicy.delay * Math.pow(2, i) : retryPolicy.delay, abortSignal);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
throw err;
|
|
66
|
-
}
|
|
67
|
-
exports.tryWithRetries = tryWithRetries;
|
|
68
|
-
class SolanaTxUtils {
|
|
69
|
-
/**
|
|
70
|
-
* Compact u16 array header size
|
|
71
|
-
* @param n elements in the compact array
|
|
72
|
-
* @returns size in bytes of array header
|
|
73
|
-
*/
|
|
74
|
-
static compactHeader(n) {
|
|
75
|
-
return (n <= SolanaTxUtils.LOW_VALUE ? 1 : n <= SolanaTxUtils.HIGH_VALUE ? 2 : 3);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Compact u16 array size
|
|
79
|
-
* @param n elements in the compact array
|
|
80
|
-
* @param size bytes per each element
|
|
81
|
-
* @returns size in bytes of array
|
|
82
|
-
*/
|
|
83
|
-
static compactArraySize(n, size) {
|
|
84
|
-
return SolanaTxUtils.compactHeader(n) + n * size;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns # number of non-compute budget related instructions
|
|
88
|
-
*
|
|
89
|
-
* @param tx
|
|
90
|
-
*/
|
|
91
|
-
static getNonComputeBudgetIxs(tx) {
|
|
92
|
-
let counter = 0;
|
|
93
|
-
for (let ix of tx.instructions) {
|
|
94
|
-
if (!ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId))
|
|
95
|
-
counter++;
|
|
96
|
-
}
|
|
97
|
-
return counter;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @param tx a solana transaction
|
|
101
|
-
* @param feePayer the publicKey of the signer
|
|
102
|
-
* @returns size in bytes of the transaction
|
|
103
|
-
*/
|
|
104
|
-
static getTxSize(tx, feePayer) {
|
|
105
|
-
const feePayerPk = [feePayer.toBase58()];
|
|
106
|
-
const signers = new Set(feePayerPk);
|
|
107
|
-
const accounts = new Set(feePayerPk);
|
|
108
|
-
const ixsSize = tx.instructions.reduce((acc, ix) => {
|
|
109
|
-
ix.keys.forEach(({ pubkey, isSigner }) => {
|
|
110
|
-
const pk = pubkey.toBase58();
|
|
111
|
-
if (isSigner)
|
|
112
|
-
signers.add(pk);
|
|
113
|
-
accounts.add(pk);
|
|
114
|
-
});
|
|
115
|
-
accounts.add(ix.programId.toBase58());
|
|
116
|
-
const nIndexes = ix.keys.length;
|
|
117
|
-
const opaqueData = ix.data.length;
|
|
118
|
-
return (acc +
|
|
119
|
-
1 + // PID index
|
|
120
|
-
SolanaTxUtils.compactArraySize(nIndexes, 1) +
|
|
121
|
-
SolanaTxUtils.compactArraySize(opaqueData, 1));
|
|
122
|
-
}, 0);
|
|
123
|
-
return (SolanaTxUtils.compactArraySize(signers.size, 64) + // signatures
|
|
124
|
-
3 + // header
|
|
125
|
-
SolanaTxUtils.compactArraySize(accounts.size, 32) + // accounts
|
|
126
|
-
32 + // blockhash
|
|
127
|
-
SolanaTxUtils.compactHeader(tx.instructions.length) + // instructions
|
|
128
|
-
ixsSize);
|
|
129
|
-
}
|
|
130
|
-
;
|
|
131
|
-
}
|
|
132
|
-
exports.SolanaTxUtils = SolanaTxUtils;
|
|
133
|
-
// COMPACT ARRAY
|
|
134
|
-
SolanaTxUtils.LOW_VALUE = 127; // 0x7f
|
|
135
|
-
SolanaTxUtils.HIGH_VALUE = 16383; // 0x3fff
|
|
136
|
-
function toClaimHash(paymentHash, nonce, confirmations) {
|
|
137
|
-
return paymentHash +
|
|
138
|
-
nonce.toString(16).padStart(16, "0") +
|
|
139
|
-
confirmations.toString(16).padStart(4, "0");
|
|
140
|
-
}
|
|
141
|
-
exports.toClaimHash = toClaimHash;
|
|
142
|
-
function fromClaimHash(claimHash) {
|
|
143
|
-
if (claimHash.length !== 84)
|
|
144
|
-
throw new Error("Claim hash invalid length: " + claimHash.length);
|
|
145
|
-
return {
|
|
146
|
-
paymentHash: claimHash.slice(0, 64),
|
|
147
|
-
nonce: new BN(claimHash.slice(64, 80), "hex"),
|
|
148
|
-
confirmations: parseInt(claimHash.slice(80, 84), 16)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
exports.fromClaimHash = fromClaimHash;
|
|
152
|
-
function toEscrowHash(paymentHash, sequence) {
|
|
153
|
-
return buffer_1.Buffer.from((0, sha2_1.sha256)(buffer_1.Buffer.concat([
|
|
154
|
-
buffer_1.Buffer.from(paymentHash, "hex"),
|
|
155
|
-
sequence.toArrayLike(buffer_1.Buffer, "be", 8)
|
|
156
|
-
]))).toString("hex");
|
|
157
|
-
}
|
|
158
|
-
exports.toEscrowHash = toEscrowHash;
|
|
159
|
-
function toBN(value) {
|
|
160
|
-
if (value == null)
|
|
161
|
-
return null;
|
|
162
|
-
return new BN(value.toString(10));
|
|
163
|
-
}
|
|
164
|
-
exports.toBN = toBN;
|
|
165
|
-
function toBigInt(value) {
|
|
166
|
-
if (value == null)
|
|
167
|
-
return null;
|
|
168
|
-
return BigInt(value.toString(10));
|
|
169
|
-
}
|
|
170
|
-
exports.toBigInt = toBigInt;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBigInt = exports.toBN = exports.toEscrowHash = exports.fromClaimHash = exports.toClaimHash = exports.SolanaTxUtils = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const BN = require("bn.js");
|
|
6
|
+
const buffer_1 = require("buffer");
|
|
7
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
8
|
+
function timeoutPromise(timeoutMillis, abortSignal) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const timeout = setTimeout(resolve, timeoutMillis);
|
|
11
|
+
if (abortSignal != null)
|
|
12
|
+
abortSignal.addEventListener("abort", () => {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
reject(new Error("Aborted"));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.timeoutPromise = timeoutPromise;
|
|
19
|
+
function onceAsync(executor) {
|
|
20
|
+
let promise;
|
|
21
|
+
return () => {
|
|
22
|
+
if (promise == null) {
|
|
23
|
+
promise = executor();
|
|
24
|
+
return promise;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return promise.catch(() => promise = executor());
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.onceAsync = onceAsync;
|
|
32
|
+
function getLogger(prefix) {
|
|
33
|
+
return {
|
|
34
|
+
debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args),
|
|
35
|
+
info: (msg, ...args) => global.atomiqLogLevel >= 2 && console.info(prefix + msg, ...args),
|
|
36
|
+
warn: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 1) && console.warn(prefix + msg, ...args),
|
|
37
|
+
error: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 0) && console.error(prefix + msg, ...args)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.getLogger = getLogger;
|
|
41
|
+
const logger = getLogger("Utils: ");
|
|
42
|
+
async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
|
|
43
|
+
retryPolicy = retryPolicy || {};
|
|
44
|
+
retryPolicy.maxRetries = retryPolicy.maxRetries || 5;
|
|
45
|
+
retryPolicy.delay = retryPolicy.delay || 500;
|
|
46
|
+
retryPolicy.exponential = retryPolicy.exponential == null ? true : retryPolicy.exponential;
|
|
47
|
+
let err = null;
|
|
48
|
+
for (let i = 0; i < retryPolicy.maxRetries; i++) {
|
|
49
|
+
try {
|
|
50
|
+
const resp = await func();
|
|
51
|
+
return resp;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
if (errorAllowed != null && errorAllowed(e))
|
|
55
|
+
throw e;
|
|
56
|
+
err = e;
|
|
57
|
+
logger.error("tryWithRetries(): error on try number: " + i, e);
|
|
58
|
+
}
|
|
59
|
+
if (abortSignal != null && abortSignal.aborted)
|
|
60
|
+
throw new Error("Aborted");
|
|
61
|
+
if (i !== retryPolicy.maxRetries - 1) {
|
|
62
|
+
await timeoutPromise(retryPolicy.exponential ? retryPolicy.delay * Math.pow(2, i) : retryPolicy.delay, abortSignal);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
exports.tryWithRetries = tryWithRetries;
|
|
68
|
+
class SolanaTxUtils {
|
|
69
|
+
/**
|
|
70
|
+
* Compact u16 array header size
|
|
71
|
+
* @param n elements in the compact array
|
|
72
|
+
* @returns size in bytes of array header
|
|
73
|
+
*/
|
|
74
|
+
static compactHeader(n) {
|
|
75
|
+
return (n <= SolanaTxUtils.LOW_VALUE ? 1 : n <= SolanaTxUtils.HIGH_VALUE ? 2 : 3);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compact u16 array size
|
|
79
|
+
* @param n elements in the compact array
|
|
80
|
+
* @param size bytes per each element
|
|
81
|
+
* @returns size in bytes of array
|
|
82
|
+
*/
|
|
83
|
+
static compactArraySize(n, size) {
|
|
84
|
+
return SolanaTxUtils.compactHeader(n) + n * size;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns # number of non-compute budget related instructions
|
|
88
|
+
*
|
|
89
|
+
* @param tx
|
|
90
|
+
*/
|
|
91
|
+
static getNonComputeBudgetIxs(tx) {
|
|
92
|
+
let counter = 0;
|
|
93
|
+
for (let ix of tx.instructions) {
|
|
94
|
+
if (!ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId))
|
|
95
|
+
counter++;
|
|
96
|
+
}
|
|
97
|
+
return counter;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param tx a solana transaction
|
|
101
|
+
* @param feePayer the publicKey of the signer
|
|
102
|
+
* @returns size in bytes of the transaction
|
|
103
|
+
*/
|
|
104
|
+
static getTxSize(tx, feePayer) {
|
|
105
|
+
const feePayerPk = [feePayer.toBase58()];
|
|
106
|
+
const signers = new Set(feePayerPk);
|
|
107
|
+
const accounts = new Set(feePayerPk);
|
|
108
|
+
const ixsSize = tx.instructions.reduce((acc, ix) => {
|
|
109
|
+
ix.keys.forEach(({ pubkey, isSigner }) => {
|
|
110
|
+
const pk = pubkey.toBase58();
|
|
111
|
+
if (isSigner)
|
|
112
|
+
signers.add(pk);
|
|
113
|
+
accounts.add(pk);
|
|
114
|
+
});
|
|
115
|
+
accounts.add(ix.programId.toBase58());
|
|
116
|
+
const nIndexes = ix.keys.length;
|
|
117
|
+
const opaqueData = ix.data.length;
|
|
118
|
+
return (acc +
|
|
119
|
+
1 + // PID index
|
|
120
|
+
SolanaTxUtils.compactArraySize(nIndexes, 1) +
|
|
121
|
+
SolanaTxUtils.compactArraySize(opaqueData, 1));
|
|
122
|
+
}, 0);
|
|
123
|
+
return (SolanaTxUtils.compactArraySize(signers.size, 64) + // signatures
|
|
124
|
+
3 + // header
|
|
125
|
+
SolanaTxUtils.compactArraySize(accounts.size, 32) + // accounts
|
|
126
|
+
32 + // blockhash
|
|
127
|
+
SolanaTxUtils.compactHeader(tx.instructions.length) + // instructions
|
|
128
|
+
ixsSize);
|
|
129
|
+
}
|
|
130
|
+
;
|
|
131
|
+
}
|
|
132
|
+
exports.SolanaTxUtils = SolanaTxUtils;
|
|
133
|
+
// COMPACT ARRAY
|
|
134
|
+
SolanaTxUtils.LOW_VALUE = 127; // 0x7f
|
|
135
|
+
SolanaTxUtils.HIGH_VALUE = 16383; // 0x3fff
|
|
136
|
+
function toClaimHash(paymentHash, nonce, confirmations) {
|
|
137
|
+
return paymentHash +
|
|
138
|
+
nonce.toString(16).padStart(16, "0") +
|
|
139
|
+
confirmations.toString(16).padStart(4, "0");
|
|
140
|
+
}
|
|
141
|
+
exports.toClaimHash = toClaimHash;
|
|
142
|
+
function fromClaimHash(claimHash) {
|
|
143
|
+
if (claimHash.length !== 84)
|
|
144
|
+
throw new Error("Claim hash invalid length: " + claimHash.length);
|
|
145
|
+
return {
|
|
146
|
+
paymentHash: claimHash.slice(0, 64),
|
|
147
|
+
nonce: new BN(claimHash.slice(64, 80), "hex"),
|
|
148
|
+
confirmations: parseInt(claimHash.slice(80, 84), 16)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
exports.fromClaimHash = fromClaimHash;
|
|
152
|
+
function toEscrowHash(paymentHash, sequence) {
|
|
153
|
+
return buffer_1.Buffer.from((0, sha2_1.sha256)(buffer_1.Buffer.concat([
|
|
154
|
+
buffer_1.Buffer.from(paymentHash, "hex"),
|
|
155
|
+
sequence.toArrayLike(buffer_1.Buffer, "be", 8)
|
|
156
|
+
]))).toString("hex");
|
|
157
|
+
}
|
|
158
|
+
exports.toEscrowHash = toEscrowHash;
|
|
159
|
+
function toBN(value) {
|
|
160
|
+
if (value == null)
|
|
161
|
+
return null;
|
|
162
|
+
return new BN(value.toString(10));
|
|
163
|
+
}
|
|
164
|
+
exports.toBN = toBN;
|
|
165
|
+
function toBigInt(value) {
|
|
166
|
+
if (value == null)
|
|
167
|
+
return null;
|
|
168
|
+
return BigInt(value.toString(10));
|
|
169
|
+
}
|
|
170
|
+
exports.toBigInt = toBigInt;
|