Skip to content

Commit

Permalink
remove stale approval lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Sep 19, 2023
1 parent 30bb3df commit d8289f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { incrementTokenTxCount as incrementTokenTxCountERC20Pool } from "../../u
import { incrementTokenTxCount as incrementTokenTxCountERC721Pool } from "../../utils/token-erc721"
import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../../utils/pool/reserve-auction"
import { saveOrRemovePositionLend } from "../../utils/position"
import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../../utils/pool/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors"
import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances, saveOrRemoveAllowances } from "../../utils/pool/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors, saveOrRemoveTranserors } from "../../utils/pool/lp-transferors"


/*******************************/
Expand Down Expand Up @@ -529,7 +529,7 @@ export function _handleDecreaseLPAllowance(event: ethereum.Event, owner: Address

// save entities to the store
pool.save()
lpAllowanceList.save()
saveOrRemoveAllowances(lpAllowanceList)
}

export function _handleIncreaseLPAllowance(event: ethereum.Event, owner: Address, spender: Address, indexes: BigInt[], amounts: BigInt[]): void {
Expand All @@ -547,28 +547,28 @@ export function _handleIncreaseLPAllowance(event: ethereum.Event, owner: Address

export function _handleRevokeLPAllowance(event: ethereum.Event, owner: Address, spender: Address, indexes: BigInt[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateAllowances(poolId, owner, spender)
revokeAllowances(entity, indexes)
const lpAllowanceList = loadOrCreateAllowances(poolId, owner, spender)
revokeAllowances(lpAllowanceList, indexes)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
saveOrRemoveAllowances(lpAllowanceList)
}

export function _handleRevokeLPTransferors(event: ethereum.Event, lender: Address, transferors: Address[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, lender)
revokeTransferors(entity, transferors)
const lpTransferorList = loadOrCreateTransferors(poolId, lender)
revokeTransferors(lpTransferorList, transferors)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
saveOrRemoveTranserors(lpTransferorList)
}

/**********************************/
Expand Down
16 changes: 16 additions & 0 deletions src/utils/pool/lp-allowances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,19 @@ export function revokeAllowances(entity: LPAllowanceList, indexes: Array<BigInt>
}
entity.allowances = entityAllowances
}

export function saveOrRemoveAllowances(entity: LPAllowanceList): void {
if (entity.allowances.length == 0) {
store.remove('LPAllowanceList', entity.id.toHexString())
} else {
entity.save()
}
}

export function saveOrRemoveTranserors(entity: LPTransferorList): void {
if (entity.transferors.length == 0) {
store.remove('LPTransferorList', entity.id.toHexString())
} else {
entity.save()
}
}
10 changes: 9 additions & 1 deletion src/utils/pool/lp-transferors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Bytes } from "@graphprotocol/graph-ts"
import { Address, Bytes, store } from "@graphprotocol/graph-ts"
import { LPTransferorList} from "../../../generated/schema";
import { addressToBytes } from "../convert";

Expand Down Expand Up @@ -40,3 +40,11 @@ export function revokeTransferors(entity: LPTransferorList, transferorsRevoked:
}
entity.transferors = entityTransferors
}

export function saveOrRemoveTranserors(entity: LPTransferorList): void {
if (entity.transferors.length == 0) {
store.remove('LPTransferorList', entity.id.toHexString())
} else {
entity.save()
}
}
17 changes: 2 additions & 15 deletions tests/erc-721-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,23 +1627,10 @@ describe("Describe entity assertions", () => {
/********************/

// check entities have been stored
assert.entityCount("LPTransferorList", 1)
assert.entityCount("LPTransferorList", 0)
assert.entityCount("LPAllowance", 0)
assert.entityCount("LPAllowanceList", 1)
assert.entityCount("LPAllowanceList", 0)
assert.entityCount("Pool", 2)

assert.fieldEquals(
"LPTransferorList",
`${lpTransferorListId.toHexString()}`,
"transferors",
"[]"
)
assert.fieldEquals(
"LPAllowanceList",
`${lpAllowanceListId.toHexString()}`,
"allowances",
"[]"
)
})

// TODO: finish implementing once a mergeOrRemoveCollateralNFT calldata becomes available
Expand Down

0 comments on commit d8289f0

Please sign in to comment.