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 Dec 3, 2024
1 parent dcf2772 commit 51e7a9c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 40 deletions.
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 @@ -4,6 +4,7 @@ import { observeIteration, subscribeEach } from '@agoric/notifier';
import {
CosmosChainInfoShape,
DenomDetailShape,
DenomShape,
OrchestrationPowersShape,
registerChainsAndAssets,
withOrchestration,
Expand Down Expand Up @@ -55,7 +56,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 @@ -77,7 +78,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
10 changes: 7 additions & 3 deletions packages/fast-usdc/src/fast-usdc.start.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { deeplyFulfilledObject, makeTracer, objectMap } from '@agoric/internal';
import { CosmosChainInfoShape, DenomDetailShape } from '@agoric/orchestration';
import {
CosmosChainInfoShape,
DenomDetailShape,
DenomShape,
} from '@agoric/orchestration';
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
Expand Down Expand Up @@ -36,7 +40,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 All @@ -46,7 +50,7 @@ export const FastUSDCConfigShape = M.splitRecord({
feeConfig: FeeConfigShape,
feedPolicy: FeedPolicyShape,
chainInfo: M.recordOf(M.string(), CosmosChainInfoShape),
assetInfo: M.recordOf(M.string(), DenomDetailShape),
assetInfo: M.arrayOf([DenomShape, DenomDetailShape]),
});

/**
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 @@ -200,13 +200,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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
30 changes: 17 additions & 13 deletions packages/orchestration/test/exos/chain-hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ test('makeTransferRoute - to issuing chain', async t => {
chainHub,
{},
withChainCapabilities(knownChains), // adds pfmEnabled
harden({ [uusdcOnAgoric]: agDetail, [uusdcOnOsmosis]: osDetail }),
harden([
[uusdcOnAgoric, agDetail],
[uusdcOnOsmosis, osDetail],
]),
);

const dest: ChainAddress = chainHub.makeChainAddress('noble1234');
Expand Down Expand Up @@ -257,12 +260,7 @@ test('makeTransferRoute - from issuing chain', async t => {
chainHub,
{},
withChainCapabilities(knownChains), // adds pfmEnabled
harden(
Object.fromEntries([
assetOn('uist', 'agoric'),
assetOn('uosmo', 'osmosis'),
]),
),
harden([assetOn('uist', 'agoric'), assetOn('uosmo', 'osmosis')]),
);

const dest: ChainAddress = chainHub.makeChainAddress('noble1234');
Expand Down Expand Up @@ -301,7 +299,7 @@ test('makeTransferRoute - through issuing chain', async t => {
chainHub,
{},
withChainCapabilities(knownChains), // adds pfmEnabled
harden({ [uusdcOnAgoric]: agDetail }),
harden([[uusdcOnAgoric, agDetail]]),
);

const dest: ChainAddress = chainHub.makeChainAddress('osmo1234');
Expand Down Expand Up @@ -359,7 +357,7 @@ test('makeTransferRoute - takes forwardOpts', t => {
chainHub,
{},
withChainCapabilities(knownChains), // adds pfmEnabled
harden({ [uusdcOnOsmosis]: osDetail }),
harden([[uusdcOnOsmosis, osDetail]]),
);

const dest: ChainAddress = chainHub.makeChainAddress('agoric1234');
Expand Down Expand Up @@ -464,7 +462,10 @@ test('makeTransferRoute - no connection info single hop', t => {
chainHub,
{},
knownChainsSansConns, // omit connections
harden({ [uusdcOnAgoric]: agDetail }),
harden([
[uusdcOnAgoric, agDetail],
[uusdcOnOsmosis, osDetail],
]),
);

t.throws(
Expand All @@ -487,7 +488,10 @@ test('makeTransferRoute - no connection info multi hop', t => {
chainHub,
{},
harden(chainInfo),
harden({ [uusdcOnAgoric]: agDetail, [uusdcOnOsmosis]: osDetail }),
harden([
[uusdcOnAgoric, agDetail],
[uusdcOnOsmosis, osDetail],
]),
);

const osmoDest = chainHub.makeChainAddress('osmo1234');
Expand Down Expand Up @@ -522,7 +526,7 @@ test('makeTransferRoute - asset not on holding chain', t => {
chainHub,
{},
withChainCapabilities(knownChains),
harden({ [uusdcOnAgoric]: agDetail }),
harden([[uusdcOnAgoric, agDetail]]),
);

// transfer USDC on agoric from osmosis to noble (impossible)
Expand All @@ -547,7 +551,7 @@ test('makeTransferRoute - no PFM path', t => {
chainHub,
{},
knownChains, // intentionally omit pfmEnabled
harden({ [uusdcOnAgoric]: agDetail }),
harden([[uusdcOnAgoric, agDetail]]),
);

// transfer USDC on agoric to osmosis
Expand Down

0 comments on commit 51e7a9c

Please sign in to comment.