|
| 1 | +// This is generated by writeCoreEval; please edit! |
| 2 | +/* eslint-disable */ |
| 3 | + |
| 4 | +const manifestBundleRef = {bundleID:"b1-400dad00c228fbca60099577d1e2ffc14f502fb1b698330edd0cad7b985e3975489d4104e4b2c467f8fbdc244792415432383805d30f50c74b0608a749327612"}; |
| 5 | +const getManifestCall = harden([ |
| 6 | + "getManifestForUpgradeEvmDests", |
| 7 | + { |
| 8 | + installKeys: { |
| 9 | + fastUsdc: { |
| 10 | + bundleID: "b1-2412ad1aecd532da4bd8003718925fe907098fe7afa69b61b67aac7a265229a8d1a8c30d1a8368c62d121087a4f6895f5d2fca9de54a965be99bf6a88ecedfb6", |
| 11 | + }, |
| 12 | + }, |
| 13 | + options: {}, |
| 14 | + }, |
| 15 | +]); |
| 16 | +const customManifest = { |
| 17 | + upgradeEvmDests: { |
| 18 | + consume: { |
| 19 | + fastUsdcKit: true, |
| 20 | + }, |
| 21 | + }, |
| 22 | +}; |
| 23 | + |
| 24 | +// Make a behavior function and "export" it by way of script completion value. |
| 25 | +// It is constructed by an anonymous invocation to ensure the absence of a global binding |
| 26 | +// for makeCoreProposalBehavior, which may not be necessary but preserves behavior pre-dating |
| 27 | +// https://github.com/Agoric/agoric-sdk/pull/8712 . |
| 28 | +const behavior = (({ |
| 29 | + manifestBundleRef, |
| 30 | + getManifestCall: [manifestGetterName, ...manifestGetterArgs], |
| 31 | + customManifest, |
| 32 | + E, |
| 33 | + log = console.info, |
| 34 | + customRestoreRef, |
| 35 | +}) => { |
| 36 | + const { entries, fromEntries } = Object; |
| 37 | + |
| 38 | + /** |
| 39 | + * Given an object whose properties may be promise-valued, return a promise |
| 40 | + * for an analogous object in which each such value has been replaced with its |
| 41 | + * fulfillment. |
| 42 | + * This is a non-recursive form of endo `deeplyFulfilled`. |
| 43 | + * |
| 44 | + * @template T |
| 45 | + * @param {{[K in keyof T]: (T[K] | Promise<T[K]>)}} obj |
| 46 | + * @returns {Promise<T>} |
| 47 | + */ |
| 48 | + const shallowlyFulfilled = async obj => { |
| 49 | + if (!obj) { |
| 50 | + return obj; |
| 51 | + } |
| 52 | + const awaitedEntries = await Promise.all( |
| 53 | + entries(obj).map(async ([key, valueP]) => { |
| 54 | + const value = await valueP; |
| 55 | + return [key, value]; |
| 56 | + }), |
| 57 | + ); |
| 58 | + return fromEntries(awaitedEntries); |
| 59 | + }; |
| 60 | + |
| 61 | + const makeRestoreRef = (vatAdminSvc, zoe) => { |
| 62 | + /** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */ |
| 63 | + const defaultRestoreRef = async bundleRef => { |
| 64 | + // extract-proposal.js creates these records, and bundleName is |
| 65 | + // the optional name under which the bundle was installed into |
| 66 | + // config.bundles |
| 67 | + const bundleIdP = |
| 68 | + 'bundleName' in bundleRef |
| 69 | + ? E(vatAdminSvc).getBundleIDByName(bundleRef.bundleName) |
| 70 | + : bundleRef.bundleID; |
| 71 | + const bundleID = await bundleIdP; |
| 72 | + const label = bundleID.slice(0, 8); |
| 73 | + return E(zoe).installBundleID(bundleID, label); |
| 74 | + }; |
| 75 | + return defaultRestoreRef; |
| 76 | + }; |
| 77 | + |
| 78 | + /** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} powers */ |
| 79 | + const coreProposalBehavior = async powers => { |
| 80 | + // NOTE: `powers` is expected to match or be a superset of the above `permits` export, |
| 81 | + // which should therefore be kept in sync with this deconstruction code. |
| 82 | + // HOWEVER, do note that this function is invoked with at least the *union* of powers |
| 83 | + // required by individual moduleBehaviors declared by the manifest getter, which is |
| 84 | + // necessary so it can use `runModuleBehaviors` to provide the appropriate subset to |
| 85 | + // each one (see ./writeCoreEvalParts.js). |
| 86 | + // Handle `powers` with the requisite care. |
| 87 | + const { |
| 88 | + consume: { vatAdminSvc, zoe, agoricNamesAdmin }, |
| 89 | + evaluateBundleCap, |
| 90 | + installation: { produce: produceInstallations }, |
| 91 | + modules: { |
| 92 | + utils: { runModuleBehaviors }, |
| 93 | + }, |
| 94 | + } = powers; |
| 95 | + |
| 96 | + // Get the on-chain installation containing the manifest and behaviors. |
| 97 | + log('evaluateBundleCap', { |
| 98 | + manifestBundleRef, |
| 99 | + manifestGetterName, |
| 100 | + vatAdminSvc, |
| 101 | + }); |
| 102 | + let bcapP; |
| 103 | + if ('bundleName' in manifestBundleRef) { |
| 104 | + bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName); |
| 105 | + } else if ('bundleID' in manifestBundleRef) { |
| 106 | + bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID); |
| 107 | + } else { |
| 108 | + const keys = Reflect.ownKeys(manifestBundleRef).map(key => |
| 109 | + typeof key === 'string' ? JSON.stringify(key) : String(key), |
| 110 | + ); |
| 111 | + const keysStr = `[${keys.join(', ')}]`; |
| 112 | + throw Error( |
| 113 | + `bundleRef must have own bundleName or bundleID, missing in ${keysStr}`, |
| 114 | + ); |
| 115 | + } |
| 116 | + const bundleCap = await bcapP; |
| 117 | + |
| 118 | + const proposalNS = await evaluateBundleCap(bundleCap); |
| 119 | + |
| 120 | + // Get the manifest and its metadata. |
| 121 | + log('execute', { |
| 122 | + manifestGetterName, |
| 123 | + bundleExports: Object.keys(proposalNS), |
| 124 | + }); |
| 125 | + const restoreRef = customRestoreRef || makeRestoreRef(vatAdminSvc, zoe); |
| 126 | + const { |
| 127 | + manifest, |
| 128 | + options: rawOptions, |
| 129 | + installations: rawInstallations, |
| 130 | + } = await proposalNS[manifestGetterName]( |
| 131 | + harden({ restoreRef }), |
| 132 | + ...manifestGetterArgs, |
| 133 | + ); |
| 134 | + |
| 135 | + // Await promises in the returned options and installations records. |
| 136 | + const [options, installations] = await Promise.all( |
| 137 | + [rawOptions, rawInstallations].map(shallowlyFulfilled), |
| 138 | + ); |
| 139 | + |
| 140 | + // Publish the installations for our dependencies. |
| 141 | + const installationEntries = entries(installations || {}); |
| 142 | + if (installationEntries.length > 0) { |
| 143 | + const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation'); |
| 144 | + await Promise.all( |
| 145 | + installationEntries.map(([key, value]) => { |
| 146 | + produceInstallations[key].reset(); |
| 147 | + produceInstallations[key].resolve(value); |
| 148 | + return E(installAdmin).update(key, value); |
| 149 | + }), |
| 150 | + ); |
| 151 | + } |
| 152 | + |
| 153 | + // Evaluate the manifest. |
| 154 | + return runModuleBehaviors({ |
| 155 | + // Remember that `powers` may be arbitrarily broad. |
| 156 | + allPowers: powers, |
| 157 | + behaviors: proposalNS, |
| 158 | + manifest: customManifest || manifest, |
| 159 | + makeConfig: (name, _permit) => { |
| 160 | + log('coreProposal:', name); |
| 161 | + return { options }; |
| 162 | + }, |
| 163 | + }); |
| 164 | + }; |
| 165 | + |
| 166 | + return coreProposalBehavior; |
| 167 | +})({ manifestBundleRef, getManifestCall, customManifest, E }); |
| 168 | +behavior; |
0 commit comments