@atomiqlabs/chain-starknet 4.0.0-dev.12 → 4.0.0-dev.13
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 +38 -38
- package/dist/index.js +54 -54
- package/dist/starknet/StarknetChainType.d.ts +13 -13
- package/dist/starknet/StarknetChainType.js +2 -2
- package/dist/starknet/StarknetInitializer.d.ts +27 -27
- 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 +52 -52
- package/dist/starknet/chain/StarknetChainInterface.js +91 -91
- package/dist/starknet/chain/StarknetModule.d.ts +14 -14
- 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 +77 -77
- package/dist/starknet/chain/modules/StarknetFees.js +114 -114
- 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 -98
- package/dist/starknet/chain/modules/StarknetTransactions.d.ts +93 -93
- package/dist/starknet/chain/modules/StarknetTransactions.js +261 -260
- package/dist/starknet/contract/StarknetContractBase.d.ts +13 -13
- package/dist/starknet/contract/StarknetContractBase.js +20 -16
- 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 +89 -90
- package/dist/starknet/events/StarknetChainEventsBrowser.js +296 -294
- package/dist/starknet/provider/RpcProviderWithRetries.d.ts +21 -21
- package/dist/starknet/provider/RpcProviderWithRetries.js +32 -32
- 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 +66 -66
- package/dist/starknet/spv_swap/StarknetSpvVaultContract.js +382 -382
- 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 +191 -191
- package/dist/starknet/swaps/StarknetSwapContract.js +424 -424
- 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 -87
- package/dist/starknet/swaps/modules/StarknetSwapInit.js +235 -225
- package/dist/starknet/swaps/modules/StarknetSwapRefund.d.ts +62 -62
- package/dist/starknet/swaps/modules/StarknetSwapRefund.js +128 -128
- package/dist/starknet/wallet/StarknetKeypairWallet.d.ts +7 -7
- package/dist/starknet/wallet/StarknetKeypairWallet.js +35 -30
- package/dist/starknet/wallet/StarknetSigner.d.ts +12 -12
- package/dist/starknet/wallet/StarknetSigner.js +47 -46
- package/dist/utils/Utils.d.ts +37 -37
- package/dist/utils/Utils.js +260 -261
- package/package.json +43 -37
- package/src/index.ts +47 -47
- package/src/starknet/StarknetChainType.ts +28 -28
- package/src/starknet/StarknetInitializer.ts +108 -108
- 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 +149 -149
- 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 -74
- package/src/starknet/chain/modules/StarknetEvents.ts +104 -104
- package/src/starknet/chain/modules/StarknetFees.ts +154 -154
- package/src/starknet/chain/modules/StarknetSignatures.ts +91 -91
- package/src/starknet/chain/modules/StarknetTokens.ts +120 -116
- package/src/starknet/chain/modules/StarknetTransactions.ts +285 -283
- package/src/starknet/contract/StarknetContractBase.ts +30 -26
- 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 +411 -411
- package/src/starknet/provider/RpcProviderWithRetries.ts +43 -43
- package/src/starknet/spv_swap/SpvVaultContractAbi.ts +656 -656
- package/src/starknet/spv_swap/StarknetSpvVaultContract.ts +483 -483
- 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 +647 -647
- 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 -287
- package/src/starknet/swaps/modules/StarknetSwapRefund.ts +196 -196
- package/src/starknet/wallet/StarknetKeypairWallet.ts +44 -39
- package/src/starknet/wallet/StarknetSigner.ts +55 -55
- package/src/utils/Utils.ts +251 -252
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
import { StarknetAction } from "../StarknetAction";
|
|
3
|
-
export declare class StarknetTokens extends StarknetModule {
|
|
4
|
-
static readonly ERC20_ETH = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
|
|
5
|
-
static readonly ERC20_STRK = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
|
|
6
|
-
static readonly GasCosts: {
|
|
7
|
-
TRANSFER: {
|
|
8
|
-
l1DataGas: number;
|
|
9
|
-
l2Gas: number;
|
|
10
|
-
l1Gas: number;
|
|
11
|
-
};
|
|
12
|
-
APPROVE: {
|
|
13
|
-
l1DataGas: number;
|
|
14
|
-
l2Gas: number;
|
|
15
|
-
l1Gas: number;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
private getContract;
|
|
19
|
-
/**
|
|
20
|
-
* Action for transferring the erc20 token
|
|
21
|
-
*
|
|
22
|
-
* @param signer
|
|
23
|
-
* @param recipient
|
|
24
|
-
* @param token
|
|
25
|
-
* @param amount
|
|
26
|
-
* @constructor
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private Transfer;
|
|
30
|
-
/**
|
|
31
|
-
* Approves spend of tokens for a specific spender
|
|
32
|
-
*
|
|
33
|
-
* @param signer
|
|
34
|
-
* @param spender
|
|
35
|
-
* @param token
|
|
36
|
-
* @param amount
|
|
37
|
-
* @constructor
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
Approve(signer: string, spender: string, token: string, amount: bigint): StarknetAction;
|
|
41
|
-
/**
|
|
42
|
-
* Checks if the provided string is a valid starknet token
|
|
43
|
-
*
|
|
44
|
-
* @param token
|
|
45
|
-
*/
|
|
46
|
-
isValidToken(token: string): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Returns the token balance of the address
|
|
49
|
-
*
|
|
50
|
-
* @param address
|
|
51
|
-
* @param token
|
|
52
|
-
*/
|
|
53
|
-
getTokenBalance(address: string, token: string): Promise<bigint>;
|
|
54
|
-
/**
|
|
55
|
-
* Returns the native currency address, return the default used by the fee module
|
|
56
|
-
*/
|
|
57
|
-
getNativeCurrencyAddress(): string;
|
|
58
|
-
/**
|
|
59
|
-
* Creates transactions for sending the over the tokens
|
|
60
|
-
*
|
|
61
|
-
* @param signer
|
|
62
|
-
* @param token token to send
|
|
63
|
-
* @param amount amount of the token to send
|
|
64
|
-
* @param recipient recipient's address
|
|
65
|
-
* @param feeRate fee rate to use for the transactions
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
txsTransfer(signer: string, token: string, amount: bigint, recipient: string, feeRate?: string): Promise<import("./StarknetTransactions").StarknetTx[]>;
|
|
69
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
import { StarknetAction } from "../StarknetAction";
|
|
3
|
+
export declare class StarknetTokens extends StarknetModule {
|
|
4
|
+
static readonly ERC20_ETH = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
|
|
5
|
+
static readonly ERC20_STRK = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
|
|
6
|
+
static readonly GasCosts: {
|
|
7
|
+
TRANSFER: {
|
|
8
|
+
l1DataGas: number;
|
|
9
|
+
l2Gas: number;
|
|
10
|
+
l1Gas: number;
|
|
11
|
+
};
|
|
12
|
+
APPROVE: {
|
|
13
|
+
l1DataGas: number;
|
|
14
|
+
l2Gas: number;
|
|
15
|
+
l1Gas: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
private getContract;
|
|
19
|
+
/**
|
|
20
|
+
* Action for transferring the erc20 token
|
|
21
|
+
*
|
|
22
|
+
* @param signer
|
|
23
|
+
* @param recipient
|
|
24
|
+
* @param token
|
|
25
|
+
* @param amount
|
|
26
|
+
* @constructor
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private Transfer;
|
|
30
|
+
/**
|
|
31
|
+
* Approves spend of tokens for a specific spender
|
|
32
|
+
*
|
|
33
|
+
* @param signer
|
|
34
|
+
* @param spender
|
|
35
|
+
* @param token
|
|
36
|
+
* @param amount
|
|
37
|
+
* @constructor
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
Approve(signer: string, spender: string, token: string, amount: bigint): StarknetAction;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the provided string is a valid starknet token
|
|
43
|
+
*
|
|
44
|
+
* @param token
|
|
45
|
+
*/
|
|
46
|
+
isValidToken(token: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the token balance of the address
|
|
49
|
+
*
|
|
50
|
+
* @param address
|
|
51
|
+
* @param token
|
|
52
|
+
*/
|
|
53
|
+
getTokenBalance(address: string, token: string): Promise<bigint>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the native currency address, return the default used by the fee module
|
|
56
|
+
*/
|
|
57
|
+
getNativeCurrencyAddress(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Creates transactions for sending the over the tokens
|
|
60
|
+
*
|
|
61
|
+
* @param signer
|
|
62
|
+
* @param token token to send
|
|
63
|
+
* @param amount amount of the token to send
|
|
64
|
+
* @param recipient recipient's address
|
|
65
|
+
* @param feeRate fee rate to use for the transactions
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
txsTransfer(signer: string, token: string, amount: bigint, recipient: string, feeRate?: string): Promise<import("./StarknetTransactions").StarknetTx[]>;
|
|
69
|
+
}
|
|
@@ -1,98 +1,102 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetTokens = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
const StarknetAction_1 = require("../StarknetAction");
|
|
6
|
-
const ERC20Abi_1 = require("./ERC20Abi");
|
|
7
|
-
const starknet_1 = require("starknet");
|
|
8
|
-
const Utils_1 = require("../../../utils/Utils");
|
|
9
|
-
const StarknetAddresses_1 = require("./StarknetAddresses");
|
|
10
|
-
class StarknetTokens extends StarknetModule_1.StarknetModule {
|
|
11
|
-
getContract(address) {
|
|
12
|
-
return new starknet_1.Contract(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetTokens = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
const StarknetAction_1 = require("../StarknetAction");
|
|
6
|
+
const ERC20Abi_1 = require("./ERC20Abi");
|
|
7
|
+
const starknet_1 = require("starknet");
|
|
8
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
9
|
+
const StarknetAddresses_1 = require("./StarknetAddresses");
|
|
10
|
+
class StarknetTokens extends StarknetModule_1.StarknetModule {
|
|
11
|
+
getContract(address) {
|
|
12
|
+
return new starknet_1.Contract({
|
|
13
|
+
abi: ERC20Abi_1.ERC20Abi,
|
|
14
|
+
address: address,
|
|
15
|
+
providerOrAccount: this.root.provider
|
|
16
|
+
}).typedv2(ERC20Abi_1.ERC20Abi);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Action for transferring the erc20 token
|
|
20
|
+
*
|
|
21
|
+
* @param signer
|
|
22
|
+
* @param recipient
|
|
23
|
+
* @param token
|
|
24
|
+
* @param amount
|
|
25
|
+
* @constructor
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
Transfer(signer, recipient, token, amount) {
|
|
29
|
+
const erc20 = this.getContract(token);
|
|
30
|
+
return new StarknetAction_1.StarknetAction(signer, this.root, erc20.populateTransaction.transfer(recipient, amount), StarknetTokens.GasCosts.TRANSFER);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Approves spend of tokens for a specific spender
|
|
34
|
+
*
|
|
35
|
+
* @param signer
|
|
36
|
+
* @param spender
|
|
37
|
+
* @param token
|
|
38
|
+
* @param amount
|
|
39
|
+
* @constructor
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
Approve(signer, spender, token, amount) {
|
|
43
|
+
const erc20 = this.getContract(token);
|
|
44
|
+
return new StarknetAction_1.StarknetAction(signer, this.root, erc20.populateTransaction.approve(spender, amount), StarknetTokens.GasCosts.APPROVE);
|
|
45
|
+
}
|
|
46
|
+
///////////////////
|
|
47
|
+
//// Tokens
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the provided string is a valid starknet token
|
|
50
|
+
*
|
|
51
|
+
* @param token
|
|
52
|
+
*/
|
|
53
|
+
isValidToken(token) {
|
|
54
|
+
return StarknetAddresses_1.StarknetAddresses.isValidAddress(token);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the token balance of the address
|
|
58
|
+
*
|
|
59
|
+
* @param address
|
|
60
|
+
* @param token
|
|
61
|
+
*/
|
|
62
|
+
async getTokenBalance(address, token) {
|
|
63
|
+
const erc20 = this.getContract(token);
|
|
64
|
+
const balance = await erc20.balance_of(address);
|
|
65
|
+
const balanceBN = (0, Utils_1.toBigInt)(balance);
|
|
66
|
+
this.logger.debug("getTokenBalance(): token balance fetched, token: " + token +
|
|
67
|
+
" address: " + address + " amount: " + balanceBN.toString());
|
|
68
|
+
return balanceBN;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the native currency address, return the default used by the fee module
|
|
72
|
+
*/
|
|
73
|
+
getNativeCurrencyAddress() {
|
|
74
|
+
return this.root.Fees.getDefaultGasToken();
|
|
75
|
+
}
|
|
76
|
+
///////////////////
|
|
77
|
+
//// Transfers
|
|
78
|
+
/**
|
|
79
|
+
* Creates transactions for sending the over the tokens
|
|
80
|
+
*
|
|
81
|
+
* @param signer
|
|
82
|
+
* @param token token to send
|
|
83
|
+
* @param amount amount of the token to send
|
|
84
|
+
* @param recipient recipient's address
|
|
85
|
+
* @param feeRate fee rate to use for the transactions
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
async txsTransfer(signer, token, amount, recipient, feeRate) {
|
|
89
|
+
const action = this.Transfer(signer, recipient, token, amount);
|
|
90
|
+
feeRate = feeRate ?? await this.root.Fees.getFeeRate();
|
|
91
|
+
this.logger.debug("txsTransfer(): transfer TX created, recipient: " + recipient.toString() +
|
|
92
|
+
" token: " + token.toString() + " amount: " + amount.toString(10));
|
|
93
|
+
return [await action.tx(feeRate)];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.StarknetTokens = StarknetTokens;
|
|
97
|
+
StarknetTokens.ERC20_ETH = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
|
|
98
|
+
StarknetTokens.ERC20_STRK = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
|
|
99
|
+
StarknetTokens.GasCosts = {
|
|
100
|
+
TRANSFER: { l1DataGas: 400, l2Gas: 4000000, l1Gas: 0 },
|
|
101
|
+
APPROVE: { l1DataGas: 400, l2Gas: 4000000, l1Gas: 0 }
|
|
102
|
+
};
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
import { Call, DeployAccountContractPayload, DeployAccountContractTransaction, Invocation, InvocationsSignerDetails, BigNumberish } from "starknet";
|
|
3
|
-
import { StarknetSigner } from "../../wallet/StarknetSigner";
|
|
4
|
-
export type StarknetTx = ({
|
|
5
|
-
type: "DEPLOY_ACCOUNT";
|
|
6
|
-
tx: DeployAccountContractPayload;
|
|
7
|
-
signed?: DeployAccountContractTransaction;
|
|
8
|
-
} | {
|
|
9
|
-
type: "INVOKE";
|
|
10
|
-
tx: Array<Call>;
|
|
11
|
-
signed?: Invocation;
|
|
12
|
-
}) & {
|
|
13
|
-
details: InvocationsSignerDetails & {
|
|
14
|
-
maxFee?: BigNumberish;
|
|
15
|
-
};
|
|
16
|
-
txId?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare class StarknetTransactions extends StarknetModule {
|
|
19
|
-
private readonly latestConfirmedNonces;
|
|
20
|
-
private cbkBeforeTxSigned;
|
|
21
|
-
/**
|
|
22
|
-
* Waits for transaction confirmation using WS subscription and occasional HTTP polling, also re-sends
|
|
23
|
-
* the transaction at regular interval
|
|
24
|
-
*
|
|
25
|
-
* @param tx starknet transaction to wait for confirmation for & keep re-sending until it confirms
|
|
26
|
-
* @param abortSignal signal to abort waiting for tx confirmation
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private confirmTransaction;
|
|
30
|
-
/**
|
|
31
|
-
* Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
|
|
32
|
-
*
|
|
33
|
-
* @param signer
|
|
34
|
-
* @param txs
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
private prepareTransactions;
|
|
38
|
-
/**
|
|
39
|
-
* Sends out a signed transaction to the RPC
|
|
40
|
-
*
|
|
41
|
-
* @param tx Starknet tx to send
|
|
42
|
-
* @param onBeforePublish a callback called before every transaction is published
|
|
43
|
-
* @param signer
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
private sendSignedTransaction;
|
|
47
|
-
/**
|
|
48
|
-
* Prepares, signs , sends (in parallel or sequentially) & optionally waits for confirmation
|
|
49
|
-
* of a batch of starknet transactions
|
|
50
|
-
*
|
|
51
|
-
* @param signer
|
|
52
|
-
* @param txs transactions to send
|
|
53
|
-
* @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
|
|
54
|
-
* are re-sent at regular intervals)
|
|
55
|
-
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
56
|
-
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
57
|
-
* are executed in order)
|
|
58
|
-
* @param onBeforePublish a callback called before every transaction is published
|
|
59
|
-
*/
|
|
60
|
-
sendAndConfirm(signer: StarknetSigner, txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
61
|
-
/**
|
|
62
|
-
* Serializes the solana transaction, saves the transaction, signers & last valid blockheight
|
|
63
|
-
*
|
|
64
|
-
* @param tx
|
|
65
|
-
*/
|
|
66
|
-
serializeTx(tx: StarknetTx): Promise<string>;
|
|
67
|
-
/**
|
|
68
|
-
* Deserializes saved solana transaction, extracting the transaction, signers & last valid blockheight
|
|
69
|
-
*
|
|
70
|
-
* @param txData
|
|
71
|
-
*/
|
|
72
|
-
deserializeTx(txData: string): Promise<StarknetTx>;
|
|
73
|
-
/**
|
|
74
|
-
* Gets the status of the raw starknet transaction
|
|
75
|
-
*
|
|
76
|
-
* @param tx
|
|
77
|
-
*/
|
|
78
|
-
getTxStatus(tx: string): Promise<"pending" | "success" | "not_found" | "reverted">;
|
|
79
|
-
/**
|
|
80
|
-
* Gets the status of the starknet transaction with a specific txId
|
|
81
|
-
*
|
|
82
|
-
* @param txId
|
|
83
|
-
*/
|
|
84
|
-
_getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted" | "rejected">;
|
|
85
|
-
/**
|
|
86
|
-
* Gets the status of the starknet transaction with a specific txId
|
|
87
|
-
*
|
|
88
|
-
* @param txId
|
|
89
|
-
*/
|
|
90
|
-
getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted">;
|
|
91
|
-
onBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): void;
|
|
92
|
-
offBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): boolean;
|
|
93
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
import { Call, DeployAccountContractPayload, DeployAccountContractTransaction, Invocation, InvocationsSignerDetails, BigNumberish } from "starknet";
|
|
3
|
+
import { StarknetSigner } from "../../wallet/StarknetSigner";
|
|
4
|
+
export type StarknetTx = ({
|
|
5
|
+
type: "DEPLOY_ACCOUNT";
|
|
6
|
+
tx: DeployAccountContractPayload;
|
|
7
|
+
signed?: DeployAccountContractTransaction;
|
|
8
|
+
} | {
|
|
9
|
+
type: "INVOKE";
|
|
10
|
+
tx: Array<Call>;
|
|
11
|
+
signed?: Invocation;
|
|
12
|
+
}) & {
|
|
13
|
+
details: InvocationsSignerDetails & {
|
|
14
|
+
maxFee?: BigNumberish;
|
|
15
|
+
};
|
|
16
|
+
txId?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class StarknetTransactions extends StarknetModule {
|
|
19
|
+
private readonly latestConfirmedNonces;
|
|
20
|
+
private cbkBeforeTxSigned;
|
|
21
|
+
/**
|
|
22
|
+
* Waits for transaction confirmation using WS subscription and occasional HTTP polling, also re-sends
|
|
23
|
+
* the transaction at regular interval
|
|
24
|
+
*
|
|
25
|
+
* @param tx starknet transaction to wait for confirmation for & keep re-sending until it confirms
|
|
26
|
+
* @param abortSignal signal to abort waiting for tx confirmation
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private confirmTransaction;
|
|
30
|
+
/**
|
|
31
|
+
* Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
|
|
32
|
+
*
|
|
33
|
+
* @param signer
|
|
34
|
+
* @param txs
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private prepareTransactions;
|
|
38
|
+
/**
|
|
39
|
+
* Sends out a signed transaction to the RPC
|
|
40
|
+
*
|
|
41
|
+
* @param tx Starknet tx to send
|
|
42
|
+
* @param onBeforePublish a callback called before every transaction is published
|
|
43
|
+
* @param signer
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private sendSignedTransaction;
|
|
47
|
+
/**
|
|
48
|
+
* Prepares, signs , sends (in parallel or sequentially) & optionally waits for confirmation
|
|
49
|
+
* of a batch of starknet transactions
|
|
50
|
+
*
|
|
51
|
+
* @param signer
|
|
52
|
+
* @param txs transactions to send
|
|
53
|
+
* @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
|
|
54
|
+
* are re-sent at regular intervals)
|
|
55
|
+
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
56
|
+
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
57
|
+
* are executed in order)
|
|
58
|
+
* @param onBeforePublish a callback called before every transaction is published
|
|
59
|
+
*/
|
|
60
|
+
sendAndConfirm(signer: StarknetSigner, txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Serializes the solana transaction, saves the transaction, signers & last valid blockheight
|
|
63
|
+
*
|
|
64
|
+
* @param tx
|
|
65
|
+
*/
|
|
66
|
+
serializeTx(tx: StarknetTx): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Deserializes saved solana transaction, extracting the transaction, signers & last valid blockheight
|
|
69
|
+
*
|
|
70
|
+
* @param txData
|
|
71
|
+
*/
|
|
72
|
+
deserializeTx(txData: string): Promise<StarknetTx>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the status of the raw starknet transaction
|
|
75
|
+
*
|
|
76
|
+
* @param tx
|
|
77
|
+
*/
|
|
78
|
+
getTxStatus(tx: string): Promise<"pending" | "success" | "not_found" | "reverted">;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the status of the starknet transaction with a specific txId
|
|
81
|
+
*
|
|
82
|
+
* @param txId
|
|
83
|
+
*/
|
|
84
|
+
_getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted" | "rejected">;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the status of the starknet transaction with a specific txId
|
|
87
|
+
*
|
|
88
|
+
* @param txId
|
|
89
|
+
*/
|
|
90
|
+
getTxIdStatus(txId: string): Promise<"pending" | "success" | "not_found" | "reverted">;
|
|
91
|
+
onBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): void;
|
|
92
|
+
offBeforeTxSigned(callback: (tx: StarknetTx) => Promise<void>): boolean;
|
|
93
|
+
}
|