Skip to content

Commit

Permalink
chore: updates types (#1139)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
towanTG and github-actions[bot] authored Dec 20, 2024
1 parent 59f2774 commit 8793bfd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 65 deletions.
6 changes: 6 additions & 0 deletions .changeset/fresh-moons-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@swapkit/plugin-chainflip": major
"@swapkit/api": minor
---

Adds chainflip streaming and retires Swapkit specific broker implementation
10 changes: 4 additions & 6 deletions packages/plugins/chainflip/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
});

Expand Down
12 changes: 5 additions & 7 deletions packages/swapkit/api/src/swapkitApi/endpoints.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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`;
Expand Down
89 changes: 37 additions & 52 deletions packages/swapkit/api/src/swapkitApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,48 +297,49 @@ export const PriceRequestSchema = z.object({

export type PriceRequest = z.infer<typeof PriceRequestSchema>;

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<typeof DepositChannelRequestSchema>;
export type BrokerDepositChannelParams = z.infer<typeof BrokerDepositChannelParamsSchema>;

export const DepositChannelResponseSchema = z.object({
channelId: z.string(),
Expand Down Expand Up @@ -618,23 +619,7 @@ export const RouteQuoteMetadataAssetSchema = z.object({

export type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;

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<typeof ChainflipMetadataSchema>;

Expand Down

0 comments on commit 8793bfd

Please sign in to comment.