Skip to content

Commit

Permalink
Update range order for sdk release version
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-S-A-W committed Dec 20, 2023
1 parent 9da5d84 commit 3fe48d0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 65 deletions.
4 changes: 2 additions & 2 deletions v3-sdk/range-order/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
61 changes: 29 additions & 32 deletions v3-sdk/range-order/src/libs/mockMarketMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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],
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions v3-sdk/range-order/src/libs/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Pool } from '@uniswap/v3-sdk'
import { Price, Token } from '@uniswap/sdk-core'

export async function getPrice(): Promise<Price<Token, Token>> {
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
}
14 changes: 7 additions & 7 deletions v3-sdk/range-order/src/libs/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ export async function constructPosition(
token1Amount: CurrencyAmount<Token>
): Promise<Position> {
// 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({
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function getPositionIds(): Promise<number[]> {
}

export async function getPosition(positionId: number) {
return Position.fetchWithPositionId(getProvider(), positionId)
return Position.fetchWithPositionId({ provider: getProvider(), positionId })
}

export async function getTokenTransferApproval(
Expand Down
28 changes: 14 additions & 14 deletions v3-sdk/range-order/src/libs/range-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -187,12 +187,12 @@ export async function constructTakeProfitOrder(
zeroForOne: boolean,
amount: number
): Promise<TakeProfitOrder> {
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
Expand Down
8 changes: 4 additions & 4 deletions v3-sdk/range-order/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3fe48d0

Please sign in to comment.