From e43674374a6eece4d0b73b04ee7387c8e3354d05 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 10:50:05 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20StakingAccount=20=E2=86=92=20Cosmos?= =?UTF-8?q?OrchestrationAccount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/examples/stakeAtom.contract.js | 15 ++++-------- ...ntKit.js => cosmosOrchestrationAccount.js} | 20 +++++++++++----- packages/orchestration/src/facade.js | 15 ++++++------ .../orchestration/test/staking-ops.test.ts | 24 ++++++++++++++----- 4 files changed, 45 insertions(+), 29 deletions(-) rename packages/orchestration/src/exos/{stakingAccountKit.js => cosmosOrchestrationAccount.js} (96%) diff --git a/packages/orchestration/src/examples/stakeAtom.contract.js b/packages/orchestration/src/examples/stakeAtom.contract.js index a1cf95a5b5f..504cb200645 100644 --- a/packages/orchestration/src/examples/stakeAtom.contract.js +++ b/packages/orchestration/src/examples/stakeAtom.contract.js @@ -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'; @@ -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'); /** @@ -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( @@ -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, { diff --git a/packages/orchestration/src/exos/stakingAccountKit.js b/packages/orchestration/src/exos/cosmosOrchestrationAccount.js similarity index 96% rename from packages/orchestration/src/exos/stakingAccountKit.js rename to packages/orchestration/src/exos/cosmosOrchestrationAccount.js index bb05d2c45b3..f13ce644372 100644 --- a/packages/orchestration/src/exos/stakingAccountKit.js +++ b/packages/orchestration/src/exos/cosmosOrchestrationAccount.js @@ -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', { @@ -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>} StakingAccountKit */ -/** @typedef {StakingAccountKit['holder']} StakingAccounHolder */ +/** + * @typedef {ReturnType< + * ReturnType + * >} CosmosOrchestrationAccountKit + */ +/** @typedef {CosmosOrchestrationAccountKit['holder']} StakingAccounHolder */ diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 3de98abc435..0551b89c2df 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -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'; @@ -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, @@ -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, diff --git a/packages/orchestration/test/staking-ops.test.ts b/packages/orchestration/test/staking-ops.test.ts index c0bba8c3001..6daf8722874 100644 --- a/packages/orchestration/test/staking-ops.test.ts +++ b/packages/orchestration/test/staking-ops.test.ts @@ -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'; @@ -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', { @@ -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, @@ -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, @@ -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,