Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from ionicprotocol/test/lev-pos-test-fixes
Browse files Browse the repository at this point in the history
Levered positions tests fixes
  • Loading branch information
carlomazzaferro authored Sep 21, 2023
2 parents 38b45d4 + bede6fb commit b19aa43
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions contracts/test/AccrueInterestTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ contract AccrueInterestTest is UpgradesBaseTest {
}

function testMintGated() public fork(POLYGON_MAINNET) {
address newMarket = 0x26EA46e975778662f98dAa0E7a12858dA9139262;
address assetWhale = 0xEd41f5967252248412E6C69475ae8a5A4274A6f8;
address newMarket = 0x71A7037a42D0fB9F905a76B7D16846b2EACC59Aa;
address assetWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb;
// approve spending
vm.startPrank(assetWhale);
IERC20Upgradeable(CErc20Delegate(newMarket).underlying()).approve(newMarket, 1e6);
Expand Down
6 changes: 1 addition & 5 deletions contracts/test/AnyLiquidationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,6 @@ contract AnyLiquidationTest is BaseTest {

function testRawLiquidation() public debuggingOnly fork(POLYGON_MAINNET) {
vm.prank(ap.getAddress("deployer"));
_functionCall(
address(fsl),
hex"a68ee119000000000000000000000000f93a5f0a4925eec32cd585641c88a498523f383c0000000000000000000000000000000000000000000000000000013f7702e3b7000000000000000000000000a9736ba05de1213145f688e4619e5a7e0dcf4c72000000000000000000000000b3d83f2cab787adcb99d4c768f1eb42c8734b5630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070085a09d30d6f8c4ecf6ee10120d1847383bb570000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"raw liquidation failed"
);
_functionCall(address(0), hex"00", "raw liquidation failed");
}
}
41 changes: 22 additions & 19 deletions contracts/test/LeveredPositionTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract LeveredPositionLensTest is BaseTest {
}
}

