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

feat(run-protocol): preview launch support, PSM work-around #5215

Merged
merged 13 commits into from
Apr 26, 2022
Merged
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
42 changes: 42 additions & 0 deletions packages/run-protocol/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
TITLE = Start RUN Protocol Preview

EVAL_DEPOSIT = 1000000ubld
GAS_ADJUSTMENT = 1.2

# stage
AG_SOLO_BASEDIR = /tmp/stage23
NETWORK_CONFIG = https://stage.agoric.net/network-config
CHAIN_ID = $(shell curl -Ss "$(NETWORK_CONFIG)" | jq -r .chainName)
RPC_IP = $(shell curl -Ss "$(NETWORK_CONFIG)" | jq -r .rpcAddrs[0] | cut -d":" -f1)
CHAIN_OPTS = --node=http://$(RPC_IP):26657 --chain-id=$(CHAIN_ID)

# local-chain
# AG_SOLO_BASEDIR=../cosmic-swingset/t1/8000
# CHAIN_ID = agoric
# CHAIN_OPTS = --chain-id=$(CHAIN_ID)

# pairs of permit, code
EVALS = gov-econ-committee-permit.json gov-econ-committee.js \
gov-amm-vaults-etc-permit.json gov-amm-vaults-etc.js \
./scripts/gov-startPSM-permit.json ./scripts/gov-startPSM.js

submit-proposal: $(EVALS)
git describe --tags --always
agd $(CHAIN_OPTS) \
--home=$(AG_SOLO_BASEDIR)/ag-cosmos-helper-statedir --keyring-backend=test \
tx gov submit-proposal swingset-core-eval \
$(EVALS) \
--title="$(TITLE) on $(CHAIN_ID)" --description="$$(cat ./docs/run-protocol-preview.md)" \
--deposit=$(EVAL_DEPOSIT) \
--gas=auto --gas-adjustment=$(GAS_ADJUSTMENT) \
--yes --from=ag-solo -b block


gov-q:
agd $(CHAIN_OPTS) query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]';

ADDR=agoric1z8vavxgfjztlhay5kftgp4kp5l4znkh4gf8lg4

bank-q:
agd $(CHAIN_OPTS) query bank balances $(ADDR)
25 changes: 25 additions & 0 deletions packages/run-protocol/docs/run-protocol-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Start RUN Protocol Preview on Devnet

We propose to launch a preview of the RUN Protocol on Devnet,
comprising the following contracts:

- runStake - borrow RUN against staked BLD
- AMM - Automated Market Maker
- VaultFactory - collateralized RUN debt positions
- liquidateMinimum
- PSM - Parity Stability Module
- mintHolder
- reserve - asset reserve for the RUN protocol

along with supporting governance contracts:
- contractGovernor
- binaryVoteCounter
- committee

This is a `swingset-core-eval` proposal that includes JavaScript to execute to enact the proposal, as well as a JSON policy to limit the capabilities of the proposal.

