Skip to content

Commit

Permalink
fix: add explicit saves
Browse files Browse the repository at this point in the history
  • Loading branch information
hieronx committed Jun 11, 2024
1 parent 6703ef3 commit 111534a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/mappings/handlers/loansHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ async function _handleLoanBorrowed(event: SubstrateEvent<LoanBorrowedEvent>): Pr

if (borrowAmount.isExternal) {
// Prices were based on the settlement prices only until spec version 1025
if (specVersion < 1025) await asset.updateCurrentPrice(borrowAmount.asExternal.settlementPrice.toBigInt())
if (specVersion < 1025) {
await asset.updateCurrentPrice(borrowAmount.asExternal.settlementPrice.toBigInt())
await asset.save()
}

await asset.increaseQuantity(borrowAmount.asExternal.quantity.toBigInt())
await AssetPositionService.buy(
Expand Down Expand Up @@ -225,7 +228,10 @@ async function _handleLoanRepaid(event: SubstrateEvent<LoanRepaidEvent>) {
const { quantity, settlementPrice } = principal.asExternal

// Prices were based on the settlement prices only until spec version 1025
if (specVersion < 1025) await asset.updateCurrentPrice(settlementPrice.toBigInt())
if (specVersion < 1025) {
await asset.updateCurrentPrice(settlementPrice.toBigInt())
await asset.save()
}

await asset.decreaseQuantity(quantity.toBigInt())
realizedProfitFifo = await AssetPositionService.sellFifo(
Expand Down Expand Up @@ -346,7 +352,10 @@ async function _handleLoanDebtTransferred(event: SubstrateEvent<LoanDebtTransfer
const { quantity, settlementPrice } = _repaidAmount.principal.asExternal

// Prices were based on the settlement prices only until spec version 1025
if (specVersion < 1025) await fromAsset.updateCurrentPrice(settlementPrice.toBigInt())
if (specVersion < 1025) {
await fromAsset.updateCurrentPrice(settlementPrice.toBigInt())
await fromAsset.save()
}

await fromAsset.decreaseQuantity(quantity.toBigInt())
realizedProfitFifo = await AssetPositionService.sellFifo(
Expand Down Expand Up @@ -392,7 +401,10 @@ async function _handleLoanDebtTransferred(event: SubstrateEvent<LoanDebtTransfer
const { quantity, settlementPrice } = _borrowAmount.asExternal

// Prices were based on the settlement prices only until spec version 1025
if (specVersion < 1025) await toAsset.updateCurrentPrice(settlementPrice.toBigInt())
if (specVersion < 1025) {
await toAsset.updateCurrentPrice(settlementPrice.toBigInt())
await toAsset.save()
}

await toAsset.increaseQuantity(quantity.toBigInt())
await AssetPositionService.buy(
Expand Down

0 comments on commit 111534a

Please sign in to comment.