Skip to content

Commit

Permalink
remove more boiler plate code
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Apr 17, 2024
1 parent 9a4d12b commit 1905648
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
33 changes: 4 additions & 29 deletions lib/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { readFileSync } from "fs";
import { Abi, AccountInterface, Contract, ProviderInterface, json, num } from "starknet";
import { Abi, AccountInterface, Contract, ProviderInterface, json } from "starknet";
import { provider } from ".";

export const ethAddress = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
export const strkAddress = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";

let ethContract: Contract;
let strkContract: Contract;

export const contractsFolder = "./target/release/argent_";
export const ethContract = await loadContract(ethAddress);
export const strkContract = await loadContract(strkAddress);

export class ContractWithClassHash extends Contract {
constructor(
Expand All @@ -22,30 +20,7 @@ export class ContractWithClassHash extends Contract {
}

export async function getFeeTokenContract(useTxV3: boolean): Promise<Contract> {
return useTxV3 ? getStrkContract() : getEthContract();
}

export async function getEthContract(): Promise<Contract> {
if (ethContract) {
return ethContract;
}
const ethProxy = await loadContract(ethAddress);
if (ethProxy.abi.some((entry) => entry.name == "implementation")) {
const implementationAddress = num.toHex((await ethProxy.implementation()).address);
const ethImplementation = await loadContract(implementationAddress);
ethContract = new Contract(ethImplementation.abi, ethAddress, ethProxy.providerOrAccount);
} else {
ethContract = ethProxy;
}
return ethContract;
}

export async function getStrkContract(): Promise<Contract> {
if (strkContract) {
return strkContract;
}
strkContract = await loadContract(strkAddress);
return strkContract;
return useTxV3 ? strkContract : ethContract;
}

export async function loadContract(contractAddress: string, classHash?: string): Promise<ContractWithClassHash> {
Expand Down
4 changes: 1 addition & 3 deletions scripts/fund-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from "fs";
import { Account, Call, Contract, uint256 } from "starknet";
import { deployer, getEthContract, getStrkContract, provider } from "../lib";
import { deployer, ethContract, provider, strkContract } from "../lib";

// Update theses
const ethFundingAmount = BigInt(1e16);
Expand All @@ -9,8 +9,6 @@ const strkFundingAmount = BigInt(5e17);
// Parse file of accounts
const v3Accounts: Account[] = JSON.parse(readFileSync("./.env.v3Accounts.json", "utf-8"));
const v2Accounts: Account[] = JSON.parse(readFileSync("./.env.v2Accounts.json", "utf-8"));
const strkContract = await getStrkContract();
const ethContract = await getEthContract();
const calls: Call[] = [];

// This will query too much in short amount of time, run at your own risks
Expand Down
4 changes: 1 addition & 3 deletions scripts/stress-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync, writeFileSync } from "fs";
import { exit } from "process";
import { Account, RPC, num, uint256 } from "starknet";
import { ArgentAccount, getEthContract, getStrkContract, provider } from "../lib";
import { ArgentAccount, ethContract, provider, strkContract } from "../lib";

// Update theses
const aimTPS = 3;
Expand All @@ -11,8 +11,6 @@ const maxFee = 1e15;
const l1_gas = { max_amount: "0x100", max_price_per_unit: num.toHex(1e15) };

// Fixed constants
const ethContract = await getEthContract();
const strkContract = await getStrkContract();
const v3Amount = Math.ceil(aimTPS * ratioTxV3);
const v2Amount = aimTPS - v3Amount;
console.log(`${v3Amount} v3 <=> ${v2Amount} v2`);
Expand Down

0 comments on commit 1905648

Please sign in to comment.