Skip to content

Commit

Permalink
feat: hypha permissions update
Browse files Browse the repository at this point in the history
  • Loading branch information
theblockstalk committed Sep 13, 2024
1 parent c6853b2 commit 27b53c9
Show file tree
Hide file tree
Showing 2 changed files with 313 additions and 5 deletions.
284 changes: 284 additions & 0 deletions src/cli/msig/hyphaAccountsCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
import { StandardProposalOptions, createProposal, executeProposal } from '.';

// @ts-expect-error args not used
export async function hyphaAccountsCreate(args: any, options: StandardProposalOptions) {
/*
updateauth dao.hypha::scheduler > EOS6Cmu3MiVXvXAnz3NFZ7sBztGh38Em7FsifT8in7XwMXhNePgNE
linkauth dao.hypha::scheduler > dao.hypha@removedtx
updateauth dao.hypha::autoenroll > join.hypha@eosio.code
linkauth dao.hypha::autoenroll > dao.hypha@autenroll
updateauth voice.hypha::active > dao.hypha@active voice.hypha@active gov.tmy@active EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB
updateauth hypha.hypha::active > dao.hypha@eosio.code gov.tmy@active hypha.hypha@eosio.code EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB
updateauth husd.hypha::active > dao.hypha@eosio.code husd.hypha@eosio.code gov.tmy@active EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB
*/
const tonomyGovOwnerPermission = {
actor: 'tonomy',
permission: 'owner',
};
const tonomyGovActivePermission = {
actor: 'tonomy',
permission: 'active',
};
const hyphaDaoSchedulerPermission = {
account: 'tonomy',
name: 'updateauth',
authorization: [
{
actor: 'dao.hypha',
permission: 'active',
},
tonomyGovOwnerPermission,
tonomyGovActivePermission,
],
data: {
account: 'dao.hypha',
permission: 'scheduler',
parent: 'active',
auth: {
threshold: 1,
waits: [],
accounts: [],
keys: [
{
key: 'EOS6Cmu3MiVXvXAnz3NFZ7sBztGh38Em7FsifT8in7XwMXhNePgNE',
weight: 1,
},
],
},
auth_parent: true,

Check failure on line 48 in src/cli/msig/hyphaAccountsCreate.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'auth_parent' is not in camel case
},
};
const hyphaDaoLinkauthScheduler = {
account: 'tonomy',
name: 'linkauth',
authorization: [
{
actor: 'dao.hypha',
permission: 'active',
},
],
data: {
account: 'dao.hypha',
code: 'dao.hypha',
type: 'removedtx',
requirement: 'scheduler',
},
};
const hyphaDaoAutoenrollPermission = {
account: 'tonomy',
name: 'updateauth',
authorization: [
{
actor: 'dao.hypha',
permission: 'active',
},
tonomyGovOwnerPermission,
tonomyGovActivePermission,
],
data: {
account: 'dao.hypha',
permission: 'autoenroll',
parent: 'active',
auth: {
threshold: 1,
waits: [],
accounts: [
{
permission: {
actor: 'join.hypha',
permission: 'eosio.code',
},
weight: 1,
},
],
keys: [],
},
auth_parent: true,

Check failure on line 96 in src/cli/msig/hyphaAccountsCreate.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'auth_parent' is not in camel case
},
};
const hyphaDaoLinkauthAutoenroll = {
account: 'tonomy',
name: 'linkauth',
authorization: [
{
actor: 'dao.hypha',
permission: 'active',
},
],
data: {
account: 'dao.hypha',
code: 'dao.hypha',
type: 'autoenroll',
requirement: 'autoenroll',
},
};
const voiceHyphaUpdateAuthActive = {
account: 'tonomy',
name: 'updateauth',
authorization: [
{
actor: 'voice.hypha',
permission: 'active',
},
tonomyGovActivePermission,
tonomyGovActivePermission,
],
data: {
account: 'voice.hypha',
permission: 'active',
parent: 'owner',
auth: {
threshold: 1,
waits: [],
accounts: [
{
permission: {
actor: 'dao.hypha',
permission: 'eosio.code',
},
weight: 1,
},
{
permission: {
actor: 'gov.tmy',
permission: 'active',
},
weight: 1,
},
{
permission: {
actor: 'voice.hypha',
permission: 'eosio.code',
},
weight: 1,
},
],
keys: [
{
key: 'EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB',
weight: 1,
},
],
},
auth_parent: false,

Check failure on line 163 in src/cli/msig/hyphaAccountsCreate.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'auth_parent' is not in camel case
},
};
const hyphaHyphaUpdateAuthActive = {
account: 'tonomy',
name: 'updateauth',
authorization: [
{
actor: 'hypha.hypha',
permission: 'active',
},
tonomyGovOwnerPermission,
tonomyGovActivePermission,
],
data: {
account: 'hypha.hypha',
permission: 'active',
parent: 'owner',
auth: {
threshold: 1,
waits: [],
accounts: [
{
permission: {
actor: 'dao.hypha',
permission: 'eosio.code',
},
weight: 1,
},
{
permission: {
actor: 'gov.tmy',
permission: 'active',
},
weight: 1,
},
{
permission: {
actor: 'hypha.hypha',
permission: 'eosio.code',
},
weight: 1,
},
],
keys: [
{
key: 'EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB',
weight: 1,
},
],
},
auth_parent: false,

Check failure on line 214 in src/cli/msig/hyphaAccountsCreate.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'auth_parent' is not in camel case
},
};
const husdHyphaUpdateAuthActive = {
account: 'tonomy',
name: 'updateauth',
authorization: [
{
actor: 'husd.hypha',
permission: 'active',
},
tonomyGovActivePermission,
tonomyGovActivePermission,
],
data: {
account: 'husd.hypha',
permission: 'active',
parent: 'owner',
auth: {
threshold: 1,
waits: [],
accounts: [
{
permission: {
actor: 'dao.hypha',
permission: 'eosio.code',
},
weight: 1,
},
{
permission: {
actor: 'gov.tmy',
permission: 'active',
},
weight: 1,
},
{
permission: {
actor: 'husd.hypha',
permission: 'eosio.code',
},
weight: 1,
},
],
keys: [
{
key: 'EOS5DMPJ4DsJ2Vc4f7g5o8z9o5HswcpXrE4C58r7wxxzZgYxQn8rB',
weight: 1,
},
],
},
auth_parent: false,

Check failure on line 265 in src/cli/msig/hyphaAccountsCreate.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'auth_parent' is not in camel case
},
};

const actions = [
hyphaDaoSchedulerPermission,
hyphaDaoLinkauthScheduler,
hyphaDaoAutoenrollPermission,
hyphaDaoLinkauthAutoenroll,
voiceHyphaUpdateAuthActive,
hyphaHyphaUpdateAuthActive,
husdHyphaUpdateAuthActive,
];

const proposalHash = await createProposal(options.proposer, options.proposalName, actions, options.privateKey, [
...options.requested,
]);

if (options.test) await executeProposal(options.proposer, options.proposalName, proposalHash);
}
34 changes: 29 additions & 5 deletions src/cli/msig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hyphaContractSet } from './hyphaContractSet';
import { setResourceConfig } from './setResourceConfig';
import { setBlockchainConfig } from './setBlockchainConfig';
import { addProd, changeProds, removeProd } from './producers';
import { hyphaAccountsCreate } from './hyphaAccountsCreate';

