Skip to content

Commit 66f9f61

Browse files
committed
refactor(contracts): enhance deployment infrastructure and standardize network configuration
Comprehensive refactoring of contract deployment system to improve reliability, usability, and maintainability: BREAKING CHANGE: Network name 'localhost' renamed to 'local' in configuration - Update .env files: LOCALHOST_* → LOCAL_* - Hardhat network config: 'localhost' → 'local' - Affects Configuration.ts, hardhat.config.ts, .env.sample Network Configuration Improvements: - Standardize network naming (localhost → local) for clarity - Add realistic timeouts per network (10s local → 300s mainnet) - Reduce max gas limit from 30M to 15M for safer defaults - Clarify network type distinctions (simulated vs real local nodes) Batch Processing Enhancements: - Introduce DEFAULT_BATCH_SIZE constant (15 facets/batch) - Replace hardcoded batch size of 2 throughout codebase - Add 1-second delays between batches to prevent RPC overload - Improve gas management for large configuration deployments Checkpoint System Improvements: - Add warning when checkpoint dir is inside node_modules - Document checkpointDir option in ResumeOptions type - Help prevent checkpoint loss on npm install/ci Developer Experience: - Add deployment convenience scripts at root and package level - Update documentation with new CLI patterns - Standardize script naming (deploy:hedera:testnet, etc.) - Simplify deployment workflows for common scenarios Infrastructure Code Quality: - Use constants instead of magic numbers - Consistent parameter defaults across functions - Improved JSDoc documentation with examples - Better separation of concerns in network configs Files affected: - Configuration & environment: .env.sample, Configuration.ts, hardhat.config.ts - Build scripts: package.json (root + contracts) - CLI entry points: cli/hardhat.ts, cli/standalone.ts - Domain layer: bond/equity createConfiguration - Infrastructure: constants, networkConfig, operations, checkpoint system - Workflows: deploySystemWithNewBlr, deploySystemWithExistingBlr - Documentation: scripts/README.md Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders>
1 parent c6ffb68 commit 66f9f61

File tree

18 files changed

+177
-81
lines changed

18 files changed

+177
-81
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
"ats:contracts:test:coverage": "npm run test:coverage --workspace=packages/ats/contracts",
8282
"ats:contracts:test:ci": "npm run test:ci --workspace=packages/ats/contracts --if-present || npm run test --workspace=packages/ats/contracts",
8383
"ats:contracts:clean": "npm run clean --workspace=packages/ats/contracts",
84+
"ats:contracts:deploy": "npm run deploy --workspace=packages/ats/contracts",
85+
"ats:contracts:deploy:local": "npm run deploy:local --workspace=packages/ats/contracts",
86+
"ats:contracts:deploy:hedera:local": "npm run deploy:hedera:local --workspace=packages/ats/contracts",
87+
"ats:contracts:deploy:hedera:previewnet": "npm run deploy:hedera:previewnet --workspace=packages/ats/contracts",
88+
"ats:contracts:deploy:hedera:testnet": "npm run deploy:hedera:testnet --workspace=packages/ats/contracts",
89+
"ats:contracts:deploy:hedera:mainnet": "npm run deploy:hedera:mainnet --workspace=packages/ats/contracts",
8490
"ats:contracts:publish": "npm run publish --workspace=packages/ats/contracts",
8591
"ats:sdk:build": "npm run build --workspace=packages/ats/sdk",
8692
"ats:sdk:test": "npm run test --workspace=packages/ats/sdk",

packages/ats/contracts/.env.sample

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# Hardhat (in-memory test network) - uses Hardhat's built-in accounts
55
# No private keys needed for hardhat network
66

7-
# Localhost (generic local Ethereum node)
8-
LOCALHOST_PRIVATE_KEY_0='0xEXAMPLEPRIVATEKEY0'
9-
LOCALHOST_PRIVATE_KEY_1='0xEXAMPLEPRIVATEKEY1'
7+
# Local (generic local Ethereum node)
8+
LOCAL_PRIVATE_KEY_0='0xEXAMPLEPRIVATEKEY0'
9+
LOCAL_PRIVATE_KEY_1='0xEXAMPLEPRIVATEKEY1'
1010
# ... add more keys as needed
1111

