-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fast-usdc): core-eval to change fastUsdc.feedPolicy (#10609)
closes: #10507 ## Description - core-eval to update fast-usdc feed policy - policy update support in init-fast-usdc builder script - some refactoring to make stuff available to the 2nd core-eval script and to the init-fast-usdc builder ### Testing Considerations 1 happy-path test: - test(boot): core-eval to change fastUsdc.feedPolicy Aside from option parsing in the builder, validation with patterns makes for essentially straight-line code. ### Security / Documentation Considerations The whole feedPolicy, for all chains, is updated at once. If the goal is to change a property for just 1 chain, it's important to keep the properties in tact for all the other chains. ### Scaling Considerations none ### Upgrade Considerations There has been some discussion of versions for `feedPolicy`. This PR doesn't add anything in that area. The block height of the vstorage write can be used as one form of version number, though that isn't available to the contract, so it wouldn't let the contract detect OCW reports based on outdated policies.
- Loading branch information
Showing
8 changed files
with
307 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/builders/scripts/fast-usdc/fast-usdc-update.build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { parseArgs } from 'node:util'; | ||
import { getManifestForUpdateFastUsdcPolicy } from '@agoric/fast-usdc/src/fast-usdc-policy.core.js'; | ||
import { toExternalConfig } from '@agoric/fast-usdc/src/utils/config-marshal.js'; | ||
import { FeedPolicyShape } from '@agoric/fast-usdc/src/type-guards.js'; | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
|
||
/** | ||
* @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js' | ||
* @import {ParseArgsConfig} from 'node:util' | ||
* @import {FastUSDCConfig} from '@agoric/fast-usdc/src/types.js' | ||
*/ | ||
|
||
/** @type {ParseArgsConfig['options']} */ | ||
const options = { | ||
feedPolicy: { type: 'string' }, | ||
}; | ||
const feedPolicyUsage = 'use --feedPolicy <policy> ...'; | ||
|
||
/** | ||
* @typedef {{ | ||
* feedPolicy?: string; | ||
* }} FastUSDCUpdateOpts | ||
*/ | ||
|
||
/** @type {CoreEvalBuilder} */ | ||
export const updateProposalBuilder = async ( | ||
_utils, | ||
/** @type {FastUSDCConfig} */ config, | ||
) => { | ||
return harden({ | ||
sourceSpec: '@agoric/fast-usdc/src/fast-usdc-policy.core.js', | ||
/** @type {[string, Parameters<typeof getManifestForUpdateFastUsdcPolicy>[1]]} */ | ||
getManifestCall: [ | ||
getManifestForUpdateFastUsdcPolicy.name, | ||
{ | ||
options: toExternalConfig( | ||
config, | ||
{}, | ||
harden({ feedPolicy: FeedPolicyShape }), | ||
), | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
/** @type {DeployScriptFunction} */ | ||
export default async (homeP, endowments) => { | ||
const { writeCoreEval } = await makeHelpers(homeP, endowments); | ||
const { | ||
values: { feedPolicy }, | ||
} = parseArgs({ args: endowments.scriptArgs, options }); | ||
|
||
const parseFeedPolicy = () => { | ||
if (typeof feedPolicy !== 'string') throw Error(feedPolicyUsage); | ||
return JSON.parse(feedPolicy); | ||
}; | ||
const config = harden({ feedPolicy: parseFeedPolicy() }); | ||
await writeCoreEval('eval-fast-usdc-policy-update', utils => | ||
updateProposalBuilder(utils, config), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** @file core-eval to publish update to Fast USDC feedPolicy */ | ||
|
||
import { E } from '@endo/far'; | ||
import { fromExternalConfig } from './utils/config-marshal.js'; | ||
import { FeedPolicyShape } from './type-guards.js'; | ||
|
||
/** | ||
* @import {Passable} from '@endo/pass-style' | ||
* @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js' | ||
* @import {LegibleCapData} from './utils/config-marshal.js' | ||
* @import {FeedPolicy} from './types.js' | ||
*/ | ||
|
||
const contractName = 'fastUsdc'; | ||
const FEED_POLICY = 'feedPolicy'; | ||
|
||
/** | ||
* XXX copied from fast-usdc.start.js | ||
* | ||
* @param {ERef<StorageNode>} node | ||
* @param {FeedPolicy} policy | ||
*/ | ||
const publishFeedPolicy = async (node, policy) => { | ||
const feedPolicy = E(node).makeChildNode(FEED_POLICY); | ||
await E(feedPolicy).setValue(JSON.stringify(policy)); | ||
}; | ||
|
||
/** | ||
* @param {BootstrapPowers & | ||
* { consume: { chainStorage: Promise<StorageNode> }} | ||
* } powers | ||
* @param {{ options: LegibleCapData<{feedPolicy: FeedPolicy & Passable}> }} config | ||
*/ | ||
export const updateFastUsdcPolicy = async ( | ||
{ consume: { agoricNames, chainStorage } }, | ||
config, | ||
) => { | ||
/** @type {Issuer<'nat'>} */ | ||
const USDCissuer = await E(agoricNames).lookup('issuer', 'USDC'); | ||
const brands = harden({ | ||
USDC: await E(USDCissuer).getBrand(), | ||
}); | ||
const { feedPolicy } = fromExternalConfig( | ||
config.options, | ||
brands, | ||
harden({ feedPolicy: FeedPolicyShape }), | ||
); | ||
|
||
const storageNode = await E(chainStorage).makeChildNode(contractName); | ||
|
||
await publishFeedPolicy(storageNode, feedPolicy); | ||
}; | ||
|
||
/** | ||
* @param {unknown} _utils | ||
* @param {{ | ||
* options: LegibleCapData<{feedPolicy: FeedPolicy & Passable}>; | ||
* }} param1 | ||
*/ | ||
export const getManifestForUpdateFastUsdcPolicy = (_utils, { options }) => { | ||
return { | ||
/** @type {BootstrapManifest} */ | ||
manifest: { | ||
[updateFastUsdcPolicy.name]: { | ||
consume: { | ||
chainStorage: true, | ||
|
||
// widely shared: name services | ||
agoricNames: true, | ||
}, | ||
}, | ||
}, | ||
options, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.