Skip to content

Commit

Permalink
capture total locked value and keep it up to date with pool updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssallam committed Jan 14, 2021
1 parent ecb9e8b commit 083dfe6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type PoolFactory @entity {
id: ID!

totalLockedValue: BigDecimal # total value from all pools expressed in OCEAN
totalLiquidity: BigDecimal! # All the pools liquidity value in Ocean
totalSwapVolume: BigDecimal! # All the swap volume in Ocean
totalSwapFee: BigDecimal! # All the swap fee in Ocean
Expand Down Expand Up @@ -28,6 +29,7 @@ type Pool @entity {
totalSwapVolume: BigDecimal! # Total swap volume in OCEAN
totalSwapFee: BigDecimal! # Total swap fee in OCEAN

lockedValue: BigDecimal! # locked value expressed in OCEAN (captures both Ocean and Datatoken)
datatokenReserve: BigDecimal! # Total pool reserve of Datatoken
oceanReserve: BigDecimal! # Total pool reserve of OCEAN
spotPrice: BigDecimal!
Expand Down
5 changes: 5 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,15 @@ export function createPoolTransaction(

pool.consumePrice = poolTx.consumePrice
pool.spotPrice = poolTx.spotPrice
const lockedValue = pool.lockedValue
pool.lockedValue = pool.oceanReserve + (pool.datatokenReserve * pool.spotPrice)
let factory = PoolFactory.load('1')
factory.totalLockedValue = factory.totalLockedValue - lockedValue + pool.lockedValue

pool.transactionCount = pool.transactionCount.plus(BigInt.fromI32(1))

pool.save()
factory.save()

debuglog(
'updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function handleNewPool(event: BPoolRegistered): void {
factory.totalLiquidity = ZERO_BD
factory.totalSwapVolume = ZERO_BD
factory.totalSwapFee = ZERO_BD
factory.totalLockedValue = ZERO_BD

factory.poolCount = 0
factory.finalizedPoolCount = 0
Expand All @@ -36,6 +37,7 @@ export function handleNewPool(event: BPoolRegistered): void {
pool.totalShares = ZERO_BD
pool.totalSwapVolume = ZERO_BD
pool.totalSwapFee = ZERO_BD
pool.lockedValue = ZERO_BD

pool.datatokenReserve = ZERO_BD
pool.oceanReserve = ZERO_BD
Expand Down

0 comments on commit 083dfe6

Please sign in to comment.