Skip to content

Commit

Permalink
fix: repay with collateral and enable switch features [skip cypress] (#…
Browse files Browse the repository at this point in the history
…2170)

Co-authored-by: Mark Hinschberger <[email protected]>
Co-authored-by: miguelmtzinf <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent 362ff86 commit 4842c3a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 57 deletions.
54 changes: 29 additions & 25 deletions src/components/transactions/Repay/CollateralRepayModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export function CollateralRepayModalContent({
const [tokenToRepayWith, setTokenToRepayWith] = useState<Asset>(repayTokens[0]);
const tokenToRepayWithBalance = tokenToRepayWith.balance || '0';

const [swapVariant, setSwapVariant] = useState<SwapVariant>('exactOut');
// const [swapVariant, setSwapVariant] = useState<SwapVariant>('exactOut');
const swapVariant: SwapVariant = 'exactOut';

const [amount, setAmount] = useState('');
const [maxSlippage, setMaxSlippage] = useState('0.5');

Expand Down Expand Up @@ -107,10 +109,10 @@ export function CollateralRepayModalContent({

const swapIn = { ...collateralReserveData, amount: tokenToRepayWithBalance };
const swapOut = { ...poolReserve, amount: amountRef.current };
if (swapVariant === 'exactIn') {
swapIn.amount = tokenToRepayWithBalance;
swapOut.amount = '0';
}
// if (swapVariant === 'exactIn') {
// swapIn.amount = tokenToRepayWithBalance;
// swapOut.amount = '0';
// }

const repayAllDebt =
isMaxSelected &&
Expand Down Expand Up @@ -139,21 +141,23 @@ export function CollateralRepayModalContent({

const handleRepayAmountChange = (value: string) => {
const maxSelected = value === '-1';

if (
maxSelected &&
valueToBigNumber(tokenToRepayWithBalance).lt(collateralAmountRequiredToCoverDebt)
) {
// The selected collateral amount is not enough to pay the full debt. We'll try to do a swap using the exact amount of collateral.
// The amount won't be known until we fetch the swap data, so we'll clear it out. Once the swap data is fetched, we'll set the amount.
amountRef.current = '';
setAmount('');
setSwapVariant('exactIn');
} else {
amountRef.current = maxSelected ? safeAmountToRepayAll.toString(10) : value;
setAmount(value);
setSwapVariant('exactOut');
}
amountRef.current = maxSelected ? safeAmountToRepayAll.toString(10) : value;
setAmount(value);

// if (
// maxSelected &&
// valueToBigNumber(tokenToRepayWithBalance).lt(collateralAmountRequiredToCoverDebt)
// ) {
// // The selected collateral amount is not enough to pay the full debt. We'll try to do a swap using the exact amount of collateral.
// // The amount won't be known until we fetch the swap data, so we'll clear it out. Once the swap data is fetched, we'll set the amount.
// amountRef.current = '';
// setAmount('');
// setSwapVariant('exactIn');
// } else {
// amountRef.current = maxSelected ? safeAmountToRepayAll.toString(10) : value;
// setAmount(value);
// setSwapVariant('exactOut');
// }
};

// for v3 we need hf after withdraw collateral, because when removing collateral to repay
Expand Down Expand Up @@ -190,8 +194,8 @@ export function CollateralRepayModalContent({
collateralReserveData.priceInUSD
);

const exactOutputAmount = swapVariant === 'exactIn' ? outputAmount : repayAmount;
const exactOutputUsd = swapVariant === 'exactIn' ? outputAmountUSD : repayAmountUsdValue;
const exactOutputAmount = repayAmount; // swapVariant === 'exactIn' ? outputAmount : repayAmount;
const exactOutputUsd = repayAmountUsdValue; // swapVariant === 'exactIn' ? outputAmountUSD : repayAmountUsdValue;

const assetsBlockingWithdraw = useZeroLTVBlockingWithdraw();

Expand Down Expand Up @@ -316,7 +320,7 @@ export function CollateralRepayModalContent({
setSlippage={setMaxSlippage}
slippageTooltipHeader={
<Stack direction="row" alignItems="center">
{swapVariant === 'exactIn' ? (
{false ? (
<>
<Trans>Minimum amount of debt to be repaid</Trans>
<Stack alignItems="end">
Expand Down Expand Up @@ -379,8 +383,8 @@ export function CollateralRepayModalContent({
<CollateralRepayActions
poolReserve={poolReserve}
fromAssetData={collateralReserveData}
repayAmount={swapVariant === 'exactIn' ? outputAmountWithSlippage : outputAmount}
repayWithAmount={swapVariant === 'exactOut' ? inputAmountWithSlippage : inputAmount}
repayAmount={outputAmount}
repayWithAmount={inputAmountWithSlippage}
repayAllDebt={repayAllDebt}
useFlashLoan={shouldUseFlashloan}
isWrongNetwork={isWrongNetwork}
Expand Down
64 changes: 32 additions & 32 deletions src/ui-config/marketsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ export const marketsData: {
governance: true,
staking: true,
liquiditySwap: true,
collateralRepay: false,
collateralRepay: true,
incentives: true,
withdrawAndSwitch: true,
debtSwitch: false,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/Cd2gEDVeqnjBn1hSeqFMitw8Q1iiyV9FYUZkLNRcL87g`,
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3Ethereum.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3Ethereum.POOL,
WETH_GATEWAY: AaveV3Ethereum.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Ethereum.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x35bb522b102326ea3f1141661df4626c87000e3e',
SWAP_COLLATERAL_ADAPTER: AaveV3Ethereum.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3Ethereum.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3Ethereum.UI_POOL_DATA_PROVIDER,
Expand All @@ -156,18 +156,18 @@ export const marketsData: {
governance: true,
staking: true,
liquiditySwap: true,
collateralRepay: false,
collateralRepay: true,
incentives: true,
withdrawAndSwitch: true,
debtSwitch: false,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/5vxMbXRhG1oQr55MWC5j6qg78waWujx1wjeuEWDA6j3`,
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3EthereumLido.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3EthereumLido.POOL,
WETH_GATEWAY: AaveV3EthereumLido.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3EthereumLido.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x66E1aBdb06e7363a618D65a910c540dfED23754f',
SWAP_COLLATERAL_ADAPTER: AaveV3EthereumLido.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3EthereumLido.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3EthereumLido.UI_POOL_DATA_PROVIDER,
Expand Down Expand Up @@ -197,7 +197,7 @@ export const marketsData: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3EthereumEtherFi.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3EthereumEtherFi.POOL,
WETH_GATEWAY: AaveV3EthereumEtherFi.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3EthereumEtherFi.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x23b282c49C88d9161aae14b5eD777B976A5Ae65D',
SWAP_COLLATERAL_ADAPTER: AaveV3EthereumEtherFi.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3EthereumEtherFi.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3EthereumEtherFi.UI_POOL_DATA_PROVIDER,
Expand All @@ -214,10 +214,10 @@ export const marketsData: {
governance: true,
staking: true,
liquiditySwap: true,
collateralRepay: false,
collateralRepay: true,
incentives: true,
debtSwitch: false,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/8wR23o1zkS4gpLqLNU4kG3JHYVucqGyopL5utGxP2q1N`,
addresses: {
Expand All @@ -238,7 +238,7 @@ export const marketsData: {
// marketTitle: 'Ethereum Permissioned Market example',
// chainId: ChainId.mainnet,
// enabledFeatures: {
// // liquiditySwap: false,
// // liquiditySwap: true,
// // collateralRepay: false,
// // incentives: true,
// permissions: true,
Expand Down Expand Up @@ -278,7 +278,7 @@ export const marketsData: {
enabledFeatures: {
liquiditySwap: true,
incentives: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/H1Et77RZh3XEf27vkAmJyzgCME2RSFLtDS2f4PPW6CGp`,
Expand All @@ -303,9 +303,9 @@ export const marketsData: {
enabledFeatures: {
liquiditySwap: true,
incentives: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/EZvK18pMhwiCjxwesRLTg81fP33WnR6BnZe5Cvma3H1C`,
addresses: {
Expand Down Expand Up @@ -352,9 +352,9 @@ export const marketsData: {
incentives: true,
liquiditySwap: true,
withdrawAndSwitch: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/GQFbb95cE6d8mV989mL5figjaGaKCQB3xqYrr1bRyXqF`,
addresses: {
Expand All @@ -366,7 +366,7 @@ export const marketsData: {
UI_INCENTIVE_DATA_PROVIDER: AaveV3Base.UI_INCENTIVE_DATA_PROVIDER,
L2_ENCODER: AaveV3Base.L2_ENCODER,
COLLECTOR: AaveV3Base.COLLECTOR,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Base.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x63dfa7c09Dc2Ff4030d6B8Dc2ce6262BF898C8A4',
SWAP_COLLATERAL_ADAPTER: AaveV3Base.SWAP_COLLATERAL_ADAPTER,
// WALLET_BALANCE_PROVIDER: AaveV2Ethereum.WALLET_BALANCE_PROVIDER,
WITHDRAW_SWITCH_ADAPTER: AaveV3Base.WITHDRAW_SWAP_ADAPTER,
Expand Down Expand Up @@ -399,10 +399,10 @@ export const marketsData: {
enabledFeatures: {
incentives: true,
liquiditySwap: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
withdrawAndSwitch: true,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/DLuE98kEb5pQNXAcKFQGQgfSQ57Xdou4jnVbAEqMfy3B`,
addresses: {
Expand All @@ -416,7 +416,7 @@ export const marketsData: {
L2_ENCODER: AaveV3Arbitrum.L2_ENCODER,
COLLECTOR: AaveV3Arbitrum.COLLECTOR,
SWAP_COLLATERAL_ADAPTER: AaveV3Arbitrum.SWAP_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Arbitrum.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0xe28e2c8d240dd5ebd0adcab86fbd79df7a052034',
DEBT_SWITCH_ADAPTER: AaveV3Arbitrum.DEBT_SWAP_ADAPTER,
WITHDRAW_SWITCH_ADAPTER: AaveV3Arbitrum.WITHDRAW_SWAP_ADAPTER,
GHO_TOKEN_ADDRESS: '0x7dff72693f6a4149b17e7c6314655f6a9f7c8b33',
Expand Down Expand Up @@ -447,17 +447,17 @@ export const marketsData: {
enabledFeatures: {
liquiditySwap: true,
incentives: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
withdrawAndSwitch: true,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/2h9woxy8RTjHu1HJsCEnmzpPHFArU33avmUh4f71JpVn`,
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3Avalanche.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3Avalanche.POOL,
WETH_GATEWAY: AaveV3Avalanche.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Avalanche.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x5d4D4007A4c6336550DdAa2a7c0d5e7972eebd16',
SWAP_COLLATERAL_ADAPTER: AaveV3Avalanche.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3Avalanche.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3Avalanche.UI_POOL_DATA_PROVIDER,
Expand Down Expand Up @@ -531,7 +531,7 @@ export const marketsData: {
chainId: ChainId.fantom,
enabledFeatures: {
incentives: true,
collateralRepay: false,
collateralRepay: true,
liquiditySwap: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/6L1vPqyE3xvkzkWjh6wUKc1ABWYYps5HJahoxhrv2PJn`,
Expand Down Expand Up @@ -592,11 +592,11 @@ export const marketsData: {
chainId: ChainId.optimism,
enabledFeatures: {
incentives: true,
collateralRepay: false,
collateralRepay: true,
liquiditySwap: true,
debtSwitch: false,
withdrawAndSwitch: true,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/DSfLz8oQBUeU5atALgUFQKMTSYV9mZAVYp4noLSXAfvb`,
addresses: {
Expand All @@ -609,7 +609,7 @@ export const marketsData: {
L2_ENCODER: AaveV3Optimism.L2_ENCODER,
COLLECTOR: AaveV3Optimism.COLLECTOR,
SWAP_COLLATERAL_ADAPTER: AaveV3Optimism.SWAP_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Optimism.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x5d4d4007a4c6336550ddaa2a7c0d5e7972eebd16',
DEBT_SWITCH_ADAPTER: AaveV3Optimism.DEBT_SWAP_ADAPTER,
WITHDRAW_SWITCH_ADAPTER: AaveV3Optimism.WITHDRAW_SWAP_ADAPTER,
},
Expand All @@ -622,17 +622,17 @@ export const marketsData: {
enabledFeatures: {
liquiditySwap: true,
incentives: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
withdrawAndSwitch: true,
switch: false,
switch: true,
},
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/Co2URyXjnxaw8WqxKyVHdirq9Ahhm5vcTs4dMedAq211`,
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3Polygon.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3Polygon.POOL,
WETH_GATEWAY: AaveV3Polygon.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3Polygon.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x5d4d4007a4c6336550ddaa2a7c0d5e7972eebd16',
SWAP_COLLATERAL_ADAPTER: AaveV3Polygon.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3Polygon.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3Polygon.UI_POOL_DATA_PROVIDER,
Expand Down Expand Up @@ -705,16 +705,16 @@ export const marketsData: {
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${apiKey}/subgraphs/id/7Jk85XgkV1MQ7u56hD8rr65rfASbayJXopugWkUoBMnZ`,
enabledFeatures: {
liquiditySwap: true,
collateralRepay: false,
collateralRepay: true,
debtSwitch: false,
withdrawAndSwitch: true,
switch: false,
switch: true,
},
addresses: {
LENDING_POOL_ADDRESS_PROVIDER: AaveV3BNB.POOL_ADDRESSES_PROVIDER,
LENDING_POOL: AaveV3BNB.POOL,
WETH_GATEWAY: AaveV3BNB.WETH_GATEWAY,
REPAY_WITH_COLLATERAL_ADAPTER: AaveV3BNB.REPAY_WITH_COLLATERAL_ADAPTER,
REPAY_WITH_COLLATERAL_ADAPTER: '0x5598BbFA2f4fE8151f45bBA0a3edE1b54B51a0a9',
SWAP_COLLATERAL_ADAPTER: AaveV3BNB.SWAP_COLLATERAL_ADAPTER,
WALLET_BALANCE_PROVIDER: AaveV3BNB.WALLET_BALANCE_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV3BNB.UI_POOL_DATA_PROVIDER,
Expand Down

2 comments on commit 4842c3a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.