Skip to content

Commit 4d349ef

Browse files
authored
feat: Update TVL query scripts for Fixes World. (DefiLlama#12904)
1 parent 38ac20e commit 4d349ef

File tree

3 files changed

+10
-145
lines changed

3 files changed

+10
-145
lines changed

projects/fixes-coins/index.js

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,11 @@
22
const { callCadence } = require("../helper/chain/flow");
33

44
let queryTVLCode = `
5-
import LiquidStaking from 0xd6f80565193ad727
6-
import stFlowToken from 0xd6f80565193ad727
7-
// Fixes Imports
8-
import FRC20AccountsPool from 0xd2abb5dbf5e08666
9-
import FixesFungibleTokenInterface from 0xd2abb5dbf5e08666
10-
import FixesTokenLockDrops from 0xd2abb5dbf5e08666
11-
import FixesTradablePool from 0xd2abb5dbf5e08666
12-
import FRC20Indexer from 0xd2abb5dbf5e08666
5+
import FixesTVL from 0xd2abb5dbf5e08666
136
147
access(all)
158
fun main(): UFix64 {
16-
// singleton resource and constants
17-
let acctsPool = FRC20AccountsPool.borrowAccountsPool()
18-
let frc20Indexer = FRC20Indexer.getIndexer()
19-
let stFlowTokenKey = "@".concat(Type<@stFlowToken.Vault>().identifier)
20-
21-
// dictionary of addresses
22-
let addrsDict = acctsPool.getAddresses(type: FRC20AccountsPool.ChildAccountType.FungibleToken)
23-
// dictionary of tickers and total locked token balances
24-
let tickerTotal: {String: UFix64} = {}
25-
// This is the soft burned LP value which is fully locked in the BlackHole Vault
26-
var flowLockedInBondingCurve = 0.0
27-
addrsDict.forEachKey(fun (key: String): Bool {
28-
if let addr = addrsDict[key] {
29-
// sum up all locked token balances in LockDrops Pool
30-
if let dropsPool = FixesTokenLockDrops.borrowDropsPool(addr) {
31-
let lockedTokenSymbol = dropsPool.getLockingTokenTicker()
32-
tickerTotal[lockedTokenSymbol] = (tickerTotal[lockedTokenSymbol] ?? 0.0) + dropsPool.getTotalLockedTokenBalance()
33-
}
34-
// sum up all burned LP value in Tradable Pool
35-
if let tradablePool = FixesTradablePool.borrowTradablePool(addr) {
36-
flowLockedInBondingCurve = flowLockedInBondingCurve + tradablePool.getFlowBalanceInPool()
37-
}
38-
}
39-
return true
40-
})
41-
// sum up all locked token balances in LockDrops Pool
42-
var totalLockingTokenTVL = 0.0
43-
tickerTotal.forEachKey(fun (key: String): Bool {
44-
let lockedAmount = tickerTotal[key]!
45-
if key == "" {
46-
// this is locked FLOW
47-
totalLockingTokenTVL = totalLockingTokenTVL + lockedAmount
48-
} else if key == "fixes" {
49-
// this is locked FIXES
50-
let price = frc20Indexer.getBenchmarkValue(tick: "fixes")
51-
totalLockingTokenTVL = totalLockingTokenTVL + lockedAmount * price
52-
} else if key == stFlowTokenKey {
53-
// this is locked stFlow
54-
totalLockingTokenTVL = totalLockingTokenTVL + LiquidStaking.calcFlowFromStFlow(stFlowAmount: lockedAmount)
55-
}
56-
return true
57-
})
58-
return totalLockingTokenTVL + flowLockedInBondingCurve
9+
return FixesTVL.getAllLockedCoinFlowValue()
5910
}
6011
`;
6112

@@ -64,7 +15,7 @@ async function tvl() {
6415
const flowTokenTVL = await callCadence(queryTVLCode, true);
6516
return { flow: flowTokenTVL };
6617
} catch (error) {
67-
throw new Error("Couln't query scripts of Fixes coins", error);
18+
throw new Error("Couln't query scripts of Fixes coins. Error: " + error.message);
6819
}
6920
}
7021

projects/fixes-frc20-staking/index.js

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,11 @@
22
const { callCadence } = require("../helper/chain/flow");
33

