@atomiqlabs/chain-solana 13.5.13 → 13.5.14

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 (131) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +73 -73
  3. package/dist/index.d.ts +81 -81
  4. package/dist/index.js +102 -102
  5. package/dist/node/index.d.ts +9 -9
  6. package/dist/node/index.js +13 -13
  7. package/dist/solana/SolanaChainType.d.ts +15 -15
  8. package/dist/solana/SolanaChainType.js +2 -2
  9. package/dist/solana/SolanaChains.d.ts +12 -12
  10. package/dist/solana/SolanaChains.js +45 -45
  11. package/dist/solana/SolanaInitializer.d.ts +94 -94
  12. package/dist/solana/SolanaInitializer.js +174 -174
  13. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +222 -222
  14. package/dist/solana/btcrelay/SolanaBtcRelay.js +455 -455
  15. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +84 -84
  16. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +70 -70
  17. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +92 -92
  18. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +109 -109
  19. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  20. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  21. package/dist/solana/chain/SolanaAction.js +87 -87
  22. package/dist/solana/chain/SolanaChainInterface.d.ts +224 -224
  23. package/dist/solana/chain/SolanaChainInterface.js +275 -275
  24. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  25. package/dist/solana/chain/SolanaModule.js +13 -13
  26. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  27. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  28. package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -32
  29. package/dist/solana/chain/modules/SolanaBlocks.js +78 -78
  30. package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
  31. package/dist/solana/chain/modules/SolanaEvents.js +238 -238
  32. package/dist/solana/chain/modules/SolanaFees.d.ts +189 -189
  33. package/dist/solana/chain/modules/SolanaFees.js +434 -434
  34. package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -24
  35. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  36. package/dist/solana/chain/modules/SolanaSlots.d.ts +33 -33
  37. package/dist/solana/chain/modules/SolanaSlots.js +72 -72
  38. package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -123
  39. package/dist/solana/chain/modules/SolanaTokens.js +242 -242
  40. package/dist/solana/chain/modules/SolanaTransactions.d.ts +149 -149
  41. package/dist/solana/chain/modules/SolanaTransactions.js +445 -445
  42. package/dist/solana/connection/ConnectionWithRetries.d.ts +35 -35
  43. package/dist/solana/connection/ConnectionWithRetries.js +86 -71
  44. package/dist/solana/events/SolanaChainEvents.d.ts +45 -45
  45. package/dist/solana/events/SolanaChainEvents.js +108 -108
  46. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +205 -205
  47. package/dist/solana/events/SolanaChainEventsBrowser.js +404 -404
  48. package/dist/solana/program/SolanaProgramBase.d.ts +73 -73
  49. package/dist/solana/program/SolanaProgramBase.js +54 -54
  50. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  51. package/dist/solana/program/SolanaProgramModule.js +11 -11
  52. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
  53. package/dist/solana/program/modules/SolanaProgramEvents.js +117 -117
  54. package/dist/solana/swaps/SolanaSwapData.d.ts +333 -333
  55. package/dist/solana/swaps/SolanaSwapData.js +535 -535
  56. package/dist/solana/swaps/SolanaSwapModule.d.ts +11 -11
  57. package/dist/solana/swaps/SolanaSwapModule.js +12 -12
  58. package/dist/solana/swaps/SolanaSwapProgram.d.ts +376 -376
  59. package/dist/solana/swaps/SolanaSwapProgram.js +769 -769
  60. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  61. package/dist/solana/swaps/SwapTypeEnum.js +43 -43
  62. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -95
  63. package/dist/solana/swaps/modules/SolanaDataAccount.js +232 -232
  64. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -69
  65. package/dist/solana/swaps/modules/SolanaLpVault.js +171 -171
  66. package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -126
  67. package/dist/solana/swaps/modules/SwapClaim.js +294 -294
  68. package/dist/solana/swaps/modules/SwapInit.d.ts +213 -213
  69. package/dist/solana/swaps/modules/SwapInit.js +658 -658
  70. package/dist/solana/swaps/modules/SwapRefund.d.ts +87 -87
  71. package/dist/solana/swaps/modules/SwapRefund.js +293 -293
  72. package/dist/solana/swaps/programIdl.json +945 -945
  73. package/dist/solana/swaps/programTypes.d.ts +943 -943
  74. package/dist/solana/swaps/programTypes.js +945 -945
  75. package/dist/solana/swaps/v1/programIdl.json +945 -945
  76. package/dist/solana/swaps/v1/programTypes.d.ts +943 -943
  77. package/dist/solana/swaps/v1/programTypes.js +945 -945
  78. package/dist/solana/swaps/v2/programIdl.json +952 -952
  79. package/dist/solana/swaps/v2/programTypes.d.ts +950 -950
  80. package/dist/solana/swaps/v2/programTypes.js +952 -952
  81. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +29 -29
  82. package/dist/solana/wallet/SolanaKeypairWallet.js +50 -50
  83. package/dist/solana/wallet/SolanaSigner.d.ts +30 -30
  84. package/dist/solana/wallet/SolanaSigner.js +30 -30
  85. package/dist/utils/Utils.d.ts +58 -58
  86. package/dist/utils/Utils.js +170 -170
  87. package/node/index.d.ts +1 -1
  88. package/node/index.js +3 -3
  89. package/package.json +46 -46
  90. package/src/index.ts +87 -87
  91. package/src/node/index.ts +9 -9
  92. package/src/solana/SolanaChainType.ts +32 -32
  93. package/src/solana/SolanaChains.ts +46 -46
  94. package/src/solana/SolanaInitializer.ts +278 -278
  95. package/src/solana/btcrelay/SolanaBtcRelay.ts +615 -615
  96. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +116 -116
  97. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +148 -148
  98. package/src/solana/btcrelay/program/programIdl.json +670 -670
  99. package/src/solana/chain/SolanaAction.ts +109 -109
  100. package/src/solana/chain/SolanaChainInterface.ts +404 -404
  101. package/src/solana/chain/SolanaModule.ts +20 -20
  102. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  103. package/src/solana/chain/modules/SolanaBlocks.ts +89 -89
  104. package/src/solana/chain/modules/SolanaEvents.ts +271 -271
  105. package/src/solana/chain/modules/SolanaFees.ts +522 -522
  106. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  107. package/src/solana/chain/modules/SolanaSlots.ts +85 -85
  108. package/src/solana/chain/modules/SolanaTokens.ts +300 -300
  109. package/src/solana/chain/modules/SolanaTransactions.ts +503 -503
  110. package/src/solana/connection/ConnectionWithRetries.ts +113 -96
  111. package/src/solana/events/SolanaChainEvents.ts +127 -127
  112. package/src/solana/events/SolanaChainEventsBrowser.ts +495 -495
  113. package/src/solana/program/SolanaProgramBase.ts +119 -119
  114. package/src/solana/program/SolanaProgramModule.ts +15 -15
  115. package/src/solana/program/modules/SolanaProgramEvents.ts +157 -157
  116. package/src/solana/swaps/SolanaSwapData.ts +735 -735
  117. package/src/solana/swaps/SolanaSwapModule.ts +19 -19
  118. package/src/solana/swaps/SolanaSwapProgram.ts +1074 -1074
  119. package/src/solana/swaps/SwapTypeEnum.ts +30 -30
  120. package/src/solana/swaps/modules/SolanaDataAccount.ts +302 -302
  121. package/src/solana/swaps/modules/SolanaLpVault.ts +208 -208
  122. package/src/solana/swaps/modules/SwapClaim.ts +387 -387
  123. package/src/solana/swaps/modules/SwapInit.ts +785 -785
  124. package/src/solana/swaps/modules/SwapRefund.ts +353 -353
  125. package/src/solana/swaps/v1/programIdl.json +944 -944
  126. package/src/solana/swaps/v1/programTypes.ts +1885 -1885
  127. package/src/solana/swaps/v2/programIdl.json +951 -951
  128. package/src/solana/swaps/v2/programTypes.ts +1899 -1899
  129. package/src/solana/wallet/SolanaKeypairWallet.ts +56 -56
  130. package/src/solana/wallet/SolanaSigner.ts +43 -43
  131. package/src/utils/Utils.ts +194 -194
