From 6997149178b06a22fcb9e6b549d24702829bf529 Mon Sep 17 00:00:00 2001 From: rabi-siddique Date: Tue, 11 Feb 2025 14:54:08 +0500 Subject: [PATCH] feat: builder script for axelar-gmp contract --- .../scripts/testing/init-axelar-gmp.js | 65 ++++++++ .../{axelar-gmp.js => axelar-gmp.contract.js} | 0 .../src/proposals/start-axelar-gmp.js | 150 ++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 packages/builders/scripts/testing/init-axelar-gmp.js rename packages/orchestration/src/examples/{axelar-gmp.js => axelar-gmp.contract.js} (100%) create mode 100644 packages/orchestration/src/proposals/start-axelar-gmp.js diff --git a/packages/builders/scripts/testing/init-axelar-gmp.js b/packages/builders/scripts/testing/init-axelar-gmp.js new file mode 100644 index 00000000000..9536158ad4b --- /dev/null +++ b/packages/builders/scripts/testing/init-axelar-gmp.js @@ -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), + ); +}; diff --git a/packages/orchestration/src/examples/axelar-gmp.js b/packages/orchestration/src/examples/axelar-gmp.contract.js similarity index 100% rename from packages/orchestration/src/examples/axelar-gmp.js rename to packages/orchestration/src/examples/axelar-gmp.contract.js diff --git a/packages/orchestration/src/proposals/start-axelar-gmp.js b/packages/orchestration/src/proposals/start-axelar-gmp.js new file mode 100644 index 00000000000..e0d6480e090 --- /dev/null +++ b/packages/orchestration/src/proposals/start-axelar-gmp.js @@ -0,0 +1,150 @@ +import { + deeplyFulfilledObject, + makeTracer, + NonNullish, +} from '@agoric/internal'; +import { E } from '@endo/far'; + +/// + +/** + * @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; + * }; + * }; + * instance: { + * produce: { + * axelarGmp: Producer; + * }; + * }; + * issuer: { + * consume: { + * BLD: Issuer<'nat'>; + * IST: Issuer<'nat'>; + * }; + * }; + * }} powers + * @param {{ + * options: { + * chainInfo: Record; + * 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} 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, + }; +};