static version.json file
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
/.env
|
||||
public/version.js
|
||||
version.json
|
||||
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
|
||||
@@ -73,6 +73,8 @@ export function unsubPrices( routes ) {
|
||||
|
||||
|
||||
async function getPriceForRoute(route) {
|
||||
if( !route.token0 || !route.token1 )
|
||||
return null
|
||||
if( route.exchange === Exchange.UniswapV3 ) {
|
||||
const addr = uniswapV3PoolAddress(route.chainId, route.token0.address, route.token1.address, route.fee)
|
||||
const store = useStore();
|
||||
@@ -85,8 +87,7 @@ async function getPriceForRoute(route) {
|
||||
const got = await pool.slot0()
|
||||
const [sqrtPrice,,,,,,] = got
|
||||
const spn = BigInt(sqrtPrice)
|
||||
let price = spn*spn * 10n**BigInt(route.token0.decimals-route.token1.decimals)
|
||||
price = FixedNumber.fromValue(price,0,WIDE_PRICE_FORMAT)
|
||||
let price = FixedNumber.fromValue(spn*spn, route.token1.decimals - route.token0.decimals, WIDE_PRICE_FORMAT)
|
||||
price = price.div(FixedNumber.fromValue(2n**(96n*2n),0,WIDE_PRICE_FORMAT))
|
||||
price = price.round(18).toString()
|
||||
// console.log(`price for ${route.token0.symbol}/${route.token1.symbol}`,price)
|
||||
|
||||
@@ -3,11 +3,11 @@ import {Exchange} from "@/blockchain/orderlib.js";
|
||||
|
||||
|
||||
export async function findRoute(chainId, tokenA, tokenB) {
|
||||
// console.log('getting query helper')
|
||||
console.log('getting query helper')
|
||||
const helper = await queryHelperContract()
|
||||
if (!helper)
|
||||
throw Error('no helper')
|
||||
console.log('getting raw routes', tokenA.address, tokenB.address)
|
||||
console.log('getting raw routes', helper, tokenA.address, tokenB.address)
|
||||
const rawRoutes = await helper.getRoutes(tokenA.address, tokenB.address)
|
||||
// todo expose all available pools
|
||||
console.log('raw routes', rawRoutes)
|
||||
|
||||
@@ -125,7 +125,7 @@ async function _discoverVaults(owner) {
|
||||
console.error(`bad vault version ${version}`)
|
||||
}
|
||||
catch (e) {
|
||||
console.log(`no vault ${num}`, e)
|
||||
console.log(`no vault ${num}`)
|
||||
}
|
||||
if( s.account === owner ) { // double-check the account since it could have changed during our await
|
||||
s.vaults = result
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<template>
|
||||
<v-text-field label='Amount' type="number" step="1" variant="outlined" aria-valuemin="0" min="0"
|
||||
v-model="os.amount" :rules="[validateRequired,validateAmount]" v-auto-select>
|
||||
<template v-slot:prepend-inner>
|
||||
<v-btn @click="os.amount = maxAmount">max {{maxAmount.toPrecision(5)}}</v-btn>
|
||||
</template>
|
||||
<template v-slot:append-inner>
|
||||
<v-btn @click="os.amountIsTokenA=!os.amountIsTokenA" variant="outlined" class="mr-2">
|
||||
{{ os.amountIsTokenA ? os.tokenA.symbol : os.tokenB.symbol }}
|
||||
{{ amountToken.symbol }}
|
||||
</v-btn>
|
||||
<v-btn :text="os.amountIsTotal ? 'total' : 'per tranche'" variant="outlined"
|
||||
@click="os.amountIsTotal=!os.amountIsTotal" class="total"/>
|
||||
@@ -12,13 +15,24 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useOrderStore} from "@/store/store";
|
||||
import {useOrderStore, useStore} from "@/store/store";
|
||||
// noinspection ES6UnusedImports
|
||||
import {vAutoSelect} from "@/misc.js";
|
||||
import {validateAmount, validateRequired} from "@/validate.js";
|
||||
import {computed} from "vue";
|
||||
|
||||
const s = useStore()
|
||||
const os = useOrderStore()
|
||||
|
||||
const amountToken = computed( ()=>os.amountIsTokenA ? os.tokenA.symbol : os.tokenB.symbol )
|
||||
const inToken = computed( ()=>os.buy ? os.tokenB : os.tokenA )
|
||||
const maxAmount = computed(()=>{
|
||||
const balance = s.balances[inToken]
|
||||
if( !balance )
|
||||
return 0
|
||||
const divisor = os.amountIsTotal ? 1 : os.tranches
|
||||
return balance / 10**inToken.value.decimals / divisor
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ const os = useOrderStore()
|
||||
|
||||
const tokenA = computed({
|
||||
get() {
|
||||
return os.baseToken
|
||||
return os.tokenA
|
||||
},
|
||||
set(value) {
|
||||
if( !os.baseToken || os.baseToken.address !== value.address ) {
|
||||
os.baseToken = value
|
||||
if( !os.tokenA || os.tokenA.address !== value.address ) {
|
||||
os.tokenA = value
|
||||
routeFinder.invoke()
|
||||
}
|
||||
}
|
||||
@@ -75,12 +75,12 @@ const routes = computed({
|
||||
})
|
||||
|
||||
async function componentFindRoute() {
|
||||
const tokenA = os.baseToken
|
||||
const tokenA = os.tokenA
|
||||
const tokenB = os.tokenB
|
||||
os.routes = []
|
||||
if (!tokenA || !tokenB)
|
||||
return
|
||||
console.log('finding route', tokenA, tokenB)
|
||||
console.log('finding route', s.chainId.value, tokenA, tokenB)
|
||||
os.routesPending = true
|
||||
try {
|
||||
const result = await findRoute(s.chainId.value, tokenA, tokenB)
|
||||
|
||||
@@ -14,18 +14,6 @@ socket.on('disconnect', () => {
|
||||
console.log(new Date(), 'ws disconnected')
|
||||
})
|
||||
|
||||
socket.on('welcome', async (data) => {
|
||||
console.log('welcome', data)
|
||||
const s = useStore()
|
||||
// todo put the vaultInitCodeHash into the chainInfo
|
||||
s.chainInfo = data.chainInfo
|
||||
s.vaultInitCodeHash = data.vaultInitCodeHash
|
||||
const p = new ethers.BrowserProvider(window.ethereum)
|
||||
const network = await p.getNetwork()
|
||||
if (network !== null)
|
||||
onChainChanged(network.chainId)
|
||||
})
|
||||
|
||||
socket.on('p', async (chainId, pool, price) => {
|
||||
console.log('pool price from message', chainId, pool, price)
|
||||
const s = useStore()
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import {knownTokens} from "@/knownTokens.js";
|
||||
import {computed, ref} from "vue";
|
||||
import {ethers} from "ethers";
|
||||
import {onChainChanged} from "@/blockchain/wallet.js";
|
||||
|
||||
|
||||
// USING THE STORE:
|
||||
@@ -31,6 +33,10 @@ function timestamp() {
|
||||
return Math.round(new Date().getTime() / 1000)
|
||||
}
|
||||
|
||||
const response = await fetch('/version.json')
|
||||
const version = await response.json()
|
||||
console.log('version', version)
|
||||
|
||||
export const useStore = defineStore('app', ()=> {
|
||||
const time = ref(timestamp())
|
||||
console.log('starting clock')
|
||||
@@ -43,7 +49,7 @@ export const useStore = defineStore('app', ()=> {
|
||||
const nav = ref(false) // controls opening navigation drawer
|
||||
|
||||
const _chainId = ref(null)
|
||||
const _chainInfo = ref({})
|
||||
const _chainInfo = ref(version.chainInfo)
|
||||
|
||||
function getTokenList() {
|
||||
const chains = _chainId.value in _chainInfo.value && _chainInfo.value[_chainId.value].tokens !== undefined ?
|
||||
@@ -81,7 +87,7 @@ export const useStore = defineStore('app', ()=> {
|
||||
get() {_providerTouch.value; return _provider},
|
||||
set(v) {_provider=v; _providerTouch.value = !_providerTouch.value}
|
||||
})
|
||||
const vaultInitCodeHash = ref(null)
|
||||
const vaultInitCodeHash = computed(() => !chain.value ? null : chain.value.vaultInitCodeHash)
|
||||
const account = ref(null)
|
||||
const vaults = ref([])
|
||||
const transactionSenders = ref([]) // a list of function(signer) that send transactions
|
||||
@@ -92,9 +98,10 @@ export const useStore = defineStore('app', ()=> {
|
||||
const orders = ref({}) // indexed by vault value is another dictionary with orderIndex as key and order status values
|
||||
|
||||
const vault = computed(() => vaults.value.length === 0 ? null : vaults.value[0])
|
||||
const balances = computed( () => vault.value === null ? {} : vaultBalances.value[vault] || {} )
|
||||
const tokens = computed(getTokens)
|
||||
const factory = computed(() => !chain.value ? null : chain.value.factory)
|
||||
const helper = computed(() => !chain.value ? null : chain.value.helper)
|
||||
const helper = computed(() => {console.log('chain helper', chain.value); return !chain.value ? null : chain.value.helper})
|
||||
const mockenv = computed(() => !chain.value ? null : chain.value.mockenv)
|
||||
const mockCoins = computed(() => !chain.value ? [] : !chain.value.mockCoins ? [] : chain.value.mockCoins)
|
||||
|
||||
@@ -122,7 +129,7 @@ export const useStore = defineStore('app', ()=> {
|
||||
return {
|
||||
nav, chainId, chainInfo, chain, provider, vaultInitCodeHash, account, vaults, transactionSenders, errors,
|
||||
extraTokens, poolPrices, vaultBalances, orders, vault, tokens, factory, helper, mockenv, mockCoins,
|
||||
removeTransactionSender, error, closeError, addToken, time,
|
||||
removeTransactionSender, error, closeError, addToken, time, balances,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user