Skip to content

Commit

Permalink
Upgrade to multisig-wallet-contracts version 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed May 10, 2024
1 parent fb14383 commit 8f1d7fd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 209 deletions.
1 change: 0 additions & 1 deletion packages/contracts/contracts/Reference.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
pragma solidity ^0.8.2;

import "multisig-wallet-contracts/contracts/MultiSigWallet.sol";
import "multisig-wallet-contracts/contracts/MultiSigWalletFactory.sol";
85 changes: 19 additions & 66 deletions packages/contracts/deploy/main_chain_devnet/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import { ethers } from "hardhat";

import { HardhatAccount } from "../../src/HardhatAccount";
import { BOACoin } from "../../src/utils/Amount";
import { ContractUtils } from "../../src/utils/ContractUtils";
import { LYT, MultiSigWallet, MultiSigWalletFactory } from "../../typechain-types";
import { LYT, MultiSigWallet } from "../../typechain-types";

import { BaseContract, Contract, Wallet } from "ethers";
import { BaseContract, Wallet } from "ethers";

import fs from "fs";

const network = "bosagora_devnet";

export const MULTI_SIG_WALLET_FACTORY_ADDRESS: { [key: string]: string } = {
bosagora_mainnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
bosagora_testnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
bosagora_devnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
};

