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

Created task for generating calldata for key hash update calls. #236

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy';
import '@nomiclabs/hardhat-etherscan';
import '@nomicfoundation/hardhat-chai-matchers'
import './tasks';

import { HardhatUserConfig } from "hardhat/config";

Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"etherscan:goerli": "yarn hardhat --network goerli etherscan-verify",
"etherscan:base": "yarn hardhat --network base etherscan-verify",
"etherscan:base_staging": "yarn hardhat --network base_staging etherscan-verify",
"genKeyUpdateCalldata": "npx hardhat genKeyUpdateCalldata",
"importVerifier": "rm -rf ./contracts/verifiers/ && cp -r ../circuits-circom/contracts ./contracts/verifiers",
"test": "npx hardhat test test/libs/*.ts test/processors/*.ts test/ramps/**/*.ts",
"test:clean": "yarn build && yarn test",
Expand Down
67 changes: 67 additions & 0 deletions contracts/tasks/genKeyUpdateCalldata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment as HRE } from "hardhat/types";
import * as readline from 'readline';

import {
ManagedKeyHashAdapter__factory,
ManagedKeyHashAdapterV2__factory
} from "../typechain/factories/contracts/processors/keyHashAdapters/index";
import { PaymentProviders } from "../utils/types"

task("genKeyUpdateCalldata", "Add a manufacturer to the ManufacturerRegistry")
.addParam("hash", "Hash of the modulus of the new domain key")
.setAction(async (taskArgs, hre: HRE) => {
// Generate the calldata for adding a new domain key to the ManagedKeyHashAdapter
const hash = taskArgs.hash;
const [ defaultAccount ] = await hre.getUnnamedAccounts();

// Allow script caller to select the payment provider they want to use
const paymentNetwork = await getPaymentNetwork();

let calldata;
if (paymentNetwork === "Venmo") {
calldata = ManagedKeyHashAdapter__factory.connect(
defaultAccount,
hre.ethers.provider
).interface.encodeFunctionData("setMailserverKeyHash", [hash]);
} else {
calldata = ManagedKeyHashAdapterV2__factory.connect(
defaultAccount,
hre.ethers.provider
).interface.encodeFunctionData("addMailServerKeyHash", [hash]);
}

console.log(calldata);
});

// A utility function to prompt the user for input
async function getPaymentNetwork(): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

const paymentProviderList = Object.keys(PaymentProviders);

const baseQuestion = `Type the name of the payment provider you want to use: \n`;
const question = paymentProviderList.reduce((acc, curr) => {
return `${acc} - ${curr}\n`;
}, baseQuestion);
const paymentNetwork = await queryUser(rl, question);

if (!paymentProviderList.includes(paymentNetwork)) {
console.log("Invalid payment provider. Please try again.");
return await getPaymentNetwork();
}

return paymentNetwork;
};

// A utility function to prompt the user for input
function queryUser(rl: readline.ReadLine, question: string): Promise<string> {
return new Promise(resolve => {
rl.question(question, (answer) => {
resolve(answer);
});
});
};
1 change: 1 addition & 0 deletions contracts/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './genKeyUpdateCalldata';
Loading