1
- import { AmountMath , AmountShape } from '@agoric/ertp' ;
1
+ import { AmountMath } from '@agoric/ertp' ;
2
2
import { assertAllDefined , makeTracer } from '@agoric/internal' ;
3
- import { ChainAddressShape } from '@agoric/orchestration' ;
3
+ import { AnyNatAmountShape , ChainAddressShape } from '@agoric/orchestration' ;
4
4
import { pickFacet } from '@agoric/vat-data' ;
5
5
import { VowShape } from '@agoric/vow' ;
6
6
import { q } from '@endo/errors' ;
@@ -16,6 +16,7 @@ import { makeFeeTools } from '../utils/fees.js';
16
16
17
17
/**
18
18
* @import {HostInterface} from '@agoric/async-flow';
19
+ * @import {TypedPattern} from '@agoric/internal'
19
20
* @import {NatAmount} from '@agoric/ertp';
20
21
* @import {ChainAddress, ChainHub, Denom, OrchestrationAccount} from '@agoric/orchestration';
21
22
* @import {ZoeTools} from '@agoric/orchestration/src/utils/zoe-tools.js';
@@ -39,47 +40,40 @@ import { makeFeeTools } from '../utils/fees.js';
39
40
* }} AdvancerKitPowers
40
41
*/
41
42
43
+ /** @type {TypedPattern<AdvancerVowCtx> } */
44
+ const AdvancerVowCtxShape = M . splitRecord (
45
+ {
46
+ fullAmount : AnyNatAmountShape ,
47
+ advanceAmount : AnyNatAmountShape ,
48
+ destination : ChainAddressShape ,
49
+ forwardingAddress : M . string ( ) ,
50
+ txHash : EvmHashShape ,
51
+ } ,
52
+ { tmpSeat : M . remotable ( ) } ,
53
+ ) ;
54
+
42
55
/** type guards internal to the AdvancerKit */
43
56
const AdvancerKitI = harden ( {
44
57
advancer : M . interface ( 'AdvancerI' , {
45
58
handleTransactionEvent : M . callWhen ( CctpTxEvidenceShape ) . returns ( ) ,
46
59
} ) ,
47
60
depositHandler : M . interface ( 'DepositHandlerI' , {
48
- onFulfilled : M . call ( M . undefined ( ) , {
49
- amount : AmountShape ,
50
- destination : ChainAddressShape ,
51
- forwardingAddress : M . string ( ) ,
52
- tmpSeat : M . remotable ( ) ,
53
- txHash : EvmHashShape ,
54
- } ) . returns ( VowShape ) ,
55
- onRejected : M . call ( M . error ( ) , {
56
- amount : AmountShape ,
57
- destination : ChainAddressShape ,
58
- forwardingAddress : M . string ( ) ,
59
- tmpSeat : M . remotable ( ) ,
60
- txHash : EvmHashShape ,
61
- } ) . returns ( ) ,
61
+ onFulfilled : M . call ( M . undefined ( ) , AdvancerVowCtxShape ) . returns ( VowShape ) ,
62
+ onRejected : M . call ( M . error ( ) , AdvancerVowCtxShape ) . returns ( ) ,
62
63
} ) ,
63
64
transferHandler : M . interface ( 'TransferHandlerI' , {
64
65
// TODO confirm undefined, and not bigint (sequence)
65
- onFulfilled : M . call ( M . undefined ( ) , {
66
- amount : AmountShape ,
67
- destination : ChainAddressShape ,
68
- forwardingAddress : M . string ( ) ,
69
- txHash : EvmHashShape ,
70
- } ) . returns ( M . undefined ( ) ) ,
71
- onRejected : M . call ( M . error ( ) , {
72
- amount : AmountShape ,
73
- destination : ChainAddressShape ,
74
- forwardingAddress : M . string ( ) ,
75
- txHash : EvmHashShape ,
76
- } ) . returns ( M . undefined ( ) ) ,
66
+ onFulfilled : M . call ( M . undefined ( ) , AdvancerVowCtxShape ) . returns (
67
+ M . undefined ( ) ,
68
+ ) ,
69
+ onRejected : M . call ( M . error ( ) , AdvancerVowCtxShape ) . returns ( M . undefined ( ) ) ,
77
70
} ) ,
78
71
} ) ;
79
72
80
73
/**
81
74
* @typedef {{
82
- * amount: NatAmount;
75
+ * fullAmount: NatAmount;
76
+ * advanceAmount: NatAmount;
83
77
* destination: ChainAddress;
84
78
* forwardingAddress: NobleAddress;
85
79
* txHash: EvmHash;
@@ -155,9 +149,9 @@ export const prepareAdvancerKit = (
155
149
// throws if the bech32 prefix is not found
156
150
const destination = chainHub . makeChainAddress ( EUD ) ;
157
151
158
- const requestedAmount = toAmount ( evidence . tx . amount ) ;
152
+ const fullAmount = toAmount ( evidence . tx . amount ) ;
159
153
// throws if requested does not exceed fees
160
- const advanceAmount = feeTools . calculateAdvance ( requestedAmount ) ;
154
+ const advanceAmount = feeTools . calculateAdvance ( fullAmount ) ;
161
155
162
156
const { zcfSeat : tmpSeat } = zcf . makeEmptySeatKit ( ) ;
163
157
const amountKWR = harden ( { USDC : advanceAmount } ) ;
@@ -174,7 +168,8 @@ export const prepareAdvancerKit = (
174
168
amountKWR ,
175
169
) ;
176
170
void watch ( depositV , this . facets . depositHandler , {
177
- amount : advanceAmount ,
171
+ fullAmount,
172
+ advanceAmount,
178
173
destination,
179
174
forwardingAddress : evidence . tx . forwardingAddress ,
180
175
tmpSeat,
@@ -193,16 +188,15 @@ export const prepareAdvancerKit = (
193
188
*/
194
189
onFulfilled ( result , ctx ) {
195
190
const { poolAccount } = this . state ;
196
- const { amount , destination, forwardingAddress , txHash } = ctx ;
191
+ const { destination, advanceAmount , ... detail } = ctx ;
197
192
const transferV = E ( poolAccount ) . transfer ( destination , {
198
193
denom : usdc . denom ,
199
- value : amount . value ,
194
+ value : advanceAmount . value ,
200
195
} ) ;
201
196
return watch ( transferV , this . facets . transferHandler , {
202
197
destination,
203
- amount,
204
- forwardingAddress,
205
- txHash,
198
+ advanceAmount,
199
+ ...detail ,
206
200
} ) ;
207
201
} ,
208
202
/**
@@ -222,39 +216,32 @@ export const prepareAdvancerKit = (
222
216
} ,
223
217
transferHandler : {
224
218
/**
225
- * @param {undefined } result TODO confirm this is not a bigint (sequence)
219
+ * @param {unknown } result TODO confirm this is not a bigint (sequence)
226
220
* @param {AdvancerVowCtx } ctx
227
221
*/
228
222
onFulfilled ( result , ctx ) {
229
223
const { notifyFacet } = this . state ;
230
- const { amount , destination, forwardingAddress , txHash } = ctx ;
224
+ const { advanceAmount , destination, ... detail } = ctx ;
231
225
log (
232
226
'Advance transfer fulfilled' ,
233
- q ( { amount, destination, result } ) . toString ( ) ,
234
- ) ;
235
- notifyFacet . notifyAdvancingResult (
236
- txHash ,
237
- forwardingAddress ,
238
- amount . value ,
239
- destination . value ,
240
- true ,
227
+ q ( { advanceAmount, destination, result } ) . toString ( ) ,
241
228
) ;
229
+ // During development, due to a bug, this call threw.
230
+ // The failure was silent (no diagnostics) due to:
231
+ // - #10576 Vows do not report unhandled rejections
232
+ // For now, the advancer kit relies on consistency between
233
+ // notifyFacet, statusManager, and callers of handleTransactionEvent().
234
+ // TODO: revisit #10576 during #10510
235
+ notifyFacet . notifyAdvancingResult ( { destination, ...detail } , true ) ;
242
236
} ,
243
237
/**
244
238
* @param {Error } error
245
239
* @param {AdvancerVowCtx } ctx
246
240
*/
247
241
onRejected ( error , ctx ) {
248
242
const { notifyFacet } = this . state ;
249
- const { amount, destination, forwardingAddress, txHash } = ctx ;
250
243
log ( 'Advance transfer rejected' , q ( error ) . toString ( ) ) ;
251
- notifyFacet . notifyAdvancingResult (
252
- txHash ,
253
- forwardingAddress ,
254
- amount . value ,
255
- destination . value ,
256
- false ,
257
- ) ;
244
+ notifyFacet . notifyAdvancingResult ( ctx , false ) ;
258
245
} ,
259
246
} ,
260
247
} ,
0 commit comments