ABI's from contract/out files
This commit is contained in:
22
vault.js
22
vault.js
@@ -1,13 +1,9 @@
|
||||
import {ethers} from "ethers";
|
||||
import {getAbi} from "./abi.js";
|
||||
import {getProvider, getSigner} from "./blockchain.js";
|
||||
import {vaultBalances, vaults} from './cache.js';
|
||||
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
|
||||
import {sendVaultOrders} from "./order.js";
|
||||
|
||||
|
||||
const vaultAbi = await getAbi('Vault')
|
||||
const factoryAbi = await getAbi('VaultFactory')
|
||||
import {newContract} from "./contract.js";
|
||||
|
||||
|
||||
export function vaultAddress(chainId, owner, num=0) {
|
||||
@@ -96,22 +92,26 @@ async function createVault(chainId, owner, num) {
|
||||
const signer = getSigner(chainId);
|
||||
const factory = chainInfo[chainId].factory;
|
||||
console.log('createVault', chainId, owner, num, factory )
|
||||
const deployer = new ethers.Contract(factory, factoryAbi, signer)
|
||||
const deployer = await newContract(factory, 'IVaultFactory', signer)
|
||||
const vaultAddr = vaultAddress(chainId, owner, num)
|
||||
console.log(' ==>', vaultAddr )
|
||||
try {
|
||||
const tx = await deployer.deployVault(owner, num)
|
||||
// console.log(`deploying vault for ${owner} #${num} with tx ${tx.hash}`)
|
||||
await tx.wait()
|
||||
const tx = await deployer['deployVault(address,uint8)'](owner, num) // must specify which deployVault() to call
|
||||
console.log(`deploying vault for ${owner} #${num} with tx ${tx.hash}`)
|
||||
const result = await tx.wait()
|
||||
if (result.status !== 1) {
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw Error(`Vault deployment reverted. tx ${tx.hash}`)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
const vault = new ethers.Contract(vaultAddr, vaultAbi, getProvider(chainId))
|
||||
const vault = await newContract(vaultAddr, 'IVault', getProvider(chainId))
|
||||
try {
|
||||
const ver = await vault.version()
|
||||
console.log(`vault already deployed at ${vaultAddr} with version ${ver}`)
|
||||
}
|
||||
catch (e2) {
|
||||
console.error('could not deploy vault:', e2)
|
||||
console.error('could not deploy vault:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user