Skip to content

Commit b17fff2

Browse files
authored
Merge the develop branch to the master branch, preparation to v3.3.0
This merge contains the following set of changes: * [Oracle, Improvement] Add oracle helper script for fetching interest amounts via async calls (#615) * [Monitor, Fix] Include cDAI balance in balanceDiff (#613) * [Monitor, Fix] Added logging prior the investedAmount call (#614) * [ALM, Fix] Fetch AMB signatures a bit earlier (#620)
2 parents d36dcad + 4eba91e commit b17fff2

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

alm/src/components/ManualExecutionButton.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const ManualExecutionButton = ({
4545
const { library, activate, account, active } = useWeb3React()
4646
const [manualExecution, setManualExecution] = useState(false)
4747
const [allowFailures, setAllowFailures] = useState(false)
48+
const notReady = !foreign.bridgeContract || !signatureCollected || !signatureCollected.length
4849

4950
useEffect(
5051
() => {
@@ -150,7 +151,7 @@ export const ManualExecutionButton = ({
150151
return (
151152
<div>
152153
<div className="is-center">
153-
<ActionButton className="button outline" onClick={() => setManualExecution(true)}>
154+
<ActionButton disabled={notReady} className="button outline" onClick={() => setManualExecution(true)}>
154155
Execute
155156
</ActionButton>
156157
</div>

alm/src/utils/getConfirmationsForTx.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export const getConfirmationsForTx = async (
8686
setPendingConfirmations(validatorPendingConfirmations.length > 0)
8787
} else {
8888
setPendingConfirmations(false)
89+
if (fromHome) {
90+
// fetch collected signatures for possible manual processing
91+
setSignatureCollected(
92+
await Promise.all(
93+
Array.from(Array(requiredSignatures).keys()).map(i => bridgeContract.methods.signature(hashMsg, i).call())
94+
)
95+
)
96+
}
8997
}
9098

9199
const undefinedConfirmations = validatorConfirmations.filter(
@@ -115,15 +123,6 @@ export const getConfirmationsForTx = async (
115123
status: VALIDATOR_CONFIRMATION_STATUS.NOT_REQUIRED
116124
}))
117125
updateConfirmations(notRequiredConfirmations)
118-
119-
if (fromHome) {
120-
// fetch collected signatures for possible manual processing
121-
setSignatureCollected(
122-
await Promise.all(
123-
Array.from(Array(requiredSignatures).keys()).map(i => bridgeContract.methods.signature(hashMsg, i).call())
124-
)
125-
)
126-
}
127126
}
128127

129128
// get transactions from success signatures

monitor/getBalances.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ async function main(bridgeMode, eventsInfo) {
5151
const foreignErc20Balance = await erc20Contract.methods
5252
.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS)
5353
.call({}, foreignDelayedBlockNumber)
54+
let foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue)
55+
try {
56+
logger.debug('calling foreignBridge.methods.investedAmount')
57+
const invested = await foreignBridge.methods.investedAmount(erc20Address).call({}, foreignDelayedBlockNumber)
58+
foreignErc20BalanceBN = foreignErc20BalanceBN.plus(invested)
59+
} catch (_) {
60+
logger.debug('compounding related methods are not present in the foreign bridge')
61+
}
5462

5563
const homeBridge = new web3Home.eth.Contract(HOME_ERC_TO_NATIVE_ABI, COMMON_HOME_BRIDGE_ADDRESS)
5664
logger.debug('calling homeBridge.methods.blockRewardContract')
@@ -66,7 +74,6 @@ async function main(bridgeMode, eventsInfo) {
6674
const mintedCoinsBN = new BN(mintedCoins)
6775
const burntCoinsBN = new BN(burntCoins)
6876
const totalSupplyBN = mintedCoinsBN.minus(burntCoinsBN)
69-
const foreignErc20BalanceBN = new BN(foreignErc20Balance).plus(lateForeignConfirmationsTotalValue)
7077

7178
const diff = foreignErc20BalanceBN.minus(totalSupplyBN).toFixed()
7279
logger.debug('Done')

oracle/docker-compose-helpers.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
version: '2.4'
3+
services:
4+
interestFetcher:
5+
cpus: 0.1
6+
mem_limit: 500m
7+
image: poanetwork/tokenbridge-oracle:latest
8+
env_file: ./.env
9+
environment:
10+
NODE_ENV: production
11+
INTEREST_FETCHER_PRIVATE_KEY: ${INTEREST_FETCHER_PRIVATE_KEY}
12+
INTEREST_FETCH_CONTRACT_ADDRESS: '0xCd152c7Bd4189Ddee97EaBb783FC5cD93CF2D230'
13+
INTERVAL: 300000
14+
restart: unless-stopped
15+
entrypoint: yarn helper:interestFether

oracle/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"confirm:collected-signatures": "./scripts/start-worker.sh confirmRelay collected-signatures-watcher",
1919
"confirm:information-request": "./scripts/start-worker.sh confirmRelay information-request-watcher",
2020
"manager:shutdown": "./scripts/start-worker.sh shutdownManager shutdown-manager",
21+
"helper:interestFether": "node ./scripts/interestFetcher.js",
2122
"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'",
2223
"test": "NODE_ENV=test mocha",
2324
"test:watch": "NODE_ENV=test mocha --watch --reporter=min",

oracle/scripts/interestFetcher.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
require('../env')
2+
const { isAddress } = require('web3').utils
3+
const { privateKeyToAddress, setIntervalAndRun } = require('../src/utils/utils')
4+
const { EXIT_CODES } = require('../src/utils/constants')
5+
const { web3Home } = require('../src/services/web3')
6+
const { sendTx } = require('../src/tx/sendTx')
7+
8+
const privateKey = process.env.INTEREST_FETCHER_PRIVATE_KEY
9+
const interval = process.env.INTERVAL ? parseInt(process.env.INTERVAL, 10) : 3600 * 1000
10+
const contractAddress = process.env.INTEREST_FETCH_CONTRACT_ADDRESS
11+
12+
if (!privateKey) {
13+
console.error('Environment variable INTEREST_FETCHER_PRIVATE_KEY is not set')
14+
process.exit(EXIT_CODES.GENERAL_ERROR)
15+
}
16+
17+
if (interval < 300 * 1000) {
18+
console.error('Interval is to small, should be at least 5 minutes')
19+
process.exit(EXIT_CODES.GENERAL_ERROR)
20+
}
21+
22+
if (!isAddress(contractAddress)) {
23+
console.error('Invalid contract address provided', contractAddress)
24+
process.exit(EXIT_CODES.GENERAL_ERROR)
25+
}
26+
27+
const gasPrice = process.env.COMMON_HOME_GAS_PRICE_FALLBACK || '1000000000'
28+
29+
async function main() {
30+
// assuming that we are using this contract - https://github.com/omni/interest-fetcher-contract
31+
const contract = new web3Home.eth.Contract([{ name: 'fetchInterest', type: 'function', inputs: [] }], contractAddress)
32+
const chainId = await web3Home.eth.getChainId()
33+
const data = contract.methods.fetchInterest().encodeABI()
34+
const senderAddress = privateKeyToAddress(privateKey)
35+
console.log(
36+
`Initialized, chainId=${chainId}, data=${data}, contract=${contractAddress}, interval=${interval / 1000}s`
37+
)
38+
39+
await setIntervalAndRun(async () => {
40+
let gasLimit
41+
try {
42+
gasLimit = await contract.methods.fetchInterest().estimateGas()
43+
} catch (e) {
44+
console.log('Gas limit estimation failed, will retry later', new Date())
45+
return
46+
}
47+
48+
const nonce = await web3Home.eth.getTransactionCount(senderAddress)
49+
50+
const txHash = await sendTx({
51+
privateKey,
52+
to: contractAddress,
53+
data,
54+
nonce,
55+
gasPrice,
56+
gasLimit: Math.round(gasLimit * 1.5),
57+
amount: '0',
58+
chainId,
59+
web3: web3Home
60+
})
61+
console.log('Sent transaction with fetch interest', txHash, new Date())
62+
}, interval)
63+
}
64+
65+
main()

0 commit comments

Comments
 (0)