mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
feat: update testscript
This commit is contained in:
parent
00d0da5326
commit
71891feaac
|
@ -178,11 +178,11 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
wmul(maxSharesPerToken, _underlyingAmt)
|
wmul(maxSharesPerToken, _underlyingAmt)
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 _initalVaultBal = vaultTokenContract.balanceOf(address(this));
|
uint256 _initalVaultBal = vaultTokenContract.balanceOf(to);
|
||||||
|
|
||||||
vaultTokenContract.withdraw(_underlyingAmt, to, address(this));
|
vaultTokenContract.withdraw(_underlyingAmt, to, address(this));
|
||||||
|
|
||||||
uint256 _finalVaultBal = vaultTokenContract.balanceOf(address(this));
|
uint256 _finalVaultBal = vaultTokenContract.balanceOf(to);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
_maxShares >= sub(_finalVaultBal, _initalVaultBal),
|
_maxShares >= sub(_finalVaultBal, _initalVaultBal),
|
||||||
|
@ -234,20 +234,19 @@ abstract contract BasicConnector is Events, DSMath, Basic {
|
||||||
? vaultTokenContract.balanceOf(address(this))
|
? vaultTokenContract.balanceOf(address(this))
|
||||||
: _shareAmt;
|
: _shareAmt;
|
||||||
|
|
||||||
uint256 _minUnderlyingAmt = convertTo18(
|
uint256 _minUnderlyingAmt = convert18ToDec(
|
||||||
_vaultShareDecimal,
|
_vaultShareDecimal,
|
||||||
wmul(minTokenPerShares, _shareAmt)
|
wmul(minTokenPerShares, _shareAmt)
|
||||||
);
|
);
|
||||||
// uint256 _minUnderlyingAmt = (shareAmt * minTokenPerShares) / 10**18;
|
|
||||||
|
|
||||||
uint256 _initalUnderlyingBal = IERC20(_underlyingToken).balanceOf(
|
uint256 _initalUnderlyingBal = IERC20(_underlyingToken).balanceOf(
|
||||||
address(this)
|
to
|
||||||
);
|
);
|
||||||
|
|
||||||
vaultTokenContract.redeem(_shareAmt, to, address(this));
|
vaultTokenContract.redeem(_shareAmt, to, address(this));
|
||||||
|
|
||||||
uint256 _finalUnderlyingBal = IERC20(_underlyingToken).balanceOf(
|
uint256 _finalUnderlyingBal = IERC20(_underlyingToken).balanceOf(
|
||||||
address(this)
|
to
|
||||||
);
|
);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"check": "ts-node status-checks/huskyCheck.ts",
|
"check": "ts-node status-checks/huskyCheck.ts",
|
||||||
"check-husky": "ts-node status-checks/huskyCheck.ts",
|
"check-husky": "ts-node status-checks/huskyCheck.ts",
|
||||||
"deploy": "ts-node scripts/deployConnectorsFromCmd.ts",
|
"deploy": "ts-node scripts/deployConnectorsFromCmd.ts",
|
||||||
"test:runner": "NODE_OPTIONS='--max-old-space-size=4096' hardhat run scripts/tests/run-tests.ts",
|
"test:runner": "NODE_OPTIONS='--max-old-space-size=8192' hardhat run scripts/tests/run-tests.ts",
|
||||||
"typechain": "hardhat typechain",
|
"typechain": "hardhat typechain",
|
||||||
"compile": "hardhat compile",
|
"compile": "hardhat compile",
|
||||||
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts",
|
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts",
|
||||||
|
|
|
@ -93,46 +93,41 @@ describe("BASIC-D", function () {
|
||||||
value: ethers.utils.parseEther("10")
|
value: ethers.utils.parseEther("10")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
||||||
|
|
||||||
let balance = await ethers.provider.getBalance(account);
|
// let balance = await ethers.provider.getBalance(account);
|
||||||
console.log("1:", balance);
|
// console.log("1:", balance);
|
||||||
balance = await daiContract.balanceOf(account);
|
// balance = await daiContract.balanceOf(account);
|
||||||
console.log("2:", balance);
|
// console.log("2:", balance);
|
||||||
let txRes = await daiContract.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("10000"));
|
let txRes = await daiContract.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("10000"));
|
||||||
await txRes.wait();
|
await txRes.wait();
|
||||||
expect(await daiContract.balanceOf(dsaWallet0.address)).to.be.eq(ethers.utils.parseEther("10000"));
|
// expect(await daiContract.balanceOf(dsaWallet0.address)).to.be.eq(ethers.utils.parseEther("10000"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Main", function () {
|
describe("Main", function () {
|
||||||
it("Calculate Total Asset and Total Supply", async () => {
|
// it("Calculate Total Asset and Total Supply", async () => {
|
||||||
const totalAsset = await erc4626Contract.totalAssets();
|
// const totalAsset = await erc4626Contract.totalAssets();
|
||||||
const totalSupply = await erc4626Contract.totalSupply();
|
// const totalSupply = await erc4626Contract.totalSupply();
|
||||||
console.log("totalAsset :>> ", totalAsset);
|
// console.log("totalAsset :>> ", totalAsset);
|
||||||
console.log("totalSupply :>> ", totalSupply);
|
// console.log("totalSupply :>> ", totalSupply);
|
||||||
});
|
// });
|
||||||
it("should deposit asset to ERC4626", async () => {
|
it("should deposit asset to ERC4626", async () => {
|
||||||
const assets = ethers.utils.parseEther("1");
|
const assets = ethers.utils.parseEther("1");
|
||||||
const previewDeposit = await erc4626Contract.previewDeposit(assets);
|
const previewDeposit = await erc4626Contract.previewDeposit(assets);
|
||||||
console.log("previewDeposit :>> ", previewDeposit);
|
console.log("previewDeposit :>> ", previewDeposit);
|
||||||
|
|
||||||
const maxDeposit = await erc4626Contract.maxDeposit(dsaWallet0.address);
|
const maxDeposit = await erc4626Contract.maxDeposit(dsaWallet0.address);
|
||||||
console.log("maxDeposit :>> ", maxDeposit);
|
// console.log("maxDeposit :>> ", maxDeposit);
|
||||||
// const maxMint = await erc4626Contract.maxMint();
|
// const maxMint = await erc4626Contract.maxMint();
|
||||||
// console.log("maxMint :>> ", maxMint);
|
// console.log("maxMint :>> ", maxMint);
|
||||||
|
|
||||||
const minSharesPerToken = ethers.utils.parseUnits("0.8");
|
const minSharesPerToken = ethers.utils.parseUnits("0.95");
|
||||||
|
|
||||||
const beforbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const beforebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
||||||
console.log("beforbalance :>> ", beforbalance);
|
console.log("beforebalance :>> ", beforebalance);
|
||||||
|
|
||||||
const spells = [
|
const spells = [
|
||||||
// {
|
|
||||||
// connector: connectorName,
|
|
||||||
// method: "deposit",
|
|
||||||
// args: [sDAIaddress, new BigNumber(1).toString(), 0, 0]
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "deposit",
|
method: "deposit",
|
||||||
|
@ -148,21 +143,19 @@ describe("BASIC-D", function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
it("should mint asset to ERC4626", async () => {
|
it("should mint asset to ERC4626", async () => {
|
||||||
const daiBalance = await daiContract.balanceOf(dsaWallet0.address);
|
// const daiBalance = await daiContract.balanceOf(dsaWallet0.address);
|
||||||
console.log("daiBalance :>> ", daiBalance);
|
// console.log("daiBalance :>> ", daiBalance);
|
||||||
const shares = ethers.utils.parseEther("1");
|
const shares = ethers.utils.parseEther("1.03");
|
||||||
const previewMint = await erc4626Contract.previewMint(shares);
|
const previewMint = await erc4626Contract.previewMint(shares);
|
||||||
console.log("previewMint :>> ", previewMint);
|
console.log("previewMint :>> ", previewMint);
|
||||||
|
|
||||||
|
const maxTokenPerShares = ethers.utils.parseUnits("1.1");
|
||||||
|
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "mint",
|
method: "mint",
|
||||||
args: [sDAIaddress, new BigNumber(1).toString(), 0, 0]
|
args: [sDAIaddress, previewMint, maxTokenPerShares, 0, 0]
|
||||||
},
|
|
||||||
{
|
|
||||||
connector: connectorName,
|
|
||||||
method: "mint",
|
|
||||||
args: [sDAIaddress, previewMint, 0, 0]
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -171,49 +164,68 @@ describe("BASIC-D", function () {
|
||||||
});
|
});
|
||||||
it("should redeem asset to ERC4626", async () => {
|
it("should redeem asset to ERC4626", async () => {
|
||||||
// const shares = new BigNumber(1).toString()
|
// const shares = new BigNumber(1).toString()
|
||||||
const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
// const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
||||||
console.log("balance :>> ", balance);
|
// console.log("balance :>> ", balance);
|
||||||
|
|
||||||
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
|
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
|
||||||
console.log("maxRedeem :>> ", maxRedeem);
|
console.log("maxRedeem :>> ", maxRedeem);
|
||||||
|
|
||||||
|
const minTokenPerShares = ethers.utils.parseUnits("1.01");
|
||||||
|
|
||||||
|
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
|
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
|
||||||
|
|
||||||
|
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
|
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
|
||||||
|
|
||||||
const setId = "83478237";
|
const setId = "83478237";
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "redeem",
|
method: "redeem",
|
||||||
args: [sDAIaddress, new BigNumber(1).toString(), wallet0.address, 0, setId]
|
args: [sDAIaddress, maxRedeem.div(2), minTokenPerShares, wallet0.address, 0, setId]
|
||||||
},
|
|
||||||
{
|
|
||||||
connector: connectorName,
|
|
||||||
method: "redeem",
|
|
||||||
args: [sDAIaddress, maxRedeem.div(2), wallet0.address, 0, setId]
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
|
console.log("afterUnderbalance :>> ", afterUnderbalance);
|
||||||
|
|
||||||
|
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
|
console.log("afterVaultbalance :>> ", afterVaultbalance);
|
||||||
|
|
||||||
});
|
});
|
||||||
it("should withdraw asset to ERC4626", async () => {
|
it("should withdraw asset to ERC4626", async () => {
|
||||||
const maxWithdraw : BigNumber = await erc4626Contract.maxWithdraw(dsaWallet0.address);
|
const maxWithdraw: BigNumber = await erc4626Contract.maxWithdraw(dsaWallet0.address);
|
||||||
console.log("maxWithdraw :>> ", maxWithdraw);
|
console.log("maxWithdraw :>> ", maxWithdraw);
|
||||||
|
|
||||||
|
const maxSharesPerToken = ethers.utils.parseUnits("0.95");
|
||||||
|
|
||||||
|
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
|
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
|
||||||
|
|
||||||
|
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
|
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
|
||||||
|
|
||||||
const setId = "83478237";
|
const setId = "83478237";
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "withdraw",
|
method: "withdraw",
|
||||||
args: [sDAIaddress, new BigNumber(1).toString(), wallet0.address, 0, setId]
|
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, wallet0.address, 0, setId]
|
||||||
},
|
|
||||||
{
|
|
||||||
connector: connectorName,
|
|
||||||
method: "withdraw",
|
|
||||||
args: [sDAIaddress, maxWithdraw, wallet0.address, 0, setId]
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
|
console.log("afterUnderbalance :>> ", afterUnderbalance);
|
||||||
|
|
||||||
|
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
|
console.log("afterVaultbalance :>> ", afterVaultbalance);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user