Skip to content

Commit 2839649

Browse files
authored
Fix bugs (#286)
* fix token * fix dispenser * fixed fre
1 parent 6148fd2 commit 2839649

10 files changed

+85
-43
lines changed

abis/Dispenser.json

+3-3
Large diffs are not rendered by default.

docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
graph-node:
44
image: graphprotocol/graph-node:v0.25.0
55
ports:
6-
- '8000:8000'
6+
- '9000:8000'
77
- '8001:8001'
88
- '8020:8020'
99
- '8030:8030'

schema.graphql

+12-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Token @entity {
99
isDatatoken: Boolean!
1010

1111
"address of ERC721 that owns the token, valid only for datatokens"
12-
owner: String
12+
nft: Nft
1313

1414
"array of addresses with minter role, can be user wallet address, dispenser etc."
1515
minter: [User!]
@@ -293,7 +293,6 @@ type FixedRateExchange @entity {
293293
totalSwapValue: BigDecimal!
294294
"address that is allowed to swap tokens"
295295
allowedSwapper: String
296-
supply: BigInt!
297296
"if the owner allowes the fre to mint"
298297
withMint: Boolean
299298
"if the fre has the minter role on the datatoken"
@@ -338,11 +337,12 @@ type FixedRateExchangeSwap @entity {
338337

339338

340339
type Dispenser @entity {
341-
"datatoken address"
340+
"token address"
342341
id: ID!
343-
active: Boolean!
344-
owner: User!
345-
datatoken: Token!
342+
active: Boolean!
343+
"if using the enterprise template the owner will always be the erc721 factory, for normal template it will a user"
344+
owner: String
345+
token: Token!
346346

347347
allowedSwapper: String
348348
isMinter: Boolean
@@ -351,7 +351,12 @@ type Dispenser @entity {
351351
"max balance of requester. If the balance is higher, the dispense is rejected"
352352
maxBalance: BigDecimal!
353353
"how many tokens are left"
354-
balance: BigDecimal!
354+
balance: BigDecimal!
355+
356+
357+
block: Int!
358+
createdTimestamp: Int!
359+
tx: String!
355360

356361
dispenses: [DispenserTransaction!] @derivedFrom(field: "dispenser")
357362
}

src/mappings/dispenser.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { log } from '@graphprotocol/graph-ts'
12
import {
23
DispenserActivated,
34
DispenserAllowedSwapperChanged,
@@ -6,13 +7,34 @@ import {
67
TokensDispensed
78
} from '../@types/Dispenser/Dispenser'
89
import { DispenserCreated } from '../@types/ERC721Factory/ERC721Factory'
9-
import { DispenserTransaction } from '../@types/schema'
10+
import { Dispenser, DispenserTransaction } from '../@types/schema'
1011
import { decimal } from './utils/constants'
11-
import { createDispenser, getDispenser } from './utils/dispenserUtils'
12+
import { getDispenser } from './utils/dispenserUtils'
13+
import { weiToDecimal } from './utils/generic'
14+
import { getToken } from './utils/tokenUtils'
1215
import { getUser } from './utils/userUtils'
1316

1417
export function handleNewDispenser(event: DispenserCreated): void {
15-
createDispenser(event.params.datatokenAddress.toHex())
18+
const dispenser = new Dispenser(event.params.datatokenAddress.toHex())
19+
const token = getToken(event.params.datatokenAddress.toHex())
20+
dispenser.token = token.id
21+
22+
dispenser.owner = event.params.owner.toHexString()
23+
dispenser.maxBalance = weiToDecimal(
24+
event.params.maxBalance.toBigDecimal(),
25+
token.decimals
26+
)
27+
dispenser.maxTokens = weiToDecimal(
28+
event.params.maxTokens.toBigDecimal(),
29+
token.decimals
30+
)
31+
dispenser.active = true
32+
33+
dispenser.allowedSwapper = event.params.allowedSwapper.toHex()
34+
dispenser.createdTimestamp = event.block.timestamp.toI32()
35+
dispenser.tx = event.transaction.hash.toHex()
36+
dispenser.block = event.block.number.toI32()
37+
dispenser.save()
1638
}
1739

1840
export function handleActivate(event: DispenserActivated): void {

src/mappings/erc721Factory.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { log } from '@graphprotocol/graph-ts'
12
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
23
import { Nft, Token } from '../@types/schema'
34
import { decimal, integer } from './utils/constants'
5+
import { weiToDecimal } from './utils/generic'
46
import { getGlobalStats } from './utils/globalUtils'
57
import { getUser } from './utils/userUtils'
68

79
export function handleNftCreated(event: NFTCreated): void {
10+
log.warning('handleNftCreated is starting', [])
811
const nft = new Nft(event.params.newTokenAddress.toHexString())
912

1013
const user = getUser(event.params.admin.toHexString())
@@ -24,16 +27,24 @@ export function handleNftCreated(event: NFTCreated): void {
2427
}
2528

2629
export function handleNewToken(event: TokenCreated): void {
30+
log.warning('handleNewToken {} {}', [
31+
event.transaction.from.toHexString(),
32+
event.address.toHexString()
33+
])
2734
const token = new Token(event.params.newTokenAddress.toHexString())
2835
token.isDatatoken = true
2936
token.address = event.params.newTokenAddress.toHexString()
3037
token.createdTimestamp = event.block.timestamp.toI32()
3138
token.tx = event.transaction.hash.toHex()
3239
token.block = event.block.number.toI32()
3340

41+
token.nft = event.params.creator.toHexString()
42+
3443
token.name = event.params.name
44+
token.symbol = event.params.symbol
3545
token.decimals = 18
3646
token.supply = decimal.ZERO
47+
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
3748

3849
const globalStats = getGlobalStats()
3950
globalStats.datatokenCount = globalStats.datatokenCount.plus(integer.ONE)

src/mappings/fixedRateExchange.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigInt } from '@graphprotocol/graph-ts'
1+
import { BigInt, log } from '@graphprotocol/graph-ts'
22
import {
33
ExchangeActivated,
44
ExchangeAllowedSwapperChanged,
@@ -19,20 +19,32 @@ import { getToken } from './utils/tokenUtils'
1919
import { getUser } from './utils/userUtils'
2020

2121
export function handleExchangeCreated(event: ExchangeCreated): void {
22+
log.warning(
23+
'handleExchangeCreated baseToken {} ; dataToken {} ; exchangeOwner {} ; fixedRate {}',
24+
[
25+
event.params.baseToken.toHexString(),
26+
event.params.dataToken.toHexString(),
27+
event.params.exchangeOwner.toHexString(),
28+
event.params.fixedRate.toBigDecimal().toString()
29+
]
30+
)
2231
const fixedRateExchange = new FixedRateExchange(
2332
event.params.exchangeId.toHexString()
2433
)
2534
const user = getUser(event.params.exchangeOwner.toHexString())
2635
fixedRateExchange.owner = user.id
27-
fixedRateExchange.datatoken = event.params.dataToken.toHexString()
28-
fixedRateExchange.baseToken = event.params.baseToken.toHexString()
29-
// fixedRateExchange.baseTokenSymbol = getTokenSymbol(event.params.baseToken)
30-
fixedRateExchange.active = false
36+
fixedRateExchange.datatoken = getToken(
37+
event.params.dataToken.toHexString()
38+
).id
39+
fixedRateExchange.baseToken = getToken(
40+
event.params.baseToken.toHexString()
41+
).id
3142

32-
fixedRateExchange.price = weiToDecimal(
33-
event.params.fixedRate.toBigDecimal(),
34-
BigInt.fromI32(18).toI32()
35-
)
43+
fixedRateExchange.active = false
44+
fixedRateExchange.price = event.params.fixedRate.toBigDecimal()
45+
fixedRateExchange.createdTimestamp = event.block.timestamp.toI32()
46+
fixedRateExchange.tx = event.transaction.hash.toHex()
47+
fixedRateExchange.block = event.block.number.toI32()
3648
fixedRateExchange.save()
3749
}
3850

@@ -145,13 +157,6 @@ export function handleSwap(event: Swapped): void {
145157
event.params.exchangeId.toHex()
146158
)
147159

148-
// reduce supply if the fixed rate is not minting tokens
149-
if (fixedRateExchange.isMinter || fixedRateExchange.withMint) {
150-
fixedRateExchange.supply = fixedRateExchange.supply.minus(
151-
event.params.dataTokenSwappedAmount
152-
)
153-
}
154-
155160
const swap = new FixedRateExchangeSwap(
156161
getUpdateOrSwapId(
157162
event.transaction.hash.toHex(),

src/mappings/utils/dispenserUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getToken } from './tokenUtils'
33

44
export function createDispenser(address: string): Dispenser {
55
const dispenser = new Dispenser(address)
6-
dispenser.datatoken = getToken(address).id
6+
dispenser.token = getToken(address).id
77
dispenser.save()
88
return dispenser
99
}

src/mappings/utils/tokenUtils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Address } from '@graphprotocol/graph-ts'
1+
import { Address, log } from '@graphprotocol/graph-ts'
22
import { Token } from '../../@types/schema'
33
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
44
import { integer } from './constants'
55
import { getGlobalStats } from './globalUtils'
66

77
export function createToken(address: string): Token {
8+
log.debug('started creating token with address: {}', [address])
89
const token = new Token(address)
910
const contract = ERC20.bind(Address.fromString(address))
1011
token.name = contract.name()

subgraph.rinkeby.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ dataSources:
88
name: ERC721Factory
99
network: rinkeby
1010
source:
11-
address: '0xa15024b732A8f2146423D14209eFd074e61964F3'
11+
address: '0xe4B39C90355899DB8f625D879B44Fa9C5Cdde550'
1212
abi: ERC721Factory
13-
startBlock: 9759283
13+
startBlock: 9984045
1414
mapping:
1515
kind: ethereum/events
1616
apiVersion: 0.0.5
@@ -30,9 +30,9 @@ dataSources:
3030
name: FixedRateExchange
3131
network: rinkeby
3232
source:
33-
address: '0x235C9bE4D23dCbd16c1Bf89ec839cb7C452FD9e9'
33+
address: '0x7084f7353bB7cfc92A65e7d23987Cb5D1A3Fb9b2'
3434
abi: FixedRateExchange
35-
startBlock: 9759283
35+
startBlock: 9984045
3636
mapping:
3737
kind: ethereum/events
3838
apiVersion: 0.0.5
@@ -43,6 +43,8 @@ dataSources:
4343
abis:
4444
- name: FixedRateExchange
4545
file: ./abis/FixedRateExchange.json
46+
- name: ERC20
47+
file: ./abis/ERC20.json
4648
eventHandlers:
4749
- event: ExchangeCreated(indexed bytes32,indexed address,indexed address,address,uint256)
4850
handler: handleExchangeCreated
@@ -62,9 +64,9 @@ dataSources:
6264
name: Dispenser
6365
network: rinkeby
6466
source:
65-
address: '0x5FFE6649C7562F3bee1ca114c7c3316BF4B45b50'
67+
address: '0xa8fFDd525835795C940370FB816f82a5F7F5F860'
6668
abi: Dispenser
67-
startBlock: 9759283
69+
startBlock: 9984045
6870
mapping:
6971
kind: ethereum/events
7072
apiVersion: 0.0.5
@@ -192,6 +194,4 @@ templates:
192194
- event: MetadataState(indexed address,uint8,uint256,uint256)
193195
handler: handleState
194196
- event: TokenURIUpdate(indexed address,string,uint256,uint256,uint256)
195-
handler: handleTokenUriUpdate
196-
features:
197-
- nonFatalErrors
197+
handler: handleTokenUriUpdate

subgraph.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,3 @@ templates:
193193
handler: handleState
194194
- event: TokenURIUpdate(indexed address,string,uint256,uint256,uint256)
195195
handler: handleTokenUriUpdate
196-
features:
197-
- nonFatalErrors

0 commit comments

Comments
 (0)