@agoric/fast-usdc 0.1.1-dev-7e54272.0 → 0.1.1-dev-3ba7ca7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/fast-usdc",
3
- "version": "0.1.1-dev-7e54272.0+7e54272",
3
+ "version": "0.1.1-dev-3ba7ca7.0+3ba7ca7",
4
4
  "description": "CLI and library for Fast USDC product",
5
5
  "type": "module",
6
6
  "files": [
@@ -21,9 +21,9 @@
21
21
  "lint:eslint": "eslint ."
22
22
  },
23
23
  "devDependencies": {
24
- "@agoric/swingset-liveslots": "0.10.3-dev-7e54272.0+7e54272",
25
- "@agoric/vats": "0.15.2-dev-7e54272.0+7e54272",
26
- "@agoric/zone": "0.2.3-dev-7e54272.0+7e54272",
24
+ "@agoric/swingset-liveslots": "0.10.3-dev-3ba7ca7.0+3ba7ca7",
25
+ "@agoric/vats": "0.15.2-dev-3ba7ca7.0+3ba7ca7",
26
+ "@agoric/zone": "0.2.3-dev-3ba7ca7.0+3ba7ca7",
27
27
  "@fast-check/ava": "^2.0.1",
28
28
  "ava": "^5.3.0",
29
29
  "c8": "^9.1.0",
@@ -31,15 +31,15 @@
31
31
  "ts-blank-space": "^0.4.1"
32
32
  },
33
33
  "dependencies": {
34
- "@agoric/client-utils": "0.1.1-dev-7e54272.0+7e54272",
35
- "@agoric/ertp": "0.16.3-dev-7e54272.0+7e54272",
36
- "@agoric/internal": "0.3.3-dev-7e54272.0+7e54272",
37
- "@agoric/notifier": "0.6.3-dev-7e54272.0+7e54272",
38
- "@agoric/orchestration": "0.1.1-dev-7e54272.0+7e54272",
39
- "@agoric/store": "0.9.3-dev-7e54272.0+7e54272",
40
- "@agoric/vat-data": "0.5.3-dev-7e54272.0+7e54272",
41
- "@agoric/vow": "0.1.1-dev-7e54272.0+7e54272",
42
- "@agoric/zoe": "0.26.3-dev-7e54272.0+7e54272",
34
+ "@agoric/client-utils": "0.1.1-dev-3ba7ca7.0+3ba7ca7",
35
+ "@agoric/ertp": "0.16.3-dev-3ba7ca7.0+3ba7ca7",
36
+ "@agoric/internal": "0.3.3-dev-3ba7ca7.0+3ba7ca7",
37
+ "@agoric/notifier": "0.6.3-dev-3ba7ca7.0+3ba7ca7",
38
+ "@agoric/orchestration": "0.1.1-dev-3ba7ca7.0+3ba7ca7",
39
+ "@agoric/store": "0.9.3-dev-3ba7ca7.0+3ba7ca7",
40
+ "@agoric/vat-data": "0.5.3-dev-3ba7ca7.0+3ba7ca7",
41
+ "@agoric/vow": "0.1.1-dev-3ba7ca7.0+3ba7ca7",
42
+ "@agoric/zoe": "0.26.3-dev-3ba7ca7.0+3ba7ca7",
43
43
  "@cosmjs/proto-signing": "^0.32.4",
44
44
  "@cosmjs/stargate": "^0.32.4",
45
45
  "@endo/base64": "^1.0.9",
@@ -77,5 +77,5 @@
77
77
  "publishConfig": {
78
78
  "access": "public"
79
79
  },
80
- "gitHead": "7e54272bf8e809a106caf58549e409f33f1fce63"
80
+ "gitHead": "3ba7ca79fab3d11187ab59eba43f59b3f112b2c0"
81
81
  }
@@ -1,5 +1,5 @@
1
- import { AmountMath, AmountShape, PaymentShape } from '@agoric/ertp';
2
- import { assertAllDefined } from '@agoric/internal';
1
+ import { AmountMath, AmountShape } from '@agoric/ertp';
2
+ import { assertAllDefined, makeTracer } from '@agoric/internal';
3
3
  import { ChainAddressShape } from '@agoric/orchestration';
4
4
  import { pickFacet } from '@agoric/vat-data';
5
5
  import { VowShape } from '@agoric/vow';
