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

One-Click LP [For Testing] #521

Draft
wants to merge 82 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
224da03
add controller helper abi and atoms
daryakaviani Jun 15, 2022
5f50ed7
open position hook
daryakaviani Jun 15, 2022
e18bc67
drafting close position
daryakaviani Jun 15, 2022
25ea441
collect fees hook
daryakaviani Jun 15, 2022
7ffd9f9
rebalance via general swap
daryakaviani Jun 15, 2022
0542b4a
rebalance via vault
daryakaviani Jun 16, 2022
75cadc7
flashloanWMintDeposit open position
daryakaviani Jun 16, 2022
36c671c
next tick price getter func
daryakaviani Jun 16, 2022
7c0920b
using nearestUsableTick
daryakaviani Jun 17, 2022
db6d0f4
fixing abi
daryakaviani Jun 17, 2022
671a40e
tx goes through, decimal refinement needed
daryakaviani Jun 17, 2022
6a0fac9
testing, debugging, using old hooks for open pos deposit
daryakaviani Jun 18, 2022
18dc6e6
log
daryakaviani Jun 18, 2022
8a214c6
fixing close position
daryakaviani Jun 18, 2022
5b8e7e7
removing mint and LP function
daryakaviani Jun 18, 2022
7d32b31
taking out safety margin
daryakaviani Jun 18, 2022
cf5e5d2
add ropsten controller helper address
daryakaviani Jun 21, 2022
8e11f52
tester button
Jun 23, 2022
40f1110
remove flashloan fee for open
Jun 27, 2022
931d94d
fixing controllerhelper address
Jun 28, 2022
72bbfde
add vault id as open param
Jun 28, 2022
a45f136
debugging collect fees
Jun 28, 2022
e5d43a5
getting position manager
Jun 29, 2022
472d3f3
debugged close position (with no burning)
Jun 29, 2022
192b87d
close position with quoter limit price
Jun 29, 2022
96dc674
collect fees works
Jun 30, 2022
c92b362
rebalance tx
Jun 30, 2022
fd6f665
rebal swap tx
Jun 30, 2022
7b20c70
general swap updates
Jul 5, 2022
7e3ff90
latest genswap rebal
Jul 5, 2022
bfb7d4f
buttons
Jul 5, 2022
1180d14
general swap rebalance works
Jul 5, 2022
c5c118c
delete rebalance test
Jul 6, 2022
ea83cc7
debugging swap rebal needmoreweth
Jul 6, 2022
a49af15
walls
Jul 6, 2022
e5d35af
add onchange params
Jul 7, 2022
dd209f6
separate cases
Jul 9, 2022
c3cc026
fixed one-sided LP positions
Jul 9, 2022
a453ea9
change rebalance to real amounts from virtual amounts
Jul 12, 2022
bc32d85
Delete fe-testing.ts
daryakaviani Jul 12, 2022
028b774
change case 1 to formula version
Jul 13, 2022
3f72818
debug new formula case 3
Jul 13, 2022
4dae775
delete old funcs
Jul 13, 2022
2c82ec3
delete unused
Jul 13, 2022
b9b3495
Revert "delete old funcs"
Jul 13, 2022
82ddfab
update lp.tx to test
Jul 13, 2022
1eb66ab
updating consts
Jul 13, 2022
4ad5b48
change one-side positions to math way
Jul 16, 2022
a538ccd
make vaultId variable
Jul 16, 2022
a137ebd
use Promise.all
Jul 16, 2022
ff16e33
use promise.all in close
Jul 16, 2022
afc42cd
token id null case
Jul 16, 2022
5a46e9b
unitokenid null for fees
Jul 16, 2022
d0f66ee
twap to slot0
Aug 3, 2022
4f6c831
collat ratio
Aug 3, 2022
c50a954
variable collateral to lp for open
Aug 3, 2022
11ca145
amount mins open
Aug 3, 2022
a7f8018
limit price
Aug 3, 2022
49ef96a
amount to burn
Aug 3, 2022
aedad68
int 128
Aug 3, 2022
97f91f3
change name to poolContract
Aug 4, 2022
648b4a5
get tickSpacing from pool
Aug 4, 2022
9ce929d
no price impact quote
Aug 5, 2022
20e5327
no more iswethtoken0
Aug 5, 2022
89d03ba
review updates
Aug 8, 2022
520d611
limit price
Aug 8, 2022
e852a85
amount mins close
Aug 8, 2022
ace48c7
fix limit price
Aug 8, 2022
4b948ce
open value
Aug 8, 2022
64b5af5
withdraw
Aug 9, 2022
5295773
close dependencies
Aug 9, 2022
5a80962
ugly fe
Aug 9, 2022
67d4fa6
dependencies
Aug 10, 2022
8b4f968
remove pool state dupe
Aug 13, 2022
8552d4c
things
Aug 17, 2022
bf0fe9b
format
Aug 17, 2022
4af4e5c
open bounds
Aug 19, 2022
d72265d
open
Aug 19, 2022
fccd68d
symmetry
Aug 23, 2022
69439af
fix flashloan
Aug 25, 2022
4e27f4c
close tweaks
Aug 29, 2022
11b35eb
chore: make it ready for goerli
nikkaroraa Nov 18, 2022
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
189 changes: 188 additions & 1 deletion packages/frontend/pages/lp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStyles, makeStyles } from '@material-ui/core'
import { Button, createStyles, makeStyles, TextField } from '@material-ui/core'
import Typography from '@material-ui/core/Typography'
import Image from 'next/image'
import React, { useState } from 'react'
Expand All @@ -15,6 +15,13 @@ import { SqueethTab, SqueethTabs } from '@components/Tabs'
import { useETHPrice } from '@hooks/useETHPrice'
import { supportedNetworkAtom } from 'src/state/wallet/atoms'
import { useAtomValue } from 'jotai'
import { useFlashClosePosition, useOpenPositionDeposit, useRebalanceGeneralSwap } from 'src/state/lp/hooks'
import { useCollectFees } from 'src/state/lp/hooks'
import BigNumber from 'bignumber.js'
import useAppCallback from '@hooks/useAppCallback'
import { useFirstValidVault } from 'src/state/positions/hooks'
import { useGetTwapSqueethPrice, useUpdateOperator } from 'src/state/controller/hooks'
import { addressesAtom } from 'src/state/positions/atoms'

