Skip to content

Commit

Permalink
feat: builder script for axelar-gmp contract
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Feb 11, 2025
1 parent 4678953 commit 6997149
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/builders/scripts/testing/init-axelar-gmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { makeHelpers } from '@agoric/deploy-script-support';
import {
getManifest,
startAxelarGmp,
} from '@agoric/orchestration/src/proposals/start-axelar-gmp.js';
import { parseArgs } from 'node:util';

/**
* @import {ParseArgsConfig} from 'node:util'
*/

/** @type {ParseArgsConfig['options']} */
const parserOpts = {
chainInfo: { type: 'string' },
assetInfo: { type: 'string' },
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
export const defaultProposalBuilder = async (
{ publishRef, install },
options,
) =>
harden({
sourceSpec: '@agoric/orchestration/src/proposals/start-axelar-gmp.js',
getManifestCall: [
getManifest.name,
{
installationRef: publishRef(
install('@agoric/orchestration/src/examples/axelar-gmp.contract.js'),
),
options,
},
],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { scriptArgs } = endowments;

const {
values: { chainInfo, assetInfo },
} = parseArgs({
args: scriptArgs,
options: parserOpts,
});

const parseChainInfo = () => {
if (typeof chainInfo !== 'string') return undefined;
return JSON.parse(chainInfo);
};
const parseAssetInfo = () => {
if (typeof assetInfo !== 'string') return undefined;
return JSON.parse(assetInfo);
};
const opts = harden({
chainInfo: parseChainInfo(),
assetInfo: parseAssetInfo(),
});

const { writeCoreEval } = await makeHelpers(homeP, endowments);

await writeCoreEval(startAxelarGmp.name, utils =>
defaultProposalBuilder(utils, opts),
);
};
150 changes: 150 additions & 0 deletions packages/orchestration/src/proposals/start-axelar-gmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import {
deeplyFulfilledObject,
makeTracer,
NonNullish,
} from '@agoric/internal';
import { E } from '@endo/far';

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

/**
* @import {Installation} from '@agoric/zoe/src/zoeService/utils.js';
* @import {CosmosChainInfo, Denom, DenomDetail} from '@agoric/orchestration';
* @import {start as StartFn} from '@agoric/orchestration/src/examples/axelar-gmp.contract.js';
*/

const trace = makeTracer('StartAxelarGMP', true);

/**
* @param {BootstrapPowers & {
* installation: {
* consume: {
* axelarGmp: Installation<StartFn>;
* };
* };
* instance: {
* produce: {
* axelarGmp: Producer<Instance>;
* };
* };
* issuer: {
* consume: {
* BLD: Issuer<'nat'>;
* IST: Issuer<'nat'>;
* };
* };
* }} powers
* @param {{
* options: {
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
* };
* }} config
*/
export const startAxelarGmp = async (
{
consume: {
agoricNames,
board,
chainStorage,
chainTimerService,
cosmosInterchainService,
localchain,
startUpgradable,
},
installation: {
consume: { axelarGmp },
},
instance: {
produce: { axelarGmp: produceInstance },
},
issuer: {
consume: { BLD, IST },
},
},
{ options: { chainInfo, assetInfo } },
) => {
trace(startAxelarGmp.name);

const marshaller = await E(board).getReadonlyMarshaller();

const privateArgs = await deeplyFulfilledObject(
harden({
agoricNames,
localchain,
marshaller,
orchestrationService: cosmosInterchainService,
storageNode: E(NonNullish(await chainStorage)).makeChildNode(
'axelar-gmp',
),
timerService: chainTimerService,
chainInfo,
assetInfo,
}),
);

/** @param {() => Promise<Issuer>} p */
const safeFulfill = async p =>
E.when(
p(),
i => i,
() => undefined,
);

const atomIssuer = await safeFulfill(() =>
E(agoricNames).lookup('issuer', 'ATOM'),
);
const osmoIssuer = await safeFulfill(() =>
E(agoricNames).lookup('issuer', 'OSMO'),
);

const issuerKeywordRecord = harden({
BLD: await BLD,
IST: await IST,
...(atomIssuer && { ATOM: atomIssuer }),
...(osmoIssuer && { OSMO: osmoIssuer }),
});
trace('issuerKeywordRecord', issuerKeywordRecord);

const { instance } = await E(startUpgradable)({
label: 'axelarGmp',
installation: axelarGmp,
issuerKeywordRecord,
privateArgs,
});
produceInstance.resolve(instance);
trace('done');
};
harden(startAxelarGmp);

export const getManifest = ({ restoreRef }, { installationRef, options }) => {
return {
manifest: {
[startAxelarGmp.name]: {
consume: {
agoricNames: true,
board: true,
chainStorage: true,
chainTimerService: true,
cosmosInterchainService: true,
localchain: true,

startUpgradable: true,
},
installation: {
consume: { axelarGmp: true },
},
instance: {
produce: { axelarGmp: true },
},
issuer: {
consume: { BLD: true, IST: true },
},
},
},
installations: {
axelarGmp: restoreRef(installationRef),
},
options,
};
};

0 comments on commit 6997149

Please sign in to comment.