-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tracking ERC-7432 role approvals
- Loading branch information
Showing
13 changed files
with
179 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { handleRoleGranted } from './role/grant-handler' | ||
export { handleRoleRevoked } from './role/revoke-handler' | ||
export { handleRoleApprovalForAll } from './role/role-approval-handler' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { RoleApprovalForAll } from '../../../generated/ERC7432-Immutable-Roles/ERC7432' | ||
import { | ||
findOrCreateAccount, | ||
insertRoleApprovalIfNotExist, | ||
deleteRoleApprovalIfExist, | ||
generateRoleApprovalId, | ||
} from '../../utils/helper' | ||
import { log } from '@graphprotocol/graph-ts' | ||
|
||
export function handleRoleApprovalForAll(event: RoleApprovalForAll): void { | ||
const grantorAddress = event.transaction.from.toHex() | ||
const operatorAddress = event.params._operator.toHex() | ||
const tokenAddress = event.params._tokenAddress.toHex() | ||
const isApproved = event.params._isApproved | ||
|
||
const grantorAccount = findOrCreateAccount(grantorAddress) | ||
const operatorAccount = findOrCreateAccount(operatorAddress) | ||
|
||
if (isApproved) { | ||
const roleApproval = insertRoleApprovalIfNotExist(grantorAccount, operatorAccount, tokenAddress) | ||
log.warning('[handleRoleApprovalForAll] Updated Role Approval: {} Tx: {}', [ | ||
roleApproval.id, | ||
event.transaction.hash.toHex(), | ||
]) | ||
} else { | ||
const roleApprovalId = generateRoleApprovalId(grantorAccount, operatorAccount, tokenAddress) | ||
deleteRoleApprovalIfExist(roleApprovalId) | ||
log.warning('[handleRoleApprovalForAll] Removed Role Approval: {} Tx: {}', [ | ||
roleApprovalId, | ||
event.transaction.hash.toHex(), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { assert, describe, test, clearStore, afterEach } from 'matchstick-as' | ||
import { createNewRoleApprovalForAllEvent } from '../helpers/events' | ||
import { validateRoleApproval, createMockRoleApproval } from '../helpers/entities' | ||
import { Addresses } from '../helpers/contants' | ||
import { handleRoleApprovalForAll } from '../../src/erc7432' | ||
|
||
const grantor = Addresses[0] | ||
const operator = Addresses[1] | ||
const tokenAddress = Addresses[2] | ||
|
||
describe('ERC-7432 RoleApprovalForAll Handler', () => { | ||
afterEach(() => { | ||
clearStore() | ||
}) | ||
|
||
describe('When RoleApproval exists', () => { | ||
test('should remove approval when is set to false', () => { | ||
createMockRoleApproval(grantor, operator, tokenAddress) | ||
assert.entityCount('RoleApproval', 1) | ||
|
||
const event = createNewRoleApprovalForAllEvent(grantor, operator, tokenAddress, false) | ||
handleRoleApprovalForAll(event) | ||
|
||
assert.entityCount('RoleApproval', 0) | ||
}) | ||
|
||
test('should not do anything when is set to true', () => { | ||
createMockRoleApproval(grantor, operator, tokenAddress) | ||
assert.entityCount('RoleApproval', 1) | ||
|
||
const event = createNewRoleApprovalForAllEvent(grantor, operator, tokenAddress, true) | ||
handleRoleApprovalForAll(event) | ||
|
||
assert.entityCount('RoleApproval', 1) | ||
validateRoleApproval(grantor, operator, tokenAddress) | ||
}) | ||
}) | ||
|
||
describe('When RoleApproval does not exist', () => { | ||
test('should not do anything when approval is set to false', () => { | ||
assert.entityCount('RoleApproval', 0) | ||
|
||
const event = createNewRoleApprovalForAllEvent(grantor, operator, tokenAddress, false) | ||
handleRoleApprovalForAll(event) | ||
|
||
assert.entityCount('RoleApproval', 0) | ||
}) | ||
|
||
test('should create approval when approval is set to true', () => { | ||
assert.entityCount('RoleApproval', 0) | ||
|
||
const event = createNewRoleApprovalForAllEvent(grantor, operator, tokenAddress, true) | ||
handleRoleApprovalForAll(event) | ||
|
||
assert.entityCount('RoleApproval', 1) | ||
validateRoleApproval(grantor, operator, tokenAddress) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters