Skip to content

Commit

Permalink
remove loadContract
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Apr 16, 2024
1 parent 9d2c0a7 commit 9a4d12b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 52 deletions.
13 changes: 2 additions & 11 deletions lib/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ import {
num,
uint256,
} from "starknet";
import {
ArgentSigner,
KeyPair,
declareContract,
ethAddress,
loadContract,
provider,
randomStarknetKeyPair,
strkAddress,
} from ".";
import { ArgentSigner, KeyPair, ethAddress, loadContract, provider, randomStarknetKeyPair, strkAddress } from ".";
export class ArgentAccount extends Account {
// Increase the gas limit by 30% to avoid failures due to gas estimation being too low with tx v3 and transactions the use escaping
override async deployAccount(
Expand Down Expand Up @@ -94,7 +85,7 @@ async function deployAccountInner(params: DeployAccountParams): Promise<
> {
const finalParams = {
...params,
classHash: params.classHash ?? (await declareContract("ArgentAccount")),
classHash: params.classHash!,
salt: params.salt ?? num.toHex(randomStarknetKeyPair().privateKey),
owner: params.owner ?? randomStarknetKeyPair(),
useTxV3: params.useTxV3 ?? false,
Expand Down
43 changes: 2 additions & 41 deletions lib/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { readFileSync } from "fs";
import {
Abi,
AccountInterface,
CompiledSierra,
Contract,
DeclareContractPayload,
ProviderInterface,
json,
num,
} from "starknet";
import { deployer, provider } from ".";

const classHashCache: Record<string, string> = {};
import { Abi, AccountInterface, Contract, ProviderInterface, json, num } from "starknet";
import { provider } from ".";

export const ethAddress = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
export const strkAddress = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
Expand All @@ -20,7 +9,6 @@ let ethContract: Contract;
let strkContract: Contract;

export const contractsFolder = "./target/release/argent_";
export const fixturesFolder = "./tests-integration/fixtures/argent_";

export class ContractWithClassHash extends Contract {
constructor(
Expand Down Expand Up @@ -60,33 +48,6 @@ export async function getStrkContract(): Promise<Contract> {
return strkContract;
}

export function getDeclareContractPayload(contractName: string, folder = contractsFolder): DeclareContractPayload {
const contract: CompiledSierra = readContract(`${folder}${contractName}.contract_class.json`);
const payload: DeclareContractPayload = { contract };
if ("sierra_program" in contract) {
payload.casm = readContract(`${folder}${contractName}.compiled_contract_class.json`);
}
return payload;
}

// Could extends Account to add our specific fn but that's too early.
export async function declareContract(contractName: string, wait = true, folder = contractsFolder): Promise<string> {
const cachedClass = classHashCache[contractName];
if (cachedClass) {
return cachedClass;
}
const payload = getDeclareContractPayload(contractName, folder);

const { class_hash, transaction_hash } = await deployer.declareIfNot(payload, { maxFee: undefined });

if (wait && transaction_hash) {
await provider.waitForTransaction(transaction_hash);
console.log(`\t${contractName} declared`);
}
classHashCache[contractName] = class_hash;
return class_hash;
}

export async function loadContract(contractAddress: string, classHash?: string): Promise<ContractWithClassHash> {
try {
const { abi } = await provider.getClassAt(contractAddress);
Expand Down

0 comments on commit 9a4d12b

Please sign in to comment.