* fix token

* fix dispenser

* fixed fre
This commit is contained in:
mihaisc 2022-01-13 08:24:57 -08:00 committed by GitHub
parent 6148fd260a
commit 2839649b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 85 additions and 43 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ services:
graph-node:
image: graphprotocol/graph-node:v0.25.0
ports:
- '8000:8000'
- '9000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'

View File

@ -9,7 +9,7 @@ type Token @entity {
isDatatoken: Boolean!
"address of ERC721 that owns the token, valid only for datatokens"
owner: String
nft: Nft
"array of addresses with minter role, can be user wallet address, dispenser etc."
minter: [User!]
@ -293,7 +293,6 @@ type FixedRateExchange @entity {
totalSwapValue: BigDecimal!
"address that is allowed to swap tokens"
allowedSwapper: String
supply: BigInt!
"if the owner allowes the fre to mint"
withMint: Boolean
"if the fre has the minter role on the datatoken"
@ -338,11 +337,12 @@ type FixedRateExchangeSwap @entity {
type Dispenser @entity {
"datatoken address"
"token address"
id: ID!
active: Boolean!
owner: User!
datatoken: Token!
"if using the enterprise template the owner will always be the erc721 factory, for normal template it will a user"
owner: String
token: Token!
allowedSwapper: String
isMinter: Boolean
@ -353,6 +353,11 @@ type Dispenser @entity {
"how many tokens are left"
balance: BigDecimal!
block: Int!
createdTimestamp: Int!
tx: String!
dispenses: [DispenserTransaction!] @derivedFrom(field: "dispenser")
}

View File

@ -1,3 +1,4 @@
import { log } from '@graphprotocol/graph-ts'
import {
DispenserActivated,
DispenserAllowedSwapperChanged,
@ -6,13 +7,34 @@ import {
TokensDispensed
} from '../@types/Dispenser/Dispenser'
import { DispenserCreated } from '../@types/ERC721Factory/ERC721Factory'
import { DispenserTransaction } from '../@types/schema'
import { Dispenser, DispenserTransaction } from '../@types/schema'
import { decimal } from './utils/constants'
import { createDispenser, getDispenser } from './utils/dispenserUtils'
import { getDispenser } from './utils/dispenserUtils'
import { weiToDecimal } from './utils/generic'
import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
export function handleNewDispenser(event: DispenserCreated): void {
createDispenser(event.params.datatokenAddress.toHex())
const dispenser = new Dispenser(event.params.datatokenAddress.toHex())
const token = getToken(event.params.datatokenAddress.toHex())
dispenser.token = token.id
dispenser.owner = event.params.owner.toHexString()
dispenser.maxBalance = weiToDecimal(
event.params.maxBalance.toBigDecimal(),
token.decimals
)
dispenser.maxTokens = weiToDecimal(
event.params.maxTokens.toBigDecimal(),
token.decimals
)
dispenser.active = true
dispenser.allowedSwapper = event.params.allowedSwapper.toHex()
dispenser.createdTimestamp = event.block.timestamp.toI32()
dispenser.tx = event.transaction.hash.toHex()
dispenser.block = event.block.number.toI32()
dispenser.save()
}
export function handleActivate(event: DispenserActivated): void {

View File

@ -1,10 +1,13 @@
import { log } from '@graphprotocol/graph-ts'
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
import { Nft, Token } from '../@types/schema'
import { decimal, integer } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getGlobalStats } from './utils/globalUtils'
import { getUser } from './utils/userUtils'
export function handleNftCreated(event: NFTCreated): void {
log.warning('handleNftCreated is starting', [])
const nft = new Nft(event.params.newTokenAddress.toHexString())
const user = getUser(event.params.admin.toHexString())
@ -24,6 +27,10 @@ export function handleNftCreated(event: NFTCreated): void {
}
export function handleNewToken(event: TokenCreated): void {
log.warning('handleNewToken {} {}', [
event.transaction.from.toHexString(),
event.address.toHexString()
])
const token = new Token(event.params.newTokenAddress.toHexString())
token.isDatatoken = true
token.address = event.params.newTokenAddress.toHexString()
@ -31,9 +38,13 @@ export function handleNewToken(event: TokenCreated): void {
token.tx = event.transaction.hash.toHex()
token.block = event.block.number.toI32()
token.nft = event.params.creator.toHexString()
token.name = event.params.name
token.symbol = event.params.symbol
token.decimals = 18
token.supply = decimal.ZERO
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
const globalStats = getGlobalStats()
globalStats.datatokenCount = globalStats.datatokenCount.plus(integer.ONE)

View File

@ -1,4 +1,4 @@
import { BigInt } from '@graphprotocol/graph-ts'
import { BigInt, log } from '@graphprotocol/graph-ts'
import {
ExchangeActivated,
ExchangeAllowedSwapperChanged,
@ -19,20 +19,32 @@ import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
export function handleExchangeCreated(event: ExchangeCreated): void {
log.warning(
'handleExchangeCreated baseToken {} ; dataToken {} ; exchangeOwner {} ; fixedRate {}',
[
event.params.baseToken.toHexString(),
event.params.dataToken.toHexString(),
event.params.exchangeOwner.toHexString(),
event.params.fixedRate.toBigDecimal().toString()
]
)
const fixedRateExchange = new FixedRateExchange(
event.params.exchangeId.toHexString()
)
const user = getUser(event.params.exchangeOwner.toHexString())
fixedRateExchange.owner = user.id
fixedRateExchange.datatoken = event.params.dataToken.toHexString()
fixedRateExchange.baseToken = event.params.baseToken.toHexString()
// fixedRateExchange.baseTokenSymbol = getTokenSymbol(event.params.baseToken)
fixedRateExchange.active = false
fixedRateExchange.datatoken = getToken(
event.params.dataToken.toHexString()
).id
fixedRateExchange.baseToken = getToken(
event.params.baseToken.toHexString()
).id
fixedRateExchange.price = weiToDecimal(
event.params.fixedRate.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
fixedRateExchange.active = false
fixedRateExchange.price = event.params.fixedRate.toBigDecimal()
fixedRateExchange.createdTimestamp = event.block.timestamp.toI32()
fixedRateExchange.tx = event.transaction.hash.toHex()
fixedRateExchange.block = event.block.number.toI32()
fixedRateExchange.save()
}
@ -145,13 +157,6 @@ export function handleSwap(event: Swapped): void {
event.params.exchangeId.toHex()
)
// reduce supply if the fixed rate is not minting tokens
if (fixedRateExchange.isMinter || fixedRateExchange.withMint) {
fixedRateExchange.supply = fixedRateExchange.supply.minus(
event.params.dataTokenSwappedAmount
)
}
const swap = new FixedRateExchangeSwap(
getUpdateOrSwapId(
event.transaction.hash.toHex(),

View File

@ -3,7 +3,7 @@ import { getToken } from './tokenUtils'
export function createDispenser(address: string): Dispenser {
const dispenser = new Dispenser(address)
dispenser.datatoken = getToken(address).id
dispenser.token = getToken(address).id
dispenser.save()
return dispenser
}

View File

@ -1,10 +1,11 @@
import { Address } from '@graphprotocol/graph-ts'
import { Address, log } from '@graphprotocol/graph-ts'
import { Token } from '../../@types/schema'
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
import { integer } from './constants'
import { getGlobalStats } from './globalUtils'
export function createToken(address: string): Token {
log.debug('started creating token with address: {}', [address])
const token = new Token(address)
const contract = ERC20.bind(Address.fromString(address))
token.name = contract.name()

View File

@ -8,9 +8,9 @@ dataSources:
name: ERC721Factory
network: rinkeby
source:
address: '0xa15024b732A8f2146423D14209eFd074e61964F3'
address: '0xe4B39C90355899DB8f625D879B44Fa9C5Cdde550'
abi: ERC721Factory
startBlock: 9759283
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
@ -30,9 +30,9 @@ dataSources:
name: FixedRateExchange
network: rinkeby
source:
address: '0x235C9bE4D23dCbd16c1Bf89ec839cb7C452FD9e9'
address: '0x7084f7353bB7cfc92A65e7d23987Cb5D1A3Fb9b2'
abi: FixedRateExchange
startBlock: 9759283
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
@ -43,6 +43,8 @@ dataSources:
abis:
- name: FixedRateExchange
file: ./abis/FixedRateExchange.json
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
- event: ExchangeCreated(indexed bytes32,indexed address,indexed address,address,uint256)
handler: handleExchangeCreated
@ -62,9 +64,9 @@ dataSources:
name: Dispenser
network: rinkeby
source:
address: '0x5FFE6649C7562F3bee1ca114c7c3316BF4B45b50'
address: '0xa8fFDd525835795C940370FB816f82a5F7F5F860'
abi: Dispenser
startBlock: 9759283
startBlock: 9984045
mapping:
kind: ethereum/events
apiVersion: 0.0.5
@ -193,5 +195,3 @@ templates:
handler: handleState
- event: TokenURIUpdate(indexed address,string,uint256,uint256,uint256)
handler: handleTokenUriUpdate
features:
- nonFatalErrors

View File

@ -193,5 +193,3 @@ templates:
handler: handleState
- event: TokenURIUpdate(indexed address,string,uint256,uint256,uint256)
handler: handleTokenUriUpdate
features:
- nonFatalErrors