diff --git a/sdk/src/quotes.ts b/sdk/src/quotes.ts index 55244e9..05c7034 100644 --- a/sdk/src/quotes.ts +++ b/sdk/src/quotes.ts @@ -119,9 +119,10 @@ const buildRainbowQuoteUrl = ({ * @param {EthereumAddress} params.fromAddress * @param {number} params.slippage * @param {boolean} params.refuel + * @param {number?} params.feePercentageBasisPoints * @returns {string} */ -const buildRainbowCrosschainQuoteUrl = ({ +export const buildRainbowCrosschainQuoteUrl = ({ chainId, toChainId, sellTokenAddress, @@ -130,6 +131,7 @@ const buildRainbowCrosschainQuoteUrl = ({ fromAddress, slippage, refuel, + feePercentageBasisPoints, }: { chainId: number; toChainId?: number; @@ -139,6 +141,7 @@ const buildRainbowCrosschainQuoteUrl = ({ fromAddress: EthereumAddress; slippage: number; refuel?: boolean; + feePercentageBasisPoints?: number; }) => { const searchParams = new URLSearchParams({ buyToken: buyTokenAddress, @@ -150,6 +153,9 @@ const buildRainbowCrosschainQuoteUrl = ({ slippage: String(slippage), swapType: SwapType.crossChain, toChainId: String(toChainId), + ...(feePercentageBasisPoints !== undefined + ? { feePercentageBasisPoints: String(feePercentageBasisPoints) } + : {}), }); return `${API_BASE_URL}/v1/quote?bridgeVersion=3&` + searchParams.toString(); }; @@ -297,6 +303,7 @@ export const getCrosschainQuote = async ( sellAmount, slippage, refuel = false, + feePercentageBasisPoints, } = params; if (!sellAmount || !toChainId) { @@ -306,6 +313,7 @@ export const getCrosschainQuote = async ( const url = buildRainbowCrosschainQuoteUrl({ buyTokenAddress, chainId, + feePercentageBasisPoints, fromAddress, refuel, sellAmount, diff --git a/sdk/tests/utils/build_url.test.ts b/sdk/tests/utils/build_url.test.ts new file mode 100644 index 0000000..626b84b --- /dev/null +++ b/sdk/tests/utils/build_url.test.ts @@ -0,0 +1,38 @@ +import { buildRainbowCrosschainQuoteUrl } from '../../src'; + +describe('when creating crosschain swap URL', () => { + it('should consider feePercentageBasisPoints if passed', () => { + expect( + buildRainbowCrosschainQuoteUrl({ + buyTokenAddress: '0x456', + chainId: 1, + feePercentageBasisPoints: 0, + fromAddress: '0x789', + refuel: false, + sellAmount: '100', + sellTokenAddress: '0x123', + slippage: 2, + toChainId: 137, + }) + ).toEqual( + 'https://swap.p.rainbow.me/v1/quote?bridgeVersion=3&buyToken=0x456&chainId=1&fromAddress=0x789&refuel=false&sellAmount=100&sellToken=0x123&slippage=2&swapType=cross-chain&toChainId=137&feePercentageBasisPoints=0' + ); + }); + it('should ignore feePercentageBasisPoints if not passed', () => { + expect( + buildRainbowCrosschainQuoteUrl({ + buyTokenAddress: '0x456', + chainId: 1, + // feePercentageBasisPoints not passed + fromAddress: '0x789', + refuel: false, + sellAmount: '100', + sellTokenAddress: '0x123', + slippage: 2, + toChainId: 137, + }) + ).toEqual( + 'https://swap.p.rainbow.me/v1/quote?bridgeVersion=3&buyToken=0x456&chainId=1&fromAddress=0x789&refuel=false&sellAmount=100&sellToken=0x123&slippage=2&swapType=cross-chain&toChainId=137' + ); + }); +});