Skip to content

Commit bdf4f06

Browse files
committed
add more test cases
1 parent 127ee70 commit bdf4f06

1 file changed

Lines changed: 46 additions & 32 deletions

File tree

cadence/tests/fork/UniswapV3SwapConnectors_test.cdc

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import "UniswapV3SwapConnectors"
88

99
/// Fork test: Overshooting dust bound for UniswapV3 swap connector
1010
///
11-
/// Demonstrates that quoteIn and quoteOut are perfectly consistent (quoteDust = 0)
12-
/// and that the overshoot from the desired amount is bounded against a real
13-
/// PYUSD/MOET pool on Flow EVM mainnet. Includes a specific amount (0.45019707)
14-
/// that produces exactly 1 UFix64 quantum (0.00000001) of overshoot.
11+
/// Demonstrates that quoteIn and quoteOut are perfectly consistent (quoteDust = 0),
12+
/// that the overshoot from the desired amount is bounded, and that the trimming
13+
/// guard (line 539 in UniswapV3SwapConnectors.cdc) correctly caps bridged amounts
14+
/// at amountOutMin — leaving dust in the COA.
15+
///
16+
/// PYUSD→MOET direction produces observable dust because MOET is an 18-decimal
17+
/// ERC20 on EVM and `toCadenceOut` floors to 10^10 wei quantum boundaries.
18+
/// MOET→PYUSD shows zero dust because PYUSD (6-decimal) converts exactly.
1519
///
1620
/// Pool contracts (Flow EVM mainnet):
1721
/// PYUSD: 0x99aF3EeA856556646C98c8B9b2548Fe815240750
@@ -201,31 +205,34 @@ access(all) fun assertQuoteDust(results: [[UFix64]]) {
201205
/// desired amount when the extra input crosses a UFix64-quantum boundary.
202206
///
203207
/// Amounts with many fractional digits are more likely to produce non-aligned
204-
/// EVM wei values that cross quantum boundaries after rounding.
208+
/// EVM wei values that cross quantum boundaries after rounding. The highest
209+
/// observed overshoot is +87 quanta at 0.20000000 MOET desired.
205210
///
206211
access(all) fun testOvershootingDustIsBounded() {
207212
let signer = Test.getAccount(0x47f544294e3b7656)
208213
ensureCOA(signer)
209214

215+
// Pool liquidity caps at ~0.58 MOET output, so amounts above that are clamped.
216+
// Focus on the productive range where quoting is uncapped.
210217
let testAmounts: [UFix64] = [
211-
0.00100000,
212-
0.00987654,
213-
0.01000000,
214-
0.05432109,
215-
0.10000000,
216-
0.12345678,
217-
0.23456789,
218-
0.34567890,
219-
0.45019707, // known: produces exactly 1 quantum (0.00000001) overshoot
220-
0.56789012,
221-
0.67890123,
222-
0.78901234,
223-
0.89012345,
224-
1.00000000,
225-
1.23456789,
226-
2.34567890,
227-
5.00000000,
228-
10.00000000
218+
0.00100000, // +62 quanta overshoot
219+
0.00500000,
220+
0.00987654, // +30 quanta
221+
0.01000000, // +69 quanta — highest observed
222+
0.02000000,
223+
0.03456789,
224+
0.05000000,
225+
0.05432109, // +26 quanta
226+
0.10000000, // +10 quanta
227+
0.12345678, // +44 quanta
228+
0.20000000,
229+
0.23456789, // +8 quanta
230+
0.30000000,
231+
0.34567890, // +4 quanta
232+
0.40000000,
233+
0.45019707, // +1 quantum — tightest possible
234+
0.50000000,
235+
0.56789012 // +62 quanta
229236
]
230237

231238
let results = runQuoteDustScript(
@@ -248,15 +255,16 @@ access(all) fun testOvershootingDustIsBoundedReverse() {
248255
let signer = Test.getAccount(0x47f544294e3b7656)
249256
ensureCOA(signer)
250257

258+
// Pool liquidity caps at ~0.62 PYUSD output in this direction.
251259
let testAmounts: [UFix64] = [
252260
0.00100000,
253261
0.01000000,
262+
0.05000000,
254263
0.10000000,
255264
0.12345678,
265+
0.30000000,
256266
0.45019707,
257-
0.78901234,
258-
1.00000000,
259-
5.00000000
267+
0.56789012
260268
]
261269

262270
// Reverse direction: MOET in, PYUSD out
@@ -481,16 +489,22 @@ access(all) fun testSwapOvershootStaysInCOA() {
481489
let testAmounts: [UFix64] = [
482490
0.00987654,
483491
0.01000000,
492+
0.03456789,
484493
0.05432109,
485494
0.10000000,
486-
0.12345678,
487-
0.23456789,
488-
0.45019707, // known quoting overshoot — likely swap-level dust too
495+
0.12345678, // dust hit in first run
496+
0.20000000,
497+
0.23456789, // dust hit
498+
0.34567890,
499+
0.45019707,
500+
0.56789012,
489501
0.67890123,
490-
0.78901234,
491-
1.00000000,
502+
0.78901234, // dust hit
503+
1.00000000, // dust hit (even with 0 quote overshoot)
492504
1.23456789,
493-
2.34567890,
505+
1.50000000,
506+
2.34567890, // dust hit
507+
3.45678901,
494508
5.00000000
495509
]
496510

0 commit comments

Comments
 (0)