There are different tiers (10k, 100k, 1mil... 100bil)
To achieve a tier, the amount * days needs to equal or exceed the tier number
There are a limited number of NFTs per tier
[If someone upgrades their NFT, a slot opens up at the lower tier on a first come / first serve basis]
How to do this:
On the UI side
we want to display the image
below the image a counter to the next upgrade
the counter turns into a button if the user can upgrade
the button is disabled if there are no free slots
We also need a good page that explains all of this
On craptastic API
Run a cron job that queries for all open positions
add their current debt balance to a counter
record their current debt balance
we store this in git state
Craptastic details
[x] Like in the liquidation bot, query for updated positions
[x] For each of them, get the viewPositionMetadata, which should contain the underlying asset (token address) as well as the debt of that position
[x] check in our JSON record (same type as in old updated positions script, but with cumulativeDebt field) if that position already exists
[x] If the position already exists AND the current debt is lower than what we recorded in the JSON record, query the NFT metadata from our API to see if this NFT has a tier and if so, do SOMETHING to demote it.
[x] Then update the currentDebt field in our record
[ ] AFTER checking all the updated positions, iterate over all the records in the JSON thing and add the currentDebt / howOftenWeCallThisInADay to the cumulativeDebt -- Let's say we call it every 3 hours, that would mean: cumulativeDebt += currentDebt * 3 / 24
[x] Store the JSON record back to GIT
On cloudfunction API
We need to keep a counter per token, per tier
If a user wants to upgrade, we check if there are any free slots, if there are free slots we generate the image
Cloudfunction API details
[x] Create a JSON file with counters (one counter for each tier)
[x] When a user wants to generate an NFT image:
[x] Load the cumulative positions file from the craptastic API
[x] If it already exists, load the position NFT metadata file
[x] Look up in the metadata file which tier this position already is in (if any)
[x] In the cumulative positions file, check what the cumulativeDebt of this position is
[x] Add to that cumulativeDebt according to this formula cumulativeDebt += (now - craptasticApiLastUpdated) * positionDebt / 24hours
[ ] Find the largest tier which smaller than the cumulativeDebt amount (i.e. if cumulativeDebt = 140k -> the closest tier is 100k)
[x] If that tier is bigger than the tier that this position already holds, we generate a new image IF the counter for that tier is no greater than 1000
[x] Query craptastic API in order to get the cumulativeDebt of current position (assume 0 if there is no record)
[x] Calculate when a user can upgrade according to this formula: daysUntilUpgrade = (nextTarget - cumulativeDebt) / debtOfPosition
[x] If users don't have an NFT, set a generic image, at the bottom of that image we will have a countdown timer (setInterval) until the next time available to upgrade
[x] if the user can upgrade, then we replace the countdown timer with the button to upgrade the NFT
Current concept:
How to do this:
On the UI side
On craptastic API
Craptastic details
viewPositionMetadata
, which should contain the underlying asset (token address) as well as the debt of that positioncumulativeDebt
field) if that position already existscumulativeDebt += currentDebt * 3 / 24
On cloudfunction API
Cloudfunction API details
cumulativeDebt += (now - craptasticApiLastUpdated) * positionDebt / 24hours
On the contracts