Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion multichain-testing/scripts/ymax-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
objectMap,
type TypedPattern,
} from '@agoric/internal';
import { YieldProtocol } from '@agoric/portfolio-api/src/constants.js';
import {
AxelarChain,
YieldProtocol,
} from '@agoric/portfolio-api/src/constants.js';
import type { OfferStatus } from '@agoric/smart-wallet/src/offers.js';
import type { NameHub } from '@agoric/vats';
import type { StartedInstanceKit as ZStarted } from '@agoric/zoe/src/zoeService/utils';
Expand Down Expand Up @@ -88,6 +91,9 @@ const parseToolArgs = (argv: string[]) =>
invitePlanner: { type: 'string' },
pruneStorage: { type: 'boolean', default: false },
'submit-for': { type: 'string' },
'resolve-account-for': { type: 'string' },
unsafeRemoteAddress: { type: 'string' },
chainName: { type: 'string' },
help: { type: 'boolean', short: 'h', default: false },
},
allowPositionals: false,
Expand Down Expand Up @@ -433,6 +439,26 @@ const main = async (
return;
}

if (values['resolve-account-for']) {
const portfolioId = Number(values['resolve-account-for']);
const { chainName, unsafeRemoteAddress: remoteAddress } = values;
const planner = walletStore.get<PortfolioPlanner>('planner');
trace(
'KLUDGE!!! resolve',
chainName,
'account for',
portfolioId,
'to',
remoteAddress,
);
await planner.UNSAFEresolveEVMAddress(
portfolioId,
chainName as AxelarChain,
remoteAddress as `0x${string}`,
);
return;
}

const positionData = parseTypedJSON(values.positions, GoalDataShape);
const targetAllocation = values['target-allocation']
? parseTypedJSON(
Expand Down
32 changes: 31 additions & 1 deletion packages/portfolio-contract/src/planner.exo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* @see {@link preparePlanner}
*/
import { makeTracer } from '@agoric/internal';
import type { AxelarChain } from '@agoric/portfolio-api/src/constants.js';
import { type Vow, VowShape, type VowTools } from '@agoric/vow';
import type { ZCF, ZCFSeat } from '@agoric/zoe';
import type { Zone } from '@agoric/zone';
import { M } from '@endo/patterns';
import type { PortfolioKit } from './portfolio.exo.ts';
import type { MovementDesc, OfferArgsFor } from './type-guards-steps.ts';
import { makeOfferArgsShapes } from './type-guards-steps.ts';
import type { ChainHub } from '@agoric/orchestration';

const trace = makeTracer('PPLN');

Expand All @@ -28,6 +30,7 @@ export const preparePlanner = (
getPortfolio,
shapes,
vowTools,
chainHubTools,
}: {
rebalance: (
seat: ZCFSeat,
Expand All @@ -37,7 +40,8 @@ export const preparePlanner = (
zcf: ZCF;
getPortfolio: (id: number) => PortfolioKit;
shapes: ReturnType<typeof makeOfferArgsShapes>;
vowTools: Pick<VowTools, 'asVow'>;
vowTools: Pick<VowTools, 'asVow' | 'when'>;
chainHubTools: Pick<ChainHub, 'getChainInfo'>;
},
) => {
const { movementDescShape } = shapes;
Expand All @@ -48,6 +52,11 @@ export const preparePlanner = (
M.number(),
M.number(),
).returns(VowShape),
UNSAFEresolveEVMAddress: M.callWhen(
M.number(),
M.string(),
M.string(),
).returns(),
});

return zone.exoClass('Planner', PlannerI, () => ({}), {
Expand Down Expand Up @@ -78,6 +87,27 @@ export const preparePlanner = (
return rebalance(emptySeat, { flow: plan }, pKit);
});
},

/** KLUDGE - contract MUST NOT rely on planner for authentic remoteAddress */
async UNSAFEresolveEVMAddress(
portfolioId: number,
chainName: AxelarChain,
remoteAddress: `0x${string}`,
) {
assert(remoteAddress.startsWith('0x'));
const pKit = getPortfolio(portfolioId);

const { namespace, reference } = await vowTools.when(
chainHubTools.getChainInfo(chainName),
);

pKit.manager.resolveAccount({
namespace: 'eip155',
chainName,
chainId: `${namespace}:${reference}`,
remoteAddress,
});
},
});
};

Expand Down
11 changes: 11 additions & 0 deletions packages/portfolio-contract/test/planner.exo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { makeIssuerKit } from '@agoric/ertp';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import type { ActualChainInfo } from '@agoric/orchestration';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { prepareVowTools } from '@agoric/vow';
import type { ZCF } from '@agoric/zoe';
Expand Down Expand Up @@ -58,6 +59,16 @@ test('planner exo submit method', async t => {
getPortfolio: mockGetPortfolio,
shapes: makeOfferArgsShapes(USDC),
vowTools: vt,
chainHubTools: {
getChainInfo: <K extends string>(_c: K) =>
vt.asVow(
async () =>
({
namespace: 'eip155',
reference: '1234',
}) as unknown as ActualChainInfo<K>,
),
},
});

const planner = makePlanner();
Expand Down
Loading