Skip to content

Commit

Permalink
Merge branch 'master' into 10394-board
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 28, 2024
2 parents 00ca9e4 + 8a52ddd commit ede0053
Show file tree
Hide file tree
Showing 18 changed files with 3,482 additions and 571 deletions.
7 changes: 6 additions & 1 deletion packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { Fail } from '@endo/errors';
import { documentStorageSchema } from '@agoric/internal/src/storage-test-utils.js';
import {
defaultMarshaller,
documentStorageSchema,
} from '@agoric/internal/src/storage-test-utils.js';
import type { CosmosValidatorAddress } from '@agoric/orchestration';
import type { start as startStakeIca } from '@agoric/orchestration/src/examples/stake-ica.contract.js';
import type { Instance } from '@agoric/zoe/src/zoeService/utils.js';
Expand Down Expand Up @@ -52,6 +55,7 @@ test.serial('config', async t => {
await documentStorageSchema(t, storage, {
note: 'Chain info for Orchestration',
node: 'agoricNames.chain',
showValue: v => defaultMarshaller.fromCapData(JSON.parse(v)),
});
}

Expand All @@ -73,6 +77,7 @@ test.serial('config', async t => {
await documentStorageSchema(t, storage, {
note: 'Chain connections for Orchestration',
node: 'agoricNames.chainConnection',
showValue: v => defaultMarshaller.fromCapData(JSON.parse(v)),
});
}
{
Expand Down
2,076 changes: 1,961 additions & 115 deletions packages/boot/test/bootstrapTests/snapshots/orchestration.test.ts.md

Large diffs are not rendered by default.

Binary file not shown.
14 changes: 13 additions & 1 deletion packages/boot/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { documentStorageSchema } from '@agoric/governance/tools/storageDoc.js';
import { Fail } from '@endo/errors';
import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js';
import { makeMarshal } from '@endo/marshal';
import { defaultMarshaller } from '@agoric/internal/src/storage-test-utils.js';
import {
makeWalletFactoryContext,
type WalletFactoryTestContext,
Expand Down Expand Up @@ -110,9 +111,20 @@ test.serial(

test.serial('writes feed policy to vstorage', async t => {
const { storage } = t.context;
const doc = {
const opts = {
node: 'fastUsdc.feedPolicy',
owner: 'the general and chain-specific policies for the Fast USDC feed',
showValue: JSON.parse,
};
await documentStorageSchema(t, storage, opts);
});

test.serial('writes fee config to vstorage', async t => {
const { storage } = t.context;
const doc = {
node: 'fastUsdc.feeConfig',
owner: 'the fee configuration for Fast USDC',
showValue: v => defaultMarshaller.fromCapData(JSON.parse(v)),
};
await documentStorageSchema(t, storage, doc);
});
Expand Down
60 changes: 57 additions & 3 deletions packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,61 @@ Generated by [AVA](https://avajs.dev).
[
[
'published.fastUsdc.feedPolicy',
'{"blockHeight":"0","values":["{\\"chainPolicies\\":{\\"Arbitrum\\":{\\"cctpTokenMessengerAddress\\":\\"0x19330d10D9Cc8751218eaf51E8885D058642E08A\\",\\"chainId\\":42161,\\"confirmations\\":2,\\"nobleContractAddress\\":\\"0x19330d10D9Cc8751218eaf51E8885D058642E08A\\"}},\\"nobleAgoricChannelId\\":\\"channel-21\\",\\"nobleDomainId\\":4}"]}',
{
chainPolicies: {
Arbitrum: {
cctpTokenMessengerAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
confirmations: 2,
nobleContractAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
},
},
nobleAgoricChannelId: 'channel-21',
nobleDomainId: 4,
},
],
]

## writes fee config to vstorage

> Under "published", the "fastUsdc.feeConfig" node is delegated to the fee configuration for Fast USDC.
> The example below illustrates the schema of the data published there.
>
> See also board marshalling conventions (_to appear_).
[
[
'published.fastUsdc.feeConfig',
{
contractRate: {
denominator: {
brand: Object @Alleged: USDC brand {},
value: 10n,
},
numerator: {
brand: Object @Alleged: USDC brand {},
value: 2n,
},
},
flat: {
brand: Object @Alleged: USDC brand {},
value: 10000n,
},
maxVariable: {
brand: Object @Alleged: USDC brand {},
value: 5000000n,
},
variableRate: {
denominator: {
brand: Object @Alleged: USDC brand {},
value: 100n,
},
numerator: {
brand: Object @Alleged: USDC brand {},
value: 1n,
},
},
},
],
]

Expand All @@ -28,10 +82,10 @@ Generated by [AVA](https://avajs.dev).
[
[
'published.fastUsdc.status.0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761702',
'{"blockHeight":"0","values":["OBSERVED"]}',
'OBSERVED',
],
[
'published.fastUsdc.status.0xd81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761799',
'{"blockHeight":"0","values":["OBSERVED"]}',
'OBSERVED',
],
]
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
97 changes: 42 additions & 55 deletions packages/fast-usdc/src/exos/advancer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AmountMath, AmountShape } from '@agoric/ertp';
import { AmountMath } from '@agoric/ertp';
import { assertAllDefined, makeTracer } from '@agoric/internal';
import { ChainAddressShape } from '@agoric/orchestration';
import { AnyNatAmountShape, ChainAddressShape } from '@agoric/orchestration';
import { pickFacet } from '@agoric/vat-data';
import { VowShape } from '@agoric/vow';
import { q } from '@endo/errors';
Expand All @@ -16,6 +16,7 @@ import { makeFeeTools } from '../utils/fees.js';

/**
* @import {HostInterface} from '@agoric/async-flow';
* @import {TypedPattern} from '@agoric/internal'
* @import {NatAmount} from '@agoric/ertp';
* @import {ChainAddress, ChainHub, Denom, OrchestrationAccount} from '@agoric/orchestration';
* @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
Expand All @@ -39,47 +40,40 @@ import { makeFeeTools } from '../utils/fees.js';
* }} AdvancerKitPowers
*/

/** @type {TypedPattern<AdvancerVowCtx>} */
const AdvancerVowCtxShape = M.splitRecord(
{
fullAmount: AnyNatAmountShape,
advanceAmount: AnyNatAmountShape,
destination: ChainAddressShape,
forwardingAddress: M.string(),
txHash: EvmHashShape,
},
{ tmpSeat: M.remotable() },
);

/** type guards internal to the AdvancerKit */
const AdvancerKitI = harden({
advancer: M.interface('AdvancerI', {
handleTransactionEvent: M.callWhen(CctpTxEvidenceShape).returns(),
}),
depositHandler: M.interface('DepositHandlerI', {
onFulfilled: M.call(M.undefined(), {
amount: AmountShape,
destination: ChainAddressShape,
forwardingAddress: M.string(),
tmpSeat: M.remotable(),
txHash: EvmHashShape,
}).returns(VowShape),
onRejected: M.call(M.error(), {
amount: AmountShape,
destination: ChainAddressShape,
forwardingAddress: M.string(),
tmpSeat: M.remotable(),
txHash: EvmHashShape,
}).returns(),
onFulfilled: M.call(M.undefined(), AdvancerVowCtxShape).returns(VowShape),
onRejected: M.call(M.error(), AdvancerVowCtxShape).returns(),
}),
transferHandler: M.interface('TransferHandlerI', {
// TODO confirm undefined, and not bigint (sequence)
onFulfilled: M.call(M.undefined(), {
amount: AmountShape,
destination: ChainAddressShape,
forwardingAddress: M.string(),
txHash: EvmHashShape,
}).returns(M.undefined()),
onRejected: M.call(M.error(), {
amount: AmountShape,
destination: ChainAddressShape,
forwardingAddress: M.string(),
txHash: EvmHashShape,
}).returns(M.undefined()),
onFulfilled: M.call(M.undefined(), AdvancerVowCtxShape).returns(
M.undefined(),
),
onRejected: M.call(M.error(), AdvancerVowCtxShape).returns(M.undefined()),
}),
});

/**
* @typedef {{
* amount: NatAmount;
* fullAmount: NatAmount;
* advanceAmount: NatAmount;
* destination: ChainAddress;
* forwardingAddress: NobleAddress;
* txHash: EvmHash;
Expand Down Expand Up @@ -155,9 +149,9 @@ export const prepareAdvancerKit = (
// throws if the bech32 prefix is not found
const destination = chainHub.makeChainAddress(EUD);

const requestedAmount = toAmount(evidence.tx.amount);
const fullAmount = toAmount(evidence.tx.amount);
// throws if requested does not exceed fees
const advanceAmount = feeTools.calculateAdvance(requestedAmount);
const advanceAmount = feeTools.calculateAdvance(fullAmount);

const { zcfSeat: tmpSeat } = zcf.makeEmptySeatKit();
const amountKWR = harden({ USDC: advanceAmount });
Expand All @@ -174,7 +168,8 @@ export const prepareAdvancerKit = (
amountKWR,
);
void watch(depositV, this.facets.depositHandler, {
amount: advanceAmount,
fullAmount,
advanceAmount,
destination,
forwardingAddress: evidence.tx.forwardingAddress,
tmpSeat,
Expand All @@ -193,16 +188,15 @@ export const prepareAdvancerKit = (
*/
onFulfilled(result, ctx) {
const { poolAccount } = this.state;
const { amount, destination, forwardingAddress, txHash } = ctx;
const { destination, advanceAmount, ...detail } = ctx;
const transferV = E(poolAccount).transfer(destination, {
denom: usdc.denom,
value: amount.value,
value: advanceAmount.value,
});
return watch(transferV, this.facets.transferHandler, {
destination,
amount,
forwardingAddress,
txHash,
advanceAmount,
...detail,
});
},
/**
Expand All @@ -222,39 +216,32 @@ export const prepareAdvancerKit = (
},
transferHandler: {
/**
* @param {undefined} result TODO confirm this is not a bigint (sequence)
* @param {unknown} result TODO confirm this is not a bigint (sequence)
* @param {AdvancerVowCtx} ctx
*/
onFulfilled(result, ctx) {
const { notifyFacet } = this.state;
const { amount, destination, forwardingAddress, txHash } = ctx;
const { advanceAmount, destination, ...detail } = ctx;
log(
'Advance transfer fulfilled',
q({ amount, destination, result }).toString(),
);
notifyFacet.notifyAdvancingResult(
txHash,
forwardingAddress,
amount.value,
destination.value,
true,
q({ advanceAmount, destination, result }).toString(),
);
// During development, due to a bug, this call threw.
// The failure was silent (no diagnostics) due to:
// - #10576 Vows do not report unhandled rejections
// For now, the advancer kit relies on consistency between
// notifyFacet, statusManager, and callers of handleTransactionEvent().
// TODO: revisit #10576 during #10510
notifyFacet.notifyAdvancingResult({ destination, ...detail }, true);
},
/**
* @param {Error} error
* @param {AdvancerVowCtx} ctx
*/
onRejected(error, ctx) {
const { notifyFacet } = this.state;
const { amount, destination, forwardingAddress, txHash } = ctx;
log('Advance transfer rejected', q(error).toString());
notifyFacet.notifyAdvancingResult(
txHash,
forwardingAddress,
amount.value,
destination.value,
false,
);
notifyFacet.notifyAdvancingResult(ctx, false);
},
},
},
Expand Down
Loading

0 comments on commit ede0053

Please sign in to comment.