Skip to content

Commit

Permalink
WT-1734 Add fees to swap and bridge routes (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
imx-mikhala committed Oct 6, 2023
1 parent 06e780a commit 36855bf
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 446 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Environment } from '@imtbl/config';
import { JsonRpcProvider } from '@ethersproject/providers';
import { BigNumber } from 'ethers';
import { BigNumber, utils } from 'ethers';
import {
BridgeRequirement,
bridgeRoute,
Expand All @@ -12,6 +12,7 @@ import { CheckoutConfiguration } from '../../../config';
import {
BridgeRouteFeeEstimate,
ChainId,
DEFAULT_TOKEN_DECIMALS,
FundingRouteFeeEstimate,
FundingStepType,
ItemType,
Expand Down Expand Up @@ -47,22 +48,22 @@ describe('bridgeRoute', () => {
{
type: FundingStepType.BRIDGE,
gasFee: {
estimatedAmount: BigNumber.from(1),
estimatedAmount: BigNumber.from(2),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeFee: {
estimatedAmount: BigNumber.from(1),
estimatedAmount: BigNumber.from(3),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
totalFees: BigNumber.from(2),
totalFees: BigNumber.from(5),
},
],
]);
Expand Down Expand Up @@ -110,8 +111,8 @@ describe('bridgeRoute', () => {
},
},
{
balance: BigNumber.from(13),
formattedBalance: '13',
balance: BigNumber.from(16),
formattedBalance: '16',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -144,8 +145,8 @@ describe('bridgeRoute', () => {
formattedAmount: '10',
},
userBalance: {
balance: BigNumber.from(13),
formattedBalance: '13',
balance: BigNumber.from(16),
formattedBalance: '16',
},
token: {
name: 'Ethereum',
Expand All @@ -154,19 +155,33 @@ describe('bridgeRoute', () => {
address: undefined,
},
},
// WT-1734 - Add fees
fees: {
approvalGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
formattedAmount: utils.formatUnits(BigNumber.from(0), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeFees: [{
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
}],
},
});
Expand All @@ -178,8 +193,8 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(12),
formattedBalance: '12',
balance: BigNumber.from(15),
formattedBalance: '15',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -212,8 +227,8 @@ describe('bridgeRoute', () => {
formattedAmount: '10',
},
userBalance: {
balance: BigNumber.from(12),
formattedBalance: '12',
balance: BigNumber.from(15),
formattedBalance: '15',
},
token: {
name: 'Ethereum',
Expand All @@ -222,19 +237,33 @@ describe('bridgeRoute', () => {
address: undefined,
},
},
// WT-1734 - Add fees
fees: {
approvalGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
formattedAmount: utils.formatUnits(BigNumber.from(0), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeFees: [{
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
}],
},
});
Expand All @@ -246,8 +275,8 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(11),
formattedBalance: '11',
balance: BigNumber.from(14),
formattedBalance: '14',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -289,8 +318,8 @@ describe('bridgeRoute', () => {
},
},
{
balance: BigNumber.from(12),
formattedBalance: '12',
balance: BigNumber.from(20),
formattedBalance: '20',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -353,17 +382,17 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(10),
formattedBalance: '10',
balance: BigNumber.from(7),
formattedBalance: '7',
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
{
balance: BigNumber.from(11),
formattedBalance: '11',
balance: BigNumber.from(10),
formattedBalance: '10',
token: {
name: '0xERC20',
symbol: '0xERC20',
Expand Down Expand Up @@ -397,8 +426,8 @@ describe('bridgeRoute', () => {
formattedAmount: '10',
},
userBalance: {
balance: BigNumber.from(11),
formattedBalance: '11',
balance: BigNumber.from(10),
formattedBalance: '10',
},
token: {
name: '0xERC20',
Expand All @@ -407,19 +436,33 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
// WT-1734 - Add fees
fees: {
approvalGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(1),
formattedAmount: utils.formatUnits(BigNumber.from(1), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeFees: [{
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
}],
},
});
Expand All @@ -431,8 +474,8 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(2),
formattedBalance: '2',
balance: BigNumber.from(6),
formattedBalance: '6',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -485,19 +528,33 @@ describe('bridgeRoute', () => {
decimals: 18,
},
},
// WT-1734 - Add fees
fees: {
approvalGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(1),
formattedAmount: utils.formatUnits(BigNumber.from(1), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeGasFees: {
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(2),
formattedAmount: utils.formatUnits(BigNumber.from(2), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
},
bridgeFees: [{
amount: BigNumber.from(0),
formattedAmount: '0',
amount: BigNumber.from(3),
formattedAmount: utils.formatUnits(BigNumber.from(3), DEFAULT_TOKEN_DECIMALS),
token: {
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
},
}],
},
});
Expand All @@ -509,8 +566,8 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(2),
formattedBalance: '2',
balance: BigNumber.from(10),
formattedBalance: '10',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down Expand Up @@ -552,8 +609,8 @@ describe('bridgeRoute', () => {
success: true,
balances: [
{
balance: BigNumber.from(1),
formattedBalance: '1',
balance: BigNumber.from(4),
formattedBalance: '4',
token: {
name: 'Ethereum',
symbol: 'ETH',
Expand Down

0 comments on commit 36855bf

Please sign in to comment.