Skip to content

Commit

Permalink
feat(orchestration): align ChainAccount spec with current implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed May 2, 2024
1 parent f2a6d41 commit 678f21f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
10 changes: 6 additions & 4 deletions packages/boot/test/bootstrapTests/test-vat-orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MsgDelegateResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js';
import type { ChainAccount, OrchestrationService } from '@agoric/orchestration';
import type { OrchestrationService } from '@agoric/orchestration';
import { decodeBase64 } from '@endo/base64';
import { M, matches } from '@endo/patterns';
import { makeWalletFactoryContext } from './walletFactory.ts';
Expand Down Expand Up @@ -65,7 +65,8 @@ test('makeAccount returns an ICA connection', async t => {
runUtils: { EV },
} = t.context;

const orchestration = await EV.vat('bootstrap').consumeItem('orchestration');
const orchestration: OrchestrationService =
await EV.vat('bootstrap').consumeItem('orchestration');

const account = await EV(orchestration).makeAccount(
'connection-0',
Expand Down Expand Up @@ -120,9 +121,10 @@ test('ICA connection can send msg with proto3', async t => {
runUtils: { EV },
} = t.context;

const orchestration = await EV.vat('bootstrap').consumeItem('orchestration');
const orchestration: OrchestrationService =
await EV.vat('bootstrap').consumeItem('orchestration');

const account: ChainAccount = await EV(orchestration).makeAccount(
const account = await EV(orchestration).makeAccount(
'connection-0',
'connection-0',
);
Expand Down
9 changes: 5 additions & 4 deletions packages/orchestration/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { makeTxPacket, parsePacketAck } from './utils/tx.js';
* @import { Zone } from '@agoric/base-zone';
* @import { TxBody } from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
* @import { ChainAccount, ChainAddress } from './types.js';
* @import { LocalIbcAddress, RemoteIbcAddress } from '@agoric/vats/tools/ibc-utils.js';
*/

const { Fail, bare } = assert;
Expand Down Expand Up @@ -102,9 +103,9 @@ const prepareChainAccount = zone =>
* @type {{
* port: Port;
* connection: Remote<Connection> | undefined;
* localAddress: string | undefined;
* localAddress: LocalIbcAddress | undefined;
* requestedRemoteAddress: string;
* remoteAddress: string | undefined;
* remoteAddress: RemoteIbcAddress | undefined;
* chainAddress: ChainAddress | undefined;
* }}
*/ (
Expand Down Expand Up @@ -194,8 +195,8 @@ const prepareChainAccount = zone =>
connectionHandler: {
/**
* @param {Remote<Connection>} connection
* @param {string} localAddr
* @param {string} remoteAddr
* @param {LocalIbcAddress} localAddr
* @param {RemoteIbcAddress} remoteAddr
*/
async onOpen(connection, localAddr, remoteAddr) {
trace(`ICA Channel Opened for ${localAddr} at ${remoteAddr}`);
Expand Down
32 changes: 26 additions & 6 deletions packages/orchestration/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import type {
Redelegation,
UnbondingDelegation,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
import type { TxBody } from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
import type {
LocalIbcAddress,
RemoteIbcAddress,
} from '@agoric/vats/tools/ibc-utils.js';
import type { Port } from '@agoric/network';

/**
* static declaration of known chain types will allow type support for
Expand Down Expand Up @@ -239,10 +245,14 @@ export interface ChainAccount {
executeTx: (msgs: Proto3JSONMsg[]) => Promise<string>;
/**
* Submit a transaction on behalf of the remote account for execution on the remote chain.
* @param msgs - records for the transaction
* @returns acknowledge string
* @param {AnyJson[]} msgs - records for the transaction
* @param {Partial<Omit<TxBody, 'messages'>>} [opts] - optional parameters for the Tx, like `timeoutHeight` and `memo`
* @returns acknowledgement string
*/
executeEncodedTx: (msgs: AnyJson[]) => Promise<string>;
executeEncodedTx: (
msgs: AnyJson[],
opts?: Partial<Omit<TxBody, 'messages'>>,
) => Promise<string>;
/** deposit payment from zoe to the account*/
deposit: (payment: Payment) => Promise<void>;
/** get Purse for a brand to .withdraw() a Payment from the account */
Expand All @@ -253,6 +263,12 @@ export interface ChainAccount {
close: () => Promise<void>;
/* transfer account to new holder */
prepareTransfer: () => Promise<Invitation>;
/** @returns the address of the remote channel */
getRemoteAddress: () => RemoteIbcAddress;
/** @returns the address of the local channel */
getLocalAddress: () => LocalIbcAddress;
/** @returns the port the ICA channel is bound to */
getPort: () => Port;
}

/**
Expand Down Expand Up @@ -442,6 +458,10 @@ export type OsmoSwapFn = (
next: TransferMsg | ChainAddress,
) => TransferMsg;

type AfterAction = { destChain: string; destAddress: ChainAddress };
type SwapExact = { amountIn: Amount; amountOut: Amount };
type SwapMaxSlippage = { amountIn: Amount; brandOut: Brand; slippage: number };
export type AfterAction = { destChain: string; destAddress: ChainAddress };
export type SwapExact = { amountIn: Amount; amountOut: Amount };
export type SwapMaxSlippage = {
amountIn: Amount;
brandOut: Brand;
slippage: number;
};

0 comments on commit 678f21f

Please sign in to comment.