Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lastPriceToken #567

Merged
merged 3 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
@@ -1,7 +1,7 @@
version: '3'
services:
graph-node:
image: graphprotocol/graph-node:v0.26.0
image: graphprotocol/graph-node:v0.27.0
ports:
- '9000:8000'
- '8001:8001'
Expand All @@ -17,7 +17,7 @@ services:
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'rinkeby:https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}'
ethereum: 'goerli:https://goerli.infura.io/v3/${INFURA_PROJECT_ID}'
RUST_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.4.23
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -26,10 +26,12 @@
"test": "npm run codegen && npm run lint && npm run type-check",
"test-integration": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
"test-dispenser": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Dispenser.test.ts'",
"test-simple": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/SimplePublishConsume.test.ts'",
"test-fixed": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/FixedRateExchange.test.ts'",
"test-users": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/users.test.ts'",
"test-ve": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/VeOcean.test.ts'",
"test-df": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/DFRewards.test.ts'",
"test-dt": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Datatoken.test.ts'",
"test-zend": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/ZEnding.test.ts'",
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
"lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix",
Expand Down
4 changes: 2 additions & 2 deletions schema.graphql
Expand Up @@ -56,7 +56,7 @@ type Token @entity {
"block number when it was created"
block: Int!

lastPriceToken: String!
lastPriceToken: Token
lastPriceValue: BigDecimal!
}

Expand Down Expand Up @@ -167,7 +167,7 @@ type Order @entity {
tx: String!
block: Int!

lastPriceToken: String!
lastPriceToken: Token
lastPriceValue: BigDecimal!
estimatedUSDValue: BigDecimal!
gasUsed: BigDecimal
Expand Down
21 changes: 13 additions & 8 deletions src/mappings/erc20Templates.ts
@@ -1,5 +1,5 @@
import { Order, Nft, OrderReuse } from '../@types/schema'
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
import { BigInt, BigDecimal, Address } from '@graphprotocol/graph-ts'

import {
NewPaymentCollector,
Expand Down Expand Up @@ -59,13 +59,18 @@ 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
)
const tokenId = token.lastPriceToken
if (tokenId) {
const priceToken = getToken(Address.fromString(tokenId), false)
order.lastPriceToken = priceToken.id
order.lastPriceValue = token.lastPriceValue
order.estimatedUSDValue = getUSDValue(
priceToken.id,
order.lastPriceValue,
order.createdTimestamp
)
}

if (event.receipt !== null && event.receipt!.gasUsed) {
order.gasUsed = event.receipt!.gasUsed.toBigDecimal()
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/mappings/fixedRateExchange.ts
Expand Up @@ -206,7 +206,11 @@ export function handleSwap(event: Swapped): void {
Address.fromString(fixedRateExchange.datatoken),
true
)
datatoken.lastPriceToken = fixedRateExchange.baseToken
const priceToken = getToken(
Address.fromString(fixedRateExchange.baseToken),
false
)
datatoken.lastPriceToken = priceToken.id
datatoken.lastPriceValue = fixedRateExchange.price
datatoken.save()
}
Expand Down
13 changes: 2 additions & 11 deletions test/integration/Datatoken.test.ts
Expand Up @@ -162,7 +162,6 @@ describe('Datatoken tests', async () => {
createdTimestamp,
tx,
block,
lastPriceToken,
lastPriceValue
}}`
}
Expand Down Expand Up @@ -214,10 +213,6 @@ describe('Datatoken tests', async () => {
assert(tx.blockNumber >= blockNumber, 'incorrect value for: tx')
assert(dt.block >= blockNumber, 'incorrect value for: block')
assert(dt.block < blockNumber + 50, 'incorrect value for: block')
assert(
dt.lastPriceToken === '0x0000000000000000000000000000000000000000',
'incorrect value for: lastPriceToken'
)
assert(dt.lastPriceValue === '0', 'incorrect value for: lastPriceValue')
})

Expand Down Expand Up @@ -275,7 +270,6 @@ describe('Datatoken tests', async () => {
createdTimestamp,
tx,
block,
lastPriceToken,
lastPriceValue
}}`
}
Expand Down Expand Up @@ -326,10 +320,6 @@ describe('Datatoken tests', async () => {
assert(tx.blockNumber >= blockNumber, 'incorrect value for: tx')
assert(dt.block >= blockNumber, 'incorrect value for: block')
assert(dt.block < blockNumber + 50, 'incorrect value for: block')
assert(
dt.lastPriceToken === '0x0000000000000000000000000000000000000000',
'incorrect value for: lastPriceToken'
)
assert(dt.lastPriceValue === '0', 'incorrect value for: lastPriceValue')
})

Expand Down Expand Up @@ -368,7 +358,7 @@ describe('Datatoken tests', async () => {
assert(Number(user2balance) === 0, 'Invalid user2 balance')

const query = {
query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id}}}`
query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id, lastPriceToken{id}}}}`
}

