Skip to content

Commit

Permalink
fix: decoder sanitizers and eth only deposit for rebalance test
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonCase committed Oct 2, 2024
1 parent 0ecc737 commit 5721dcc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 79 deletions.
12 changes: 10 additions & 2 deletions src/base/DecodersAndSanitizers/LayerZeroOFTDecoderAndSanitizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MessagingFee } from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";

contract LayerZeroOFTDecoderAndSanitizer is BaseDecoderAndSanitizer {
error LayerZeroOFTDecoderAndSanitizer_ComposedMsgNotSupported();
error LayerZeroOFTDecoderAndSanitizer_NotVault();

constructor(address _boringVault) BaseDecoderAndSanitizer(_boringVault) { }

Expand All @@ -29,13 +30,20 @@ contract LayerZeroOFTDecoderAndSanitizer is BaseDecoderAndSanitizer {
address refundReceiver
)
external
pure
view
returns (bytes memory)
{
if (bytes32ToAddress(_sendParam.to) != boringVault) {
revert LayerZeroOFTDecoderAndSanitizer_NotVault();
}
if (_sendParam.composeMsg.length > 0) {
revert LayerZeroOFTDecoderAndSanitizer_ComposedMsgNotSupported();
}

return abi.encodePacked(_sendParam.dstEid, _sendParam.to, refundReceiver);
return abi.encodePacked(_sendParam.dstEid);
}

function bytes32ToAddress(bytes32 b) internal pure returns (address) {
return address(uint160(uint256(b)));
}
}
55 changes: 0 additions & 55 deletions src/base/DecodersAndSanitizers/StargateV1DecoderAndSanitizer.sol

This file was deleted.