interface IDeployedContract {
name: string;
address: string;
Expand All @@ -34,7 +25,6 @@ class Deployments {
public deployments: Map<string, IDeployedContract>;
public deployers: FnDeployer[];
public accounts: IAccount;
private MULTI_SIG_WALLET_FACTORY_CONTRACT: Contract | undefined;

public ownersOfMultiSigWallet: string[] = [
"0x2312c098Cef41C0F55350bC3Ad8F4AFf983d9432",
Expand All @@ -55,13 +45,6 @@ class Deployments {
};
}

public async attachPreviousContracts() {
const factory = await ethers.getContractFactory("MultiSigWalletFactory");
this.MULTI_SIG_WALLET_FACTORY_CONTRACT = factory.attach(
MULTI_SIG_WALLET_FACTORY_ADDRESS[network]
) as BaseContract;
}

public addContract(name: string, address: string, contract: BaseContract) {
this.deployments.set(name, {
name,
Expand All @@ -71,9 +54,6 @@ class Deployments {
}

public getContract(name: string): BaseContract | undefined {
if (name === "MultiSigWalletFactory") {
return this.MULTI_SIG_WALLET_FACTORY_CONTRACT;
}
const info = this.deployments.get(name);
if (info !== undefined) {
return info.contract;
Expand All @@ -83,9 +63,6 @@ class Deployments {
}

public getContractAddress(name: string): string | undefined {
if (name === "MultiSigWalletFactory") {
return MULTI_SIG_WALLET_FACTORY_ADDRESS[network];
}
const info = this.deployments.get(name);
if (info !== undefined) {
return info.address;
Expand Down Expand Up @@ -139,50 +116,29 @@ class Deployments {
}
}

async function deployMultiSigWalletFactory(accounts: IAccount, deployment: Deployments) {
const contractName = "MultiSigWalletFactory";
async function deployMultiSigWallet(accounts: IAccount, deployment: Deployments) {
const contractName = "MultiSigWallet";
console.log(`Deploy ${contractName}...`);
const factory = await ethers.getContractFactory("MultiSigWalletFactory");
const contract = (await factory.connect(accounts.deployer).deploy()) as MultiSigWalletFactory;

const factory = await ethers.getContractFactory("MultiSigWallet");
const contract = (await factory
.connect(accounts.deployer)
.deploy(
"OwnerWallet",
"",
deployment.ownersOfMultiSigWallet,
deployment.requiredMultiSigWallet
)) as MultiSigWallet;
await contract.deployed();
await contract.deployTransaction.wait();

deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
}

async function deployMultiSigWallet(accounts: IAccount, deployment: Deployments): Promise<MultiSigWallet | undefined> {
const contractName = "MultiSigWallet";
console.log(`Deploy ${contractName}...`);
if (deployment.getContract("MultiSigWalletFactory") === undefined) {
console.error("Contract is not deployed!");
return;
const owners = await contract.getMembers();
for (let idx = 0; idx < owners.length; idx++) {
console.log(`MultiSigWallet's owners[${idx}]: ${owners[idx]}`);
}

const factoryContract = deployment.getContract("MultiSigWalletFactory") as MultiSigWalletFactory;

const address = await ContractUtils.getEventValueString(
await factoryContract
.connect(accounts.deployer)
.create("OwnerWallet", "", deployment.ownersOfMultiSigWallet, deployment.requiredMultiSigWallet),
factoryContract.interface,
"ContractInstantiation",
"wallet"
);

if (address !== undefined) {
const contract = (await ethers.getContractFactory("MultiSigWallet")).attach(address) as MultiSigWallet;

const owners = await contract.getMembers();
for (let idx = 0; idx < owners.length; idx++) {
console.log(`MultiSigWallet's owners[${idx}]: ${owners[idx]}`);
}

deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
} else {
console.error(`Failed to deploy ${contractName}`);
}
deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
}

async function deployToken(accounts: IAccount, deployment: Deployments) {
Expand Down Expand Up @@ -212,9 +168,6 @@ async function deployToken(accounts: IAccount, deployment: Deployments) {
async function main() {
const deployments = new Deployments();

await deployments.attachPreviousContracts();

// deployments.addDeployer(deployMultiSigWalletFactory);
deployments.addDeployer(deployMultiSigWallet);
deployments.addDeployer(deployToken);

Expand Down
85 changes: 19 additions & 66 deletions packages/contracts/deploy/side_chain_devnet/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import { ethers } from "hardhat";

import { HardhatAccount } from "../../src/HardhatAccount";
import { BOACoin } from "../../src/utils/Amount";
import { ContractUtils } from "../../src/utils/ContractUtils";
import { LYT, MultiSigWallet, MultiSigWalletFactory } from "../../typechain-types";
import { LYT, MultiSigWallet } from "../../typechain-types";

import { BaseContract, Contract, Wallet } from "ethers";
import { BaseContract, Wallet } from "ethers";

import fs from "fs";

const network = "bosagora_devnet";

export const MULTI_SIG_WALLET_FACTORY_ADDRESS: { [key: string]: string } = {
bosagora_mainnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
bosagora_testnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
bosagora_devnet: "0xF120890C71B2B9fF4578088A398a2402Ae0d3616",
};

interface IDeployedContract {
name: string;
address: string;
Expand All @@ -34,7 +25,6 @@ class Deployments {
public deployments: Map<string, IDeployedContract>;
public deployers: FnDeployer[];
public accounts: IAccount;
private MULTI_SIG_WALLET_FACTORY_CONTRACT: Contract | undefined;

public ownersOfMultiSigWallet: string[] = [
"0x2312c098Cef41C0F55350bC3Ad8F4AFf983d9432",
Expand All @@ -55,13 +45,6 @@ class Deployments {
};
}

public async attachPreviousContracts() {
const factory = await ethers.getContractFactory("MultiSigWalletFactory");
this.MULTI_SIG_WALLET_FACTORY_CONTRACT = factory.attach(
MULTI_SIG_WALLET_FACTORY_ADDRESS[network]
) as BaseContract;
}

public addContract(name: string, address: string, contract: BaseContract) {
this.deployments.set(name, {
name,
Expand All @@ -71,9 +54,6 @@ class Deployments {
}

public getContract(name: string): BaseContract | undefined {
if (name === "MultiSigWalletFactory") {
return this.MULTI_SIG_WALLET_FACTORY_CONTRACT;
}
const info = this.deployments.get(name);
if (info !== undefined) {
return info.contract;
Expand All @@ -83,9 +63,6 @@ class Deployments {
}

public getContractAddress(name: string): string | undefined {
if (name === "MultiSigWalletFactory") {
return MULTI_SIG_WALLET_FACTORY_ADDRESS[network];
}
const info = this.deployments.get(name);
if (info !== undefined) {
return info.address;
Expand Down Expand Up @@ -139,50 +116,29 @@ class Deployments {
}
}

async function deployMultiSigWalletFactory(accounts: IAccount, deployment: Deployments) {
const contractName = "MultiSigWalletFactory";
async function deployMultiSigWallet(accounts: IAccount, deployment: Deployments) {
const contractName = "MultiSigWallet";
console.log(`Deploy ${contractName}...`);
const factory = await ethers.getContractFactory("MultiSigWalletFactory");
const contract = (await factory.connect(accounts.deployer).deploy()) as MultiSigWalletFactory;

const factory = await ethers.getContractFactory("MultiSigWallet");
const contract = (await factory
.connect(accounts.deployer)
.deploy(
"OwnerWallet",
"",
deployment.ownersOfMultiSigWallet,
deployment.requiredMultiSigWallet
)) as MultiSigWallet;
await contract.deployed();
await contract.deployTransaction.wait();

deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
}

async function deployMultiSigWallet(accounts: IAccount, deployment: Deployments): Promise<MultiSigWallet | undefined> {
const contractName = "MultiSigWallet";
console.log(`Deploy ${contractName}...`);
if (deployment.getContract("MultiSigWalletFactory") === undefined) {
console.error("Contract is not deployed!");
return;
const owners = await contract.getMembers();
for (let idx = 0; idx < owners.length; idx++) {
console.log(`MultiSigWallet's owners[${idx}]: ${owners[idx]}`);
}

const factoryContract = deployment.getContract("MultiSigWalletFactory") as MultiSigWalletFactory;

const address = await ContractUtils.getEventValueString(
await factoryContract
.connect(accounts.deployer)
.create("OwnerWallet", "", deployment.ownersOfMultiSigWallet, deployment.requiredMultiSigWallet),
factoryContract.interface,
"ContractInstantiation",
"wallet"
);

if (address !== undefined) {
const contract = (await ethers.getContractFactory("MultiSigWallet")).attach(address) as MultiSigWallet;

const owners = await contract.getMembers();
for (let idx = 0; idx < owners.length; idx++) {
console.log(`MultiSigWallet's owners[${idx}]: ${owners[idx]}`);
}

deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
} else {
console.error(`Failed to deploy ${contractName}`);
}
deployment.addContract(contractName, contract.address, contract);
console.log(`Deployed ${contractName} to ${contract.address}`);
}

async function deployToken(accounts: IAccount, deployment: Deployments) {
Expand Down Expand Up @@ -212,9 +168,6 @@ async function deployToken(accounts: IAccount, deployment: Deployments) {
async function main() {
const deployments = new Deployments();

await deployments.attachPreviousContracts();

// deployments.addDeployer(deployMultiSigWalletFactory);
deployments.addDeployer(deployMultiSigWallet);
deployments.addDeployer(deployToken);

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loyalty-tokens",
"version": "1.1.1",
"version": "1.1.2",
"description": "Smart contracts for the loyalty tokens",
"files": [
"**/*.sol"
Expand Down Expand Up @@ -48,7 +48,7 @@
"hardhat": "^2.12.7",
"hardhat-gas-reporter": "^1.0.7",
"mocha": "10.1.0",
"multisig-wallet-contracts": "^1.1.2",
"multisig-wallet-contracts": "^1.1.3",
"prettier": "^2.5.1",
"prettier-plugin-solidity": "^1.1.1",
"solhint": "^3.3.6",
Expand Down
41 changes: 6 additions & 35 deletions packages/contracts/test/DelegatedTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "@nomiclabs/hardhat-waffle";
import { ethers } from "hardhat";

import { HardhatAccount } from "../src/HardhatAccount";
import { LYT, MultiSigWallet, MultiSigWalletFactory } from "../typechain-types";
import { LYT, MultiSigWallet } from "../typechain-types";

import assert from "assert";
import { BigNumber, Wallet } from "ethers";
Expand All @@ -12,34 +12,16 @@ import { ContractUtils } from "../src/utils/ContractUtils";
import { expect } from "chai";
import { BOACoin } from "../src/utils/Amount";

async function deployMultiSigWalletFactory(deployer: Wallet): Promise<MultiSigWalletFactory> {
const factory = await ethers.getContractFactory("MultiSigWalletFactory");
const contract = (await factory.connect(deployer).deploy()) as MultiSigWalletFactory;
await contract.deployed();
await contract.deployTransaction.wait();
return contract;
}

async function deployMultiSigWallet(
factoryAddress: string,
deployer: Wallet,
owners: string[],
required: number
): Promise<MultiSigWallet | undefined> {
const contractFactory = await ethers.getContractFactory("MultiSigWalletFactory");
const factoryContract = contractFactory.attach(factoryAddress) as MultiSigWalletFactory;

const address = await ContractUtils.getEventValueString(
await factoryContract.connect(deployer).create("", "", owners, required),
factoryContract.interface,
"ContractInstantiation",
"wallet"
);

if (address !== undefined) {
await factoryContract.register(address);
return (await ethers.getContractFactory("MultiSigWallet")).attach(address) as MultiSigWallet;
} else return undefined;
const factory = await ethers.getContractFactory("MultiSigWallet");
const contract = (await factory.connect(deployer).deploy("", "", owners, required)) as MultiSigWallet;
await contract.deployed();
await contract.deployTransaction.wait();
return contract;
}

async function deployToken(deployer: Wallet, owner: string): Promise<LYT> {
Expand All @@ -55,19 +37,12 @@ describe("Test for LYT token", () => {
const [deployer, account0, account1, account2, account3, account4, account5] = raws;
const owners1 = [account0, account1, account2];

let multiSigFactory: MultiSigWalletFactory;
let multiSigWallet: MultiSigWallet | undefined;
let token: LYT;
const requiredConfirmations = 2;

before(async () => {
multiSigFactory = await deployMultiSigWalletFactory(deployer);
assert.ok(multiSigFactory);
});

it("Create Wallet by Factory", async () => {
multiSigWallet = await deployMultiSigWallet(
multiSigFactory.address,
deployer,
owners1.map((m) => m.address),
requiredConfirmations
Expand All @@ -78,10 +53,6 @@ describe("Test for LYT token", () => {
await multiSigWallet.getMembers(),
owners1.map((m) => m.address)
);

assert.deepStrictEqual(await multiSigFactory.getNumberOfWalletsForMember(account0.address), BigNumber.from(1));
assert.deepStrictEqual(await multiSigFactory.getNumberOfWalletsForMember(account1.address), BigNumber.from(1));
assert.deepStrictEqual(await multiSigFactory.getNumberOfWalletsForMember(account2.address), BigNumber.from(1));
});

it("Create Token, Owner is MultiSigWallet", async () => {
Expand Down
Loading

0 comments on commit 8f1d7fd

Please sign in to comment.