diff --git a/package-lock.json b/package-lock.json index eb858ac..01ec2eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc6", + "version": "0.20.45", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc6", + "version": "0.20.45", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index aefac43..6a3dea0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc7", + "version": "0.20.42-rc8", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/config/chains.json b/src/config/chains.json index 4fad92a..ea887a8 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -38,6 +38,18 @@ "curveRegistry": "0x93461072c00b2740c474a3d52c70be6249c802d8" } }, + "204": { + "chainId": "204", + "explorer": "http://opbnbscan.com/", + "label": "opBNB Chain", + "shortName": "opBNB", + "code": "opbnb", + "rpc": "https://opbnb-mainnet-rpc.bnbchain.org", + "baseCurrencyName": "BNB", + "contracts": { + "WETH": "0x4200000000000000000000000000000000000006" + } + }, "3": { "chainId": "3", "explorer": "https://ropsten.etherscan.io/", @@ -77,6 +89,19 @@ "curveRegistry": "" } }, + "42161": { + "chainId": "42161", + "explorer": "https://arbiscan.io/", + "label": "Arbitrum", + "shortName": "Arbitrum", + "code": "arb", + "rpc": "https://arb1.arbitrum.io/rpc", + "baseCurrencyName": "ARB", + "contracts": { + "WETH": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", + "curveRegistiry": "0x445FE580eF8d70FF569aB36e80c647af338db351" + } + }, "4002": { "chainId": "4002", "explorer": "https://testnet.ftmscan.com/", diff --git a/src/config/envs.json b/src/config/envs.json index be254cf..8672516 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -93,6 +93,42 @@ "http": "/orion-indexer/" } } + }, + "42161": { + "api": "https://trade.orion.xyz/arbitrum-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } + }, + "204": { + "api": "https://trade.orion.xyz/opbnb-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, diff --git a/src/constants/chains.ts b/src/constants/chains.ts index 790a42d..74135ed 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -15,4 +15,6 @@ export const productionChains = [ SupportedChainId.FANTOM_OPERA, SupportedChainId.POLYGON, SupportedChainId.OKC, + SupportedChainId.ARBITRUM, + SupportedChainId.OPBNB, ]; diff --git a/src/constants/networkCodes.ts b/src/constants/networkCodes.ts index 75fe8ee..d04ac04 100644 --- a/src/constants/networkCodes.ts +++ b/src/constants/networkCodes.ts @@ -1 +1 @@ -export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip'] as const; +export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb'] as const; diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index 019e7cc..d28fc5a 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -1,246 +1,245 @@ -import type { BigNumber } from 'bignumber.js'; -import { z } from 'zod'; +import type {BigNumber} from 'bignumber.js'; +import {z} from 'zod'; import swapInfoSchema from './schemas/swapInfoSchema.js'; import exchangeInfoSchema from './schemas/exchangeInfoSchema.js'; import cancelOrderSchema from './schemas/cancelOrderSchema.js'; import orderBenefitsSchema from './schemas/orderBenefitsSchema.js'; import errorSchema from './schemas/errorSchema.js'; import placeAtomicSwapSchema from './schemas/placeAtomicSwapSchema.js'; -import { AggregatorWS } from './ws'; -import { atomicSwapHistorySchema } from './schemas/atomicSwapHistorySchema.js'; +import {AggregatorWS} from './ws'; +import {atomicSwapHistorySchema} from './schemas/atomicSwapHistorySchema.js'; import type { - BasicAuthCredentials, - NetworkShortName, - SignedCancelOrderRequest, - SignedLockOrder, - SignedOrder + BasicAuthCredentials, + OrderSource, + NetworkShortName, + SignedLockOrder, + SignedCancelOrderRequest, + SignedOrder } from '../../types.js'; import { - pairConfigSchema, aggregatedOrderbookSchema, - exchangeOrderbookSchema, poolReservesSchema, + pairConfigSchema, aggregatedOrderbookSchema, + exchangeOrderbookSchema, poolReservesSchema, } from './schemas/index.js'; import toUpperCase from '../../utils/toUpperCase.js'; import httpToWS from '../../utils/httpToWS.js'; -import { ethers } from 'ethers'; +import {ethers} from 'ethers'; import orderSchema from './schemas/orderSchema.js'; -import { fetchWithValidation } from 'simple-typed-fetch'; +import {fetchWithValidation} from 'simple-typed-fetch'; class Aggregator { - private readonly apiUrl: string; + private readonly apiUrl: string; - readonly ws: AggregatorWS; + readonly ws: AggregatorWS; - private readonly basicAuth?: BasicAuthCredentials | undefined; + private readonly basicAuth?: BasicAuthCredentials | undefined; - get api() { - return this.apiUrl; - } + get api() { + return this.apiUrl; + } - constructor( - httpAPIUrl: string, - wsAPIUrl: string, - basicAuth?: BasicAuthCredentials - ) { - // const oaUrl = new URL(apiUrl); - // const oaWsProtocol = oaUrl.protocol === 'https:' ? 'wss' : 'ws'; - // const aggregatorWsUrl = `${oaWsProtocol}://${oaUrl.host + (oaUrl.pathname === '/' - // ? '' - // : oaUrl.pathname)}/v1`; + constructor( + httpAPIUrl: string, + wsAPIUrl: string, + basicAuth?: BasicAuthCredentials + ) { + // const oaUrl = new URL(apiUrl); + // const oaWsProtocol = oaUrl.protocol === 'https:' ? 'wss' : 'ws'; + // const aggregatorWsUrl = `${oaWsProtocol}://${oaUrl.host + (oaUrl.pathname === '/' + // ? '' + // : oaUrl.pathname)}/v1`; - this.apiUrl = httpAPIUrl; - this.ws = new AggregatorWS(httpToWS(wsAPIUrl)); - this.basicAuth = basicAuth; + this.apiUrl = httpAPIUrl; + this.ws = new AggregatorWS(httpToWS(wsAPIUrl)); + this.basicAuth = basicAuth; - this.getHistoryAtomicSwaps = this.getHistoryAtomicSwaps.bind(this); - this.getPairConfig = this.getPairConfig.bind(this); - this.getPairConfigs = this.getPairConfigs.bind(this); - this.getPairsList = this.getPairsList.bind(this); - this.getSwapInfo = this.getSwapInfo.bind(this); + this.getHistoryAtomicSwaps = this.getHistoryAtomicSwaps.bind(this); + this.getPairConfig = this.getPairConfig.bind(this); + this.getPairConfigs = this.getPairConfigs.bind(this); + this.getPairsList = this.getPairsList.bind(this); + this.getSwapInfo = this.getSwapInfo.bind(this); this.getCrossChainAssetsByNetwork = this.getCrossChainAssetsByNetwork.bind(this); - this.getTradeProfits = this.getTradeProfits.bind(this); - this.placeAtomicSwap = this.placeAtomicSwap.bind(this); - this.placeOrder = this.placeOrder.bind(this); + this.getTradeProfits = this.getTradeProfits.bind(this); + this.placeAtomicSwap = this.placeAtomicSwap.bind(this); + this.placeOrder = this.placeOrder.bind(this); this.placeLockOrder = this.placeLockOrder.bind(this); - this.cancelOrder = this.cancelOrder.bind(this); - this.checkWhitelisted = this.checkWhitelisted.bind(this); - this.getLockedBalance = this.getLockedBalance.bind(this); - this.getAggregatedOrderbook = this.getAggregatedOrderbook.bind(this); - this.getExchangeOrderbook = this.getExchangeOrderbook.bind(this); - this.getPoolReserves = this.getPoolReserves.bind(this); - this.getVersion = this.getVersion.bind(this); - this.getPrices = this.getPrices.bind(this); - } - - get basicAuthHeaders() { - if (this.basicAuth) { - return { - Authorization: `Basic ${btoa(`${this.basicAuth.username}:${this.basicAuth.password}`)}`, - }; + this.cancelOrder = this.cancelOrder.bind(this); + this.checkWhitelisted = this.checkWhitelisted.bind(this); + this.getLockedBalance = this.getLockedBalance.bind(this); + this.getAggregatedOrderbook = this.getAggregatedOrderbook.bind(this); + this.getExchangeOrderbook = this.getExchangeOrderbook.bind(this); + this.getPoolReserves = this.getPoolReserves.bind(this); + this.getVersion = this.getVersion.bind(this); + this.getPrices = this.getPrices.bind(this); } - return {}; - } - getOrder = (orderId: string, owner?: string) => { - if (!ethers.isHexString(orderId)) { - throw new Error(`Invalid order id: ${orderId}. Must be a hex string`); + get basicAuthHeaders() { + if (this.basicAuth) { + return { + Authorization: `Basic ${btoa(`${this.basicAuth.username}:${this.basicAuth.password}`)}`, + }; + } + return {}; } - const url = new URL(`${this.apiUrl}/api/v1/order`); - url.searchParams.append('orderId', orderId); - if (owner !== undefined) { - if (!ethers.isAddress(owner)) { - throw new Error(`Invalid owner address: ${owner}`); - } - url.searchParams.append('owner', owner); + + getOrder = (orderId: string, owner?: string) => { + if (!ethers.isHexString(orderId)) { + throw new Error(`Invalid order id: ${orderId}. Must be a hex string`); + } + const url = new URL(`${this.apiUrl}/api/v1/order`); + url.searchParams.append('orderId', orderId); + if (owner !== undefined) { + if (!ethers.isAddress(owner)) { + throw new Error(`Invalid owner address: ${owner}`); + } + url.searchParams.append('owner', owner); + } + return fetchWithValidation( + url.toString(), + orderSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); } - return fetchWithValidation( - url.toString(), - orderSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - } - getPairsList = (market: 'spot') => { - const url = new URL(`${this.apiUrl}/api/v1/pairs/list`); - url.searchParams.append('market', toUpperCase(market)); + getPairsList = (market: 'spot') => { + const url = new URL(`${this.apiUrl}/api/v1/pairs/list`); + url.searchParams.append('market', toUpperCase(market)); - return fetchWithValidation( - url.toString(), - z.array(z.string().toUpperCase()), - { headers: this.basicAuthHeaders }, - ); - }; - - getAggregatedOrderbook = (pair: string, depth = 20) => { - const url = new URL(`${this.apiUrl}/api/v1/orderbook`); - url.searchParams.append('pair', pair); - url.searchParams.append('depth', depth.toString()); - return fetchWithValidation( - url.toString(), - aggregatedOrderbookSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; - - getAvailableExchanges = () => fetchWithValidation( - `${this.apiUrl}/api/v1/exchange/list`, - z.string().array(), - ); - - getExchangeOrderbook = ( - pair: string, - exchange: string, - depth = 20, - filterByBrokerBalances: boolean | null = null, - ) => { - const url = new URL(`${this.apiUrl}/api/v1/orderbook/${exchange}/${pair}`); - url.searchParams.append('pair', pair); - url.searchParams.append('depth', depth.toString()); - if (filterByBrokerBalances !== null) { - url.searchParams.append('filterByBrokerBalances', filterByBrokerBalances.toString()); - } - return fetchWithValidation( - url.toString(), - exchangeOrderbookSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; - - getPairConfigs = (market: 'spot') => { - const url = new URL(`${this.apiUrl}/api/v1/pairs/exchangeInfo`); - url.searchParams.append('market', toUpperCase(market)); - - return fetchWithValidation( - url.toString(), - exchangeInfoSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - } - - getPoolReserves = ( - pair: string, - exchange: string, - ) => { - const url = new URL(`${this.apiUrl}/api/v1/pools/reserves/${exchange}/${pair}`); - return fetchWithValidation( - url.toString(), - poolReservesSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; - - getVersion = () => fetchWithValidation( - `${this.apiUrl}/api/v1/version`, - z.object({ - serviceName: z.string(), - version: z.string(), - apiVersion: z.string(), - }), - { headers: this.basicAuthHeaders }, - errorSchema, - ); - - getPairConfig = (assetPair: string) => fetchWithValidation( - `${this.apiUrl}/api/v1/pairs/exchangeInfo/${assetPair}`, - pairConfigSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - - checkWhitelisted = (address: string) => fetchWithValidation( - `${this.apiUrl}/api/v1/whitelist/check?address=${address}`, - z.boolean(), - { headers: this.basicAuthHeaders }, - errorSchema, - ); - - placeOrder = ( - signedOrder: SignedOrder, - isCreateInternalOrder: boolean, - isReversedOrder?: boolean, - partnerId?: string, - fromWidget?: boolean, - source?: 'TERMINAL_MARKET' | 'TERMINAL_LIMIT' | 'SWAP_UI', - rawExchangeRestrictions?: string | undefined, - ) => { - const headers = { - 'Content-Type': 'application/json', - Accept: 'application/json', - ...(isReversedOrder !== undefined) && { - 'X-Reverse-Order': isReversedOrder ? 'true' : 'false', - }, - ...(partnerId !== undefined) && { 'X-Partner-Id': partnerId }, - ...(fromWidget !== undefined) && { 'X-From-Widget': fromWidget ? 'true' : 'false' }, - ...(source !== undefined) && { 'X-Source': source }, - ...this.basicAuthHeaders, + return fetchWithValidation( + url.toString(), + z.array(z.string().toUpperCase()), + {headers: this.basicAuthHeaders}, + ); }; - const url = new URL(`${this.apiUrl}/api/v1/order/${isCreateInternalOrder ? 'internal' : ''}`); + getAggregatedOrderbook = (pair: string, depth = 20) => { + const url = new URL(`${this.apiUrl}/api/v1/orderbook`); + url.searchParams.append('pair', pair); + url.searchParams.append('depth', depth.toString()); + return fetchWithValidation( + url.toString(), + aggregatedOrderbookSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; - return fetchWithValidation( - url.toString(), - z.object({ - orderId: z.string(), - placementRequests: z.array( - z.object({ - amount: z.number(), - brokerAddress: z.string(), - exchange: z.string(), - }), - ).optional(), - }), - { - headers, - method: 'POST', - body: JSON.stringify({ ...signedOrder, rawExchangeRestrictions }), - }, - errorSchema, + getAvailableExchanges = () => fetchWithValidation( + `${this.apiUrl}/api/v1/exchange/list`, + z.string().array(), ); - }; + + getExchangeOrderbook = ( + pair: string, + exchange: string, + depth = 20, + filterByBrokerBalances: boolean | null = null, + ) => { + const url = new URL(`${this.apiUrl}/api/v1/orderbook/${exchange}/${pair}`); + url.searchParams.append('pair', pair); + url.searchParams.append('depth', depth.toString()); + if (filterByBrokerBalances !== null) { + url.searchParams.append('filterByBrokerBalances', filterByBrokerBalances.toString()); + } + return fetchWithValidation( + url.toString(), + exchangeOrderbookSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; + + getPairConfigs = (market: 'spot') => { + const url = new URL(`${this.apiUrl}/api/v1/pairs/exchangeInfo`); + url.searchParams.append('market', toUpperCase(market)); + + return fetchWithValidation( + url.toString(), + exchangeInfoSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + } + + getPoolReserves = ( + pair: string, + exchange: string, + ) => { + const url = new URL(`${this.apiUrl}/api/v1/pools/reserves/${exchange}/${pair}`); + return fetchWithValidation( + url.toString(), + poolReservesSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; + + getVersion = () => fetchWithValidation( + `${this.apiUrl}/api/v1/version`, + z.object({ + serviceName: z.string(), + version: z.string(), + apiVersion: z.string(), + }), + {headers: this.basicAuthHeaders}, + errorSchema, + ); + + getPairConfig = (assetPair: string) => fetchWithValidation( + `${this.apiUrl}/api/v1/pairs/exchangeInfo/${assetPair}`, + pairConfigSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + + checkWhitelisted = (address: string) => fetchWithValidation( + `${this.apiUrl}/api/v1/whitelist/check?address=${address}`, + z.boolean(), + {headers: this.basicAuthHeaders}, + errorSchema, + ); + + placeOrder = ( + signedOrder: SignedOrder, + isCreateInternalOrder: boolean, + isReversedOrder?: boolean, + partnerId?: string, + source?: OrderSource, + rawExchangeRestrictions?: string | undefined, + ) => { + const headers = { + 'Content-Type': 'application/json', + Accept: 'application/json', + ...(isReversedOrder !== undefined) && { + 'X-Reverse-Order': isReversedOrder ? 'true' : 'false', + }, + ...(partnerId !== undefined) && {'X-Partner-Id': partnerId}, + ...(source !== undefined) && {'X-Source': source}, + ...this.basicAuthHeaders, + }; + + const url = new URL(`${this.apiUrl}/api/v1/order/${isCreateInternalOrder ? 'internal' : ''}`); + + return fetchWithValidation( + url.toString(), + z.object({ + orderId: z.string(), + placementRequests: z.array( + z.object({ + amount: z.number(), + brokerAddress: z.string(), + exchange: z.string(), + }), + ).optional(), + }), + { + headers, + method: 'POST', + body: JSON.stringify({...signedOrder, rawExchangeRestrictions}), + }, + errorSchema, + ); + }; placeLockOrder = ( signedLockOrder: SignedLockOrder, @@ -275,60 +274,60 @@ class Aggregator { ); }; - cancelOrder = (signedCancelOrderRequest: SignedCancelOrderRequest) => fetchWithValidation( - `${this.apiUrl}/api/v1/order`, - cancelOrderSchema, - { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - ...this.basicAuthHeaders, - }, - body: JSON.stringify({ - ...signedCancelOrderRequest, - sender: signedCancelOrderRequest.senderAddress, - }), - }, - errorSchema, - ); - - getSwapInfo = ( - type: 'exactSpend' | 'exactReceive', - assetIn: string, - assetOut: string, - amount: string, - instantSettlement?: boolean, - exchanges?: string[] | 'cex' | 'pools', - ) => { - const url = new URL(`${this.apiUrl}/api/v1/swap`); - url.searchParams.append('assetIn', assetIn); - url.searchParams.append('assetOut', assetOut); - if (type === 'exactSpend') { - url.searchParams.append('amountIn', amount); - } else { - url.searchParams.append('amountOut', amount); - } - if (exchanges !== undefined) { - if (Array.isArray(exchanges)) { - exchanges.forEach((exchange) => { - url.searchParams.append('exchanges', exchange); - }); - } else { - url.searchParams.append('exchanges', exchanges); - } - } - if (instantSettlement !== undefined && instantSettlement) { - url.searchParams.append('instantSettlement', 'true'); - } - - return fetchWithValidation( - url.toString(), - swapInfoSchema, - { headers: this.basicAuthHeaders }, - errorSchema, + cancelOrder = (signedCancelOrderRequest: SignedCancelOrderRequest) => fetchWithValidation( + `${this.apiUrl}/api/v1/order`, + cancelOrderSchema, + { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + ...this.basicAuthHeaders, + }, + body: JSON.stringify({ + ...signedCancelOrderRequest, + sender: signedCancelOrderRequest.senderAddress, + }), + }, + errorSchema, ); - }; + + getSwapInfo = ( + type: 'exactSpend' | 'exactReceive', + assetIn: string, + assetOut: string, + amount: string, + instantSettlement?: boolean, + exchanges?: string[] | 'cex' | 'pools', + ) => { + const url = new URL(`${this.apiUrl}/api/v1/swap`); + url.searchParams.append('assetIn', assetIn); + url.searchParams.append('assetOut', assetOut); + if (type === 'exactSpend') { + url.searchParams.append('amountIn', amount); + } else { + url.searchParams.append('amountOut', amount); + } + if (exchanges !== undefined) { + if (Array.isArray(exchanges)) { + exchanges.forEach((exchange) => { + url.searchParams.append('exchanges', exchange); + }); + } else { + url.searchParams.append('exchanges', exchanges); + } + } + if (instantSettlement !== undefined && instantSettlement) { + url.searchParams.append('instantSettlement', 'true'); + } + + return fetchWithValidation( + url.toString(), + swapInfoSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; getCrossChainAssetsByNetwork = (sourceChain: NetworkShortName) => { const url = new URL(`${this.apiUrl}/api/v1/cross-chain/assets`); @@ -342,89 +341,90 @@ class Aggregator { ) } - getPrices = (assetPair: string, includePools: boolean) => { - const url = new URL(`${this.apiUrl}/api/v1/prices/`); - url.searchParams.append('assetPair', assetPair); - url.searchParams.append('includePools', includePools.toString()); - return fetchWithValidation( - url.toString(), - z.number(), - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; + getPrices = (assetPair: string, includePools: boolean) => { + const url = new URL(`${this.apiUrl}/api/v1/prices/`); + url.searchParams.append('assetPair', assetPair); + url.searchParams.append('includePools', includePools.toString()); + return fetchWithValidation( + url.toString(), + z.number(), + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; - getLockedBalance = (address: string, currency: string) => { - const url = new URL(`${this.apiUrl}/api/v1/address/balance/reserved/${currency}`); - url.searchParams.append('address', address); - return fetchWithValidation( - url.toString(), - z.object({ - [currency]: z.number(), - }).partial(), - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; + getLockedBalance = (address: string, currency: string) => { + const url = new URL(`${this.apiUrl}/api/v1/address/balance/reserved/${currency}`); + url.searchParams.append('address', address); + return fetchWithValidation( + url.toString(), + z.object({ + [currency]: z.number(), + }).partial(), + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; - getTradeProfits = ( - symbol: string, - amount: BigNumber, - isBuy: boolean, - ) => { - const url = new URL(`${this.apiUrl}/api/v1/orderBenefits`); - url.searchParams.append('symbol', symbol); - url.searchParams.append('amount', amount.toString()); - url.searchParams.append('side', isBuy ? 'buy' : 'sell'); + getTradeProfits = ( + symbol: string, + amount: BigNumber, + isBuy: boolean, + ) => { + const url = new URL(`${this.apiUrl}/api/v1/orderBenefits`); + url.searchParams.append('symbol', symbol); + url.searchParams.append('amount', amount.toString()); + url.searchParams.append('side', isBuy ? 'buy' : 'sell'); - return fetchWithValidation( - url.toString(), - orderBenefitsSchema, - { headers: this.basicAuthHeaders }, - errorSchema, - ); - }; + return fetchWithValidation( + url.toString(), + orderBenefitsSchema, + {headers: this.basicAuthHeaders}, + errorSchema, + ); + }; - /** - * Placing atomic swap. Placement must take place on the target chain. - * @param secretHash Secret hash - * @param sourceNetworkCode uppercase, e.g. BSC, ETH - * @returns Fetch promise - */ - placeAtomicSwap = ( - secretHash: string, + /** + * Placing atomic swap. Placement must take place on the target chain. + * @param secretHash Secret hash + * @param sourceNetworkCode uppercase, e.g. BSC, ETH + * @returns Fetch promise + */ + placeAtomicSwap = ( + secretHash: string, sourceNetworkCode: NetworkShortName, - ) => fetchWithValidation( - `${this.apiUrl}/api/v1/atomic-swap`, - placeAtomicSwapSchema, - { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - ...this.basicAuthHeaders, - }, - method: 'POST', - body: JSON.stringify({ - secretHash, - sourceNetworkCode, - }), - }, - errorSchema, - ); + ) => fetchWithValidation( + `${this.apiUrl}/api/v1/atomic-swap`, + placeAtomicSwapSchema, + { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + ...this.basicAuthHeaders, + }, + method: 'POST', + body: JSON.stringify({ + secretHash, + sourceNetworkCode, + }), + }, + errorSchema, + ); - /** - * Get placed atomic swaps. Each atomic swap received from this list has a target chain corresponding to this Aggregator - * @param sender Sender address + /** + * Get placed atomic swaps. Each atomic swap received from this list has a target chain corresponding to this Aggregator + * @param sender Sender address * @param limit - * @returns Fetch promise - */ - getHistoryAtomicSwaps = (sender: string, limit = 1000) => { - const url = new URL(`${this.apiUrl}/api/v1/atomic-swap/history/all`); - url.searchParams.append('sender', sender); - url.searchParams.append('limit', limit.toString()); - return fetchWithValidation(url.toString(), atomicSwapHistorySchema, { headers: this.basicAuthHeaders }); - }; + * @returns Fetch promise + */ + getHistoryAtomicSwaps = (sender: string, limit = 1000) => { + const url = new URL(`${this.apiUrl}/api/v1/atomic-swap/history/all`); + url.searchParams.append('sender', sender); + url.searchParams.append('limit', limit.toString()); + return fetchWithValidation(url.toString(), atomicSwapHistorySchema, {headers: this.basicAuthHeaders}); + }; } + export * as schemas from './schemas/index.js'; export * as ws from './ws/index.js'; -export { Aggregator }; +export {Aggregator}; diff --git a/src/types.ts b/src/types.ts index 4e72128..01372ae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -106,10 +106,11 @@ export enum SupportedChainId { MAINNET = '1', ROPSTEN = '3', GOERLI = '5', - ARBITRUM_GOERLI = '421613', + ARBITRUM = '42161', FANTOM_OPERA = '250', POLYGON = '137', OKC = '66', + OPBNB = '204', POLYGON_TESTNET = '80001', FANTOM_TESTNET = '4002', @@ -117,6 +118,7 @@ export enum SupportedChainId { BSC_TESTNET = '97', OKC_TESTNET = '65', DRIP_TESTNET = '56303', + ARBITRUM_GOERLI = '421613', // For testing and debug purpose // BROKEN = '0', @@ -477,3 +479,5 @@ export type AtomicSwap = Partial< refundTx?: TransactionInfo | undefined liquidityMigrationTx?: TransactionInfo | undefined } + +export type OrderSource = 'TERMINAL_MARKET' | 'TERMINAL_LIMIT' | 'SWAP_UI' | 'WIDGET';