claim assets when single side deposit

This commit is contained in:
mingda
2020-09-21 23:37:58 +08:00
parent 43fc333275
commit 8b7bdb801c
2 changed files with 42 additions and 4 deletions

View File

@@ -119,10 +119,14 @@ contract Settlement is Storage {
uint256 quoteCapital = getQuoteCapitalBalanceOf(msg.sender);
uint256 baseCapital = getBaseCapitalBalanceOf(msg.sender);
uint256 quoteAmount = _TARGET_QUOTE_TOKEN_AMOUNT_.mul(quoteCapital).div(
getTotalQuoteCapital()
);
uint256 baseAmount = _TARGET_BASE_TOKEN_AMOUNT_.mul(baseCapital).div(getTotalBaseCapital());
uint256 quoteAmount = 0;
if (quoteCapital > 0) {
quoteAmount = _TARGET_QUOTE_TOKEN_AMOUNT_.mul(quoteCapital).div(getTotalQuoteCapital());
}
uint256 baseAmount = 0;
if (baseCapital > 0) {
baseAmount = _TARGET_BASE_TOKEN_AMOUNT_.mul(baseCapital).div(getTotalBaseCapital());
}
_TARGET_QUOTE_TOKEN_AMOUNT_ = _TARGET_QUOTE_TOKEN_AMOUNT_.sub(quoteAmount);
_TARGET_BASE_TOKEN_AMOUNT_ = _TARGET_BASE_TOKEN_AMOUNT_.sub(baseAmount);

View File

@@ -394,6 +394,40 @@ describe("Admin", () => {
);
});
it("final settlement when only deposit base", async () => {
await ctx.DODO.methods
.depositBase(decimalStr("10"))
.send(ctx.sendParam(lp1));
await ctx.DODO.methods
.finalSettlement()
.send(ctx.sendParam(ctx.Deployer));
await ctx.DODO.methods.claimAssets().send(ctx.sendParam(lp1));
assert.equal(
await ctx.BASE.methods.balanceOf(lp1).call(),
decimalStr("100")
);
});
it("final settlement when only deposit quote", async () => {
await ctx.DODO.methods
.depositQuote(decimalStr("1000"))
.send(ctx.sendParam(lp1));
await ctx.DODO.methods
.finalSettlement()
.send(ctx.sendParam(ctx.Deployer));
await ctx.DODO.methods.claimAssets().send(ctx.sendParam(lp1));
assert.equal(
await ctx.QUOTE.methods.balanceOf(lp1).call(),
decimalStr("10000")
);
});
it("final settlement revert cases", async () => {
await assert.rejects(
ctx.DODO.methods.claimAssets().send(ctx.sendParam(lp1)),