This commit is contained in:
Tim
2024-01-23 01:32:44 -04:00
parent 0e5a4bac6d
commit ee021c9590
6 changed files with 63 additions and 3 deletions

48
src/blockchain/ohlcs.js Normal file
View File

@@ -0,0 +1,48 @@
import {socket} from "@/socket.js";
import {useStore} from "@/store/store.js";
import {Exchange} from "@/blockchain/orderlib.js";
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
import {ethers, FixedNumber} from "ethers";
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
const ohlcSubCounts = {} // 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 subOHLCs( chainId, poolPeriods ) {
if( !poolPeriods.length )
return
const toSub = []
for( const [pool,period] of poolPeriods ) {
const key = `${pool}|${period}`
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
ohlcSubCounts[key] = 1
toSub.push(key)
} else {
ohlcSubCounts[key]++
}
}
if( toSub.length )
socket.emit('subOHLCs', chainId, toSub)
}
export function unsubPrices( chainId, poolPeriods ) {
const toUnsub = []
for( const [pool,period] of poolPeriods ) {
const key = `${pool}|${period}`
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
console.error('overdecremented',pool,period)
ohlcSubCounts[key] = 1
toSub.push(key)
} else {
ohlcSubCounts[key]--
if( ohlcSubCounts[key] == 0 )
toUnsub.push(key)
}
}
if( toUnsub.length )
socket.emit('unsubOHLCs', chainId, toUnsub )
}
// todo get history

View File

@@ -4,6 +4,7 @@ import {Exchange} from "@/blockchain/orderlib.js";
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js"; import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
import {ethers, FixedNumber} from "ethers"; import {ethers, FixedNumber} from "ethers";
import {uniswapV3PoolAbi} from "@/blockchain/abi.js"; import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
import {subOHLCs} from "@/blockchain/ohlcs.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 const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits

View File

@@ -8,6 +8,7 @@ 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";
import {routeInverted} from "@/misc.js"; import {routeInverted} from "@/misc.js";
import {subOHLCs} from "@/blockchain/ohlcs.js";
const s = useStore() const s = useStore()
const os = useOrderStore() const os = useOrderStore()
@@ -37,8 +38,10 @@ const price = computed(()=>{
return p.toPrecision(props.precision) return p.toPrecision(props.precision)
}) })
if( route.value ) if( route.value ) {
subPrices([route.value]) subPrices([route.value])
subOHLCs( s.chainId.value, [[route.value.pool,'1D']])
}
else else
console.log('route is empty: no price') console.log('route is empty: no price')

View File

@@ -48,12 +48,14 @@
<v-card-title><v-icon icon="mdi-safe-square" color="grey-darken-2" size="small"/> Vault Assets {{s.vaults.length>1?'#'+(num+1):''}}</v-card-title> <!-- todo vault nicknames --> <v-card-title><v-icon icon="mdi-safe-square" color="grey-darken-2" size="small"/> Vault Assets {{s.vaults.length>1?'#'+(num+1):''}}</v-card-title> <!-- todo vault nicknames -->
<v-card-subtitle v-if="exists" class="overflow-x-hidden"><copy-button :text="addr"/>{{addr}}</v-card-subtitle> <v-card-subtitle v-if="exists" class="overflow-x-hidden"><copy-button :text="addr"/>{{addr}}</v-card-subtitle>
<v-card-text v-if="empty"> <v-card-text v-if="empty">
<!--
<p> <p>
Your vault is a smart contract that securely holds your funds plus any orders you place. When your order Your vault is a smart contract that securely holds your funds plus any orders you place. When your order
conditions are met, Dexorder creates a blockchain transaction asking your vault to execute the order. Your conditions are met, Dexorder creates a blockchain transaction asking your vault to execute the order. Your
vault then checks that order against the current blockchain time and pool price, and only trades if vault then checks that order against the current blockchain time and pool price, and only trades if
everything looks good. everything looks good.
</p> </p>
-->
<p v-if="!s.mockenv">There are no funds currently in your vault. Send tokens to the address above to fund your vault.</p> <p v-if="!s.mockenv">There are no funds currently in your vault. Send tokens to the address above to fund your vault.</p>
<p v-if="s.mockenv">There are no funds currently in your vault. Use the faucet below to mint some testnet coins into your vault.</p> <p v-if="s.mockenv">There are no funds currently in your vault. Use the faucet below to mint some testnet coins into your vault.</p>
</v-card-text> </v-card-text>

View File

@@ -1,7 +1,6 @@
import {io} from "socket.io-client"; import {io} from "socket.io-client";
import {useStore} from "@/store/store.js"; import {useStore} from "@/store/store.js";
import {flushOrders, onChainChanged} from "@/blockchain/wallet.js"; import {flushOrders} from "@/blockchain/wallet.js";
import {ethers} from "ethers";
import {parseOrderStatus} from "@/blockchain/orderlib.js"; import {parseOrderStatus} from "@/blockchain/orderlib.js";
export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]}) export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]})
@@ -22,6 +21,10 @@ socket.on('p', async (chainId, pool, price) => {
s.poolPrices[[chainId,pool]] = price s.poolPrices[[chainId,pool]] = price
}) })
socket.on('ohlcs', async (chainId, pool, ohlcs) => {
console.log('pool bars', pool, ohlcs)
})
socket.on('vb', async (chainId, vault, balances) => { socket.on('vb', async (chainId, vault, balances) => {
const s = useStore() const s = useStore()
if( s.chainId.value !== chainId ) if( s.chainId.value !== chainId )

3
tradingview.md Normal file
View File

@@ -0,0 +1,3 @@
https://github.com/tradingview/charting_library
https://www.tradingview.com/charting-library-docs/latest/getting_started/Best-Practices/