@atomiqlabs/chain-solana 7.3.8 → 8.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/solana/SolanaChains.d.ts +14 -0
- package/dist/solana/SolanaChains.js +18 -0
- package/dist/solana/SolanaInitializer.d.ts +18 -0
- package/dist/solana/SolanaInitializer.js +59 -0
- package/dist/solana/base/SolanaAction.js +25 -38
- package/dist/solana/base/modules/SolanaBlocks.js +18 -29
- package/dist/solana/base/modules/SolanaEvents.js +15 -26
- package/dist/solana/base/modules/SolanaFees.d.ts +4 -5
- package/dist/solana/base/modules/SolanaFees.js +168 -182
- package/dist/solana/base/modules/SolanaSlots.js +16 -29
- package/dist/solana/base/modules/SolanaTokens.d.ts +6 -7
- package/dist/solana/base/modules/SolanaTokens.js +63 -84
- package/dist/solana/base/modules/SolanaTransactions.d.ts +2 -2
- package/dist/solana/base/modules/SolanaTransactions.js +143 -165
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +2 -3
- package/dist/solana/btcrelay/SolanaBtcRelay.js +185 -221
- package/dist/solana/events/SolanaChainEvents.js +113 -138
- package/dist/solana/events/SolanaChainEventsBrowser.js +56 -65
- package/dist/solana/program/modules/SolanaProgramEvents.js +13 -24
- package/dist/solana/swaps/SolanaSwapData.d.ts +15 -11
- package/dist/solana/swaps/SolanaSwapData.js +29 -13
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +40 -41
- package/dist/solana/swaps/SolanaSwapProgram.js +212 -221
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +2 -3
- package/dist/solana/swaps/modules/SolanaDataAccount.js +117 -141
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +4 -5
- package/dist/solana/swaps/modules/SolanaLpVault.js +87 -110
- package/dist/solana/swaps/modules/SwapClaim.d.ts +4 -4
- package/dist/solana/swaps/modules/SwapClaim.js +122 -134
- package/dist/solana/swaps/modules/SwapInit.d.ts +2 -3
- package/dist/solana/swaps/modules/SwapInit.js +254 -285
- package/dist/solana/swaps/modules/SwapRefund.d.ts +2 -3
- package/dist/solana/swaps/modules/SwapRefund.js +103 -113
- package/dist/utils/Utils.d.ts +10 -0
- package/dist/utils/Utils.js +62 -35
- package/package.json +9 -6
- package/src/index.ts +1 -0
- package/src/solana/SolanaChains.ts +16 -0
- package/src/solana/SolanaInitializer.ts +98 -0
- package/src/solana/base/SolanaBase.ts +1 -2
- package/src/solana/base/modules/SolanaEvents.ts +0 -1
- package/src/solana/base/modules/SolanaFees.ts +35 -31
- package/src/solana/base/modules/SolanaTokens.ts +26 -27
- package/src/solana/base/modules/SolanaTransactions.ts +33 -28
- package/src/solana/btcrelay/SolanaBtcRelay.ts +6 -10
- package/src/solana/events/SolanaChainEventsBrowser.ts +14 -10
- package/src/solana/program/modules/SolanaProgramEvents.ts +1 -1
- package/src/solana/swaps/SolanaSwapData.ts +38 -19
- package/src/solana/swaps/SolanaSwapProgram.ts +133 -105
- package/src/solana/swaps/modules/SolanaDataAccount.ts +4 -6
- package/src/solana/swaps/modules/SolanaLpVault.ts +18 -18
- package/src/solana/swaps/modules/SwapClaim.ts +14 -17
- package/src/solana/swaps/modules/SwapInit.ts +35 -38
- package/src/solana/swaps/modules/SwapRefund.ts +20 -23
- package/src/utils/Utils.ts +35 -0
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SolanaChainEvents = void 0;
|
|
13
4
|
const fs = require("fs/promises");
|
|
@@ -32,25 +23,23 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
32
23
|
*
|
|
33
24
|
* @private
|
|
34
25
|
*/
|
|
35
|
-
getLastSignature() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (arr.length < 2)
|
|
41
|
-
return {
|
|
42
|
-
signature: txt,
|
|
43
|
-
slot: 0
|
|
44
|
-
};
|
|
26
|
+
async getLastSignature() {
|
|
27
|
+
try {
|
|
28
|
+
const txt = (await fs.readFile(this.directory + BLOCKHEIGHT_FILENAME)).toString();
|
|
29
|
+
const arr = txt.split(";");
|
|
30
|
+
if (arr.length < 2)
|
|
45
31
|
return {
|
|
46
|
-
signature:
|
|
47
|
-
slot:
|
|
32
|
+
signature: txt,
|
|
33
|
+
slot: 0
|
|
48
34
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
35
|
+
return {
|
|
36
|
+
signature: arr[0],
|
|
37
|
+
slot: parseInt(arr[1])
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Saves last signature & slot to the filesystem
|
|
@@ -86,28 +75,26 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
86
75
|
* @private
|
|
87
76
|
* @returns {boolean} whether the operation was successful
|
|
88
77
|
*/
|
|
89
|
-
fetchTxAndProcessEvent(signature) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (transaction == null)
|
|
97
|
-
return false;
|
|
98
|
-
const eventObject = this.getEventObjectFromTransaction(transaction);
|
|
99
|
-
if (eventObject == null)
|
|
100
|
-
return true;
|
|
101
|
-
console.log("Instructions: ", eventObject.instructions);
|
|
102
|
-
console.log("Events: ", eventObject.events);
|
|
103
|
-
yield this.processEvent(eventObject);
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
console.error(e);
|
|
78
|
+
async fetchTxAndProcessEvent(signature) {
|
|
79
|
+
try {
|
|
80
|
+
const transaction = await this.connection.getParsedTransaction(signature, {
|
|
81
|
+
commitment: "confirmed",
|
|
82
|
+
maxSupportedTransactionVersion: 0
|
|
83
|
+
});
|
|
84
|
+
if (transaction == null)
|
|
108
85
|
return false;
|
|
109
|
-
|
|
110
|
-
|
|
86
|
+
const eventObject = this.getEventObjectFromTransaction(transaction);
|
|
87
|
+
if (eventObject == null)
|
|
88
|
+
return true;
|
|
89
|
+
console.log("Instructions: ", eventObject.instructions);
|
|
90
|
+
console.log("Events: ", eventObject.events);
|
|
91
|
+
await this.processEvent(eventObject);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
console.error(e);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
111
98
|
}
|
|
112
99
|
/**
|
|
113
100
|
* Returns websocket event handler for specific event type
|
|
@@ -138,45 +125,41 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
138
125
|
* @param lastProcessedSignature
|
|
139
126
|
* @private
|
|
140
127
|
*/
|
|
141
|
-
getNewSignatures(lastProcessedSignature) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
fetched = yield this.connection.getSignaturesForAddress(this.solanaSwapProgram.program.programId, {
|
|
159
|
-
before: signatures[signatures.length - 1].signature,
|
|
160
|
-
until: lastProcessedSignature.signature,
|
|
161
|
-
limit: this.logFetchLimit
|
|
162
|
-
}, "confirmed");
|
|
128
|
+
async getNewSignatures(lastProcessedSignature) {
|
|
129
|
+
let signatures = [];
|
|
130
|
+
let fetched = null;
|
|
131
|
+
while (fetched == null || fetched.length === this.logFetchLimit) {
|
|
132
|
+
if (signatures.length === 0) {
|
|
133
|
+
fetched = await this.connection.getSignaturesForAddress(this.solanaSwapProgram.program.programId, {
|
|
134
|
+
until: lastProcessedSignature.signature,
|
|
135
|
+
limit: this.logFetchLimit
|
|
136
|
+
}, "confirmed");
|
|
137
|
+
//Check if newest returned signature (index 0) is older than the latest signature's slot, this is a sanity check
|
|
138
|
+
if (fetched.length > 0 && fetched[0].slot < lastProcessedSignature.slot) {
|
|
139
|
+
console.log("[Solana Events POLL] Sanity check triggered, returned signature slot height is older than latest!");
|
|
140
|
+
return;
|
|
163
141
|
}
|
|
164
|
-
signatures = signatures.concat(fetched);
|
|
165
142
|
}
|
|
166
|
-
|
|
167
|
-
|
|
143
|
+
else {
|
|
144
|
+
fetched = await this.connection.getSignaturesForAddress(this.solanaSwapProgram.program.programId, {
|
|
145
|
+
before: signatures[signatures.length - 1].signature,
|
|
146
|
+
until: lastProcessedSignature.signature,
|
|
147
|
+
limit: this.logFetchLimit
|
|
148
|
+
}, "confirmed");
|
|
149
|
+
}
|
|
150
|
+
signatures = signatures.concat(fetched);
|
|
151
|
+
}
|
|
152
|
+
return signatures;
|
|
168
153
|
}
|
|
169
154
|
/**
|
|
170
155
|
* Gets single latest known signature
|
|
171
156
|
*
|
|
172
157
|
* @private
|
|
173
158
|
*/
|
|
174
|
-
getFirstSignature() {
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}, "confirmed");
|
|
179
|
-
});
|
|
159
|
+
async getFirstSignature() {
|
|
160
|
+
return await this.connection.getSignaturesForAddress(this.solanaSwapProgram.program.programId, {
|
|
161
|
+
limit: 1
|
|
162
|
+
}, "confirmed");
|
|
180
163
|
}
|
|
181
164
|
/**
|
|
182
165
|
* Processes signatures, fetches transactions & processes event through event handlers
|
|
@@ -185,78 +168,70 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
185
168
|
* @private
|
|
186
169
|
* @returns {Promise<{signature: string, slot: number}>} latest processed transaction signature and slot height
|
|
187
170
|
*/
|
|
188
|
-
processSignatures(signatures) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const result = yield signaturePromise;
|
|
198
|
-
delete this.signaturesProcessing[txSignature.signature];
|
|
199
|
-
if (result) {
|
|
200
|
-
lastSuccessfulSignature = txSignature;
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
console.log("[Solana Events POLL] Process signature: ", txSignature);
|
|
205
|
-
const processPromise = this.fetchTxAndProcessEvent(txSignature.signature);
|
|
206
|
-
this.signaturesProcessing[txSignature.signature] = processPromise;
|
|
207
|
-
const result = yield processPromise;
|
|
208
|
-
if (!result)
|
|
209
|
-
throw new Error("Failed to process signature: " + txSignature);
|
|
210
|
-
lastSuccessfulSignature = txSignature;
|
|
171
|
+
async processSignatures(signatures) {
|
|
172
|
+
let lastSuccessfulSignature = null;
|
|
173
|
+
try {
|
|
174
|
+
for (let i = signatures.length - 1; i >= 0; i--) {
|
|
175
|
+
const txSignature = signatures[i];
|
|
176
|
+
//Check if signature is already being processed by the
|
|
177
|
+
const signaturePromise = this.signaturesProcessing[txSignature.signature];
|
|
178
|
+
if (signaturePromise != null) {
|
|
179
|
+
const result = await signaturePromise;
|
|
211
180
|
delete this.signaturesProcessing[txSignature.signature];
|
|
181
|
+
if (result) {
|
|
182
|
+
lastSuccessfulSignature = txSignature;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
212
185
|
}
|
|
186
|
+
console.log("[Solana Events POLL] Process signature: ", txSignature);
|
|
187
|
+
const processPromise = this.fetchTxAndProcessEvent(txSignature.signature);
|
|
188
|
+
this.signaturesProcessing[txSignature.signature] = processPromise;
|
|
189
|
+
const result = await processPromise;
|
|
190
|
+
if (!result)
|
|
191
|
+
throw new Error("Failed to process signature: " + txSignature);
|
|
192
|
+
lastSuccessfulSignature = txSignature;
|
|
193
|
+
delete this.signaturesProcessing[txSignature.signature];
|
|
213
194
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
console.error(e);
|
|
198
|
+
}
|
|
199
|
+
return lastSuccessfulSignature;
|
|
219
200
|
}
|
|
220
201
|
/**
|
|
221
202
|
* Polls for new events & processes them
|
|
222
203
|
*
|
|
223
204
|
* @private
|
|
224
205
|
*/
|
|
225
|
-
checkEvents() {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
});
|
|
206
|
+
async checkEvents() {
|
|
207
|
+
const lastSignature = await this.getLastSignature();
|
|
208
|
+
let signatures = lastSignature == null ? await this.getFirstSignature() : await this.getNewSignatures(lastSignature);
|
|
209
|
+
let lastSuccessfulSignature = await this.processSignatures(signatures);
|
|
210
|
+
if (lastSuccessfulSignature != null) {
|
|
211
|
+
await this.saveLastSignature(lastSuccessfulSignature.signature, lastSuccessfulSignature.slot);
|
|
212
|
+
}
|
|
234
213
|
}
|
|
235
|
-
setupHttpPolling() {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
console.error(e);
|
|
243
|
-
});
|
|
244
|
-
if (this.stopped)
|
|
245
|
-
return;
|
|
246
|
-
this.timeout = setTimeout(func, this.logFetchInterval);
|
|
214
|
+
async setupHttpPolling() {
|
|
215
|
+
this.stopped = false;
|
|
216
|
+
let func;
|
|
217
|
+
func = async () => {
|
|
218
|
+
await this.checkEvents().catch(e => {
|
|
219
|
+
console.error("Failed to fetch Sol log");
|
|
220
|
+
console.error(e);
|
|
247
221
|
});
|
|
248
|
-
|
|
249
|
-
|
|
222
|
+
if (this.stopped)
|
|
223
|
+
return;
|
|
224
|
+
this.timeout = setTimeout(func, this.logFetchInterval);
|
|
225
|
+
};
|
|
226
|
+
await func();
|
|
250
227
|
}
|
|
251
|
-
init() {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
this.setupWebsocket();
|
|
259
|
-
});
|
|
228
|
+
async init() {
|
|
229
|
+
try {
|
|
230
|
+
await fs.mkdir(this.directory);
|
|
231
|
+
}
|
|
232
|
+
catch (e) { }
|
|
233
|
+
await this.setupHttpPolling();
|
|
234
|
+
this.setupWebsocket();
|
|
260
235
|
}
|
|
261
236
|
stop() {
|
|
262
237
|
this.stopped = true;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SolanaChainEventsBrowser = void 0;
|
|
13
4
|
const base_1 = require("@atomiqlabs/base");
|
|
@@ -36,23 +27,21 @@ class SolanaChainEventsBrowser {
|
|
|
36
27
|
* @private
|
|
37
28
|
* @returns {Promise<InstructionWithAccounts<SwapProgram>[]>} array of parsed instructions
|
|
38
29
|
*/
|
|
39
|
-
getTransactionInstructions(signature) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return res;
|
|
49
|
-
}));
|
|
50
|
-
if (transaction == null)
|
|
51
|
-
return null;
|
|
52
|
-
if (transaction.meta.err != null)
|
|
53
|
-
return null;
|
|
54
|
-
return this.solanaSwapProgram.Events.decodeInstructions(transaction.transaction.message);
|
|
30
|
+
async getTransactionInstructions(signature) {
|
|
31
|
+
const transaction = await (0, Utils_1.tryWithRetries)(async () => {
|
|
32
|
+
const res = await this.connection.getParsedTransaction(signature, {
|
|
33
|
+
commitment: "confirmed",
|
|
34
|
+
maxSupportedTransactionVersion: 0
|
|
35
|
+
});
|
|
36
|
+
if (res == null)
|
|
37
|
+
throw new Error("Transaction not found!");
|
|
38
|
+
return res;
|
|
55
39
|
});
|
|
40
|
+
if (transaction == null)
|
|
41
|
+
return null;
|
|
42
|
+
if (transaction.meta.err != null)
|
|
43
|
+
return null;
|
|
44
|
+
return this.solanaSwapProgram.Events.decodeInstructions(transaction.transaction.message);
|
|
56
45
|
}
|
|
57
46
|
/**
|
|
58
47
|
* Converts initialize instruction data into {SolanaSwapData}
|
|
@@ -83,33 +72,39 @@ class SolanaChainEventsBrowser {
|
|
|
83
72
|
* @returns {() => Promise<SolanaSwapData>} getter to be passed to InitializeEvent constructor
|
|
84
73
|
*/
|
|
85
74
|
getSwapDataGetter(eventObject, txoHash) {
|
|
86
|
-
return () =>
|
|
75
|
+
return async () => {
|
|
87
76
|
if (eventObject.instructions == null)
|
|
88
|
-
eventObject.instructions =
|
|
77
|
+
eventObject.instructions = await this.getTransactionInstructions(eventObject.signature);
|
|
89
78
|
if (eventObject.instructions == null)
|
|
90
79
|
return null;
|
|
91
80
|
const initIx = eventObject.instructions.find(ix => ix != null && (ix.name === "offererInitializePayIn" || ix.name === "offererInitialize"));
|
|
92
81
|
if (initIx == null)
|
|
93
82
|
return null;
|
|
94
83
|
return this.instructionToSwapData(initIx, txoHash);
|
|
95
|
-
}
|
|
84
|
+
};
|
|
96
85
|
}
|
|
97
86
|
parseInitializeEvent(data, eventObject) {
|
|
98
87
|
const paymentHash = buffer_1.Buffer.from(data.hash).toString("hex");
|
|
99
88
|
const txoHash = buffer_1.Buffer.from(data.txoHash).toString("hex");
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
const escrowHash = (0, Utils_1.toEscrowHash)(paymentHash, data.sequence);
|
|
90
|
+
this.logger.debug("InitializeEvent paymentHash: " + paymentHash + " sequence: " + data.sequence.toString(10) +
|
|
91
|
+
" txoHash: " + txoHash + " escrowHash: " + escrowHash);
|
|
92
|
+
return new base_1.InitializeEvent(escrowHash, SwapTypeEnum_1.SwapTypeEnum.toChainSwapType(data.kind), (0, Utils_1.onceAsync)(this.getSwapDataGetter(eventObject, txoHash)));
|
|
102
93
|
}
|
|
103
94
|
parseRefundEvent(data) {
|
|
104
95
|
const paymentHash = buffer_1.Buffer.from(data.hash).toString("hex");
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
const escrowHash = (0, Utils_1.toEscrowHash)(paymentHash, data.sequence);
|
|
97
|
+
this.logger.debug("RefundEvent paymentHash: " + paymentHash + " sequence: " + data.sequence.toString(10) +
|
|
98
|
+
" escrowHash: " + escrowHash);
|
|
99
|
+
return new base_1.RefundEvent(escrowHash);
|
|
107
100
|
}
|
|
108
101
|
parseClaimEvent(data) {
|
|
109
102
|
const secret = buffer_1.Buffer.from(data.secret).toString("hex");
|
|
110
103
|
const paymentHash = buffer_1.Buffer.from(data.hash).toString("hex");
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const escrowHash = (0, Utils_1.toEscrowHash)(paymentHash, data.sequence);
|
|
105
|
+
this.logger.debug("ClaimEvent paymentHash: " + paymentHash + " sequence: " + data.sequence.toString(10) +
|
|
106
|
+
" secret: " + secret + " escrowHash: " + escrowHash);
|
|
107
|
+
return new base_1.ClaimEvent(escrowHash, secret);
|
|
113
108
|
}
|
|
114
109
|
/**
|
|
115
110
|
* Processes event as received from the chain, parses it & calls event listeners
|
|
@@ -117,31 +112,29 @@ class SolanaChainEventsBrowser {
|
|
|
117
112
|
* @param eventObject
|
|
118
113
|
* @protected
|
|
119
114
|
*/
|
|
120
|
-
processEvent(eventObject) {
|
|
121
|
-
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
parsedEvent.meta = {
|
|
136
|
-
timestamp: eventObject.blockTime,
|
|
137
|
-
txId: eventObject.signature
|
|
138
|
-
};
|
|
139
|
-
return parsedEvent;
|
|
140
|
-
}).filter(parsedEvent => parsedEvent != null);
|
|
141
|
-
for (let listener of this.listeners) {
|
|
142
|
-
yield listener(parsedEvents);
|
|
115
|
+
async processEvent(eventObject) {
|
|
116
|
+
let parsedEvents = eventObject.events.map(event => {
|
|
117
|
+
let parsedEvent;
|
|
118
|
+
switch (event.name) {
|
|
119
|
+
case "ClaimEvent":
|
|
120
|
+
parsedEvent = this.parseClaimEvent(event.data);
|
|
121
|
+
break;
|
|
122
|
+
case "RefundEvent":
|
|
123
|
+
parsedEvent = this.parseRefundEvent(event.data);
|
|
124
|
+
break;
|
|
125
|
+
case "InitializeEvent":
|
|
126
|
+
parsedEvent = this.parseInitializeEvent(event.data, eventObject);
|
|
127
|
+
break;
|
|
143
128
|
}
|
|
144
|
-
|
|
129
|
+
parsedEvent.meta = {
|
|
130
|
+
timestamp: eventObject.blockTime,
|
|
131
|
+
txId: eventObject.signature
|
|
132
|
+
};
|
|
133
|
+
return parsedEvent;
|
|
134
|
+
}).filter(parsedEvent => parsedEvent != null);
|
|
135
|
+
for (let listener of this.listeners) {
|
|
136
|
+
await listener(parsedEvents);
|
|
137
|
+
}
|
|
145
138
|
}
|
|
146
139
|
/**
|
|
147
140
|
* Returns websocket event handler for specific event type
|
|
@@ -179,13 +172,11 @@ class SolanaChainEventsBrowser {
|
|
|
179
172
|
this.setupWebsocket();
|
|
180
173
|
return Promise.resolve();
|
|
181
174
|
}
|
|
182
|
-
stop() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.eventListeners = [];
|
|
188
|
-
});
|
|
175
|
+
async stop() {
|
|
176
|
+
for (let num of this.eventListeners) {
|
|
177
|
+
await this.solanaSwapProgram.program.removeEventListener(num);
|
|
178
|
+
}
|
|
179
|
+
this.eventListeners = [];
|
|
189
180
|
}
|
|
190
181
|
registerListener(cbk) {
|
|
191
182
|
this.listeners.push(cbk);
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SolanaProgramEvents = void 0;
|
|
13
4
|
const SolanaEvents_1 = require("../../base/modules/SolanaEvents");
|
|
@@ -29,18 +20,16 @@ class SolanaProgramEvents extends SolanaEvents_1.SolanaEvents {
|
|
|
29
20
|
* @param signature
|
|
30
21
|
* @private
|
|
31
22
|
*/
|
|
32
|
-
getEvents(signature) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
maxSupportedTransactionVersion: 0
|
|
37
|
-
});
|
|
38
|
-
if (tx.meta.err)
|
|
39
|
-
return [];
|
|
40
|
-
const events = this.parseLogs(tx.meta.logMessages);
|
|
41
|
-
events.reverse();
|
|
42
|
-
return events;
|
|
23
|
+
async getEvents(signature) {
|
|
24
|
+
const tx = await this.connection.getTransaction(signature, {
|
|
25
|
+
commitment: "confirmed",
|
|
26
|
+
maxSupportedTransactionVersion: 0
|
|
43
27
|
});
|
|
28
|
+
if (tx.meta.err)
|
|
29
|
+
return [];
|
|
30
|
+
const events = this.parseLogs(tx.meta.logMessages);
|
|
31
|
+
events.reverse();
|
|
32
|
+
return events;
|
|
44
33
|
}
|
|
45
34
|
/**
|
|
46
35
|
* Runs a search backwards in time, processing the events for a specific topic public key
|
|
@@ -52,17 +41,17 @@ class SolanaProgramEvents extends SolanaEvents_1.SolanaEvents {
|
|
|
52
41
|
* @param logBatchSize how many signatures should be fetched in one getSignaturesForAddress call
|
|
53
42
|
*/
|
|
54
43
|
findInEvents(topicKey, processor, abortSignal, logBatchSize) {
|
|
55
|
-
return this.findInSignatures(topicKey, (signatures) =>
|
|
44
|
+
return this.findInSignatures(topicKey, async (signatures) => {
|
|
56
45
|
for (let data of signatures) {
|
|
57
|
-
for (let event of
|
|
46
|
+
for (let event of await this.getEvents(data.signature)) {
|
|
58
47
|
if (abortSignal != null)
|
|
59
48
|
abortSignal.throwIfAborted();
|
|
60
|
-
const result =
|
|
49
|
+
const result = await processor(event);
|
|
61
50
|
if (result != null)
|
|
62
51
|
return result;
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
|
-
}
|
|
54
|
+
}, abortSignal, logBatchSize);
|
|
66
55
|
}
|
|
67
56
|
/**
|
|
68
57
|
* Decodes the instructions for this program from the transaction, leaves null in the returned instructions array
|
|
@@ -28,22 +28,24 @@ export declare class SolanaSwapData extends SwapData {
|
|
|
28
28
|
getClaimer(): string;
|
|
29
29
|
setClaimer(newClaimer: string): void;
|
|
30
30
|
serialize(): any;
|
|
31
|
-
getAmount():
|
|
31
|
+
getAmount(): bigint;
|
|
32
32
|
getToken(): string;
|
|
33
33
|
isToken(token: string): boolean;
|
|
34
34
|
getType(): ChainSwapType;
|
|
35
|
-
getExpiry():
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
getExpiry(): bigint;
|
|
36
|
+
getConfirmationsHint(): number;
|
|
37
|
+
getNonceHint(): bigint;
|
|
38
38
|
isPayIn(): boolean;
|
|
39
39
|
isPayOut(): boolean;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
49
|
toSwapDataStruct(): IdlTypes<SwapProgram>["SwapData"];
|
|
48
50
|
correctPDA(account: IdlAccounts<SwapProgram>["escrowState"]): boolean;
|
|
49
51
|
equals(other: SolanaSwapData): boolean;
|
|
@@ -52,4 +54,6 @@ export declare class SolanaSwapData extends SwapData {
|
|
|
52
54
|
static kindToType(value: number): ChainSwapType;
|
|
53
55
|
isClaimer(address: string): boolean;
|
|
54
56
|
isOfferer(address: string): boolean;
|
|
57
|
+
getDepositToken(): string;
|
|
58
|
+
isDepositToken(token: string): boolean;
|
|
55
59
|
}
|