chore: remove fee compute for swap transaction and muliplier base inclusion fee for simulation#139
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates swap-transaction validation so that fee computation is no longer applied when decoding/validating a swap envelope from XDR, and adjusts the related unit test expectations.
Changes:
- Update
TransactionService.createValidatedSwapTransactionto stop using thecomputingFeereturn value and return the original decoded transaction. - Update
TransactionServiceswap-validation test expectations around Soroban invoke swap simulation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/snap/src/services/transaction/TransactionService.ts | Stops propagating the computingFee result through swap validation/return path. |
| packages/snap/src/services/transaction/TransactionService.test.ts | Updates Soroban swap validation test assertions to match the new return behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Bridge API swap transaction already include the fee — we trust it and do not recalculate. | ||
| // For Soroban invokes, computingFee simulates the transaction to validate it. | ||
| await this.computingFee(transaction); |
There was a problem hiding this comment.
this is expected, as we only using compute fee method to simulate if the txn is get though or not
| ); | ||
| } | ||
|
|
||
| // Get the min resource fee from the simulation response. |
There was a problem hiding this comment.
further to Stellar Team suggest, we should no need to change the resource fee
instead we should change the base fee (inclusion fee)
| timeout: this.#getTimeout(), | ||
| scope, | ||
| // Base fee is a placeholder until RPC simulation. | ||
| fee: BASE_FEE.toString(), |
There was a problem hiding this comment.
dont use fix fee here
| 'Invalid fee amount, falling back to configured inclusion fee', | ||
| ); | ||
| fee = BASE_FEE; | ||
| fee = baseInclusionFee(); |
There was a problem hiding this comment.
for fallback case, we should also do multiplier with the base fee
| /** | ||
| * Fetches the current base fee per operation from the Stellar network. | ||
| * Fetches the current Stellar network base fee and applies | ||
| * {@link AppConfig.transaction.baseFeeMultiplier} to produce the per-operation inclusion fee. | ||
| * | ||
| * @param scope - The CAIP-2 chain ID. | ||
| * @returns A Promise that resolves to the base fee as BigNumber. | ||
| * @returns A Promise that resolves to the inclusion fee in stroops. | ||
| * @throws {NetworkServiceException} If the fee cannot be fetched. | ||
| */ | ||
| async getBaseFee(scope: KnownCaip2ChainId): Promise<BigNumber> { |
There was a problem hiding this comment.
we keep getBaseFee for now, otherwise, it will be a lot of changes
| isSimErrorSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('applies simulationFeeMultiplier to minResourceFee before assembling', async () => { | ||
| const { simulateTransactionSpy } = getRpcServerSpies(); | ||
| const mockInvoke = createMockInvokeHostFunctionTransaction(); | ||
| const minResourceFee = '1000'; | ||
| const transactionData = new SorobanDataBuilder(); | ||
| const setResourceFeeSpy = jest.spyOn(transactionData, 'setResourceFee'); | ||
| simulateTransactionSpy.mockResolvedValue({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| _parsed: true, | ||
| id: '1', | ||
| latestLedger: 1, | ||
| events: [], | ||
| minResourceFee, | ||
| transactionData, | ||
| result: { auth: [] }, | ||
| } as never); | ||
|
|
||
| const result = await networkService.simulateTransaction( | ||
| mockInvoke, | ||
| scope, | ||
| ); | ||
|
|
||
| expect(result).toBeInstanceOf(Transaction); | ||
| expect(setResourceFeeSpy).toHaveBeenCalledWith( | ||
| new BigNumber(minResourceFee) | ||
| .multipliedBy(AppConfig.transaction.simulationFeeMultiplier) | ||
| .toString(), | ||
| ); | ||
| }); | ||
|
|
||
| it('calls RPC simulateTransaction with the wrapped envelope getRaw()', async () => { | ||
| const { simulateTransactionSpy } = getRpcServerSpies(); |
There was a problem hiding this comment.
this is no need to add a regression test
Explanation
References
Checklist