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); }