diff --git a/abis/SftRolesRegistry.json b/abis/SftRolesRegistry.json deleted file mode 100644 index 2b43383..0000000 --- a/abis/SftRolesRegistry.json +++ /dev/null @@ -1,586 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "_operator", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "_isApproved", - "type": "bool" - } - ], - "name": "RoleApprovalForAll", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "_role", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenAmount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "_grantor", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "_grantee", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "_expirationDate", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "bool", - "name": "_revocable", - "type": "bool" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "RoleGranted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "_role", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenAmount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "_revoker", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "_grantee", - "type": "address" - } - ], - "name": "RoleRevoked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "_grantor", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "_tokenAmount", - "type": "uint256" - } - ], - "name": "Withdrew", - "type": "event" - }, - { - "inputs": [], - "name": "UNIQUE_ROLE", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "deposits", - "outputs": [ - { - "internalType": "address", - "name": "grantor", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tokenAmount", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tokenAmount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "grantor", - "type": "address" - }, - { - "internalType": "address", - "name": "grantee", - "type": "address" - }, - { - "internalType": "uint64", - "name": "expirationDate", - "type": "uint64" - }, - { - "internalType": "bool", - "name": "revocable", - "type": "bool" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "internalType": "struct IERCXXXX.RoleAssignment", - "name": "_grantRoleData", - "type": "tuple" - } - ], - "name": "grantRoleFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "_grantor", - "type": "address" - }, - { - "internalType": "address", - "name": "_operator", - "type": "address" - } - ], - "name": "isRoleApprovedForAll", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256[]", - "name": "", - "type": "uint256[]" - }, - { - "internalType": "uint256[]", - "name": "", - "type": "uint256[]" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "onERC1155BatchReceived", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "name": "onERC1155Received", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "_role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "_grantee", - "type": "address" - } - ], - "name": "revokeRoleFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "_role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "_grantee", - "type": "address" - } - ], - "name": "roleData", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "grantee", - "type": "address" - }, - { - "internalType": "uint64", - "name": "expirationDate", - "type": "uint64" - }, - { - "internalType": "bool", - "name": "revocable", - "type": "bool" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "internalType": "struct IERCXXXX.RoleData", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "_role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "_grantee", - "type": "address" - } - ], - "name": "roleExpirationDate", - "outputs": [ - { - "internalType": "uint64", - "name": "expirationDate_", - "type": "uint64" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "_operator", - "type": "address" - }, - { - "internalType": "bool", - "name": "_isApproved", - "type": "bool" - } - ], - "name": "setRoleApprovalForAll", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "tokenApprovals", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] \ No newline at end of file diff --git a/src/sftRolesRegistry/index.ts b/src/sftRolesRegistry/index.ts deleted file mode 100644 index 34daa46..0000000 --- a/src/sftRolesRegistry/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { handleRoleGranted } from './role-granted-handler' -export { handleRoleRevoked } from './role-revoked-handler' -export { handleRoleApprovalForAll } from './role-approval-for-all-handler' diff --git a/src/sftRolesRegistry/role-approval-for-all-handler.ts b/src/sftRolesRegistry/role-approval-for-all-handler.ts deleted file mode 100644 index af518ff..0000000 --- a/src/sftRolesRegistry/role-approval-for-all-handler.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { RoleApprovalForAll } from '../../generated/SftRolesRegistry/SftRolesRegistry' -import { findOrCreateRoleApproval, findOrCreateAccount, findOrCreateRolesRegistry } from '../../utils' -import { log } from '@graphprotocol/graph-ts' - -/** -@dev This handler is called when a role approval for all is set. -@param event RoleApprovalForAll The event emitted by the contract. - -Example: - event RoleApprovalForAll(address indexed _tokenAddress, address indexed _operator, bool _isApproved); -*/ -export function handleRoleApprovalForAll(event: RoleApprovalForAll): void { - const rolesRegistryAddress = event.address.toHex() - const grantorAddress = event.transaction.from.toHex() - const operatorAddress = event.params._operator.toHex() - const tokenAddress = event.params._tokenAddress.toHex() - const isApproved = event.params._isApproved - - const grantor = findOrCreateAccount(grantorAddress) - const operator = findOrCreateAccount(operatorAddress) - const rolesRegistry = findOrCreateRolesRegistry(rolesRegistryAddress) - const roleApproval = findOrCreateRoleApproval(rolesRegistry, grantor, operator, tokenAddress) - roleApproval.isApproved = isApproved - roleApproval.save() - - log.warning('[sftRolesRegistry][handleRoleApprovalForAll] Updated RoleAssignment Approval: {} Tx: {}', [ - roleApproval.id, - event.transaction.hash.toHex(), - ]) -} diff --git a/src/sftRolesRegistry/role-granted-handler.ts b/src/sftRolesRegistry/role-granted-handler.ts deleted file mode 100644 index 5a173fc..0000000 --- a/src/sftRolesRegistry/role-granted-handler.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { log } from '@graphprotocol/graph-ts' -import { RoleGranted } from '../../generated/SftRolesRegistry/SftRolesRegistry' -import { Account, Nft } from '../../generated/schema' -import { generateERC721NftId, findOrCreateAccount, findOrCreateRoleAssignment } from '../../utils' - -export function handleRoleGranted(event: RoleGranted): void { - const tokenId = event.params._tokenId - const tokenAddress = event.params._tokenAddress.toHex() - - const nftId = generateERC721NftId(tokenAddress, tokenId) - const nft = Nft.load(nftId) - if (!nft) { - log.warning('[handleRoleGranted] NFT {} does not exist, skipping...', [nftId]) - return - } - - const grantorAddress = event.params._grantor.toHex().toLowerCase() - const grantorAccount = Account.load(grantorAddress) - if (!grantorAccount) { - log.warning('[handleRoleGranted] grantor {} does not exist, skipping...', [grantorAddress]) - return - } - if (grantorAccount.id != nft.owner) { - log.warning('[handleRoleGranted] NFT {} is not owned by {}, skipping...', [nftId, grantorAccount.id]) - return - } - - const granteeAccount = findOrCreateAccount(event.params._grantee.toHex()) - const roleAssignment = findOrCreateRoleAssignment(event, grantorAccount, granteeAccount, nft) - log.warning('[handleRoleGranted] roleAssignment: {} NFT: {} Tx: {}', [ - roleAssignment.id, - nftId, - event.transaction.hash.toHex(), - ]) -} diff --git a/src/sftRolesRegistry/role-revoked-handler.ts b/src/sftRolesRegistry/role-revoked-handler.ts deleted file mode 100644 index 6f8bd99..0000000 --- a/src/sftRolesRegistry/role-revoked-handler.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { log } from '@graphprotocol/graph-ts' -import { RoleRevoked } from '../../generated/SftRolesRegistry/SftRolesRegistry' -import { Account, Nft, RoleAssignment } from '../../generated/schema' -import { findOrCreateRolesRegistry, generateERC721NftId, generateRoleAssignmentId } from '../../utils' - -export function handleRoleRevoked(event: RoleRevoked): void { - const tokenId = event.params._tokenId - const tokenAddress = event.params._tokenAddress.toHexString() - - const nftId = generateERC721NftId(tokenAddress, tokenId) - const nft = Nft.load(nftId) - if (!nft) { - log.warning('[handleRoleRevoked] NFT {} does not exist, skipping...', [nftId]) - return - } - - const revokerAddress = event.params._revoker.toHex().toLowerCase() - const revoker = Account.load(revokerAddress) - if (!revoker) { - log.warning('[handleRoleGranted] revoker {} does not exist, skipping...', [revokerAddress]) - return - } - - const granteeAddress = event.params._grantee.toHex().toLowerCase() - const grantee = Account.load(granteeAddress) - if (!grantee) { - log.warning('[handleRoleGranted] grantee {} does not exist, skipping...', [granteeAddress]) - return - } - const rolesRegistry = findOrCreateRolesRegistry(event.address.toHex()) - const roleAssignmentId = generateRoleAssignmentId(rolesRegistry, revoker, grantee, nft, event.params._role) - const roleAssignment = RoleAssignment.load(roleAssignmentId) - if (!roleAssignment) { - log.warning('[handleRoleRevoked] RoleAssignment {} does not exist, skipping...', [roleAssignmentId]) - return - } - if (event.block.timestamp > roleAssignment.expirationDate) { - log.warning('[handleRoleRevoked] RoleAssignment {} already expired, skipping...', [roleAssignmentId]) - return - } - - roleAssignment.expirationDate = event.block.timestamp - roleAssignment.save() - log.warning('[handleRoleRevoked] Revoked RoleAssignment: {} NFT: {} Tx: {}', [ - roleAssignmentId, - nftId, - event.transaction.hash.toHex(), - ]) -} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 4a0fb89..9ad5d19 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -82,35 +82,4 @@ dataSources: handler: handleRoleRevoked - event: RoleApprovalForAll(indexed address,indexed address,bool) handler: handleRoleApprovalForAll - file: ./src/erc-7432/index.ts - - - name: SftRolesRegistry - kind: ethereum - network: {{network}} - source: - abi: SftRolesRegistry -{{#isSelfHosted}} - startBlock: 1 -{{/isSelfHosted}} - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - - RoleAssignment - - RoleApproval - abis: - - name: SftRolesRegistry - file: ./abis/SftRolesRegistry.json - eventHandlers: - - event: RoleGranted(indexed uint256,indexed bytes32,address,uint256,uint256,address,address,uint64,bool,bytes) - handler: handleRoleGranted - - event: RoleRevoked(indexed uint256,indexed bytes32,address,uint256,uint256,address,address) - handler: handleRoleRevoked - - event: RoleApprovalForAll(indexed address,indexed address,bool) - handler: handleRoleApprovalForAll - - event: Withdrew(indexed uint256,indexed address,address,uint256,uint256) - handler: handleWithdrew - file: ./src/erc-7432/index.ts + file: ./src/erc-7432/index.ts \ No newline at end of file