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!
|
tx: String!
|
||||||
|
|
||||||
"block number when it was created"
|
"block number when it was created"
|
||||||
block: Int!
|
block: Int!
|
||||||
|
|
||||||
|
lastPriceToken: String!
|
||||||
|
lastPriceValue: BigDecimal!
|
||||||
}
|
}
|
||||||
|
|
||||||
"utility type"
|
"utility type"
|
||||||
@ -261,6 +264,10 @@ type Order @entity {
|
|||||||
createdTimestamp: Int!
|
createdTimestamp: Int!
|
||||||
tx: String!
|
tx: String!
|
||||||
block: Int!
|
block: Int!
|
||||||
|
|
||||||
|
lastPriceToken: String!
|
||||||
|
lastPriceValue: BigDecimal!
|
||||||
|
estimatedUSDValue: BigDecimal!
|
||||||
}
|
}
|
||||||
|
|
||||||
# to be removed, mabye for pool shares only
|
# to be removed, mabye for pool shares only
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
import { integer } from './utils/constants'
|
import { integer } from './utils/constants'
|
||||||
import { weiToDecimal } from './utils/generic'
|
import { weiToDecimal } from './utils/generic'
|
||||||
import { addOrder } from './utils/globalUtils'
|
import { addOrder } from './utils/globalUtils'
|
||||||
import { getToken } from './utils/tokenUtils'
|
import { getToken, getUSDValue } from './utils/tokenUtils'
|
||||||
import { getUser } from './utils/userUtils'
|
import { getUser } from './utils/userUtils'
|
||||||
|
|
||||||
function getOrderId(
|
function getOrderId(
|
||||||
@ -63,7 +63,13 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||||||
order.createdTimestamp = event.block.timestamp.toI32()
|
order.createdTimestamp = event.block.timestamp.toI32()
|
||||||
order.tx = event.transaction.hash.toHex()
|
order.tx = event.transaction.hash.toHex()
|
||||||
order.block = event.block.number.toI32()
|
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()
|
order.save()
|
||||||
token.save()
|
token.save()
|
||||||
addOrder()
|
addOrder()
|
||||||
|
@ -199,6 +199,15 @@ export function handleSwap(event: Swapped): void {
|
|||||||
event.params.tokenOutAddress.toHexString(),
|
event.params.tokenOutAddress.toHexString(),
|
||||||
swap.baseTokenAmount
|
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(
|
export function handlePublishMarketFeeChanged(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BigInt } from '@graphprotocol/graph-ts'
|
import { BigInt, Address } from '@graphprotocol/graph-ts'
|
||||||
import {
|
import {
|
||||||
LOG_EXIT,
|
LOG_EXIT,
|
||||||
LOG_JOIN,
|
LOG_JOIN,
|
||||||
@ -177,6 +177,12 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||||||
poolSnapshot.save()
|
poolSnapshot.save()
|
||||||
poolTx.save()
|
poolTx.save()
|
||||||
pool.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
|
// 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 { Nft, Token } from '../../@types/schema'
|
||||||
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
|
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
|
||||||
import { ERC20Template, ERC721Template } from '../../@types/templates'
|
import { ERC20Template, ERC721Template } from '../../@types/templates'
|
||||||
import { addNft } from './globalUtils'
|
import { addNft } from './globalUtils'
|
||||||
|
import { ZERO_ADDRESS } from './constants'
|
||||||
|
|
||||||
export function createToken(address: Address, isDatatoken: boolean): Token {
|
export function createToken(address: Address, isDatatoken: boolean): Token {
|
||||||
log.debug('started creating token with address: {}', [address.toHexString()])
|
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()
|
const decimals = contract.try_decimals()
|
||||||
if (decimals.reverted) token.decimals = 18
|
if (decimals.reverted) token.decimals = 18
|
||||||
else token.decimals = decimals.value
|
else token.decimals = decimals.value
|
||||||
|
token.lastPriceToken = ZERO_ADDRESS
|
||||||
|
token.lastPriceValue = BigDecimal.zero()
|
||||||
token.save()
|
token.save()
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
@ -56,3 +59,11 @@ export function getNftToken(address: Address): Nft {
|
|||||||
}
|
}
|
||||||
return newToken
|
return newToken
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUSDValue(
|
||||||
|
address: string,
|
||||||
|
value: BigDecimal,
|
||||||
|
timestamp: number
|
||||||
|
): BigDecimal {
|
||||||
|
return BigDecimal.zero()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user