@@ -15,31 +15,25 @@ const { isGTE } = AmountMath;
15
15
  /**
16
16
  * @import {HostInterface} from '@agoric/async-flow';
17
17
  * @import {NatAmount} from '@agoric/ertp';
18
- * @import {ChainAddress, ChainHub, Denom, DenomAmount, OrchestrationAccount} from '@agoric/orchestration';
18
+ * @import {ChainAddress, ChainHub, Denom, OrchestrationAccount} from '@agoric/orchestration';
19
+ * @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
19
20
  * @import {VowTools} from '@agoric/vow';
20
21
  * @import {Zone} from '@agoric/zone';
21
22
  * @import {CctpTxEvidence, FeeConfig, LogFn} from '../types.js';
22
23
  * @import {StatusManager} from './status-manager.js';
23
- */
24
-
25
- /**
26
- * Expected interface from LiquidityPool
27
- *
28
- * @typedef {{
29
- * lookupBalance(): NatAmount;
30
- * borrow(amount: Amount<"nat">): Promise<Payment<"nat">>;
31
- * repay(payments: PaymentKeywordRecord): Promise<void>
32
- * }} AssetManagerFacet
24
+ * @import {LiquidityPoolKit} from './liquidity-pool.js';
33
25
  */
34
26
 
35
27
  /**
36
28
  * @typedef {{
37
29
  * chainHub: ChainHub;
38
30
  * feeConfig: FeeConfig;
39
- * log: LogFn;
31
+ * localTransfer: ZoeTools['localTransfer'];
32
+ * log?: LogFn;
40
33
  * statusManager: StatusManager;
41
34
  * usdc: { brand: Brand<'nat'>; denom: Denom; };
42
35
  * vowTools: VowTools;
36
+ * zcf: ZCF;
43
37
  * }} AdvancerKitPowers
44
38
  */
45
39
 
@@ -49,13 +43,15 @@ const AdvancerKitI = harden({
49
43
  handleTransactionEvent: M.callWhen(CctpTxEvidenceShape).returns(),
50
44
  }),
