Skip to content

Commit

Permalink
feat: assetInfo as array of entries
Browse files Browse the repository at this point in the history
- to facililate registering the same denom across multiple chains in `ChainHub`
- denoms are unique to a chain, but not all chains
  • Loading branch information
0xpatrickdev committed Nov 29, 2024
1 parent 81d1df5 commit 49cdf6e
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 89 deletions.
21 changes: 14 additions & 7 deletions multichain-testing/tools/asset-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const makeAssetInfo = (
noble: ['uusdc'],
osmosis: ['uosmo', 'uion'],
},
): Record<string, DenomDetail> => {
): [Denom, DenomDetail][] => {
const getChannelId = (
issuingChainId: string,
holdingChainName: string,
Expand Down Expand Up @@ -46,19 +46,26 @@ export const makeAssetInfo = (
{},
);

const assetInfo: Record<string, DenomDetail> = {};
const seen = new Set();
const assetInfo: [Denom, DenomDetail][] = [];
for (const holdingChain of Object.keys(chainInfo)) {
for (const [issuingChain, denoms] of Object.entries(currentTokenMap)) {
for (const denom of denoms) {
const denomOrHash =
holdingChain === issuingChain
? denom
: toDenomHash(denom, chainInfo[issuingChain].chainId, holdingChain);
assetInfo[denomOrHash] = {
baseName: issuingChain,
chainName: holdingChain,
baseDenom: denom,
};

const seenKey = `${denomOrHash}-${holdingChain}`;
if (seen.has(seenKey)) continue;
seen.add(seenKey);
assetInfo.push([denomOrHash,
{
baseName: issuingChain,
chainName: holdingChain,
baseDenom: denom,
}
]);
}
}
}
Expand Down
49 changes: 29 additions & 20 deletions packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,26 @@ test.serial('basic-flows', async t => {
'--chainInfo',
JSON.stringify(withChainCapabilities(fetchedChainInfo)),
'--assetInfo',
JSON.stringify({
'ibc/uusdconagoric': {
chainName: 'agoric',
baseName: 'noble',
baseDenom: 'uusdc',
},
JSON.stringify([
[
'ibc/uusdconagoric',
{
chainName: 'agoric',
baseName: 'noble',
baseDenom: 'uusdc',
},
],
// not tested until #10006. consider renaming to ibc/uusdconcosmos
// and updating boot/tools/ibc/mocks.ts
'ibc/uusdchash': {
chainName: 'cosmoshub',
baseName: 'noble',
baseDenom: 'uusdc',
},
}),
[
'ibc/uusdchash',
{
chainName: 'cosmoshub',
baseName: 'noble',
baseDenom: 'uusdc',
},
],
]),
],
),
);
Expand Down Expand Up @@ -522,14 +528,17 @@ test.serial('basic-flows - portfolio holder', async t => {
'--chainInfo',
JSON.stringify(withChainCapabilities(fetchedChainInfo)),
'--assetInfo',
JSON.stringify({
ubld: {
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'ubld',
brandKey: 'BLD',
},
}),
JSON.stringify([
[
'ubld',
{
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'ubld',
brandKey: 'BLD',
},
],
]),
],
),
);
Expand Down
19 changes: 11 additions & 8 deletions packages/boot/test/orchestration/contract-upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ test('resume', async t => {
'--chainInfo',
JSON.stringify(withChainCapabilities(fetchedChainInfo)),
'--assetInfo',
JSON.stringify({
uist: {
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'uist',
brandKey: 'Stable',
},
}),
JSON.stringify([
[
'uist',
{
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'uist',
brandKey: 'Stable',
},
],
]),
]),
);

Expand Down
19 changes: 11 additions & 8 deletions packages/boot/test/orchestration/restart-contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ test.serial('send-anywhere', async t => {
'--chainInfo',
JSON.stringify(withChainCapabilities(fetchedChainInfo)),
'--assetInfo',
JSON.stringify({
uist: {
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'uist',
brandKey: 'Stable',
},
}),
JSON.stringify([
[
'uist',
{
chainName: 'agoric',
baseName: 'agoric',
baseDenom: 'uist',
brandKey: 'Stable',
},
],
]),
]),
);

