Skip to content

Commit

Permalink
refactor: only update cash in accrue interest
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 4, 2024
1 parent e27191f commit 4b6de03
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
29 changes: 0 additions & 29 deletions subgraphs/venus/src/mappings/vToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export function handleMint(event: Mint): void {
);

const market = getOrCreateMarket(marketAddress, event);
const vTokenContract = VToken.bind(marketAddress);

// we'll first update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);

// and finally we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.plus(event.params.mintTokens);
Expand All @@ -82,10 +78,6 @@ export function handleMintBehalf(event: MintBehalf): void {
);

const market = getOrCreateMarket(marketAddress, event);
const vTokenContract = VToken.bind(marketAddress);

// we'll first update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);

// and finally we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.plus(event.params.mintTokens);
Expand Down Expand Up @@ -120,10 +112,6 @@ export function handleRedeem(event: Redeem): void {
accountVToken.entity.save();

const market = getOrCreateMarket(marketAddress, event);
const vTokenContract = VToken.bind(marketAddress);

// we'll update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);

// and finally we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.minus(
Expand All @@ -145,11 +133,8 @@ export function handleRedeem(event: Redeem): void {
export function handleBorrow(event: Borrow): void {
const marketAddress = event.address;
const market = getOrCreateMarket(marketAddress, event);
const vTokenContract = VToken.bind(marketAddress);
market.totalBorrowsMantissa = event.params.totalBorrows;

// we'll update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);
market.save();

const account = getOrCreateAccount(event.params.borrower);
Expand Down Expand Up @@ -182,13 +167,9 @@ export function handleBorrow(event: Borrow): void {
export function handleRepayBorrow(event: RepayBorrow): void {
const marketAddress = event.address;
const market = getOrCreateMarket(marketAddress, event);
const vTokenContract = VToken.bind(marketAddress);

market.totalBorrowsMantissa = event.params.totalBorrows;

// we'll update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);

market.save();

const accountVToken = updateAccountVTokenBorrow(
Expand Down Expand Up @@ -330,9 +311,6 @@ export function handleMintV1(event: MintV1): void {
accountVToken.entity.vTokenBalanceMantissa.plus(event.params.mintTokens),
);
const market = getOrCreateMarket(event.address, event);
const vTokenContract = VToken.bind(marketAddress);
// we'll first update the cash value of the market and then the rates, since they depend on it
updateMarketCashMantissa(market, vTokenContract);

// finally we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.plus(event.params.mintTokens);
Expand All @@ -354,10 +332,6 @@ export function handleMintBehalfV1(event: MintBehalfV1): void {
accountVToken.entity.vTokenBalanceMantissa.plus(event.params.mintTokens),
);
const market = getOrCreateMarket(event.address, event);
const vTokenContract = VToken.bind(marketAddress);

// we'll first update the cash value of the market
updateMarketCashMantissa(market, vTokenContract);

// and then we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.plus(event.params.mintTokens);
Expand All @@ -370,9 +344,6 @@ export function handleMintBehalfV1(event: MintBehalfV1): void {
export function handleRedeemV1(event: RedeemV1): void {
const marketAddress = event.address;
const market = getOrCreateMarket(event.address, event);
const vTokenContract = VToken.bind(marketAddress);
// we'll first update the cash value of the market and then the rates, since they depend on it
updateMarketCashMantissa(market, vTokenContract);

// finally we update the market total supply
market.totalSupplyVTokenMantissa = market.totalSupplyVTokenMantissa.minus(
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/venus/tests/VToken/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe('VToken', () => {
assert.fieldEquals('Market', aaaTokenAddress.toHexString(), key, value);
};

assertMarketDocument('accrualBlockNumber', '999');
assertMarketDocument('accrualBlockNumber', '1');
assertMarketDocument('exchangeRateMantissa', '365045823500000000000000');
assertMarketDocument('borrowIndex', newBorrowIndex.toString());
assertMarketDocument('reservesMantissa', '5128000000000000000');
Expand Down

0 comments on commit 4b6de03

Please sign in to comment.