mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
parent
1cfe520dad
commit
ccded4c4b1
@ -57,7 +57,10 @@ type Token @entity {
|
||||
tx: String!
|
||||
|
||||
"block number when it was created"
|
||||
block: Int!
|
||||
block: Int!
|
||||
|
||||
lastPriceToken: String!
|
||||
lastPriceValue: BigDecimal!
|
||||
}
|
||||
|
||||
"utility type"
|
||||
@ -261,6 +264,10 @@ type Order @entity {
|
||||
createdTimestamp: Int!
|
||||
tx: String!
|
||||
block: Int!
|
||||
|
||||
lastPriceToken: String!
|
||||
lastPriceValue: BigDecimal!
|
||||
estimatedUSDValue: BigDecimal!
|
||||
}
|
||||
|
||||
# to be removed, mabye for pool shares only
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
import { integer } from './utils/constants'
|
||||
import { weiToDecimal } from './utils/generic'
|
||||
import { addOrder } from './utils/globalUtils'
|
||||
import { getToken } from './utils/tokenUtils'
|
||||
import { getToken, getUSDValue } from './utils/tokenUtils'
|
||||
import { getUser } from './utils/userUtils'
|
||||
|
||||
function getOrderId(
|
||||
@ -63,7 +63,13 @@ export function handleOrderStarted(event: OrderStarted): void {
|
||||
order.createdTimestamp = event.block.timestamp.toI32()
|
||||
order.tx = event.transaction.hash.toHex()
|
||||
order.block = event.block.number.toI32()
|
||||
|
||||
order.lastPriceToken = token.lastPriceToken
|
||||
order.lastPriceValue = token.lastPriceValue
|
||||
order.estimatedUSDValue = getUSDValue(
|
||||
order.lastPriceToken,
|
||||
order.lastPriceValue,
|
||||
order.createdTimestamp
|
||||
)
|
||||
order.save()
|
||||
token.save()
|
||||
addOrder()
|
||||
|
@ -199,6 +199,15 @@ export function handleSwap(event: Swapped): void {
|
||||
event.params.tokenOutAddress.toHexString(),
|
||||
swap.baseTokenAmount
|
||||
)
|
||||
|
||||
// update datatoken lastPriceToken and lastPriceValue
|
||||
const datatoken = getToken(
|
||||
Address.fromString(fixedRateExchange.datatoken),
|
||||
true
|
||||
)
|
||||
datatoken.lastPriceToken = fixedRateExchange.baseToken
|
||||
datatoken.lastPriceValue = fixedRateExchange.price
|
||||
datatoken.save()
|
||||
}
|
||||
|
||||
export function handlePublishMarketFeeChanged(
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { BigInt } from '@graphprotocol/graph-ts'
|
||||
import { BigInt, Address } from '@graphprotocol/graph-ts'
|
||||
import {
|
||||
LOG_EXIT,
|
||||
LOG_JOIN,
|
||||
@ -177,6 +177,12 @@ export function handleSwap(event: LOG_SWAP): void {
|
||||
poolSnapshot.save()
|
||||
poolTx.save()
|
||||
pool.save()
|
||||
|
||||
// update datatoken lastPriceToken and lastPriceValue
|
||||
const datatoken = getToken(Address.fromString(pool.datatoken), true)
|
||||
datatoken.lastPriceToken = pool.baseToken
|
||||
datatoken.lastPriceValue = spotPrice
|
||||
datatoken.save()
|
||||
}
|
||||
|
||||
// setup is just to set token weight(it will mostly be 50:50) and spotPrice
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { Address, log } from '@graphprotocol/graph-ts'
|
||||
import { Address, log, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import { Nft, Token } from '../../@types/schema'
|
||||
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
|
||||
import { ERC20Template, ERC721Template } from '../../@types/templates'
|
||||
import { addNft } from './globalUtils'
|
||||
import { ZERO_ADDRESS } from './constants'
|
||||
|
||||
export function createToken(address: Address, isDatatoken: boolean): Token {
|
||||
log.debug('started creating token with address: {}', [address.toHexString()])
|
||||
@ -22,6 +23,8 @@ export function createToken(address: Address, isDatatoken: boolean): Token {
|
||||
const decimals = contract.try_decimals()
|
||||
if (decimals.reverted) token.decimals = 18
|
||||
else token.decimals = decimals.value
|
||||
token.lastPriceToken = ZERO_ADDRESS
|
||||
token.lastPriceValue = BigDecimal.zero()
|
||||
token.save()
|
||||
return token
|
||||
}
|
||||
@ -56,3 +59,11 @@ export function getNftToken(address: Address): Nft {
|
||||
}
|
||||
return newToken
|
||||
}
|
||||
|
||||
export function getUSDValue(
|
||||
address: string,
|
||||
value: BigDecimal,
|
||||
timestamp: number
|
||||
): BigDecimal {
|
||||
return BigDecimal.zero()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user