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

Fix for TONCO invalidated positions tracking + price at the end #332

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion seasons/S7_defi_scores.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ TONCO is a CLMM DEX and every time user provides liquidity to the pool, new NFT
User can withdraw entire amount of liquidity at any time, when it is done, liquidity goes back to the user
and NFT marked as init=false. So to get all active liqudity positions by the user we are getting all NFTs
from collections owner by [router contract](https://tonviewer.com/EQC_-t0nCnOFMdp7E7qPxAOCbCWGFz-e3pwxb6tTvFmshjt5)
and init=true. Next we are extracting initial liquidity transfers during the NFT mint transaction chain
which have not been withdrawn by sending [POSITIONNFTV3_POSITION_BURN#46ca335a](https://docs.tonco.io/technical-reference/contracts/position_nft)
message. Next we are extracting initial liquidity transfers during the NFT mint transaction chain
and estimating that liquidity in USD based on the price of the assets at the time of the transaction.

### Farmix
Expand Down
9 changes: 7 additions & 2 deletions seasons/sql/s7_defi_tvl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ tonco_collections as (
), tonco_positions as (
-- get all NFT positions which is active now (init=true)
select address, owner_address from public.nft_items ni
where collection_address in (select * from tonco_collections) and init
where collection_address in (select * from tonco_collections) -- and init
-- since we have to track which positions have been withdrawn we will exclude all positions with
-- POSITIONNFTV3_POSITION_BURN#46ca335a message before the end of the season
and not exists (select from messages where direction ='in' and destination = ni.address
and created_at < 1734433200 and opcode = 1187656538 order by created_at desc limit 1)
), tonco_positions_first_tx as (
-- get first transaction for every NFT position. This tx will be a part of mint tx chain
-- to get the first transaction we will filter by end_status and orig_status and also filter
Expand All @@ -505,7 +509,8 @@ tonco_collections as (
-- for all other jettons let's get latest agg price just before the event
else (select price_usd from prices.agg_prices ap where
ap.base = jetton_master_address and
price_time < tx_now
-- estimate using the price and the end of the season
price_time < 1734433200
order by price_time desc limit 1)
end
) * amount / 1e6 as amount_usd from tonco_jetton_transfers
Expand Down
Loading