From 835397a57c28322f1fc56d6e85531e4f640118e8 Mon Sep 17 00:00:00 2001 From: Axe Date: Mon, 16 May 2022 13:43:36 +0100 Subject: [PATCH] Avalanche network support (#134) * avax-support, remove js-sdk resolver dep * add missing contract addr --- manifest.json | 47 ++++++++++++++++++++++++---------- package.json | 2 +- src/app.js | 8 +++--- src/config/configuration.js | 5 +++- src/web3client/client.js | 26 ++++++++----------- src/web3client/eventTracker.js | 2 +- 6 files changed, 55 insertions(+), 35 deletions(-) diff --git a/manifest.json b/manifest.json index 54053d11..8f96cddd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,81 +1,102 @@ { - "schema-version": "1", + "schema-version": "2", "name": "sentinel-manifest", "networks": { "3": { "name": "Ropsten", "epoch": 9400000, "batch": "0x6b878902A8648815e1E896515e25D985715bE485", - "cid": "QmeXA7DXVjSi1m6AVgKfGXGoRmdzEVWtC61jiPG46CqgG4" + "cid": "QmeXA7DXVjSi1m6AVgKfGXGoRmdzEVWtC61jiPG46CqgG4", + "resolver": "0x3b44e06D96BcA9412CBc23F80F41B9e30933571a" }, "4": { "name": "Rinkeby", "epoch": 7400000, "batch": "0x6b878902A8648815e1E896515e25D985715bE485", - "cid": "QmbjBccKM4KpULfauknMfruZCsMiJcgzmhqjyxLg6kUFha" + "cid": "QmbjBccKM4KpULfauknMfruZCsMiJcgzmhqjyxLg6kUFha", + "resolver": "0x659635Fab0A0cef1293f7eb3c7934542B6A6B31A" }, "5": { "name": "Goerli", "epoch": 3500000, "batch": "0x48B6934B354666Daa1d9A4ccEE114873312acF55", - "cid": "Qmf8U7cRZcvqW7J8WYaZGG7whEWJfhjdPCyMQdK7EaesfW" + "cid": "Qmf8U7cRZcvqW7J8WYaZGG7whEWJfhjdPCyMQdK7EaesfW", + "resolver": "0x3710AB3fDE2B61736B8BB0CE845D6c61F667a78E" + }, "10": { "name": "Optimism", "epoch": 4300000, "batch": "0xEe1bd2C743BF40B1206B090Fa9aB27A0C57d7B90", - "toga": "0xA3c8502187fD7a7118eAD59dc811281448946C8f" + "toga": "0xA3c8502187fD7a7118eAD59dc811281448946C8f", + "resolver": "0x743B5f46BC86caF41bE4956d9275721E0531B186" }, "42": { "name": "Kovan", "epoch": 23709362, "batch": "0x6b878902A8648815e1E896515e25D985715bE485", - "cid": "QmavpZdKJeRN3zk2VWxP6dj8zKGfKxDWPcWiFBqgS4DoWq" + "cid": "QmavpZdKJeRN3zk2VWxP6dj8zKGfKxDWPcWiFBqgS4DoWq", + "resolver": "0x851d3dd9dc97c1df1DA73467449B3893fc76D85B" }, "69": { "name": "Optimism (Kovan)", "epoch": 308821, "batch": "0x62C82F3b04705a8b54a60c6A9B782AFbe8081C40", - "cid": "Qmf1L2Lw3z4WzqQRRw8jV43JtgVzAfFEHR81bavCV3bRuL" + "cid": "Qmf1L2Lw3z4WzqQRRw8jV43JtgVzAfFEHR81bavCV3bRuL", + "resolver": "0x218B65780615Ff134f9Ad810CB98839534D3C0D6" }, "100": { "name": "Gnosis Chain", "epoch": 14845091, "batch": "0x7Ac49B1539C2580972D9B43b41a4ec93A4290cdF", "toga": "0xb7DE52F4281a7a276E18C40F94cd93159C4A2d22", - "cid": "QmYpvhjEw8jubkP9YMxmkiSf8Jbcthq3NV8auvcwZ4cTJR" + "cid": "QmYpvhjEw8jubkP9YMxmkiSf8Jbcthq3NV8auvcwZ4cTJR", + "resolver": "0xD2009765189164b495c110D61e4D301729079911" }, "137": { "name": "Polygon", "epoch": 11000000, "batch": "0xAB4075f621100563f4551C0Ca50944809b03E948", "toga": "0x6AEAeE5Fd4D05A741723D752D30EE4D72690A8f7", - "cid": "QmdcjBYuAZiW4Vm8TR6AEE6Ajt9LVLT5WvLL3Rqt5f46fC" + "cid": "QmdcjBYuAZiW4Vm8TR6AEE6Ajt9LVLT5WvLL3Rqt5f46fC", + "resolver": "0xE0cc76334405EE8b39213E620587d815967af39C" }, "42161": { "name": "arbitrum-one", "epoch": 7600000, "batch": "0xA87F76e99f6C8Ff8996d14f550ceF47f193D9A09", - "toga": "0xFC63B7C762B10670Eda15cF3ca3970bCDB28C9eF" + "toga": "0xFC63B7C762B10670Eda15cF3ca3970bCDB28C9eF", + "resolver": "0x609b9d9d6Ee9C3200745A79B9d3398DBd63d509F" }, "43113": { "name": "Avalanche (Fuji)", "epoch": 3220231, "batch": "0xFabcf1239357D8051a8028222c28b0ffdc0F7398", - "cid": "" + "cid": "", + "resolver": "0x141920741bC45b962B59c833cd849bA617F7ef38" + }, + "43114": { + "name": "Avalanche (C-Chain)", + "epoch": 14700000, + "batch": "0xcFE6382B33F2AdaFbE46e6A26A88E0182ae32b0c", + "toga": "0x3D9A67D5ec1E72CEcA8157e028855056786b6159", + "cid": "", + "resolver": "0x24a3F04F70B7f07B9673EadD3e146391BcfEa5c1" }, "80001": { "name": "Mumbai (Polygon)", "epoch": 7295264, "batch": "0xf8A70a8589c579D3C169812b050C2B4475784EA9", "toga": "0xc301D28088d537E24c41A7AAd03896E7E16074f4", - "cid": "QmXhmMyzf2p4hBwytqCdqZioihqApvRtk3mx4kBrn7B3BV" + "cid": "QmXhmMyzf2p4hBwytqCdqZioihqApvRtk3mx4kBrn7B3BV", + "resolver": "0x8C54C83FbDe3C59e59dd6E324531FB93d4F504d3" }, "421611": { "name": "Arbitrum (Rinkeby)", "epoch": 7309284, "batch": "0x00A1c6dB5287f09D9C3e99C2B74E03F4A7d2F545", - "cid": "QmREesEuHQXAi4FFkD36Wo1cca2pJPETjRfnZQ46BcyJUK" + "cid": "QmREesEuHQXAi4FFkD36Wo1cca2pJPETjRfnZQ46BcyJUK", + "resolver": "0xa2C0C70A1E922f5f060ec20EE3aF002C163b4567" } } } diff --git a/package.json b/package.json index 778ab27d..29f4a5b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superfluid-sentinel", - "version": "0.9.6", + "version": "0.9.7", "description": "Superfluid Sentinel", "main": "main.js", "scripts": { diff --git a/src/app.js b/src/app.js index 9ad7b5fb..83b2e07d 100644 --- a/src/app.js +++ b/src/app.js @@ -146,13 +146,14 @@ class App { try { this.logger.debug(`booting sentinel`); this._isShutdown = false; - - // create all web3 infrastructure needed - await this.client.init(); + // connect to provided rpc + await this.client.connect(); // if we are running tests don't try to load network information if (!this.config.RUN_TEST_ENV) { this.config.loadNetworkInfo(await this.client.getChainId()); } + // create all web3 infrastructure needed + await this.client.init(); if (this.config.BATCH_CONTRACT !== undefined) { await this.client.loadBatchContract(); } @@ -187,7 +188,6 @@ class App { // query balances to make liquidations estimations await this.bootstrap.start(); this.queues.init(); - this.timer.startAfter(this.queues); this.timer.startAfter(this.eventTracker, currentBlock); // start http server to serve node health reports and dashboard diff --git a/src/config/configuration.js b/src/config/configuration.js index 0e6be40c..e64ac111 100644 --- a/src/config/configuration.js +++ b/src/config/configuration.js @@ -33,7 +33,7 @@ class Config { this.CONCURRENCY = config.concurrency; this.COLD_BOOT = config.cold_boot; this.NUM_RETRIES = config.number_retries; - this.RESOLVER = config.resolver; + this.RESOLVER = config.resolver || process.env.RESOLVER_ADDRESS; this.SHUTDOWN_ON_ERROR = config.shutdown_on_error; this.LIQUIDATION_JOB_AWAITS = config.liquidation_job_awaits; this.ONLY_LISTED_TOKENS = config.only_listed_tokens === "true"; @@ -102,6 +102,9 @@ class Config { this.BATCH_CONTRACT = manifest.networks[chainId].batch; this.TOGA_CONTRACT = manifest.networks[chainId].toga || undefined; this.CID = manifest.networks[chainId].cid || undefined; + if(this.RESOLVER === undefined) { + this.RESOLVER = manifest.networks[chainId].resolver || undefined; + } } getConfigurationInfo () { diff --git a/src/web3client/client.js b/src/web3client/client.js index 1d21b01a..6196238f 100644 --- a/src/web3client/client.js +++ b/src/web3client/client.js @@ -1,5 +1,4 @@ const Web3 = require("web3"); -const SDKConfig = require("@superfluid-finance/js-sdk/src/getConfig.js"); const IResolver = require("@superfluid-finance/ethereum-contracts/build/contracts/IResolver.json"); const ICFA = require("@superfluid-finance/ethereum-contracts/build/contracts/IConstantFlowAgreementV1.json"); const IIDA = require("@superfluid-finance/ethereum-contracts/build/contracts/IInstantDistributionAgreementV1.json"); @@ -22,14 +21,15 @@ class Client { this.superTokens = new Map(); this.superTokensAddresses = []; this.version = this.app.config.PROTOCOL_RELEASE_VERSION; - this.isInitialized = false; + this.isConnected = false; this.totalRequests = 0; this.totalSkippedBlockRequests = 0; } - async initialize () { + async connect () { try { - if(!this.app.config.HTTP_RPC_NODE) throw new Error("No HTTP RPC set"); + this.app.logger.info(`Client connecting to RPC...`); + if(!this.app.config.HTTP_RPC_NODE) throw new Error(`Client.connect(): no HTTP RPC set`); const web3Provider = new Web3.providers.HttpProvider(this.app.config.HTTP_RPC_NODE, { keepAlive: true }); @@ -37,7 +37,8 @@ class Client { this.web3.eth.currentProvider.sendAsync = function (payload, callback) { return this.send(payload, callback); }; - this.isInitialized = true; + this.isConnected = true; + this.app.logger.info(`Client connected to RPC`); } catch (err) { this.app.logger.error(err); throw new Error(`Client.initialize(): ${err}`); @@ -46,8 +47,10 @@ class Client { async init () { try { + if(!this.isConnected) { + throw Error(`Client.init(): not connected to rpc`); + } this.app.logger.info(`Web3Client start`); - await this.initialize(); this.app.logger.info(`ChainId: ${await this.getChainId()}`) await this._loadSuperfluidContracts(); if (this.app.config.PRIVATE_KEY !== undefined) { @@ -73,7 +76,6 @@ class Client { this.app.logger.warn("!!!ACCOUNT NOT FUNDED!!! Will fail to execute liquidations!"); } } - this.app.logger.info("Connecting to Node: HTTP"); this.web3.eth.transactionConfirmationBlocks = 3; } catch (err) { this.app.logger.error(err); @@ -109,14 +111,8 @@ class Client { async _loadSuperfluidContracts () { try { - let resolverAddress; - if (this.app.config.RESOLVER !== undefined) { - resolverAddress = this.app.config.RESOLVER; - } else { - resolverAddress = SDKConfig(await this.getChainId()).resolverAddress; - } const superfluidIdent = `Superfluid.${this.version}`; - this.resolver = new this.web3.eth.Contract(IResolver.abi,resolverAddress); + this.resolver = new this.web3.eth.Contract(IResolver.abi,this.app.config.RESOLVER); const superfluidAddress = await this.resolver.methods.get(superfluidIdent).call(); this.sf = new this.web3.eth.Contract(ISuperfluid.abi,superfluidAddress); const govAddress = await this.sf.methods.getGovernance().call(); @@ -126,7 +122,7 @@ class Client { const [cfaAddress, idaAddress] = await Promise.all([this.sf.methods.getAgreementClass(cfaIdent).call(), this.sf.methods.getAgreementClass(idaIdent).call()]); this.CFAv1 = new this.web3.eth.Contract(ICFA.abi, cfaAddress); this.IDAv1 = new this.web3.eth.Contract(IIDA.abi, idaAddress); - this.app.logger.info(`Resolver: ${resolverAddress}`); + this.app.logger.info(`Resolver: ${this.app.config.RESOLVER}`); this.app.logger.info(`Superfluid: ${superfluidAddress}`); this.app.logger.info(`Superfluid Governance: ${govAddress}`); this.app.logger.info(`CFA address: ${cfaAddress}`); diff --git a/src/web3client/eventTracker.js b/src/web3client/eventTracker.js index e676b61c..b532e7cf 100644 --- a/src/web3client/eventTracker.js +++ b/src/web3client/eventTracker.js @@ -48,7 +48,7 @@ class EventTracker { } async start (oldBlock) { - if (this.app.client.isInitialized === undefined || !this.app.client.isInitialized) { + if (this.app.client.isConnected === undefined || !this.app.client.isConnected) { throw Error("BlockTracker.start() - client is not initialized "); } if (oldBlock) {