Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrow Asset Value Doesn't Reflect currentTimestamp Parameter #606

Open
chananyulim1616 opened this issue Dec 25, 2024 · 1 comment
Open

Comments

@chananyulim1616
Copy link

When using the userSummary method, I noticed that changing the currentTimestamp parameter does not affect the value of the borrowed assets (unexpected behavior). However, the value of supplied assets changes correctly as expected.

Here’s the relevant code snippet:

const currentTimestamp = dayjs().unix();

const formattedReserves = formatReservesAndIncentives({
  reserves: reservesArray,
  currentTimestamp,
  marketReferenceCurrencyDecimals:
    baseCurrencyData.marketReferenceCurrencyDecimals,
  marketReferencePriceInUsd:
    baseCurrencyData.marketReferenceCurrencyPriceInUsd,
  reserveIncentives,
});

const userSummary = formatUserSummary({
  currentTimestamp,
  marketReferencePriceInUsd:
    baseCurrencyData.marketReferenceCurrencyPriceInUsd,
  marketReferenceCurrencyDecimals:
    baseCurrencyData.marketReferenceCurrencyDecimals,
  userReserves: userReservesArray,
  formattedReserves,
  userEmodeCategoryId: userReserves.userEmodeCategoryId,
});

The currentTimestamp correctly updates the value for supplied assets but does not impact the value for borrowed assets. This seems inconsistent. Could you confirm if this is a bug or if I'm missing something in the implementation?

@defispartan
Copy link
Collaborator

Thanks for reporting, I was able to re-produce this behavior with a test script on ETH mainnet

For debugging, the calculation for userReserve.variableBorrows occurs here cc @grothem @JoaquinBattilana

const ethers = require("ethers");
const { UiPoolDataProvider, ChainId } = require("@aave/contract-helpers");
const markets = require("@bgd-labs/aave-address-book");
const { formatUserSummary, formatReserves } = require("@aave/math-utils");
const dayjs = require("dayjs");

const provider = new ethers.providers.JsonRpcProvider(
  "https://eth-mainnet.public.blastapi.io"
);

const currentAccount = "0x6c2A355929Ee1262305E385Ad49B84FE5f5A4777";

const poolDataProviderContract = new UiPoolDataProvider({
  uiPoolDataProviderAddress: markets.AaveV3Ethereum.UI_POOL_DATA_PROVIDER,
  provider,
  chainId: ChainId.mainnet,
});

async function fetchUserSummary() {
  const reserves = await poolDataProviderContract.getReservesHumanized({
    lendingPoolAddressProvider: markets.AaveV3Ethereum.POOL_ADDRESSES_PROVIDER,
  });

  const userReserves = await poolDataProviderContract.getUserReservesHumanized({
    lendingPoolAddressProvider: markets.AaveV3Ethereum.POOL_ADDRESSES_PROVIDER,
    user: currentAccount,
  });

  const reservesArray = reserves.reservesData;
  const baseCurrencyData = reserves.baseCurrencyData;
  const userReservesArray = userReserves.userReserves;

  const currentTimestamp = dayjs().unix();

  const formattedReserves = formatReserves({
    reserves: reservesArray,
    currentTimestamp,
    marketReferenceCurrencyDecimals:
      baseCurrencyData.marketReferenceCurrencyDecimals,
    marketReferencePriceInUsd:
      baseCurrencyData.marketReferenceCurrencyPriceInUsd,
  });
  console.log("Current timestamp: ", currentTimestamp);
  const userSummary = formatUserSummary({
    currentTimestamp,
    marketReferencePriceInUsd:
      baseCurrencyData.marketReferenceCurrencyPriceInUsd,
    marketReferenceCurrencyDecimals:
      baseCurrencyData.marketReferenceCurrencyDecimals,
    userReserves: userReservesArray,
    formattedReserves,
  });
  return userSummary;
}

(async function testVariableBorrows() {
  console.log("Fetching user summary...");
  const userSummary = await fetchUserSummary();

  console.log("Fetching initial variable borrows...");
  const initialBorrows = userSummary.userReservesData.map(
    (reserve) => reserve.scaledVariableDebt
  );
  console.log("Initial variable borrows:", initialBorrows);

  console.log("Waiting 10 seconds...");
  await new Promise((resolve) => setTimeout(resolve, 10000));

  console.log("Fetching variable borrows after 10 seconds...");
  const updatedUserSummary = await fetchUserSummary();
  const finalBorrows = updatedUserSummary.userReservesData.map(
    (reserve) => reserve.scaledVariableDebt
  );
  console.log("Final variable borrows:", finalBorrows);

  const differences = initialBorrows.map((initial, index) => {
    const final = finalBorrows[index];
    return {
      reserveIndex: index,
      initial,
      final,
      difference: final - initial,
    };
  });

  console.log("Differences in variable borrows:", differences);
})();

@aave aave deleted a comment Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants