mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
Merge pull request #9 from Instadapp/feat/weeth-connector
eETH-weETH Connectors
This commit is contained in:
commit
ab3d5dc02d
7
contracts/mainnet/connectors/eeth/events.sol
Normal file
7
contracts/mainnet/connectors/eeth/events.sol
Normal file
|
@ -0,0 +1,7 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(uint256 amount, uint256 getId, uint256 setId);
|
||||
event LogDepositWeth(uint256 amount, uint256 getId, uint256 setId);
|
||||
}
|
12
contracts/mainnet/connectors/eeth/helpers.sol
Normal file
12
contracts/mainnet/connectors/eeth/helpers.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
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);
|
||||
}
|
6
contracts/mainnet/connectors/eeth/interfaces.sol
Normal file
6
contracts/mainnet/connectors/eeth/interfaces.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
interface IEtherfiPool {
|
||||
function deposit() external payable returns (uint256);
|
||||
}
|
71
contracts/mainnet/connectors/eeth/main.sol
Normal file
71
contracts/mainnet/connectors/eeth/main.sol
Normal file
|
@ -0,0 +1,71 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import "./helpers.sol";
|
||||
import "./events.sol";
|
||||
import {Basic} from "../../common/basic.sol";
|
||||
|
||||
contract EETHContract is Helpers, Basic, Events {
|
||||
/**
|
||||
* @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 wethAmount The amount of wETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of ETH deposited.
|
||||
*/
|
||||
function depositWeth(
|
||||
uint256 wethAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 _amount = getUint(getId, wethAmount);
|
||||
_amount = _amount == type(uint256).max
|
||||
? WETH_CONTRACT.balanceOf(address(this))
|
||||
: _amount;
|
||||
|
||||
uint256 _ethBeforeBalance = address(this).balance;
|
||||
WETH_CONTRACT.withdraw(_amount);
|
||||
uint256 _ethAfterBalance = address(this).balance;
|
||||
|
||||
uint256 _ethAmount = _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,
|
||||
uint256 setId
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amount = getUint(getId, amount);
|
||||
_amount = _amount == type(uint256).max
|
||||
? address(this).balance
|
||||
: _amount;
|
||||
|
||||
ETHERFI_POOL.deposit{value: _amount}();
|
||||
|
||||
setUint(setId, _amount);
|
||||
|
||||
_eventName = "LogDeposit(uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amount, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2EETH is EETHContract {
|
||||
string public name = "EETH-v1.0";
|
||||
}
|
17
contracts/mainnet/connectors/weeth/events.sol
Normal file
17
contracts/mainnet/connectors/weeth/events.sol
Normal file
|
@ -0,0 +1,17 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(
|
||||
uint256 eETHAmount,
|
||||
uint256 weETHAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
event LogWithdraw(
|
||||
uint256 weETHAmount,
|
||||
uint256 eETHAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
13
contracts/mainnet/connectors/weeth/helpers.sol
Normal file
13
contracts/mainnet/connectors/weeth/helpers.sol
Normal file
|
@ -0,0 +1,13 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import "./interfaces.sol";
|
||||
import {TokenInterface} from "../../common/interfaces.sol";
|
||||
|
||||
contract Helpers {
|
||||
IWEETH internal constant WEETH_CONTRACT =
|
||||
IWEETH(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee);
|
||||
|
||||
TokenInterface internal constant EETH_CONTRACT =
|
||||
TokenInterface(0x35fA164735182de50811E8e2E824cFb9B6118ac2);
|
||||
}
|
8
contracts/mainnet/connectors/weeth/interfaces.sol
Normal file
8
contracts/mainnet/connectors/weeth/interfaces.sol
Normal file
|
@ -0,0 +1,8 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
interface IWEETH {
|
||||
function balanceOf(address account) external view returns (uint256);
|
||||
function wrap(uint256 _eETHAmount) external returns (uint256);
|
||||
function unwrap(uint256 _weETHAmount) external returns (uint256);
|
||||
}
|
62
contracts/mainnet/connectors/weeth/main.sol
Normal file
62
contracts/mainnet/connectors/weeth/main.sol
Normal file
|
@ -0,0 +1,62 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import "./helpers.sol";
|
||||
import "./events.sol";
|
||||
import {Basic} from "../../common/basic.sol";
|
||||
|
||||
contract WEETHContract is Helpers, Basic, Events {
|
||||
/**
|
||||
* @dev Deposit eETH into weETH.
|
||||
* @notice Wrap eETH into weETH
|
||||
* @param eETHAmount The amount of eETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve eETH amount.
|
||||
* @param setId ID stores the amount of weETH deposited.
|
||||
*/
|
||||
function deposit(
|
||||
uint256 eETHAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 _eETHAmount = getUint(getId, eETHAmount);
|
||||
_eETHAmount = _eETHAmount == type(uint256).max
|
||||
? EETH_CONTRACT.balanceOf(address(this))
|
||||
: _eETHAmount;
|
||||
|
||||
approve(EETH_CONTRACT, address(WEETH_CONTRACT), _eETHAmount);
|
||||
uint256 _weETHAmount = WEETH_CONTRACT.wrap(_eETHAmount);
|
||||
|
||||
setUint(setId, _weETHAmount);
|
||||
|
||||
_eventName = "LogDeposit(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_eETHAmount, _weETHAmount, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw eETH from weETH from Smart Account
|
||||
* @notice Unwrap eETH from weETH
|
||||
* @param weETHAmount The amount of weETH to withdraw. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve weETH amount.
|
||||
* @param setId ID stores the amount of eETH.
|
||||
*/
|
||||
function withdraw(
|
||||
uint256 weETHAmount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 _weETHAmount = getUint(getId, weETHAmount);
|
||||
_weETHAmount = _weETHAmount == type(uint256).max
|
||||
? WEETH_CONTRACT.balanceOf(address(this))
|
||||
: _weETHAmount;
|
||||
|
||||
uint256 _eETHAmount = WEETH_CONTRACT.unwrap(_weETHAmount);
|
||||
setUint(setId, _eETHAmount);
|
||||
|
||||
_eventName = "LogWithdraw(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_weETHAmount, _eETHAmount, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2WEETH is WEETHContract {
|
||||
string public constant name = "WEETH-v1.0";
|
||||
}
|
180
test/mainnet/eeth/eeth.test.ts
Normal file
180
test/mainnet/eeth/eeth.test.ts
Normal file
|
@ -0,0 +1,180 @@
|
|||
import hre from "hardhat";
|
||||
import { expect } from "chai";
|
||||
const { ethers } = hre;
|
||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import { ConnectV2EETH__factory } from "../../../typechain";
|
||||
import type { Signer, Contract } from "ethers";
|
||||
|
||||
describe("eETH Staking", function () {
|
||||
const connectorName = "eETH-test";
|
||||
|
||||
let dsaWallet0: Contract;
|
||||
let wallet0: Signer, wallet1: Signer;
|
||||
let masterSigner: Signer;
|
||||
let instaConnectorsV2: Contract;
|
||||
let connector: Contract;
|
||||
|
||||
before(async () => {
|
||||
[wallet0, wallet1] = await ethers.getSigners();
|
||||
masterSigner = await getMasterSigner();
|
||||
instaConnectorsV2 = await ethers.getContractAt(
|
||||
abis.core.connectorsV2,
|
||||
addresses.core.connectorsV2
|
||||
);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: ConnectV2EETH__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2,
|
||||
});
|
||||
console.log("Connector address", connector.address);
|
||||
});
|
||||
|
||||
it("Should have contracts deployed.", async function () {
|
||||
expect(!!instaConnectorsV2.address).to.be.true;
|
||||
expect(!!connector.address).to.be.true;
|
||||
expect(!!(await masterSigner.getAddress())).to.be.true;
|
||||
});
|
||||
|
||||
describe("DSA wallet setup", function () {
|
||||
it("Should build DSA v2", async function () {
|
||||
dsaWallet0 = await buildDSAv2(await wallet0.getAddress());
|
||||
expect(!!dsaWallet0.address).to.be.true;
|
||||
});
|
||||
|
||||
it("Deposit ETH into DSA wallet", async function () {
|
||||
await wallet0.sendTransaction({
|
||||
to: dsaWallet0.address,
|
||||
value: ethers.utils.parseEther("10"),
|
||||
});
|
||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
||||
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 () {
|
||||
it("Should deposit ETH 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: "deposit",
|
||||
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)
|
||||
);
|
||||
});
|
||||
|
||||
it("Should deposit wETH into eETH", async function () {
|
||||
const amount = ethers.utils.parseEther("10");
|
||||
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)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
167
test/mainnet/weeth/weeth.test.ts
Normal file
167
test/mainnet/weeth/weeth.test.ts
Normal file
|
@ -0,0 +1,167 @@
|
|||
import hre from "hardhat";
|
||||
import { expect } from "chai";
|
||||
const { ethers } = hre;
|
||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import { ConnectV2WEETH__factory } from "../../../typechain";
|
||||
import type { Signer, Contract } from "ethers";
|
||||
|
||||
describe("Wrapping / Unwrapping eETH", function () {
|
||||
const connectorName = "weETH-test";
|
||||
|
||||
let dsaWallet0: Contract;
|
||||
let wallet0: Signer, wallet1: Signer;
|
||||
let masterSigner: Signer;
|
||||
let instaConnectorsV2: Contract;
|
||||
let connector: Contract;
|
||||
|
||||
before(async () => {
|
||||
[wallet0, wallet1] = await ethers.getSigners();
|
||||
masterSigner = await getMasterSigner();
|
||||
instaConnectorsV2 = await ethers.getContractAt(
|
||||
abis.core.connectorsV2,
|
||||
addresses.core.connectorsV2
|
||||
);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: ConnectV2WEETH__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2,
|
||||
});
|
||||
console.log("Connector address", connector.address);
|
||||
});
|
||||
|
||||
it("Should have contracts deployed.", async function () {
|
||||
expect(!!instaConnectorsV2.address).to.be.true;
|
||||
expect(!!connector.address).to.be.true;
|
||||
expect(!!(await masterSigner.getAddress())).to.be.true;
|
||||
});
|
||||
|
||||
describe("DSA wallet setup", function () {
|
||||
it("Should build DSA v2", async function () {
|
||||
dsaWallet0 = await buildDSAv2(await wallet0.getAddress());
|
||||
expect(!!dsaWallet0.address).to.be.true;
|
||||
});
|
||||
|
||||
it("Deposit ETH into DSA wallet", async function () {
|
||||
await wallet0.sendTransaction({
|
||||
to: dsaWallet0.address,
|
||||
value: ethers.utils.parseEther("10"),
|
||||
});
|
||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
||||
ethers.utils.parseEther("10")
|
||||
);
|
||||
});
|
||||
|
||||
it("Topup eETH into DSA wallet", async function () {
|
||||
const eETHTAddress = "0x35fA164735182de50811E8e2E824cFb9B6118ac2";
|
||||
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 eETHHolder = "0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee";
|
||||
const amount = ethers.utils.parseEther("10");
|
||||
|
||||
const eETHContract = await ethers.getContractAt(IERC20ABI, eETHTAddress);
|
||||
await hre.network.provider.send("hardhat_setBalance", [
|
||||
eETHHolder,
|
||||
"0x56BC75E2D63100000",
|
||||
]);
|
||||
|
||||
console.log(
|
||||
"Holder eETH Balance before topup:",
|
||||
ethers.utils.formatEther(await eETHContract.balanceOf(eETHHolder))
|
||||
);
|
||||
console.log(
|
||||
"holder ETH Balance before topup:",
|
||||
ethers.utils.formatEther(await ethers.provider.getBalance(eETHHolder))
|
||||
);
|
||||
await hre.network.provider.request({
|
||||
method: "hardhat_impersonateAccount",
|
||||
params: [eETHHolder],
|
||||
});
|
||||
const eETHHolderSigner = await ethers.getSigner(eETHHolder);
|
||||
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 eETH Balance after topup:",
|
||||
ethers.utils.formatEther(balance)
|
||||
);
|
||||
|
||||
await hre.network.provider.request({
|
||||
method: "hardhat_stopImpersonatingAccount",
|
||||
params: [eETHHolder],
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("Main", function () {
|
||||
it("Should wrap and unwrap eETH", async function () {
|
||||
const eETHTAddress = "0x35fA164735182de50811E8e2E824cFb9B6118ac2";
|
||||
const weETHAddress = "0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee";
|
||||
const IERC20ABI = [
|
||||
"function balanceOf(address account) external view returns (uint256)",
|
||||
];
|
||||
const eETHContract = await ethers.getContractAt(IERC20ABI, eETHTAddress);
|
||||
const weETHContract = await ethers.getContractAt(IERC20ABI, weETHAddress);
|
||||
const amount = ethers.utils.parseEther("10");
|
||||
const initialBalance = await weETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"weETH Balance before wrapping:",
|
||||
ethers.utils.formatEther(initialBalance)
|
||||
);
|
||||
console.log("Wrapping 10 eETH to weETH");
|
||||
const spells = [
|
||||
{
|
||||
connector: connectorName,
|
||||
method: "deposit",
|
||||
args: [amount, 0, 0],
|
||||
},
|
||||
];
|
||||
const spellsEncoded = encodeSpells(spells);
|
||||
const tx = await dsaWallet0
|
||||
.connect(wallet0)
|
||||
.cast(...spellsEncoded, await wallet1.getAddress());
|
||||
const receipt = await tx.wait();
|
||||
const finalBalance = await weETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"weETH Balance after wrapping:",
|
||||
ethers.utils.formatEther(finalBalance)
|
||||
);
|
||||
|
||||
const uint256Max = ethers.BigNumber.from(2).pow(256).sub(1);
|
||||
const initialBalance2 = await eETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"eETH Balance before unwrapping:",
|
||||
ethers.utils.formatEther(initialBalance2)
|
||||
);
|
||||
console.log("Unwrapping all eETH to ETH");
|
||||
const spells2 = [
|
||||
{
|
||||
connector: connectorName,
|
||||
method: "withdraw",
|
||||
args: [uint256Max, 0, 0],
|
||||
},
|
||||
];
|
||||
const spellsEncoded2 = encodeSpells(spells2);
|
||||
const tx2 = await dsaWallet0
|
||||
.connect(wallet0)
|
||||
.cast(...spellsEncoded2, await wallet1.getAddress());
|
||||
const receipt2 = await tx2.wait();
|
||||
const finalBalance2 = await eETHContract.balanceOf(dsaWallet0.address);
|
||||
console.log(
|
||||
"eETH Balance after unwrapping:",
|
||||
ethers.utils.formatEther(finalBalance2)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user