diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bd59615..42c40db 100644 --- a/docker/docker-compose.yml +++ b/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' @@ -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 diff --git a/package.json b/package.json index b471c54..9dd2642 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/schema.graphql b/schema.graphql index b0f78f8..de60748 100644 --- a/schema.graphql +++ b/schema.graphql @@ -56,7 +56,7 @@ type Token @entity { "block number when it was created" block: Int! - lastPriceToken: String! + lastPriceToken: Token lastPriceValue: BigDecimal! } @@ -167,7 +167,7 @@ type Order @entity { tx: String! block: Int! - lastPriceToken: String! + lastPriceToken: Token lastPriceValue: BigDecimal! estimatedUSDValue: BigDecimal! gasUsed: BigDecimal diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts index e48040f..a38d48c 100644 --- a/src/mappings/erc20Templates.ts +++ b/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, @@ -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 { diff --git a/src/mappings/fixedRateExchange.ts b/src/mappings/fixedRateExchange.ts index 8964e7a..36e1247 100644 --- a/src/mappings/fixedRateExchange.ts +++ b/src/mappings/fixedRateExchange.ts @@ -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() } diff --git a/test/integration/Datatoken.test.ts b/test/integration/Datatoken.test.ts index f9aff1b..a47c158 100644 --- a/test/integration/Datatoken.test.ts +++ b/test/integration/Datatoken.test.ts @@ -162,7 +162,6 @@ describe('Datatoken tests', async () => { createdTimestamp, tx, block, - lastPriceToken, lastPriceValue }}` } @@ -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') }) @@ -275,7 +270,6 @@ describe('Datatoken tests', async () => { createdTimestamp, tx, block, - lastPriceToken, lastPriceValue }}` } @@ -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') }) @@ -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) @@ -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) }) }) diff --git a/test/integration/Dispenser.test.ts b/test/integration/Dispenser.test.ts index a210018..17d0748 100644 --- a/test/integration/Dispenser.test.ts +++ b/test/integration/Dispenser.test.ts @@ -202,7 +202,6 @@ describe('Dispenser tests', async () => { createdTimestamp, tx, block, - lastPriceToken, lastPriceValue }}` } @@ -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') }) diff --git a/test/integration/FixedRateExchange.test.ts b/test/integration/FixedRateExchange.test.ts index b1e81cf..7d99469 100644 --- a/test/integration/FixedRateExchange.test.ts +++ b/test/integration/FixedRateExchange.test.ts @@ -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') }) diff --git a/test/integration/SimplePublishConsume.test.ts b/test/integration/SimplePublishConsume.test.ts index 1f86e2b..0de6d92 100644 --- a/test/integration/SimplePublishConsume.test.ts +++ b/test/integration/SimplePublishConsume.test.ts @@ -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, { @@ -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() === @@ -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, { @@ -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(), diff --git a/test/integration/users.test.ts b/test/integration/users.test.ts index 29a4de6..afd791b 100644 --- a/test/integration/users.test.ts +++ b/test/integration/users.test.ts @@ -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 @@ -284,7 +284,6 @@ 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') @@ -292,5 +291,9 @@ describe('User tests', async () => { 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' + ) }) })