1212
# Hedera Local (Docker-based Hedera local node)
@@ -33,8 +33,8 @@ HEDERA_MAINNET_PRIVATE_KEY_1='0xEXAMPLEPRIVATEKEY9'
3333
# Hardhat (no external endpoint, uses in-memory network)
3434
# HARDHAT_JSON_RPC_ENDPOINT not required
3535

36-
# Localhost (generic local Ethereum node, defaults to http://127.0.0.1:8545)
37-
LOCALHOST_JSON_RPC_ENDPOINT='http://127.0.0.1:8545'
36+
# Local (generic local Ethereum node, defaults to http://127.0.0.1:8545)
37+
LOCAL_JSON_RPC_ENDPOINT='http://127.0.0.1:8545'
3838

3939
# Hedera Local (Docker-based Hedera local node)
4040
HEDERA_LOCAL_JSON_RPC_ENDPOINT='http://127.0.0.1:7546'

packages/ats/contracts/Configuration.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ const NETWORK_ENV_PREFIX_SEPARATOR_REGEX = /-/g;
230230
*
231231
* Network Types:
232232
* - hardhat: Hardhat's in-memory test network (ephemeral, no persistence)
233-
* - localhost: Generic local Ethereum node (e.g., Hardhat node, Ganache, Anvil)
233+
* - local: Generic local Ethereum node (e.g., Hardhat node, Ganache, Anvil)
234234
* - hedera-local: Local Hedera node running in Docker
235235
* - hedera-previewnet: Hedera previewnet (public test network)
236236
* - hedera-testnet: Hedera testnet (primary test network)
237237
* - hedera-mainnet: Hedera mainnet (production network)
238238
*/
239239
export const NETWORKS = [
240240
"hardhat",
241-
"localhost",
241+
"local",
242242
"hedera-local",
243243
"hedera-previewnet",
244244
"hedera-testnet",
@@ -262,7 +262,7 @@ const formatNetworkEnvPrefix = (network: Network): string =>
262262
* @deprecated Old network names. Use new names from NETWORKS instead.
263263
*/
264264
export const NETWORK_ALIASES: Record<string, Network> = {
265-
local: "localhost",
265+
localhost: "local",
266266
previewnet: "hedera-previewnet",
267267
testnet: "hedera-testnet",
268268
mainnet: "hedera-mainnet",
@@ -424,7 +424,7 @@ export default class Configuration {
424424
jsonRpc: Configuration._getEnvironmentVariable({
425425
name: `${network.toUpperCase().replace(/-/g, "_")}_JSON_RPC_ENDPOINT`,
426426
defaultValue:
427-
network === "localhost"
427+
network === "local"
428428
? "http://127.0.0.1:8545"
429429
: network === "hedera-local"
430430
? "http://127.0.0.1:7546"
@@ -435,7 +435,7 @@ export default class Configuration {
435435
mirror: Configuration._getEnvironmentVariable({
436436
name: `${network.toUpperCase().replace(/-/g, "_")}_MIRROR_NODE_ENDPOINT`,
437437
defaultValue:
438-
network === "localhost"
438+
network === "local"
439439
? ""
440440
: network === "hedera-local"
441441
? "http://127.0.0.1:5600"

packages/ats/contracts/hardhat.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ const config: HardhatUserConfig = {
253253
blockGasLimit: 30_000_000,
254254
hardfork: "cancun",
255255
},
256-
localhost: {
257-
url: Configuration.endpoints.localhost.jsonRpc,
258-
accounts: Configuration.privateKeys.localhost,
256+
local: {
257+
url: Configuration.endpoints.local.jsonRpc,
258+
accounts: Configuration.privateKeys.local,
259259
timeout: 60_000,
260260
},
261261
"hedera-local": {

packages/ats/contracts/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@
5252
"lint:js": "eslint .",
5353
"lint:js:fix": "eslint . --fix",
5454
"generate:registry": "npx ts-node scripts/tools/generateRegistry.ts",
55+
"deploy": "npm run build && npx ts-node -r tsconfig-paths/register scripts/cli/standalone.ts",
56+
"deploy:local": "NETWORK=local npm run deploy",
57+
"deploy:local:auto": "npx hardhat node > hardhat-node.log 2>&1 & sleep 3 && npm run deploy:local; kill $!",
58+
"deploy:hedera:local": "NETWORK=hedera-local npm run deploy",
59+
"deploy:hedera:previewnet": "NETWORK=hedera-previewnet npm run deploy",
60+
"deploy:hedera:testnet": "NETWORK=hedera-testnet npm run deploy",
61+
"deploy:hedera:mainnet": "NETWORK=hedera-mainnet npm run deploy",
62+
"local:hardhat": "npx hardhat node",
5563
"deploy:hardhat": "npx hardhat run scripts/cli/hardhat.ts",
56-
"deploy:standalone": "npm run compile && npx ts-node -r tsconfig-paths/register scripts/cli/standalone.ts",
5764
"publish": "npm publish",
5865
"compile": "npx hardhat compile",
5966
"compile:traces": "npx hardhat --show-stack-traces compile",

packages/ats/contracts/scripts/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ This README provides comprehensive reference documentation for the deployment sy
3131
| ---------------------------------------------------- | ------------------------ | --------------------------- |
3232
| `npm run deploy:hardhat -- --network hardhat` | In-memory testing | Hardhat project |
3333
| `npm run deploy:hardhat -- --network hedera-testnet` | Testnet deployment | Hardhat + `.env` |
34-
| `npm run deploy:standalone` | Standalone deployment | Compiled artifacts + `.env` |
34+
| `npm run deploy` | Standalone deployment | Compiled artifacts + `.env` |
35+
| `npm run deploy:hedera:testnet` | Testnet shortcut | `.env` configured |
3536
| `npm run generate:registry` | Update contract metadata | Contracts compiled |
3637

3738
---
@@ -518,11 +519,11 @@ Check the output file in `deployments/{network}_{timestamp}.json`:
518519

519520
The deployment system supports three modes:
520521

521-
| Mode | Entry Point | Signer Source | Use Case | Command |
522-
| -------------- | -------------------------------------- | --------------------- | ----------------------------------------- | -------------------------------------------- |
523-
| **Hardhat** | [cli/hardhat.ts](cli/hardhat.ts) | `ethers.getSigners()` | Hardhat project deployment | `npm run deploy:hardhat -- --network <name>` |
524-
| **Standalone** | [cli/standalone.ts](cli/standalone.ts) | `ethers.Wallet` | No Hardhat dependency, ~3x faster startup | `npm run deploy:standalone` |
525-
| **Module** | Import in your code | Any ethers.js Signer | Custom scripts, programmatic deployment | See example below |
522+
| Mode | Entry Point | Signer Source | Use Case | Command |
523+
| -------------- | -------------------------------------- | --------------------- | ----------------------------------------- | --------------------------------------------------- |
524+
| **Hardhat** | [cli/hardhat.ts](cli/hardhat.ts) | `ethers.getSigners()` | Hardhat project deployment | `npm run deploy:hardhat -- --network <name>` |
525+
| **Standalone** | [cli/standalone.ts](cli/standalone.ts) | `ethers.Wallet` | No Hardhat dependency, ~3x faster startup | `npm run deploy` or `npm run deploy:hedera:testnet` |
526+
| **Module** | Import in your code | Any ethers.js Signer | Custom scripts, programmatic deployment | See example below |
526527

527528
### Import as Module
528529

packages/ats/contracts/scripts/cli/hardhat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import { deploySystemWithNewBlr } from "../workflows/deploySystemWithNewBlr";
20-
import { getNetworkConfig, getAllNetworks } from "@scripts/infrastructure";
20+
import { getNetworkConfig, getAllNetworks, DEFAULT_BATCH_SIZE } from "@scripts/infrastructure";
2121

2222
/**
2323
* Main deployment function for Hardhat environment.
@@ -57,8 +57,8 @@ async function main() {
5757
// Check for PartialBatchDeploy mode from environment
5858
const partialBatchDeploy = process.env.PARTIAL_BATCH_DEPLOY === "true";
5959

60-
// Get batch size from environment or default to 2
61-
const batchSize = process.env.BATCH_SIZE ? parseInt(process.env.BATCH_SIZE) : 2;
60+
// Get batch size from environment or use DEFAULT_BATCH_SIZE constant
61+
const batchSize = process.env.BATCH_SIZE ? parseInt(process.env.BATCH_SIZE) : DEFAULT_BATCH_SIZE;
6262

6363
try {
6464
// Deploy system with new BLR

packages/ats/contracts/scripts/cli/standalone.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* USE_TIMETRAVEL - Enable TimeTravel mode (default: false)
1414
*
1515
* Usage:
16-
* NETWORK=hedera-testnet npx ts-node scripts/cli/standalone.ts
16+
* npm run deploy
1717
* or
18-
* npm run deploy:standalone
18+
* npm run deploy:hedera:testnet
1919
*
2020
* @module cli/standalone
2121
*/
2222

2323
import { deploySystemWithNewBlr } from "../workflows/deploySystemWithNewBlr";
24-
import { getAllNetworks, getNetworkConfig } from "@scripts/infrastructure";
24+
import { getAllNetworks, getNetworkConfig, DEFAULT_BATCH_SIZE } from "@scripts/infrastructure";
2525
import { Wallet, providers } from "ethers";
2626

2727
/**
@@ -32,7 +32,7 @@ async function main() {
3232
const network = process.env.NETWORK || "hedera-testnet";
3333
const useTimeTravel = process.env.USE_TIMETRAVEL === "true";
3434
const partialBatchDeploy = process.env.PARTIAL_BATCH_DEPLOY === "true";
35-
const batchSize = process.env.BATCH_SIZE ? parseInt(process.env.BATCH_SIZE) : 2;
35+
const batchSize = process.env.BATCH_SIZE ? parseInt(process.env.BATCH_SIZE) : DEFAULT_BATCH_SIZE;
3636

3737
console.log(`🚀 Starting ATS deployment (standalone mode)`);
3838
console.log("=".repeat(60));

packages/ats/contracts/scripts/domain/bond/createConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ConfigurationError,
1919
createBatchConfiguration,
2020
OperationResult,
21+
DEFAULT_BATCH_SIZE,
2122
} from "@scripts/infrastructure";
2223
import { BOND_CONFIG_ID, atsRegistry } from "@scripts/domain";
2324

@@ -137,7 +138,7 @@ export async function createBondConfiguration(
137138
facetAddresses: Record<string, string>,
138139
useTimeTravel: boolean = false,
139140
partialBatchDeploy: boolean = false,
140-
batchSize: number = 2,
141+
batchSize: number = DEFAULT_BATCH_SIZE,
141142
): Promise<OperationResult<ConfigurationData, ConfigurationError>> {
142143
// Get facet names based on time travel mode
143144
// Include TimeTravelFacet when useTimeTravel=true to provide time manipulation functions

packages/ats/contracts/scripts/domain/equity/createConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ConfigurationError,
1919
OperationResult,
2020
createBatchConfiguration,
21+
DEFAULT_BATCH_SIZE,
2122
} from "@scripts/infrastructure";
2223
import { EQUITY_CONFIG_ID, atsRegistry } from "@scripts/domain";
2324

@@ -137,7 +138,7 @@ export async function createEquityConfiguration(
137138
facetAddresses: Record<string, string>,
138139
useTimeTravel: boolean = false,
139140
partialBatchDeploy: boolean = false,
140-
batchSize: number = 2,
141+
batchSize: number = DEFAULT_BATCH_SIZE,
141142
): Promise<OperationResult<ConfigurationData, ConfigurationError>> {
142143
// Get facet names based on time travel mode
143144
// Include TimeTravelFacet when useTimeTravel=true to provide time manipulation functions

0 commit comments

Comments
 (0)