Skip to content

Commit

Permalink
Avalanche network support (#134)
Browse files Browse the repository at this point in the history
* avax-support, remove js-sdk resolver dep

* add missing contract addr
  • Loading branch information
ngmachado committed May 16, 2022
1 parent bdb0634 commit 835397a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
47 changes: 34 additions & 13 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superfluid-sentinel",
"version": "0.9.6",
"version": "0.9.7",
"description": "Superfluid Sentinel",
"main": "main.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 () {
Expand Down
26 changes: 11 additions & 15 deletions src/web3client/client.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -22,22 +21,24 @@ 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
});
this.web3 = new Web3(web3Provider);
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}`);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/web3client/eventTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 835397a

Please sign in to comment.