-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
6ded487
commit 4d5fff7
Showing
4 changed files
with
340 additions
and
318 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
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, | ||
}, | ||
}; | ||
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, | ||
}, | ||
}; | ||
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), | ||
app_name: appName, | ||
description, | ||
username_hash: tonomyUsername.usernameHash, | ||
logo_url: logoUrl, | ||
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, | ||
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); | ||
} |
Oops, something went wrong.