Minting unshETH with a LSD
The following section details how to mint unshETH with a list of supported LSDs and WETH.
We assume that inputAmount
(in wei units) and inputLSDAddress
correspond to the respective amount and contract address of the LSD being used to mint unsheth.
Required Contracts & Interfaces
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()
The vdAMM address is currently: 0x0Ae38f7E10A43B5b2fB064B42a2f4514cbA909ef.
However this may change in the future, and so it should be dynamically called from the LSDVault contract.
//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()
The unshETHZap Address is currently: 0x51A80238B5738725128d3a3e06Ab41c1d4C05C74.
However this may change in the future, and so it should be dynamically called from the LSDVault contract.
//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)
Supported 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++
}
Currently supported LSDs are:
sfrxETH: 0xac3e018457b222d93114458476f3e3416abbe38f
rETH: 0xae78736cd615f374d3085123a210448e74fc6393
wstETH: 0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0
cbETH: 0xbe9895146f7af43049ca1c1ae358b0541ea49704
WETH: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
ankrETH: 0xE95A203B1a91a908F9B9CE46459d101078c2c3cb
swETH: 0xf951E335afb289353dc249e82926178EaC7DEd78
More LSDs will be added in the future.
Price Discovery
1. Get the Deposit Fee (in terms of the input LSD)
//solidity
(uint256 depositFee, ) = IVdAmm(vdAmmAddress).getDepositFee(inputAmount, inputLSDAddress);
//ethers.js
const [depositFee] = await vdAmmContract.getDepositFee(inputAmount, inputLSDAddress)
2. Get the Price of the LSD in terms of unshETH
//solidity
uint256 price = ILSDVault(LSDVaultAddress).getPrice(inputLSDAddress);
//ethers.js
const price = await LSDVaultContract.getPrice(inputLSDAddress)
3. Calculate the final amount of unshETH to be minted
//solidity
uint256 unshETHMintedInWei = price*(inputAmount-depositFee)/1e18
//ethers.js
const unshETHMintedInWei = price.mul(inputAmount.sub(depositFee)).div(1e18)
Submitting the Transaction
1. Approve the LSD to be spent by the 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. Call the deposit lsd function of the unshETHZap
//solidity
IunshETHZap(unshETHZapAddress).deposit_lsd(inputLSDAddress, inputAmount)
//ethers.js
await unshETHZapContract.deposit_lsd(inputLSDAddress, inputAmount)