Skip to content

Commit

Permalink
WT-1980 Update smart checkout fee types (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
imx-mikhala authored Dec 20, 2023
1 parent 9c1b4a4 commit 6e5b095
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 128 deletions.
1 change: 1 addition & 0 deletions packages/checkout/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {
ChainSlug,
CheckoutStatus,
ExchangeType,
FeeType,
FundingStepType,
GasEstimateType,
GasTokenType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { CheckoutConfiguration } from '../../../config';
import {
ChainId,
FeeType,
FundingStepType,
ItemType,
} from '../../../types';
Expand Down Expand Up @@ -130,7 +131,8 @@ describe('bridgeRoute', () => {
},
},
fees: {
approvalGasFees: {
approvalGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(0),
formattedAmount: utils.formatUnits(BigNumber.from(0), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -139,7 +141,8 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
bridgeGasFees: {
bridgeGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -150,6 +153,7 @@ describe('bridgeRoute', () => {
},
bridgeFees: [
{
type: FeeType.BRIDGE_FEE,
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -159,6 +163,7 @@ describe('bridgeRoute', () => {
},
},
{
type: FeeType.IMMUTABLE_FEE,
amount: BigNumber.from(4),
formattedAmount: utils.formatUnits(BigNumber.from(4), DEFAULT_TOKEN_DECIMALS),
token: {
Expand Down Expand Up @@ -221,7 +226,8 @@ describe('bridgeRoute', () => {
},
},
fees: {
approvalGasFees: {
approvalGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(0),
formattedAmount: utils.formatUnits(BigNumber.from(0), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -230,7 +236,8 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
bridgeGasFees: {
bridgeGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -241,6 +248,7 @@ describe('bridgeRoute', () => {
},
bridgeFees: [
{
type: FeeType.BRIDGE_FEE,
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -250,6 +258,7 @@ describe('bridgeRoute', () => {
},
},
{
type: FeeType.IMMUTABLE_FEE,
amount: BigNumber.from(4),
formattedAmount: utils.formatUnits(BigNumber.from(4), DEFAULT_TOKEN_DECIMALS),
token: {
Expand Down Expand Up @@ -432,7 +441,8 @@ describe('bridgeRoute', () => {
},
},
fees: {
approvalGasFees: {
approvalGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(1),
formattedAmount: utils.formatUnits(BigNumber.from(1), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -441,7 +451,8 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
bridgeGasFees: {
bridgeGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -452,6 +463,7 @@ describe('bridgeRoute', () => {
},
bridgeFees: [
{
type: FeeType.BRIDGE_FEE,
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -461,6 +473,7 @@ describe('bridgeRoute', () => {
},
},
{
type: FeeType.IMMUTABLE_FEE,
amount: BigNumber.from(4),
formattedAmount: utils.formatUnits(BigNumber.from(4), DEFAULT_TOKEN_DECIMALS),
token: {
Expand Down Expand Up @@ -533,7 +546,8 @@ describe('bridgeRoute', () => {
},
},
fees: {
approvalGasFees: {
approvalGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(1),
formattedAmount: utils.formatUnits(BigNumber.from(1), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -542,7 +556,8 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
bridgeGasFees: {
bridgeGasFee: {
type: FeeType.GAS,
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -553,6 +568,7 @@ describe('bridgeRoute', () => {
},
bridgeFees: [
{
type: FeeType.BRIDGE_FEE,
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
Expand All @@ -562,6 +578,7 @@ describe('bridgeRoute', () => {
},
},
{
type: FeeType.IMMUTABLE_FEE,
amount: BigNumber.from(4),
formattedAmount: utils.formatUnits(BigNumber.from(4), DEFAULT_TOKEN_DECIMALS),
token: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AvailableRoutingOptions,
BridgeFees,
TokenInfo,
FeeType,
} from '../../../types';
import { CheckoutConfiguration, getL1ChainId, getL2ChainId } from '../../../config';
import {
Expand All @@ -33,36 +34,47 @@ export const hasSufficientL1Eth = (
};

const constructFees = (
bridgeGasFees: BigNumber,
bridgeGasFee: BigNumber,
bridgeFee: BigNumber,
imtblFee: BigNumber,
approvalGasFees: BigNumber,
approvalGasFee: BigNumber,
token?: TokenInfo,
): BridgeFees => {
const bridgeFeeDecimals = token?.decimals ?? DEFAULT_TOKEN_DECIMALS;
const bridgeFees = [];

if (bridgeFee.gt(0)) {
bridgeFees.push({
type: FeeType.BRIDGE_FEE,
amount: bridgeFee,
formattedAmount: utils.formatUnits(bridgeFee, bridgeFeeDecimals),
token,
});
}

if (imtblFee.gt(0)) {
bridgeFees.push({
type: FeeType.IMMUTABLE_FEE,
amount: imtblFee,
formattedAmount: utils.formatUnits(imtblFee, bridgeFeeDecimals),
token,
});
}

return {
approvalGasFees: {
amount: approvalGasFees,
formattedAmount: utils.formatUnits(approvalGasFees, DEFAULT_TOKEN_DECIMALS),
approvalGasFee: {
type: FeeType.GAS,
amount: approvalGasFee,
formattedAmount: utils.formatUnits(approvalGasFee, DEFAULT_TOKEN_DECIMALS),
token,
},
bridgeGasFees: {
amount: bridgeGasFees,
formattedAmount: utils.formatUnits(bridgeGasFees, DEFAULT_TOKEN_DECIMALS),
bridgeGasFee: {
type: FeeType.GAS,
amount: bridgeGasFee,
formattedAmount: utils.formatUnits(bridgeGasFee, DEFAULT_TOKEN_DECIMALS),
token,
},
bridgeFees: [
{
amount: bridgeFee,
formattedAmount: utils.formatUnits(bridgeFee, bridgeFeeDecimals),
token,
},
{
amount: imtblFee,
formattedAmount: utils.formatUnits(imtblFee, bridgeFeeDecimals),
token,
},
],
bridgeFees,
};
};

Expand Down
Loading

0 comments on commit 6e5b095

Please sign in to comment.