-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR fixes the issue with publishing the kread bundles. To fix it `agoric published` has been replaced by the `installBundles` script in the `agoric/contract/scripts/` folder. The script connects to the chain using Cosmos StargateClient library and sends a transaction to the correct endpoint with the bundle as payload. This is along the lines of what happens under the hood of `agoric publish` as well but for some reason that seems to be broken currently. For funding the gas fees of the transaction, the same account is used that funds the transactions to publish the committee bundles and sends proposals for the kread-committee and kread. Also, in this PR: - Added some extra steps to `make kread-committee` (and no-build version) that fetches the address that is to be funded from the `AGORIC_SDK_PATH/packages/cosmic-swingset/t1/8000/` folder and funds it. This way we no longer need to run `kread-committee`, copy the logged address and fund it. - Reverted back to the old folder structure where the contract code lives in `src` instead of the versioned folder structere. ## Related Issues Fixes #111 ## Checklist Make sure all items are checked before submitting the pull request. Remove any items that are not applicable. - [x] I have used agoric's linter on my code (Agoric/agoric-sdk#8274) - [x] I have updated the documentation to reflect the changes (if applicable). - [x] I have added/updated unit tests to cover the changes. - [x] All existing tests pass.
- Loading branch information
1 parent
064b281
commit 56f72c4
Showing
37 changed files
with
356 additions
and
3,143 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
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
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
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,101 @@ | ||
/* 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', | ||
}); | ||
|
||
/** | ||
* Gets the wallet from the mnemonic and uses it to connect to the chain using a stargate client | ||
* | ||
* @param {string} walletMnemonic the mnemonic of the wallet that signs the transaction | ||
* @returns A stargate client | ||
*/ | ||
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), | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* Parse bundle, get wallet and send transaction | ||
* over stargate to install the bundle on chain | ||
*/ | ||
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.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.