more price handling bugfixes
This commit is contained in:
@@ -6,6 +6,7 @@ import {ethers, FixedNumber} from "ethers";
|
|||||||
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
||||||
|
|
||||||
const subscriptionCounts = {} // key is route and value is a subscription counter
|
const subscriptionCounts = {} // key is route and value is a subscription counter
|
||||||
|
export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits
|
||||||
|
|
||||||
|
|
||||||
export function subPrices( routes ) {
|
export function subPrices( routes ) {
|
||||||
@@ -84,9 +85,8 @@ async function getPriceForRoute(route) {
|
|||||||
const [sqrtPrice,,,,,,] = got
|
const [sqrtPrice,,,,,,] = got
|
||||||
const spn = BigInt(sqrtPrice)
|
const spn = BigInt(sqrtPrice)
|
||||||
let price = spn*spn * 10n**BigInt(route.token0.decimals-route.token1.decimals)
|
let price = spn*spn * 10n**BigInt(route.token0.decimals-route.token1.decimals)
|
||||||
const format = {decimals:38,width:512,signed:false}; // 38 decimals is 127 bits
|
price = FixedNumber.fromValue(price,0,WIDE_PRICE_FORMAT)
|
||||||
price = FixedNumber.fromValue(price,0,format)
|
price = price.div(FixedNumber.fromValue(2n**(96n*2n),0,WIDE_PRICE_FORMAT))
|
||||||
price = price.div(FixedNumber.fromValue(2n**(96n*2n),0,format))
|
|
||||||
price = price.round(18).toString()
|
price = price.round(18).toString()
|
||||||
console.log(`price for ${route.token0.symbol}/${route.token1.symbol}`,price)
|
console.log(`price for ${route.token0.symbol}/${route.token1.symbol}`,price)
|
||||||
store.poolPrices[addr] = price
|
store.poolPrices[addr] = price
|
||||||
|
|||||||
@@ -50,9 +50,7 @@ function gib() {
|
|||||||
if( s.account ) {
|
if( s.account ) {
|
||||||
disabled.value = true
|
disabled.value = true
|
||||||
socket.emit('faucet', s.chainId, s.account)
|
socket.emit('faucet', s.chainId, s.account)
|
||||||
setTimeout(()=>disabled.value=false,
|
setTimeout(()=>disabled.value=false, 60*1000)
|
||||||
1000) // todo
|
|
||||||
// 60*1000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {useStore} from "@/store/store";
|
import {useStore} from "@/store/store";
|
||||||
import {subPrices, unsubPrices} from "@/blockchain/prices.js";
|
import {subPrices, unsubPrices, WIDE_PRICE_FORMAT} from "@/blockchain/prices.js";
|
||||||
import {computed, onBeforeUnmount} from "vue";
|
import {computed, onBeforeUnmount} from "vue";
|
||||||
import {FixedNumber} from "ethers";
|
import {FixedNumber} from "ethers";
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ const price = computed(()=>{
|
|||||||
console.log('pool price is',typeof p, p)
|
console.log('pool price is',typeof p, p)
|
||||||
if( !p )
|
if( !p )
|
||||||
return ''
|
return ''
|
||||||
p = FixedNumber.fromString(p).toUnsafeFloat()
|
p = FixedNumber.fromString(p, WIDE_PRICE_FORMAT).toUnsafeFloat()
|
||||||
if( props.inverted )
|
if( props.inverted )
|
||||||
p = 1/p
|
p = 1/p
|
||||||
return p.toPrecision(props.precision)
|
return p.toPrecision(props.precision)
|
||||||
|
|||||||
Reference in New Issue
Block a user