使用LSD铸造unshETH
以下部分详细说明如何使用支持的LSD和WETH铸造unshETH。
我们假设inputAmount(以wei单位表示)和inputLSDaddress对应于用于铸造unshETH的相应数量和合约地址的LSD。
所需的合约和接口
unshETH: 0x0Ae38f7E10A43B5b2fB064B42a2f4514cbA909ef
LSDVault: 0x51A80238B5738725128d3a3e06Ab41c1d4C05C74
//solidity
interface ILSDVault {
function getPrice(address lsd) public view returns(uint256);
function swapperAddress() external view returns (address);
function unshethZapAddress() external view returns (address);
function supportedLSDs(uint256 index) external view returns (address);
}
//ethers.js
const ILSDVaultABI = [
'function getPrice(address lsd) public view returns (uint256)',
'function swapperAddress() external view returns (address)',
'function unshethZapAddress() external view returns (address)',
'function supportedLSDs(uint256 index) external view returns (address)',
]
const LSDVaultAddress = '0x51A80238B5738725128d3a3e06Ab41c1d4C05C74'
const LSDVaultContract = new ethers.Contract(LSDVaultAddress, ILSDVault, provider)
vdAMM
//solidity
address vdaAMMAddress = ILSDVault(LSDVaultAddress).swapperAddress();
//ethers.js
const vdAmmAddress = await LSDVaultContract.swapperAddress()
vdAMM地址目前为: 0x0Ae38f7E10A43B5b2fB064B42a2f4514cbA909ef.
然而,这在未来可能会发生变化,因此应该从LSDVault合约中动态调用。
//solidity
interface IVdAmm {
function getDepositFee(uint256 lsdAmountIn, address lsd) external returns(uint256, uint256);
}
//ethers.js
const IVdAmmABI = ['function getDepositFee(uint256 lsdAmountIn, address lsd) external returns (uint256, uint256)']
const vdAmmContract = new ethers.Contract(vdAmmAddress, IVdAmm, provider)
unshETHZap
//solidity
address unshethZapAddress = ILSDVault(LSDVaultAddress).unshethZapAddress();
//ethers.js
const unshETHZapAddress = await LSDVaultContract.unshethZapAddress()
unshETHZap地址目前为: 0x51A80238B5738725128d3a3e06Ab41c1d4C05C74.
然而,这在未来可能会发生变化,因此应该从LSDVault合约中动态调用。
//solidity
interface IunshETHZap {
function deposit_lsd(address lsdAddress, uint256 amount) external;
}
//ethers.js
const IunshETHZapABI = ['function deposit_lsd(address lsdAddress, uint256 amount) external']
const unshETHZapContract = new ethers.Contract(unshETHZapAddress, IunshETHZap, provider)
支持的LSDs
// solidity
uint256 i = 0;
address lsdAddress;
while (true) {
lsdAddress = ILSDVault(LSDVaultAddress).supportedLSDs(i);
if (lsdAddress == address(0)) {
break;
}
// Process the LSD address here
i++;
}
// ethers.js
let i = 0
let lsdAddress
while (true) {
lsdAddress = await LSDVaultContract.supportedLSDs(i)
if (lsdAddress === '0x0000000000000000000000000000000000000000') {
break
}
console.log(`LSD Address ${i}: ${lsdAddress}`)
i++
}
目前支持的LSDs如下:
sfrxETH: 0xac3e018457b222d93114458476f3e3416abbe38f
rETH: 0xae78736cd615f374d3085123a210448e74fc6393
wstETH: 0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0
cbETH: 0xbe9895146f7af43049ca1c1ae358b0541ea49704
WETH: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
ankrETH: 0xE95A203B1a91a908F9B9CE46459d101078c2c3cb
swETH: 0xf951E335afb289353dc249e82926178EaC7DEd78
未来将添加更多LSDs。
价格发现
1. 获取存款费用(以输入的LSD为单位)
//solidity
(uint256 depositFee, ) = IVdAmm(vdAmmAddress).getDepositFee(inputAmount, inputLSDAddress);
//ethers.js
const [depositFee] = await vdAmmContract.getDepositFee(inputAmount, inputLSDAddress)
2. 获取LSD相对于unshETH的价格
//solidity
uint256 price = ILSDVault(LSDVaultAddress).getPrice(inputLSDAddress);
//ethers.js
const price = await LSDVaultContract.getPrice(inputLSDAddress)
3. 计算要铸造的最终unshETH数量
//solidity
uint256 unshETHMintedInWei = price*(inputAmount-depositFee)/1e18
//ethers.js
const unshETHMintedInWei = price.mul(inputAmount.sub(depositFee)).div(1e18)
提交交易
1. 批准LSD可以被unshETHZap使用
//solidity
IERC20(inputLSDAddress).approve(unshETHZapAddress, inputAmount);
//ethers.js
const IERC20ABI = ['function approve(address spender, uint256 amount) external returns (bool)']
const IERC20Contract = new ethers.Contract(inputLSDAddress, IERC20ABI, provider)
await IERC20Contract.approve(unshETHZapAddress, inputAmount)
2. 调用unshETHZap的存款LSD函数
//solidity
IunshETHZap(unshETHZapAddress).deposit_lsd(inputLSDAddress, inputAmount)
//ethers.js
await unshETHZapContract.deposit_lsd(inputLSDAddress, inputAmount)