Skip to content

Commit

Permalink
mini-demo/exp: covert orch contract to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
mujahidkay committed Nov 18, 2024
1 parent c4ea224 commit a434cec
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 65 deletions.
4 changes: 2 additions & 2 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ build:
buildc:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn build:deployer"
deployc:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.ts --eval src/orca.proposal.js"
deploy:
yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js
yarn node scripts/deploy-contract.js --install src/orca.contract.ts --eval src/orca.proposal.js
test-orca:
yarn test ./test/orca-contract.test.js

Expand Down
2 changes: 1 addition & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@agoric/store": "^0.9.3-u17.1",
"@agoric/vats": "^0.16.0-u17.1",
"@agoric/zoe": "^0.26.3-u17.1",
"@endo/bundle-source": "^3.4.0",
"@endo/bundle-source": "^3.5.0",
"@endo/errors": "^1.2.4",
"@endo/far": "^1.1.4",
"@endo/init": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion contract/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { permit as boardAuxPermit } from './src/platform-goals/board-aux.core.js
const config1 = ({
name,
coreEntry = `./src/${name}.proposal.js`,
contractEntry = `./src/${name}.contract.js`,
contractEntry = `./src/${name}.contract.ts`,
coreScript = `bundles/deploy-${name}.js`,
coreScriptOptions = undefined,
permitFile = `deploy-${name}-permit.json`,
Expand Down
2 changes: 1 addition & 1 deletion contract/src/builder/init-orca.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const defaultProposalBuilder = async (
getManifestForOrca.name,
{
installKeys: {
orca: publishRef(install('../../src/orca.contract.js')),
orca: publishRef(install('../../src/orca.contract.ts')),
},
chainDetails,
},
Expand Down
48 changes: 20 additions & 28 deletions contract/src/orca.contract.js → contract/src/orca.contract.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/// <reference types="@agoric/vats/src/core/types-ambient"/>
/// <reference types="@agoric/zoe/src/contractFacet/types-ambient"/>

import { AmountShape } from '@agoric/ertp';
import { makeTracer } from '@agoric/internal';
import { withOrchestration } from '@agoric/orchestration/src/utils/start-helper.js';
import { ChainInfoShape } from '@agoric/orchestration/src/typeGuards.js';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { M } from '@endo/patterns';
import * as flows from './orca.flows.js';
import * as flows from './orca.flows.ts';

import type { Marshaller } from '@agoric/internal/src/lib-chainStorage.js';
import type { CosmosChainInfo } from '@agoric/orchestration';
import type { OrchestrationPowers, OrchestrationTools } from '@agoric/orchestration/src/utils/start-helper.js';
import type { Zone } from '@agoric/zone';

/**
* @import {Marshaller} from '@agoric/internal/src/lib-chainStorage.js';
* @import {CosmosChainInfo} from '@agoric/orchestration';
* @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js';
* @import {Zone} from '@agoric/zone';
*/

/// <reference types="@agoric/vats/src/core/types-ambient"/>
/// <reference types="@agoric/zoe/src/contractFacet/types-ambient"/>

const { entries, keys } = Object;
const trace = makeTracer('OrchDev1');
Expand All @@ -34,8 +34,8 @@ const OrchestrationPowersShape = M.splitRecord({
agoricNames: M.remotable('agoricNames'),
});

/** @type {ContractMeta} */
export const meta = {

export const meta: ContractMeta = {
privateArgsShape: M.and(
OrchestrationPowersShape,
M.splitRecord({
Expand All @@ -48,23 +48,15 @@ export const meta = {
};
harden(meta);

/**
* @typedef {{
* chainDetails: Record<string, CosmosChainInfo>
* }} OrcaTerms
*
* @param {ZCF<OrcaTerms>} zcf
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
*/
type OrcaTerms = {
chainDetails: Record<string, CosmosChainInfo>
}

const contract = async (
zcf,
privateArgs,
zone,
{ orchestrateAll, zoeTools, chainHub },
zcf: ZCF<OrcaTerms>,
privateArgs: OrchestrationPowers & {marshaller: Marshaller},
zone: Zone,
{ orchestrateAll, zoeTools, chainHub }: OrchestrationTools,
) => {
trace('orca start contract');

Expand Down Expand Up @@ -113,4 +105,4 @@ const contract = async (
export const start = withOrchestration(contract);
harden(start);

/** @typedef {typeof start} OrcaSF */
export type OrcaSF = typeof start;
39 changes: 13 additions & 26 deletions contract/src/orca.flows.js → contract/src/orca.flows.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/**
* @import {GuestOf} from '@agoric/async-flow';
* @import {Amount} from '@agoric/ertp/src/types.js';
* @import {Marshaller, StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
* @import {ChainAddress, Orchestrator} from '@agoric/orchestration';
* @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
* @import {Transfer} from './orca.contract.js';
* @import {DenomArg} from '@agoric/orchestration';
*/
import type { Orchestrator } from '@agoric/orchestration';
import type { ZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js';
import type { DenomArg } from '@agoric/orchestration';

import { M, mustMatch } from '@endo/patterns';
import { makeTracer } from './debug.js';
Expand All @@ -17,13 +10,13 @@ const trace = makeTracer('OrchFlows');
/**
* Create an account on a Cosmos chain and return a continuing offer with
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
*
* @param {Orchestrator} orch
* @param {unknown} _ctx
* @param {ZCFSeat} seat
* @param {{ chainName: string, denom: string }} offerArgs
*/
export const makeAccount = async (orch, _ctx, seat, offerArgs) => {
export const makeAccount = async (
orch: Orchestrator,
_ctx: unknown,
seat: ZCFSeat,
offerArgs: { chainName: string; denom: string },
) => {
trace('makeAccount');
mustMatch(offerArgs, M.splitRecord({ chainName: M.string() }));
const { chainName } = offerArgs;
Expand All @@ -39,18 +32,12 @@ harden(makeAccount);
/**
* Create an account on a Cosmos chain and return a continuing offer with
* invitations makers for Delegate, WithdrawRewards, Transfer, etc.
*
* @param {Orchestrator} orch
* @param {object} ctx
* @param {ZoeTools['localTransfer']} ctx.localTransfer
* @param {ZCFSeat} seat
* @param {{ chainName: string, denom: DenomArg }} offerArgs
*/
export const makeCreateAndFund = async (
orch,
{ localTransfer },
seat,
{ chainName, denom },
orch: Orchestrator,
{ localTransfer }: { localTransfer: ZoeTools['localTransfer'] },
seat: ZCFSeat,
{ chainName, denom }: { chainName: string; denom: DenomArg },
) => {
trace(
`invoked makeCreateAndFund with chain ${chainName}, and denom ${denom}`,
Expand Down
2 changes: 1 addition & 1 deletion contract/src/orca.proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { makeTracer } from './tools/debug.js';
* @import {ERef} from '@endo/far';
* @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js';
* @import {ChainInfo, IBCConnectionInfo,} from '@agoric/orchestration';
* @import {OrcaSF} from './orca.contract.js';
* @import {OrcaSF} from './orca.contract.ts';
* @import {ContractStartFunction} from '@agoric/zoe/src/zoeService/utils.js';
*/

Expand Down
2 changes: 1 addition & 1 deletion contract/test/bundle-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { E, passStyleOf } from '@endo/far';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';

const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/orca.contract.js`);
const contractPath = myRequire.resolve(`../src/orca.contract.ts`);

test('bundleSource() bundles the contract for use with zoe', async t => {
const bundle = await bundleSource(contractPath);
Expand Down
4 changes: 2 additions & 2 deletions contract/test/orca-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { installContract } from '../src/platform-goals/start-contract.js';
* @import {IcaAccount, MakeCosmosInterchainService} from '@agoric/orchestration';
* @import {LocalChain,LocalChainAccount} from '@agoric/vats/src/localchain.js';
* @import {TargetRegistration} from '@agoric/vats/src/bridge-target.js';
* @import {OrcaSF} from '../src/orca.contract.js';
* @import {OrcaSF} from '../src/orca.contract.ts';
*/

const nodeRequire = createRequire(import.meta.url);

const contractPath = nodeRequire.resolve(`../src/orca.contract.js`);
const contractPath = nodeRequire.resolve(`../src/orca.contract.ts`);
const scriptRoot = {
orca: nodeRequire.resolve('../src/orca.proposal.js'),
};
Expand Down
4 changes: 3 additions & 1 deletion contract/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"outDir": "./dist"
"outDir": "./dist",
"allowImportingTsExtensions": true,
"noEmit": true
},
"include": ["tools", "test"],
"exclude": ["node_modules"]
Expand Down
Loading

0 comments on commit a434cec

Please sign in to comment.