diff --git a/abis/v5/DataPermissionImplementation.json b/abis/v5/DataPermissionImplementation.json new file mode 100644 index 0000000..bf65bda --- /dev/null +++ b/abis/v5/DataPermissionImplementation.json @@ -0,0 +1,1434 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "AccessControlBadConfirmation", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "neededRole", + "type": "bytes32" + } + ], + "name": "AccessControlUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [], + "name": "ECDSAInvalidSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "ECDSAInvalidSignatureLength", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "ECDSAInvalidSignatureS", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "ERC1967InvalidImplementation", + "type": "error" + }, + { + "inputs": [], + "name": "ERC1967NonPayable", + "type": "error" + }, + { + "inputs": [], + "name": "EmptyGrant", + "type": "error" + }, + { + "inputs": [], + "name": "EmptyUrl", + "type": "error" + }, + { + "inputs": [], + "name": "EnforcedPause", + "type": "error" + }, + { + "inputs": [], + "name": "ExpectedPause", + "type": "error" + }, + { + "inputs": [], + "name": "FailedInnerCall", + "type": "error" + }, + { + "inputs": [], + "name": "GrantAlreadyUsed", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "InactivePermission", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInitialization", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expectedNonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "providedNonce", + "type": "uint256" + } + ], + "name": "InvalidNonce", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "fileOwner", + "type": "address" + }, + { + "internalType": "address", + "name": "requestor", + "type": "address" + } + ], + "name": "NotFileOwner", + "type": "error" + }, + { + "inputs": [], + "name": "NotInitializing", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "permissionOwner", + "type": "address" + }, + { + "internalType": "address", + "name": "requestor", + "type": "address" + } + ], + "name": "NotPermissionGrantor", + "type": "error" + }, + { + "inputs": [], + "name": "ServerAlreadyRegistered", + "type": "error" + }, + { + "inputs": [], + "name": "ServerNotFound", + "type": "error" + }, + { + "inputs": [], + "name": "ServerNotTrusted", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "existingUrl", + "type": "string" + }, + { + "internalType": "string", + "name": "providedUrl", + "type": "string" + } + ], + "name": "ServerUrlMismatch", + "type": "error" + }, + { + "inputs": [], + "name": "UUPSUnauthorizedCallContext", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot", + "type": "bytes32" + } + ], + "name": "UUPSUnsupportedProxiableUUID", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAddress", + "type": "error" + }, + { + "anonymous": false, + "inputs": [], + "name": "EIP712DomainChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "version", + "type": "uint64" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "grant", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "fileIds", + "type": "uint256[]" + } + ], + "name": "PermissionAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "PermissionRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "serverId", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "ServerAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "serverId", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "serverUrl", + "type": "string" + } + ], + "name": "ServerTrusted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "serverId", + "type": "address" + } + ], + "name": "ServerUntrusted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAINTAINER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UPGRADE_INTERFACE_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "string", + "name": "grant", + "type": "string" + }, + { + "internalType": "uint256[]", + "name": "fileIds", + "type": "uint256[]" + } + ], + "internalType": "struct IDataPermissions.PermissionInput", + "name": "permission", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "addPermission", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "dataRegistry", + "outputs": [ + { + "internalType": "contract IDataRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "eip712Domain", + "outputs": [ + { + "internalType": "bytes1", + "name": "fields", + "type": "bytes1" + }, + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "version", + "type": "string" + }, + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "verifyingContract", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "uint256[]", + "name": "extensions", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + } + ], + "name": "filePermissionIds", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleAdmin", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trustedForwarderAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "internalType": "contract IDataRegistry", + "name": "dataRegistryAddress", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "isActivePermission", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "forwarder", + "type": "address" + } + ], + "name": "isTrustedForwarder", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + } + ], + "name": "multicall", + "outputs": [ + { + "internalType": "bytes[]", + "name": "results", + "type": "bytes[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "permissionFileIds", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "grant", + "type": "string" + } + ], + "name": "permissionIdByGrant", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "permissions", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "address", + "name": "grantor", + "type": "address" + }, + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "string", + "name": "grant", + "type": "string" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bool", + "name": "isActive", + "type": "bool" + }, + { + "internalType": "uint256[]", + "name": "fileIds", + "type": "uint256[]" + } + ], + "internalType": "struct IDataPermissions.PermissionInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "permissionsCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "callerConfirmation", + "type": "address" + } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "name": "revokePermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "permissionId", + "type": "uint256" + } + ], + "internalType": "struct IDataPermissions.RevokePermissionInput", + "name": "revokePermissionInput", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "revokePermissionWithSignature", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "serverId", + "type": "address" + } + ], + "name": "servers", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "internalType": "struct IDataPermissions.Server", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "adminRole", + "type": "bytes32" + } + ], + "name": "setRoleAdmin", + "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": "serverId", + "type": "address" + }, + { + "internalType": "string", + "name": "serverUrl", + "type": "string" + } + ], + "name": "trustServer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "address", + "name": "serverId", + "type": "address" + }, + { + "internalType": "string", + "name": "serverUrl", + "type": "string" + } + ], + "internalType": "struct IDataPermissions.TrustServerInput", + "name": "trustServerInput", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "trustServerWithSignature", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "trustedForwarder", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "serverId", + "type": "address" + } + ], + "name": "untrustServer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "address", + "name": "serverId", + "type": "address" + } + ], + "internalType": "struct IDataPermissions.UntrustServerInput", + "name": "untrustServerInput", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "untrustServerWithSignature", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IDataRegistry", + "name": "newDataRegistry", + "type": "address" + } + ], + "name": "updateDataRegistry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trustedForwarderAddress", + "type": "address" + } + ], + "name": "updateTrustedForwarder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userNonce", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "permissionIndex", + "type": "uint256" + } + ], + "name": "userPermissionIdsAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userPermissionIdsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userPermissionIdsValues", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "permissionIndex", + "type": "uint256" + } + ], + "name": "userRevokedPermissionIdsAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userRevokedPermissionIdsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userRevokedPermissionIdsValues", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "serverIndex", + "type": "uint256" + } + ], + "name": "userServerIdsAt", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userServerIdsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "userServerIdsValues", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + } +] \ No newline at end of file diff --git a/abis/v5/DataRegistryImplementation.json b/abis/v5/DataRegistryImplementation.json new file mode 100644 index 0000000..b93e6d8 --- /dev/null +++ b/abis/v5/DataRegistryImplementation.json @@ -0,0 +1,1188 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "AccessControlBadConfirmation", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "neededRole", + "type": "bytes32" + } + ], + "name": "AccessControlUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "ERC1967InvalidImplementation", + "type": "error" + }, + { + "inputs": [], + "name": "ERC1967NonPayable", + "type": "error" + }, + { + "inputs": [], + "name": "EnforcedPause", + "type": "error" + }, + { + "inputs": [], + "name": "ExpectedPause", + "type": "error" + }, + { + "inputs": [], + "name": "FailedInnerCall", + "type": "error" + }, + { + "inputs": [], + "name": "FileNotFound", + "type": "error" + }, + { + "inputs": [], + "name": "FileUrlAlreadyUsed", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInitialization", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "InvalidSchemaId", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidUrl", + "type": "error" + }, + { + "inputs": [], + "name": "NoPermission", + "type": "error" + }, + { + "inputs": [], + "name": "NotFileOwner", + "type": "error" + }, + { + "inputs": [], + "name": "NotInitializing", + "type": "error" + }, + { + "inputs": [], + "name": "UUPSUnauthorizedCallContext", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot", + "type": "bytes32" + } + ], + "name": "UUPSUnsupportedProxiableUUID", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "FileAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "version", + "type": "uint64" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "PermissionGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "proofIndex", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "dlpId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "score", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "proofUrl", + "type": "string" + } + ], + "name": "ProofAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "RefinementAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "RefinementUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAINTAINER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "REFINEMENT_SERVICE_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UPGRADE_INTERFACE_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "addFile", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "name": "addFilePermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "internalType": "struct IDataRegistry.Permission[]", + "name": "permissions", + "type": "tuple[]" + } + ], + "name": "addFileWithPermissions", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "internalType": "struct IDataRegistry.Permission[]", + "name": "permissions", + "type": "tuple[]" + }, + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "addFileWithPermissionsAndSchema", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "addFileWithSchema", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "score", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dlpId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "metadata", + "type": "string" + }, + { + "internalType": "string", + "name": "proofUrl", + "type": "string" + }, + { + "internalType": "string", + "name": "instruction", + "type": "string" + } + ], + "internalType": "struct IDataRegistry.ProofData", + "name": "data", + "type": "tuple" + } + ], + "internalType": "struct IDataRegistry.Proof", + "name": "proof", + "type": "tuple" + } + ], + "name": "addProof", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "name": "addRefinementWithPermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "dataRefinerRegistry", + "outputs": [ + { + "internalType": "contract IDataRefinerRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "fileIdByUrl", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "filePermissions", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "fileProofs", + "outputs": [ + { + "components": [ + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "score", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dlpId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "metadata", + "type": "string" + }, + { + "internalType": "string", + "name": "proofUrl", + "type": "string" + }, + { + "internalType": "string", + "name": "instruction", + "type": "string" + } + ], + "internalType": "struct IDataRegistry.ProofData", + "name": "data", + "type": "tuple" + } + ], + "internalType": "struct IDataRegistry.Proof", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + } + ], + "name": "fileRefinements", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + } + ], + "name": "files", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "uint256", + "name": "addedAtBlock", + "type": "uint256" + } + ], + "internalType": "struct IDataRegistry.FileResponse", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "filesCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleAdmin", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trustedForwarderAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "forwarder", + "type": "address" + } + ], + "name": "isTrustedForwarder", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + } + ], + "name": "multicall", + "outputs": [ + { + "internalType": "bytes[]", + "name": "results", + "type": "bytes[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "callerConfirmation", + "type": "address" + } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "adminRole", + "type": "bytes32" + } + ], + "name": "setRoleAdmin", + "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": [], + "name": "trustedForwarder", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IDataRefinerRegistry", + "name": "newDataRefinerRegistry", + "type": "address" + } + ], + "name": "updateDataRefinerRegistry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trustedForwarderAddress", + "type": "address" + } + ], + "name": "updateTrustedForwarder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + } +] \ No newline at end of file diff --git a/config/moksha.json b/config/moksha.json index 15ecd20..0f2a423 100644 --- a/config/moksha.json +++ b/config/moksha.json @@ -19,7 +19,8 @@ "vanaEpoch": true, "dlpPerformance": true, "queryEngine": true, - "dataRefinerRegistry": true + "dataRefinerRegistry": true, + "dataPermission": true } }, "initParams": { diff --git a/config/vana.json b/config/vana.json index 65cafca..a391713 100644 --- a/config/vana.json +++ b/config/vana.json @@ -19,7 +19,8 @@ "vanaEpoch": true, "dlpPerformance": true, "queryEngine": true, - "dataRefinerRegistry": true + "dataRefinerRegistry": true, + "dataPermission": true } }, "initParams": { diff --git a/schema.graphql b/schema.graphql index f44929d..3b5dc0b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,6 +1,12 @@ type User @entity(immutable: false) { id: ID! fileContributions: [DataRegistryProof!] @derivedFrom(field: "user") + "All files owned by this user" + files: [File!]! @derivedFrom(field: "owner") + "All permissions granted by this user" + permissions: [Permission!]! @derivedFrom(field: "grantor") + "All servers trusted by this user" + trustedServers: [TrustedServer!]! @derivedFrom(field: "user") } type UserTotals @entity(immutable: false) { @@ -130,3 +136,56 @@ type DlpPerformance @entity(immutable: false) { createdTxHash: Bytes! createdAtBlock: BigInt! } + +type File @entity(immutable: false) { + "The unique ID of the file, equivalent to the on-chain fileId." + id: ID! + "The owner of the file." + owner: User! + "The URL where the file data is stored (e.g., IPFS)." + url: String! + "The schema ID associated with this file, if any." + schemaId: BigInt! + "The block number when the file was added." + addedAtBlock: BigInt! + "The timestamp when the file was added." + addedAtTimestamp: BigInt! + "The transaction hash of the file addition." + transactionHash: Bytes! +} + +type Permission @entity(immutable: false) { + "The unique ID of the permission, equivalent to the on-chain permissionId." + id: ID! + "The user who granted the permission." + grantor: User! + "The content identifier (e.g., IPFS URL) for the grant details." + grant: String! + "The nonce used for this permission grant." + nonce: BigInt! + "The signature provided by the user." + signature: Bytes! + "Whether the permission is currently active or has been revoked." + isActive: Boolean! + "File IDs associated with this permission." + fileIds: [BigInt!]! + "The block number when the permission was granted." + addedAtBlock: BigInt! + "The timestamp when the permission was granted." + addedAtTimestamp: BigInt! + "The transaction hash of the permission grant." + transactionHash: Bytes! +} + +type TrustedServer @entity(immutable: false) { + "Composite ID: userAddress-serverAddress" + id: ID! + "The user who trusts the server." + user: User! + "The server's address (ID)." + serverAddress: Bytes! + "The URL of the server." + serverUrl: String! + "Timestamp of when the trust was established." + trustedAt: BigInt! +} diff --git a/src/lib/contract/shared.ts b/src/lib/contract/shared.ts index 71358f3..38883df 100644 --- a/src/lib/contract/shared.ts +++ b/src/lib/contract/shared.ts @@ -1,5 +1,5 @@ -import {Dlp, User} from "../../../generated/schema"; -import {getOrCreateTotals, getTotalsIdDlp} from "../entity/totals"; +import { Dlp, User } from "../../../generated/schema"; +import { getOrCreateTotals, getTotalsIdDlp } from "../entity/totals"; export function getOrCreateUser(userId: string): User { let user = User.load(userId); diff --git a/src/lib/contract/v1/data-registry.ts b/src/lib/contract/v1/data-registry.ts index 03530cc..79d814c 100644 --- a/src/lib/contract/v1/data-registry.ts +++ b/src/lib/contract/v1/data-registry.ts @@ -2,7 +2,7 @@ import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; import { DataRegistryProof, - EpochReference, + File, FileOwner, } from "../../../../generated/schema"; @@ -10,19 +10,35 @@ import { FileAdded as FileAddedEvent, ProofAdded as FileProofAdded, } from "../../../../generated/DataRegistryImplementationV1/DataRegistryImplementationV1"; -import { EPOCH_REFERENCE_ID_CURRENT } from "../../entity/epoch"; +import { getEpochForBlock } from "../../entity/epoch"; // FIX: Added getEpochForBlock and EPOCH_REFERENCE_ID_CURRENT here import { getOrCreateUserTotals, getUserTotalsId, } from "../../entity/usertotals"; import { getOrCreateTotals, TOTALS_ID_GLOBAL } from "../../entity/totals"; -import { getEpochForBlock } from "../../entity/epoch"; +import { getOrCreateUser } from "../shared"; export function handleFileAddedV1(event: FileAddedEvent): void { log.info("Handling DataRegistry FileAdded with transaction hash: {}", [ event.transaction.hash.toHex(), ]); + // Create user entity if it doesn't exist + const user = getOrCreateUser(event.params.ownerAddress.toHex()); + + // Create new File entity + const file = new File(event.params.fileId.toString()); + file.owner = user.id; + file.url = event.params.url; + file.addedAtBlock = event.block.number; + file.addedAtTimestamp = event.block.timestamp; + file.transactionHash = event.transaction.hash; + + // V1 of the contract does not support schemaId, so we set it to 0 + file.schemaId = GraphBigInt.fromI32(0); + + file.save(); + const ownership = new FileOwner(event.params.fileId.toString()); ownership.ownerAddress = event.params.ownerAddress; ownership.save(); diff --git a/src/lib/contract/v2/data-registry.ts b/src/lib/contract/v2/data-registry.ts index b45f75b..bc846a5 100644 --- a/src/lib/contract/v2/data-registry.ts +++ b/src/lib/contract/v2/data-registry.ts @@ -2,7 +2,9 @@ import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; import { DataRegistryProof, + File, FileOwner, + Dlp, } from "../../../../generated/schema"; import { @@ -20,13 +22,29 @@ import { TOTALS_ID_GLOBAL, } from "../../entity/totals"; import { getEpochForBlock } from "../../entity/epoch"; -import {getOrCreateDlp} from "../shared"; +import { getOrCreateUser } from "../shared"; export function handleFileAddedV2(event: FileAddedEvent): void { log.info("Handling DataRegistry FileAdded with transaction hash: {}", [ event.transaction.hash.toHex(), ]); + // Create user entity if it doesn't exist + const user = getOrCreateUser(event.params.ownerAddress.toHex()); + + // Create new File entity + const file = new File(event.params.fileId.toString()); + file.owner = user.id; + file.url = event.params.url; + file.addedAtBlock = event.block.number; + file.addedAtTimestamp = event.block.timestamp; + file.transactionHash = event.transaction.hash; + + // V2 of the contract does not support schemaId, so we set it to 0 + file.schemaId = GraphBigInt.fromI32(0); + + file.save(); + const ownership = new FileOwner(event.params.fileId.toString()); ownership.ownerAddress = event.params.ownerAddress; ownership.save(); @@ -39,13 +57,18 @@ export function handleDataRegistryProofAddedV2(event: FileProofAdded): void { // Get epoch for the current block const epochId = getEpochForBlock(event.block.number); - if (!epochId) { + // FIX: Check for "-1" explicitly, as it is a truthy string + if (epochId == "-1") { log.error("No epoch found for block {}", [event.block.number.toString()]); return; } - // Ensure the Dlp entity exists - const dlp = getOrCreateDlp(event.params.dlpId.toString()); + // FIX: Load DLP instead of creating it to handle non-existent DLP case gracefully + const dlp = Dlp.load(event.params.dlpId.toString()); + if (dlp == null) { + log.error("DLP not found for proof: {}", [event.params.dlpId.toString()]); + return; + } // Create a new DataRegistryProof entity const proof = new DataRegistryProof(event.transaction.hash.toHex()); diff --git a/src/lib/contract/v3/data-registry.ts b/src/lib/contract/v3/data-registry.ts index 85fa1e8..b093cb6 100644 --- a/src/lib/contract/v3/data-registry.ts +++ b/src/lib/contract/v3/data-registry.ts @@ -3,7 +3,7 @@ import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; import { DataRegistryProof, Dlp, - EpochReference, + File, FileOwner, } from "../../../../generated/schema"; @@ -11,7 +11,6 @@ import { FileAdded as FileAddedEvent, ProofAdded as FileProofAdded, } from "../../../../generated/DataRegistryImplementationV3/DataRegistryImplementationV3"; -import { EPOCH_REFERENCE_ID_CURRENT } from "../../entity/epoch"; import { getOrCreateUserTotals, getUserTotalsId, @@ -22,7 +21,7 @@ import { getTotalsIdDlp, TOTALS_ID_GLOBAL, } from "../../entity/totals"; -import {getOrCreateDlp, getOrCreateUser} from "../shared"; +import { getOrCreateUser } from "../shared"; import { getEpochForBlock } from "../../entity/epoch"; export function handleFileAddedV3(event: FileAddedEvent): void { @@ -30,6 +29,22 @@ export function handleFileAddedV3(event: FileAddedEvent): void { event.transaction.hash.toHex(), ]); + // Create user entity if it doesn't exist + const user = getOrCreateUser(event.params.ownerAddress.toHex()); + + // Create new File entity + const file = new File(event.params.fileId.toString()); + file.owner = user.id; + file.url = event.params.url; + file.addedAtBlock = event.block.number; + file.addedAtTimestamp = event.block.timestamp; + file.transactionHash = event.transaction.hash; + + // V3 of the contract does not support schemaId, so we set it to 0 + file.schemaId = GraphBigInt.fromI32(0); + + file.save(); + const ownership = new FileOwner(event.params.fileId.toString()); ownership.ownerAddress = event.params.ownerAddress; ownership.save(); @@ -42,13 +57,18 @@ export function handleDataRegistryProofAddedV3(event: FileProofAdded): void { // Get epoch for the current block const epochId = getEpochForBlock(event.block.number); - if (!epochId) { + // Check for "-1" explicitly, as it is a truthy string + if (epochId == "-1") { log.error("No epoch found for block {}", [event.block.number.toString()]); return; } - // Ensure the Dlp entity exists - const dlp = getOrCreateDlp(event.params.dlpId.toString()); + // Load DLP instead of creating it to handle non-existent DLP case gracefully + const dlp = Dlp.load(event.params.dlpId.toString()); + if (dlp == null) { + log.error("DLP not found for proof: {}", [event.params.dlpId.toString()]); + return; + } // Create a new DataRegistryProof entity const proof = new DataRegistryProof(event.transaction.hash.toHex()); diff --git a/src/lib/contract/v5/data-permission.ts b/src/lib/contract/v5/data-permission.ts new file mode 100644 index 0000000..70af0d3 --- /dev/null +++ b/src/lib/contract/v5/data-permission.ts @@ -0,0 +1,114 @@ +import { + log, + store, + BigInt as GraphBigInt, + Bytes, +} from "@graphprotocol/graph-ts"; +import { + PermissionAdded, + PermissionRevoked, + ServerTrusted, + ServerUntrusted, + DataPermissionImplementation, +} from "../../../../generated/DataPermissionImplementation/DataPermissionImplementation"; +import { Permission, TrustedServer } from "../../../../generated/schema"; +import { getOrCreateUser } from "../shared"; + +export function handlePermissionAdded(event: PermissionAdded): void { + log.info("Handling PermissionAdded with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + const grantor = getOrCreateUser(event.params.user.toHex()); + const permissionId = event.params.permissionId; + + const permission = new Permission(permissionId.toString()); + permission.grantor = grantor.id; // Renamed from 'user' to 'grantor' + permission.grant = event.params.grant; + permission.addedAtBlock = event.block.number; + permission.addedAtTimestamp = event.block.timestamp; + permission.transactionHash = event.transaction.hash; + + // Set new fields + permission.isActive = true; // New permissions are active by default + permission.fileIds = event.params.fileIds; // Store the new fileIds array + + // Since nonce and signature are not in the event, we must call the contract. + const contract = DataPermissionImplementation.bind(event.address); + const permissionData = contract.try_permissions(permissionId); + + if (!permissionData.reverted) { + // The returned struct has a 'grantor' field, not 'user' + permission.nonce = permissionData.value.nonce; + permission.signature = permissionData.value.signature; + } else { + log.warning( + "Could not get permission data for id {}. Nonce and signature will be zero.", + [permissionId.toString()], + ); + permission.nonce = GraphBigInt.zero(); + permission.signature = new Bytes(0); + } + + permission.save(); +} + +export function handlePermissionRevoked(event: PermissionRevoked): void { + log.info("Handling PermissionRevoked for permissionId: {}", [ + event.params.permissionId.toString(), + ]); + + const permissionId = event.params.permissionId.toString(); + const permission = Permission.load(permissionId); + + if (permission) { + permission.isActive = false; + permission.save(); + } else { + log.warning("Received revoke event for a permission not found in subgraph: {}", [ + permissionId, + ]); + } +} + +export function handleServerTrusted(event: ServerTrusted): void { + log.info("Handling ServerTrusted for user {} and server {}", [ + event.params.user.toHex(), + event.params.serverId.toHex(), + ]); + + const user = getOrCreateUser(event.params.user.toHex()); + const serverId = event.params.serverId; + const compositeId = `${user.id}-${serverId.toHex()}`; + + let trustedServer = TrustedServer.load(compositeId); + if (trustedServer == null) { + trustedServer = new TrustedServer(compositeId); + trustedServer.user = user.id; + trustedServer.serverAddress = serverId; + } + + trustedServer.serverUrl = event.params.serverUrl; + trustedServer.trustedAt = event.block.timestamp; + trustedServer.save(); +} + +export function handleServerUntrusted(event: ServerUntrusted): void { + log.info("Handling ServerUntrusted for user {} and server {}", [ + event.params.user.toHex(), + event.params.serverId.toHex(), + ]); + + const userId = event.params.user.toHex(); + const serverId = event.params.serverId.toHex(); + const compositeId = `${userId}-${serverId}`; + + const trustedServer = TrustedServer.load(compositeId); + if (trustedServer != null) { + store.remove("TrustedServer", compositeId); + } else { + log.warning("Attempted to untrust a server that was not found: {}", [ + compositeId, + ]); + } +} diff --git a/src/lib/contract/v5/dlp-registry.ts b/src/lib/contract/v5/dlp-registry.ts index 64a4f0c..98c2261 100644 --- a/src/lib/contract/v5/dlp-registry.ts +++ b/src/lib/contract/v5/dlp-registry.ts @@ -1,4 +1,4 @@ -import { BigInt, log } from "@graphprotocol/graph-ts"; +import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; import { DlpRegistered, DlpUpdated, @@ -9,10 +9,8 @@ import { } from "../../../../generated/DLPRegistryImplementationV5/DLPRegistryImplementationV5"; import { Dlp } from "../../../../generated/schema"; -import { getTotalsIdDlp } from "../../entity/totals/constants"; import { getOrCreateDlpList } from "../../../../src/lib/entity/dlp-list"; -import { getOrCreateTotals } from "../../entity/totals"; -import {getOrCreateDlp, getOrCreateUser} from "../shared"; +import { getOrCreateDlp, getOrCreateUser } from "../shared"; // Mirrored from DLPRegistry.IDLPRegistry.DlpStatus enum dlpStatus { @@ -46,13 +44,13 @@ export function handleDlpRegisteredV5(event: DlpRegistered): void { dlp.createdAt = event.block.timestamp; dlp.createdTxHash = event.transaction.hash; dlp.createdAtBlock = event.block.number; - dlp.status = BigInt.fromI32(dlpStatus.REGISTERED); + dlp.status = GraphBigInt.fromI32(dlpStatus.REGISTERED); // New field in v5 dlp.isVerified = false; // Keep staking fields for backward compatibility but set to zero - dlp.performanceRating = BigInt.zero(); + dlp.performanceRating = GraphBigInt.zero(); dlp.save(); @@ -102,7 +100,7 @@ export function handleDlpStatusUpdatedV5(event: DlpStatusUpdated): void { if (dlp != null) { const newStatus = event.params.newStatus; - dlp.status = BigInt.fromI32(newStatus); + dlp.status = GraphBigInt.fromI32(newStatus); // Track eligibility transitions if (newStatus === dlpStatus.ELIGIBLE) { @@ -142,9 +140,9 @@ export function handleDlpVerificationUpdatedV5( } if (isEligible) { - dlp.status = BigInt.fromI32(dlpStatus.ELIGIBLE); + dlp.status = GraphBigInt.fromI32(dlpStatus.ELIGIBLE); } else { - dlp.status = BigInt.fromI32(dlpStatus.REGISTERED); + dlp.status = GraphBigInt.fromI32(dlpStatus.REGISTERED); } dlp.save(); } else { @@ -157,8 +155,15 @@ export function handleDlpTokenUpdatedV5(event: DlpTokenUpdated): void { event.transaction.hash.toHexString(), ]); - // Ensure the Dlp entity exists - const dlp = getOrCreateDlp(event.params.dlpId.toString()); + // Load DLP instead of creating it to handle non-existent DLP case gracefully + const dlp = Dlp.load(event.params.dlpId.toString()); + + if (dlp == null) { + log.error("DLP not found for token update: {}", [ + event.params.dlpId.toString(), + ]); + return; + } dlp.token = event.params.tokenAddress; dlp.save(); @@ -172,9 +177,9 @@ export function handleDlpTokenUpdatedV5(event: DlpTokenUpdated): void { } if (isEligible) { - dlp.status = BigInt.fromI32(dlpStatus.ELIGIBLE); + dlp.status = GraphBigInt.fromI32(dlpStatus.ELIGIBLE); } else { - dlp.status = BigInt.fromI32(dlpStatus.REGISTERED); + dlp.status = GraphBigInt.fromI32(dlpStatus.REGISTERED); } dlp.save(); } @@ -185,5 +190,4 @@ export function handleDlpRegistrationDepositAmountUpdatedV5( log.info("handleDlpRegistrationDepositAmountUpdatedV5: {}", [ event.transaction.hash.toHexString(), ]); - // No state changes needed for deposit amount updates } diff --git a/src/lib/contract/v5/vana-epoch.ts b/src/lib/contract/v5/vana-epoch.ts index 9366a19..a1f98de 100644 --- a/src/lib/contract/v5/vana-epoch.ts +++ b/src/lib/contract/v5/vana-epoch.ts @@ -1,4 +1,4 @@ -import { BigInt, log } from "@graphprotocol/graph-ts"; +import { log } from "@graphprotocol/graph-ts"; import { EpochCreated, EpochDlpRewardAdded, @@ -6,12 +6,9 @@ import { EpochRewardAmountUpdated, EpochSizeUpdated, } from "../../../../generated/VanaEpochImplementationV5/VanaEpochImplementationV5"; -import { Epoch, EpochReference } from "../../../../generated/schema"; +import { Epoch } from "../../../../generated/schema"; import { getOrCreateCurrentParams } from "../../entity/params"; -import { - EPOCH_REFERENCE_ID_CURRENT, - saveCurrentEpochReference, -} from "../../entity/epoch"; +import { saveCurrentEpochReference } from "../../entity/epoch"; export function handleEpochCreatedV5(event: EpochCreated): void { log.info("handleEpochCreatedV5: {}", [event.transaction.hash.toHexString()]); diff --git a/src/lib/entity/epoch/epoch-reference.ts b/src/lib/entity/epoch/epoch-reference.ts index 6a2a4b0..bde29cf 100644 --- a/src/lib/entity/epoch/epoch-reference.ts +++ b/src/lib/entity/epoch/epoch-reference.ts @@ -1,4 +1,4 @@ -import { BigInt, log } from "@graphprotocol/graph-ts"; +import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; import { Epoch, EpochReference } from "../../../../generated/schema"; import { EPOCH_REFERENCE_ID_CURRENT } from "./constants"; import { epochRanges } from "../../../mapping"; @@ -24,7 +24,7 @@ export function saveCurrentEpochReference(newEpochId: string): EpochReference { return currentEpoch; } -export function getEpochForBlock(blockNumber: BigInt): string { +export function getEpochForBlock(blockNumber: GraphBigInt): string { const currentEpochRef = getCurrentEpochReference(); if (!currentEpochRef || !currentEpochRef.epoch) { return getEpochFromRanges(blockNumber); @@ -35,15 +35,15 @@ export function getEpochForBlock(blockNumber: BigInt): string { return getEpochFromRanges(blockNumber); } - if (currentEpoch.endBlock.le(BigInt.zero())) { + if (currentEpoch.endBlock.le(GraphBigInt.zero())) { return currentEpoch.id; } // If the current epoch is in the past, we need to use the next epoch if (blockNumber.gt(currentEpoch.endBlock)) { // Get the next epoch by incrementing the current epoch ID - const nextEpochId = BigInt.fromString(currentEpoch.id) - .plus(BigInt.fromI32(1)) + const nextEpochId = GraphBigInt.fromString(currentEpoch.id) + .plus(GraphBigInt.fromI32(1)) .toString(); const nextEpoch = Epoch.load(nextEpochId); if (nextEpoch) { @@ -56,7 +56,8 @@ export function getEpochForBlock(blockNumber: BigInt): string { return currentEpoch.id; } -function getEpochFromRanges(blockNumber: BigInt): string { +function getEpochFromRanges(blockNumber: GraphBigInt): string { + // @ts-ignore const blockNumberInt = Number.parseInt(blockNumber.toString()); for (let i = 0; i < epochRanges.length; i++) { diff --git a/src/mapping.ts.template b/src/mapping.ts.template index 5d27411..ed2dfbc 100644 --- a/src/mapping.ts.template +++ b/src/mapping.ts.template @@ -63,3 +63,6 @@ export * from "./lib/contract/v5/vana-epoch"; {{#includes.v5.dlpPerformance}} export * from "./lib/contract/v5/dlp-performance"; {{/includes.v5.dlpPerformance}} +{{#includes.v5.dataPermission}} +export * from "./lib/contract/v5/data-permission"; +{{/includes.v5.dataPermission}} \ No newline at end of file diff --git a/subgraph.moksha.yaml b/subgraph.moksha.yaml index 50d3975..c6c57ef 100644 --- a/subgraph.moksha.yaml +++ b/subgraph.moksha.yaml @@ -163,6 +163,8 @@ dataSources: handler: handleDlpVerificationUpdatedV5 - event: DlpTokenUpdated(indexed uint256,address) handler: handleDlpTokenUpdatedV5 + - event: DlpSubEligibilityThresholdUpdated(uint256) + handler: handleDlpSubEligibilityThresholdUpdatedV5 - event: DlpRegistrationDepositAmountUpdated(uint256) handler: handleDlpRegistrationDepositAmountUpdatedV5 file: ./src/mapping.ts @@ -219,4 +221,57 @@ dataSources: eventHandlers: - event: EpochDlpPerformancesSaved(indexed uint256,indexed uint256,uint256,uint256,uint256,uint256) handler: handleEpochDlpPerformancesSavedV5 + file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataPermissionImplementation + network: moksha + source: + address: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de" + abi: DataPermissionImplementation + startBlock: 3517249 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Permission + - User + - TrustedServer + abis: + - name: DataPermissionImplementation + file: ./abis/v5/DataPermissionImplementation.json + eventHandlers: + - event: PermissionAdded(indexed uint256,indexed address,string,uint256[]) + handler: handlePermissionAdded + - event: PermissionRevoked(indexed uint256) + handler: handlePermissionRevoked + - event: ServerTrusted(indexed address,indexed address,string) + handler: handleServerTrusted + - event: ServerUntrusted(indexed address,indexed address) + handler: handleServerUntrusted + file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataRegistryImplementationV5 + network: moksha + source: + address: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C" + abi: DataRegistryImplementationV5 + startBlock: 3425120 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - EpochReference + - DataRegistryProof + abis: + - name: DataRegistryImplementationV5 + file: ./abis/v5/DataRegistryImplementation.json + eventHandlers: + - event: FileAdded(indexed uint256,indexed address,string) + handler: handleFileAddedV3 + - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) + handler: handleDataRegistryProofAddedV3 file: ./src/mapping.ts \ No newline at end of file diff --git a/subgraph.vana-moksha.yaml b/subgraph.vana-moksha.yaml index a11787f..ff7305e 100644 --- a/subgraph.vana-moksha.yaml +++ b/subgraph.vana-moksha.yaml @@ -163,6 +163,8 @@ dataSources: handler: handleDlpVerificationUpdatedV5 - event: DlpTokenUpdated(indexed uint256,address) handler: handleDlpTokenUpdatedV5 + - event: DlpSubEligibilityThresholdUpdated(uint256) + handler: handleDlpSubEligibilityThresholdUpdatedV5 - event: DlpRegistrationDepositAmountUpdated(uint256) handler: handleDlpRegistrationDepositAmountUpdatedV5 file: ./src/mapping.ts @@ -219,4 +221,57 @@ dataSources: eventHandlers: - event: EpochDlpPerformancesSaved(indexed uint256,indexed uint256,uint256,uint256,uint256,uint256) handler: handleEpochDlpPerformancesSavedV5 + file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataPermissionImplementation + network: vana-moksha + source: + address: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de" + abi: DataPermissionImplementation + startBlock: 3517249 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Permission + - User + - TrustedServer + abis: + - name: DataPermissionImplementation + file: ./abis/v5/DataPermissionImplementation.json + eventHandlers: + - event: PermissionAdded(indexed uint256,indexed address,string,uint256[]) + handler: handlePermissionAdded + - event: PermissionRevoked(indexed uint256) + handler: handlePermissionRevoked + - event: ServerTrusted(indexed address,indexed address,string) + handler: handleServerTrusted + - event: ServerUntrusted(indexed address,indexed address) + handler: handleServerUntrusted + file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataRegistryImplementationV5 + network: vana-moksha + source: + address: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C" + abi: DataRegistryImplementationV5 + startBlock: 3425120 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - EpochReference + - DataRegistryProof + abis: + - name: DataRegistryImplementationV5 + file: ./abis/v5/DataRegistryImplementation.json + eventHandlers: + - event: FileAdded(indexed uint256,indexed address,string) + handler: handleFileAddedV3 + - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) + handler: handleDataRegistryProofAddedV3 file: ./src/mapping.ts \ No newline at end of file diff --git a/subgraph.vana.yaml b/subgraph.vana.yaml index 76f5152..5b69dd6 100644 --- a/subgraph.vana.yaml +++ b/subgraph.vana.yaml @@ -222,3 +222,56 @@ dataSources: - event: EpochDlpPerformancesSaved(indexed uint256,indexed uint256,uint256,uint256,uint256,uint256) handler: handleEpochDlpPerformancesSavedV5 file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataPermissionImplementation + network: vana + source: + address: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de" + abi: DataPermissionImplementation + startBlock: 3965727 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Permission + - User + - TrustedServer + abis: + - name: DataPermissionImplementation + file: ./abis/v5/DataPermissionImplementation.json + eventHandlers: + - event: PermissionAdded(indexed uint256,indexed address,string,uint256[]) + handler: handlePermissionAdded + - event: PermissionRevoked(indexed uint256) + handler: handlePermissionRevoked + - event: ServerTrusted(indexed address,indexed address,string) + handler: handleServerTrusted + - event: ServerUntrusted(indexed address,indexed address) + handler: handleServerUntrusted + file: ./src/mapping.ts + + - kind: ethereum/contract + name: DataRegistryImplementationV5 + network: vana + source: + address: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C" + abi: DataRegistryImplementationV5 + startBlock: 3425120 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - EpochReference + - DataRegistryProof + abis: + - name: DataRegistryImplementationV5 + file: ./abis/v5/DataRegistryImplementation.json + eventHandlers: + - event: FileAdded(indexed uint256,indexed address,string) + handler: handleFileAddedV3 + - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) + handler: handleDataRegistryProofAddedV3 + file: ./src/mapping.ts \ No newline at end of file diff --git a/tests/unit/contract/v1/data-registry.test.ts b/tests/unit/contract/v1/data-registry.test.ts new file mode 100644 index 0000000..bfeb5af --- /dev/null +++ b/tests/unit/contract/v1/data-registry.test.ts @@ -0,0 +1,58 @@ +import { + assert, + beforeEach, + clearStore, + describe, + test, +} from "matchstick-as/assembly/index"; +import { BigInt as GraphBigInt } from "@graphprotocol/graph-ts"; +import { handleFileAddedV1 } from "../../../../src/lib/contract/v1/data-registry"; +import { createFileAddedEvent } from "./utils/data-registry-events"; + +// Hook to clear the store before each test, ensuring test isolation +beforeEach(() => { + clearStore(); +}); + +describe("handleFileAddedV1", () => { + test("creates both a File and a FileOwner entity", () => { + // 1. ARRANGE: Set up test data and create the mock event + const fileId = 1; + const ownerAddress = "0x1234567890123456789012345678901234567890"; + const url = "ipfs://Qm..."; + + const fileAddedEvent = createFileAddedEvent(fileId, ownerAddress, url); + + // 2. ACT: Call the handler function with the mock event + handleFileAddedV1(fileAddedEvent); + + // 3. ASSERT: Check that the store is in the correct state + + // --- Assert the NEW functionality --- + assert.entityCount("File", 1); + assert.fieldEquals("File", fileId.toString(), "id", fileId.toString()); + assert.fieldEquals("File", fileId.toString(), "owner", ownerAddress); + assert.fieldEquals("File", fileId.toString(), "url", url); + assert.fieldEquals("File", fileId.toString(), "schemaId", "0"); // Important check for V1 + assert.fieldEquals( + "File", + fileId.toString(), + "transactionHash", + fileAddedEvent.transaction.hash.toHexString(), + ); + + // Also check that the associated User was created + assert.entityCount("User", 1); + assert.fieldEquals("User", ownerAddress, "id", ownerAddress); + + // --- Assert the ORIGINAL functionality (prevents regression) --- + assert.entityCount("FileOwner", 1); + assert.fieldEquals("FileOwner", fileId.toString(), "id", fileId.toString()); + assert.fieldEquals( + "FileOwner", + fileId.toString(), + "ownerAddress", + ownerAddress, + ); + }); +}); diff --git a/tests/unit/contract/v1/utils/data-registry-events.ts b/tests/unit/contract/v1/utils/data-registry-events.ts new file mode 100644 index 0000000..8e8a3fd --- /dev/null +++ b/tests/unit/contract/v1/utils/data-registry-events.ts @@ -0,0 +1,28 @@ +import { Address, ethereum } from "@graphprotocol/graph-ts"; +import { newMockEvent } from "matchstick-as/assembly/index"; +import { FileAdded as FileAddedEvent } from "../../../../../generated/DataRegistryImplementationV1/DataRegistryImplementationV1"; + +export function createFileAddedEvent( + fileId: i32, + ownerAddress: string, + url: string, +): FileAddedEvent { + const normalizedAddr = ownerAddress.toLowerCase(); + const fileAddedEvent = changetype(newMockEvent()); + fileAddedEvent.parameters = new Array(); + + fileAddedEvent.parameters.push( + new ethereum.EventParam("fileId", ethereum.Value.fromI32(fileId)), + ); + fileAddedEvent.parameters.push( + new ethereum.EventParam( + "ownerAddress", + ethereum.Value.fromAddress(Address.fromString(normalizedAddr)), + ), + ); + fileAddedEvent.parameters.push( + new ethereum.EventParam("url", ethereum.Value.fromString(url)), + ); + + return fileAddedEvent; +}