diff --git a/contracts/EncryptedDEXPair.sol b/contracts/EncryptedDEXPair.sol index 4e1a63f..4282139 100644 --- a/contracts/EncryptedDEXPair.sol +++ b/contracts/EncryptedDEXPair.sol @@ -234,12 +234,16 @@ contract EncryptedDEXPair is EncryptedERC20 { uint32 burnedTotal ) { - if(TFHE.isInitialized(reserve0PendingAdd)) reserve0PendingAddDec = TFHE.decrypt(reserve0PendingAdd); - if(TFHE.isInitialized(reserve1PendingAdd)) reserve1PendingAddDec = TFHE.decrypt(reserve1PendingAdd); - if(TFHE.isInitialized(pendingTotalMints[currentTradingEpoch])) mintedTotal = TFHE.decrypt(pendingTotalMints[currentTradingEpoch]); - if(TFHE.isInitialized(pendingTotalToken0In[currentTradingEpoch])) amount0In = TFHE.decrypt(pendingTotalToken0In[currentTradingEpoch]); - if(TFHE.isInitialized(pendingTotalToken1In[currentTradingEpoch])) amount1In = TFHE.decrypt(pendingTotalToken1In[currentTradingEpoch]); - if(TFHE.isInitialized(pendingTotalBurns[currentTradingEpoch])) burnedTotal = TFHE.decrypt(pendingTotalBurns[currentTradingEpoch]); + if (TFHE.isInitialized(reserve0PendingAdd)) reserve0PendingAddDec = TFHE.decrypt(reserve0PendingAdd); + if (TFHE.isInitialized(reserve1PendingAdd)) reserve1PendingAddDec = TFHE.decrypt(reserve1PendingAdd); + if (TFHE.isInitialized(pendingTotalMints[currentTradingEpoch])) + mintedTotal = TFHE.decrypt(pendingTotalMints[currentTradingEpoch]); + if (TFHE.isInitialized(pendingTotalToken0In[currentTradingEpoch])) + amount0In = TFHE.decrypt(pendingTotalToken0In[currentTradingEpoch]); + if (TFHE.isInitialized(pendingTotalToken1In[currentTradingEpoch])) + amount1In = TFHE.decrypt(pendingTotalToken1In[currentTradingEpoch]); + if (TFHE.isInitialized(pendingTotalBurns[currentTradingEpoch])) + burnedTotal = TFHE.decrypt(pendingTotalBurns[currentTradingEpoch]); } function batchSettlement() external { @@ -289,7 +293,8 @@ contract EncryptedDEXPair is EncryptedERC20 { amount1InMinusFee + reserve1 - uint32( - (uint64(reserve1) * uint64(reserve0)) / (uint64(reserve0) + uint64(amount0InMinusFee) - uint64(amount0Out)) + (uint64(reserve1) * uint64(reserve0)) / + (uint64(reserve0) + uint64(amount0InMinusFee) - uint64(amount0Out)) ); } else { // here we do the opposite, first sell token0 at current token0 price then swap remaining token1 according to AMM formula @@ -298,7 +303,8 @@ contract EncryptedDEXPair is EncryptedERC20 { amount0InMinusFee + reserve0 - uint32( - (uint64(reserve0) * uint64(reserve1)) / (uint64(reserve1) + uint64(amount1InMinusFee) - uint64(amount1Out)) + (uint64(reserve0) * uint64(reserve1)) / + (uint64(reserve1) + uint64(amount1InMinusFee) - uint64(amount1Out)) ); } totalToken0ClaimableSwap[currentTradingEpoch] = amount0Out; diff --git a/test/EncryptedDEX/EncryptedDEX.ts b/test/EncryptedDEX/EncryptedDEX.ts index 76ac5b3..77adb9d 100644 --- a/test/EncryptedDEX/EncryptedDEX.ts +++ b/test/EncryptedDEX/EncryptedDEX.ts @@ -203,7 +203,7 @@ describe("Private DEX", function () { await tx23.wait(); console.log("Eve submitted a swap order at tradingEpoch ", await pair.currentTradingEpoch(), "\n"); - const tx24 = await pair.batchSettlement({ gasLimit : 10_000_000 }); + const tx24 = await pair.batchSettlement({ gasLimit: 10_000_000 }); await tx24.wait(); console.log( @@ -243,7 +243,7 @@ describe("Private DEX", function () { balance = await getPrivateBalanceERC20(pairAddress, "carol"); console.log("Carol now owns a private balance of ", balance, " liquidity tokens \n"); - const tx29 = await pair.batchSettlement({ gasLimit : 10_000_000 }); + const tx29 = await pair.batchSettlement({ gasLimit: 10_000_000 }); await tx29.wait(); console.log(