Skip to content

Commit 9e16a4b

Browse files
authored
fix: update fees response schema (#251)
* Update fees response schema * Add changeset
1 parent 679c590 commit 9e16a4b

File tree

2 files changed

+88
-25
lines changed

2 files changed

+88
-25
lines changed

.changeset/wet-mangos-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@across-protocol/app-sdk": patch
3+
---
4+
5+
Update fees response schema

packages/sdk/src/api/swap-approval.ts

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import {
99
stringOrStringArray,
1010
} from "./validators.js";
1111

12+
export enum FeeDetailsType {
13+
TOTAL_BREAKDOWN = "total-breakdown",
14+
MAX_TOTAL_BREAKDOWN = "max-total-breakdown",
15+
ACROSS = "across",
16+
}
17+
1218
// Request schema
1319
export const baseSwapQueryParamsSchema = z.object({
1420
amount: positiveIntString,
@@ -44,6 +50,21 @@ const feeComponentSchema = z.object({
4450
}),
4551
});
4652

53+
const bridgeFeeDetailComponentSchema = z.object({
54+
amount: bigNumberString,
55+
pct: z.string(),
56+
token: z
57+
.object({
58+
address: ethereumAddress,
59+
symbol: z.string(),
60+
decimals: positiveInteger,
61+
chainId: positiveInteger,
62+
name: z.string().optional(),
63+
})
64+
.optional(),
65+
amountUsd: z.string().optional(),
66+
});
67+
4768
const gasFeeSchema = z.object({
4869
amount: bigNumberString,
4970
amountUsd: z.string(),
@@ -55,10 +76,6 @@ const gasFeeSchema = z.object({
5576
}),
5677
});
5778

58-
const gasFeeWithPctSchema = gasFeeSchema.extend({
59-
pct: z.string(),
60-
});
61-
6279
const swapStepSchema = z.object({
6380
tokenIn: z.object({
6481
address: ethereumAddress,
@@ -100,23 +117,25 @@ const bridgeStepSchema = z.object({
100117
name: z.string().optional(),
101118
}),
102119
fees: z.object({
103-
totalRelay: z.object({
104-
pct: z.string(),
105-
total: bigNumberString,
106-
}),
107-
relayerCapital: z.object({
108-
pct: z.string(),
109-
total: bigNumberString,
110-
}),
111-
relayerGas: z.object({
112-
pct: z.string(),
113-
total: bigNumberString,
114-
}),
115-
lp: z.object({
116-
pct: z.string(),
117-
total: bigNumberString,
120+
amount: bigNumberString,
121+
pct: z.string(),
122+
token: z.object({
123+
address: ethereumAddress,
124+
symbol: z.string(),
125+
decimals: positiveInteger,
126+
chainId: positiveInteger,
127+
name: z.string().optional(),
118128
}),
129+
details: z
130+
.object({
131+
type: z.nativeEnum(FeeDetailsType),
132+
relayerCapital: bridgeFeeDetailComponentSchema.optional(),
133+
destinationGas: bridgeFeeDetailComponentSchema.optional(),
134+
lp: bridgeFeeDetailComponentSchema.optional(),
135+
})
136+
.optional(),
119137
}),
138+
provider: z.string().optional(),
120139
});
121140

122141
const allowanceCheckSchema = z.object({
@@ -210,15 +229,54 @@ export const swapApprovalResponseSchema = z.object({
210229
name: z.string().optional(),
211230
}),
212231
fees: z.object({
213-
total: feeComponentSchema,
232+
total: feeComponentSchema.extend({
233+
details: z
234+
.object({
235+
type: z.nativeEnum(FeeDetailsType),
236+
swapImpact: feeComponentSchema.optional(),
237+
app: feeComponentSchema.optional(),
238+
bridge: feeComponentSchema
239+
.extend({
240+
details: z
241+
.object({
242+
type: z.nativeEnum(FeeDetailsType),
243+
lp: feeComponentSchema.optional(),
244+
destinationGas: feeComponentSchema.optional(),
245+
relayerCapital: feeComponentSchema.optional(),
246+
})
247+
.optional(),
248+
})
249+
.optional(),
250+
})
251+
.optional(),
252+
}),
253+
maxTotal: feeComponentSchema
254+
.extend({
255+
details: z
256+
.object({
257+
type: z.nativeEnum(FeeDetailsType),
258+
maxSwapImpact: feeComponentSchema.optional(),
259+
app: feeComponentSchema.optional(),
260+
bridge: feeComponentSchema
261+
.extend({
262+
details: z
263+
.object({
264+
type: z.nativeEnum(FeeDetailsType),
265+
lp: feeComponentSchema.optional(),
266+
destinationGas: feeComponentSchema.optional(),
267+
relayerCapital: feeComponentSchema.optional(),
268+
})
269+
.optional(),
270+
})
271+
.optional(),
272+
})
273+
.optional(),
274+
})
275+
.optional(),
214276
originGas: gasFeeSchema,
215-
destinationGas: gasFeeWithPctSchema,
216-
relayerCapital: feeComponentSchema,
217-
lpFee: feeComponentSchema,
218-
relayerTotal: feeComponentSchema,
219-
app: feeComponentSchema,
220277
}),
221278
inputAmount: bigNumberString,
279+
maxInputAmount: bigNumberString.optional(),
222280
expectedOutputAmount: bigNumberString,
223281
minOutputAmount: bigNumberString,
224282
expectedFillTime: positiveInteger,

0 commit comments

Comments
 (0)