Update build webui

This commit is contained in:
2025-02-01 17:06:36 +07:00
parent 31f9d6ab5d
commit 7b02aeb68e
4 changed files with 16 additions and 1201 deletions

View File

@@ -1,9 +1,14 @@
ARG NODE_VERSION=17 ARG NODE_VERSION=17
ARG ALPINE_VERSION=3.19.0 ARG ALPINE_VERSION=3.19.0
FROM node:${NODE_VERSION}-alpine AS node FROM node:${NODE_VERSION}-alpine AS node
FROM alpine:${ALPINE_VERSION} AS builder FROM alpine:${ALPINE_VERSION} AS builder
# Set the working directory in the container
WORKDIR /app
COPY --from=node /usr/lib /usr/lib COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/lib /usr/local/lib COPY --from=node /usr/local/lib /usr/local/lib
@@ -12,12 +17,14 @@ COPY --from=node /usr/local/bin /usr/local/bin
RUN node -v RUN node -v
# Set the working directory in the container
WORKDIR /app
# Copy the package.json and package-lock.json first to leverage Docker's cache # Copy the package.json and package-lock.json first to leverage Docker's cache
COPY ./src/Managing.WebApp/package*.json ./ COPY /src/Managing.WebApp/package.json ./
#RUN npm config set registry http://registry.cnpmjs.org
# Install dependencies
#RUN npm ci --production --loglevel=verbose
#RUN npm i --omit=dev --loglevel=verbose
RUN apk update && apk add --no-cache git RUN apk update && apk add --no-cache git
# Remove Yarn and Yarnpkg binaries if they exist # Remove Yarn and Yarnpkg binaries if they exist
RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg
@@ -25,23 +32,20 @@ RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg
# Install Yarn globally # Install Yarn globally
RUN npm install -g yarn RUN npm install -g yarn
# Clear Yarn cache
RUN yarn cache clean
# Use npm registry #RUN npm i --max-old-space-size=12000 --loglevel=verbose
RUN yarn config set registry https://registry.npmjs.org/ RUN yarn add eslint-plugin-jsdoc@37.9.7 --dev --ignore-engines
# Install dependencies
RUN yarn install --verbose RUN yarn install --verbose
# Copy the application code # Copy the application code
COPY ./src/Managing.WebApp/ /app/ COPY src/Managing.WebApp/ /app/
RUN ls -alh RUN ls -alh
RUN ls -alh src/ RUN ls -alh src/
# Build the Vite application # Build the Vite application
#RUN npm run build
RUN node --max-old-space-size=8192 ./node_modules/.bin/vite build RUN node --max-old-space-size=8192 ./node_modules/.bin/vite build
# Stage 2: Create the runtime image # Stage 2: Create the runtime image
FROM nginx:alpine FROM nginx:alpine

View File

