mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	fix bug and update test script
This commit is contained in:
		
							parent
							
								
									cf06f90a72
								
							
						
					
					
						commit
						4980c0c9a0
					
				| 
						 | 
				
			
			@ -16,5 +16,5 @@ interface IController {
 | 
			
		|||
    function liquidate(address user, uint256 min_x, bool use_eth) external;
 | 
			
		||||
    function max_borrowable(uint256 collateral, uint256 N) external view returns(uint256);
 | 
			
		||||
    function min_collateral(uint256 debt, uint256 N) external view returns(uint256);
 | 
			
		||||
    function user_state(address user) external view returns(uint256[] memory);
 | 
			
		||||
    function user_state(address user) external view returns(uint256[4] memory);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,9 +132,8 @@ abstract contract MakerResolver is Helpers, Events {
 | 
			
		|||
            approve(collateralContract, address(controller), _amt);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        uint256[] memory res = controller.user_state(address(this));
 | 
			
		||||
 | 
			
		||||
        uint256 _debt = debt == uint(-1) ? controller.max_borrowable(_amt, res[3]) : debt;
 | 
			
		||||
        uint256[4] memory res = controller.user_state(address(this));
 | 
			
		||||
        uint256 _debt = debt == uint(-1) ? controller.max_borrowable(_amt + res[0], res[3]) - res[2] : debt;
 | 
			
		||||
 | 
			
		||||
        controller.borrow_more{value: ethAmt}(_amt, _debt);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -186,77 +186,6 @@ describe("CRV USD", function () {
 | 
			
		|||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // it("Revert when loan exists", async function () {
 | 
			
		||||
    //   const spells = [
 | 
			
		||||
    //     {
 | 
			
		||||
    //       connector: connectorName,
 | 
			
		||||
    //       method: "createLoan",
 | 
			
		||||
    //       args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10]
 | 
			
		||||
    //     }
 | 
			
		||||
    //   ];
 | 
			
		||||
 | 
			
		||||
    //   await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)).to.be.revertedWith('Loan already created');
 | 
			
		||||
    // });
 | 
			
		||||
 | 
			
		||||
    // it("create loan with maximum debt", async function () {
 | 
			
		||||
    //   const spells = [
 | 
			
		||||
    //     {
 | 
			
		||||
    //       connector: connectorName,
 | 
			
		||||
    //       method: "createLoan",
 | 
			
		||||
    //       args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10]
 | 
			
		||||
    //     }
 | 
			
		||||
    //   ];
 | 
			
		||||
 | 
			
		||||
    //   const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
    //   await tx.wait();
 | 
			
		||||
 | 
			
		||||
    //   expect(await crvUSD.balanceOf(dsaWallet1.address)).to.be.gt(
 | 
			
		||||
    //     ethers.utils.parseEther("1000")
 | 
			
		||||
    //   );
 | 
			
		||||
 | 
			
		||||
    //   console.log("maximum debt amount: ", (await crvUSD.balanceOf(dsaWallet1.address)).toString() )
 | 
			
		||||
    // });
 | 
			
		||||
 | 
			
		||||
    // it("Create Loan with maximum collateral and maximum debt", async function () {
 | 
			
		||||
    //   const spells = [
 | 
			
		||||
    //     {
 | 
			
		||||
    //       connector: connectorName,
 | 
			
		||||
    //       method: "createLoan",
 | 
			
		||||
    //       args: [tokens.sfrxeth.address, dsaMaxValue, dsaMaxValue, 10]
 | 
			
		||||
    //     }
 | 
			
		||||
    //   ];
 | 
			
		||||
 | 
			
		||||
    //   const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
    //   await tx.wait();
 | 
			
		||||
 | 
			
		||||
    //   expect(await crvUSD.balanceOf(dsaWallet2.address)).to.be.gt(
 | 
			
		||||
    //     ethers.utils.parseEther("1000").toString()
 | 
			
		||||
    //   );
 | 
			
		||||
    //   expect(await sfrxEth.balanceOf(dsaWallet2.address)).to.be.eq(
 | 
			
		||||
    //     '0'
 | 
			
		||||
    //   );
 | 
			
		||||
    //   console.log("maximum debt amount after maximum collateral: ", (await crvUSD.balanceOf(dsaWallet2.address)).toString() )
 | 
			
		||||
    // });
 | 
			
		||||
 | 
			
		||||
    // it("Create Loan with eth", async function () {
 | 
			
		||||
    //   const balance = await ethers.provider.getBalance(dsaWallet0.address)
 | 
			
		||||
    //   const spells = [
 | 
			
		||||
    //     {
 | 
			
		||||
    //       connector: connectorName,
 | 
			
		||||
    //       method: "createLoan",
 | 
			
		||||
    //       args: [tokens.eth.address, ethers.utils.parseEther('2').toString(), dsaMaxValue, 10]
 | 
			
		||||
    //     }
 | 
			
		||||
    //   ];
 | 
			
		||||
 | 
			
		||||
    //   const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
    //   await tx.wait();
 | 
			
		||||
 | 
			
		||||
    //   expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.eq(
 | 
			
		||||
    //     ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('2'))
 | 
			
		||||
    //   );
 | 
			
		||||
    //   console.log("maximum debt amount after create loan with 2 eth: ", (await crvUSD.balanceOf(dsaWallet0.address)).toString() )
 | 
			
		||||
    // });
 | 
			
		||||
 | 
			
		||||
    it("add Collateral", async function () {
 | 
			
		||||
      const balance = await sfrxEth.balanceOf(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
| 
						 | 
				
			
			@ -317,7 +246,132 @@ describe("CRV USD", function () {
 | 
			
		|||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "borrowMore",
 | 
			
		||||
          args: [tokens.sfrxeth.address, '0', dsaMaxValue]
 | 
			
		||||
          args: [tokens.sfrxeth.address, ethers.utils.parseEther('2'), dsaMaxValue]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.gt(
 | 
			
		||||
        ethers.BigNumber.from(balance).add(ethers.utils.parseEther('100'))
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("Revert when loan exists", async function () {
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "createLoan",
 | 
			
		||||
          args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      await expect(dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)).to.be.revertedWith('Loan already created');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("create loan with maximum debt", async function () {
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "createLoan",
 | 
			
		||||
          args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await crvUSD.balanceOf(dsaWallet1.address)).to.be.gt(
 | 
			
		||||
        ethers.utils.parseEther("1000")
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      console.log("maximum debt amount: ", (await crvUSD.balanceOf(dsaWallet1.address)).toString() )
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("Create Loan with maximum collateral and maximum debt", async function () {
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "createLoan",
 | 
			
		||||
          args: [tokens.sfrxeth.address, dsaMaxValue, dsaMaxValue, 10]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet2.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await crvUSD.balanceOf(dsaWallet2.address)).to.be.gt(
 | 
			
		||||
        ethers.utils.parseEther("1000").toString()
 | 
			
		||||
      );
 | 
			
		||||
      expect(await sfrxEth.balanceOf(dsaWallet2.address)).to.be.eq(
 | 
			
		||||
        '0'
 | 
			
		||||
      );
 | 
			
		||||
      console.log("maximum debt amount after maximum collateral: ", (await crvUSD.balanceOf(dsaWallet2.address)).toString() )
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("Create Loan with eth", async function () {
 | 
			
		||||
      const balance = await ethers.provider.getBalance(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "createLoan",
 | 
			
		||||
          args: [tokens.eth.address, ethers.utils.parseEther('2').toString(), dsaMaxValue, 10]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.eq(
 | 
			
		||||
        ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('2'))
 | 
			
		||||
      );
 | 
			
		||||
      console.log("maximum debt amount after create loan with 2 eth: ", (await crvUSD.balanceOf(dsaWallet0.address)).toString() )
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("add Collateral eth", async function () {
 | 
			
		||||
      const balance = await ethers.provider.getBalance(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "addCollateral",
 | 
			
		||||
          args: [tokens.eth.address, ethers.utils.parseEther('3').toString(), 0, 0]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.eq(
 | 
			
		||||
        ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('3'))
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("remove Collateral eth", async function () {
 | 
			
		||||
      const balance = await ethers.provider.getBalance(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "removeCollateral",
 | 
			
		||||
          args: [tokens.eth.address, ethers.utils.parseEther('1').toString(), 0, 0]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.eq(
 | 
			
		||||
        ethers.BigNumber.from(balance).add(ethers.utils.parseEther('1'))
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("borrow more", async function () {
 | 
			
		||||
      const balance = await crvUSD.balanceOf(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "borrowMore",
 | 
			
		||||
          args: [tokens.eth.address, '0', ethers.utils.parseEther('10')]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -325,8 +379,26 @@ describe("CRV USD", function () {
 | 
			
		|||
      await tx.wait();
 | 
			
		||||
 | 
			
		||||
      expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.eq(
 | 
			
		||||
        ethers.BigNumber.from(balance).add(ethers.utils.parseEther('100'))
 | 
			
		||||
        ethers.BigNumber.from(balance).add(ethers.utils.parseEther('10'))
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("borrow more", async function () {
 | 
			
		||||
      const balance = await crvUSD.balanceOf(dsaWallet0.address)
 | 
			
		||||
      const spells = [
 | 
			
		||||
        {
 | 
			
		||||
          connector: connectorName,
 | 
			
		||||
          method: "borrowMore",
 | 
			
		||||
          args: [tokens.eth.address, '0', dsaMaxValue]
 | 
			
		||||
        }
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
      const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
 | 
			
		||||
      await tx.wait();
 | 
			
		||||
      expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.gt(
 | 
			
		||||
        ethers.BigNumber.from(balance).add(ethers.utils.parseEther('1000'))
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user