Skip to content

Commit

Permalink
chore: provide noble ica for intermediateRecipient
Browse files Browse the repository at this point in the history
- noble only accepts bech32 addresses for the recipient field in ibc transfers
- this change creates an ICA noble to facilitate the requirement
- if an IBC transfer fails, we expect it to return the origin (agoric `localOrchAccount`), not the `intermediateRecipient`
  • Loading branch information
0xpatrickdev committed Dec 5, 2024
1 parent 0ad8d7d commit 2614509
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 14 deletions.
20 changes: 15 additions & 5 deletions packages/fast-usdc/src/exos/advancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const prepareAdvancerKit = (
* notifyFacet: import('./settler.js').SettlerKit['notify'];
* borrowerFacet: LiquidityPoolKit['borrower'];
* poolAccount: HostInterface<OrchestrationAccount<{chainId: 'agoric'}>>;
* intermediateRecipient: ChainAddress;
* }} config
*/
config => harden(config),
Expand Down Expand Up @@ -187,12 +188,20 @@ export const prepareAdvancerKit = (
* @param {AdvancerVowCtx & { tmpSeat: ZCFSeat }} ctx
*/
onFulfilled(result, ctx) {
const { poolAccount } = this.state;
const { poolAccount, intermediateRecipient } = this.state;
const { destination, advanceAmount, ...detail } = ctx;
const transferV = E(poolAccount).transfer(destination, {
denom: usdc.denom,
value: advanceAmount.value,
});
const transferV = E(poolAccount).transfer(
destination,
{
denom: usdc.denom,
value: advanceAmount.value,
},
{
forwardOpts: {
intermediateRecipient,
},
},
);
return watch(transferV, this.facets.transferHandler, {
destination,
advanceAmount,
Expand Down Expand Up @@ -250,6 +259,7 @@ export const prepareAdvancerKit = (
notifyFacet: M.remotable(),
borrowerFacet: M.remotable(),
poolAccount: M.remotable(),
intermediateRecipient: ChainAddressShape,
}),
},
);
Expand Down
10 changes: 9 additions & 1 deletion packages/fast-usdc/src/exos/settler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AmountMath } from '@agoric/ertp';
import { assertAllDefined, makeTracer } from '@agoric/internal';
import { ChainAddressShape } from '@agoric/orchestration';
import { atob } from '@endo/base64';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
Expand Down Expand Up @@ -93,6 +94,7 @@ export const prepareSettler = (
* remoteDenom: Denom;
* repayer: LiquidityPoolKit['repayer'];
* settlementAccount: HostInterface<OrchestrationAccount<{ chainId: 'agoric' }>>
* intermediateRecipient: ChainAddress;
* }} config
*/
config => {
Expand Down Expand Up @@ -255,14 +257,19 @@ export const prepareSettler = (
* @param {string} EUD
*/
forward(txHash, sender, fullValue, EUD) {
const { settlementAccount } = this.state;
const { settlementAccount, intermediateRecipient } = this.state;

const dest = chainHub.makeChainAddress(EUD);

// TODO? statusManager.forwarding(txHash, sender, amount);
const txfrV = E(settlementAccount).transfer(
dest,
AmountMath.make(USDC, fullValue),
{
forwardOpts: {
intermediateRecipient,
},
},
);
void vowTools.watch(txfrV, this.facets.transferHandler, {
txHash,
Expand Down Expand Up @@ -305,6 +312,7 @@ export const prepareSettler = (
sourceChannel: M.string(),
remoteDenom: M.string(),
mintedEarly: M.remotable('mintedEarly'),
intermediateRecipient: ChainAddressShape,
}),
},
);
Expand Down
20 changes: 15 additions & 5 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
'test of forcing evidence',
);

const { makeLocalAccount } = orchestrateAll(flows, {});
const { makeLocalAccount, makeNobleAccount } = orchestrateAll(flows, {});

const creatorFacet = zone.exo('Fast USDC Creator', undefined, {
/** @type {(operatorId: string) => Promise<Invitation<OperatorKit>>} */
Expand Down Expand Up @@ -214,18 +214,26 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
privateArgs.assetInfo,
);
}

const nobleAccountV = zone.makeOnce('NobleAccount', () => makeNobleAccount());
const feedKit = zone.makeOnce('Feed Kit', () => makeFeedKit());

const poolAccountV = zone.makeOnce('PoolAccount', () => makeLocalAccount());
const settleAccountV = zone.makeOnce('SettleAccount', () =>
makeLocalAccount(),
);
// when() is OK here since this clearly resolves promptly.
/** @type {HostInterface<OrchestrationAccount<{chainId: 'agoric';}>>[]} */
const [poolAccount, settlementAccount] = await vowTools.when(
vowTools.all([poolAccountV, settleAccountV]),
/** @type {[HostInterface<OrchestrationAccount<{chainId: 'noble-1';}>>, HostInterface<OrchestrationAccount<{chainId: 'agoric';}>>, HostInterface<OrchestrationAccount<{chainId: 'agoric';}>>]} */
const [nobleAccount, poolAccount, settlementAccount] = await vowTools.when(
vowTools.all([nobleAccountV, poolAccountV, settleAccountV]),
);
trace('settlementAccount', settlementAccount);
trace('poolAccount', poolAccount);
trace('nobleAccount', nobleAccount);

const intermediateRecipient = await vowTools.when(
E(nobleAccount).getAddress(),
);
trace('intermediateRecipient', intermediateRecipient);

const [_agoric, _noble, agToNoble] = await vowTools.when(
chainHub.getChainsAndConnection('agoric', 'noble'),
Expand All @@ -235,13 +243,15 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
sourceChannel: agToNoble.transferChannel.counterPartyChannelId,
remoteDenom: 'uusdc',
settlementAccount,
intermediateRecipient,
});

const advancer = zone.makeOnce('Advancer', () =>
makeAdvancer({
borrowerFacet: poolKit.borrower,
notifyFacet: settlerKit.notify,
poolAccount,
intermediateRecipient,
}),
);
// Connect evidence stream to advancer
Expand Down
10 changes: 10 additions & 0 deletions packages/fast-usdc/src/fast-usdc.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ export const makeLocalAccount = async orch => {
return agoricChain.makeAccount();
};
harden(makeLocalAccount);

/**
* @satisfies {OrchestrationFlow}
* @param {Orchestrator} orch
*/
export const makeNobleAccount = async orch => {
const nobleChain = await orch.getChain('noble');
return nobleChain.makeAccount();
};
harden(makeNobleAccount);
4 changes: 3 additions & 1 deletion packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { prepareStatusManager } from '../../src/exos/status-manager.js';
import { makeFeeTools } from '../../src/utils/fees.js';
import { addressTools } from '../../src/utils/address.js';
import { commonSetup } from '../supports.js';
import { MockCctpTxEvidences } from '../fixtures.js';
import { MockCctpTxEvidences, intermediateRecipient } from '../fixtures.js';
import {
makeTestFeeConfig,
makeTestLogger,
Expand Down Expand Up @@ -113,6 +113,7 @@ const createTestExtensions = (t, common: CommonSetup) => {
borrowerFacet: mockBorrowerF,
notifyFacet: mockNotifyF,
poolAccount: mockAccounts.mockPoolAccount.account,
intermediateRecipient,
});

return {
Expand Down Expand Up @@ -221,6 +222,7 @@ test('updates status to OBSERVED on insufficient pool funds', async t => {
borrowerFacet: mockBorrowerErrorF,
notifyFacet: mockNotifyF,
poolAccount: mockPoolAccount.account,
intermediateRecipient,
});

const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
Expand Down
16 changes: 15 additions & 1 deletion packages/fast-usdc/test/exos/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { prepareSettler } from '../../src/exos/settler.js';
import { prepareStatusManager } from '../../src/exos/status-manager.js';
import type { CctpTxEvidence } from '../../src/types.js';
import { makeFeeTools } from '../../src/utils/fees.js';
import { MockCctpTxEvidences, MockVTransferEvents } from '../fixtures.js';
import {
MockCctpTxEvidences,
MockVTransferEvents,
intermediateRecipient,
} from '../fixtures.js';
import { makeTestLogger, prepareMockOrchAccounts } from '../mocks.js';
import { commonSetup } from '../supports.js';

Expand Down Expand Up @@ -87,6 +91,7 @@ const makeTestContext = async t => {
fetchedChainInfo.agoric.connections['noble-1'].transferChannel
.counterPartyChannelId,
remoteDenom: 'uusdc',
intermediateRecipient,
});

const simulate = harden({
Expand Down Expand Up @@ -280,6 +285,15 @@ test('slow path: forward to EUD; remove pending tx', async t => {
value: 'osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
},
usdc.units(150),
{
forwardOpts: {
intermediateRecipient: {
chainId: 'noble-1',
encoding: 'bech32',
value: 'noble1test',
},
},
},
],
]);

Expand Down
3 changes: 2 additions & 1 deletion packages/fast-usdc/test/fast-usdc.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const startContract = async (

const makeTestContext = async (t: ExecutionContext) => {
const common = await commonSetup(t);
await E(common.mocks.ibcBridge).setAddressPrefix('noble');

const startKit = await startContract(common, 2);

Expand Down Expand Up @@ -405,7 +406,7 @@ const makeCustomer = (
const [ibcTransferMsg] = lm.messages;
// support advances to noble + other chains
const receiver =
ibcTransferMsg.receiver === 'pfm'
ibcTransferMsg.receiver === 'noble1test' // intermediateRecipient value
? JSON.parse(ibcTransferMsg.memo).forward.receiver
: ibcTransferMsg.receiver;
return (
Expand Down
7 changes: 7 additions & 0 deletions packages/fast-usdc/test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { VTransferIBCEvent } from '@agoric/vats';
import { buildVTransferEvent } from '@agoric/orchestration/tools/ibc-mocks.js';
import fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js';
import type { ChainAddress } from '@agoric/orchestration';
import type { CctpTxEvidence } from '../src/types.js';

const mockScenarios = [
Expand Down Expand Up @@ -141,3 +142,9 @@ export const MockVTransferEvents: Record<
MockCctpTxEvidences.AGORIC_UNKNOWN_EUD().aux.recipientAddress,
}),
};

export const intermediateRecipient: ChainAddress = harden({
chainId: 'noble-1',
value: 'noble1test',
encoding: 'bech32',
});
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ Generated by [AVA](https://avajs.dev).
withdrawHandler: Object @Alleged: Liquidity Pool withdrawHandler {},
},
'Liquidity Pool_kindHandle': 'Alleged: kind',
NobleAccount: 'Vow',
'Operator Kit_kindHandle': 'Alleged: kind',
PendingTxs: {},
PoolAccount: 'Vow',
Expand All @@ -601,6 +602,9 @@ Generated by [AVA](https://avajs.dev).
makeLocalAccount: {
asyncFlow_kindHandle: 'Alleged: kind',
},
makeNobleAccount: {
asyncFlow_kindHandle: 'Alleged: kind',
},
},
pending: {},
vstorage: {
Expand All @@ -620,6 +624,10 @@ Generated by [AVA](https://avajs.dev).
pending: false,
value: Object @Alleged: LocalChainFacade public {},
},
noble: {
pending: false,
value: Object @Alleged: RemoteChainFacade public {},
},
},
ibcTools: {
IBCTransferSenderKit_kindHandle: 'Alleged: kind',
Expand Down
Binary file modified packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap
Binary file not shown.

0 comments on commit 2614509

Please sign in to comment.