Try to fix proxy

This commit is contained in:
2025-06-10 16:42:30 +07:00
parent ad466ba796
commit 3674783946
4 changed files with 41 additions and 79 deletions

View File

@@ -9,10 +9,8 @@ import {TokensData} from "../../../types/tokens.js";
import {isMarketOrderType} from "../../../utils/orders.js";
import {applySlippageToMinOut} from "../../../utils/trade/index.js";
import {simulateExecuteOrder} from "../../../utils/simulateExecuteOrder.js";
import type {GmxSdk} from "../../..";
import {DEFAULT_UI_FEE_RECEIVER_ACCOUNT} from "../../utils/utils.js";
export type SwapOrderParams = {
fromTokenAddress: string;
@@ -32,15 +30,7 @@ export async function createSwapOrderTxn(sdk: GmxSdk, p: SwapOrderParams) {
const { encodedPayload, totalWntAmount } = await getParams(sdk, p);
const { encodedPayload: simulationEncodedPayload, totalWntAmount: sumaltionTotalWntAmount } = await getParams(sdk, p);
const skipSimulation = true;
if (p.orderType !== OrderType.LimitSwap && skipSimulation !== true) {
await simulateExecuteOrder(sdk, {
primaryPriceOverrides: {},
createMulticallPayload: simulationEncodedPayload,
value: sumaltionTotalWntAmount,
tokensData: p.tokensData,
});
}
await sdk.callContract(
getContract(sdk.chainId, "ExchangeRouter"),
@@ -78,7 +68,7 @@ async function getParams(sdk: GmxSdk, p: SwapOrderParams) {
callbackContract: zeroAddress,
market: zeroAddress,
swapPath: p.swapPath,
uiFeeReceiver: DEFAULT_UI_FEE_RECEIVER_ACCOUNT,
uiFeeReceiver: sdk.config.settings?.uiFeeReceiverAccount ?? zeroAddress,
},
numbers: {
sizeDeltaUsd: 0n,

View File

@@ -1,27 +1,27 @@
import {withRetry} from "viem";
import {
EXECUTION_FEE_CONFIG_V2,
GAS_PRICE_PREMIUM_MAP,
getChain,
MAX_PRIORITY_FEE_PER_GAS_MAP
EXECUTION_FEE_CONFIG_V2,
GAS_PRICE_PREMIUM_MAP,
getChain,
MAX_PRIORITY_FEE_PER_GAS_MAP
} from "../../configs/chains.js";
import {getContract} from "../../configs/contracts.js";
import {
decreaseOrderGasLimitKey,
depositGasLimitKey,
ESTIMATED_GAS_FEE_BASE_AMOUNT_V2_1,
ESTIMATED_GAS_FEE_MULTIPLIER_FACTOR,
ESTIMATED_GAS_FEE_PER_ORACLE_PRICE,
GLV_DEPOSIT_GAS_LIMIT,
GLV_PER_MARKET_GAS_LIMIT,
GLV_WITHDRAWAL_GAS_LIMIT,
increaseOrderGasLimitKey,
shiftGasLimitKey,
singleSwapGasLimitKey,
swapOrderGasLimitKey,
uiFeeFactorKey,
withdrawalGasLimitKey,
decreaseOrderGasLimitKey,
depositGasLimitKey,
ESTIMATED_GAS_FEE_BASE_AMOUNT_V2_1,
ESTIMATED_GAS_FEE_MULTIPLIER_FACTOR,
ESTIMATED_GAS_FEE_PER_ORACLE_PRICE,
GLV_DEPOSIT_GAS_LIMIT,
GLV_PER_MARKET_GAS_LIMIT,
GLV_WITHDRAWAL_GAS_LIMIT,
increaseOrderGasLimitKey,
shiftGasLimitKey,
singleSwapGasLimitKey,
swapOrderGasLimitKey,
uiFeeFactorKey,
withdrawalGasLimitKey,
} from "../../configs/dataStore.js";
import type {DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts, TradeFeesType} from "../../types/trade.js";
@@ -31,16 +31,16 @@ import {TokensData} from "../../types/tokens.js";
import {bigMath} from "../../utils/bigmath.js";
import {estimateOrderOraclePriceCount} from "../../utils/fees/estimateOraclePriceCount.js";
import {
estimateExecuteDecreaseOrderGasLimit,
estimateExecuteIncreaseOrderGasLimit,
estimateExecuteSwapOrderGasLimit,
getExecutionFee,
estimateExecuteDecreaseOrderGasLimit,
estimateExecuteIncreaseOrderGasLimit,
estimateExecuteSwapOrderGasLimit,
getExecutionFee,
} from "../../utils/fees/executionFee.js";
import {getSwapCount} from "../../utils/trade/index.js";
import {Module} from "../base.js";
export const DEFAULT_UI_FEE_RECEIVER_ACCOUNT = "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB";
const DEFAULT_UI_FEE_RECEIVER_ACCOUNT = "0xff00000000000000000000000000000000000001";
export class Utils extends Module {
private _gasLimits: GasLimitsConfig | null = null;
@@ -265,7 +265,7 @@ export class Utils extends Module {
return this._uiFeeFactor;
}
const uiFeeReceiverAccount = DEFAULT_UI_FEE_RECEIVER_ACCOUNT;
const uiFeeReceiverAccount = this.sdk.config.settings?.uiFeeReceiverAccount ?? DEFAULT_UI_FEE_RECEIVER_ACCOUNT;
const uiFeeFactor = await this.sdk
.executeMulticall({

View File

@@ -2,11 +2,7 @@ import fp from 'fastify-plugin'
import {FastifyReply, FastifyRequest} from 'fastify'
import {z} from 'zod'
import {GmxSdk} from '../../generated/gmxsdk/index.js'
import {ApolloClient} from '@apollo/client/core/ApolloClient.js'
import {InMemoryCache} from '@apollo/client/cache/inmemory/inMemoryCache.js'
import {gql} from 'graphql-tag'
import {HttpLink} from '@apollo/client/link/http/HttpLink.js'
import 'cross-fetch/dist/node-polyfill.js' // Required for Apollo Client in Node.js
import {arbitrum} from 'viem/chains';
import {getTokenBySymbol} from '../../generated/gmxsdk/configs/tokens.js';
import {
@@ -37,15 +33,17 @@ import {formatUsd} from '../../generated/gmxsdk/utils/numbers/formatting.js';
import {calculateDisplayDecimals} from '../../generated/gmxsdk/utils/numbers/index.js';
import {handleError} from '../../utils/errorHandler.js';
import {getContract} from '../../generated/gmxsdk/configs/contracts.js';
import {CLAIMABLE_FUNDING_AMOUNT} from '../../generated/gmxsdk/configs/dataStore.js';
import {Abi, zeroHash} from 'viem';
import {hashDataMap, hashString} from '../../generated/gmxsdk/utils/hash.js';
import {CLAIMABLE_FUNDING_AMOUNT} from '../../generated/gmxsdk/configs/dataStore.js';
import {abis} from '../../generated/gmxsdk/abis/index.js';
import {DEFAULT_UI_FEE_RECEIVER_ACCOUNT} from '../../generated/gmxsdk/modules/utils/utils.js'
import {approveContractImpl, getTokenAllowance} from './privy.js';
// Add the missing CLAIMABLE_UI_FEE_AMOUNT constant based on the pattern
export const CLAIMABLE_UI_FEE_AMOUNT = hashString("CLAIMABLE_UI_FEE_AMOUNT");
import {ApolloClient} from '@apollo/client/core/ApolloClient.js'
import {InMemoryCache} from '@apollo/client/cache/inmemory/inMemoryCache.js'
import {gql} from 'graphql-tag'
import {HttpLink} from '@apollo/client/link/http/HttpLink.js'
import 'cross-fetch/dist/node-polyfill.js' // Required for Apollo Client in Node.js
import {approveContractImpl, getTokenAllowance} from './privy.js';
// Cache implementation for markets info data
interface CacheEntry {
@@ -90,6 +88,9 @@ async function getMarketsInfoWithCache(sdk: GmxSdk): Promise<{ marketsInfoData:
return data as { marketsInfoData: MarketsInfoData; tokensData: TokensData };
}
const CLAIMABLE_UI_FEE_AMOUNT = hashString("CLAIMABLE_UI_FEE_AMOUNT");
const UI_FEE_RECEIVER_ACCOUNT = "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB";
/**
* Creates a GraphQL client for the GMX synthetics subgraph
* @param chainId The chain ID to get the client for
@@ -226,7 +227,9 @@ export async function getClientForAddress(
rpcUrl: "https://arb1.arbitrum.io/rpc",
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
settings: {
uiFeeReceiverAccount: UI_FEE_RECEIVER_ACCOUNT
},
markets: {
"0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4": {
isListed: false,
@@ -1627,7 +1630,7 @@ export const getClaimableUiFeesImpl = async (
}
// Get UI fee receiver from SDK config
const uiFeeReceiver = DEFAULT_UI_FEE_RECEIVER_ACCOUNT;
const uiFeeReceiver = UI_FEE_RECEIVER_ACCOUNT;
// Build multicall request for all markets
const multicallRequest = marketAddresses.reduce((request, marketAddress) => {

View File

@@ -149,37 +149,6 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
account
)
})
// Define route to get rebate stats
fastify.get('/rebate-stats', {
schema: {
querystring: Type.Object({
account: Type.String()
}),
response: {
200: Type.Object({
success: Type.Boolean(),
rebateStats: Type.Optional(Type.Object({
totalRebateUsd: Type.Number(),
discountUsd: Type.Number(),
volume: Type.Number(),
tier: Type.Number(),
rebateFactor: Type.Number(),
discountFactor: Type.Number()
})),
error: Type.Optional(Type.String())
})
}
}
}, async (request, reply) => {
const { account } = request.query
// Call the getGmxRebateStats method from the GMX plugin
return request.getGmxRebateStats(
reply,
account
)
})
}
export default plugin