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)', 'function decimals() view returns (uint8)', 'function totalSupply() view returns (uint256)', 'function balanceOf(address) view returns (uint256)', 'function transfer(address,uint256) returns (bool)', 'function transferFrom(address,address,uint256) returns (bool)', 'function approve(address,uint256) returns (bool success)', 'function allowance(address,address) view returns (uint256)', 'event Transfer(address indexed,address indexed,uint256)', 'event Approval(address indexed,address indexed,uint256)', ] const TimedOrderSpec = '(' + 'address tokenIn,' + 'address tokenOut,' + 'uint24 fee,' + 'uint32 deadline,' + 'uint32 leeway,' + 'uint160 minSqrtPriceX96,' + 'uint160 maxSqrtPriceX96,' + 'uint8 numTranches,' + 'uint256 amount,' + 'bool amountIsInput' + ')' export const timedOrderAbi = [ 'event TimedOrderCreated (address owner, uint64 index, Spec spec)', 'event TimedOrderFilled (address owner, uint64 index, uint256 amountIn, uint256 amountOut)', 'event TimedOrderCompleted (address owner, uint64 index)', 'event TimedOrderError (address owner, uint64 index, string reason)', `timedOrder(${TimedOrderSpec}) returns (uint64 index)`, ] 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)) }