diff --git a/contracts/DODOPrivatePool/impl/DPPTrader.sol b/contracts/DODOPrivatePool/impl/DPPTrader.sol index 698ee8c..f0d1c5b 100644 --- a/contracts/DODOPrivatePool/impl/DPPTrader.sol +++ b/contracts/DODOPrivatePool/impl/DPPTrader.sol @@ -53,8 +53,7 @@ contract DPPTrader is DPPVault { _transferQuoteOut(to, receiveQuoteAmount); _transferQuoteOut(_MAINTAINER_, mtFee); - _setReserve(baseBalance, _QUOTE_TOKEN_.balanceOf(address(this))); - + // update TARGET if (_RState_ != uint32(newRState)) { require(newBaseTarget <= uint112(-1),"OVERFLOW"); @@ -63,6 +62,8 @@ contract DPPTrader is DPPVault { emit RChange(newRState); } + _setReserve(baseBalance, _QUOTE_TOKEN_.balanceOf(address(this))); + emit DODOSwap( address(_BASE_TOKEN_), address(_QUOTE_TOKEN_), @@ -90,7 +91,6 @@ contract DPPTrader is DPPVault { _transferBaseOut(to, receiveBaseAmount); _transferBaseOut(_MAINTAINER_, mtFee); - _setReserve(_BASE_TOKEN_.balanceOf(address(this)), quoteBalance); // update TARGET if (_RState_ != uint32(newRState)) { @@ -100,6 +100,8 @@ contract DPPTrader is DPPVault { emit RChange(newRState); } + _setReserve(_BASE_TOKEN_.balanceOf(address(this)), quoteBalance); + emit DODOSwap( address(_QUOTE_TOKEN_), address(_BASE_TOKEN_), diff --git a/test/DPP/trader.test.ts b/test/DPP/trader.test.ts index fefe86a..e356eba 100644 --- a/test/DPP/trader.test.ts +++ b/test/DPP/trader.test.ts @@ -78,6 +78,7 @@ describe("DPP Trader", () => { // sell at R>1 and R not change state await ctx.transferBaseToDPP(trader, decimalStr("1")) await logGas(ctx.DPP.methods.sellBase(trader), ctx.sendParam(trader), "sellBase - sell at R>1 and R not change state") + balances = await ctx.getBalances(trader) assert.equal(balances.traderBase, "10946772292527553373") assert.equal(balances.traderQuote, "903421814651005338950") @@ -90,7 +91,7 @@ describe("DPP Trader", () => { // sell at R>1 and R change state await ctx.transferBaseToDPP(trader, decimalStr("2")) - let resp = await ctx.DPP.methods.querySellBase(trader,decimalStr("2")).call(); + let resp = await ctx.DPP.methods.querySellBase(trader, decimalStr("2")).call(); let bs = await ctx.getBalances(trader); let lpFeeRate = await ctx.DPP.methods._LP_FEE_RATE_().call();