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

Fix bucket bankruptcy #66

Merged
merged 6 commits into from
Sep 11, 2023
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
7 changes: 3 additions & 4 deletions src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,10 @@ export function _handleBucketBankruptcy(event: ethereum.Event, index: BigInt, lp
bucketBankruptcy.transactionHash = event.transaction.hash

// update entities
const pool = Pool.load(addressToBytes(event.address))
if (pool != null) {
const pool = Pool.load(addressToBytes(event.address))!

// update pool state
log.info("_handleBucketBankruptcy updating pool {} for bankruptcy in bucket {}", [event.address.toHexString(), index.toString()])
updatePool(pool)

// update bucket state to zero out bucket contents
Expand Down Expand Up @@ -648,8 +649,6 @@ export function _handleBucketBankruptcy(event: ethereum.Event, index: BigInt, lp
// save entities to store
pool.save()
bucket.save()
}

bucketBankruptcy.save()
}

Expand Down
5 changes: 3 additions & 2 deletions src/utils/pool/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export function updateBucketLends(bucket: Bucket, lend: Lend): void {
// get current index of lend in bucket's list of lends
const index = lends.indexOf(lend.id)
if (lend.lpb != ZERO_BD && index == -1) {
bucket.lends = bucket.lends.concat([lend.id])
lends.push(lend.id)
} else if (lend.lpb == ZERO_BD && index != -1) {
bucket.lends.splice(index, 1)
lends.splice(index, 1)
}
bucket.lends = lends
}
6 changes: 6 additions & 0 deletions tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export class LendUpdatedParams {
lpbValueInQuote: BigInt
}
export function assertLendUpdate(params: LendUpdatedParams): void {
assert.fieldEquals(
"Lend",
`${params.id.toHexString()}`,
"poolAddress",
`${params.poolAddress}`
)
assert.fieldEquals(
"Lend",
`${params.id.toHexString()}`,
Expand Down