Skip to content

Commit

Permalink
fix: auto-load storage slots in fuels deploy (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 authored Dec 2, 2023
1 parent 70233c1 commit 17788fe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-doors-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

The fuels CLI's deploy now auto-loads storage slots for contracts, just like typegen.
10 changes: 9 additions & 1 deletion packages/fuels/src/cli/commands/deploy/deployContract.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { ContractFactory } from '@fuel-ts/contract';
import type { DeployContractOptions } from '@fuel-ts/contract';
import type { WalletUnlocked } from '@fuel-ts/wallet';
import { readFileSync } from 'fs';
import { existsSync, readFileSync } from 'fs';

import { debug } from '../../utils/logger';

export async function deployContract(
wallet: WalletUnlocked,
binaryPath: string,
abiPath: string,
storageSlotsPath: string,
deployConfig: DeployContractOptions
) {
debug(`Deploying contract for ABI: ${abiPath}`);

const bytecode = readFileSync(binaryPath);

if (existsSync(storageSlotsPath)) {
const storageSlots = JSON.parse(readFileSync(storageSlotsPath, 'utf-8'));
// eslint-disable-next-line no-param-reassign
deployConfig.storageSlots = storageSlots;
}

const { minGasPrice: gasPrice } = wallet.provider.getGasConfig();

const abi = JSON.parse(readFileSync(abiPath, 'utf-8'));
Expand Down
10 changes: 9 additions & 1 deletion packages/fuels/src/cli/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getABIPath,
getContractName,
getContractCamelCase,
getStorageSlotsPath,
} from '../../config/forcUtils';
import type { FuelsConfig, DeployedContract } from '../../types';
import { debug, log } from '../../utils/logger';
Expand All @@ -25,6 +26,7 @@ export async function deploy(config: FuelsConfig) {
const contractPath = config.contracts[i];
const binaryPath = getBinaryPath(contractPath);
const abiPath = getABIPath(contractPath);
const storageSlotsPath = getStorageSlotsPath(contractPath);
const projectName = getContractName(contractPath);
const contractName = getContractCamelCase(contractPath);
const deployConfig = await getDeployConfig(config.deployConfig, {
Expand All @@ -33,7 +35,13 @@ export async function deploy(config: FuelsConfig) {
contractPath,
});

const contractId = await deployContract(wallet, binaryPath, abiPath, deployConfig);
const contractId = await deployContract(
wallet,
binaryPath,
abiPath,
storageSlotsPath,
deployConfig
);

debug(`Contract deployed: ${projectName} - ${contractId}`);

Expand Down
5 changes: 5 additions & 0 deletions packages/fuels/src/cli/config/forcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ export function getABIPath(contractPath: string) {
export function getABIPaths(paths: string[]) {
return Promise.all(paths.map((path) => getABIPath(path)));
}

export const getStorageSlotsPath = (contractPath: string) => {
const projectName = getContractName(contractPath);
return join(contractPath, `/out/debug/${projectName}-storage_slots.json`);
};

0 comments on commit 17788fe

Please sign in to comment.