Skip to content

Commit

Permalink
feat: fusdc assetInfo and chainInfo by netname
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Nov 26, 2024
1 parent 6e1d21d commit 5b163e4
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion packages/builders/scripts/fast-usdc/init-fast-usdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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 {
multiplyBy,
parseRatio,
Expand All @@ -17,12 +19,34 @@ 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} from '@agoric/orchestration';
*/

const { keys } = Object;

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',
},
[`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'>>}
* @type {Record<string, Pick<FastUSDCConfig, 'oracles' | 'feedPolicy' | 'chainInfo' | 'assetInfo' >>}
*
* TODO: determine OCW operator addresses
* meanwhile, use price oracle addresses (from updatePriceFeeds.js).
Expand All @@ -47,6 +71,10 @@ const configurations = {
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo)
),
assetInfo: defaultAssetInfo,
},
MAINNET: {
oracles: {
Expand All @@ -69,6 +97,10 @@ const configurations = {
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo)
),
assetInfo: defaultAssetInfo,
},
DEVNET: {
oracles: {
Expand All @@ -90,6 +122,10 @@ const configurations = {
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo) // TODO: use devnet values
),
assetInfo: defaultAssetInfo, // TODO: use emerynet values
},
EMERYNET: {
oracles: {
Expand All @@ -108,6 +144,10 @@ const configurations = {
},
},
},
chainInfo: /** @type {Record<string, CosmosChainInfo & Passable>} */ (
withChainCapabilities(fetchedChainInfo) // TODO: use emerynet values
),
assetInfo: defaultAssetInfo, // TODO: use emerynet values
},
};

Expand Down Expand Up @@ -243,10 +283,22 @@ export default async (homeP, endowments) => {
};

const parseChainInfo = () => {
if (net) {
if (!(net in configurations)) {
throw Error(`${net} not in ${keys(configurations)}`);
}
return configurations[net].feedPolicy;
}
if (!chainInfo) throw Error(chainInfoUsage);
return JSON.parse(chainInfo);
};
const parseAssetInfo = () => {
if (net) {
if (!(net in configurations)) {
throw Error(`${net} not in ${keys(configurations)}`);
}
return configurations[net].feedPolicy;
}
if (!assetInfo) throw Error(assetInfoUsage);
return JSON.parse(assetInfo);
};
Expand Down

0 comments on commit 5b163e4

Please sign in to comment.