慢雾:DeFi 当红项目 YAM 闪电折戟,一行代码如何蒸发数亿美元? (3)
时间:2020-08-14 18:05来源:未知 作者:admin 点击:
次
function rebase () public { // EOA only require ( msg . sender == tx . origin ); // ensure rebasing at correct time _inRebaseWindow (); // This comparison also ensures there is no reentrancy. require
function rebase() public { // EOA only require(msg.sender == tx.origin); // ensure rebasing at correct time _inRebaseWindow(); // This comparison also ensures there is no reentrancy. require(lastRebaseTimestampSec.add(minRebaseTimeIntervalSec) < now); // Snap the rebase time to the start of this window. lastRebaseTimestampSec = now.sub( now.mod(minRebaseTimeIntervalSec)).add(rebaseWindowOffsetSec); epoch = epoch.add(1); // get twap from uniswap v2; uint256 exchangeRate = getTWAP(); // calculates % change to supply (uint256 offPegPerc, bool positive) = computeOffPegPerc(exchangeRate); uint256 indexDelta = offPegPerc; // Apply the Dampening factor. indexDelta = indexDelta.div(rebaseLag); YAMTokenInterface yam = YAMTokenInterface(yamAddress); if (positive) { require(yam.yamsScalingFactor().mul(uint256(10**18).add(indexDelta)).div(10**18) < yam.maxScalingFactor(), "new scaling factor will be too big"); } //SlowMist// 取当前 YAM 代币的供应量 uint256 currSupply = yam.totalSupply(); uint256 mintAmount; // reduce indexDelta to account for minting //SlowMist// 计算要调整的供应量 if (positive) { uint256 mintPerc = indexDelta.mul(rebaseMintPerc).div(10**18); indexDelta = indexDelta.sub(mintPerc); mintAmount = currSupply.mul(mintPerc).div(10**18); } // rebase //SlowMist// 调用 YAM 的 rebase 逻辑 uint256
(责任编辑:admin1) |
织梦二维码生成器
------分隔线----------------------------