From 3fe48d0bc0b37e82ebfe29a97a81b8d46907f3a6 Mon Sep 17 00:00:00 2001 From: Florian Winkler Date: Wed, 20 Dec 2023 17:07:56 +0100 Subject: [PATCH] Update range order for sdk release version --- v3-sdk/range-order/package.json | 4 +- .../range-order/src/libs/mockMarketMaker.ts | 61 +++++++++---------- v3-sdk/range-order/src/libs/pool.ts | 12 ++-- v3-sdk/range-order/src/libs/positions.ts | 14 ++--- v3-sdk/range-order/src/libs/range-order.ts | 28 ++++----- v3-sdk/range-order/yarn.lock | 8 +-- 6 files changed, 62 insertions(+), 65 deletions(-) diff --git a/v3-sdk/range-order/package.json b/v3-sdk/range-order/package.json index eb8df5ce..4f7b6afb 100644 --- a/v3-sdk/range-order/package.json +++ b/v3-sdk/range-order/package.json @@ -1,13 +1,13 @@ { "name": "range-order", - "version": "2.0.0", + "version": "2.1.0", "private": true, "dependencies": { "@types/node": "^16.7.13", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@uniswap/sdk-core": "npm:@koraykoska/uniswap-sdk-core@^6.0.9", - "@uniswap/v3-sdk": "npm:@florian-s-a-w/uniswap-v3-sdk@3.15.17", + "@uniswap/v3-sdk": "npm:@florian-s-a-w/uniswap-v3-sdk@4.0.2", "ethers": "^5.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/v3-sdk/range-order/src/libs/mockMarketMaker.ts b/v3-sdk/range-order/src/libs/mockMarketMaker.ts index 8401d975..bd8ceae7 100644 --- a/v3-sdk/range-order/src/libs/mockMarketMaker.ts +++ b/v3-sdk/range-order/src/libs/mockMarketMaker.ts @@ -24,27 +24,26 @@ export async function buyWETH() { CurrentConfig.mockMarketMakerPool.token0.decimals ) ) - const pool = await Pool.initFromChain( - getProvider(), - CurrentConfig.tokens.token0, - CurrentConfig.tokens.token1, - CurrentConfig.tokens.poolFee - ) + const pool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: CurrentConfig.tokens.token0, + tokenB: CurrentConfig.tokens.token1, + fee: CurrentConfig.tokens.poolFee, + }) 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: CurrentConfig.mockMarketMakerWallet.address, } - console.log('Constructed Pool') - await SwapRouter.executeQuotedSwapOnPool( + await SwapRouter.executeQuotedSwapOnPool({ pool, - ethAmount, - TradeType.EXACT_OUTPUT, - options, - getMMMWallet() - ) + amount: ethAmount, + tradeType: TradeType.EXACT_OUTPUT, + swapOptions: options, + signer: getMMMWallet(), + }) return TransactionState.Sent } catch (err) { console.log(err) @@ -57,12 +56,12 @@ export async function sellWETH() { try { const ethAmount = CurrentConfig.mockMarketMakerPool.sellAmount - const pool = await Pool.initFromChain( - getProvider(), - CurrentConfig.tokens.token0, - CurrentConfig.tokens.token1, - CurrentConfig.tokens.poolFee - ) + const pool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: CurrentConfig.tokens.token0, + tokenB: CurrentConfig.tokens.token1, + fee: CurrentConfig.tokens.poolFee, + }) const swapRoute = new Route( [pool], @@ -134,17 +133,16 @@ export async function getToken1FromMockPool(sellETHAmount: number) { CurrentConfig.mockMarketMakerWallet.address, CurrentConfig.mockMarketMakerPool.token0 ) - console.log('Balance 0: ' + balance0) if (Number(balance0) < sellETHAmount) { await wrapETHMMM(sellETHAmount) } - const pool = await Pool.initFromChain( - getProvider(), - CurrentConfig.mockMarketMakerPool.token0, - CurrentConfig.mockMarketMakerPool.token1, - CurrentConfig.mockMarketMakerPool.poolFee - ) + const pool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: CurrentConfig.mockMarketMakerPool.token0, + tokenB: CurrentConfig.mockMarketMakerPool.token1, + fee: CurrentConfig.mockMarketMakerPool.poolFee, + }) const currencyAmount = CurrencyAmount.fromRawAmount( CurrentConfig.mockMarketMakerPool.token0, @@ -154,13 +152,12 @@ export async function getToken1FromMockPool(sellETHAmount: number) { ) ) - await SwapRouter.executeQuotedSwapOnPool( + await SwapRouter.executeQuotedSwapOnPool({ pool, - currencyAmount, - TradeType.EXACT_INPUT, - undefined, - getMMMWallet() - ) + amount: currencyAmount, + tradeType: TradeType.EXACT_INPUT, + signer: getMMMWallet(), + }) } function getMMMWallet(): ethers.Wallet { diff --git a/v3-sdk/range-order/src/libs/pool.ts b/v3-sdk/range-order/src/libs/pool.ts index aa494e34..a598b8db 100644 --- a/v3-sdk/range-order/src/libs/pool.ts +++ b/v3-sdk/range-order/src/libs/pool.ts @@ -4,12 +4,12 @@ import { Pool } from '@uniswap/v3-sdk' import { Price, Token } from '@uniswap/sdk-core' export async function getPrice(): Promise> { - const pool = await Pool.initFromChain( - getProvider(), - CurrentConfig.tokens.token0, - CurrentConfig.tokens.token1, - CurrentConfig.tokens.poolFee - ) + const pool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: CurrentConfig.tokens.token0, + tokenB: CurrentConfig.tokens.token1, + fee: CurrentConfig.tokens.poolFee, + }) return pool.token0Price } diff --git a/v3-sdk/range-order/src/libs/positions.ts b/v3-sdk/range-order/src/libs/positions.ts index 163d1639..823c4c80 100644 --- a/v3-sdk/range-order/src/libs/positions.ts +++ b/v3-sdk/range-order/src/libs/positions.ts @@ -97,12 +97,12 @@ export async function constructPosition( token1Amount: CurrencyAmount ): Promise { // construct pool instance - const pool = await Pool.initFromChain( - getProvider(), - token0Amount.currency, - token1Amount.currency, - CurrentConfig.tokens.poolFee - ) + const pool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: token0Amount.currency, + tokenB: token1Amount.currency, + fee: CurrentConfig.tokens.poolFee, + }) // create position using the maximum liquidity from input amounts return Position.fromAmounts({ @@ -147,7 +147,7 @@ export async function getPositionIds(): Promise { } export async function getPosition(positionId: number) { - return Position.fetchWithPositionId(getProvider(), positionId) + return Position.fetchWithPositionId({ provider: getProvider(), positionId }) } export async function getTokenTransferApproval( diff --git a/v3-sdk/range-order/src/libs/range-order.ts b/v3-sdk/range-order/src/libs/range-order.ts index ae782cd8..7f115c3a 100644 --- a/v3-sdk/range-order/src/libs/range-order.ts +++ b/v3-sdk/range-order/src/libs/range-order.ts @@ -50,16 +50,16 @@ export async function watchTakeProfitOrder( if (!address || !provider) { return TransactionState.Failed } - const pool = await Pool.initFromChain( + const pool = await Pool.initFromChain({ provider, - CurrentConfig.tokens.token0, - CurrentConfig.tokens.token1, - CurrentConfig.tokens.poolFee - ) - const currentPosition = await Position.fetchWithPositionId( + tokenA: CurrentConfig.tokens.token0, + tokenB: CurrentConfig.tokens.token1, + fee: CurrentConfig.tokens.poolFee, + }) + const currentPosition = await Position.fetchWithPositionId({ provider, - positionId - ) + positionId, + }) if ( currentPosition.tokensOwed0 === undefined || @@ -187,12 +187,12 @@ export async function constructTakeProfitOrder( zeroForOne: boolean, amount: number ): Promise { - const configuredPool = await Pool.initFromChain( - getProvider(), - CurrentConfig.tokens.token0, - CurrentConfig.tokens.token1, - CurrentConfig.tokens.poolFee - ) + const configuredPool = await Pool.initFromChain({ + provider: getProvider(), + tokenA: CurrentConfig.tokens.token0, + tokenB: CurrentConfig.tokens.token1, + fee: CurrentConfig.tokens.poolFee, + }) const current = await getPrice() const priceTarget = zeroForOne diff --git a/v3-sdk/range-order/yarn.lock b/v3-sdk/range-order/yarn.lock index 4091ad88..ac8d24c0 100644 --- a/v3-sdk/range-order/yarn.lock +++ b/v3-sdk/range-order/yarn.lock @@ -2531,10 +2531,10 @@ "@uniswap/v3-core" "1.0.0" base64-sol "1.0.1" -"@uniswap/v3-sdk@npm:@florian-s-a-w/uniswap-v3-sdk@3.15.17": - version "3.15.17" - resolved "https://registry.yarnpkg.com/@florian-s-a-w/uniswap-v3-sdk/-/uniswap-v3-sdk-3.15.17.tgz#73d183242a77135ce903a5e9aa8c0fbcceeffbb5" - integrity sha512-NKwwewrv7ySiDkGtXx+GmPkv3kpw6MimpmDRfVvjAatm3+emkyOwUW49TiW816PBHHkV9HExihSf8a0JdVGtEw== +"@uniswap/v3-sdk@npm:@florian-s-a-w/uniswap-v3-sdk@4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@florian-s-a-w/uniswap-v3-sdk/-/uniswap-v3-sdk-4.0.2.tgz#260942599aab4baf4d91a5643c204dba94dd0507" + integrity sha512-/8qO6E0rhsMQ9PGEf2pa+H8lbi7a7rpoHuQPbcvnauYD5KmaLiAnVC5MjYfO3SmX5ZENoDVLFibI3LXF05q1yg== dependencies: "@ethersproject/abi" "^5.0.12" "@ethersproject/solidity" "^5.0.9"