Fix a bit the sdk and trades

This commit is contained in:
2025-05-27 13:47:07 +07:00
parent ebcaff6b5b
commit f743436634
3 changed files with 32 additions and 12 deletions

View File

@@ -6,12 +6,13 @@ import {getByKey} from "../../utils/objects.js";
import {createFindSwapPath, findAllSwapPaths, getWrappedAddress} from "../../utils/swap/swapPath.js";
import {convertToUsd, getIsUnwrap, getIsWrap, getTokensRatioByPrice} from "../../utils/tokens.js";
import {getIncreasePositionAmounts} from "../../utils/trade/amounts.js";
import {getAcceptablePriceInfo} from "../../utils/prices.js";
import {getAcceptablePriceInfo, getOrderThresholdType} from "../../utils/prices.js";
import type {GmxSdk} from "../..";
import {createSwapEstimator, getMarketsGraph} from "../../utils/swap/swapRouting.js";
import {getSwapAmountsByFromValue, getSwapAmountsByToValue} from "../../utils/swap/index.js";
import {EntryField, SidecarSlTpOrderEntryValid} from "../../types/sidecarOrders.js";
import {ethers} from "ethers";
/** Base Optional params for helpers, allows to avoid calling markets, tokens and uiFeeFactor methods if they are already passed */
interface BaseOptionalParams {
@@ -180,9 +181,9 @@ export async function increaseOrderHelper(
collateralDeltaAmount: increaseAmounts.collateralDeltaAmount,
indexPrice: params.stopLossPrice,
collateralPrice: 0n,
acceptablePrice: params.isLong ? 2n ** 256n - 1n : 0n,
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n,
recommendedAcceptablePriceDeltaBps: 50n,
acceptablePrice: params.isLong ? 0n : ethers.MaxUint256,
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps,
recommendedAcceptablePriceDeltaBps: 30n,
estimatedPnl: 0n,
estimatedPnlPercentage: 0n,
realizedPnl: 0n,
@@ -195,7 +196,7 @@ export async function increaseOrderHelper(
fundingFeeUsd: 0n,
swapProfitFeeUsd: 0n,
positionPriceImpactDeltaUsd: 0n,
priceImpactDiffUsd: 0n,
priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd,
payedRemainingCollateralAmount: 0n,
payedOutputUsd: 0n,
payedRemainingCollateralUsd: 0n,
@@ -204,8 +205,11 @@ export async function increaseOrderHelper(
decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
triggerOrderType: OrderType.StopLossDecrease,
triggerPrice: params.stopLossPrice,
triggerThresholdType: getOrderThresholdType(OrderType.StopLossDecrease, params.isLong),
}
console.log(stopLossDecreaseAmounts);
const stopLossEntry: SidecarSlTpOrderEntryValid = {
decreaseAmounts: stopLossDecreaseAmounts,
id: "sl-order",
@@ -255,8 +259,8 @@ export async function increaseOrderHelper(
indexPrice: params.takeProfitPrice, // Keep original trigger price for indexPrice
collateralPrice: 0n, // Consider if this needs calculation
acceptablePrice: acceptablePriceInfo.acceptablePrice,
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, // Add 0.5% buffer to acceptable price impact
recommendedAcceptablePriceDeltaBps: 50n, // Set recommended buffer to 0.5%
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps, // Add 0.5% buffer to acceptable price impact
recommendedAcceptablePriceDeltaBps: 30n, // Set recommended buffer to 0.5%
estimatedPnl: 0n,
estimatedPnlPercentage: 0n,
realizedPnl: 0n,
@@ -269,7 +273,7 @@ export async function increaseOrderHelper(
fundingFeeUsd: 0n,
swapProfitFeeUsd: 0n,
positionPriceImpactDeltaUsd: 0n,
priceImpactDiffUsd: 0n,
priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd,
payedRemainingCollateralAmount: 0n,
payedOutputUsd: 0n,
payedRemainingCollateralUsd: 0n,
@@ -278,6 +282,7 @@ export async function increaseOrderHelper(
decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
triggerOrderType: OrderType.LimitDecrease,
triggerPrice: params.takeProfitPrice,
triggerThresholdType: getOrderThresholdType(OrderType.LimitDecrease, params.isLong),
}
const takeProfitEntry: SidecarSlTpOrderEntryValid = {

View File

@@ -138,7 +138,7 @@ export async function getClientForAddress(
account: account,
oracleUrl: "https://arbitrum-api.gmxinfra.io",
rpcUrl: "https://arb1.arbitrum.io/rpc",
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
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: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB"
@@ -212,7 +212,7 @@ export const openGmxPositionImpl = async (
marketAddress: marketInfo.marketTokenAddress,
payTokenAddress: collateralToken.address,
collateralTokenAddress: collateralToken.address,
allowedSlippageBps: 100, // 1% slippage
allowedSlippageBps: 50, // 0.5% slippage
leverage: leverageBps,
skipSimulation: true,
referralCodeForTxn: encodeReferralCode("kaigen_ai"),