51
45
  depositHandler: M.interface('DepositHandlerI', {
52
- onFulfilled: M.call(AmountShape, {
46
+ onFulfilled: M.call(M.undefined(), {
47
+ amount: AmountShape,
53
48
  destination: ChainAddressShape,
54
- payment: PaymentShape,
49
+ tmpSeat: M.remotable(),
55
50
  }).returns(VowShape),
56
51
  onRejected: M.call(M.error(), {
52
+ amount: AmountShape,
57
53
  destination: ChainAddressShape,
58
- payment: PaymentShape,
54
+ tmpSeat: M.remotable(),
59
55
  }).returns(),
60
56
  }),
61
57
  transferHandler: M.interface('TransferHandlerI', {
@@ -77,7 +73,16 @@ const AdvancerKitI = harden({
77
73
  */
78
74
  export const prepareAdvancerKit = (
79
75
  zone,
80
- { chainHub, feeConfig, log, statusManager, usdc, vowTools: { watch, when } },
76
+ {
77
+ chainHub,
78
+ feeConfig,
79
+ localTransfer,
80
+ log = makeTracer('Advancer', true),
81
+ statusManager,
82
+ usdc,
83
+ vowTools: { watch, when },
84
+ zcf,
85
+ } = /** @type {AdvancerKitPowers} */ ({}),
81
86
  ) => {
82
87
  assertAllDefined({
83
88
  chainHub,
@@ -95,8 +100,8 @@ export const prepareAdvancerKit = (
95
100
  AdvancerKitI,
96
101
  /**
97
102
  * @param {{
98
- * assetManagerFacet: AssetManagerFacet;
99
- * poolAccount: ERef<HostInterface<OrchestrationAccount<{chainId: 'agoric'}>>>;
103
+ * borrowerFacet: LiquidityPoolKit['borrower'];
104
+ * poolAccount: HostInterface<OrchestrationAccount<{chainId: 'agoric'}>>;
100
105
  * }} config
101
106
  */
102
107
  config => harden(config),
@@ -115,8 +120,7 @@ export const prepareAdvancerKit = (
115
120
  async handleTransactionEvent(evidence) {
116
121
  await null;
117
122
  try {
118
- // TODO poolAccount might be a vow we need to unwrap
119
- const { assetManagerFacet, poolAccount } = this.state;
123
+ const { borrowerFacet, poolAccount } = this.state;
120
124
  const { recipientAddress } = evidence.aux;
121
125
  const { EUD } = addressTools.getQueryParams(
122
126
  recipientAddress,
@@ -129,14 +133,12 @@ export const prepareAdvancerKit = (
129
133
  const advanceAmount = feeTools.calculateAdvance(requestedAmount);
130
134
 
131
135
  // TODO: consider skipping and using `borrow()`s internal balance check
132
- const poolBalance = assetManagerFacet.lookupBalance();
136
+ const poolBalance = borrowerFacet.getBalance();
133
137
  if (!isGTE(poolBalance, requestedAmount)) {
134
138
  log(
135
139
  `Insufficient pool funds`,
136
140
  `Requested ${q(advanceAmount)} but only have ${q(poolBalance)}`,
137
141
  );
138
- // report `requestedAmount`, not `advancedAmount`... do we need to
139
- // communicate net to `StatusManger` in case fees change in between?
140
142
  statusManager.observe(evidence);
141
143
  return;
142
144
  }
@@ -152,19 +154,29 @@ export const prepareAdvancerKit = (
152
154
  return;
153
155
  }
154
156
 
157
+ const { zcfSeat: tmpSeat } = zcf.makeEmptySeatKit();
158
+ const amountKWR = harden({ USDC: advanceAmount });
155
159
  try {
156
- const payment = await assetManagerFacet.borrow(advanceAmount);
157
- const depositV = E(poolAccount).deposit(payment);
158
- void watch(depositV, this.facets.depositHandler, {
159
- destination,
160
- payment,
161
- });
160
+ borrowerFacet.borrow(tmpSeat, amountKWR);
162
161
  } catch (e) {
163
- // `.borrow()` might fail if the balance changes since we
164
- // requested it. TODO - how to handle this? change ADVANCED -> OBSERVED?
165
- // Note: `depositHandler` handles the `.deposit()` failure
162
+ // We do not expect this to fail since there are no turn boundaries
163
+ // between .getBalance() and .borrow().
164
+ // We catch to report outside of the normal error flow since this is
165
+ // not expected.
166
166
  log('🚨 advance borrow failed', q(e).toString());
167
167
  }
168
+
169
+ const depositV = localTransfer(
170
+ tmpSeat,
171
+ // @ts-expect-error LocalAccountMethods vs OrchestrationAccount
172
+ poolAccount,
173
+ amountKWR,
174
+ );
175
+ void watch(depositV, this.facets.depositHandler, {
176
+ amount: advanceAmount,
177
+ destination,
178
+ tmpSeat,
179
+ });
168
180
  } catch (e) {
169
181
  log('Advancer error:', q(e).toString());
170
182
  statusManager.observe(evidence);
@@ -173,18 +185,15 @@ export const prepareAdvancerKit = (
173
185
  },
174
186
  depositHandler: {
175
187
  /**
176
- * @param {NatAmount} amount amount returned from deposit
177
- * @param {{ destination: ChainAddress; payment: Payment<'nat'> }} ctx
188
+ * @param {undefined} result
189
+ * @param {{ amount: Amount<'nat'>; destination: ChainAddress; tmpSeat: ZCFSeat }} ctx
178
190
  */
179
- onFulfilled(amount, { destination }) {
191
+ onFulfilled(result, { amount, destination }) {
180
192
  const { poolAccount } = this.state;
181
- const transferV = E(poolAccount).transfer(
182
- destination,
183
- /** @type {DenomAmount} */ ({
184
- denom: usdc.denom,
185
- value: amount.value,
186
- }),
187
- );
193
+ const transferV = E(poolAccount).transfer(destination, {
194
+ denom: usdc.denom,
195
+ value: amount.value,
196
+ });
188
197
  return watch(transferV, this.facets.transferHandler, {
189
198
  destination,
190
199
  amount,
@@ -192,12 +201,17 @@ export const prepareAdvancerKit = (
192
201
  },
193
202
  /**
194
203
  * @param {Error} error
195
- * @param {{ destination: ChainAddress; payment: Payment<'nat'> }} ctx
204
+ * @param {{ amount: Amount<'nat'>; destination: ChainAddress; tmpSeat: ZCFSeat }} ctx
196
205
  */
197
- onRejected(error, { payment }) {
198
- // TODO return live payment from ctx to LP
206
+ onRejected(error, { tmpSeat }) {
207
+ // TODO return seat allocation from ctx to LP?
199
208
  log('🚨 advance deposit failed', q(error).toString());
200
- log('TODO live payment to return to LP', q(payment).toString());
209
+ // TODO #10510 (comprehensive error testing) determine
210
+ // course of action here
211
+ log(
212
+ 'TODO live payment on seat to return to LP',
213
+ q(tmpSeat).toString(),
214
+ );
201
215
  },
202
216
  },
203
217
  transferHandler: {
@@ -206,23 +220,24 @@ export const prepareAdvancerKit = (
206
220
  * @param {{ destination: ChainAddress; amount: NatAmount; }} ctx
207
221
  */
208
222
  onFulfilled(result, { destination, amount }) {
209
- // TODO vstorage update?
223
+ // TODO vstorage update? We don't currently have a status for
224
+ // Advanced + transferV settled
210
225
  log(
211
226
  'Advance transfer fulfilled',
212
227
  q({ amount, destination, result }).toString(),
213
228
  );
214
229
  },
215
230
  onRejected(error) {
216
- // XXX retry logic?
217
- // What do we do if we fail, should we keep a Status?
231
+ // TODO #10510 (comprehensive error testing) determine
232
+ // course of action here. This might fail due to timeout.
218
233
  log('Advance transfer rejected', q(error).toString());
219
234
  },
220
235
  },
221
236
  },
222
237
  {
223
238
  stateShape: harden({
224
- assetManagerFacet: M.remotable(),
225
- poolAccount: M.or(VowShape, M.remotable()),
239
+ borrowerFacet: M.remotable(),
240
+ poolAccount: M.remotable(),
226
241
  }),
227
242
  },
228
243
  );
@@ -11,9 +11,10 @@ import {
11
11
  } from '@agoric/orchestration';
12
12
  import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js';
13
13
  import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
14
+ import { makeZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js';
15
+ import { depositToSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';
14
16
  import { E } from '@endo/far';
15
17
  import { M, objectMap } from '@endo/patterns';
16
- import { depositToSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';
17
18
  import { prepareAdvancer } from './exos/advancer.js';
18
19
  import { prepareLiquidityPoolKit } from './exos/liquidity-pool.js';
19
20
  import { prepareSettler } from './exos/settler.js';
@@ -21,12 +22,16 @@ import { prepareStatusManager } from './exos/status-manager.js';
21
22
  import { prepareTransactionFeedKit } from './exos/transaction-feed.js';
22
23
  import { defineInertInvitation } from './utils/zoe.js';
23
24
  import { FastUSDCTermsShape, FeeConfigShape } from './type-guards.js';
25
+ import * as flows from './fast-usdc.flows.js';
24
26
 
25
27
  const trace = makeTracer('FastUsdc');
26
28
 
27
29
  /**
28
30
  * @import {Denom} from '@agoric/orchestration';
31
+ * @import {HostInterface} from '@agoric/async-flow';
32
+ * @import {OrchestrationAccount} from '@agoric/orchestration';
29
33
  * @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js';
34
+ * @import {Vow} from '@agoric/vow';
30
35
  * @import {Zone} from '@agoric/zone';
31
36
  * @import {OperatorKit} from './exos/operator-kit.js';
32
37
  * @import {CctpTxEvidence, FeeConfig} from './types.js';
@@ -73,35 +78,22 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
73
78
  );
74
79
  const statusManager = prepareStatusManager(zone);
75
80
  const makeSettler = prepareSettler(zone, { statusManager });
76
- const { chainHub, vowTools } = tools;
81
+ const { chainHub, orchestrateAll, vowTools } = tools;
82
+ const { localTransfer } = makeZoeTools(zcf, vowTools);
77
83
  const makeAdvancer = prepareAdvancer(zone, {
78
84
  chainHub,
79
85
  feeConfig,
80
- log: trace,
86
+ localTransfer,
81
87
  usdc: harden({
82
88
  brand: terms.brands.USDC,
83
89
  denom: terms.usdcDenom,
84
90
  }),
85
91
  statusManager,
86
92
  vowTools,
93
+ zcf,
87
94
  });
88
95
  const makeFeedKit = prepareTransactionFeedKit(zone, zcf);
89
96
  assertAllDefined({ makeFeedKit, makeAdvancer, makeSettler, statusManager });
90
- const feedKit = makeFeedKit();
91
- const advancer = makeAdvancer(
92
- // @ts-expect-error FIXME
93
- {},
94
- );
95
- // Connect evidence stream to advancer
96
- void observeIteration(subscribeEach(feedKit.public.getEvidenceSubscriber()), {
97
- updateState(evidence) {
98
- try {
99
- void advancer.handleTransactionEvent(evidence);
100
- } catch (err) {
101
- trace('🚨 Error handling transaction event', err);
102
- }
103
- },
104
- });
105
97
  const makeLiquidityPoolKit = prepareLiquidityPoolKit(
106
98
  zone,
107
99
  zcf,
@@ -114,16 +106,19 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
114
106
  'test of forcing evidence',
115
107
  );
116
108
 
109
+ const { makeLocalAccount } = orchestrateAll(flows, {});
110
+
117
111
  const creatorFacet = zone.exo('Fast USDC Creator', undefined, {
118
112
  /** @type {(operatorId: string) => Promise<Invitation<OperatorKit>>} */
119
113
  async makeOperatorInvitation(operatorId) {
114
+ // eslint-disable-next-line no-use-before-define
120
115
  return feedKit.creator.makeOperatorInvitation(operatorId);
121
116
  },
122
117
  /**
123
118
  * @param {{ USDC: Amount<'nat'>}} amounts
124
119
  */
125
120
  testBorrow(amounts) {
126
- console.log('🚧🚧 UNTIL: borrow is integrated 🚧🚧', amounts);
121
+ console.log('🚧🚧 UNTIL: borrow is integrated (#10388) 🚧🚧', amounts);
127
122
  const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit();
128
123
  // eslint-disable-next-line no-use-before-define
129
124
  poolKit.borrower.borrow(tmpAssetManagerSeat, amounts);
@@ -136,7 +131,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
136
131
  * @returns {Promise<AmountKeywordRecord>}
137
132
  */
138
133
  async testRepay(amounts, payments) {
139
- console.log('🚧🚧 UNTIL: repay is integrated 🚧🚧', amounts);
134
+ console.log('🚧🚧 UNTIL: repay is integrated (#10388) 🚧🚧', amounts);
140
135
  const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit();
141
136
  await depositToSeat(
142
137
  zcf,
@@ -164,6 +159,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
164
159
  * @param {CctpTxEvidence} evidence
165
160
  */
166
161
  makeTestPushInvitation(evidence) {
162
+ // eslint-disable-next-line no-use-before-define
167
163
  void advancer.handleTransactionEvent(evidence);
168
164
  return makeTestInvitation();
169
165
  },
@@ -207,6 +203,34 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
207
203
  makeLiquidityPoolKit(shareMint, privateArgs.storageNode),
208
204
  );
209
205
 
206
+ const feedKit = zone.makeOnce('Feed Kit', () => makeFeedKit());
207
+
208
+ const poolAccountV =
209
+ // cast to HostInterface
210
+ /** @type { Vow<HostInterface<OrchestrationAccount<{chainId: 'agoric';}>>>} */ (
211
+ /** @type {unknown}*/ (
212
+ zone.makeOnce('Pool Local Orch Account', () => makeLocalAccount())
213
+ )
214
+ );
215
+ const poolAccount = await vowTools.when(poolAccountV);
216
+
217
+ const advancer = zone.makeOnce('Advancer', () =>
218
+ makeAdvancer({
219
+ borrowerFacet: poolKit.borrower,
220
+ poolAccount,
221
+ }),
222
+ );
223
+ // Connect evidence stream to advancer
224
+ void observeIteration(subscribeEach(feedKit.public.getEvidenceSubscriber()), {
225
+ updateState(evidence) {
226
+ try {
227
+ void advancer.handleTransactionEvent(evidence);
228
+ } catch (err) {
229
+ trace('🚨 Error handling transaction event', err);
230
+ }
231
+ },
232
+ });
233
+
210
234
  return harden({ creatorFacet, publicFacet });
211
235
  };
212
236
  harden(contract);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @import {Orchestrator, OrchestrationFlow} from '@agoric/orchestration';
3
+ */
4
+
5
+ /**
6
+ * @satisfies {OrchestrationFlow}
7
+ * @param {Orchestrator} orch
8
+ */
9
+ export const makeLocalAccount = async orch => {
10
+ const agoricChain = await orch.getChain('agoric');
11
+ return agoricChain.makeAccount();
12
+ };
13
+ harden(makeLocalAccount);