@atomiqlabs/chain-solana 12.0.13 → 12.0.15
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 +11 -11
- 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 +65 -65
- package/dist/solana/chain/SolanaChainInterface.js +125 -125
- 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 +68 -68
- package/dist/solana/chain/modules/SolanaEvents.js +238 -225
- 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 +323 -323
- package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
- package/dist/solana/events/SolanaChainEvents.js +256 -256
- package/dist/solana/events/SolanaChainEventsBrowser.d.ts +75 -75
- package/dist/solana/events/SolanaChainEventsBrowser.js +172 -172
- 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 +53 -53
- package/dist/solana/program/modules/SolanaProgramEvents.js +114 -114
- package/dist/solana/swaps/SolanaSwapData.d.ts +71 -71
- package/dist/solana/swaps/SolanaSwapData.js +292 -292
- package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
- package/dist/solana/swaps/SolanaSwapModule.js +11 -11
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +224 -224
- package/dist/solana/swaps/SolanaSwapProgram.js +570 -570
- 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 +262 -262
- 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 +11 -11
- package/dist/solana/wallet/SolanaSigner.js +17 -17
- 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 +27 -27
- package/src/solana/SolanaChains.ts +23 -23
- package/src/solana/SolanaInitializer.ts +102 -102
- package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -589
- 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 +192 -192
- 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 +270 -256
- 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 +365 -365
- package/src/solana/events/SolanaChainEvents.ts +299 -299
- package/src/solana/events/SolanaChainEventsBrowser.ts +209 -209
- package/src/solana/program/SolanaProgramBase.ts +79 -79
- package/src/solana/program/SolanaProgramModule.ts +15 -15
- package/src/solana/program/modules/SolanaProgramEvents.ts +155 -155
- package/src/solana/swaps/SolanaSwapData.ts +430 -430
- package/src/solana/swaps/SolanaSwapModule.ts +16 -16
- package/src/solana/swaps/SolanaSwapProgram.ts +854 -854
- 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 +323 -323
- 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 +24 -24
- package/src/utils/Utils.ts +180 -180
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { SolanaModule } from "../SolanaModule";
|
|
3
|
-
import { Buffer } from "buffer";
|
|
4
|
-
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
5
|
-
export declare class SolanaSignatures extends SolanaModule {
|
|
6
|
-
/**
|
|
7
|
-
* Produces an ed25519 signature over the sha256 of a specified data Buffer, only works with providers which
|
|
8
|
-
* expose their private key (i.e. backend based, not browser wallet based)
|
|
9
|
-
*
|
|
10
|
-
* @param signer
|
|
11
|
-
* @param data data to sign
|
|
12
|
-
*/
|
|
13
|
-
getDataSignature(signer: SolanaSigner, data: Buffer): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Checks whether a signature is a valid Ed25519 signature produced by publicKey over a data message (computes
|
|
16
|
-
* sha256 hash of the message)
|
|
17
|
-
*
|
|
18
|
-
* @param data signed data
|
|
19
|
-
* @param signature data signature
|
|
20
|
-
* @param publicKey public key of the signer
|
|
21
|
-
*/
|
|
22
|
-
isValidDataSignature(data: Buffer, signature: string, publicKey: string): Promise<boolean>;
|
|
23
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SolanaModule } from "../SolanaModule";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
import { SolanaSigner } from "../../wallet/SolanaSigner";
|
|
5
|
+
export declare class SolanaSignatures extends SolanaModule {
|
|
6
|
+
/**
|
|
7
|
+
* Produces an ed25519 signature over the sha256 of a specified data Buffer, only works with providers which
|
|
8
|
+
* expose their private key (i.e. backend based, not browser wallet based)
|
|
9
|
+
*
|
|
10
|
+
* @param signer
|
|
11
|
+
* @param data data to sign
|
|
12
|
+
*/
|
|
13
|
+
getDataSignature(signer: SolanaSigner, data: Buffer): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether a signature is a valid Ed25519 signature produced by publicKey over a data message (computes
|
|
16
|
+
* sha256 hash of the message)
|
|
17
|
+
*
|
|
18
|
+
* @param data signed data
|
|
19
|
+
* @param signature data signature
|
|
20
|
+
* @param publicKey public key of the signer
|
|
21
|
+
*/
|
|
22
|
+
isValidDataSignature(data: Buffer, signature: string, publicKey: string): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaSignatures = void 0;
|
|
4
|
-
const SolanaModule_1 = require("../SolanaModule");
|
|
5
|
-
const tweetnacl_1 = require("tweetnacl");
|
|
6
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
-
const buffer_1 = require("buffer");
|
|
8
|
-
const sha2_1 = require("@noble/hashes/sha2");
|
|
9
|
-
class SolanaSignatures extends SolanaModule_1.SolanaModule {
|
|
10
|
-
///////////////////
|
|
11
|
-
//// Data signatures
|
|
12
|
-
/**
|
|
13
|
-
* Produces an ed25519 signature over the sha256 of a specified data Buffer, only works with providers which
|
|
14
|
-
* expose their private key (i.e. backend based, not browser wallet based)
|
|
15
|
-
*
|
|
16
|
-
* @param signer
|
|
17
|
-
* @param data data to sign
|
|
18
|
-
*/
|
|
19
|
-
getDataSignature(signer, data) {
|
|
20
|
-
if (signer.keypair == null)
|
|
21
|
-
throw new Error("Unsupported");
|
|
22
|
-
const buff = (0, sha2_1.sha256)(data);
|
|
23
|
-
const signature = tweetnacl_1.sign.detached(buff, signer.keypair.secretKey);
|
|
24
|
-
return Promise.resolve(buffer_1.Buffer.from(signature).toString("hex"));
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Checks whether a signature is a valid Ed25519 signature produced by publicKey over a data message (computes
|
|
28
|
-
* sha256 hash of the message)
|
|
29
|
-
*
|
|
30
|
-
* @param data signed data
|
|
31
|
-
* @param signature data signature
|
|
32
|
-
* @param publicKey public key of the signer
|
|
33
|
-
*/
|
|
34
|
-
isValidDataSignature(data, signature, publicKey) {
|
|
35
|
-
const hash = (0, sha2_1.sha256)(data);
|
|
36
|
-
return Promise.resolve(tweetnacl_1.sign.detached.verify(hash, buffer_1.Buffer.from(signature, "hex"), new web3_js_1.PublicKey(publicKey).toBuffer()));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.SolanaSignatures = SolanaSignatures;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaSignatures = void 0;
|
|
4
|
+
const SolanaModule_1 = require("../SolanaModule");
|
|
5
|
+
const tweetnacl_1 = require("tweetnacl");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const buffer_1 = require("buffer");
|
|
8
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
9
|
+
class SolanaSignatures extends SolanaModule_1.SolanaModule {
|
|
10
|
+
///////////////////
|
|
11
|
+
//// Data signatures
|
|
12
|
+
/**
|
|
13
|
+
* Produces an ed25519 signature over the sha256 of a specified data Buffer, only works with providers which
|
|
14
|
+
* expose their private key (i.e. backend based, not browser wallet based)
|
|
15
|
+
*
|
|
16
|
+
* @param signer
|
|
17
|
+
* @param data data to sign
|
|
18
|
+
*/
|
|
19
|
+
getDataSignature(signer, data) {
|
|
20
|
+
if (signer.keypair == null)
|
|
21
|
+
throw new Error("Unsupported");
|
|
22
|
+
const buff = (0, sha2_1.sha256)(data);
|
|
23
|
+
const signature = tweetnacl_1.sign.detached(buff, signer.keypair.secretKey);
|
|
24
|
+
return Promise.resolve(buffer_1.Buffer.from(signature).toString("hex"));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether a signature is a valid Ed25519 signature produced by publicKey over a data message (computes
|
|
28
|
+
* sha256 hash of the message)
|
|
29
|
+
*
|
|
30
|
+
* @param data signed data
|
|
31
|
+
* @param signature data signature
|
|
32
|
+
* @param publicKey public key of the signer
|
|
33
|
+
*/
|
|
34
|
+
isValidDataSignature(data, signature, publicKey) {
|
|
35
|
+
const hash = (0, sha2_1.sha256)(data);
|
|
36
|
+
return Promise.resolve(tweetnacl_1.sign.detached.verify(hash, buffer_1.Buffer.from(signature, "hex"), new web3_js_1.PublicKey(publicKey).toBuffer()));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.SolanaSignatures = SolanaSignatures;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { SolanaModule } from "../SolanaModule";
|
|
2
|
-
import { Commitment } from "@solana/web3.js";
|
|
3
|
-
export declare class SolanaSlots extends SolanaModule {
|
|
4
|
-
readonly SLOT_CACHE_SLOTS = 12;
|
|
5
|
-
readonly SLOT_CACHE_TIME: number;
|
|
6
|
-
private slotCache;
|
|
7
|
-
/**
|
|
8
|
-
* Initiates fetch of a given slot & saves it to cache
|
|
9
|
-
*
|
|
10
|
-
* @param commitment
|
|
11
|
-
* @private
|
|
12
|
-
*/
|
|
13
|
-
private fetchAndSaveSlot;
|
|
14
|
-
/**
|
|
15
|
-
* Gets the latest slot for a given commitment, with the timestamp of when that slot was actually retrieved from
|
|
16
|
-
* the RPC (useful for when slots are cached), does no estimation on the current slot number based on cached value
|
|
17
|
-
*
|
|
18
|
-
* @param commitment
|
|
19
|
-
*/
|
|
20
|
-
getSlotAndTimestamp(commitment: Commitment): Promise<{
|
|
21
|
-
slot: number;
|
|
22
|
-
timestamp: number;
|
|
23
|
-
}>;
|
|
24
|
-
/**
|
|
25
|
-
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
26
|
-
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
27
|
-
*
|
|
28
|
-
* @param commitment
|
|
29
|
-
*/
|
|
30
|
-
getSlot(commitment: Commitment): Promise<number>;
|
|
31
|
-
}
|
|
1
|
+
import { SolanaModule } from "../SolanaModule";
|
|
2
|
+
import { Commitment } from "@solana/web3.js";
|
|
3
|
+
export declare class SolanaSlots extends SolanaModule {
|
|
4
|
+
readonly SLOT_CACHE_SLOTS = 12;
|
|
5
|
+
readonly SLOT_CACHE_TIME: number;
|
|
6
|
+
private slotCache;
|
|
7
|
+
/**
|
|
8
|
+
* Initiates fetch of a given slot & saves it to cache
|
|
9
|
+
*
|
|
10
|
+
* @param commitment
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
private fetchAndSaveSlot;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the latest slot for a given commitment, with the timestamp of when that slot was actually retrieved from
|
|
16
|
+
* the RPC (useful for when slots are cached), does no estimation on the current slot number based on cached value
|
|
17
|
+
*
|
|
18
|
+
* @param commitment
|
|
19
|
+
*/
|
|
20
|
+
getSlotAndTimestamp(commitment: Commitment): Promise<{
|
|
21
|
+
slot: number;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
26
|
+
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
27
|
+
*
|
|
28
|
+
* @param commitment
|
|
29
|
+
*/
|
|
30
|
+
getSlot(commitment: Commitment): Promise<number>;
|
|
31
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaSlots = void 0;
|
|
4
|
-
const SolanaModule_1 = require("../SolanaModule");
|
|
5
|
-
class SolanaSlots extends SolanaModule_1.SolanaModule {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.SLOT_CACHE_SLOTS = 12;
|
|
9
|
-
this.SLOT_CACHE_TIME = this.SLOT_CACHE_SLOTS * this.root.SLOT_TIME;
|
|
10
|
-
this.slotCache = {};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Initiates fetch of a given slot & saves it to cache
|
|
14
|
-
*
|
|
15
|
-
* @param commitment
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
fetchAndSaveSlot(commitment) {
|
|
19
|
-
const slotPromise = this.connection.getSlot(commitment);
|
|
20
|
-
const timestamp = Date.now();
|
|
21
|
-
this.slotCache[commitment] = {
|
|
22
|
-
slot: slotPromise,
|
|
23
|
-
timestamp
|
|
24
|
-
};
|
|
25
|
-
slotPromise.catch(e => {
|
|
26
|
-
if (this.slotCache[commitment] != null && this.slotCache[commitment].slot === slotPromise)
|
|
27
|
-
delete this.slotCache[commitment];
|
|
28
|
-
throw e;
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
slot: slotPromise,
|
|
32
|
-
timestamp
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
///////////////////
|
|
36
|
-
//// Slots
|
|
37
|
-
/**
|
|
38
|
-
* Gets the latest slot for a given commitment, with the timestamp of when that slot was actually retrieved from
|
|
39
|
-
* the RPC (useful for when slots are cached), does no estimation on the current slot number based on cached value
|
|
40
|
-
*
|
|
41
|
-
* @param commitment
|
|
42
|
-
*/
|
|
43
|
-
async getSlotAndTimestamp(commitment) {
|
|
44
|
-
let cachedSlotData = this.slotCache[commitment];
|
|
45
|
-
if (cachedSlotData == null || Date.now() - cachedSlotData.timestamp > this.SLOT_CACHE_TIME) {
|
|
46
|
-
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
slot: await cachedSlotData.slot,
|
|
50
|
-
timestamp: cachedSlotData.timestamp
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
55
|
-
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
56
|
-
*
|
|
57
|
-
* @param commitment
|
|
58
|
-
*/
|
|
59
|
-
async getSlot(commitment) {
|
|
60
|
-
let cachedSlotData = this.slotCache[commitment];
|
|
61
|
-
if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
|
|
62
|
-
return (await cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root.SLOT_TIME);
|
|
63
|
-
}
|
|
64
|
-
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
|
65
|
-
return await cachedSlotData.slot;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.SolanaSlots = SolanaSlots;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaSlots = void 0;
|
|
4
|
+
const SolanaModule_1 = require("../SolanaModule");
|
|
5
|
+
class SolanaSlots extends SolanaModule_1.SolanaModule {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.SLOT_CACHE_SLOTS = 12;
|
|
9
|
+
this.SLOT_CACHE_TIME = this.SLOT_CACHE_SLOTS * this.root.SLOT_TIME;
|
|
10
|
+
this.slotCache = {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Initiates fetch of a given slot & saves it to cache
|
|
14
|
+
*
|
|
15
|
+
* @param commitment
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
fetchAndSaveSlot(commitment) {
|
|
19
|
+
const slotPromise = this.connection.getSlot(commitment);
|
|
20
|
+
const timestamp = Date.now();
|
|
21
|
+
this.slotCache[commitment] = {
|
|
22
|
+
slot: slotPromise,
|
|
23
|
+
timestamp
|
|
24
|
+
};
|
|
25
|
+
slotPromise.catch(e => {
|
|
26
|
+
if (this.slotCache[commitment] != null && this.slotCache[commitment].slot === slotPromise)
|
|
27
|
+
delete this.slotCache[commitment];
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
slot: slotPromise,
|
|
32
|
+
timestamp
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
///////////////////
|
|
36
|
+
//// Slots
|
|
37
|
+
/**
|
|
38
|
+
* Gets the latest slot for a given commitment, with the timestamp of when that slot was actually retrieved from
|
|
39
|
+
* the RPC (useful for when slots are cached), does no estimation on the current slot number based on cached value
|
|
40
|
+
*
|
|
41
|
+
* @param commitment
|
|
42
|
+
*/
|
|
43
|
+
async getSlotAndTimestamp(commitment) {
|
|
44
|
+
let cachedSlotData = this.slotCache[commitment];
|
|
45
|
+
if (cachedSlotData == null || Date.now() - cachedSlotData.timestamp > this.SLOT_CACHE_TIME) {
|
|
46
|
+
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
slot: await cachedSlotData.slot,
|
|
50
|
+
timestamp: cachedSlotData.timestamp
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
|
|
55
|
+
* value, cache has relatively short expiry of just 12 slots (4.8 seconds)
|
|
56
|
+
*
|
|
57
|
+
* @param commitment
|
|
58
|
+
*/
|
|
59
|
+
async getSlot(commitment) {
|
|
60
|
+
let cachedSlotData = this.slotCache[commitment];
|
|
61
|
+
if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
|
|
62
|
+
return (await cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root.SLOT_TIME);
|
|
63
|
+
}
|
|
64
|
+
cachedSlotData = this.fetchAndSaveSlot(commitment);
|
|
65
|
+
return await cachedSlotData.slot;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.SolanaSlots = SolanaSlots;
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import { SolanaModule } from "../SolanaModule";
|
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
import { Account } from "@solana/spl-token";
|
|
4
|
-
import { SolanaTx } from "./SolanaTransactions";
|
|
5
|
-
import { SolanaAction } from "../SolanaAction";
|
|
6
|
-
export declare class SolanaTokens extends SolanaModule {
|
|
7
|
-
static readonly CUCosts: {
|
|
8
|
-
WRAP_SOL: number;
|
|
9
|
-
ATA_CLOSE: number;
|
|
10
|
-
ATA_INIT: number;
|
|
11
|
-
TRANSFER: number;
|
|
12
|
-
TRANSFER_SOL: number;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Creates an ATA for a specific public key & token, the ATA creation is paid for by the underlying provider's
|
|
16
|
-
* public key
|
|
17
|
-
*
|
|
18
|
-
* @param signer
|
|
19
|
-
* @param publicKey public key address of the user for which to initiate the ATA
|
|
20
|
-
* @param token token identification for which the ATA should be initialized
|
|
21
|
-
* @param requiredAta optional required ata address to use, if the address doesn't match it returns null
|
|
22
|
-
* @constructor
|
|
23
|
-
*/
|
|
24
|
-
InitAta(signer: PublicKey, publicKey: PublicKey, token: PublicKey, requiredAta?: PublicKey): SolanaAction | null;
|
|
25
|
-
/**
|
|
26
|
-
* Action for wrapping SOL to WSOL for a specific public key
|
|
27
|
-
*
|
|
28
|
-
* @param publicKey public key of the user for which to wrap the SOL
|
|
29
|
-
* @param amount amount of SOL in lamports (smallest unit) to wrap
|
|
30
|
-
* @param initAta whether we should also initialize the ATA before depositing SOL
|
|
31
|
-
* @constructor
|
|
32
|
-
*/
|
|
33
|
-
Wrap(publicKey: PublicKey, amount: bigint, initAta: boolean): SolanaAction;
|
|
34
|
-
/**
|
|
35
|
-
* Action for unwrapping WSOL to SOL for a specific public key
|
|
36
|
-
*
|
|
37
|
-
* @param publicKey public key of the user for which to unwrap the sol
|
|
38
|
-
* @constructor
|
|
39
|
-
*/
|
|
40
|
-
Unwrap(publicKey: PublicKey): SolanaAction;
|
|
41
|
-
static readonly WSOL_ADDRESS: PublicKey;
|
|
42
|
-
static readonly SPL_ATA_RENT_EXEMPT = 2039280;
|
|
43
|
-
/**
|
|
44
|
-
* Action for transferring the native SOL token, uses provider's public key as a sender
|
|
45
|
-
*
|
|
46
|
-
* @param signer
|
|
47
|
-
* @param recipient
|
|
48
|
-
* @param amount
|
|
49
|
-
* @constructor
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
private SolTransfer;
|
|
53
|
-
/**
|
|
54
|
-
* Action for transferring the SPL token, uses provider's public key as a sender
|
|
55
|
-
*
|
|
56
|
-
* @param signer
|
|
57
|
-
* @param recipient
|
|
58
|
-
* @param token
|
|
59
|
-
* @param amount
|
|
60
|
-
* @constructor
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private Transfer;
|
|
64
|
-
/**
|
|
65
|
-
* Creates transactions for sending SOL (the native token)
|
|
66
|
-
*
|
|
67
|
-
* @param signer
|
|
68
|
-
* @param amount amount of the SOL in lamports (smallest unit) to send
|
|
69
|
-
* @param recipient recipient's address
|
|
70
|
-
* @param feeRate fee rate to use for the transactions
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
private txsTransferSol;
|
|
74
|
-
/**
|
|
75
|
-
* Creates transactions for sending the over the tokens
|
|
76
|
-
*
|
|
77
|
-
* @param signer
|
|
78
|
-
* @param token token to send
|
|
79
|
-
* @param amount amount of the token to send
|
|
80
|
-
* @param recipient recipient's address
|
|
81
|
-
* @param feeRate fee rate to use for the transactions
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
private txsTransferTokens;
|
|
85
|
-
/**
|
|
86
|
-
* Checks if the provided string is a valid solana token
|
|
87
|
-
*
|
|
88
|
-
* @param token
|
|
89
|
-
*/
|
|
90
|
-
isValidToken(token: string): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Returns the specific ATA or null if it doesn't exist
|
|
93
|
-
*
|
|
94
|
-
* @param ata
|
|
95
|
-
*/
|
|
96
|
-
getATAOrNull(ata: PublicKey): Promise<Account | null>;
|
|
97
|
-
/**
|
|
98
|
-
* Checks whether the specific ATA exists, uses tryWithRetries so retries on failure
|
|
99
|
-
*
|
|
100
|
-
* @param ata
|
|
101
|
-
*/
|
|
102
|
-
ataExists(ata: PublicKey): Promise<boolean>;
|
|
103
|
-
/**
|
|
104
|
-
* Returns the rent exempt deposit required to initiate the ATA
|
|
105
|
-
*/
|
|
106
|
-
getATARentExemptLamports(): Promise<bigint>;
|
|
107
|
-
/**
|
|
108
|
-
* Returns the token balance of the public key
|
|
109
|
-
*
|
|
110
|
-
* @param publicKey
|
|
111
|
-
* @param token
|
|
112
|
-
*/
|
|
113
|
-
getTokenBalance(publicKey: PublicKey, token: PublicKey): Promise<{
|
|
114
|
-
balance: bigint;
|
|
115
|
-
ataExists: boolean;
|
|
116
|
-
}>;
|
|
117
|
-
/**
|
|
118
|
-
* Returns the native currency address, we use WSOL address as placeholder for SOL
|
|
119
|
-
*/
|
|
120
|
-
getNativeCurrencyAddress(): PublicKey;
|
|
121
|
-
/**
|
|
122
|
-
* Parses string base58 representation of the token address to a PublicKey object
|
|
123
|
-
* @param address
|
|
124
|
-
*/
|
|
125
|
-
toTokenAddress(address: string): PublicKey;
|
|
126
|
-
/**
|
|
127
|
-
* Create transactions for sending a specific token to a destination address
|
|
128
|
-
*
|
|
129
|
-
* @param signer
|
|
130
|
-
* @param token token to use for the transfer
|
|
131
|
-
* @param amount amount of token in base units to transfer
|
|
132
|
-
* @param dstAddress destination address of the recipient
|
|
133
|
-
* @param feeRate fee rate to use for the transaction
|
|
134
|
-
*/
|
|
135
|
-
txsTransfer(signer: PublicKey, token: PublicKey, amount: bigint, dstAddress: PublicKey, feeRate?: string): Promise<SolanaTx[]>;
|
|
136
|
-
}
|
|
1
|
+
import { SolanaModule } from "../SolanaModule";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { Account } from "@solana/spl-token";
|
|
4
|
+
import { SolanaTx } from "./SolanaTransactions";
|
|
5
|
+
import { SolanaAction } from "../SolanaAction";
|
|
6
|
+
export declare class SolanaTokens extends SolanaModule {
|
|
7
|
+
static readonly CUCosts: {
|
|
8
|
+
WRAP_SOL: number;
|
|
9
|
+
ATA_CLOSE: number;
|
|
10
|
+
ATA_INIT: number;
|
|
11
|
+
TRANSFER: number;
|
|
12
|
+
TRANSFER_SOL: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates an ATA for a specific public key & token, the ATA creation is paid for by the underlying provider's
|
|
16
|
+
* public key
|
|
17
|
+
*
|
|
18
|
+
* @param signer
|
|
19
|
+
* @param publicKey public key address of the user for which to initiate the ATA
|
|
20
|
+
* @param token token identification for which the ATA should be initialized
|
|
21
|
+
* @param requiredAta optional required ata address to use, if the address doesn't match it returns null
|
|
22
|
+
* @constructor
|
|
23
|
+
*/
|
|
24
|
+
InitAta(signer: PublicKey, publicKey: PublicKey, token: PublicKey, requiredAta?: PublicKey): SolanaAction | null;
|
|
25
|
+
/**
|
|
26
|
+
* Action for wrapping SOL to WSOL for a specific public key
|
|
27
|
+
*
|
|
28
|
+
* @param publicKey public key of the user for which to wrap the SOL
|
|
29
|
+
* @param amount amount of SOL in lamports (smallest unit) to wrap
|
|
30
|
+
* @param initAta whether we should also initialize the ATA before depositing SOL
|
|
31
|
+
* @constructor
|
|
32
|
+
*/
|
|
33
|
+
Wrap(publicKey: PublicKey, amount: bigint, initAta: boolean): SolanaAction;
|
|
34
|
+
/**
|
|
35
|
+
* Action for unwrapping WSOL to SOL for a specific public key
|
|
36
|
+
*
|
|
37
|
+
* @param publicKey public key of the user for which to unwrap the sol
|
|
38
|
+
* @constructor
|
|
39
|
+
*/
|
|
40
|
+
Unwrap(publicKey: PublicKey): SolanaAction;
|
|
41
|
+
static readonly WSOL_ADDRESS: PublicKey;
|
|
42
|
+
static readonly SPL_ATA_RENT_EXEMPT = 2039280;
|
|
43
|
+
/**
|
|
44
|
+
* Action for transferring the native SOL token, uses provider's public key as a sender
|
|
45
|
+
*
|
|
46
|
+
* @param signer
|
|
47
|
+
* @param recipient
|
|
48
|
+
* @param amount
|
|
49
|
+
* @constructor
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
private SolTransfer;
|
|
53
|
+
/**
|
|
54
|
+
* Action for transferring the SPL token, uses provider's public key as a sender
|
|
55
|
+
*
|
|
56
|
+
* @param signer
|
|
57
|
+
* @param recipient
|
|
58
|
+
* @param token
|
|
59
|
+
* @param amount
|
|
60
|
+
* @constructor
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private Transfer;
|
|
64
|
+
/**
|
|
65
|
+
* Creates transactions for sending SOL (the native token)
|
|
66
|
+
*
|
|
67
|
+
* @param signer
|
|
68
|
+
* @param amount amount of the SOL in lamports (smallest unit) to send
|
|
69
|
+
* @param recipient recipient's address
|
|
70
|
+
* @param feeRate fee rate to use for the transactions
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
private txsTransferSol;
|
|
74
|
+
/**
|
|
75
|
+
* Creates transactions for sending the over the tokens
|
|
76
|
+
*
|
|
77
|
+
* @param signer
|
|
78
|
+
* @param token token to send
|
|
79
|
+
* @param amount amount of the token to send
|
|
80
|
+
* @param recipient recipient's address
|
|
81
|
+
* @param feeRate fee rate to use for the transactions
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private txsTransferTokens;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the provided string is a valid solana token
|
|
87
|
+
*
|
|
88
|
+
* @param token
|
|
89
|
+
*/
|
|
90
|
+
isValidToken(token: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the specific ATA or null if it doesn't exist
|
|
93
|
+
*
|
|
94
|
+
* @param ata
|
|
95
|
+
*/
|
|
96
|
+
getATAOrNull(ata: PublicKey): Promise<Account | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Checks whether the specific ATA exists, uses tryWithRetries so retries on failure
|
|
99
|
+
*
|
|
100
|
+
* @param ata
|
|
101
|
+
*/
|
|
102
|
+
ataExists(ata: PublicKey): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the rent exempt deposit required to initiate the ATA
|
|
105
|
+
*/
|
|
106
|
+
getATARentExemptLamports(): Promise<bigint>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the token balance of the public key
|
|
109
|
+
*
|
|
110
|
+
* @param publicKey
|
|
111
|
+
* @param token
|
|
112
|
+
*/
|
|
113
|
+
getTokenBalance(publicKey: PublicKey, token: PublicKey): Promise<{
|
|
114
|
+
balance: bigint;
|
|
115
|
+
ataExists: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Returns the native currency address, we use WSOL address as placeholder for SOL
|
|
119
|
+
*/
|
|
120
|
+
getNativeCurrencyAddress(): PublicKey;
|
|
121
|
+
/**
|
|
122
|
+
* Parses string base58 representation of the token address to a PublicKey object
|
|
123
|
+
* @param address
|
|
124
|
+
*/
|
|
125
|
+
toTokenAddress(address: string): PublicKey;
|
|
126
|
+
/**
|
|
127
|
+
* Create transactions for sending a specific token to a destination address
|
|
128
|
+
*
|
|
129
|
+
* @param signer
|
|
130
|
+
* @param token token to use for the transfer
|
|
131
|
+
* @param amount amount of token in base units to transfer
|
|
132
|
+
* @param dstAddress destination address of the recipient
|
|
133
|
+
* @param feeRate fee rate to use for the transaction
|
|
134
|
+
*/
|
|
135
|
+
txsTransfer(signer: PublicKey, token: PublicKey, amount: bigint, dstAddress: PublicKey, feeRate?: string): Promise<SolanaTx[]>;
|
|
136
|
+
}
|