ERC4626是一个vault,在DAI中,使用ETH换取DAI。其流程为先充值ETH到maker vault。
Vault
- 资产的管理、分红
- 用户充值某项资产获取某个凭证
- 该凭证作为分红、推出的依据
- Yield Farming/借贷/质押等
以太坊改进提案EIP:ethereum improvemwnt proposal
最初EIP-4626提出想法
4626代码,与最初标准还是有不同,ERC4626是继承ERC20
较好的4626代码分别是solmate和openzepplin
ERC4626
assets & shares
返回金库基础资产代币地址
function asset() external view returns(address assetTokenAddress);
返回金库管理的基础代币总额
function totalAssets() external view returns(uint256 totalManagedAssets);
需要注意的是,在ERC4626中规则中,一个vault只能管理一个代币
数量估计
function convertToShares(uint256 assets) external view returns(uinr256 shares);
function convertToAssets(uint256 shares) external view returns(uint256 assets);
充值资产,获取share
function maxDeposit(address receiver) external view returns(uint256 maxAssets);
function previewDeposit(uint256 assets) external view returns(uint256 shares);
function deposit(uint256 assers,address receiver) external returns(uint256 shares);
function maxMint(address receiver) external view returns(uint256 assets);
function mint(uint256 shares,address receiver) external returns(uint256 assets);
返回shares,拿回资产
function maxWithdraw(address owner) external view returns(uint256 maxAssets);
function previewWithdraw(uint256 assets) external view returns(uint256 shares);
function Withdraw(uint256 assets,address receiver,address owner) external returns(uint256 shares);
function maxRedeem(address owner) external view returns(uint256 maxShares);
function previewRedeem(uint256 shares) external returns(uint256 assets);
function Redeem(uint256 shares,address receiver,address owner) external retuens(uint256 assets);
总结如下:
两个事件
event Deposit(address indexed sender,address indexed owner,uint256 assets,uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
Front-Running
区块链交易在发布之后和正式上链之前,交易存在交易池中。矿空会根据优先级打包交易。
Front-running是指在金融交易中,某人或机构在知道客户即将进行大额交易的情况下,趁机在交易执行之前,以自己或自己所代表的利益进行相同或相似的交易。