44
let queryTVLCode = `
5-
import FRC20Staking from 0xd2abb5dbf5e08666
6-
import FRC20AccountsPool from 0xd2abb5dbf5e08666
7-
import FRC20Marketplace from 0xd2abb5dbf5e08666
8-
import FRC20Storefront from 0xd2abb5dbf5e08666
9-
import FRC20Indexer from 0xd2abb5dbf5e08666
5+
import FixesTVL from 0xd2abb5dbf5e08666
106
117
access(all)
128
fun main(): UFix64 {
13-
let acctsPool = FRC20AccountsPool.borrowAccountsPool()
14-
let stakingTokens = acctsPool.getAddresses(type: FRC20AccountsPool.ChildAccountType.Staking)
15-
16-
var totalTVL = 0.0
17-
let ticks = stakingTokens.keys
18-
19-
for tick in ticks {
20-
let stakingAddr = stakingTokens[tick]!
21-
let stakingPool = FRC20Staking.borrowPool(stakingAddr)
22-
if stakingPool == nil {
23-
continue
24-
}
25-
26-
let indexer = FRC20Indexer.getIndexer()
27-
// calculate floor price
28-
let benchmarkPrice = indexer.getBenchmarkValue(tick: tick)
29-
var floorPrice = benchmarkPrice
30-
31-
if let marketAddr = acctsPool.getFRC20MarketAddress(tick: tick) {
32-
if let market = FRC20Marketplace.borrowMarket(marketAddr) {
33-
let buyPriceRanks = market.getPriceRanks(type: FRC20Storefront.ListingType.FixedPriceBuyNow)
34-
if buyPriceRanks.length > 0 {
35-
var i = 0
36-
let floorPriceRank = buyPriceRanks[i]
37-
let listIds = market.getListedIds(type: FRC20Storefront.ListingType.FixedPriceBuyNow, rank: floorPriceRank)
38-
if listIds.length > 0 {
39-
if let listing = market.getListedItem(
40-
type: FRC20Storefront.ListingType.FixedPriceBuyNow,
41-
rank: floorPriceRank,
42-
id: listIds[0]
43-
) {
44-
if let details = listing.getDetails() {
45-
floorPrice = details.pricePerToken()
46-
}
47-
}
48-
}
49-
}
50-
}
51-
} // end if
52-
53-
var details = stakingPool!.getDetails()
54-
let validStaked = details.totalStaked - details.totalUnstakingLocked
55-
56-
totalTVL = totalTVL + (validStaked * (floorPrice - benchmarkPrice))
57-
}
58-
return totalTVL
9+
return FixesTVL.getAllStakedFlowValue()
5910
}
6011
`;
6112

@@ -64,9 +15,9 @@ async function tvl() {
6415
const flowTokenTVL = await callCadence(queryTVLCode, true);
6516
return { flow: flowTokenTVL };
6617
} catch (error) {
18+
console.error(error.message);
6719
throw new Error(
68-
"Couln't query scripts of fixes 𝔉rc20 treasury pool",
69-
error
20+
"Couln't query scripts of fixes 𝔉rc20 treasury pool. Error: " + error.message
7021
);
7122
}
7223
}

projects/fixes-frc20/index.js

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,11 @@
22
const { callCadence } = require("../helper/chain/flow");
33

44
let queryTVLCode = `
5-
import FRC20Indexer from 0xd2abb5dbf5e08666
6-
import FGameLottery from 0xd2abb5dbf5e08666
7-
import FGameLotteryRegistry from 0xd2abb5dbf5e08666
8-
import FGameLotteryFactory from 0xd2abb5dbf5e08666
9-
import FRC20FTShared from 0xd2abb5dbf5e08666
10-
import FRC20Staking from 0xd2abb5dbf5e08666
11-
import FRC20AccountsPool from 0xd2abb5dbf5e08666
5+
import FixesTVL from 0xd2abb5dbf5e08666
126
137
access(all)
148
fun main(): UFix64 {
15-
let indexer = FRC20Indexer.getIndexer()
16-
let tokens = indexer.getTokens()
17-
var totalBalance = 0.0
18-
// all treasury pool balance
19-
for tick in tokens {
20-
let balance = indexer.getPoolBalance(tick: tick)
21-
totalBalance = totalBalance + balance
22-
}
23-
24-
// FLOW lottery jackpot balance
25-
let registry = FGameLotteryRegistry.borrowRegistry()
26-
let flowLotteryPoolName = FGameLotteryFactory.getFIXESMintingLotteryPoolName()
27-
if let poolAddr = registry.getLotteryPoolAddress(flowLotteryPoolName) {
28-
if let poolRef = FGameLottery.borrowLotteryPool(poolAddr) {
29-
let jackpotBalance = poolRef.getJackpotPoolBalance()
30-
totalBalance = totalBalance + jackpotBalance
31-
}
32-
}
33-
34-
// Unclaimed FLOW Reward in the staking reward pool
35-
let acctsPool = FRC20AccountsPool.borrowAccountsPool()
36-
let platformStakingTick = FRC20FTShared.getPlatformStakingTickerName()
37-
if let stakingPoolAddr = acctsPool.getFRC20StakingAddress(tick: platformStakingTick) {
38-
if let stakingPool = FRC20Staking.borrowPool(stakingPoolAddr) {
39-
if let detail = stakingPool.getRewardDetails("") {
40-
totalBalance = totalBalance + detail.totalReward
41-
}
42-
}
43-
}
44-
45-
return totalBalance
9+
return FixesTVL.getAllTreasuryFlowValue()
4610
}
4711
`;
4812

@@ -52,8 +16,7 @@ async function tvl() {
5216
return { flow: flowTokenTVL };
5317
} catch (error) {
5418
throw new Error(
55-
"Couln't query scripts of fixes 𝔉rc20 treasury pool",
56-
error
19+
"Couln't query scripts of fixes 𝔉rc20 treasury pool. Error: " + error.message
5720
);
5821
}
5922
}

0 commit comments

Comments
 (0)