Closed juuroudojo closed 1 year ago
Some immediate things that have to be done:
This has lead to you breaking many existing test files because you made extra changes to the resolver contracts + the correct formatting and linting were not done.
1) IbAlluoUSD and Handler "before each" hook for "Test upgradeability of original ibAlluo contract": Error: missing argument: in Contract constructor (count=3, expectedCount=4, code=MISSING_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18) at ContractFactory.
(node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16) at step (node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53) at E:\Coding Projects\liquidity-direction-protocol\node_modules\@ethersproject\contracts\lib\index.js:23:71 at new Promise ( ) at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12) at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16) 2) IbAlluo and Exchange "before each" hook for "The exchange should be working normally: Check all swap combinations": Error: missing argument: in Contract constructor (count=3, expectedCount=4, code=MISSING_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18) at ContractFactory.
(node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16) at step (node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53) at E:\Coding Projects\liquidity-direction-protocol\node_modules\@ethersproject\contracts\lib\index.js:23:71 at new Promise ( ) at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12) at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16) 3) Handler and different adapters "before each" hook for "Depositing 1 wbtc and immediately attempting to withdraw 0.5 should put you in the waiting list": Error: missing argument: in Contract constructor (count=3, expectedCount=4, code=MISSING_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18) at ContractFactory.
(node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16) at step (node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53) at E:\Coding Projects\liquidity-direction-protocol\node_modules\@ethersproject\contracts\lib\index.js:23:71 at new Promise ( ) at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12) at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16) 4) IbAlluoUSD and Handler "before each" hook for "Test grabbing block number through timestamp using binary search": Error: missing argument: in Contract constructor (count=3, expectedCount=4, code=MISSING_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18) at ContractFactory.
(node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16) at step (node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53) at E:\Coding Projects\liquidity-direction-protocol\node_modules\@ethersproject\contracts\lib\index.js:23:71 at new Promise ( ) at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12) at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16) 5) Superfluid resolver with StIbAlluo/IbAlluo "before each" hook for "When critical (8 hr or less buffer), checker should return true and liquidateSender should wrap ibAlluos to prevent liquidation.": Error: missing argument: in Contract constructor (count=3, expectedCount=4, code=MISSING_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18) at ContractFactory.
(node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16) at step (node_modules\@ethersproject\contracts\lib\index.js:48:23) at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53) at E:\Coding Projects\liquidity-direction-protocol\node_modules\@ethersproject\contracts\lib\index.js:23:71 at new Promise ( ) at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12) at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16)
Please fix these tests and next time make sure to run all tests before you push - though this is now taken care of with pre-push hooks running npx hardhat test.
It is important to see that other parts of the protocol are not broken by your changes.
About BufferManager.sol specifically, I will break it into two parts : The adapter refilling logic and the bridging logic.
Bridging Checker() -
Let's cut down on the mapping ibAlluoToToken because we can actually grab this token (USDC for USD for example) by querying the primaryToken of the adapter. Lower maintenance there. So if we change the primary token in the adapter for some reason, we don't need to come and reset it in the BufferManager.
For readability, can we extract the if condition for bridging line 133-134 into a separate view function?
What is the particular reason you don't put the minBridgeAmount in native token decimals and instead use wei then convert this to toekn decimals inside the condition? It makes it confusing what this minBridgeAmount should be enumerated in.
Overall the logic is buggy. At the moment, it will fail this case where:
a. We need to refill the adapters but there are no pending withdrawals + there are funds in the buffermanager. b. Gelato calls checker and it says - no pending withdrawals?, then bridge this over to mainnet.
In fact, it should also check that there are no required refills. There are multiple ways to approach this, including changing the order in which you do the checks --> do the refill check first in the loop, then the adapter pendign wtihdrawal.
Lines 126,127 - Don't redeclare these variables
Relay fee pct line 142 - please make sure that this is a uint stored inside the contract that we can change.
In the case that the adapter requires a refill, your gelato resolver will ignore the refill request if we do not have enough funds to fully top it up. eg. need 1000 USDC but we only have 800USDC in the buffer manager, it returns false.
It should instead be - pull 200 usdc from gnosis and then send 800 + 200 = 1000 usdc back to the adapter - barring that we have not topped up more than the limit. More on this in my next comment about the Buffer refilling logic.
Buffer Refilling In General
The logic is not following the specs of the ticket correctly but here are details for each function: https://app.dework.xyz/alluo/alluo-smart-contra?taskId=0b15da6d-5a43-4384-ac1e-a655caf0bc78
1. refillBuffer()
As mentioned in point 6. of https://github.com/GetAlluo/liquidity-direction-protocol/pull/125#issuecomment-1360857863,
the refilledPerEpoch parameter should only be increased everytime we take funds from gnosis to top up the buffer.
At the moment, all it does is move funds from the adapter --> buffermanager --> adapter , which is pointless. It needs to be complemented with the gnosis sending funds to top up the buffer.
Please look at how the initial draft of the contract was written:
But in particular, remember that the refilledPerEpoch should only be incremented with the funds taken from gnosis, not the funds existing in the buffer from other deposits.
2. adapterRequiredRefill()
There is a case where there is no return value : if actualAmount< expectedAmount && difference* 10000/expectedAmount <= 500.
This will cause the checker to revert.
3. confirmEpoch()
This needs to be tested. I know I wrote this as a draft but there are no tests for this, which is extremely important for this ticket.
Bridging + AnyCall swap()
I suppose we will need a catchup about this because a ticket has not been made for this bridging part so you might be confused with what needs to happen.
More generally about testing:
There are insufficient unit and integration tests for these. As there are quite a few complex if statements, we should explore all the possible routes.
Check all permutations of the coniditions for which the checker() returns true for bridging:
Check all the permutations for which we refill the buffer and the manner in which the refilling happens (funds from buffermanager --> adapter, funds from buffer manager + gnosis -->adapter, funds only from gnosis --> adapter )
It might be helpful to extract the two gelato checker view functions and just have two separate checkers.
Unit tests for isAdapterPendingWithdrawals returning correct values
Unit tests for adapterRequiredRefill - please reference point 2. from https://github.com/GetAlluo/liquidity-direction-protocol/pull/125#issuecomment-1360864379
Unit tests for _confirmEpoch and the different cases for the epoch system to make sure it is working as intended.
eg. everytime time exceeds epoch length, we are correctly starting a new epoch
We can discuss integration tests later on after these are complete.
All comments from above, down to this one were made at commit :
VoteExecutorSlave Line 203: Please make getEntries a view function.
VoteExecutorSlave: Create an admin function that allows gnosis to set the entries array manually in the case of mulitchain anycall error. It will also make testing much easier.
Write unit tests for the two functions above.
BufferManager: Please refactor adapterRequiredRefill using inverted ifs.
BufferManager: Can you write direct unit tests for ConfirmEpoch because I wrote this epoch thing ages ago and Ididnt have a chance to test every branch.
I am still reviewing other core functionalities but will need more time for that.
Once u make changes above and finish addressing the points from the previous review, can you start deploying everything to Mumbai so that by the time I finish my review, we can easily integrate it into mumbai but upgrading the contracts.
The only thing is, please talk to Alex about contracts which are overlapping, especially the adapters. I asked him to make them upgradeable so there will be some conflict there.
Review as of my https://github.com/GetAlluo/liquidity-direction-protocol/pull/125/commits/f90176a43550bd7f74c4c5b5cebd6805bfe89dd6 that fixed a bug with confirmEpoch.
Generally, most comments below are about refactoring and making it more readable because it is quite confusing at the moment to review different cases myself.
Once you do this, I'll do a final check of any logic that might be buggy.
Contract:
In initialize, please grant GELATO role to gnosis.
checker() please refactor 131-132 if statements.
canRefill() please refactor:
refillBuffer()
Please refactor canBridge() to clean up double if.
Please create interface files for CallProxy and ISpokePool and import them instead.
I'll ask you to add some events later down the line so we can keep track of things better.
Testing
Write unit test for speedUp.
Write unit tests for confirmEpoch and go through different test cases to confirm what I went through with you during the debugging session I did.
Test line 358.
Write unit test for setRelayer fee pct (just as a formality).
closes #114