Skip to content

Commit

Permalink
refactor: moved hypha to one file
Browse files Browse the repository at this point in the history
  • Loading branch information
theblockstalk committed Oct 14, 2024
1 parent 6ded487 commit 4d5fff7
Show file tree
Hide file tree
Showing 4 changed files with 340 additions and 318 deletions.
324 changes: 324 additions & 0 deletions src/cli/msig/hypha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
import { Authority, bytesToTokens } from '../../sdk/services/blockchain';
import { StandardProposalOptions, createProposal, executeProposal } from '.';
import { deployContract } from './deployContract';
import { AccountType, getSettings, TonomyUsername } from '../../sdk';
import { Name } from '@wharfkit/antelope';

// @ts-expect-error args not used
export async function hyphaAccountsCreate(args: any, options: StandardProposalOptions) {
function createNewAccountAction(name: string, active: Authority, owner: Authority) {
return {
account: 'tonomy',
name: 'newaccount',
authorization: [
{
actor: 'tonomy',
permission: 'owner',
},
{
actor: 'tonomy',
permission: 'active',
},
],
data: {
creator: 'tonomy',
name,
owner,
active,
},
};
}

const tonomyGovActivePermission = {
actor: 'gov.tmy',
permission: 'active',
};

const daoHyphaAction = createNewAccountAction(
'dao.hypha',
Authority.fromKey('EOS7pMcjCS15XKxEssnFqKeq5HUJVTuoXMBbjYfGrQJrya2TSxgNV').addAccount(
tonomyGovActivePermission
),
Authority.fromKey('EOS7pMcjCS15XKxEssnFqKeq5HUJVTuoXMBbjYfGrQJrya2TSxgNV').addAccount(tonomyGovActivePermission)
);
const voiceHyphaOwner = Authority.fromKey('EOS55WiNqboivthg3uERZkdj4saxbSt8D33KQzWqaMBCXASoqxFsP').addAccount(
tonomyGovActivePermission
);
const voiceHyphaActive = Authority.fromKey('EOS55WiNqboivthg3uERZkdj4saxbSt8D33KQzWqaMBCXASoqxFsP').addAccount(
tonomyGovActivePermission
);

voiceHyphaActive.addCodePermission('dao.hypha');
voiceHyphaActive.addCodePermission('voice.hypha');
const voiceHyphaAction = createNewAccountAction('voice.hypha', voiceHyphaActive, voiceHyphaOwner);

const hyphaHyphaOwner = Authority.fromKey('EOS6KTU2YYtnN8ZRXDcG4cdFpRGkRssrBgR1u7Y3YqUX3KYYcfpRP').addAccount(
tonomyGovActivePermission
);
const hyphaHyphaActive = Authority.fromKey('EOS6KTU2YYtnN8ZRXDcG4cdFpRGkRssrBgR1u7Y3YqUX3KYYcfpRP').addAccount(
tonomyGovActivePermission
);

hyphaHyphaActive.addCodePermission('dao.hypha');
hyphaHyphaActive.addCodePermission('hypha.hypha');
const hyphaHyphaAction = createNewAccountAction('hypha.hypha', hyphaHyphaActive, hyphaHyphaOwner);

const husdHyphaOwner = Authority.fromKey('EOS8ftihCrL5nVJDUo4Y5qCzcJpeHuLA1jezP38j3jHm8tGDiAsbQ').addAccount(
tonomyGovActivePermission
);
const husdHyphaActive = Authority.fromKey('EOS8ftihCrL5nVJDUo4Y5qCzcJpeHuLA1jezP38j3jHm8tGDiAsbQ').addAccount(
tonomyGovActivePermission
);

husdHyphaActive.addCodePermission('dao.hypha');
husdHyphaActive.addCodePermission('husd.hypha');
const husdHyphaAction = createNewAccountAction('husd.hypha', husdHyphaActive, husdHyphaOwner);

const kvHyphaAction = createNewAccountAction(
'kv.hypha',
Authority.fromKey('EOS8kcBzk6JrzDgoAqYMHzNFrgdkxJMM595kjJxWUPEfVtnHsdKLK').addAccount(
tonomyGovActivePermission
),
Authority.fromKey('EOS8kcBzk6JrzDgoAqYMHzNFrgdkxJMM595kjJxWUPEfVtnHsdKLK').addAccount(tonomyGovActivePermission)
);
const joinHyphaAction = createNewAccountAction(
'join.hypha',
Authority.fromKey('EOS52LPbWzd8iXUS3DWnn2CkU4HE4kVRSHVtyvWK4dDMLnAUYnogB').addAccount(
tonomyGovActivePermission
),
Authority.fromKey('EOS52LPbWzd8iXUS3DWnn2CkU4HE4kVRSHVtyvWK4dDMLnAUYnogB').addAccount(tonomyGovActivePermission)
);
const srviceHyphaAction = createNewAccountAction(
'srvice.hypha',
Authority.fromKey('EOS7ammTdz8NCdpfPwwXqYck6d93iUVZaE4hgjgTyxXX1nYFEHMzJ').addAccount(
tonomyGovActivePermission
),
Authority.fromKey('EOS7ammTdz8NCdpfPwwXqYck6d93iUVZaE4hgjgTyxXX1nYFEHMzJ').addAccount(tonomyGovActivePermission)
);
const loginHyphaAction = createNewAccountAction(
'login.hypha',
Authority.fromKey('EOS7ktQxW7cPTF17VhTV6U64WVdGCtMoxM7kbszQmPYTsi5nMVfYi').addAccount(
tonomyGovActivePermission
),
Authority.fromKey('EOS7ktQxW7cPTF17VhTV6U64WVdGCtMoxM7kbszQmPYTsi5nMVfYi').addAccount(tonomyGovActivePermission)
);

const actions = [
daoHyphaAction,
voiceHyphaAction,
hyphaHyphaAction,
husdHyphaAction,
kvHyphaAction,
joinHyphaAction,
srviceHyphaAction,
loginHyphaAction,
];

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

if (options.test) await executeProposal(options.proposer, options.proposalName, proposalHash);
}

