@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,6 +1,6 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
import { StarknetTx } from "./StarknetTransactions";
|
|
3
|
-
import { DeployAccountContractPayload } from "starknet";
|
|
4
|
-
export declare class StarknetAccounts extends StarknetModule {
|
|
5
|
-
getAccountDeployTransaction(deploymentData: DeployAccountContractPayload): Promise<StarknetTx>;
|
|
6
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
import { StarknetTx } from "./StarknetTransactions";
|
|
3
|
+
import { DeployAccountContractPayload } from "starknet";
|
|
4
|
+
export declare class StarknetAccounts extends StarknetModule {
|
|
5
|
+
getAccountDeployTransaction(deploymentData: DeployAccountContractPayload): Promise<StarknetTx>;
|
|
6
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetAccounts = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
class StarknetAccounts extends StarknetModule_1.StarknetModule {
|
|
6
|
-
async getAccountDeployTransaction(deploymentData) {
|
|
7
|
-
const feeDetails = this.root.Fees.getFeeDetails({ l1DataGas: 500, l2Gas: 5000 * 40000, l1Gas: 0 }, await this.root.Fees.getFeeRate());
|
|
8
|
-
const details = {
|
|
9
|
-
...feeDetails,
|
|
10
|
-
walletAddress: deploymentData.contractAddress,
|
|
11
|
-
cairoVersion: "1",
|
|
12
|
-
chainId: this.root.starknetChainId,
|
|
13
|
-
nonce: 0,
|
|
14
|
-
accountDeploymentData: [],
|
|
15
|
-
skipValidate: false
|
|
16
|
-
};
|
|
17
|
-
return {
|
|
18
|
-
type: "DEPLOY_ACCOUNT",
|
|
19
|
-
tx: deploymentData,
|
|
20
|
-
details
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.StarknetAccounts = StarknetAccounts;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetAccounts = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
class StarknetAccounts extends StarknetModule_1.StarknetModule {
|
|
6
|
+
async getAccountDeployTransaction(deploymentData) {
|
|
7
|
+
const feeDetails = this.root.Fees.getFeeDetails({ l1DataGas: 500, l2Gas: 5000 * 40000, l1Gas: 0 }, await this.root.Fees.getFeeRate());
|
|
8
|
+
const details = {
|
|
9
|
+
...feeDetails,
|
|
10
|
+
walletAddress: deploymentData.contractAddress,
|
|
11
|
+
cairoVersion: "1",
|
|
12
|
+
chainId: this.root.starknetChainId,
|
|
13
|
+
nonce: 0,
|
|
14
|
+
accountDeploymentData: [],
|
|
15
|
+
skipValidate: false
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
type: "DEPLOY_ACCOUNT",
|
|
19
|
+
tx: deploymentData,
|
|
20
|
+
details
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.StarknetAccounts = StarknetAccounts;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
export declare class StarknetAddresses extends StarknetModule {
|
|
3
|
-
/**
|
|
4
|
-
* Checks whether an address is a valid starknet address
|
|
5
|
-
*
|
|
6
|
-
* @param value
|
|
7
|
-
*/
|
|
8
|
-
static isValidAddress(value: string): boolean;
|
|
9
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
export declare class StarknetAddresses extends StarknetModule {
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether an address is a valid starknet address
|
|
5
|
+
*
|
|
6
|
+
* @param value
|
|
7
|
+
*/
|
|
8
|
+
static isValidAddress(value: string): boolean;
|
|
9
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetAddresses = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
const starknet_1 = require("starknet");
|
|
6
|
-
class StarknetAddresses extends StarknetModule_1.StarknetModule {
|
|
7
|
-
///////////////////
|
|
8
|
-
//// Address utils
|
|
9
|
-
/**
|
|
10
|
-
* Checks whether an address is a valid starknet address
|
|
11
|
-
*
|
|
12
|
-
* @param value
|
|
13
|
-
*/
|
|
14
|
-
static isValidAddress(value) {
|
|
15
|
-
if (value.length !== 66)
|
|
16
|
-
return false;
|
|
17
|
-
try {
|
|
18
|
-
(0, starknet_1.validateAndParseAddress)(value);
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.StarknetAddresses = StarknetAddresses;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetAddresses = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
const starknet_1 = require("starknet");
|
|
6
|
+
class StarknetAddresses extends StarknetModule_1.StarknetModule {
|
|
7
|
+
///////////////////
|
|
8
|
+
//// Address utils
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether an address is a valid starknet address
|
|
11
|
+
*
|
|
12
|
+
* @param value
|
|
13
|
+
*/
|
|
14
|
+
static isValidAddress(value) {
|
|
15
|
+
if (value.length !== 66)
|
|
16
|
+
return false;
|
|
17
|
+
try {
|
|
18
|
+
(0, starknet_1.validateAndParseAddress)(value);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.StarknetAddresses = StarknetAddresses;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
export type StarknetBlockTag = "
|
|
3
|
-
export declare class StarknetBlocks extends StarknetModule {
|
|
4
|
-
private BLOCK_CACHE_TIME;
|
|
5
|
-
private blockCache;
|
|
6
|
-
/**
|
|
7
|
-
* Initiates fetch of a given block & saves it to cache
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
* @param blockTag
|
|
11
|
-
*/
|
|
12
|
-
private fetchAndSaveBlockTime;
|
|
13
|
-
private cleanupBlocks;
|
|
14
|
-
/**
|
|
15
|
-
* Gets the block for a given blocktag, with caching
|
|
16
|
-
*
|
|
17
|
-
* @param blockTag
|
|
18
|
-
*/
|
|
19
|
-
getBlockTime(blockTag: StarknetBlockTag | number): Promise<number>;
|
|
20
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
export type StarknetBlockTag = "pre_confirmed" | "latest";
|
|
3
|
+
export declare class StarknetBlocks extends StarknetModule {
|
|
4
|
+
private BLOCK_CACHE_TIME;
|
|
5
|
+
private blockCache;
|
|
6
|
+
/**
|
|
7
|
+
* Initiates fetch of a given block & saves it to cache
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
* @param blockTag
|
|
11
|
+
*/
|
|
12
|
+
private fetchAndSaveBlockTime;
|
|
13
|
+
private cleanupBlocks;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the block for a given blocktag, with caching
|
|
16
|
+
*
|
|
17
|
+
* @param blockTag
|
|
18
|
+
*/
|
|
19
|
+
getBlockTime(blockTag: StarknetBlockTag | number): Promise<number>;
|
|
20
|
+
}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetBlocks = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
class StarknetBlocks extends StarknetModule_1.StarknetModule {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.BLOCK_CACHE_TIME = 5 * 1000;
|
|
9
|
-
this.blockCache = {};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Initiates fetch of a given block & saves it to cache
|
|
13
|
-
*
|
|
14
|
-
* @private
|
|
15
|
-
* @param blockTag
|
|
16
|
-
*/
|
|
17
|
-
fetchAndSaveBlockTime(blockTag) {
|
|
18
|
-
const blockTagStr = blockTag.toString(10);
|
|
19
|
-
const blockTimePromise = this.provider.getBlockWithTxHashes(blockTag).then(result => result.timestamp);
|
|
20
|
-
const timestamp = Date.now();
|
|
21
|
-
this.blockCache[blockTagStr] = {
|
|
22
|
-
blockTime: blockTimePromise,
|
|
23
|
-
timestamp
|
|
24
|
-
};
|
|
25
|
-
blockTimePromise.catch(e => {
|
|
26
|
-
if (this.blockCache[blockTagStr] != null && this.blockCache[blockTagStr].blockTime === blockTimePromise)
|
|
27
|
-
delete this.blockCache[blockTagStr];
|
|
28
|
-
throw e;
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
blockTime: blockTimePromise,
|
|
32
|
-
timestamp
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
cleanupBlocks() {
|
|
36
|
-
const currentTime = Date.now();
|
|
37
|
-
//Keys are in order that they were added, so we can stop at the first non-expired block
|
|
38
|
-
for (let key in this.blockCache) {
|
|
39
|
-
const block = this.blockCache[key];
|
|
40
|
-
if (currentTime - block.timestamp > this.BLOCK_CACHE_TIME) {
|
|
41
|
-
delete this.blockCache[key];
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
///////////////////
|
|
49
|
-
//// Blocks
|
|
50
|
-
/**
|
|
51
|
-
* Gets the block for a given blocktag, with caching
|
|
52
|
-
*
|
|
53
|
-
* @param blockTag
|
|
54
|
-
*/
|
|
55
|
-
getBlockTime(blockTag) {
|
|
56
|
-
this.cleanupBlocks();
|
|
57
|
-
let cachedBlockData = this.blockCache[blockTag.toString(10)];
|
|
58
|
-
if (cachedBlockData == null || Date.now() - cachedBlockData.timestamp > this.BLOCK_CACHE_TIME) {
|
|
59
|
-
cachedBlockData = this.fetchAndSaveBlockTime(blockTag);
|
|
60
|
-
}
|
|
61
|
-
return cachedBlockData.blockTime;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.StarknetBlocks = StarknetBlocks;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetBlocks = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
class StarknetBlocks extends StarknetModule_1.StarknetModule {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.BLOCK_CACHE_TIME = 5 * 1000;
|
|
9
|
+
this.blockCache = {};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Initiates fetch of a given block & saves it to cache
|
|
13
|
+
*
|
|
14
|
+
* @private
|
|
15
|
+
* @param blockTag
|
|
16
|
+
*/
|
|
17
|
+
fetchAndSaveBlockTime(blockTag) {
|
|
18
|
+
const blockTagStr = blockTag.toString(10);
|
|
19
|
+
const blockTimePromise = this.provider.getBlockWithTxHashes(blockTag).then(result => result.timestamp);
|
|
20
|
+
const timestamp = Date.now();
|
|
21
|
+
this.blockCache[blockTagStr] = {
|
|
22
|
+
blockTime: blockTimePromise,
|
|
23
|
+
timestamp
|
|
24
|
+
};
|
|
25
|
+
blockTimePromise.catch(e => {
|
|
26
|
+
if (this.blockCache[blockTagStr] != null && this.blockCache[blockTagStr].blockTime === blockTimePromise)
|
|
27
|
+
delete this.blockCache[blockTagStr];
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
blockTime: blockTimePromise,
|
|
32
|
+
timestamp
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
cleanupBlocks() {
|
|
36
|
+
const currentTime = Date.now();
|
|
37
|
+
//Keys are in order that they were added, so we can stop at the first non-expired block
|
|
38
|
+
for (let key in this.blockCache) {
|
|
39
|
+
const block = this.blockCache[key];
|
|
40
|
+
if (currentTime - block.timestamp > this.BLOCK_CACHE_TIME) {
|
|
41
|
+
delete this.blockCache[key];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
///////////////////
|
|
49
|
+
//// Blocks
|
|
50
|
+
/**
|
|
51
|
+
* Gets the block for a given blocktag, with caching
|
|
52
|
+
*
|
|
53
|
+
* @param blockTag
|
|
54
|
+
*/
|
|
55
|
+
getBlockTime(blockTag) {
|
|
56
|
+
this.cleanupBlocks();
|
|
57
|
+
let cachedBlockData = this.blockCache[blockTag.toString(10)];
|
|
58
|
+
if (cachedBlockData == null || Date.now() - cachedBlockData.timestamp > this.BLOCK_CACHE_TIME) {
|
|
59
|
+
cachedBlockData = this.fetchAndSaveBlockTime(blockTag);
|
|
60
|
+
}
|
|
61
|
+
return cachedBlockData.blockTime;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.StarknetBlocks = StarknetBlocks;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { StarknetModule } from "../StarknetModule";
|
|
2
|
-
export type StarknetEvent = {
|
|
3
|
-
block_hash: string;
|
|
4
|
-
block_number: number;
|
|
5
|
-
transaction_hash: string;
|
|
6
|
-
from_address: string;
|
|
7
|
-
keys: string[];
|
|
8
|
-
data: string[];
|
|
9
|
-
};
|
|
10
|
-
export declare class StarknetEvents extends StarknetModule {
|
|
11
|
-
readonly EVENTS_LIMIT = 100;
|
|
12
|
-
readonly FORWARD_BLOCK_RANGE = 2000;
|
|
13
|
-
/**
|
|
14
|
-
* Returns the all the events occuring in a block range as identified by the contract and keys
|
|
15
|
-
*
|
|
16
|
-
* @param contract
|
|
17
|
-
* @param keys
|
|
18
|
-
* @param startBlock
|
|
19
|
-
* @param endBlock
|
|
20
|
-
* @param abortSignal
|
|
21
|
-
*/
|
|
22
|
-
getBlockEvents(contract: string, keys: string[][], startBlock?: number, endBlock?: number, abortSignal?: AbortSignal): Promise<StarknetEvent[]>;
|
|
23
|
-
/**
|
|
24
|
-
* Runs a search backwards in time, processing events from a specific contract and keys
|
|
25
|
-
*
|
|
26
|
-
* @param contract
|
|
27
|
-
* @param keys
|
|
28
|
-
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
29
|
-
* was found, or null if the search should continue
|
|
30
|
-
* @param abortSignal
|
|
31
|
-
*/
|
|
32
|
-
findInEvents<T>(contract: string, keys: string[][], processor: (signatures: StarknetEvent[]) => Promise<T>, abortSignal?: AbortSignal): Promise<T>;
|
|
33
|
-
/**
|
|
34
|
-
* Runs a search forwards in time, processing events from a specific contract and keys
|
|
35
|
-
*
|
|
36
|
-
* @param contract
|
|
37
|
-
* @param keys
|
|
38
|
-
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
39
|
-
* was found, or null if the search should continue
|
|
40
|
-
* @param abortSignal
|
|
41
|
-
* @param logFetchLimit
|
|
42
|
-
*/
|
|
43
|
-
findInEventsForward<T>(contract: string, keys: string[][], processor: (signatures: StarknetEvent[]) => Promise<T>, abortSignal?: AbortSignal, logFetchLimit?: number): Promise<T>;
|
|
44
|
-
}
|
|
1
|
+
import { StarknetModule } from "../StarknetModule";
|
|
2
|
+
export type StarknetEvent = {
|
|
3
|
+
block_hash: string;
|
|
4
|
+
block_number: number;
|
|
5
|
+
transaction_hash: string;
|
|
6
|
+
from_address: string;
|
|
7
|
+
keys: string[];
|
|
8
|
+
data: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare class StarknetEvents extends StarknetModule {
|
|
11
|
+
readonly EVENTS_LIMIT = 100;
|
|
12
|
+
readonly FORWARD_BLOCK_RANGE = 2000;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the all the events occuring in a block range as identified by the contract and keys
|
|
15
|
+
*
|
|
16
|
+
* @param contract
|
|
17
|
+
* @param keys
|
|
18
|
+
* @param startBlock
|
|
19
|
+
* @param endBlock
|
|
20
|
+
* @param abortSignal
|
|
21
|
+
*/
|
|
22
|
+
getBlockEvents(contract: string, keys: string[][], startBlock?: number, endBlock?: number, abortSignal?: AbortSignal): Promise<StarknetEvent[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Runs a search backwards in time, processing events from a specific contract and keys
|
|
25
|
+
*
|
|
26
|
+
* @param contract
|
|
27
|
+
* @param keys
|
|
28
|
+
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
29
|
+
* was found, or null if the search should continue
|
|
30
|
+
* @param abortSignal
|
|
31
|
+
*/
|
|
32
|
+
findInEvents<T>(contract: string, keys: string[][], processor: (signatures: StarknetEvent[]) => Promise<T>, abortSignal?: AbortSignal): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Runs a search forwards in time, processing events from a specific contract and keys
|
|
35
|
+
*
|
|
36
|
+
* @param contract
|
|
37
|
+
* @param keys
|
|
38
|
+
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
39
|
+
* was found, or null if the search should continue
|
|
40
|
+
* @param abortSignal
|
|
41
|
+
* @param logFetchLimit
|
|
42
|
+
*/
|
|
43
|
+
findInEventsForward<T>(contract: string, keys: string[][], processor: (signatures: StarknetEvent[]) => Promise<T>, abortSignal?: AbortSignal, logFetchLimit?: number): Promise<T>;
|
|
44
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StarknetEvents = void 0;
|
|
4
|
-
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
-
class StarknetEvents extends StarknetModule_1.StarknetModule {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.EVENTS_LIMIT = 100;
|
|
9
|
-
this.FORWARD_BLOCK_RANGE = 2000;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the all the events occuring in a block range as identified by the contract and keys
|
|
13
|
-
*
|
|
14
|
-
* @param contract
|
|
15
|
-
* @param keys
|
|
16
|
-
* @param startBlock
|
|
17
|
-
* @param endBlock
|
|
18
|
-
* @param abortSignal
|
|
19
|
-
*/
|
|
20
|
-
async getBlockEvents(contract, keys, startBlock, endBlock = startBlock, abortSignal) {
|
|
21
|
-
const events = [];
|
|
22
|
-
let result = null;
|
|
23
|
-
while (result == null || result?.continuation_token != null) {
|
|
24
|
-
result = await this.root.provider.getEvents({
|
|
25
|
-
address: contract,
|
|
26
|
-
from_block: startBlock == null ? "
|
|
27
|
-
to_block: endBlock == null ? "
|
|
28
|
-
keys,
|
|
29
|
-
chunk_size: this.EVENTS_LIMIT,
|
|
30
|
-
continuation_token: result?.continuation_token
|
|
31
|
-
});
|
|
32
|
-
if (abortSignal != null)
|
|
33
|
-
abortSignal.throwIfAborted();
|
|
34
|
-
events.push(...result.events);
|
|
35
|
-
}
|
|
36
|
-
return events;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Runs a search backwards in time, processing events from a specific contract and keys
|
|
40
|
-
*
|
|
41
|
-
* @param contract
|
|
42
|
-
* @param keys
|
|
43
|
-
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
44
|
-
* was found, or null if the search should continue
|
|
45
|
-
* @param abortSignal
|
|
46
|
-
*/
|
|
47
|
-
async findInEvents(contract, keys, processor, abortSignal) {
|
|
48
|
-
const latestBlockNumber = await this.provider.getBlockNumber();
|
|
49
|
-
for (let blockNumber = latestBlockNumber; blockNumber >= 0; blockNumber -= this.FORWARD_BLOCK_RANGE) {
|
|
50
|
-
const eventsResult = await this.getBlockEvents(contract, keys, Math.max(blockNumber - this.FORWARD_BLOCK_RANGE, 0), blockNumber === latestBlockNumber ? null : blockNumber, abortSignal);
|
|
51
|
-
const result = await processor(eventsResult.reverse());
|
|
52
|
-
if (result != null)
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Runs a search forwards in time, processing events from a specific contract and keys
|
|
59
|
-
*
|
|
60
|
-
* @param contract
|
|
61
|
-
* @param keys
|
|
62
|
-
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
63
|
-
* was found, or null if the search should continue
|
|
64
|
-
* @param abortSignal
|
|
65
|
-
* @param logFetchLimit
|
|
66
|
-
*/
|
|
67
|
-
async findInEventsForward(contract, keys, processor, abortSignal, logFetchLimit) {
|
|
68
|
-
if (logFetchLimit == null || logFetchLimit > this.EVENTS_LIMIT)
|
|
69
|
-
logFetchLimit = this.EVENTS_LIMIT;
|
|
70
|
-
let eventsResult = null;
|
|
71
|
-
while (eventsResult == null || eventsResult?.continuation_token != null) {
|
|
72
|
-
eventsResult = await this.root.provider.getEvents({
|
|
73
|
-
address: contract,
|
|
74
|
-
to_block: "latest",
|
|
75
|
-
keys,
|
|
76
|
-
chunk_size: logFetchLimit ?? this.EVENTS_LIMIT,
|
|
77
|
-
continuation_token: eventsResult?.continuation_token
|
|
78
|
-
});
|
|
79
|
-
if (abortSignal != null)
|
|
80
|
-
abortSignal.throwIfAborted();
|
|
81
|
-
const result = await processor(eventsResult.events);
|
|
82
|
-
if (result != null)
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.StarknetEvents = StarknetEvents;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StarknetEvents = void 0;
|
|
4
|
+
const StarknetModule_1 = require("../StarknetModule");
|
|
5
|
+
class StarknetEvents extends StarknetModule_1.StarknetModule {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.EVENTS_LIMIT = 100;
|
|
9
|
+
this.FORWARD_BLOCK_RANGE = 2000;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns the all the events occuring in a block range as identified by the contract and keys
|
|
13
|
+
*
|
|
14
|
+
* @param contract
|
|
15
|
+
* @param keys
|
|
16
|
+
* @param startBlock
|
|
17
|
+
* @param endBlock
|
|
18
|
+
* @param abortSignal
|
|
19
|
+
*/
|
|
20
|
+
async getBlockEvents(contract, keys, startBlock, endBlock = startBlock, abortSignal) {
|
|
21
|
+
const events = [];
|
|
22
|
+
let result = null;
|
|
23
|
+
while (result == null || result?.continuation_token != null) {
|
|
24
|
+
result = await this.root.provider.getEvents({
|
|
25
|
+
address: contract,
|
|
26
|
+
from_block: startBlock == null ? "latest" : { block_number: startBlock },
|
|
27
|
+
to_block: endBlock == null ? "latest" : { block_number: endBlock },
|
|
28
|
+
keys,
|
|
29
|
+
chunk_size: this.EVENTS_LIMIT,
|
|
30
|
+
continuation_token: result?.continuation_token
|
|
31
|
+
});
|
|
32
|
+
if (abortSignal != null)
|
|
33
|
+
abortSignal.throwIfAborted();
|
|
34
|
+
events.push(...result.events);
|
|
35
|
+
}
|
|
36
|
+
return events;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Runs a search backwards in time, processing events from a specific contract and keys
|
|
40
|
+
*
|
|
41
|
+
* @param contract
|
|
42
|
+
* @param keys
|
|
43
|
+
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
44
|
+
* was found, or null if the search should continue
|
|
45
|
+
* @param abortSignal
|
|
46
|
+
*/
|
|
47
|
+
async findInEvents(contract, keys, processor, abortSignal) {
|
|
48
|
+
const latestBlockNumber = await this.provider.getBlockNumber();
|
|
49
|
+
for (let blockNumber = latestBlockNumber; blockNumber >= 0; blockNumber -= this.FORWARD_BLOCK_RANGE) {
|
|
50
|
+
const eventsResult = await this.getBlockEvents(contract, keys, Math.max(blockNumber - this.FORWARD_BLOCK_RANGE, 0), blockNumber === latestBlockNumber ? null : blockNumber, abortSignal);
|
|
51
|
+
const result = await processor(eventsResult.reverse());
|
|
52
|
+
if (result != null)
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Runs a search forwards in time, processing events from a specific contract and keys
|
|
59
|
+
*
|
|
60
|
+
* @param contract
|
|
61
|
+
* @param keys
|
|
62
|
+
* @param processor called for every batch of returned signatures, should return a value if the correct signature
|
|
63
|
+
* was found, or null if the search should continue
|
|
64
|
+
* @param abortSignal
|
|
65
|
+
* @param logFetchLimit
|
|
66
|
+
*/
|
|
67
|
+
async findInEventsForward(contract, keys, processor, abortSignal, logFetchLimit) {
|
|
68
|
+
if (logFetchLimit == null || logFetchLimit > this.EVENTS_LIMIT)
|
|
69
|
+
logFetchLimit = this.EVENTS_LIMIT;
|
|
70
|
+
let eventsResult = null;
|
|
71
|
+
while (eventsResult == null || eventsResult?.continuation_token != null) {
|
|
72
|
+
eventsResult = await this.root.provider.getEvents({
|
|
73
|
+
address: contract,
|
|
74
|
+
to_block: "latest",
|
|
75
|
+
keys,
|
|
76
|
+
chunk_size: logFetchLimit ?? this.EVENTS_LIMIT,
|
|
77
|
+
continuation_token: eventsResult?.continuation_token
|
|
78
|
+
});
|
|
79
|
+
if (abortSignal != null)
|
|
80
|
+
abortSignal.throwIfAborted();
|
|
81
|
+
const result = await processor(eventsResult.events);
|
|
82
|
+
if (result != null)
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.StarknetEvents = StarknetEvents;
|