const eosioMsigContract = EosioMsigContract.Instance;

Expand Down Expand Up @@ -53,6 +54,7 @@ export default async function msig(args: string[]) {

const proposer = newGovernanceAccounts[0];
let signingKey: string | undefined = process.env.SIGNING_KEY;
const signingAccount = proposer;

if (!signingKey) {
if (!process.env.TONOMY_BOARD_PRIVATE_KEYS)
Expand All @@ -69,7 +71,7 @@ export default async function msig(args: string[]) {
const proposalName = Name.from(args[1]);

try {
const transaction = await eosioMsigContract.cancel(proposer, proposalName, proposer, signer);
const transaction = await eosioMsigContract.cancel(proposer, proposalName, signingAccount, signer);

console.log('Transaction: ', JSON.stringify(transaction, null, 2));
console.error('Transaction succeeded');
Expand Down Expand Up @@ -204,6 +206,17 @@ export default async function msig(args: string[]) {
test,
}
);
} else if (proposalType === 'hypha-accounts-create') {
await hyphaAccountsCreate(
{},
{
proposer,
proposalName,
privateKey,
requested: newGovernanceAccounts,
test,
}
);
} else if (proposalType === 'res-config-set') {
await setResourceConfig(
{},
Expand Down Expand Up @@ -233,7 +246,13 @@ export default async function msig(args: string[]) {
const proposalName = Name.from(args[1]);

try {
const transaction = await eosioMsigContract.approve(proposer, proposalName, proposer, undefined, signer);
const transaction = await eosioMsigContract.approve(
proposer,
proposalName,
signingAccount,
undefined,
signer
);

console.log('Transaction: ', JSON.stringify(transaction, null, 2));
console.error('Transaction succeeded');
Expand All @@ -245,7 +264,7 @@ export default async function msig(args: string[]) {
const proposalName = Name.from(args[1]);

try {
const transaction = await eosioMsigContract.exec(proposer, proposalName, proposer, signer);
const transaction = await eosioMsigContract.exec(proposer, proposalName, signingAccount, signer);

console.log('Transaction: ', JSON.stringify(transaction, null, 2));
console.error('Transaction succeeded');
Expand Down Expand Up @@ -327,7 +346,12 @@ export async function createProposal(
}
}

export async function executeProposal(proposer: string, proposalName: Name, proposalHash: Checksum256) {
export async function executeProposal(
proposer: string,
proposalName: Name,
proposalHash: Checksum256,
signingAccount?: NameType
) {
if (!process.env.TONOMY_BOARD_PRIVATE_KEYS) throw new Error('TONOMY_BOARD_PRIVATE_KEYS not set');
const tonomyGovKeys: string[] = JSON.parse(process.env.TONOMY_BOARD_PRIVATE_KEYS).keys;
const tonomyGovSigners = tonomyGovKeys.map((key) => createSigner(PrivateKey.from(key)));
Expand All @@ -345,7 +369,7 @@ export async function executeProposal(proposer: string, proposalName: Name, prop

console.log('Proposal approved succeeded');

await eosioMsigContract.exec(proposer, proposalName, proposer, tonomyGovSigners[0]);
await eosioMsigContract.exec(proposer, proposalName, signingAccount ?? proposer, tonomyGovSigners[0]);

console.log('Proposal executed succeeded');
} catch (e) {
Expand Down

0 comments on commit 27b53c9

Please sign in to comment.