@atomiqlabs/chain-starknet 4.0.0-dev.26 → 4.0.0-dev.28
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 +39 -39
- package/dist/index.js +55 -55
- package/dist/starknet/StarknetChainType.d.ts +13 -13
- package/dist/starknet/StarknetChainType.js +2 -2
- package/dist/starknet/StarknetInitializer.d.ts +28 -28
- package/dist/starknet/StarknetInitializer.js +69 -69
- package/dist/starknet/btcrelay/BtcRelayAbi.d.ts +250 -250
- package/dist/starknet/btcrelay/BtcRelayAbi.js +341 -341
- package/dist/starknet/btcrelay/StarknetBtcRelay.d.ts +186 -186
- package/dist/starknet/btcrelay/StarknetBtcRelay.js +379 -379
- package/dist/starknet/btcrelay/headers/StarknetBtcHeader.d.ts +31 -31
- package/dist/starknet/btcrelay/headers/StarknetBtcHeader.js +74 -74
- package/dist/starknet/btcrelay/headers/StarknetBtcStoredHeader.d.ts +51 -51
- package/dist/starknet/btcrelay/headers/StarknetBtcStoredHeader.js +113 -113
- package/dist/starknet/chain/StarknetAction.d.ts +19 -19
- package/dist/starknet/chain/StarknetAction.js +73 -73
- package/dist/starknet/chain/StarknetChainInterface.d.ts +54 -54
- package/dist/starknet/chain/StarknetChainInterface.js +97 -97
- package/dist/starknet/chain/StarknetModule.d.ts +9 -9
- package/dist/starknet/chain/StarknetModule.js +13 -13
- package/dist/starknet/chain/modules/ERC20Abi.d.ts +755 -755
- package/dist/starknet/chain/modules/ERC20Abi.js +1032 -1032
- package/dist/starknet/chain/modules/StarknetAccounts.d.ts +6 -6
- package/dist/starknet/chain/modules/StarknetAccounts.js +24 -24
- package/dist/starknet/chain/modules/StarknetAddresses.d.ts +9 -9
- package/dist/starknet/chain/modules/StarknetAddresses.js +26 -26
- package/dist/starknet/chain/modules/StarknetBlocks.d.ts +20 -20
- package/dist/starknet/chain/modules/StarknetBlocks.js +64 -64
- package/dist/starknet/chain/modules/StarknetEvents.d.ts +44 -44
- package/dist/starknet/chain/modules/StarknetEvents.js +88 -88
- package/dist/starknet/chain/modules/StarknetFees.d.ts +82 -82
- package/dist/starknet/chain/modules/StarknetFees.js +121 -121
- package/dist/starknet/chain/modules/StarknetSignatures.d.ts +29 -29
- package/dist/starknet/chain/modules/StarknetSignatures.js +72 -72
- package/dist/starknet/chain/modules/StarknetTokens.d.ts +69 -69
- package/dist/starknet/chain/modules/StarknetTokens.js +102 -102
- package/dist/starknet/chain/modules/StarknetTransactions.d.ts +111 -110
- package/dist/starknet/chain/modules/StarknetTransactions.js +359 -351
- package/dist/starknet/contract/StarknetContractBase.d.ts +13 -13
- package/dist/starknet/contract/StarknetContractBase.js +20 -20
- package/dist/starknet/contract/StarknetContractModule.d.ts +8 -8
- package/dist/starknet/contract/StarknetContractModule.js +11 -11
- package/dist/starknet/contract/modules/StarknetContractEvents.d.ts +51 -51
- package/dist/starknet/contract/modules/StarknetContractEvents.js +97 -97
- package/dist/starknet/events/StarknetChainEvents.d.ts +21 -21
- package/dist/starknet/events/StarknetChainEvents.js +52 -52
- package/dist/starknet/events/StarknetChainEventsBrowser.d.ts +84 -84
- package/dist/starknet/events/StarknetChainEventsBrowser.js +307 -307
- package/dist/starknet/provider/RpcProviderWithRetries.d.ts +41 -41
- package/dist/starknet/provider/RpcProviderWithRetries.js +70 -70
- package/dist/starknet/spv_swap/SpvVaultContractAbi.d.ts +488 -488
- package/dist/starknet/spv_swap/SpvVaultContractAbi.js +656 -656
- package/dist/starknet/spv_swap/StarknetSpvVaultContract.d.ts +89 -89
- package/dist/starknet/spv_swap/StarknetSpvVaultContract.js +477 -477
- package/dist/starknet/spv_swap/StarknetSpvVaultData.d.ts +49 -49
- package/dist/starknet/spv_swap/StarknetSpvVaultData.js +145 -145
- package/dist/starknet/spv_swap/StarknetSpvWithdrawalData.d.ts +25 -25
- package/dist/starknet/spv_swap/StarknetSpvWithdrawalData.js +72 -72
- package/dist/starknet/swaps/EscrowManagerAbi.d.ts +431 -431
- package/dist/starknet/swaps/EscrowManagerAbi.js +583 -583
- package/dist/starknet/swaps/StarknetSwapContract.d.ts +197 -197
- package/dist/starknet/swaps/StarknetSwapContract.js +440 -440
- package/dist/starknet/swaps/StarknetSwapData.d.ts +74 -74
- package/dist/starknet/swaps/StarknetSwapData.js +325 -325
- package/dist/starknet/swaps/StarknetSwapModule.d.ts +10 -10
- package/dist/starknet/swaps/StarknetSwapModule.js +11 -11
- package/dist/starknet/swaps/handlers/IHandler.d.ts +13 -13
- package/dist/starknet/swaps/handlers/IHandler.js +2 -2
- package/dist/starknet/swaps/handlers/claim/ClaimHandlers.d.ts +13 -13
- package/dist/starknet/swaps/handlers/claim/ClaimHandlers.js +13 -13
- package/dist/starknet/swaps/handlers/claim/HashlockClaimHandler.d.ts +21 -21
- package/dist/starknet/swaps/handlers/claim/HashlockClaimHandler.js +44 -44
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +24 -24
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.js +48 -48
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +25 -25
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.js +40 -40
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +20 -20
- package/dist/starknet/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.js +30 -30
- package/dist/starknet/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +45 -45
- package/dist/starknet/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +52 -52
- package/dist/starknet/swaps/handlers/refund/TimelockRefundHandler.d.ts +17 -17
- package/dist/starknet/swaps/handlers/refund/TimelockRefundHandler.js +27 -27
- package/dist/starknet/swaps/modules/StarknetLpVault.d.ts +69 -69
- package/dist/starknet/swaps/modules/StarknetLpVault.js +122 -122
- package/dist/starknet/swaps/modules/StarknetSwapClaim.d.ts +53 -53
- package/dist/starknet/swaps/modules/StarknetSwapClaim.js +100 -100
- package/dist/starknet/swaps/modules/StarknetSwapInit.d.ts +94 -94
- package/dist/starknet/swaps/modules/StarknetSwapInit.js +235 -235
- package/dist/starknet/swaps/modules/StarknetSwapRefund.d.ts +62 -62
- package/dist/starknet/swaps/modules/StarknetSwapRefund.js +128 -128
- package/dist/starknet/wallet/StarknetBrowserSigner.d.ts +5 -5
- package/dist/starknet/wallet/StarknetBrowserSigner.js +11 -11
- package/dist/starknet/wallet/StarknetKeypairWallet.d.ts +7 -7
- package/dist/starknet/wallet/StarknetKeypairWallet.js +35 -35
- package/dist/starknet/wallet/StarknetPersistentSigner.d.ts +33 -33
- package/dist/starknet/wallet/StarknetPersistentSigner.js +248 -243
- package/dist/starknet/wallet/StarknetSigner.d.ts +18 -18
- package/dist/starknet/wallet/StarknetSigner.js +69 -69
- package/dist/starknet/wallet/accounts/StarknetKeypairWallet.d.ts +7 -7
- package/dist/starknet/wallet/accounts/StarknetKeypairWallet.js +35 -35
- package/dist/utils/Utils.d.ts +39 -39
- package/dist/utils/Utils.js +264 -264
- package/package.json +45 -45
- package/src/index.ts +48 -48
- package/src/starknet/StarknetChainType.ts +28 -28
- package/src/starknet/StarknetInitializer.ts +110 -110
- package/src/starknet/btcrelay/BtcRelayAbi.ts +338 -338
- package/src/starknet/btcrelay/StarknetBtcRelay.ts +494 -494
- package/src/starknet/btcrelay/headers/StarknetBtcHeader.ts +100 -100
- package/src/starknet/btcrelay/headers/StarknetBtcStoredHeader.ts +141 -141
- package/src/starknet/chain/StarknetAction.ts +85 -85
- package/src/starknet/chain/StarknetChainInterface.ts +165 -165
- package/src/starknet/chain/StarknetModule.ts +19 -19
- package/src/starknet/chain/modules/ERC20Abi.ts +1029 -1029
- package/src/starknet/chain/modules/StarknetAccounts.ts +25 -25
- package/src/starknet/chain/modules/StarknetAddresses.ts +22 -22
- package/src/starknet/chain/modules/StarknetBlocks.ts +75 -75
- package/src/starknet/chain/modules/StarknetEvents.ts +104 -104
- package/src/starknet/chain/modules/StarknetFees.ts +162 -162
- package/src/starknet/chain/modules/StarknetSignatures.ts +91 -91
- package/src/starknet/chain/modules/StarknetTokens.ts +120 -120
- package/src/starknet/chain/modules/StarknetTransactions.ts +399 -392
- package/src/starknet/contract/StarknetContractBase.ts +30 -30
- package/src/starknet/contract/StarknetContractModule.ts +16 -16
- package/src/starknet/contract/modules/StarknetContractEvents.ts +134 -134
- package/src/starknet/events/StarknetChainEvents.ts +67 -67
- package/src/starknet/events/StarknetChainEventsBrowser.ts +420 -420
- package/src/starknet/provider/RpcProviderWithRetries.ts +83 -83
- package/src/starknet/spv_swap/SpvVaultContractAbi.ts +656 -656
- package/src/starknet/spv_swap/StarknetSpvVaultContract.ts +591 -591
- package/src/starknet/spv_swap/StarknetSpvVaultData.ts +195 -195
- package/src/starknet/spv_swap/StarknetSpvWithdrawalData.ts +79 -79
- package/src/starknet/swaps/EscrowManagerAbi.ts +582 -582
- package/src/starknet/swaps/StarknetSwapContract.ts +668 -668
- package/src/starknet/swaps/StarknetSwapData.ts +455 -455
- package/src/starknet/swaps/StarknetSwapModule.ts +17 -17
- package/src/starknet/swaps/handlers/IHandler.ts +20 -20
- package/src/starknet/swaps/handlers/claim/ClaimHandlers.ts +23 -23
- package/src/starknet/swaps/handlers/claim/HashlockClaimHandler.ts +53 -53
- package/src/starknet/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +73 -73
- package/src/starknet/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +67 -67
- package/src/starknet/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +50 -50
- package/src/starknet/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +102 -102
- package/src/starknet/swaps/handlers/refund/TimelockRefundHandler.ts +38 -38
- package/src/starknet/swaps/modules/StarknetLpVault.ts +147 -147
- package/src/starknet/swaps/modules/StarknetSwapClaim.ts +141 -141
- package/src/starknet/swaps/modules/StarknetSwapInit.ts +300 -300
- package/src/starknet/swaps/modules/StarknetSwapRefund.ts +196 -196
- package/src/starknet/wallet/StarknetBrowserSigner.ts +11 -11
- package/src/starknet/wallet/StarknetPersistentSigner.ts +314 -310
- package/src/starknet/wallet/StarknetSigner.ts +84 -84
- package/src/starknet/wallet/accounts/StarknetKeypairWallet.ts +44 -44
- package/src/utils/Utils.ts +262 -262
|
@@ -1,351 +1,359 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetTransactions = exports.isStarknetTxDeployAccount = exports.isStarknetTxInvoke = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
const starknet_1 = require("starknet");
|
|
6
|
-
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
-
function isStarknetTxInvoke(obj) {
|
|
8
|
-
return typeof (obj) === "object" &&
|
|
9
|
-
typeof (obj.details) === "object" &&
|
|
10
|
-
(obj.txId == null || typeof (obj.txId) === "string") &&
|
|
11
|
-
obj.type === "INVOKE" &&
|
|
12
|
-
Array.isArray(obj.tx) &&
|
|
13
|
-
(obj.signed == null || typeof (obj.signed) === "object");
|
|
14
|
-
}
|
|
15
|
-
exports.isStarknetTxInvoke = isStarknetTxInvoke;
|
|
16
|
-
function isStarknetTxDeployAccount(obj) {
|
|
17
|
-
return typeof (obj) === "object" &&
|
|
18
|
-
typeof (obj.details) === "object" &&
|
|
19
|
-
(obj.txId == null || typeof (obj.txId) === "string") &&
|
|
20
|
-
obj.type === "DEPLOY_ACCOUNT" &&
|
|
21
|
-
Array.isArray(obj.tx) &&
|
|
22
|
-
(obj.signed == null || typeof (obj.signed) === "object");
|
|
23
|
-
}
|
|
24
|
-
exports.isStarknetTxDeployAccount = isStarknetTxDeployAccount;
|
|
25
|
-
const MAX_UNCONFIRMED_TXS = 25;
|
|
26
|
-
class StarknetTransactions extends StarknetModule_1.StarknetModule {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
this.latestConfirmedNonces = {};
|
|
30
|
-
this.latestPendingNonces = {};
|
|
31
|
-
this.latestSignedNonces = {};
|
|
32
|
-
this._cbksBeforeTxReplace = [];
|
|
33
|
-
this.cbksBeforeTxSigned = [];
|
|
34
|
-
this._knownTxSet = new Set();
|
|
35
|
-
}
|
|
36
|
-
sendTransaction(tx) {
|
|
37
|
-
switch (tx.type) {
|
|
38
|
-
case "INVOKE":
|
|
39
|
-
return this.provider.channel.invoke(tx.signed, tx.details).then(res => res.transaction_hash);
|
|
40
|
-
case "DEPLOY_ACCOUNT":
|
|
41
|
-
return this.provider.channel.deployAccount(tx.signed, tx.details).then((res) => res.transaction_hash);
|
|
42
|
-
default:
|
|
43
|
-
throw new Error("Unsupported tx type!");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns the nonce of the account or 0, if the account is not deployed yet
|
|
48
|
-
*
|
|
49
|
-
* @param address
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
* @
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param
|
|
113
|
-
* @
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
nonce
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
nonce
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* @param
|
|
156
|
-
* @
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* @param
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
tx
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
tx
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetTransactions = exports.isStarknetTxDeployAccount = exports.isStarknetTxInvoke = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
const starknet_1 = require("starknet");
|
|
6
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
+
function isStarknetTxInvoke(obj) {
|
|
8
|
+
return typeof (obj) === "object" &&
|
|
9
|
+
typeof (obj.details) === "object" &&
|
|
10
|
+
(obj.txId == null || typeof (obj.txId) === "string") &&
|
|
11
|
+
obj.type === "INVOKE" &&
|
|
12
|
+
Array.isArray(obj.tx) &&
|
|
13
|
+
(obj.signed == null || typeof (obj.signed) === "object");
|
|
14
|
+
}
|
|
15
|
+
exports.isStarknetTxInvoke = isStarknetTxInvoke;
|
|
16
|
+
function isStarknetTxDeployAccount(obj) {
|
|
17
|
+
return typeof (obj) === "object" &&
|
|
18
|
+
typeof (obj.details) === "object" &&
|
|
19
|
+
(obj.txId == null || typeof (obj.txId) === "string") &&
|
|
20
|
+
obj.type === "DEPLOY_ACCOUNT" &&
|
|
21
|
+
Array.isArray(obj.tx) &&
|
|
22
|
+
(obj.signed == null || typeof (obj.signed) === "object");
|
|
23
|
+
}
|
|
24
|
+
exports.isStarknetTxDeployAccount = isStarknetTxDeployAccount;
|
|
25
|
+
const MAX_UNCONFIRMED_TXS = 25;
|
|
26
|
+
class StarknetTransactions extends StarknetModule_1.StarknetModule {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.latestConfirmedNonces = {};
|
|
30
|
+
this.latestPendingNonces = {};
|
|
31
|
+
this.latestSignedNonces = {};
|
|
32
|
+
this._cbksBeforeTxReplace = [];
|
|
33
|
+
this.cbksBeforeTxSigned = [];
|
|
34
|
+
this._knownTxSet = new Set();
|
|
35
|
+
}
|
|
36
|
+
sendTransaction(tx) {
|
|
37
|
+
switch (tx.type) {
|
|
38
|
+
case "INVOKE":
|
|
39
|
+
return this.provider.channel.invoke(tx.signed, tx.details).then(res => res.transaction_hash);
|
|
40
|
+
case "DEPLOY_ACCOUNT":
|
|
41
|
+
return this.provider.channel.deployAccount(tx.signed, tx.details).then((res) => res.transaction_hash);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("Unsupported tx type!");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the nonce of the account or 0, if the account is not deployed yet
|
|
48
|
+
*
|
|
49
|
+
* @param address
|
|
50
|
+
* @param blockTag
|
|
51
|
+
*/
|
|
52
|
+
async getNonce(address, blockTag = starknet_1.BlockTag.PRE_CONFIRMED) {
|
|
53
|
+
try {
|
|
54
|
+
return BigInt(await this.provider.getNonceForAddress(address, blockTag));
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (e.message != null && e.message.includes("20: Contract not found")) {
|
|
58
|
+
return BigInt(0);
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Waits for transaction confirmation using WS subscription and occasional HTTP polling, also re-sends
|
|
65
|
+
* the transaction at regular interval
|
|
66
|
+
*
|
|
67
|
+
* @param tx starknet transaction to wait for confirmation for & keep re-sending until it confirms
|
|
68
|
+
* @param abortSignal signal to abort waiting for tx confirmation
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async confirmTransaction(tx, abortSignal) {
|
|
72
|
+
const checkTxns = new Set([tx.txId]);
|
|
73
|
+
const txReplaceListener = (oldTx, oldTxId, newTx, newTxId) => {
|
|
74
|
+
if (checkTxns.has(oldTxId))
|
|
75
|
+
checkTxns.add(newTxId);
|
|
76
|
+
return Promise.resolve();
|
|
77
|
+
};
|
|
78
|
+
this.onBeforeTxReplace(txReplaceListener);
|
|
79
|
+
let state = "pending";
|
|
80
|
+
let confirmedTxId = null;
|
|
81
|
+
while (state === "pending" || state === "not_found") {
|
|
82
|
+
await (0, Utils_1.timeoutPromise)(3000, abortSignal);
|
|
83
|
+
for (let txId of checkTxns) {
|
|
84
|
+
//TODO: Rebroadcast latest tx if possible, we might need to do that in case we use 2 different RPCs on the backend
|
|
85
|
+
// as the other one might not have the tx in their mempool
|
|
86
|
+
// if(state==="not_found" && tx.signed!=null) await this.sendSignedTransaction(tx).catch(e => {
|
|
87
|
+
// if(e.baseError?.code === 59) return; //Transaction already in the mempool
|
|
88
|
+
// this.logger.error("confirmTransaction(): Error on transaction re-send: ", e);
|
|
89
|
+
// });
|
|
90
|
+
state = await this._getTxIdStatus(txId);
|
|
91
|
+
if (state === "rejected" || state === "reverted" || state === "success") {
|
|
92
|
+
confirmedTxId = txId;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.offBeforeTxReplace(txReplaceListener);
|
|
98
|
+
if (state === "rejected")
|
|
99
|
+
throw new Error("Transaction rejected!");
|
|
100
|
+
const nextAccountNonce = (0, Utils_1.toBigInt)(tx.details.nonce) + 1n;
|
|
101
|
+
const currentConfirmedNonce = this.latestConfirmedNonces[(0, Utils_1.toHex)(tx.details.walletAddress)];
|
|
102
|
+
if (currentConfirmedNonce == null || nextAccountNonce > currentConfirmedNonce) {
|
|
103
|
+
this.latestConfirmedNonces[(0, Utils_1.toHex)(tx.details.walletAddress)] = nextAccountNonce;
|
|
104
|
+
}
|
|
105
|
+
if (state === "reverted")
|
|
106
|
+
throw new Error("Transaction reverted!");
|
|
107
|
+
return confirmedTxId;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
|
|
111
|
+
*
|
|
112
|
+
* @param signer
|
|
113
|
+
* @param txs
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
async prepareTransactions(signer, txs) {
|
|
117
|
+
let nonce = await this.getNonce(signer.getAddress());
|
|
118
|
+
const latestPendingNonce = this.latestPendingNonces[(0, Utils_1.toHex)(signer.getAddress())];
|
|
119
|
+
if (latestPendingNonce != null && latestPendingNonce > nonce) {
|
|
120
|
+
this.logger.debug("prepareTransactions(): Using 'pending' nonce from local cache!");
|
|
121
|
+
nonce = latestPendingNonce;
|
|
122
|
+
}
|
|
123
|
+
//Add deploy account tx
|
|
124
|
+
if (nonce === 0n) {
|
|
125
|
+
const deployPayload = await signer.getDeployPayload();
|
|
126
|
+
if (deployPayload != null)
|
|
127
|
+
txs.unshift(await this.root.Accounts.getAccountDeployTransaction(deployPayload));
|
|
128
|
+
}
|
|
129
|
+
if (!signer.isManagingNoncesInternally) {
|
|
130
|
+
if (nonce === 0n) {
|
|
131
|
+
//Just increment the nonce by one and hope the wallet is smart enough to deploy account first
|
|
132
|
+
nonce = 1n;
|
|
133
|
+
}
|
|
134
|
+
for (let i = 0; i < txs.length; i++) {
|
|
135
|
+
const tx = txs[i];
|
|
136
|
+
if (tx.details.nonce != null)
|
|
137
|
+
nonce = BigInt(tx.details.nonce); //Take the nonce from last tx
|
|
138
|
+
if (nonce == null)
|
|
139
|
+
nonce = BigInt(await this.root.provider.getNonceForAddress(signer.getAddress())); //Fetch the nonce
|
|
140
|
+
if (tx.details.nonce == null)
|
|
141
|
+
tx.details.nonce = nonce;
|
|
142
|
+
this.logger.debug("sendAndConfirm(): transaction prepared (" + (i + 1) + "/" + txs.length + "), nonce: " + tx.details.nonce);
|
|
143
|
+
nonce += BigInt(1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (let tx of txs) {
|
|
147
|
+
for (let callback of this.cbksBeforeTxSigned) {
|
|
148
|
+
await callback(tx);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sends out a signed transaction to the RPC
|
|
154
|
+
*
|
|
155
|
+
* @param tx Starknet tx to send
|
|
156
|
+
* @param onBeforePublish a callback called before every transaction is published
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
async sendSignedTransaction(tx, onBeforePublish) {
|
|
160
|
+
if (onBeforePublish != null)
|
|
161
|
+
await onBeforePublish(tx.txId, StarknetTransactions.serializeTx(tx));
|
|
162
|
+
this.logger.debug("sendSignedTransaction(): sending transaction: ", tx.txId);
|
|
163
|
+
const txResult = await this.sendTransaction(tx);
|
|
164
|
+
if (tx.txId !== txResult)
|
|
165
|
+
this.logger.warn("sendSignedTransaction(): sent tx hash not matching the precomputed hash!");
|
|
166
|
+
this.logger.info("sendSignedTransaction(): tx sent, expected txHash: " + tx.txId + ", txHash: " + txResult);
|
|
167
|
+
return txResult;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Prepares, signs , sends (in parallel or sequentially) & optionally waits for confirmation
|
|
171
|
+
* of a batch of starknet transactions
|
|
172
|
+
*
|
|
173
|
+
* @param signer
|
|
174
|
+
* @param txs transactions to send
|
|
175
|
+
* @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
|
|
176
|
+
* are re-sent at regular intervals)
|
|
177
|
+
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
178
|
+
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
179
|
+
* are executed in order)
|
|
180
|
+
* @param onBeforePublish a callback called before every transaction is published
|
|
181
|
+
*/
|
|
182
|
+
async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
183
|
+
await this.prepareTransactions(signer, txs);
|
|
184
|
+
const signedTxs = [];
|
|
185
|
+
//Don't separate the signing process from the sending when using browser-based wallet
|
|
186
|
+
if (signer.signTransaction != null)
|
|
187
|
+
for (let i = 0; i < txs.length; i++) {
|
|
188
|
+
const tx = txs[i];
|
|
189
|
+
const signedTx = await signer.signTransaction(tx);
|
|
190
|
+
signedTxs.push(signedTx);
|
|
191
|
+
this.logger.debug("sendAndConfirm(): transaction signed (" + (i + 1) + "/" + txs.length + "): " + signedTx.txId);
|
|
192
|
+
const nextAccountNonce = BigInt(signedTx.details.nonce) + 1n;
|
|
193
|
+
const currentSignedNonce = this.latestSignedNonces[(0, Utils_1.toHex)(signedTx.details.walletAddress)];
|
|
194
|
+
if (currentSignedNonce == null || nextAccountNonce > currentSignedNonce) {
|
|
195
|
+
this.latestSignedNonces[(0, Utils_1.toHex)(signedTx.details.walletAddress)] = nextAccountNonce;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this.logger.debug("sendAndConfirm(): sending transactions, count: " + txs.length +
|
|
199
|
+
" waitForConfirmation: " + waitForConfirmation + " parallel: " + parallel);
|
|
200
|
+
const txIds = [];
|
|
201
|
+
if (parallel) {
|
|
202
|
+
let promises = [];
|
|
203
|
+
for (let i = 0; i < txs.length; i++) {
|
|
204
|
+
let tx;
|
|
205
|
+
if (signer.signTransaction == null) {
|
|
206
|
+
const txId = await signer.sendTransaction(txs[i], onBeforePublish);
|
|
207
|
+
tx = txs[i];
|
|
208
|
+
tx.txId = txId;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const signedTx = signedTxs[i];
|
|
212
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
213
|
+
tx = signedTx;
|
|
214
|
+
}
|
|
215
|
+
if (tx.details.nonce != null) {
|
|
216
|
+
const nextAccountNonce = BigInt(tx.details.nonce) + 1n;
|
|
217
|
+
const currentPendingNonce = this.latestPendingNonces[(0, Utils_1.toHex)(tx.details.walletAddress)];
|
|
218
|
+
if (currentPendingNonce == null || nextAccountNonce > currentPendingNonce) {
|
|
219
|
+
this.latestPendingNonces[(0, Utils_1.toHex)(tx.details.walletAddress)] = nextAccountNonce;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
promises.push(this.confirmTransaction(tx, abortSignal));
|
|
223
|
+
if (!waitForConfirmation)
|
|
224
|
+
txIds.push(tx.txId);
|
|
225
|
+
this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + txs.length + "): " + tx.txId);
|
|
226
|
+
if (promises.length >= MAX_UNCONFIRMED_TXS) {
|
|
227
|
+
if (waitForConfirmation)
|
|
228
|
+
txIds.push(...await Promise.all(promises));
|
|
229
|
+
promises = [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (waitForConfirmation && promises.length > 0) {
|
|
233
|
+
txIds.push(...await Promise.all(promises));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
for (let i = 0; i < txs.length; i++) {
|
|
238
|
+
let tx;
|
|
239
|
+
if (signer.signTransaction == null) {
|
|
240
|
+
const txId = await signer.sendTransaction(txs[i], onBeforePublish);
|
|
241
|
+
tx = txs[i];
|
|
242
|
+
tx.txId = txId;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const signedTx = signedTxs[i];
|
|
246
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
247
|
+
tx = signedTx;
|
|
248
|
+
}
|
|
249
|
+
if (tx.details.nonce != null) {
|
|
250
|
+
const nextAccountNonce = BigInt(tx.details.nonce) + 1n;
|
|
251
|
+
const currentPendingNonce = this.latestPendingNonces[(0, Utils_1.toHex)(tx.details.walletAddress)];
|
|
252
|
+
if (currentPendingNonce == null || nextAccountNonce > currentPendingNonce) {
|
|
253
|
+
this.latestPendingNonces[(0, Utils_1.toHex)(tx.details.walletAddress)] = nextAccountNonce;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const confirmPromise = this.confirmTransaction(tx, abortSignal);
|
|
257
|
+
this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + txs.length + "): " + tx.txId);
|
|
258
|
+
//Don't await the last promise when !waitForConfirmation
|
|
259
|
+
let txHash = tx.txId;
|
|
260
|
+
if (i < txs.length - 1 || waitForConfirmation)
|
|
261
|
+
txHash = await confirmPromise;
|
|
262
|
+
txIds.push(txHash);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
this.logger.info("sendAndConfirm(): sent transactions, count: " + txs.length +
|
|
266
|
+
" waitForConfirmation: " + waitForConfirmation + " parallel: " + parallel);
|
|
267
|
+
return txIds;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Serializes the starknet transaction, saves the transaction, signers & last valid blockheight
|
|
271
|
+
*
|
|
272
|
+
* @param tx
|
|
273
|
+
*/
|
|
274
|
+
static serializeTx(tx) {
|
|
275
|
+
return JSON.stringify(tx, (key, value) => {
|
|
276
|
+
if (typeof (value) === "bigint")
|
|
277
|
+
return {
|
|
278
|
+
_type: "bigint",
|
|
279
|
+
_value: (0, Utils_1.toHex)(value)
|
|
280
|
+
};
|
|
281
|
+
return value;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Deserializes saved starknet transaction, extracting the transaction, signers & last valid blockheight
|
|
286
|
+
*
|
|
287
|
+
* @param txData
|
|
288
|
+
*/
|
|
289
|
+
static deserializeTx(txData) {
|
|
290
|
+
return JSON.parse(txData, (key, value) => {
|
|
291
|
+
if (typeof (value) === "object" && value._type === "bigint")
|
|
292
|
+
return BigInt(value._value);
|
|
293
|
+
return value;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Gets the status of the raw starknet transaction
|
|
298
|
+
*
|
|
299
|
+
* @param tx
|
|
300
|
+
*/
|
|
301
|
+
async getTxStatus(tx) {
|
|
302
|
+
const parsedTx = StarknetTransactions.deserializeTx(tx);
|
|
303
|
+
return await this.getTxIdStatus(parsedTx.txId);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Gets the status of the starknet transaction with a specific txId
|
|
307
|
+
*
|
|
308
|
+
* @param txId
|
|
309
|
+
*/
|
|
310
|
+
async _getTxIdStatus(txId) {
|
|
311
|
+
const status = await this.provider.getTransactionStatus(txId).catch(e => {
|
|
312
|
+
if (e.message != null && e.message.includes("29: Transaction hash not found"))
|
|
313
|
+
return null;
|
|
314
|
+
throw e;
|
|
315
|
+
});
|
|
316
|
+
if (status == null)
|
|
317
|
+
return this._knownTxSet.has(txId) ? "pending" : "not_found";
|
|
318
|
+
if (status.finality_status === starknet_1.ETransactionStatus.RECEIVED)
|
|
319
|
+
return "pending";
|
|
320
|
+
if (status.finality_status === starknet_1.ETransactionStatus.REJECTED)
|
|
321
|
+
return "rejected";
|
|
322
|
+
if (status.execution_status === starknet_1.ETransactionExecutionStatus.SUCCEEDED) {
|
|
323
|
+
return "success";
|
|
324
|
+
}
|
|
325
|
+
return "reverted";
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Gets the status of the starknet transaction with a specific txId
|
|
329
|
+
*
|
|
330
|
+
* @param txId
|
|
331
|
+
*/
|
|
332
|
+
async getTxIdStatus(txId) {
|
|
333
|
+
const status = await this._getTxIdStatus(txId);
|
|
334
|
+
if (status === "rejected")
|
|
335
|
+
return "reverted";
|
|
336
|
+
return status;
|
|
337
|
+
}
|
|
338
|
+
onBeforeTxReplace(callback) {
|
|
339
|
+
this._cbksBeforeTxReplace.push(callback);
|
|
340
|
+
}
|
|
341
|
+
offBeforeTxReplace(callback) {
|
|
342
|
+
const index = this._cbksBeforeTxReplace.indexOf(callback);
|
|
343
|
+
if (index === -1)
|
|
344
|
+
return false;
|
|
345
|
+
this._cbksBeforeTxReplace.splice(index, 1);
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
onBeforeTxSigned(callback) {
|
|
349
|
+
this.cbksBeforeTxSigned.push(callback);
|
|
350
|
+
}
|
|
351
|
+
offBeforeTxSigned(callback) {
|
|
352
|
+
const index = this.cbksBeforeTxSigned.indexOf(callback);
|
|
353
|
+
if (index === -1)
|
|
354
|
+
return false;
|
|
355
|
+
this.cbksBeforeTxSigned.splice(index, 1);
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.StarknetTransactions = StarknetTransactions;
|