Skip to content

Commit bd65e7f

Browse files
fix: relay transaction fees (#7098)
## Explanation Determine Relay provider fees directly from data with no calculation. ## References Related to [#6186](MetaMask/MetaMask-planning#6186) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Read provider fees directly from Relay response (`fees.relayer.amountUsd`) and update quote normalization, types, and tests accordingly. > > - **Relay strategy** > - **Fee source**: Use `fees.relayer.amountUsd` for provider fee in `normalizeQuote` instead of deriving from `details`. > - **Types**: Update `RelayQuote` to remove `details.currencyIn` and replace `fees.gas` with `fees.relayer` in `src/strategy/relay/types.ts`. > - **Normalization**: Adjust provider fee calculation in `src/strategy/relay/relay-quotes.ts`. > - **Tests** > - Update `relay-quotes.test.ts` mocks and expectations to align with new `fees.relayer` structure and provider fee calculation. > - **Changelog** > - Add entry: Read Relay provider fees directly from response. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit b91a4ca. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ddf2247 commit bd65e7f

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

packages/transaction-pay-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Read Relay provider fees directly from response ([#7098](https://github.com/MetaMask/core/pull/7098))
13+
1014
## [4.0.0]
1115

1216
### Added

packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const QUOTE_REQUEST_MOCK: QuoteRequest = {
3737

3838
const QUOTE_MOCK = {
3939
details: {
40-
currencyIn: {
41-
amountUsd: '2.34',
42-
},
4340
currencyOut: {
4441
amountFormatted: '1.0',
4542
amountUsd: '1.23',
@@ -51,8 +48,8 @@ const QUOTE_MOCK = {
5148
timeEstimate: 300,
5249
},
5350
fees: {
54-
gas: {
55-
amountUsd: '3.45',
51+
relayer: {
52+
amountUsd: '1.11',
5653
},
5754
},
5855
steps: [

packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ function normalizeQuote(
164164
fullRequest: PayStrategyGetQuotesRequest,
165165
): TransactionPayQuote<RelayQuote> {
166166
const { messenger, transaction } = fullRequest;
167-
const { details } = quote;
168-
const { currencyIn, currencyOut } = details;
167+
const { details, fees } = quote;
169168

170169
const { usdToFiatRate } = getFiatRates(messenger, request);
171170

@@ -175,7 +174,7 @@ function normalizeQuote(
175174
);
176175

177176
const provider = getFiatValueFromUsd(
178-
new BigNumber(currencyIn.amountUsd).minus(currencyOut.amountUsd),
177+
new BigNumber(fees.relayer.amountUsd),
179178
usdToFiatRate,
180179
);
181180

packages/transaction-pay-controller/src/strategy/relay/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import type { Hex } from '@metamask/utils';
22

33
export type RelayQuote = {
44
details: {
5-
currencyIn: {
6-
amountUsd: string;
7-
};
85
currencyOut: {
96
amountFormatted: string;
107
amountUsd: string;
@@ -16,7 +13,7 @@ export type RelayQuote = {
1613
timeEstimate: number;
1714
};
1815
fees: {
19-
gas: {
16+
relayer: {
2017
amountUsd: string;
2118
};
2219
};

0 commit comments

Comments
 (0)