Skip to content

Commit

Permalink
refactor: StakingAccount → CosmosOrchestrationAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 4, 2024
1 parent 20d693b commit e436743
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
15 changes: 5 additions & 10 deletions packages/orchestration/src/examples/stakeAtom.contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* @file Example contract that uses orchestration
*/
/** @file Example contract that uses orchestration */
// TODO rename to "stakeIca" or something else that conveys is parameterized nature

import { makeTracer, StorageNodeShape } from '@agoric/internal';
Expand All @@ -10,7 +8,7 @@ import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { M } from '@endo/patterns';
import { prepareStakingAccountKit } from '../exos/stakingAccountKit.js';
import { prepareCosmosOrchestrationAccountKit } from '../exos/cosmosOrchestrationAccount.js';

const trace = makeTracer('StakeAtom');
/**
Expand Down Expand Up @@ -63,11 +61,8 @@ export const start = async (zcf, privateArgs, baggage) => {

const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller);

const makeStakingAccountKit = prepareStakingAccountKit(
zone,
makeRecorderKit,
zcf,
);
const makeCosmosOrchestrationAccountKit =
prepareCosmosOrchestrationAccountKit(zone, makeRecorderKit, zcf);

async function makeAccountKit() {
const account = await E(orchestration).makeAccount(
Expand All @@ -82,7 +77,7 @@ export const start = async (zcf, privateArgs, baggage) => {
);
const accountAddress = await E(account).getAddress();
trace('account address', accountAddress);
const { holder, invitationMakers } = makeStakingAccountKit(
const { holder, invitationMakers } = makeCosmosOrchestrationAccountKit(
accountAddress,
bondDenom,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ const toDenomAmount = c => ({ denom: c.denom, value: BigInt(c.amount) });
* @param {MakeRecorderKit} makeRecorderKit
* @param {ZCF} zcf
*/
export const prepareStakingAccountKit = (zone, makeRecorderKit, zcf) => {
const makeStakingAccountKit = zone.exoClassKit(
export const prepareCosmosOrchestrationAccountKit = (
zone,
makeRecorderKit,
zcf,
) => {
const makeCosmosOrchestrationAccountKit = zone.exoClassKit(
'Staking Account Holder',
{
helper: M.interface('helper', {
Expand Down Expand Up @@ -408,11 +412,15 @@ export const prepareStakingAccountKit = (zone, makeRecorderKit, zcf) => {
const arg = null;
/** @satisfies {StakingAccountActions} */
// eslint-disable-next-line no-unused-vars
const kit = makeStakingAccountKit(arg, arg, arg).holder;
const kit = makeCosmosOrchestrationAccountKit(arg, arg, arg).holder;
};

return makeStakingAccountKit;
return makeCosmosOrchestrationAccountKit;
};

/** @typedef {ReturnType<ReturnType<typeof prepareStakingAccountKit>>} StakingAccountKit */
/** @typedef {StakingAccountKit['holder']} StakingAccounHolder */
/**
* @typedef {ReturnType<
* ReturnType<typeof prepareCosmosOrchestrationAccountKit>
* >} CosmosOrchestrationAccountKit
*/
/** @typedef {CosmosOrchestrationAccountKit['holder']} StakingAccounHolder */
15 changes: 8 additions & 7 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Orchestration service */

import { E } from '@endo/far';
import { prepareStakingAccountKit } from './exos/stakingAccountKit.js';
import { prepareCosmosOrchestrationAccountKit } from './exos/cosmosOrchestrationAccount.js';

/**
* @import {Zone} from '@agoric/zone';
Expand Down Expand Up @@ -104,11 +104,12 @@ const makeRemoteChainFacade = (name, { orchestration, timer, zcf, zone }) => {
allowedQueries: [],
});
const makeRecorderKit = () => anyVal;
const makeStakingAccountKit = prepareStakingAccountKit(
zone.subZone(name),
makeRecorderKit,
zcf,
);
const makeCosmosOrchestrationAccountKit =
prepareCosmosOrchestrationAccountKit(
zone.subZone(name),
makeRecorderKit,
zcf,
);

return {
getChainInfo: async () => chainInfo,
Expand All @@ -130,7 +131,7 @@ const makeRemoteChainFacade = (name, { orchestration, timer, zcf, zone }) => {
// FIXME look up real values
const bondDenom = name;
// @ts-expect-error FIXME promise resolution through membrane
return makeStakingAccountKit(address, bondDenom, {
return makeCosmosOrchestrationAccountKit(address, bondDenom, {
account: icaAccount,
storageNode: anyVal,
icqConnection: anyVal,
Expand Down
24 changes: 18 additions & 6 deletions packages/orchestration/test/staking-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import type { TimestampRecord, TimestampValue } from '@agoric/time';
import type { AnyJson } from '@agoric/cosmic-proto';
import { makeDurableZone } from '@agoric/zone/durable.js';
import {
prepareStakingAccountKit,
prepareCosmosOrchestrationAccountKit,
trivialDelegateResponse,
} from '../src/exos/stakingAccountKit.js';
} from '../src/exos/cosmosOrchestrationAccount.js';
import { encodeTxResponse } from '../src/utils/cosmos.js';
import type { IcaAccount, ChainAddress, ICQConnection } from '../src/types.js';

Expand Down Expand Up @@ -208,7 +208,7 @@ test('withdrawRewards() on StakingAccountHolder formats message correctly', asyn
const s = makeScenario();
const { account, calls, timer } = s;
const { makeRecorderKit, storageNode, zcf, icqConnection, zone } = s;
const make = prepareStakingAccountKit(zone, makeRecorderKit, zcf);
const make = prepareCosmosOrchestrationAccountKit(zone, makeRecorderKit, zcf);

// Higher fidelity tests below use invitationMakers.
const { holder } = make(account.getAddress(), 'uatom', {
Expand All @@ -232,7 +232,11 @@ test(`delegate; redelegate using invitationMakers`, async t => {
const { account, calls, timer } = s;
const { makeRecorderKit, storageNode, zcf, zoe, icqConnection, zone } = s;
const aBrand = Far('Token') as Brand<'nat'>;
const makeAccountKit = prepareStakingAccountKit(zone, makeRecorderKit, zcf);
const makeAccountKit = prepareCosmosOrchestrationAccountKit(
zone,
makeRecorderKit,
zcf,
);

const { invitationMakers } = makeAccountKit(account.getAddress(), 'uatom', {
account,
Expand Down Expand Up @@ -297,7 +301,11 @@ test(`withdraw rewards using invitationMakers`, async t => {
const s = makeScenario();
const { account, calls, timer } = s;
const { makeRecorderKit, storageNode, zcf, zoe, icqConnection, zone } = s;
const makeAccountKit = prepareStakingAccountKit(zone, makeRecorderKit, zcf);
const makeAccountKit = prepareCosmosOrchestrationAccountKit(
zone,
makeRecorderKit,
zcf,
);

const { invitationMakers } = makeAccountKit(account.getAddress(), 'uatom', {
account,
Expand All @@ -323,7 +331,11 @@ test(`undelegate waits for unbonding period`, async t => {
const s = makeScenario();
const { account, calls, timer } = s;
const { makeRecorderKit, storageNode, zcf, zoe, icqConnection, zone } = s;
const makeAccountKit = prepareStakingAccountKit(zone, makeRecorderKit, zcf);
const makeAccountKit = prepareCosmosOrchestrationAccountKit(
zone,
makeRecorderKit,
zcf,
);

const { invitationMakers } = makeAccountKit(account.getAddress(), 'uatom', {
account,
Expand Down

0 comments on commit e436743

Please sign in to comment.