@@ -1,73 +1,73 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Idl, Program } from "@coral-xyz/anchor";
4
- import { SolanaChainInterface } from "../chain/SolanaChainInterface";
5
- import { SolanaProgramEvents } from "./modules/SolanaProgramEvents";
6
- import { Keypair, PublicKey } from "@solana/web3.js";
7
- import { Buffer } from "buffer";
8
- /**
9
- * Base class providing program specific utilities
10
- */
11
- export declare class SolanaProgramBase<T extends Idl> {
12
- /**
13
- * @internal
14
- */
15
- protected readonly logger: {
16
- debug: (msg: string, ...args: any[]) => false | void;
17
- info: (msg: string, ...args: any[]) => false | void;
18
- warn: (msg: string, ...args: any[]) => false | void;
19
- error: (msg: string, ...args: any[]) => false | void;
20
- };
21
- program: Program<T>;
22
- /**
23
- * @internal
24
- */
25
- readonly _Events: SolanaProgramEvents<T>;
26
- /**
27
- * @internal
28
- */
29
- readonly _Chain: SolanaChainInterface;
30
- constructor(chainInterface: SolanaChainInterface, programIdl: any, programAddress?: string);
31
- /**
32
- * Derives static PDA address from the seed
33
- *
34
- * @param seed
35
- *
36
- * @internal
37
- */
38
- protected pda(seed: string): PublicKey;
39
- /**
40
- * Returns a function for deriving a dynamic PDA address from seed + dynamic arguments
41
- *
42
- * @param seed
43
- * @param func function translating the function argument to Buffer[]
44
- *
45
- * @internal
46
- */
47
- protected pda<T extends Array<any>>(seed: string, func: (...args: T) => Buffer[]): (...args: T) => PublicKey;
48
- /**
49
- * Derives static PDA address from the seed
50
- *
51
- * @param seed
52
- *
53
- * @internal
54
- */
55
- static _pda(seed: string): (programId: PublicKey) => PublicKey;
56
- /**
57
- * Returns a function for deriving a dynamic PDA address from seed + dynamic arguments
58
- *
59
- * @param seed
60
- * @param func function translating the function argument to Buffer[]
61
- *
62
- * @internal
63
- */
64
- static _pda<T extends Array<any>>(seed: string, func: (...args: T) => Buffer[]): (programId: PublicKey, ...args: T) => PublicKey;
65
- /**
66
- * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
67
- *
68
- * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
69
- *
70
- * @internal
71
- */
72
- _keypair<T extends Array<any>>(func: (...args: T) => Buffer[]): (...args: T) => Keypair;
73
- }
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Idl, Program } from "@coral-xyz/anchor";
4
+ import { SolanaChainInterface } from "../chain/SolanaChainInterface";
5
+ import { SolanaProgramEvents } from "./modules/SolanaProgramEvents";
6
+ import { Keypair, PublicKey } from "@solana/web3.js";
7
+ import { Buffer } from "buffer";
8
+ /**
9
+ * Base class providing program specific utilities
10
+ */
11
+ export declare class SolanaProgramBase<T extends Idl> {
12
+ /**
13
+ * @internal
14
+ */
15
+ protected readonly logger: {
16
+ debug: (msg: string, ...args: any[]) => false | void;
17
+ info: (msg: string, ...args: any[]) => false | void;
18
+ warn: (msg: string, ...args: any[]) => false | void;
19
+ error: (msg: string, ...args: any[]) => false | void;
20
+ };
21
+ program: Program<T>;
22
+ /**
23
+ * @internal
24
+ */
25
+ readonly _Events: SolanaProgramEvents<T>;
26
+ /**
27
+ * @internal
28
+ */
29
+ readonly _Chain: SolanaChainInterface;
30
+ constructor(chainInterface: SolanaChainInterface, programIdl: any, programAddress?: string);
31
+ /**
32
+ * Derives static PDA address from the seed
33
+ *
34
+ * @param seed
35
+ *
36
+ * @internal
37
+ */
38
+ protected pda(seed: string): PublicKey;
39
+ /**
40
+ * Returns a function for deriving a dynamic PDA address from seed + dynamic arguments
41
+ *
42
+ * @param seed
43
+ * @param func function translating the function argument to Buffer[]
44
+ *
45
+ * @internal
46
+ */
47
+ protected pda<T extends Array<any>>(seed: string, func: (...args: T) => Buffer[]): (...args: T) => PublicKey;
48
+ /**
49
+ * Derives static PDA address from the seed
50
+ *
51
+ * @param seed
52
+ *
53
+ * @internal
54
+ */
55
+ static _pda(seed: string): (programId: PublicKey) => PublicKey;
56
+ /**
57
+ * Returns a function for deriving a dynamic PDA address from seed + dynamic arguments
58
+ *
59
+ * @param seed
60
+ * @param func function translating the function argument to Buffer[]
61
+ *
62
+ * @internal
63
+ */
64
+ static _pda<T extends Array<any>>(seed: string, func: (...args: T) => Buffer[]): (programId: PublicKey, ...args: T) => PublicKey;
65
+ /**
66
+ * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
67
+ *
68
+ * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
69
+ *
70
+ * @internal
71
+ */
72
+ _keypair<T extends Array<any>>(func: (...args: T) => Buffer[]): (...args: T) => Keypair;
73
+ }
@@ -1,54 +1,54 @@
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
- /**
17
- * @internal
18
- */
19
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
20
- this._Chain = chainInterface;
21
- 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()), {}));
22
- this._Events = new SolanaProgramEvents_1.SolanaProgramEvents(chainInterface, this);
23
- }
24
- pda(seed, func) {
25
- if (func == null) {
26
- return SolanaProgramBase._pda(seed)(this.program.programId);
27
- }
28
- return SolanaProgramBase._pda(seed, func).bind(this, this.program.programId);
29
- }
30
- static _pda(seed, func) {
31
- if (func == null) {
32
- return (programId) => web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)], programId)[0];
33
- }
34
- return (programId, ...args) => {
35
- const res = func(...args);
36
- return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)].concat(res), programId)[0];
37
- };
38
- }
39
- /**
40
- * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
41
- *
42
- * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
43
- *
44
- * @internal
45
- */
46
- _keypair(func) {
47
- return (...args) => {
48
- const res = func(...args);
49
- const buff = (0, sha2_1.sha256)(buffer_1.Buffer.concat(res));
50
- return web3_js_1.Keypair.fromSeed(buff);
51
- };
52
- }
53
- }
54
- 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
+ /**
17
+ * @internal
18
+ */
19
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
20
+ this._Chain = chainInterface;
21
+ 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()), {}));
22
+ this._Events = new SolanaProgramEvents_1.SolanaProgramEvents(chainInterface, this);
23
+ }
24
+ pda(seed, func) {
25
+ if (func == null) {
26
+ return SolanaProgramBase._pda(seed)(this.program.programId);
27
+ }
28
+ return SolanaProgramBase._pda(seed, func).bind(this, this.program.programId);
29
+ }
30
+ static _pda(seed, func) {
31
+ if (func == null) {
32
+ return (programId) => web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)], programId)[0];
33
+ }
34
+ return (programId, ...args) => {
35
+ const res = func(...args);
36
+ return web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(seed)].concat(res), programId)[0];
37
+ };
38
+ }
39
+ /**
40
+ * Returns a function for deriving a dynamic deterministic keypair from dynamic arguments
41
+ *
42
+ * @param func function translating the function argument to Buffer[] to be used for deriving the keypair
43
+ *
44
+ * @internal
45
+ */
46
+ _keypair(func) {
47
+ return (...args) => {
48
+ const res = func(...args);
49
+ const buff = (0, sha2_1.sha256)(buffer_1.Buffer.concat(res));
50
+ return web3_js_1.Keypair.fromSeed(buff);
51
+ };
52
+ }
53
+ }
54
+ 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,53 +1,53 @@
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 { ParsedMessage, ParsedTransactionWithMeta, 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<NonNullable<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
- * Runs a search backwards in time, processing the events for a specific topic public key
30
- *
31
- * @param topicKey
32
- * @param processor called for every event, should return a value if the correct event was found, or null
33
- * if the search should continue
34
- * @param abortSignal
35
- * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
36
- * @param startBlockheight
37
- */
38
- findInEvents<T>(topicKey: PublicKey, processor: (event: ProgramEvent<IDL>, tx: ParsedTransactionWithMeta) => Promise<T | null | undefined>, abortSignal?: AbortSignal, logBatchSize?: number, startBlockheight?: number): Promise<T | null>;
39
- /**
40
- * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
41
- * for every instruction that doesn't correspond to this program (as those are impossible to parse)
42
- *
43
- * @param transactionMessage
44
- */
45
- decodeInstructions(transactionMessage: ParsedMessage): (InstructionWithAccounts<IDL> | null)[];
46
- /**
47
- * Parses program event related to this program from transaction logs
48
- *
49
- * @param logs
50
- */
51
- parseLogs(logs: string[]): ProgramEvent<IDL>[];
52
- }
53
- 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 { ParsedMessage, ParsedTransactionWithMeta, 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<NonNullable<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
+ * Runs a search backwards in time, processing the events for a specific topic public key
30
+ *
31
+ * @param topicKey
32
+ * @param processor called for every event, should return a value if the correct event was found, or null
33
+ * if the search should continue
34
+ * @param abortSignal
35
+ * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
36
+ * @param startBlockheight
37
+ */
38
+ findInEvents<T>(topicKey: PublicKey, processor: (event: ProgramEvent<IDL>, tx: ParsedTransactionWithMeta) => Promise<T | null | undefined>, abortSignal?: AbortSignal, logBatchSize?: number, startBlockheight?: number): Promise<T | null>;
39
+ /**
40
+ * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
41
+ * for every instruction that doesn't correspond to this program (as those are impossible to parse)
42
+ *
43
+ * @param transactionMessage
44
+ */
45
+ decodeInstructions(transactionMessage: ParsedMessage): (InstructionWithAccounts<IDL> | null)[];
46
+ /**
47
+ * Parses program event related to this program from transaction logs
48
+ *
49
+ * @param logs
50
+ */
51
+ parseLogs(logs: string[]): ProgramEvent<IDL>[];
52
+ }
53
+ export {};
@@ -1,117 +1,117 @@
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
- * Runs a search backwards in time, processing the events for a specific topic public key
19
- *
20
- * @param topicKey
21
- * @param processor called for every event, should return a value if the correct event was found, or null
22
- * if the search should continue
23
- * @param abortSignal
24
- * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
25
- * @param startBlockheight
26
- */
27
- findInEvents(topicKey, processor, abortSignal, logBatchSize, startBlockheight) {
28
- return this.findInSignatures(topicKey, async (data) => {
29
- if (data.signatures) {
30
- for (let info of data.signatures) {
31
- if (info.err)
32
- continue;
33
- const tx = await this.connection.getParsedTransaction(info.signature, {
34
- commitment: "confirmed",
35
- maxSupportedTransactionVersion: 0
36
- });
37
- if (tx == null || tx.meta == null || tx.meta.err || tx.meta.logMessages == null)
38
- continue;
39
- const events = this.parseLogs(tx.meta.logMessages);
40
- events.reverse();
41
- for (let event of events) {
42
- if (abortSignal != null)
43
- abortSignal.throwIfAborted();
44
- const result = await processor(event, tx);
45
- if (result != null)
46
- return result;
47
- }
48
- }
49
- }
50
- else if (data.txs) {
51
- for (let tx of data.txs) {
52
- if (tx.meta == null || tx.meta.err || tx.meta.logMessages == null)
53
- continue;
54
- const events = this.parseLogs(tx.meta.logMessages);
55
- events.reverse();
56
- for (let event of events) {
57
- if (abortSignal != null)
58
- abortSignal.throwIfAborted();
59
- const result = await processor(event, tx);
60
- if (result != null)
61
- return result;
62
- }
63
- }
64
- }
65
- return null;
66
- }, abortSignal, logBatchSize, startBlockheight);
67
- }
68
- /**
69
- * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
70
- * for every instruction that doesn't correspond to this program (as those are impossible to parse)
71
- *
72
- * @param transactionMessage
73
- */
74
- decodeInstructions(transactionMessage) {
75
- const instructions = [];
76
- for (let _ix of transactionMessage.instructions) {
77
- if (!_ix.programId.equals(this.program.program.programId)) {
78
- instructions.push(null);
79
- continue;
80
- }
81
- const ix = _ix;
82
- if (ix.data == null)
83
- continue;
84
- const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
85
- if (parsedIx == null)
86
- throw new Error(`Failed to decode transaction instruction: ${ix.data}!`);
87
- const accountsData = this.nameMappedInstructions[parsedIx.name];
88
- let accounts = null;
89
- if (accountsData != null && accountsData.accounts != null) {
90
- accounts = {};
91
- for (let i = 0; i < accountsData.accounts.length; i++) {
92
- accounts[accountsData.accounts[i].name] = ix.accounts[i];
93
- }
94
- }
95
- instructions.push({
96
- name: parsedIx.name,
97
- data: parsedIx.data,
98
- accounts: accounts
99
- });
100
- }
101
- return instructions;
102
- }
103
- /**
104
- * Parses program event related to this program from transaction logs
105
- *
106
- * @param logs
107
- */
108
- parseLogs(logs) {
109
- const eventsGenerator = this.eventParser.parseLogs(logs);
110
- const events = [];
111
- for (let log of eventsGenerator) {
112
- events.push(log);
113
- }
114
- return events;
115
- }
116
- }
117
- 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
+ * Runs a search backwards in time, processing the events for a specific topic public key
19
+ *
20
+ * @param topicKey
21
+ * @param processor called for every event, should return a value if the correct event was found, or null
22
+ * if the search should continue
23
+ * @param abortSignal
24
+ * @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
25
+ * @param startBlockheight
26
+ */
27
+ findInEvents(topicKey, processor, abortSignal, logBatchSize, startBlockheight) {
28
+ return this.findInSignatures(topicKey, async (data) => {
29
+ if (data.signatures) {
30
+ for (let info of data.signatures) {
31
+ if (info.err)
32
+ continue;
33
+ const tx = await this.connection.getParsedTransaction(info.signature, {
34
+ commitment: "confirmed",
35
+ maxSupportedTransactionVersion: 0
36
+ });
37
+ if (tx == null || tx.meta == null || tx.meta.err || tx.meta.logMessages == null)
38
+ continue;
39
+ const events = this.parseLogs(tx.meta.logMessages);
40
+ events.reverse();
41
+ for (let event of events) {
42
+ if (abortSignal != null)
43
+ abortSignal.throwIfAborted();
44
+ const result = await processor(event, tx);
45
+ if (result != null)
46
+ return result;
47
+ }
48
+ }
49
+ }
50
+ else if (data.txs) {
51
+ for (let tx of data.txs) {
52
+ if (tx.meta == null || tx.meta.err || tx.meta.logMessages == null)
53
+ continue;
54
+ const events = this.parseLogs(tx.meta.logMessages);
55
+ events.reverse();
56
+ for (let event of events) {
57
+ if (abortSignal != null)
58
+ abortSignal.throwIfAborted();
59
+ const result = await processor(event, tx);
60
+ if (result != null)
61
+ return result;
62
+ }
63
+ }
64
+ }
65
+ return null;
66
+ }, abortSignal, logBatchSize, startBlockheight);
67
+ }
68
+ /**
69
+ * Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
70
+ * for every instruction that doesn't correspond to this program (as those are impossible to parse)
71
+ *
72
+ * @param transactionMessage
73
+ */
74
+ decodeInstructions(transactionMessage) {
75
+ const instructions = [];
76
+ for (let _ix of transactionMessage.instructions) {
77
+ if (!_ix.programId.equals(this.program.program.programId)) {
78
+ instructions.push(null);
79
+ continue;
80
+ }
81
+ const ix = _ix;
82
+ if (ix.data == null)
83
+ continue;
84
+ const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
85
+ if (parsedIx == null)
86
+ throw new Error(`Failed to decode transaction instruction: ${ix.data}!`);
87
+ const accountsData = this.nameMappedInstructions[parsedIx.name];
88
+ let accounts = null;
89
+ if (accountsData != null && accountsData.accounts != null) {
90
+ accounts = {};
91
+ for (let i = 0; i < accountsData.accounts.length; i++) {
92
+ accounts[accountsData.accounts[i].name] = ix.accounts[i];
93
+ }
94
+ }
95
+ instructions.push({
96
+ name: parsedIx.name,
97
+ data: parsedIx.data,
98
+ accounts: accounts
99
+ });
100
+ }
101
+ return instructions;
102
+ }
103
+ /**
104
+ * Parses program event related to this program from transaction logs
105
+ *
106
+ * @param logs
107
+ */
108
+ parseLogs(logs) {
109
+ const eventsGenerator = this.eventParser.parseLogs(logs);
110
+ const events = [];
111
+ for (let log of eventsGenerator) {
112
+ events.push(log);
113
+ }
114
+ return events;
115
+ }
116
+ }
117
+ exports.SolanaProgramEvents = SolanaProgramEvents;