Skip to content

Commit

Permalink
Merge pull request #174 from Se7en-Seas/feat/lombard-minting-bsc
Browse files Browse the repository at this point in the history
add lombard btc bsc staking/minting
  • Loading branch information
mel0ndev authored Dec 18, 2024
2 parents 34afa7f + daa1da2 commit 484578e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ abstract contract LombardBTCMinterDecoderAndSanitizer is BaseDecoderAndSanitizer
(, address to,,,) = abi.decode(data, (uint256, address, uint64, bytes32, uint32));
addressesFound = abi.encodePacked(to);
}

/// @notice for minting using cbBTCPPM contract
function swapCBBTCToLBTC(uint256 /*amount*/ ) external pure virtual returns (bytes memory addressesFound) {
return addressesFound;

/// @notice for minting using cbBTCPPM contract (on Base)
function swapCBBTCToLBTC(uint256 /*amount*/) external pure virtual returns (bytes memory addressesFound) {
return addressesFound;
}

/// @notice for minting using btcbPMM contract (on BSC)
function swapBTCBToLBTC(uint256 /*amount*/) external pure virtual returns (bytes memory addressesFound) {
return addressesFound;
}

}
82 changes: 42 additions & 40 deletions test/integrations/LombardBtcStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ contract LombardBTCStakingIntegrationTest is Test, MerkleTreeHelper {
targets[0] = getAddress(sourceChain, "BTCB");
targets[1] = getAddress(sourceChain, "LBTC");
targets[2] = getAddress(sourceChain, "LBTC");
targets[3] = getAddress(sourceChain, "LBTC");
targets[4] = getAddress(sourceChain, "LBTC");
targets[3] = getAddress(sourceChain, "BTCB");
targets[4] = getAddress(sourceChain, "BTCBPMM");

bytes memory depositData = abi.encode(
OutputWithPayload(
Expand All @@ -169,21 +169,26 @@ contract LombardBTCStakingIntegrationTest is Test, MerkleTreeHelper {
bytes memory signature = hex"00"; // Could be any bytes

// Dummy BTC Pubkey -- P2WPKH scriptPubkey
bytes memory scriptPubkey = abi.encodePacked(
hex"0014", // OP_0 (00) followed by OP_DATA_20 (14)
hex"1234567890123456789012345678901234567890" // 20 bytes of example data
);
//bytes memory scriptPubkey = abi.encodePacked(
// hex"0014", // OP_0 (00) followed by OP_DATA_20 (14)
// hex"1234567890123456789012345678901234567890" // 20 bytes of example data
//);

// Target Data
bytes[] memory targetData = new bytes[](5);
targetData[0] =
abi.encodeWithSignature("approve(address,uint256)", getAddress(sourceChain, "LBTC"), type(uint256).max);
targetData[1] = abi.encodeWithSignature("mint(address,uint256)", getAddress(sourceChain, "boringVault"), 100e18);
targetData[2] = abi.encodeWithSignature("mint(bytes,bytes)", depositData, signature);
targetData[3] = abi.encodeWithSignature("redeem(bytes,uint256)", scriptPubkey, 90e18);
targetData[4] = abi.encodeWithSignature("burn(uint256)", 10e18);

// Eth Amounts
targetData[1] =
abi.encodeWithSignature("mint(address,uint256)", getAddress(sourceChain, "boringVault"), 100e18);
targetData[2] =
abi.encodeWithSignature("mint(bytes,bytes)", depositData, signature);
targetData[3] =
abi.encodeWithSignature("approve(address,uint256)", getAddress(sourceChain, "BTCBPMM"), type(uint256).max);
targetData[4] =
abi.encodeWithSignature("swapBTCBToLBTC(uint256)", 10e18);

// Eth Amounts
uint256[] memory values = new uint256[](5); //empty, not passing any ETH

// Decoders and Sanitizers
Expand Down Expand Up @@ -220,25 +225,22 @@ contract LombardBTCStakingIntegrationTest is Test, MerkleTreeHelper {
bytes32[][] memory manageTree = _generateMerkleTree(leafs);
manager.setManageRoot(address(this), manageTree[manageTree.length - 1][0]);

ManageLeaf[] memory manageLeafs = new ManageLeaf[](7);
ManageLeaf[] memory manageLeafs = new ManageLeaf[](5);
manageLeafs[0] = leafs[0];
manageLeafs[1] = leafs[1];
manageLeafs[2] = leafs[2];
manageLeafs[3] = leafs[3];
manageLeafs[4] = leafs[4];
manageLeafs[5] = leafs[5];
manageLeafs[6] = leafs[6];
manageLeafs[3] = leafs[3];
manageLeafs[4] = leafs[4];


bytes32[][] memory manageProofs = _getProofsUsingTree(manageLeafs, manageTree);

address[] memory targets = new address[](7);
address[] memory targets = new address[](5);
targets[0] = getAddress(sourceChain, "cbBTC");
targets[1] = getAddress(sourceChain, "LBTC");
targets[2] = getAddress(sourceChain, "LBTC");
targets[3] = getAddress(sourceChain, "LBTC");
targets[4] = getAddress(sourceChain, "LBTC");
targets[5] = getAddress(sourceChain, "cbBTC");
targets[6] = getAddress(sourceChain, "cbBTCPMM");
targets[3] = getAddress(sourceChain, "cbBTC"); //approving dif swap contract
targets[4] = getAddress(sourceChain, "cbBTCPMM");

bytes memory depositData = abi.encode(
OutputWithPayload(
Expand All @@ -252,36 +254,36 @@ contract LombardBTCStakingIntegrationTest is Test, MerkleTreeHelper {

bytes memory signature = hex"00"; // Could be any bytes

// Dummy BTC Pubkey -- P2WPKH scriptPubkey
bytes memory scriptPubkey = abi.encodePacked(
hex"0014", // OP_0 (00) followed by OP_DATA_20 (14)
hex"1234567890123456789012345678901234567890" // 20 bytes of example data
);
// // Dummy BTC Pubkey -- P2WPKH scriptPubkey
// bytes memory scriptPubkey = abi.encodePacked(
// hex"0014", // OP_0 (00) followed by OP_DATA_20 (14)
// hex"1234567890123456789012345678901234567890" // 20 bytes of example data
// );

// Target Data
bytes[] memory targetData = new bytes[](7);
targetData[0] =
bytes[] memory targetData = new bytes[](5);
targetData[0] =
abi.encodeWithSignature("approve(address,uint256)", getAddress(sourceChain, "LBTC"), type(uint256).max);
targetData[1] = abi.encodeWithSignature("mint(address,uint256)", getAddress(sourceChain, "boringVault"), 100e18);
targetData[2] = abi.encodeWithSignature("mint(bytes,bytes)", depositData, signature);
targetData[3] = abi.encodeWithSignature("redeem(bytes,uint256)", scriptPubkey, 90e18);
targetData[4] = abi.encodeWithSignature("burn(uint256)", 10e18);
targetData[5] =
abi.encodeWithSignature("approve(address,uint256)", getAddress(sourceChain, "cbBTCPMM"), type(uint256).max);
targetData[6] = abi.encodeWithSignature("swapCBBTCToLBTC(uint256)", 1e4);
targetData[1] =
abi.encodeWithSignature("mint(address,uint256)", getAddress(sourceChain, "boringVault"), 100e18);
targetData[2] =
abi.encodeWithSignature("mint(bytes,bytes)", depositData, signature);
targetData[3] =
abi.encodeWithSignature("approve(address,uint256)", getAddress(sourceChain, "cbBTCPMM"), type(uint256).max);
targetData[4] =
abi.encodeWithSignature("swapCBBTCToLBTC(uint256)", 1e4);

// Eth Amounts
uint256[] memory values = new uint256[](5); //empty, not passing any ETH

// Eth Amounts
uint256[] memory values = new uint256[](7); //empty, not passing any ETH

// Decoders and Sanitizers
address[] memory decodersAndSanitizers = new address[](7);
address[] memory decodersAndSanitizers = new address[](5);
decodersAndSanitizers[0] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[1] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[2] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[3] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[4] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[5] = rawDataDecoderAndSanitizer;
decodersAndSanitizers[6] = rawDataDecoderAndSanitizer;

// Run the functions
manager.manageVaultWithMerkleVerification(manageProofs, decodersAndSanitizers, targets, targetData, values);
Expand Down
12 changes: 9 additions & 3 deletions test/resources/ChainValues.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,8 @@ contract ChainValues {
values[fraxtal]["dev1Address"] = 0xf8553c8552f906C19286F21711721E206EE4909E.toBytes32();
values[fraxtal]["liquidPayoutAddress"] = 0xA9962a5BfBea6918E958DeE0647E99fD7863b95A.toBytes32();
values[fraxtal]["balancerVault"] = address(1).toBytes32();
// ERC20

// ERC20s
values[fraxtal]["wfrxETH"] = 0xFC00000000000000000000000000000000000006.toBytes32();

// Standard Bridge.
Expand All @@ -1252,14 +1253,19 @@ contract ChainValues {
}

function _addBscValues() private {
// Deployment/Dev
values[bsc]["deployerAddress"] = 0x5F2F11ad8656439d5C14d9B351f8b09cDaC2A02d.toBytes32();
values[bsc]["dev0Address"] = 0x0463E60C7cE10e57911AB7bD1667eaa21de3e79b.toBytes32();
values[bsc]["dev1Address"] = 0xf8553c8552f906C19286F21711721E206EE4909E.toBytes32();


// ERC20s
values[bsc]["LBTC"] = 0xecAc9C5F704e954931349Da37F60E39f515c11c1.toBytes32();
values[bsc]["WBTC"] = 0x0555E30da8f98308EdB960aa94C0Db47230d2B9c.toBytes32();
values[bsc]["WBNB"] = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c.toBytes32();
values[bsc]["BTCB"] = 0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c.toBytes32();
values[bsc]["BTCB"] = 0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c.toBytes32();

// Lombard
values[bsc]["BTCBPMM"] = 0xE4ff44a615dF38e37cdF475833c1d57774CC9D4A.toBytes32();

//Balancer (not deployed on BSC, but needed for merkle manager)
values[bsc]["vault"] = 0xBA12222222228d8Ba445958a75a0704d566BF2C8.toBytes32();
Expand Down
58 changes: 30 additions & 28 deletions test/resources/MerkleTreeHelper/MerkleTreeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5838,33 +5838,10 @@ contract MerkleTreeHelper is CommonBase, ChainValues {
new address[](1),
string.concat("Mint LBTC"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);
leafs[leafIndex].argumentAddresses[0] = getAddress(sourceChain, "boringVault");

unchecked {
leafIndex++;
}
leafs[leafIndex] = ManageLeaf(
address(LBTC), //target
false,
"redeem(bytes,uint256)",
new address[](0),
string.concat("Unstake LBTC"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);

unchecked {
leafIndex++;
}
leafs[leafIndex] = ManageLeaf(
address(LBTC), //target
false,
"burn(uint256)",
new address[](0),
string.concat("Burn LBTC"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);

);
leafs[leafIndex].argumentAddresses[0] = getAddress(sourceChain, "boringVault");

//set the swap leaf based on if we are on bnc or base
if (getAddress("base", "cbBTC") == address(BTCB_or_CBBtc)) {
unchecked {
leafIndex++;
Expand All @@ -5889,7 +5866,32 @@ contract MerkleTreeHelper is CommonBase, ChainValues {
new address[](0),
string.concat("Swap cbBTC to LBTC"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);
);
} else {
unchecked {
leafIndex++;
}
leafs[leafIndex] = ManageLeaf(
address(BTCB_or_CBBtc), //target
false,
"approve(address,uint256)",
new address[](1),
string.concat("Approve BTCB to be swapped for LBTC via swap contract"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);
leafs[leafIndex].argumentAddresses[0] = getAddress(sourceChain, "BTCBPMM");

unchecked {
leafIndex++;
}
leafs[leafIndex] = ManageLeaf(
getAddress(sourceChain, "BTCBPMM"), //target
false,
"swapBTCBToLBTC(uint256)",
new address[](0),
string.concat("Swap BTCB to LBTC"),
getAddress(sourceChain, "rawDataDecoderAndSanitizer")
);
}
}

Expand Down

0 comments on commit 484578e

Please sign in to comment.