Skip to content

Commit

Permalink
Add multisig deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
delaaxe committed Aug 18, 2023
1 parent d56ca25 commit cdf10b1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions deployments/multisig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x737ee2f87ce571a58c6c8da558ec18a07ceb64a6172d5ec46171fbc80077a48: 0.1.0 (goerli-1, goerli-2)
4 changes: 2 additions & 2 deletions scripts/deploy-account.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import "dotenv/config";
import { declareContract, deployAccount, deployer, loadContract, provider } from "../tests/lib";

const argentAccountClassHash = await declareContract("ArgentAccount", false);
const argentAccountClassHash = await declareContract("ArgentAccount", true);
console.log("ArgentAccount class hash:", argentAccountClassHash);
const testDappClassHash = await declareContract("TestDapp", false);
const testDappClassHash = await declareContract("TestDapp", true);
console.log("TestDapp class hash:", testDappClassHash);

console.log("Deploying new account");
Expand Down
33 changes: 33 additions & 0 deletions scripts/deploy-multisig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "dotenv/config";
import { declareContract, deployer, deployMultisig, loadContract, provider } from "../tests/lib";

const multisigClassHash = await declareContract("ArgentMultisig", true);
console.log("ArgentMultisig class hash:", multisigClassHash);
const testDappClassHash = await declareContract("TestDapp", true);
console.log("TestDapp class hash:", testDappClassHash);

console.log("Deploying new account");

const threshold = 1;
const signersLength = 2;
const { account, keys, signers } = await deployMultisig(multisigClassHash, threshold, signersLength);

console.log("Account address:", account.address);
console.log("Account signers:", signers);
console.log(
"Account private keys:",
keys.map(({ privateKey }) => privateKey),
);

console.log("Deploying new test dapp");
const { contract_address } = await deployer.deployContract({ classHash: testDappClassHash });
console.log("TestDapp address:", contract_address);
const testDappContract = await loadContract(contract_address);

console.log("Calling test dapp");
testDappContract.connect(account);
const response = await testDappContract.set_number(42n);
await provider.waitForTransaction(response.transaction_hash);

const number = await testDappContract.get_number(account.address);
console.log(number === 42n ? "Seems good!" : "Something went wrong :(");
7 changes: 4 additions & 3 deletions tests/lib/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ export async function upgradeAccount(
return await provider.waitForTransaction(transferTxHash);
}

export async function fundAccount(recipient: string, amount: number | bigint): Promise<void> {
export async function fundAccount(recipient: string, amount: number | bigint) {
if (provider.isDevnet) {
return await mintEth(recipient);
await mintEth(recipient);
return;
}
const ethContract = await getEthContract();
ethContract.connect(deployer);

const bn = uint256.bnToUint256(amount);
await ethContract.invoke("transfer", CallData.compile([recipient, bn.low, bn.high]));
return ethContract.invoke("transfer", CallData.compile([recipient, bn.low, bn.high]));
}

export enum EscapeStatus {
Expand Down
7 changes: 5 additions & 2 deletions tests/lib/multisig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Account, CallData, Contract, GetTransactionReceiptResponse, hash, num } from "starknet";
import { KeyPair, MultisigSigner, loadContract, mintEth, provider, randomKeyPair, randomKeyPairs } from ".";
import { KeyPair, MultisigSigner, loadContract, provider, randomKeyPair, randomKeyPairs, fundAccount } from ".";

export interface MultisigWallet {
account: Account;
Expand All @@ -22,7 +22,10 @@ export async function deployMultisig(
const addressSalt = num.toHex(randomKeyPair().privateKey);

const contractAddress = hash.calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
await mintEth(contractAddress);
const response = await fundAccount(contractAddress, 1e15); // 0.001 ETH
if (response) {
await provider.waitForTransaction(response.transaction_hash);
}

const deploymentSigner = new MultisigSigner(keys.filter((_, i) => deploymentIndexes.includes(i)));
const account = new Account(provider, contractAddress, deploymentSigner, "1");
Expand Down

0 comments on commit cdf10b1

Please sign in to comment.