moonwall 1.0.0-dev.0
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 +681 -0
- package/README.md +54 -0
- package/config_schema.json +811 -0
- package/dist/api/constants/accounts.d.ts +36 -0
- package/dist/api/constants/accounts.d.ts.map +1 -0
- package/dist/api/constants/accounts.js +67 -0
- package/dist/api/constants/chain.d.ts +134 -0
- package/dist/api/constants/chain.d.ts.map +1 -0
- package/dist/api/constants/chain.js +149 -0
- package/dist/api/constants/index.d.ts +4 -0
- package/dist/api/constants/index.d.ts.map +1 -0
- package/dist/api/constants/index.js +3 -0
- package/dist/api/constants/smartContract.d.ts +29 -0
- package/dist/api/constants/smartContract.d.ts.map +1 -0
- package/dist/api/constants/smartContract.js +118 -0
- package/dist/api/testing/blocks.d.ts +59 -0
- package/dist/api/testing/blocks.d.ts.map +1 -0
- package/dist/api/testing/blocks.js +147 -0
- package/dist/api/testing/contracts.d.ts +5 -0
- package/dist/api/testing/contracts.d.ts.map +1 -0
- package/dist/api/testing/contracts.js +32 -0
- package/dist/api/testing/ethers.d.ts +3 -0
- package/dist/api/testing/ethers.d.ts.map +1 -0
- package/dist/api/testing/ethers.js +38 -0
- package/dist/api/testing/events.d.ts +12 -0
- package/dist/api/testing/events.d.ts.map +1 -0
- package/dist/api/testing/events.js +23 -0
- package/dist/api/testing/extrinsics.d.ts +5 -0
- package/dist/api/testing/extrinsics.d.ts.map +1 -0
- package/dist/api/testing/extrinsics.js +10 -0
- package/dist/api/testing/index.d.ts +9 -0
- package/dist/api/testing/index.d.ts.map +1 -0
- package/dist/api/testing/index.js +8 -0
- package/dist/api/testing/jumping.d.ts +8 -0
- package/dist/api/testing/jumping.d.ts.map +1 -0
- package/dist/api/testing/jumping.js +78 -0
- package/dist/api/testing/providers.d.ts +18 -0
- package/dist/api/testing/providers.d.ts.map +1 -0
- package/dist/api/testing/providers.js +34 -0
- package/dist/api/testing/viem.d.ts +139 -0
- package/dist/api/testing/viem.d.ts.map +1 -0
- package/dist/api/testing/viem.js +247 -0
- package/dist/api/types/config.d.ts +609 -0
- package/dist/api/types/config.d.ts.map +1 -0
- package/dist/api/types/config.js +1 -0
- package/dist/api/types/context.d.ts +125 -0
- package/dist/api/types/context.d.ts.map +1 -0
- package/dist/api/types/context.js +1 -0
- package/dist/api/types/contracts.d.ts +66 -0
- package/dist/api/types/contracts.d.ts.map +1 -0
- package/dist/api/types/contracts.js +1 -0
- package/dist/api/types/eth.d.ts +3 -0
- package/dist/api/types/eth.d.ts.map +1 -0
- package/dist/api/types/eth.js +1 -0
- package/dist/api/types/foundations.d.ts +11 -0
- package/dist/api/types/foundations.d.ts.map +1 -0
- package/dist/api/types/foundations.js +1 -0
- package/dist/api/types/helpers.d.ts +7 -0
- package/dist/api/types/helpers.d.ts.map +1 -0
- package/dist/api/types/helpers.js +1 -0
- package/dist/api/types/index.d.ts +8 -0
- package/dist/api/types/index.d.ts.map +1 -0
- package/dist/api/types/index.js +7 -0
- package/dist/api/types/runner.d.ts +490 -0
- package/dist/api/types/runner.d.ts.map +1 -0
- package/dist/api/types/runner.js +1 -0
- package/dist/cli/cmds/components/LogViewer.d.ts +17 -0
- package/dist/cli/cmds/components/LogViewer.d.ts.map +1 -0
- package/dist/cli/cmds/components/LogViewer.js +171 -0
- package/dist/cli/cmds/entrypoint.d.ts +6 -0
- package/dist/cli/cmds/entrypoint.d.ts.map +1 -0
- package/dist/cli/cmds/entrypoint.js +192 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.js +117 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.js +103 -0
- package/dist/cli/cmds/interactiveCmds/index.d.ts +4 -0
- package/dist/cli/cmds/interactiveCmds/index.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/index.js +3 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.js +32 -0
- package/dist/cli/cmds/main.d.ts +2 -0
- package/dist/cli/cmds/main.d.ts.map +1 -0
- package/dist/cli/cmds/main.js +336 -0
- package/dist/cli/cmds/runNetwork.d.ts +3 -0
- package/dist/cli/cmds/runNetwork.d.ts.map +1 -0
- package/dist/cli/cmds/runNetwork.js +292 -0
- package/dist/cli/cmds/runTests.d.ts +12 -0
- package/dist/cli/cmds/runTests.d.ts.map +1 -0
- package/dist/cli/cmds/runTests.js +257 -0
- package/dist/cli/internal/cmdFunctions/downloader.d.ts +4 -0
- package/dist/cli/internal/cmdFunctions/downloader.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/downloader.js +49 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts +10 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.js +145 -0
- package/dist/cli/internal/cmdFunctions/index.d.ts +5 -0
- package/dist/cli/internal/cmdFunctions/index.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/index.js +4 -0
- package/dist/cli/internal/cmdFunctions/initialisation.d.ts +20 -0
- package/dist/cli/internal/cmdFunctions/initialisation.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/initialisation.js +150 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.d.ts +3 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.js +37 -0
- package/dist/cli/internal/commandParsers.d.ts +59 -0
- package/dist/cli/internal/commandParsers.d.ts.map +1 -0
- package/dist/cli/internal/commandParsers.js +305 -0
- package/dist/cli/internal/deriveTestIds.d.ts +8 -0
- package/dist/cli/internal/deriveTestIds.d.ts.map +1 -0
- package/dist/cli/internal/deriveTestIds.js +123 -0
- package/dist/cli/internal/effect/index.d.ts +6 -0
- package/dist/cli/internal/effect/index.d.ts.map +1 -0
- package/dist/cli/internal/effect/index.js +5 -0
- package/dist/cli/internal/fileCheckers.d.ts +11 -0
- package/dist/cli/internal/fileCheckers.d.ts.map +1 -0
- package/dist/cli/internal/fileCheckers.js +165 -0
- package/dist/cli/internal/foundations/index.d.ts +4 -0
- package/dist/cli/internal/foundations/index.d.ts.map +1 -0
- package/dist/cli/internal/foundations/index.js +4 -0
- package/dist/cli/internal/index.d.ts +12 -0
- package/dist/cli/internal/index.d.ts.map +1 -0
- package/dist/cli/internal/index.js +11 -0
- package/dist/cli/internal/launcherCommon.d.ts +4 -0
- package/dist/cli/internal/launcherCommon.d.ts.map +1 -0
- package/dist/cli/internal/launcherCommon.js +130 -0
- package/dist/cli/internal/localNode.d.ts +16 -0
- package/dist/cli/internal/localNode.d.ts.map +1 -0
- package/dist/cli/internal/localNode.js +362 -0
- package/dist/cli/internal/logging.d.ts +2 -0
- package/dist/cli/internal/logging.d.ts.map +1 -0
- package/dist/cli/internal/logging.js +26 -0
- package/dist/cli/internal/node.d.ts +33 -0
- package/dist/cli/internal/node.d.ts.map +1 -0
- package/dist/cli/internal/node.js +228 -0
- package/dist/cli/internal/processHelpers.d.ts +17 -0
- package/dist/cli/internal/processHelpers.d.ts.map +1 -0
- package/dist/cli/internal/processHelpers.js +56 -0
- package/dist/cli/internal/providerFactories.d.ts +48 -0
- package/dist/cli/internal/providerFactories.d.ts.map +1 -0
- package/dist/cli/internal/providerFactories.js +442 -0
- package/dist/cli/internal/testIdParser.d.ts +34 -0
- package/dist/cli/internal/testIdParser.d.ts.map +1 -0
- package/dist/cli/internal/testIdParser.js +167 -0
- package/dist/cli/lib/binariesHelpers.d.ts +15 -0
- package/dist/cli/lib/binariesHelpers.d.ts.map +1 -0
- package/dist/cli/lib/binariesHelpers.js +99 -0
- package/dist/cli/lib/configReader.d.ts +8 -0
- package/dist/cli/lib/configReader.d.ts.map +1 -0
- package/dist/cli/lib/configReader.js +115 -0
- package/dist/cli/lib/contractFunctions.d.ts +2 -0
- package/dist/cli/lib/contractFunctions.d.ts.map +1 -0
- package/dist/cli/lib/contractFunctions.js +2 -0
- package/dist/cli/lib/globalContext.d.ts +46 -0
- package/dist/cli/lib/globalContext.d.ts.map +1 -0
- package/dist/cli/lib/globalContext.js +710 -0
- package/dist/cli/lib/governanceProcedures.d.ts +27 -0
- package/dist/cli/lib/governanceProcedures.d.ts.map +1 -0
- package/dist/cli/lib/governanceProcedures.js +458 -0
- package/dist/cli/lib/handlers/index.d.ts +5 -0
- package/dist/cli/lib/handlers/index.d.ts.map +1 -0
- package/dist/cli/lib/handlers/index.js +5 -0
- package/dist/cli/lib/repoDefinitions/index.d.ts +6 -0
- package/dist/cli/lib/repoDefinitions/index.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/index.js +21 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.js +30 -0
- package/dist/cli/lib/repoDefinitions/polkadot.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/polkadot.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/polkadot.js +11 -0
- package/dist/cli/lib/repoDefinitions/tanssi.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/tanssi.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/tanssi.js +14 -0
- package/dist/cli/lib/rpcFunctions.d.ts +2 -0
- package/dist/cli/lib/rpcFunctions.d.ts.map +1 -0
- package/dist/cli/lib/rpcFunctions.js +26 -0
- package/dist/cli/lib/runnerContext.d.ts +32 -0
- package/dist/cli/lib/runnerContext.d.ts.map +1 -0
- package/dist/cli/lib/runnerContext.js +156 -0
- package/dist/cli/lib/shardManager.d.ts +40 -0
- package/dist/cli/lib/shardManager.d.ts.map +1 -0
- package/dist/cli/lib/shardManager.js +80 -0
- package/dist/cli/lib/upgradeProcedures.d.ts +5 -0
- package/dist/cli/lib/upgradeProcedures.d.ts.map +1 -0
- package/dist/cli/lib/upgradeProcedures.js +221 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/contracts/contractInteraction.d.ts +17 -0
- package/dist/contracts/contractInteraction.d.ts.map +1 -0
- package/dist/contracts/contractInteraction.js +170 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/foundations/chopsticks/handler.d.ts +3 -0
- package/dist/foundations/chopsticks/handler.d.ts.map +1 -0
- package/dist/foundations/chopsticks/handler.js +93 -0
- package/dist/foundations/chopsticks/helpers.d.ts +27 -0
- package/dist/foundations/chopsticks/helpers.d.ts.map +1 -0
- package/dist/foundations/chopsticks/helpers.js +133 -0
- package/dist/foundations/dev/handler.d.ts +3 -0
- package/dist/foundations/dev/handler.d.ts.map +1 -0
- package/dist/foundations/dev/handler.js +136 -0
- package/dist/foundations/dev/helpers.d.ts +27 -0
- package/dist/foundations/dev/helpers.d.ts.map +1 -0
- package/dist/foundations/dev/helpers.js +161 -0
- package/dist/foundations/read-only/handler.d.ts +3 -0
- package/dist/foundations/read-only/handler.d.ts.map +1 -0
- package/dist/foundations/read-only/handler.js +32 -0
- package/dist/foundations/zombie/handler.d.ts +3 -0
- package/dist/foundations/zombie/handler.d.ts.map +1 -0
- package/dist/foundations/zombie/handler.js +92 -0
- package/dist/foundations/zombie/helpers.d.ts +16 -0
- package/dist/foundations/zombie/helpers.d.ts.map +1 -0
- package/dist/foundations/zombie/helpers.js +97 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/internal/common.d.ts +3 -0
- package/dist/internal/common.d.ts.map +1 -0
- package/dist/internal/common.js +41 -0
- package/dist/internal/index.d.ts +4 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +3 -0
- package/dist/internal/logger.d.ts +24 -0
- package/dist/internal/logger.d.ts.map +1 -0
- package/dist/internal/logger.js +66 -0
- package/dist/internal/logging.d.ts +7 -0
- package/dist/internal/logging.d.ts.map +1 -0
- package/dist/internal/logging.js +36 -0
- package/dist/moondebug.d.ts +3 -0
- package/dist/moondebug.d.ts.map +1 -0
- package/dist/moondebug.js +2 -0
- package/dist/services/cache/FileLock.d.ts +11 -0
- package/dist/services/cache/FileLock.d.ts.map +1 -0
- package/dist/services/cache/FileLock.js +68 -0
- package/dist/services/cache/StartupCacheService.d.ts +23 -0
- package/dist/services/cache/StartupCacheService.d.ts.map +1 -0
- package/dist/services/cache/StartupCacheService.js +159 -0
- package/dist/services/cache/index.d.ts +3 -0
- package/dist/services/cache/index.d.ts.map +1 -0
- package/dist/services/cache/index.js +2 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.d.ts +158 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.d.ts.map +1 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.js +282 -0
- package/dist/services/chopsticks/ChopsticksService.d.ts +313 -0
- package/dist/services/chopsticks/ChopsticksService.d.ts.map +1 -0
- package/dist/services/chopsticks/ChopsticksService.js +77 -0
- package/dist/services/chopsticks/chopsticksConfigParser.d.ts +40 -0
- package/dist/services/chopsticks/chopsticksConfigParser.d.ts.map +1 -0
- package/dist/services/chopsticks/chopsticksConfigParser.js +201 -0
- package/dist/services/chopsticks/index.d.ts +5 -0
- package/dist/services/chopsticks/index.d.ts.map +1 -0
- package/dist/services/chopsticks/index.js +4 -0
- package/dist/services/chopsticks/launchChopsticksEffect.d.ts +225 -0
- package/dist/services/chopsticks/launchChopsticksEffect.d.ts.map +1 -0
- package/dist/services/chopsticks/launchChopsticksEffect.js +623 -0
- package/dist/services/config/configAccessors.d.ts +41 -0
- package/dist/services/config/configAccessors.d.ts.map +1 -0
- package/dist/services/config/configAccessors.js +149 -0
- package/dist/services/config/index.d.ts +2 -0
- package/dist/services/config/index.d.ts.map +1 -0
- package/dist/services/config/index.js +1 -0
- package/dist/services/errors.d.ts +72 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +31 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +6 -0
- package/dist/services/network/NodeReadinessService.d.ts +35 -0
- package/dist/services/network/NodeReadinessService.d.ts.map +1 -0
- package/dist/services/network/NodeReadinessService.js +120 -0
- package/dist/services/network/PortDiscoveryService.d.ts +22 -0
- package/dist/services/network/PortDiscoveryService.d.ts.map +1 -0
- package/dist/services/network/PortDiscoveryService.js +77 -0
- package/dist/services/network/RpcPortDiscoveryService.d.ts +25 -0
- package/dist/services/network/RpcPortDiscoveryService.d.ts.map +1 -0
- package/dist/services/network/RpcPortDiscoveryService.js +136 -0
- package/dist/services/network/index.d.ts +4 -0
- package/dist/services/network/index.d.ts.map +1 -0
- package/dist/services/network/index.js +3 -0
- package/dist/services/process/ProcessManagerService.d.ts +49 -0
- package/dist/services/process/ProcessManagerService.d.ts.map +1 -0
- package/dist/services/process/ProcessManagerService.js +162 -0
- package/dist/services/process/index.d.ts +3 -0
- package/dist/services/process/index.d.ts.map +1 -0
- package/dist/services/process/index.js +2 -0
- package/dist/services/process/launchNodeEffect.d.ts +40 -0
- package/dist/services/process/launchNodeEffect.d.ts.map +1 -0
- package/dist/services/process/launchNodeEffect.js +86 -0
- package/dist/util/functions/index.d.ts +3 -0
- package/dist/util/functions/index.d.ts.map +1 -0
- package/dist/util/functions/index.js +4 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +2 -0
- package/package.json +157 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { createWalletClient, hexToNumber, http, } from "viem";
|
|
2
|
+
import { setTimeout as timer } from "node:timers/promises";
|
|
3
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
4
|
+
import { ALITH_ADDRESS, ALITH_PRIVATE_KEY } from "../constants/accounts.js";
|
|
5
|
+
import { normalizeUrlToHttps, directRpcRequest } from "../../internal/common.js";
|
|
6
|
+
/**
|
|
7
|
+
* @name getDevChain
|
|
8
|
+
* @description This function returns a development chain object for Moonbeam.
|
|
9
|
+
* @param url - The WebSocket URL of the development chain.
|
|
10
|
+
*
|
|
11
|
+
* @returns Returns an object that represents the Moonbeam development chain.
|
|
12
|
+
* The object includes properties such as the chain's ID, name, network, native currency, and RPC URLs.
|
|
13
|
+
*
|
|
14
|
+
* @property id - The ID of the development chain. For Moonbeam Dev, this is 1281.
|
|
15
|
+
* @property name - The name of the development chain. For this function, it's "Moonbeam Dev".
|
|
16
|
+
* @property network - The network name of the development chain. For this function, it's "moonbeam".
|
|
17
|
+
* @property nativeCurrency - An object containing the native currency's details:
|
|
18
|
+
* - decimals: The number of decimal places the native currency supports.
|
|
19
|
+
* - name: The name of the native currency. For Moonbeam Dev, it's "Glimmer".
|
|
20
|
+
* - symbol: The symbol of the native currency. For Moonbeam Dev, it's "GLMR".
|
|
21
|
+
* @property rpcUrls - An object that includes the RPC URLs for the chain:
|
|
22
|
+
* - public: The public HTTP URL(s) for the chain.
|
|
23
|
+
* - default: The default HTTP URL(s) for the chain.
|
|
24
|
+
*/
|
|
25
|
+
export async function getDevChain(url) {
|
|
26
|
+
const httpUrl = normalizeUrlToHttps(url);
|
|
27
|
+
const block = { http: [httpUrl] };
|
|
28
|
+
return {
|
|
29
|
+
id: 1281,
|
|
30
|
+
name: "Moonbeam Dev",
|
|
31
|
+
nativeCurrency: {
|
|
32
|
+
decimals: 18,
|
|
33
|
+
name: "Glimmer",
|
|
34
|
+
symbol: "GLMR",
|
|
35
|
+
},
|
|
36
|
+
rpcUrls: {
|
|
37
|
+
public: block,
|
|
38
|
+
default: block,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Derives a Viem chain object from a given HTTP endpoint.
|
|
44
|
+
*
|
|
45
|
+
* @export
|
|
46
|
+
* @param endpoint The endpoint for the JSON RPC requests.
|
|
47
|
+
* @param maxRetries Maximum number of retry attempts (default: 3)
|
|
48
|
+
* @returns A promise that resolves to an object satisfying the Chain interface, which includes
|
|
49
|
+
* properties such as the chain id, chain name, network name, native currency information,
|
|
50
|
+
* and RPC URLs.
|
|
51
|
+
* @throws Will throw an error if the RPC request fails after all retries.
|
|
52
|
+
* @example
|
|
53
|
+
* const chain = await deriveViemChain('http://localhost:8545');
|
|
54
|
+
*/
|
|
55
|
+
export async function deriveViemChain(endpoint, maxRetries = 3) {
|
|
56
|
+
const httpEndpoint = normalizeUrlToHttps(endpoint);
|
|
57
|
+
const block = { http: [httpEndpoint] };
|
|
58
|
+
let lastError;
|
|
59
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
60
|
+
try {
|
|
61
|
+
const id = hexToNumber(await directRpcRequest(httpEndpoint, "eth_chainId", []));
|
|
62
|
+
const name = await directRpcRequest(httpEndpoint, "system_chain", []);
|
|
63
|
+
const { tokenSymbol, tokenDecimals } = await directRpcRequest(httpEndpoint, "system_properties", []);
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
name,
|
|
67
|
+
nativeCurrency: {
|
|
68
|
+
decimals: tokenDecimals,
|
|
69
|
+
name: tokenSymbol,
|
|
70
|
+
symbol: tokenSymbol,
|
|
71
|
+
},
|
|
72
|
+
rpcUrls: {
|
|
73
|
+
public: block,
|
|
74
|
+
default: block,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
lastError = error;
|
|
80
|
+
if (attempt < maxRetries) {
|
|
81
|
+
console.warn(`Failed to derive viem chain on attempt ${attempt}/${maxRetries} from ${httpEndpoint}: ${error.message}. Retrying...`);
|
|
82
|
+
await timer(1000 * attempt); // Linear backoff
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`Failed to derive viem chain after ${maxRetries} attempts from ${httpEndpoint}: ${lastError?.message || "Unknown error"}`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @name deployViemContract
|
|
90
|
+
* @description This function deploys a contract to the Moonbeam development chain.
|
|
91
|
+
* @param context - The DevModeContext object.
|
|
92
|
+
* @param abi - The Application Binary Interface (ABI) of the contract.
|
|
93
|
+
* @param bytecode - The compiled bytecode of the contract.
|
|
94
|
+
* @param privateKey - The private key used for the deployment transaction (defaults to ALITH_PRIVATE_KEY).
|
|
95
|
+
*
|
|
96
|
+
* @returns Returns an object containing the deployed contract's address, the transaction status, and any logs.
|
|
97
|
+
*
|
|
98
|
+
* @throws This function will throw an error if the contract deployment fails.
|
|
99
|
+
*
|
|
100
|
+
* @async This function returns a Promise that resolves when the contract has been successfully deployed.
|
|
101
|
+
*
|
|
102
|
+
* @property contractAddress - The address of the deployed contract.
|
|
103
|
+
* @property status - The status of the contract deployment transaction.
|
|
104
|
+
* @property logs - Any logs produced during the contract deployment transaction.
|
|
105
|
+
*/
|
|
106
|
+
export async function deployViemContract(
|
|
107
|
+
// TODO: Make this generic
|
|
108
|
+
context, abi, bytecode, options) {
|
|
109
|
+
const url = context.viem().transport.url;
|
|
110
|
+
const { privateKey = ALITH_PRIVATE_KEY, ...rest } = options || {};
|
|
111
|
+
const blob = {
|
|
112
|
+
...rest,
|
|
113
|
+
abi,
|
|
114
|
+
bytecode,
|
|
115
|
+
account: privateKeyToAccount(privateKey),
|
|
116
|
+
};
|
|
117
|
+
const account = privateKeyToAccount(ALITH_PRIVATE_KEY);
|
|
118
|
+
const client = createWalletClient({
|
|
119
|
+
transport: http(url),
|
|
120
|
+
account,
|
|
121
|
+
chain: await deriveViemChain(url),
|
|
122
|
+
});
|
|
123
|
+
const hash = await client.deployContract(blob);
|
|
124
|
+
await context.createBlock();
|
|
125
|
+
for (let i = 0; i < 5; i++) {
|
|
126
|
+
try {
|
|
127
|
+
const { contractAddress, status, logs } = await context
|
|
128
|
+
.viem()
|
|
129
|
+
.getTransactionReceipt({ hash });
|
|
130
|
+
return { contractAddress, status, logs, hash };
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
console.log(e.message);
|
|
134
|
+
console.log("Contract deployment query, retrying...");
|
|
135
|
+
await timer(100);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Contract deployment query failed after 5 retries");
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* createRawTransfer function creates and signs a transfer, as a hex string, that can be submitted to the network via public client."
|
|
142
|
+
*
|
|
143
|
+
* @export
|
|
144
|
+
* @template TOptions - Optional parameters of Viem's TransferOptions
|
|
145
|
+
* @param {DevModeContext} context - the DevModeContext instance
|
|
146
|
+
* @param {`0x${string}`} to - the destination address of the transfer
|
|
147
|
+
* @param {InputAmountFormats} value - the amount to transfer. It accepts different formats including number, bigint, string or hexadecimal strings
|
|
148
|
+
* @param {TOptions} [options] - (optional) additional transaction options
|
|
149
|
+
* @returns {Promise<`0x${string}`>} - the signed raw transaction in hexadecimal string format
|
|
150
|
+
*/
|
|
151
|
+
export async function createRawTransfer(context, to, value, options) {
|
|
152
|
+
const transferAmount = typeof value === "bigint" ? value : BigInt(value);
|
|
153
|
+
return await createViemTransaction(context, {
|
|
154
|
+
...options,
|
|
155
|
+
to: to,
|
|
156
|
+
value: transferAmount,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* createViemTransaction function creates and signs a raw transaction, as a hex string, that can be submitted to the network via public client."
|
|
161
|
+
*
|
|
162
|
+
* @export
|
|
163
|
+
* @template TOptions - Optional parameters of Viem's TransactionOptions
|
|
164
|
+
* @param {GenericContext} context - the GenericContext instance
|
|
165
|
+
* @param {TOptions} options - transaction options including type, privateKey, value, to, chainId, gasPrice, estimatedGas, accessList, data
|
|
166
|
+
* @returns {Promise<string>} - the signed raw transaction in hexadecimal string format
|
|
167
|
+
*/
|
|
168
|
+
export async function createViemTransaction(context, options) {
|
|
169
|
+
const type = !!options && !!options.txnType ? options.txnType : "eip1559";
|
|
170
|
+
const privateKey = !!options && !!options.privateKey ? options.privateKey : ALITH_PRIVATE_KEY;
|
|
171
|
+
const account = privateKeyToAccount(privateKey);
|
|
172
|
+
const value = options?.value ? options.value : 0n;
|
|
173
|
+
const to = options?.to ? options.to : "0x0000000000000000000000000000000000000000";
|
|
174
|
+
const chainId = await context.viem().getChainId();
|
|
175
|
+
const txnCount = await context.viem().getTransactionCount({ address: account.address });
|
|
176
|
+
const gasPrice = await context.viem().getGasPrice();
|
|
177
|
+
const data = options?.data ? options.data : "0x";
|
|
178
|
+
const estimatedGas = options.skipEstimation || options.gas !== undefined
|
|
179
|
+
? 1500000n
|
|
180
|
+
: await context.viem().estimateGas({ account: account.address, to, value, data });
|
|
181
|
+
const accessList = options?.accessList ? options.accessList : [];
|
|
182
|
+
const txnBlob = type === "eip1559"
|
|
183
|
+
? {
|
|
184
|
+
to,
|
|
185
|
+
value,
|
|
186
|
+
maxFeePerGas: options.maxFeePerGas !== undefined ? options.maxFeePerGas : gasPrice,
|
|
187
|
+
maxPriorityFeePerGas: options.maxPriorityFeePerGas !== undefined ? options.maxPriorityFeePerGas : gasPrice,
|
|
188
|
+
gas: options.gas !== undefined ? options.gas : estimatedGas,
|
|
189
|
+
nonce: options.nonce !== undefined ? options.nonce : txnCount,
|
|
190
|
+
data,
|
|
191
|
+
chainId,
|
|
192
|
+
type,
|
|
193
|
+
}
|
|
194
|
+
: type === "legacy"
|
|
195
|
+
? {
|
|
196
|
+
to,
|
|
197
|
+
value,
|
|
198
|
+
gasPrice: options.gasPrice !== undefined ? options.gasPrice : gasPrice,
|
|
199
|
+
gas: options.gas !== undefined ? options.gas : estimatedGas,
|
|
200
|
+
nonce: options.nonce !== undefined ? options.nonce : txnCount,
|
|
201
|
+
data,
|
|
202
|
+
}
|
|
203
|
+
: type === "eip2930"
|
|
204
|
+
? {
|
|
205
|
+
to,
|
|
206
|
+
value,
|
|
207
|
+
gasPrice: options.gasPrice !== undefined ? options.gasPrice : gasPrice,
|
|
208
|
+
gas: options.gas !== undefined ? options.gas : estimatedGas,
|
|
209
|
+
nonce: options.nonce !== undefined ? options.nonce : txnCount,
|
|
210
|
+
data,
|
|
211
|
+
chainId,
|
|
212
|
+
type,
|
|
213
|
+
}
|
|
214
|
+
: {};
|
|
215
|
+
if ((type === "eip1559" && accessList.length > 0) ||
|
|
216
|
+
(type === "eip2930" && accessList.length > 0)) {
|
|
217
|
+
txnBlob.accessList = accessList;
|
|
218
|
+
}
|
|
219
|
+
return await account.signTransaction(txnBlob);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* checkBalance function checks the balance of a given account.
|
|
223
|
+
*
|
|
224
|
+
* @export
|
|
225
|
+
* @param {DevModeContext} context - the DevModeContext instance
|
|
226
|
+
* @param {`0x${string}`} [account=ALITH_ADDRESS] - the account address whose balance is to be checked. If no account is provided, it defaults to ALITH_ADDRESS
|
|
227
|
+
* @returns {Promise<bigint>} - returns a Promise that resolves to the account's balance as a BigInt
|
|
228
|
+
*/
|
|
229
|
+
export async function checkBalance(context, account = ALITH_ADDRESS, block = "latest") {
|
|
230
|
+
return typeof block === "string"
|
|
231
|
+
? await context.viem().getBalance({ address: account, blockTag: block })
|
|
232
|
+
: typeof block === "bigint"
|
|
233
|
+
? await context.viem().getBalance({ address: account, blockNumber: block })
|
|
234
|
+
: await context.viem().getBalance({ address: account });
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Sends a raw signed transaction on to RPC node for execution.
|
|
238
|
+
*
|
|
239
|
+
* @async
|
|
240
|
+
* @function
|
|
241
|
+
* @param {GenericContext} context - The DevModeContext for the Ethereum client interaction.
|
|
242
|
+
* @param {`0x${string}`} rawTx - The signed and serialized hexadecimal transaction string.
|
|
243
|
+
* @returns {Promise<any>} A Promise resolving when the transaction is sent or rejecting with an error.
|
|
244
|
+
*/
|
|
245
|
+
export async function sendRawTransaction(context, rawTx) {
|
|
246
|
+
return await context.viem().request({ method: "eth_sendRawTransaction", params: [rawTx] });
|
|
247
|
+
}
|