@atomiqlabs/chain-starknet 3.0.0-beta.8 → 3.0.0-beta.9
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetInitializer = exports.StarknetAssets = void 0;
|
|
4
|
-
exports.initializeStarknet = initializeStarknet;
|
|
3
|
+
exports.StarknetInitializer = exports.initializeStarknet = exports.StarknetAssets = void 0;
|
|
5
4
|
const starknet_1 = require("starknet");
|
|
6
5
|
const StarknetFees_1 = require("./chain/modules/StarknetFees");
|
|
7
6
|
const StarknetChainInterface_1 = require("./chain/StarknetChainInterface");
|
|
@@ -59,6 +58,7 @@ function initializeStarknet(options, bitcoinRpc, network) {
|
|
|
59
58
|
spvVaultWithdrawalDataConstructor: StarknetSpvWithdrawalData_1.StarknetSpvWithdrawalData
|
|
60
59
|
};
|
|
61
60
|
}
|
|
61
|
+
exports.initializeStarknet = initializeStarknet;
|
|
62
62
|
;
|
|
63
63
|
exports.StarknetInitializer = {
|
|
64
64
|
chainId: "STARKNET",
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetFees = void 0;
|
|
4
|
-
exports.starknetGasMul = starknetGasMul;
|
|
5
|
-
exports.starknetGasAdd = starknetGasAdd;
|
|
3
|
+
exports.StarknetFees = exports.starknetGasAdd = exports.starknetGasMul = void 0;
|
|
6
4
|
const Utils_1 = require("../../../utils/Utils");
|
|
7
5
|
const StarknetTokens_1 = require("./StarknetTokens");
|
|
8
6
|
const MAX_FEE_AGE = 5000;
|
|
9
7
|
function starknetGasMul(gas, scalar) {
|
|
10
8
|
return { l1Gas: gas.l1Gas * scalar, l2Gas: gas.l2Gas * scalar, l1DataGas: gas.l1DataGas * scalar };
|
|
11
9
|
}
|
|
10
|
+
exports.starknetGasMul = starknetGasMul;
|
|
12
11
|
function starknetGasAdd(a, b) {
|
|
13
12
|
return { l1Gas: a.l1Gas + b.l1Gas, l2Gas: a.l2Gas + b.l2Gas, l1DataGas: a.l1DataGas + b.l1DataGas };
|
|
14
13
|
}
|
|
14
|
+
exports.starknetGasAdd = starknetGasAdd;
|
|
15
15
|
class StarknetFees {
|
|
16
16
|
constructor(provider, maxFeeRate = { l1GasCost: 1000000000000000n, l2GasCost: 1000000000000000n, l1DataGasCost: 1000000000000000n } /*100 * 10000 GWei*/, feeMultiplier = 1.25, da) {
|
|
17
17
|
this.logger = (0, Utils_1.getLogger)("StarknetFees: ");
|
package/dist/utils/Utils.js
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUint256 =
|
|
4
|
-
exports.timeoutPromise = timeoutPromise;
|
|
5
|
-
exports.onceAsync = onceAsync;
|
|
6
|
-
exports.getLogger = getLogger;
|
|
7
|
-
exports.tryWithRetries = tryWithRetries;
|
|
8
|
-
exports.toHex = toHex;
|
|
9
|
-
exports.calculateHash = calculateHash;
|
|
10
|
-
exports.u32ArrayToBuffer = u32ArrayToBuffer;
|
|
11
|
-
exports.bufferToU32Array = bufferToU32Array;
|
|
12
|
-
exports.u32ReverseEndianness = u32ReverseEndianness;
|
|
13
|
-
exports.bigNumberishToBuffer = bigNumberishToBuffer;
|
|
14
|
-
exports.toBigInt = toBigInt;
|
|
15
|
-
exports.bytes31SpanToBuffer = bytes31SpanToBuffer;
|
|
16
|
-
exports.bufferToBytes31Span = bufferToBytes31Span;
|
|
17
|
-
exports.bufferToByteArray = bufferToByteArray;
|
|
18
|
-
exports.poseidonHashRange = poseidonHashRange;
|
|
19
|
-
exports.parseInitFunctionCalldata = parseInitFunctionCalldata;
|
|
20
|
-
exports.findLastIndex = findLastIndex;
|
|
3
|
+
exports.findLastIndex = exports.parseInitFunctionCalldata = exports.poseidonHashRange = exports.bufferToByteArray = exports.bufferToBytes31Span = exports.bytes31SpanToBuffer = exports.toBigInt = exports.bigNumberishToBuffer = exports.u32ReverseEndianness = exports.bufferToU32Array = exports.u32ArrayToBuffer = exports.calculateHash = exports.toHex = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = exports.isUint256 = void 0;
|
|
21
4
|
const starknet_types_08_1 = require("@starknet-io/starknet-types-08");
|
|
22
5
|
const starknet_1 = require("starknet");
|
|
23
6
|
const buffer_1 = require("buffer");
|
|
@@ -25,6 +8,7 @@ const StarknetSwapData_1 = require("../starknet/swaps/StarknetSwapData");
|
|
|
25
8
|
function isUint256(val) {
|
|
26
9
|
return val.low != null && val.high != null;
|
|
27
10
|
}
|
|
11
|
+
exports.isUint256 = isUint256;
|
|
28
12
|
function timeoutPromise(timeoutMillis, abortSignal) {
|
|
29
13
|
return new Promise((resolve, reject) => {
|
|
30
14
|
const timeout = setTimeout(resolve, timeoutMillis);
|
|
@@ -35,6 +19,7 @@ function timeoutPromise(timeoutMillis, abortSignal) {
|
|
|
35
19
|
});
|
|
36
20
|
});
|
|
37
21
|
}
|
|
22
|
+
exports.timeoutPromise = timeoutPromise;
|
|
38
23
|
function onceAsync(executor) {
|
|
39
24
|
let promise;
|
|
40
25
|
return () => {
|
|
@@ -47,6 +32,7 @@ function onceAsync(executor) {
|
|
|
47
32
|
}
|
|
48
33
|
};
|
|
49
34
|
}
|
|
35
|
+
exports.onceAsync = onceAsync;
|
|
50
36
|
function getLogger(prefix) {
|
|
51
37
|
return {
|
|
52
38
|
// @ts-ignore
|
|
@@ -59,6 +45,7 @@ function getLogger(prefix) {
|
|
|
59
45
|
error: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 0) && console.error(prefix + msg, ...args)
|
|
60
46
|
};
|
|
61
47
|
}
|
|
48
|
+
exports.getLogger = getLogger;
|
|
62
49
|
const logger = getLogger("Utils: ");
|
|
63
50
|
async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
|
|
64
51
|
retryPolicy = retryPolicy || {};
|
|
@@ -85,6 +72,7 @@ async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
|
|
|
85
72
|
}
|
|
86
73
|
throw err;
|
|
87
74
|
}
|
|
75
|
+
exports.tryWithRetries = tryWithRetries;
|
|
88
76
|
function toHex(value, length = 64) {
|
|
89
77
|
if (value == null)
|
|
90
78
|
return null;
|
|
@@ -102,6 +90,7 @@ function toHex(value, length = 64) {
|
|
|
102
90
|
}
|
|
103
91
|
return "0x" + value.toString("hex").padStart(length, "0");
|
|
104
92
|
}
|
|
93
|
+
exports.toHex = toHex;
|
|
105
94
|
function calculateHash(tx) {
|
|
106
95
|
const commonData = {
|
|
107
96
|
version: tx.details.version,
|
|
@@ -137,6 +126,7 @@ function calculateHash(tx) {
|
|
|
137
126
|
throw new Error("Unsupported tx type!");
|
|
138
127
|
}
|
|
139
128
|
}
|
|
129
|
+
exports.calculateHash = calculateHash;
|
|
140
130
|
function u32ArrayToBuffer(arr) {
|
|
141
131
|
const buffer = buffer_1.Buffer.alloc(4 * arr.length);
|
|
142
132
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -144,6 +134,7 @@ function u32ArrayToBuffer(arr) {
|
|
|
144
134
|
}
|
|
145
135
|
return buffer;
|
|
146
136
|
}
|
|
137
|
+
exports.u32ArrayToBuffer = u32ArrayToBuffer;
|
|
147
138
|
function bufferToU32Array(buffer) {
|
|
148
139
|
const result = [];
|
|
149
140
|
for (let i = 0; i < buffer.length; i += 4) {
|
|
@@ -151,6 +142,7 @@ function bufferToU32Array(buffer) {
|
|
|
151
142
|
}
|
|
152
143
|
return result;
|
|
153
144
|
}
|
|
145
|
+
exports.bufferToU32Array = bufferToU32Array;
|
|
154
146
|
function u32ReverseEndianness(value) {
|
|
155
147
|
const valueBN = BigInt(value);
|
|
156
148
|
return Number(((valueBN & 0xffn) << 24n) |
|
|
@@ -158,6 +150,7 @@ function u32ReverseEndianness(value) {
|
|
|
158
150
|
((valueBN >> 8n) & 0xff00n) |
|
|
159
151
|
((valueBN >> 24n) & 0xffn));
|
|
160
152
|
}
|
|
153
|
+
exports.u32ReverseEndianness = u32ReverseEndianness;
|
|
161
154
|
function bigNumberishToBuffer(value, length) {
|
|
162
155
|
if (isUint256(value)) {
|
|
163
156
|
return buffer_1.Buffer.concat([bigNumberishToBuffer(value.high, 16), bigNumberishToBuffer(value.low, 16)]);
|
|
@@ -180,6 +173,7 @@ function bigNumberishToBuffer(value, length) {
|
|
|
180
173
|
return buff.slice(buff.length - length);
|
|
181
174
|
return buff;
|
|
182
175
|
}
|
|
176
|
+
exports.bigNumberishToBuffer = bigNumberishToBuffer;
|
|
183
177
|
function toBigInt(value) {
|
|
184
178
|
if (value == null)
|
|
185
179
|
return null;
|
|
@@ -196,6 +190,7 @@ function toBigInt(value) {
|
|
|
196
190
|
}
|
|
197
191
|
return BigInt(value);
|
|
198
192
|
}
|
|
193
|
+
exports.toBigInt = toBigInt;
|
|
199
194
|
function bytes31SpanToBuffer(span, length) {
|
|
200
195
|
const buffers = [];
|
|
201
196
|
const numFullBytes31 = Math.floor(length / 31);
|
|
@@ -211,6 +206,7 @@ function bytes31SpanToBuffer(span, length) {
|
|
|
211
206
|
buffers.push(bigNumberishToBuffer(span[i], additionalBytes));
|
|
212
207
|
return buffer_1.Buffer.concat(buffers);
|
|
213
208
|
}
|
|
209
|
+
exports.bytes31SpanToBuffer = bytes31SpanToBuffer;
|
|
214
210
|
function bufferToBytes31Span(buffer, startIndex = 0, endIndex = buffer.length) {
|
|
215
211
|
const values = [];
|
|
216
212
|
for (let i = startIndex + 31; i < endIndex; i += 31) {
|
|
@@ -220,6 +216,7 @@ function bufferToBytes31Span(buffer, startIndex = 0, endIndex = buffer.length) {
|
|
|
220
216
|
values.push(BigInt("0x" + buffer.slice(startIndex + (values.length * 31), endIndex).toString("hex")));
|
|
221
217
|
return values;
|
|
222
218
|
}
|
|
219
|
+
exports.bufferToBytes31Span = bufferToBytes31Span;
|
|
223
220
|
function bufferToByteArray(buffer, startIndex = 0, endIndex = buffer.length) {
|
|
224
221
|
const values = [];
|
|
225
222
|
for (let i = startIndex + 31; i < endIndex; i += 31) {
|
|
@@ -237,9 +234,11 @@ function bufferToByteArray(buffer, startIndex = 0, endIndex = buffer.length) {
|
|
|
237
234
|
pendingWordLen
|
|
238
235
|
];
|
|
239
236
|
}
|
|
237
|
+
exports.bufferToByteArray = bufferToByteArray;
|
|
240
238
|
function poseidonHashRange(buffer, startIndex = 0, endIndex = buffer.length) {
|
|
241
239
|
return starknet_1.hash.computePoseidonHashOnElements(bufferToBytes31Span(buffer, startIndex, endIndex));
|
|
242
240
|
}
|
|
241
|
+
exports.poseidonHashRange = poseidonHashRange;
|
|
243
242
|
function parseInitFunctionCalldata(calldata, claimHandler) {
|
|
244
243
|
const escrow = StarknetSwapData_1.StarknetSwapData.fromSerializedFeltArray(calldata, claimHandler);
|
|
245
244
|
const signatureLen = Number(toBigInt(calldata.shift()));
|
|
@@ -251,6 +250,7 @@ function parseInitFunctionCalldata(calldata, claimHandler) {
|
|
|
251
250
|
throw new Error("Calldata not read fully!");
|
|
252
251
|
return { escrow, signature, timeout, extraData };
|
|
253
252
|
}
|
|
253
|
+
exports.parseInitFunctionCalldata = parseInitFunctionCalldata;
|
|
254
254
|
function findLastIndex(array, callback) {
|
|
255
255
|
for (let i = array.length - 1; i >= 0; i--) {
|
|
256
256
|
if (callback(array[i], i))
|
|
@@ -258,3 +258,4 @@ function findLastIndex(array, callback) {
|
|
|
258
258
|
}
|
|
259
259
|
return -1;
|
|
260
260
|
}
|
|
261
|
+
exports.findLastIndex = findLastIndex;
|