@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.
Files changed (114) hide show
  1. package/LICENSE +201 -201
  2. package/dist/index.d.ts +29 -29
  3. package/dist/index.js +45 -45
  4. package/dist/solana/SolanaChainType.d.ts +10 -10
  5. package/dist/solana/SolanaChainType.js +2 -2
  6. package/dist/solana/SolanaChains.d.ts +20 -20
  7. package/dist/solana/SolanaChains.js +25 -25
  8. package/dist/solana/SolanaInitializer.d.ts +18 -18
  9. package/dist/solana/SolanaInitializer.js +63 -63
  10. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +228 -228
  11. package/dist/solana/btcrelay/SolanaBtcRelay.js +441 -441
  12. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +29 -29
  13. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +34 -34
  14. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +46 -46
  15. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +78 -78
  16. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  17. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  18. package/dist/solana/chain/SolanaAction.js +86 -86
  19. package/dist/solana/chain/SolanaChainInterface.d.ts +58 -58
  20. package/dist/solana/chain/SolanaChainInterface.js +112 -112
  21. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  22. package/dist/solana/chain/SolanaModule.js +13 -13
  23. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  24. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  25. package/dist/solana/chain/modules/SolanaBlocks.d.ts +28 -28
  26. package/dist/solana/chain/modules/SolanaBlocks.js +72 -72
  27. package/dist/solana/chain/modules/SolanaEvents.d.ts +25 -25
  28. package/dist/solana/chain/modules/SolanaEvents.js +58 -58
  29. package/dist/solana/chain/modules/SolanaFees.d.ts +121 -121
  30. package/dist/solana/chain/modules/SolanaFees.js +379 -379
  31. package/dist/solana/chain/modules/SolanaSignatures.d.ts +23 -23
  32. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  33. package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
  34. package/dist/solana/chain/modules/SolanaSlots.js +68 -68
  35. package/dist/solana/chain/modules/SolanaTokens.d.ts +136 -136
  36. package/dist/solana/chain/modules/SolanaTokens.js +248 -248
  37. package/dist/solana/chain/modules/SolanaTransactions.d.ts +124 -124
  38. package/dist/solana/chain/modules/SolanaTransactions.js +332 -332
  39. package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
  40. package/dist/solana/events/SolanaChainEvents.js +256 -256
  41. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +85 -85
  42. package/dist/solana/events/SolanaChainEventsBrowser.js +194 -194
  43. package/dist/solana/program/SolanaProgramBase.d.ts +40 -40
  44. package/dist/solana/program/SolanaProgramBase.js +43 -43
  45. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  46. package/dist/solana/program/SolanaProgramModule.js +11 -11
  47. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +59 -59
  48. package/dist/solana/program/modules/SolanaProgramEvents.js +103 -103
  49. package/dist/solana/swaps/SolanaSwapData.d.ts +59 -59
  50. package/dist/solana/swaps/SolanaSwapData.js +267 -267
  51. package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
  52. package/dist/solana/swaps/SolanaSwapModule.js +11 -11
  53. package/dist/solana/swaps/SolanaSwapProgram.d.ts +202 -202
  54. package/dist/solana/swaps/SolanaSwapProgram.js +470 -463
  55. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  56. package/dist/solana/swaps/SwapTypeEnum.js +42 -42
  57. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +94 -94
  58. package/dist/solana/swaps/modules/SolanaDataAccount.js +231 -231
  59. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +71 -71
  60. package/dist/solana/swaps/modules/SolanaLpVault.js +173 -173
  61. package/dist/solana/swaps/modules/SwapClaim.d.ts +129 -129
  62. package/dist/solana/swaps/modules/SwapClaim.js +291 -291
  63. package/dist/solana/swaps/modules/SwapInit.d.ts +217 -217
  64. package/dist/solana/swaps/modules/SwapInit.js +519 -519
  65. package/dist/solana/swaps/modules/SwapRefund.d.ts +82 -82
  66. package/dist/solana/swaps/modules/SwapRefund.js +252 -252
  67. package/dist/solana/swaps/programIdl.json +945 -945
  68. package/dist/solana/swaps/programTypes.d.ts +943 -943
  69. package/dist/solana/swaps/programTypes.js +945 -945
  70. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +9 -9
  71. package/dist/solana/wallet/SolanaKeypairWallet.js +33 -33
  72. package/dist/solana/wallet/SolanaSigner.d.ts +10 -10
  73. package/dist/solana/wallet/SolanaSigner.js +16 -16
  74. package/dist/utils/Utils.d.ts +53 -53
  75. package/dist/utils/Utils.js +170 -170
  76. package/package.json +41 -41
  77. package/src/index.ts +36 -36
  78. package/src/solana/SolanaChainType.ts +25 -25
  79. package/src/solana/SolanaChains.ts +23 -23
  80. package/src/solana/SolanaInitializer.ts +102 -102
  81. package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -588
  82. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +57 -57
  83. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +102 -102
  84. package/src/solana/btcrelay/program/programIdl.json +670 -670
  85. package/src/solana/chain/SolanaAction.ts +108 -108
  86. package/src/solana/chain/SolanaChainInterface.ts +174 -174
  87. package/src/solana/chain/SolanaModule.ts +20 -20
  88. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  89. package/src/solana/chain/modules/SolanaBlocks.ts +78 -78
  90. package/src/solana/chain/modules/SolanaEvents.ts +56 -56
  91. package/src/solana/chain/modules/SolanaFees.ts +450 -450
  92. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  93. package/src/solana/chain/modules/SolanaSlots.ts +82 -82
  94. package/src/solana/chain/modules/SolanaTokens.ts +307 -307
  95. package/src/solana/chain/modules/SolanaTransactions.ts +370 -370
  96. package/src/solana/events/SolanaChainEvents.ts +299 -299
  97. package/src/solana/events/SolanaChainEventsBrowser.ts +256 -256
  98. package/src/solana/program/SolanaProgramBase.ts +79 -79
  99. package/src/solana/program/SolanaProgramModule.ts +15 -15
  100. package/src/solana/program/modules/SolanaProgramEvents.ts +140 -140
  101. package/src/solana/swaps/SolanaSwapData.ts +379 -379
  102. package/src/solana/swaps/SolanaSwapModule.ts +16 -16
  103. package/src/solana/swaps/SolanaSwapProgram.ts +697 -692
  104. package/src/solana/swaps/SwapTypeEnum.ts +29 -29
  105. package/src/solana/swaps/modules/SolanaDataAccount.ts +307 -307
  106. package/src/solana/swaps/modules/SolanaLpVault.ts +215 -215
  107. package/src/solana/swaps/modules/SwapClaim.ts +389 -389
  108. package/src/solana/swaps/modules/SwapInit.ts +663 -663
  109. package/src/solana/swaps/modules/SwapRefund.ts +312 -312
  110. package/src/solana/swaps/programIdl.json +944 -944
  111. package/src/solana/swaps/programTypes.ts +1885 -1885
  112. package/src/solana/wallet/SolanaKeypairWallet.ts +36 -36
  113. package/src/solana/wallet/SolanaSigner.ts +23 -23
  114. package/src/utils/Utils.ts +180 -180
