@atomiqlabs/chain-solana 9.0.0 → 9.0.2
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/solana/SolanaChains.d.ts +6 -0
- package/dist/solana/SolanaChains.js +7 -0
- package/dist/solana/btcrelay/SolanaBtcRelay.js +1 -1
- package/dist/solana/chain/modules/SolanaFees.js +0 -1
- package/dist/solana/events/SolanaChainEvents.js +7 -10
- package/dist/solana/events/SolanaChainEventsBrowser.js +1 -1
- package/dist/solana/swaps/modules/SwapRefund.js +0 -1
- package/dist/utils/Utils.js +4 -4
- package/package.json +1 -1
- package/src/solana/SolanaChains.ts +7 -0
- package/src/solana/btcrelay/SolanaBtcRelay.ts +2 -1
- package/src/solana/chain/modules/SolanaFees.ts +0 -1
- package/src/solana/events/SolanaChainEvents.ts +7 -11
- package/src/solana/events/SolanaChainEventsBrowser.ts +1 -1
- package/src/solana/swaps/modules/SwapRefund.ts +0 -1
- package/src/utils/Utils.ts +4 -4
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export declare const SolanaChains: {
|
|
2
|
+
readonly 2: {
|
|
3
|
+
readonly addresses: {
|
|
4
|
+
readonly swapContract: "11111111111111111111111111111111";
|
|
5
|
+
readonly btcRelayContract: "11111111111111111111111111111111";
|
|
6
|
+
};
|
|
7
|
+
};
|
|
2
8
|
readonly 1: {
|
|
3
9
|
readonly addresses: {
|
|
4
10
|
readonly swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM";
|
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SolanaChains = void 0;
|
|
4
4
|
const base_1 = require("@atomiqlabs/base");
|
|
5
5
|
exports.SolanaChains = {
|
|
6
|
+
//TODO: Not deployed yet
|
|
7
|
+
[base_1.BitcoinNetwork.TESTNET4]: {
|
|
8
|
+
addresses: {
|
|
9
|
+
swapContract: "11111111111111111111111111111111",
|
|
10
|
+
btcRelayContract: "11111111111111111111111111111111"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
6
13
|
[base_1.BitcoinNetwork.TESTNET]: {
|
|
7
14
|
addresses: {
|
|
8
15
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
@@ -44,7 +44,7 @@ class SolanaBtcRelay extends SolanaProgramBase_1.SolanaProgramBase {
|
|
|
44
44
|
headerTopic: this.BtcRelayHeader(serializedBlock.hash),
|
|
45
45
|
systemProgram: web3_js_1.SystemProgram.programId
|
|
46
46
|
})
|
|
47
|
-
.instruction());
|
|
47
|
+
.instruction(), 100000);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Creates verify action to be used with the swap program, specifies the action to be firstIxBeforeComputeBudget,
|
|
@@ -98,13 +98,11 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
98
98
|
const eventObject = this.getEventObjectFromTransaction(transaction);
|
|
99
99
|
if (eventObject == null)
|
|
100
100
|
return true;
|
|
101
|
-
console.log("Instructions: ", eventObject.instructions);
|
|
102
|
-
console.log("Events: ", eventObject.events);
|
|
103
101
|
await this.processEvent(eventObject);
|
|
104
102
|
return true;
|
|
105
103
|
}
|
|
106
104
|
catch (e) {
|
|
107
|
-
|
|
105
|
+
this.logger.error("fetchTxAndProcessEvent(): Error fetching transaction and processing event, signature: " + signature, e);
|
|
108
106
|
return false;
|
|
109
107
|
}
|
|
110
108
|
}
|
|
@@ -121,14 +119,14 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
121
119
|
return;
|
|
122
120
|
if (this.isSignatureProcessed(signature))
|
|
123
121
|
return;
|
|
124
|
-
|
|
122
|
+
this.logger.debug("getWsEventHandler(" + name + "): Process signature: ", signature);
|
|
125
123
|
this.signaturesProcessing[signature] = this.processEvent({
|
|
126
124
|
events: [{ name, data: data }],
|
|
127
125
|
instructions: null,
|
|
128
126
|
blockTime: Math.floor(Date.now() / 1000),
|
|
129
127
|
signature
|
|
130
128
|
}).then(() => true).catch(e => {
|
|
131
|
-
|
|
129
|
+
this.logger.error("getWsEventHandler(" + name + "): Error processing signature: " + signature, e);
|
|
132
130
|
return false;
|
|
133
131
|
});
|
|
134
132
|
};
|
|
@@ -150,7 +148,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
150
148
|
}, "confirmed");
|
|
151
149
|
//Check if newest returned signature (index 0) is older than the latest signature's slot, this is a sanity check
|
|
152
150
|
if (fetched.length > 0 && fetched[0].slot < lastProcessedSignature.slot) {
|
|
153
|
-
|
|
151
|
+
this.logger.debug("getNewSignatures(): Sanity check triggered, returned signature slot height is older than latest!");
|
|
154
152
|
return;
|
|
155
153
|
}
|
|
156
154
|
}
|
|
@@ -198,7 +196,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
198
196
|
continue;
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
|
-
|
|
199
|
+
this.logger.debug("processSignatures(): Process signature: ", txSignature);
|
|
202
200
|
const processPromise = this.fetchTxAndProcessEvent(txSignature.signature);
|
|
203
201
|
this.signaturesProcessing[txSignature.signature] = processPromise;
|
|
204
202
|
const result = await processPromise;
|
|
@@ -210,7 +208,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
210
208
|
}
|
|
211
209
|
}
|
|
212
210
|
catch (e) {
|
|
213
|
-
|
|
211
|
+
this.logger.error("processSignatures(): Failed processing signatures: ", e);
|
|
214
212
|
}
|
|
215
213
|
return lastSuccessfulSignature;
|
|
216
214
|
}
|
|
@@ -232,8 +230,7 @@ class SolanaChainEvents extends SolanaChainEventsBrowser_1.SolanaChainEventsBrow
|
|
|
232
230
|
let func;
|
|
233
231
|
func = async () => {
|
|
234
232
|
await this.checkEvents().catch(e => {
|
|
235
|
-
|
|
236
|
-
console.error(e);
|
|
233
|
+
this.logger.error("setupHttpPolling(): Failed to fetch Solana log: ", e);
|
|
237
234
|
});
|
|
238
235
|
if (this.stopped)
|
|
239
236
|
return;
|
|
@@ -153,7 +153,7 @@ class SolanaChainEventsBrowser {
|
|
|
153
153
|
blockTime: Math.floor(Date.now() / 1000),
|
|
154
154
|
signature
|
|
155
155
|
}).then(() => true).catch(e => {
|
|
156
|
-
|
|
156
|
+
this.logger.error("wsEventHandler: Error when processing signature: " + signature, e);
|
|
157
157
|
return false;
|
|
158
158
|
});
|
|
159
159
|
};
|
|
@@ -185,7 +185,6 @@ class SwapRefund extends SolanaSwapModule_1.SolanaSwapModule {
|
|
|
185
185
|
throw new base_1.SwapDataVerificationError("ATA not initialized");
|
|
186
186
|
if (feeRate == null)
|
|
187
187
|
feeRate = await this.program.getRefundFeeRate(swapData);
|
|
188
|
-
console.log("[SolanaSwapProgram] txsRefundsWithAuthorization: feeRate: ", feeRate);
|
|
189
188
|
const signatureBuffer = buffer_1.Buffer.from(signature, "hex");
|
|
190
189
|
const shouldUnwrap = this.shouldUnwrap(swapData);
|
|
191
190
|
const action = await this.RefundWithSignature(swapData, timeout, prefix, signatureBuffer);
|
package/dist/utils/Utils.js
CHANGED
|
@@ -31,10 +31,10 @@ function onceAsync(executor) {
|
|
|
31
31
|
exports.onceAsync = onceAsync;
|
|
32
32
|
function getLogger(prefix) {
|
|
33
33
|
return {
|
|
34
|
-
debug: (msg, ...args) => console.debug(prefix + msg, ...args),
|
|
35
|
-
info: (msg, ...args) => console.info(prefix + msg, ...args),
|
|
36
|
-
warn: (msg, ...args) => console.warn(prefix + msg, ...args),
|
|
37
|
-
error: (msg, ...args) => console.error(prefix + msg, ...args)
|
|
34
|
+
debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args),
|
|
35
|
+
info: (msg, ...args) => global.atomiqLogLevel >= 2 && console.info(prefix + msg, ...args),
|
|
36
|
+
warn: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 1) && console.warn(prefix + msg, ...args),
|
|
37
|
+
error: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 0) && console.error(prefix + msg, ...args)
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
exports.getLogger = getLogger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import {BitcoinNetwork} from "@atomiqlabs/base";
|
|
2
2
|
|
|
3
3
|
export const SolanaChains = {
|
|
4
|
+
//TODO: Not deployed yet
|
|
5
|
+
[BitcoinNetwork.TESTNET4]: {
|
|
6
|
+
addresses: {
|
|
7
|
+
swapContract: "11111111111111111111111111111111",
|
|
8
|
+
btcRelayContract: "11111111111111111111111111111111"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
4
11
|
[BitcoinNetwork.TESTNET]: {
|
|
5
12
|
addresses: {
|
|
6
13
|
swapContract: "4hfUykhqmD7ZRvNh1HuzVKEY7ToENixtdUKZspNDCrEM",
|
|
@@ -125,13 +125,10 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
125
125
|
const eventObject = this.getEventObjectFromTransaction(transaction);
|
|
126
126
|
if(eventObject==null) return true;
|
|
127
127
|
|
|
128
|
-
console.log("Instructions: ", eventObject.instructions);
|
|
129
|
-
console.log("Events: ", eventObject.events);
|
|
130
|
-
|
|
131
128
|
await this.processEvent(eventObject);
|
|
132
129
|
return true;
|
|
133
130
|
} catch (e) {
|
|
134
|
-
|
|
131
|
+
this.logger.error("fetchTxAndProcessEvent(): Error fetching transaction and processing event, signature: "+signature, e);
|
|
135
132
|
return false;
|
|
136
133
|
}
|
|
137
134
|
}
|
|
@@ -150,7 +147,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
150
147
|
if(this.signaturesProcessing[signature]!=null) return;
|
|
151
148
|
if(this.isSignatureProcessed(signature)) return;
|
|
152
149
|
|
|
153
|
-
|
|
150
|
+
this.logger.debug("getWsEventHandler("+name+"): Process signature: ", signature);
|
|
154
151
|
|
|
155
152
|
this.signaturesProcessing[signature] = this.processEvent({
|
|
156
153
|
events: [{name, data: data as any}],
|
|
@@ -158,7 +155,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
158
155
|
blockTime: Math.floor(Date.now()/1000),
|
|
159
156
|
signature
|
|
160
157
|
}).then(() => true).catch(e => {
|
|
161
|
-
|
|
158
|
+
this.logger.error("getWsEventHandler("+name+"): Error processing signature: "+signature, e);
|
|
162
159
|
return false;
|
|
163
160
|
});
|
|
164
161
|
};
|
|
@@ -182,7 +179,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
182
179
|
}, "confirmed");
|
|
183
180
|
//Check if newest returned signature (index 0) is older than the latest signature's slot, this is a sanity check
|
|
184
181
|
if(fetched.length>0 && fetched[0].slot<lastProcessedSignature.slot) {
|
|
185
|
-
|
|
182
|
+
this.logger.debug("getNewSignatures(): Sanity check triggered, returned signature slot height is older than latest!");
|
|
186
183
|
return;
|
|
187
184
|
}
|
|
188
185
|
} else {
|
|
@@ -236,7 +233,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
235
|
|
|
239
|
-
|
|
236
|
+
this.logger.debug("processSignatures(): Process signature: ", txSignature);
|
|
240
237
|
|
|
241
238
|
const processPromise: Promise<boolean> = this.fetchTxAndProcessEvent(txSignature.signature);
|
|
242
239
|
this.signaturesProcessing[txSignature.signature] = processPromise;
|
|
@@ -248,7 +245,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
248
245
|
delete this.signaturesProcessing[txSignature.signature];
|
|
249
246
|
}
|
|
250
247
|
} catch (e) {
|
|
251
|
-
|
|
248
|
+
this.logger.error("processSignatures(): Failed processing signatures: ", e);
|
|
252
249
|
}
|
|
253
250
|
return lastSuccessfulSignature;
|
|
254
251
|
}
|
|
@@ -276,8 +273,7 @@ export class SolanaChainEvents extends SolanaChainEventsBrowser {
|
|
|
276
273
|
let func;
|
|
277
274
|
func = async () => {
|
|
278
275
|
await this.checkEvents().catch(e => {
|
|
279
|
-
|
|
280
|
-
console.error(e);
|
|
276
|
+
this.logger.error("setupHttpPolling(): Failed to fetch Solana log: ", e);
|
|
281
277
|
});
|
|
282
278
|
if(this.stopped) return;
|
|
283
279
|
this.timeout = setTimeout(func, this.logFetchInterval);
|
|
@@ -211,7 +211,7 @@ export class SolanaChainEventsBrowser implements ChainEvents<SolanaSwapData> {
|
|
|
211
211
|
blockTime: Math.floor(Date.now()/1000),
|
|
212
212
|
signature
|
|
213
213
|
}).then(() => true).catch(e => {
|
|
214
|
-
|
|
214
|
+
this.logger.error("wsEventHandler: Error when processing signature: "+signature, e);
|
|
215
215
|
return false;
|
|
216
216
|
});
|
|
217
217
|
};
|
|
@@ -249,7 +249,6 @@ export class SwapRefund extends SolanaSwapModule {
|
|
|
249
249
|
if(shouldInitAta && !initAta) throw new SwapDataVerificationError("ATA not initialized");
|
|
250
250
|
|
|
251
251
|
if(feeRate==null) feeRate = await this.program.getRefundFeeRate(swapData);
|
|
252
|
-
console.log("[SolanaSwapProgram] txsRefundsWithAuthorization: feeRate: ", feeRate);
|
|
253
252
|
|
|
254
253
|
const signatureBuffer = Buffer.from(signature, "hex");
|
|
255
254
|
|
package/src/utils/Utils.ts
CHANGED
|
@@ -28,10 +28,10 @@ export function onceAsync<T>(executor: () => Promise<T>): () => Promise<T> {
|
|
|
28
28
|
|
|
29
29
|
export function getLogger(prefix: string) {
|
|
30
30
|
return {
|
|
31
|
-
debug: (msg, ...args) => console.debug(prefix+msg, ...args),
|
|
32
|
-
info: (msg, ...args) => console.info(prefix+msg, ...args),
|
|
33
|
-
warn: (msg, ...args) => console.warn(prefix+msg, ...args),
|
|
34
|
-
error: (msg, ...args) => console.error(prefix+msg, ...args)
|
|
31
|
+
debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix+msg, ...args),
|
|
32
|
+
info: (msg, ...args) => global.atomiqLogLevel >= 2 && console.info(prefix+msg, ...args),
|
|
33
|
+
warn: (msg, ...args) => (global.atomiqLogLevel==null || global.atomiqLogLevel >= 1) && console.warn(prefix+msg, ...args),
|
|
34
|
+
error: (msg, ...args) => (global.atomiqLogLevel==null || global.atomiqLogLevel >= 0) && console.error(prefix+msg, ...args)
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|