@@ -13,6 +13,10 @@ export class V3DutchOrderTrade<
13
13
> {
14
14
public readonly tradeType : TTradeType
15
15
public readonly order : UnsignedV3DutchOrder
16
+ public readonly expectedAmounts : {
17
+ expectedAmountIn : string ;
18
+ expectedAmountOut : string ;
19
+ } | undefined ;
16
20
17
21
private _inputAmount : CurrencyAmount < TInput > | undefined
18
22
private _outputAmounts : CurrencyAmount < TOutput > [ ] | undefined
@@ -25,15 +29,21 @@ export class V3DutchOrderTrade<
25
29
currenciesOut,
26
30
orderInfo,
27
31
tradeType,
32
+ expectedAmounts,
28
33
} : {
29
34
currencyIn : TInput
30
35
currenciesOut : TOutput [ ]
31
36
orderInfo : UnsignedV3DutchOrderInfo
32
37
tradeType : TTradeType
38
+ expectedAmounts ?: {
39
+ expectedAmountIn : string ;
40
+ expectedAmountOut : string ;
41
+ }
33
42
} ) {
34
43
this . _currencyIn = currencyIn
35
44
this . _currenciesOut = currenciesOut
36
45
this . tradeType = tradeType
46
+ this . expectedAmounts = expectedAmounts ;
37
47
38
48
// Assuming not cross-chain
39
49
this . order = new UnsignedV3DutchOrder ( orderInfo , currencyIn . chainId )
@@ -42,10 +52,12 @@ export class V3DutchOrderTrade<
42
52
public get inputAmount ( ) : CurrencyAmount < TInput > {
43
53
if ( this . _inputAmount ) return this . _inputAmount
44
54
45
- const amount = CurrencyAmount . fromRawAmount (
46
- this . _currencyIn ,
47
- this . order . info . input . startAmount . toString ( )
48
- )
55
+ const amount = this . expectedAmounts ?. expectedAmountIn
56
+ ? this . getExpectedAmountIn ( )
57
+ : CurrencyAmount . fromRawAmount (
58
+ this . _currencyIn ,
59
+ this . order . info . input . startAmount . toString ( )
60
+ )
49
61
this . _inputAmount = amount
50
62
return amount
51
63
}
@@ -72,7 +84,9 @@ export class V3DutchOrderTrade<
72
84
73
85
// Same assumption as V2 that there is only one non-fee output at a time, and it exists at index 0
74
86
public get outputAmount ( ) : CurrencyAmount < TOutput > {
75
- return this . outputAmounts [ 0 ] ;
87
+ return this . expectedAmounts ?. expectedAmountOut
88
+ ? this . getExpectedAmountOut ( )
89
+ : this . outputAmounts [ 0 ] ;
76
90
}
77
91
78
92
public minimumAmountOut ( ) : CurrencyAmount < TOutput > {
@@ -123,4 +137,26 @@ export class V3DutchOrderTrade<
123
137
this . minimumAmountOut ( ) . quotient
124
138
) ;
125
139
}
140
+
141
+ private getExpectedAmountIn ( ) : CurrencyAmount < TInput > {
142
+ if ( ! this . expectedAmounts ?. expectedAmountIn ) {
143
+ throw new Error ( "expectedAmountIn not set" ) ;
144
+ }
145
+
146
+ return CurrencyAmount . fromRawAmount (
147
+ this . _currencyIn ,
148
+ this . expectedAmounts . expectedAmountIn
149
+ ) ;
150
+ }
151
+
152
+ private getExpectedAmountOut ( ) : CurrencyAmount < TOutput > {
153
+ if ( ! this . expectedAmounts ?. expectedAmountOut ) {
154
+ throw new Error ( "expectedAmountOut not set" ) ;
155
+ }
156
+
157
+ return CurrencyAmount . fromRawAmount (
158
+ this . _currenciesOut [ 0 ] ,
159
+ this . expectedAmounts . expectedAmountOut
160
+ ) ;
161
+ }
126
162
}
0 commit comments