diff --git a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift index 44de1f9df51..2b865effb23 100644 --- a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift @@ -58,7 +58,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { didSet { if sellAmount != oldValue { // sell amount changed, new quotes are needed - swapResponse = nil + zeroExQuote = nil jupiterQuote = nil braveFee = nil // price quote requested for a different amount @@ -117,9 +117,9 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { @Published var isUpdatingPriceQuote = false /// The brave fee for the current price quote @Published var braveFee: BraveWallet.BraveSwapFeeResponse? - /// The SwapResponse / price quote currently being displayed for Ethereum swap. + /// The ZeroExQuote / price quote currently being displayed for Ethereum swap. /// The quote needs preserved to know when to show `protocolFeesForDisplay` fees. - @Published var swapResponse: BraveWallet.SwapResponse? + @Published var zeroExQuote: BraveWallet.ZeroExQuote? /// If the Brave Fee is voided for this swap. var isBraveFeeVoided: Bool { @@ -150,7 +150,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { guard let braveFee, let protocolFeePct = Double(braveFee.protocolFeePct), !protocolFeePct.isZero else { return nil } - if let swapResponse, swapResponse.fees.zeroExFee == nil { + if let zeroExQuote, zeroExQuote.fees.zeroExFee == nil { // `protocolFeePct` should only be surfaced to users if `zeroExFee` is non-null. return nil } @@ -308,10 +308,10 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { } } - private func swapParameters( + private func swapQuoteParameters( for base: SwapParamsBase, in network: BraveWallet.NetworkInfo - ) -> BraveWallet.SwapParams? { + ) -> BraveWallet.SwapQuoteParams? { guard let accountInfo = accountInfo, let sellToken = selectedFromToken, @@ -340,18 +340,22 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { sellAmountInWei = "" buyAmountInWei = weiFormatter.weiString(from: buyAmount.normalizedDecimals, radix: .decimal, decimals: Int(buyToken.decimals)) ?? "0" } - let swapParams = BraveWallet.SwapParams( - chainId: network.chainId, - takerAddress: accountInfo.address, - sellAmount: sellAmountInWei, - buyAmount: buyAmountInWei, - buyToken: buyAddress, - sellToken: sellAddress, - slippagePercentage: slippage, - gasPrice: "" + // We store 0.5% as 0.005, so multiply by 100 to get 0.5 + let slippagePercentage = slippage * 100 + let swapQuoteParams = BraveWallet.SwapQuoteParams( + from: accountInfo.accountId, + fromChainId: network.chainId, + fromToken: sellAddress, + fromAmount: sellAmountInWei, + to: accountInfo.accountId, + toChainId: network.chainId, + toToken: buyAddress, + toAmount: buyAmountInWei, + slippagePercentage: "\(slippagePercentage)", + routePriority: .recommended ) - return swapParams + return swapQuoteParams } @MainActor private func createEthSwapTransaction() async -> Bool { @@ -364,13 +368,13 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { defer { self.isMakingTx = false } let coin = accountInfo.coin let network = await rpcService.network(coin, origin: nil) - guard let swapParams = self.swapParameters(for: .perSellAsset, in: network) else { + guard let swapQuoteParams = self.swapQuoteParameters(for: .perSellAsset, in: network) else { self.state = .error(Strings.Wallet.unknownError) self.clearAllAmount() return false } - let (swapResponse, _, _) = await swapService.transactionPayload(swapParams) - guard let swapResponse = swapResponse else { + let (swapTransactionUnion, _, _) = await swapService.transaction(.init(zeroExTransactionParams: swapQuoteParams)) + guard let swapResponse = swapTransactionUnion?.zeroExTransaction else { self.state = .error(Strings.Wallet.unknownError) self.clearAllAmount() return false @@ -427,9 +431,9 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { /// Update price market and sell/buy amount fields based on `SwapParamsBase` @MainActor private func handleEthPriceQuoteResponse( - _ response: BraveWallet.SwapResponse, + _ response: BraveWallet.ZeroExQuote, base: SwapParamsBase, - swapParams: BraveWallet.SwapParams + swapQuoteParams: BraveWallet.SwapQuoteParams ) async { let weiFormatter = WeiFormatter(decimalFormatStyle: .decimals(precision: 18)) switch base { @@ -465,12 +469,14 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { } } - self.swapResponse = response + self.zeroExQuote = response let network = await rpcService.network(selectedFromToken?.coin ?? .eth, origin: nil) let (braveSwapFeeResponse, _) = await swapService.braveFee( .init( chainId: network.chainId, - swapParams: swapParams + inputToken: swapQuoteParams.fromToken, + outputToken: swapQuoteParams.toToken, + taker: swapQuoteParams.fromAccountId.address ) ) if let braveSwapFeeResponse { @@ -576,7 +582,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { return bumpedValue.rounded().asString(radix: 16) } - @MainActor private func checkBalanceShowError(swapResponse: BraveWallet.SwapResponse) async { + @MainActor private func checkBalanceShowError(swapResponse: BraveWallet.ZeroExQuote) async { guard let accountInfo = accountInfo, let sellAmountValue = BDouble(sellAmount.normalizedDecimals), @@ -647,26 +653,16 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { } @MainActor private func fetchSolPriceQuote( - swapParams: BraveWallet.SwapParams, + swapQuoteParams: BraveWallet.SwapQuoteParams, network: BraveWallet.NetworkInfo ) async { - // 0.5% is 50bps. We store 0.5% as 0.005, so multiply by 10_000 - let slippageBps = Int32(swapParams.slippagePercentage * 10_000) - let jupiterQuoteParams: BraveWallet.JupiterQuoteParams = .init( - chainId: network.chainId, - inputMint: swapParams.sellToken, - outputMint: swapParams.buyToken, - amount: swapParams.sellAmount, - slippageBps: slippageBps, - userPublicKey: swapParams.takerAddress - ) self.isUpdatingPriceQuote = true - let (jupiterQuote, swapErrorResponse, _) = await swapService.jupiterQuote(jupiterQuoteParams) + let (swapQuoteUnion, swapQuoteErrorUnion, _) = await swapService.quote(swapQuoteParams) defer { self.isUpdatingPriceQuote = false } guard !Task.isCancelled else { return } - if let jupiterQuote { - await self.handleSolPriceQuoteResponse(jupiterQuote, swapParams: swapParams) - } else if let swapErrorResponse { + if let jupiterQuote = swapQuoteUnion?.jupiterQuote { + await self.handleSolPriceQuoteResponse(jupiterQuote, swapQuoteParams: swapQuoteParams) + } else if let swapErrorResponse = swapQuoteErrorUnion?.jupiterError { // check balance first because error can be caused by insufficient balance if let sellTokenBalance = self.selectedFromTokenBalance, let sellAmountValue = BDouble(self.sellAmount.normalizedDecimals), @@ -689,22 +685,21 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { @MainActor private func handleSolPriceQuoteResponse( _ response: BraveWallet.JupiterQuote, - swapParams: BraveWallet.SwapParams + swapQuoteParams: BraveWallet.SwapQuoteParams ) async { - guard let route = response.routes.first else { return } self.jupiterQuote = response let formatter = WeiFormatter(decimalFormatStyle: .balance) if let selectedToToken { - buyAmount = formatter.decimalString(for: "\(route.otherAmountThreshold)", radix: .decimal, decimals: Int(selectedToToken.decimals)) ?? "" + buyAmount = formatter.decimalString(for: response.outAmount, radix: .decimal, decimals: Int(selectedToToken.decimals)) ?? "" } // No exchange rate is returned by Jupiter API, so we estimate it from the quote. if let selectedFromToken, - let newFromAmount = formatter.decimalString(for: "\(route.inAmount)", radix: .decimal, decimals: Int(selectedFromToken.decimals)), + let newFromAmount = formatter.decimalString(for: response.inAmount, radix: .decimal, decimals: Int(selectedFromToken.decimals)), let newFromAmountWrapped = BDouble(newFromAmount), let selectedToToken, - let newToAmount = formatter.decimalString(for: "\(route.otherAmountThreshold)", radix: .decimal, decimals: Int(selectedToToken.decimals)), + let newToAmount = formatter.decimalString(for: response.outAmount, radix: .decimal, decimals: Int(selectedToToken.decimals)), let newToAmountWrapped = BDouble(newToAmount), newFromAmountWrapped != 0 { let rate = newToAmountWrapped / newFromAmountWrapped @@ -715,8 +710,9 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { let (braveSwapFeeResponse, _) = await swapService.braveFee( .init( chainId: network.chainId, - swapParams: swapParams - ) + inputToken: swapQuoteParams.fromToken, + outputToken: swapQuoteParams.toToken, + taker: swapQuoteParams.fromAccountId.address) ) if let braveSwapFeeResponse { self.braveFee = braveSwapFeeResponse @@ -745,24 +741,20 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { @MainActor private func createSolSwapTransaction() async -> Bool { guard let jupiterQuote, - let route = jupiterQuote.routes.first, - let accountInfo = self.accountInfo, - let selectedToToken, - let selectedFromToken else { + let accountInfo = self.accountInfo else { return false } self.isMakingTx = true defer { self.isMakingTx = false } let network = await rpcService.network(.sol, origin: nil) - let jupiterSwapParams: BraveWallet.JupiterSwapParams = .init( + + let jupiterTransactionParams: BraveWallet.JupiterTransactionParams = .init( + quote: jupiterQuote, chainId: network.chainId, - route: route, - userPublicKey: accountInfo.address, - inputMint: selectedFromToken.contractAddress(in: network), - outputMint: selectedToToken.contractAddress(in: network) + userPublicKey: accountInfo.address ) - let (swapTransactions, errorResponse, _) = await swapService.jupiterSwapTransactions(jupiterSwapParams) - guard let swapTransactions else { + let (swapTransactionUnion, errorResponseUnion, _) = await swapService.transaction(.init(jupiterTransactionParams: jupiterTransactionParams)) + guard let jupiterTransaction = swapTransactionUnion?.jupiterTransaction else { // check balance first because error can cause by insufficient balance if let sellTokenBalance = self.selectedFromTokenBalance, let sellAmountValue = BDouble(self.sellAmount.normalizedDecimals), @@ -771,7 +763,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { return false } // check if jupiterQuote fails due to insufficient liquidity - if errorResponse?.isInsufficientLiquidity == true { + if let errorResponse = errorResponseUnion?.jupiterError, errorResponse.isInsufficientLiquidity == true { self.state = .error(Strings.Wallet.insufficientLiquidity) return false } @@ -779,7 +771,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { return false } let (solTxData, status, _) = await solTxManagerProxy.makeTxData( - fromBase64EncodedTransaction: swapTransactions.swapTransaction, + fromBase64EncodedTransaction: jupiterTransaction, txType: .solanaSwap, send: .init( maxRetries: .init(maxRetries: 2), @@ -841,7 +833,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { priceQuoteTask?.cancel() priceQuoteTask = Task { @MainActor in // reset quotes before fetching new quote - swapResponse = nil + zeroExQuote = nil jupiterQuote = nil braveFee = nil guard let accountInfo else { @@ -853,7 +845,7 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { // Entering a buy amount is disabled for Solana swaps, always use // `SwapParamsBase.perSellAsset` to fetch quote based on the sell amount. // `SwapParamsBase.perBuyAsset` is sent when `selectedToToken` is changed. - guard let swapParams = self.swapParameters( + guard let swapQuoteParams = self.swapQuoteParameters( for: accountInfo.coin == .sol ? .perSellAsset : base, in: network ) else { @@ -862,9 +854,9 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { } switch accountInfo.coin { case .eth: - await fetchEthPriceQuote(base: base, swapParams: swapParams, network: network) + await fetchEthPriceQuote(base: base, swapQuoteParams: swapQuoteParams, network: network) case .sol: - await fetchSolPriceQuote(swapParams: swapParams, network: network) + await fetchSolPriceQuote(swapQuoteParams: swapQuoteParams, network: network) default: break } @@ -873,16 +865,15 @@ public class SwapTokenStore: ObservableObject, WalletObserverStore { @MainActor private func fetchEthPriceQuote( base: SwapParamsBase, - swapParams: BraveWallet.SwapParams, + swapQuoteParams: BraveWallet.SwapQuoteParams, network: BraveWallet.NetworkInfo ) async { self.isUpdatingPriceQuote = true defer { self.isUpdatingPriceQuote = false } - let (swapResponse, swapErrorResponse, _) = await swapService.priceQuote(swapParams) - guard !Task.isCancelled else { return } - if let swapResponse = swapResponse { - await self.handleEthPriceQuoteResponse(swapResponse, base: base, swapParams: swapParams) - } else if let swapErrorResponse = swapErrorResponse { + let (swapQuoteUnion, swapQuoteErrorUnion, _) = await swapService.quote(swapQuoteParams) + if let swapResponse = swapQuoteUnion?.zeroExQuote { + await self.handleEthPriceQuoteResponse(swapResponse, base: base, swapQuoteParams: swapQuoteParams) + } else if let swapErrorResponse = swapQuoteErrorUnion?.zeroExError { // check balance first because error can cause by insufficient balance if let sellTokenBalance = self.selectedFromTokenBalance, let sellAmountValue = BDouble(self.sellAmount.normalizedDecimals), diff --git a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift index 0bec691a21d..9e6a050fd29 100644 --- a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift +++ b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift @@ -523,17 +523,6 @@ extension BraveWallet.KeyringId { } } -extension BraveWallet.BraveSwapFeeParams { - convenience init(chainId: String, swapParams: BraveWallet.SwapParams) { - self.init( - chainId: chainId, - inputToken: swapParams.sellToken, - outputToken: swapParams.buyToken, - taker: swapParams.takerAddress - ) - } -} - public extension String { /// Returns true if the string ends with a supported ENS extension. var endsWithSupportedENSExtension: Bool { diff --git a/Sources/BraveWallet/Preview Content/MockSwapService.swift b/Sources/BraveWallet/Preview Content/MockSwapService.swift index 29d258ea3cf..5042e37a479 100644 --- a/Sources/BraveWallet/Preview Content/MockSwapService.swift +++ b/Sources/BraveWallet/Preview Content/MockSwapService.swift @@ -13,28 +13,12 @@ class MockSwapService: BraveWalletSwapService { completion(true) } - func transactionPayload(_ params: BraveWallet.SwapParams, completion: @escaping (BraveWallet.SwapResponse?, BraveWallet.SwapErrorResponse?, String) -> Void) { - completion(.init(price: "", guaranteedPrice: "", to: "", data: "", value: "", gas: "", estimatedGas: "", gasPrice: "", protocolFee: "", minimumProtocolFee: "", buyTokenAddress: "", sellTokenAddress: "", buyAmount: "", sellAmount: "", allowanceTarget: "", sellTokenToEthRate: "", buyTokenToEthRate: "", estimatedPriceImpact: "", sources: [], fees: .init(zeroExFee: nil)), nil, "") + func transaction(_ params: BraveWallet.SwapTransactionParamsUnion, completion: @escaping (BraveWallet.SwapTransactionUnion?, BraveWallet.SwapErrorUnion?, String) -> Void) { + completion(.init(zeroExTransaction: .init(price: "", guaranteedPrice: "", to: "", data: "", value: "", gas: "", estimatedGas: "", gasPrice: "", protocolFee: "", minimumProtocolFee: "", buyTokenAddress: "", sellTokenAddress: "", buyAmount: "", sellAmount: "", allowanceTarget: "", sellTokenToEthRate: "", buyTokenToEthRate: "", estimatedPriceImpact: "", sources: [], fees: .init(zeroExFee: nil))), nil, "") } - func priceQuote(_ params: BraveWallet.SwapParams, completion: @escaping (BraveWallet.SwapResponse?, BraveWallet.SwapErrorResponse?, String) -> Void) { - completion(.init(price: "", guaranteedPrice: "", to: "", data: "", value: "", gas: "", estimatedGas: "", gasPrice: "", protocolFee: "", minimumProtocolFee: "", buyTokenAddress: "", sellTokenAddress: "", buyAmount: "", sellAmount: "", allowanceTarget: "", sellTokenToEthRate: "", buyTokenToEthRate: "", estimatedPriceImpact: "", sources: [], fees: .init(zeroExFee: nil)), nil, "") - } - - func jupiterQuote(_ params: BraveWallet.JupiterQuoteParams, completion: @escaping (BraveWallet.JupiterQuote?, BraveWallet.JupiterErrorResponse?, String) -> Void) { - completion(nil, nil, "") - } - - func jupiterSwapTransactions(_ params: BraveWallet.JupiterSwapParams, completion: @escaping (Bool, BraveWallet.JupiterSwapTransactions?, String?) -> Void) { - completion(false, nil, nil) - } - - func hasJupiterFees(forTokenMint mint: String, completion: @escaping (Bool) -> Void) { - completion(false) - } - - func jupiterSwapTransactions(_ params: BraveWallet.JupiterSwapParams, completion: @escaping (BraveWallet.JupiterSwapTransactions?, BraveWallet.JupiterErrorResponse?, String) -> Void) { - completion(nil, .init(statusCode: "0", error: "Error", message: "Error Message", isInsufficientLiquidity: false), "") + func quote(_ params: BraveWallet.SwapQuoteParams, completion: @escaping (BraveWallet.SwapQuoteUnion?, BraveWallet.SwapErrorUnion?, String) -> Void) { + completion(.init(zeroExQuote: .init(price: "", guaranteedPrice: "", to: "", data: "", value: "", gas: "", estimatedGas: "", gasPrice: "", protocolFee: "", minimumProtocolFee: "", buyTokenAddress: "", sellTokenAddress: "", buyAmount: "", sellAmount: "", allowanceTarget: "", sellTokenToEthRate: "", buyTokenToEthRate: "", estimatedPriceImpact: "", sources: [], fees: .init(zeroExFee: nil))), nil, "") } func braveFee(_ params: BraveWallet.BraveSwapFeeParams, completion: @escaping (BraveWallet.BraveSwapFeeResponse?, String) -> Void) { diff --git a/Tests/BraveWalletTests/SwapTokenStoreTests.swift b/Tests/BraveWalletTests/SwapTokenStoreTests.swift index ddab6d5ecb9..8c7fb8c1d83 100644 --- a/Tests/BraveWalletTests/SwapTokenStoreTests.swift +++ b/Tests/BraveWalletTests/SwapTokenStoreTests.swift @@ -247,8 +247,24 @@ class SwapStoreTests: XCTestCase { completion("", 0, "", .internalError, "") } let swapService = BraveWallet.TestSwapService() - swapService._priceQuote = { $1(.init(), nil, "") } - swapService._transactionPayload = { $1(.init(), nil, "") } + swapService._quote = { _, completion in + if coin == .eth { + completion(.init(zeroExQuote: .init()), nil, "") + } else if coin == .sol { + completion(.init(jupiterQuote: .init()), nil, "") + } else { + XCTFail("Coin type is not supported for swap") + } + } + swapService._transaction = { _, completion in + if coin == .eth { + completion(.init(zeroExTransaction: .init()), nil, "") + } else if coin == .sol { + completion(.init(jupiterTransaction: .init()), nil, "") + } else { + XCTFail("Coin type is not supported for swap") + } + } swapService._braveFee = { params, completion in completion(nil, "") } @@ -269,17 +285,35 @@ class SwapStoreTests: XCTestCase { /// Test change to `sellAmount` (from value) will fetch price quote and assign to `buyAmount` func testFetchPriceQuoteSell() { let (keyringService, blockchainRegistry, rpcService, swapService, txService, walletService, ethTxManagerProxy, solTxManagerProxy, mockAssetManager) = setupServices() - swapService._priceQuote = { _, completion in - let swapResponse: BraveWallet.SwapResponse = .init() - swapResponse.buyAmount = "2000000000000000000" - // protocol fee should only be shown when non-nil - swapResponse.fees.zeroExFee = .init( + let zeroExQuote: BraveWallet.ZeroExQuote = .init( + price: "", + guaranteedPrice: "", + to: "", + data: "", + value: "", + gas: "", + estimatedGas: "", + gasPrice: "", + protocolFee: "", + minimumProtocolFee: "", + buyTokenAddress: "", + sellTokenAddress: "", + buyAmount: "2000000000000000000", + sellAmount: "", + allowanceTarget: "", + sellTokenToEthRate: "", + buyTokenToEthRate: "", + estimatedPriceImpact: "", + sources: [], + fees: .init(zeroExFee: .init( feeType: "", feeToken: "", feeAmount: "", billingType: "" - ) - completion(swapResponse, nil, "") + )) + ) + swapService._quote = { _, completion in + completion(.init(zeroExQuote: zeroExQuote), nil, "") } swapService._braveFee = { params, completion in let feeResponse = BraveWallet.BraveSwapFeeResponse( @@ -335,11 +369,10 @@ class SwapStoreTests: XCTestCase { /// Test change to `buyAmount` (to value) will fetch price quote and assign to `buyAmount` func testFetchPriceQuoteBuy() { let (keyringService, blockchainRegistry, rpcService, swapService, txService, walletService, ethTxManagerProxy, solTxManagerProxy, mockAssetManager) = setupServices() - swapService._priceQuote = { _, completion in - let swapResponse: BraveWallet.SwapResponse = .init() - swapResponse.sellAmount = "3000000000000000000" - swapResponse.fees.zeroExFee = nil // protocol fee should only be shown when non-nil - completion(swapResponse, nil, "") + let zeroExQuote: BraveWallet.ZeroExQuote = .init() + zeroExQuote.sellAmount = "3000000000000000000" + swapService._quote = { _, completion in + completion(.init(zeroExQuote: zeroExQuote), nil, "") } swapService._braveFee = { params, completion in let feeResponse = BraveWallet.BraveSwapFeeResponse( @@ -407,19 +440,22 @@ class SwapStoreTests: XCTestCase { network: .mockSolana, coin: .sol ) - swapService._jupiterQuote = { jupiterQuoteParams, completion in - // verify 0.005 is converted to 50 - XCTAssertEqual(jupiterQuoteParams.slippageBps, 50) - let route: BraveWallet.JupiterRoute = .init( - inAmount: 10000000, // 0.01 SOL (9 decimals) - outAmount: 2500000, // 2.5 SPD (6 decimals) - amount: 2500000, // 2.5 SPD (6 decimals) - otherAmountThreshold: 2500000, // 2.5 SPD (6 decimals) + swapService._quote = { swapQuoteParams, completion in + // verify 0.005 is converted to 0.5 + XCTAssertEqual(swapQuoteParams.slippagePercentage, "0.5") + let jupiterQuote: BraveWallet.JupiterQuote = .init( + inputMint: BraveWallet.BlockchainToken.mockSolToken.contractAddress, + inAmount: "10000000", // 0.01 SOL (9 decimals) + outputMint: BraveWallet.BlockchainToken.mockSpdToken.contractAddress, + outAmount: "2500000", // 2.5 SPD (6 decimals) + otherAmountThreshold: "2500000", // 2.5 SPD (6 decimals) swapMode: "", - priceImpactPct: 0, - slippageBps: jupiterQuoteParams.slippageBps, // 0.5% - marketInfos: []) - completion(.init(routes: [route]), nil, "") + slippageBps: "50", // 0.5% + platformFee: nil, + priceImpactPct: "0", + routePlan: [] + ) + completion(.init(jupiterQuote: jupiterQuote), nil, "") } swapService._braveFee = { params, completion in let feeResponse = BraveWallet.BraveSwapFeeResponse( @@ -492,14 +528,14 @@ class SwapStoreTests: XCTestCase { network: .mockSolana, coin: .sol ) - swapService._jupiterQuote = { _, completion in - let errorResponse: BraveWallet.JupiterErrorResponse = .init( + swapService._quote = { _, completion in + let errorUnion: BraveWallet.SwapErrorUnion = .init(jupiterError: .init( statusCode: "", error: "", message: "", - isInsufficientLiquidity: true + isInsufficientLiquidity: true) ) - completion(nil, errorResponse, "") + completion(nil, errorUnion, "") } let store = SwapTokenStore( keyringService: keyringService, @@ -664,22 +700,24 @@ class SwapStoreTests: XCTestCase { /// Test creating a sol swap transaction @MainActor func testSwapSolSwapTransaction() async { - let route: BraveWallet.JupiterRoute = .init( - inAmount: 3000000000, - outAmount: 2500000, // 2.5 SPD (6 decimals) - amount: 2500000, // 2.5 SPD (6 decimals) - otherAmountThreshold: 2500000, // 2.5 SPD (6 decimals) + let jupiterQuote: BraveWallet.JupiterQuote = .init( + inputMint: BraveWallet.BlockchainToken.mockSolToken.contractAddress, + inAmount: "3000000000", + outputMint: BraveWallet.BlockchainToken.mockSpdToken.contractAddress, + outAmount: "2500000", // 2.5 SPD (6 decimals) + otherAmountThreshold: "2500000", // 2.5 SPD (6 decimals) swapMode: "", - priceImpactPct: 0, - slippageBps: 50, // 0.5% - marketInfos: []) + slippageBps: "50", // 0.5% + platformFee: nil, + priceImpactPct: "0", + routePlan: [] + ) let (keyringService, blockchainRegistry, rpcService, swapService, txService, walletService, ethTxManagerProxy, solTxManagerProxy, mockAssetManager) = setupServices( network: .mockSolana, coin: .sol ) - swapService._jupiterSwapTransactions = { _, completion in - let swapTransactions: BraveWallet.JupiterSwapTransactions = .init(swapTransaction: "1") - completion(swapTransactions, nil, "") + swapService._transaction = { _, completion in + completion(.init(jupiterTransaction: "1"), nil, "") } solTxManagerProxy._makeTxDataFromBase64EncodedTransaction = { _, _, _, completion in completion(.init(), .success, "") @@ -706,7 +744,7 @@ class SwapStoreTests: XCTestCase { selectedFromToken: .mockSolToken, selectedToToken: .mockSpdToken, sellAmount: "0.01", - jupiterQuote: .init(routes: [route]) + jupiterQuote: jupiterQuote ) store.state = .swap diff --git a/package-lock.json b/package-lock.json index 9dfeef915bb..2cf07684351 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.62.128/brave-core-ios-1.62.128.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.62.140/brave-core-ios-1.62.140.tgz", "leo": "github:brave/leo#792ab5c9f82784578e8f8fc14b9eaa24fa1956d2", "leo-sf-symbols": "github:brave/leo-sf-symbols#775bb8fca9df76679b9b272545e162418127c5de", "page-metadata-parser": "^1.1.3", @@ -514,9 +514,9 @@ } }, "node_modules/brave-core-ios": { - "version": "1.62.128", - "resolved": "https://github.com/brave/brave-browser/releases/download/v1.62.128/brave-core-ios-1.62.128.tgz", - "integrity": "sha512-9g+CuzbzEACRh5JvzxKFmA1NKJxu1et04uJeIIIFbrKDWDuFCPvyXYinky8EzlzEMYmzPxdigr6QUzaKkNQxvg==", + "version": "1.62.140", + "resolved": "https://github.com/brave/brave-browser/releases/download/v1.62.140/brave-core-ios-1.62.140.tgz", + "integrity": "sha512-6HigfG6ybYCDKP4LhNx8A+7TpCLm6CMMKpSCyNLtu3G/v8g5VWJNM831CVsYLg8Jurjz04blO0FAiPiBZkOYJg==", "license": "ISC" }, "node_modules/browserslist": { @@ -3214,8 +3214,8 @@ } }, "brave-core-ios": { - "version": "https://github.com/brave/brave-browser/releases/download/v1.62.128/brave-core-ios-1.62.128.tgz", - "integrity": "sha512-9g+CuzbzEACRh5JvzxKFmA1NKJxu1et04uJeIIIFbrKDWDuFCPvyXYinky8EzlzEMYmzPxdigr6QUzaKkNQxvg==" + "version": "https://github.com/brave/brave-browser/releases/download/v1.62.140/brave-core-ios-1.62.140.tgz", + "integrity": "sha512-6HigfG6ybYCDKP4LhNx8A+7TpCLm6CMMKpSCyNLtu3G/v8g5VWJNM831CVsYLg8Jurjz04blO0FAiPiBZkOYJg==" }, "browserslist": { "version": "4.17.1", diff --git a/package.json b/package.json index fada7dac319..62e956395c0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.62.128/brave-core-ios-1.62.128.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.62.140/brave-core-ios-1.62.140.tgz", "leo": "github:brave/leo#792ab5c9f82784578e8f8fc14b9eaa24fa1956d2", "leo-sf-symbols": "github:brave/leo-sf-symbols#775bb8fca9df76679b9b272545e162418127c5de", "page-metadata-parser": "^1.1.3",