Skip to content

Commit

Permalink
fix(useMultipleSUpplyWithBorrow): finally working
Browse files Browse the repository at this point in the history
  • Loading branch information
akanoce committed Jan 21, 2024
1 parent 41cf1c6 commit 82b8ada
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
50 changes: 32 additions & 18 deletions apps/web/src/hooks/useMultipleSupplyWithBorrow.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { useMutation } from 'wagmi';
import { createSupplyTxs } from '@/api';
import { createBorrowTx, createSupplyTxs } from '@/api';
import { useAaveContracts } from '@/providers';
import { useAccountAdapter } from './useAccountAdapter';
import { EthereumTransactionTypeExtended } from '@aave/aave-utilities/packages/contract-helpers';
import { LPSupplyParamsType } from '@aave/aave-utilities/packages/contract-helpers/dist/esm/v3-pool-contract/lendingPoolTypes';
import {
EthereumTransactionTypeExtended,
InterestRate
} from '@aave/aave-utilities/packages/contract-helpers';
import {
LPBorrowParamsType,
LPSupplyParamsType
} from '@aave/aave-utilities/packages/contract-helpers/dist/esm/v3-pool-contract/lendingPoolTypes';
import { ReserveDataHumanized } from '@aave/aave-utilities/packages/contract-helpers/dist/esm/v3-UiPoolDataProvider-contract/types';
import { FormatReserveUSDResponse } from '@aave/aave-utilities/packages/math-utils';
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -42,15 +48,23 @@ export const useMultipleSupplyWithBorrow = ({ toSupply, toBorrow }: Props) => {
reserve: reserve.underlyingAsset
};

console.log('TX', supplyData);
console.log({ reserve });

console.log({
...supplyData,
amountInUsd,
ltv: reserve.formattedBaseLTVasCollateral
});
console.log('Creating supply with permit txs...');
const supplyTxs = await createSupplyTxs(poolContract, {
...supplyData
});

totalEstimatedAvailableUsdToBorrow +=
BigNumber(amountInUsd).toNumber() *
Number(reserve.baseLTVasCollateral);
totalEstimatedAvailableUsdToBorrow += new BigNumber(amountInUsd)
.multipliedBy(
new BigNumber(reserve.formattedBaseLTVasCollateral)
)
.toNumber();

allTxs.push(...supplyTxs);
}
Expand All @@ -65,17 +79,17 @@ export const useMultipleSupplyWithBorrow = ({ toSupply, toBorrow }: Props) => {
maxAmountBorrowable
});

// const borrowData: LPBorrowParamsType = {
// amount: maxAmountBorrowable.toString(),
// user: account,
// reserve: toBorrow.underlyingAsset,
// interestRateMode: InterestRate.Variable
// };

// const borrowTxs = await createBorrowTx(poolContract, {
// ...borrowData
// });
// allTxs.push(...borrowTxs);
const borrowData: LPBorrowParamsType = {
amount: maxAmountBorrowable.toString(),
user: account,
reserve: toBorrow.underlyingAsset,
interestRateMode: InterestRate.Variable
};

const borrowTxs = await createBorrowTx(poolContract, {
...borrowData
});
allTxs.push(...borrowTxs);
console.log('Submitting txs...');
await sendTransaction({ txs: allTxs });
};
Expand Down
1 change: 0 additions & 1 deletion packages/lfgho-sdk/src/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ export const useTransactions = () => {
const txGas = await tx.gas();
console.log('txGas', txGas);
const extendedTxData = await tx.tx();
extendedTxData.to;
extendedTxs.push(extendedTxData);
}

Expand Down

0 comments on commit 82b8ada

Please sign in to comment.