Ethereum smart contracts

  1. Deposit Contract(Ethereum): This contract is responsible for taking all the ETH and ETH derivative deposits from the users and storing the sharePrice. It passes the messages to Message Contract for passing of message. The deposit contract will look something like this:

contract Deposit{
	uint256 public sharePrice;
	function deposit(address _tokenAddress, address _receiver, uint256 _value, uint256 _destId) external payable;
	function executeStrategies(address[] _strategyAddress,bytes[] memory _executionData,uint256[] _value) external;
}
  1. Strategy Manager Contract: This contract is responsible for managing all the staking/restaking/BnL etc. strategies. It further helps in execution of the strategies. It looks something like the following:

contract StrategyManager{
  struct StrategyStruct{
	   uint256 ethDeposited;
     uint256 rewardsEarned;
     uint256 ethWithdrawn;
  }
  mapping(address=>address) public strategies;
  mapping(address=>StrategyStruct) public strategyDeposits;
	function addStrategies(address _strategy) external;
	function updateStratgy(address _strategy, StrategyStruct memory _changeBalane) external;
}
  1. Strategy Contracts(Ethereum): This contract is responsible for executing strategies on Ethereum on different protocols. Whenever a new protocol is whitelisted for staking, a new strategy contract is created and deposit contract delegates the calls to this contract whenever it has to interact with the protocol:

// This is a sample strategy actual strategies can look different
abstract contract Strategy{
	address public constant StakingAddress;
	address public constant TOKEN_ADDRESS;
	function tokenPrice() external view returns(uint256);
	// apart from this all function depends on the strategy that needs to be executed
}
  1. Messaging Contract: This contract is responsible for sending message from L1 to L2. It uses LayerZero and other messaging protocol to do so. The Messaging Contract looks like this:

contract MessagingApp{
	address public lzEndpoint;
	address public Deposit;
	function sendMessage(bytes memory _data, uint256 _destID) external onlyDeposit
	function receiveMessage(bytes memory _data) external onlyDeposit
}

The messaging contract uses following type Ids to know what kind of transaction it is:

    id=1 deposit
    id=2 rewards
    id=3 withdrawal
    id=4 L2 deposit received
  1. Withdrawal Contract: This contract is responsible for creation of withdrawal queues and giving users their deposit back once the assets are withdrawn from strategies. It looks something like this:

contract Withdrawal{
	address public MessagingApp;
	Struct WithdrawalRequest{
		uint256 timeCreated;
		uint256 value;
	}
	mapping(address=>WithdrawalRequest) withdrawalQueue;
	
	function createWithdrawalRequest(address _receiver, uint256 _value) external onlyMessagingApp;
	function claimWithdrawal(address _receiver, uint256 _value) exernal
}

Last updated