-
Notifications
You must be signed in to change notification settings - Fork 39
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
Documentation for the CoreEval feature #799
Changes from 14 commits
79db198
f5ca122
3076b3a
b429cf0
41ea905
398d7e6
647a07c
1d56b80
b22d2dd
fe3040a
c09f748
78aebad
e5492db
ef84da2
ca2b873
0a94fdd
0dbc077
eb90ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Injecting Code to Agoric Testnet | ||
|
||
Agoric facilitates safely injecting code to the Agoric testnet, usually for the purpose of running a contract and modifying it based on the result of a governance vote. To do so, we submit a proposal using cosmos-sdk level API ([swingset.CoreEval](https://community.agoric.com/t/blder-dao-governance-using-arbitrary-code-injection-swingset-coreeval/99)). If the proposal passes its governance vote, its JavaScript code is run with ocaps extracted using the proposal's declared capabilities, which the code can combine to perform privileged tasks. | ||
|
||
To do this, do the following: | ||
|
||
1. [Declare the capabilities that the proposal will require](./permissions.md). | ||
2. [Code the proposal itself](./proposal.md). | ||
3. [Deploy the proposal to a local testnet](./local-testnet.md). | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Deploy a Governance Proposal to a Local Testnet | ||
|
||
To create, start, and deploy an Agoric governance proposal to a local Agoric Testnet, do the following: | ||
|
||
1. If you're using a Mac, ensure that you have [Xcode](https://apps.apple.com/us/app/xcode/id497799835) installed. | ||
2. Create a project folder that will allow you to run a local blockchain: | ||
|
||
```jsx | ||
agoric init <The name of your project> | ||
``` | ||
|
||
For example, if you wanted to run your local blockchain from a folder named "Demo", you'd run this command: | ||
|
||
```jsx | ||
agoric init Demo | ||
``` | ||
|
||
**Note:** Your project folder should *not* be located within your local clone of the agoric SDK. | ||
|
||
3. Install additional dependencies by entering your project folder and running the following command. | ||
|
||
```jsx | ||
cd <Name of your project (e.g., Demo)> | ||
agoric install | ||
``` | ||
|
||
4. Start the chain by running the following command. (**Note:** You should still be located within your project folder.) | ||
|
||
```jsx | ||
agoric start local-chain --verbose --reset | ||
``` | ||
|
||
5. Wait for the first block to be produced. | ||
6. Open a second terminal. | ||
7. Within the second terminal, navigate to `<agoric-sdk>/bin` and submit the governance proposal by running the following command. | ||
|
||
``` | ||
./agd --chain-id=agoriclocal --title=<Insert your own title> --description=<Insert your description> --home=<PATH to your project folder>/_agstate/keys --keyring-backend=test --from=provision tx gov submit-proposal swingset-core-eval <PATH to permissions> <PATH to proposal> | ||
``` | ||
|
||
For example, to deploy the PSM proposal referenced in the previous topics, run the following: | ||
|
||
``` | ||
./agd --chain-id=agoriclocal --title=<Insert your own title> --description=<Insert your description> --home=<PATH to your project folder>/_agstate/keys --keyring-backend=test --from=provision tx gov submit-proposal swingset-core-eval ../packages/inter-protocol/test/psm/gov-add-psm-permit.json ../packages/inter-protocol/test/psm/gov-add-psm.js | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Declaring Required Capabilities | ||
|
||
Write a json file declaring the capabilities that the proposal will need. For example, | ||
[gov-add-psm-permit.json](https://github.com/Agoric/agoric-sdk/blob/master/packages/inter-protocol/test/psm/gov-add-psm-permit.json) | ||
declares capabilities needed to start a new PSM contract. Note that capabilities are declared using | ||
their name as a property along with any truthy value. For example,`"bankManager": true` and | ||
`"bankManager": 'hello'` are equivalent; they both set the `bankManager` capability. | ||
|
||
::: details Show example permissions file | ||
``` | ||
{ | ||
"consume": { | ||
"agoricNamesAdmin": true, | ||
"bankManager": true, | ||
"board": true, | ||
"chainStorage": true, | ||
"zoe": "zoe", | ||
"feeMintAccess": "zoe", | ||
"economicCommitteeCreatorFacet": "economicCommittee", | ||
"econCharterKit": true, | ||
"provisionPoolStartResult": true, | ||
"psmKit": true, | ||
"chainTimerService": "timer" | ||
}, | ||
"produce": { | ||
"testFirstAnchorKit": true | ||
}, | ||
"installation": { | ||
"consume": { | ||
"contractGovernor": true, | ||
"psm": true, | ||
"mintHolder": true | ||
} | ||
}, | ||
"instance": { | ||
"consume": { | ||
"economicCommittee": true | ||
} | ||
}, | ||
"issuer": { | ||
"produce": { | ||
"DAI": true | ||
}, | ||
"consume": { | ||
"DAI": true | ||
} | ||
}, | ||
"brand": { | ||
"consume": { | ||
"DAI": true, | ||
"IST": true | ||
}, | ||
"produce": { | ||
"DAI": true | ||
} | ||
} | ||
} | ||
``` | ||
::: | ||
|
||
## Top Level Consume Section | ||
|
||
In this section you need to set all the permissions that your contract will need to be able to use | ||
(i.e., "consume"). Some of the listed permissions in the example PSM permission file above are of | ||
general interest to most contracts, while others are more specific to the PSM contract. | ||
|
||
* **agoricNamesAdmin**: Grants write access to the Agoric name service. This permission is somewhat specific to the PSM contract. | ||
* **bankManager**: Grants access to bank-related functionality within ERTP, allowing the contract to manipulate nearly all Cosmos assets in the chain. Because this capability is very powerful, this permission should only be granted to contracts that absolutely need it. | ||
* **board**: Grants write access to the [board name service](/guides/wallet/README.md#the-agoric-board). | ||
* **chainStorage**: Grants write access to the chain storage node, which is required when running `agd query` commands. Thus, most contracts will need access to this. | ||
* **zoe**: When this permission is set, it grants access to the Zoe framework. All contracts will need access to this. | ||
* **feeMintAccess**: When this permission is set, the contract will be able to create digital assets. Only contracts that mint privileged Agoric digital assets (i.e., not the unprivileged **[zcf.makeZCFMint()](/reference/zoe-api/zoe-contract-facet.md#zcf-makezcfmint-keyword-assetkind-displayinfo)**) will need access to this. | ||
* **economicCommitteeCreatorFacet**, **econCharterKit**, **provisionPoolStartResult**: These 3 permissions are required by governed contracts. | ||
* **chainTimerService**: When this permission is set, it grants access to the *chainTimerService*. All governed contracts need access to this so they know when a vote is complete. | ||
|
||
## Top Level Produce Section | ||
|
||
Specifies what, if anything, the contract produces. For example, the example PSM contract | ||
produces *testFirstAnchorKit* which is used for testing purposes. | ||
|
||
## Installation Section | ||
|
||
Specifies what well-known installations the contract requires. At a minimum, the contract itself should | ||
be listed as an installation. Governed contracts should include a *contractGovernor* installation. | ||
|
||
## Instance Section | ||
|
||
Specifies what instances, if any, the contract produces or consumes. | ||
|
||
## Issuer Section | ||
|
||
Specifies what **[Issuers](/reference/ertp-api/issuer.md)**, if any, the contract produces or consumes. | ||
|
||
## Brand Section | ||
|
||
dckc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Specifies what **[Brands](/reference/ertp-api/brand.md)**, if any, the contract produces or consumes. | ||
Note that any **Brands** associated with digital assets that the contract mints | ||
are not included in this section, unless they're also produced or consumed in some other capacity. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand why this "not included in this section" note is here. It seems wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was based on a misunderstanding I had of what the Brand & Issuer sections contained. I've deleted the note. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Code the Proposal | ||
|
||
You will need to write a proposal script that runs the contract, and possibly does additional things depending on your needs. (Usually these additional things will be dependent on a governance vote.) For example, [gov-add-psm.js](https://github.com/Agoric/agoric-sdk/blob/master/packages/inter-protocol/test/psm/gov-add-psm.js) is a proposal Agoric created for the PSM contract: | ||
|
||
::: details Show example proposal | ||
```jsx | ||
/* global startPSM */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The global environment for CoreEval scripts is another thing we should document: where Documenting And
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like you're saying that startPSM isn't a part of CoreEval's global environment anymore. But gov-add-psm.js is checked-in code, it appears to assume that startPSM is part of its global environment, and the code works when I run it. So it seems like startPSM is still in global? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, but there are no automated tests for it
That surprises me. There are no errors in the agd logs? And you can see a new PSM contract started with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelfig , @Tyrosine22 says you were there when it worked for him. Any idea how the global reference to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: just say "The script executes in an environment with globals such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We verified that the vote passed and that something happened on the chain.
I don't know if the proposal contents were viable or completed successfully, only that they were initiated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following text was added to the top blurb on proposal.md: "The script executes in an environment with globals such as E and Far provided." |
||
// @ts-nocheck | ||
|
||
/** | ||
* @typedef {{ | ||
* denom: string, | ||
* keyword?: string, | ||
* proposedName?: string, | ||
* decimalPlaces?: number | ||
* }} AnchorOptions | ||
*/ | ||
|
||
/** @type {AnchorOptions} */ | ||
const DAI = { | ||
keyword: 'DAI', | ||
decimalPlaces: 18, | ||
denom: 'ibc/toydai', | ||
proposedName: 'Maker DAI', | ||
}; | ||
|
||
const config = { | ||
options: { anchorOptions: DAI }, | ||
WantMintedFeeBP: 1n, | ||
GiveMintedFeeBP: 3n, | ||
MINT_LIMIT: 0n, | ||
}; | ||
|
||
/** @param {unknown} permittedPowers see gov-add-psm-permit.json */ | ||
const main = async permittedPowers => { | ||
console.log('starting PSM:', DAI); | ||
const { | ||
consume: { feeMintAccess: _, ...restC }, | ||
...restP | ||
} = permittedPowers; | ||
const noMinting = { consume: restC, ...restP }; | ||
await Promise.all([ | ||
startPSM.makeAnchorAsset(noMinting, { | ||
options: { anchorOptions: DAI }, | ||
}), | ||
startPSM.startPSM(permittedPowers, config), | ||
]); | ||
console.log('started PSM:', config); | ||
}; | ||
|
||
// "export" from script | ||
main; | ||
|
||
``` | ||
::: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"How can I tell?" I can imagine our audience asking. I suggest providing an example log entry showing a block being produced.
(suggestion; not critical / important)