@atomiqlabs/chain-starknet 4.0.0-dev.13 → 4.0.0-dev.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/dist/starknet/btcrelay/StarknetBtcRelay.d.ts +1 -1
- package/dist/starknet/provider/RpcProviderWithRetries.d.ts +22 -2
- package/dist/starknet/provider/RpcProviderWithRetries.js +38 -4
- package/dist/starknet/swaps/StarknetSwapContract.d.ts +1 -1
- package/package.json +2 -2
- package/src/starknet/btcrelay/StarknetBtcRelay.ts +1 -1
- package/src/starknet/provider/RpcProviderWithRetries.ts +41 -3
- package/src/starknet/swaps/StarknetSwapContract.ts +1 -1
|
@@ -61,7 +61,7 @@ export declare class StarknetBtcRelay<B extends BtcBlock> extends StarknetContra
|
|
|
61
61
|
}, requiredBlockheight?: number): Promise<{
|
|
62
62
|
header: StarknetBtcStoredHeader;
|
|
63
63
|
height: number;
|
|
64
|
-
}
|
|
64
|
+
}>;
|
|
65
65
|
/**
|
|
66
66
|
* Retrieves blockheader data by blockheader's commit hash,
|
|
67
67
|
*
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { RPC08, RPC09, RpcProvider, RpcProviderOptions } from "starknet";
|
|
2
|
+
export declare class Rpc08ChannelWithRetries extends RPC08.RpcChannel {
|
|
3
|
+
readonly retryPolicy?: {
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
exponential?: boolean;
|
|
7
|
+
};
|
|
8
|
+
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
exponential?: boolean;
|
|
12
|
+
});
|
|
13
|
+
protected fetchEndpoint(method: any, params?: any): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
export declare class Rpc09ChannelWithRetries extends RPC09.RpcChannel {
|
|
3
16
|
readonly retryPolicy?: {
|
|
4
17
|
maxRetries?: number;
|
|
5
18
|
delay?: number;
|
|
@@ -13,6 +26,13 @@ export declare class RpcChannelWithRetries extends RpcChannel {
|
|
|
13
26
|
protected fetchEndpoint(method: any, params?: any): Promise<any>;
|
|
14
27
|
}
|
|
15
28
|
export declare class RpcProviderWithRetries extends RpcProvider {
|
|
29
|
+
/**
|
|
30
|
+
* Tries to do naive detection of the spec version based on the suffix of nodeUrl, better pass the `specVersion`
|
|
31
|
+
* in the options!
|
|
32
|
+
*
|
|
33
|
+
* @param options
|
|
34
|
+
* @param retryPolicy
|
|
35
|
+
*/
|
|
16
36
|
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
17
37
|
maxRetries?: number;
|
|
18
38
|
delay?: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RpcProviderWithRetries = exports.
|
|
3
|
+
exports.RpcProviderWithRetries = exports.Rpc09ChannelWithRetries = exports.Rpc08ChannelWithRetries = void 0;
|
|
4
4
|
const starknet_1 = require("starknet");
|
|
5
5
|
const Utils_1 = require("../../utils/Utils");
|
|
6
|
-
class
|
|
6
|
+
class Rpc08ChannelWithRetries extends starknet_1.RPC08.RpcChannel {
|
|
7
7
|
constructor(options, retryPolicy) {
|
|
8
8
|
super(options);
|
|
9
9
|
this.retryPolicy = retryPolicy;
|
|
@@ -22,11 +22,45 @@ class RpcChannelWithRetries extends starknet_1.RpcChannel {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.
|
|
25
|
+
exports.Rpc08ChannelWithRetries = Rpc08ChannelWithRetries;
|
|
26
|
+
class Rpc09ChannelWithRetries extends starknet_1.RPC09.RpcChannel {
|
|
27
|
+
constructor(options, retryPolicy) {
|
|
28
|
+
super(options);
|
|
29
|
+
this.retryPolicy = retryPolicy;
|
|
30
|
+
}
|
|
31
|
+
fetchEndpoint(method, params) {
|
|
32
|
+
return (0, Utils_1.tryWithRetries)(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
|
|
33
|
+
if (!e.message.startsWith("RPC: "))
|
|
34
|
+
return false;
|
|
35
|
+
const arr = e.message.split("\n");
|
|
36
|
+
const errorCode = parseInt(arr[arr.length - 1]);
|
|
37
|
+
if (isNaN(errorCode))
|
|
38
|
+
return false;
|
|
39
|
+
if (errorCode < 0)
|
|
40
|
+
return false; //Not defined error, e.g. Rate limit (-32097)
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Rpc09ChannelWithRetries = Rpc09ChannelWithRetries;
|
|
26
46
|
class RpcProviderWithRetries extends starknet_1.RpcProvider {
|
|
47
|
+
/**
|
|
48
|
+
* Tries to do naive detection of the spec version based on the suffix of nodeUrl, better pass the `specVersion`
|
|
49
|
+
* in the options!
|
|
50
|
+
*
|
|
51
|
+
* @param options
|
|
52
|
+
* @param retryPolicy
|
|
53
|
+
*/
|
|
27
54
|
constructor(options, retryPolicy) {
|
|
55
|
+
if (options.specVersion == null)
|
|
56
|
+
options.specVersion = options.nodeUrl.endsWith("v0_8") ? "0.8.1" : "0.9.0";
|
|
28
57
|
super(options);
|
|
29
|
-
this.channel
|
|
58
|
+
if (this.channel.id === "RPC081") {
|
|
59
|
+
this.channel = new Rpc08ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
60
|
+
}
|
|
61
|
+
else if (this.channel.id === "RPC090") {
|
|
62
|
+
this.channel = new Rpc09ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
63
|
+
}
|
|
30
64
|
}
|
|
31
65
|
}
|
|
32
66
|
exports.RpcProviderWithRetries = RpcProviderWithRetries;
|
|
@@ -148,7 +148,7 @@ export declare class StarknetSwapContract extends StarknetContractBase<typeof Es
|
|
|
148
148
|
txid: string;
|
|
149
149
|
hex: string;
|
|
150
150
|
height: number;
|
|
151
|
-
}, requiredConfirmations: number, vout: number, commitedHeader?: StarknetBtcStoredHeader, synchronizer?: RelaySynchronizer<StarknetBtcStoredHeader, StarknetTx, any>, initAta?: boolean, feeRate?: string): Promise<StarknetTx[]
|
|
151
|
+
}, requiredConfirmations: number, vout: number, commitedHeader?: StarknetBtcStoredHeader, synchronizer?: RelaySynchronizer<StarknetBtcStoredHeader, StarknetTx, any>, initAta?: boolean, feeRate?: string): Promise<StarknetTx[]>;
|
|
152
152
|
txsRefund(signer: string, swapData: StarknetSwapData, check?: boolean, initAta?: boolean, feeRate?: string): Promise<StarknetTx[]>;
|
|
153
153
|
txsRefundWithAuthorization(signer: string, swapData: StarknetSwapData, { timeout, prefix, signature }: {
|
|
154
154
|
timeout: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-starknet",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.15",
|
|
4
4
|
"description": "Starknet specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atomiqlabs/base": "^10.0.0-dev.9",
|
|
32
32
|
"@noble/hashes": "^1.7.1",
|
|
33
|
-
"@scure/btc-signer": "1.6.0",
|
|
33
|
+
"@scure/btc-signer": "^1.6.0",
|
|
34
34
|
"abi-wan-kanabi": "2.2.4",
|
|
35
35
|
"buffer": "6.0.3"
|
|
36
36
|
},
|
|
@@ -222,7 +222,7 @@ export class StarknetBtcRelay<B extends BtcBlock>
|
|
|
222
222
|
public async retrieveLogAndBlockheight(blockData: {blockhash: string}, requiredBlockheight?: number): Promise<{
|
|
223
223
|
header: StarknetBtcStoredHeader,
|
|
224
224
|
height: number
|
|
225
|
-
}
|
|
225
|
+
}> {
|
|
226
226
|
//TODO: we can fetch the blockheight and events in parallel
|
|
227
227
|
const blockHeight = await this.getBlockHeight();
|
|
228
228
|
if(requiredBlockheight!=null && blockHeight < requiredBlockheight) {
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
RPC08, RPC09,
|
|
3
3
|
RpcProvider,
|
|
4
4
|
RpcProviderOptions
|
|
5
5
|
} from "starknet";
|
|
6
6
|
import {tryWithRetries} from "../../utils/Utils";
|
|
7
7
|
|
|
8
|
-
export class
|
|
8
|
+
export class Rpc08ChannelWithRetries extends RPC08.RpcChannel {
|
|
9
|
+
|
|
10
|
+
readonly retryPolicy?: {
|
|
11
|
+
maxRetries?: number, delay?: number, exponential?: boolean
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
15
|
+
maxRetries?: number, delay?: number, exponential?: boolean
|
|
16
|
+
}) {
|
|
17
|
+
super(options);
|
|
18
|
+
this.retryPolicy = retryPolicy;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected fetchEndpoint(method: any, params?: any): Promise<any> {
|
|
22
|
+
return tryWithRetries(() => super.fetchEndpoint(method, params), this.retryPolicy, e => {
|
|
23
|
+
if(!e.message.startsWith("RPC: ")) return false;
|
|
24
|
+
const arr = e.message.split("\n");
|
|
25
|
+
const errorCode = parseInt(arr[arr.length-1]);
|
|
26
|
+
if(isNaN(errorCode)) return false;
|
|
27
|
+
if(errorCode < 0) return false; //Not defined error, e.g. Rate limit (-32097)
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class Rpc09ChannelWithRetries extends RPC09.RpcChannel {
|
|
9
35
|
|
|
10
36
|
readonly retryPolicy?: {
|
|
11
37
|
maxRetries?: number, delay?: number, exponential?: boolean
|
|
@@ -33,11 +59,23 @@ export class RpcChannelWithRetries extends RpcChannel {
|
|
|
33
59
|
|
|
34
60
|
export class RpcProviderWithRetries extends RpcProvider {
|
|
35
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Tries to do naive detection of the spec version based on the suffix of nodeUrl, better pass the `specVersion`
|
|
64
|
+
* in the options!
|
|
65
|
+
*
|
|
66
|
+
* @param options
|
|
67
|
+
* @param retryPolicy
|
|
68
|
+
*/
|
|
36
69
|
constructor(options?: RpcProviderOptions, retryPolicy?: {
|
|
37
70
|
maxRetries?: number, delay?: number, exponential?: boolean
|
|
38
71
|
}) {
|
|
72
|
+
if(options.specVersion==null) options.specVersion = options.nodeUrl.endsWith("v0_8") ? "0.8.1" : "0.9.0";
|
|
39
73
|
super(options);
|
|
40
|
-
this.channel
|
|
74
|
+
if(this.channel.id==="RPC081") {
|
|
75
|
+
this.channel = new Rpc08ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
76
|
+
} else if(this.channel.id==="RPC090") {
|
|
77
|
+
this.channel = new Rpc09ChannelWithRetries({ ...options, waitMode: false }, retryPolicy);
|
|
78
|
+
}
|
|
41
79
|
}
|
|
42
80
|
|
|
43
81
|
}
|
|
@@ -466,7 +466,7 @@ export class StarknetSwapContract
|
|
|
466
466
|
synchronizer?: RelaySynchronizer<StarknetBtcStoredHeader, StarknetTx, any>,
|
|
467
467
|
initAta?: boolean,
|
|
468
468
|
feeRate?: string
|
|
469
|
-
): Promise<StarknetTx[]
|
|
469
|
+
): Promise<StarknetTx[]> {
|
|
470
470
|
return this.Claim.txsClaimWithTxData(
|
|
471
471
|
typeof(signer)==="string" ? signer : signer.getAddress(),
|
|
472
472
|
swapData,
|