refactored watcher; produces logs
This commit is contained in:
50
vault.js
50
vault.js
@@ -1,5 +1,51 @@
|
||||
import {ethers} from "ethers";
|
||||
import {getAbi} from "./abi.js";
|
||||
import {getProvider, getSigner} from "./blockchain.js";
|
||||
import {Cache} from './cache.js';
|
||||
|
||||
const DEPLOYER_ADDRESS = '0xF99aB16Bd8398EAf12407D05A0F8824316008E99'
|
||||
const VAULT_INIT_CODE_HASH = '0xbf043f7035d5aa3be2b3c94df5b256fbe24675689327af4ab71c48194c463031'
|
||||
|
||||
const vaults = new Cache('vaults') // vault:owner
|
||||
|
||||
const deployerAbi = await getAbi('VaultDeployer');
|
||||
|
||||
|
||||
function newVault(address, owner) {
|
||||
return {address, owner, balances: {}}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
export function loginAddress(socket, chainId, address) {
|
||||
// todo check for existing vault
|
||||
// todo send welcome with basic info
|
||||
}
|
||||
if (!vaults[address]) {
|
||||
//
|
||||
} else {
|
||||
// todo send welcome with basic info and extra tokens
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function ensureVault(socket, chainId, owner) {
|
||||
const address = vaultAddress(chainId, owner)
|
||||
if (!vaults[address]) {
|
||||
const deployer = new ethers.Contract(DEPLOYER_ADDRESS, deployerAbi, getSigner(chainId))
|
||||
await deployer.deployVault(owner)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function watchVaultCreated(provider, db, event) {
|
||||
console.log(`vault created`, event)
|
||||
}
|
||||
|
||||
export async function watchErc20Transfer(provider, db, event) {
|
||||
console.log('Transfer', event)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user