Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-mangos-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@across-protocol/app-sdk": patch
---

Update fees response schema
108 changes: 83 additions & 25 deletions packages/sdk/src/api/swap-approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import {
stringOrStringArray,
} from "./validators.js";

export enum FeeDetailsType {
TOTAL_BREAKDOWN = "total-breakdown",
MAX_TOTAL_BREAKDOWN = "max-total-breakdown",
ACROSS = "across",
}

// Request schema
export const baseSwapQueryParamsSchema = z.object({
amount: positiveIntString,
Expand Down Expand Up @@ -44,6 +50,21 @@ const feeComponentSchema = z.object({
}),
});

const bridgeFeeDetailComponentSchema = z.object({
amount: bigNumberString,
pct: z.string(),
token: z
.object({
address: ethereumAddress,
symbol: z.string(),
decimals: positiveInteger,
chainId: positiveInteger,
name: z.string().optional(),
})
.optional(),
amountUsd: z.string().optional(),
});

const gasFeeSchema = z.object({
amount: bigNumberString,
amountUsd: z.string(),
Expand All @@ -55,10 +76,6 @@ const gasFeeSchema = z.object({
}),
});

const gasFeeWithPctSchema = gasFeeSchema.extend({
pct: z.string(),
});

const swapStepSchema = z.object({
tokenIn: z.object({
address: ethereumAddress,
Expand Down Expand Up @@ -100,23 +117,25 @@ const bridgeStepSchema = z.object({
name: z.string().optional(),
}),
fees: z.object({
totalRelay: z.object({
pct: z.string(),
total: bigNumberString,
}),
relayerCapital: z.object({
pct: z.string(),
total: bigNumberString,
}),
relayerGas: z.object({
pct: z.string(),
total: bigNumberString,
}),
lp: z.object({
pct: z.string(),
total: bigNumberString,
amount: bigNumberString,
pct: z.string(),
token: z.object({
address: ethereumAddress,
symbol: z.string(),
decimals: positiveInteger,
chainId: positiveInteger,
name: z.string().optional(),
}),
details: z
.object({
type: z.nativeEnum(FeeDetailsType),
relayerCapital: bridgeFeeDetailComponentSchema.optional(),
destinationGas: bridgeFeeDetailComponentSchema.optional(),
lp: bridgeFeeDetailComponentSchema.optional(),
})
.optional(),
}),
provider: z.string().optional(),
});

const allowanceCheckSchema = z.object({
Expand Down Expand Up @@ -210,15 +229,54 @@ export const swapApprovalResponseSchema = z.object({
name: z.string().optional(),
}),
fees: z.object({
total: feeComponentSchema,
total: feeComponentSchema.extend({
details: z
.object({
type: z.nativeEnum(FeeDetailsType),
swapImpact: feeComponentSchema.optional(),
app: feeComponentSchema.optional(),
bridge: feeComponentSchema
.extend({
details: z
.object({
type: z.nativeEnum(FeeDetailsType),
lp: feeComponentSchema.optional(),
destinationGas: feeComponentSchema.optional(),
relayerCapital: feeComponentSchema.optional(),
})
.optional(),
})
.optional(),
})
.optional(),
}),
maxTotal: feeComponentSchema
.extend({
details: z
.object({
type: z.nativeEnum(FeeDetailsType),
maxSwapImpact: feeComponentSchema.optional(),
app: feeComponentSchema.optional(),
bridge: feeComponentSchema
.extend({
details: z
.object({
type: z.nativeEnum(FeeDetailsType),
lp: feeComponentSchema.optional(),
destinationGas: feeComponentSchema.optional(),
relayerCapital: feeComponentSchema.optional(),
})
.optional(),
})
.optional(),
})
.optional(),
})
.optional(),
originGas: gasFeeSchema,
destinationGas: gasFeeWithPctSchema,
relayerCapital: feeComponentSchema,
lpFee: feeComponentSchema,
relayerTotal: feeComponentSchema,
app: feeComponentSchema,
}),
inputAmount: bigNumberString,
maxInputAmount: bigNumberString.optional(),
expectedOutputAmount: bigNumberString,
minOutputAmount: bigNumberString,
expectedFillTime: positiveInteger,
Expand Down
Loading