Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carson/cake decoders #30

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "nucleus-deployments"]
path = nucleus-deployments
url = [email protected]:Ion-Protocol/nucleus-deployments.git
[submodule "lib/v3-periphery"]
path = lib/v3-periphery
url = https://github.com/Uniswap/v3-periphery
1 change: 1 addition & 0 deletions lib/v3-periphery
Submodule v3-periphery added at 068238
25 changes: 25 additions & 0 deletions src/base/DecodersAndSanitizers/EarnETHDecoderAndSanitizer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { BaseDecoderAndSanitizer } from "./BaseDecoderAndSanitizer.sol";
import { NativeWrapperDecoderAndSanitizer } from "./Protocols/NativeWrapperDecoderAndSanitizer.sol";
import { UniswapV3DecoderAndSanitizer } from "src/base/DecodersAndSanitizers/Protocols/UniswapV3DecoderAndSanitizer.sol";
import { MasterChefV3DecoderAndSanitizer } from
"src/base/DecodersAndSanitizers/Protocols/MasterChefV3DecoderAndSanitizer.sol";
import { PendleRouterDecoderAndSanitizer } from
"src/base/DecodersAndSanitizers/Protocols/PendleRouterDecoderAndSanitizer.sol";

contract EarnETHDecoderAndSanitizer is
NativeWrapperDecoderAndSanitizer,
UniswapV3DecoderAndSanitizer,
MasterChefV3DecoderAndSanitizer,
PendleRouterDecoderAndSanitizer
{
constructor(
address _boringVault,
address _uniswapV3NonFungiblePositionManager
)
UniswapV3DecoderAndSanitizer(_uniswapV3NonFungiblePositionManager)
BaseDecoderAndSanitizer(_boringVault)
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { BaseDecoderAndSanitizer } from "src/base/DecodersAndSanitizers/BaseDecoderAndSanitizer.sol";

abstract contract MasterChefV3DecoderAndSanitizer is BaseDecoderAndSanitizer {
function harvest(uint256, address _to) external pure virtual returns (bytes memory addressesFound) {
return abi.encodePacked(_to);
}

function withdraw(uint256, address _to) external pure virtual returns (bytes memory addressesFound) {
return abi.encodePacked(_to);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ abstract contract PendleRouterDecoderAndSanitizer is BaseDecoderAndSanitizer {
//============================== ERRORS ===============================

error PendleRouterDecoderAndSanitizer__AggregatorSwapsNotPermitted();
error PendleRouterDecoderAndSanitizer__LimitOrderSwapsNotPermitted();

//============================== PENDLEROUTER ===============================

Expand Down Expand Up @@ -164,4 +165,72 @@ abstract contract PendleRouterDecoderAndSanitizer is BaseDecoderAndSanitizer {
addressesFound = abi.encodePacked(addressesFound, markets[i]);
}
}

function addLiquiditySingleTokenKeepYt(
address receiver,
address market,
uint256 minLpOut,
uint256 minYtOut,
DecoderCustomTypes.TokenInput calldata input
)
external
pure
virtual
returns (bytes memory addressesFound)
{
if (
input.swapData.swapType != DecoderCustomTypes.SwapType.NONE || input.swapData.extRouter != address(0)
|| input.pendleSwap != address(0) || input.tokenIn != input.tokenMintSy
) revert PendleRouterDecoderAndSanitizer__AggregatorSwapsNotPermitted();

addressesFound = abi.encodePacked(receiver, market, input.tokenIn);
}

function addLiquiditySingleToken(
address receiver,
address market,
uint256 minLpOut,
DecoderCustomTypes.ApproxParams calldata guessPtReceivedFromSy,
DecoderCustomTypes.TokenInput calldata input,
DecoderCustomTypes.LimitOrderData calldata limit
)
external
pure
returns (bytes memory addressesFound)
{
if (
input.swapData.swapType != DecoderCustomTypes.SwapType.NONE || input.swapData.extRouter != address(0)
|| input.pendleSwap != address(0) || input.tokenIn != input.tokenMintSy
) revert PendleRouterDecoderAndSanitizer__AggregatorSwapsNotPermitted();

if (limit.limitRouter != address(0)) {
revert PendleRouterDecoderAndSanitizer__LimitOrderSwapsNotPermitted();
}

addressesFound = abi.encodePacked(receiver, market);
}

function removeLiquiditySingleToken(
address receiver,
address market,
uint256 netLpToRemove,
DecoderCustomTypes.TokenOutput calldata output,
DecoderCustomTypes.LimitOrderData calldata limit
)
external
pure
virtual
returns (bytes memory addressFound)
{
if (
output.swapData.swapType != DecoderCustomTypes.SwapType.NONE || output.swapData.extRouter != address(0)
|| output.pendleSwap != address(0) || output.tokenOut != output.tokenRedeemSy
) revert PendleRouterDecoderAndSanitizer__AggregatorSwapsNotPermitted();

if (limit.limitRouter != address(0)) {
revert PendleRouterDecoderAndSanitizer__LimitOrderSwapsNotPermitted();
}

addressFound = abi.encodePacked(receiver, market);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import { BaseDecoderAndSanitizer } from "src/base/DecodersAndSanitizers/BaseDecoderAndSanitizer.sol";

abstract contract RenzoDecoderAndSanitizer is BaseDecoderAndSanitizer {
function depositETH() external returns (bytes memory addressesFound) {
// nothing to sanitize
return addressesFound;
}

function deposit(
address to,
uint256[] memory amounts,
uint256 minLpAmount,
uint256 deadline
)
external
returns (bytes memory addressesFound)
{
addressesFound = abi.encodePacked(to);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@ abstract contract UniswapV3DecoderAndSanitizer is BaseDecoderAndSanitizer {
// Return addresses found
addressesFound = abi.encodePacked(params.recipient);
}

function safeTransferFrom(
address,
address to,
uint256
)
external
pure
virtual
returns (bytes memory addressesFound)
{
addressesFound = abi.encodePacked(to);
}
}
36 changes: 36 additions & 0 deletions src/interfaces/DecoderCustomTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,42 @@ contract DecoderCustomTypes {
bool needScale;
}

enum OrderType {
SY_FOR_PT,
PT_FOR_SY,
SY_FOR_YT,
YT_FOR_SY
}

struct Order {
uint256 salt;
uint256 expiry;
uint256 nonce;
OrderType orderType;
address token;
address YT;
address maker;
address receiver;
uint256 makingAmount;
uint256 lnImpliedRate;
uint256 failSafeRate;
bytes permit;
}

struct FillOrderParams {
Order order;
bytes signature;
uint256 makingAmount;
}

struct LimitOrderData {
address limitRouter;
uint256 epsSkipMarket; // only used for swap operations, will be ignored otherwise
FillOrderParams[] normalFills;
FillOrderParams[] flashFills;
bytes optData;
}

enum SwapType {
NONE,
KYBERSWAP,
Expand Down
Loading