removed db migrations
This commit is contained in:
46
vault.js
46
vault.js
@@ -1,24 +1,42 @@
|
||||
import {ethers} from "ethers";
|
||||
import {ethers, keccak256} from "ethers";
|
||||
import {getAbi} from "./abi.js";
|
||||
import {getProvider, getSigner} from "./blockchain.js";
|
||||
import {getSigner} from "./blockchain.js";
|
||||
import {Cache} from './cache.js';
|
||||
import vaultCode from 'contract/out/Vault.sol/Vault.json'
|
||||
import assert from "assert";
|
||||
import fs from 'fs';
|
||||
import {ALL_CHAINS} from "./misc.js";
|
||||
|
||||
const DEPLOYER_ADDRESS = '0xF99aB16Bd8398EAf12407D05A0F8824316008E99'
|
||||
const VAULT_INIT_CODE_HASH = '0xbf043f7035d5aa3be2b3c94df5b256fbe24675689327af4ab71c48194c463031'
|
||||
const VAULT_INIT_CODE_HASH = keccak256(vaultCode.bytecode.object)
|
||||
|
||||
console.log(VAULT_INIT_CODE_HASH)
|
||||
|
||||
const deployerAddresses = {}
|
||||
|
||||
for (const chainId of ALL_CHAINS) {
|
||||
const path = `contract/broadcast/Deploy.sol/${chainId}/run-${process.env['DEXORDER_DEPLOYMENT_' + chainId]}.json`;
|
||||
const deployment = JSON.parse(fs.readFileSync(path, 'utf8')) // synchronous is ok we only do this once on init
|
||||
assert(deployment.transactions[0].contractName === 'VaultDeployer')
|
||||
deployerAddresses[chainId] = deployment.transactions[0].contractAddress
|
||||
}
|
||||
|
||||
const vaults = new Cache('vaults') // vault:owner
|
||||
// Vault
|
||||
// address owner
|
||||
// balances { tokenAddress: amount }
|
||||
// recentOrders []
|
||||
|
||||
const deployerAbi = await getAbi('VaultDeployer');
|
||||
|
||||
|
||||
function newVault(address, owner) {
|
||||
return {address, owner, balances: {}}
|
||||
return {address, owner, tokens: {}} // internal json version
|
||||
}
|
||||
|
||||
export function vaultAddress(chainId, ownerAddress) {
|
||||
const encoded = ethers.AbiCoder.defaultAbiCoder().encode(['address'], [ownerAddress])
|
||||
const salt = ethers.keccak256(encoded)
|
||||
return ethers.getCreate2Address(DEPLOYER_ADDRESS, salt, VAULT_INIT_CODE_HASH)
|
||||
return ethers.getCreate2Address(getDeployerAddress(chainId), salt, VAULT_INIT_CODE_HASH)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +66,20 @@ export async function watchVaultCreated(provider, db, event) {
|
||||
|
||||
export async function watchErc20Transfer(provider, db, event) {
|
||||
console.log('Transfer', event)
|
||||
const [from, to, amount] = event.args
|
||||
let vault = vaults[from]
|
||||
let delta = 0
|
||||
if (vault !== undefined)
|
||||
delta = -amount
|
||||
else {
|
||||
vault = vaults[to]
|
||||
if (vault !== undefined)
|
||||
delta = amount
|
||||
}
|
||||
if (vault) {
|
||||
let oldBalance = vault.balances[event.address]
|
||||
if (oldBalance === undefined) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user