@atomiqlabs/chain-solana 12.0.14 → 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 -238
- 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 -270
- 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,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<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>, abortSignal?: AbortSignal, logBatchSize?: number, startBlockheight?: number): Promise<T>;
|
|
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>[];
|
|
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<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>, abortSignal?: AbortSignal, logBatchSize?: number, startBlockheight?: number): Promise<T>;
|
|
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>[];
|
|
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,114 +1,114 @@
|
|
|
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.meta.err)
|
|
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 {
|
|
51
|
-
for (let tx of data.txs) {
|
|
52
|
-
if (tx.meta.err)
|
|
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
|
-
}, abortSignal, logBatchSize, startBlockheight);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
|
|
69
|
-
* for every instruction that doesn't correspond to this program (as those are impossible to parse)
|
|
70
|
-
*
|
|
71
|
-
* @param transactionMessage
|
|
72
|
-
*/
|
|
73
|
-
decodeInstructions(transactionMessage) {
|
|
74
|
-
const instructions = [];
|
|
75
|
-
for (let _ix of transactionMessage.instructions) {
|
|
76
|
-
if (!_ix.programId.equals(this.program.program.programId)) {
|
|
77
|
-
instructions.push(null);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const ix = _ix;
|
|
81
|
-
if (ix.data == null)
|
|
82
|
-
continue;
|
|
83
|
-
const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
|
|
84
|
-
const accountsData = this.nameMappedInstructions[parsedIx.name];
|
|
85
|
-
let accounts;
|
|
86
|
-
if (accountsData != null && accountsData.accounts != null) {
|
|
87
|
-
accounts = {};
|
|
88
|
-
for (let i = 0; i < accountsData.accounts.length; i++) {
|
|
89
|
-
accounts[accountsData.accounts[i].name] = ix.accounts[i];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
instructions.push({
|
|
93
|
-
name: parsedIx.name,
|
|
94
|
-
data: parsedIx.data,
|
|
95
|
-
accounts: accounts
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return instructions;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Parses program event related to this program from transaction logs
|
|
102
|
-
*
|
|
103
|
-
* @param logs
|
|
104
|
-
*/
|
|
105
|
-
parseLogs(logs) {
|
|
106
|
-
const eventsGenerator = this.eventParser.parseLogs(logs);
|
|
107
|
-
const events = [];
|
|
108
|
-
for (let log of eventsGenerator) {
|
|
109
|
-
events.push(log);
|
|
110
|
-
}
|
|
111
|
-
return events;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
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.meta.err)
|
|
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 {
|
|
51
|
+
for (let tx of data.txs) {
|
|
52
|
+
if (tx.meta.err)
|
|
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
|
+
}, abortSignal, logBatchSize, startBlockheight);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
|
|
69
|
+
* for every instruction that doesn't correspond to this program (as those are impossible to parse)
|
|
70
|
+
*
|
|
71
|
+
* @param transactionMessage
|
|
72
|
+
*/
|
|
73
|
+
decodeInstructions(transactionMessage) {
|
|
74
|
+
const instructions = [];
|
|
75
|
+
for (let _ix of transactionMessage.instructions) {
|
|
76
|
+
if (!_ix.programId.equals(this.program.program.programId)) {
|
|
77
|
+
instructions.push(null);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const ix = _ix;
|
|
81
|
+
if (ix.data == null)
|
|
82
|
+
continue;
|
|
83
|
+
const parsedIx = this.programCoder.instruction.decode(ix.data, 'base58');
|
|
84
|
+
const accountsData = this.nameMappedInstructions[parsedIx.name];
|
|
85
|
+
let accounts;
|
|
86
|
+
if (accountsData != null && accountsData.accounts != null) {
|
|
87
|
+
accounts = {};
|
|
88
|
+
for (let i = 0; i < accountsData.accounts.length; i++) {
|
|
89
|
+
accounts[accountsData.accounts[i].name] = ix.accounts[i];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
instructions.push({
|
|
93
|
+
name: parsedIx.name,
|
|
94
|
+
data: parsedIx.data,
|
|
95
|
+
accounts: accounts
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return instructions;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parses program event related to this program from transaction logs
|
|
102
|
+
*
|
|
103
|
+
* @param logs
|
|
104
|
+
*/
|
|
105
|
+
parseLogs(logs) {
|
|
106
|
+
const eventsGenerator = this.eventParser.parseLogs(logs);
|
|
107
|
+
const events = [];
|
|
108
|
+
for (let log of eventsGenerator) {
|
|
109
|
+
events.push(log);
|
|
110
|
+
}
|
|
111
|
+
return events;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.SolanaProgramEvents = SolanaProgramEvents;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import * as BN from "bn.js";
|
|
3
|
-
import { ChainSwapType, SwapData } from "@atomiqlabs/base";
|
|
4
|
-
import { SwapProgram } from "./programTypes";
|
|
5
|
-
import { IdlAccounts, IdlTypes } from "@coral-xyz/anchor";
|
|
6
|
-
import { SingleInstructionWithAccounts } from "../program/modules/SolanaProgramEvents";
|
|
7
|
-
export type InitInstruction = SingleInstructionWithAccounts<SwapProgram["instructions"][2 | 3], SwapProgram>;
|
|
8
|
-
export declare class SolanaSwapData extends SwapData {
|
|
9
|
-
offerer: PublicKey;
|
|
10
|
-
claimer: PublicKey;
|
|
11
|
-
token: PublicKey;
|
|
12
|
-
amount: BN;
|
|
13
|
-
paymentHash: string;
|
|
14
|
-
sequence: BN;
|
|
15
|
-
expiry: BN;
|
|
16
|
-
nonce: BN;
|
|
17
|
-
confirmations: number;
|
|
18
|
-
payOut: boolean;
|
|
19
|
-
kind: number;
|
|
20
|
-
payIn: boolean;
|
|
21
|
-
claimerAta?: PublicKey;
|
|
22
|
-
offererAta?: PublicKey;
|
|
23
|
-
securityDeposit: BN;
|
|
24
|
-
claimerBounty: BN;
|
|
25
|
-
txoHash: string;
|
|
26
|
-
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);
|
|
27
|
-
constructor(data: any);
|
|
28
|
-
getOfferer(): string;
|
|
29
|
-
setOfferer(newOfferer: string): void;
|
|
30
|
-
getClaimer(): string;
|
|
31
|
-
setClaimer(newClaimer: string): void;
|
|
32
|
-
serialize(): any;
|
|
33
|
-
getAmount(): bigint;
|
|
34
|
-
getToken(): string;
|
|
35
|
-
isToken(token: string): boolean;
|
|
36
|
-
getType(): ChainSwapType;
|
|
37
|
-
getExpiry(): bigint;
|
|
38
|
-
getConfirmationsHint(): number;
|
|
39
|
-
getNonceHint(): bigint;
|
|
40
|
-
isPayIn(): boolean;
|
|
41
|
-
isPayOut(): boolean;
|
|
42
|
-
getClaimHash(): string;
|
|
43
|
-
getEscrowHash(): string;
|
|
44
|
-
getSequence(): bigint;
|
|
45
|
-
getTxoHashHint(): string;
|
|
46
|
-
getHTLCHashHint(): string;
|
|
47
|
-
getExtraData(): string;
|
|
48
|
-
setExtraData(txoHash: string): void;
|
|
49
|
-
getSecurityDeposit(): bigint;
|
|
50
|
-
getClaimerBounty(): bigint;
|
|
51
|
-
getTotalDeposit(): bigint;
|
|
52
|
-
toSwapDataStruct(): IdlTypes<SwapProgram>["SwapData"];
|
|
53
|
-
correctPDA(account: IdlAccounts<SwapProgram>["escrowState"]): boolean;
|
|
54
|
-
equals(other: SolanaSwapData): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Converts initialize instruction data into {SolanaSwapData}
|
|
57
|
-
*
|
|
58
|
-
* @param initIx
|
|
59
|
-
* @param txoHash
|
|
60
|
-
* @private
|
|
61
|
-
* @returns {SolanaSwapData} converted and parsed swap data
|
|
62
|
-
*/
|
|
63
|
-
static fromInstruction(initIx: InitInstruction, txoHash: string): SolanaSwapData;
|
|
64
|
-
static fromEscrowState(account: IdlAccounts<SwapProgram>["escrowState"]): SolanaSwapData;
|
|
65
|
-
static typeToKind(type: ChainSwapType): number;
|
|
66
|
-
static kindToType(value: number): ChainSwapType;
|
|
67
|
-
isClaimer(address: string): boolean;
|
|
68
|
-
isOfferer(address: string): boolean;
|
|
69
|
-
getDepositToken(): string;
|
|
70
|
-
isDepositToken(token: string): boolean;
|
|
71
|
-
}
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import * as BN from "bn.js";
|
|
3
|
+
import { ChainSwapType, SwapData } from "@atomiqlabs/base";
|
|
4
|
+
import { SwapProgram } from "./programTypes";
|
|
5
|
+
import { IdlAccounts, IdlTypes } from "@coral-xyz/anchor";
|
|
6
|
+
import { SingleInstructionWithAccounts } from "../program/modules/SolanaProgramEvents";
|
|
7
|
+
export type InitInstruction = SingleInstructionWithAccounts<SwapProgram["instructions"][2 | 3], SwapProgram>;
|
|
8
|
+
export declare class SolanaSwapData extends SwapData {
|
|
9
|
+
offerer: PublicKey;
|
|
10
|
+
claimer: PublicKey;
|
|
11
|
+
token: PublicKey;
|
|
12
|
+
amount: BN;
|
|
13
|
+
paymentHash: string;
|
|
14
|
+
sequence: BN;
|
|
15
|
+
expiry: BN;
|
|
16
|
+
nonce: BN;
|
|
17
|
+
confirmations: number;
|
|
18
|
+
payOut: boolean;
|
|
19
|
+
kind: number;
|
|
20
|
+
payIn: boolean;
|
|
21
|
+
claimerAta?: PublicKey;
|
|
22
|
+
offererAta?: PublicKey;
|
|
23
|
+
securityDeposit: BN;
|
|
24
|
+
claimerBounty: BN;
|
|
25
|
+
txoHash: string;
|
|
26
|
+
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);
|
|
27
|
+
constructor(data: any);
|
|
28
|
+
getOfferer(): string;
|
|
29
|
+
setOfferer(newOfferer: string): void;
|
|
30
|
+
getClaimer(): string;
|
|
31
|
+
setClaimer(newClaimer: string): void;
|
|
32
|
+
serialize(): any;
|
|
33
|
+
getAmount(): bigint;
|
|
34
|
+
getToken(): string;
|
|
35
|
+
isToken(token: string): boolean;
|
|
36
|
+
getType(): ChainSwapType;
|
|
37
|
+
getExpiry(): bigint;
|
|
38
|
+
getConfirmationsHint(): number;
|
|
39
|
+
getNonceHint(): bigint;
|
|
40
|
+
isPayIn(): boolean;
|
|
41
|
+
isPayOut(): boolean;
|
|
42
|
+
getClaimHash(): string;
|
|
43
|
+
getEscrowHash(): string;
|
|
44
|
+
getSequence(): bigint;
|
|
45
|
+
getTxoHashHint(): string;
|
|
46
|
+
getHTLCHashHint(): string;
|
|
47
|
+
getExtraData(): string;
|
|
48
|
+
setExtraData(txoHash: string): void;
|
|
49
|
+
getSecurityDeposit(): bigint;
|
|
50
|
+
getClaimerBounty(): bigint;
|
|
51
|
+
getTotalDeposit(): bigint;
|
|
52
|
+
toSwapDataStruct(): IdlTypes<SwapProgram>["SwapData"];
|
|
53
|
+
correctPDA(account: IdlAccounts<SwapProgram>["escrowState"]): boolean;
|
|
54
|
+
equals(other: SolanaSwapData): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Converts initialize instruction data into {SolanaSwapData}
|
|
57
|
+
*
|
|
58
|
+
* @param initIx
|
|
59
|
+
* @param txoHash
|
|
60
|
+
* @private
|
|
61
|
+
* @returns {SolanaSwapData} converted and parsed swap data
|
|
62
|
+
*/
|
|
63
|
+
static fromInstruction(initIx: InitInstruction, txoHash: string): SolanaSwapData;
|
|
64
|
+
static fromEscrowState(account: IdlAccounts<SwapProgram>["escrowState"]): SolanaSwapData;
|
|
65
|
+
static typeToKind(type: ChainSwapType): number;
|
|
66
|
+
static kindToType(value: number): ChainSwapType;
|
|
67
|
+
isClaimer(address: string): boolean;
|
|
68
|
+
isOfferer(address: string): boolean;
|
|
69
|
+
getDepositToken(): string;
|
|
70
|
+
isDepositToken(token: string): boolean;
|
|
71
|
+
}
|