Skip to content

Commit

Permalink
9063 make account (#9489)
Browse files Browse the repository at this point in the history
closes: #9063

## Description

Wrapping up lose ends to close #9063. Whatever's left belongs in a new
ticket.


### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

<!-- What aspects of this PR are relevant to upgrading live production
systems, and how should they be addressed? -->
  • Loading branch information
mergify[bot] committed Jun 12, 2024
2 parents 1d94913 + 521dfd0 commit 0282e58
Show file tree
Hide file tree
Showing 22 changed files with 429 additions and 57 deletions.

Large diffs are not rendered by default.

Binary file not shown.
5 changes: 4 additions & 1 deletion packages/boot/test/bootstrapTests/vat-orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test('makeAccount returns an ICA connection', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand All @@ -95,7 +96,7 @@ test('makeAccount returns an ICA connection', async t => {
t.regex(remoteAddress, /icahost/);
t.regex(localAddress, /icacontroller/);
t.regex(chainAddress.address, /cosmos1/);
t.regex(chainAddress.chainId, /FIXME/); // TODO, use a real chainId #9063
t.is(chainAddress.chainId, 'somechain-1');
t.truthy(matches(port, M.remotable('Port')));
t.log('ICA Account Addresses', {
remoteAddress,
Expand All @@ -113,6 +114,7 @@ test('ICA connection can be closed', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand All @@ -134,6 +136,7 @@ test('ICA connection can send msg with proto3', async t => {
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'somechain-1',
'connection-0',
'connection-0',
);
Expand Down
1 change: 1 addition & 0 deletions packages/orchestration/scripts/fetch-chain-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const outputFile = 'src/fetched-chain-info.js';
* Names for which to fetch info
*/
const chainNames = [
'agoric',
'celestia',
'cosmoshub',
'dydx',
Expand Down
4 changes: 3 additions & 1 deletion packages/orchestration/src/chain-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import fetchedChainInfo from './fetched-chain-info.js';
const knownChains = /** @satisfies {Record<string, ChainInfo>} */ (
harden({
...fetchedChainInfo,
agoric: {
// XXX does not have useful connections
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9492
agoriclocal: {
chainId: 'agoriclocal',
connections: {
'cosmoshub-4': {
Expand Down
6 changes: 4 additions & 2 deletions packages/orchestration/src/examples/stakeIca.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const trace = makeTracer('StakeAtom');

export const meta = harden({
customTermsShape: {
chainId: M.string(),
hostConnectionId: M.string(),
controllerConnectionId: M.string(),
bondDenom: M.string(),
Expand All @@ -34,6 +35,7 @@ export const privateArgsShape = meta.privateArgsShape;

/**
* @typedef {{
* chainId: string;
* hostConnectionId: IBCConnectionID;
* controllerConnectionId: IBCConnectionID;
* bondDenom: string;
Expand All @@ -51,8 +53,7 @@ export const privateArgsShape = meta.privateArgsShape;
* @param {Baggage} baggage
*/
export const start = async (zcf, privateArgs, baggage) => {
// TODO #9063 this roughly matches what we'll get from Chain<C>.getChainInfo()
const { hostConnectionId, controllerConnectionId, bondDenom } =
const { chainId, hostConnectionId, controllerConnectionId, bondDenom } =
zcf.getTerms();
const { orchestration, marshaller, storageNode, timer } = privateArgs;

Expand All @@ -68,6 +69,7 @@ export const start = async (zcf, privateArgs, baggage) => {

async function makeAccountKit() {
const account = await E(orchestration).makeAccount(
chainId,
hostConnectionId,
controllerConnectionId,
);
Expand Down
14 changes: 7 additions & 7 deletions packages/orchestration/src/examples/swapExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ export const start = async (zcf, privateArgs, baggage) => {
async (/** @type {Orchestrator} */ orch, { zcf }, seat, offerArgs) => {
const { give } = seat.getProposal();

const celestia = await orch.getChain('celestia');
const omni = await orch.getChain('omniflixhub');
const agoric = await orch.getChain('agoric');

const [celestiaAccount, localAccount] = await Promise.all([
celestia.makeAccount(),
const [omniAccount, localAccount] = await Promise.all([
omni.makeAccount(),
agoric.makeAccount(),
]);

const tiaAddress = celestiaAccount.getAddress();
const omniAddress = omniAccount.getAddress();

// deposit funds from user seat to LocalChainAccount
const payments = await withdrawFromSeat(zcf, seat, give);
Expand All @@ -122,8 +122,8 @@ export const start = async (zcf, privateArgs, baggage) => {

// build swap instructions with orcUtils library
const transferMsg = orcUtils.makeOsmosisSwap({
destChain: 'celestia',
destAddress: tiaAddress,
destChain: 'omniflixhub',
destAddress: omniAddress,
amountIn: give.Stable,
brandOut: /** @type {any} */ ('FIXME'),
slippage: 0.03,
Expand All @@ -132,7 +132,7 @@ export const start = async (zcf, privateArgs, baggage) => {
await localAccount
.transferSteps(give.Stable, transferMsg)
.then(_txResult =>
celestiaAccount.delegate(offerArgs.validator, offerArgs.staked),
omniAccount.delegate(offerArgs.validator, offerArgs.staked),
)
.catch(e => console.error(e));

Expand Down
6 changes: 3 additions & 3 deletions packages/orchestration/src/examples/unbondExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const start = async (zcf, privateArgs, baggage) => {
// We would actually alreaady have the account from the orchestrator
// ??? could these be passed in? It would reduce the size of this handler,
// keeping it focused on long-running operations.
const celestia = await orch.getChain('celestia');
const celestiaAccount = await celestia.makeAccount();
const omni = await orch.getChain('omniflixhub');
const omniAccount = await omni.makeAccount();

// TODO implement these
// const delegations = await celestiaAccount.getDelegations();
Expand All @@ -86,7 +86,7 @@ export const start = async (zcf, privateArgs, baggage) => {
// await celestiaAccount.transfer(tiaAmt, strideAccount.getAddress());

// await strideAccount.liquidStake(tiaAmt);
console.log(celestiaAccount, strideAccount);
console.log(omniAccount, strideAccount);
},
);

Expand Down
9 changes: 5 additions & 4 deletions packages/orchestration/src/exos/chainAccountKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const ChainAccountI = M.interface('ChainAccount', {

/**
* @typedef {{
* chainId: string;
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: LocalIbcAddress | undefined;
Expand All @@ -60,11 +61,13 @@ export const prepareChainAccountKit = zone =>
'ChainAccountKit',
{ account: ChainAccountI, connectionHandler: ConnectionHandlerI },
/**
* @param {string} chainId
* @param {Port} port
* @param {string} requestedRemoteAddress
*/
(port, requestedRemoteAddress) =>
(chainId, port, requestedRemoteAddress) =>
/** @type {State} */ ({
chainId,
port,
connection: undefined,
requestedRemoteAddress,
Expand Down Expand Up @@ -158,9 +161,7 @@ export const prepareChainAccountKit = zone =>
this.state.localAddress = localAddr;
this.state.chainAddress = harden({
address: findAddressField(remoteAddr) || UNPARSABLE_CHAIN_ADDRESS,
// TODO get this from `Chain` object #9063
// XXX how do we get a chainId for an unknown chain? seems it may need to be a user supplied arg
chainId: 'FIXME',
chainId: this.state.chainId,
addressEncoding: 'bech32',
});
},
Expand Down
34 changes: 20 additions & 14 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAcc
/**
* @import {Zone} from '@agoric/zone';
* @import {TimerService} from '@agoric/time';
* @import {IBCConnectionID} from '@agoric/vats';
* @import {LocalChain} from '@agoric/vats/src/localchain.js';
* @import {Remote} from '@agoric/internal';
* @import {OrchestrationService} from './service.js';
* @import {Chain, ChainInfo, CosmosChainInfo, OrchestrationAccount, Orchestrator} from './types.js';
* @import {Chain, ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, Orchestrator} from './types.js';
*/

/** @type {any} */
Expand Down Expand Up @@ -91,6 +92,7 @@ const makeLocalChainFacade = (
/**
* @template {CosmosChainInfo} CCI
* @param {CCI} chainInfo
* @param {IBCConnectionInfo} connectionInfo
* @param {object} io
* @param {Remote<OrchestrationService>} io.orchestration
* @param {Remote<TimerService>} io.timer
Expand All @@ -100,13 +102,12 @@ const makeLocalChainFacade = (
*/
const makeRemoteChainFacade = (
chainInfo,
connectionInfo,
{ orchestration, timer, zcf, zone },
) => {
const name = chainInfo.chainId;

const makeRecorderKit = () => anyVal;
const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount(
zone.subZone(name),
zone.subZone(chainInfo.chainId),
makeRecorderKit,
zcf,
);
Expand All @@ -115,14 +116,13 @@ const makeRemoteChainFacade = (
getChainInfo: async () => chainInfo,
/** @returns {Promise<OrchestrationAccount<CCI>>} */
makeAccount: async () => {
// FIXME look up real values
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9063
const hostConnectionId = 'connection-1';
const controllerConnectionId = 'connection-2';

const icaAccount = await E(orchestration).makeAccount(
hostConnectionId,
controllerConnectionId,
chainInfo.chainId,
// XXX IBCConnectionInfo concessions for JSON encoding
/** @type {IBCConnectionID} */ (connectionInfo.id),
/** @type {IBCConnectionID} */ (
connectionInfo.counterparty.connection_id
),
);

const address = await E(icaAccount).getAddress();
Expand Down Expand Up @@ -190,17 +190,23 @@ export const makeOrchestrationFacade = ({
/** @type {Orchestrator} */
const orc = {
async getChain(name) {
const chainInfo = await chainHub.getChainInfo(name);
const agoricChainInfo = await chainHub.getChainInfo('agoric');

if (name === 'agoric') {
return makeLocalChainFacade(
localchain,
makeLocalChainAccountKit,
chainInfo,
agoricChainInfo,
);
}

return makeRemoteChainFacade(chainInfo, {
const remoteChainInfo = await chainHub.getChainInfo(name);
const connectionInfo = await chainHub.getConnectionInfo(
agoricChainInfo.chainId,
remoteChainInfo.chainId,
);

return makeRemoteChainFacade(remoteChainInfo, connectionInfo, {
orchestration: orchestrationService,
timer: timerService,
zcf,
Expand Down
Loading

0 comments on commit 0282e58

Please sign in to comment.