Skip to content

Commit 5f6afd1

Browse files
authored
feat(swap): track valora fee (#5368)
### Description As the title says. ### Test plan - Updated tests ### Related issues - Fixes RET-1061 ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)
1 parent 0776d57 commit 5f6afd1

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

src/analytics/Properties.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ type SwapQuoteEvent = SwapEvent & {
11831183
*/
11841184
estimatedPriceImpact: string | null
11851185
price: string
1186+
appFeePercentageIncludedInPrice: string | null | undefined
11861187
provider: string
11871188
}
11881189

@@ -1288,6 +1289,7 @@ interface SwapEventsProperties {
12881289
swapApproveTxId: string
12891290
estimatedSellTokenUsdValue?: number
12901291
estimatedBuyTokenUsdValue?: number
1292+
estimatedAppFeeUsdValue: number | undefined
12911293
areSwapTokensShuffled: boolean
12921294
}
12931295
[SwapEvents.swap_execute_error]: SwapQuoteEvent &
@@ -1301,6 +1303,7 @@ interface SwapEventsProperties {
13011303
swapApproveTxId: string
13021304
estimatedSellTokenUsdValue?: number
13031305
estimatedBuyTokenUsdValue?: number
1306+
estimatedAppFeeUsdValue: number | undefined
13041307
areSwapTokensShuffled: boolean
13051308
}
13061309
[SwapEvents.swap_learn_more]: undefined

src/swap/SwapScreen.test.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getDynamicConfigParams, getExperimentParams, getFeatureGate } from 'src
1616
import { StatsigFeatureGates } from 'src/statsig/types'
1717
import SwapScreen from 'src/swap/SwapScreen'
1818
import { swapStart } from 'src/swap/slice'
19-
import { Field } from 'src/swap/types'
19+
import { FetchQuoteResponse, Field } from 'src/swap/types'
2020
import { NO_QUOTE_ERROR_MESSAGE } from 'src/swap/useSwapQuote'
2121
import { NetworkId } from 'src/transactions/types'
2222
import { publicClient } from 'src/viem'
@@ -181,10 +181,12 @@ const renderScreen = ({
181181
}
182182
}
183183

