Skip to content

Commit ee48c20

Browse files
authored
fix(rebalancer): align bridge execution with planned quote mode (#8635)
1 parent 78199f4 commit ee48c20

4 files changed

Lines changed: 607 additions & 50 deletions

File tree

typescript/rebalancer/src/bridges/LiFiBridge.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,49 @@ describe('LiFiBridge.quote() input validation', function () {
557557
});
558558
});
559559

560+
describe('LiFiBridge.quote() routing policy', function () {
561+
let bridge: LiFiBridge;
562+
563+
beforeEach(() => {
564+
bridge = new LiFiBridge(BRIDGE_CONFIG, testLogger);
565+
});
566+
567+
it('should use RECOMMENDED order for reverse toAmount quotes', async () => {
568+
const originalFetch = globalThis.fetch;
569+
let requestUrl = '';
570+
571+
globalThis.fetch = (async (input: URL | RequestInfo) => {
572+
requestUrl = String(input);
573+
return {
574+
ok: true,
575+
json: async () =>
576+
createLiFiStep({
577+
toChainId: 1151111081099710,
578+
toAmount: '5000000000',
579+
}),
580+
} as Response;
581+
}) as typeof fetch;
582+
583+
try {
584+
const quote = await bridge.quote({
585+
fromChain: 42161,
586+
toChain: 1151111081099710,
587+
fromToken: TOKEN_ADDR,
588+
toToken: TOKEN_ADDR,
589+
fromAddress: SENDER_ADDR,
590+
toAddress: SENDER_ADDR,
591+
toAmount: 5000000000n,
592+
});
593+
const params = new URL(requestUrl).searchParams;
594+
595+
expect(params.get('order')).to.equal('RECOMMENDED');
596+
expect(quote.requestParams.toAmount).to.equal(5000000000n);
597+
} finally {
598+
globalThis.fetch = originalFetch;
599+
}
600+
});
601+
});
602+
560603
describe('LiFiBridge.getStatus()', function () {
561604
let bridge: LiFiBridge;
562605

typescript/rebalancer/src/bridges/LiFiBridge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class LiFiBridge implements IExternalBridge {
381381
slippage: (params.slippage ?? this.config.defaultSlippage ?? 0.005)
382382
.toFixed(4)
383383
.replace(/\.?0+$/, ''),
384-
order: 'CHEAPEST',
384+
order: 'RECOMMENDED',
385385
integrator: this.config.integrator,
386386
});
387387

0 commit comments

Comments
 (0)