* 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: graph-node:
image: graphprotocol/graph-node:v0.25.0 image: graphprotocol/graph-node:v0.25.0
ports: ports:
- '8000:8000' - '9000:8000'
- '8001:8001' - '8001:8001'
- '8020:8020' - '8020:8020'
- '8030:8030' - '8030:8030'

View File

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

View File

@ -1,3 +1,4 @@
import { log } from '@graphprotocol/graph-ts'
import { import {
DispenserActivated, DispenserActivated,
DispenserAllowedSwapperChanged, DispenserAllowedSwapperChanged,
@ -6,13 +7,34 @@ import {
TokensDispensed TokensDispensed
} from '../@types/Dispenser/Dispenser' } from '../@types/Dispenser/Dispenser'
import { DispenserCreated } from '../@types/ERC721Factory/ERC721Factory' import { DispenserCreated } from '../@types/ERC721Factory/ERC721Factory'
import { DispenserTransaction } from '../@types/schema' import { Dispenser, DispenserTransaction } from '../@types/schema'
import { decimal } from './utils/constants' 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' import { getUser } from './utils/userUtils'
export function handleNewDispenser(event: DispenserCreated): void { 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 { 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 { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
import { Nft, Token } from '../@types/schema' import { Nft, Token } from '../@types/schema'
import { decimal, integer } from './utils/constants' import { decimal, integer } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getGlobalStats } from './utils/globalUtils' import { getGlobalStats } from './utils/globalUtils'
import { getUser } from './utils/userUtils' import { getUser } from './utils/userUtils'
export function handleNftCreated(event: NFTCreated): void { export function handleNftCreated(event: NFTCreated): void {
log.warning('handleNftCreated is starting', [])
const nft = new Nft(event.params.newTokenAddress.toHexString()) const nft = new Nft(event.params.newTokenAddress.toHexString())
const user = getUser(event.params.admin.toHexString()) const user = getUser(event.params.admin.toHexString())
@ -24,6 +27,10 @@ export function handleNftCreated(event: NFTCreated): void {
} }
export function handleNewToken(event: TokenCreated): 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()) const token = new Token(event.params.newTokenAddress.toHexString())
token.isDatatoken = true token.isDatatoken = true
token.address = event.params.newTokenAddress.toHexString() token.address = event.params.newTokenAddress.toHexString()
@ -31,9 +38,13 @@ export function handleNewToken(event: TokenCreated): void {
token.tx = event.transaction.hash.toHex() token.tx = event.transaction.hash.toHex()
token.block = event.block.number.toI32() token.block = event.block.number.toI32()
token.nft = event.params.creator.toHexString()
token.name = event.params.name token.name = event.params.name
token.symbol = event.params.symbol
token.decimals = 18 token.decimals = 18
token.supply = decimal.ZERO token.supply = decimal.ZERO
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
const globalStats = getGlobalStats() const globalStats = getGlobalStats()
globalStats.datatokenCount = globalStats.datatokenCount.plus(integer.ONE) 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 { import {
ExchangeActivated, ExchangeActivated,
ExchangeAllowedSwapperChanged, ExchangeAllowedSwapperChanged,
@ -19,20 +19,32 @@ import { getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils' import { getUser } from './utils/userUtils'
export function handleExchangeCreated(event: ExchangeCreated): void { 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( const fixedRateExchange = new FixedRateExchange(
event.params.exchangeId.toHexString() event.params.exchangeId.toHexString()
) )
const user = getUser(event.params.exchangeOwner.toHexString()) const user = getUser(event.params.exchangeOwner.toHexString())
fixedRateExchange.owner = user.id fixedRateExchange.owner = user.id
fixedRateExchange.datatoken = event.params.dataToken.toHexString() fixedRateExchange.datatoken = getToken(
fixedRateExchange.baseToken = event.params.baseToken.toHexString() event.params.dataToken.toHexString()
// fixedRateExchange.baseTokenSymbol = getTokenSymbol(event.params.baseToken) ).id
fixedRateExchange.active = false fixedRateExchange.baseToken = getToken(
event.params.baseToken.toHexString()
).id
fixedRateExchange.price = weiToDecimal( fixedRateExchange.active = false
event.params.fixedRate.toBigDecimal(), fixedRateExchange.price = event.params.fixedRate.toBigDecimal()
BigInt.fromI32(18).toI32() fixedRateExchange.createdTimestamp = event.block.timestamp.toI32()
) fixedRateExchange.tx = event.transaction.hash.toHex()
fixedRateExchange.block = event.block.number.toI32()
fixedRateExchange.save() fixedRateExchange.save()
} }
@ -145,13 +157,6 @@ export function handleSwap(event: Swapped): void {
event.params.exchangeId.toHex() 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( const swap = new FixedRateExchangeSwap(
getUpdateOrSwapId( getUpdateOrSwapId(
event.transaction.hash.toHex(), event.transaction.hash.toHex(),

View File

@ -3,7 +3,7 @@ import { getToken } from './tokenUtils'
export function createDispenser(address: string): Dispenser { export function createDispenser(address: string): Dispenser {
const dispenser = new Dispenser(address) const dispenser = new Dispenser(address)
dispenser.datatoken = getToken(address).id dispenser.token = getToken(address).id
dispenser.save() dispenser.save()
return dispenser 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 { Token } from '../../@types/schema'
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20' import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
import { integer } from './constants' import { integer } from './constants'
import { getGlobalStats } from './globalUtils' import { getGlobalStats } from './globalUtils'
export function createToken(address: string): Token { export function createToken(address: string): Token {
log.debug('started creating token with address: {}', [address])
const token = new Token(address) const token = new Token(address)
const contract = ERC20.bind(Address.fromString(address)) const contract = ERC20.bind(Address.fromString(address))
token.name = contract.name() token.name = contract.name()

View File

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

View File

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