mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: wETH-eETH function
This commit is contained in:
parent
29081d7884
commit
5a152e1d4a
|
@ -3,4 +3,5 @@ pragma solidity 0.8.19;
|
|||
|
||||
contract Events {
|
||||
event LogDeposit(uint256 amount, uint256 getId, uint256 setId);
|
||||
event LogDepositWeth(uint256 amount, uint256 getId, uint256 setId);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
pragma solidity 0.8.19;
|
||||
|
||||
import "./interfaces.sol";
|
||||
import {TokenInterface} from "../../common/interfaces.sol";
|
||||
|
||||
contract Helpers{
|
||||
IEtherfiPool internal constant ETHERFI_POOL = IEtherfiPool(0x308861A430be4cce5502d0A12724771Fc6DaF216);
|
||||
TokenInterface internal constant WETH_CONTRACT = TokenInterface(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
|
||||
}
|
||||
|
|
|
@ -7,12 +7,45 @@ import {Basic} from "../../common/basic.sol";
|
|||
|
||||
contract EETHContract is Helpers, Basic, Events {
|
||||
/**
|
||||
* @dev deposit ETH into Etherfi.
|
||||
* @notice stake Eth in Etherfi, users receive eETH tokens on a 1:1 basis representing their staked ETH.
|
||||
* @param amount The amount of ETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of ETH deposited.
|
||||
*/
|
||||
* @dev deposit wETH into Etherfi.
|
||||
* @notice unwrap wETH and stake ETH in Etherfi, users receive eETH tokens on a 1:1 basis representing their staked ETH.
|
||||
* @param amount The amount of ETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of ETH deposited.
|
||||
*/
|
||||
function depositWeth(
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 _amount = getUint(getId, amount);
|
||||
_amount = _amount == type(uint256).max
|
||||
? WETH_CONTRACT.balanceOf(address(this))
|
||||
: _amount;
|
||||
|
||||
uint256 _ethBeforeBalance = address(this).balance;
|
||||
|
||||
WETH_CONTRACT.approve(address(WETH_CONTRACT), _amount);
|
||||
WETH_CONTRACT.withdraw(_amount);
|
||||
|
||||
uint256 _ethAfterBalance = address(this).balance;
|
||||
|
||||
uint256 _ethAmount = sub(_ethAfterBalance, _ethBeforeBalance);
|
||||
ETHERFI_POOL.deposit{value: _ethAmount}();
|
||||
|
||||
setUint(setId, _ethAmount);
|
||||
|
||||
_eventName = "LogDepositWeth(uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amount, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev deposit ETH into Etherfi.
|
||||
* @notice stake ETH in Etherfi, users receive eETH tokens on a 1:1 basis representing their staked ETH.
|
||||
* @param amount The amount of ETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of ETH deposited.
|
||||
*/
|
||||
function deposit(
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
|
@ -26,7 +59,7 @@ contract EETHContract is Helpers, Basic, Events {
|
|||
_amount = _amount == type(uint256).max
|
||||
? address(this).balance
|
||||
: _amount;
|
||||
|
||||
|
||||
ETHERFI_POOL.deposit{value: _amount}();
|
||||
|
||||
setUint(setId, _amount);
|
||||
|
|
|
@ -56,6 +56,52 @@ describe("eETH Staking", function () {
|
|||
ethers.utils.parseEther("10")
|
||||
);
|
||||
});
|
||||
it("Topup wETH into DSA wallet", async function () {
|
||||
const wETHAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
|
||||
const IERC20ABI = [
|
||||
"function approve(address spender, uint256 amount) external returns (bool)",
|
||||
"function balanceOf(address account) external view returns (uint256)",
|
||||
"function transfer(address recipient, uint256 amount) external returns (bool)",
|
||||
];
|
||||
const wETHHolder = "0xF04a5cC80B1E94C69B48f5ee68a08CD2F09A7c3E";
|
||||
const amount = ethers.utils.parseEther("10");
|
||||
|
||||
const eETHContract = await ethers.getContractAt(IERC20ABI, wETHAddress);
|
||||
await hre.network.provider.send("hardhat_setBalance", [
|
||||
wETHHolder,
|
||||
"0x56BC75E2D63100000",
|
||||
]);
|
||||
|
||||
console.log(
|
||||
"Holder wETH Balance before topup:",
|
||||
ethers.utils.formatEther(await eETHContract.balanceOf(wETHHolder))
|
||||
);
|
||||
console.log(
|
||||
"Holder ETH Balance before topup:",
|
||||
ethers.utils.formatEther(await ethers.provider.getBalance(wETHHolder))
|
||||
);
|
||||
await hre.network.provider.request({
|
||||
method: "hardhat_impersonateAccount",
|
||||
params: [wETHHolder],
|
||||
});
|
||||
const eETHHolderSigner = await ethers.getSigner(wETHHolder);
|
||||
await eETHContract
|
||||
.connect(eETHHolderSigner)
|
||||
.approve(dsaWallet0.address, amount);
|
||||
await eETHContract
|
||||
.connect(eETHHolderSigner)
|
||||
.transfer(dsaWallet0.address, amount);
|
||||
const balance = await eETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"DSA wETH Balance after topup:",
|
||||
ethers.utils.formatEther(balance)
|
||||
);
|
||||
|
||||
await hre.network.provider.request({
|
||||
method: "hardhat_stopImpersonatingAccount",
|
||||
params: [wETHHolder],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Main", function () {
|
||||
|
@ -94,5 +140,41 @@ describe("eETH Staking", function () {
|
|||
ethers.utils.formatEther(finalBalance)
|
||||
);
|
||||
});
|
||||
|
||||
it("Should deposit wETH into eETH", async function () {
|
||||
const amount = ethers.utils.parseEther("1");
|
||||
const eETHTAddress = "0x35fA164735182de50811E8e2E824cFb9B6118ac2";
|
||||
const IERC20ABI = [
|
||||
"function approve(address spender, uint256 amount) external returns (bool)",
|
||||
"function balanceOf(address account) external view returns (uint256)",
|
||||
];
|
||||
const eETHContract = await ethers.getContractAt(IERC20ABI, eETHTAddress);
|
||||
|
||||
const initialBalance = await eETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"eETH Balance before:",
|
||||
ethers.utils.formatEther(initialBalance)
|
||||
);
|
||||
|
||||
const spells = [
|
||||
{
|
||||
connector: connectorName,
|
||||
method: "depositWeth",
|
||||
args: [amount, 0, 0],
|
||||
},
|
||||
];
|
||||
|
||||
const spellsEncoded = encodeSpells(spells);
|
||||
const tx = await dsaWallet0
|
||||
.connect(wallet0)
|
||||
.cast(...encodeSpells(spells), await wallet1.getAddress());
|
||||
const receipt = await tx.wait();
|
||||
|
||||
const finalBalance = await eETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"eETH Balance after:",
|
||||
ethers.utils.formatEther(finalBalance)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user