Assertions
Assertions check the correctness of the simulation flow.
try {
let currentBlock = await provider.getBlockNumber();
let previousBlock = (currentBlock - 1).toString(16);
const WBTC_FEED = "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c";
let wbtcFeed = new ethers.Contract(WBTC_FEED, oracleAbi, provider);
let [latestRound, pastRound] = await Promise.all([
wbtcFeed.latestRoundData(),
wbtcFeed.latestRoundData({ blockTag: ("0x" + previousBlock) })
]);
let currentPrice = latestRound[1] / 1e8;
let pastPrice = pastRound[1] / 1e8;
if (currentPrice <= pastPrice) {
return true;
} else if (currentPrice > pastPrice) {
return false;
} else {
return "NC";
}
} catch (err) {
console.log("error in priceDrop Assertion", err);
return err;
}
Last updated