Skip to content

Commit

Permalink
test(support): register USDC and its variants in ChainHub
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Oct 29, 2024
1 parent 9e08694 commit 3b34528
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/orchestration/test/exos/make-test-loa-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const prepareMakeTestLOAKit = (

t.log('register Agoric chain and BLD in ChainHub');
utils.registerAgoricBld();
t.log('register Noble and DYDX chains and USDC in ChainHub');
utils.registerUSDC();
return account;
};
};
61 changes: 61 additions & 0 deletions packages/orchestration/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ import { setupFakeNetwork } from './network-fakes.js';
import { buildVTransferEvent } from '../tools/ibc-mocks.js';
import { makeChainHub } from '../src/exos/chain-hub.js';
import fetchedChainInfo from '../src/fetched-chain-info.js';
import { denomHash } from '../src/utils/denomHash.js';

export {
makeFakeLocalchainBridge,
makeFakeTransferBridge,
} from '@agoric/vats/tools/fake-bridge.js';

const usdcOnAgoric = `ibc/${denomHash({
channelId:
fetchedChainInfo.agoric.connections['noble-1'].transferChannel.channelId,
denom: 'uusdc',
})}`;

const usdcOnDydx = `ibc/${denomHash({
channelId:
fetchedChainInfo.dydx.connections['noble-1'].transferChannel.channelId,
denom: 'uusdc',
})}`;

export const commonSetup = async (t: ExecutionContext<any>) => {
t.log('bootstrap vat dependencies');
// The common setup cannot support a durable zone because many of the fakes are not durable.
Expand All @@ -47,6 +60,7 @@ export const commonSetup = async (t: ExecutionContext<any>) => {

const bld = withAmountUtils(makeIssuerKit('BLD'));
const ist = withAmountUtils(makeIssuerKit('IST'));
const usdc = withAmountUtils(makeIssuerKit('USDC'));
const bankBridgeMessages = [] as any[];
const { bankManager, pourPayment } = await makeFakeBankManagerKit({
onToBridge: obj => bankBridgeMessages.push(obj),
Expand All @@ -58,10 +72,17 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
'Inter Stable Token',
ist.issuerKit,
);
await E(bankManager).addAsset(
usdcOnAgoric,
'USDC',
'USD Coin',
usdc.issuerKit,
);
// These mints no longer stay in sync with bankManager.
// Use pourPayment() for IST.
const { mint: _b, ...bldSansMint } = bld;
const { mint: _i, ...istSansMint } = ist;
const { mint: _u, ...usdcSansMint } = usdc;
// XXX real bankManager does this. fake should too?
// TODO https://github.com/Agoric/agoric-sdk/issues/9966
await makeWellKnownSpaces(agoricNamesAdmin, t.log, ['vbankAsset']);
Expand All @@ -87,6 +108,17 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
displayInfo: { IOU: true },
}),
);
await E(E(agoricNamesAdmin).lookupAdmin('vbankAsset')).update(
usdcOnAgoric,
/** @type {AssetInfo} */ harden({
brand: usdc.brand,
issuer: usdc.issuer,
issuerName: 'USDC',
denom: usdcOnAgoric,
proposedName: 'USDC',
displayInfo: { IOU: true },
}),
);

const vowTools = prepareSwingsetVowTools(rootZone.subZone('vows'));

Expand Down Expand Up @@ -187,6 +219,33 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
}
};

const registerUSDC = () => {
if (!chainHub.getAsset('uusdc')) {
chainHub.registerChain('noble', fetchedChainInfo.noble);
chainHub.registerAsset('uusdc', {
chainName: 'noble',
baseName: 'noble',
baseDenom: 'uusdc',
});
}
if (!chainHub.getAsset(usdcOnAgoric)) {
chainHub.registerAsset(usdcOnAgoric, {
chainName: 'agoric',
baseName: 'noble',
baseDenom: 'uusdc',
brand: usdc.brand,
});
}
if (!chainHub.getAsset(usdcOnDydx)) {
chainHub.registerChain('dydx', fetchedChainInfo.dydx);
chainHub.registerAsset(usdcOnDydx, {
chainName: 'dydx',
baseName: 'noble',
baseDenom: 'uusdc',
});
}
};

return {
bootstrap: {
agoricNames,
Expand All @@ -204,6 +263,7 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
brands: {
bld: bldSansMint,
ist: istSansMint,
usdc: usdcSansMint,
},
mocks: {
ibcBridge,
Expand All @@ -230,6 +290,7 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
inspectDibcBridge: () => E(ibcBridge).inspectDibcBridge(),
inspectBankBridge: () => harden([...bankBridgeMessages]),
registerAgoricBld,
registerUSDC,
transmitTransferAck,
},
};
Expand Down

0 comments on commit 3b34528

Please sign in to comment.