// @ts-expect-error args not used
export async function hyphaAddAccountPermissions(args: any, options: StandardProposalOptions) {
const tonomyGovActivePermission = {
actor: 'gov.tmy',
permission: 'active',
};
const tonomyGovOwnerPermission = {
actor: 'tonomy',
permission: 'owner',
};

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 161 in src/cli/msig/hypha.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 209 in src/cli/msig/hypha.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 actions = [
hyphaDaoSchedulerPermission,
hyphaDaoLinkauthScheduler,
hyphaDaoAutoenrollPermission,
hyphaDaoLinkauthAutoenroll,
];

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

if (options.test) await executeProposal(options.proposer, options.proposalName, proposalHash);
}

// @ts-expect-error args not used
export async function hyphaContractSet(args: any, options: StandardProposalOptions) {
const name = 'join';
const contract = `${name}.hypha`;
const appName = `Hypha {${name.toUpperCase()}`;
const username = `${name}hypha`;
const description = `Hypha ${name} contract`;
const logoUrl = 'https://hypha.earth/wp-content/themes/hypha2023/img/logos/logo-white.svg';
const origin = `https://${name}.pangea-test.hypha.earth`;
const ramKb = 10000;
const contractDir = `/home/dev/Downloads/pangea-hypha-deploy/${contract}`;

const tonomyUsername = TonomyUsername.fromUsername(username, AccountType.APP, getSettings().accountSuffix);
const tokens = bytesToTokens(ramKb * 1000);

console.log(`Setting up hypha contract "${contract}" with ${tokens} tokens to buy ${ramKb}KB of RAM`);

const adminSetAppAction = {
authorization: [
{
actor: 'tonomy',
permission: 'active',
},
],
account: 'tonomy',
name: 'adminsetapp',
data: {
account_name: Name.from(contract),

Check failure on line 270 in src/cli/msig/hypha.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'account_name' is not in camel case
app_name: appName,

Check failure on line 271 in src/cli/msig/hypha.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'app_name' is not in camel case
description,
username_hash: tonomyUsername.usernameHash,

Check failure on line 273 in src/cli/msig/hypha.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'username_hash' is not in camel case
logo_url: logoUrl,

Check failure on line 274 in src/cli/msig/hypha.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'logo_url' is not in camel case
origin,
},
};

const transferTokensAction = {
authorization: [
{
actor: 'partners.tmy',
permission: 'active',
},
],
account: 'eosio.token',
name: 'transfer',
data: {
from: 'partners.tmy',
to: contract,
quantity: tokens,
memo: `RAM for ${contract}`,
},
};

const buyRamAction = {
account: 'tonomy',
name: 'buyram',
authorization: [
{
actor: contract,
permission: 'active',
},
],
data: {
dao_owner: contract,

Check failure on line 306 in src/cli/msig/hypha.ts

View workflow job for this annotation

GitHub Actions / test

Identifier 'dao_owner' is not in camel case
app: contract,
quant: tokens,
},
};

const deployActions = await deployContract({ contractName: contract, contractDir, returnActions: true }, options);

if (!deployActions) throw new Error('Expected deployActions to be defined');

const actions = [adminSetAppAction, transferTokensAction, buyRamAction, ...deployActions];

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

if (options.test) await executeProposal(options.proposer, options.proposalName, proposalHash);
}
Loading

0 comments on commit 4d5fff7

Please sign in to comment.