From e0e2a824f9d84e46bf94f597d2c5ea2354361466 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 11:47:30 -0700 Subject: [PATCH] chore: orchestrationAccountMethods --- .../src/exos/cosmosOrchestrationAccount.js | 32 +++++++++++++------ packages/orchestration/src/facade.js | 1 - .../src/utils/orchestrationAccount.js | 19 +++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 packages/orchestration/src/utils/orchestrationAccount.js diff --git a/packages/orchestration/src/exos/cosmosOrchestrationAccount.js b/packages/orchestration/src/exos/cosmosOrchestrationAccount.js index f809f8f946f1..073a9b3685b9 100644 --- a/packages/orchestration/src/exos/cosmosOrchestrationAccount.js +++ b/packages/orchestration/src/exos/cosmosOrchestrationAccount.js @@ -16,7 +16,7 @@ import { MsgUndelegateResponse, } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js'; -import { AmountShape, PaymentShape } from '@agoric/ertp'; +import { AmountShape } from '@agoric/ertp'; import { makeTracer } from '@agoric/internal'; import { M } from '@agoric/vat-data'; import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js'; @@ -27,7 +27,6 @@ import { AmountArgShape, ChainAddressShape, ChainAmountShape, - CoinShape, DelegationShape, } from '../typeGuards.js'; import { @@ -35,10 +34,11 @@ import { maxClockSkew, tryDecodeResponse, } from '../utils/cosmos.js'; +import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js'; import { dateInSeconds } from '../utils/time.js'; /** - * @import {AmountArg, IcaAccount, ChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, DenomAmount, OrchestrationAccountI} from '../types.js'; + * @import {AmountArg, IcaAccount, ChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, DenomAmount, OrchestrationAccountI, DenomArg} from '../types.js'; * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'; * @import {Coin} from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js'; * @import {Delegation} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js'; @@ -68,17 +68,14 @@ const { Fail } = assert; /** @see {OrchestrationAccountI} */ export const IcaAccountHolderI = M.interface('IcaAccountHolder', { + ...orchestrationAccountMethods, asContinuingOffer: M.call().returns({ publicSubscribers: M.any(), invitationMakers: M.any(), holder: M.any(), }), getPublicTopics: M.call().returns(TopicsRecordShape), - getAddress: M.call().returns(ChainAddressShape), - getBalance: M.callWhen().optional(M.string()).returns(CoinShape), - getBalances: M.callWhen().optional(M.string()).returns(M.arrayOf(CoinShape)), delegate: M.callWhen(ChainAddressShape, AmountShape).returns(M.undefined()), - deposit: M.callWhen(PaymentShape).returns(M.undefined()), redelegate: M.callWhen( ChainAddressShape, ChainAddressShape, @@ -359,12 +356,12 @@ export const prepareCosmosOrchestrationAccountKit = ( return harden(coins.map(toDenomAmount)); }, /** - * @param {DenomAmount['denom']} [denom] - defaults to bondDenom + * @param {DenomArg} denom * @returns {Promise} */ async getBalance(denom) { - const { chainAddress, icqConnection, bondDenom } = this.state; - denom ||= bondDenom; + const { chainAddress, icqConnection } = this.state; + // TODO #9211 lookup denom from brand assert.typeof(denom, 'string'); const [result] = await E(icqConnection).query([ @@ -383,6 +380,21 @@ export const prepareCosmosOrchestrationAccountKit = ( return harden(toDenomAmount(balance)); }, + send(toAccount, amount) { + console.log('send got', toAccount, amount); + throw Error('not yet implemented'); + }, + + transfer(amount, msg) { + console.log('transferSteps got', amount, msg); + throw Error('not yet implemented'); + }, + + transferSteps(amount, msg) { + console.log('transferSteps got', amount, msg); + throw Error('not yet implemented'); + }, + withdrawRewards() { throw assert.error('Not implemented'); }, diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 46e06fd6bf25..33fb0107e332 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -129,7 +129,6 @@ const makeRemoteChainFacade = (name, { orchestration, timer, zcf, zone }) => { // FIXME look up real values const bondDenom = name; - // @ts-expect-error FIXME missing methods return makeCosmosOrchestrationAccount(address, bondDenom, { account: icaAccount, storageNode: anyVal, diff --git a/packages/orchestration/src/utils/orchestrationAccount.js b/packages/orchestration/src/utils/orchestrationAccount.js new file mode 100644 index 000000000000..b5b325980c1e --- /dev/null +++ b/packages/orchestration/src/utils/orchestrationAccount.js @@ -0,0 +1,19 @@ +import { M } from '@endo/patterns'; +import { PaymentShape } from '@agoric/ertp'; +import { AmountArgShape, ChainAddressShape, CoinShape } from '../typeGuards.js'; + +/** @import {OrchestrationAccountI} from '../orchestration-api.js'; */ + +// TODO complete this interface +/** @see {OrchestrationAccountI} */ +export const orchestrationAccountMethods = { + getAddress: M.call().returns(ChainAddressShape), + getBalance: M.callWhen(M.any()).returns(CoinShape), + getBalances: M.callWhen().returns(M.arrayOf(CoinShape)), + send: M.callWhen(ChainAddressShape, AmountArgShape).returns(M.undefined()), + transfer: M.callWhen(AmountArgShape, ChainAddressShape).returns( + M.undefined(), + ), + transferSteps: M.callWhen(AmountArgShape, M.any()).returns(M.undefined()), + deposit: M.callWhen(PaymentShape).returns(M.undefined()), +};