Skip to content

Commit

Permalink
fixup! chore: advancer validates settlementAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 18, 2024
1 parent c8e0529 commit ac84a97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
11 changes: 1 addition & 10 deletions packages/fast-usdc/src/exos/advancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const AdvancerKitI = harden({
advancer: M.interface('AdvancerI', {
handleTransactionEvent: M.callWhen(CctpTxEvidenceShape).returns(),
setIntermediateRecipient: M.call(ChainAddressShape).returns(),
setSettlementAddress: M.call(ChainAddressShape).returns(),
}),
depositHandler: M.interface('DepositHandlerI', {
onFulfilled: M.call(M.undefined(), AdvancerVowCtxShape).returns(VowShape),
Expand Down Expand Up @@ -118,16 +117,15 @@ export const prepareAdvancerKit = (
* notifyFacet: import('./settler.js').SettlerKit['notify'];
* borrowerFacet: LiquidityPoolKit['borrower'];
* poolAccount: HostInterface<OrchestrationAccount<{chainId: 'agoric'}>>;
* settlementAddress: ChainAddress;
* intermediateRecipient?: ChainAddress;
* settlementAddress?: ChainAddress;
* }} config
*/
config =>
harden({
...config,
// make sure the state record has these properties, perhaps with an undefined value
intermediateRecipient: config.intermediateRecipient,
settlementAddress: config.settlementAddress,
}),
{
advancer: {
Expand All @@ -154,9 +152,6 @@ export const prepareAdvancerKit = (
const { recipientAddress } = evidence.aux;
const decoded = decodeAddressHook(recipientAddress);
mustMatch(decoded, AddressHookShape);
if (!settlementAddress?.value) {
throw Fail`⚠️ No 'settlementAddress'. must call 'publishAddresses' first.`;
}
if (decoded.baseAddress !== settlementAddress.value) {
throw Fail`⚠️ baseAddress of address hook ${q(decoded.baseAddress)} does not match the expected address ${q(settlementAddress.value)}`;
}
Expand Down Expand Up @@ -199,10 +194,6 @@ export const prepareAdvancerKit = (
setIntermediateRecipient(intermediateRecipient) {
this.state.intermediateRecipient = intermediateRecipient;
},
/** @param {ChainAddress} settlementAddress */
setSettlementAddress(settlementAddress) {
this.state.settlementAddress = settlementAddress;
},
},
depositHandler: {
/**
Expand Down
16 changes: 7 additions & 9 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,12 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
},
async publishAddresses() {
!baggage.has(ADDRESSES_BAGGAGE_KEY) || Fail`Addresses already published`;
const [poolAccountAddress, settlementAccountAddress] =
await vowTools.when(
vowTools.all([
E(poolAccount).getAddress(),
E(settlementAccount).getAddress(),
]),
);
advancer.setSettlementAddress(settlementAccountAddress);
const [poolAccountAddress] = await vowTools.when(
vowTools.all([E(poolAccount).getAddress()]),
);
const addresses = harden({
poolAccount: poolAccountAddress.value,
settlementAccount: settlementAccountAddress.value,
settlementAccount: settlementAddress.value,
});
baggage.init(ADDRESSES_BAGGAGE_KEY, addresses);
await publishAddresses(storageNode, addresses);
Expand Down Expand Up @@ -285,6 +280,8 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
);
trace('settlementAccount', settlementAccount);
trace('poolAccount', poolAccount);
const settlementAddress = await E(settlementAccount).getAddress();
trace('settlementAddress', settlementAddress);

const [_agoric, _noble, agToNoble] = await vowTools.when(
chainHub.getChainsAndConnection('agoric', 'noble'),
Expand All @@ -301,6 +298,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
borrowerFacet: poolKit.borrower,
notifyFacet: settlerKit.notify,
poolAccount,
settlementAddress,
}),
);
// Connect evidence stream to advancer
Expand Down
28 changes: 0 additions & 28 deletions packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,31 +625,3 @@ test('rejects advances to unknown settlementAccount', async t => {
],
]);
});

test('does not advance without settlementAddress set', async t => {
const {
extensions: {
services: { makeAdvancer },
helpers: { inspectLogs },
mocks: { mockPoolAccount, mockNotifyF, mockBorrowerF },
},
} = t.context;

// make a new advancer without setting `settlementAddress`
const advancer = makeAdvancer({
borrowerFacet: mockBorrowerF,
notifyFacet: mockNotifyF,
poolAccount: mockPoolAccount.account,
intermediateRecipient,
});
const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_OSMO();

void advancer.handleTransactionEvent(mockEvidence);
await eventLoopIteration();
t.deepEqual(inspectLogs(), [
[
'Advancer error:',
Error("⚠️ No 'settlementAddress'. must call 'publishAddresses' first."),
],
]);
});

0 comments on commit ac84a97

Please sign in to comment.