Skip to content

Commit

Permalink
Merge pull request #20 from uniswapfoundation/feat/release-sdk-versio…
Browse files Browse the repository at this point in the history
…n-update

Feat/release sdk version update
  • Loading branch information
Florian-S-A-W authored Dec 20, 2023
2 parents ddbe51b + 559578e commit 2b19b8a
Show file tree
Hide file tree
Showing 41 changed files with 359 additions and 1,200 deletions.
6 changes: 3 additions & 3 deletions v3-sdk/collecting-fees/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "collecting-fees",
"version": "0.1.0",
"version": "0.2.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.18",
"@uniswap/v3-sdk": "npm:@florian-s-a-w/uniswap-v3-sdk@4.0.1",
"ethers": "^5.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -19,7 +19,7 @@
"build": "react-scripts build",
"lint": "yarn eslint .",
"install:chain": "curl -L https://foundry.paradigm.xyz | bash && clear && echo $0 | exec && foundryup",
"start:chain": "anvil --chain-id 1337 --fork-url"
"start:chain": "anvil --chain-id 1 --fork-url"
},
"eslintConfig": {
"extends": [
Expand Down
24 changes: 12 additions & 12 deletions v3-sdk/collecting-fees/src/libs/liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function collectFees(
return TransactionState.Failed
}

const position = await Position.fetchWithPositionId(provider, positionId)
const position = await Position.fetchWithPositionId({ provider, positionId })
const transactionResponse = await position.collectFeesOnChain({
signer: wallet,
provider,
Expand Down Expand Up @@ -59,12 +59,12 @@ export async function getTokenTransferApproval(
return TransactionState.Failed
}

const receipt = await approveTokenTransfer(
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES[token.chainId],
token.address,
TOKEN_AMOUNT_TO_APPROVE_FOR_TRANSFER,
getWallet()
)
const receipt = await approveTokenTransfer({
contractAddress: NONFUNGIBLE_POSITION_MANAGER_ADDRESSES[token.chainId],
tokenAddress: token.address,
amount: TOKEN_AMOUNT_TO_APPROVE_FOR_TRANSFER,
signer: getWallet(),
})
if (receipt) {
return TransactionState.Sent
} else {
Expand All @@ -82,12 +82,12 @@ export async function constructPosition(
}

// construct pool instance
const pool = await Pool.initFromChain(
const pool = await Pool.initFromChain({
provider,
token0Amount.currency,
token1Amount.currency,
CurrentConfig.tokens.poolFee
)
tokenA: token0Amount.currency,
tokenB: token1Amount.currency,
fee: CurrentConfig.tokens.poolFee,
})

// create position using the maximum liquidity from input amounts
return Position.fromAmounts({
Expand Down
8 changes: 4 additions & 4 deletions v3-sdk/collecting-fees/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.18":
version "3.15.18"
resolved "https://registry.yarnpkg.com/@florian-s-a-w/uniswap-v3-sdk/-/uniswap-v3-sdk-3.15.18.tgz#7396fa89834ef71eda944a3e697cca2a4b23ff2b"
integrity sha512-rPK/JiEuDIHP1F35uiupx7wMArnRO0WjoeNVe59FyhJYhyEyhoQHop3zT0OA+mn5ckWlOj6MHBv82tkhCPZwQQ==
"@uniswap/v3-sdk@npm:@florian-s-a-w/uniswap-v3-sdk@4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@florian-s-a-w/uniswap-v3-sdk/-/uniswap-v3-sdk-4.0.1.tgz#25c3ad8ee80c88192166caeb649aef1dc433fd6a"
integrity sha512-wQ0HGzhiJ39zIlrp8iyRMyYUzY8b6R1yQ/siqa1M1BImTpZnwvH9q87lHRhHhjt8qd05EMogoCxkdFDMhrIw4A==
dependencies:
"@ethersproject/abi" "^5.0.12"
"@ethersproject/solidity" "^5.0.9"
Expand Down
6 changes: 3 additions & 3 deletions v3-sdk/minting-position/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@uniswap/sdk-core": "^3.1.0",
"@uniswap/v3-sdk": "^3.9.0",
"@uniswap/sdk-core": "npm:@koraykoska/uniswap-sdk-core@^6.0.9",
"@uniswap/v3-sdk": "npm:@florian-s-a-w/[email protected]",
"ethers": "^5.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -19,7 +19,7 @@
"build": "react-scripts build",
"lint": "yarn eslint .",
"install:chain": "curl -L https://foundry.paradigm.xyz | bash && clear && echo $0 | exec && foundryup",
"start:chain": "anvil --chain-id 1337 --fork-url"
"start:chain": "anvil --chain-id 1 --fork-url"
},
"eslintConfig": {
"extends": [
Expand Down
4 changes: 2 additions & 2 deletions v3-sdk/minting-position/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const CurrentConfig: ExampleConfig = {
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
},
tokens: {
token0: USDC_TOKEN,
token0: DAI_TOKEN,
token0Amount: 1000,
token1: DAI_TOKEN,
token1: USDC_TOKEN,
token1Amount: 1000,
poolFee: FeeAmount.LOW,
},
Expand Down
45 changes: 16 additions & 29 deletions v3-sdk/minting-position/src/example/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import './Example.css'
import { Environment, CurrentConfig } from '../config'
import { getCurrencyBalance } from '../libs/balance'
import {
getPositionIds,
getPositionInfo,
mintPosition,
PositionInfo,
} from '../libs/positions'
import { getPositions, mintPosition } from '../libs/positions'
import {
connectBrowserExtensionWallet,
getProvider,
TransactionState,
getWalletAddress,
} from '../libs/providers'
import { Position } from '@uniswap/v3-sdk'

const useOnBlockUpdated = (callback: (blockNumber: number) => void) => {
useEffect(() => {
Expand All @@ -27,8 +23,7 @@ const useOnBlockUpdated = (callback: (blockNumber: number) => void) => {
const Example = () => {
const [token0Balance, setToken0Balance] = useState<string>()
const [token1Balance, setToken1Balance] = useState<string>()
const [positionIds, setPositionIds] = useState<number[]>([])
const [positionsInfo, setPositionsInfo] = useState<PositionInfo[]>([])
const [positions, setPositions] = useState<Position[]>([])
const [txState, setTxState] = useState<TransactionState>(TransactionState.New)
const [blockNumber, setBlockNumber] = useState<number>(0)

Expand All @@ -54,10 +49,8 @@ const Example = () => {
await getCurrencyBalance(provider, address, CurrentConfig.tokens.token1)
)

// Set Position Info
const ids = await getPositionIds()
setPositionIds(ids)
setPositionsInfo(await Promise.all(ids.map(getPositionInfo)))
// Set Positions
setPositions(await getPositions())
}, [])

// Event Handlers
Expand All @@ -75,19 +68,15 @@ const Example = () => {

// Formatted Data

const positionInfoStrings: string[] = useMemo(() => {
if (positionIds.length !== positionsInfo.length) {
return []
}

return positionIds
.map((id, index) => [id, positionsInfo[index]])
.map((info) => {
const id = info[0]
const posInfo = info[1] as PositionInfo
return `${id}: ${posInfo.liquidity.toString()} liquidity, owed ${posInfo.tokensOwed0.toString()} and ${posInfo.tokensOwed1.toString()}`
})
}, [positionIds, positionsInfo])
const positionStrings: string[] = useMemo(() => {
return positions.map((pos) => {
return `${
pos.positionId ? pos.positionId : 'No id'
}: ${pos.amount0.toSignificant()} and ${pos.amount1.toSignificant()} liquidity , owed ${
pos.tokensOwed0 ? pos.tokensOwed0.toString() : '0'
} and ${pos.tokensOwed1 ? pos.tokensOwed1.toString() : '0'}`
})
}, [positions])

return (
<div className="App">
Expand Down Expand Up @@ -117,16 +106,14 @@ const Example = () => {
<h3>{`${CurrentConfig.tokens.token1.symbol} Balance: ${token1Balance}`}</h3>
<div>
Positions:{' '}
{positionInfoStrings.map((s, i) => (
{positionStrings.map((s, i) => (
<p key={i}>{s}</p>
))}
</div>
<button
onClick={() => onMintPosition()}
disabled={
txState === TransactionState.Sending ||
getProvider() === null ||
CurrentConfig.rpc.mainnet === ''
txState === TransactionState.Sending || getProvider() === null
}>
<p>Mint Position</p>
</button>
Expand Down
6 changes: 3 additions & 3 deletions v3-sdk/minting-position/src/libs/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file stores web3 related constants such as addresses, token definitions, ETH currency references and ABI's

import { SupportedChainId, Token } from '@uniswap/sdk-core'
import { ChainId, Token } from '@uniswap/sdk-core'

// Addresses

Expand All @@ -12,15 +12,15 @@ export const NONFUNGIBLE_POSITION_MANAGER_CONTRACT_ADDRESS =
// Currencies and Tokens

export const USDC_TOKEN = new Token(
SupportedChainId.MAINNET,
ChainId.MAINNET,
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
6,
'USDC',
'USD//C'
)

export const DAI_TOKEN = new Token(
SupportedChainId.MAINNET,
ChainId.MAINNET,
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
18,
'DAI',
Expand Down
49 changes: 5 additions & 44 deletions v3-sdk/minting-position/src/libs/pool.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,17 @@
import { ethers } from 'ethers'
import { CurrentConfig } from '../config'
import IUniswapV3PoolABI from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json'
import { POOL_FACTORY_CONTRACT_ADDRESS } from './constants'
import { getProvider } from './providers'
import { computePoolAddress } from '@uniswap/v3-sdk'
import { getProvider } from '../libs/providers'
import { Pool } from '@uniswap/v3-sdk'

interface PoolInfo {
token0: string
token1: string
fee: number
tickSpacing: number
sqrtPriceX96: ethers.BigNumber
liquidity: ethers.BigNumber
tick: number
}

export async function getPoolInfo(): Promise<PoolInfo> {
export async function getPool(): Promise<Pool> {
const provider = getProvider()
if (!provider) {
throw new Error('No provider')
}

const currentPoolAddress = computePoolAddress({
factoryAddress: POOL_FACTORY_CONTRACT_ADDRESS,
return Pool.initFromChain({
provider,
tokenA: CurrentConfig.tokens.token0,
tokenB: CurrentConfig.tokens.token1,
fee: CurrentConfig.tokens.poolFee,
})

const poolContract = new ethers.Contract(
currentPoolAddress,
IUniswapV3PoolABI.abi,
provider
)

const [token0, token1, fee, tickSpacing, liquidity, slot0] =
await Promise.all([
poolContract.token0(),
poolContract.token1(),
poolContract.fee(),
poolContract.tickSpacing(),
poolContract.liquidity(),
poolContract.slot0(),
])

return {
token0,
token1,
fee,
tickSpacing,
liquidity,
sqrtPriceX96: slot0[0],
tick: slot0[1],
}
}
Loading

0 comments on commit 2b19b8a

Please sign in to comment.