Skip to content

Commit

Permalink
add script to install bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandelis Symeonidis committed Dec 13, 2023
1 parent 09a7050 commit 5be2e35
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 3,106 deletions.
10 changes: 9 additions & 1 deletion agoric/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ clean:
# 5. make provision-fee-collector
# 6. start the KREAd contract using 'KREAD_COMMITTEE_NAME='kread' KREAD_COMMITTEE_ADDRESSES='{"voter": "agoric1ersatz"}' make start-kread'
kread-committee: dist/kread-committee-info.json
cd $(COSMIC_SWINGSET_PATH); \
make fund-acct ACCT_ADDR=$$(head t1/8000/ag-cosmos-helper-address) FUNDS=1000000000000uist; \
make fund-acct ACCT_ADDR=$$(head t1/8000/ag-cosmos-helper-address) FUNDS=1000000000000ubld; \
cd $(AG_DIR); \
jq -r '.bundles[]' dist/kread-committee-info.json | sort -u > kread-committee-bundles.out
for b in `cat kread-committee-bundles.out` ; do \
$(AGORIC_CMD) publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
Expand All @@ -98,13 +102,17 @@ kread-committee: dist/kread-committee-info.json
start-kread: dist/start-kread-info.json
jq -r '.bundles[]' dist/start-kread-info.json | sort -u > start-kread-bundles.out
for b in `cat start-kread-bundles.out` ; do \
$(AGORIC_CMD) publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
node contract/scripts/installBundles.js $(COSMIC_SWINGSET_PATH) $$b ; \
done
cd $(COSMIC_SWINGSET_PATH); \
make scenario2-core-eval EVAL_PERMIT=$(AG_DIR)/dist/start-kread-permit.json \
EVAL_CODE=$(AG_DIR)/dist/start-kread.js EVAL_CLEAN=$(AG_DIR)/dist/start-kread.js.t scenario2-vote VOTE_PROPOSAL=$(NEXT_PROPOSAL) \

kread-committee-no-build:
cd $(COSMIC_SWINGSET_PATH); \
make fund-acct ACCT_ADDR=$$(head t1/8000/ag-cosmos-helper-address) FUNDS=1000000000000uist; \
make fund-acct ACCT_ADDR=$$(head t1/8000/ag-cosmos-helper-address) FUNDS=1000000000000ubld; \
cd $(AG_DIR); \
jq -r '.bundles[]' dist/kread-committee-info.json | sort -u > kread-committee-bundles.out
for b in `cat kread-committee-bundles.out` ; do \
$(AGORIC_CMD) publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
Expand Down
13 changes: 3 additions & 10 deletions agoric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ ensure you are in the agoric folder otherwise cd to agoric folder

1. Start the chain
1. make local-testnet
2. Update KEPLR_ADDRESS in Makefile.paths
1. try to `make kread-committee`
2. it will fail but look for `"sender","value":"agoric1` to find the address
1. if it fails for another reason, you may need to run `make reset-client-local-testnet`
3. copy that address into Makefile.paths.local for KEPLR_ADDRESS
3. fund the account
1. make fund-account
4. make the committee
2. make the committee
1. make kread-committee
5. provision the fee collector wallet
3. provision the fee collector wallet
1. make provision-fee-collector
6. start the KREAd contract
4. start the KREAd contract
1. make clean start-kread

To confirm it started,
Expand Down
6 changes: 6 additions & 0 deletions agoric/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@agoric/assert": "agoric-upgrade-11",
"@agoric/cosmic-proto": "agoric-upgrade-11",
"@agoric/deploy-script-support": "agoric-upgrade-11",
"@agoric/ertp": "agoric-upgrade-11",
"@agoric/governance": "agoric-upgrade-11",
Expand All @@ -44,6 +45,11 @@
"@agoric/vats": "agoric-upgrade-11",
"@agoric/zoe": "agoric-upgrade-11",
"@agoric/zone": "agoric-upgrade-11",
"@cosmjs/crypto": "^0.32.1",
"@cosmjs/encoding": "^0.32.1",
"@cosmjs/math": "^0.32.1",
"@cosmjs/proto-signing": "^0.32.1",
"@cosmjs/stargate": "^0.31.1",
"@endo/bundle-source": "^2.5.2-upstream-rollup",
"@endo/eventual-send": "^0.17.2",
"@endo/far": "^0.2.18",
Expand Down
91 changes: 91 additions & 0 deletions agoric/contract/scripts/installBundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* eslint-disable no-undef */
import { fromBech32 } from '@cosmjs/encoding';
import { SigningStargateClient, defaultRegistryTypes } from '@cosmjs/stargate';
import { DirectSecp256k1HdWallet, Registry, coins } from '@cosmjs/proto-signing';
import { Decimal } from '@cosmjs/math';
import { stringToPath } from '@cosmjs/crypto';
import { MsgInstallBundle } from '@agoric/cosmic-proto/swingset/msgs.js';
import * as fs from 'fs';

const RPC = 'http://localhost:26657';

const hdPath = (coinType = 118, account = 0) =>
stringToPath(`m/44'/${coinType}'/${account}'/0/0`);

export const registry = new Registry([
...defaultRegistryTypes,
['/agoric.swingset.MsgInstallBundle', MsgInstallBundle],
]);

const Agoric = {
Bech32MainPrefix: 'agoric',
CoinType: 564,
};

const makeFeeObject = ({ denom, amount, gas }) => ({
amount: coins(amount || 0, denom || 'uist'),
gas: gas ? String(gas) : 'auto',
});

const initializeStargateClient = async (walletMnemonic) => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(walletMnemonic, {
prefix: Agoric.Bech32MainPrefix,
hdPaths: [hdPath(Agoric.CoinType, 0), hdPath(Agoric.CoinType, 1)],
});

return SigningStargateClient.connectWithSigner(RPC, wallet, {
registry,
gasPrice: {
denom: 'uist',
amount: Decimal.fromUserInput('50000000', 0),
},
});
};

async function installBundle() {
const cosmicSwingsetPath = process.argv[2];
const bundlePath = process.argv[3];

const bundleText = await fs.readFileSync(bundlePath, 'utf-8');
const walletAddress = (await fs.readFileSync(
`${cosmicSwingsetPath}/t1/8000/ag-cosmos-helper-address`,
'utf-8',
)).trim();
const walletMnemonic = (await fs.readFileSync(
`${cosmicSwingsetPath}/t1/8000/ag-solo-mnemonic`,
'utf-8',
)).trim();

const proposalMsg = {
typeUrl: '/agoric.swingset.MsgInstallBundle',
value: {
bundle: bundleText,
submitter: fromBech32(walletAddress).data,
},
};

const stargateClient = await initializeStargateClient(
walletMnemonic
);

if (!stargateClient) {
throw new Error('stargateClient not found');
}

const estimate = await stargateClient.simulate(
walletAddress,
[proposalMsg],
undefined,
);
const adjustment = 1.3;
const gas = Math.ceil(estimate * adjustment);
const txResult = await stargateClient.signAndBroadcast(
walletAddress,
[proposalMsg],
makeFeeObject({ gas }),
);

console.log(txResult)
}

await installBundle();
File renamed without changes.
File renamed without changes.
File renamed without changes.
164 changes: 0 additions & 164 deletions agoric/contract/src/kreadV1/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions agoric/contract/src/kreadV2/errors.js

This file was deleted.

Loading

0 comments on commit 5be2e35

Please sign in to comment.