Here is a simple example of a smart contract for ETHLending and ETHBorrowing:
pragma solidity ^0.8.0;
contractETHLending {
uint256 public totalSupply;
uint256 public balanceOf;
uint256 public dueDate;
mapping(address => uint256) public allowed;
constructor() {
totalSupply = 100 * 10**18; // set default totalSupply to 100 ETH
balanceOf = totalSupply;
dueDate = uint256(date.now().year + 18 * 10**10); // set dueDate to current year
allowed[msg.sender] = 0; // allow all senders to borrow
}
function transfer(address _to, uint256 _value) public {
require(_to != address(0), "Only the zero address can be a transferee");
require(_value > balanceOf, "Insufficient value to loan");
balanceOf -= _value;
balanceOfOf[msg.sender] += _value;
allowed[msg.sender] += _value;
emit Transfer(msg.sender, _to, _value);
}
function loan(address _sender, uint256 _value) public {
require(_sender != address(0), "Only the zero address can be a loaner");
require(_value > balanceOfOf[_sender], "Insufficient value to borrow");
balanceOfOf[_sender] -= _value;
balanceOfOf[msg.sender] += _value;
emit Transfer(msg.sender, _sender, _value);
allowed[msg.sender] = 0; // allow all senders to borrow
}
function balanceOf() public view returns (uint256) {
return balanceOfOf[msg.sender];
}
function allowed() public view returns (mapping(address => uint256)) {
return allowed;
}
}
contractETHBorrowing {
uint256 public totalSupply;
uint256 public balanceOf;
uint256 public dueDate;
mapping(address => uint256) public allowed;
constructor() {
totalSupply = 100 * 10**18; // set default totalSupply to 100 ETH
balanceOf = totalSupply;
dueDate = uint256(date.now().year + 18 * 10**10); // set dueDate to current year
allowed[msg.sender] = 0; // allow all senders to borrow
}
function borrow(address _sender, uint256 _value) public {
require(_sender != address(0), "Only the zero address can be a loaner");
require(_value > balanceOfOf[_sender], "Insufficient value to borrow");
balanceOfOf[_sender] -= _value;
balanceOfOf[msg.sender] += _value;
allowed[msg.sender] = 0; // allow all senders to borrow
emitborrow(msg.sender, _sender, _value);
}
function returnETH() public view returns (uint256) {
return balanceOfOf[msg.sender];
}
function allowed() public view returns (mapping(address => uint256)) {
return allowed;
}
}
This contract allows a user to borrow ETH and return it. The user can also lend ETH to others and have them borrow it from them. The contract also allows the user to see the balance of their account and the total supply of ETH they have.