Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/range order updated #59

Closed
Closed
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e2ff0f1
Add naive tick visualization guide
Florian-S-A-W Jun 4, 2023
57c7778
Update graph to show custom tooltip, calculate virtual liquidity
Florian-S-A-W Jun 10, 2023
1161037
Calculate maximal extractable liquidity instead of virtual V2 liquidity
Florian-S-A-W Jun 11, 2023
96e9632
Improve formatting of Tooltip
Florian-S-A-W Jun 11, 2023
359470d
Cleanup tvl function in active liquidity
Florian-S-A-W Jun 12, 2023
f082741
Add simple oracle example
Florian-S-A-W Jun 23, 2023
ca3e9c4
Merge pull request #1 from Florian-S-A-W/feat/oracle
Florian-S-A-W Jun 23, 2023
8ddd1a5
Add range order setup with Mock Market Maker
Florian-S-A-W Jun 26, 2023
f8170ca
Mint, watch and withdraw range order
Florian-S-A-W Jun 27, 2023
23e46b3
Update Readme
Florian-S-A-W Jun 27, 2023
7ef7f74
Update config and change lower tick configuration
Florian-S-A-W Jun 28, 2023
4080dac
Update readme, config, small changes in MMM and React
Florian-S-A-W Jun 29, 2023
bf2d8fc
Merge pull request #3 from uniswapfoundation/feat/range-order
Florian-S-A-W Jul 3, 2023
1b7e598
Clean up pool data dependencies and remove unused constants
Florian-S-A-W Jul 3, 2023
d08503e
Cleanup oracle, remove unused functions and constants
Florian-S-A-W Jul 3, 2023
134d2be
Cleanup range-order
Florian-S-A-W Jul 3, 2023
f5979e3
Merge pull request #4 from uniswapfoundation/feat/advanced
Florian-S-A-W Jul 3, 2023
afae74b
Add get pool data via multicall code example
Florian-S-A-W Jul 24, 2023
490b4f6
Merge pull request #5 from uniswapfoundation/feat/multicall-pool-data
Florian-S-A-W Jul 24, 2023
e9b2982
Remove unused Wallet from config and README
Florian-S-A-W Aug 8, 2023
89e2a97
Merge pull request #6 from uniswapfoundation/feat/multicall-pool-data
Florian-S-A-W Aug 8, 2023
44f96c6
Merge remote-tracking branch 'upstream/main'
koraykoska Oct 27, 2023
08cf3c5
Update quoting guide
Florian-S-A-W Nov 18, 2023
dd91c2f
Merge pull request #7 from uniswapfoundation/feat/quoting_updated
Florian-S-A-W Nov 18, 2023
53764eb
Switch quoting example to quoteExactInput function
Florian-S-A-W Nov 18, 2023
195c322
Merge pull request #8 from uniswapfoundation/feat/quoting_updated
Florian-S-A-W Nov 18, 2023
f1e4832
Update dependencies
Florian-S-A-W Nov 18, 2023
f85c43b
Update trading example for new sdk version
Florian-S-A-W Nov 21, 2023
a20c5a9
Merge pull request #9 from uniswapfoundation/feat/trading_updated
Florian-S-A-W Nov 21, 2023
ec12d63
Use updated version of v3-sdk
Florian-S-A-W Nov 21, 2023
45b4999
Merge pull request #10 from uniswapfoundation/feat/trading_updated
Florian-S-A-W Nov 21, 2023
d7251e1
Update dependencies
Florian-S-A-W Nov 21, 2023
478d32f
Add template for offchain-simulation example
Florian-S-A-W Nov 21, 2023
af948f4
Add offchain-simulation example
Florian-S-A-W Nov 24, 2023
68f1b68
Merge pull request #11 from uniswapfoundation/feat/offchain_simulation
Florian-S-A-W Nov 24, 2023
e59d023
Fix dependency mismatch issue in routing example
Florian-S-A-W Nov 24, 2023
7ba5a87
Merge pull request #12 from uniswapfoundation/feat/routing_updated
Florian-S-A-W Nov 24, 2023
d035635
Remove multicall example
Florian-S-A-W Nov 25, 2023
5ae1f62
Clean up quoting example
Florian-S-A-W Nov 25, 2023
e6ea20d
Cleanup trading example
Florian-S-A-W Nov 25, 2023
0967d69
Clean up offchain-simulations example
Florian-S-A-W Nov 25, 2023
aef54a0
Merge pull request #13 from uniswapfoundation/fix/cleanup
Florian-S-A-W Nov 25, 2023
270c97c
Update oracle example to match new sdk version
Florian-S-A-W Dec 6, 2023
e2bb7ed
Merge pull request #14 from uniswapfoundation/feat/oracle_updated
Florian-S-A-W Dec 6, 2023
71a27f9
Fix advanced examples package names
Florian-S-A-W Dec 6, 2023
544984e
Merge pull request #15 from uniswapfoundation/fix/package-names
Florian-S-A-W Dec 6, 2023
3a24272
Update range order example for new sdk
Florian-S-A-W Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup range-order
Remove unused functions and constants in range-order, update readme.
Return actual target price of range order instead of user defined price from which order is created
  • Loading branch information
