mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 22:52:36 +03:00
Semantics improvements
This commit is contained in:
@@ -6,7 +6,7 @@ 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 { OrionAggregatorWS } from './ws/index.js';
|
||||
import { AggregatorWS } from './ws/index.js';
|
||||
import { atomicSwapHistorySchema } from './schemas/atomicSwapHistorySchema.js';
|
||||
import type { Exchange, SignedCancelOrderRequest, SignedCFDOrder, SignedOrder } from '../../types.js';
|
||||
import { pairConfigSchema } from './schemas/index.js';
|
||||
@@ -21,10 +21,10 @@ import orderSchema from './schemas/orderSchema.js';
|
||||
import { exchanges } from '../../constants/index.js';
|
||||
import { fetchWithValidation } from 'simple-typed-fetch';
|
||||
|
||||
class OrionAggregator {
|
||||
class Aggregator {
|
||||
private readonly apiUrl: string;
|
||||
|
||||
readonly ws: OrionAggregatorWS;
|
||||
readonly ws: AggregatorWS;
|
||||
|
||||
get api() {
|
||||
return this.apiUrl;
|
||||
@@ -36,12 +36,12 @@ class OrionAggregator {
|
||||
) {
|
||||
// const oaUrl = new URL(apiUrl);
|
||||
// const oaWsProtocol = oaUrl.protocol === 'https:' ? 'wss' : 'ws';
|
||||
// const orionAggregatorWsUrl = `${oaWsProtocol}://${oaUrl.host + (oaUrl.pathname === '/'
|
||||
// const aggregatorWsUrl = `${oaWsProtocol}://${oaUrl.host + (oaUrl.pathname === '/'
|
||||
// ? ''
|
||||
// : oaUrl.pathname)}/v1`;
|
||||
|
||||
this.apiUrl = httpAPIUrl;
|
||||
this.ws = new OrionAggregatorWS(httpToWS(wsAPIUrl));
|
||||
this.ws = new AggregatorWS(httpToWS(wsAPIUrl));
|
||||
|
||||
this.getHistoryAtomicSwaps = this.getHistoryAtomicSwaps.bind(this);
|
||||
this.getPairConfig = this.getPairConfig.bind(this);
|
||||
@@ -351,7 +351,7 @@ class OrionAggregator {
|
||||
);
|
||||
|
||||
/**
|
||||
* Get placed atomic swaps. Each atomic swap received from this list has a target chain corresponding to this Orion Aggregator
|
||||
* Get placed atomic swaps. Each atomic swap received from this list has a target chain corresponding to this Aggregator
|
||||
* @param sender Sender address
|
||||
* @returns Fetch promise
|
||||
*/
|
||||
@@ -364,4 +364,4 @@ class OrionAggregator {
|
||||
}
|
||||
export * as schemas from './schemas/index.js';
|
||||
export * as ws from './ws/index.js';
|
||||
export { OrionAggregator };
|
||||
export { Aggregator };
|
||||
@@ -71,7 +71,6 @@ const subOrderSchema = baseOrderSchema.extend({
|
||||
})),
|
||||
exchange: z.enum(exchanges),
|
||||
brokerAddress:
|
||||
// https://github.com/orionprotocol/orion-aggregator/blob/98f543e59b7bbf14d8db0417c6af5cf7575f3956/src/main/java/io/orionprotocol/aggregator/model/Exchange.java#L116
|
||||
z.enum(['ORION_BROKER', 'SELF_BROKER'])
|
||||
.or(z.custom<SelfBroker>((value) => {
|
||||
if (typeof value === 'string' && isSelfBroker(value)) {
|
||||
@@ -23,7 +23,6 @@ import { objectKeys } from '../../../utils/objectKeys.js';
|
||||
|
||||
const UNSUBSCRIBE = 'u';
|
||||
|
||||
// https://github.com/orionprotocol/orion-aggregator/tree/feature/OP-1752-symmetric-swap#swap-info-subscribe
|
||||
type SwapSubscriptionRequest = {
|
||||
// d: string, // swap request UUID, set by client side
|
||||
i: string // asset in
|
||||
@@ -162,7 +161,7 @@ const isSubType = (subType: string): subType is keyof Subscription => Object.val
|
||||
|
||||
const unknownMessageTypeRegex = /An unknown message type: '(.*)', json: (.*)/;
|
||||
const nonExistentMessageRegex = /Could not cancel nonexistent subscription: (.*)/;
|
||||
class OrionAggregatorWS {
|
||||
class AggregatorWS {
|
||||
private ws?: WebSocket | undefined;
|
||||
|
||||
// is used to make sure we do not need to renew ws subscription
|
||||
@@ -319,10 +318,10 @@ class OrionAggregatorWS {
|
||||
this.isClosedIntentionally = false;
|
||||
this.ws = new WebSocket(this.wsUrl);
|
||||
this.ws.onerror = (err) => {
|
||||
this.logger?.(`OrionAggregatorWS: ${err.message}`);
|
||||
this.logger?.(`AggregatorWS: ${err.message}`);
|
||||
};
|
||||
this.ws.onclose = () => {
|
||||
this.logger?.(`OrionAggregatorWS: connection closed ${this.isClosedIntentionally ? 'intentionally' : ''}`);
|
||||
this.logger?.(`AggregatorWS: connection closed ${this.isClosedIntentionally ? 'intentionally' : ''}`);
|
||||
if (!this.isClosedIntentionally) this.init(true);
|
||||
};
|
||||
this.ws.onopen = () => {
|
||||
@@ -342,12 +341,12 @@ class OrionAggregatorWS {
|
||||
}
|
||||
});
|
||||
}
|
||||
this.logger?.(`OrionAggregatorWS: connection opened${isReconnect ? ' (reconnect)' : ''}`);
|
||||
this.logger?.(`AggregatorWS: connection opened${isReconnect ? ' (reconnect)' : ''}`);
|
||||
};
|
||||
this.ws.onmessage = (e) => {
|
||||
const { data } = e;
|
||||
if (typeof data !== 'string') throw new Error('OrionAggregatorWS: received non-string message');
|
||||
this.logger?.(`OrionAggregatorWS: received message: ${data}`);
|
||||
if (typeof data !== 'string') throw new Error('AggregatorWS: received non-string message');
|
||||
this.logger?.(`AggregatorWS: received message: ${data}`);
|
||||
const rawJson: unknown = JSON.parse(data);
|
||||
|
||||
const messageSchema = z.union([
|
||||
@@ -389,9 +388,9 @@ class OrionAggregatorWS {
|
||||
console.warn(`You tried to subscribe to '${subscription}' with unknown payload '${jsonPayload}'. This is probably a bug in the code. Please be sure that you are subscribing to the existing subscription with the correct payload.`)
|
||||
} else {
|
||||
const subType = objectKeys(this.subscriptions).find((st) => this.subscriptions[st]?.[id]);
|
||||
if (subType === undefined) throw new Error(`OrionAggregatorWS: cannot find subscription type by id ${id}. Current subscriptions: ${JSON.stringify(this.subscriptions)}`);
|
||||
if (subType === undefined) throw new Error(`AggregatorWS: cannot find subscription type by id ${id}. Current subscriptions: ${JSON.stringify(this.subscriptions)}`);
|
||||
const sub = this.subscriptions[subType]?.[id];
|
||||
if (sub === undefined) throw new Error(`OrionAggregatorWS: cannot find subscription by id ${id}. Current subscriptions: ${JSON.stringify(this.subscriptions)}`);
|
||||
if (sub === undefined) throw new Error(`AggregatorWS: cannot find subscription by id ${id}. Current subscriptions: ${JSON.stringify(this.subscriptions)}`);
|
||||
if ('errorCb' in sub) {
|
||||
sub.errorCb(err.m);
|
||||
}
|
||||
@@ -658,7 +657,7 @@ class OrionAggregatorWS {
|
||||
|
||||
export * as schemas from './schemas/index.js';
|
||||
export {
|
||||
OrionAggregatorWS,
|
||||
AggregatorWS,
|
||||
SubscriptionType,
|
||||
UnsubscriptionType,
|
||||
MessageType,
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
governancePoolsSchema,
|
||||
governancePoolSchema,
|
||||
} from './schemas/index.js';
|
||||
import type redeemOrderSchema from '../OrionAggregator/schemas/redeemOrderSchema.js';
|
||||
import type redeemOrderSchema from '../Aggregator/schemas/redeemOrderSchema.js';
|
||||
import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema.js';
|
||||
import { makePartial } from '../../utils/index.js';
|
||||
import type { networkCodes } from '../../constants/index.js';
|
||||
@@ -63,7 +63,7 @@ type CfdHistoryQuery = {
|
||||
page?: number
|
||||
limit?: number
|
||||
} & Partial<Record<string, string | number>>
|
||||
class OrionBlockchain {
|
||||
class BlockchainService {
|
||||
private readonly apiUrl: string;
|
||||
|
||||
get api() {
|
||||
@@ -112,7 +112,7 @@ class OrionBlockchain {
|
||||
this.getGovernancePool = this.getGovernancePool.bind(this);
|
||||
}
|
||||
|
||||
get orionBlockchainWsUrl() {
|
||||
get blockchainServiceWsUrl() {
|
||||
return `${this.apiUrl}/`;
|
||||
}
|
||||
|
||||
@@ -356,8 +356,8 @@ class OrionBlockchain {
|
||||
);
|
||||
|
||||
/**
|
||||
* Sender is user address in source Orion Blockchain instance \
|
||||
* Receiver is user address in target Orion Blockchain instance
|
||||
* Sender is user address in source BlockchainService instance \
|
||||
* Receiver is user address in target BlockchainService instance
|
||||
*/
|
||||
getAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery | AtomicSwapHistoryTargetQuery) => {
|
||||
const url = new URL(`${this.apiUrl}/api/atomic/history/`);
|
||||
@@ -446,4 +446,4 @@ class OrionBlockchain {
|
||||
}
|
||||
|
||||
export * as schemas from './schemas/index.js';
|
||||
export { OrionBlockchain };
|
||||
export { BlockchainService };
|
||||
@@ -1,4 +1,4 @@
|
||||
export * as orionAggregator from './OrionAggregator/index.js';
|
||||
export * as orionBlockchain from './OrionBlockchain/index.js';
|
||||
export * as aggregator from './Aggregator/index.js';
|
||||
export * as blockchainService from './BlockchainService/index.js';
|
||||
export * as priceFeed from './PriceFeed/index.js';
|
||||
export * as referralSystem from './ReferralSystem/index.js';
|
||||
|
||||
Reference in New Issue
Block a user