See also:
- [using keplr wallet for devnet governance and staking](https://github.com/Agoric/documentation/issues/668)
- [Install RUN Protocol Preview release in devnet on April 22 · Issue \#5062 · Agoric/agoric\-sdk](https://github.com/Agoric/agoric-sdk/issues/5062)
- https://agoric.com/discord channel `#devnet`
- https://commonwealth.im/agoric
5 changes: 4 additions & 1 deletion packages/run-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"scripts": {
"build": "yarn build:bundles",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this build * like 'lint' does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps... but some of the build:* things involve blockchain access, so they don't fit the same workflow.

"build:bundles": "node ./scripts/build-bundles.js",
"deploy:proposal": "agoric deploy ./scripts/init-core.js",
"build:eval:main": "agoric deploy ./scripts/init-core.js",
"deploy:contracts": "agoric deploy scripts/deploy-contracts.js",
"build:eval-permit:psm": "node src/psm/writePsmScript.js --permit >scripts/gov-startPSM-permit.json",
"build:eval-code:psm": "node src/psm/writePsmScript.js >scripts/gov-startPSM.js; yarn prettier --write scripts/gov-startPSM.js",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
Expand Down
101 changes: 101 additions & 0 deletions packages/run-protocol/scripts/deploy-contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env node
// @ts-check
import url from 'url';
import { makeHelpers } from '@agoric/deploy-script-support';
import { E } from '@endo/eventual-send';
import { getCopyMapEntries, makeCopyMap } from '@agoric/store';

// TODO: CLI options to choose contracts
const contractRefs = [
'../../governance/bundles/bundle-contractGovernor.js',
'../../governance/bundles/bundle-committee.js',
'../../governance/bundles/bundle-binaryVoteCounter.js',
'../bundles/bundle-runStake.js',
'../bundles/bundle-amm.js',
'../bundles/bundle-vaultFactory.js',
'../bundles/bundle-liquidateMinimum.js',
'../bundles/bundle-reserve.js',
'../bundles/bundle-psm.js',
'../../vats/bundles/bundle-mintHolder.js',
];
const contractRoots = contractRefs.map(ref =>
url.fileURLToPath(new URL(ref, import.meta.url)),
);

/** @type {<T>(store: any, key: string, make: () => T) => Promise<T>} */
const provide = async (store, key, make) => {
const found = await E(store).get(key);
if (found) {
return found;
}
const value = make();
await E(store).set(key, value);
return value;
};

export default async (homeP, endowments) => {
const home = await homeP;
const { zoe, scratch, board } = home;

const { installInPieces, getBundlerMaker } = await makeHelpers(
homeP,
endowments,
);
const bundler = E(getBundlerMaker({ log: console.log })).makeBundler({
zoe,
});

console.log('getting installCache...');
/** @type {CopyMap<string, {installation: Installation, boardId: string, path?: string}>} */
const initial = await provide(scratch, 'installCache', () => makeCopyMap([]));
console.log('initially:', initial.payload.keys.length, 'entries');

// ISSUE: getCopyMapEntries of CopyMap<K, V> loses K, V.
/** @type {Map<string, {installation: Installation, boardId: string, path?: string}>} */
const working = new Map(getCopyMapEntries(initial));

let added = 0;

/** @type {EndoZipBase64Bundle[]} */
const bundles = await Promise.all(
contractRoots.map(path => import(path).then(m => m.default)),
);

let ix = 0;
for await (const bundle of bundles) {
const sha512 = bundle.endoZipBase64Sha512;
if (working.has(bundle.endoZipBase64Sha512)) {
console.log('hit:', { path: contractRefs[ix], sha512 });
} else {
console.log('miss:', {
path: contractRefs[ix],
length: bundle.endoZipBase64.length,
sha512,
});
const installation = await installInPieces(bundle, bundler, {
persist: true,
});
const boardId = await E(board).getId(installation);
working.set(sha512, { installation, boardId, path: contractRefs[ix] });
added += 1;
}
ix += 1;
}

const final = makeCopyMap(working);
assert.equal(final.payload.keys.length, working.size);
await (added > 0 && E(home.scratch).set('installCache', final));
console.log({
initial: initial.payload.keys.length,
added,
total: working.size,
});

const items = [...working.entries()]
.map(([sha512, { boardId, path }]) => ({ sha512, boardId, path }))
.sort();
const boardId = await E(board).getId(JSON.stringify(items));
console.log({
boardId,
});
};
48 changes: 48 additions & 0 deletions packages/run-protocol/scripts/gov-startPSM-permit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"consume": {
"bankManager": "bank",
"zoe": "zoe",
"feeMintAccess": "zoe",
"economicCommitteeCreatorFacet": "economicCommittee",
"chainTimerService": "timer",
"agoricNamesAdmin": true,
"board": true
},
"installation": {
"consume": {
"mintHolder": "zoe",
"contractGovernor": "zoe",
"psm": "zoe"
}
},
"issuer": {
"produce": {
"AUSD": true
},
"consume": {
"AUSD": "bank"
}
},
"brand": {
"produce": {
"AUSD": true
},
"consume": {
"AUSD": "bank",
"RUN": "zoe"
}
},
"produce": {
"psmCreatorFacet": "psm",
"psmGovernorCreatorFacet": "psmGovernor"
},
"instance": {
"consume": {
"economicCommittee": "economicCommittee"
},
"produce": {
"psm": "psm",
"psmGovernor": "psm"
}
}
}
Loading