From ef50cf7188e6663e5402240693aa273edcf4c3ae Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 11 Aug 2022 04:37:03 +0800 Subject: [PATCH] new updates --- .../mainnet/connectors/euler/helpers.sol | 2 - .../mainnet/connectors/euler/interface.sol | 16 +--- contracts/mainnet/connectors/euler/main.sol | 88 +++---------------- scripts/tests/mainnet/tokens.ts | 7 ++ test/mainnet/euler/euler.test.ts | 40 +++++---- 5 files changed, 41 insertions(+), 112 deletions(-) diff --git a/contracts/mainnet/connectors/euler/helpers.sol b/contracts/mainnet/connectors/euler/helpers.sol index 73660049..a38342f1 100644 --- a/contracts/mainnet/connectors/euler/helpers.sol +++ b/contracts/mainnet/connectors/euler/helpers.sol @@ -10,8 +10,6 @@ contract Helpers is Basic, Events { 0x27182842E098f60e3D576794A5bFFb0777E025d3; IEulerMarkets internal constant markets = IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3); - IEulerSwap internal constant swapExec = - IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341); struct swapHelper { address _sellAddr; diff --git a/contracts/mainnet/connectors/euler/interface.sol b/contracts/mainnet/connectors/euler/interface.sol index 88b4150c..594c068b 100644 --- a/contracts/mainnet/connectors/euler/interface.sol +++ b/contracts/mainnet/connectors/euler/interface.sol @@ -36,6 +36,8 @@ interface IEulerEToken { function balanceOf(address account) external view returns (uint256); + function balanceOfUnderlying(address account) external view returns (uint); + function transferFrom(address from, address to, uint amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); @@ -63,17 +65,3 @@ interface IEulerDToken { uint256 amount ) external returns (bool); } - -struct Swap1InchParams { - uint256 subAccountIdIn; - uint256 subAccountIdOut; - address underlyingIn; - address underlyingOut; - uint256 amount; - uint256 amountOutMinimum; - bytes payload; -} - -interface IEulerSwap { - function swap1Inch(Swap1InchParams memory) external; -} diff --git a/contracts/mainnet/connectors/euler/main.sol b/contracts/mainnet/connectors/euler/main.sol index cd0d787c..45d9847a 100644 --- a/contracts/mainnet/connectors/euler/main.sol +++ b/contracts/mainnet/connectors/euler/main.sol @@ -95,7 +95,7 @@ abstract contract Euler is Helpers { TokenInterface tokenContract = TokenInterface(_token); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); - _amt = _amt == uint256(-1) ? eToken.balanceOf(address(this)) : _amt; + _amt = _amt == uint256(-1) ? eToken.balanceOfUnderlying(address(this)) : _amt; uint256 initialBal = tokenContract.balanceOf(address(this)); eToken.withdraw(subAccount, _amt); @@ -377,104 +377,36 @@ abstract contract Euler is Helpers { /** * @dev Approve debt. - * @notice Approves receiver to take debt. - * @param subAccountId Subaccount number - * @param debtReceiver Address of receiver - * @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param amt The amount of the token to mint. - * @param getId ID to retrieve amt. + * @notice Approve sender to send debt. + * @param subAccountId Subaccount id of receiver + * @param debtSender Address of sender + * @param token The address of the token.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param amt The amount of the token. * @param setId ID stores the amount of tokens deposited. */ function approveDebt( uint256 subAccountId, - address debtReceiver, + address debtSender, address token, uint256 amt, - uint256 getId, uint256 setId ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint256 _amt = getUint(getId, amt); bool isEth = token == ethAddr; address _token = isEth ? wethAddr : token; IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); - dToken.approveDebt(subAccountId, debtReceiver, _amt); + dToken.approveDebt(subAccountId, debtSender, amt); - setUint(setId, _amt); + setUint(setId, amt); _eventName = "LogApproveDebt(uint256,address,address,uint256)"; - _eventParam = abi.encode(subAccountId, debtReceiver, token, _amt); - } - - /** - * @dev Swap. - * @notice Executes swap. - * @param params swapParams struct - */ - function swap(swapParams memory params) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - swapHelper memory helperParams; - - helperParams._sellAddr = params.sellAddr == ethAddr - ? wethAddr - : params.sellAddr; - helperParams._buyAddr = params.sellAddr == ethAddr - ? wethAddr - : params.buyAddr; - - TokenInterface sellToken = TokenInterface(helperParams._sellAddr); - TokenInterface buyToken = TokenInterface(helperParams._buyAddr); - - approve(sellToken, address(swapExec), params.sellAmt); - - (helperParams._buyDec, helperParams._sellDec) = getTokensDec( - buyToken, - sellToken - ); - helperParams._sellAmt18 = convertTo18( - helperParams._sellDec, - params.sellAmt - ); - helperParams._slippageAmt = convert18ToDec( - helperParams._buyDec, - wmul(params.unitAmt, helperParams._sellAmt18) - ); - - Swap1InchParams memory oneInchParams = Swap1InchParams({ - subAccountIdIn: params.subAccountFrom, - subAccountIdOut: params.subAccountTo, - underlyingIn: helperParams._sellAddr, - underlyingOut: helperParams._buyAddr, - amount: params.sellAmt, - amountOutMinimum: helperParams._slippageAmt, - payload: params.callData - }); - - swapExec.swap1Inch(oneInchParams); - - if (!checkIfEnteredMarket(helperParams._buyAddr)) { - markets.enterMarket(params.subAccountTo, helperParams._buyAddr); - } - - _eventName = "LogSwap(uint256,uint256,address,address,uint256,uint256,bytes)"; - _eventParam = abi.encode( - params.subAccountFrom, - params.subAccountTo, - params.buyAddr, - params.sellAddr, - params.sellAmt, - params.unitAmt, - params.callData - ); + _eventParam = abi.encode(subAccountId, debtSender, token, amt); } /** diff --git a/scripts/tests/mainnet/tokens.ts b/scripts/tests/mainnet/tokens.ts index b3f26d76..54e1c0bc 100644 --- a/scripts/tests/mainnet/tokens.ts +++ b/scripts/tests/mainnet/tokens.ts @@ -34,6 +34,13 @@ export const tokens = { name: "Wrapped Ether", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decimals: 18 + }, + ens: { + type: "token", + symbol: "ENS", + name: "Etherem Name Services", + address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72", + decimals: 18 } }; diff --git a/test/mainnet/euler/euler.test.ts b/test/mainnet/euler/euler.test.ts index d6215098..7e271f44 100644 --- a/test/mainnet/euler/euler.test.ts +++ b/test/mainnet/euler/euler.test.ts @@ -12,6 +12,24 @@ import { tokens } from "../../../scripts/tests/mainnet/tokens"; const { ethers } = hre; import type { Signer, Contract } from "ethers"; +const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' +const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0' +const Usdc = parseUnits('5000', 6) + +const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' +const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2' +const Dai = parseUnits('5000', 18) + +const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' +const ACC_WETH = '0x05547D4e1A2191B91510Ea7fA8555a2788C70030' +const Weth = parseUnits('50', 18) + +const token_usdc = new ethers.Contract( + USDC, + IERC20__factory.abi, + ethers.provider, +) + describe("Euler", function () { const connectorName = "EULER-TEST-A"; let connector: any; @@ -21,18 +39,6 @@ describe("Euler", function () { let instaConnectorsV2: Contract; let masterSigner: Signer; - const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' - const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0' - const Usdc = parseUnits('5000', 6) - - const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f' - const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2' - const Dai = parseUnits('5000', 18) - - const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' - const ACC_WETH = '0x05547D4e1A2191B91510Ea7fA8555a2788C70030' - const Weth = parseUnits('50', 18) - before(async () => { await hre.network.provider.request({ method: "hardhat_reset", @@ -84,11 +90,6 @@ describe("Euler", function () { }); it("Deposit USDC into DSA wallet", async function () { - const token_usdc = new ethers.Contract( - USDC, - IERC20__factory.abi, - ethers.provider, - ) await hre.network.provider.request({ method: 'hardhat_impersonateAccount', @@ -251,6 +252,9 @@ describe("Euler", function () { .cast(...encodeSpells(spells), wallet1.getAddress()); await tx.wait(); + expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte( + parseUnits('2', 6) + ); }) it("Should borrow ENS into DSA wallet sub-account 1", async function () { @@ -409,7 +413,7 @@ describe("Euler", function () { { connector: connectorName, method: "approveDebt", - args: ["0", "0x9F60699cE23f1Ab86Ec3e095b477Ff79d4f409AD", tokens.dai.address, "10000000", "0", "0"], + args: ["0", "0x85c2ac24a8BD9Ff6E2Ef6cf76C198E36550f41D7", tokens.dai.address, "10000000", "0"], }, ];