-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0x3f9f7e13a91e0098b723946abd69b87e1e8ae23a
696 lines (621 loc) · 19.5 KB
/
0x3f9f7e13a91e0098b723946abd69b87e1e8ae23a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
export interface ExampleConfig {
env: Environment
rpc: {
local: string
mainnet: string
}
wallet: {
address: string
privateKey: string
}
tokens: {
in: Token
amountIn: number
out: Token
poolFee: number
}
}
export const CurrentConfig: ExampleConfig = {
env: Environment.LOCAL,
rpc: {
local: 'http://localhost:8545',
mainnet: '',
},
wallet: {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
privateKey:
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
},
tokens: {
in: WETH_TOKEN,
amountIn: 1,
out: USDC_TOKEN,
poolFee: FeeAmount.MEDIUM,
},
}
export const CurrentConfig: ExampleConfig = {
env: Environment.WALLET_EXTENSION,
rpc: {
local: 'http://localhost:8545',
},
wallet: {
...
},
tokens: {
...
},
}
async function getPoolInfo() {
const [token0, token1, fee, liquidity, slot0] =
await Promise.all([
poolContract.fee(),
poolContract.liquidity(),
poolContract.slot0(),
])
return {
fee,
liquidity,
sqrtPriceX96: slot0[0],
tick: slot0[1],
}
}
const poolInfo = await getPoolInfo()
const pool = new Pool(
CurrentConfig.tokens.in,
CurrentConfig.tokens.out,
CurrentConfig.tokens.poolFee,
poolInfo.sqrtPriceX96.toString(),
poolInfo.liquidity.toString(),
poolInfo.tick
)
- PoolA: USDC/ WETH
- PoolB: USDT/ WETH
- PoolC: USDT/ DAI
PoolA -> PoolB -> PoolC
import { Route } from '@uniswap/v3-sdk'
const swapRoute = new Route(
[pool],
CurrentConfig.tokens.in,
CurrentConfig.tokens.out
)
const amountOut = await getOutputQuote(swapRoute)
import { SwapQuoter } from '@uniswap/v3-sdk'
import { CurrencyAmount, TradeType } from '@uniswap/sdk-core'
const { calldata } = await SwapQuoter.quoteCallParameters(
swapRoute,
CurrencyAmount.fromRawAmount(
CurrentConfig.tokens.in,
fromReadableAmount(
CurrentConfig.tokens.amountIn,
CurrentConfig.tokens.in.decimals
)
),
TradeType.EXACT_INPUT,
{
useQuoterV2: true,
}
)
const quoteCallReturnData = await provider.call({
to: QUOTER_CONTRACT_ADDRESS,
data: calldata,
})
return ethers.utils.defaultAbiCoder.decode(['uint256'], quoteCallReturnData)import { Trade } from 'uniswap/v3-sdk'
import { CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
const uncheckedTrade = Trade.createUncheckedTrade({
route: swapRoute,
inputAmount: CurrencyAmount.fromRawAmount(
CurrentConfig.tokens.in,
fromReadableAmount(
CurrentConfig.tokens.amountIn,
CurrentConfig.tokens.in.decimals
)
),
outputAmount: CurrencyAmount.fromRawAmount(
CurrentConfig.tokens.out,
JSBI.BigInt(amountOut)
),
tradeType: TradeType.EXACT_INPUT,
})const tokenApproval = await getTokenTransferApproval(CurrentConfig.tokens.in)import { SwapOptions } from '@uniswap/v3-sdk'
import { Percent } from '@uniswap/sdk-core'
const options: SwapOptions = {
slippageTolerance: new Percent(50, 10_000), // 50 bips, or 0.50%
deadline: Math.floor(Date.now() / 1000) + 60 * 20, // 20 minutes from the current Unix time
recipient: walletAddress,
}
import { SwapRouter } from '@uniswap/v3-sdk'
const methodParameters = SwapRouter.swapCallParameters([uncheckedTrade], options)const tx = {
data: methodParameters.calldata,
to: SWAP_ROUTER_ADDRESS,
value: methodParameters.value,
from: walletAddress,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}
const res = await wallet.sendTransaction(tx)
import { Token } from '@uniswap/sdk-core'
interface ExampleConfig {
env: Environment
rpc: {
local: string
mainnet: string
}
wallet: {
address: string
privateKey: string
}
tokens: {
in: Token
amountIn: number
out: Token
}
}
export const CurrentConfig: ExampleConfig = {...}
import { AlphaRouter, ChainId } from '@uniswap/smart-order-router'
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const router = new AlphaRouter({
chainId: ChainId.MAINNET,
provider,
})import { SwapOptionsSwapRouter02, SwapType } from '@uniswap/smart-order-router'
import { Percent } from '@uniswap/sdk-core'
const options: SwapOptionsSwapRouter02 = {
recipient: CurrentConfig.wallet.address,
slippageTolerance: new Percent(50, 10_000),
deadline: Math.floor(Date.now() / 1000 + 1800),
type: SwapType.SWAP_ROUTER_02,
}import { CurrencyAmount, TradeType } from '@uniswap/sdk-core'
const rawTokenAmountIn: JSBI = fromReadableAmount(
CurrentConfig.currencies.amountIn,
CurrentConfig.currencies.in.decimals
)
const route = await router.route(
CurrencyAmount.fromRawAmount(
CurrentConfig.currencies.in,
rawTokenAmountIn
),
CurrentConfig.currencies.out,
TradeType.EXACT_INPUT,
options
)export function fromReadableAmount(amount: number, decimals: number): JSBI {
const extraDigits = Math.pow(10, countDecimals(amount))
const adjustedAmount = amount * extraDigits
return JSBI.divide(
JSBI.multiply(
JSBI.BigInt(adjustedAmount),
JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(decimals))
),
JSBI.BigInt(extraDigits)
)
}if (!route || !route.methodParameters) {
// Handle failed request
}import { ethers } from 'ethers'
...
const wallet = new ethers.Wallet(privateKey, provider)
const tokenContract = new ethers.Contract(
CurrentConfig.tokens.in.address,
ERC20ABI,
wallet
)
const tokenApproval = await tokenContract.approve(
V3_SWAP_ROUTER_ADDRESS,
ethers.BigNumber.from(rawTokenAmountIn.toString())
)const txRes = await wallet.sendTransaction({
data: route.methodParameters.calldata,
to: V3_SWAP_ROUTER_ADDRESS,
value: route.methodParameters.value,
from: wallet.address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
})import { Pool, Position } from '@uniswap/v3-sdk'
import JSBI from 'jsbi'
const pool = new Pool(...)
const tickLower: number = -100
const tickUpper: number = 200
const liquidity: JSBI = JSBI.BigInt('1000000000000000000')
const position = new Position({
pool,
liquidity,
tickLower,
tickUpper
})import { BigIntish } from '@uniswap/sdk-core'
const pool = new Pool(...)
const tickLower: number = -100
const tickUpper: number = 200
const amount0: BigIntish = '1000000000000000000'
const amount1: BigIntish = JSBI.BigInt('1000000000000000000')
const useFullPrecision: boolean = true
const position = Position.fromAmounts({
pool,
tickLower,
tickUpper,
amount0,
amount1,
useFullPrecision
})import { BigIntish } from '@uniswap/sdk-core'
...
const pool = new Pool(...)
const tickLower: number = -200
const tickUpper: number = 100
const amount0: BigIntish = '1000000000000000000'
const useFullPrecision: boolean = true
const singleSidePositionToken0 = Position.fromAmount0({
pool,
tickLower,
tickUpper,
amount0,
useFullPrecision
})
const amount1: BigIntish = 100000000
const singleSidePositionToken1 = Position.fromAmount1({
pool,
tickLower,
tickUpper,
amount1,
useFullPrecision
})import { MintOptions, NonfungiblePositionManager } from '@uniswap/v3-sdk'
const mintOptions: MintOptions = {
recipient: address,
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
slippageTolerance: new Percent(50, 10_000),
}
// get calldata for minting a position
const { calldata, value } = NonfungiblePositionManager.addCallParameters(
positionToMint,
mintOptions
)const { calldata, value } = NonfungiblePositionManager.removeCallParameters(
currentPosition,
removeLiquidityOptions
)const { calldata, value } =
NonfungiblePositionManager.collectCallParameters(collectOptions)const token0Approval = await getTokenTransferApproval(
token0Address,
amount0
)
const token1Approval = await getTokenTransferApproval(
token1Address,
amount1
)import { ethers, BigNumber } from 'ethers'
async function getTokenTransferApproval(address: string, amount: BigNumber) {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const tokenContract = new ethers.Contract(
token.address,
ERC20_ABI,
provider
)
return tokenContract.approve(
NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
amount
)
}import { computePoolAddress, FeeAmount } from '@uniswap/v3-sdk'
import { Token } from '@uniswap/sdk-core'
const token0: Token = ...
const token1: Token = ...
const fee: FeeAmount = ...
const POOL_FACTORY_CONTRACT_ADDRESS: string = ...
const currentPoolAddress = computePoolAddress({
factoryAddress: POOL_FACTORY_CONTRACT_ADDRESS,
tokenA: token0,
tokenB: token1,
fee: poolFee,
})import IUniswapV3PoolABI from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json'
const poolContract = new ethers.Contract(
currentPoolAddress,
IUniswapV3PoolABI.abi,
provider
)
const [liquidity, slot0] =
await Promise.all([
poolContract.liquidity(),
poolContract.slot0(),
])import { Pool } from '@uniswap/v3-sdk'
const configuredPool = new Pool(
token0,
token1,
poolFee,
slot0.sqrtPriceX96.toString(),
liquidity.toString(),
slot0.tick
)import { Position } from '@uniswap/v3-sdk'
import { BigIntish } from '@uniswap/sdk-core'
// The maximum token amounts we want to provide. BigIntish accepts number, string or JSBI
const amount0: BigIntish = ...
const amount1: BigIntish = ...
const position = Position.fromAmounts({
pool: configuredPool,
tickLower:
nearestUsableTick(configuredPool.tickCurrent, configuredPool.tickSpacing) -
configuredPool.tickSpacing * 2,
tickUpper:
nearestUsableTick(configuredPool.tick, configuredPool.tickSpacing) +
configuredPool.tickSpacing * 2,
amount0: amount0,
amount1: amount1,
useFullPrecision: true,
})import { MintOptions, NonfungiblePositionManager } from '@uniswap/v3-sdk'
import { Percent } from '@uniswap/sdk-core'
const mintOptions: MintOptions = {
recipient: address,
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
slippageTolerance: new Percent(50, 10_000),
}
// get calldata for minting a position
const { calldata, value } = NonfungiblePositionManager.addCallParameters(
position,
mintOptions
)const transaction = {
data: calldata,
to: NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
value: value,
from: address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}const wallet = new ethers.Wallet(privateKey, provider)
const txRes = await wallet.sendTransaction(transaction)import { ethers } from 'ethers'
import INONFUNGIBLE_POSITION_MANAGER from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const nfpmContract = new ethers.Contract(
NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
INONFUNGIBLE_POSITION_MANAGER.abi,
provider
)
const numPositions = await nfpmContract.balanceOf(address)const calls = []
for (let i = 0; i < numPositions; i++) {
calls.push(
nfpmContract.tokenOfOwnerByIndex(address, i)
)
}
const positionIds = await Promise.all(calls)function positions(
uint256 tokenId
) external view returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
)interface PositionInfo {
tickLower: number
tickUpper: number
liquidity: JSBI
feeGrowthInside0LastX128: JSBI
feeGrowthInside1LastX128: JSBI
tokensOwed0: JSBI
tokensOwed1: JSBI
}const positionCalls = []
for (let id of positionIds) {
positionCalls.push(
nfpmContract.positions(id)
)
}
const callResponses = await Promise.all(positionCalls)const positionInfos = callResponses.map((position) => {
return {
tickLower: position.tickLower,
tickUpper: position.tickUpper,
liquidity: JSBI.BigInt(position.liquidity),
feeGrowthInside0LastX128: JSBI.BigInt(position.feeGrowthInside0LastX128),
feeGrowthInside1LastX128: JSBI.BigInt(position.feeGrowthInside1LastX128),
tokensOwed0: JSBI.BigInt(position.tokensOwed0),
tokensOwed1: JSBI.BigInt(position.tokensOwed1),
}
})const positionInfos = callResponses.map((position) => {
return {
tickLower: position.tickLower,
tickUpper: position.tickUpper,
liquidity: JSBI.BigInt(position.liquidity),
feeGrowthInside0LastX128: JSBI.BigInt(position.feeGrowthInside0LastX128),
feeGrowthInside1LastX128: JSBI.BigInt(position.feeGrowthInside1LastX128),
tokensOwed0: JSBI.BigInt(position.tokensOwed0),
tokensOwed1: JSBI.BigInt(position.tokensOwed1),
}
})
const numPositions = await nfpmContract.balanceOf(address)const calls = []
for (let i = 0; i < numPositions; i++) {
calls.push(
nfpmContract.tokenOfOwnerByIndex(address, i)
)
}
const positionIds = await Promise.all(calls)const calls = []
for (let i = 0; i < numPositions; i++) {
calls.push(
nfpmContract.tokenOfOwnerByIndex(address, i)
)
}
const positionIds = await Promise.all(calls)interface PositionInfo {
tickLower: number
tickUpper: number
liquidity: JSBI
feeGrowthInside0LastX128: JSBI
feeGrowthInside1LastX128: JSBI
tokensOwed0: JSBI
tokensOwed1: JSBI
}const positionCalls = []
for (let id of positionIds) {
positionCalls.push(
nfpmContract.positions(id)
)
}
const callResponses = await Promise.all(positionCalls)const positionInfos = callResponses.map((position) => {
return {
tickLower: position.tickLower,
tickUpper: position.tickUpper,
liquidity: JSBI.BigInt(position.liquidity),
feeGrowthInside0LastX128: JSBI.BigInt(position.feeGrowthInside0LastX128),
feeGrowthInside1LastX128: JSBI.BigInt(position.feeGrowthInside1LastX128),
tokensOwed0: JSBI.BigInt(position.tokensOwed0),
tokensOwed1: JSBI.BigInt(position.tokensOwed1),
}
})export const CurrentConfig: ExampleConfig = {
env: Environment.LOCAL,
rpc: {
local: 'http://localhost:8545',
mainnet: 'https://mainnet.infura.io/v3/0ac57a06f2994538829c14745750d721',
},
wallet: {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
privateKey:
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
},
tokens: {
token0: USDC_TOKEN,
token0Amount: 1000,
token1: DAI_TOKEN,
token1Amount: 1000,
poolFee: FeeAmount.LOW,
fractionToRemove: 1,
fractionToAdd: 0.5,
},
}const fractionToAdd: number = ...
const amount0Increased: JSBI = fromReadableAmount(
readableAmount0 * fractionToAdd,
token0.decimals
)
const amount1Increase: JSBI = fromReadableAmount(
readableAmount1 * fractionToAdd,
token1.decimals
)
const positionToIncreaseBy = constructPosition(
amount0Increased,
amount1Increase
)
)import { Pool, Position } from '@uniswap/v3-sdk'
import JSBI from 'jsbi'
function constructPosition(
amount0: JSBI,
amount1: JSBI
): Position {
// create Pool same as in the previous guide
const pool = new Pool(...)
// create position using the maximum liquidity from input amounts
return Position.fromAmounts({
pool,
tickLower:
nearestUsableTick(pool.tickCurrent, pool.tickSpacing) -
pool.tickSpacing * 2,
tickUpper:
nearestUsableTick(pool.tickCurrent, pool.tickSpacing) +
pool.tickSpacing * 2,
amount0,
amount1,
useFullPrecision: true,
})
}import { AddLiquidityOptions } from '@uniswap/v3-sdk'
const addLiquidityOptions: AddLiquidityOptions = {
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
slippageTolerance: new Percent(50, 10_000),
tokenId,
}import { NonfungiblePositionManager } from '@uniswap/v3-sdk'
const positionToIncreaseBy = constructPosition(CurrentConfig.tokens.amount0, CurrentConfig.tokens.amount1)
const { calldata, value } = NonfungiblePositionManager.addCallParameters(
positionToIncreaseBy,
addLiquidityOptions
)import { ethers } from 'ethers'
const transaction = {
data: calldata,
to: NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
value: value,
from: address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}
const wallet = new ethers.Wallet(privateKey, provider)
const txRes = await wallet.sendTransaction(transaction)import { ethers } from 'ethers'
const transaction = {
data: calldata,
to: NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
value: value,
from: address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}
const wallet = new ethers.Wallet(privateKey, provider)
const txRes = await wallet.sendTransaction(transaction)const amount0: JSBI = fromReadableAmount(
readableAmount0 * fractionToAdd,
token0.decimals
)
const amount1: JSBI = fromReadableAmount(
readableAmount1 * fractionToAdd,
token1.decimals
)
const currentPosition = constructPosition(
amount0,
amount1
)import { RemoveLiquidityOptions } from '@uniswap/v3-sdk'
import { Percent } from '@uniswap/sdk-core'
const removeLiquidityOptions: RemoveLiquidityOptions = {
deadline: Math.floor(Date.now() / 1000) + 60 * 20,
slippageTolerance: new Percent(50, 10_000),
tokenId: positionId,
// percentage of liquidity to remove
liquidityPercentage: new Percent(0.5),
collectOptions,
}import { CurrencyAmount } from '@uniswap/sdk-core'
import { CollectOptions } from '@uniswap/v3-sdk'
const collectOptions: Omit<CollectOptions, 'tokenId'> = {
expectedCurrencyOwed0: CurrencyAmount.fromRawAmount(
token0,
0
),
expectedCurrencyOwed1: CurrencyAmount.fromRawAmount(
token1,
0
),
recipient: address,
}const { calldata, value } = NonfungiblePositionManager.removeCallParameters(
currentPosition,
removeLiquidityOptions
)const transaction = {
data: calldata,
to: NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
value: value,
from: address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}
const txRes = await wallet.sendTransaction(transaction)import { ethers } from 'ethers'
import JSBI from 'jsbi'
...
const nfpmContract = new ethers.Contract(NONFUNGIBLE_POSITION_MANAGER_ADDRESS, provider)
const position = nfpmContract.positions(positionId)import { CurrencyAmount } from '@uniswap/sdk-core'
const collectOptions: CollectOptions = {
tokenId: positionId,
expectedCurrencyOwed0: CurrencyAmount.fromRawAmount(
CurrentConfig.tokens.token0,
JSBI.BigInt(position.tokensOwed0)
),
expectedCurrencyOwed1: CurrencyAmount.fromRawAmount(
CurrentConfig.tokens.token1,
JSBI.BigInt(position.tokensOwed1)
),
recipient: address,
}const positionInfos = callResponses.map((position) => {
return {
tickLower: position.tickLower,
tickUpper: position.tickUpper,
liquidity: JSBI.BigInt(position.liquidity),
feeGrowthInside0LastX128: JSBI.BigInt(position.feeGrowthInside0LastX128),
feeGrowthInside1LastX128: JSBI.BigInt(position.feeGrowthInside1LastX128),
tokensOwed0: JSBI.BigInt(position.tokensOwed0),
tokensOwed1: JSBI.BigInt(position.tokensOwed1),
}
})const { calldata, value } =
NonfungiblePositionManager.collectCallParameters(collectOptions)const transaction = {
data: calldata,
to: NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS,
value: value,
from: address,
maxFeePerGas: MAX_FEE_PER_GAS,
maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS,
}
const txRes = await wallet.sendTransaction(transaction)const tokenInApproval = await getTokenTransferApproval(
token0,
V3_SWAP_ROUTER_ADDRESS
)
const tokenOutApproval = await getTokenTransferApproval(
token1,
V3_SWAP_ROUTER_ADDRESS
)