@@ -114,73 +114,76 @@ export class StrategyCombinedUniswap {
114
114
shouldContinue ,
115
115
) ) as SwapApiResponse [ ]
116
116
117
- const uniswapSwapParams = {
118
- ...swapParams ,
119
- amount : swapParams . amount - BigInt ( exactInputQuotes [ 0 ] . amountOut ) ,
120
- receiver : swapParams . from ,
121
- }
122
- const {
123
- protocol,
124
- data : path ,
125
- amountIn : uniswapAmountIn , // assuming exact out trade
126
- } = await fetchUniswapQuote ( uniswapSwapParams )
127
-
128
- result . quotes = exactInputQuotes . map ( ( exactInputQuote ) => {
129
- const uniswapSwapMulticallItem = encodeSwapMulticallItem ( {
130
- handler :
131
- protocol === "V2"
132
- ? SWAPPER_HANDLER_UNISWAP_V2
133
- : SWAPPER_HANDLER_UNISWAP_V3 ,
134
- mode : BigInt ( SwapperMode . TARGET_DEBT ) ,
135
- account : swapParams . accountOut ,
136
- tokenIn : swapParams . tokenIn . addressInfo ,
137
- tokenOut : swapParams . tokenOut . addressInfo ,
138
- vaultIn : swapParams . vaultIn ,
139
- accountIn : swapParams . accountIn ,
140
- receiver : swapParams . receiver ,
141
- amountOut : swapParams . targetDebt ,
142
- data : path as Hex ,
143
- } )
144
-
145
- const combinedMulticallItems = [
146
- ...exactInputQuote . swap . multicallItems ,
147
- uniswapSwapMulticallItem ,
148
- ]
149
-
150
- const swap = buildApiResponseSwap (
151
- swapParams . from ,
152
- combinedMulticallItems ,
153
- )
154
-
155
- const verify = buildApiResponseVerifyDebtMax (
156
- swapParams . chainId ,
157
- swapParams . receiver ,
158
- swapParams . accountOut ,
159
- swapParams . targetDebt ,
160
- swapParams . deadline ,
161
- )
162
-
163
- const amountIn =
164
- BigInt ( exactInputQuote . amountIn ) + BigInt ( uniswapAmountIn )
165
- const amountInMax = applySlippage ( amountIn , swapParams . slippage , true )
166
-
167
- return {
168
- amountIn : String ( amountIn ) ,
169
- amountInMax : String ( amountInMax ) ,
170
- amountOut : String ( swapParams . amount ) ,
171
- amountOutMin : String ( swapParams . amount ) ,
172
- vaultIn : swapParams . vaultIn ,
173
- receiver : swapParams . receiver ,
174
- accountIn : swapParams . accountIn ,
175
- accountOut : swapParams . accountOut ,
176
- tokenIn : swapParams . tokenIn ,
177
- tokenOut : swapParams . tokenOut ,
178
- slippage : swapParams . slippage ,
179
- route : [ ...exactInputQuote . route , { providerName : "Uniswap" } ] ,
180
- swap,
181
- verify,
182
- }
183
- } )
117
+ result . quotes = await Promise . all (
118
+ exactInputQuotes . map ( async ( exactInputQuote ) => {
119
+ const uniswapSwapParams = {
120
+ ...swapParams ,
121
+ amount : swapParams . amount - BigInt ( exactInputQuote . amountOutMin ) ,
122
+ receiver : swapParams . from ,
123
+ }
124
+
125
+ const {
126
+ protocol,
127
+ data : path ,
128
+ amountIn : uniswapAmountIn , // assuming exact out trade
129
+ } = await fetchUniswapQuote ( uniswapSwapParams )
130
+
131
+ const uniswapSwapMulticallItem = encodeSwapMulticallItem ( {
132
+ handler :
133
+ protocol === "V2"
134
+ ? SWAPPER_HANDLER_UNISWAP_V2
135
+ : SWAPPER_HANDLER_UNISWAP_V3 ,
136
+ mode : BigInt ( SwapperMode . TARGET_DEBT ) ,
137
+ account : swapParams . accountOut ,
138
+ tokenIn : swapParams . tokenIn . addressInfo ,
139
+ tokenOut : swapParams . tokenOut . addressInfo ,
140
+ vaultIn : swapParams . vaultIn ,
141
+ accountIn : swapParams . accountIn ,
142
+ receiver : swapParams . receiver ,
143
+ amountOut : swapParams . targetDebt ,
144
+ data : path as Hex ,
145
+ } )
146
+
147
+ const combinedMulticallItems = [
148
+ ...exactInputQuote . swap . multicallItems ,
149
+ uniswapSwapMulticallItem ,
150
+ ]
151
+
152
+ const swap = buildApiResponseSwap (
153
+ swapParams . from ,
154
+ combinedMulticallItems ,
155
+ )
156
+
157
+ const verify = buildApiResponseVerifyDebtMax (
158
+ swapParams . chainId ,
159
+ swapParams . receiver ,
160
+ swapParams . accountOut ,
161
+ swapParams . targetDebt ,
162
+ swapParams . deadline ,
163
+ )
164
+
165
+ const amountIn =
166
+ BigInt ( exactInputQuote . amountIn ) + BigInt ( uniswapAmountIn )
167
+ const amountInMax = applySlippage ( amountIn , swapParams . slippage , true )
168
+
169
+ return {
170
+ amountIn : String ( amountIn ) ,
171
+ amountInMax : String ( amountInMax ) ,
172
+ amountOut : String ( swapParams . amount ) ,
173
+ amountOutMin : String ( swapParams . amount ) ,
174
+ vaultIn : swapParams . vaultIn ,
175
+ receiver : swapParams . receiver ,
176
+ accountIn : swapParams . accountIn ,
177
+ accountOut : swapParams . accountOut ,
178
+ tokenIn : swapParams . tokenIn ,
179
+ tokenOut : swapParams . tokenOut ,
180
+ slippage : swapParams . slippage ,
181
+ route : [ ...exactInputQuote . route , { providerName : "Uniswap" } ] ,
182
+ swap,
183
+ verify,
184
+ }
185
+ } ) ,
186
+ )
184
187
} catch ( error ) {
185
188
result . error = error
186
189
}
0 commit comments