Skip to content

Commit

Permalink
feat: exposing parameter (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
fringlesinthestreet authored Jun 11, 2024
1 parent c7e5989 commit 3c8ce53
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sdk/src/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -130,6 +131,7 @@ const buildRainbowCrosschainQuoteUrl = ({
fromAddress,
slippage,
refuel,
feePercentageBasisPoints,
}: {
chainId: number;
toChainId?: number;
Expand All @@ -139,6 +141,7 @@ const buildRainbowCrosschainQuoteUrl = ({
fromAddress: EthereumAddress;
slippage: number;
refuel?: boolean;
feePercentageBasisPoints?: number;
}) => {
const searchParams = new URLSearchParams({
buyToken: buyTokenAddress,
Expand All @@ -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();
};
Expand Down Expand Up @@ -297,6 +303,7 @@ export const getCrosschainQuote = async (
sellAmount,
slippage,
refuel = false,
feePercentageBasisPoints,
} = params;

if (!sellAmount || !toChainId) {
Expand All @@ -306,6 +313,7 @@ export const getCrosschainQuote = async (
const url = buildRainbowCrosschainQuoteUrl({
buyTokenAddress,
chainId,
feePercentageBasisPoints,
fromAddress,
refuel,
sellAmount,
Expand Down
38 changes: 38 additions & 0 deletions sdk/tests/utils/build_url.test.ts
Original file line number Diff line number Diff line change
@@ -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'
);
});
});

0 comments on commit 3c8ce53

Please sign in to comment.