Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
melotik committed Oct 31, 2023
1 parent 484f620 commit f73e24d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/sdk/protocols/lending/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { INT_ONE, INT_ZERO } from "./constants";
* - Making position snapshots
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down
6 changes: 4 additions & 2 deletions subgraphs/_reference_/src/sdk/protocols/lending/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { PositionManager } from "./position";
* need to think about all of the detailed storage changes that occur.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down Expand Up @@ -888,14 +888,16 @@ export class DataManager {
newVariableBorrowBalance: BigInt | null = null,
newStableBorrowBalance: BigInt | null = null,
newReserveBalance: BigInt | null = null,
exchangeRate: BigDecimal | null = null
exchangeRate: BigDecimal | null = null,
outputTokenSupply: BigInt | null = null
): void {
const mantissaFactorBD = exponentToBigDecimal(
this.inputToken.getDecimals()
);
this.inputToken.updatePrice(inputTokenPriceUSD);
this.market.inputTokenPriceUSD = inputTokenPriceUSD;
this.market.inputTokenBalance = newInputTokenBalance;
this.market.outputTokenSupply = outputTokenSupply;
if (newVariableBorrowBalance) {
this.market.variableBorrowedTokenBalance = newVariableBorrowBalance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PositionSide } from "./constants";
* make changes to a given position.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down
9 changes: 8 additions & 1 deletion subgraphs/_reference_/src/sdk/protocols/lending/snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
* need to think about all of the detailed storage changes that occur.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down Expand Up @@ -456,6 +456,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyDepositUSD.plus(amountUSD);
this.financialSnapshot.dailyDepositUSD =
this.financialSnapshot.dailyDepositUSD.plus(amountUSD);
this.marketDailySnapshot.dailyDepositCount += INT_ONE;
this.usageDailySnapshot.dailyDepositCount += INT_ONE;
this.usageHourlySnapshot.hourlyDepositCount += INT_ONE;
} else if (transactionType == TransactionType.WITHDRAW) {
Expand All @@ -467,6 +468,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyWithdrawUSD.plus(amountUSD);
this.financialSnapshot.dailyWithdrawUSD =
this.financialSnapshot.dailyWithdrawUSD.plus(amountUSD);
this.marketDailySnapshot.dailyWithdrawCount += INT_ONE;
this.usageDailySnapshot.dailyWithdrawCount += INT_ONE;
this.usageHourlySnapshot.hourlyWithdrawCount += INT_ONE;
} else if (transactionType == TransactionType.BORROW) {
Expand All @@ -478,6 +480,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyBorrowUSD.plus(amountUSD);
this.financialSnapshot.dailyBorrowUSD =
this.financialSnapshot.dailyBorrowUSD.plus(amountUSD);
this.marketDailySnapshot.dailyBorrowCount += INT_ONE;
this.usageDailySnapshot.dailyBorrowCount += INT_ONE;
this.usageHourlySnapshot.hourlyBorrowCount += INT_ONE;
} else if (transactionType == TransactionType.REPAY) {
Expand All @@ -489,6 +492,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyRepayUSD.plus(amountUSD);
this.financialSnapshot.dailyRepayUSD =
this.financialSnapshot.dailyRepayUSD.plus(amountUSD);
this.marketDailySnapshot.dailyRepayCount += INT_ONE;
this.usageDailySnapshot.dailyRepayCount += INT_ONE;
this.usageHourlySnapshot.hourlyRepayCount += INT_ONE;
} else if (transactionType == TransactionType.LIQUIDATE) {
Expand All @@ -500,6 +504,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyLiquidateUSD.plus(amountUSD);
this.financialSnapshot.dailyLiquidateUSD =
this.financialSnapshot.dailyLiquidateUSD.plus(amountUSD);
this.marketDailySnapshot.dailyLiquidateCount += INT_ONE;
this.usageDailySnapshot.dailyLiquidateCount += INT_ONE;
this.usageHourlySnapshot.hourlyLiquidateCount += INT_ONE;
} else if (transactionType == TransactionType.TRANSFER) {
Expand All @@ -511,6 +516,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyTransferUSD.plus(amountUSD);
this.financialSnapshot.dailyTransferUSD =
this.financialSnapshot.dailyTransferUSD.plus(amountUSD);
this.marketDailySnapshot.dailyTransferCount += INT_ONE;
this.usageDailySnapshot.dailyTransferCount += INT_ONE;
} else if (transactionType == TransactionType.FLASHLOAN) {
this.marketDailySnapshot.dailyFlashloanUSD =
Expand All @@ -521,6 +527,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyFlashloanUSD.plus(amountUSD);
this.financialSnapshot.dailyFlashloanUSD =
this.financialSnapshot.dailyFlashloanUSD.plus(amountUSD);
this.marketDailySnapshot.dailyFlashloanCount += INT_ONE;
this.usageDailySnapshot.dailyFlashloanCount += INT_ONE;
} else {
log.error("[updateTransactionData] Invalid transaction type: {}", [
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/sdk/protocols/lending/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
* use in mappings and get info about the token.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down
10 changes: 7 additions & 3 deletions subgraphs/aave-forks/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ export function _handleReserveDataUpdated(
assetPriceUSD,
tryTotalSupply.value,
vBorrowBalance,
sBorrowBalance
sBorrowBalance,
null,
null,
tryTotalSupply.value
);

const tryScaledSupply = aTokenContract.try_scaledTotalSupply();
Expand Down Expand Up @@ -1164,7 +1167,7 @@ export function _handleMintedToTreasury(
return;
}

const tokenManager = new TokenManager(asset, event, TokenType.REBASING);
const tokenManager = new TokenManager(market.inputToken, event);
const amountUSD = tokenManager.getAmountUSD(amount);
const treasuryAddress = getTreasuryAddress(market);
const treasuryBalance = getCollateralBalance(market, treasuryAddress);
Expand Down Expand Up @@ -1269,7 +1272,8 @@ export function _handleTransfer(
interestRateType
);

const amountUSD = tokenManager.getAmountUSD(amount);
const inputTokenManager = new TokenManager(market.inputToken, event);
const amountUSD = inputTokenManager.getAmountUSD(amount);
const manager = new DataManager(
market.id,
market.inputToken,
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/aave-forks/src/sdk/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { INT_ONE, INT_ZERO } from "./constants";
* - Making position snapshots
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down
6 changes: 4 additions & 2 deletions subgraphs/aave-forks/src/sdk/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { PositionManager } from "./position";
* need to think about all of the detailed storage changes that occur.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down Expand Up @@ -950,14 +950,16 @@ export class DataManager {
newVariableBorrowBalance: BigInt | null = null,
newStableBorrowBalance: BigInt | null = null,
newReserveBalance: BigInt | null = null,
exchangeRate: BigDecimal | null = null
exchangeRate: BigDecimal | null = null,
outputTokenSupply: BigInt | null = null
): void {
const mantissaFactorBD = exponentToBigDecimal(
this.inputToken.getDecimals()
);
this.inputToken.updatePrice(inputTokenPriceUSD);
this.market.inputTokenPriceUSD = inputTokenPriceUSD;
this.market.inputTokenBalance = newInputTokenBalance;
this.market.outputTokenSupply = outputTokenSupply;
if (newVariableBorrowBalance) {
this.market.variableBorrowedTokenBalance = newVariableBorrowBalance;
}
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/aave-forks/src/sdk/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PositionSide } from "./constants";
* make changes to a given position.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down
9 changes: 8 additions & 1 deletion subgraphs/aave-forks/src/sdk/snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
* need to think about all of the detailed storage changes that occur.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down Expand Up @@ -456,6 +456,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyDepositUSD.plus(amountUSD);
this.financialSnapshot.dailyDepositUSD =
this.financialSnapshot.dailyDepositUSD.plus(amountUSD);
this.marketDailySnapshot.dailyDepositCount += INT_ONE;
this.usageDailySnapshot.dailyDepositCount += INT_ONE;
this.usageHourlySnapshot.hourlyDepositCount += INT_ONE;
} else if (transactionType == TransactionType.WITHDRAW) {
Expand All @@ -467,6 +468,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyWithdrawUSD.plus(amountUSD);
this.financialSnapshot.dailyWithdrawUSD =
this.financialSnapshot.dailyWithdrawUSD.plus(amountUSD);
this.marketDailySnapshot.dailyWithdrawCount += INT_ONE;
this.usageDailySnapshot.dailyWithdrawCount += INT_ONE;
this.usageHourlySnapshot.hourlyWithdrawCount += INT_ONE;
} else if (transactionType == TransactionType.BORROW) {
Expand All @@ -478,6 +480,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyBorrowUSD.plus(amountUSD);
this.financialSnapshot.dailyBorrowUSD =
this.financialSnapshot.dailyBorrowUSD.plus(amountUSD);
this.marketDailySnapshot.dailyBorrowCount += INT_ONE;
this.usageDailySnapshot.dailyBorrowCount += INT_ONE;
this.usageHourlySnapshot.hourlyBorrowCount += INT_ONE;
} else if (transactionType == TransactionType.REPAY) {
Expand All @@ -489,6 +492,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyRepayUSD.plus(amountUSD);
this.financialSnapshot.dailyRepayUSD =
this.financialSnapshot.dailyRepayUSD.plus(amountUSD);
this.marketDailySnapshot.dailyRepayCount += INT_ONE;
this.usageDailySnapshot.dailyRepayCount += INT_ONE;
this.usageHourlySnapshot.hourlyRepayCount += INT_ONE;
} else if (transactionType == TransactionType.LIQUIDATE) {
Expand All @@ -500,6 +504,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyLiquidateUSD.plus(amountUSD);
this.financialSnapshot.dailyLiquidateUSD =
this.financialSnapshot.dailyLiquidateUSD.plus(amountUSD);
this.marketDailySnapshot.dailyLiquidateCount += INT_ONE;
this.usageDailySnapshot.dailyLiquidateCount += INT_ONE;
this.usageHourlySnapshot.hourlyLiquidateCount += INT_ONE;
} else if (transactionType == TransactionType.TRANSFER) {
Expand All @@ -511,6 +516,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyTransferUSD.plus(amountUSD);
this.financialSnapshot.dailyTransferUSD =
this.financialSnapshot.dailyTransferUSD.plus(amountUSD);
this.marketDailySnapshot.dailyTransferCount += INT_ONE;
this.usageDailySnapshot.dailyTransferCount += INT_ONE;
} else if (transactionType == TransactionType.FLASHLOAN) {
this.marketDailySnapshot.dailyFlashloanUSD =
Expand All @@ -521,6 +527,7 @@ export class SnapshotManager {
this.marketHourlySnapshot.hourlyFlashloanUSD.plus(amountUSD);
this.financialSnapshot.dailyFlashloanUSD =
this.financialSnapshot.dailyFlashloanUSD.plus(amountUSD);
this.marketDailySnapshot.dailyFlashloanCount += INT_ONE;
this.usageDailySnapshot.dailyFlashloanCount += INT_ONE;
} else {
log.error("[updateTransactionData] Invalid transaction type: {}", [
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/aave-forks/src/sdk/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
* use in mappings and get info about the token.
*
* Schema Version: 3.1.1
* SDK Version: 1.0.7
* SDK Version: 1.0.8
* Author(s):
* - @melotik
* - @dhruv-chauhan
Expand Down

0 comments on commit f73e24d

Please sign in to comment.