UNPKG

@quantara/sdk

Version:

JavaScript/TypeScript SDK for interacting with Quantara Protocol on Neura Testnet

288 lines (287 loc) 14.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mockExternalSwap = exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.MOCK_GAS_PRICE = exports.usdToToken = void 0; const viem_1 = require("viem"); const factors_1 = require("../configs/factors"); const trade_1 = require("../types/trade"); const markets_1 = require("../utils/markets"); const numbers_1 = require("../utils/numbers"); const tokens_1 = require("../utils/tokens"); function usdToToken(usd, token) { return (0, tokens_1.convertToTokenAmount)((0, numbers_1.expandDecimals)(usd, factors_1.USD_DECIMALS), token.decimals, token.prices?.minPrice); } exports.usdToToken = usdToToken; exports.MOCK_GAS_PRICE = 100000000n; // (0.1 gwei) function mockMarketKeys() { return [ "0x7ADcFFbd657b91Bd38e01607f153F85a9148FCA8", // WANKR/USD [WANKR-USN] "0xfBbE8618684b25b1789Bed13eB51E62c1FA24328", // BTC/USD [BTC-USN] "0xd6749Aaf32866Bd5AfA17297A095Af53E09bB2DD", // ETH/USD [WANKR-USN] ]; } exports.mockMarketKeys = mockMarketKeys; function mockTokensData(overrides = {}) { const tokens = { ...overrides, // Native ANKR token "0x0000000000000000000000000000000000000000": { address: "0x0000000000000000000000000000000000000000", name: "ANKR", symbol: "ANKR", decimals: 18, isNative: true, isTrading: "PYTH:ANKRUSD", priceDecimals: 3, imageUrl: "https://assets.coingecko.com/coins/images/4324/standard/Ankr_Blue_Symbol.png?1754623142", wrappedAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", prices: { minPrice: (0, numbers_1.expandDecimals)(138, 29), // ~$0.138 maxPrice: (0, numbers_1.expandDecimals)(138, 29), }, ...(overrides["0x0000000000000000000000000000000000000000"] || {}), }, // Wrapped ANKR token "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a": { address: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", name: "WANKR", symbol: "WANKR", decimals: 18, isWrapped: true, isTrading: "PYTH:ANKRUSD", priceDecimals: 3, imageUrl: "https://assets.coingecko.com/coins/images/4324/standard/Ankr_Blue_Symbol.png?1754623142", prices: { minPrice: (0, numbers_1.expandDecimals)(138, 29), // ~$0.138 maxPrice: (0, numbers_1.expandDecimals)(138, 29), }, ...(overrides["0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a"] || {}), }, // USN stablecoin "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982": { address: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", name: "Noon USN", symbol: "USN", decimals: 18, isStable: true, imageUrl: "https://assets.coingecko.com/coins/images/53948/standard/Copy_of_USN.png?1748952392", coingeckoUrl: "https://www.coingecko.com/en/coins/noon-usn", explorerUrl: "https://testnet-blockscout.infra.neuraprotocol.io/address/0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", prices: { minPrice: (0, numbers_1.expandDecimals)(1, 30), // $1 maxPrice: (0, numbers_1.expandDecimals)(1, 30), }, ...(overrides["0xF22870a514b0c288A8E0cAf341146fc9E0f3D982"] || {}), }, // Bitcoin "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26": { address: "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", name: "Bitcoin", symbol: "BTC", decimals: 18, imageUrl: "https://assets.coingecko.com/coins/images/1/standard/bitcoin.png?1696501400", coingeckoUrl: "https://www.coingecko.com/en/coins/bitcoin", explorerUrl: "https://testnet-blockscout.infra.neuraprotocol.io/address/0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", prices: { minPrice: (0, numbers_1.expandDecimals)(112500, 30), // ~$112,500 maxPrice: (0, numbers_1.expandDecimals)(112500, 30), }, ...(overrides["0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26"] || {}), }, // Ethereum (synthetic) "0x8C29a7E63723144066ce864B6085B2db538E59D7": { address: "0x8C29a7E63723144066ce864B6085B2db538E59D7", name: "Ethereum", symbol: "ETH", decimals: 18, isSynthetic: true, isTrading: "PYTH:ETHUSD", imageUrl: "https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628", coingeckoUrl: "https://www.coingecko.com/en/coins/ethereum", prices: { minPrice: (0, numbers_1.expandDecimals)(4167, 30), // ~$4,167 maxPrice: (0, numbers_1.expandDecimals)(4167, 30), }, ...(overrides["0x8C29a7E63723144066ce864B6085B2db538E59D7"] || {}), }, }; return tokens; } exports.mockTokensData = mockTokensData; /** * @param marketKeys - array of market addresses */ function mockMarketsData(marketKeys) { const marketConfigs = { "0x7ADcFFbd657b91Bd38e01607f153F85a9148FCA8": { indexTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR longTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, "0xfBbE8618684b25b1789Bed13eB51E62c1FA24328": { indexTokenAddress: "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", // BTC longTokenAddress: "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", // BTC shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, "0xd6749Aaf32866Bd5AfA17297A095Af53E09bB2DD": { indexTokenAddress: "0x8C29a7E63723144066ce864B6085B2db538E59D7", // ETH longTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, }; return marketKeys.reduce((acc, marketAddress) => { const config = marketConfigs[marketAddress]; if (!config) return acc; acc[marketAddress] = { marketTokenAddress: marketAddress, indexTokenAddress: config.indexTokenAddress, longTokenAddress: config.longTokenAddress, shortTokenAddress: config.shortTokenAddress, isSameCollaterals: config.longTokenAddress === config.shortTokenAddress, isSpotOnly: false, data: "", name: "Test Market", }; return acc; }, {}); } exports.mockMarketsData = mockMarketsData; function mockMarketsInfoData(tokensData, marketKeys, overrides = {}) { const marketConfigs = { "0x7ADcFFbd657b91Bd38e01607f153F85a9148FCA8": { indexTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR longTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, "0xfBbE8618684b25b1789Bed13eB51E62c1FA24328": { indexTokenAddress: "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", // BTC longTokenAddress: "0x5e06D1bd47dd726A9bcd637e3D2F86B236e50c26", // BTC shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, "0xd6749Aaf32866Bd5AfA17297A095Af53E09bB2DD": { indexTokenAddress: "0x8C29a7E63723144066ce864B6085B2db538E59D7", // ETH longTokenAddress: "0xBd833b6eCC30CAEaBf81dB18BB0f1e00C6997E7a", // WANKR shortTokenAddress: "0xF22870a514b0c288A8E0cAf341146fc9E0f3D982", // USN }, }; return marketKeys.reduce((acc, marketAddress) => { const config = marketConfigs[marketAddress]; if (!config) return acc; const indexToken = (0, tokens_1.getTokenData)(tokensData, config.indexTokenAddress); const longToken = (0, tokens_1.getTokenData)(tokensData, config.longTokenAddress); const shortToken = (0, tokens_1.getTokenData)(tokensData, config.shortTokenAddress); const isSpotOnly = false; acc[marketAddress] = { isDisabled: false, marketTokenAddress: marketAddress, indexTokenAddress: config.indexTokenAddress, longTokenAddress: config.longTokenAddress, shortTokenAddress: config.shortTokenAddress, isSameCollaterals: config.longTokenAddress === config.shortTokenAddress, isSpotOnly, name: (0, markets_1.getMarketFullName)({ longToken, shortToken, indexToken, isSpotOnly }), longToken, shortToken, indexToken, longPoolAmount: usdToToken(1000, longToken), shortPoolAmount: usdToToken(1000, shortToken), maxLongPoolAmount: usdToToken(10000, longToken), maxShortPoolAmount: usdToToken(10000, shortToken), maxLongPoolUsdForDeposit: usdToToken(10000, longToken), maxShortPoolUsdForDeposit: usdToToken(10000, shortToken), poolValueMax: (0, numbers_1.expandDecimals)(2000, factors_1.USD_DECIMALS), poolValueMin: (0, numbers_1.expandDecimals)(2000, factors_1.USD_DECIMALS), reserveFactorLong: (0, numbers_1.expandDecimals)(5, 29), reserveFactorShort: (0, numbers_1.expandDecimals)(5, 29), openInterestReserveFactorLong: (0, numbers_1.expandDecimals)(5, 29), openInterestReserveFactorShort: (0, numbers_1.expandDecimals)(5, 29), maxOpenInterestLong: (0, numbers_1.expandDecimals)(5, 29), maxOpenInterestShort: (0, numbers_1.expandDecimals)(5, 29), positionImpactPoolAmount: usdToToken(1000, indexToken), positionImpactPoolDistributionRate: 0n, minPositionImpactPoolAmount: 0n, swapImpactPoolAmountLong: usdToToken(1000, longToken), swapImpactPoolAmountShort: usdToToken(1000, shortToken), positionFeeFactorForPositiveImpact: (0, numbers_1.expandDecimals)(5, 26), positionFeeFactorForNegativeImpact: (0, numbers_1.expandDecimals)(5, 26), positionImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23), positionImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23), maxPositionImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23), maxPositionImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23), maxPositionImpactFactorForLiquidations: (0, numbers_1.expandDecimals)(1, 23), positionImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30), swapFeeFactorForPositiveImpact: (0, numbers_1.expandDecimals)(2, 27), swapFeeFactorForNegativeImpact: (0, numbers_1.expandDecimals)(2, 27), atomicSwapFeeFactor: (0, numbers_1.expandDecimals)(2, 27), swapImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23), swapImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23), swapImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30), // MarketInfo borrowingFactorPerSecondForLongs: 0n, borrowingFactorPerSecondForShorts: 0n, borrowingExponentFactorLong: 0n, borrowingExponentFactorShort: 0n, fundingFactor: 0n, fundingExponentFactor: 0n, fundingIncreaseFactorPerSecond: 0n, fundingDecreaseFactorPerSecond: 0n, maxFundingFactorPerSecond: 0n, minFundingFactorPerSecond: 0n, thresholdForDecreaseFunding: 0n, thresholdForStableFunding: 0n, totalBorrowingFees: 0n, minCollateralFactor: 0n, minCollateralFactorForOpenInterestLong: 0n, minCollateralFactorForOpenInterestShort: 0n, longPoolAmountAdjustment: 0n, shortPoolAmountAdjustment: 0n, borrowingFactorLong: 0n, borrowingFactorShort: 0n, fundingFactorPerSecond: 0n, longsPayShorts: false, longInterestUsd: (0, numbers_1.expandDecimals)(500, factors_1.USD_DECIMALS), shortInterestUsd: (0, numbers_1.expandDecimals)(500, factors_1.USD_DECIMALS), longInterestInTokens: usdToToken(500, indexToken), shortInterestInTokens: usdToToken(500, indexToken), maxPnlFactorForTradersLong: (0, numbers_1.expandDecimals)(1, 30), maxPnlFactorForTradersShort: (0, numbers_1.expandDecimals)(1, 30), data: "", virtualPoolAmountForLongToken: 0n, virtualPoolAmountForShortToken: 0n, virtualInventoryForPositions: 0n, virtualMarketId: viem_1.zeroAddress, virtualLongTokenId: viem_1.zeroAddress, virtualShortTokenId: viem_1.zeroAddress, ...(overrides[marketAddress] || {}), }; return acc; }, {}); } exports.mockMarketsInfoData = mockMarketsInfoData; function mockExternalSwap({ inToken, outToken, amountIn, amountOut, priceIn, priceOut, feesUsd = (0, numbers_1.expandDecimals)(5, factors_1.USD_DECIMALS), // $5 default fee data = "0x1", to = "0x1234567890123456789012345678901234567891", receiver = "0x1234567890123456789012345678901234567890", }) { const usdIn = (amountIn * priceIn) / (0, numbers_1.expandDecimals)(1, inToken.decimals); const usdOut = (amountOut * priceOut) / (0, numbers_1.expandDecimals)(1, outToken.decimals); return { aggregator: trade_1.ExternalSwapAggregator.OpenOcean, inTokenAddress: inToken.address, outTokenAddress: outToken.address, receiver, usdIn, usdOut, amountIn, amountOut, priceIn, priceOut, feesUsd, txnData: { to, data, value: 0n, estimatedGas: 100000n, estimatedExecutionFee: 100000n, }, }; } exports.mockExternalSwap = mockExternalSwap;