实现了一个简单的金库合约,可以存币和取币,并且可以按照存储代币的比例进行取币。
金库合约的组成部分:
- ERC20: 本合约集成了ERC20的相关方法,通过IERC20接口调用.
- depoist: 存币方法.
- withdraw: 取币方法.
https://github.com/syd2025/vault
存币计算方式:
A - Amount to deposit
B - Balance of vault before deposit
S - Shares to mint
T - Total shares before mint
- (A + B)/B = (S+T)/T => S = A * T / B
取币计算方式: A - Amount to withdraw
B = Balance of vault before withdraw
S = Shares to burn
T = Total shares before burn
- (B - A)/B = (T - S)/T => A = B * S / T
$ forge build$ forge test$ forge fmt$ forge snapshot$ anvil$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>$ cast <subcommand>$ forge --help
$ anvil --help
$ cast --help