Skip to content

Commit

Permalink
Merge pull request #332 from ton-society/hotifx/tonco_fixes
Browse files Browse the repository at this point in the history
Fix for TONCO invalidated positions tracking + price at the end
  • Loading branch information
shuva10v authored Dec 18, 2024
2 parents 3d55ba6 + a7caf89 commit 1a385e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 1a385e2

Please sign in to comment.