From 21015e921945545cd552d59ffb1e0251593c80f2 Mon Sep 17 00:00:00 2001 From: lomonoshka Date: Thu, 28 Sep 2023 19:48:12 +0400 Subject: [PATCH] Added factory schema --- package.json | 2 +- src/Unit/Exchange/callGenerators/curve.ts | 2 +- src/Unit/Exchange/callGenerators/uniswapV2.ts | 2 +- src/Unit/Exchange/callGenerators/uniswapV3.ts | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 8 ++------ src/constants/factories.ts | 1 + src/services/Aggregator/ws/schemas/swapInfoSchema.ts | 4 +++- src/types.ts | 11 ++++++++++- 8 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 src/constants/factories.ts diff --git a/package.json b/package.json index 707d1bd..242b3be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.92-rc102", + "version": "0.19.92-rc103", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/callGenerators/curve.ts b/src/Unit/Exchange/callGenerators/curve.ts index 42e2123..2ce2b0a 100644 --- a/src/Unit/Exchange/callGenerators/curve.ts +++ b/src/Unit/Exchange/callGenerators/curve.ts @@ -1,7 +1,7 @@ import { SwapExecutor__factory, CurveRegistry__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js" import type { BigNumberish, providers } from "ethers" -import type { SingleSwap } from "../generateSwapCalldata.js" import { addCallParams } from "./utils.js" +import type { SingleSwap } from "../../../types.js" export async function generateCurveStableSwapCall( amount: BigNumberish, diff --git a/src/Unit/Exchange/callGenerators/uniswapV2.ts b/src/Unit/Exchange/callGenerators/uniswapV2.ts index bec62de..fe276d7 100644 --- a/src/Unit/Exchange/callGenerators/uniswapV2.ts +++ b/src/Unit/Exchange/callGenerators/uniswapV2.ts @@ -3,8 +3,8 @@ import { SafeArray } from "../../../utils/safeGetters.js" import { BigNumber } from "ethers" import type { BytesLike, BigNumberish } from "ethers" import { defaultAbiCoder, concat } from "ethers/lib/utils.js" -import type { SingleSwap } from "../generateSwapCalldata.js" import { addCallParams, generateCalls } from "./utils.js" +import type { SingleSwap } from "../../../types.js" export async function generateUni2Calls( path: SafeArray, diff --git a/src/Unit/Exchange/callGenerators/uniswapV3.ts b/src/Unit/Exchange/callGenerators/uniswapV3.ts index f18e05a..2dd8b95 100644 --- a/src/Unit/Exchange/callGenerators/uniswapV3.ts +++ b/src/Unit/Exchange/callGenerators/uniswapV3.ts @@ -1,8 +1,8 @@ import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js" import { type BigNumberish, providers, type BytesLike, ethers } from "ethers" import { SafeArray } from "../../../utils/safeGetters.js" -import type { SingleSwap } from "../generateSwapCalldata.js" import { addCallParams, generateCalls } from "./utils.js" +import type { SingleSwap } from "../../../types.js" export async function generateUni3Call( swap: SingleSwap, diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index 7358acb..f0b70a3 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -9,15 +9,11 @@ import { generateUni3Calls, generateOrion3Calls, generateUni3Call, generateOrion import { exchangeToNativeDecimals, generateCalls, pathCallWithBalance } from './callGenerators/utils.js'; import { generateApproveCall, generateTransferCall } from './callGenerators/erc20.js'; import { generateCurveStableSwapCall } from './callGenerators/curve.js'; +import type { SingleSwap } from '../../types.js'; export type Factory = "UniswapV2" | "UniswapV3" | "Curve" | "OrionV2" | "OrionV3" -export type SingleSwap = { - pool: string - assetIn: string - assetOut: string - factory: Factory -} + export type GenerateSwapCalldataParams = { amount: BigNumberish diff --git a/src/constants/factories.ts b/src/constants/factories.ts new file mode 100644 index 0000000..200d3e2 --- /dev/null +++ b/src/constants/factories.ts @@ -0,0 +1 @@ +export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3"] as const diff --git a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts index 288838b..aa79db8 100644 --- a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts +++ b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts @@ -1,6 +1,7 @@ import { z } from 'zod'; import MessageType from '../MessageType.js'; import baseMessageSchema from './baseMessageSchema.js'; +import factories from '../../../../constants/factories.js'; const alternativeSchema = z.object({ // execution alternatives e: z.string().array(), // exchanges @@ -11,6 +12,7 @@ const alternativeSchema = z.object({ // execution alternatives aa: z.number().optional(), // available amount in aao: z.number().optional(), // available amount out }); +const factorySchema = z.enum(factories); const swapInfoSchemaBase = baseMessageSchema.extend({ T: z.literal(MessageType.SWAP_INFO), S: z.string(), // swap request id @@ -37,7 +39,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({ p: z.string(), // pool address ai: z.string().toUpperCase(), // asset in ao: z.string().toUpperCase(), // asset out - f: z.string(), // factory + f: factorySchema, // factory })) }); diff --git a/src/types.ts b/src/types.ts index d7a7b3f..6f3afc4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ +import factories from './constants/factories.js'; import type { BigNumber } from 'bignumber.js'; import type subOrderStatuses from './constants/subOrderStatuses.js'; import type positionStatuses from './constants/positionStatuses.js'; import type { knownEnvs } from './config/schemas/index.js'; import type getHistory from './Orion/bridge/getHistory.js'; -import type { SingleSwap } from './Unit/Exchange/generateSwapCalldata.js'; export type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial; @@ -166,6 +166,15 @@ export type SwapInfoAlternative = { availableAmountOut?: number | undefined } +export type Factory = typeof factories[number] + +export type SingleSwap = { + pool: string + assetIn: string + assetOut: string + factory: Factory +} + export type SwapInfoBase = { swapRequestId: string assetIn: string