14 changes: 11 additions & 3 deletions src/base/DecodersAndSanitizers/StargateV2DecoderAndSanitizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ contract StargateV2DecoderAndSanitizer is BaseDecoderAndSanitizer {
constructor(address _boringVault) BaseDecoderAndSanitizer(_boringVault) { }

error StargateV2DecoderAndSanitizer_ComposedMsgNotSupported();

error StargateV2DecoderAndSanitizer_MustBeVault();
/**
* @dev _sendParam:
* uint32 dstEid; // Destination endpoint ID. [VERIFY]
* bytes32 to; // Recipient address. [VERIFY]
* uint256 amountLD; // Amount to send in local decimals.
* uint256 minAmountLD; // Minimum amount to send in local decimals.
* bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
* bytes composeMsg; // The composed message for the send() operation. [NONE]
* bytes composeMsg; // The composed message for the send() operation.
* bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations. [NONE]
* @dev _fee:
* uint256 nativeFee;
* uint256 lzTokenFee;
*/

function sendToken(
SendParam memory _sendParam,
MessagingFee memory _messagingFee,
Expand All @@ -30,9 +31,16 @@ contract StargateV2DecoderAndSanitizer is BaseDecoderAndSanitizer {
external
returns (bytes memory)
{
if (bytes32ToAddress(_sendParam.to) != boringVault || _refundAddress != boringVault) {
revert StargateV2DecoderAndSanitizer_MustBeVault();
}
if (_sendParam.composeMsg.length > 0) {
revert StargateV2DecoderAndSanitizer_ComposedMsgNotSupported();
}
return abi.encodePacked(_sendParam.dstEid, _sendParam.to, _refundAddress);
return abi.encodePacked(_sendParam.dstEid);
}

function bytes32ToAddress(bytes32 b) internal pure returns (address) {
return address(uint160(uint256(b)));
}
}
29 changes: 12 additions & 17 deletions test/strategy/SeiyanEthRebalance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,29 @@ contract SeiyanEthRebalanceStrategyTest is StrategyBase {
}

function testRebalance() public {
// to-do DEAL new WETH that would be bridged
uint256 vaultBalance = base.balanceOf(address(boringVault));
deal(WETH, address(boringVault), vaultBalance + SEI_WETH);
vaultBalance = base.balanceOf(address(boringVault));

deal(address(boringVault), vaultBalance + SEI_WETH);
vaultBalance = address(boringVault).balance;
_setUpManager(vaultBalance);
assertEq(manager.manageRoot(ADMIN), _getRoot(), "Root not set correctly");

Leaf[] memory myLeafs = _getLeafsForTest(vaultBalance);

bytes32[][] memory manageProofs = new bytes32[][](2);
address[] memory decodersAndSanitizers = new address[](2);
address[] memory targets = new address[](2);
bytes[] memory targetData = new bytes[](2);
uint256[] memory values = new uint256[](2);
bytes32[][] memory manageProofs = new bytes32[][](1);
address[] memory decodersAndSanitizers = new address[](1);
address[] memory targets = new address[](1);
bytes[] memory targetData = new bytes[](1);
uint256[] memory values = new uint256[](1);

manageProofs = _getProofsUsingTree(myLeafs, tree);
decodersAndSanitizers[0] = myLeafs[0].decoderAndSanitizer;
decodersAndSanitizers[1] = myLeafs[1].decoderAndSanitizer;

targets[0] = myLeafs[0].target;
targets[1] = myLeafs[1].target;

targetData[0] = abi.encodeWithSelector(myLeafs[0].selector, vaultBalance);
targetData[1] = abi.encodeWithSelector(myLeafs[1].selector, address(boringVault), true);
targetData[0] = abi.encodeWithSelector(myLeafs[0].selector, address(boringVault), true);

values[0] = 0;
values[1] = vaultBalance;
values[0] = vaultBalance;

// console.log("myLeafs[0]");
// console.log(myLeafs[0].decoderAndSanitizer);
Expand Down Expand Up @@ -110,9 +106,8 @@ contract SeiyanEthRebalanceStrategyTest is StrategyBase {
bytes memory packedArguments = abi.encodePacked(address(boringVault));
Leaf memory pirexEthLeaf =
Leaf(address(decoder), PIREX_ETH, true, PirexEthDecoderAndSanitizer.deposit.selector, packedArguments);
myLeafs = new Leaf[](2);
myLeafs = new Leaf[](1);

myLeafs[0] = wethForEthLeaf;
myLeafs[1] = pirexEthLeaf;
myLeafs[0] = pirexEthLeaf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ address constant STARGATE = 0x5c386D85b1B82FD9Db681b9176C8a4248bb6345B;
uint32 constant ETH_EID = 30_101;
uint256 constant SEI_TO_MINT = 100 ether;

contract LayerZeroOFTStrategy is StrategyBase {
contract StargateStrategy is StrategyBase {
using OptionsBuilder for bytes;

LayerZeroOFTDecoderAndSanitizer sanitizer;
Expand Down Expand Up @@ -47,7 +47,7 @@ contract LayerZeroOFTStrategy is StrategyBase {
bytes memory packedArguments = abi.encodePacked(STARGATE);
Leaf memory approveLeaf =
Leaf(address(sanitizer), WETH, false, BaseDecoderAndSanitizer.approve.selector, packedArguments);
packedArguments = abi.encodePacked(ETH_EID, addressToBytes32(address(boringVault)), ADMIN);
packedArguments = abi.encodePacked(ETH_EID);
Leaf memory sendLeaf =
Leaf(address(sanitizer), STARGATE, true, LayerZeroOFTDecoderAndSanitizer.send.selector, packedArguments);

Expand Down Expand Up @@ -107,4 +107,8 @@ contract LayerZeroOFTStrategy is StrategyBase {
function addressToBytes32(address _addr) public pure returns (bytes32) {
return bytes32(uint256(uint160(_addr)));
}

function bytes32ToAddress(bytes32 b) public pure returns (address) {
return address(uint160(uint256(b)));
}
}

0 comments on commit 5721dcc

Please sign in to comment.