Created
July 19, 2021 18:16
-
-
Save nginnever/edfe30ed08be9073663663f1939e34c1 to your computer and use it in GitHub Desktop.
test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {AddressZero} from "@ethersproject/constants" | |
import GnosisSafeL2 from "../../abis/GnosisSafeL2.json" | |
import GnosisSafeProxyFactory from "../../abis/GnosisSafeProxyFactory.json" | |
import {Contract, ContractFactory} from "@ethersproject/contracts" | |
import {JsonRpcSigner, Web3Provider} from "@ethersproject/providers" | |
const {REACT_APP_PROXY_ADDRESS} = process.env | |
const createGnosisSafe = async ( | |
admins: string[], | |
votingThreshold: number, | |
provider: Web3Provider, | |
signer: JsonRpcSigner | |
): Promise<string> => | |
new Promise(async (resolve, reject) => { | |
try { | |
const GnosisSafeL2Factory = new ContractFactory( | |
GnosisSafeL2.abi, | |
GnosisSafeL2.bytecode, | |
signer | |
) | |
const singleton = await GnosisSafeL2Factory.deploy() | |
const factory = new Contract(REACT_APP_PROXY_ADDRESS!, GnosisSafeProxyFactory.abi, signer) | |
const template = await factory.callStatic.createProxy(singleton.address, "0x") | |
console.log(template) | |
await factory.createProxy(singleton.address, "0x").then((tx: any) => tx.wait()) | |
console.log("proxy created") | |
const safe = GnosisSafeL2Factory.attach(template) | |
await safe | |
.setup(admins, votingThreshold, AddressZero, "0x", AddressZero, AddressZero, 0, AddressZero) | |
.then((tx: any) => tx.wait()) | |
const owners = await safe.getOwners() | |
console.log(owners) | |
resolve(singleton.address) | |
} catch (e) { | |
reject(e) | |
} | |
}) | |
export default createGnosisSafe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment