Skip to content

Commit 3c16d47

Browse files
turadgChris-Hibbert
andcommitted
feat: CAIP-10 destinations
Co-Authored-By: Chris Hibbert <[email protected]>
1 parent fd22f4d commit 3c16d47

File tree

4 files changed

+35
-52
lines changed

4 files changed

+35
-52
lines changed

packages/fast-usdc-contract/src/exos/advancer.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
AnyNatAmountShape,
3636
CosmosChainAddressShape,
3737
} from '@agoric/orchestration';
38+
import type { AccountId } from '@agoric/orchestration/src/orchestration-api.js';
39+
import { parseAccountIdArg } from '@agoric/orchestration/src/utils/address.js';
3840
import type { ZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js';
3941
import { pickFacet } from '@agoric/vat-data';
4042
import type { VowTools } from '@agoric/vow';
@@ -63,7 +65,7 @@ interface AdvancerKitPowers {
6365
interface AdvancerVowCtx {
6466
fullAmount: NatAmount;
6567
advanceAmount: NatAmount;
66-
destination: CosmosChainAddress;
68+
destination: AccountId;
6769
forwardingAddress: NobleAddress;
6870
txHash: EvmHash;
6971
}
@@ -72,7 +74,7 @@ const AdvancerVowCtxShape: TypedPattern<AdvancerVowCtx> = M.splitRecord(
7274
{
7375
fullAmount: AnyNatAmountShape,
7476
advanceAmount: AnyNatAmountShape,
75-
destination: CosmosChainAddressShape,
77+
destination: M.string(), // AccountId
7678
forwardingAddress: M.string(),
7779
txHash: EvmHashShape,
7880
},
@@ -200,7 +202,7 @@ export const prepareAdvancerKit = (
200202
log(`decoded EUD: ${EUD}`);
201203
assert.typeof(EUD, 'string');
202204
// throws if the bech32 prefix is not found
203-
const destination = chainHub.makeChainAddress(EUD);
205+
const destination = chainHub.resolveAccountId(EUD);
204206

205207
const fullAmount = toAmount(evidence.tx.amount);
206208
const { borrower, notifier, poolAccount } = this.state;
@@ -262,8 +264,12 @@ export const prepareAdvancerKit = (
262264
value: advanceAmount.value,
263265
});
264266
const intermediateRecipient = getNobleICA().getAddress();
267+
const accountId = parseAccountIdArg(destination);
268+
269+
assert.equal(accountId.namespace, 'cosmos');
270+
265271
const transferOrSendV =
266-
destination.chainId === settlementAddress.chainId
272+
accountId.reference === settlementAddress.chainId
267273
? E(poolAccount).send(destination, amount)
268274
: E(poolAccount).transfer(destination, amount, {
269275
forwardOpts: { intermediateRecipient },

packages/fast-usdc-contract/src/exos/settler.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import type {
3737
import type {
3838
AccountId,
3939
ChainHub,
40-
CosmosChainAddress,
4140
Denom,
4241
OrchestrationAccount,
4342
} from '@agoric/orchestration';
@@ -112,7 +111,7 @@ const makeMintedEarlyKey = (addr: NobleAddress, amount: bigint): string =>
112111
/** @param {Brand<'nat'>} USDC */
113112
export const makeAdvanceDetailsShape = (USDC: Brand<'nat'>) =>
114113
harden({
115-
destination: CosmosChainAddressShape,
114+
destination: M.string(),
116115
forwardingAddress: M.string(),
117116
fullAmount: makeNatAmountShape(USDC),
118117
txHash: EvmHashShape,
@@ -184,10 +183,9 @@ export const prepareSettler = (
184183
makeAdvanceDetailsShape(USDC),
185184
M.boolean(),
186185
).returns(),
187-
checkMintedEarly: M.call(
188-
CctpTxEvidenceShape,
189-
CosmosChainAddressShape,
190-
).returns(M.boolean()),
186+
checkMintedEarly: M.call(CctpTxEvidenceShape, M.string()).returns(
187+
M.boolean(),
188+
),
191189
}),
192190
self: M.interface('SettlerSelfI', {
193191
addMintedEarly: M.call(M.string(), M.nat()).returns(),
@@ -295,24 +293,21 @@ export const prepareSettler = (
295293
txHash: EvmHash;
296294
forwardingAddress: NobleAddress;
297295
fullAmount: Amount<'nat'>;
298-
destination: CosmosChainAddress;
296+
destination: AccountId;
299297
},
300298
success: boolean,
301299
): void {
302300
const { mintedEarly } = this.state;
303301
const { value: fullValue } = fullAmount;
304302
const key = makeMintedEarlyKey(forwardingAddress, fullValue);
303+
305304
if (mintedEarly.has(key)) {
306305
asMultiset(mintedEarly).remove(key);
307306
statusManager.advanceOutcomeForMintedEarly(txHash, success);
308307
if (success) {
309308
void this.facets.self.disburse(txHash, fullValue);
310309
} else {
311-
void this.facets.self.forward(
312-
txHash,
313-
fullValue,
314-
destination.value,
315-
);
310+
void this.facets.self.forward(txHash, fullValue, destination);
316311
}
317312
} else {
318313
statusManager.advanceOutcome(forwardingAddress, fullValue, success);
@@ -323,12 +318,12 @@ export const prepareSettler = (
323318
* funds to the pool.
324319
*
325320
* @param {CctpTxEvidence} evidence
326-
* @param {CosmosChainAddress} destination
321+
* @param {AccountId} destination
327322
* @returns {boolean} whether the EUD received funds without an advance
328323
*/
329324
checkMintedEarly(
330325
evidence: CctpTxEvidence,
331-
destination: CosmosChainAddress,
326+
destination: AccountId,
332327
): boolean {
333328
const {
334329
tx: { forwardingAddress, amount },
@@ -344,7 +339,7 @@ export const prepareSettler = (
344339
);
345340
asMultiset(mintedEarly).remove(key);
346341
statusManager.advanceOutcomeForUnknownMint(evidence);
347-
void this.facets.self.forward(txHash, amount, destination.value);
342+
void this.facets.self.forward(txHash, amount, destination);
348343
return true;
349344
}
350345
return false;

packages/fast-usdc-contract/test/exos/advancer.test.ts

+11-28
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const createTestExtensions = (t, common: CommonSetup) => {
139139
// assume this never returns true for most tests
140140
checkMintedEarly: (evidence, destination) => {
141141
mustMatch(harden(evidence), CctpTxEvidenceShape);
142-
mustMatch(destination, CosmosChainAddressShape);
142+
mustMatch(destination, M.string());
143143
return false;
144144
},
145145
});
@@ -251,11 +251,8 @@ test('updates status to ADVANCING in happy path', async t => {
251251
brand: usdc.brand,
252252
value: 146999999n,
253253
},
254-
destination: {
255-
chainId: 'osmosis-1',
256-
encoding: 'bech32',
257-
value: 'osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
258-
},
254+
destination:
255+
'cosmos:osmosis-1:osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
259256
},
260257
],
261258
]);
@@ -268,9 +265,7 @@ test('updates status to ADVANCING in happy path', async t => {
268265
txHash: evidence.txHash,
269266
forwardingAddress: evidence.tx.forwardingAddress,
270267
fullAmount: usdc.make(evidence.tx.amount),
271-
destination: {
272-
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
273-
},
268+
destination: `cosmos:osmosis-1:${decodeAddressHook(evidence.aux.recipientAddress).query.EUD}`,
274269
},
275270
true, // indicates transfer succeeded
276271
],
@@ -412,9 +407,7 @@ test('recovery behavior if Advance Fails (ADVANCE_FAILED)', async t => {
412407
txHash: evidence.txHash,
413408
forwardingAddress: evidence.tx.forwardingAddress,
414409
fullAmount: usdc.make(evidence.tx.amount),
415-
destination: {
416-
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
417-
},
410+
destination: `cosmos:dydx-mainnet-1:${decodeAddressHook(evidence.aux.recipientAddress).query.EUD}`,
418411
},
419412
false, // this indicates transfer failed
420413
],
@@ -660,11 +653,8 @@ test('will not advance same txHash:chainId evidence twice', async t => {
660653
'Advance succeeded',
661654
{
662655
advanceAmount: { brand: usdc.brand, value: 146999999n },
663-
destination: {
664-
chainId: 'osmosis-1',
665-
encoding: 'bech32',
666-
value: 'osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
667-
},
656+
destination:
657+
'cosmos:osmosis-1:osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
668658
},
669659
],
670660
]);
@@ -913,11 +903,8 @@ test('uses bank send for agoric1 EUD', async t => {
913903
brand: usdc.brand,
914904
value: 244999999n,
915905
},
916-
destination: {
917-
chainId: 'agoric-3',
918-
encoding: 'bech32',
919-
value: 'agoric13rj0cc0hm5ac2nt0sdup2l7gvkx4v9tyvgq3h2',
920-
},
906+
destination:
907+
'cosmos:agoric-3:agoric13rj0cc0hm5ac2nt0sdup2l7gvkx4v9tyvgq3h2',
921908
},
922909
],
923910
]);
@@ -929,9 +916,7 @@ test('uses bank send for agoric1 EUD', async t => {
929916
txHash: evidence.txHash,
930917
forwardingAddress: evidence.tx.forwardingAddress,
931918
fullAmount: usdc.make(evidence.tx.amount),
932-
destination: {
933-
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
934-
},
919+
destination: `cosmos:agoric-3:${decodeAddressHook(evidence.aux.recipientAddress).query.EUD}`,
935920
},
936921
true, // indicates send succeeded
937922
],
@@ -970,9 +955,7 @@ test('notifies of advance failure if bank send fails', async t => {
970955
txHash: evidence.txHash,
971956
forwardingAddress: evidence.tx.forwardingAddress,
972957
fullAmount: usdc.make(evidence.tx.amount),
973-
destination: {
974-
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
975-
},
958+
destination: `cosmos:agoric-3:${decodeAddressHook(evidence.aux.recipientAddress).query.EUD}`,
976959
},
977960
false, // indicates send failed
978961
],

packages/fast-usdc-contract/test/exos/settler.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import type { Baggage } from '@agoric/vat-data';
2323
import cctpChainInfo from '@agoric/orchestration/src/cctp-chain-info.js';
2424
import {
2525
prepareSettler,
26-
stateShape,
2726
type SettlerKit,
27+
stateShape,
2828
} from '../../src/exos/settler.ts';
2929
import { prepareStatusManager } from '../../src/exos/status-manager.ts';
3030
import {
31+
intermediateRecipient,
3132
MockCctpTxEvidences,
3233
MockVTransferEvents,
33-
intermediateRecipient,
3434
} from '../fixtures.js';
3535
import { makeTestLogger, prepareMockOrchAccounts } from '../mocks.js';
3636
import { commonSetup } from '../supports.js';
@@ -137,12 +137,11 @@ const makeTestContext = async t => {
137137
if (typeof EUD !== 'string') {
138138
throw Error(`EUD not found in ${recipientAddress}`);
139139
}
140-
const destination = chainHub.makeChainAddress(EUD);
141140
return harden({
142141
txHash,
143142
forwardingAddress,
144143
fullAmount: usdc.make(amount),
145-
destination,
144+
destination: chainHub.resolveAccountId(EUD),
146145
});
147146
};
148147

@@ -515,7 +514,7 @@ test('Settlement for unknown transaction (minted early)', async t => {
515514
'forwarding',
516515
150000000n,
517516
'to',
518-
'osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
517+
'cosmos:osmosis-1:osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men',
519518
'for',
520519
'0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761702',
521520
],

0 commit comments

Comments
 (0)