2021-12-02 12:08:47 +01:00
|
|
|
import { Nft, NftUpdate } from '../@types/schema'
|
2021-11-29 13:11:58 +01:00
|
|
|
import {
|
|
|
|
MetadataCreated,
|
|
|
|
MetadataState,
|
|
|
|
MetadataUpdated,
|
2022-02-18 12:09:18 +01:00
|
|
|
TokenURIUpdate,
|
|
|
|
AddedManager,
|
|
|
|
AddedTo725StoreList,
|
|
|
|
AddedToCreateERC20List,
|
|
|
|
AddedToMetadataList,
|
|
|
|
RemovedFrom725StoreList,
|
|
|
|
RemovedFromCreateERC20List,
|
|
|
|
RemovedFromMetadataList,
|
|
|
|
RemovedManager,
|
|
|
|
CleanedPermissions
|
2021-11-29 13:11:58 +01:00
|
|
|
} from '../@types/templates/ERC721Template/ERC721Template'
|
2021-12-02 12:08:47 +01:00
|
|
|
import { NftUpdateType } from './utils/constants'
|
2022-02-18 12:09:18 +01:00
|
|
|
import { getNftToken } from './utils/tokenUtils'
|
|
|
|
|
2021-12-02 12:08:47 +01:00
|
|
|
function getId(tx: string, nftAddress: string): string {
|
|
|
|
return `${tx}-${nftAddress}`
|
|
|
|
}
|
2021-11-29 13:11:58 +01:00
|
|
|
|
2022-02-18 12:09:18 +01:00
|
|
|
export function handleMetadataCreated(event: MetadataCreated): void {
|
2021-12-02 12:08:47 +01:00
|
|
|
const nftAddress = event.address.toHex()
|
|
|
|
const nft = Nft.load(nftAddress)
|
|
|
|
if (!nft) return
|
2021-11-29 13:11:58 +01:00
|
|
|
|
2021-12-02 12:08:47 +01:00
|
|
|
nft.assetState = event.params.state
|
2022-01-28 12:05:04 +01:00
|
|
|
nft.providerUrl = event.params.decryptorUrl.toString()
|
2022-02-17 13:00:54 +01:00
|
|
|
|
2021-12-02 12:08:47 +01:00
|
|
|
const nftUpdate = new NftUpdate(
|
|
|
|
getId(event.transaction.hash.toHex(), nftAddress)
|
|
|
|
)
|
|
|
|
|
|
|
|
nftUpdate.type = NftUpdateType.METADATA_CREATED
|
|
|
|
nftUpdate.userAddress = event.params.createdBy.toHex()
|
|
|
|
nftUpdate.assetState = event.params.state
|
|
|
|
|
2022-01-28 12:05:04 +01:00
|
|
|
nftUpdate.nft = nft.id
|
|
|
|
nftUpdate.providerUrl = nft.providerUrl
|
|
|
|
|
2021-12-02 12:08:47 +01:00
|
|
|
nftUpdate.timestamp = event.block.timestamp.toI32()
|
|
|
|
nftUpdate.tx = event.transaction.hash.toHex()
|
|
|
|
nftUpdate.block = event.block.number.toI32()
|
|
|
|
|
|
|
|
nftUpdate.save()
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
2022-02-18 12:09:18 +01:00
|
|
|
export function handleMetadataUpdated(event: MetadataUpdated): void {
|
2021-12-02 12:08:47 +01:00
|
|
|
const nftAddress = event.address.toHex()
|
|
|
|
const nft = Nft.load(nftAddress)
|
|
|
|
if (!nft) return
|
|
|
|
|
|
|
|
nft.assetState = event.params.state
|
|
|
|
|
|
|
|
const nftUpdate = new NftUpdate(
|
|
|
|
getId(event.transaction.hash.toHex(), nftAddress)
|
|
|
|
)
|
|
|
|
|
2022-02-24 15:32:25 +01:00
|
|
|
nftUpdate.nft = nft.id
|
2021-12-02 12:08:47 +01:00
|
|
|
nftUpdate.type = NftUpdateType.METADATA_UPDATED
|
|
|
|
nftUpdate.userAddress = event.params.updatedBy.toHex()
|
|
|
|
nftUpdate.assetState = event.params.state
|
|
|
|
|
|
|
|
nftUpdate.timestamp = event.block.timestamp.toI32()
|
|
|
|
nftUpdate.tx = event.transaction.hash.toHex()
|
|
|
|
nftUpdate.block = event.block.number.toI32()
|
|
|
|
|
|
|
|
nftUpdate.save()
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
2022-02-18 12:09:18 +01:00
|
|
|
export function handleMetadataState(event: MetadataState): void {
|
2021-12-02 12:08:47 +01:00
|
|
|
const nftAddress = event.address.toHex()
|
|
|
|
const nft = Nft.load(nftAddress)
|
|
|
|
if (!nft) return
|
|
|
|
|
|
|
|
nft.assetState = event.params.state
|
|
|
|
|
|
|
|
const nftUpdate = new NftUpdate(
|
|
|
|
getId(event.transaction.hash.toHex(), nftAddress)
|
|
|
|
)
|
|
|
|
|
2022-02-24 15:32:25 +01:00
|
|
|
nftUpdate.nft = nft.id
|
2021-12-02 12:08:47 +01:00
|
|
|
nftUpdate.type = NftUpdateType.STATE_UPDATED
|
|
|
|
nftUpdate.userAddress = event.params.updatedBy.toHex()
|
|
|
|
nftUpdate.assetState = event.params.state
|
|
|
|
|
|
|
|
nftUpdate.timestamp = event.block.timestamp.toI32()
|
|
|
|
nftUpdate.tx = event.transaction.hash.toHex()
|
|
|
|
nftUpdate.block = event.block.number.toI32()
|
|
|
|
|
|
|
|
nftUpdate.save()
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleTokenUriUpdate(event: TokenURIUpdate): void {
|
|
|
|
const nftAddress = event.address.toHex()
|
|
|
|
const nft = Nft.load(nftAddress)
|
|
|
|
|
|
|
|
if (!nft) return
|
|
|
|
|
2022-01-28 12:05:04 +01:00
|
|
|
nft.tokenUri = event.params.tokenURI.toString()
|
2021-12-02 12:08:47 +01:00
|
|
|
|
|
|
|
const nftUpdate = new NftUpdate(
|
|
|
|
getId(event.transaction.hash.toHex(), nftAddress)
|
|
|
|
)
|
2022-02-24 15:32:25 +01:00
|
|
|
nftUpdate.nft = nft.id
|
2021-12-02 12:08:47 +01:00
|
|
|
nftUpdate.type = NftUpdateType.TOKENURI_UPDATED
|
|
|
|
nftUpdate.userAddress = event.params.updatedBy.toHex()
|
2022-01-28 12:05:04 +01:00
|
|
|
nftUpdate.tokenUri = nft.tokenUri
|
2021-12-02 12:08:47 +01:00
|
|
|
nftUpdate.timestamp = event.block.timestamp.toI32()
|
|
|
|
nftUpdate.tx = event.transaction.hash.toHex()
|
|
|
|
nftUpdate.block = event.block.number.toI32()
|
|
|
|
|
|
|
|
nftUpdate.save()
|
|
|
|
nft.save()
|
|
|
|
}
|
2022-02-18 12:09:18 +01:00
|
|
|
|
|
|
|
// roles
|
|
|
|
export function handleAddedManager(event: AddedManager): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.managerRole) existingRoles = []
|
|
|
|
else existingRoles = nft.managerRole as string[]
|
|
|
|
if (!existingRoles.includes(event.params.user.toHexString()))
|
|
|
|
existingRoles.push(event.params.user.toHexString())
|
|
|
|
nft.managerRole = existingRoles
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
export function handleRemovedManager(event: RemovedManager): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
const newList: string[] = []
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.managerRole) existingRoles = []
|
|
|
|
else existingRoles = nft.managerRole as string[]
|
|
|
|
if (!existingRoles || existingRoles.length < 1) return
|
|
|
|
while (existingRoles.length > 0) {
|
|
|
|
const role = existingRoles.shift().toString()
|
|
|
|
if (!role) break
|
|
|
|
if (role !== event.params.user.toHexString()) newList.push(role)
|
|
|
|
}
|
|
|
|
nft.managerRole = newList
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
// storeUpdater
|
|
|
|
export function handleAddedTo725StoreList(event: AddedTo725StoreList): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.storeUpdateRole) existingRoles = []
|
|
|
|
else existingRoles = nft.storeUpdateRole as string[]
|
|
|
|
if (!existingRoles.includes(event.params.user.toHexString()))
|
|
|
|
existingRoles.push(event.params.user.toHexString())
|
|
|
|
nft.storeUpdateRole = existingRoles
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleRemovedFrom725StoreList(
|
|
|
|
event: RemovedFrom725StoreList
|
|
|
|
): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
const newList: string[] = []
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.storeUpdateRole) existingRoles = []
|
|
|
|
else existingRoles = nft.storeUpdateRole as string[]
|
|
|
|
if (!existingRoles || existingRoles.length < 1) return
|
|
|
|
while (existingRoles.length > 0) {
|
|
|
|
const role = existingRoles.shift().toString()
|
|
|
|
if (!role) break
|
|
|
|
if (role !== event.params.user.toHexString()) newList.push(role)
|
|
|
|
}
|
|
|
|
nft.storeUpdateRole = newList
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
// erc20Deployer
|
|
|
|
export function handleAddedToCreateERC20List(
|
|
|
|
event: AddedToCreateERC20List
|
|
|
|
): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.erc20DeployerRole) existingRoles = []
|
|
|
|
else existingRoles = nft.erc20DeployerRole as string[]
|
|
|
|
if (!existingRoles.includes(event.params.user.toHexString()))
|
|
|
|
existingRoles.push(event.params.user.toHexString())
|
|
|
|
nft.erc20DeployerRole = existingRoles
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleRemovedFromCreateERC20List(
|
|
|
|
event: RemovedFromCreateERC20List
|
|
|
|
): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
const newList: string[] = []
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.erc20DeployerRole) existingRoles = []
|
|
|
|
else existingRoles = nft.erc20DeployerRole as string[]
|
|
|
|
if (!existingRoles || existingRoles.length < 1) return
|
|
|
|
while (existingRoles.length > 0) {
|
|
|
|
const role = existingRoles.shift().toString()
|
|
|
|
if (!role) break
|
|
|
|
if (role !== event.params.user.toHexString()) newList.push(role)
|
|
|
|
}
|
|
|
|
nft.erc20DeployerRole = newList
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
// metadata updater
|
|
|
|
export function handleAddedToMetadataList(event: AddedToMetadataList): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.metadataRole) existingRoles = []
|
|
|
|
else existingRoles = nft.metadataRole as string[]
|
|
|
|
if (!existingRoles.includes(event.params.user.toHexString()))
|
|
|
|
existingRoles.push(event.params.user.toHexString())
|
|
|
|
nft.metadataRole = existingRoles
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleRemovedFromMetadataList(
|
|
|
|
event: RemovedFromMetadataList
|
|
|
|
): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
const newList: string[] = []
|
|
|
|
let existingRoles: string[]
|
|
|
|
if (!nft.metadataRole) existingRoles = []
|
|
|
|
else existingRoles = nft.metadataRole as string[]
|
|
|
|
if (!existingRoles || existingRoles.length < 1) return
|
|
|
|
while (existingRoles.length > 0) {
|
|
|
|
const role = existingRoles.shift().toString()
|
|
|
|
if (!role) break
|
|
|
|
if (role !== event.params.user.toHexString()) newList.push(role)
|
|
|
|
}
|
|
|
|
nft.metadataRole = newList
|
|
|
|
nft.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function handleCleanedPermissions(event: CleanedPermissions): void {
|
|
|
|
const nft = getNftToken(event.address)
|
|
|
|
const newList: string[] = []
|
|
|
|
nft.metadataRole = newList
|
|
|
|
nft.erc20DeployerRole = newList
|
|
|
|
nft.storeUpdateRole = newList
|
|
|
|
nft.managerRole = newList
|
|
|
|
nft.save()
|
|
|
|
}
|