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

ON-509: fix subgraph sync #12

Merged
merged 3 commits into from
Nov 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/goerli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"network": "goerli",
"erc721": [
"ERC721": [
{
"name": "ChronosTraveler",
"address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32",
Expand Down
4 changes: 2 additions & 2 deletions config/mumbai.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"network": "mumbai",
"erc721": [
"ERC721": [
{
"name": "AavegotchiGotchi",
"address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e",
Expand All @@ -12,7 +12,7 @@
"startBlock": 38134604
}
],
"erc1155": [
"ERC1155": [
{
"name": "AavegotchiWearable",
"address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8",
Expand Down
4 changes: 2 additions & 2 deletions config/polygon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"network": "matic",
"erc721": [
"ERC721": [
{
"name": "AavegotchiGotchi",
"address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d",
Expand All @@ -17,7 +17,7 @@
"startBlock": 36796276
}
],
"erc1155": [
"ERC1155": [
{
"name": "AavegotchiWearable",
"address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f",
Expand Down
2 changes: 1 addition & 1 deletion mustache.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function replaceFirstElementFlag(data) {
return {
[key]: data[key].map((item, index) => {
if (index === 0) {
return { ...item, isFirstElement: true }
return { ...item, name: key }
} else {
return item
}
Expand Down
1 change: 1 addition & 0 deletions src/erc1155/transfer-batch-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function handleTransferBatch(event: TransferBatch): void {
amounts.length.toString(),
event.transaction.hash.toHex(),
])
return
}

for (let i = 0; i < tokenIds.length; i++) {
Expand Down
18 changes: 4 additions & 14 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ schema:
file: ./schema.graphql
dataSources:

{{#erc721}}
{{#isFirstElement}}
- name: ERC721
{{/isFirstElement}}
{{^isFirstElement}}
{{#ERC721}}
- name: {{name}}
{{/isFirstElement}}
kind: ethereum
network: {{network}}
source:
Expand All @@ -30,15 +25,10 @@ dataSources:
- event: Transfer(indexed address,indexed address,indexed uint256)
handler: handleTransfer
file: ./src/erc721/index.ts
{{/erc721}}
{{/ERC721}}

{{#erc1155}}
{{#isFirstElement}}
- name: ERC1155
{{/isFirstElement}}
{{^isFirstElement}}
{{#ERC1155}}
- name: {{name}}
{{/isFirstElement}}
kind: ethereum
network: {{network}}
source:
Expand All @@ -61,7 +51,7 @@ dataSources:
- event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
handler: handleTransferBatch
file: ./src/erc1155/index.ts
{{/erc1155}}
{{/ERC1155}}

- name: ERC7432
kind: ethereum
Expand Down
10 changes: 5 additions & 5 deletions tests/erc1155/transfer-batch-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ERC-1155 Transfer Batch Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
}
})

Expand All @@ -45,7 +45,7 @@ describe('ERC-1155 Transfer Batch Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
}
})
})
Expand All @@ -68,7 +68,7 @@ describe('ERC-1155 Transfer Batch Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
}
})

Expand All @@ -82,7 +82,7 @@ describe('ERC-1155 Transfer Batch Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
}

const event2 = createTransferBatchEvent(Addresses[0], Addresses[1], Addresses[2], TokenIds, Amounts, ZERO_ADDRESS)
Expand All @@ -94,7 +94,7 @@ describe('ERC-1155 Transfer Batch Handler', () => {
assert.fieldEquals('Nft', _id2, 'tokenId', TokenIds[i].toString())
assert.fieldEquals('Nft', _id2, 'owner', Addresses[2])
assert.fieldEquals('Nft', _id2, 'amount', Amounts[i].toString())
assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155)
}
})
})
Expand Down
10 changes: 5 additions & 5 deletions tests/erc1155/transfer-single-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ERC-1155 Transfer Single Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
})

test('should transfer NFT and create Account when NFT exist Account does not', () => {
Expand All @@ -53,7 +53,7 @@ describe('ERC-1155 Transfer Single Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
})
})
describe('When NFT or Account exists', () => {
Expand All @@ -79,7 +79,7 @@ describe('ERC-1155 Transfer Single Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)
})

test('should transfer NFT and update amount after two transfers', () => {
Expand All @@ -98,7 +98,7 @@ describe('ERC-1155 Transfer Single Handler', () => {
assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString())
assert.fieldEquals('Nft', _id, 'owner', Addresses[1])
assert.fieldEquals('Nft', _id, 'amount', Amounts[1].toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155)

const event2 = createTransferSingleEvent(
Addresses[0],
Expand All @@ -115,7 +115,7 @@ describe('ERC-1155 Transfer Single Handler', () => {
assert.fieldEquals('Nft', _id2, 'tokenId', TokenIds[0].toString())
assert.fieldEquals('Nft', _id2, 'owner', Addresses[2])
assert.fieldEquals('Nft', _id2, 'amount', Amounts[0].toString())
assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155.toString())
assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155)
})
})
})
2 changes: 1 addition & 1 deletion tests/helpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createMockNft(tokenAddress: string, tokenId: string, ownerAddres
const nft = new Nft(generateERC721NftId(tokenAddress, BigInt.fromString(tokenId)))
nft.tokenAddress = tokenAddress
nft.tokenId = BigInt.fromString(tokenId)
nft.type = NftType.ERC721.toString()
nft.type = NftType.ERC721

const nftOwner = createMockAccount(ownerAddress)

Expand Down
4 changes: 2 additions & 2 deletions utils/entities/nft/erc-1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function upsertERC1155Nft(tokenAddress: string, tokenId: BigInt, amount:
nft.tokenId = tokenId
nft.tokenAddress = tokenAddress
nft.owner = findOrCreateAccount(to).id
nft.type = NftType.ERC1155.toString()
nft.type = NftType.ERC1155
}

return updateERC1155Balance(findOrCreateAccount(from), findOrCreateAccount(to), nft, amount)
Expand All @@ -30,7 +30,7 @@ export function findOrCreateERC1155Nft(tokenAddress: string, tokenId: BigInt, to
nft = new Nft(nftId)
nft.tokenId = tokenId
nft.tokenAddress = tokenAddress
nft.type = NftType.ERC1155.toString()
nft.type = NftType.ERC1155
nft.owner = to.id
nft.save()
}
Expand Down
4 changes: 2 additions & 2 deletions utils/entities/nft/erc-721.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NftType } from '../../enums'
import { Nft } from '../../../generated/schema'
import { NftType } from '../../enums'
import { findOrCreateAccount } from '../account'
import { BigInt } from '@graphprotocol/graph-ts'

Expand All @@ -14,7 +14,7 @@ export function upsertERC721Nft(tokenAddress: string, tokenId: BigInt, to: strin
nft = new Nft(nftId)
nft.tokenId = tokenId
nft.tokenAddress = tokenAddress
nft.type = NftType.ERC721.toString()
nft.type = NftType.ERC721
}

nft.owner = findOrCreateAccount(to).id
Expand Down
9 changes: 6 additions & 3 deletions utils/enums/nft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export enum NftType {
ERC721,
ERC1155,
// We are using a class instead of an enum because we need to use the values as string, but we need to map it enum alike
export class NftType {
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
static ERC721: string = 'ERC721'
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
static ERC1155: string = 'ERC1155'
}