refactored watcher; produces logs

This commit is contained in:
Tim Olson
2023-09-01 18:58:04 -04:00
parent 97234c955f
commit 2e1d2aaa96
9 changed files with 238 additions and 68 deletions

30
abi.js
View File

@@ -1,3 +1,9 @@
import {readFile} from './misc.js'
import {ethers} from "ethers";
const ABI_BASE_PATH = '../contract/out'
export const erc20Abi = [
'function name() view returns (string)',
'function symbol() view returns (string)',
@@ -26,6 +32,7 @@ const TimedOrderSpec = '(' +
'bool amountIsInput' +
')'
export const timedOrderAbi = [
'event TimedOrderCreated (address owner, uint64 index, Spec spec)',
'event TimedOrderFilled (address owner, uint64 index, uint256 amountIn, uint256 amountOut)',
@@ -35,8 +42,31 @@ export const timedOrderAbi = [
]
const vaultDeployerAbi = [
'function deployVault(address owner) returns (address vault)',
'event VaultCreated( address deployer, address owner )',
]
export const abi = {
'ERC20': erc20Abi,
'TimedOrder': timedOrderAbi,
'VaultDeployer': vaultDeployerAbi,
}
export async function getAbi(className) {
let found = abi[className]
if (found === undefined) {
console.log('warning: loading ABI from filesystem for '+className)
const data = await readFile(ABI_BASE_PATH + `/${className}.sol/${className}.json`)
found = JSON.parse(data.toString())['abi']
abi[className] = found
}
return found
}
export async function getInterface(className) {
return new ethers.Interface(await getAbi(className))
}