const useStyles = makeStyles((theme) =>
createStyles({
Expand Down Expand Up @@ -73,15 +80,102 @@ const useStyles = makeStyles((theme) =>
chartNav: {
border: `1px solid ${theme.palette.primary.main}30`,
},
buttonTest: {
width: '300px',
color: 'gray',
backgroundColor: '#a9fbf6',
marginTop: '10px',
marginBottom: '10px',
},
testField: {
marginTop: '10px',
marginBottom: '10px',
},
}),
)

export function LPCalculator() {
const { controllerHelper } = useAtomValue(addressesAtom)
const classes = useStyles()
const { isRestricted } = useRestrictUser()
const ethPrice = useETHPrice()
const [lpType, setLpType] = useState(0)
const supportedNetwork = useAtomValue(supportedNetworkAtom)
const squeethPrice = useGetTwapSqueethPrice()
const openLPPosition = useOpenPositionDeposit()
const closeLPPosition = useFlashClosePosition()
const collectFees = useCollectFees()
const rebalanceSwap = useRebalanceGeneralSwap()
const updateOperator = useUpdateOperator()
const { vaultId, validVault: vault } = useFirstValidVault()

const [vaultID, setVaultID] = useState(0)
const [squeethAmount, setSqueethAmount] = useState(0)
const [lowerTick, setLowerTick] = useState(-500000)
const [upperTick, setUpperTick] = useState(500000)
const [slippage, setSlippage] = useState(0.0025)
const [collatToWithdraw, setCollatToWithdraw] = useState(0)
const [collatRatio, setCollatRatio] = useState(1.5)
const [liquidityPercentage, setLiquidityPercentage] = useState(1)
const [burnPercentage, setBurnPercentage] = useState(1)
const [burnExactRemoved, setBurnExactRemoved] = useState(true)

const openPos = useAppCallback(async () => {
try {
await openLPPosition(
new BigNumber(squeethAmount),
lowerTick,
upperTick,
vaultID,
collatRatio,
slippage,
collatToWithdraw,
() => {},
)
} catch (e) {
console.log(e)
}
}, [squeethAmount, vaultID, lowerTick, upperTick, collatRatio, slippage, collatToWithdraw, openLPPosition])

const updateOp = useAppCallback(async () => {
try {
await updateOperator(vaultID, controllerHelper)
} catch (e) {
console.log(e)
}
}, [vaultID, controllerHelper, updateOperator])

const collFees = useAppCallback(async () => {
try {
await collectFees(vaultID, () => {})
} catch (e) {
console.log(e)
}
}, [vaultID, collectFees])

const closePos = useAppCallback(async () => {
try {
await closeLPPosition(
vaultID,
liquidityPercentage,
burnPercentage,
collatToWithdraw,
burnExactRemoved,
slippage,
() => {},
)
} catch (e) {
console.log(e)
}
}, [vaultID, liquidityPercentage, burnPercentage, collatToWithdraw, burnExactRemoved, slippage, closeLPPosition])

const rebalSwap = useAppCallback(async () => {
try {
await rebalanceSwap(vaultID, lowerTick, upperTick, slippage, () => {})
} catch (e) {
console.log(e)
}
}, [vaultID, lowerTick, upperTick, slippage, rebalanceSwap])

return (
<div>
Expand Down Expand Up @@ -155,6 +249,99 @@ export function LPCalculator() {
contracts are experimental technology and we encourage caution only risking funds you can afford to
lose.
</Typography>
<Typography className={classes.heading} variant="subtitle1" color="primary">
Testing One Click LP Hooks
</Typography>
<TextField
className={classes.testField}
id="outlined-name"
label="Vault ID"
value={vaultID}
onChange={(event) => setVaultID(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Squeeth Amount"
value={squeethAmount}
onChange={(event) => setSqueethAmount(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Lower Tick"
value={lowerTick}
onChange={(event) => setLowerTick(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Upper Tick"
value={upperTick}
onChange={(event) => setUpperTick(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Slippage Tolerance"
value={slippage}
onChange={(event) => setSlippage(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Collateral to Withdraw"
value={collatToWithdraw}
onChange={(event) => setCollatToWithdraw(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Collat Ratio"
value={collatRatio}
onChange={(event) => setCollatRatio(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Liquidity Percentage (in decimal)"
value={liquidityPercentage}
onChange={(event) => setLiquidityPercentage(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Burn Percentage (in decimal)"
value={burnPercentage}
onChange={(event) => setBurnPercentage(Number(event.target.value))}
/>
<TextField
className={classes.testField}
id="outlined-name"
label="Burn Exact Removed"
value={burnExactRemoved}
onChange={(event) => setBurnExactRemoved(Boolean(event.target.value))}
/>
<br />
<Button onClick={openPos} className={classes.buttonTest}>
{'Open Mint and Deposit'}
</Button>
<br />
<Button onClick={updateOp} className={classes.buttonTest}>
{'Update Operator'}
</Button>
<br />
<Button onClick={collFees} className={classes.buttonTest}>
{'Collect Fees'}
</Button>
<br />
<Button onClick={closePos} className={classes.buttonTest}>
{'Close Position'}
</Button>
<br />
<Button onClick={rebalSwap} className={classes.buttonTest}>
{'Rebalance General Swap'}
</Button>
</div>
) : (
<div style={{ marginTop: '16px' }}>
Expand Down
Loading