From b3ca2069c572a6e77a20ff2a4e4e9bdcaa650210 Mon Sep 17 00:00:00 2001 From: Priyam Anand Date: Tue, 25 Jun 2024 17:14:38 +0530 Subject: [PATCH 1/6] feat: added looping button --- .../SupplyAssetsList/SupplyAssetsListItem.tsx | 110 + src/ui-config/marketsConfig.tsx | 16 +- src/utils/contracts/CreditDelegationToken.ts | 362 ++ src/utils/contracts/ERC20.ts | 707 +++ src/utils/contracts/Leverage.ts | 424 ++ src/utils/contracts/Pool.ts | 4063 +++++++++++++++++ src/utils/contracts/common.ts | 37 + 7 files changed, 5713 insertions(+), 6 deletions(-) create mode 100644 src/utils/contracts/CreditDelegationToken.ts create mode 100644 src/utils/contracts/ERC20.ts create mode 100644 src/utils/contracts/Leverage.ts create mode 100644 src/utils/contracts/Pool.ts create mode 100644 src/utils/contracts/common.ts diff --git a/src/modules/dashboard/lists/SupplyAssetsList/SupplyAssetsListItem.tsx b/src/modules/dashboard/lists/SupplyAssetsList/SupplyAssetsListItem.tsx index f8954811..2339da78 100644 --- a/src/modules/dashboard/lists/SupplyAssetsList/SupplyAssetsListItem.tsx +++ b/src/modules/dashboard/lists/SupplyAssetsList/SupplyAssetsListItem.tsx @@ -1,5 +1,9 @@ import { Trans } from '@lingui/macro'; import { Button } from '@mui/material'; +import { useWeb3React } from '@web3-react/core'; +import { BigNumber, constants, Contract, providers } from 'ethers'; +import { parseEther } from 'ethers/lib/utils'; +import { useState } from 'react'; import { useAssetCaps } from 'src/hooks/useAssetCaps'; import { useModalContext } from 'src/hooks/useModal'; import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext'; @@ -8,6 +12,15 @@ import { DashboardReserve } from 'src/utils/dashboardSortUtils'; import { CapsHint } from '../../../../components/caps/CapsHint'; import { CapType } from '../../../../components/caps/helper'; import { Link, ROUTES } from '../../../../components/primitives/Link'; +import { useAppDataContext } from '../../../../hooks/app-data-provider/useAppDataProvider'; +import { useWeb3Context } from '../../../../libs/hooks/useWeb3Context'; +import { marketsData } from '../../../../ui-config/marketsConfig'; +import { + CreditDelegationTokenABI, + ICreditDelegationToken, +} from '../../../../utils/contracts/CreditDelegationToken'; +import { Leverage, LeverageABI } from '../../../../utils/contracts/Leverage'; +import { availableMarkets } from '../../../../utils/marketsAndNetworksConfig'; import { SpkAirdropNoteInline } from '../BorrowAssetsList/BorrowAssetsListItem'; import { ListAPRColumn } from '../ListAPRColumn'; import { ListButtonsColumn } from '../ListButtonsColumn'; @@ -31,13 +44,94 @@ export const SupplyAssetsListItem = ({ showSwap, hideSupply, }: DashboardReserve) => { + const { reserves } = useAppDataContext(); + const { library: provider } = useWeb3React(); + const { currentAccount } = useWeb3Context(); const { currentMarket } = useProtocolDataContext(); const { openSupply, openPSMSwap } = useModalContext(); + const [isLooping, setIsLooping] = useState(false); // Hide the asset to prevent it from being supplied if supply cap has been reached const { supplyCap: supplyCapUsage } = useAssetCaps(); if (supplyCapUsage.isMaxed) return null; + const doLoopingAction = async () => { + try { + setIsLooping(true); + const currentMarketData = marketsData[availableMarkets[0]]; + const signer = provider?.getSigner(currentAccount); + const interestRateMode = 2; + const leverageInstance = new Contract( + currentMarketData.addresses.LEVERAGE!, + LeverageABI, + signer + ) as Leverage; + // looping + const debtTokenAddress = reserves.filter( + (item) => + item.underlyingAsset.toLowerCase() === + currentMarketData.addresses.WRAPPED_TOKEN?.toLowerCase() + )[0].variableDebtTokenAddress; + const debtTokenInstance = new Contract( + debtTokenAddress, + CreditDelegationTokenABI, + signer + ) as ICreditDelegationToken; + + const delegationAmount = await debtTokenInstance.borrowAllowance( + currentAccount, + currentMarketData.addresses.LEVERAGE! + ); + console.log('delegation amount ', delegationAmount, delegationAmount.toString()); + if (delegationAmount.eq(BigNumber.from('0'))) { + const txn = await debtTokenInstance.approveDelegation( + currentMarketData.addresses.LEVERAGE!, + constants.MaxUint256.toString() + ); + await txn.wait(1); + console.log(txn); + } + + const loopCount = 5; + const borrowRatio = 8000; // 80% + + const loopingTxn = await leverageInstance.loop(loopCount, borrowRatio, interestRateMode, 0, { + value: parseEther('1'), + }); + + await loopingTxn.wait(1); + console.log(loopingTxn); + + // unlooping + // const aTokenAddress = reserves.filter((item) => item.symbol === 'wstXTZ')[0].aTokenAddress; + // const aTokenInstance = new Contract(aTokenAddress, ERC20ABI, signer) as ERC20; + + // const approvalAmt = await aTokenInstance.allowance( + // currentAccount, + // currentMarketData.addresses.LEVERAGE! + // ); + // if (approvalAmt.eq(BigNumber.from('0'))) { + // const aTokenTx = await aTokenInstance.approve( + // currentMarketData.addresses.LEVERAGE!, + // constants.MaxUint256.toString() + // ); + // await aTokenTx.wait(2); + // console.log(aTokenTx); + // } + + // const unloop = await leverageInstance.unLoop( + // BigNumber.from(parseEther('1')), + // currentAccount, + // interestRateMode + // ); + // await unloop.wait(1); + // console.log(unloop); + } catch (error) { + console.error('Error in doing the looping action', error); + } + setIsLooping(false); + }; + return ( Deposit )} + {!hideSupply && symbol === 'XTZ' && ( + + )} {showSwap && ( + From c42c18a0495038c995cde1a08c1a5d4a49405337 Mon Sep 17 00:00:00 2001 From: Priyam Anand Date: Tue, 25 Jun 2024 22:25:21 +0530 Subject: [PATCH 3/6] added new market configs --- src/ui-config/marketsConfig.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui-config/marketsConfig.tsx b/src/ui-config/marketsConfig.tsx index c16a707c..a56209eb 100644 --- a/src/ui-config/marketsConfig.tsx +++ b/src/ui-config/marketsConfig.tsx @@ -70,13 +70,13 @@ export const marketsData: { faucet: false, }, addresses: { - LENDING_POOL_ADDRESS_PROVIDER: '0x8780b9f46123A151f8325E0bEE5e8B977DEFf1FA'.toLowerCase(), - LENDING_POOL: '0xB3a5e66cF7Fd00C14E6DC9f57E4200BDd4d5ba8b', - WALLET_BALANCE_PROVIDER: '0xaD66495fBb102Bb5420326C20F92592a1bddf0d9', - UI_POOL_DATA_PROVIDER: '0x6A71659daBd47de688d5bD7eb18F7F599900c9a3', + LENDING_POOL_ADDRESS_PROVIDER: '0xB58cF2e8BBBE691f27f96eA32F54A21E7F75fD0C'.toLowerCase(), + LENDING_POOL: '0x717E0e99E4c71d896804bD2cF0532d3112ffd5D5', + WALLET_BALANCE_PROVIDER: '0x6B92955469e184F1eeF5567748f6F12D608bB698', + UI_POOL_DATA_PROVIDER: '0x325C2184D59bcB687eb777fd5FbB192fb8dD6CEB', UI_INCENTIVE_DATA_PROVIDER: '0x65374686E598ae4AA22E2E4780436C029EEc6E3b', - WETH_GATEWAY: '0xD9bf48dde1b08A6e13AA1b6F9E5Ac943898021E3', - LEVERAGE: '0x00398eB80CD3090fbCfad86B162d875Ac2AC5035', + WETH_GATEWAY: '0xB39537551422D916e6B0013Ef7Dd257D07a17FE3', + LEVERAGE: '0xd4864b20bfA721c7201E53E6AF52b1c3498EB5E6', WRAPPED_TOKEN: '0xc2ef9495272b43f5257b35a1b6dda78932839871', }, faucetUrl: 'https://faucet.plend.finance/receiveFaucetTokens', From 426da98840aaafd39d4190c18d6efb416d2fae8b Mon Sep 17 00:00:00 2001 From: Priyam Anand Date: Wed, 26 Jun 2024 11:46:50 +0530 Subject: [PATCH 4/6] fix: added wait time for txns and loaders --- .../BorrowedPositionsListItem.tsx | 17 ++++++++++------- .../SupplyAssetsList/SupplyAssetsListItem.tsx | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/modules/dashboard/lists/BorrowedPositionsList/BorrowedPositionsListItem.tsx b/src/modules/dashboard/lists/BorrowedPositionsList/BorrowedPositionsListItem.tsx index 6c6dde5c..63af1023 100644 --- a/src/modules/dashboard/lists/BorrowedPositionsList/BorrowedPositionsListItem.tsx +++ b/src/modules/dashboard/lists/BorrowedPositionsList/BorrowedPositionsListItem.tsx @@ -1,6 +1,6 @@ import { InterestRate } from '@aave/contract-helpers'; import { Trans } from '@lingui/macro'; -import { Button } from '@mui/material'; +import { Button, CircularProgress } from '@mui/material'; import { useWeb3React } from '@web3-react/core'; import { BigNumber, constants, Contract, providers } from 'ethers'; import { parseEther } from 'ethers/lib/utils'; @@ -61,12 +61,10 @@ export const BorrowedPositionsListItem = ({ currentMarketData.addresses.LEVERAGE! ); if (approvalAmt.eq(BigNumber.from('0'))) { - const aTokenTx = await aTokenInstance.approve( + await aTokenInstance.approve( currentMarketData.addresses.LEVERAGE!, constants.MaxUint256.toString() ); - await aTokenTx.wait(2); - console.log(aTokenTx); } const unloop = await leverageInstance.unLoop( @@ -74,8 +72,7 @@ export const BorrowedPositionsListItem = ({ currentAccount, interestRateMode ); - console.log(unloop); - await unloop.wait(2); + await unloop.wait(1); router.reload(); } catch (error) { @@ -136,7 +133,13 @@ export const BorrowedPositionsListItem = ({ variant="contained" onClick={() => handleUnloopingAction()} > - Unloop + {isUnlooping ? ( + + + + ) : ( + Unloop + )} )} {showSwap && ( From f7a48e6dedc95121b35bdf53aa8a470df7ff1fe3 Mon Sep 17 00:00:00 2001 From: Priyam Anand Date: Fri, 28 Jun 2024 15:53:25 +0530 Subject: [PATCH 5/6] fix: updated leverge contract address for new bug fixed contract --- .../BorrowAssetsList/BorrowAssetsListItem.tsx | 6 +++--- .../BorrowedPositionsListItem.tsx | 14 +++++++++++--- .../SupplyAssetsList/SupplyAssetsListItem.tsx | 3 +-- src/ui-config/marketsConfig.tsx | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/modules/dashboard/lists/BorrowAssetsList/BorrowAssetsListItem.tsx b/src/modules/dashboard/lists/BorrowAssetsList/BorrowAssetsListItem.tsx index 0632fbbf..0d999b26 100644 --- a/src/modules/dashboard/lists/BorrowAssetsList/BorrowAssetsListItem.tsx +++ b/src/modules/dashboard/lists/BorrowAssetsList/BorrowAssetsListItem.tsx @@ -24,10 +24,11 @@ export const BorrowAssetsListItem = ({ variableBorrowRate, vIncentivesData, underlyingAsset, + isFreezed, }: DashboardReserve) => { const { openBorrow } = useModalContext(); const { currentMarket } = useProtocolDataContext(); - // const borrowButtonDisable = isFreezed || Number(availableBorrows) <= 0; + const borrowButtonDisable = isFreezed || Number(availableBorrows) <= 0; return (