From 52e1c88b58874622a0a09a983bb8dca1050a8818 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Mon, 11 Oct 2021 12:14:55 +0300 Subject: [PATCH 1/4] Include cDAI balance in balanceDiff (#613) --- monitor/getBalances.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/monitor/getBalances.js b/monitor/getBalances.js index 3cd5655c..9ab39397 100644 --- a/monitor/getBalances.js +++ b/monitor/getBalances.js @@ -66,7 +66,13 @@ async function main(bridgeMode, eventsInfo) { const mintedCoinsBN = new BN(mintedCoins) const burntCoinsBN = new BN(burntCoins) const totalSupplyBN = mintedCoinsBN.minus(burntCoinsBN) - const foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue) + let foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue) + try { + const invested = await foreignBridge.methods.investedAmount(erc20Address).call({}, foreignDelayedBlockNumber) + foreignErc20BalanceBN = foreignErc20BalanceBN.plus(invested) + } catch (_) { + logger.debug('compounding related methods are not present in the foreign bridge') + } const diff = foreignErc20BalanceBN.minus(totalSupplyBN).toFixed() logger.debug('Done') From a05ff51555fe458e9450df1b25948af99b5a45e4 Mon Sep 17 00:00:00 2001 From: Alexander Kolotov Date: Tue, 12 Oct 2021 18:06:50 +0300 Subject: [PATCH 2/4] Added logging prior the investedAmount call (#614) --- monitor/getBalances.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/monitor/getBalances.js b/monitor/getBalances.js index 9ab39397..92fea2bc 100644 --- a/monitor/getBalances.js +++ b/monitor/getBalances.js @@ -51,6 +51,14 @@ async function main(bridgeMode, eventsInfo) { const foreignErc20Balance = await erc20Contract.methods .balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS) .call({}, foreignDelayedBlockNumber) + let foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue) + try { + logger.debug('calling foreignBridge.methods.investedAmount') + const invested = await foreignBridge.methods.investedAmount(erc20Address).call({}, foreignDelayedBlockNumber) + foreignErc20BalanceBN = foreignErc20BalanceBN.plus(invested) + } catch (_) { + logger.debug('compounding related methods are not present in the foreign bridge') + } const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_NATIVE_ABI, COMMON_HOME_BRIDGE_ADDRESS) logger.debug('calling homeBridge.methods.blockRewardContract') @@ -66,13 +74,6 @@ async function main(bridgeMode, eventsInfo) { const mintedCoinsBN = new BN(mintedCoins) const burntCoinsBN = new BN(burntCoins) const totalSupplyBN = mintedCoinsBN.minus(burntCoinsBN) - let foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue) - try { - const invested = await foreignBridge.methods.investedAmount(erc20Address).call({}, foreignDelayedBlockNumber) - foreignErc20BalanceBN = foreignErc20BalanceBN.plus(invested) - } catch (_) { - logger.debug('compounding related methods are not present in the foreign bridge') - } const diff = foreignErc20BalanceBN.minus(totalSupplyBN).toFixed() logger.debug('Done') From 1e3aa53ab3817818964e45b7278d6784bc75935d Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Thu, 21 Oct 2021 13:33:12 +0300 Subject: [PATCH 3/4] Add oracle helper script for fetching interest amounts via async calls (#615) --- oracle/docker-compose-helpers.yml | 15 +++++++ oracle/package.json | 1 + oracle/scripts/interestFetcher.js | 65 +++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 oracle/docker-compose-helpers.yml create mode 100644 oracle/scripts/interestFetcher.js diff --git a/oracle/docker-compose-helpers.yml b/oracle/docker-compose-helpers.yml new file mode 100644 index 00000000..716a8a13 --- /dev/null +++ b/oracle/docker-compose-helpers.yml @@ -0,0 +1,15 @@ +--- +version: '2.4' +services: + interestFetcher: + cpus: 0.1 + mem_limit: 500m + image: poanetwork/tokenbridge-oracle:latest + env_file: ./.env + environment: + NODE_ENV: production + INTEREST_FETCHER_PRIVATE_KEY: ${INTEREST_FETCHER_PRIVATE_KEY} + INTEREST_FETCH_CONTRACT_ADDRESS: '0xCd152c7Bd4189Ddee97EaBb783FC5cD93CF2D230' + INTERVAL: 300000 + restart: unless-stopped + entrypoint: yarn helper:interestFether diff --git a/oracle/package.json b/oracle/package.json index 8b4236e9..50f17b74 100644 --- a/oracle/package.json +++ b/oracle/package.json @@ -18,6 +18,7 @@ "confirm:collected-signatures": "./scripts/start-worker.sh confirmRelay collected-signatures-watcher", "confirm:information-request": "./scripts/start-worker.sh confirmRelay information-request-watcher", "manager:shutdown": "./scripts/start-worker.sh shutdownManager shutdown-manager", + "helper:interestFether": "node ./scripts/interestFetcher.js", "dev": "concurrently -n 'watcher:signature-request,watcher:collected-signatures,watcher:affirmation-request,watcher:transfer, sender:home,sender:foreign' -c 'red,green,yellow,blue,magenta,cyan' 'yarn watcher:signature-request' 'yarn watcher:collected-signatures' 'yarn watcher:affirmation-request' 'yarn watcher:transfer' 'yarn sender:home' 'yarn sender:foreign'", "test": "NODE_ENV=test mocha", "test:watch": "NODE_ENV=test mocha --watch --reporter=min", diff --git a/oracle/scripts/interestFetcher.js b/oracle/scripts/interestFetcher.js new file mode 100644 index 00000000..1e30773f --- /dev/null +++ b/oracle/scripts/interestFetcher.js @@ -0,0 +1,65 @@ +require('../env') +const { isAddress } = require('web3').utils +const { privateKeyToAddress, setIntervalAndRun } = require('../src/utils/utils') +const { EXIT_CODES } = require('../src/utils/constants') +const { web3Home } = require('../src/services/web3') +const { sendTx } = require('../src/tx/sendTx') + +const privateKey = process.env.INTEREST_FETCHER_PRIVATE_KEY +const interval = process.env.INTERVAL ? parseInt(process.env.INTERVAL, 10) : 3600 * 1000 +const contractAddress = process.env.INTEREST_FETCH_CONTRACT_ADDRESS + +if (!privateKey) { + console.error('Environment variable INTEREST_FETCHER_PRIVATE_KEY is not set') + process.exit(EXIT_CODES.GENERAL_ERROR) +} + +if (interval < 300 * 1000) { + console.error('Interval is to small, should be at least 5 minutes') + process.exit(EXIT_CODES.GENERAL_ERROR) +} + +if (!isAddress(contractAddress)) { + console.error('Invalid contract address provided', contractAddress) + process.exit(EXIT_CODES.GENERAL_ERROR) +} + +const gasPrice = process.env.COMMON_HOME_GAS_PRICE_FALLBACK || '1000000000' + +async function main() { + // assuming that we are using this contract - https://github.com/omni/interest-fetcher-contract + const contract = new web3Home.eth.Contract([{ name: 'fetchInterest', type: 'function', inputs: [] }], contractAddress) + const chainId = await web3Home.eth.getChainId() + const data = contract.methods.fetchInterest().encodeABI() + const senderAddress = privateKeyToAddress(privateKey) + console.log( + `Initialized, chainId=${chainId}, data=${data}, contract=${contractAddress}, interval=${interval / 1000}s` + ) + + await setIntervalAndRun(async () => { + let gasLimit + try { + gasLimit = await contract.methods.fetchInterest().estimateGas() + } catch (e) { + console.log('Gas limit estimation failed, will retry later', new Date()) + return + } + + const nonce = await web3Home.eth.getTransactionCount(senderAddress) + + const txHash = await sendTx({ + privateKey, + to: contractAddress, + data, + nonce, + gasPrice, + gasLimit: Math.round(gasLimit * 1.5), + amount: '0', + chainId, + web3: web3Home + }) + console.log('Sent transaction with fetch interest', txHash, new Date()) + }, interval) +} + +main() From 4eba91ef7e2d811da3e5e4cf5e0ef3cd47c3ea09 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Wed, 3 Nov 2021 19:21:35 +0300 Subject: [PATCH 4/4] Fetch AMB signatures a bit earlier (#620) --- alm/src/components/ManualExecutionButton.tsx | 3 ++- alm/src/utils/getConfirmationsForTx.ts | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/alm/src/components/ManualExecutionButton.tsx b/alm/src/components/ManualExecutionButton.tsx index cd492e86..32492d2f 100644 --- a/alm/src/components/ManualExecutionButton.tsx +++ b/alm/src/components/ManualExecutionButton.tsx @@ -45,6 +45,7 @@ export const ManualExecutionButton = ({ const { library, activate, account, active } = useWeb3React() const [manualExecution, setManualExecution] = useState(false) const [allowFailures, setAllowFailures] = useState(false) + const notReady = !foreign.bridgeContract || !signatureCollected || !signatureCollected.length useEffect( () => { @@ -150,7 +151,7 @@ export const ManualExecutionButton = ({ return (
- setManualExecution(true)}> + setManualExecution(true)}> Execute
diff --git a/alm/src/utils/getConfirmationsForTx.ts b/alm/src/utils/getConfirmationsForTx.ts index 54374efb..a7d87354 100644 --- a/alm/src/utils/getConfirmationsForTx.ts +++ b/alm/src/utils/getConfirmationsForTx.ts @@ -86,6 +86,14 @@ export const getConfirmationsForTx = async ( setPendingConfirmations(validatorPendingConfirmations.length > 0) } else { setPendingConfirmations(false) + if (fromHome) { + // fetch collected signatures for possible manual processing + setSignatureCollected( + await Promise.all( + Array.from(Array(requiredSignatures).keys()).map(i => bridgeContract.methods.signature(hashMsg, i).call()) + ) + ) + } } const undefinedConfirmations = validatorConfirmations.filter( @@ -115,15 +123,6 @@ export const getConfirmationsForTx = async ( status: VALIDATOR_CONFIRMATION_STATUS.NOT_REQUIRED })) updateConfirmations(notRequiredConfirmations) - - if (fromHome) { - // fetch collected signatures for possible manual processing - setSignatureCollected( - await Promise.all( - Array.from(Array(requiredSignatures).keys()).map(i => bridgeContract.methods.signature(hashMsg, i).call()) - ) - ) - } } // get transactions from success signatures