Expand Down
28 changes: 18 additions & 10 deletions packages/builders/scripts/fast-usdc/init-fast-usdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,39 @@ import { parseArgs } from 'node:util';
* @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';
* @import {CosmosChainInfo, Denom, DenomDetail} 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 })}`]:
/** @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 })}`]:
],
[
`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' >>}
Expand Down
5 changes: 3 additions & 2 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { observeIteration, subscribeEach } from '@agoric/notifier';
import {
CosmosChainInfoShape,
DenomDetailShape,
DenomShape,
OrchestrationPowersShape,
registerChainsAndAssets,
withOrchestration,
Expand Down Expand Up @@ -60,7 +61,7 @@ export const meta = {
feeConfig: FeeConfigShape,
marshaller: M.remotable(),
chainInfo: M.recordOf(M.string(), CosmosChainInfoShape),
assetInfo: M.recordOf(M.string(), DenomDetailShape),
assetInfo: M.arrayOf([DenomShape, DenomDetailShape]),
},
};
harden(meta);
Expand All @@ -82,7 +83,7 @@ const publishFeeConfig = async (node, marshaller, feeConfig) => {
* marshaller: Marshaller;
* feeConfig: FeeConfig;
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: Record<Denom, DenomDetail & { brandKey?: string}>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string}][];
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/fast-usdc.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const contractName = 'fastUsdc';
* feeConfig: FeeConfig;
* feedPolicy: FeedPolicy & Passable;
* chainInfo: Record<string, CosmosChainInfo & Passable>;
* assetInfo: Record<Denom, DenomDetail & {brandKey?: string}>;
* assetInfo: [Denom, DenomDetail & {brandKey?: string}][];
* }} FastUSDCConfig
*/
/** @type {TypedPattern<FastUSDCConfig>} */
Expand Down
12 changes: 5 additions & 7 deletions packages/fast-usdc/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,11 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
return { agoric, osmosis, noble };
})();

const assetInfo = harden(
Object.fromEntries([
assetOn('uusdc', 'noble'),
[uusdcOnAgoric, agUSDCDetail],
assetOn('uusdc', 'noble', 'osmosis', fetchedChainInfo),
]),
);
const assetInfo: [Denom, DenomDetail & { brandKey?: string }][] = harden([
assetOn('uusdc', 'noble'),
[uusdcOnAgoric, agUSDCDetail],
assetOn('uusdc', 'noble', 'osmosis', fetchedChainInfo),
]);

return {
bootstrap: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { registerChainsAndAssets } from '../utils/chain-hub-helper.js';
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* chainInfo?: Record<string, CosmosChainInfo>;
* assetInfo?: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo?: [Denom, DenomDetail & { brandKey?: string }][];
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as flows from './basic-flows.flows.js';
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* chainInfo?: Record<string, CosmosChainInfo>;
* assetInfo?: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo?: [Denom, DenomDetail & { brandKey?: string }][];
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ harden(SingleNatAmountRecord);
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* chainInfo?: Record<string, CosmosChainInfo>;
* assetInfo?: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo?: [Denom, DenomDetail & { brandKey?: string }][];
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/src/examples/swap.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const meta = {
marshaller: M.remotable('marshaller'),
timerService: M.or(TimerServiceShape, null),
chainInfo: M.recordOf(M.string(), CosmosChainInfoShape),
assetInfo: M.recordOf(M.string(), DenomDetailShape),
assetInfo: M.arrayOf([M.string(), DenomDetailShape]),
},
upgradability: 'canUpgrade',
};
Expand Down Expand Up @@ -54,7 +54,7 @@ harden(makeNatAmountShape);
* timerService: Remote<TimerService>;
* marshaller: Marshaller;
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const trace = makeTracer(contractName, true);
* @param {{
* options: {
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
* };
* }} config
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/src/proposals/start-basic-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const contractName = 'basicFlows';
* @param {{
* options: {
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
* };
* }} config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const trace = makeTracer('StartSA', true);
* @param {{
* options: {
* chainInfo: Record<string, CosmosChainInfo>;
* assetInfo: Record<Denom, DenomDetail & { brandKey?: string }>;
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
* };
* }} config
*/
Expand Down
9 changes: 6 additions & 3 deletions packages/orchestration/src/utils/chain-hub-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param {ChainHub} chainHub
* @param {Record<string, Brand<'nat'>>} brands
* @param {Record<string, CosmosChainInfo> | undefined} chainInfo
* @param {Record<Denom, DenomDetail & { brandKey?: string }> | undefined} assetInfo
* @param {[Denom, DenomDetail & { brandKey?: string }][] | undefined} assetInfo
*/
export const registerChainsAndAssets = (
chainHub,
Expand Down Expand Up @@ -43,11 +43,14 @@ export const registerChainsAndAssets = (
}
console.log('chainHub: registered connections', [...registeredPairs].sort());

console.log('chainHub: registering assets', Object.keys(assetInfo || {}));
console.log(
'chainHub: registering assets',
assetInfo?.map(([denom, { chainName }]) => `${chainName}: ${denom}`),
);
if (!assetInfo) {
return;
}
for (const [denom, info] of Object.entries(assetInfo)) {
for (const [denom, info] of assetInfo) {
const { brandKey, ...rest } = info;
const infoWithBrand = brandKey
? { ...rest, brand: brands[brandKey] }
Expand Down
Loading

0 comments on commit 49cdf6e

Please sign in to comment.