Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Typescripting Orch Contract (WIP) #96

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/package.json b/package.json
index 6bbb9f9ef6ec6f0d181e3a7886c55c7970000f7b..e28a9a6ed0ef10b90a212d19b9ad6b4abd876a6d 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
"@agoric/time": "0.3.3-upgrade-18-dev-ef001c0.0+ef001c0",
"@agoric/zoe": "0.26.3-upgrade-18-dev-ef001c0.0+ef001c0",
"@endo/base64": "^1.0.8",
- "@endo/bundle-source": "^3.4.2",
+ "@endo/bundle-source": "^3.5.0",
"@endo/errors": "^1.2.7",
"@endo/far": "^1.1.8",
"@endo/marshal": "^1.6.1",
4 changes: 2 additions & 2 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@agoric/async-flow": "^0.1.1-u17.1",
"@agoric/deploy-script-support": "^0.10.4-u17.1",
"@agoric/deploy-script-support": "patch:@agoric/deploy-script-support@npm%3A0.10.4-upgrade-18-dev-ef001c0.0#~/.yarn/patches/@agoric-deploy-script-support-npm-0.10.4-upgrade-18-dev-ef001c0.0-39c74744cc.patch",
"@agoric/eslint-config": "^0.4.1-u17.1",
"@agoric/inter-protocol": "^0.17.0-u17.1",
"@agoric/smart-wallet": "^0.5.4-u17.1",
Expand Down Expand Up @@ -73,7 +73,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/scripts/init-orca.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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
50 changes: 21 additions & 29 deletions contract/src/orca.contract.js → contract/src/orca.contract.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/// <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 {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';
*/
import * as flows from './orca.flows.ts';

/// <reference types="@agoric/vats/src/core/types-ambient"/>
/// <reference types="@agoric/zoe/src/contractFacet/types-ambient"/>
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';

const { entries, keys } = Object;
const trace = makeTracer('OrchDev1');
Expand All @@ -34,8 +35,7 @@ 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 @@ -8,7 +8,7 @@ import { makeTracer } from './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
Loading