Skip to content

Commit

Permalink
Merge pull request #12 from La-DAO/fix/cuica-utils-missing-providrs
Browse files Browse the repository at this point in the history
Fix/cuica utils missing providrs
  • Loading branch information
0xdcota committed Dec 21, 2023
2 parents f88fc13 + de9e76e commit 571dbf1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
72 changes: 41 additions & 31 deletions scripts/routines/routineUpdateBulletin.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,72 @@
const { ethers } = require('ethers')
const { ethers } = require("ethers");
const {
determineTest,
getLocalhostJsonRPCProvider,
logNewLine,
getEnvWSigner,
getChainProvider,
CUICA_DATA_MAINNET
} = require('../utilsCuica')
const { routineSignLastRound } = require('./routineSignLastRound')
CUICA_DATA_MAINNET,
} = require("../utilsCuica");
const { routineSignLastRound } = require("./routineSignLastRound");

const TEST = determineTest()
const TEST = determineTest();

/**
* @notice Updates roundId data at {PriceBulletin}
* @param {string} chainName
* @param {string} chainName
*/
async function routineUpdateBulletin(chainName='localhost') {
const {digest, v, r, s, info, callData} = await routineSignLastRound(chainName)
async function routineUpdateBulletin(chainName = "localhost") {
const { digest, v, r, s, info, callData } = await routineSignLastRound(
chainName
);

const bulletinAbi = [
'function updateBulletin(bytes)',
'function updateBulletinWithRewardLog(bytes)',
'function updateBulletinWithRewardClaim(bytes, address)',
'function latestRoundData() view returns (uint, int256, uint, uint, uint)',
]
let bulletin
"function updateBulletin(bytes)",
"function updateBulletinWithRewardLog(bytes)",
"function updateBulletinWithRewardClaim(bytes, address)",
"function latestRoundData() view returns (uint, int256, uint, uint, uint)",
];
let bulletin;
if (TEST) {
bulletin = new ethers.Contract(
CUICA_DATA_MAINNET.gnosis.priceBulletin,
bulletinAbi,
getEnvWSigner(getLocalhostJsonRPCProvider())
)
);
} else {
bulletin = new ethers.Contract(
CUICA_DATA_MAINNET[chainName].priceBulletin,
bulletinAbi,
getEnvWSigner(getChainProvider(chainName))
)
);
}

console.log(`${logNewLine('INFO')} Updating PriceBulletin ...`)
const tx = await bulletin.updateBulletin(
callData
)
await tx.wait()
let lastRoundInfo = await bulletin.latestRoundData()
console.log(
`${logNewLine("INFO")} ${chainName} - Updating PriceBulletin ...`
);
const tx = await bulletin.updateBulletin(callData);
await tx.wait();
let lastRoundInfo = await bulletin.latestRoundData();
lastRoundInfo = {
roundId: lastRoundInfo[0],
answer: lastRoundInfo[1],
startedAt: lastRoundInfo[2],
updatedAt: lastRoundInfo[3],
answeredInRound: lastRoundInfo[4]
}
answeredInRound: lastRoundInfo[4],
};
const updateResult = info.roundId.eq(lastRoundInfo.roundId);
if (updateResult) {
console.log(`${logNewLine('INFO')} Successfully updated {PriceBulletin}: latestAnswer(): ${lastRoundInfo.answer.toString()}`)
console.log(
`${logNewLine(
"INFO"
)} ${chainName} - Successfully updated {PriceBulletin}: latestAnswer(): ${lastRoundInfo.answer.toString()}`
);
} else {
console.log(`${logNewLine('WARN')} !!! Failed to update {PriceBulletin}: roundId: ${info.roundId.toString()}`)
console.log(
`${logNewLine(
"WARN"
)} ${chainName} - !!! Failed to update {PriceBulletin}: roundId: ${info.roundId.toString()}`
);
}
}

Expand All @@ -65,10 +75,10 @@ async function routineUpdateBulletin(chainName='localhost') {
if (require.main === module) {
routineUpdateBulletin()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})
.catch((error) => {
console.error(error);
process.exit(1);
});
}

exports.routineUpdateBulletin = routineUpdateBulletin
exports.routineUpdateBulletin = routineUpdateBulletin;
4 changes: 4 additions & 0 deletions scripts/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ async function routineCallbacks() {
console.log(`${logNewLine('INFO')} Begin of scheduler callbacks ...`)
await routineUpdateAllOracles()
await routineUpdateBulletin('gnosis')

// Testnets
await routineUpdateBulletin('sepolia')
await routineUpdateBulletin('goerli')
}

scheduler()
4 changes: 4 additions & 0 deletions scripts/utilsCuica.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const PROVIDERS = {
sepolia: {
chainId: 11155111,
providers: [process.env.RPC_SEPOLIA]
},
goerli: {
chainId: 5,
providers: [process.env.RPC_GOERLI]
}
}

Expand Down

0 comments on commit 571dbf1

Please sign in to comment.