YFI_V1的金库合约代码里yVault的生成公式有点蒙圈// shares/ totalSupply()_增发前_yVault == _amount / _pool_balance ??? ,代码是这句shares = (_amount.mul(totalSupply())).div(_pool);

YFI_V1的金库合约代码里yVault的生成公式有点蒙圈// shares/ totalSupply()_增发前_yVault == _amount / _pool_balance ??? ,代码是这句shares = (_amount.mul(totalSupply())).div(_pool);

代码实现如下

function deposit(uint _amount) public { uint _pool = balance(); uint _before = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), _amount); uint _after = token.balanceOf(address(this)); _amount = _after.sub(_before); // Additional check for deflationary tokens uint shares = 0; if (totalSupply() == 0) { shares = _amount; } else { //??? shares/ totalSupply()_增发前_yVault == _amount / _pool_balance ??? shares = (_amount.mul(totalSupply())).div(_pool); } _mint(msg.sender, shares); }

请先 登录 后评论

最佳答案 2021-07-04 17:11

就是计算应得的份额。

若 totalSupply() 为 10 , _pool 为 11 , 存款_amount 是 1.

对应的份额就是 1 * 10 / 11 .

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,2187 浏览
  • Ethereal 提出于 2021-07-04 16:36