diff --git a/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.stories.tsx b/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.stories.tsx index 9fff3c8c8e..48a824efb8 100644 --- a/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.stories.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.stories.tsx @@ -22,7 +22,6 @@ storiesOf('Swap List Pool', module) ptPriceTokenB: '0', fee: '0.3', // 0.3% provider: 'minswap', - price: 2, batcherFee: {quantity: '1', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', @@ -38,7 +37,6 @@ storiesOf('Swap List Pool', module) ptPriceTokenB: '0', fee: '0.3', // 0.3% provider: 'sundaeswap', - price: 6, batcherFee: {quantity: '122', tokenId: ''}, deposit: {quantity: '432', tokenId: ''}, poolId: '23455', diff --git a/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.tsx b/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.tsx index 1b7580abcf..761f768943 100644 --- a/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/SelectPool/SelectPoolFromList/SelectPoolFromList.tsx @@ -1,13 +1,17 @@ import {useSwap} from '@yoroi/swap' -import {Swap} from '@yoroi/types' +import {Balance, Swap} from '@yoroi/types' +import BigNumber from 'bignumber.js' import React, {useState} from 'react' import {StyleSheet, Text, TouchableOpacity, View} from 'react-native' import LinearGradient from 'react-native-linear-gradient' -import {Spacer} from '../../../../../components' +import {Boundary, Spacer} from '../../../../../components' import {useMetrics} from '../../../../../metrics/metricsManager' import {useSelectedWallet} from '../../../../../SelectedWallet' import {COLORS} from '../../../../../theme' +import {YoroiWallet} from '../../../../../yoroi-wallets/cardano/types' +import {useTokenInfo} from '../../../../../yoroi-wallets/hooks' +import {Quantities} from '../../../../../yoroi-wallets/utils' import {useNavigateTo} from '../../navigation' import {PoolIcon} from '../../PoolIcon/PoolIcon' import {useStrings} from '../../strings' @@ -33,74 +37,109 @@ export const SelectPoolFromList = ({pools = []}: Props) => { navigate.startSwap() } + const decimals = wallet.primaryTokenInfo.decimals ?? 0 + const ticker = wallet.primaryTokenInfo.ticker + const protocolCapitalize = (protocol: string): string => protocol[0].toUpperCase() + protocol.substring(1) return ( - {pools.map((pool) => ( - - - - - - handleCardSelect(pool)} style={[styles.card]}> - - - - - - {protocolCapitalize(pool.provider)} - + {pools.map((pool) => { + const formattedDepositInPt = `${Quantities.format(pool.deposit.quantity, decimals, decimals)} ${ticker}` + const formattedBatcherFeeInPt = `${Quantities.format(pool.batcherFee.quantity, decimals, decimals)} ${ticker}` + + return ( + + + + + + handleCardSelect(pool)} style={[styles.card]}> + + + + - - - + {protocolCapitalize(pool.provider)} + - - {strings.price} + + + - {`${pool.price} ${wallet.primaryTokenInfo.ticker}`} + + + - - - + + - - {`${strings.tvl}, ${wallet.primaryTokenInfo.ticker}`} + + {`${strings.tvl}, ${wallet.primaryTokenInfo.ticker}`} - {pool.deposit.quantity} + {formattedDepositInPt} + - - - + + - - {strings.poolFee}, % + + {strings.poolFee}, % - {pool.fee}% + {pool.fee}% + - - - + + - - {`${strings.batcherFee}, ${wallet.primaryTokenInfo.ticker}`} + + {`${strings.batcherFee}, ${wallet.primaryTokenInfo.ticker}`} - {pool.batcherFee.quantity} + {formattedBatcherFeeInPt} + - - - + + + - - ))} + ) + })} + + ) +} + +type PriceInAdaProps = {pool: Swap.Pool; wallet: YoroiWallet; sell: Balance.Amount} +const PriceInAda = ({pool, wallet, sell}: PriceInAdaProps) => { + const strings = useStrings() + + const {decimals: decimalsA = 0}= useTokenInfo({wallet, tokenId: pool.tokenA.tokenId}) + const {decimals: decimalsB = 0}= useTokenInfo({wallet, tokenId: pool.tokenB.tokenId}) + + const scaleA = new BigNumber(10).pow(decimalsA) + const scaleB = new BigNumber(10).pow(decimalsB) + + const isSellTokenA = pool.tokenA.tokenId === sell.tokenId + const [dividend, divisor] = isSellTokenA + ? [new BigNumber(pool.ptPriceTokenB).multipliedBy(scaleB), new BigNumber(pool.ptPriceTokenA).multipliedBy(scaleA)] + : [new BigNumber(pool.ptPriceTokenA).multipliedBy(scaleA), new BigNumber(pool.ptPriceTokenB).multipliedBy(scaleB)] + // limit decimals + const ptPrice = divisor.isZero() ? '0' : dividend.dividedBy(divisor).toFixed(Math.max(decimalsA, decimalsB), BigNumber.ROUND_DOWN) + // const price = parsedPrice != null ? asQuantity(parsedPrice) : Quantities.zero + // const formattedPriceInPt = `${Quantities.format(price, 0, decimals)} ${ticker}` + return ( + + {strings.price} + + {ptPrice} ) } diff --git a/apps/wallet-mobile/src/features/Swap/common/mocks.ts b/apps/wallet-mobile/src/features/Swap/common/mocks.ts index b204b3c578..ac93729850 100644 --- a/apps/wallet-mobile/src/features/Swap/common/mocks.ts +++ b/apps/wallet-mobile/src/features/Swap/common/mocks.ts @@ -28,7 +28,6 @@ export const mocks = { tokenId: '0029cb7c88c7567b63d1a512c0ed626aa169688ec980730c0473b913.6c702083', }, poolId: '0029cb7c88c7567b63d1a512c0ed626aa169688ec980730c0473b913.702083', - price: 0.0890390378168252, provider: 'sundaeswap', tokenA: {quantity: asQuantity(20630071), tokenId: ''}, tokenB: { diff --git a/apps/wallet-mobile/src/i18n/locales/en-US.json b/apps/wallet-mobile/src/i18n/locales/en-US.json index 74fa00e732..21b3eed28c 100644 --- a/apps/wallet-mobile/src/i18n/locales/en-US.json +++ b/apps/wallet-mobile/src/i18n/locales/en-US.json @@ -168,7 +168,7 @@ "swap.swapScreen.enterSlippage": "Enter a value from 0% to 100%. You can also enter up to 1 decimal", "swap.swapScreen.poolVerification": "{pool} verification", "swap.swapScreen.volume": "Volume, 24h", - "swap.swapScreen.tvl": " TVL", + "swap.swapScreen.tvl": "TVL", "swap.listOrders.completed": "completed orders", "swap.listOrders.open": "open orders", "swap.listOrders.sheet.title": "Confirm order cancelation", diff --git a/packages/swap/src/adapters/openswap-api/api.mocks.ts b/packages/swap/src/adapters/openswap-api/api.mocks.ts index a38ee77bca..29b8166095 100644 --- a/packages/swap/src/adapters/openswap-api/api.mocks.ts +++ b/packages/swap/src/adapters/openswap-api/api.mocks.ts @@ -41,7 +41,6 @@ const createOrderData: Swap.CreateOrderData = { tokenB: {tokenId: '', quantity: '1000000000'}, ptPriceTokenA: '0', ptPriceTokenB: '0', - price: 0, batcherFee: {tokenId: '', quantity: '0'}, deposit: {tokenId: '', quantity: '2000000'}, poolId: @@ -78,7 +77,6 @@ const getPools: Swap.Pool[] = [ }, batcherFee: {quantity: '2000000', tokenId: ''}, fee: '0.3', - price: 0, poolId: '0be55d262b29f564998ff81efe21bdc0022621c12f15af08d0f2ddb1.7339a8bcda85e2c997d9f16beddbeb3ad755f5202f5cfd9cb08db346a1292c01', provider: 'minswap', @@ -100,7 +98,6 @@ const getPools: Swap.Pool[] = [ }, batcherFee: {quantity: '2000000', tokenId: ''}, fee: '0.3', - price: 0, poolId: '0be55d262b29f564998ff81efe21bdc0022621c12f15af08d0f2ddb1.7339a8bcda85e2c997d9f16beddbeb3ad755f5202f5cfd9cb08db346a1292c01', provider: 'sundaeswap', @@ -122,7 +119,6 @@ const getPools: Swap.Pool[] = [ }, batcherFee: {quantity: '2000000', tokenId: ''}, fee: '0.3', - price: 0, poolId: '0be55d262b29f564998ff81efe21bdc0022621c12f15af08d0f2ddb1.7339a8bcda85e2c997d9f16beddbeb3ad755f5202f5cfd9cb08db346a1292c01', provider: 'sundaeswap', diff --git a/packages/swap/src/helpers/mocks.ts b/packages/swap/src/helpers/mocks.ts index 2092fb7cde..a93eed89b0 100644 --- a/packages/swap/src/helpers/mocks.ts +++ b/packages/swap/src/helpers/mocks.ts @@ -9,7 +9,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'muesliswap_v2', - price: 0, batcherFee: {quantity: '950000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '1', @@ -25,7 +24,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'vyfi', - price: 0, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '2', @@ -41,7 +39,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'minswap', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '3', @@ -57,7 +54,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.35', // 0.35% provider: 'wingriders', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '4', @@ -73,7 +69,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '5', @@ -89,7 +84,6 @@ const mockedPools1: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.05', // 0.05% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '6', @@ -108,7 +102,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'muesliswap_v2', - price: 0, batcherFee: {quantity: '950000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -125,7 +118,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'vyfi', - price: 0, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -142,7 +134,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'minswap', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -159,7 +150,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.35', // 0.35% provider: 'wingriders', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -176,7 +166,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', // 0.3% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -193,7 +182,6 @@ const mockedPools2: Swap.Pool[] = [ ptPriceTokenB: '0.0695404765', fee: '0.05', // 0.05% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -211,7 +199,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.3', // 0.3% provider: 'muesliswap_v2', - price: 0, batcherFee: {quantity: '950000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -227,7 +214,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.3', // 0.3% provider: 'vyfi', - price: 0, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -243,7 +229,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.3', // 0.3% provider: 'minswap', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -259,7 +244,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.35', // 0.35% provider: 'wingriders', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -275,7 +259,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.3', // 0.3% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -291,7 +274,6 @@ const mockedPools3: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.05', // 0.05% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -309,7 +291,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenA: '0.06950020009', fee: '0.3', // 0.3% provider: 'muesliswap_v2', - price: 0, batcherFee: {quantity: '950000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -325,7 +306,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenA: '0.06950020009', fee: '0.3', // 0.3% provider: 'vyfi', - price: 0, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -341,7 +321,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenA: '0.06950020009', fee: '0.3', // 0.3% provider: 'minswap', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -357,7 +336,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.35', // 0.35% provider: 'wingriders', - price: 0, batcherFee: {quantity: '2000000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -373,7 +351,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenA: '0.06950020009', fee: '0.3', // 0.3% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -389,7 +366,6 @@ const mockedPools4: Swap.Pool[] = [ ptPriceTokenB: '0.06950020009', fee: '0.05', // 0.05% provider: 'sundaeswap', - price: 0, batcherFee: {quantity: '2500000', tokenId: ''}, deposit: {quantity: '2000000', tokenId: ''}, poolId: '0', @@ -483,7 +459,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'muesliswap_v2', - price: 0, batcherFee: { quantity: '950000', tokenId: '', @@ -581,7 +556,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'vyfi', - price: 0, batcherFee: { quantity: '1900000', tokenId: '', @@ -679,7 +653,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'minswap', - price: 0, batcherFee: { quantity: '2000000', tokenId: '', @@ -777,7 +750,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.35', provider: 'wingriders', - price: 0, batcherFee: { quantity: '2000000', tokenId: '', @@ -875,7 +847,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'sundaeswap', - price: 0, batcherFee: { quantity: '2500000', tokenId: '', @@ -973,7 +944,6 @@ const mockedOrderCalculations1: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.05', provider: 'sundaeswap', - price: 0, batcherFee: { quantity: '2500000', tokenId: '', @@ -1067,7 +1037,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'muesliswap_v2', - price: 0, batcherFee: { quantity: '950000', tokenId: '', @@ -1158,7 +1127,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'vyfi', - price: 0, batcherFee: { quantity: '1900000', tokenId: '', @@ -1249,7 +1217,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'minswap', - price: 0, batcherFee: { quantity: '2000000', tokenId: '', @@ -1340,7 +1307,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.35', provider: 'wingriders', - price: 0, batcherFee: { quantity: '2000000', tokenId: '', @@ -1431,7 +1397,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.3', provider: 'sundaeswap', - price: 0, batcherFee: { quantity: '2500000', tokenId: '', @@ -1522,7 +1487,6 @@ const mockedOrderCalculations2: SwapOrderCalculation[] = [ ptPriceTokenB: '0.0695404765', fee: '0.05', provider: 'sundaeswap', - price: 0, batcherFee: { quantity: '2500000', tokenId: '', diff --git a/packages/swap/src/helpers/orders/getBuyAmount.test.ts b/packages/swap/src/helpers/orders/amounts/getBuyAmount.test.ts similarity index 100% rename from packages/swap/src/helpers/orders/getBuyAmount.test.ts rename to packages/swap/src/helpers/orders/amounts/getBuyAmount.test.ts diff --git a/packages/swap/src/helpers/orders/getBuyAmount.ts b/packages/swap/src/helpers/orders/amounts/getBuyAmount.ts similarity index 89% rename from packages/swap/src/helpers/orders/getBuyAmount.ts rename to packages/swap/src/helpers/orders/amounts/getBuyAmount.ts index 97a746d963..d9c234d68c 100644 --- a/packages/swap/src/helpers/orders/getBuyAmount.ts +++ b/packages/swap/src/helpers/orders/amounts/getBuyAmount.ts @@ -1,9 +1,9 @@ import BigNumber from 'bignumber.js' import {Balance, Swap} from '@yoroi/types' -import {ceilDivision} from '../../utils/ceilDivision' -import {Quantities} from '../../utils/quantities' -import {asQuantity} from '../../utils/asQuantity' +import {ceilDivision} from '../../../utils/ceilDivision' +import {Quantities} from '../../../utils/quantities' +import {asQuantity} from '../../../utils/asQuantity' /** * Calculate the amount to buy based on the desired sell amount in a liquidity pool. diff --git a/packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.test.ts b/packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.test.ts similarity index 88% rename from packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.test.ts rename to packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.test.ts index 04bada4c1a..d0ac842251 100644 --- a/packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.test.ts +++ b/packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.test.ts @@ -1,5 +1,5 @@ -import {mockNumberLocale} from '../../adapters/intl/number-locale.mocks' -import {asQuantity} from '../../utils/asQuantity' +import {mockNumberLocale} from '../../../adapters/intl/number-locale.mocks' +import {asQuantity} from '../../../utils/asQuantity' import {getMinAdaReceiveAfterSlippage} from './getMinAdaReceiveAfterSlippage' describe('getMinAdaReceiveAfterSlippage', () => { diff --git a/packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.ts b/packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.ts similarity index 90% rename from packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.ts rename to packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.ts index 1eb61d5549..828abc1b15 100644 --- a/packages/swap/src/helpers/orders/getMinAdaReceiveAfterSlippage.ts +++ b/packages/swap/src/helpers/orders/amounts/getMinAdaReceiveAfterSlippage.ts @@ -1,6 +1,6 @@ import {Balance, Numbers} from '@yoroi/types' -import {Quantities} from '../../utils/quantities' -import {asQuantity} from '../../utils/asQuantity' +import {Quantities} from '../../../utils/quantities' +import {asQuantity} from '../../../utils/asQuantity' /** * Calculate the minimum amount of ADA received after accounting for slippage. diff --git a/packages/swap/src/helpers/orders/getQuantityWithSlippage.test.ts b/packages/swap/src/helpers/orders/amounts/getQuantityWithSlippage.test.ts similarity index 100% rename from packages/swap/src/helpers/orders/getQuantityWithSlippage.test.ts rename to packages/swap/src/helpers/orders/amounts/getQuantityWithSlippage.test.ts diff --git a/packages/swap/src/helpers/orders/getQuantityWithSlippage.ts b/packages/swap/src/helpers/orders/amounts/getQuantityWithSlippage.ts similarity index 80% rename from packages/swap/src/helpers/orders/getQuantityWithSlippage.ts rename to packages/swap/src/helpers/orders/amounts/getQuantityWithSlippage.ts index 6e50762b59..15c55cd18f 100644 --- a/packages/swap/src/helpers/orders/getQuantityWithSlippage.ts +++ b/packages/swap/src/helpers/orders/amounts/getQuantityWithSlippage.ts @@ -1,6 +1,6 @@ import {Balance} from '@yoroi/types' -import {ceilDivision} from '../../utils/ceilDivision' -import {asQuantity} from '../../utils/asQuantity' +import {ceilDivision} from '../../../utils/ceilDivision' +import {asQuantity} from '../../../utils/asQuantity' export const getQuantityWithSlippage = ( quantity: Balance.Quantity, diff --git a/packages/swap/src/helpers/orders/getSellAmount.test.ts b/packages/swap/src/helpers/orders/amounts/getSellAmount.test.ts similarity index 100% rename from packages/swap/src/helpers/orders/getSellAmount.test.ts rename to packages/swap/src/helpers/orders/amounts/getSellAmount.test.ts diff --git a/packages/swap/src/helpers/orders/getSellAmount.ts b/packages/swap/src/helpers/orders/amounts/getSellAmount.ts similarity index 90% rename from packages/swap/src/helpers/orders/getSellAmount.ts rename to packages/swap/src/helpers/orders/amounts/getSellAmount.ts index 34b985ba1a..38c1ee0e60 100644 --- a/packages/swap/src/helpers/orders/getSellAmount.ts +++ b/packages/swap/src/helpers/orders/amounts/getSellAmount.ts @@ -1,9 +1,9 @@ import BigNumber from 'bignumber.js' import {Balance, Swap} from '@yoroi/types' -import {ceilDivision} from '../../utils/ceilDivision' -import {Quantities} from '../../utils/quantities' -import {asQuantity} from '../../utils/asQuantity' +import {ceilDivision} from '../../../utils/ceilDivision' +import {Quantities} from '../../../utils/quantities' +import {asQuantity} from '../../../utils/asQuantity' /** * Calculate the amount to sell based on the desired buy amount in a liquidity pool. diff --git a/packages/swap/src/helpers/orders/getFrontendFee.test.ts b/packages/swap/src/helpers/orders/costs/getFrontendFee.test.ts similarity index 98% rename from packages/swap/src/helpers/orders/getFrontendFee.test.ts rename to packages/swap/src/helpers/orders/costs/getFrontendFee.test.ts index 001724a096..4801478704 100644 --- a/packages/swap/src/helpers/orders/getFrontendFee.test.ts +++ b/packages/swap/src/helpers/orders/costs/getFrontendFee.test.ts @@ -1,9 +1,9 @@ import {Balance} from '@yoroi/types' import {getFrontendFee} from './getFrontendFee' -import {milkHoldersDiscountTiers} from '../../translators/constants' -import {Quantities} from '../../utils/quantities' -import {asQuantity} from '../../utils/asQuantity' +import {milkHoldersDiscountTiers} from '../../../translators/constants' +import {Quantities} from '../../../utils/quantities' +import {asQuantity} from '../../../utils/asQuantity' describe('getFrontendFee', () => { const primaryTokenId = 'primary.token' diff --git a/packages/swap/src/helpers/orders/getFrontendFee.ts b/packages/swap/src/helpers/orders/costs/getFrontendFee.ts similarity index 95% rename from packages/swap/src/helpers/orders/getFrontendFee.ts rename to packages/swap/src/helpers/orders/costs/getFrontendFee.ts index 8dd09d8eb1..e66874c901 100644 --- a/packages/swap/src/helpers/orders/getFrontendFee.ts +++ b/packages/swap/src/helpers/orders/costs/getFrontendFee.ts @@ -1,12 +1,12 @@ import {Balance} from '@yoroi/types' import BigNumber from 'bignumber.js' -import {Quantities} from '../../utils/quantities' +import {Quantities} from '../../../utils/quantities' import { SwapDiscountTier, milkHoldersDiscountTiers, -} from '../../translators/constants' -import {asQuantity} from '../../utils/asQuantity' +} from '../../../translators/constants' +import {asQuantity} from '../../../utils/asQuantity' /** * Calculates the frontend fee and selects a discount tier for a swap transaction. diff --git a/packages/swap/src/helpers/orders/getLiquidityProviderFee.test.ts b/packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.test.ts similarity index 90% rename from packages/swap/src/helpers/orders/getLiquidityProviderFee.test.ts rename to packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.test.ts index 63ccc03b78..ec2584c8f7 100644 --- a/packages/swap/src/helpers/orders/getLiquidityProviderFee.test.ts +++ b/packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.test.ts @@ -1,6 +1,6 @@ -import {Quantities} from '../../utils/quantities' +import {Quantities} from '../../../utils/quantities' import {getLiquidityProviderFee} from './getLiquidityProviderFee' -import {asQuantity} from '../../utils/asQuantity' +import {asQuantity} from '../../../utils/asQuantity' describe('getLiquidityProviderFee', () => { it('should return zero when sell quantity is zero', () => { diff --git a/packages/swap/src/helpers/orders/getLiquidityProviderFee.ts b/packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.ts similarity index 73% rename from packages/swap/src/helpers/orders/getLiquidityProviderFee.ts rename to packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.ts index 62f790e2ad..b3018b98b4 100644 --- a/packages/swap/src/helpers/orders/getLiquidityProviderFee.ts +++ b/packages/swap/src/helpers/orders/costs/getLiquidityProviderFee.ts @@ -1,7 +1,7 @@ import {Balance} from '@yoroi/types' -import {Quantities} from '../../utils/quantities' -import {ceilDivision} from '../../utils/ceilDivision' -import {asQuantity} from '../../utils/asQuantity' +import {Quantities} from '../../../utils/quantities' +import {ceilDivision} from '../../../utils/ceilDivision' +import {asQuantity} from '../../../utils/asQuantity' export const getLiquidityProviderFee = ( poolFee: string, diff --git a/packages/swap/src/helpers/orders/makeLimitOrder.test.ts b/packages/swap/src/helpers/orders/factories/makeLimitOrder.test.ts similarity index 96% rename from packages/swap/src/helpers/orders/makeLimitOrder.test.ts rename to packages/swap/src/helpers/orders/factories/makeLimitOrder.test.ts index 3e484d5f45..e104036cfa 100644 --- a/packages/swap/src/helpers/orders/makeLimitOrder.test.ts +++ b/packages/swap/src/helpers/orders/factories/makeLimitOrder.test.ts @@ -14,11 +14,10 @@ describe('makeLimitOrder', () => { const pool: Swap.Pool = { tokenA: {quantity: '4500000', tokenId: 'tokenA'}, tokenB: {quantity: '9000000', tokenId: 'tokenB'}, - ptPriceTokenA: '0', - ptPriceTokenB: '0', + ptPriceTokenA: '1', + ptPriceTokenB: '0.5', fee: '0.3', provider: 'minswap', - price: 2, batcherFee: {quantity: '1', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', diff --git a/packages/swap/src/helpers/orders/makeLimitOrder.ts b/packages/swap/src/helpers/orders/factories/makeLimitOrder.ts similarity index 92% rename from packages/swap/src/helpers/orders/makeLimitOrder.ts rename to packages/swap/src/helpers/orders/factories/makeLimitOrder.ts index 9d1d5c6be6..bd19798232 100644 --- a/packages/swap/src/helpers/orders/makeLimitOrder.ts +++ b/packages/swap/src/helpers/orders/factories/makeLimitOrder.ts @@ -1,5 +1,5 @@ import {Balance, Swap} from '@yoroi/types' -import {getQuantityWithSlippage} from './getQuantityWithSlippage' +import {getQuantityWithSlippage} from '../amounts/getQuantityWithSlippage' /** * Create a limit order with specified parameters. diff --git a/packages/swap/src/helpers/orders/makeOrderCalculations.ts b/packages/swap/src/helpers/orders/factories/makeOrderCalculations.ts similarity index 91% rename from packages/swap/src/helpers/orders/makeOrderCalculations.ts rename to packages/swap/src/helpers/orders/factories/makeOrderCalculations.ts index 8f555035ef..1e38b5d8a2 100644 --- a/packages/swap/src/helpers/orders/makeOrderCalculations.ts +++ b/packages/swap/src/helpers/orders/factories/makeOrderCalculations.ts @@ -1,14 +1,14 @@ import {Balance, Swap} from '@yoroi/types' import {BigNumber} from 'bignumber.js' -import {SwapOrderCalculation} from '../../translators/reactjs/state/state' -import {getQuantityWithSlippage} from './getQuantityWithSlippage' -import {getLiquidityProviderFee} from './getLiquidityProviderFee' -import {getFrontendFee} from './getFrontendFee' -import {getMarketPrice} from './getMarketPrice' -import {getBuyAmount} from './getBuyAmount' -import {getSellAmount} from './getSellAmount' -import {asQuantity} from '../../utils/asQuantity' -import {Quantities} from '../../utils/quantities' +import {SwapOrderCalculation} from '../../../translators/reactjs/state/state' +import {getQuantityWithSlippage} from '../amounts/getQuantityWithSlippage' +import {getLiquidityProviderFee} from '../costs/getLiquidityProviderFee' +import {getFrontendFee} from '../costs/getFrontendFee' +import {getMarketPrice} from '../../prices/getMarketPrice' +import {getBuyAmount} from '../amounts/getBuyAmount' +import {getSellAmount} from '../amounts/getSellAmount' +import {asQuantity} from '../../../utils/asQuantity' +import {Quantities} from '../../../utils/quantities' export const makeOrderCalculations = ({ orderType, diff --git a/packages/swap/src/helpers/orders/makePossibleMarketOrder.test.ts b/packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.test.ts similarity index 98% rename from packages/swap/src/helpers/orders/makePossibleMarketOrder.test.ts rename to packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.test.ts index 3146240bf9..849f789b43 100644 --- a/packages/swap/src/helpers/orders/makePossibleMarketOrder.test.ts +++ b/packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.test.ts @@ -19,7 +19,6 @@ describe('makePossibleMarketOrder', () => { ptPriceTokenB: '0', fee: '0.3', provider: 'minswap', - price: 2, batcherFee: {quantity: '1', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', @@ -35,7 +34,6 @@ describe('makePossibleMarketOrder', () => { ptPriceTokenB: '0', fee: '0.3', provider: 'sundaeswap', - price: 2, batcherFee: {quantity: '10', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', diff --git a/packages/swap/src/helpers/orders/makePossibleMarketOrder.ts b/packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.ts similarity index 92% rename from packages/swap/src/helpers/orders/makePossibleMarketOrder.ts rename to packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.ts index 24c659212b..e5dccb5e4a 100644 --- a/packages/swap/src/helpers/orders/makePossibleMarketOrder.ts +++ b/packages/swap/src/helpers/orders/factories/makePossibleMarketOrder.ts @@ -1,7 +1,7 @@ import {Balance, Swap} from '@yoroi/types' -import {getBuyAmount} from './getBuyAmount' -import {getQuantityWithSlippage} from './getQuantityWithSlippage' +import {getBuyAmount} from '../amounts/getBuyAmount' +import {getQuantityWithSlippage} from '../amounts/getQuantityWithSlippage' /** * Create a possible market order choosing the best pool based on the given parameters. diff --git a/packages/swap/src/helpers/pools/getBestBuyPool.test.ts b/packages/swap/src/helpers/pools/getBestBuyPool.test.ts index 525c6b802e..05a2aecce2 100644 --- a/packages/swap/src/helpers/pools/getBestBuyPool.test.ts +++ b/packages/swap/src/helpers/pools/getBestBuyPool.test.ts @@ -1,7 +1,7 @@ import {Balance} from '@yoroi/types' import {getBestBuyPool} from './getBestBuyPool' -import {getBuyAmount} from '../orders/getBuyAmount' +import {getBuyAmount} from '../orders/amounts/getBuyAmount' import {mocks} from '../mocks' describe('getBestBuyPool', () => { diff --git a/packages/swap/src/helpers/pools/getBestBuyPool.ts b/packages/swap/src/helpers/pools/getBestBuyPool.ts index 56a70f66c7..082834c1e2 100644 --- a/packages/swap/src/helpers/pools/getBestBuyPool.ts +++ b/packages/swap/src/helpers/pools/getBestBuyPool.ts @@ -1,8 +1,8 @@ import {Balance, Swap} from '@yoroi/types' import {Quantities} from '../../utils/quantities' -import {getBuyAmount} from '../orders/getBuyAmount' -import {getPriceAfterFee} from '../orders/getPriceAfterFee' +import {getBuyAmount} from '../orders/amounts/getBuyAmount' +import {getPriceAfterFee} from '../prices/getPriceAfterFee' import BigNumber from 'bignumber.js' /** diff --git a/packages/swap/src/helpers/pools/getBestSellPool.test.ts b/packages/swap/src/helpers/pools/getBestSellPool.test.ts index 2b636e5b59..0c6a599ca2 100644 --- a/packages/swap/src/helpers/pools/getBestSellPool.test.ts +++ b/packages/swap/src/helpers/pools/getBestSellPool.test.ts @@ -1,7 +1,7 @@ import {Balance} from '@yoroi/types' import {getBestSellPool} from './getBestSellPool' -import {getSellAmount} from '../orders/getSellAmount' +import {getSellAmount} from '../orders/amounts/getSellAmount' import {mocks} from '../mocks' describe('getBestSellPool', () => { diff --git a/packages/swap/src/helpers/pools/getBestSellPool.ts b/packages/swap/src/helpers/pools/getBestSellPool.ts index 83c6922bd4..747e489332 100644 --- a/packages/swap/src/helpers/pools/getBestSellPool.ts +++ b/packages/swap/src/helpers/pools/getBestSellPool.ts @@ -2,8 +2,8 @@ import {Balance, Swap} from '@yoroi/types' import {Quantities} from '../../utils/quantities' import BigNumber from 'bignumber.js' -import {getPriceAfterFee} from '../orders/getPriceAfterFee' -import {getSellAmount} from '../orders/getSellAmount' +import {getPriceAfterFee} from '../prices/getPriceAfterFee' +import {getSellAmount} from '../orders/amounts/getSellAmount' /** * Find the best pool to sell based on the desired sell amount in a liquidity pool. diff --git a/packages/swap/src/helpers/orders/getMarketPrice.test.ts b/packages/swap/src/helpers/prices/getMarketPrice.test.ts similarity index 100% rename from packages/swap/src/helpers/orders/getMarketPrice.test.ts rename to packages/swap/src/helpers/prices/getMarketPrice.test.ts diff --git a/packages/swap/src/helpers/orders/getMarketPrice.ts b/packages/swap/src/helpers/prices/getMarketPrice.ts similarity index 100% rename from packages/swap/src/helpers/orders/getMarketPrice.ts rename to packages/swap/src/helpers/prices/getMarketPrice.ts diff --git a/packages/swap/src/helpers/prices/getPairPriceInPtTerms.test.ts b/packages/swap/src/helpers/prices/getPairPriceInPtTerms.test.ts new file mode 100644 index 0000000000..13ee88b0af --- /dev/null +++ b/packages/swap/src/helpers/prices/getPairPriceInPtTerms.test.ts @@ -0,0 +1,58 @@ +import {Swap} from '@yoroi/types' +import {getPairPriceInPtTerms} from './getPairPriceInPtTerms' + +describe('getPriceAfterFee', () => { + it('should calculate the correct price based on sides and decimals', () => { + // arrange + const pool: Swap.Pool = { + tokenA: {quantity: '1', tokenId: 'tokenA'}, + tokenB: {quantity: '2', tokenId: 'tokenB'}, + ptPriceTokenA: '0.03465765134', + ptPriceTokenB: '3.81247293317', + fee: '0.3', // 0.3% + provider: 'minswap', + batcherFee: {quantity: '950000', tokenId: ''}, + deposit: {quantity: '1', tokenId: ''}, + poolId: '0', + lpToken: { + quantity: '0', + tokenId: '0', + }, + } + + // act + const pricesAB = getPairPriceInPtTerms({ + amountA: pool.tokenA, + decimalsA: 6, + decimalsB: 0, + ptPriceTokenA: '1', + ptPriceTokenB: '8566.52826101672', + sell: { + quantity: '1', + tokenId: 'tokenA', + }, + }) + + const pricesBA = getPairPriceInPtTerms({ + amountA: pool.tokenA, + decimalsA: 6, + decimalsB: 0, + ptPriceTokenA: '1', + ptPriceTokenB: '8566.52826101672', + sell: { + quantity: '1', + tokenId: 'tokenB', + }, + }) + + // assert + expect(pricesAB).toStrictEqual({ + ptPriceAB: '0.008566', + ptPriceBA: '116.733403', + }) + expect(pricesBA).toStrictEqual({ + ptPriceAB: '116.733403', + ptPriceBA: '0.008566', + }) + }) +}) diff --git a/packages/swap/src/helpers/prices/getPairPriceInPtTerms.ts b/packages/swap/src/helpers/prices/getPairPriceInPtTerms.ts new file mode 100644 index 0000000000..c8969e69b4 --- /dev/null +++ b/packages/swap/src/helpers/prices/getPairPriceInPtTerms.ts @@ -0,0 +1,49 @@ +import {Balance} from '@yoroi/types' +import {BigNumber} from 'bignumber.js' +export const getPairPriceInPtTerms = ({ + sell, + amountA, + decimalsA = 0, + decimalsB = 0, + // prices not scaled - visual + ptPriceTokenA, + ptPriceTokenB, + precision, +}: { + sell: Balance.Amount + amountA: Balance.Amount + decimalsA: number + decimalsB: number + ptPriceTokenA: string + ptPriceTokenB: string + precision?: number +}) => { + const calculatePrice = ( + dividend: BigNumber, + divisor: BigNumber, + scale: number, + ) => { + return divisor.isZero() + ? '0' + : dividend + .dividedBy(divisor) + .toFixed(precision ?? scale, BigNumber.ROUND_DOWN) + } + + const scaleA = new BigNumber(10).pow(decimalsA) + const scaleB = new BigNumber(10).pow(decimalsB) + + const isSellTokenA = amountA.tokenId === sell.tokenId + const priceA = new BigNumber(ptPriceTokenA).multipliedBy(scaleA) + const priceB = new BigNumber(ptPriceTokenB).multipliedBy(scaleB) + + const ptPriceAB = isSellTokenA + ? calculatePrice(priceB, priceA, Math.max(decimalsA, decimalsB)) + : calculatePrice(priceA, priceB, Math.max(decimalsA, decimalsB)) + + const ptPriceBA = isSellTokenA + ? calculatePrice(priceA, priceB, Math.max(decimalsA, decimalsB)) + : calculatePrice(priceB, priceA, Math.max(decimalsA, decimalsB)) + + return {ptPriceAB, ptPriceBA} +} diff --git a/packages/swap/src/helpers/orders/getPriceAfterFee.test.ts b/packages/swap/src/helpers/prices/getPriceAfterFee.test.ts similarity index 98% rename from packages/swap/src/helpers/orders/getPriceAfterFee.test.ts rename to packages/swap/src/helpers/prices/getPriceAfterFee.test.ts index 44e24ab60f..85c2ac6b52 100644 --- a/packages/swap/src/helpers/orders/getPriceAfterFee.test.ts +++ b/packages/swap/src/helpers/prices/getPriceAfterFee.test.ts @@ -11,7 +11,6 @@ describe('getPriceAfterFee', () => { ptPriceTokenB: '3.81247293317', fee: '0.3', // 0.3% provider: 'minswap', - price: 2, batcherFee: {quantity: '950000', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', @@ -36,7 +35,6 @@ describe('getPriceAfterFee', () => { ptPriceTokenB: '1', fee: '0.3', // 0.3% provider: 'minswap', - price: 2, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', @@ -61,7 +59,6 @@ describe('getPriceAfterFee', () => { ptPriceTokenB: '1', fee: '0.3', // 0.3% provider: 'minswap', - price: 2, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', @@ -86,7 +83,6 @@ describe('getPriceAfterFee', () => { ptPriceTokenB: '1', fee: '0.3', // 0.3% provider: 'minswap', - price: 2, batcherFee: {quantity: '1900000', tokenId: ''}, deposit: {quantity: '1', tokenId: ''}, poolId: '0', diff --git a/packages/swap/src/helpers/orders/getPriceAfterFee.ts b/packages/swap/src/helpers/prices/getPriceAfterFee.ts similarity index 100% rename from packages/swap/src/helpers/orders/getPriceAfterFee.ts rename to packages/swap/src/helpers/prices/getPriceAfterFee.ts diff --git a/packages/swap/src/helpers/transformers.ts b/packages/swap/src/helpers/transformers.ts index 960dbe64bb..9626bd3224 100644 --- a/packages/swap/src/helpers/transformers.ts +++ b/packages/swap/src/helpers/transformers.ts @@ -150,7 +150,6 @@ export const transformersMaker = ( lpToken: asYoroiAmount(lpToken), batcherFee: asYoroiAmount({amount: batcherFee, address: undefined}), fee: poolFee, - price: 0, poolId, provider, } diff --git a/packages/swap/src/index.ts b/packages/swap/src/index.ts index e75a57dcec..91d86d1005 100644 --- a/packages/swap/src/index.ts +++ b/packages/swap/src/index.ts @@ -1,7 +1,4 @@ -export { - makeStorageMaker, - makeStorageMakerDefault, -} from './adapters/async-storage/storage.mocks' +// mocks export { mockSwapManager, mockSwapManagerDefault, @@ -10,16 +7,31 @@ export { export {mockSwapStateDefault} from './translators/reactjs/state/state.mocks' export {apiMocks} from './adapters/openswap-api/api.mocks' -export {getBuyAmount} from './helpers/orders/getBuyAmount' -export {getSellAmount} from './helpers/orders/getSellAmount' -export {makePossibleMarketOrder} from './helpers/orders/makePossibleMarketOrder' -export {getMarketPrice} from './helpers/orders/getMarketPrice' -export {getMinAdaReceiveAfterSlippage} from './helpers/orders/getMinAdaReceiveAfterSlippage' -export {getLiquidityProviderFee} from './helpers/orders/getLiquidityProviderFee' -export {makeLimitOrder} from './helpers/orders/makeLimitOrder' +// orders amounts +export {getBuyAmount} from './helpers/orders/amounts/getBuyAmount' +export {getSellAmount} from './helpers/orders/amounts/getSellAmount' +export {getMinAdaReceiveAfterSlippage} from './helpers/orders/amounts/getMinAdaReceiveAfterSlippage' +export {getQuantityWithSlippage} from './helpers/orders/amounts/getQuantityWithSlippage' +// orders factories +export {makePossibleMarketOrder} from './helpers/orders/factories/makePossibleMarketOrder' +export {makeLimitOrder} from './helpers/orders/factories/makeLimitOrder' +export {makeOrderCalculations} from './helpers/orders/factories/makeOrderCalculations' +// orders costs +export {getLiquidityProviderFee} from './helpers/orders/costs/getLiquidityProviderFee' +export {getFrontendFee} from './helpers/orders/costs/getFrontendFee' + +// prices +export {getMarketPrice} from './helpers/prices/getMarketPrice' +export {getPriceAfterFee} from './helpers/prices/getPriceAfterFee' +export {getPairPriceInPtTerms} from './helpers/prices/getPairPriceInPtTerms' +// pools export {getPoolUrlByProvider} from './helpers/pools/getPoolUrlByProvider' +export {getBestBuyPool} from './helpers/pools/getBestBuyPool' +export {getBestSellPool} from './helpers/pools/getBestSellPool' +export {getBestPoolCalculation} from './helpers/pools/getBestPoolCalculation' +// translators export {SwapProvider} from './translators/reactjs/provider/SwapProvider' export {SwapState} from './translators/reactjs/state/state' export {useSwapCreateOrder} from './translators/reactjs/hooks/useSwapCreateOrder' @@ -29,19 +41,21 @@ export {useSwapPoolsByPair} from './translators/reactjs/hooks/useSwapPoolsByPair export {useSwapSetSlippage} from './translators/reactjs/hooks/useSwapSetSlippage' export {useSwapSlippage} from './translators/reactjs/hooks/useSwapSlippage' export {useSwapTokensByPairToken} from './translators/reactjs/hooks/useSwapTokensByPairToken' +export {useSwap} from './translators/reactjs/hooks/useSwap' +export { + supportedProviders, + milkHoldersDiscountTiers, + milkTokenId, +} from './translators/constants' +// factories export {swapApiMaker} from './adapters/openswap-api/api' export {swapManagerMaker} from './manager' - -export {useSwap} from './translators/reactjs/hooks/useSwap' - export { swapStorageMaker, swapStorageSlippageKey, } from './adapters/async-storage/storage' - export { - supportedProviders, - milkHoldersDiscountTiers, - milkTokenId, -} from './translators/constants' + makeStorageMaker, + makeStorageMakerDefault, +} from './adapters/async-storage/storage.mocks' diff --git a/packages/swap/src/translators/reactjs/state/state.ts b/packages/swap/src/translators/reactjs/state/state.ts index d3e3e5191c..b97a604534 100644 --- a/packages/swap/src/translators/reactjs/state/state.ts +++ b/packages/swap/src/translators/reactjs/state/state.ts @@ -3,7 +3,7 @@ import {produce} from 'immer' import {Quantities} from '../../../utils/quantities' import {SwapDiscountTier} from '../../../translators/constants' -import {makeOrderCalculations} from '../../../helpers/orders/makeOrderCalculations' +import {makeOrderCalculations} from '../../../helpers/orders/factories/makeOrderCalculations' import {selectedPoolCalculationSelector} from './selectors/selectedPoolCalculationSelector' import {getBestPoolCalculation} from '../../../helpers/pools/getBestPoolCalculation' diff --git a/packages/types/src/swap/pool.ts b/packages/types/src/swap/pool.ts index bf34c0c970..27e4476e48 100644 --- a/packages/types/src/swap/pool.ts +++ b/packages/types/src/swap/pool.ts @@ -29,7 +29,6 @@ export type SwapPool = { tokenB: BalanceAmount ptPriceTokenA: string // float, current price in lovelace of tokenA, i.e. 0.000000000000000000. ptPriceTokenB: string // float, current price in lovelace of tokenB, i.e. 0.000000000000000000. - price: number // float, current price in tokenA / tokenB according to the pool, NOT SUITABLE for price calculations, just for display purposes, i.e. 0.9097362621640215. batcherFee: BalanceAmount deposit: BalanceAmount // amount of deposit / minUTxO required by protocol, returned to user, in lovelace. // utxo: string // txhash#txindex of latest transaction involving this pool.