mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
Added factory schema
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@orionprotocol/sdk",
|
"name": "@orionprotocol/sdk",
|
||||||
"version": "0.19.92-rc102",
|
"version": "0.19.92-rc103",
|
||||||
"description": "Orion Protocol SDK",
|
"description": "Orion Protocol SDK",
|
||||||
"main": "./lib/index.cjs",
|
"main": "./lib/index.cjs",
|
||||||
"module": "./lib/index.js",
|
"module": "./lib/index.js",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { SwapExecutor__factory, CurveRegistry__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js"
|
import { SwapExecutor__factory, CurveRegistry__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js"
|
||||||
import type { BigNumberish, providers } from "ethers"
|
import type { BigNumberish, providers } from "ethers"
|
||||||
import type { SingleSwap } from "../generateSwapCalldata.js"
|
|
||||||
import { addCallParams } from "./utils.js"
|
import { addCallParams } from "./utils.js"
|
||||||
|
import type { SingleSwap } from "../../../types.js"
|
||||||
|
|
||||||
export async function generateCurveStableSwapCall(
|
export async function generateCurveStableSwapCall(
|
||||||
amount: BigNumberish,
|
amount: BigNumberish,
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { SafeArray } from "../../../utils/safeGetters.js"
|
|||||||
import { BigNumber } from "ethers"
|
import { BigNumber } from "ethers"
|
||||||
import type { BytesLike, BigNumberish } from "ethers"
|
import type { BytesLike, BigNumberish } from "ethers"
|
||||||
import { defaultAbiCoder, concat } from "ethers/lib/utils.js"
|
import { defaultAbiCoder, concat } from "ethers/lib/utils.js"
|
||||||
import type { SingleSwap } from "../generateSwapCalldata.js"
|
|
||||||
import { addCallParams, generateCalls } from "./utils.js"
|
import { addCallParams, generateCalls } from "./utils.js"
|
||||||
|
import type { SingleSwap } from "../../../types.js"
|
||||||
|
|
||||||
export async function generateUni2Calls(
|
export async function generateUni2Calls(
|
||||||
path: SafeArray<SingleSwap>,
|
path: SafeArray<SingleSwap>,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js"
|
import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v5/index.js"
|
||||||
import { type BigNumberish, providers, type BytesLike, ethers } from "ethers"
|
import { type BigNumberish, providers, type BytesLike, ethers } from "ethers"
|
||||||
import { SafeArray } from "../../../utils/safeGetters.js"
|
import { SafeArray } from "../../../utils/safeGetters.js"
|
||||||
import type { SingleSwap } from "../generateSwapCalldata.js"
|
|
||||||
import { addCallParams, generateCalls } from "./utils.js"
|
import { addCallParams, generateCalls } from "./utils.js"
|
||||||
|
import type { SingleSwap } from "../../../types.js"
|
||||||
|
|
||||||
export async function generateUni3Call(
|
export async function generateUni3Call(
|
||||||
swap: SingleSwap,
|
swap: SingleSwap,
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ import { generateUni3Calls, generateOrion3Calls, generateUni3Call, generateOrion
|
|||||||
import { exchangeToNativeDecimals, generateCalls, pathCallWithBalance } from './callGenerators/utils.js';
|
import { exchangeToNativeDecimals, generateCalls, pathCallWithBalance } from './callGenerators/utils.js';
|
||||||
import { generateApproveCall, generateTransferCall } from './callGenerators/erc20.js';
|
import { generateApproveCall, generateTransferCall } from './callGenerators/erc20.js';
|
||||||
import { generateCurveStableSwapCall } from './callGenerators/curve.js';
|
import { generateCurveStableSwapCall } from './callGenerators/curve.js';
|
||||||
|
import type { SingleSwap } from '../../types.js';
|
||||||
|
|
||||||
export type Factory = "UniswapV2" | "UniswapV3" | "Curve" | "OrionV2" | "OrionV3"
|
export type Factory = "UniswapV2" | "UniswapV3" | "Curve" | "OrionV2" | "OrionV3"
|
||||||
|
|
||||||
export type SingleSwap = {
|
|
||||||
pool: string
|
|
||||||
assetIn: string
|
|
||||||
assetOut: string
|
|
||||||
factory: Factory
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GenerateSwapCalldataParams = {
|
export type GenerateSwapCalldataParams = {
|
||||||
amount: BigNumberish
|
amount: BigNumberish
|
||||||
|
|||||||
1
src/constants/factories.ts
Normal file
1
src/constants/factories.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3"] as const
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import MessageType from '../MessageType.js';
|
import MessageType from '../MessageType.js';
|
||||||
import baseMessageSchema from './baseMessageSchema.js';
|
import baseMessageSchema from './baseMessageSchema.js';
|
||||||
|
import factories from '../../../../constants/factories.js';
|
||||||
|
|
||||||
const alternativeSchema = z.object({ // execution alternatives
|
const alternativeSchema = z.object({ // execution alternatives
|
||||||
e: z.string().array(), // exchanges
|
e: z.string().array(), // exchanges
|
||||||
@@ -11,6 +12,7 @@ const alternativeSchema = z.object({ // execution alternatives
|
|||||||
aa: z.number().optional(), // available amount in
|
aa: z.number().optional(), // available amount in
|
||||||
aao: z.number().optional(), // available amount out
|
aao: z.number().optional(), // available amount out
|
||||||
});
|
});
|
||||||
|
const factorySchema = z.enum(factories);
|
||||||
const swapInfoSchemaBase = baseMessageSchema.extend({
|
const swapInfoSchemaBase = baseMessageSchema.extend({
|
||||||
T: z.literal(MessageType.SWAP_INFO),
|
T: z.literal(MessageType.SWAP_INFO),
|
||||||
S: z.string(), // swap request id
|
S: z.string(), // swap request id
|
||||||
@@ -37,7 +39,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
|
|||||||
p: z.string(), // pool address
|
p: z.string(), // pool address
|
||||||
ai: z.string().toUpperCase(), // asset in
|
ai: z.string().toUpperCase(), // asset in
|
||||||
ao: z.string().toUpperCase(), // asset out
|
ao: z.string().toUpperCase(), // asset out
|
||||||
f: z.string(), // factory
|
f: factorySchema, // factory
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
11
src/types.ts
11
src/types.ts
@@ -1,10 +1,10 @@
|
|||||||
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
||||||
|
import factories from './constants/factories.js';
|
||||||
import type { BigNumber } from 'bignumber.js';
|
import type { BigNumber } from 'bignumber.js';
|
||||||
import type subOrderStatuses from './constants/subOrderStatuses.js';
|
import type subOrderStatuses from './constants/subOrderStatuses.js';
|
||||||
import type positionStatuses from './constants/positionStatuses.js';
|
import type positionStatuses from './constants/positionStatuses.js';
|
||||||
import type { knownEnvs } from './config/schemas/index.js';
|
import type { knownEnvs } from './config/schemas/index.js';
|
||||||
import type getHistory from './Orion/bridge/getHistory.js';
|
import type getHistory from './Orion/bridge/getHistory.js';
|
||||||
import type { SingleSwap } from './Unit/Exchange/generateSwapCalldata.js';
|
|
||||||
|
|
||||||
export type DeepPartial<T> = T extends object ? {
|
export type DeepPartial<T> = T extends object ? {
|
||||||
[P in keyof T]?: DeepPartial<T[P]>;
|
[P in keyof T]?: DeepPartial<T[P]>;
|
||||||
@@ -166,6 +166,15 @@ export type SwapInfoAlternative = {
|
|||||||
availableAmountOut?: number | undefined
|
availableAmountOut?: number | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Factory = typeof factories[number]
|
||||||
|
|
||||||
|
export type SingleSwap = {
|
||||||
|
pool: string
|
||||||
|
assetIn: string
|
||||||
|
assetOut: string
|
||||||
|
factory: Factory
|
||||||
|
}
|
||||||
|
|
||||||
export type SwapInfoBase = {
|
export type SwapInfoBase = {
|
||||||
swapRequestId: string
|
swapRequestId: string
|
||||||
assetIn: string
|
assetIn: string
|
||||||
|
|||||||
Reference in New Issue
Block a user