Skip to content

Commit

Permalink
feat(builders): fast-usdc policy update builder
Browse files Browse the repository at this point in the history
 - use deploy config from fast-usdc package
  • Loading branch information
dckc committed Dec 8, 2024
1 parent 58fb1bc commit 8ded3d8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 138 deletions.
61 changes: 61 additions & 0 deletions packages/builders/scripts/fast-usdc/fast-usdc-update.build.js
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),
);
};
140 changes: 2 additions & 138 deletions packages/builders/scripts/fast-usdc/init-fast-usdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
getManifestForFastUSDC,
} from '@agoric/fast-usdc/src/fast-usdc.start.js';
import { toExternalConfig } from '@agoric/fast-usdc/src/utils/config-marshal.js';
import { denomHash, withChainCapabilities } from '@agoric/orchestration';
import fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js';
import { configurations } from '@agoric/fast-usdc/src/utils/deploy-config.js';
import {
multiplyBy,
parseRatio,
Expand All @@ -18,146 +17,11 @@ import { parseArgs } from 'node:util';
/**
* @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js'
* @import {ParseArgsConfig} from 'node:util'
* @import {FastUSDCConfig} from '@agoric/fast-usdc/src/fast-usdc.start.js'
* @import {Passable} from '@endo/marshal';
* @import {CosmosChainInfo, Denom, DenomDetail} from '@agoric/orchestration';
* @import {FastUSDCConfig} from '@agoric/fast-usdc/src/types.js'
*/

const { keys } = Object;

/** @type {[Denom, DenomDetail & { brandKey?: string}][]} */
const defaultAssetInfo = [
[
'uusdc',
{
baseName: 'noble',
chainName: 'noble',
baseDenom: 'uusdc',
},
],
[
`ibc/${denomHash({ denom: 'uusdc', channelId: fetchedChainInfo.agoric.connections['noble-1'].transferChannel.channelId })}`,
{
baseName: 'noble',
chainName: 'agoric',
baseDenom: 'uusdc',
brandKey: 'USDC',
},
],
[
`ibc/${denomHash({ denom: 'uusdc', channelId: fetchedChainInfo.osmosis.connections['noble-1'].transferChannel.channelId })}`,
{
baseName: 'noble',
chainName: 'osmosis',
baseDenom: 'uusdc',
},
],
];

/**
* @type {Record<string, Pick<FastUSDCConfig, 'oracles' | 'feedPolicy' | 'chainInfo' | 'assetInfo' >>}
*
* TODO: determine OCW operator addresses
* meanwhile, use price oracle addresses (from updatePriceFeeds.js).
*/
const configurations = {
A3P_INTEGRATION: {
oracles: {
gov1: 'agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q',
gov2: 'agoric1wrfh296eu2z34p6pah7q04jjuyj3mxu9v98277',
gov3: 'agoric1ydzxwh6f893jvpaslmaz6l8j2ulup9a7x8qvvq',
},
feedPolicy: {
nobleAgoricChannelId: 'TODO',
nobleDomainId: 4,
chainPolicies: {
Arbitrum: {
cctpTokenMessengerAddress:
'0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
confirmations: 2,
nobleContractAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo)
),
assetInfo: defaultAssetInfo,
},
MAINNET: {
oracles: {
'01node': 'agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8',
'Simply Staking': 'agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr',
P2P: 'agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj',
},
feedPolicy: {
nobleAgoricChannelId: 'channel-21',
nobleDomainId: 4,
chainPolicies: {
Arbitrum: {
cctpTokenMessengerAddress:
'0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
confirmations: 2,
nobleContractAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo)
),
assetInfo: defaultAssetInfo,
},
DEVNET: {
oracles: {
DSRV: 'agoric1lw4e4aas9q84tq0q92j85rwjjjapf8dmnllnft',
Stakin: 'agoric1zj6vrrrjq4gsyr9lw7dplv4vyejg3p8j2urm82',
'01node': 'agoric1ra0g6crtsy6r3qnpu7ruvm7qd4wjnznyzg5nu4',
'Simply Staking': 'agoric1qj07c7vfk3knqdral0sej7fa6eavkdn8vd8etf',
P2P: 'agoric10vjkvkmpp9e356xeh6qqlhrny2htyzp8hf88fk',
},
feedPolicy: {
nobleAgoricChannelId: 'TODO',
nobleDomainId: 4,
chainPolicies: {
Arbitrum: {
cctpTokenMessengerAddress: '0xTODO',
chainId: 421614,
confirmations: 2,
nobleContractAddress: '0xTODO',
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo) // TODO: use devnet values
),
assetInfo: defaultAssetInfo, // TODO: use emerynet values
},
EMERYNET: {
oracles: {
gov1: 'agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce',
gov2: 'agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang',
},
feedPolicy: {
nobleAgoricChannelId: 'TODO',
nobleDomainId: 4,
chainPolicies: {
Arbitrum: {
cctpTokenMessengerAddress: '0xTODO',
chainId: 421614,
confirmations: 2,
nobleContractAddress: '0xTODO',
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo) // TODO: use emerynet values
),
assetInfo: defaultAssetInfo, // TODO: use emerynet values
},
};

/** @type {ParseArgsConfig['options']} */
const options = {
flatFee: { type: 'string', default: '0.01' },
Expand Down

0 comments on commit 8ded3d8

Please sign in to comment.