Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export const useTransactionHandler = ({
TxAction.GAS_ESTIMATION,
false,
)
console.log(error, parsedError)
setTxError(parsedError)
setMainTxState({
txHash: undefined,
Expand Down
93 changes: 84 additions & 9 deletions packages/money-market/src/store/poolSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FaucetService,
IncentivesController,
IncentivesControllerV2,
IncentivesControllerV2Interface,
InterestRate,
LendingPool,
LendingPoolBundle,
Expand All @@ -29,6 +28,7 @@ import {
UiPoolDataProvider,
UserReserveDataHumanized,
V3FaucetService,
valueToWei,
WithdrawAndSwitchAdapterService,
} from "@aave/contract-helpers"
import {
Expand All @@ -45,6 +45,7 @@ import {
} from "@aave/contract-helpers/dist/esm/v3-pool-contract/lendingPoolTypes"
import {
BigNumber,
constants,
PopulatedTransaction,
providers,
Signature,
Expand Down Expand Up @@ -173,6 +174,24 @@ export interface PoolSlice {
) => Promise<PopulatedTransaction>
}

const bypassGasEstimation = (
txArr: EthereumTransactionTypeExtended[],
user: string,
rawCall: () => Promise<PopulatedTransaction>,
): EthereumTransactionTypeExtended[] => {
return txArr.map((props) => ({
...props,
tx: async () => {
const tx = await rawCall()
return {
...tx,
from: user,
value: DEFAULT_NULL_VALUE_ON_TX,
}
},
}))
}

export const createPoolSlice: StateCreator<
RootStore,
[["zustand/subscribeWithSelector", never], ["zustand/devtools", never]],
Expand Down Expand Up @@ -461,14 +480,34 @@ export const createPoolSlice: StateCreator<
return service.mint({ ...args, userAddress })
}
},
withdraw: (args) => {
withdraw: async (args) => {
const pool = getCorrectPool()
const user = get().account
return pool.withdraw({
const poolContract = pool.getContractInstance(
pool instanceof Pool ? pool.poolAddress : pool.lendingPoolAddress,
)

const tx = await pool.withdraw({
...args,
user,
useOptimizedPath: optimizedPath(get().currentChainId),
})

const { amount, reserve } = args
const { decimalsOf } = pool.erc20Service
const decimals = await decimalsOf(reserve)
const convertedAmount =
amount === "-1"
? constants.MaxUint256.toString()
: valueToWei(amount, decimals)

return bypassGasEstimation(tx, user, () =>
poolContract.populateTransaction.withdraw(
reserve,
convertedAmount,
user,
),
)
},
setUsageAsCollateralTx: async (args) => {
const pool = getCorrectPool()
Expand All @@ -495,12 +534,22 @@ export const createPoolSlice: StateCreator<
setUsageAsCollateral: async (args) => {
const pool = getCorrectPool()
const user = get().account
const poolContract = pool.getContractInstance(
pool instanceof Pool ? pool.poolAddress : pool.lendingPoolAddress,
)

return pool.setUsageAsCollateral({
const tx = await pool.setUsageAsCollateral({
...args,
user,
useOptimizedPath: get().useOptimizedPath(),
})

return bypassGasEstimation(tx, user, () =>
poolContract.populateTransaction.setUserUseReserveAsCollateral(
args.reserve,
args.usageAsCollateral,
),
)
},
swapBorrowRateMode: async (args) => {
const pool = getCorrectPool()
Expand Down Expand Up @@ -837,10 +886,16 @@ export const createPoolSlice: StateCreator<
setUserEMode: async (categoryId) => {
const pool = getCorrectPool() as Pool
const user = get().account
return pool.setUserEMode({
const poolContract = pool.getContractInstance(pool.poolAddress)

const tx = pool.setUserEMode({
user,
categoryId,
})

return bypassGasEstimation(tx, user, () =>
poolContract.populateTransaction.setUserEMode(categoryId),
)
},
signERC20Approval: async (args) => {
const pool = getCorrectPool() as Pool
Expand Down Expand Up @@ -872,27 +927,47 @@ export const createPoolSlice: StateCreator<
const incentivesTxBuilder = new IncentivesController(
get().jsonRpcProvider(),
)
const incentivesTxBuilderV2: IncentivesControllerV2Interface =
new IncentivesControllerV2(get().jsonRpcProvider())
const incentivesTxBuilderV2 = new IncentivesControllerV2(
get().jsonRpcProvider(),
)

if (get().currentMarketData.v3) {
const incentivesContract = incentivesTxBuilderV2.getContractInstance(
selectedReward.incentiveControllerAddress,
)
if (selectedReward.symbol === "all") {
return incentivesTxBuilderV2.claimAllRewards({
const tx = incentivesTxBuilderV2.claimAllRewards({
user: currentAccount,
assets: allReserves,
to: currentAccount,
incentivesControllerAddress:
selectedReward.incentiveControllerAddress,
})

return bypassGasEstimation(tx, currentAccount, () =>
incentivesContract.populateTransaction.claimAllRewards(
allReserves,
currentAccount,
),
)
} else {
return incentivesTxBuilderV2.claimRewards({
const tx = incentivesTxBuilderV2.claimRewards({
user: currentAccount,
assets: allReserves,
to: currentAccount,
incentivesControllerAddress:
selectedReward.incentiveControllerAddress,
reward: selectedReward.rewardTokenAddress,
})

return bypassGasEstimation(tx, currentAccount, () =>
incentivesContract.populateTransaction.claimRewards(
allReserves,
constants.MaxUint256.toString(),
currentAccount,
selectedReward.rewardTokenAddress,
),
)
}
} else {
return incentivesTxBuilder.claimRewards({
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/helpers/subscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type SubscanLinkPath = "tx" | "account" | "block"

const SUBSCAN_API_PROXY_URL =
"https://unified-main-aggr-indx.indexer.hydration.cloud/api/proxy/subscan"
"https://unified-main-aggr-indx.indexer.hydration.cloud/proxy/subscan"

export const subscan = {
rdns: "io.subscan",
Expand Down
Loading