Skip to content

Commit

Permalink
chore: improve swagger docs and fix add liquidity (#81)
Browse files Browse the repository at this point in the history
* chore: improve swagger documentation

* fix: use correct nfts for addLiquidity

* feat: add changeset and remove test file
  • Loading branch information
cdotta authored Aug 12, 2024
1 parent 6286558 commit 6e391d7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-shirts-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@treasure-dev/tdk-core": minor
---

fix add liquidity for erc20-nft
127 changes: 78 additions & 49 deletions apps/api/src/schema/magicswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,36 @@ const poolSchema = Type.Object({

// Define the schema for the main object with descriptions
export const poolsReplySchema = Type.Object({
pools: Type.Array(poolSchema),
pools: Type.Array(poolSchema, { description: "Array of pools" }),
});

export const poolReplySchema = poolSchema;

export const routeBodySchema = Type.Object({
tokenInId: Type.String(),
tokenOutId: Type.String(),
amount: Type.String(),
isExactOut: Type.Boolean(),
tokenInId: Type.String({
description: "The unique identifier of the `in` token",
}),
tokenOutId: Type.String({
description: "The unique identifier of the `out` token",
}),
amount: Type.String({ description: "Amount to calculate route and quote" }),
isExactOut: Type.Boolean({ description: "Boolean indicating if exact out" }),
});

const legTokenSchema = Type.Object({
name: Type.String({ description: "Token name" }),
symbol: Type.String({ description: "Token symbol" }),
address: Type.String({ description: "Token address" }),
decimals: Type.Number({ description: "Token decimals" }),
tokenId: Type.Optional(Type.String({ description: "Token ID" })),
});

const legSchema = Type.Object({
poolAddress: Type.String({ description: "Pool address" }),
poolType: Type.String({ description: "Pool type" }),
poolFee: Type.Number({ description: "Pool fee" }),
tokenFrom: Type.Object({
name: Type.String(),
symbol: Type.String(),
address: Type.String(),
decimals: Type.Number(),
tokenId: Type.Optional(Type.String()),
}),
tokenTo: Type.Object({
name: Type.String(),
symbol: Type.String(),
address: Type.String(),
decimals: Type.Number(),
tokenId: Type.Optional(Type.String()),
}),
tokenFrom: legTokenSchema,
tokenTo: legTokenSchema,
assumedAmountIn: Type.Number({ description: "Assumed amount in" }),
assumedAmountOut: Type.Number({ description: "Assumed amount out" }),
swapPortion: Type.Number({ description: "Swap portion" }),
Expand All @@ -164,51 +164,80 @@ export const routeReplySchema = Type.Object({
amountOut: Type.String({ description: "Amount out" }),
tokenIn: tokenSchema,
tokenOut: tokenSchema,
legs: Type.Array(legSchema),
path: Type.Array(Type.String()),
priceImpact: Type.Number(),
derivedValue: Type.Number(),
lpFee: Type.Number(),
protocolFee: Type.Number(),
royaltiesFee: Type.Number(),
legs: Type.Array(legSchema, { description: "Array of route legs" }),
path: Type.Array(Type.String(), {
description: "Array that defines the swap path",
}),
priceImpact: Type.Number({ description: "Price impact" }),
derivedValue: Type.Number({ description: "Derived value" }),
lpFee: Type.Number({ description: "Liquidity provider fee" }),
protocolFee: Type.Number({ description: "Protocol fee" }),
royaltiesFee: Type.Number({ description: "Royalties fee" }),
});

const nftInputSchema = Type.Object({
id: Type.String(),
quantity: Type.Number(),
id: Type.String({ description: "The unique identifier of the NFT" }),
quantity: Type.Number({ description: "The quantity of the NFT" }),
});

export const swapBodySchema = Type.Object({
backendWallet: Type.Optional(Type.String()),
tokenInId: Type.String(),
tokenOutId: Type.String(),
amountIn: Type.Optional(Type.String()),
amountOut: Type.Optional(Type.String()),
path: Type.Array(Type.String()),
isExactOut: Type.Boolean(),
nftsIn: Type.Optional(Type.Array(nftInputSchema)),
nftsOut: Type.Optional(Type.Array(nftInputSchema)),
slippage: Type.Optional(Type.Number()),
tokenInId: Type.String({
description: "The unique identifier of the `in` token",
}),
tokenOutId: Type.String({
description: "The unique identifier of the `out` token",
}),
amountIn: Type.Optional(Type.String({ description: "Amount to swap" })),
amountOut: Type.Optional(Type.String({ description: "Amount to swap" })),
path: Type.Array(
Type.String({ description: "Array that defines the swap path" }),
),
isExactOut: Type.Boolean({ description: "Boolean indicating if exact out" }),
nftsIn: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs to swap in" }),
),
nftsOut: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs to swap out" }),
),
slippage: Type.Optional(Type.Number({ description: "Slippage tolerance" })),
});

export const addLiquidityBodySchema = Type.Object({
backendWallet: Type.Optional(Type.String()),
nfts0: Type.Optional(Type.Array(nftInputSchema)),
nfts1: Type.Optional(Type.Array(nftInputSchema)),
amount0: Type.Optional(Type.String()),
amount1: Type.Optional(Type.String()),
amount0Min: Type.Optional(Type.String()),
amount1Min: Type.Optional(Type.String()),
nfts0: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs for token0" }),
),
nfts1: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs for token1" }),
),
amount0: Type.Optional(Type.String({ description: "Amount for token0" })),
amount1: Type.Optional(Type.String({ description: "Amount for token1" })),
amount0Min: Type.Optional(
Type.String({ description: "Minimum amount for token0" }),
),
amount1Min: Type.Optional(
Type.String({ description: "Minimum amount for token1" }),
),
});

export const removeLiquidityBodySchema = Type.Object({
backendWallet: Type.Optional(Type.String()),
nfts0: Type.Optional(Type.Array(nftInputSchema)),
nfts1: Type.Optional(Type.Array(nftInputSchema)),
amountLP: Type.String(),
amount0Min: Type.String(),
amount1Min: Type.String(),
swapLeftover: Type.Optional(Type.Boolean({ default: true })),
nfts0: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs for token0" }),
),
nfts1: Type.Optional(
Type.Array(nftInputSchema, { description: "Array of NFTs for token1" }),
),
amountLP: Type.String({ description: "Amount of LP tokens" }),
amount0Min: Type.String({ description: "Minimum amount for token0" }),
amount1Min: Type.String({ description: "Minimum amount for token1" }),
swapLeftover: Type.Optional(
Type.Boolean({
default: true,
description: "Boolean indicating if swap leftover",
}),
),
});

const poolParamsSchema = Type.Object({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/magicswap/getAddLiquidityArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export const getAddLiquidityArgs = ({
collection: Array.from({ length: nftsA.length }).fill(
tokenA.collectionId,
) as AddressString[],
tokenId: nftsB.map(({ id }) => BigInt(id)),
amount: nftsB.map(({ quantity }) => BigInt(quantity)),
tokenId: nftsA.map(({ id }) => BigInt(id)),
amount: nftsA.map(({ quantity }) => BigInt(quantity)),
},
tokenB.id,
amountB,
Expand Down

0 comments on commit 6e391d7

Please sign in to comment.