From 8793bfda642ca8d278784c76583ddc872417cea6 Mon Sep 17 00:00:00 2001 From: towan <95243956+towanTG@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:52:51 +0400 Subject: [PATCH] chore: updates types (#1139) Co-authored-by: github-actions[bot] --- .changeset/fresh-moons-fold.md | 6 ++ packages/plugins/chainflip/src/plugin.ts | 10 +-- .../swapkit/api/src/swapkitApi/endpoints.ts | 12 ++- packages/swapkit/api/src/swapkitApi/types.ts | 89 ++++++++----------- 4 files changed, 52 insertions(+), 65 deletions(-) create mode 100644 .changeset/fresh-moons-fold.md diff --git a/.changeset/fresh-moons-fold.md b/.changeset/fresh-moons-fold.md new file mode 100644 index 000000000..1e9226547 --- /dev/null +++ b/.changeset/fresh-moons-fold.md @@ -0,0 +1,6 @@ +--- +"@swapkit/plugin-chainflip": major +"@swapkit/api": minor +--- + +Adds chainflip streaming and retires Swapkit specific broker implementation diff --git a/packages/plugins/chainflip/src/plugin.ts b/packages/plugins/chainflip/src/plugin.ts index a4e109a03..72faf5fb2 100644 --- a/packages/plugins/chainflip/src/plugin.ts +++ b/packages/plugins/chainflip/src/plugin.ts @@ -25,7 +25,7 @@ function plugin({ const brokerUrl = chainflipBrokerUrl || legacyChainflipBrokerUrl; - if (!(swapParams?.route?.buyAsset && brokerUrl)) { + if (!(swapParams?.route?.buyAsset && brokerUrl && swapParams.route.meta.chainflip)) { throw new SwapKitError("core_swap_invalid_params", { ...swapParams, chainflipBrokerUrl: brokerUrl, @@ -61,11 +61,9 @@ function plugin({ const { depositAddress } = await swapkitApiEndpoints.getChainflipDepositChannel({ body: { - buyAsset: buyAssetString, - recipient, - sellAsset: sellAssetString, - maxBoostFeeBps, - ...(chainflip ? chainflip : {}), + ...chainflip, + destinationAddress: recipient || chainflip.destinationAddress, + maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps, }, }); diff --git a/packages/swapkit/api/src/swapkitApi/endpoints.ts b/packages/swapkit/api/src/swapkitApi/endpoints.ts index 5aa67dfcf..58ec94f3b 100644 --- a/packages/swapkit/api/src/swapkitApi/endpoints.ts +++ b/packages/swapkit/api/src/swapkitApi/endpoints.ts @@ -1,8 +1,8 @@ import crypto from "crypto"; -import { AssetValue, ProviderName, RequestClient, SwapKitError } from "@swapkit/helpers"; +import { ProviderName, RequestClient, SwapKitError } from "@swapkit/helpers"; import { - type DepositChannelRequest, + type BrokerDepositChannelParams, type DepositChannelResponse, DepositChannelResponseSchema, type GasResponse, @@ -351,13 +351,11 @@ export async function getChainflipDepositChannel({ body, }: { isDev?: boolean; - body: DepositChannelRequest; + body: BrokerDepositChannelParams; }) { - const { sellAsset, buyAsset, recipient } = body; - const sellAssetValue = AssetValue.from({ asset: sellAsset }); - const buyAssetValue = AssetValue.from({ asset: buyAsset }); + const { destinationAddress } = body; - if (!(sellAssetValue && buyAssetValue && recipient)) { + if (!destinationAddress) { throw new SwapKitError("chainflip_broker_invalid_params"); } const url = `${getBaseUrl(isDev)}/channel`; diff --git a/packages/swapkit/api/src/swapkitApi/types.ts b/packages/swapkit/api/src/swapkitApi/types.ts index 0975d99d7..78423994e 100644 --- a/packages/swapkit/api/src/swapkitApi/types.ts +++ b/packages/swapkit/api/src/swapkitApi/types.ts @@ -297,48 +297,49 @@ export const PriceRequestSchema = z.object({ export type PriceRequest = z.infer; -export const DepositChannelRequestSchema = z.object({ - sellAsset: z.string({ - description: "Asset to sell", - }), - buyAsset: z.string({ - description: "Asset to buy", +export const BrokerDepositChannelParamsSchema = z.object({ + sellAsset: z.object({ + chain: z.string(), // identifier of the asset + asset: z.string(), // identifier of the asset }), - recipient: z.string({ - description: "Final recipient of the swap", + buyAsset: z.object({ + chain: z.string(), // identifier of the asset + asset: z.string(), // identifier of the asset }), - ccmMetadata: z.optional( - z.object({ - message: z.string(), - gasBudget: z.string(), - cfParameters: z.string(), - }), - ), - dcaParameters: z.optional( - z.object({ - chunkIntervalBlocks: z.number(), - numberOfChunks: z.number(), - }), - ), - maxBoostFeeBps: z.optional(z.number()), - affiliateFees: z.optional( - z.array( + destinationAddress: z.string(), + channelMetadata: z + .object({ + cfParameters: z.string().optional(), + gasBudget: z.string().optional(), + message: z.string().optional(), + }) + .optional(), + affiliateFees: z + .array( z.object({ brokerAddress: z.string(), - basisPoints: z.number(), + feeBps: z.number(), }), - ), - ), - refundParameters: z.optional( - z.object({ - retryDuration: z.number(), - refundAddress: z.string(), - minPrice: z.string(), - }), - ), + ) + .optional(), + refundParameters: z + .object({ + minPrice: z.string().optional(), + refundAddress: z.string().optional(), + retryDuration: z.number().optional(), + }) + .optional(), + dcaParameters: z + .object({ + chunkInterval: z.number().optional(), + numberOfChunks: z.number().optional(), + }) + .optional(), + brokerCommissionBps: z.number().optional(), + maxBoostFeeBps: z.number().optional(), }); -export type DepositChannelRequest = z.infer; +export type BrokerDepositChannelParams = z.infer; export const DepositChannelResponseSchema = z.object({ channelId: z.string(), @@ -618,23 +619,7 @@ export const RouteQuoteMetadataAssetSchema = z.object({ export type RouteQuoteMetadataAsset = z.infer; -export const ChainflipMetadataSchema = z.object({ - boost: z.optional(z.boolean()), - maxBoostFeeBps: z.optional(z.number()), - dcaParams: z.optional( - z.object({ - chunkIntervalBlocks: z.number(), - numberOfChunks: z.number(), - }), - ), - killOrFillParams: z.optional( - z.object({ - refundAddress: z.string(), - retryDurationBlocks: z.number(), - slippageTolerancePercent: z.number(), - }), - ), -}); +export const ChainflipMetadataSchema = BrokerDepositChannelParamsSchema; export type ChainflipMetadata = z.infer;