-
Notifications
You must be signed in to change notification settings - Fork 4
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
update Position schema; add PositionLend entity #62
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two concerns noted regarding mutating copies of collections.
src/mappings/position-manager.ts
Outdated
} | ||
const positionLend = loadOrCreatePositionLend(redeem.tokenId, bucketId, index) | ||
positionLend.lpb = ZERO_BD | ||
positionLend.lpbValueInQuote = ZERO_BD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unnecessary to mutate anything besides lpb
, because the entity will be removed from the store.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
src/mappings/base/base-pool.ts
Outdated
for (let i = 0; i < bucket.positionLends.length; i++) { | ||
const positionLendId = bucket.positionLends[i] | ||
const positionLend = PositionLend.load(positionLendId)! | ||
positionLend.depositTime = bucketBankruptcy.blockTimestamp.plus(ONE_BI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we would update anything aside from positionLend.lpb
here. By setting lpb
to 0, saveOrRemovePositionLend
should always call store.remove
, so these mutations would never be persisted. Regardless, advancing depositTime
doesn't seem appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove those updates. The depositTime
advancing matches the contract logic
src/mappings/position-manager.ts
Outdated
// remove position from old account | ||
const oldOwnerAccount = loadOrCreateAccount(transfer.from) | ||
const index = oldOwnerAccount.positions.indexOf(bigIntToBytes(transfer.tokenId)) | ||
if (index != -1) oldOwnerAccount.positions.splice(index, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not going to work. When we call entity.collection, it returns a copy of the collection. Mutations on this collection will not persist when save is called on line 296.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, and also updated in handleBurn
.
src/utils/position.ts
Outdated
const bucket = Bucket.load(positionLend.bucket)! | ||
const existingBucketIndex = bucket.positionLends.indexOf(positionLend.id) | ||
if (existingBucketIndex != -1) { | ||
bucket.positionLends.splice(existingBucketIndex, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and line 104 mutate a copy of the collection, and will not effect the entity, even when the caller calls .save
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; thank you!
PositionLend
entity and associate withPosition
andBucket
in many-to-one relationship.Position
andAccount
entitiestokenURI
attribute toPosition
entitylpb
andlpbValueInQuote
for eachPositionLend
associated with aPosition
by callinggetPositionInfo
MoveLiquidity
and removeLend
update logic as this is already handled in the associatedMoveQuoteToken
eventMoveLiquidity
test