-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simulation tests and preview functions accuracy tests (#83)
* fix: set offset factor when deploying * feat: base contract for integration tests * feat: e2e simulation * wip: measure accuracy of preview functions * chore: add comments * fix: deploy scripts constructors * fix: use `assets.collateral` in `convertCollateralToUnderlying` * feat: handle surplus equity in `rebalanceBeforeWithdraw` * Enforces a reversion in case the `minForRebalance` limit is breached (#88) * feat: add check for over exposure * build: update failing tests * build: add test case for `RatioOutsideRange` * build: remove duplicate test file * Reversion due to high slippage in `redeem` and `deposit` (#85) * feat: extend `SwapperStorage` to contain oracles and slippages for tokens * feat: setters/getters for new `Swapper` storage variables * feat: add slippage limit check * style: reorder functions * feat: alter how max slippage works * style: forge fmt * build: setter tests for new swapper functions * fix: minor issue in accounting for `fromAmount` in swap * build: add slippage to `SwapAdapterMock` and test slippage check in `Swapper` * feat: additional parameters in initializers * build: update tests * fix: maxDeviationUSD calclulation * style: forge fmt * build: test slippageTooHigh setup WIP * style: forge fmt * build: test `rebalanceUp` reversion when slippage is too high * fix: remove commented code * WIP: test helper * build: testFail case for `rebalanceDownToDebt` when slippage is too high * style: forge fmt * build: setup context for testing `MaxSlippageExceeded` reversion in tests * build: tests for slippage reversion in `deposit` and `redeem` * fix: typo, deposit reversion test case * Update fork block number and adjust test cases (#84) * build: update fork block number constant * build: update supply/borrow caps in lending pool * fix: WIP debugging LoanLogic tests * fix: `_changeSupplyAndBorrowCap` typo * style: forge fmt * fix: add `CbETH` supply and borrow caps in `LoopStrategy` constructor * fix: order of operations in convertUSDToAsset conversion * fix: previewRedeem tests precision * build: increase gap of slippage in slippage test * natspec: extend comment * fix: increase slippage in mockadapter * style: forge fmt --------- Co-authored-by: DuXXuD <duxxud@gmail.com> * build: add capacity for `SwapperMock` to have real/estimated offsets for testing * build: add tests for surplus equity due to swap * fix: remove console logs * fix: deploy config change * feat: add integration base test * fix: move out preview accuracy testing * fix: handle maxSlippageUSD = 0 * chore: renaming * chore: move scenarios to unit folder * chore: remove unused imports * chore: gitignore simulation output * fix: moving scenario tests * fix: moving scenario tests * chore: imports fix * upd gitignore * gitignore: ignore simulation output * fix: import console * fix: gitignore test failing without dir * add gitignore simulation output back --------- Co-authored-by: NouDaimon <peric.iason@gmail.com> Co-authored-by: NouDaimon <81045441+NouDaimon@users.noreply.github.com>
- Loading branch information
1 parent
58a2eba
commit 697b389
Showing
18 changed files
with
662 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Base mainnet RPC, used in tests on a forked mainnet | ||
BASE_MAINNET_RPC_URL= | ||
# Tenderly base fork used for deployments to testnet | ||
TENDERLY_RPC_FORK= | ||
FORK_RPC= | ||
# Deployer private key | ||
DEPLOYER_PK= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ out/ | |
# pnpm | ||
pnpm-lock.yaml | ||
|
||
# simulation output | ||
test/integration/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
pragma solidity ^0.8.21; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { IACLManager } from "@aave/contracts/interfaces/IACLManager.sol"; | ||
import { DeployForkScript } from "../../deploy/DeployFork.s.sol"; | ||
import { VmSafe } from "forge-std/Vm.sol"; | ||
|
||
/// @notice Setup contract for the integration tests | ||
/// @notice deploys all related contracts on the fork, and setup lending pool parameters | ||
contract IntegrationBase is Test, DeployForkScript { | ||
|
||
string internal BASE_RPC_URL = vm.envString("BASE_MAINNET_RPC_URL"); | ||
|
||
VmSafe.Wallet public testDeployer = vm.createWallet("deployer"); | ||
|
||
function setUp() public virtual { | ||
vm.createSelectFork(BASE_RPC_URL); | ||
|
||
_setDeployer(testDeployer.privateKey); | ||
|
||
address aclAdmin = poolAddressesProvider.getACLAdmin(); | ||
vm.startPrank(aclAdmin); | ||
IACLManager(poolAddressesProvider.getACLManager()).addPoolAdmin( | ||
testDeployer.addr | ||
); | ||
poolAddressesProvider.setACLAdmin(testDeployer.addr); | ||
vm.stopPrank(); | ||
|
||
_deployWrappedCbETH(); | ||
_setupWrappedCbETH(); | ||
_setupWETHborrowCap(); | ||
|
||
_deploySwapper(); | ||
_deploySwapAdapters(); | ||
_setupSwapperRoutes(); | ||
|
||
_deployLoopStrategy(); | ||
|
||
_setupRoles(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
pragma solidity ^0.8.21; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { IntegrationBase } from "./IntegrationBase.sol"; | ||
|
||
/// @notice Test confirming deployment is done correctly and we can deposit and redeem funds | ||
contract IntegrationBaseTest is IntegrationBase { | ||
|
||
/// @dev test confirming deployment is done correctly and we can deposit and redeem funds | ||
function test_integrationBaseTest() public { | ||
address user = makeAddr("user"); | ||
|
||
uint256 amount = 1 ether; | ||
|
||
vm.startPrank(user); | ||
deal(address(CbETH), user, amount); | ||
CbETH.approve(address(strategy), amount); | ||
|
||
uint256 shares = strategy.deposit(amount, user); | ||
|
||
strategy.redeem(shares / 2, user, user); | ||
|
||
vm.stopPrank(); | ||
} | ||
} |
Oops, something went wrong.