184-
const defaultQuote = {
184+
const defaultQuote: FetchQuoteResponse = {
185185
unvalidatedSwapTransaction: {
186+
chainId: 44787,
186187
price: '1.2345678',
187188
guaranteedPrice: '1.1234567',
189+
appFeePercentageIncludedInPrice: undefined,
188190
sellTokenAddress: mockCeloAddress,
189191
buyTokenAddress: mockCusdAddress,
190192
sellAmount: '1234000000000000000',
@@ -195,7 +197,7 @@ const defaultQuote = {
195197
value: '0',
196198
data: '0x0',
197199
gas: '1800000',
198-
gasPrice: '500000000',
200+
estimatedGasUse: undefined,
199201
estimatedPriceImpact: '0.1',
200202
},
201203
details: {
@@ -995,6 +997,8 @@ describe('SwapScreen', () => {
995997
preparedTransactions,
996998
receivedAt: quoteReceivedTimestamp,
997999
price: defaultQuote.unvalidatedSwapTransaction.price,
1000+
appFeePercentageIncludedInPrice:
1001+
defaultQuote.unvalidatedSwapTransaction.appFeePercentageIncludedInPrice,
9981002
provider: defaultQuote.details.swapProvider,
9991003
estimatedPriceImpact: defaultQuote.unvalidatedSwapTransaction.estimatedPriceImpact,
10001004
allowanceTarget: defaultQuote.unvalidatedSwapTransaction.allowanceTarget,
@@ -1046,6 +1050,8 @@ describe('SwapScreen', () => {
10461050
preparedTransactions: [preparedTransactions[1]], // no approval transaction
10471051
receivedAt: expect.any(Number),
10481052
price: defaultQuote.unvalidatedSwapTransaction.price,
1053+
appFeePercentageIncludedInPrice:
1054+
defaultQuote.unvalidatedSwapTransaction.appFeePercentageIncludedInPrice,
10491055
provider: defaultQuote.details.swapProvider,
10501056
estimatedPriceImpact: defaultQuote.unvalidatedSwapTransaction.estimatedPriceImpact,
10511057
allowanceTarget: defaultQuote.unvalidatedSwapTransaction.allowanceTarget,
@@ -1091,6 +1097,8 @@ describe('SwapScreen', () => {
10911097
preparedTransactions,
10921098
receivedAt: quoteReceivedTimestamp,
10931099
price: defaultQuote.unvalidatedSwapTransaction.price,
1100+
appFeePercentageIncludedInPrice:
1101+
defaultQuote.unvalidatedSwapTransaction.appFeePercentageIncludedInPrice,
10941102
provider: defaultQuote.details.swapProvider,
10951103
estimatedPriceImpact: defaultQuote.unvalidatedSwapTransaction.estimatedPriceImpact,
10961104
allowanceTarget: defaultQuote.unvalidatedSwapTransaction.allowanceTarget,

src/swap/SwapScreen.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export function SwapScreen({ route }: Props) {
411411
}
412412

413413
const swapAmountParam = updatedField === Field.FROM ? 'sellAmount' : 'buyAmount'
414-
const { estimatedPriceImpact, price, allowanceTarget } = quote
414+
const { estimatedPriceImpact, price, appFeePercentageIncludedInPrice, allowanceTarget } = quote
415415

416416
const resultType = quote.preparedTransactions.type
417417
switch (resultType) {
@@ -434,6 +434,7 @@ export function SwapScreen({ route }: Props) {
434434
allowanceTarget,
435435
estimatedPriceImpact,
436436
price,
437+
appFeePercentageIncludedInPrice,
437438
provider: quote.provider,
438439
web3Library: 'viem',
439440
...getSwapTxsAnalyticsProperties(
@@ -454,6 +455,7 @@ export function SwapScreen({ route }: Props) {
454455
),
455456
receivedAt: quote.receivedAt,
456457
price: quote.price,
458+
appFeePercentageIncludedInPrice: quote.appFeePercentageIncludedInPrice,
457459
provider: quote.provider,
458460
estimatedPriceImpact,
459461
allowanceTarget,

src/swap/saga.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const mockSwapFromParams = (toTokenId: string, feeCurrency?: Address): PayloadAc
9797
},
9898
]),
9999
price: '1',
100+
appFeePercentageIncludedInPrice: '0.6',
100101
provider: '0x',
101102
estimatedPriceImpact: '0.1',
102103
allowanceTarget: mockAllowanceTarget,
@@ -145,6 +146,7 @@ const mockSwapEthereum: PayloadAction<SwapInfo> = {
145146
},
146147
]),
147148
price: '1',
149+
appFeePercentageIncludedInPrice: '0.6',
148150
provider: '0x',
149151
estimatedPriceImpact: '0.1',
150152
allowanceTarget: mockAllowanceTarget,
@@ -430,6 +432,7 @@ describe(swapSubmitSaga, () => {
430432
amount: swapPrepared.payload.userInput.swapAmount[Field.TO],
431433
amountType: 'buyAmount',
432434
price: '1',
435+
appFeePercentageIncludedInPrice: '0.6',
433436
allowanceTarget: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
434437
estimatedPriceImpact: '0.1',
435438
provider: '0x',
@@ -440,6 +443,7 @@ describe(swapSubmitSaga, () => {
440443
quoteToTransactionElapsedTimeInMs: 10_000,
441444
estimatedBuyTokenUsdValue: 100,
442445
estimatedSellTokenUsdValue: 100,
446+
estimatedAppFeeUsdValue: 0.6,
443447
web3Library: 'viem',
444448
gas: 1384480,
445449
maxGasFee: 0.01661376,
@@ -663,6 +667,7 @@ describe(swapSubmitSaga, () => {
663667
amount: mockSwap.payload.userInput.swapAmount[Field.TO],
664668
amountType: 'buyAmount',
665669
price: '1',
670+
appFeePercentageIncludedInPrice: '0.6',
666671
allowanceTarget: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
667672
estimatedPriceImpact: '0.1',
668673
provider: '0x',
@@ -673,6 +678,7 @@ describe(swapSubmitSaga, () => {
673678
quoteToTransactionElapsedTimeInMs: 10_000,
674679
estimatedBuyTokenUsdValue: 100,
675680
estimatedSellTokenUsdValue: 100,
681+
estimatedAppFeeUsdValue: 0.6,
676682
web3Library: 'viem',
677683
gas: 1384480,
678684
maxGasFee: 0.01661376,

src/swap/saga.ts

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export function* swapSubmitSaga(action: PayloadAction<SwapInfo>) {
157157
const {
158158
provider,
159159
price,
160+
appFeePercentageIncludedInPrice,
160161
allowanceTarget,
161162
estimatedPriceImpact,
162163
preparedTransactions: serializablePreparedTransactions,
@@ -206,6 +207,7 @@ export function* swapSubmitSaga(action: PayloadAction<SwapInfo>) {
206207
amount,
207208
amountType,
208209
price,
210+
appFeePercentageIncludedInPrice,
209211
allowanceTarget,
210212
estimatedPriceImpact,
211213
provider,
@@ -214,6 +216,8 @@ export function* swapSubmitSaga(action: PayloadAction<SwapInfo>) {
214216
swapApproveTxId: swapApproveContext.id,
215217
estimatedSellTokenUsdValue,
216218
estimatedBuyTokenUsdValue,
219+
estimatedAppFeeUsdValue:
220+
(Number(appFeePercentageIncludedInPrice) / 100) * Number(estimatedSellTokenUsdValue),
217221
web3Library: 'viem' as const,
218222
areSwapTokensShuffled,
219223
...getSwapTxsAnalyticsProperties(preparedTransactions, fromToken.networkId, tokensById),

src/swap/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface SwapInfo {
5353
preparedTransactions: SerializableTransactionRequest[]
5454
receivedAt: number
5555
price: string
56+
appFeePercentageIncludedInPrice: string | undefined
5657
provider: string
5758
estimatedPriceImpact: string | null
5859
allowanceTarget: string

0 commit comments

Comments
 (0)