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