await sleep(2000)
Expand Down Expand Up @@ -428,5 +418,6 @@ describe('Datatoken tests', async () => {
assert(token, 'Invalid token')
assert(token.orderCount === '1', 'Invalid orderCount after order')
assert(token.orders[0].id === orderId)
assert(token.orders[0].lastPriceToken.id === ZERO_ADDRESS)
})
})
5 changes: 0 additions & 5 deletions test/integration/Dispenser.test.ts
Expand Up @@ -202,7 +202,6 @@ describe('Dispenser tests', async () => {
createdTimestamp,
tx,
block,
lastPriceToken,
lastPriceValue
}}`
}
Expand Down Expand Up @@ -254,10 +253,6 @@ describe('Dispenser tests', async () => {
assert(dtTx.blockNumber >= blockNumber, 'incorrect value for: tx')
assert(dt.block >= blockNumber, 'incorrect value for: block')
assert(dt.block < blockNumber + 50, 'incorrect value for: block')
assert(
dt.lastPriceToken === '0x0000000000000000000000000000000000000000',
'incorrect value for: lastPriceToken'
)
assert(dt.lastPriceValue === '0', 'incorrect value for: lastPriceValue')
})

Expand Down
4 changes: 0 additions & 4 deletions test/integration/FixedRateExchange.test.ts
Expand Up @@ -273,10 +273,6 @@ describe('Fixed Rate Exchange tests', async () => {
assert(dtTx.blockNumber >= blockNumber, 'incorrect value for: tx')
assert(dt.block >= blockNumber, 'incorrect value for: block')
assert(dt.block < blockNumber + 50, 'incorrect value for: block')
assert(
dt.lastPriceToken === '0x0000000000000000000000000000000000000000',
'incorrect value for: lastPriceToken'
)
assert(dt.lastPriceValue === '0', 'incorrect value for: lastPriceValue')
})

Expand Down
11 changes: 9 additions & 2 deletions test/integration/SimplePublishConsume.test.ts
Expand Up @@ -282,7 +282,9 @@ describe('Simple Publish & consume test', async () => {
)
const orderId = `${orderTx.transactionHash.toLowerCase()}-${datatokenAddress.toLowerCase()}-${user1.toLowerCase()}`

const query = { query: `query {order(id:"${orderId}"){id, providerFee}}` }
const query = {
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}}}`
}

await sleep(2000)
const response = await fetch(subgraphUrl, {
Expand All @@ -293,6 +295,9 @@ describe('Simple Publish & consume test', async () => {
const queryResult = await response.json()

const providerFeeJSON = JSON.parse(queryResult.data.order.providerFee)
const lastPriceToken = queryResult.data.order.lastPriceToken.id

assert(lastPriceToken === ZERO_ADDRESS, 'Wrong lastPriceToken')

assert(
providerFeeJSON.providerFeeAddress.toLowerCase() ===
Expand Down Expand Up @@ -352,7 +357,7 @@ describe('Simple Publish & consume test', async () => {
const orderId = `${orderTx.transactionHash.toLowerCase()}-${datatokenAddress.toLowerCase()}-${user4.toLowerCase()}`

const initialQuery = {
query: `query {order(id:"${orderId}"){id, providerFee}}`
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}}}`
}
await sleep(2000)
const initialResponse = await fetch(subgraphUrl, {
Expand All @@ -363,7 +368,9 @@ describe('Simple Publish & consume test', async () => {
const initialProviderFeeJSON = JSON.parse(
initialQueryResult.data.order.providerFee
)
const lastPriceToken = initialQueryResult.data.order.lastPriceToken.id

assert(lastPriceToken === ZERO_ADDRESS, 'Wrong initial lastPriceToken set')
assert(
initialProviderFeeJSON.providerFeeAddress.toLowerCase() ===
setInitialProviderFee.providerFeeAddress.toLowerCase(),
Expand Down
7 changes: 5 additions & 2 deletions test/integration/users.test.ts
Expand Up @@ -33,7 +33,7 @@ async function userQuery(user: string) {
user(id:"${user}"){
id
tokenBalancesOwned {id}
orders {id}
orders {id, lastPriceToken{id}}
freSwaps {id}
totalOrders
totalSales
Expand Down Expand Up @@ -284,13 +284,16 @@ describe('User tests', async () => {
await sleep(2000)

const user = await userQuery(user3)

assert(user.id === user3, 'incorrect value for: id')
assert(user.tokenBalancesOwned.length === 0, 'incorrect tokenBalancesOwned')
assert(user.orders.length === 1, 'incorrect value for: orders')
assert(user.freSwaps.length === 0, 'incorrect value for: freSwaps')
assert(user.totalOrders === '1', 'incorrect value for: totalOrders')
assert(user.totalSales === '0', 'incorrect value for: totalSales')
assert(user.__typename === 'User', 'incorrect value for: __typename')
assert(
user.orders[0].lastPriceToken.id === ZERO_ADDRESS,
'incorrect value for: lastPriceToken'
)
})
})