Skip to content

Commit

Permalink
chore: orchestrationAccountMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 4, 2024
1 parent 7622490 commit e0e2a82
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
32 changes: 22 additions & 10 deletions packages/orchestration/src/exos/cosmosOrchestrationAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,18 +27,18 @@ import {
AmountArgShape,
ChainAddressShape,
ChainAmountShape,
CoinShape,
DelegationShape,
} from '../typeGuards.js';
import {
encodeTxResponse,
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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -359,12 +356,12 @@ export const prepareCosmosOrchestrationAccountKit = (
return harden(coins.map(toDenomAmount));
},
/**
* @param {DenomAmount['denom']} [denom] - defaults to bondDenom
* @param {DenomArg} denom
* @returns {Promise<DenomAmount>}
*/
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([
Expand All @@ -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');
},
Expand Down
1 change: 0 additions & 1 deletion packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions packages/orchestration/src/utils/orchestrationAccount.js
Original file line number Diff line number Diff line change
@@ -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()),
};

0 comments on commit e0e2a82

Please sign in to comment.