Skip to content

Commit

Permalink
simple test leverage working
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Mar 11, 2024
1 parent ef31176 commit 5d8dc69
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
7 changes: 2 additions & 5 deletions contracts/interfaces/external/pendle/IPRouter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;


interface IPLimitOrderType {
enum OrderType {
SY_FOR_PT,
Expand Down Expand Up @@ -58,15 +57,14 @@ struct FillOrderParams {
uint256 makingAmount;
}


struct SwapData {
SwapType swapType;
SwapTypePendle swapType;
address extRouter;
bytes extCalldata;
bool needScale;
}

enum SwapType {
enum SwapTypePendle {
NONE,
KYBERSWAP,
ONE_INCH,
Expand Down Expand Up @@ -111,7 +109,6 @@ struct LimitOrderData {
bytes optData;
}


interface IPRouter {
event SwapPtAndSy(
address indexed caller,
Expand Down
4 changes: 2 additions & 2 deletions contracts/swapper/LevSwapper/BaseLevSwapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract contract BaseLevSwapper is Swapper {
// Hook to add liquidity to the underlying protocol
amountOut = _add(data);
// Deposit into the AngleStaker
angleStaker().deposit(amountOut, to);
if (address(angleStaker()) != address(0)) angleStaker().deposit(amountOut, to);
} else {
uint256 toUnstake;
uint256 toRemove;
Expand All @@ -63,7 +63,7 @@ abstract contract BaseLevSwapper is Swapper {
(uint256, uint256, IERC20[], bytes[], bytes)
);
// Should transfer the token to the contract this will claim the rewards for the current owner of the wrapper
angleStaker().withdraw(toUnstake, address(this), address(this));
if (address(angleStaker()) != address(0)) angleStaker().withdraw(toUnstake, address(this), address(this));
_remove(toRemove, data);
// Taking the same example as in the `leverage` side, you can withdraw USDC, DAI and USDT while wanting to
// to repay a debt in agEUR so you need to do a multiswap.
Expand Down
13 changes: 7 additions & 6 deletions contracts/swapper/LevSwapper/pendle/PendleLevSwapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract PendleLevSwapper is BaseLevSwapper {
) BaseLevSwapper(_core, _uniV3Router, _oneInch, _angleRouter) {
if (address(collateral()) != address(0)) {
collateral().safeIncreaseAllowance(address(SY()), type(uint256).max);
SY().safeIncreaseAllowance(address(pendleRouter()), type(uint256).max);
IERC20(address(SY())).safeIncreaseAllowance(address(pendleRouter()), type(uint256).max);
}
}

Expand All @@ -31,14 +31,15 @@ abstract contract PendleLevSwapper is BaseLevSwapper {
function _add(bytes memory) internal override returns (uint256 amountOut) {
uint256 amount = collateral().balanceOf(address(this));
// It needs to be deposited directly onto `YT`contracts to mint both PT and YT tokens
uint256 amountSharesOut = SY().deposit(address(this), collateral(), amount, 0);
uint256 amountSharesOut = SY().deposit(address(this), address(collateral()), amount, 0);
LimitOrderData memory limit;
(amountOut, ) = pendleRouter().swapExactSyForPt(
address(this),
market(),
address(market()),
amountSharesOut,
0,
ApproxParams({ guessMin: 0, guessMax: 2 * amountSharesOut, guessOffchain: 0, maxIteration: 10, eps: 1e15 }),
hex""
limit
);
}

Expand All @@ -47,11 +48,11 @@ abstract contract PendleLevSwapper is BaseLevSwapper {
uint256 minAmountOut = abi.decode(data, (uint256));
PT().safeTransfer(address(market()), amount);
(uint256 amountSy, ) = market().swapExactPtForSy(address(SY()), amount, hex"");
SY.redeem(address(this), amountSy, collateral(), minAmountOut, true);
SY().redeem(address(this), amountSy, address(collateral()), minAmountOut, true);
}

/// @notice Router for simpler swap
function pendleRouter() public pure virtual returns (IPRouter) {
function pendleRouter() public pure returns (IPRouter) {
return IPRouter(0x00000000005BBB0EF59571E58418F9a4357b68A0);
}

Expand Down
15 changes: 10 additions & 5 deletions contracts/swapper/LevSwapper/pendle/PendleLevSwapperTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,33 @@ contract PendleLevSwapperTemplate is PendleLevSwapper {
IAngleRouterSidechain _angleRouter
) PendleLevSwapper(_core, _uniV3Router, _oneInch, _angleRouter) {}

/// @inheritdoc BaseLevSwapper
function angleStaker() public pure override returns (IBorrowStaker) {
return IBorrowStaker(address(0));
}

/// @inheritdoc PendleLevSwapper
function PT() public pure virtual returns (IERC20) {
function PT() public pure override returns (IERC20) {
return IERC20(address(0));
}

/// @inheritdoc PendleLevSwapper
function SY() public pure virtual returns (IStandardizedYield) {
function SY() public pure override returns (IStandardizedYield) {
return IStandardizedYield(address(0));
}

/// @inheritdoc PendleLevSwapper
function YT() public pure virtual returns (IPYieldTokenV2) {
function YT() public pure override returns (IPYieldTokenV2) {
return IPYieldTokenV2(address(0));
}

/// @inheritdoc PendleLevSwapper
function market() public pure virtual returns (IPMarketV3) {
function market() public pure override returns (IPMarketV3) {
return IPMarketV3(address(0));
}

/// @inheritdoc PendleLevSwapper
function collateral() public pure virtual returns (IERC20) {
function collateral() public pure override returns (IERC20) {
return IERC20(address(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,33 @@ contract PendleLevSwapperRenzo is PendleLevSwapper {
IAngleRouterSidechain _angleRouter
) PendleLevSwapper(_core, _uniV3Router, _oneInch, _angleRouter) {}

/// @inheritdoc BaseLevSwapper
function angleStaker() public pure override returns (IBorrowStaker) {
return IBorrowStaker(address(0));
}

/// @inheritdoc PendleLevSwapper
function PT() public pure virtual returns (IERC20) {
function PT() public pure override returns (IERC20) {
return IERC20(address(0xeEE8aED1957ca1545a0508AfB51b53cCA7e3c0d1));
}

/// @inheritdoc PendleLevSwapper
function SY() public pure virtual returns (IStandardizedYield) {
function SY() public pure override returns (IStandardizedYield) {
return IStandardizedYield(address(0x22E12A50e3ca49FB183074235cB1db84Fe4C716D));
}

/// @inheritdoc PendleLevSwapper
function YT() public pure virtual returns (IPYieldTokenV2) {
return IPYieldTokenV2(address(0x256fb830945141f7927785c06b65dabc3744213c));
function YT() public pure override returns (IPYieldTokenV2) {
return IPYieldTokenV2(address(0x256Fb830945141f7927785c06b65dAbc3744213c));
}

/// @inheritdoc PendleLevSwapper
function market() public pure virtual returns (IPMarketV3) {
function market() public pure override returns (IPMarketV3) {
return IPMarketV3(address(0xDe715330043799D7a80249660d1e6b61eB3713B3));
}

/// @inheritdoc PendleLevSwapper
function collateral() public pure virtual returns (IERC20) {
return IERC20(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
function collateral() public pure override returns (IERC20) {
return IERC20(address(0xbf5495Efe5DB9ce00f80364C8B423567e58d2110));
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"size:dev": "FOUNDRY_PROFILE=dev forge build --skip test --sizes",
"prettier": "prettier --write '**/*.sol'",
"lint": "yarn lint:check --fix",
"lint:check": "solhint --max-warnings 20 \"**/*.sol\"",
"lint:check": "solhint --max-warnings 20 \"**/*.sol\""
},
"keywords": [],
"author": "Angle Core Team",
Expand Down
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
borrow/=lib/borrow-contracts/contracts
borrow/=lib/borrow-contracts/contracts
utils/=lib/utils
9 changes: 7 additions & 2 deletions test/foundry/swapper/pendle/PendleLevSwapperTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import "borrow/interfaces/ICoreBorrow.sol";
import "../../../../contracts/mock/MockTokenPermit.sol";
import { SwapType, BaseLevSwapper, PendleLevSwapperRenzo, PendleLevSwapper, Swapper, IUniswapV3Router, IAngleRouterSidechain } from "../../../../contracts/swapper/LevSwapper/pendle/implementations/PendleLevSwapperRenzo.sol";

interface IStETH {
function submit(address) external payable returns (uint256);
}

contract PendleLevSwapperTest is BaseTest {
using stdStorage for StdStorage;
using SafeERC20 for IERC20;
Expand All @@ -27,7 +31,7 @@ contract PendleLevSwapperTest is BaseTest {
function setUp() public override {
super.setUp();

_ethereum = vm.createFork(vm.envString("ETH_NODE_URI_ARBITRUM"), 19413820);
_ethereum = vm.createFork(vm.envString("ETH_NODE_URI_MAINNET"), 19413820);
vm.selectFork(_ethereum);

// reset coreBorrow because the `makePersistent()` doens't work on my end
Expand Down Expand Up @@ -82,9 +86,10 @@ contract PendleLevSwapperTest is BaseTest {

function testLeverageSuccess(uint256 amount) public {
amount = bound(amount, 10 ** 15, 10 ** 20);

deal(address(collateral), address(_alice), amount);

vm.startPrank(_alice);

// intermediary variables
bytes[] memory oneInchData = new bytes[](0);

Expand Down

0 comments on commit 5d8dc69

Please sign in to comment.