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

Schema updates #7

Merged
merged 19 commits into from
Apr 3, 2023
Merged

Schema updates #7

merged 19 commits into from
Apr 3, 2023

Conversation

EdNoepel
Copy link
Contributor

@EdNoepel EdNoepel commented Mar 30, 2023

Several changes, notably to Pool and LiquidationAuction entities. Bucket indicies changed from BigInt to Int. Event prices and amounts changed from BigInt to BigDecimal, consistent with other entities. Remove Lend entity from account when lender has no LP in bucket. Remove Loan entity from account when borrower has no debt.

Unit tests have only been updated to keep them running; no new coverage has been implemented.

@EdNoepel EdNoepel marked this pull request as ready for review March 30, 2023 18:23
@EdNoepel EdNoepel requested a review from MikeHathaway March 30, 2023 18:23
addQuoteToken.index = event.params.index.toU32()
addQuoteToken.amount = wadToDecimal(event.params.amount)
addQuoteToken.lpAwarded = wadToDecimal(event.params.lpAwarded)
addQuoteToken.lup = wadToDecimal(event.params.lup)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any case where we would want to access the raw integer data of the event instead of the parsed human friendly version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was on the fence about LP values. My goal was to make events consistent with non-event entities, and LPs were already BigDecimal there, so I ran with it.

Should we use BigInt for all LP values across both entity types?

Copy link
Contributor

@MikeHathaway MikeHathaway Mar 31, 2023

Choose a reason for hiding this comment

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

I think LPs should probably be handled similarly to the other accounting. I don't have a strong opinion on it one way or the other. Consistency sounds good, and the conversion accuracy seems high so happy with your approach.

}

// update the list of lends initiated by an account, if it hasn't been added already
export function updateAccountLends(account: Account, lend: Lend): void {
const lends = account.lends
// get current index of lend in account's list of lends
const index = lends.indexOf(lend.id)
if (index == -1) {
if (lend.lpb != ZERO_BD && index == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any use case for tracking the closed out lend / loan positions for historical analytics purposes? Thinking specifically about displaying a historical positions tab

Copy link
Contributor Author

@EdNoepel EdNoepel Mar 31, 2023

Choose a reason for hiding this comment

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

The use case of historical data for analytics should be handled by BlockAnalytica. Our subgraph should only endeavor to retain history in places where it is needed for our UI, particularly for liquidations and burn rewards. It's a shame TheGraph doesn't let you query state at a particular block height like Vulcanize did.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was under the impression that BlockAnalytica would be using this subgraph for their analytics dashboard?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I believe that you can query state at a particular block height: https://thegraph.com/docs/en/querying/graphql-api/#time-travel-queries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

51c184a makes some adjustments and documents this topic in the README. Will share this with BlockAnalytica once we agree upon it to ensure there are no concerns.

@@ -32,15 +32,19 @@ export function updateAccountPools(account: Account, pool: Pool): void {
if (index == -1) {
account.pools = account.pools.concat([pool.id])
}
// TODO: Determine whether account has any Lend or Loan in pool without O(n) iteration.
Copy link
Contributor

Choose a reason for hiding this comment

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

We could potentially use an ennumerable set for this - it might be a better way to track than raw filtering

src/erc-20-pool.ts Outdated Show resolved Hide resolved
tests/utils/common.ts Outdated Show resolved Hide resolved

settle.save()
}

export function handleTransferLPs(event: TransferLPsEvent): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to call out to a loadOrCreateLend for the new owner, as well as add an account entity for them.

Copy link
Contributor

@MikeHathaway MikeHathaway Mar 30, 2023

Choose a reason for hiding this comment

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

Also, do we want to increment the pool and token tx counts in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done in 67577d0. Note that I'm not using incrementTokenTxCount because this action has no bearing on collateral. Also not sure if it's really the quote token or the LP token whose TX count should be incremented. Happy to discuss further.

Copy link
Contributor

@MikeHathaway MikeHathaway Mar 31, 2023

Choose a reason for hiding this comment

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

Yeah, those are really good questions. It would potentially be both if there was quote and collateral in the bucket. Might be a heavy computational lift to calculate that info given a potential requirement for additional RPC calls. RPC calls seem to be the real limiting factor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, for now, should I just sprinkle incrementTokenTxCount for every lender operation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that's reasonable. It would reflect higher pool activity for that token

if (token == null) {
// create new account if account hasn't already been stored
token = new Token(id) as Token
token.name = getTokenName(tokenAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

These methods won't work for PositionManager ERC721 NFT's since they were intended only for ERC20.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 67577d0 I removed decimals and totalSupply, two methods which are not supported by ERC-721.

Copy link
Contributor

@MikeHathaway MikeHathaway Mar 31, 2023

Choose a reason for hiding this comment

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

That was an improvement, but getTokenName, and getTokenSymbol are both binding to the ERC20 contract, which may result in unexpected behavior. We should add an ERC721 contract and abi under the ERC721 pool factory and create methods binding to those. May be out of scope though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the ERC-721 pool is out-of-scope for this PR, It makes sense to add the ABI now to fix this. Done in 64bed6f.

@@ -186,6 +190,24 @@ export function updatePoolLiquidationAuctions(pool: Pool, liquidationAuction: Li
}
}

// if present, remove a settled liquidation from the pool's collection of active liquidations
export function removeLiquidationFromPool(pool: Pool, liquidationAuction: LiquidationAuction): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar question about leaving dead entities in storage for historical analytics purposes. Also, should this be splice instead of slice?

Copy link
Contributor Author

@EdNoepel EdNoepel Mar 31, 2023

Choose a reason for hiding this comment

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

Good catch on the splice vs slice; fixed in 67577d0.

Although we generally don't want to persist dead entities in our subgraph, there are use cases for storing historical liquidations, particularly for the UI. I am considering a separate collection in the schema for these.
Added this to the next epic for discussion.

Copy link
Contributor

@MikeHathaway MikeHathaway left a comment

Choose a reason for hiding this comment

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

Generally looks great! Just had a few questions and comments

src/erc-20-pool.ts Outdated Show resolved Hide resolved
@EdNoepel EdNoepel requested a review from MikeHathaway March 31, 2023 16:24
@EdNoepel
Copy link
Contributor Author

@MikeHathaway I addressed many of the concerns. Happy to continue discussion about the others.

@MikeHathaway
Copy link
Contributor

Big picture, should we also handle Grant Fund as part of this subgraph as opposed to a separate repository?

@EdNoepel
Copy link
Contributor Author

EdNoepel commented Apr 3, 2023

Big picture, should we also handle Grant Fund as part of this subgraph as opposed to a separate repository?

I would prefer this repo cover the whole protocol, but I am not ready to commit to that decision.

Copy link
Contributor

@MikeHathaway MikeHathaway left a comment

Choose a reason for hiding this comment

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

LGTM

@EdNoepel EdNoepel merged commit c32806e into develop Apr 3, 2023
@EdNoepel EdNoepel deleted the 2418 branch April 3, 2023 20:26
@MikeHathaway
Copy link
Contributor

MikeHathaway commented Apr 3, 2023

Big picture, should we also handle Grant Fund as part of this subgraph as opposed to a separate repository?

I would prefer this repo cover the whole protocol, but I am not ready to commit to that decision.

I agree. I had added a paragraph in the README to the contrary that we might want to remove while a decision is pending.* Moved this here as I had added that text. Thanks for the README change.

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