Skip to content

Commit 89b494c

Browse files
committed
nftupdate
1 parent 1868a62 commit 89b494c

9 files changed

+143
-41
lines changed

schema.graphql

+27-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Token @entity {
3939
createdTimestamp: Int
4040

4141
"datatoken creation transaction id"
42-
tx: Bytes
42+
tx: String!
4343

4444
"block number when it was created"
4545
block: Int
@@ -84,7 +84,7 @@ type Nft @entity{
8484
"block time nft was created"
8585
createdTimestamp: Int!
8686
"nft creation transaction id"
87-
tx: Bytes
87+
tx: String!
8888
"block number when it was created"
8989
block: Int
9090
}
@@ -163,7 +163,7 @@ type Pool @entity {
163163
"block time when pool was created"
164164
createdTimestamp: Int!
165165
"pool creation transaction id"
166-
tx: Bytes
166+
tx: String!
167167
"block number when it was created"
168168
block: Int
169169

@@ -211,7 +211,7 @@ type PoolTransaction @entity {
211211
"block time when pool was created"
212212
timestamp: Int!
213213
"pool creation transaction id"
214-
tx: Bytes
214+
tx: String!
215215
"block number when it was created"
216216
block: Int
217217

@@ -253,7 +253,7 @@ type Order @entity {
253253
consumerMarketAmmount: BigDecimal #call contract to get fee ammount
254254

255255
createdTimestamp: Int!
256-
tx: Bytes
256+
tx: String!
257257
block: Int!
258258
}
259259

@@ -268,7 +268,7 @@ type TokenTransaction @entity {
268268
gasUsed: BigDecimal!
269269
gasPrice: BigDecimal!
270270
createdTimestamp: Int!
271-
tx: Bytes!
271+
tx: String!
272272
}
273273

274274
type User @entity {
@@ -303,7 +303,7 @@ type FixedRateExchange @entity {
303303
swaps: [FixedRateExchangeSwap!] @derivedFrom(field: "exchangeId")
304304

305305
createdTimestamp: Int!
306-
tx: Bytes
306+
tx: String!
307307
block: Int!
308308
}
309309

@@ -322,7 +322,7 @@ type FixedRateExchangeUpdate @entity {
322322

323323
block: Int!
324324
createdTimestamp: Int!
325-
tx: Bytes!
325+
tx: String!
326326
}
327327

328328
type FixedRateExchangeSwap @entity {
@@ -333,7 +333,7 @@ type FixedRateExchangeSwap @entity {
333333
dataTokenAmount: BigDecimal!
334334
block: Int!
335335
createdTimestamp: Int!
336-
tx: Bytes!
336+
tx: String!
337337
}
338338

339339

@@ -364,7 +364,7 @@ type DispenserTransaction @entity {
364364

365365
block: Int!
366366
createdTimestamp: Int!
367-
tx: Bytes!
367+
tx: String!
368368
}
369369

370370
type PoolSnapshot @entity {
@@ -402,25 +402,36 @@ type GlobalStats @entity {
402402
orderCount: BigInt
403403

404404
"number of pools for all factories"
405-
poolCount: Int!
405+
poolCount: Int!
406406
"number of finalized pools for all factories"
407-
finalizedPoolCount: Int!
407+
finalizedPoolCount: Int!
408408
"probably remove due to inconsistencies and imposibility to calculate"
409-
totalOrderVolume: BigDecimal
409+
totalOrderVolume: BigDecimal
410410
}
411411

412412

413+
enum NftUpdateType {
414+
METADATA_CREATED,
415+
METADATA_UPDATED,
416+
STATE_UPDATED,
417+
TOKENURI_UPDATED
418+
}
419+
413420
type NftUpdate @entity {
414421
id: ID! # update tx + nft address
415-
datatoken: Nft!
422+
423+
nft: Nft!
416424

417425
"user that made the update"
418426
userAddress: String!
419427

420-
"state of the asset in this update"
428+
"state of the asset in this update"
421429
assetState: Int!
422430

431+
"type of the update: metadata created, metadata update, state update, token uri update"
432+
type: NftUpdateType!
433+
423434
block: Int!
424435
timestamp: Int!
425-
tx: Bytes!
436+
tx: String!
426437
}

src/mappings/dispenser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function handleTokensDispensed(event: TokensDispensed): void {
5353
dispenserTransaction.user = user.id
5454

5555
dispenserTransaction.createdTimestamp = event.block.timestamp.toI32()
56-
dispenserTransaction.tx = event.transaction.hash
56+
dispenserTransaction.tx = event.transaction.hash.toHex()
5757
dispenserTransaction.block = event.block.number.toI32()
5858
dispenserTransaction.save()
5959
}

src/mappings/erc20Templates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function handleOrderStarted(event: OrderStarted): void {
4646
order.consumerMarket = consumeMarket.id
4747

4848
order.createdTimestamp = event.block.timestamp.toI32()
49-
order.tx = event.transaction.hash
49+
order.tx = event.transaction.hash.toHex()
5050
order.block = event.block.number.toI32()
5151

5252
order.save()

src/mappings/erc721Factory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function handleNftCreated(event: NFTCreated): void {
1212
nft.name = event.params.tokenName
1313
nft.symbol = ''
1414
nft.createdTimestamp = event.block.timestamp.toI32()
15-
nft.tx = event.transaction.hash
15+
nft.tx = event.transaction.hash.toHex()
1616
nft.block = event.block.number.toI32()
1717

1818
nft.save()
@@ -23,7 +23,7 @@ export function handleNewToken(event: TokenCreated): void {
2323
token.isDatatoken = true
2424
token.address = event.params.newTokenAddress.toHexString()
2525
token.createdTimestamp = event.block.timestamp.toI32()
26-
token.tx = event.transaction.hash
26+
token.tx = event.transaction.hash.toHex()
2727
token.block = event.block.number.toI32()
2828

2929
token.name = event.params.name

src/mappings/fixedRateExchange.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function handleRateChange(event: ExchangeRateChanged): void {
4848
)
4949
newExchangeUpdate.oldPrice = fixedRateExchange.price
5050
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
51-
newExchangeUpdate.tx = event.transaction.hash
51+
newExchangeUpdate.tx = event.transaction.hash.toHex()
5252
newExchangeUpdate.block = event.block.number.toI32()
5353

5454
fixedRateExchange.price = weiToDecimal(
@@ -84,7 +84,7 @@ export function handleActivated(event: ExchangeActivated): void {
8484
newExchangeUpdate.oldActive = fixedRateExchange.active
8585
newExchangeUpdate.newActive = true
8686
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
87-
newExchangeUpdate.tx = event.transaction.hash
87+
newExchangeUpdate.tx = event.transaction.hash.toHex()
8888
newExchangeUpdate.block = event.block.number.toI32()
8989

9090
fixedRateExchange.active = true
@@ -107,7 +107,7 @@ export function handleDeactivated(event: ExchangeDeactivated): void {
107107
newExchangeUpdate.newActive = false
108108

109109
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
110-
newExchangeUpdate.tx = event.transaction.hash
110+
newExchangeUpdate.tx = event.transaction.hash.toHex()
111111
newExchangeUpdate.block = event.block.number.toI32()
112112

113113
fixedRateExchange.active = false
@@ -129,7 +129,7 @@ export function handleAllowedSwapperChanged(
129129
)
130130

131131
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
132-
newExchangeUpdate.tx = event.transaction.hash
132+
newExchangeUpdate.tx = event.transaction.hash.toHex()
133133
newExchangeUpdate.block = event.block.number.toI32()
134134
newExchangeUpdate.oldAllowedSwapper = fixedRateExchange.allowedSwapper
135135

@@ -159,7 +159,7 @@ export function handleSwap(event: Swapped): void {
159159
)
160160
)
161161
swap.createdTimestamp = event.block.timestamp.toI32()
162-
swap.tx = event.transaction.hash
162+
swap.tx = event.transaction.hash.toHex()
163163
swap.block = event.block.number.toI32()
164164

165165
swap.exchangeId = event.params.exchangeId.toHex()

src/mappings/nftUpdate.ts

+94-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,104 @@
1+
import { Nft, NftUpdate } from '../@types/schema'
12
import {
23
MetadataCreated,
34
MetadataState,
45
MetadataUpdated,
56
TokenURIUpdate
67
} from '../@types/templates/ERC721Template/ERC721Template'
8+
import { NftUpdateType } from './utils/constants'
79

8-
export function handleCreated(event: MetadataCreated): void {}
10+
function getId(tx: string, nftAddress: string): string {
11+
return `${tx}-${nftAddress}`
12+
}
913

10-
export function handleUpdated(event: MetadataUpdated): void {}
14+
export function handleCreated(event: MetadataCreated): void {
15+
const nftAddress = event.address.toHex()
16+
const nft = Nft.load(nftAddress)
17+
if (!nft) return
1118

12-
export function handleState(event: MetadataState): void {}
19+
nft.assetState = event.params.state
1320

14-
export function handleUriUpdate(event: TokenURIUpdate): void {}
21+
const nftUpdate = new NftUpdate(
22+
getId(event.transaction.hash.toHex(), nftAddress)
23+
)
24+
25+
nftUpdate.type = NftUpdateType.METADATA_CREATED
26+
nftUpdate.userAddress = event.params.createdBy.toHex()
27+
nftUpdate.assetState = event.params.state
28+
29+
nftUpdate.timestamp = event.block.timestamp.toI32()
30+
nftUpdate.tx = event.transaction.hash.toHex()
31+
nftUpdate.block = event.block.number.toI32()
32+
33+
nftUpdate.save()
34+
nft.save()
35+
}
36+
37+
export function handleUpdated(event: MetadataUpdated): void {
38+
const nftAddress = event.address.toHex()
39+
const nft = Nft.load(nftAddress)
40+
if (!nft) return
41+
42+
nft.assetState = event.params.state
43+
44+
const nftUpdate = new NftUpdate(
45+
getId(event.transaction.hash.toHex(), nftAddress)
46+
)
47+
48+
nftUpdate.type = NftUpdateType.METADATA_UPDATED
49+
nftUpdate.userAddress = event.params.updatedBy.toHex()
50+
nftUpdate.assetState = event.params.state
51+
52+
nftUpdate.timestamp = event.block.timestamp.toI32()
53+
nftUpdate.tx = event.transaction.hash.toHex()
54+
nftUpdate.block = event.block.number.toI32()
55+
56+
nftUpdate.save()
57+
nft.save()
58+
}
59+
60+
export function handleState(event: MetadataState): void {
61+
const nftAddress = event.address.toHex()
62+
const nft = Nft.load(nftAddress)
63+
if (!nft) return
64+
65+
nft.assetState = event.params.state
66+
67+
const nftUpdate = new NftUpdate(
68+
getId(event.transaction.hash.toHex(), nftAddress)
69+
)
70+
71+
nftUpdate.type = NftUpdateType.STATE_UPDATED
72+
nftUpdate.userAddress = event.params.updatedBy.toHex()
73+
nftUpdate.assetState = event.params.state
74+
75+
nftUpdate.timestamp = event.block.timestamp.toI32()
76+
nftUpdate.tx = event.transaction.hash.toHex()
77+
nftUpdate.block = event.block.number.toI32()
78+
79+
nftUpdate.save()
80+
nft.save()
81+
}
82+
83+
export function handleTokenUriUpdate(event: TokenURIUpdate): void {
84+
const nftAddress = event.address.toHex()
85+
const nft = Nft.load(nftAddress)
86+
87+
if (!nft) return
88+
89+
nft.tokenUri = event.params.tokenURI
90+
91+
const nftUpdate = new NftUpdate(
92+
getId(event.transaction.hash.toHex(), nftAddress)
93+
)
94+
95+
nftUpdate.type = NftUpdateType.TOKENURI_UPDATED
96+
nftUpdate.userAddress = event.params.updatedBy.toHex()
97+
98+
nftUpdate.timestamp = event.block.timestamp.toI32()
99+
nftUpdate.tx = event.transaction.hash.toHex()
100+
nftUpdate.block = event.block.number.toI32()
101+
102+
nftUpdate.save()
103+
nft.save()
104+
}

src/mappings/poolFactory.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import { BPoolCreated } from '../@types/FactoryRouter/FactoryRouter'
22
import { Pool } from '../@types/schema'
3-
import { getPoolToken } from './utils/poolUtils'
3+
import { getToken } from './utils/tokenUtils'
44

55
export function handleNewPool(event: BPoolCreated): void {
66
const pool = new Pool(event.params.newBPoolAddress.toHex())
77

8-
const baseToken = getPoolToken(
9-
event.params.newBPoolAddress.toHex(),
10-
event.params.basetokenAddress.toHex()
11-
)
8+
const baseToken = getToken(event.params.basetokenAddress.toHex())
129
pool.baseToken = baseToken.id
1310

14-
const datatoken = getPoolToken(
15-
event.params.newBPoolAddress.toHex(),
16-
event.params.datatokenAddress.toHex()
17-
)
11+
const datatoken = getToken(event.params.datatokenAddress.toHex())
1812
pool.datatoken = datatoken.id
1913

2014
pool.owner = event.params.registeredBy.toHex()
2115

2216
pool.createdTimestamp = event.block.timestamp.toI32()
23-
pool.tx = event.transaction.hash
17+
pool.tx = event.transaction.hash.toHex()
2418
pool.block = event.block.number.toI32()
2519

2620
pool.save()

src/mappings/utils/constants.ts

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ export enum PoolTransactionType {
2525
SWAP = 'SWAP',
2626
SETUP = 'SETUP'
2727
}
28+
29+
export enum NftUpdateType {
30+
METADATA_CREATED = 'METADATA_CREATED',
31+
METADATA_UPDATED = 'METADATA_UPDATED',
32+
STATE_UPDATED = 'STATE_UPDATED',
33+
TOKENURI_UPDATED = 'TOKENURI_UPDATED'
34+
}

subgraph.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ templates:
118118
- event: PublishMarketFees(indexed address,indexed address,uint256)
119119
handler: handlePublishMarketFees
120120
- event: ConsumeMarketFees(indexed address,indexed address,uint256)
121-
handler: handleConsumeMarketFees
121+
handler: handleConsumeMarketFees
122122
- kind: ethereum/contract
123123
name: BFactory
124124
network: barge
@@ -194,6 +194,6 @@ templates:
194194
- event: MetadataState(indexed address,uint8,uint256,uint256)
195195
handler: handleState
196196
- event: TokenURIUpdate(indexed address,string,uint256,uint256,uint256)
197-
handler: handleUriUpdate
197+
handler: handleTokenUriUpdate
198198
features:
199199
- nonFatalErrors

0 commit comments

Comments
 (0)