@@ -8,6 +8,7 @@ import { E } from '@endo/far';
8
8
import { M } from '@endo/patterns' ;
9
9
import { CctpTxEvidenceShape , EudParamShape } from '../typeGuards.js' ;
10
10
import { addressTools } from '../utils/address.js' ;
11
+ import { makeFeeTools } from '../utils/fees.js' ;
11
12
12
13
const { isGTE } = AmountMath ;
13
14
@@ -17,7 +18,7 @@ const { isGTE } = AmountMath;
17
18
* @import {ChainAddress, ChainHub, Denom, DenomAmount, OrchestrationAccount} from '@agoric/orchestration';
18
19
* @import {VowTools} from '@agoric/vow';
19
20
* @import {Zone} from '@agoric/zone';
20
- * @import {CctpTxEvidence, LogFn} from '../types.js';
21
+ * @import {CctpTxEvidence, FeeConfig, LogFn} from '../types.js';
21
22
* @import {StatusManager} from './status-manager.js';
22
23
*/
23
24
@@ -34,6 +35,7 @@ const { isGTE } = AmountMath;
34
35
/**
35
36
* @typedef {{
36
37
* chainHub: ChainHub;
38
+ * feeConfig: FeeConfig;
37
39
* log: LogFn;
38
40
* statusManager: StatusManager;
39
41
* usdc: { brand: Brand<'nat'>; denom: Denom; };
@@ -75,15 +77,16 @@ const AdvancerKitI = harden({
75
77
*/
76
78
export const prepareAdvancerKit = (
77
79
zone ,
78
- { chainHub, log, statusManager, usdc, vowTools : { watch, when } } ,
80
+ { chainHub, feeConfig , log, statusManager, usdc, vowTools : { watch, when } } ,
79
81
) => {
80
82
assertAllDefined ( {
81
83
chainHub,
84
+ feeConfig,
82
85
statusManager,
83
86
watch,
84
87
when,
85
88
} ) ;
86
-
89
+ const feeTools = makeFeeTools ( usdc . brand , feeConfig ) ;
87
90
/** @param {bigint } value */
88
91
const toAmount = value => AmountMath . make ( usdc . brand , value ) ;
89
92
@@ -123,14 +126,17 @@ export const prepareAdvancerKit = (
123
126
// this will throw if the bech32 prefix is not found, but is handled by the catch
124
127
const destination = chainHub . makeChainAddress ( EUD ) ;
125
128
const requestedAmount = toAmount ( evidence . tx . amount ) ;
129
+ const advanceAmount = feeTools . calculateAdvance ( requestedAmount ) ;
126
130
127
131
// TODO: consider skipping and using `borrow()`s internal balance check
128
132
const poolBalance = assetManagerFacet . lookupBalance ( ) ;
129
133
if ( ! isGTE ( poolBalance , requestedAmount ) ) {
130
134
log (
131
135
`Insufficient pool funds` ,
132
- `Requested ${ q ( requestedAmount ) } but only have ${ q ( poolBalance ) } ` ,
136
+ `Requested ${ q ( advanceAmount ) } but only have ${ q ( poolBalance ) } ` ,
133
137
) ;
138
+ // report `requestedAmount`, not `advancedAmount`... do we need to
139
+ // communicate net to `StatusManger` in case fees change in between?
134
140
statusManager . observe ( evidence ) ;
135
141
return ;
136
142
}
@@ -147,7 +153,7 @@ export const prepareAdvancerKit = (
147
153
}
148
154
149
155
try {
150
- const payment = await assetManagerFacet . borrow ( requestedAmount ) ;
156
+ const payment = await assetManagerFacet . borrow ( advanceAmount ) ;
151
157
const depositV = E ( poolAccount ) . deposit ( payment ) ;
152
158
void watch ( depositV , this . facets . depositHandler , {
153
159
destination,
0 commit comments