Store eventIndex.
This commit is contained in:
parent
ec9d7e733f
commit
915df7a440
|
@ -121,6 +121,7 @@ type Nft @entity{
|
|||
type NftData @entity{
|
||||
"nft address+key"
|
||||
id: ID!
|
||||
tx: String!
|
||||
nft: Nft!
|
||||
key: Bytes
|
||||
value: Bytes
|
||||
|
@ -353,6 +354,7 @@ type OPC @entity {
|
|||
"fee in percent taken by OPC from providerFees"
|
||||
providerFee: BigDecimal
|
||||
approvedTokens: [Token!]
|
||||
tx: String!
|
||||
}
|
||||
|
||||
enum NftUpdateType {
|
||||
|
@ -386,6 +388,7 @@ type NftUpdate @entity {
|
|||
|
||||
type Template @entity{
|
||||
id: ID!
|
||||
tx: String!
|
||||
fixedRateTemplates: [String!]
|
||||
dispenserTemplates: [String!]
|
||||
ssTemplates: [String!]
|
||||
|
@ -468,6 +471,7 @@ type VeDelegation @entity {
|
|||
cancelTime: BigInt!
|
||||
expireTime: BigInt!
|
||||
block: Int!
|
||||
tx: String!
|
||||
}
|
||||
|
||||
type VeOCEAN @entity {
|
||||
|
@ -551,6 +555,7 @@ enum DFHistoryType {
|
|||
type DFAvailableClaim @entity {
|
||||
"id = {userId}-{tokenId}"
|
||||
id: ID!
|
||||
txId: String!
|
||||
receiver: DFReward!
|
||||
amount: BigDecimal!
|
||||
token: Token!
|
||||
|
@ -573,6 +578,7 @@ type DFHistory @entity {
|
|||
type DFReward @entity {
|
||||
"id = {user address}"
|
||||
id: ID!
|
||||
txId: String!
|
||||
receiver: User!
|
||||
availableClaims: [DFAvailableClaim!] @derivedFrom(field: "receiver")
|
||||
history: [DFHistory!] @derivedFrom(field: "receiver")
|
||||
|
@ -584,7 +590,7 @@ type NftTransferHistory @entity {
|
|||
nft: Nft!
|
||||
oldOwner: User!
|
||||
newOwner: User!
|
||||
txId: String
|
||||
txId: String!
|
||||
timestamp: Int!
|
||||
block: Int!
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ export function handleAllocated(event: Allocated): void {
|
|||
// loop all allocations
|
||||
const token = getToken(event.params.tokenAddress, false)
|
||||
for (let i = 0; i < event.params.tos.length; i++) {
|
||||
const reward = getDFReward(event.params.tos[i])
|
||||
const reward = getDFReward(event.params.tos[i], event.transaction.hash.toHex())
|
||||
|
||||
const history = new DFHistory(
|
||||
event.params.tos[i].toHexString() +
|
||||
'-' +
|
||||
|
@ -32,7 +33,8 @@ export function handleAllocated(event: Allocated): void {
|
|||
// update available claims
|
||||
const claim = getDFAvailableClaim(
|
||||
event.params.tos[i],
|
||||
event.params.tokenAddress
|
||||
event.params.tokenAddress,
|
||||
event.transaction.hash.toHex()
|
||||
)
|
||||
claim.amount = claim.amount.plus(history.amount)
|
||||
claim.save()
|
||||
|
@ -42,7 +44,7 @@ export function handleAllocated(event: Allocated): void {
|
|||
export function handleClaimed(event: Claimed): void {
|
||||
// loop all allocations
|
||||
const token = getToken(event.params.tokenAddress, false)
|
||||
const reward = getDFReward(event.params.to)
|
||||
const reward = getDFReward(event.params.to, event.transaction.hash.toHex())
|
||||
const history = new DFHistory(
|
||||
event.transaction.hash.toHex() + '-' + event.logIndex.toString()
|
||||
)
|
||||
|
@ -59,7 +61,7 @@ export function handleClaimed(event: Claimed): void {
|
|||
history.save()
|
||||
|
||||
// update available claims
|
||||
const claim = getDFAvailableClaim(event.params.to, event.params.tokenAddress)
|
||||
const claim = getDFAvailableClaim(event.params.to, event.params.tokenAddress, event.transaction.hash.toHex())
|
||||
claim.amount = claim.amount.minus(history.amount)
|
||||
claim.save()
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ export function handleActivate(event: DispenserActivated): void {
|
|||
)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
dispenser.active = true
|
||||
dispenser.tx = event.transaction.hash.toHex()
|
||||
dispenser.save()
|
||||
}
|
||||
|
||||
|
@ -67,6 +68,7 @@ export function handleDeactivate(event: DispenserDeactivated): void {
|
|||
)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
dispenser.active = false
|
||||
dispenser.tx = event.transaction.hash.toHex()
|
||||
dispenser.save()
|
||||
}
|
||||
|
||||
|
@ -76,6 +78,7 @@ export function handleAllowedSwapperChanged(
|
|||
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
dispenser.allowedSwapper = event.params.newAllowedSwapper.toHex()
|
||||
dispenser.tx = event.transaction.hash.toHex()
|
||||
dispenser.save()
|
||||
}
|
||||
|
||||
|
@ -111,5 +114,6 @@ export function handleOwnerWinthdraw(event: OwnerWithdrawed): void {
|
|||
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
|
||||
const dispenser = getDispenser(dispenserID)
|
||||
dispenser.balance = decimal.ZERO
|
||||
dispenser.tx = event.transaction.hash.toHex()
|
||||
dispenser.save()
|
||||
}
|
||||
|
|
|
@ -149,6 +149,7 @@ export function handlePublishMarketFeeChanged(
|
|||
event.params.PublishMarketFeeAmount.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
// TODO - shold we have a history
|
||||
}
|
||||
|
@ -163,6 +164,7 @@ export function handleAddedMinter(event: AddedMinter): void {
|
|||
if (!existingRoles.includes(event.params.user.toHexString()))
|
||||
existingRoles.push(event.params.user.toHexString())
|
||||
token.minter = existingRoles
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -179,6 +181,7 @@ export function handleRemovedMinter(event: RemovedMinter): void {
|
|||
if (role !== event.params.user.toHexString()) newList.push(role)
|
||||
}
|
||||
token.minter = newList
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -190,6 +193,7 @@ export function handleAddedPaymentManager(event: AddedPaymentManager): void {
|
|||
if (!existingRoles.includes(event.params.user.toHexString()))
|
||||
existingRoles.push(event.params.user.toHexString())
|
||||
token.paymentManager = existingRoles
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
export function handleRemovedPaymentManager(
|
||||
|
@ -207,6 +211,7 @@ export function handleRemovedPaymentManager(
|
|||
if (role !== event.params.user.toHexString()) newList.push(role)
|
||||
}
|
||||
token.paymentManager = newList
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
export function handleCleanedPermissions(event: CleanedPermissions): void {
|
||||
|
@ -217,12 +222,14 @@ export function handleCleanedPermissions(event: CleanedPermissions): void {
|
|||
const nft = Nft.load(token.nft as string)
|
||||
if (nft) token.paymentCollector = nft.owner
|
||||
else token.paymentCollector = '0x0000000000000000000000000000000000000000'
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
|
||||
export function handleNewPaymentCollector(event: NewPaymentCollector): void {
|
||||
const token = getToken(event.address, true)
|
||||
token.paymentCollector = event.params._newPaymentCollector.toHexString()
|
||||
token.tx = event.transaction.hash.toHex()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -245,6 +252,7 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
if (order) {
|
||||
order.providerFee = providerFee
|
||||
order.providerFeeValidUntil = event.params.validUntil
|
||||
order.tx = event.transaction.hash.toHex()
|
||||
order.save()
|
||||
return
|
||||
}
|
||||
|
@ -253,6 +261,7 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
if (orderReuse) {
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
orderReuse.tx = event.transaction.hash.toHex()
|
||||
orderReuse.save()
|
||||
} else {
|
||||
orderReuse = new OrderReuse(event.transaction.hash.toHex())
|
||||
|
|
|
@ -35,6 +35,7 @@ export function handleOPCFeeChanged(event: OPCFeeChanged): void {
|
|||
event.params.newProviderFee.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
opc.tx = event.transaction.hash.toHex()
|
||||
opc.save()
|
||||
}
|
||||
|
||||
|
@ -72,6 +73,7 @@ export function handleTokenAdded(event: TokenAdded): void {
|
|||
}
|
||||
|
||||
opc.approvedTokens = existingTokens
|
||||
opc.tx = event.transaction.hash.toHex()
|
||||
|
||||
opc.save()
|
||||
}
|
||||
|
@ -89,11 +91,13 @@ export function handleTokenRemoved(event: TokenRemoved): void {
|
|||
if (role != event.params.token.toHexString()) newList.push(role)
|
||||
}
|
||||
opc.approvedTokens = newList
|
||||
opc.tx = event.transaction.hash.toHex()
|
||||
opc.save()
|
||||
}
|
||||
export function handleSSContractAdded(event: SSContractAdded): void {
|
||||
// add token to approvedTokens
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
let existingContracts: string[]
|
||||
if (!templates.ssTemplates) existingContracts = []
|
||||
else existingContracts = templates.ssTemplates as string[]
|
||||
|
@ -104,6 +108,7 @@ export function handleSSContractAdded(event: SSContractAdded): void {
|
|||
}
|
||||
export function handleSSContractRemoved(event: SSContractRemoved): void {
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
const newList: string[] = []
|
||||
let existingContracts: string[]
|
||||
if (!templates.ssTemplates) existingContracts = []
|
||||
|
@ -124,6 +129,7 @@ export function handleFixedRateContractAdded(
|
|||
FixedRateExchange.create(event.params.contractAddress)
|
||||
// add token to approvedTokens
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
let existingContracts: string[]
|
||||
if (!templates.fixedRateTemplates) existingContracts = []
|
||||
else existingContracts = templates.fixedRateTemplates as string[]
|
||||
|
@ -136,6 +142,7 @@ export function handleFixedRateContractRemoved(
|
|||
event: FixedRateContractRemoved
|
||||
): void {
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
const newList: string[] = []
|
||||
let existingContracts: string[]
|
||||
if (!templates.fixedRateTemplates) existingContracts = []
|
||||
|
@ -155,6 +162,7 @@ export function handleDispenserContractAdded(
|
|||
Dispenser.create(event.params.contractAddress)
|
||||
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
let existingContracts: string[]
|
||||
if (!templates.dispenserTemplates) existingContracts = []
|
||||
else existingContracts = templates.dispenserTemplates as string[]
|
||||
|
@ -167,6 +175,7 @@ export function handleDispenserContractRemoved(
|
|||
event: DispenserContractRemoved
|
||||
): void {
|
||||
const templates = getTemplates()
|
||||
templates.tx = event.transaction.hash.toHex()
|
||||
const newList: string[] = []
|
||||
let existingContracts: string[]
|
||||
if (!templates.dispenserTemplates) existingContracts = []
|
||||
|
|
|
@ -89,6 +89,7 @@ export function handleMintStateChanged(event: ExchangeMintStateChanged): void {
|
|||
)
|
||||
const fixedRateExchange = getFixedRateExchange(fixedRateId)
|
||||
fixedRateExchange.withMint = event.params.withMint
|
||||
fixedRateExchange.tx = event.transaction.hash.toHex()
|
||||
fixedRateExchange.save()
|
||||
}
|
||||
|
||||
|
@ -226,6 +227,7 @@ export function handleSwap(event: Swapped): void {
|
|||
)
|
||||
datatoken.lastPriceToken = priceToken.id
|
||||
datatoken.lastPriceValue = fixedRateExchange.price
|
||||
datatoken.tx = event.transaction.hash.toHex()
|
||||
datatoken.save()
|
||||
}
|
||||
|
||||
|
@ -244,6 +246,7 @@ export function handlePublishMarketFeeChanged(
|
|||
event.params.swapFee.toBigDecimal(),
|
||||
BigInt.fromI32(18).toI32()
|
||||
)
|
||||
fixedRateExchange.tx = event.transaction.hash.toHex()
|
||||
fixedRateExchange.save()
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +264,7 @@ export function handleTokenCollected(event: TokenCollected): void {
|
|||
fixedRateExchange.baseTokenBalance.minus(
|
||||
weiToDecimal(event.params.amount.toBigDecimal(), baseToken.decimals)
|
||||
)
|
||||
|
||||
fixedRateExchange.tx = event.transaction.hash.toHex()
|
||||
fixedRateExchange.save()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,6 +281,7 @@ export function handleNftData(event: DataChanged): void {
|
|||
if (data == null) {
|
||||
data = new NftData(id)
|
||||
}
|
||||
data.tx = event.transaction.hash.toHex()
|
||||
data.key = event.params.key
|
||||
data.value = event.params.value
|
||||
data.nft = nft.id
|
||||
|
|
|
@ -1,31 +1,34 @@
|
|||
import { Address, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import { Address, BigDecimal, String } from '@graphprotocol/graph-ts'
|
||||
import { DFAvailableClaim, DFReward } from '../../@types/schema'
|
||||
import { getUser } from './userUtils'
|
||||
|
||||
export function createDFReward(address: Address): DFReward {
|
||||
export function createDFReward(address: Address, txId: String): DFReward {
|
||||
const dfRewards = new DFReward(address.toHexString())
|
||||
const user = getUser(address.toHexString())
|
||||
dfRewards.txId = txId
|
||||
dfRewards.receiver = user.id
|
||||
dfRewards.save()
|
||||
return dfRewards
|
||||
}
|
||||
|
||||
export function getDFReward(address: Address): DFReward {
|
||||
export function getDFReward(address: Address, txId: String): DFReward {
|
||||
let dfRewards = DFReward.load(address.toHexString())
|
||||
if (dfRewards === null) {
|
||||
dfRewards = createDFReward(address)
|
||||
dfRewards = createDFReward(address, txId)
|
||||
}
|
||||
return dfRewards
|
||||
}
|
||||
|
||||
export function getDFAvailableClaim(
|
||||
user: Address,
|
||||
token: Address
|
||||
token: Address,
|
||||
txId: String,
|
||||
): DFAvailableClaim {
|
||||
const id = user.toHexString() + '-' + token.toHexString()
|
||||
let dfClaim = DFAvailableClaim.load(id)
|
||||
if (dfClaim == null) {
|
||||
dfClaim = new DFAvailableClaim(id)
|
||||
dfClaim.txId = txId
|
||||
dfClaim.receiver = user.toHexString()
|
||||
dfClaim.amount = BigDecimal.zero()
|
||||
dfClaim.token = token.toHexString()
|
||||
|
|
Loading…
Reference in New Issue