From b4e1fdb6ad0048b0027c4a11d91f37defb57f44e Mon Sep 17 00:00:00 2001
From: Mujahid Khan <106528609+mujahidkay@users.noreply.github.com>
Date: Mon, 23 Dec 2024 14:07:26 +0500
Subject: [PATCH] chore: JS -> TS
---
contract/rollup.config.mjs | 2 +-
contract/scripts/init-orca.js | 2 +-
.../{orca.contract.js => orca.contract.ts} | 48 ++++++++-----------
contract/src/{orca.flows.js => orca.flows.ts} | 39 +++++----------
contract/src/orca.proposal.js | 2 +-
contract/test/bundle-source.test.js | 2 +-
contract/test/orca-contract.test.js | 4 +-
contract/tsconfig.json | 4 +-
8 files changed, 42 insertions(+), 61 deletions(-)
rename contract/src/{orca.contract.js => orca.contract.ts} (77%)
rename contract/src/{orca.flows.js => orca.flows.ts} (70%)
diff --git a/contract/rollup.config.mjs b/contract/rollup.config.mjs
index 7c5f883..bffb741 100644
--- a/contract/rollup.config.mjs
+++ b/contract/rollup.config.mjs
@@ -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`,
diff --git a/contract/scripts/init-orca.js b/contract/scripts/init-orca.js
index bac2ab7..f8c129b 100644
--- a/contract/scripts/init-orca.js
+++ b/contract/scripts/init-orca.js
@@ -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,
},
diff --git a/contract/src/orca.contract.js b/contract/src/orca.contract.ts
similarity index 77%
rename from contract/src/orca.contract.js
rename to contract/src/orca.contract.ts
index 22b9331..3dd6bfa 100644
--- a/contract/src/orca.contract.js
+++ b/contract/src/orca.contract.ts
@@ -1,20 +1,20 @@
+///
+///
+
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';
- */
-///
-///
const { entries, keys } = Object;
const trace = makeTracer('OrchDev1');
@@ -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({
@@ -48,23 +48,15 @@ export const meta = {
};
harden(meta);
-/**
- * @typedef {{
- * chainDetails: Record
- * }} OrcaTerms
- *
- * @param {ZCF} zcf
- * @param {OrchestrationPowers & {
- * marshaller: Marshaller;
- * }} privateArgs
- * @param {Zone} zone
- * @param {OrchestrationTools} tools
- */
+type OrcaTerms = {
+ chainDetails: Record
+}
+
const contract = async (
- zcf,
- privateArgs,
- zone,
- { orchestrateAll, zoeTools, chainHub },
+ zcf: ZCF,
+ privateArgs: OrchestrationPowers & {marshaller: Marshaller},
+ zone: Zone,
+ { orchestrateAll, zoeTools, chainHub }: OrchestrationTools,
) => {
trace('orca start contract');
@@ -113,4 +105,4 @@ const contract = async (
export const start = withOrchestration(contract);
harden(start);
-/** @typedef {typeof start} OrcaSF */
+export type OrcaSF = typeof start;
diff --git a/contract/src/orca.flows.js b/contract/src/orca.flows.ts
similarity index 70%
rename from contract/src/orca.flows.js
rename to contract/src/orca.flows.ts
index 8349a29..4f5f5d4 100644
--- a/contract/src/orca.flows.js
+++ b/contract/src/orca.flows.ts
@@ -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';
@@ -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;
@@ -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}`,
diff --git a/contract/src/orca.proposal.js b/contract/src/orca.proposal.js
index c5db794..68344a8 100644
--- a/contract/src/orca.proposal.js
+++ b/contract/src/orca.proposal.js
@@ -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';
*/
diff --git a/contract/test/bundle-source.test.js b/contract/test/bundle-source.test.js
index 4e95844..0beed6c 100644
--- a/contract/test/bundle-source.test.js
+++ b/contract/test/bundle-source.test.js
@@ -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);
diff --git a/contract/test/orca-contract.test.js b/contract/test/orca-contract.test.js
index 7a670a5..271c188 100644
--- a/contract/test/orca-contract.test.js
+++ b/contract/test/orca-contract.test.js
@@ -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'),
};
diff --git a/contract/tsconfig.json b/contract/tsconfig.json
index 4646fe5..1260aa5 100644
--- a/contract/tsconfig.json
+++ b/contract/tsconfig.json
@@ -12,7 +12,9 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
- "outDir": "./dist"
+ "outDir": "./dist",
+ "allowImportingTsExtensions": true,
+ "noEmit": true
},
"include": ["tools", "test"],
"exclude": ["node_modules"]