@@ -1,43 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaProgramBase = void 0;
4
- const anchor_1 = require("@coral-xyz/anchor");
5
- const SolanaProgramEvents_1 = require("./modules/SolanaProgramEvents");
6
- const web3_js_1 = require("@solana/web3.js");
7
- const sha2_1 = require("@noble/hashes/sha2");
8
- const buffer_1 = require("buffer");
9
- const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
10
- const Utils_1 = require("../../utils/Utils");
11
- /**
12
- * Base class providing program specific utilities
13
- */
14
- class SolanaProgramBase {
15
- constructor(chainInterface, programIdl, programAddress) {
16
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
17
- this.Chain = chainInterface;
18
- this.program = new anchor_1.Program(programIdl, programAddress || programIdl.metadata.address, new anchor_1.AnchorProvider(chainInterface.connection, new SolanaKeypairWallet_1.SolanaKeypairWallet(web3_js_1.Keypair.generate()), {}));
19
- this.Events = new SolanaProgramEvents_1.SolanaProgramEvents(chainInterface, this);
20
- }
21
- pda(seed, func) {
22
- if (func == null) {
23
- return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)], this.program.programId)[0];
24
- }
25
- return (...args) => {
26
- const res = func(...args);
27
- return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)].concat(res), this.program.programId)[0];
28
- };
29
- }
30
- /**
31
- * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
32
- *
33
- * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
34
- */
35
- keypair(func) {
36
- return (...args) => {
37
- const res = func(...args);
38
- const buff = (0, sha2_1.sha256)(buffer_1.Buffer.concat(res));
39
- return web3_js_1.Keypair.fromSeed(buff);
40
- };
41
- }
42
- }
43
- exports.SolanaProgramBase = SolanaProgramBase;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaProgramBase = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const SolanaProgramEvents_1 = require("./modules/SolanaProgramEvents");
6
+ const web3_js_1 = require("@solana/web3.js");
7
+ const sha2_1 = require("@noble/hashes/sha2");
8
+ const buffer_1 = require("buffer");
9
+ const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
10
+ const Utils_1 = require("../../utils/Utils");
11
+ /**
12
+ * Base class providing program specific utilities
13
+ */
14
+ class SolanaProgramBase {
15
+ constructor(chainInterface, programIdl, programAddress) {
16
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
17
+ this.Chain = chainInterface;
18
+ this.program = new anchor_1.Program(programIdl, programAddress || programIdl.metadata.address, new anchor_1.AnchorProvider(chainInterface.connection, new SolanaKeypairWallet_1.SolanaKeypairWallet(web3_js_1.Keypair.generate()), {}));
19
+ this.Events = new SolanaProgramEvents_1.SolanaProgramEvents(chainInterface, this);
20
+ }
21
+ pda(seed, func) {
22
+ if (func == null) {
23
+ return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)], this.program.programId)[0];
24
+ }
25
+ return (...args) => {
26
+ const res = func(...args);
27
+ return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)].concat(res), this.program.programId)[0];
28
+ };
29
+ }
30
+ /**
31
+ * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
32
+ *
33
+ * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
34
+ */
35
+ keypair(func) {
36
+ return (...args) => {
37
+ const res = func(...args);
38
+ const buff = (0, sha2_1.sha256)(buffer_1.Buffer.concat(res));
39
+ return web3_js_1.Keypair.fromSeed(buff);
40
+ };
41
+ }
42
+ }
43
+ exports.SolanaProgramBase = SolanaProgramBase;
@@ -1,8 +1,8 @@
1
- import { SolanaModule } from "../chain/SolanaModule";
2
- import { Idl } from "@coral-xyz/anchor";
3
- import { SolanaProgramBase } from "./SolanaProgramBase";
4
- import { SolanaChainInterface } from "../chain/SolanaChainInterface";
5
- export declare class SolanaProgramModule<IDL extends Idl> extends SolanaModule {
6
- protected readonly program: SolanaProgramBase<IDL>;
7
- constructor(chainInterface: SolanaChainInterface, program: SolanaProgramBase<IDL>);
8
- }
1
+ import { SolanaModule } from "../chain/SolanaModule";
2
+ import { Idl } from "@coral-xyz/anchor";
3
+ import { SolanaProgramBase } from "./SolanaProgramBase";
4
+ import { SolanaChainInterface } from "../chain/SolanaChainInterface";
5
+ export declare class SolanaProgramModule<IDL extends Idl> extends SolanaModule {
6
+ protected readonly program: SolanaProgramBase<IDL>;
7
+ constructor(chainInterface: SolanaChainInterface, program: SolanaProgramBase<IDL>);
8
+ }
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaProgramModule = void 0;
4
- const SolanaModule_1 = require("../chain/SolanaModule");
5
- class SolanaProgramModule extends SolanaModule_1.SolanaModule {
6
- constructor(chainInterface, program) {
7
- super(chainInterface);
8
- this.program = program;
9
- }
10
- }
11
- exports.SolanaProgramModule = SolanaProgramModule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaProgramModule = void 0;
4
+ const SolanaModule_1 = require("../chain/SolanaModule");
5
+ class SolanaProgramModule extends SolanaModule_1.SolanaModule {
6
+ constructor(chainInterface, program) {
7
+ super(chainInterface);
8
+ this.program = program;
9
+ }
10
+ }
11
+ exports.SolanaProgramModule = SolanaProgramModule;
@@ -1,59 +1,59 @@
1
- import { SolanaEvents } from "../../chain/modules/SolanaEvents";
2
- import { DecodeType, Event, Idl, IdlTypes } from "@coral-xyz/anchor";
3
- import { IdlField, IdlInstruction } from "@coral-xyz/anchor/dist/cjs/idl";
4
- import { ConfirmedSignatureInfo, ParsedMessage, PublicKey } from "@solana/web3.js";
5
- import { SolanaProgramBase } from "../SolanaProgramBase";
6
- import { SolanaChainInterface } from "../../chain/SolanaChainInterface";
7
- type DecodedFieldOrNull<D, Defined> = D extends IdlField ? DecodeType<D["type"], Defined> : unknown;
8
- type ArgsTuple<A extends IdlField[], Defined> = {
9
- [K in A[number]["name"]]: DecodedFieldOrNull<Extract<A[number], {
10
- name: K;
11
- }>, Defined>;
12
- };
13
- export type InstructionWithAccounts<IDL extends Idl> = SingleInstructionWithAccounts<IDL["instructions"][number], IDL>;
14
- export type SingleInstructionWithAccounts<I extends IdlInstruction, IDL extends Idl> = {
15
- name: I["name"];
16
- accounts: {
17
- [key in I["accounts"][number]["name"]]: PublicKey;
18
- };
19
- data: ArgsTuple<I["args"], IdlTypes<IDL>>;
20
- };
21
- export type ProgramEvent<IDL extends Idl> = Event<IDL["events"][number], Record<string, any>>;
22
- export declare class SolanaProgramEvents<IDL extends Idl> extends SolanaEvents {
23
- private readonly programCoder;
24
- private readonly eventParser;
25
- private readonly program;
26
- private readonly nameMappedInstructions;
27
- constructor(chain: SolanaChainInterface, program: SolanaProgramBase<IDL>);
28
- /**
29
- * Gets events from specific transaction as specified by signature, events are ordered from newest to oldest
30
- *
31
- * @param signature
32
- * @private
33
- */
34
- private getEvents;
35
- /**
36
- * Runs a search backwards in time, processing the events for a specific topic public key
37
- *
38
- * @param topicKey
39
- * @param processor called for every event, should return a value if the correct event was found, or null
40
- * if the search should continue
41
- * @param abortSignal
42
- * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
43
- */
44
- findInEvents<T>(topicKey: PublicKey, processor: (event: ProgramEvent<IDL>, info: ConfirmedSignatureInfo) => Promise<T>, abortSignal?: AbortSignal, logBatchSize?: number): Promise<T>;
45
- /**
46
- * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
47
- * for every instruction that doesn't correspond to this program (as those are impossible to parse)
48
- *
49
- * @param transactionMessage
50
- */
51
- decodeInstructions(transactionMessage: ParsedMessage): InstructionWithAccounts<IDL>[];
52
- /**
53
- * Parses program event related to this program from transaction logs
54
- *
55
- * @param logs
56
- */
57
- parseLogs(logs: string[]): ProgramEvent<IDL>[];
58
- }
59
- export {};
1
+ import { SolanaEvents } from "../../chain/modules/SolanaEvents";
2
+ import { DecodeType, Event, Idl, IdlTypes } from "@coral-xyz/anchor";
3
+ import { IdlField, IdlInstruction } from "@coral-xyz/anchor/dist/cjs/idl";
4
+ import { ConfirmedSignatureInfo, ParsedMessage, PublicKey } from "@solana/web3.js";
5
+ import { SolanaProgramBase } from "../SolanaProgramBase";
6
+ import { SolanaChainInterface } from "../../chain/SolanaChainInterface";
7
+ type DecodedFieldOrNull<D, Defined> = D extends IdlField ? DecodeType<D["type"], Defined> : unknown;
8
+ type ArgsTuple<A extends IdlField[], Defined> = {
9
+ [K in A[number]["name"]]: DecodedFieldOrNull<Extract<A[number], {
10
+ name: K;
11
+ }>, Defined>;
12
+ };
13
+ export type InstructionWithAccounts<IDL extends Idl> = SingleInstructionWithAccounts<IDL["instructions"][number], IDL>;
14
+ export type SingleInstructionWithAccounts<I extends IdlInstruction, IDL extends Idl> = {
15
+ name: I["name"];
16
+ accounts: {
17
+ [key in I["accounts"][number]["name"]]: PublicKey;
18
+ };
19
+ data: ArgsTuple<I["args"], IdlTypes<IDL>>;
20
+ };
21
+ export type ProgramEvent<IDL extends Idl> = Event<IDL["events"][number], Record<string, any>>;
22
+ export declare class SolanaProgramEvents<IDL extends Idl> extends SolanaEvents {
23
+ private readonly programCoder;
24
+ private readonly eventParser;
25
+ private readonly program;
26
+ private readonly nameMappedInstructions;
27
+ constructor(chain: SolanaChainInterface, program: SolanaProgramBase<IDL>);
28
+ /**
29
+ * Gets events from specific transaction as specified by signature, events are ordered from newest to oldest
30
+ *
31
+ * @param signature
32
+ * @private
33
+ */
34
+ private getEvents;
35
+ /**
36
+ * Runs a search backwards in time, processing the events for a specific topic public key
37
+ *
38
+ * @param topicKey
39
+ * @param processor called for every event, should return a value if the correct event was found, or null
40
+ * if the search should continue
41
+ * @param abortSignal
42
+ * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
43
+ */
44
+ findInEvents<T>(topicKey: PublicKey, processor: (event: ProgramEvent<IDL>, info: ConfirmedSignatureInfo) => Promise<T>, abortSignal?: AbortSignal, logBatchSize?: number): Promise<T>;
45
+ /**
46
+ * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
47
+ * for every instruction that doesn't correspond to this program (as those are impossible to parse)
48
+ *
49
+ * @param transactionMessage
50
+ */
51
+ decodeInstructions(transactionMessage: ParsedMessage): InstructionWithAccounts<IDL>[];
52
+ /**
53
+ * Parses program event related to this program from transaction logs
54
+ *
55
+ * @param logs
56
+ */
57
+ parseLogs(logs: string[]): ProgramEvent<IDL>[];
58
+ }
59
+ export {};
@@ -1,103 +1,103 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaProgramEvents = void 0;
4
- const SolanaEvents_1 = require("../../chain/modules/SolanaEvents");
5
- const anchor_1 = require("@coral-xyz/anchor");
6
- class SolanaProgramEvents extends SolanaEvents_1.SolanaEvents {
7
- constructor(chain, program) {
8
- super(chain);
9
- this.program = program;
10
- this.programCoder = new anchor_1.BorshCoder(program.program.idl);
11
- this.eventParser = new anchor_1.EventParser(program.program.programId, this.programCoder);
12
- this.nameMappedInstructions = {};
13
- for (let ix of program.program.idl.instructions) {
14
- this.nameMappedInstructions[ix.name] = ix;
15
- }
16
- }
17
- /**
18
- * Gets events from specific transaction as specified by signature, events are ordered from newest to oldest
19
- *
20
- * @param signature
21
- * @private
22
- */
23
- async getEvents(signature) {
24
- const tx = await this.connection.getTransaction(signature, {
25
- commitment: "confirmed",
26
- maxSupportedTransactionVersion: 0
27
- });
28
- if (tx.meta.err)
29
- return [];
30
- const events = this.parseLogs(tx.meta.logMessages);
31
- events.reverse();
32
- return events;
33
- }
34
- /**
35
- * Runs a search backwards in time, processing the events for a specific topic public key
36
- *
37
- * @param topicKey
38
- * @param processor called for every event, should return a value if the correct event was found, or null
39
- * if the search should continue
40
- * @param abortSignal
41
- * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
42
- */
43
- findInEvents(topicKey, processor, abortSignal, logBatchSize) {
44
- return this.findInSignatures(topicKey, async (signatures) => {
45
- for (let data of signatures) {
46
- for (let event of await this.getEvents(data.signature)) {
47
- if (abortSignal != null)
48
- abortSignal.throwIfAborted();
49
- const result = await processor(event, data);
50
- if (result != null)
51
- return result;
52
- }
53
- }
54
- }, abortSignal, logBatchSize);
55
- }
56
- /**
57
- * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
58
- * for every instruction that doesn't correspond to this program (as those are impossible to parse)
59
- *
60
- * @param transactionMessage
61
- */
62
- decodeInstructions(transactionMessage) {
63
- const instructions = [];
64
- for (let _ix of transactionMessage.instructions) {
65
- if (!_ix.programId.equals(this.program.program.programId)) {
66
- instructions.push(null);
67
- continue;
68
- }
69
- const ix = _ix;
70
- if (ix.data == null)
71
- continue;
72
- const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
73
- const accountsData = this.nameMappedInstructions[parsedIx.name];
74
- let accounts;
75
- if (accountsData != null && accountsData.accounts != null) {
76
- accounts = {};
77
- for (let i = 0; i < accountsData.accounts.length; i++) {
78
- accounts[accountsData.accounts[i].name] = ix.accounts[i];
79
- }
80
- }
81
- instructions.push({
82
- name: parsedIx.name,
83
- data: parsedIx.data,
84
- accounts: accounts
85
- });
86
- }
87
- return instructions;
88
- }
89
- /**
90
- * Parses program event related to this program from transaction logs
91
- *
92
- * @param logs
93
- */
94
- parseLogs(logs) {
95
- const eventsGenerator = this.eventParser.parseLogs(logs);
96
- const events = [];
97
- for (let log of eventsGenerator) {
98
- events.push(log);
99
- }
100
- return events;
101
- }
102
- }
103
- exports.SolanaProgramEvents = SolanaProgramEvents;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaProgramEvents = void 0;
4
+ const SolanaEvents_1 = require("../../chain/modules/SolanaEvents");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
+ class SolanaProgramEvents extends SolanaEvents_1.SolanaEvents {
7
+ constructor(chain, program) {
8
+ super(chain);
9
+ this.program = program;
10
+ this.programCoder = new anchor_1.BorshCoder(program.program.idl);
11
+ this.eventParser = new anchor_1.EventParser(program.program.programId, this.programCoder);
12
+ this.nameMappedInstructions = {};
13
+ for (let ix of program.program.idl.instructions) {
14
+ this.nameMappedInstructions[ix.name] = ix;
15
+ }
16
+ }
17
+ /**
18
+ * Gets events from specific transaction as specified by signature, events are ordered from newest to oldest
19
+ *
20
+ * @param signature
21
+ * @private
22
+ */
23
+ async getEvents(signature) {
24
+ const tx = await this.connection.getTransaction(signature, {
25
+ commitment: "confirmed",
26
+ maxSupportedTransactionVersion: 0
27
+ });
28
+ if (tx.meta.err)
29
+ return [];
30
+ const events = this.parseLogs(tx.meta.logMessages);
31
+ events.reverse();
32
+ return events;
33
+ }
34
+ /**
35
+ * Runs a search backwards in time, processing the events for a specific topic public key
36
+ *
37
+ * @param topicKey
38
+ * @param processor called for every event, should return a value if the correct event was found, or null
39
+ * if the search should continue
40
+ * @param abortSignal
41
+ * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
42
+ */
43
+ findInEvents(topicKey, processor, abortSignal, logBatchSize) {
44
+ return this.findInSignatures(topicKey, async (signatures) => {
45
+ for (let data of signatures) {
46
+ for (let event of await this.getEvents(data.signature)) {
47
+ if (abortSignal != null)
48
+ abortSignal.throwIfAborted();
49
+ const result = await processor(event, data);
50
+ if (result != null)
51
+ return result;
52
+ }
53
+ }
54
+ }, abortSignal, logBatchSize);
55
+ }
56
+ /**
57
+ * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
58
+ * for every instruction that doesn't correspond to this program (as those are impossible to parse)
59
+ *
60
+ * @param transactionMessage
61
+ */
62
+ decodeInstructions(transactionMessage) {
63
+ const instructions = [];
64
+ for (let _ix of transactionMessage.instructions) {
65
+ if (!_ix.programId.equals(this.program.program.programId)) {
66
+ instructions.push(null);
67
+ continue;
68
+ }
69
+ const ix = _ix;
70
+ if (ix.data == null)
71
+ continue;
72
+ const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
73
+ const accountsData = this.nameMappedInstructions[parsedIx.name];
74
+ let accounts;
75
+ if (accountsData != null && accountsData.accounts != null) {
76
+ accounts = {};
77
+ for (let i = 0; i < accountsData.accounts.length; i++) {
78
+ accounts[accountsData.accounts[i].name] = ix.accounts[i];
79
+ }
80
+ }
81
+ instructions.push({
82
+ name: parsedIx.name,
83
+ data: parsedIx.data,
84
+ accounts: accounts
85
+ });
86
+ }
87
+ return instructions;
88
+ }
89
+ /**
90
+ * Parses program event related to this program from transaction logs
91
+ *
92
+ * @param logs
93
+ */
94
+ parseLogs(logs) {
95
+ const eventsGenerator = this.eventParser.parseLogs(logs);
96
+ const events = [];
97
+ for (let log of eventsGenerator) {
98
+ events.push(log);
99
+ }
100
+ return events;
101
+ }
102
+ }
103
+ exports.SolanaProgramEvents = SolanaProgramEvents;
@@ -1,59 +1,59 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- import * as BN from "bn.js";
3
- import { SwapData, ChainSwapType } from "@atomiqlabs/base";
4
- import { SwapProgram } from "./programTypes";
5
- import { IdlAccounts, IdlTypes } from "@coral-xyz/anchor";
6
- export declare class SolanaSwapData extends SwapData {
7
- offerer: PublicKey;
8
- claimer: PublicKey;
9
- token: PublicKey;
10
- amount: BN;
11
- paymentHash: string;
12
- sequence: BN;
13
- expiry: BN;
14
- nonce: BN;
15
- confirmations: number;
16
- payOut: boolean;
17
- kind: number;
18
- payIn: boolean;
19
- claimerAta?: PublicKey;
20
- offererAta?: PublicKey;
21
- securityDeposit: BN;
22
- claimerBounty: BN;
23
- txoHash: string;
24
- constructor(offerer: PublicKey, claimer: PublicKey, token: PublicKey, amount: BN, paymentHash: string, sequence: BN, expiry: BN, nonce: BN, confirmations: number, payOut: boolean, kind: number, payIn: boolean, offererAta: PublicKey, claimerAta: PublicKey, securityDeposit: BN, claimerBounty: BN, txoHash: string);
25
- constructor(data: any);
26
- getOfferer(): string;
27
- setOfferer(newOfferer: string): void;
28
- getClaimer(): string;
29
- setClaimer(newClaimer: string): void;
30
- serialize(): any;
31
- getAmount(): bigint;
32
- getToken(): string;
33
- isToken(token: string): boolean;
34
- getType(): ChainSwapType;
35
- getExpiry(): bigint;
36
- getConfirmationsHint(): number;
37
- getNonceHint(): bigint;
38
- isPayIn(): boolean;
39
- isPayOut(): boolean;
40
- getClaimHash(): string;
41
- getEscrowHash(): string;
42
- getSequence(): bigint;
43
- getTxoHashHint(): string;
44
- getExtraData(): string;
45
- setExtraData(txoHash: string): void;
46
- getSecurityDeposit(): bigint;
47
- getClaimerBounty(): bigint;
48
- getTotalDeposit(): bigint;
49
- toSwapDataStruct(): IdlTypes<SwapProgram>["SwapData"];
50
- correctPDA(account: IdlAccounts<SwapProgram>["escrowState"]): boolean;
51
- equals(other: SolanaSwapData): boolean;
52
- static fromEscrowState(account: IdlAccounts<SwapProgram>["escrowState"]): SolanaSwapData;
53
- static typeToKind(type: ChainSwapType): number;
54
- static kindToType(value: number): ChainSwapType;
55
- isClaimer(address: string): boolean;
56
- isOfferer(address: string): boolean;
57
- getDepositToken(): string;
58
- isDepositToken(token: string): boolean;
59
- }
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import * as BN from "bn.js";
3
+ import { SwapData, ChainSwapType } from "@atomiqlabs/base";
4
+ import { SwapProgram } from "./programTypes";
5
+ import { IdlAccounts, IdlTypes } from "@coral-xyz/anchor";
6
+ export declare class SolanaSwapData extends SwapData {
7
+ offerer: PublicKey;
8
+ claimer: PublicKey;
9
+ token: PublicKey;
10
+ amount: BN;
11
+ paymentHash: string;
12
+ sequence: BN;
13
+ expiry: BN;
14
+ nonce: BN;
15
+ confirmations: number;
16
+ payOut: boolean;
17
+ kind: number;
18
+ payIn: boolean;
19
+ claimerAta?: PublicKey;
20
+ offererAta?: PublicKey;
21
+ securityDeposit: BN;
22
+ claimerBounty: BN;
23
+ txoHash: string;
24
+ constructor(offerer: PublicKey, claimer: PublicKey, token: PublicKey, amount: BN, paymentHash: string, sequence: BN, expiry: BN, nonce: BN, confirmations: number, payOut: boolean, kind: number, payIn: boolean, offererAta: PublicKey, claimerAta: PublicKey, securityDeposit: BN, claimerBounty: BN, txoHash: string);
25
+ constructor(data: any);
26
+ getOfferer(): string;
27
+ setOfferer(newOfferer: string): void;
28
+ getClaimer(): string;
29
+ setClaimer(newClaimer: string): void;
30
+ serialize(): any;
31
+ getAmount(): bigint;
32
+ getToken(): string;
33
+ isToken(token: string): boolean;
34
+ getType(): ChainSwapType;
35
+ getExpiry(): bigint;
36
+ getConfirmationsHint(): number;
37
+ getNonceHint(): bigint;
38
+ isPayIn(): boolean;
39
+ isPayOut(): boolean;
40
+ getClaimHash(): string;
41
+ getEscrowHash(): string;
42
+ getSequence(): bigint;
43
+ getTxoHashHint(): string;
44
+ getExtraData(): string;
45
+ setExtraData(txoHash: string): void;
46
+ getSecurityDeposit(): bigint;
47
+ getClaimerBounty(): bigint;
48
+ getTotalDeposit(): bigint;
49
+ toSwapDataStruct(): IdlTypes<SwapProgram>["SwapData"];
50
+ correctPDA(account: IdlAccounts<SwapProgram>["escrowState"]): boolean;
51
+ equals(other: SolanaSwapData): boolean;
52
+ static fromEscrowState(account: IdlAccounts<SwapProgram>["escrowState"]): SolanaSwapData;
53
+ static typeToKind(type: ChainSwapType): number;
54
+ static kindToType(value: number): ChainSwapType;
55
+ isClaimer(address: string): boolean;
56
+ isOfferer(address: string): boolean;
57
+ getDepositToken(): string;
58
+ isDepositToken(token: string): boolean;
59
+ }