Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add manual ci for querying grant role events #336

Merged
merged 14 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-eggs-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/solidity-contracts': minor
---

add manual ci for querying grant role events
36 changes: 36 additions & 0 deletions .github/workflows/manual-query-grant-role-event.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Manually Query Grant Role Events

on:
workflow_dispatch:
inputs:
contractAddress:
description: 'Enter the contract address for which you wanna query the grant role events for'
required: true
type: string
rpc:
description: 'Enter network rpc'
required: true
default: 'https://rpc.ankr.com/eth'
type: string

jobs:
verify-upgrade:
runs-on: ubuntu-latest
env:
RPC_URL: ${{ github.event.inputs.rpc }}
steps:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- name: Query Events
run: |
npx hardhat compile && npx hardhat grant-role-event-filter --contract ${{ github.event.inputs.contractAddress }}
working-directory: ./packages/solidity-contracts
- name: Upload event payload as an artifact
uses: actions/upload-artifact@v4
with:
name: event-query-payload
path: grantedRoles.json
retention-days: 90
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ packages/fungible-token/exports/types
dist

# verification ci artifacts
packages/solidity-contracts/verification.json
packages/solidity-contracts/verification.json

# grant role query ci artifacts
packages/solidity-contracts/grantedRoles.json
118 changes: 118 additions & 0 deletions packages/solidity-contracts/scripts/hardhat/eventFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { writeFileSync } from 'fs';

task(
'grant-role-event-filter',
'Filters grant role event for a specific contract to keep track of assigned roles'
)
.addParam('contract', 'address of the contract')
.setAction(
async (taskArgs: any, hre: HardhatRuntimeEnvironment): Promise<void> => {
const provider = new hre.ethers.JsonRpcProvider(process.env.RPC_URL);

const grantRoleEvenABI = [
viraj124 marked this conversation as resolved.
Show resolved Hide resolved
{
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',
},
{
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',
},
];

// existing roles
const DEFAULT_ADMIN_ROLE = hre.ethers.ZeroHash;
const PAUSER_ROLE = hre.ethers.keccak256(
hre.ethers.toUtf8Bytes('PAUSER_ROLE')
);
const COMMITTER_ROLE = hre.ethers.keccak256(
hre.ethers.toUtf8Bytes('COMMITTER_ROLE')
);
const SET_RATE_LIMITER_ROLE = hre.ethers.keccak256(
hre.ethers.toUtf8Bytes('SET_RATE_LIMITER_ROLE')
);

const roles = [
{ name: 'DEFAULT_ADMIN_ROLE', value: DEFAULT_ADMIN_ROLE },
{ name: 'PAUSER_ROLE', value: PAUSER_ROLE },
{ name: 'COMMITTER_ROLE', value: COMMITTER_ROLE },
{ name: 'SET_RATE_LIMITER_ROLE', value: SET_RATE_LIMITER_ROLE },
];

const contract = new hre.ethers.Contract(
taskArgs.contract,
grantRoleEvenABI,
provider
);

const eventPayload: any = [];

try {
const events = await contract.queryFilter(
contract.filters.RoleGranted()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you query too many blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently tested with a public rpc, triggering the ci frequently might result in rate limit issues, as currently we query all blocks.

With a private rpc we should be good, but I was also thinking if we can specify a block range too but for now decided to keep the number of inputs minimal, so didn't add that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, hardhat tasks are not the ideal way to do this. Also why do we need this to be in the ci?

Copy link
Contributor Author

@viraj124 viraj124 Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to be able to manually trigger it by specifying contract address and rpc from the ci and there is no tool with a ui live currently that we can use for filtering events, there is a rate limit error risk with this approach but using a pvt rpc reduces that risk to a great extent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, hardhat tasks are not the ideal way to do this. Also why do we need this to be in the ci?

Please propose alternatives. I am tempted to use external infra for this task, like envio.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can use the graph protocol or quickly spin up our own indexer using ponder.sh

);

for (const event of events) {
viraj124 marked this conversation as resolved.
Show resolved Hide resolved
// only checking for active roles
const hasRole = await contract.hasRole(event.args[0], event.args[1]);
if (hasRole) {
const eventArgs: any = {};
// computing the `role` in a readable format
eventArgs.role =
roles.find((role) => role.value === event.args[0])?.name ||
'UNKNOWN_ROLE';
eventArgs.account = event.args[1];

eventPayload.push(eventArgs);
}
}

writeFileSync('grantedRoles.json', JSON.stringify(eventPayload));
viraj124 marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
throw new Error(`Unable to filter and query events: ${error}`);
}
}
);
1 change: 1 addition & 0 deletions packages/solidity-contracts/scripts/hardhat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './withdrawalResume';
export * from './withdrawalBlacklist';
export * from './withdrawalWhitelist';
export * from './verifyMainnetDeployment';
export * from './eventFilter';
Loading