Skip to content

Commit 1537907

Browse files
committed
feat: pass fee percent to LiFi quote
1 parent 5d2c045 commit 1537907

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/routes/lifi/LiFiRoute.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import type {
5959
ValidatedParams,
6060
ValidationResult,
6161
LiFiConfig,
62+
LiFiFeeConfig,
6263
} from './types';
6364
import { getAllTokenIdsForChain } from 'utils/tokenHelpers';
6465
import { sleep } from 'utils';
@@ -180,7 +181,7 @@ export class LiFiRoute<N extends Network>
180181
? canonicalAddress(request.recipient)
181182
: generateThrowawayAddress(toChain.chain);
182183

183-
const integrator = this.getIntegrator(request);
184+
const { integrator, feePercent } = this.getFeeConfig(request);
184185

185186
const quoteRequest: QuoteRequest = {
186187
fromChain: fromChainId,
@@ -196,7 +197,7 @@ export class LiFiRoute<N extends Network>
196197
maxPriceImpact: params.normalizedParams.maxPriceImpact,
197198
integrator,
198199
referrer: params.options.referrer,
199-
fee: params.options.fee,
200+
fee: feePercent,
200201
};
201202

202203
// Lifi SDK has a AllowDenyPrefer type but then it's converted into a different format for quote requests...
@@ -216,12 +217,12 @@ export class LiFiRoute<N extends Network>
216217
return getQuote(quoteRequest);
217218
}
218219

219-
getIntegrator(request: routes.RouteTransferRequest<N>): string {
220-
if (!this.config?.getIntegrator) {
221-
return DEFAULT_INTEGRATOR;
220+
getFeeConfig(request: routes.RouteTransferRequest<N>): LiFiFeeConfig {
221+
if (!this.config?.getFeeConfig) {
222+
return { integrator: DEFAULT_INTEGRATOR, feePercent: 0 };
222223
}
223224

224-
return this.config.getIntegrator(request);
225+
return this.config.getFeeConfig(request);
225226
}
226227

227228
async quote(
@@ -386,7 +387,7 @@ export function createLiFiRouteWithConfig<N extends Network>(
386387
// to avoid extra network calls to fetch chains which we don't need.
387388
lifiSdkConfig.set({
388389
// The integrator is required here so just set it to the default.
389-
// The actual integrator used will be set per-quote in fetchQuote()
390+
// The actual integrator used will be set per-quote in fetchQuote().
390391
integrator: DEFAULT_INTEGRATOR,
391392
apiUrl: config.apiUrl ?? DEFAULT_API_URL,
392393
});

src/routes/lifi/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export type Receipt = routes.Receipt & { tool: string };
4242
export type TransferParams = routes.TransferParams<Options>;
4343
export type ValidationResult = routes.ValidationResult<Options>;
4444

45+
export interface LiFiFeeConfig {
46+
integrator: string;
47+
feePercent: number; // e.g., 0.01 = 1%
48+
}
49+
4550
export interface LiFiConfig<N extends Network> {
4651
apiUrl?: string;
47-
getIntegrator?: (request: routes.RouteTransferRequest<N>) => string;
52+
getFeeConfig?: (request: routes.RouteTransferRequest<N>) => LiFiFeeConfig;
4853
}

0 commit comments

Comments
 (0)