init funding test

This commit is contained in:
mingda
2020-10-27 02:53:23 +08:00
parent 081c0ecde4
commit dd60e1727f
9 changed files with 305 additions and 120 deletions

View File

@@ -23,27 +23,27 @@ contract DVMFunding is DVMStorage {
if (baseReserve == 0 && quoteReserve == 0) {
mintAmount = baseInput;
}
// // case 2. supply when quote reserve is 0
// if (baseReserve > 0 && quoteReserve == 0) {
// uint256 mintRatio = DecimalMath.divFloor(baseInput, baseReserve);
// mintAmount = DecimalMath.mulFloor(_VAULT_.totalSupply(), mintRatio);
// }
// // case 3. normal case
// if (baseReserve > 0 && quoteReserve > 0) {
// uint256 baseInputRatio = DecimalMath.divFloor(baseInput, baseReserve);
// uint256 quoteInputRatio = DecimalMath.divFloor(quoteInput, quoteReserve);
// uint256 mintRatio = baseInputRatio > quoteInputRatio ? quoteInputRatio : baseInputRatio;
// // 在提币的时候向下取整。因此永远不会出现balance为0但totalsupply不为0的情况
// // 但有可能出现reserve>0但totalSupply=0的场景
// uint256 totalShare = _VAULT_.totalSupply();
// if (totalShare > 0) {
// mintAmount = DecimalMath.mulFloor(totalShare, mintRatio);
// } else {
// mintAmount = baseInput;
// }
// }
// _VAULT_.mint(account, mintAmount);
// _VAULT_.sync();
// case 2. supply when quote reserve is 0
if (baseReserve > 0 && quoteReserve == 0) {
uint256 mintRatio = DecimalMath.divFloor(baseInput, baseReserve);
mintAmount = DecimalMath.mulFloor(_VAULT_.totalSupply(), mintRatio);
}
// case 3. normal case
if (baseReserve > 0 && quoteReserve > 0) {
uint256 baseInputRatio = DecimalMath.divFloor(baseInput, baseReserve);
uint256 quoteInputRatio = DecimalMath.divFloor(quoteInput, quoteReserve);
uint256 mintRatio = baseInputRatio > quoteInputRatio ? quoteInputRatio : baseInputRatio;
// 在提币的时候向下取整。因此永远不会出现balance为0但totalsupply不为0的情况
// 但有可能出现reserve>0但totalSupply=0的场景
uint256 totalShare = _VAULT_.totalSupply();
if (totalShare > 0) {
mintAmount = DecimalMath.mulFloor(totalShare, mintRatio);
} else {
mintAmount = baseInput;
}
}
_VAULT_.mint(account, mintAmount);
_VAULT_.sync();
}
function sellShares(