chore: remove old router logic

Closes #16201
This commit is contained in:
Sale Djenic 2024-08-28 14:50:09 +02:00 committed by saledjenic
parent ff9f272295
commit c515a963e3
8 changed files with 60 additions and 67 deletions

View File

@ -150,7 +150,7 @@ QtObject:
uuidOfTheLastRequestForSuggestedRoutes: string
## Forward declarations
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string)
proc suggestedRoutesReady(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string)
proc delete*(self: Service) =
self.QObject.delete
@ -181,7 +181,7 @@ QtObject:
self.events.on(SignalType.WalletSuggestedRoutes.event) do(e:Args):
var data = WalletSignal(e)
self.suggestedRoutesV2Ready(data.uuid, data.bestRoute, data.bestRouteRaw, data.errorCode, data.error)
self.suggestedRoutesReady(data.uuid, data.bestRoute, data.bestRouteRaw, data.errorCode, data.error)
self.events.on(PendingTransactionTypeDto.WalletTransfer.event) do(e: Args):
try:
@ -653,7 +653,7 @@ QtObject:
except Exception as e:
error "Error getting suggested fees", msg = e.msg
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string) =
proc suggestedRoutesReady(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string) =
if self.uuidOfTheLastRequestForSuggestedRoutes != uuid:
return
@ -668,7 +668,7 @@ QtObject:
toNetworks: getToNetworksList(oldRoute),
)
self.events.emit(SIGNAL_SUGGESTED_ROUTES_READY, SuggestedRoutesArgs(
uuid: uuid,
uuid: uuid,
suggestedRoutes: suggestedDto,
errCode: errCode,
errDescription: errDescription
@ -697,7 +697,7 @@ QtObject:
amountOutHex = "0x" & eth_utils.stripLeadingZeros(bigAmountOut.toHex)
try:
let res = eth.suggestedRoutesV2Async(uuid, ord(sendType), accountFrom, accountTo, amountInHex, amountOutHex, token,
let res = eth.suggestedRoutesAsync(uuid, ord(sendType), accountFrom, accountTo, amountInHex, amountOutHex, token,
toToken, disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable)
except CatchableError as e:
error "suggestedRoutes", exception=e.msg

View File

@ -1,4 +1,4 @@
const noGasErrorCode = "WR-017"
const noGasErrorCode = "WR-002"
# This method will group the account assets by symbol (in case of communiy, the token address)
proc onAllTokensBuilt*(self: Service, response: string) {.slot.} =
@ -119,7 +119,7 @@ proc getHasBalanceCache*(self: Service): bool =
proc getChainsWithNoGasFromError*(self: Service, errCode: string, errDescription: string): Table[int, string] =
## Extracts the chainId and token from the error description for chains with no gas.
## If the error code is not "WR-017", an empty table is returned.
## If the error code is not "WR-002", an empty table is returned.
result = initTable[int, string]()
if errCode == noGasErrorCode:

View File

@ -38,7 +38,7 @@ proc suggestedFees*(chainId: int): RpcResponse[JsonNode] =
let payload = %* [chainId]
return core.callPrivateRPC("wallet_getSuggestedFees", payload)
proc prepareDataForSuggestedRoutesV2(uuid: string, sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string,
proc prepareDataForSuggestedRoutes(uuid: string, sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string,
token: string, toToken: string, disabledFromChainIDs, disabledToChainIDs: seq[int], lockedInAmounts: Table[string, string],
extraParamsTable: Table[string, string]): JsonNode =
@ -68,26 +68,26 @@ proc prepareDataForSuggestedRoutesV2(uuid: string, sendType: int, accountFrom: s
return %* [data]
proc suggestedRoutesV2*(sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string, token: string,
proc suggestedRoutes*(sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string, token: string,
toToken: string, disabledFromChainIDs, disabledToChainIDs: seq[int], lockedInAmounts: Table[string, string],
extraParamsTable: Table[string, string]): RpcResponse[JsonNode] {.raises: [RpcException].} =
let payload = prepareDataForSuggestedRoutesV2(uuid = "", sendType, accountFrom, accountTo, amountIn, amountOut, token, toToken, disabledFromChainIDs,
let payload = prepareDataForSuggestedRoutes(uuid = "", sendType, accountFrom, accountTo, amountIn, amountOut, token, toToken, disabledFromChainIDs,
disabledToChainIDs, lockedInAmounts, extraParamsTable)
if payload.isNil:
raise newException(RpcException, "Invalid key in extraParamsTable")
return core.callPrivateRPC("wallet_getSuggestedRoutesV2", payload)
return core.callPrivateRPC("wallet_getSuggestedRoutes", payload)
proc suggestedRoutesV2Async*(uuid: string, sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string, token: string,
proc suggestedRoutesAsync*(uuid: string, sendType: int, accountFrom: string, accountTo: string, amountIn: string, amountOut: string, token: string,
toToken: string, disabledFromChainIDs, disabledToChainIDs: seq[int], lockedInAmounts: Table[string, string],
extraParamsTable: Table[string, string]): RpcResponse[JsonNode] {.raises: [RpcException].} =
let payload = prepareDataForSuggestedRoutesV2(uuid, sendType, accountFrom, accountTo, amountIn, amountOut, token, toToken, disabledFromChainIDs,
let payload = prepareDataForSuggestedRoutes(uuid, sendType, accountFrom, accountTo, amountIn, amountOut, token, toToken, disabledFromChainIDs,
disabledToChainIDs, lockedInAmounts, extraParamsTable)
if payload.isNil:
raise newException(RpcException, "Invalid key in extraParamsTable")
return core.callPrivateRPC("wallet_getSuggestedRoutesV2Async", payload)
return core.callPrivateRPC("wallet_getSuggestedRoutesAsync", payload)
proc stopSuggestedRoutesV2AsyncCalcualtion*() : RpcResponse[JsonNode] =
return core.callPrivateRPC("wallet_stopSuggestedRoutesV2AsyncCalcualtion")
proc stopSuggestedRoutesAsyncCalculation*() : RpcResponse[JsonNode] =
return core.callPrivateRPC("wallet_stopSuggestedRoutesAsyncCalculation")
rpc(getEstimatedLatestBlockNumber, "wallet"):
chainId: int

View File

@ -366,11 +366,11 @@ SplitView {
ComboBox {
id: routerErrorComboBox
model: [
{name: "errNotEnoughTokenBalance", value: Constants.swap.errorCodes.errNotEnoughTokenBalance},
{name: "errNotEnoughNativeBalance", value: Constants.swap.errorCodes.errNotEnoughNativeBalance},
{name: "errPriceTimeout", value: Constants.swap.errorCodes.errPriceTimeout},
{name: "errNotEnoughLiquidity", value: Constants.swap.errorCodes.errNotEnoughLiquidity},
{name: "errPriceImpactTooHigh", value: Constants.swap.errorCodes.errPriceImpactTooHigh}
{name: "errNotEnoughTokenBalance", value: Constants.routerErrorCodes.router.errNotEnoughTokenBalance},
{name: "errNotEnoughNativeBalance", value: Constants.routerErrorCodes.router.errNotEnoughNativeBalance},
{name: "errPriceTimeout", value: Constants.routerErrorCodes.processor.errPriceTimeout},
{name: "errNotEnoughLiquidity", value: Constants.routerErrorCodes.processor.errNotEnoughLiquidity},
{name: "errPriceImpactTooHigh", value: Constants.routerErrorCodes.processor.errPriceImpactTooHigh}
]
textRole: "name"
valueRole: "value"

View File

@ -632,7 +632,7 @@ Item {
// emit event that no routes were found due to not enough token balance
txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughTokenBalance, "errNotEnoughTokenBalance")
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.router.errNotEnoughTokenBalance, "errNotEnoughTokenBalance")
// verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived)
@ -670,7 +670,7 @@ Item {
// emit event that no routes were found due to not enough eth balance
txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughNativeBalance, "errNotEnoughNativeBalance")
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.router.errNotEnoughNativeBalance, "errNotEnoughNativeBalance")
// verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived)
@ -708,7 +708,7 @@ Item {
// emit event that no routes were found due to price timeout
txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errPriceTimeout, "errPriceTimeout")
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.processor.errPriceTimeout, "errPriceTimeout")
// verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived)
@ -746,7 +746,7 @@ Item {
// emit event that no routes were found due to not enough liquidity
txRoutes.uuid = root.swapAdaptor.uuid
root.swapStore.suggestedRoutesReady(txRoutes, Constants.swap.errorCodes.errNotEnoughLiquidity, "errNotEnoughLiquidity")
root.swapStore.suggestedRoutesReady(txRoutes, Constants.routerErrorCodes.processor.errNotEnoughLiquidity, "errNotEnoughLiquidity")
// verify loading state was removed and that error was displayed
verify(!root.swapAdaptor.validSwapProposalReceived)

View File

@ -155,9 +155,9 @@ QObject {
}
// Properties to handle error states
readonly property bool isRouteEthBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.swap.errorCodes.errNotEnoughNativeBalance
readonly property bool isRouteEthBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.routerErrorCodes.router.errNotEnoughNativeBalance
readonly property bool isRouteTokenBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.swap.errorCodes.errNotEnoughTokenBalance
readonly property bool isRouteTokenBalanceInsufficient: root.validSwapProposalReceived && root.swapOutputData.errCode === Constants.routerErrorCodes.router.errNotEnoughTokenBalance
readonly property bool isTokenBalanceInsufficient: {
if (!!root.fromToken && !!root.fromToken.symbol) {
@ -191,12 +191,13 @@ QObject {
} else if (isBalanceInsufficientForFees) {
return qsTr("Insufficient funds to pay gas fees")
} else if (root.swapOutputData.hasError) {
// TOOD #15874: Unify with WalletUtils router error code handling
switch (root.swapOutputData.errCode) {
case Constants.swap.errorCodes.errPriceTimeout:
case Constants.routerErrorCodes.processor.errPriceTimeout:
return qsTr("Fetching the price took longer than expected. Please, try again later.")
case Constants.swap.errorCodes.errNotEnoughLiquidity:
case Constants.routerErrorCodes.processor.errNotEnoughLiquidity:
return qsTr("Not enough liquidity. Lower token amount or try again later.")
case Constants.swap.errorCodes.errPriceImpactTooHigh:
case Constants.routerErrorCodes.processor.errPriceImpactTooHigh:
return qsTr("Price impact too high. Lower token amount or try again later.")
}
return qsTr("Something went wrong. Change amount, token or try again later.")

View File

@ -1105,33 +1105,34 @@ QtObject {
}
readonly property QtObject router: QtObject {
readonly property string errENSRegisterRequiresUsernameAndPubKey : "WR-001"
readonly property string errENSRegisterTestnetSTTOnly : "WR-002"
readonly property string errENSRegisterMainnetSNTOnly : "WR-003"
readonly property string errENSReleaseRequiresUsername : "WR-004"
readonly property string errENSSetPubKeyRequiresUsernameAndPubKey : "WR-005"
readonly property string errStickersBuyRequiresPackID : "WR-006"
readonly property string errSwapRequiresToTokenID : "WR-007"
readonly property string errSwapTokenIDMustBeDifferent : "WR-008"
readonly property string errSwapAmountInAmountOutMustBeExclusive : "WR-009"
readonly property string errSwapAmountInMustBePositive : "WR-010"
readonly property string errSwapAmountOutMustBePositive : "WR-011"
readonly property string errLockedAmountNotSupportedForNetwork : "WR-012"
readonly property string errLockedAmountNotNegative : "WR-013"
readonly property string errLockedAmountExceedsTotalSendAmount : "WR-014"
readonly property string errLockedAmountLessThanSendAmountAllNetworks : "WR-015"
readonly property string errNotEnoughTokenBalance : "WR-016"
readonly property string errNotEnoughNativeBalance : "WR-017"
readonly property string errNativeTokenNotFound : "WR-018"
readonly property string errDisabledChainFoundAmongLockedNetworks : "WR-019"
readonly property string errENSSetPubKeyInvalidUsername : "WR-020"
readonly property string errLockedAmountExcludesAllSupported : "WR-021"
readonly property string errTokenNotFound : "WR-022"
readonly property string errNoBestRouteFound : "WR-023"
readonly property string errCannotCheckReceiverBalance : "WR-024"
readonly property string errCannotCheckLockedAmounts : "WR-025"
readonly property string errLowAmountInForHopBridge : "WR-026"
readonly property string errNoPositiveBalance : "WR-027"
readonly property string errENSRegisterRequiresUsernameAndPubKey : "WRR-001"
readonly property string errENSRegisterTestnetSTTOnly : "WRR-002"
readonly property string errENSRegisterMainnetSNTOnly : "WRR-003"
readonly property string errENSReleaseRequiresUsername : "WRR-004"
readonly property string errENSSetPubKeyRequiresUsernameAndPubKey : "WRR-005"
readonly property string errStickersBuyRequiresPackID : "WRR-006"
readonly property string errSwapRequiresToTokenID : "WRR-007"
readonly property string errSwapTokenIDMustBeDifferent : "WRR-008"
readonly property string errSwapAmountInAmountOutMustBeExclusive : "WRR-009"
readonly property string errSwapAmountInMustBePositive : "WRR-010"
readonly property string errSwapAmountOutMustBePositive : "WRR-011"
readonly property string errLockedAmountNotSupportedForNetwork : "WRR-012"
readonly property string errLockedAmountNotNegative : "WRR-013"
readonly property string errLockedAmountExceedsTotalSendAmount : "WRR-014"
readonly property string errLockedAmountLessThanSendAmountAllNetworks : "WRR-015"
readonly property string errDisabledChainFoundAmongLockedNetworks : "WRR-016"
readonly property string errENSSetPubKeyInvalidUsername : "WRR-017"
readonly property string errLockedAmountExcludesAllSupported : "WRR-018"
readonly property string errCannotCheckLockedAmounts : "WRR-019"
readonly property string errNotEnoughTokenBalance : "WR-001"
readonly property string errNotEnoughNativeBalance : "WR-002"
readonly property string errNativeTokenNotFound : "WR-003"
readonly property string errTokenNotFound : "WR-004"
readonly property string errNoBestRouteFound : "WR-005"
readonly property string errCannotCheckReceiverBalance : "WR-006"
readonly property string errLowAmountInForHopBridge : "WR-007"
readonly property string errNoPositiveBalance : "WR-008"
}
}
@ -1444,15 +1445,6 @@ QtObject {
readonly property string paraswapV5SwapContractAddress: "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57"
readonly property string paraswapV6_2ContractAddress: "0x6a000f20005980200259b80c5102003040001068"
readonly property string paraswapTermsAndConditionUrl: "https://files.paraswap.io/tos_v4.pdf"
// TOOD #15874: Unify with WalletUtils router error code handling
readonly property QtObject errorCodes: QtObject {
readonly property string errNotEnoughTokenBalance: "WR-016"
readonly property string errNotEnoughNativeBalance: "WR-017"
readonly property string errPriceTimeout: "WPP-037"
readonly property string errNotEnoughLiquidity: "WPP-038"
readonly property string errPriceImpactTooHigh: "WPP-039"
}
}
// Mirrors src/app_service/service/transaction/service.nim -> EstimatedTime

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit fb150f3d166aaf2bc1d512ff14953dd1509a9ddc
Subproject commit 0235889e12bcd13e8e25fe1ee9a6d497ece57d01