function testPrintLeveredPositions() public fork(POLYGON_MAINNET) {
function testPrintLeveredPositions() public debuggingOnly fork(POLYGON_MAINNET) {
address[] memory markets = factory.getWhitelistedCollateralMarkets();

emit log_named_array("markets", markets);
Expand Down Expand Up @@ -518,9 +518,10 @@ contract Jbrl2BrlLeveredPositionTest is LeveredPositionTest {
}
}

contract BombTDaiLeveredPositionTest is LeveredPositionTest {
contract BombWbnbLeveredPositionTest is LeveredPositionTest {
uint256 depositAmount = 100e18;
address whale = 0xe7B7dF67C1fe053f1C6B965826d3bFF19603c482;
address wbnbWhale = 0x57E30beb8054B248CE301FeabfD0c74677Fa40f0;
uint256 ratioOnCreation = 1.0e18;
uint256 minBorrowNative = 1e17;

Expand All @@ -537,8 +538,8 @@ contract BombTDaiLeveredPositionTest is LeveredPositionTest {
abi.encode(minBorrowNative)
);

address xMarket = 0x11771Cd06dB2633EF6A0cEef027E8e1A120d3f25; // BOMB
address yMarket = 0x66b05c1711094c32c99a65d2734C72dE0A1C3c81; // tdai
address xMarket = 0x9B6E1039103812E0dcC1100a158e4a68014b2571; // BOMB
address yMarket = 0x9dD00920f5B74A31177cbaB834AB0904703c31B1; // WBNB

collateralMarket = ICErc20(xMarket);
stableMarket = ICErc20(yMarket);
Expand All @@ -548,16 +549,18 @@ contract BombTDaiLeveredPositionTest is LeveredPositionTest {
IERC20Upgradeable collateralToken = IERC20Upgradeable(collateralMarket.underlying());
IERC20Upgradeable stableToken = IERC20Upgradeable(stableMarket.underlying());
// call amountOutAndSlippageOfSwap to cache the slippage
vm.startPrank(whale);
{
vm.startPrank(whale);
collateralToken.approve(address(registry), 1e36);
registry.amountOutAndSlippageOfSwap(collateralToken, 1e18, stableToken);
collateralToken.transfer(address(this), depositAmount);
vm.stopPrank();

vm.startPrank(wbnbWhale);
stableToken.approve(address(registry), 1e36);
registry.amountOutAndSlippageOfSwap(stableToken, 1e18, collateralToken);

collateralToken.transfer(address(this), depositAmount);
vm.stopPrank();
}
vm.stopPrank();

vm.prank(whale);
collateralToken.transfer(address(this), depositAmount);
Expand Down Expand Up @@ -610,7 +613,7 @@ contract PearlUsdrWUsdrUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0x06F61E22ef144f1cC4550D40ffbF681CB1C3aCAF;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0x03Fa7A2628D63985bDFe07B95d4026663ED96065;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -631,7 +634,7 @@ contract PearlUsdcUsdrLeveredPositionTest is LeveredPositionTest {

address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address usdcMarket = 0x71A7037a42D0fB9F905a76B7D16846b2EACC59Aa;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract
address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb;

IRedemptionStrategy liquidator = new SolidlySwapLiquidator();
Expand Down Expand Up @@ -679,7 +682,7 @@ contract PearlUsdrUsdcUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0x83DF24fE1B1eBF38048B91ffc4a8De0bAa88b891;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0x97Bd59A8202F8263C2eC39cf6cF6B438D0B45876; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -702,7 +705,7 @@ contract PearlUsdrDaiUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0xBcE30B4D78cEb9a75A1Aa62156529c3592b3F08b;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0x85Fa2331040933A02b154579fAbE6A6a5A765279; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -725,7 +728,7 @@ contract PearlUsdrTngblUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0x2E870Aeee3D9d1eA29Ec93d2c0A99A4e0D5EB697;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0xdaeF32cA8D699015fcFB2884F6902fFCebE51c5b; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -748,7 +751,7 @@ contract PearlUsdrWbtcUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0xffc8c8d747E52fAfbf973c64Bab10d38A6902c46;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0x39976f6328ebA2a3C860b7DE5cF2c1bB41581FB8; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -771,7 +774,7 @@ contract PearlUsdrWethUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0x343D9a8D2Bc6A62390aEc764bb5b900C4B039127;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0x7D02A8b758791A03319102f81bF61E220F73e43D; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -794,7 +797,7 @@ contract PearlUsdrMaticUsdrLpLeveredPositionTest is LeveredPositionTest {
address lpTokenMarket = 0xfacEdA4f9731797102f040380aD5e234c92d1942;
address usdrMarket = 0x1F11940B239D129dE0e5D30A3E59089af5Ecd6ed;
address lpTokenWhale = 0xdA0AfBeEEBef6dA2F060237D35cab759b99B13B6; // Thena Gauge
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265;
address usdrWhale = 0x00e8c0E92eB3Ad88189E7125Ec8825eDc03Ab265; // wUSDR contract

_configurePair(lpTokenMarket, usdrMarket);
_fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale);
Expand All @@ -816,7 +819,7 @@ contract RetroCashAUsdcCashLeveredPositionTest is LeveredPositionTest {
// LP token underlying xCASH-USDC
address lpTokenMarket = 0x1D2A7078a404ab970f951d5A6dbECD9e24838FB6;
address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa;
address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa;
address lpTokenWhale = 0x35a499c15b4dDCf7e98628D415346B9795CCa80d;
address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0;

_configurePair(lpTokenMarket, cashMarket);
Expand All @@ -838,7 +841,7 @@ contract RetroUsdcAUsdcCashLeveredPositionTest is LeveredPositionTest {
// LP token underlying xCASH-USDC
address lpTokenMarket = 0x1D2A7078a404ab970f951d5A6dbECD9e24838FB6;
address usdcMarket = 0x38EbA94210bCEf3F9231E1764EE230abC14D1cbc;
address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa;
address lpTokenWhale = 0x35a499c15b4dDCf7e98628D415346B9795CCa80d;
address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb;

_configurePair(lpTokenMarket, usdcMarket);
Expand Down Expand Up @@ -898,7 +901,7 @@ contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest {
function afterForkSetUp() internal override {
super.afterForkSetUp();

uint256 depositAmount = 2e18;
uint256 depositAmount = 1e18;

// LP token underlying xUSDC-WETH05
address lpTokenMarket = 0xC7cA03A0bE1dBAc350E5BfE5050fC5af6406490E;
Expand Down
8 changes: 6 additions & 2 deletions contracts/test/LiquidatorsRegistryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.10;

import { LiquidatorsRegistry } from "../liquidators/registry/LiquidatorsRegistry.sol";
import { LiquidatorsRegistryExtension } from "../liquidators/registry/LiquidatorsRegistryExtension.sol";
import { LiquidatorsRegistrySecondExtension } from "../liquidators/registry/LiquidatorsRegistrySecondExtension.sol";
import { ILiquidatorsRegistry } from "../liquidators/registry/ILiquidatorsRegistry.sol";
import { IRedemptionStrategy } from "../liquidators/IRedemptionStrategy.sol";
import { MasterPriceOracle } from "../oracles/MasterPriceOracle.sol";
Expand Down Expand Up @@ -47,9 +48,12 @@ contract LiquidatorsRegistryTest is BaseTest {
function upgradeRegistry() internal {
DiamondBase asBase = DiamondBase(address(registry));
address[] memory exts = asBase._listExtensions();
LiquidatorsRegistryExtension newExt = new LiquidatorsRegistryExtension();
LiquidatorsRegistryExtension newExt1 = new LiquidatorsRegistryExtension();
LiquidatorsRegistrySecondExtension newExt2 = new LiquidatorsRegistrySecondExtension();
vm.prank(SafeOwnable(address(registry)).owner());
asBase._registerExtension(newExt, DiamondExtension(exts[0]));
asBase._registerExtension(newExt1, DiamondExtension(exts[0]));
vm.prank(SafeOwnable(address(registry)).owner());
asBase._registerExtension(newExt2, DiamondExtension(exts[1]));
}

function _functionCall(
Expand Down

0 comments on commit b19aa43

Please sign in to comment.