mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
parent
eae28b5553
commit
88038ed8ff
|
@ -93,7 +93,7 @@ describe("BASIC-D", function () {
|
||||||
value: ethers.utils.parseEther("10")
|
value: ethers.utils.parseEther("10")
|
||||||
});
|
});
|
||||||
|
|
||||||
let txRes = await daiContract.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("1000"));
|
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"));
|
||||||
});
|
});
|
||||||
|
@ -108,17 +108,15 @@ describe("BASIC-D", function () {
|
||||||
// });
|
// });
|
||||||
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");
|
||||||
|
|
||||||
// Returns the amount of shares for assets
|
|
||||||
const previewDeposit = await erc4626Contract.previewDeposit(assets);
|
const previewDeposit = await erc4626Contract.previewDeposit(assets);
|
||||||
console.log("previewDeposit :>> ", previewDeposit.toString());
|
console.log("previewDeposit :>> ", previewDeposit);
|
||||||
|
|
||||||
const maxDeposit = await erc4626Contract.maxDeposit(dsaWallet0.address);
|
const maxDeposit = await erc4626Contract.maxDeposit(dsaWallet0.address);
|
||||||
|
|
||||||
let minSharesPerToken = ethers.utils.parseUnits("0.95");
|
let minSharesPerToken = ethers.utils.parseUnits("0.95");
|
||||||
|
|
||||||
const beforebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const beforebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
||||||
console.log("Share before balance :>> ", beforebalance.toString());
|
console.log("beforebalance :>> ", beforebalance);
|
||||||
|
|
||||||
let spells = [
|
let spells = [
|
||||||
{
|
{
|
||||||
|
@ -132,9 +130,7 @@ describe("BASIC-D", function () {
|
||||||
let receipt = await tx.wait();
|
let receipt = await tx.wait();
|
||||||
|
|
||||||
const afterbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const afterbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
||||||
console.log("Share after balance :>> ", afterbalance.toString());
|
console.log("afterbalance :>> ", afterbalance);
|
||||||
|
|
||||||
expect(afterbalance.sub(beforebalance)).to.be.lte(previewDeposit)
|
|
||||||
|
|
||||||
// In case of not satisfying min rate
|
// In case of not satisfying min rate
|
||||||
minSharesPerToken = ethers.utils.parseUnits("1");
|
minSharesPerToken = ethers.utils.parseUnits("1");
|
||||||
|
@ -150,15 +146,11 @@ describe("BASIC-D", function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
it("should mint asset to ERC4626", async () => {
|
it("should mint asset to ERC4626", async () => {
|
||||||
const beforeBalance = await daiContract.balanceOf(dsaWallet0.address);
|
// const daiBalance = await daiContract.balanceOf(dsaWallet0.address);
|
||||||
console.log("token balance before :>> ", beforeBalance.toString());
|
// console.log("daiBalance :>> ", daiBalance);
|
||||||
const beforeSharebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const shares = ethers.utils.parseEther("1.03");
|
||||||
console.log("share balance before :>> ", beforeSharebalance.toString());
|
|
||||||
|
|
||||||
const shares = ethers.utils.parseEther("1");
|
|
||||||
// Returns token amount for shares
|
|
||||||
const previewMint = await erc4626Contract.previewMint(shares);
|
const previewMint = await erc4626Contract.previewMint(shares);
|
||||||
console.log("Token amount preview Mint :>> ", previewMint.toString());
|
console.log("previewMint :>> ", previewMint);
|
||||||
|
|
||||||
let maxTokenPerShares = ethers.utils.parseUnits("1.1");
|
let maxTokenPerShares = ethers.utils.parseUnits("1.1");
|
||||||
|
|
||||||
|
@ -166,18 +158,13 @@ describe("BASIC-D", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "mint",
|
method: "mint",
|
||||||
args: [sDAIaddress, shares, maxTokenPerShares, 0, 0]
|
args: [sDAIaddress, previewMint, maxTokenPerShares, 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
||||||
let receipt = await tx.wait();
|
let receipt = await tx.wait();
|
||||||
|
|
||||||
const afterbalance = await daiContract.balanceOf(dsaWallet0.address);
|
|
||||||
console.log("token balance after :>> ", afterbalance.toString());
|
|
||||||
const afterSharebalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
|
||||||
console.log("share balance after :>> ", afterSharebalance.toString());
|
|
||||||
|
|
||||||
// In case of not satisfying max rate
|
// In case of not satisfying max rate
|
||||||
maxTokenPerShares = ethers.utils.parseUnits("1");
|
maxTokenPerShares = ethers.utils.parseUnits("1");
|
||||||
|
|
||||||
|
@ -185,26 +172,26 @@ describe("BASIC-D", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "mint",
|
method: "mint",
|
||||||
args: [sDAIaddress, shares, maxTokenPerShares, 0, 0]
|
args: [sDAIaddress, previewMint, maxTokenPerShares, 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
|
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
|
||||||
|
|
||||||
});
|
});
|
||||||
it("should Max redeem", async () => {
|
it("should redeem asset to ERC4626", async () => {
|
||||||
const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
// const shares = new BigNumber(1).toString()
|
||||||
console.log("Share balance :>> ", balance.toString());
|
// const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
||||||
|
// console.log("balance :>> ", balance);
|
||||||
|
|
||||||
// Returns max Shares
|
|
||||||
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
|
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
|
||||||
console.log("maxRedeem :>> ", maxRedeem.toString());
|
console.log("maxRedeem :>> ", maxRedeem);
|
||||||
|
|
||||||
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
|
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
|
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
|
||||||
|
|
||||||
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
|
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
|
||||||
|
|
||||||
let minTokenPerShares = ethers.utils.parseUnits("1.01");
|
let minTokenPerShares = ethers.utils.parseUnits("1.01");
|
||||||
|
|
||||||
|
@ -213,101 +200,72 @@ describe("BASIC-D", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "redeem",
|
method: "redeem",
|
||||||
args: [sDAIaddress, ethers.constants.MaxUint256, minTokenPerShares, dsaWallet0.address, 0, setId]
|
args: [sDAIaddress, maxRedeem.div(2), minTokenPerShares, wallet0.address, 0, setId]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
||||||
let receipt = await tx.wait();
|
let receipt = await tx.wait();
|
||||||
|
|
||||||
const afterUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
|
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
console.log("afterUnderbalance :>> ", afterUnderbalance.toString());
|
console.log("afterUnderbalance :>> ", afterUnderbalance);
|
||||||
|
|
||||||
const afterVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
console.log("afterVaultbalance :>> ", afterVaultbalance.toString());
|
console.log("afterVaultbalance :>> ", afterVaultbalance);
|
||||||
});
|
|
||||||
|
|
||||||
it("should Revert for not satisfying min redeem rate", async () => {
|
|
||||||
const balance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
|
||||||
console.log("Share balance :>> ", balance.toString());
|
|
||||||
|
|
||||||
let spells = [
|
|
||||||
{
|
|
||||||
connector: connectorName,
|
|
||||||
method: "deposit",
|
|
||||||
args: [sDAIaddress, ethers.utils.parseEther("1"), ethers.utils.parseUnits("0.95"), 0, 0]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
|
||||||
let receipt = await tx.wait();
|
|
||||||
|
|
||||||
// Returns max Shares
|
|
||||||
const maxRedeem: BigNumber = await erc4626Contract.maxRedeem(dsaWallet0.address);
|
|
||||||
console.log("maxRedeem :>> ", maxRedeem.toString());
|
|
||||||
|
|
||||||
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
|
|
||||||
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
|
|
||||||
|
|
||||||
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
|
||||||
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
|
|
||||||
|
|
||||||
expect(beforeVaultbalance).to.be.gte("950000000000000000")
|
|
||||||
|
|
||||||
// In case of not satisfying min rate
|
// In case of not satisfying min rate
|
||||||
let minTokenPerShares = ethers.utils.parseUnits("1.5");
|
minTokenPerShares = ethers.utils.parseUnits("1.2");
|
||||||
|
|
||||||
spells = [
|
spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "redeem",
|
method: "redeem",
|
||||||
args: [sDAIaddress, ethers.constants.MaxUint256, minTokenPerShares, dsaWallet0.address, 0, 0]
|
args: [sDAIaddress, maxRedeem.div(2), minTokenPerShares, wallet0.address, 0, setId]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
|
await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address)).to.be.reverted;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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.toString());
|
console.log("maxWithdraw :>> ", maxWithdraw);
|
||||||
|
|
||||||
const beforeUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
|
const beforeUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
console.log("beforeUnderbalance :>> ", beforeUnderbalance.toString());
|
console.log("beforeUnderbalance :>> ", beforeUnderbalance);
|
||||||
|
|
||||||
const beforeVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const beforeVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
console.log("beforeVaultbalance :>> ", beforeVaultbalance.toString());
|
console.log("beforeVaultbalance :>> ", beforeVaultbalance);
|
||||||
|
|
||||||
let maxSharesPerToken = ethers.utils.parseUnits("0.975");
|
let maxSharesPerToken = ethers.utils.parseUnits("0.95");
|
||||||
|
|
||||||
const setId = "83478237";
|
const setId = "83478237";
|
||||||
let spells = [
|
let spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "withdraw",
|
method: "withdraw",
|
||||||
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, dsaWallet0.address, 0, setId]
|
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, wallet0.address, 0, setId]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
let tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
|
||||||
let receipt = await tx.wait();
|
let receipt = await tx.wait();
|
||||||
|
|
||||||
const afterUnderbalance = await daiContract.balanceOf(dsaWallet0.address);
|
const afterUnderbalance = await daiContract.balanceOf(wallet0.address);
|
||||||
console.log("afterUnderbalance :>> ", afterUnderbalance.toString());
|
console.log("afterUnderbalance :>> ", afterUnderbalance);
|
||||||
|
|
||||||
const afterVaultbalance = await erc4626Contract.balanceOf(dsaWallet0.address);
|
const afterVaultbalance = await erc4626Contract.balanceOf(wallet0.address);
|
||||||
console.log("afterVaultbalance :>> ", afterVaultbalance.toString());
|
console.log("afterVaultbalance :>> ", afterVaultbalance);
|
||||||
|
|
||||||
// In case of not satisfying min rate
|
// In case of not satisfying min rate
|
||||||
|
|
||||||
maxSharesPerToken = ethers.utils.parseUnits("0.95");
|
maxSharesPerToken = ethers.utils.parseUnits("1");
|
||||||
|
|
||||||
spells = [
|
spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "withdraw",
|
method: "withdraw",
|
||||||
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, dsaWallet0.address, 0, setId]
|
args: [sDAIaddress, maxWithdraw, maxSharesPerToken, wallet0.address, 0, setId]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user