Florian-S-A-W committed Jul 3, 2023
commit 134d2be3e5bd606c938308bced5f2040a5bd5c08
3 changes: 2 additions & 1 deletion v3-sdk/range-order/README.md
Original file line number Diff line number Diff line change
@@ -11,14 +11,15 @@ The core functionality of this example can be found in [`range-order`](./src/lib
This example only works on a local fork of mainnet.

A wallet with 10,000 ETH is available to create Limit orders. On startup and execution of an order, the wallet wraps 1 ETH to get 1 WETH.
Clicking on Create Order creates a Take Profit order to a target Price specified in the configuration.
Clicking on Create Order creates a Take Profit order as close as possible to a target Price specified in the configuration.

A second wallet is available to simulate swaps by other market participants on the pool.
It also has 10,000 ETH available, half of which it sells for token1 on startup.
Clicking on buy or sell WETH buys or sells the amounts specified in the `config.ts` file on the pool where the Range Order is created.

To simulate listening for new blocks, the local chain is created with interval mining. This means transactions take some time to execute. The block time is therefore set to 6s.
The application needs 2-4 blocks to startup when a new local chain is created.
Transactions take 1 block to get included and the displayed values need another block to update as new read calls are made. Be aware that some functions include multiple transactions that are included sequentially.

## Configuration

59 changes: 2 additions & 57 deletions v3-sdk/range-order/src/libs/providers.ts
Original file line number Diff line number Diff line change
@@ -8,9 +8,6 @@ const mainnetProvider = new ethers.providers.JsonRpcProvider(
)
const wallet = createWallet()

const browserExtensionProvider = createBrowserExtensionProvider()
let walletExtensionAddress: string | null = null

// Interfaces

export enum TransactionState {
@@ -32,9 +29,7 @@ export function getProvider(): providers.Provider {
}

export function getWalletAddress(): string | null {
return CurrentConfig.env === Environment.WALLET_EXTENSION
? walletExtensionAddress
: wallet.address
return wallet.address
}

export function getWallet(): Wallet {
@@ -44,28 +39,7 @@ export function getWallet(): Wallet {
export async function sendTransaction(
transaction: ethers.providers.TransactionRequest
): Promise<TransactionState> {
if (CurrentConfig.env === Environment.WALLET_EXTENSION) {
return sendTransactionViaExtension(transaction)
} else {
return sendTransactionViaWallet(transaction)
}
}

export async function connectBrowserExtensionWallet() {
if (!window.ethereum) {
return null
}

const { ethereum } = window
const provider = new ethers.providers.Web3Provider(ethereum)
const accounts = await provider.send('eth_requestAccounts', [])

if (accounts.length !== 1) {
return
}

walletExtensionAddress = accounts[0]
return walletExtensionAddress
return sendTransactionViaWallet(transaction)
}

// Internal Functionality
@@ -78,35 +52,6 @@ function createWallet(): ethers.Wallet {
return new ethers.Wallet(CurrentConfig.wallet.privateKey, provider)
}

function createBrowserExtensionProvider(): ethers.providers.Web3Provider | null {
try {
return new ethers.providers.Web3Provider(window?.ethereum, 'any')
} catch (e) {
console.log('No Wallet Extension Found')
return null
}
}

// Transacting with a wallet extension via a Web3 Provider
async function sendTransactionViaExtension(
transaction: ethers.providers.TransactionRequest
): Promise<TransactionState> {
try {
const receipt = await browserExtensionProvider?.send(
'eth_sendTransaction',
[transaction]
)
if (receipt) {
return TransactionState.Sent
} else {
return TransactionState.Failed
}
} catch (e) {
console.log(e)
return TransactionState.Rejected
}
}

async function sendTransactionViaWallet(
transaction: ethers.providers.TransactionRequest
): Promise<TransactionState> {
8 changes: 7 additions & 1 deletion v3-sdk/range-order/src/libs/range-order.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import {
MintOptions,
CollectOptions,
RemoveLiquidityOptions,
tickToPrice,
} from '@uniswap/v3-sdk'
import { getPoolInfo, getPrice } from './pool'
import { CurrentConfig } from '../config'
@@ -246,10 +247,15 @@ export async function constructTakeProfitOrder(
configuredPool,
zeroForOne
)
const closestTargetPrice = tickToPrice(
position.amount0.currency,
position.amount1.currency,
targetTick
)

return {
targetTick,
targetPrice: priceTarget,
targetPrice: closestTargetPrice,
position,
zeroForOne,
}
15 changes: 0 additions & 15 deletions v3-sdk/range-order/src/libs/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion v3-sdk/range-order/src/libs/wallet.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import {
WETH_CONTRACT_ADDRESS,
} from './constants'
import { getProvider, getWalletAddress, sendTransaction } from './providers'
import { toReadableAmount } from './utils'
import { toReadableAmount } from './conversion'

export async function getCurrencyBalance(
provider: providers.Provider,