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

Subgraph Improvements #55

Merged
merged 25 commits into from
Aug 17, 2023
Merged

Subgraph Improvements #55

merged 25 commits into from
Aug 17, 2023

Conversation

MikeHathaway
Copy link
Contributor

@MikeHathaway MikeHathaway commented Aug 16, 2023

  • Finish implementing BucketBankruptcy event and expand test
  • Update Lend.depositTime
  • Record subset hash for collection and fungibile pools
  • Add test for ERC721Pool BucketTake
  • Add test for ERC721Pool TransferLP
  • Create _handleTransferLP to reduce complexity
  • Fix LPB tracking in handleTransferLP & MoveLiquidity
  • Remove unused event handlers from ERC20Pool and ERC721Pool 83326c8
  • add tracking of screening stage voting power in DistributionPeriodVote

@MikeHathaway MikeHathaway changed the title Additional 721 Improvements Subgraph Improvements Aug 16, 2023
@MikeHathaway MikeHathaway requested a review from EdNoepel August 16, 2023 04:20
@MikeHathaway MikeHathaway marked this pull request as ready for review August 16, 2023 04:20
@@ -151,6 +151,8 @@ type Bucket @entity {
deposit: BigDecimal!
# total LP for all lenders in the bucket
lpb: BigDecimal!
# list of lends associated with the bucket
lends: [Lend!]!
Copy link
Contributor Author

@MikeHathaway MikeHathaway Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a way to know all lends in a bucket whose LPB should be zeroed out on bankruptcy

Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible issue managing depositTime on moveQuoteToken operations.

@@ -220,8 +222,10 @@ export function _handleMoveQuoteToken(erc20Event: MoveQuoteTokenERC20Event | nul
// update to bucket lend state
const toBucketLendId = getLendId(toBucketId, lender)
const toBucketLend = loadOrCreateLend(toBucketId, toBucketLendId, pool.id, moveQuoteToken.lender)
toBucketLend.depositTime = getDepositTime(blockTimestamp, toBucketLend)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this will always set depositTime to blockTimestamp (toBucketLend could not have a greater time) rather than setting to the max of fromBucketLend.depositTime and toBucketLend.depositTime - see logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in: 039811a

tests/erc-20-pool.test.ts Show resolved Hide resolved
Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// add new lend
const newLend = loadOrCreateLend(bucketId, newLendId, pool.id, transferLP.newOwner)
// TODO: should we simply use lenderInfo.depositTime instead of getDepositTime?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're already calling it on line 438, it seems safer to take the value. But the logic on line 437 seems to jive with the contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove the getLenderInfo call for oldLend.lpb?

Copy link
Contributor Author

@MikeHathaway MikeHathaway Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use lenderInfo for depositTime in 5fd73b5

// Redeem - transfer from PositionManager to lender, creating the lender's Lend

// event does not reveal LP amounts transferred for each bucket, so query the pool and update
// remove old lend
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment says "remove old lend" but the old lends aren't currently being removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 431, updateAccountLends removes the lend if LPB is zero:

lends.splice(index, 1)
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the Lends are still in the store, even though they are no longer being associated with the Account

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed; we're not doing a store.remove anywhere, and probably should be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lends are attached to Accounts, Buckets, and Positions. Seems when LPB=0 they are removed from Accounts and Positions, but not Buckets. We'll need to fix that before doing a store.remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an additional updateBucketLends to _handleTransferLP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when someone redeems a position NFT, _handleTransferLP takes care of Account.lends and Bucket.lends, and handleRedeemPosition takes care of Position.indexes.

@MikeHathaway MikeHathaway merged commit 9b39b69 into develop Aug 17, 2023
@MikeHathaway MikeHathaway deleted the 721-and-debt branch August 17, 2023 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants