Skip to content

Commit

Permalink
set rules at deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbir committed Dec 20, 2024
1 parent 4bb0203 commit c9d116c
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,77 @@

pragma solidity 0.8.27;

import "../lib/forge-std/src/Vm.sol";
import "../src/mocks/IMorphoEthereumBundlerV2.sol";
import "../src/p2pLendingProxyFactory/P2pLendingProxyFactory.sol";
import {Script} from "forge-std/Script.sol";

contract Deploy is Script {
address constant MorphoEthereumBundlerV2 = 0x23055618898e202386e6c13955a58D3C68200BFB;
address constant P2pTreasury = 0x6Bb8b45a1C6eA816B70d76f83f7dC4f0f87365Ff;

function run()
external
returns (P2pLendingProxyFactory factory, P2pLendingProxy proxy)
{
// allowed calldata for factory
bytes4 multicallSelector = IMorphoEthereumBundlerV2.multicall.selector;

P2pStructs.Rule memory rule0Deposit = P2pStructs.Rule({ // approve2
ruleType: P2pStructs.RuleType.StartsWith,
index: 0,
allowedBytes: hex"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000184af504202"
});
P2pStructs.Rule memory rule1Deposit = P2pStructs.Rule({ // spender in approve2 must be MorphoEthereumBundlerV2
ruleType: P2pStructs.RuleType.StartsWith,
index: 336,
allowedBytes: abi.encodePacked(MorphoEthereumBundlerV2)
});
P2pStructs.Rule memory rule2Deposit = P2pStructs.Rule({ // transferFrom2
ruleType: P2pStructs.RuleType.StartsWith,
index: 640,
allowedBytes: hex"54c53ef0"
});
P2pStructs.Rule memory rule3Deposit = P2pStructs.Rule({ // erc4626Deposit
ruleType: P2pStructs.RuleType.StartsWith,
index: 768,
allowedBytes: hex"6ef5eeae"
});
P2pStructs.Rule[] memory rulesDeposit = new P2pStructs.Rule[](4);
rulesDeposit[0] = rule0Deposit;
rulesDeposit[1] = rule1Deposit;
rulesDeposit[2] = rule2Deposit;
rulesDeposit[3] = rule3Deposit;

P2pStructs.Rule memory rule0Withdrawal = P2pStructs.Rule({ // erc4626Redeem
ruleType: P2pStructs.RuleType.StartsWith,
index: 0,
allowedBytes: hex"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a4a7f6e606"
});

P2pStructs.Rule[] memory rulesWithdrawal = new P2pStructs.Rule[](1);
rulesWithdrawal[0] = rule0Withdrawal;

uint256 deployerKey = vm.envUint("PRIVATE_KEY");
Vm.Wallet memory wallet = vm.createWallet(deployerKey);

vm.startBroadcast(deployerKey);
factory = new P2pLendingProxyFactory(
0x000000005504F0f5CF39b1eD609B892d23028E57,
0x6Bb8b45a1C6eA816B70d76f83f7dC4f0f87365Ff
);
factory = new P2pLendingProxyFactory(
wallet.addr,
P2pTreasury
);
factory.setCalldataRules(
P2pStructs.FunctionType.Deposit,
MorphoEthereumBundlerV2,
multicallSelector,
rulesDeposit
);
factory.setCalldataRules(
P2pStructs.FunctionType.Withdrawal,
MorphoEthereumBundlerV2,
multicallSelector,
rulesWithdrawal
);
vm.stopBroadcast();

proxy = P2pLendingProxy(factory.getReferenceP2pLendingProxy());
Expand Down

0 comments on commit c9d116c

Please sign in to comment.