https://eips.ethereum.org/EIP...Abstract以下规范容许为代表单个底层 ERC-20 份额的保险库施行规范 API。 该规范是 ERC-20 代币的扩大,它提供了存取代币和读取余额的基本功能。
Motivation代币化保险库不足标准化,导致施行细节多样化。 一些不同的例子包含借贷市场、聚合器和具备外在利息的代币。 这使得须要合乎许多规范的协定在聚合器或插件层难以集成,并迫使每个协定实现本人的适配器,这些适配器容易出错并节约开发资源。代币化保险库的规范将升高收益保险库的集成工作量,同时创立更加统一和弱小的施行模式。
CodeEventsDeposit事件:
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);Withdraw事件:
event Withdraw( address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);IMMUTABLESERC20 public immutable asset;constructor( ERC20 _asset, string memory _name, string memory _symbol) ERC20(_name, _symbol, _asset.decimals()) { asset = _asset;}Main LogicDeposit函数:function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) { // Check for rounding error since we round down in previewDeposit. require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES"); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares);}Mint函数:
...