-
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.
- Loading branch information
Showing
10 changed files
with
159 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { RoleApprovalForAll } from '../../../generated/ERC7432-Immutable-Roles/ERC7432' | ||
import { findOrCreateAccount, insertRoleApprovalIfNotExist, deleteRoleApprovalIfExist } 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.info('[handleRoleGranted] Updated Role Approval: {}', [roleApproval.id]) | ||
} else { | ||
deleteRoleApprovalIfExist(grantorAccount, operatorAccount, 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
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,55 @@ | ||
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() | ||
}) | ||
|
||
test('should not do anything when approval does not exist and 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 does not exist and 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) | ||
}) | ||
|
||
test('should remove approval when approval exists and 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 approval exists and 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) | ||
}) | ||
}) |
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