mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-30 01:27:57 +03:00
is exact receive
This commit is contained in:
@@ -268,11 +268,16 @@ class Aggregator {
|
||||
amount: string,
|
||||
instantSettlement?: boolean,
|
||||
exchanges?: string[] | 'cex' | 'pools',
|
||||
isExactReceive?: boolean,
|
||||
) => {
|
||||
const url = new URL(`${this.apiUrl}/api/v1/swap`);
|
||||
url.searchParams.append('assetIn', assetIn);
|
||||
url.searchParams.append('assetOut', assetOut);
|
||||
url.searchParams.append('amountIn', amount);
|
||||
if (isExactReceive !== true) {
|
||||
url.searchParams.append('amountIn', amount);
|
||||
} else {
|
||||
url.searchParams.append('amountOut', amount);
|
||||
}
|
||||
|
||||
if (exchanges !== undefined) {
|
||||
if (Array.isArray(exchanges)) {
|
||||
|
||||
@@ -52,11 +52,26 @@ const swapInfoBase = z.object({
|
||||
autoSlippage: z.number().optional(),
|
||||
});
|
||||
|
||||
const swapInfoSchema = swapInfoBase.extend({
|
||||
const swapInfoByAmountIn = swapInfoBase.extend({
|
||||
availableAmountOut: z.null(),
|
||||
availableAmountIn: z.number(),
|
||||
marketAmountOut: z.number().nullable(),
|
||||
marketAmountIn: z.null(),
|
||||
});
|
||||
}).transform((val) => ({
|
||||
...val,
|
||||
isExactReceive: false as const,
|
||||
}));
|
||||
|
||||
const swapInfoByAmountOut = swapInfoBase.extend({
|
||||
availableAmountOut: z.number(),
|
||||
availableAmountIn: z.null(),
|
||||
marketAmountOut: z.null(),
|
||||
marketAmountIn: z.number().nullable(),
|
||||
}).transform((val) => ({
|
||||
...val,
|
||||
isExactReceive: true as const,
|
||||
}));
|
||||
|
||||
const swapInfoSchema = swapInfoByAmountIn.or(swapInfoByAmountOut);
|
||||
|
||||
export default swapInfoSchema;
|
||||
|
||||
@@ -544,11 +544,27 @@ class AggregatorWS {
|
||||
autoSlippage: json.sl,
|
||||
};
|
||||
|
||||
this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[json.S]?.callback({
|
||||
marketAmountOut: json.mo,
|
||||
availableAmountIn: json.aa,
|
||||
...baseSwapInfo,
|
||||
});
|
||||
switch (json.er) { // exactReceive
|
||||
case false:
|
||||
this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[json.S]?.callback({
|
||||
isExactReceive: false,
|
||||
marketAmountOut: json.mo,
|
||||
availableAmountIn: json.aa,
|
||||
...baseSwapInfo,
|
||||
});
|
||||
|
||||
break;
|
||||
case true:
|
||||
this.subscriptions[SubscriptionType.SWAP_SUBSCRIBE]?.[json.S]?.callback({
|
||||
isExactReceive: true,
|
||||
...baseSwapInfo,
|
||||
marketAmountIn: json.mi,
|
||||
availableAmountOut: json.aao,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MessageType.INITIALIZATION:
|
||||
|
||||
@@ -51,9 +51,25 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
|
||||
sl: z.number().optional(),
|
||||
});
|
||||
|
||||
const swapInfoSchema = swapInfoSchemaBase.extend({
|
||||
const swapInfoSchemaByAmountIn = swapInfoSchemaBase.extend({
|
||||
mo: z.number().optional(), // market amount out
|
||||
aa: z.number(), // available amount in
|
||||
});
|
||||
}).transform((content) => ({
|
||||
...content,
|
||||
er: false as const,
|
||||
}));
|
||||
|
||||
const swapInfoSchemaByAmountOut = swapInfoSchemaBase.extend({
|
||||
mi: z.number().optional(), // market amount in
|
||||
aao: z.number(), // available amount out
|
||||
}).transform((content) => ({
|
||||
...content,
|
||||
er: true as const,
|
||||
}));
|
||||
|
||||
const swapInfoSchema = z.union([
|
||||
swapInfoSchemaByAmountIn,
|
||||
swapInfoSchemaByAmountOut,
|
||||
]);
|
||||
|
||||
export default swapInfoSchema;
|
||||
|
||||
Reference in New Issue
Block a user