@@ -1,338 +0,0 @@
/* eslint-disable */
/* tslint:disable */
/**
* Mock Service Worker (0.36.5).
* @see https://github.com/mswjs/msw
* - Please do NOT modify this file.
* - Please do NOT serve this file on production.
*/
const INTEGRITY_CHECKSUM = '02f4ad4a2797f85668baf196e553d929'
const bypassHeaderName = 'x-msw-bypass'
const activeClientIds = new Set()
self.addEventListener('install', function () {
return self.skipWaiting()
})
self.addEventListener('activate', async function (event) {
return self.clients.claim()
})
self.addEventListener('message', async function (event) {
const clientId = event.source.id
if (!clientId || !self.clients) {
return
}
const client = await self.clients.get(clientId)
if (!client) {
return
}
const allClients = await self.clients.matchAll()
switch (event.data) {
case 'KEEPALIVE_REQUEST': {
sendToClient(client, {
type: 'KEEPALIVE_RESPONSE',
})
break
}
case 'INTEGRITY_CHECK_REQUEST': {
sendToClient(client, {
type: 'INTEGRITY_CHECK_RESPONSE',
payload: INTEGRITY_CHECKSUM,
})
break
}
case 'MOCK_ACTIVATE': {
activeClientIds.add(clientId)
sendToClient(client, {
type: 'MOCKING_ENABLED',
payload: true,
})
break
}
case 'MOCK_DEACTIVATE': {
activeClientIds.delete(clientId)
break
}
case 'CLIENT_CLOSED': {
activeClientIds.delete(clientId)
const remainingClients = allClients.filter((client) => {
return client.id !== clientId
})
// Unregister itself when there are no more clients
if (remainingClients.length === 0) {
self.registration.unregister()
}
break
}
}
})
// Resolve the "main" client for the given event.
// Client that issues a request doesn't necessarily equal the client
// that registered the worker. It's with the latter the worker should
// communicate with during the response resolving phase.
async function resolveMainClient(event) {
const client = await self.clients.get(event.clientId)
if (client.frameType === 'top-level') {
return client
}
const allClients = await self.clients.matchAll()
return allClients
.filter((client) => {
// Get only those clients that are currently visible.
return client.visibilityState === 'visible'
})
.find((client) => {
// Find the client ID that's recorded in the
// set of clients that have registered the worker.
return activeClientIds.has(client.id)
})
}
async function handleRequest(event, requestId) {
const client = await resolveMainClient(event)
const response = await getResponse(event, client, requestId)
// Send back the response clone for the "response:*" life-cycle events.
// Ensure MSW is active and ready to handle the message, otherwise
// this message will pend indefinitely.
if (client && activeClientIds.has(client.id)) {
;(async function () {
const clonedResponse = response.clone()
sendToClient(client, {
type: 'RESPONSE',
payload: {
requestId,
type: clonedResponse.type,
ok: clonedResponse.ok,
status: clonedResponse.status,
statusText: clonedResponse.statusText,
body:
clonedResponse.body === null ? null : await clonedResponse.text(),
headers: serializeHeaders(clonedResponse.headers),
redirected: clonedResponse.redirected,
},
})
})()
}
return response
}
async function getResponse(event, client, requestId) {
const { request } = event
const requestClone = request.clone()
const getOriginalResponse = () => fetch(requestClone)
// Bypass mocking when the request client is not active.
if (!client) {
return getOriginalResponse()
}
// Bypass initial page load requests (i.e. static assets).
// The absence of the immediate/parent client in the map of the active clients
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
// and is not ready to handle requests.
if (!activeClientIds.has(client.id)) {
return await getOriginalResponse()
}
// Bypass requests with the explicit bypass header
if (requestClone.headers.get(bypassHeaderName) === 'true') {
const cleanRequestHeaders = serializeHeaders(requestClone.headers)
// Remove the bypass header to comply with the CORS preflight check.
delete cleanRequestHeaders[bypassHeaderName]
const originalRequest = new Request(requestClone, {
headers: new Headers(cleanRequestHeaders),
})
return fetch(originalRequest)
}
// Send the request to the client-side MSW.
const reqHeaders = serializeHeaders(request.headers)
const body = await request.text()
const clientMessage = await sendToClient(client, {
type: 'REQUEST',
payload: {
id: requestId,
url: request.url,
method: request.method,
headers: reqHeaders,
cache: request.cache,
mode: request.mode,
credentials: request.credentials,
destination: request.destination,
integrity: request.integrity,
redirect: request.redirect,
referrer: request.referrer,
referrerPolicy: request.referrerPolicy,
body,
bodyUsed: request.bodyUsed,
keepalive: request.keepalive,
},
})
switch (clientMessage.type) {
case 'MOCK_SUCCESS': {
return delayPromise(
() => respondWithMock(clientMessage),
clientMessage.payload.delay,
)
}
case 'MOCK_NOT_FOUND': {
return getOriginalResponse()
}
case 'NETWORK_ERROR': {
const { name, message } = clientMessage.payload
const networkError = new Error(message)
networkError.name = name
// Rejecting a request Promise emulates a network error.
throw networkError
}
case 'INTERNAL_ERROR': {
const parsedBody = JSON.parse(clientMessage.payload.body)
console.error(
`\
[MSW] Uncaught exception in the request handler for "%s %s":
${parsedBody.location}
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
`,
request.method,
request.url,
)
return respondWithMock(clientMessage)
}
}
return getOriginalResponse()
}
self.addEventListener('fetch', function (event) {
const { request } = event
const accept = request.headers.get('accept') || ''
// Bypass server-sent events.
if (accept.includes('text/event-stream')) {
return
}
// Bypass navigation requests.
if (request.mode === 'navigate') {
return
}
// Opening the DevTools triggers the "only-if-cached" request
// that cannot be handled by the worker. Bypass such requests.
if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
return
}
// Bypass all requests when there are no active clients.
// Prevents the self-unregistered worked from handling requests
// after it's been deleted (still remains active until the next reload).
if (activeClientIds.size === 0) {
return
}
const requestId = uuidv4()
return event.respondWith(
handleRequest(event, requestId).catch((error) => {
if (error.name === 'NetworkError') {
console.warn(
'[MSW] Successfully emulated a network error for the "%s %s" request.',
request.method,
request.url,
)
return
}
// At this point, any exception indicates an issue with the original request/response.
console.error(
`\
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
request.method,
request.url,
`${error.name}: ${error.message}`,
)
}),
)
})
function serializeHeaders(headers) {
const reqHeaders = {}
headers.forEach((value, name) => {
reqHeaders[name] = reqHeaders[name]
? [].concat(reqHeaders[name]).concat(value)
: value
})
return reqHeaders
}
function sendToClient(client, message) {
return new Promise((resolve, reject) => {
const channel = new MessageChannel()
channel.port1.onmessage = (event) => {
if (event.data && event.data.error) {
return reject(event.data.error)
}
resolve(event.data)
}
client.postMessage(JSON.stringify(message), [channel.port2])
})
}
function delayPromise(cb, duration) {
return new Promise((resolve) => {
setTimeout(() => resolve(cb()), duration)
})
}
function respondWithMock(clientMessage) {
return new Response(clientMessage.payload.body, {
...clientMessage.payload,
headers: clientMessage.payload.headers,
})
}
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0
const v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}

View File

@@ -23,7 +23,6 @@
"@wagmi/connectors": "^4.3.2", "@wagmi/connectors": "^4.3.2",
"@wagmi/core": "^2.9.0", "@wagmi/core": "^2.9.0",
"@walletconnect/universal-provider": "^2.8.6", "@walletconnect/universal-provider": "^2.8.6",
"axios": "^0.27.2",
"classnames": "^2.3.1", "classnames": "^2.3.1",
"connectkit": "^1.7.3", "connectkit": "^1.7.3",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
@@ -52,14 +51,6 @@
"zustand": "^4.4.1" "zustand": "^4.4.1"
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.0",
"@tailwindcss/forms": "^0.5.1",
"@tailwindcss/line-clamp": "^0.4.0",
"@tailwindcss/typography": "^0.5.2",
"@tanstack/eslint-plugin-query": "^4.34.1",
"@testing-library/dom": "^8.13.0",
"@testing-library/react": "^13.2.0",
"@types/jest": "^27.5.1",
"@types/react": "^18.0.9", "@types/react": "^18.0.9",
"@types/react-dom": "^18.0.4", "@types/react-dom": "^18.0.4",
"@types/react-grid-layout": "^1.3.2", "@types/react-grid-layout": "^1.3.2",
@@ -74,25 +65,9 @@
"all-contributors-cli": "^6.20.0", "all-contributors-cli": "^6.20.0",
"autoprefixer": "^10.4.7", "autoprefixer": "^10.4.7",
"daisyui": "^3.5.1", "daisyui": "^3.5.1",
"esbuild-jest": "^0.4.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-typescript": "^3.0.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.0.0",
"jest-watch-typeahead": "^1.1.0",
"node-notifier": "^10.0.1",
"postcss": "^8.4.13", "postcss": "^8.4.13",
"prettier": "^2.6.1", "prettier": "^2.6.1",
"prettier-plugin-tailwind-css": "^1.5.0", "prettier-plugin-tailwind-css": "^1.5.0",
"rimraf": "^3.0.2",
"serve": "^14.2.0",
"tailwindcss": "^3.0.23", "tailwindcss": "^3.0.23",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"vite": "^4.4.9", "vite": "^4.4.9",

View File

@@ -1,826 +0,0 @@
import {useAccount} from "wagmi";
import {getContract} from "config/contracts";
import {
BORROWING_EXPONENT_FACTOR_KEY,
BORROWING_FACTOR_KEY,
CLAIMABLE_FUNDING_AMOUNT,
FUNDING_DECREASE_FACTOR_PER_SECOND,
FUNDING_EXPONENT_FACTOR_KEY,
FUNDING_FACTOR_KEY,
FUNDING_INCREASE_FACTOR_PER_SECOND,
IS_MARKET_DISABLED_KEY,
MAX_FUNDING_FACTOR_PER_SECOND,
MAX_OPEN_INTEREST_KEY,
MAX_PNL_FACTOR_FOR_TRADERS_KEY,
MAX_PNL_FACTOR_KEY,
MAX_POOL_AMOUNT_KEY,
MAX_POOL_USD_FOR_DEPOSIT_KEY,
MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY,
MAX_POSITION_IMPACT_FACTOR_KEY,
MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY,
MIN_COLLATERAL_FACTOR_KEY,
MIN_FUNDING_FACTOR_PER_SECOND,
MIN_POSITION_IMPACT_POOL_AMOUNT_KEY,
OPEN_INTEREST_IN_TOKENS_KEY,
OPEN_INTEREST_KEY,
OPEN_INTEREST_RESERVE_FACTOR_KEY,
POOL_AMOUNT_ADJUSTMENT_KEY,
POOL_AMOUNT_KEY,
POSITION_FEE_FACTOR_KEY,
POSITION_IMPACT_EXPONENT_FACTOR_KEY,
POSITION_IMPACT_FACTOR_KEY,
POSITION_IMPACT_POOL_AMOUNT_KEY,
POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY,
RESERVE_FACTOR_KEY,
SWAP_FEE_FACTOR_KEY,
SWAP_IMPACT_EXPONENT_FACTOR_KEY,
SWAP_IMPACT_FACTOR_KEY,
SWAP_IMPACT_POOL_AMOUNT_KEY,
THRESHOLD_FOR_DECREASE_FUNDING,
THRESHOLD_FOR_STABLE_FUNDING,
VIRTUAL_MARKET_ID_KEY,
VIRTUAL_TOKEN_ID_KEY,
} from "config/dataStore";
import {convertTokenAddress} from "config/tokens";
import {useMulticall} from "lib/multicall";
import {hashDataMapAsync} from "lib/multicall/hashDataAsync";
import {BN_ONE} from "lib/numbers";
import {getByKey} from "lib/objects";
import {TokensData, useTokensDataRequest} from "../tokens";
import {MarketsInfoData} from "./types";
import {useMarkets} from "./useMarkets";
import {getContractMarketPrices} from "./utils";
import DataStore from "abis/DataStore.json";
import SyntheticsReader from "abis/SyntheticsReader.json";
export type MarketsInfoResult = {
marketsInfoData?: MarketsInfoData;
tokensData?: TokensData;
pricesUpdatedAt?: number;
};
export function useMarketsInfoRequest(chainId: number): MarketsInfoResult {
const {address: account} = useAccount();
const {marketsData, marketsAddresses} = useMarkets(chainId);
const {tokensData, pricesUpdatedAt} = useTokensDataRequest(chainId);
const dataStoreAddress = getContract(chainId, "DataStore");
const isDepencenciesLoading = !marketsAddresses || !tokensData;
const {data} = useMulticall(chainId, "useMarketsInfo", {
inWorker: true,
key: !isDepencenciesLoading &&
marketsAddresses.length > 0 && [marketsAddresses.join("-"), dataStoreAddress, account, pricesUpdatedAt],
// Refreshed on every prices update
refreshInterval: null,
clearUnusedKeys: true,
keepPreviousData: true,
request: async () => {
const request = {};
const promises = (marketsAddresses || []).map(async (marketAddress) => {
const market = getByKey(marketsData, marketAddress)!;
const marketPrices = getContractMarketPrices(tokensData!, market)!;
if (!marketPrices) {
// eslint-disable-next-line no-console
console.warn("missed market prices", market);
return;
}
const marketProps = {
marketToken: market.marketTokenAddress,
indexToken: market.indexTokenAddress,
longToken: market.longTokenAddress,
shortToken: market.shortTokenAddress,
};
request[`${marketAddress}-reader`] = {
contractAddress: getContract(chainId, "SyntheticsReader"),
abi: SyntheticsReader.abi,
calls: {
marketInfo: {
methodName: "getMarketInfo",
params: [dataStoreAddress, marketPrices, marketAddress],
},
marketTokenPriceMax: {
methodName: "getMarketTokenPrice",
params: [
dataStoreAddress,
marketProps,
marketPrices.indexTokenPrice,
marketPrices.longTokenPrice,
marketPrices.shortTokenPrice,
MAX_PNL_FACTOR_FOR_TRADERS_KEY,
true,
],
},
marketTokenPriceMin: {
methodName: "getMarketTokenPrice",
params: [
dataStoreAddress,
marketProps,
marketPrices.indexTokenPrice,
marketPrices.longTokenPrice,
marketPrices.shortTokenPrice,
MAX_PNL_FACTOR_FOR_TRADERS_KEY,
false,
],
},
},
};
const hashedKeys = await hashDataMapAsync({
isDisabled: [
["bytes32", "address"],
[IS_MARKET_DISABLED_KEY, marketAddress],
],
longPoolAmount: [
["bytes32", "address", "address"],
[POOL_AMOUNT_KEY, marketAddress, market.longTokenAddress],
],
shortPoolAmount: [
["bytes32", "address", "address"],
[POOL_AMOUNT_KEY, marketAddress, market.shortTokenAddress],
],
maxLongPoolAmount: [
["bytes32", "address", "address"],
[MAX_POOL_AMOUNT_KEY, marketAddress, market.longTokenAddress],
],
maxShortPoolAmount: [
["bytes32", "address", "address"],
[MAX_POOL_AMOUNT_KEY, marketAddress, market.shortTokenAddress],
],
maxLongPoolUsdForDeposit: [
["bytes32", "address", "address"],
[MAX_POOL_USD_FOR_DEPOSIT_KEY, marketAddress, market.longTokenAddress],
],
maxShortPoolUsdForDeposit: [
["bytes32", "address", "address"],
[MAX_POOL_USD_FOR_DEPOSIT_KEY, marketAddress, market.shortTokenAddress],
],
longPoolAmountAdjustment: [
["bytes32", "address", "address"],
[POOL_AMOUNT_ADJUSTMENT_KEY, marketAddress, market.longTokenAddress],
],
shortPoolAmountAdjustment: [
["bytes32", "address", "address"],
[POOL_AMOUNT_ADJUSTMENT_KEY, marketAddress, market.shortTokenAddress],
],
reserveFactorLong: [
["bytes32", "address", "bool"],
[RESERVE_FACTOR_KEY, marketAddress, true],
],
reserveFactorShort: [
["bytes32", "address", "bool"],
[RESERVE_FACTOR_KEY, marketAddress, false],
],
openInterestReserveFactorLong: [
["bytes32", "address", "bool"],
[OPEN_INTEREST_RESERVE_FACTOR_KEY, marketAddress, true],
],
openInterestReserveFactorShort: [
["bytes32", "address", "bool"],
[OPEN_INTEREST_RESERVE_FACTOR_KEY, marketAddress, false],
],
maxOpenInterestLong: [
["bytes32", "address", "bool"],
[MAX_OPEN_INTEREST_KEY, marketAddress, true],
],
maxOpenInterestShort: [
["bytes32", "address", "bool"],
[MAX_OPEN_INTEREST_KEY, marketAddress, false],
],
positionImpactPoolAmount: [
["bytes32", "address"],
[POSITION_IMPACT_POOL_AMOUNT_KEY, marketAddress],
],
minPositionImpactPoolAmount: [
["bytes32", "address"],
[MIN_POSITION_IMPACT_POOL_AMOUNT_KEY, marketAddress],
],
positionImpactPoolDistributionRate: [
["bytes32", "address"],
[POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY, marketAddress],
],
swapImpactPoolAmountLong: [
["bytes32", "address", "address"],
[SWAP_IMPACT_POOL_AMOUNT_KEY, marketAddress, market.longTokenAddress],
],
swapImpactPoolAmountShort: [
["bytes32", "address", "address"],
[SWAP_IMPACT_POOL_AMOUNT_KEY, marketAddress, market.shortTokenAddress],
],
borrowingFactorLong: [
["bytes32", "address", "bool"],
[BORROWING_FACTOR_KEY, marketAddress, true],
],
borrowingFactorShort: [
["bytes32", "address", "bool"],
[BORROWING_FACTOR_KEY, marketAddress, false],
],
borrowingExponentFactorLong: [
["bytes32", "address", "bool"],
[BORROWING_EXPONENT_FACTOR_KEY, marketAddress, true],
],
borrowingExponentFactorShort: [
["bytes32", "address", "bool"],
[BORROWING_EXPONENT_FACTOR_KEY, marketAddress, false],
],
fundingFactor: [
["bytes32", "address"],
[FUNDING_FACTOR_KEY, marketAddress],
],
fundingExponentFactor: [
["bytes32", "address"],
[FUNDING_EXPONENT_FACTOR_KEY, marketAddress],
],
fundingIncreaseFactorPerSecond: [
["bytes32", "address"],
[FUNDING_INCREASE_FACTOR_PER_SECOND, marketAddress],
],
fundingDecreaseFactorPerSecond: [
["bytes32", "address"],
[FUNDING_DECREASE_FACTOR_PER_SECOND, marketAddress],
],
thresholdForStableFunding: [
["bytes32", "address"],
[THRESHOLD_FOR_STABLE_FUNDING, marketAddress],
],
thresholdForDecreaseFunding: [
["bytes32", "address"],
[THRESHOLD_FOR_DECREASE_FUNDING, marketAddress],
],
minFundingFactorPerSecond: [
["bytes32", "address"],
[MIN_FUNDING_FACTOR_PER_SECOND, marketAddress],
],
maxFundingFactorPerSecond: [
["bytes32", "address"],
[MAX_FUNDING_FACTOR_PER_SECOND, marketAddress],
],
maxPnlFactorForTradersLong: [
["bytes32", "bytes32", "address", "bool"],
[MAX_PNL_FACTOR_KEY, MAX_PNL_FACTOR_FOR_TRADERS_KEY, marketAddress, true],
],
maxPnlFactorForTradersShort: [
["bytes32", "bytes32", "address", "bool"],
[MAX_PNL_FACTOR_KEY, MAX_PNL_FACTOR_FOR_TRADERS_KEY, marketAddress, false],
],
claimableFundingAmountLong: account
? [
["bytes32", "address", "address", "address"],
[CLAIMABLE_FUNDING_AMOUNT, marketAddress, market.longTokenAddress, account],
]
: undefined,
claimableFundingAmountShort: account
? [
["bytes32", "address", "address", "address"],
[CLAIMABLE_FUNDING_AMOUNT, marketAddress, market.shortTokenAddress, account],
]
: undefined,
positionFeeFactorForPositiveImpact: [
["bytes32", "address", "bool"],
[POSITION_FEE_FACTOR_KEY, marketAddress, true],
],
positionFeeFactorForNegativeImpact: [
["bytes32", "address", "bool"],
[POSITION_FEE_FACTOR_KEY, marketAddress, false],
],
positionImpactFactorPositive: [
["bytes32", "address", "bool"],
[POSITION_IMPACT_FACTOR_KEY, marketAddress, true],
],
positionImpactFactorNegative: [
["bytes32", "address", "bool"],
[POSITION_IMPACT_FACTOR_KEY, marketAddress, false],
],
maxPositionImpactFactorPositive: [
["bytes32", "address", "bool"],
[MAX_POSITION_IMPACT_FACTOR_KEY, marketAddress, true],
],
maxPositionImpactFactorNegative: [
["bytes32", "address", "bool"],
[MAX_POSITION_IMPACT_FACTOR_KEY, marketAddress, false],
],
maxPositionImpactFactorForLiquidations: [
["bytes32", "address"],
[MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY, marketAddress],
],
minCollateralFactor: [
["bytes32", "address"],
[MIN_COLLATERAL_FACTOR_KEY, marketAddress],
],
minCollateralFactorForOpenInterestLong: [
["bytes32", "address", "bool"],
[MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY, marketAddress, true],
],
minCollateralFactorForOpenInterestShort: [
["bytes32", "address", "bool"],
[MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY, marketAddress, false],
],
positionImpactExponentFactor: [
["bytes32", "address"],
[POSITION_IMPACT_EXPONENT_FACTOR_KEY, marketAddress],
],
swapFeeFactorForPositiveImpact: [
["bytes32", "address", "bool"],
[SWAP_FEE_FACTOR_KEY, marketAddress, true],
],
swapFeeFactorForNegativeImpact: [
["bytes32", "address", "bool"],
[SWAP_FEE_FACTOR_KEY, marketAddress, false],
],
swapImpactFactorPositive: [
["bytes32", "address", "bool"],
[SWAP_IMPACT_FACTOR_KEY, marketAddress, true],
],
swapImpactFactorNegative: [
["bytes32", "address", "bool"],
[SWAP_IMPACT_FACTOR_KEY, marketAddress, false],
],
swapImpactExponentFactor: [
["bytes32", "address"],
[SWAP_IMPACT_EXPONENT_FACTOR_KEY, marketAddress],
],
longInterestUsingLongToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_KEY, marketAddress, market.longTokenAddress, true],
],
longInterestUsingShortToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_KEY, marketAddress, market.shortTokenAddress, true],
],
shortInterestUsingLongToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_KEY, marketAddress, market.longTokenAddress, false],
],
shortInterestUsingShortToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_KEY, marketAddress, market.shortTokenAddress, false],
],
longInterestInTokensUsingLongToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_IN_TOKENS_KEY, marketAddress, market.longTokenAddress, true],
],
longInterestInTokensUsingShortToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_IN_TOKENS_KEY, marketAddress, market.shortTokenAddress, true],
],
shortInterestInTokensUsingLongToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_IN_TOKENS_KEY, marketAddress, market.longTokenAddress, false],
],
shortInterestInTokensUsingShortToken: [
["bytes32", "address", "address", "bool"],
[OPEN_INTEREST_IN_TOKENS_KEY, marketAddress, market.shortTokenAddress, false],
],
virtualMarketId: [
["bytes32", "address"],
[VIRTUAL_MARKET_ID_KEY, marketAddress],
],
virtualLongTokenId: [
["bytes32", "address"],
[VIRTUAL_TOKEN_ID_KEY, market.longTokenAddress],
],
virtualShortTokenId: [
["bytes32", "address"],
[VIRTUAL_TOKEN_ID_KEY, market.shortTokenAddress],
],
});
request[`${marketAddress}-dataStore`] = {
contractAddress: dataStoreAddress,
abi: DataStore.abi,
calls: {
isDisabled: {
methodName: "getBool",
params: [hashedKeys.isDisabled],
},
longPoolAmount: {
methodName: "getUint",
params: [hashedKeys.longPoolAmount],
},
shortPoolAmount: {
methodName: "getUint",
params: [hashedKeys.shortPoolAmount],
},
maxLongPoolAmount: {
methodName: "getUint",
params: [hashedKeys.maxLongPoolAmount],
},
maxShortPoolAmount: {
methodName: "getUint",
params: [hashedKeys.maxShortPoolAmount],
},
maxLongPoolUsdForDeposit: {
methodName: "getUint",
params: [hashedKeys.maxLongPoolUsdForDeposit],
},
maxShortPoolUsdForDeposit: {
methodName: "getUint",
params: [hashedKeys.maxShortPoolUsdForDeposit],
},
longPoolAmountAdjustment: {
methodName: "getUint",
params: [hashedKeys.longPoolAmountAdjustment],
},
shortPoolAmountAdjustment: {
methodName: "getUint",
params: [hashedKeys.shortPoolAmountAdjustment],
},
reserveFactorLong: {
methodName: "getUint",
params: [hashedKeys.reserveFactorLong],
},
reserveFactorShort: {
methodName: "getUint",
params: [hashedKeys.reserveFactorShort],
},
openInterestReserveFactorLong: {
methodName: "getUint",
params: [hashedKeys.openInterestReserveFactorLong],
},
openInterestReserveFactorShort: {
methodName: "getUint",
params: [hashedKeys.openInterestReserveFactorShort],
},
maxOpenInterestLong: {
methodName: "getUint",
params: [hashedKeys.maxOpenInterestLong],
},
maxOpenInterestShort: {
methodName: "getUint",
params: [hashedKeys.maxOpenInterestShort],
},
positionImpactPoolAmount: {
methodName: "getUint",
params: [hashedKeys.positionImpactPoolAmount],
},
minPositionImpactPoolAmount: {
methodName: "getUint",
params: [hashedKeys.minPositionImpactPoolAmount],
},
positionImpactPoolDistributionRate: {
methodName: "getUint",
params: [hashedKeys.positionImpactPoolDistributionRate],
},
swapImpactPoolAmountLong: {
methodName: "getUint",
params: [hashedKeys.swapImpactPoolAmountLong],
},
swapImpactPoolAmountShort: {
methodName: "getUint",
params: [hashedKeys.swapImpactPoolAmountShort],
},
borrowingFactorLong: {
methodName: "getUint",
params: [hashedKeys.borrowingFactorLong],
},
borrowingFactorShort: {
methodName: "getUint",
params: [hashedKeys.borrowingFactorShort],
},
borrowingExponentFactorLong: {
methodName: "getUint",
params: [hashedKeys.borrowingExponentFactorLong],
},
borrowingExponentFactorShort: {
methodName: "getUint",
params: [hashedKeys.borrowingExponentFactorShort],
},
fundingFactor: {
methodName: "getUint",
params: [hashedKeys.fundingFactor],
},
fundingExponentFactor: {
methodName: "getUint",
params: [hashedKeys.fundingExponentFactor],
},
fundingIncreaseFactorPerSecond: {
methodName: "getUint",
params: [hashedKeys.fundingIncreaseFactorPerSecond],
},
fundingDecreaseFactorPerSecond: {
methodName: "getUint",
params: [hashedKeys.fundingDecreaseFactorPerSecond],
},
thresholdForStableFunding: {
methodName: "getUint",
params: [hashedKeys.thresholdForStableFunding],
},
thresholdForDecreaseFunding: {
methodName: "getUint",
params: [hashedKeys.thresholdForDecreaseFunding],
},
minFundingFactorPerSecond: {
methodName: "getUint",
params: [hashedKeys.minFundingFactorPerSecond],
},
maxFundingFactorPerSecond: {
methodName: "getUint",
params: [hashedKeys.maxFundingFactorPerSecond],
},
maxPnlFactorForTradersLong: {
methodName: "getUint",
params: [hashedKeys.maxPnlFactorForTradersLong],
},
maxPnlFactorForTradersShort: {
methodName: "getUint",
params: [hashedKeys.maxPnlFactorForTradersShort],
},
claimableFundingAmountLong: account
? {
methodName: "getUint",
params: [hashedKeys.claimableFundingAmountLong],
}
: undefined,
claimableFundingAmountShort: account
? {
methodName: "getUint",
params: [hashedKeys.claimableFundingAmountShort],
}
: undefined,
positionFeeFactorForPositiveImpact: {
methodName: "getUint",
params: [hashedKeys.positionFeeFactorForPositiveImpact],
},
positionFeeFactorForNegativeImpact: {
methodName: "getUint",
params: [hashedKeys.positionFeeFactorForNegativeImpact],
},
positionImpactFactorPositive: {
methodName: "getUint",
params: [hashedKeys.positionImpactFactorPositive],
},
positionImpactFactorNegative: {
methodName: "getUint",
params: [hashedKeys.positionImpactFactorNegative],
},
maxPositionImpactFactorPositive: {
methodName: "getUint",
params: [hashedKeys.maxPositionImpactFactorPositive],
},
maxPositionImpactFactorNegative: {
methodName: "getUint",
params: [hashedKeys.maxPositionImpactFactorNegative],
},
maxPositionImpactFactorForLiquidations: {
methodName: "getUint",
params: [hashedKeys.maxPositionImpactFactorForLiquidations],
},
minCollateralFactor: {
methodName: "getUint",
params: [hashedKeys.minCollateralFactor],
},
minCollateralFactorForOpenInterestLong: {
methodName: "getUint",
params: [hashedKeys.minCollateralFactorForOpenInterestLong],
},
minCollateralFactorForOpenInterestShort: {
methodName: "getUint",
params: [hashedKeys.minCollateralFactorForOpenInterestShort],
},
positionImpactExponentFactor: {
methodName: "getUint",
params: [hashedKeys.positionImpactExponentFactor],
},
swapFeeFactorForPositiveImpact: {
methodName: "getUint",
params: [hashedKeys.swapFeeFactorForPositiveImpact],
},
swapFeeFactorForNegativeImpact: {
methodName: "getUint",
params: [hashedKeys.swapFeeFactorForNegativeImpact],
},
swapImpactFactorPositive: {
methodName: "getUint",
params: [hashedKeys.swapImpactFactorPositive],
},
swapImpactFactorNegative: {
methodName: "getUint",
params: [hashedKeys.swapImpactFactorNegative],
},
swapImpactExponentFactor: {
methodName: "getUint",
params: [hashedKeys.swapImpactExponentFactor],
},
longInterestUsingLongToken: {
methodName: "getUint",
params: [hashedKeys.longInterestUsingLongToken],
},
longInterestUsingShortToken: {
methodName: "getUint",
params: [hashedKeys.longInterestUsingShortToken],
},
shortInterestUsingLongToken: {
methodName: "getUint",
params: [hashedKeys.shortInterestUsingLongToken],
},
shortInterestUsingShortToken: {
methodName: "getUint",
params: [hashedKeys.shortInterestUsingShortToken],
},
longInterestInTokensUsingLongToken: {
methodName: "getUint",
params: [hashedKeys.longInterestInTokensUsingLongToken],
},
longInterestInTokensUsingShortToken: {
methodName: "getUint",
params: [hashedKeys.longInterestInTokensUsingShortToken],
},
shortInterestInTokensUsingLongToken: {
methodName: "getUint",
params: [hashedKeys.shortInterestInTokensUsingLongToken],
},
shortInterestInTokensUsingShortToken: {
methodName: "getUint",
params: [hashedKeys.shortInterestInTokensUsingShortToken],
},
virtualMarketId: {
methodName: "getBytes32",
params: [hashedKeys.virtualMarketId],
},
virtualLongTokenId: {
methodName: "getBytes32",
params: [hashedKeys.virtualLongTokenId],
},
virtualShortTokenId: {
methodName: "getBytes32",
params: [hashedKeys.virtualShortTokenId],
},
},
};
});
await Promise.all(promises);
return request;
},
parseResponse: (res) => {
const result = marketsAddresses!.reduce((acc: MarketsInfoData, marketAddress) => {
const readerErrors = res.errors[`${marketAddress}-reader`];
const dataStoreErrors = res.errors[`${marketAddress}-dataStore`];
const readerValues = res.data[`${marketAddress}-reader`];
const dataStoreValues = res.data[`${marketAddress}-dataStore`];
// Skip invalid market
if (!readerValues || !dataStoreValues || readerErrors || dataStoreErrors) {
// eslint-disable-next-line no-console
console.log("market info error", marketAddress, readerErrors, dataStoreErrors, dataStoreValues);
return acc;
}
const market = getByKey(marketsData, marketAddress)!;
const marketDivisor = market.isSameCollaterals ? BigInt(2) : BN_ONE;
const longInterestUsingLongToken =
BigInt(dataStoreValues.longInterestUsingLongToken.returnValues[0]) / marketDivisor;
const longInterestUsingShortToken =
BigInt(dataStoreValues.longInterestUsingShortToken.returnValues[0]) / marketDivisor;
const shortInterestUsingLongToken =
BigInt(dataStoreValues.shortInterestUsingLongToken.returnValues[0]) / marketDivisor;
const shortInterestUsingShortToken =
BigInt(dataStoreValues.shortInterestUsingShortToken.returnValues[0]) / marketDivisor;
const longInterestUsd = longInterestUsingLongToken + longInterestUsingShortToken;
const shortInterestUsd = shortInterestUsingLongToken + shortInterestUsingShortToken;
const longInterestInTokensUsingLongToken =
BigInt(dataStoreValues.longInterestInTokensUsingLongToken.returnValues[0]) / marketDivisor;
const longInterestInTokensUsingShortToken =
BigInt(dataStoreValues.longInterestInTokensUsingShortToken.returnValues[0]) / marketDivisor;
const shortInterestInTokensUsingLongToken =
BigInt(dataStoreValues.shortInterestInTokensUsingLongToken.returnValues[0]) / marketDivisor;
const shortInterestInTokensUsingShortToken =
BigInt(dataStoreValues.shortInterestInTokensUsingShortToken.returnValues[0]) / marketDivisor;
const longInterestInTokens = longInterestInTokensUsingLongToken + longInterestInTokensUsingShortToken;
const shortInterestInTokens = shortInterestInTokensUsingLongToken + shortInterestInTokensUsingShortToken;
const {nextFunding, virtualInventory} = readerValues.marketInfo.returnValues;
const [, poolValueInfoMin] = readerValues.marketTokenPriceMin.returnValues;
const [, poolValueInfoMax] = readerValues.marketTokenPriceMax.returnValues;
const longToken = getByKey(tokensData!, market.longTokenAddress)!;
const shortToken = getByKey(tokensData!, market.shortTokenAddress)!;
const indexToken = getByKey(tokensData!, convertTokenAddress(chainId, market.indexTokenAddress, "native"))!;
acc[marketAddress] = {
...market,
isDisabled: dataStoreValues.isDisabled.returnValues[0],
longToken,
shortToken,
indexToken,
longInterestUsd,
shortInterestUsd,
longInterestInTokens,
shortInterestInTokens,
longPoolAmount: dataStoreValues.longPoolAmount.returnValues[0] / marketDivisor,
shortPoolAmount: dataStoreValues.shortPoolAmount.returnValues[0] / marketDivisor,
maxLongPoolUsdForDeposit: dataStoreValues.maxLongPoolUsdForDeposit.returnValues[0],
maxShortPoolUsdForDeposit: dataStoreValues.maxShortPoolUsdForDeposit.returnValues[0],
maxLongPoolAmount: dataStoreValues.maxLongPoolAmount.returnValues[0],
maxShortPoolAmount: dataStoreValues.maxShortPoolAmount.returnValues[0],
longPoolAmountAdjustment: dataStoreValues.longPoolAmountAdjustment.returnValues[0],
shortPoolAmountAdjustment: dataStoreValues.shortPoolAmountAdjustment.returnValues[0],
poolValueMin: poolValueInfoMin.poolValue,
poolValueMax: poolValueInfoMax.poolValue,
reserveFactorLong: dataStoreValues.reserveFactorLong.returnValues[0],
reserveFactorShort: dataStoreValues.reserveFactorShort.returnValues[0],
openInterestReserveFactorLong: dataStoreValues.openInterestReserveFactorLong.returnValues[0],
openInterestReserveFactorShort: dataStoreValues.openInterestReserveFactorShort.returnValues[0],
maxOpenInterestLong: dataStoreValues.maxOpenInterestLong.returnValues[0],
maxOpenInterestShort: dataStoreValues.maxOpenInterestShort.returnValues[0],
totalBorrowingFees: poolValueInfoMax.totalBorrowingFees,
positionImpactPoolAmount: dataStoreValues.positionImpactPoolAmount.returnValues[0],
minPositionImpactPoolAmount: dataStoreValues.minPositionImpactPoolAmount.returnValues[0],
positionImpactPoolDistributionRate: dataStoreValues.positionImpactPoolDistributionRate.returnValues[0],
swapImpactPoolAmountLong: dataStoreValues.swapImpactPoolAmountLong.returnValues[0],
swapImpactPoolAmountShort: dataStoreValues.swapImpactPoolAmountShort.returnValues[0],
borrowingFactorLong: dataStoreValues.borrowingFactorLong.returnValues[0],
borrowingFactorShort: dataStoreValues.borrowingFactorShort.returnValues[0],
borrowingExponentFactorLong: dataStoreValues.borrowingExponentFactorLong.returnValues[0],
borrowingExponentFactorShort: dataStoreValues.borrowingExponentFactorShort.returnValues[0],
fundingFactor: dataStoreValues.fundingFactor.returnValues[0],
fundingExponentFactor: dataStoreValues.fundingExponentFactor.returnValues[0],
fundingIncreaseFactorPerSecond: dataStoreValues.fundingIncreaseFactorPerSecond.returnValues[0],
fundingDecreaseFactorPerSecond: dataStoreValues.fundingDecreaseFactorPerSecond.returnValues[0],
thresholdForDecreaseFunding: dataStoreValues.thresholdForDecreaseFunding.returnValues[0],
thresholdForStableFunding: dataStoreValues.thresholdForStableFunding.returnValues[0],
minFundingFactorPerSecond: dataStoreValues.minFundingFactorPerSecond.returnValues[0],
maxFundingFactorPerSecond: dataStoreValues.maxFundingFactorPerSecond.returnValues[0],
pnlLongMax: poolValueInfoMax.longPnl,
pnlLongMin: poolValueInfoMin.longPnl,
pnlShortMax: poolValueInfoMax.shortPnl,
pnlShortMin: poolValueInfoMin.shortPnl,
netPnlMax: poolValueInfoMax.netPnl,
netPnlMin: poolValueInfoMin.netPnl,
maxPnlFactorForTradersLong: dataStoreValues.maxPnlFactorForTradersLong.returnValues[0],
maxPnlFactorForTradersShort: dataStoreValues.maxPnlFactorForTradersShort.returnValues[0],
minCollateralFactor: dataStoreValues.minCollateralFactor.returnValues[0],
minCollateralFactorForOpenInterestLong:
dataStoreValues.minCollateralFactorForOpenInterestLong.returnValues[0],
minCollateralFactorForOpenInterestShort:
dataStoreValues.minCollateralFactorForOpenInterestShort.returnValues[0],
claimableFundingAmountLong: dataStoreValues.claimableFundingAmountLong
? dataStoreValues.claimableFundingAmountLong?.returnValues[0] / marketDivisor
: undefined,
claimableFundingAmountShort: dataStoreValues.claimableFundingAmountShort
? dataStoreValues.claimableFundingAmountShort?.returnValues[0] / marketDivisor
: undefined,
positionFeeFactorForPositiveImpact: dataStoreValues.positionFeeFactorForPositiveImpact.returnValues[0],
positionFeeFactorForNegativeImpact: dataStoreValues.positionFeeFactorForNegativeImpact.returnValues[0],
positionImpactFactorPositive: dataStoreValues.positionImpactFactorPositive.returnValues[0],
positionImpactFactorNegative: dataStoreValues.positionImpactFactorNegative.returnValues[0],
maxPositionImpactFactorPositive: dataStoreValues.maxPositionImpactFactorPositive.returnValues[0],
maxPositionImpactFactorNegative: dataStoreValues.maxPositionImpactFactorNegative.returnValues[0],
maxPositionImpactFactorForLiquidations:
dataStoreValues.maxPositionImpactFactorForLiquidations.returnValues[0],
positionImpactExponentFactor: dataStoreValues.positionImpactExponentFactor.returnValues[0],
swapFeeFactorForPositiveImpact: dataStoreValues.swapFeeFactorForPositiveImpact.returnValues[0],
swapFeeFactorForNegativeImpact: dataStoreValues.swapFeeFactorForNegativeImpact.returnValues[0],
swapImpactFactorPositive: dataStoreValues.swapImpactFactorPositive.returnValues[0],
swapImpactFactorNegative: dataStoreValues.swapImpactFactorNegative.returnValues[0],
swapImpactExponentFactor: dataStoreValues.swapImpactExponentFactor.returnValues[0],
borrowingFactorPerSecondForLongs: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForLongs,
borrowingFactorPerSecondForShorts: readerValues.marketInfo.returnValues.borrowingFactorPerSecondForShorts,
fundingFactorPerSecond: nextFunding.fundingFactorPerSecond,
longsPayShorts: nextFunding.longsPayShorts,
virtualPoolAmountForLongToken: virtualInventory.virtualPoolAmountForLongToken,
virtualPoolAmountForShortToken: virtualInventory.virtualPoolAmountForShortToken,
virtualInventoryForPositions: virtualInventory.virtualInventoryForPositions,
virtualMarketId: dataStoreValues.virtualMarketId.returnValues[0],
virtualLongTokenId: dataStoreValues.virtualLongTokenId.returnValues[0],
virtualShortTokenId: dataStoreValues.virtualShortTokenId.returnValues[0],
};
return acc;
}, {} as MarketsInfoData);
return result;
},
});
return {
marketsInfoData: isDepencenciesLoading ? undefined : data,
tokensData,
pricesUpdatedAt,
};
}