Skip to content

Commit

Permalink
Adding uniswap position tables (#126)
Browse files Browse the repository at this point in the history
* Starting to add uniswap positions table

* linting

* Moving uniswap positions above allocations

* Fixing position bugs, adding placeholder

* Fixing uniswap positions, cleaning up ui

* Fix amountX --> amountY conversion and price typing

Co-authored-by: Hayden Shively <17186559+haydenshively@users.noreply.github.com>
  • Loading branch information
IanWoodard and haydenshively authored Oct 21, 2022
1 parent 8395e1c commit 438dbf6
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 50 deletions.
72 changes: 64 additions & 8 deletions prime/src/assets/abis/MarginAccountLens.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,36 @@
],
"name": "getAssets",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" }
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
Expand All @@ -29,8 +53,40 @@
],
"name": "getLiabilities",
"outputs": [
{ "internalType": "uint256", "name": "amount0", "type": "uint256" },
{ "internalType": "uint256", "name": "amount1", "type": "uint256" }
{
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "contract MarginAccount",
"name": "account",
"type": "address"
}
],
"name": "getUniswapPositions",
"outputs": [
{
"internalType": "bytes32[]",
"name": "keys",
"type": "bytes32[]"
},
{
"internalType": "uint256[]",
"name": "fees",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const MIN_TICK = TickMath.MIN_TICK;
const MAX_TICK = TickMath.MAX_TICK;

type TickPrice = {
price: string;
price: number;
tick: number;
};

Expand Down Expand Up @@ -423,7 +423,7 @@ export default function UniswapAddLiquidityActionCard(props: ActionCardProps) {
)}
<div className='flex flex-row gap-2 mb-4'>
<SteppedInput
value={lower?.price || ''}
value={lower?.price.toString(10) ?? ''}
label='Min Price'
token0={token0}
token1={token1}
Expand All @@ -440,7 +440,7 @@ export default function UniswapAddLiquidityActionCard(props: ActionCardProps) {
tickInfo.tickSpacing
);
const nearestPrice = tickToPrice(nearestTick, token0.decimals, token1.decimals, isToken0Selected);
if (parseFloat(nearestPrice) < parseFloat(upper.price) && nearestTick >= MIN_TICK) {
if (nearestPrice < upper.price && nearestTick >= MIN_TICK) {
updateLower({
price: nearestPrice,
tick: nearestTick,
Expand Down Expand Up @@ -493,7 +493,7 @@ export default function UniswapAddLiquidityActionCard(props: ActionCardProps) {
disabled={poolAddress == null}
/>
<SteppedInput
value={upper?.price || ''}
value={upper?.price.toString(10) ?? ''}
label='Max Price'
token0={token0}
token1={token1}
Expand All @@ -510,7 +510,7 @@ export default function UniswapAddLiquidityActionCard(props: ActionCardProps) {
tickInfo.tickSpacing
);
const nearestPrice = tickToPrice(nearestTick, token0.decimals, token1.decimals, isToken0Selected);
if (parseFloat(nearestPrice) > parseFloat(lower.price) && nearestTick <= MAX_TICK) {
if (nearestPrice > lower.price && nearestTick <= MAX_TICK) {
updateUpper({
price: nearestPrice,
tick: nearestTick,
Expand Down
12 changes: 6 additions & 6 deletions prime/src/components/borrow/uniswap/LiquidityChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ function nearestPriceInGraphOrNull(

export type LiquidityChartProps = {
data: ChartEntry[];
rangeStart: string;
rangeEnd: string;
currentPrice: string;
rangeStart: number;
rangeEnd: number;
currentPrice: number;
};

export default function LiquidityChart(props: LiquidityChartProps) {
const { data, rangeStart, rangeEnd, currentPrice } = props;
const minPrice = data.length > 0 ? data[0].price : 0;
const maxPrice = data.length > 0 ? data[data.length - 1].price : 0;
const updatedRangeStart = nearestPriceInGraphOrNull(parseFloat(rangeStart), minPrice, maxPrice, data);
const updatedRangeEnd = nearestPriceInGraphOrNull(parseFloat(rangeEnd), minPrice, maxPrice, data);
const updatedCurrentPrice = nearestPriceInGraphOrNull(parseFloat(currentPrice), minPrice, maxPrice, data);
const updatedRangeStart = nearestPriceInGraphOrNull(rangeStart, minPrice, maxPrice, data);
const updatedRangeEnd = nearestPriceInGraphOrNull(rangeEnd, minPrice, maxPrice, data);
const updatedCurrentPrice = nearestPriceInGraphOrNull(currentPrice, minPrice, maxPrice, data);
const ticks = [
data[Math.floor(Math.floor(data.length / 2) / 2)].price,
data[Math.floor(data.length / 2)].price,
Expand Down
Loading

0 comments on commit 438dbf6

Please # to comment.