From f07e06e6ac1555c7dcc9f374ab834172f3c003fa Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sun, 30 Jul 2023 13:00:04 -0400 Subject: [PATCH 01/14] add crv connector --- .../mainnet/connectors/crv_USD/events.sol | 11 + .../mainnet/connectors/crv_USD/helpers.sol | 23 +++ .../mainnet/connectors/crv_USD/interface.sol | 20 ++ contracts/mainnet/connectors/crv_USD/main.sol | 195 ++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 contracts/mainnet/connectors/crv_USD/events.sol create mode 100644 contracts/mainnet/connectors/crv_USD/helpers.sol create mode 100644 contracts/mainnet/connectors/crv_USD/interface.sol create mode 100644 contracts/mainnet/connectors/crv_USD/main.sol diff --git a/contracts/mainnet/connectors/crv_USD/events.sol b/contracts/mainnet/connectors/crv_USD/events.sol new file mode 100644 index 00000000..64937640 --- /dev/null +++ b/contracts/mainnet/connectors/crv_USD/events.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogCreateLoan(address indexed collateral, uint256 amt, uint256 debt, uint256 indexed N); + event LogAddCollateral(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); + event LogRemoveCollateral(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); + event LogBorrowMore(address indexed collateral, uint256 indexed amt, uint256 indexed debt); + event LogRepay(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); + event LogLiquidate(address indexed collateral, uint256 indexed min_x); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/crv_USD/helpers.sol b/contracts/mainnet/connectors/crv_USD/helpers.sol new file mode 100644 index 00000000..c0d439c6 --- /dev/null +++ b/contracts/mainnet/connectors/crv_USD/helpers.sol @@ -0,0 +1,23 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + + address internal constant CRV_USD = 0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E; + /** + * @dev ControllerFactory Interface + */ + IControllerFactory internal constant ctrFactory = IControllerFactory(0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC); + + /** + * @dev Get controller address by given collateral asset + */ + function getController(address collateral) internal view returns(IController controller) { + controller = IController(ctrFactory.get_controller(collateral, 0)); + } +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/crv_USD/interface.sol b/contracts/mainnet/connectors/crv_USD/interface.sol new file mode 100644 index 00000000..df2856ac --- /dev/null +++ b/contracts/mainnet/connectors/crv_USD/interface.sol @@ -0,0 +1,20 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { TokenInterface } from "../../common/interfaces.sol"; + +interface IControllerFactory { + function get_controller(address collateral, uint256 index) external view returns (address); +} + +interface IController { + function create_loan(uint256 collateral, uint256 debt, uint256 N) payable external; + function add_collateral(uint256 collateral, address _for) payable external; + function remove_collateral(uint256 collateral, bool use_eth) external; + function borrow_more(uint256 collateral, uint256 debt) payable external; + function repay(uint256 _d_debt, address _for, int256 max_active_band, bool use_eth) payable external; + 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); +} diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol new file mode 100644 index 00000000..d55503ab --- /dev/null +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -0,0 +1,195 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +/** + * @title MakerDAO. + * @dev Collateralized Borrowing. + */ + +import { TokenInterface, AccountInterface } from "../../common/interfaces.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; +import "./interface.sol"; + +abstract contract MakerResolver is Helpers, Events { + /** + * @dev Create loan + * @param collateral collateral token address + * @param amt Amount of collateral to use + * @param debt Stablecoin debt to take + * @param N Number of bands to deposit into (to do autoliquidation-deliquidation), can be from MIN_TICKS(4) to MAX_TICKS(50) + */ + function createLoan( + address collateral, + uint256 amt, + uint256 debt, + uint256 N + ) external returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + uint256 _amt = amt; + + uint256 ethAmt; + if (collateral == ethAddr) { + _amt = _amt == uint(-1) ? address(this).balance : _amt; + ethAmt = _amt; + } else { + TokenInterface collateralContract = TokenInterface(_collateral); + _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; + approve(collateralContract, address(controller), _amt); + } + + uint256 _debt = debt == uint(-1) ? controller.max_borrowable(_amt, N) : debt; + + controller.create_loan{value: ethAmt}(_amt, _debt, N); + _eventName = "LogCreateLoan(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, debt, N); + } + + /** + * @dev Add collateral + * @notice Add extra collateral to avoid bad liqidations + * @param collateral collateral asset address + * @param amt Amount of collateral to add + * @param getId ID to retrieve amt. + * @param setId ID stores the collateral amount of tokens added. + */ + function addCollateral( + address collateral, + uint256 amt, + uint256 getId, + uint256 setId + ) external returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + uint _amt = getUint(getId, amt); + + uint ethAmt; + if (collateral == ethAddr) { + _amt = _amt == uint(-1) ? address(this).balance : _amt; + ethAmt = _amt; + } else { + TokenInterface collateralContract = TokenInterface(_collateral); + _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; + approve(collateralContract, address(controller), _amt); + } + + controller.add_collateral{value: ethAmt}(_amt, address(this)); + + setUint(setId, _amt); + _eventName = "LogAddCollateral(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, getId, setId); + } + + /** + * @dev Remove ETH/ERC20_Token Collateral. + * @notice Remove some collateral without repaying the debt + * @param collateral collateral asset address + * @param amt Amount of collateral to add + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function removeCollateral( + address collateral, + uint256 amt, + uint256 getId, + uint256 setId + ) external returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + uint _amt = getUint(getId, amt); + + controller.remove_collateral(_amt, collateral == ethAddr); + + setUint(setId, _amt); + + _eventName = "LogRemoveCollateral(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, getId, setId); + } + + /** + * @dev Borrow more stablecoins while adding more collateral (not necessary) + * @param collateral collateral token address + * @param amt Amount of collateral to add + * @param debt Amount of stablecoin debt to take + */ + function borrowMore( + address collateral, + uint256 amt, + uint256 debt + ) external returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + uint _amt = amt; + + uint ethAmt; + if (collateral == ethAddr) { + _amt = _amt == uint(-1) ? address(this).balance : _amt; + ethAmt = _amt; + } else { + TokenInterface collateralContract = TokenInterface(_collateral); + _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; + 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; + + controller.borrow_more{value: ethAmt}(_amt, _debt); + + _eventName = "LogBorrowMore(address,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, debt); + } + + /** + * @dev Borrow DAI. + * @notice Borrow DAI using a MakerDAO vault + * @param collateral collateral token address + * @param amt The amount of debt to repay. If higher than the current debt - will do full repayment + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of DAI borrowed. + */ + function repay( + address collateral, + uint256 amt, + uint256 getId, + uint256 setId + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + uint _amt = amt; + + TokenInterface stableCoin = TokenInterface(CRV_USD); + _amt = _amt == uint(-1) ? stableCoin.balanceOf(address(this)) : _amt; + TokenInterface collateralContract = TokenInterface(_collateral); + approve(collateralContract, address(controller), _amt); + + controller.repay(_amt, address(this), 2**255-1, true); + + _eventName = "LogRepay(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, getId, setId); + } + + /** + * @dev Peform a bad liquidation (or self-liquidation) of user if health is not good + * @param collateral collateral token address + * @param min_x Minimal amount of stablecoin to receive (to avoid liquidators being sandwiched) + */ + function liquidate( + address collateral, + uint256 min_x + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + address _collateral = collateral == ethAddr ? wethAddr : collateral; + IController controller = getController(_collateral); + + controller.liquidate(address(this), min_x, collateral == ethAddr); + + _eventName = "LogLiquidate(address,uint256)"; + _eventParam = abi.encode(collateral, min_x); + } +} + +contract ConnectV2MakerDAO is MakerResolver { + string public constant name = "CRV-USD-v1"; +} \ No newline at end of file From 7a708c9eec9f85dde0877f9114985e1ac4cdee6a Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sun, 30 Jul 2023 23:47:11 -0400 Subject: [PATCH 02/14] update test case --- contracts/mainnet/connectors/crv_USD/main.sol | 2 +- scripts/tests/mainnet/tokens.ts | 30 +++- test/mainnet/crv_usd/crv_usd.test.ts | 166 ++++++++++++++++++ 3 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 test/mainnet/crv_usd/crv_usd.test.ts diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index d55503ab..f1356de2 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -190,6 +190,6 @@ abstract contract MakerResolver is Helpers, Events { } } -contract ConnectV2MakerDAO is MakerResolver { +contract ConnectV2CRV is MakerResolver { string public constant name = "CRV-USD-v1"; } \ No newline at end of file diff --git a/scripts/tests/mainnet/tokens.ts b/scripts/tests/mainnet/tokens.ts index 41f31237..a8a06e50 100644 --- a/scripts/tests/mainnet/tokens.ts +++ b/scripts/tests/mainnet/tokens.ts @@ -76,7 +76,35 @@ export const tokens = { aTokenAddress: "0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1", cTokenAddress: "0x35A18000230DA775CAc24873d00Ff85BccdeD550", decimals: 18 - } + }, + crvusd: { + type: "token", + symbol: "crvUSD", + name: "Curve.Fi USD Stablecoin", + address: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E", + decimals: 18 + }, + sfrxeth: { + type: "token", + symbol: "sfrxETH", + name: "Staked Frax Ether", + address: "0xac3E018457B222d93114458476f3E3416Abbe38F", + decimals: 18 + }, + wsteth: { + type: "token", + symbol: "wstETH", + name: "Wrapped liquid staked Ether 2.0", + address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", + decimals: 18 + }, + wbtc: { + type: "token", + symbol: "WBTC", + name: "Wrapped BTC", + address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", + decimals: 8 + }, }; export const dsaMaxValue = "115792089237316195423570985008687907853269984665640564039457584007913129639935"; diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts new file mode 100644 index 00000000..ca4749e6 --- /dev/null +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -0,0 +1,166 @@ +import { expect } from "chai"; +import hre from "hardhat"; +const { waffle, ethers } = hre; +const { provider, deployContract } = waffle; + +import { Signer, Contract } from "ethers"; +import { BigNumber } from "bignumber.js"; + +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 { tokens } from "../../../scripts/tests/mainnet/tokens"; +import { abis } from "../../../scripts/constant/abis"; +import { constants } from "../../../scripts/constant/constant"; +import { ConnectV2CRV__factory } from "../../../typechain"; +import { MaxUint256 } from "@uniswap/sdk-core"; +import { USDC_OPTIMISTIC_KOVAN } from "@uniswap/smart-order-router"; + +describe("CRV USD", function () { + const connectorName = "CRV_USD-TEST-A"; + const market = "0xc3d688B66703497DAA19211EEdff47f25384cdc3"; + const base = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; + const wst_whale = "0x248cCBf4864221fC0E840F29BB042ad5bFC89B5c"; + const wethWhale = "0x78bB3aEC3d855431bd9289fD98dA13F9ebB7ef15"; + + const ABI = [ + "function balanceOf(address account) public view returns (uint256)", + "function approve(address spender, uint256 amount) external returns(bool)", + "function transfer(address recipient, uint256 amount) external returns (bool)" + ]; + const wethContract = new ethers.Contract(tokens.weth.address, ABI); + const baseContract = new ethers.Contract(base, ABI); + const linkContract = new ethers.Contract(tokens.wbtc.address, ABI); + const crvUSD = new ethers.Contract(tokens.crvusd.address, ABI) + const wstETH = new ethers.Contract(tokens.wsteth.address, ABI) + + let dsaWallet0: any; + let dsaWallet1: any; + let dsaWallet2: any; + let dsaWallet3: any; + let wallet: any; + let dsa0Signer: any; + let masterSigner: Signer; + let instaConnectorsV2: Contract; + let connector: any; + let signer: any; + let sfrxSigner: any; + +// const comet = new ethers.Contract(market, cometABI); + + const wallets = provider.getWallets(); + const [wallet0, wallet1, wallet2, wallet3] = wallets; + + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + //@ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + // blockNumber: 15444500 + } + } + ] + }); + masterSigner = await getMasterSigner(); + instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2CRV__factory, + signer: masterSigner, + connectors: instaConnectorsV2 + }); + console.log("Connector address", connector.address); + + await hre.network.provider.send("hardhat_setBalance", [wst_whale, ethers.utils.parseEther("10").toHexString()]); + + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [wst_whale] + }); + + signer = await ethers.getSigner(wst_whale); + + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [wethWhale] + }); + sfrxSigner = await ethers.getSigner(wethWhale); + }); + + 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(wallet0.address); + expect(!!dsaWallet0.address).to.be.true; + dsaWallet1 = await buildDSAv2(wallet0.address); + expect(!!dsaWallet1.address).to.be.true; + dsaWallet2 = await buildDSAv2(wallet0.address); + expect(!!dsaWallet2.address).to.be.true; + dsaWallet3 = await buildDSAv2(wallet0.address); + expect(!!dsaWallet3.address).to.be.true; + wallet = await ethers.getSigner(dsaWallet0.address); + expect(!!dsaWallet1.address).to.be.true; + }); + + it("Deposit ETH into DSA wallet", async function () { + await hre.network.provider.request({ + method: "hardhat_impersonateAccount", + params: [wallet.address] + }); + + dsa0Signer = await ethers.getSigner(wallet.address); + 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")); + await wallet0.sendTransaction({ + to: dsaWallet1.address, + value: ethers.utils.parseEther("10") + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); + await wallet0.sendTransaction({ + to: dsaWallet3.address, + value: ethers.utils.parseEther("10") + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); + + await wstETH.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther('10')) + }); + }); + + describe("Main", function () { + //deposit asset + it("Create Loan", async function () { + const bal = await wstETH.balanceOf(dsaWallet0.address) + console.log('--------balance of weseth---------', bal.toString()) + // const spells = [ + // { + // connector: connectorName, + // method: "createLoan", + // args: [tokens.wsteth.address, ethers.utils.parseEther('1'), ethers.utils.parseEther('100'), 10] + // } + // ]; + + // const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + // const receipt = await tx.wait(); + + // console.log("-----balance of CRV-USD-----", (await crvUSD.balanceOf(wallet0.address)).toString()) + // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("5")); + // expect((await comet.connect(signer).userCollateral(dsaWallet0.address, tokens.weth.address)).balance).to.be.gte( + // ethers.utils.parseEther("5") + // ); + }); + + }); +}); From 80b0914a3e78539caa39ab46eb33bf569cb7729c Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 2 Aug 2023 07:34:44 -0400 Subject: [PATCH 03/14] add test script --- test/mainnet/crv_usd/crv_usd.test.ts | 242 ++++++++++++++++++++++----- 1 file changed, 204 insertions(+), 38 deletions(-) diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index ca4749e6..8ff76bd9 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -11,30 +11,47 @@ 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 { tokens } from "../../../scripts/tests/mainnet/tokens"; +import { tokens, dsaMaxValue } from "../../../scripts/tests/mainnet/tokens"; import { abis } from "../../../scripts/constant/abis"; import { constants } from "../../../scripts/constant/constant"; -import { ConnectV2CRV__factory } from "../../../typechain"; +import { ConnectV2CRV__factory, IERC20Minimal__factory } from "../../../typechain"; import { MaxUint256 } from "@uniswap/sdk-core"; import { USDC_OPTIMISTIC_KOVAN } from "@uniswap/smart-order-router"; +import ABI_Ctr from "./ABI.json" + describe("CRV USD", function () { const connectorName = "CRV_USD-TEST-A"; const market = "0xc3d688B66703497DAA19211EEdff47f25384cdc3"; const base = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; - const wst_whale = "0x248cCBf4864221fC0E840F29BB042ad5bFC89B5c"; + const wst_whale = "0x78bB3aEC3d855431bd9289fD98dA13F9ebB7ef15"; const wethWhale = "0x78bB3aEC3d855431bd9289fD98dA13F9ebB7ef15"; - const ABI = [ - "function balanceOf(address account) public view returns (uint256)", - "function approve(address spender, uint256 amount) external returns(bool)", - "function transfer(address recipient, uint256 amount) external returns (bool)" - ]; - const wethContract = new ethers.Contract(tokens.weth.address, ABI); - const baseContract = new ethers.Contract(base, ABI); - const linkContract = new ethers.Contract(tokens.wbtc.address, ABI); - const crvUSD = new ethers.Contract(tokens.crvusd.address, ABI) - const wstETH = new ethers.Contract(tokens.wsteth.address, ABI) + const wethContract = new ethers.Contract( + tokens.weth.address, + IERC20Minimal__factory.abi, + ethers.provider + ); + const baseContract = new ethers.Contract( + base, + IERC20Minimal__factory.abi, + ethers.provider + ); + const linkContract = new ethers.Contract( + tokens.wbtc.address, + IERC20Minimal__factory.abi, + ethers.provider + ); + const crvUSD = new ethers.Contract( + tokens.crvusd.address, + IERC20Minimal__factory.abi, + ethers.provider + ); + const sfrxEth = new ethers.Contract( + tokens.sfrxeth.address, + IERC20Minimal__factory.abi, + ethers.provider + ); let dsaWallet0: any; let dsaWallet1: any; @@ -48,7 +65,7 @@ describe("CRV USD", function () { let signer: any; let sfrxSigner: any; -// const comet = new ethers.Contract(market, cometABI); + // const comet = new ethers.Contract(market, cometABI); const wallets = provider.getWallets(); const [wallet0, wallet1, wallet2, wallet3] = wallets; @@ -61,7 +78,7 @@ describe("CRV USD", function () { forking: { //@ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - // blockNumber: 15444500 + // blockNumber: 17811076 } } ] @@ -85,13 +102,19 @@ describe("CRV USD", function () { signer = await ethers.getSigner(wst_whale); - await hre.network.provider.request({ - method: "hardhat_impersonateAccount", - params: [wethWhale] - }); - sfrxSigner = await ethers.getSigner(wethWhale); - }); + // await hre.network.provider.request({ + // method: "hardhat_impersonateAccount", + // params: [wethWhale] + // }); + // sfrxSigner = await ethers.getSigner(wethWhale); + // const tmp = await ethers.getContractAt(ABI_Ctr, "0xa920de414ea4ab66b97da1bfe9e6eca7d4219635") + + // console.log("======1111111111111==========",(await tmp.max_borrowable("500000000000000000", 10)).toString()) + // await sfrxEth.connect(signer).approve(tmp.address, "999999999999999999999999999999") + // await tmp.connect(signer).create_loan("1000000000000000000", "50000000000000000000", "10") + // console.log("-----balance of CRV-USD-----", (await crvUSD.balanceOf(signer.address)).toString()) + }); it("Should have contracts deployed.", async function () { expect(!!instaConnectorsV2.address).to.be.true; expect(!!connector.address).to.be.true; @@ -135,32 +158,175 @@ describe("CRV USD", function () { }); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - await wstETH.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther('10')) + let txRes = await sfrxEth.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("10000")); + await txRes.wait(); + txRes = await sfrxEth.connect(signer).transfer(dsaWallet1.address, ethers.utils.parseEther("1000")); + await txRes.wait(); + txRes = await sfrxEth.connect(signer).transfer(dsaWallet2.address, ethers.utils.parseEther("1000")); + await txRes.wait(); }); }); describe("Main", function () { //deposit asset it("Create Loan", async function () { - const bal = await wstETH.balanceOf(dsaWallet0.address) - console.log('--------balance of weseth---------', bal.toString()) - // const spells = [ - // { - // connector: connectorName, - // method: "createLoan", - // args: [tokens.wsteth.address, ethers.utils.parseEther('1'), ethers.utils.parseEther('100'), 10] - // } - // ]; + const spells = [ + { + connector: connectorName, + method: "createLoan", + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), ethers.utils.parseEther('1000'), 10] + } + ]; - // const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); - // const receipt = await tx.wait(); + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + await tx.wait(); - // console.log("-----balance of CRV-USD-----", (await crvUSD.balanceOf(wallet0.address)).toString()) - // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("5")); - // expect((await comet.connect(signer).userCollateral(dsaWallet0.address, tokens.weth.address)).balance).to.be.gte( - // ethers.utils.parseEther("5") - // ); + expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.eq( + ethers.utils.parseEther("1000") + ); }); + // 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 = [ + { + connector: connectorName, + method: "addCollateral", + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), 0, 0] + } + ]; + + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + await tx.wait(); + + expect(await sfrxEth.balanceOf(dsaWallet0.address)).to.be.eq( + ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('1')) + ); + }); + + it("remove Collateral", async function () { + const balance = await sfrxEth.balanceOf(dsaWallet0.address) + const spells = [ + { + connector: connectorName, + method: "removeCollateral", + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), 0, 0] + } + ]; + + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + await tx.wait(); + + expect(await sfrxEth.balanceOf(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.sfrxeth.address, '0', ethers.utils.parseEther('50')] + } + ]; + + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + await tx.wait(); + + expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.eq( + ethers.BigNumber.from(balance).add(ethers.utils.parseEther('50')) + ); + }); + + it("borrow more", async function () { + const balance = await crvUSD.balanceOf(dsaWallet0.address) + const spells = [ + { + connector: connectorName, + method: "borrowMore", + args: [tokens.sfrxeth.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.eq( + ethers.BigNumber.from(balance).add(ethers.utils.parseEther('100')) + ); + }); }); }); From cf06f90a7209b67637a7a12eee4742cbe3a1af8e Mon Sep 17 00:00:00 2001 From: q1q0 Date: Wed, 2 Aug 2023 07:35:22 -0400 Subject: [PATCH 04/14] update testscript --- test/mainnet/crv_usd/crv_usd.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index 8ff76bd9..3fdb286c 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -18,7 +18,7 @@ import { ConnectV2CRV__factory, IERC20Minimal__factory } from "../../../typechai import { MaxUint256 } from "@uniswap/sdk-core"; import { USDC_OPTIMISTIC_KOVAN } from "@uniswap/smart-order-router"; -import ABI_Ctr from "./ABI.json" +// import ABI_Ctr from "./ABI.json" describe("CRV USD", function () { const connectorName = "CRV_USD-TEST-A"; From 4980c0c9a00de90663a831bc22ac9b9c35d2ceaa Mon Sep 17 00:00:00 2001 From: q1q0 Date: Mon, 7 Aug 2023 13:56:02 -0400 Subject: [PATCH 05/14] fix bug and update test script --- .../mainnet/connectors/crv_USD/interface.sol | 2 +- contracts/mainnet/connectors/crv_USD/main.sol | 5 +- test/mainnet/crv_usd/crv_usd.test.ts | 218 ++++++++++++------ 3 files changed, 148 insertions(+), 77 deletions(-) diff --git a/contracts/mainnet/connectors/crv_USD/interface.sol b/contracts/mainnet/connectors/crv_USD/interface.sol index df2856ac..3f4075bf 100644 --- a/contracts/mainnet/connectors/crv_USD/interface.sol +++ b/contracts/mainnet/connectors/crv_USD/interface.sol @@ -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); } diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index f1356de2..9b28857e 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -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); diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index 3fdb286c..25932004 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -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')) + ); + }); + }); }); From 12d86342baa217ecc1ac18c630914ec980201259 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Thu, 7 Sep 2023 16:29:30 -0400 Subject: [PATCH 06/14] update get controller function --- .../mainnet/connectors/crv_USD/helpers.sol | 4 +-- contracts/mainnet/connectors/crv_USD/main.sol | 26 ++++++++++++++----- test/mainnet/crv_usd/crv_usd.test.ts | 26 +++++++++---------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/contracts/mainnet/connectors/crv_USD/helpers.sol b/contracts/mainnet/connectors/crv_USD/helpers.sol index c0d439c6..0493c6a2 100644 --- a/contracts/mainnet/connectors/crv_USD/helpers.sol +++ b/contracts/mainnet/connectors/crv_USD/helpers.sol @@ -17,7 +17,7 @@ abstract contract Helpers is DSMath, Basic { /** * @dev Get controller address by given collateral asset */ - function getController(address collateral) internal view returns(IController controller) { - controller = IController(ctrFactory.get_controller(collateral, 0)); + function getController(address collateral, uint256 i) internal view returns(IController controller) { + controller = IController(ctrFactory.get_controller(collateral, i)); } } \ No newline at end of file diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 9b28857e..92e142a7 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -15,18 +15,20 @@ abstract contract MakerResolver is Helpers, Events { /** * @dev Create loan * @param collateral collateral token address + * @param version controller version * @param amt Amount of collateral to use * @param debt Stablecoin debt to take * @param N Number of bands to deposit into (to do autoliquidation-deliquidation), can be from MIN_TICKS(4) to MAX_TICKS(50) */ function createLoan( - address collateral, + address collateral, + uint256 version, uint256 amt, uint256 debt, uint256 N ) external returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); uint256 _amt = amt; uint256 ethAmt; @@ -50,18 +52,20 @@ abstract contract MakerResolver is Helpers, Events { * @dev Add collateral * @notice Add extra collateral to avoid bad liqidations * @param collateral collateral asset address + * @param version controller version * @param amt Amount of collateral to add * @param getId ID to retrieve amt. * @param setId ID stores the collateral amount of tokens added. */ function addCollateral( address collateral, + uint256 version, uint256 amt, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); uint _amt = getUint(getId, amt); uint ethAmt; @@ -85,18 +89,20 @@ abstract contract MakerResolver is Helpers, Events { * @dev Remove ETH/ERC20_Token Collateral. * @notice Remove some collateral without repaying the debt * @param collateral collateral asset address + * @param version controller version * @param amt Amount of collateral to add * @param getId ID to retrieve amt. * @param setId ID stores the amount of tokens deposited. */ function removeCollateral( address collateral, + uint256 version, uint256 amt, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); uint _amt = getUint(getId, amt); controller.remove_collateral(_amt, collateral == ethAddr); @@ -110,16 +116,18 @@ abstract contract MakerResolver is Helpers, Events { /** * @dev Borrow more stablecoins while adding more collateral (not necessary) * @param collateral collateral token address + * @param version controller version * @param amt Amount of collateral to add * @param debt Amount of stablecoin debt to take */ function borrowMore( address collateral, + uint256 version, uint256 amt, uint256 debt ) external returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); uint _amt = amt; uint ethAmt; @@ -145,18 +153,20 @@ abstract contract MakerResolver is Helpers, Events { * @dev Borrow DAI. * @notice Borrow DAI using a MakerDAO vault * @param collateral collateral token address + * @param version controller version * @param amt The amount of debt to repay. If higher than the current debt - will do full repayment * @param getId ID to retrieve amt. * @param setId ID stores the amount of DAI borrowed. */ function repay( address collateral, + uint256 version, uint256 amt, uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); uint _amt = amt; TokenInterface stableCoin = TokenInterface(CRV_USD); @@ -173,14 +183,16 @@ abstract contract MakerResolver is Helpers, Events { /** * @dev Peform a bad liquidation (or self-liquidation) of user if health is not good * @param collateral collateral token address + * @param version controller version * @param min_x Minimal amount of stablecoin to receive (to avoid liquidators being sandwiched) */ function liquidate( address collateral, + uint256 version, uint256 min_x ) external payable returns (string memory _eventName, bytes memory _eventParam) { address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral); + IController controller = getController(_collateral, version); controller.liquidate(address(this), min_x, collateral == ethAddr); diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index 25932004..265308e2 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -174,7 +174,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), ethers.utils.parseEther('1000'), 10] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), ethers.utils.parseEther('1000'), 10] } ]; @@ -192,7 +192,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "addCollateral", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] } ]; @@ -210,7 +210,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "removeCollateral", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] } ]; @@ -228,7 +228,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.sfrxeth.address, '0', ethers.utils.parseEther('50')] + args: [tokens.sfrxeth.address, "0", '0', ethers.utils.parseEther('50')] } ]; @@ -246,7 +246,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('2'), dsaMaxValue] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('2'), dsaMaxValue] } ]; @@ -263,7 +263,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] } ]; @@ -275,7 +275,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] + args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] } ]; @@ -294,7 +294,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, dsaMaxValue, dsaMaxValue, 10] + args: [tokens.sfrxeth.address, "0", dsaMaxValue, dsaMaxValue, 10] } ]; @@ -316,7 +316,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.eth.address, ethers.utils.parseEther('2').toString(), dsaMaxValue, 10] + args: [tokens.eth.address, "0", ethers.utils.parseEther('2').toString(), dsaMaxValue, 10] } ]; @@ -335,7 +335,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "addCollateral", - args: [tokens.eth.address, ethers.utils.parseEther('3').toString(), 0, 0] + args: [tokens.eth.address, "0", ethers.utils.parseEther('3').toString(), 0, 0] } ]; @@ -353,7 +353,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "removeCollateral", - args: [tokens.eth.address, ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.eth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] } ]; @@ -371,7 +371,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, '0', ethers.utils.parseEther('10')] + args: [tokens.eth.address, "0", '0', ethers.utils.parseEther('10')] } ]; @@ -389,7 +389,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, '0', dsaMaxValue] + args: [tokens.eth.address, "0", '0', dsaMaxValue] } ]; From c20a79b5d0a414de459083753b050b6737d625d8 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Sat, 9 Sep 2023 19:16:54 +0400 Subject: [PATCH 07/14] feat: createLoan function update --- .../mainnet/connectors/crv_USD/helpers.sol | 5 +- contracts/mainnet/connectors/crv_USD/main.sol | 61 +++++++++++-------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/contracts/mainnet/connectors/crv_USD/helpers.sol b/contracts/mainnet/connectors/crv_USD/helpers.sol index 0493c6a2..5d2c403c 100644 --- a/contracts/mainnet/connectors/crv_USD/helpers.sol +++ b/contracts/mainnet/connectors/crv_USD/helpers.sol @@ -12,12 +12,13 @@ abstract contract Helpers is DSMath, Basic { /** * @dev ControllerFactory Interface */ - IControllerFactory internal constant ctrFactory = IControllerFactory(0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC); + IControllerFactory internal constant CONTROLLER_FACTORY = + IControllerFactory(0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC); /** * @dev Get controller address by given collateral asset */ function getController(address collateral, uint256 i) internal view returns(IController controller) { - controller = IController(ctrFactory.get_controller(collateral, i)); + controller = IController(CONTROLLER_FACTORY.get_controller(collateral, i)); } } \ No newline at end of file diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 92e142a7..648457b6 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -2,7 +2,7 @@ pragma solidity ^0.7.0; /** - * @title MakerDAO. + * @title Curve USD. * @dev Collateralized Borrowing. */ @@ -11,41 +11,52 @@ import { Helpers } from "./helpers.sol"; import { Events } from "./events.sol"; import "./interface.sol"; -abstract contract MakerResolver is Helpers, Events { +abstract contract CurveUSDResolver is Helpers, Events { /** * @dev Create loan - * @param collateral collateral token address - * @param version controller version - * @param amt Amount of collateral to use - * @param debt Stablecoin debt to take - * @param N Number of bands to deposit into (to do autoliquidation-deliquidation), can be from MIN_TICKS(4) to MAX_TICKS(50) + * @dev If a user already has an existing loan, the function will revert. + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param amount Amount of collateral (For max: `uint256(-1)`) + * @param debt Stablecoin debt to take (For max: `uint256(-1)`) + * @param numBands Number of bands to deposit into (to do autoliquidation-deliquidation), can only be from MIN_TICKS(4) to MAX_TICKS(50) + * @param controllerVersion Controller version, + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of debt borrowed. */ function createLoan( address collateral, - uint256 version, - uint256 amt, + uint256 amount, uint256 debt, - uint256 N + uint256 numBands, + uint256 controllerVersion, + uint256 getId, + uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); - uint256 _amt = amt; + uint256 _amt = getUint(getId, amount); - uint256 ethAmt; - if (collateral == ethAddr) { - _amt = _amt == uint(-1) ? address(this).balance : _amt; - ethAmt = _amt; + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + TokenInterface collateralContract = TokenInterface(_collateralAddress); + + // Get controller address of collateral. + IController controller = getController(_collateralAddress, controllerVersion); + + if (_isEth) { + _amt = _amt == uint256(-1) ? address(this).balance : _amt; + convertEthToWeth(_isEth, collateralContract, _amt); } else { - TokenInterface collateralContract = TokenInterface(_collateral); - _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; - approve(collateralContract, address(controller), _amt); + _amt = _amt == uint256(-1) ? collateralContract.balanceOf(address(this)) : _amt; } - uint256 _debt = debt == uint(-1) ? controller.max_borrowable(_amt, N) : debt; + approve(collateralContract, address(controller), _amt); - controller.create_loan{value: ethAmt}(_amt, _debt, N); + uint256 _debt = debt == uint256(-1) ? controller.max_borrowable(_amt, numBands) : debt; + + controller.create_loan(_amt, _debt, numBands); + + setUint(setId, _debt); _eventName = "LogCreateLoan(address,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, amt, debt, N); + _eventParam = abi.encode(collateral, _amt, debt, numBands, getId, setId); } /** @@ -201,6 +212,6 @@ abstract contract MakerResolver is Helpers, Events { } } -contract ConnectV2CRV is MakerResolver { - string public constant name = "CRV-USD-v1"; +contract ConnectV2CurveUSD is CurveUSDResolver { + string public constant name = "CurveUSD-v1.0"; } \ No newline at end of file From e59fb91f6b65ee73c4698dce889ee9e7e9918ab7 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sat, 9 Sep 2023 18:29:38 -0400 Subject: [PATCH 08/14] update few changes --- .../mainnet/connectors/crv_USD/events.sol | 10 +- .../mainnet/connectors/crv_USD/interface.sol | 1 + contracts/mainnet/connectors/crv_USD/main.sol | 141 ++++++++++-------- test/mainnet/crv_usd/crv_usd.test.ts | 93 +++++++++--- 4 files changed, 160 insertions(+), 85 deletions(-) diff --git a/contracts/mainnet/connectors/crv_USD/events.sol b/contracts/mainnet/connectors/crv_USD/events.sol index 64937640..ab12236a 100644 --- a/contracts/mainnet/connectors/crv_USD/events.sol +++ b/contracts/mainnet/connectors/crv_USD/events.sol @@ -2,10 +2,10 @@ pragma solidity ^0.7.0; contract Events { - event LogCreateLoan(address indexed collateral, uint256 amt, uint256 debt, uint256 indexed N); - event LogAddCollateral(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); + event LogCreateLoan(address indexed collateral, uint256 amt, uint256 debt, uint256 indexed numBands, uint256 controllerVersion, uint256 getId, uint256 setId); + event LogAddCollateral(address indexed collateral, uint256 indexed amt, uint256 controllerVersion, uint256 getId, uint256 setId); event LogRemoveCollateral(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); - event LogBorrowMore(address indexed collateral, uint256 indexed amt, uint256 indexed debt); - event LogRepay(address indexed collateral, uint256 indexed amt, uint256 getId, uint256 setId); - event LogLiquidate(address indexed collateral, uint256 indexed min_x); + event LogBorrowMore(address indexed collateral, uint256 indexed amt, uint256 controllerVersion, uint256 indexed debt); + event LogRepay(address indexed collateral, uint256 indexed amt, uint256 controllerVersion, uint256 getId, uint256 setId); + event LogLiquidate(address indexed collateral, uint256 indexed min_x, uint256 controllerVersion, uint256 getId, uint256 setId); } \ No newline at end of file diff --git a/contracts/mainnet/connectors/crv_USD/interface.sol b/contracts/mainnet/connectors/crv_USD/interface.sol index 3f4075bf..85d09cdd 100644 --- a/contracts/mainnet/connectors/crv_USD/interface.sol +++ b/contracts/mainnet/connectors/crv_USD/interface.sol @@ -13,6 +13,7 @@ interface IController { function remove_collateral(uint256 collateral, bool use_eth) external; function borrow_more(uint256 collateral, uint256 debt) payable external; function repay(uint256 _d_debt, address _for, int256 max_active_band, bool use_eth) payable external; + function repay(uint256 _d_debt) payable external; 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); diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 648457b6..7cb3a8b9 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -55,160 +55,179 @@ abstract contract CurveUSDResolver is Helpers, Events { controller.create_loan(_amt, _debt, numBands); setUint(setId, _debt); - _eventName = "LogCreateLoan(address,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, _amt, debt, numBands, getId, setId); + _eventName = "LogCreateLoan(address,uint256,uint256,uint256,uint256,uin256,uin256)"; + _eventParam = abi.encode(collateral, _amt, debt, numBands, controllerVersion, getId, setId); } /** * @dev Add collateral * @notice Add extra collateral to avoid bad liqidations - * @param collateral collateral asset address - * @param version controller version - * @param amt Amount of collateral to add + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param amt Amount of collateral (For max: `uint256(-1)`) + * @param controllerVersion Controller version, * @param getId ID to retrieve amt. * @param setId ID stores the collateral amount of tokens added. */ function addCollateral( address collateral, - uint256 version, uint256 amt, + uint256 controllerVersion, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + IController controller = getController(_collateralAddress, controllerVersion); + TokenInterface collateralContract = TokenInterface(_collateralAddress); uint _amt = getUint(getId, amt); uint ethAmt; - if (collateral == ethAddr) { + if (_isEth) { _amt = _amt == uint(-1) ? address(this).balance : _amt; ethAmt = _amt; + convertEthToWeth(_isEth, collateralContract, _amt); } else { - TokenInterface collateralContract = TokenInterface(_collateral); _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; - approve(collateralContract, address(controller), _amt); } - controller.add_collateral{value: ethAmt}(_amt, address(this)); + approve(collateralContract, address(controller), _amt); + controller.add_collateral(_amt, address(this)); setUint(setId, _amt); - _eventName = "LogAddCollateral(address,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, amt, getId, setId); + _eventName = "LogAddCollateral(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, controllerVersion, getId, setId); } /** * @dev Remove ETH/ERC20_Token Collateral. * @notice Remove some collateral without repaying the debt - * @param collateral collateral asset address - * @param version controller version - * @param amt Amount of collateral to add + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param amt Remove collateral amount (For max: `uint256(-1)`) + * @param controllerVersion controller version * @param getId ID to retrieve amt. * @param setId ID stores the amount of tokens deposited. */ function removeCollateral( address collateral, - uint256 version, uint256 amt, + uint256 controllerVersion, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + IController controller = getController(_collateralAddress, controllerVersion); uint _amt = getUint(getId, amt); controller.remove_collateral(_amt, collateral == ethAddr); setUint(setId, _amt); - _eventName = "LogRemoveCollateral(address,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, amt, getId, setId); + _eventName = "LogRemoveCollateral(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, controllerVersion, getId, setId); } /** * @dev Borrow more stablecoins while adding more collateral (not necessary) - * @param collateral collateral token address - * @param version controller version - * @param amt Amount of collateral to add - * @param debt Amount of stablecoin debt to take + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param amt Collateral amount for borrow more (For max: `uint256(-1)`) + * @param debt Stablecoin debt to take for borrow more (For max: `uint256(-1)`) + * @param controllerVersion controller version + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. */ function borrowMore( address collateral, - uint256 version, uint256 amt, - uint256 debt + uint256 debt, + uint256 controllerVersion, + uint256 getId, + uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); - uint _amt = amt; + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + IController controller = getController(_collateralAddress, controllerVersion); + TokenInterface collateralContract = TokenInterface(_collateralAddress); + uint _amt = getUint(getId, amt); uint ethAmt; - if (collateral == ethAddr) { + if (_isEth) { _amt = _amt == uint(-1) ? address(this).balance : _amt; ethAmt = _amt; + convertEthToWeth(_isEth, collateralContract, _amt); } else { - TokenInterface collateralContract = TokenInterface(_collateral); _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; - approve(collateralContract, address(controller), _amt); } + + approve(collateralContract, address(controller), _amt); 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); - - _eventName = "LogBorrowMore(address,uint256,uint256)"; - _eventParam = abi.encode(collateral, amt, debt); + controller.borrow_more(_amt, _debt); + + setUint(setId, _amt); + _eventName = "LogBorrowMore(address,uint256,uint256,uint256,uin256,uin256)"; + _eventParam = abi.encode(collateral, amt, debt, controllerVersion, getId, setId); } /** - * @dev Borrow DAI. - * @notice Borrow DAI using a MakerDAO vault - * @param collateral collateral token address - * @param version controller version - * @param amt The amount of debt to repay. If higher than the current debt - will do full repayment + * @dev Repay Curve-USD. + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param amt repay amount (For max: `uint256(-1)`) + * @param controllerVersion Controller version, * @param getId ID to retrieve amt. - * @param setId ID stores the amount of DAI borrowed. + * @param setId ID stores the amount of debt borrowed. */ function repay( address collateral, - uint256 version, uint256 amt, + uint256 controllerVersion, uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); - uint _amt = amt; + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + IController controller = getController(_collateralAddress, controllerVersion); + uint _amt = getUint(getId, amt); TokenInterface stableCoin = TokenInterface(CRV_USD); _amt = _amt == uint(-1) ? stableCoin.balanceOf(address(this)) : _amt; - TokenInterface collateralContract = TokenInterface(_collateral); - approve(collateralContract, address(controller), _amt); - controller.repay(_amt, address(this), 2**255-1, true); + approve(stableCoin, address(controller), _amt); - _eventName = "LogRepay(address,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, amt, getId, setId); + controller.repay(_amt); + + setUint(setId, _amt); + _eventName = "LogRepay(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, amt, controllerVersion, getId, setId); } /** * @dev Peform a bad liquidation (or self-liquidation) of user if health is not good * @param collateral collateral token address - * @param version controller version * @param min_x Minimal amount of stablecoin to receive (to avoid liquidators being sandwiched) + * @param controllerVersion controller version + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of debt borrowed. */ function liquidate( address collateral, - uint256 version, - uint256 min_x + uint256 min_x, + uint256 controllerVersion, + uint256 getId, + uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { - address _collateral = collateral == ethAddr ? wethAddr : collateral; - IController controller = getController(_collateral, version); + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + IController controller = getController(_collateralAddress, controllerVersion); + uint _min_x = getUint(getId, min_x); - controller.liquidate(address(this), min_x, collateral == ethAddr); + controller.liquidate(address(this), _min_x, _isEth); - _eventName = "LogLiquidate(address,uint256)"; - _eventParam = abi.encode(collateral, min_x); + setUint(setId, _min_x); + _eventName = "LogLiquidate(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(collateral, _min_x, controllerVersion, getId, setId); } } diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index 265308e2..fab52797 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -14,9 +14,7 @@ import { addresses } from "../../../scripts/tests/mainnet/addresses"; import { tokens, dsaMaxValue } from "../../../scripts/tests/mainnet/tokens"; import { abis } from "../../../scripts/constant/abis"; import { constants } from "../../../scripts/constant/constant"; -import { ConnectV2CRV__factory, IERC20Minimal__factory } from "../../../typechain"; -import { MaxUint256 } from "@uniswap/sdk-core"; -import { USDC_OPTIMISTIC_KOVAN } from "@uniswap/smart-order-router"; +import { ConnectV2CurveUSD__factory, IERC20Minimal__factory } from "../../../typechain"; // import ABI_Ctr from "./ABI.json" @@ -87,7 +85,7 @@ describe("CRV USD", function () { instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); connector = await deployAndEnableConnector({ connectorName, - contractArtifact: ConnectV2CRV__factory, + contractArtifact: ConnectV2CurveUSD__factory, signer: masterSigner, connectors: instaConnectorsV2 }); @@ -174,7 +172,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), ethers.utils.parseEther('1000'), 10] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), ethers.utils.parseEther('1000'), "10", "1", "0", "0"] } ]; @@ -192,7 +190,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "addCollateral", - args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), "1", 0, 0] } ]; @@ -210,7 +208,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "removeCollateral", - args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), "1", 0, 0] } ]; @@ -228,7 +226,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.sfrxeth.address, "0", '0', ethers.utils.parseEther('50')] + args: [tokens.sfrxeth.address, '0', ethers.utils.parseEther('50'), "1", 0, 0] } ]; @@ -240,13 +238,13 @@ describe("CRV USD", function () { ); }); - it("borrow more", async function () { + it("borrow more with maximum value", async function () { const balance = await crvUSD.balanceOf(dsaWallet0.address) const spells = [ { connector: connectorName, method: "borrowMore", - args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('2'), dsaMaxValue] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('2'), dsaMaxValue, 1, 0, 0] } ]; @@ -263,19 +261,19 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, "0", ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10, "1", "0", "0"] } ]; - 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, "0", ethers.utils.parseEther('1').toString(), dsaMaxValue, 10] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('1').toString(), dsaMaxValue, 10, "1", "0", "0"] } ]; @@ -289,12 +287,40 @@ describe("CRV USD", function () { console.log("maximum debt amount: ", (await crvUSD.balanceOf(dsaWallet1.address)).toString() ) }); + it("Repay loans", async function () { + const balance = await crvUSD.balanceOf(dsaWallet1.address) + const spells = [ + { + connector: connectorName, + method: "repay", + args: [tokens.sfrxeth.address, ethers.utils.parseEther('100').toString(), "1", "0", "0"] + } + ]; + const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + expect(await crvUSD.balanceOf(dsaWallet1.address)).to.be.eq( + ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('100')) + ); + }); + + it("Repay loans with max value", async function () { + const balance = await crvUSD.balanceOf(dsaWallet1.address) + const spells = [ + { + connector: connectorName, + method: "repay", + args: [tokens.sfrxeth.address, dsaMaxValue, "1", "0", "0"] + } + ]; + await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + expect(await crvUSD.balanceOf(dsaWallet1.address)).to.be.eq(0); + }); + it("Create Loan with maximum collateral and maximum debt", async function () { const spells = [ { connector: connectorName, method: "createLoan", - args: [tokens.sfrxeth.address, "0", dsaMaxValue, dsaMaxValue, 10] + args: [tokens.sfrxeth.address, dsaMaxValue, dsaMaxValue, 10, "1", "0", "0"] } ]; @@ -316,7 +342,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "createLoan", - args: [tokens.eth.address, "0", ethers.utils.parseEther('2').toString(), dsaMaxValue, 10] + args: [tokens.eth.address, ethers.utils.parseEther('2').toString(), dsaMaxValue, 10, "0", "0", "0"] } ]; @@ -335,7 +361,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "addCollateral", - args: [tokens.eth.address, "0", ethers.utils.parseEther('3').toString(), 0, 0] + args: [tokens.eth.address, ethers.utils.parseEther('3').toString(), 0, 0, 0] } ]; @@ -353,7 +379,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "removeCollateral", - args: [tokens.eth.address, "0", ethers.utils.parseEther('1').toString(), 0, 0] + args: [tokens.eth.address, ethers.utils.parseEther('1').toString(), 0, 0, 0] } ]; @@ -371,7 +397,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, "0", '0', ethers.utils.parseEther('10')] + args: [tokens.eth.address, '0', ethers.utils.parseEther('10'), 0, 0, 0] } ]; @@ -389,7 +415,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, "0", '0', dsaMaxValue] + args: [tokens.eth.address, '0', dsaMaxValue, 0, 0, 0] } ]; @@ -400,5 +426,34 @@ describe("CRV USD", function () { ); }); + + it("Repay loans", async function () { + const balance = await crvUSD.balanceOf(dsaWallet0.address) + const spells = [ + { + connector: connectorName, + method: "repay", + args: [tokens.eth.address, ethers.utils.parseEther('100').toString(), "0", "0", "0"] + } + ]; + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + expect(await crvUSD.balanceOf(dsaWallet0.address)).to.be.eq( + ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('100')) + ); + }); + + it("Repay loans with max value", async function () { + const balance = await crvUSD.balanceOf(dsaWallet0.address) + const spells = [ + { + connector: connectorName, + method: "repay", + args: [tokens.eth.address, dsaMaxValue, "0", "0", "0"] + } + ]; + await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); + console.log("crv balance after repay with max value: ",await crvUSD.balanceOf(dsaWallet0.address)) + }); + }); }); From f9bf50373948e8cae2da1cfb79cab2f835d9da88 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Sat, 9 Sep 2023 18:35:54 -0400 Subject: [PATCH 09/14] update liquidate --- contracts/mainnet/connectors/crv_USD/main.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 7cb3a8b9..3337486d 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -223,6 +223,9 @@ abstract contract CurveUSDResolver is Helpers, Events { IController controller = getController(_collateralAddress, controllerVersion); uint _min_x = getUint(getId, min_x); + TokenInterface stableCoin = TokenInterface(CRV_USD); + approve(stableCoin, address(controller), _min_x); + controller.liquidate(address(this), _min_x, _isEth); setUint(setId, _min_x); From ca8375b21c8bdbc4ec871de34755715ade52bb02 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 11 Sep 2023 19:16:21 +0400 Subject: [PATCH 10/14] feat: new updates --- contracts/mainnet/connectors/crv_USD/main.sol | 122 ++++++++++++------ test/mainnet/crv_usd/crv_usd.test.ts | 30 ++--- 2 files changed, 90 insertions(+), 62 deletions(-) diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 3337486d..8be545a1 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -16,8 +16,8 @@ abstract contract CurveUSDResolver is Helpers, Events { * @dev Create loan * @dev If a user already has an existing loan, the function will revert. * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) - * @param amount Amount of collateral (For max: `uint256(-1)`) - * @param debt Stablecoin debt to take (For max: `uint256(-1)`) + * @param amt Amount of collateral (For max: `uint256(-1)`) + * @param debtAmt Stablecoin debt to take (For max: `uint256(-1)`) * @param numBands Number of bands to deposit into (to do autoliquidation-deliquidation), can only be from MIN_TICKS(4) to MAX_TICKS(50) * @param controllerVersion Controller version, * @param getId ID to retrieve amt. @@ -25,14 +25,14 @@ abstract contract CurveUSDResolver is Helpers, Events { */ function createLoan( address collateral, - uint256 amount, - uint256 debt, + uint256 amt, + uint256 debtAmt, uint256 numBands, uint256 controllerVersion, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - uint256 _amt = getUint(getId, amount); + uint256 _amt = getUint(getId, amt); bool _isEth = collateral == ethAddr; address _collateralAddress = _isEth ? wethAddr : collateral; @@ -50,13 +50,13 @@ abstract contract CurveUSDResolver is Helpers, Events { approve(collateralContract, address(controller), _amt); - uint256 _debt = debt == uint256(-1) ? controller.max_borrowable(_amt, numBands) : debt; + uint256 _debtAmt = debtAmt == uint256(-1) ? controller.max_borrowable(_amt, numBands) : debtAmt; - controller.create_loan(_amt, _debt, numBands); + controller.create_loan(_amt, _debtAmt, numBands); - setUint(setId, _debt); + setUint(setId, _debtAmt); _eventName = "LogCreateLoan(address,uint256,uint256,uint256,uint256,uin256,uin256)"; - _eventParam = abi.encode(collateral, _amt, debt, numBands, controllerVersion, getId, setId); + _eventParam = abi.encode(collateral, _amt, _debtAmt, numBands, controllerVersion, getId, setId); } /** @@ -75,16 +75,17 @@ abstract contract CurveUSDResolver is Helpers, Events { uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + bool _isEth = collateral == ethAddr; address _collateralAddress = _isEth ? wethAddr : collateral; + + // Get controller address of collateral. IController controller = getController(_collateralAddress, controllerVersion); TokenInterface collateralContract = TokenInterface(_collateralAddress); - uint _amt = getUint(getId, amt); - uint ethAmt; if (_isEth) { _amt = _amt == uint(-1) ? address(this).balance : _amt; - ethAmt = _amt; convertEthToWeth(_isEth, collateralContract, _amt); } else { _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; @@ -94,6 +95,7 @@ abstract contract CurveUSDResolver is Helpers, Events { controller.add_collateral(_amt, address(this)); setUint(setId, _amt); + _eventName = "LogAddCollateral(address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode(collateral, amt, controllerVersion, getId, setId); } @@ -114,15 +116,17 @@ abstract contract CurveUSDResolver is Helpers, Events { uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { - bool _isEth = collateral == ethAddr; - address _collateralAddress = _isEth ? wethAddr : collateral; - IController controller = getController(_collateralAddress, controllerVersion); uint _amt = getUint(getId, amt); - controller.remove_collateral(_amt, collateral == ethAddr); + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + + IController controller = getController(_collateralAddress, controllerVersion); + + // remove_collateral will unwrap the eth. + controller.remove_collateral(_amt, _isEth); setUint(setId, _amt); - _eventName = "LogRemoveCollateral(address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode(collateral, amt, controllerVersion, getId, setId); } @@ -130,30 +134,64 @@ abstract contract CurveUSDResolver is Helpers, Events { /** * @dev Borrow more stablecoins while adding more collateral (not necessary) * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) - * @param amt Collateral amount for borrow more (For max: `uint256(-1)`) - * @param debt Stablecoin debt to take for borrow more (For max: `uint256(-1)`) + * @param debtAmt Stablecoin debt to take for borrow more (For max: `uint256(-1)`) * @param controllerVersion controller version * @param getId ID to retrieve amt. * @param setId ID stores the amount of tokens deposited. */ function borrowMore( address collateral, - uint256 amt, - uint256 debt, + uint256 debtAmt, uint256 controllerVersion, uint256 getId, uint256 setId ) external returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, debtAmt); + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; IController controller = getController(_collateralAddress, controllerVersion); - TokenInterface collateralContract = TokenInterface(_collateralAddress); - uint _amt = getUint(getId, amt); - uint ethAmt; + uint256[4] memory res = controller.user_state(address(this)); + uint256 _debtAmt = debtAmt == uint(-1) + ? controller.max_borrowable(res[0], res[3]) - res[2] + : debtAmt; + + controller.borrow_more(_amt, _debtAmt); + + setUint(setId, _amt); + _eventName = "LogBorrowMore(address,uint256,uint256,uin256,uin256)"; + _eventParam = abi.encode(collateral, debtAmt, controllerVersion, getId, setId); + } + + /** + * @dev Borrow more stablecoins while adding more collateral (not necessary) + * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) + * @param colAmt Collateral amount for borrow more (For max: `uint256(-1)`) + * @param debtAmt Stablecoin debt to take for borrow more (For max: `uint256(-1)`) + * @param controllerVersion controller version + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function addCollateralAndBorrowMore( + address collateral, + uint256 colAmt, + uint256 debtAmt, + uint256 controllerVersion, + uint256 getId, + uint256 setId + ) external returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, colAmt); + + bool _isEth = collateral == ethAddr; + address _collateralAddress = _isEth ? wethAddr : collateral; + TokenInterface collateralContract = TokenInterface(_collateralAddress); + + IController controller = getController(_collateralAddress, controllerVersion); + if (_isEth) { _amt = _amt == uint(-1) ? address(this).balance : _amt; - ethAmt = _amt; convertEthToWeth(_isEth, collateralContract, _amt); } else { _amt = _amt == uint(-1) ? collateralContract.balanceOf(address(this)) : _amt; @@ -162,20 +200,22 @@ abstract contract CurveUSDResolver is Helpers, Events { approve(collateralContract, address(controller), _amt); 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; + uint256 _debtAmt = debtAmt == uint(-1) + ? controller.max_borrowable(_amt + res[0], res[3]) - res[2] + : debtAmt; - controller.borrow_more(_amt, _debt); + controller.borrow_more(_amt, _debtAmt); setUint(setId, _amt); - _eventName = "LogBorrowMore(address,uint256,uint256,uint256,uin256,uin256)"; - _eventParam = abi.encode(collateral, amt, debt, controllerVersion, getId, setId); + _eventName = "LogAddCollateralAndBorrowMore(address,uint256,uint256,uint256,uin256,uin256)"; + _eventParam = abi.encode(collateral, colAmt, debtAmt, controllerVersion, getId, setId); } /** * @dev Repay Curve-USD. * @param collateral Collateral token address.(For ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) * @param amt repay amount (For max: `uint256(-1)`) - * @param controllerVersion Controller version, + * @param controllerVersion Controller version. * @param getId ID to retrieve amt. * @param setId ID stores the amount of debt borrowed. */ @@ -186,10 +226,11 @@ abstract contract CurveUSDResolver is Helpers, Events { uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + bool _isEth = collateral == ethAddr; address _collateralAddress = _isEth ? wethAddr : collateral; IController controller = getController(_collateralAddress, controllerVersion); - uint _amt = getUint(getId, amt); TokenInterface stableCoin = TokenInterface(CRV_USD); _amt = _amt == uint(-1) ? stableCoin.balanceOf(address(this)) : _amt; @@ -206,31 +247,32 @@ abstract contract CurveUSDResolver is Helpers, Events { /** * @dev Peform a bad liquidation (or self-liquidation) of user if health is not good * @param collateral collateral token address - * @param min_x Minimal amount of stablecoin to receive (to avoid liquidators being sandwiched) - * @param controllerVersion controller version + * @param minReceiveAmt Minimal amount of stablecoin to receive (to avoid liquidators being sandwiched) + * @param controllerVersion controller version. * @param getId ID to retrieve amt. * @param setId ID stores the amount of debt borrowed. */ - function liquidate( + function selfLiquidate( address collateral, - uint256 min_x, + uint256 minReceiveAmt, uint256 controllerVersion, uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { + uint _minReceiveAmt = getUint(getId, minReceiveAmt); + bool _isEth = collateral == ethAddr; address _collateralAddress = _isEth ? wethAddr : collateral; IController controller = getController(_collateralAddress, controllerVersion); - uint _min_x = getUint(getId, min_x); TokenInterface stableCoin = TokenInterface(CRV_USD); - approve(stableCoin, address(controller), _min_x); + approve(stableCoin, address(controller), _minReceiveAmt); - controller.liquidate(address(this), _min_x, _isEth); + controller.liquidate(address(this), _minReceiveAmt, _isEth); - setUint(setId, _min_x); + setUint(setId, _minReceiveAmt); _eventName = "LogLiquidate(address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(collateral, _min_x, controllerVersion, getId, setId); + _eventParam = abi.encode(collateral, _minReceiveAmt, controllerVersion, getId, setId); } } diff --git a/test/mainnet/crv_usd/crv_usd.test.ts b/test/mainnet/crv_usd/crv_usd.test.ts index fab52797..039217cc 100644 --- a/test/mainnet/crv_usd/crv_usd.test.ts +++ b/test/mainnet/crv_usd/crv_usd.test.ts @@ -63,8 +63,6 @@ describe("CRV USD", function () { let signer: any; let sfrxSigner: any; - // const comet = new ethers.Contract(market, cometABI); - const wallets = provider.getWallets(); const [wallet0, wallet1, wallet2, wallet3] = wallets; @@ -99,20 +97,8 @@ describe("CRV USD", function () { }); signer = await ethers.getSigner(wst_whale); - - // await hre.network.provider.request({ - // method: "hardhat_impersonateAccount", - // params: [wethWhale] - // }); - // sfrxSigner = await ethers.getSigner(wethWhale); - - // const tmp = await ethers.getContractAt(ABI_Ctr, "0xa920de414ea4ab66b97da1bfe9e6eca7d4219635") - - // console.log("======1111111111111==========",(await tmp.max_borrowable("500000000000000000", 10)).toString()) - // await sfrxEth.connect(signer).approve(tmp.address, "999999999999999999999999999999") - // await tmp.connect(signer).create_loan("1000000000000000000", "50000000000000000000", "10") - // console.log("-----balance of CRV-USD-----", (await crvUSD.balanceOf(signer.address)).toString()) }); + it("Should have contracts deployed.", async function () { expect(!!instaConnectorsV2.address).to.be.true; expect(!!connector.address).to.be.true; @@ -185,7 +171,7 @@ describe("CRV USD", function () { }); it("add Collateral", async function () { - const balance = await sfrxEth.balanceOf(dsaWallet0.address) + const balanceBefore = await sfrxEth.balanceOf(dsaWallet0.address) const spells = [ { connector: connectorName, @@ -198,7 +184,7 @@ describe("CRV USD", function () { await tx.wait(); expect(await sfrxEth.balanceOf(dsaWallet0.address)).to.be.eq( - ethers.BigNumber.from(balance).sub(ethers.utils.parseEther('1')) + ethers.BigNumber.from(balanceBefore).sub(ethers.utils.parseEther('1')) ); }); @@ -226,7 +212,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.sfrxeth.address, '0', ethers.utils.parseEther('50'), "1", 0, 0] + args: [tokens.sfrxeth.address, ethers.utils.parseEther('50'), "1", 0, 0] } ]; @@ -238,12 +224,12 @@ describe("CRV USD", function () { ); }); - it("borrow more with maximum value", async function () { + it("addCollateralAndBorrowMore with maximum value", async function () { const balance = await crvUSD.balanceOf(dsaWallet0.address) const spells = [ { connector: connectorName, - method: "borrowMore", + method: "addCollateralAndBorrowMore", args: [tokens.sfrxeth.address, ethers.utils.parseEther('2'), dsaMaxValue, 1, 0, 0] } ]; @@ -397,7 +383,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, '0', ethers.utils.parseEther('10'), 0, 0, 0] + args: [tokens.eth.address, ethers.utils.parseEther('10'), 0, 0, 0] } ]; @@ -415,7 +401,7 @@ describe("CRV USD", function () { { connector: connectorName, method: "borrowMore", - args: [tokens.eth.address, '0', dsaMaxValue, 0, 0, 0] + args: [tokens.eth.address, dsaMaxValue, 0, 0, 0] } ]; From e15d7ffd5225ff5af556995bfa28d957be0e949c Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 11 Sep 2023 19:19:08 +0400 Subject: [PATCH 11/14] feat: minor fix --- contracts/mainnet/connectors/crv_USD/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crv_USD/main.sol index 8be545a1..cf9bbe50 100644 --- a/contracts/mainnet/connectors/crv_USD/main.sol +++ b/contracts/mainnet/connectors/crv_USD/main.sol @@ -158,7 +158,7 @@ abstract contract CurveUSDResolver is Helpers, Events { ? controller.max_borrowable(res[0], res[3]) - res[2] : debtAmt; - controller.borrow_more(_amt, _debtAmt); + controller.borrow_more(0, _debtAmt); setUint(setId, _amt); _eventName = "LogBorrowMore(address,uint256,uint256,uin256,uin256)"; From 57806b926a168c6190d8f404851a4f506c36bffc Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 11 Sep 2023 19:23:25 +0400 Subject: [PATCH 12/14] feat: rename folder --- contracts/mainnet/connectors/{crv_USD => crvusd}/events.sol | 0 contracts/mainnet/connectors/{crv_USD => crvusd}/helpers.sol | 0 contracts/mainnet/connectors/{crv_USD => crvusd}/interface.sol | 0 contracts/mainnet/connectors/{crv_USD => crvusd}/main.sol | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename contracts/mainnet/connectors/{crv_USD => crvusd}/events.sol (100%) rename contracts/mainnet/connectors/{crv_USD => crvusd}/helpers.sol (100%) rename contracts/mainnet/connectors/{crv_USD => crvusd}/interface.sol (100%) rename contracts/mainnet/connectors/{crv_USD => crvusd}/main.sol (100%) diff --git a/contracts/mainnet/connectors/crv_USD/events.sol b/contracts/mainnet/connectors/crvusd/events.sol similarity index 100% rename from contracts/mainnet/connectors/crv_USD/events.sol rename to contracts/mainnet/connectors/crvusd/events.sol diff --git a/contracts/mainnet/connectors/crv_USD/helpers.sol b/contracts/mainnet/connectors/crvusd/helpers.sol similarity index 100% rename from contracts/mainnet/connectors/crv_USD/helpers.sol rename to contracts/mainnet/connectors/crvusd/helpers.sol diff --git a/contracts/mainnet/connectors/crv_USD/interface.sol b/contracts/mainnet/connectors/crvusd/interface.sol similarity index 100% rename from contracts/mainnet/connectors/crv_USD/interface.sol rename to contracts/mainnet/connectors/crvusd/interface.sol diff --git a/contracts/mainnet/connectors/crv_USD/main.sol b/contracts/mainnet/connectors/crvusd/main.sol similarity index 100% rename from contracts/mainnet/connectors/crv_USD/main.sol rename to contracts/mainnet/connectors/crvusd/main.sol From cc018480e956f45f8020bb8026457752d22be21b Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 11 Sep 2023 20:07:21 +0400 Subject: [PATCH 13/14] feat: update --- hardhat.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 0508b8e5..87f74d71 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -38,7 +38,7 @@ const PRIVATE_KEY = process.env.PRIVATE_KEY; const mnemonic = process.env.MNEMONIC ?? "test test test test test test test test test test test junk"; const networkGasPriceConfig: Record = { - mainnet: 100, + mainnet: 35, polygon: 50, avalanche: 40, arbitrum: 1, From f08949dbc2ecf19134e1c8b2122a21cad8a582c5 Mon Sep 17 00:00:00 2001 From: q1q0 Date: Mon, 11 Sep 2023 17:58:33 -0400 Subject: [PATCH 14/14] update hardhat config --- hardhat.config.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 87f74d71..dcbefc64 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -38,7 +38,7 @@ const PRIVATE_KEY = process.env.PRIVATE_KEY; const mnemonic = process.env.MNEMONIC ?? "test test test test test test test test test test test junk"; const networkGasPriceConfig: Record = { - mainnet: 35, + mainnet: 37, polygon: 50, avalanche: 40, arbitrum: 1, @@ -120,7 +120,17 @@ const config: HardhatUserConfig = { arbitrumOne: String(process.env.ARB_ETHSCAN_KEY), avalanche: String(process.env.AVAX_ETHSCAN_KEY), opera: String(process.env.FTM_ETHSCAN_KEY) - } + }, + customChains: [ + { + network: "mainnet", + chainId: 1, + urls: { + apiURL: "http://api.etherscan.io/api", + browserURL: "https://etherscan.io" + } + } + ] }, typechain: { outDir: "typechain",