fix(@desktop/wallet): fix swap in routerV2 integration
This commit is contained in:
parent
7e9f680e0b
commit
c6fd0f41db
|
@ -1,4 +1,4 @@
|
||||||
import json, options, sequtils, sugar, chronicles
|
import json, options, chronicles
|
||||||
|
|
||||||
import base
|
import base
|
||||||
import signal_type
|
import signal_type
|
||||||
|
@ -20,6 +20,7 @@ type WalletSignal* = ref object of Signal
|
||||||
requestId*: Option[int]
|
requestId*: Option[int]
|
||||||
txHashes*: seq[string]
|
txHashes*: seq[string]
|
||||||
uuid*: string
|
uuid*: string
|
||||||
|
bestRouteRaw*: string
|
||||||
bestRoute*: seq[TransactionPathDtoV2]
|
bestRoute*: seq[TransactionPathDtoV2]
|
||||||
error*: string
|
error*: string
|
||||||
errorCode*: string
|
errorCode*: string
|
||||||
|
@ -57,7 +58,9 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
|
||||||
if event.contains("Uuid"):
|
if event.contains("Uuid"):
|
||||||
result.uuid = event["Uuid"].getStr()
|
result.uuid = event["Uuid"].getStr()
|
||||||
if event.contains("Best"):
|
if event.contains("Best"):
|
||||||
result.bestRoute = event["Best"].getElems().map(x => x.toTransactionPathDtoV2())
|
let bestRouteJsonNode = event["Best"]
|
||||||
|
result.bestRouteRaw = $bestRouteJsonNode
|
||||||
|
result.bestRoute = bestRouteJsonNode.toTransactionPathsDtoV2()
|
||||||
if event.contains("details"):
|
if event.contains("details"):
|
||||||
result.error = event["details"].getStr
|
result.error = event["details"].getStr
|
||||||
if event.contains("code"):
|
if event.contains("code"):
|
||||||
|
|
|
@ -12,6 +12,8 @@ import app_service/service/keycard/service as keycard_service
|
||||||
import app_service/service/keycard/constants as keycard_constants
|
import app_service/service/keycard/constants as keycard_constants
|
||||||
import app/modules/shared/wallet_utils
|
import app/modules/shared/wallet_utils
|
||||||
import app_service/service/transaction/dto
|
import app_service/service/transaction/dto
|
||||||
|
import app_service/service/transaction/dtoV2
|
||||||
|
import app_service/service/transaction/dto_conversion
|
||||||
import app/modules/shared_models/currency_amount
|
import app/modules/shared_models/currency_amount
|
||||||
import app_service/service/token/service
|
import app_service/service/token/service
|
||||||
import app_service/service/network/network_item as network_service_item
|
import app_service/service/network/network_item as network_service_item
|
||||||
|
@ -284,7 +286,11 @@ method authenticateAndTransfer*(self: Module, fromAddr: string, toAddr: string,
|
||||||
|
|
||||||
method authenticateAndTransferWithPaths*(self: Module, fromAddr: string, toAddr: string, assetKey: string, toAssetKey: string, uuid: string,
|
method authenticateAndTransferWithPaths*(self: Module, fromAddr: string, toAddr: string, assetKey: string, toAssetKey: string, uuid: string,
|
||||||
sendType: SendType, selectedTokenName: string, selectedTokenIsOwnerToken: bool, rawPaths: string, slippagePercentage: Option[float]) =
|
sendType: SendType, selectedTokenName: string, selectedTokenIsOwnerToken: bool, rawPaths: string, slippagePercentage: Option[float]) =
|
||||||
self.tmpSendTransactionDetails.paths = rawPaths.convertToTransactionPathsDto()
|
# Temporary until transaction service rework is completed
|
||||||
|
let pathsV2 = rawPaths.toTransactionPathsDtoV2()
|
||||||
|
let pathsV1 = pathsV2.convertToOldRoute().addFirstSimpleBridgeTxFlag()
|
||||||
|
|
||||||
|
self.tmpSendTransactionDetails.paths = pathsV1
|
||||||
self.tmpSendTransactionDetails.slippagePercentage = slippagePercentage
|
self.tmpSendTransactionDetails.slippagePercentage = slippagePercentage
|
||||||
self.authenticateAndTransfer(fromAddr, toAddr, assetKey, toAssetKey, uuid, sendType, selectedTokenName, selectedTokenIsOwnerToken)
|
self.authenticateAndTransfer(fromAddr, toAddr, assetKey, toAssetKey, uuid, sendType, selectedTokenName, selectedTokenIsOwnerToken)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@ type
|
||||||
nonce*: Option[Nonce] # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce
|
nonce*: Option[Nonce] # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce
|
||||||
txType*: string
|
txType*: string
|
||||||
|
|
||||||
chainID*: Option[int] # (optional) chainID in case of a bridge hop transaction
|
chainID*: Option[int] # (optional) source chainID
|
||||||
|
chainIDTo*: Option[int] # (optional) destination chainID
|
||||||
symbol*: Option[string] # (optional) symbol in case of a bridge hop transaction
|
symbol*: Option[string] # (optional) symbol in case of a bridge hop transaction
|
||||||
recipient*: Option[Address] # (optional) recipient in case of a bridge hop transaction
|
recipient*: Option[Address] # (optional) recipient in case of a bridge hop transaction
|
||||||
amount*: Option[UInt256] # (optional) amount in case of a bridge hop transaction
|
amount*: Option[UInt256] # (optional) amount in case of a bridge hop transaction
|
||||||
|
@ -25,6 +26,8 @@ type
|
||||||
|
|
||||||
tokenID*: Option[UInt256] # (optional) chainID in case of a ERC721 transaction
|
tokenID*: Option[UInt256] # (optional) chainID in case of a ERC721 transaction
|
||||||
|
|
||||||
|
tokenIdFrom*: Option[string] # (optional) source token symbol
|
||||||
|
tokenIdTo*: Option[string] # (optional) destination token symbol
|
||||||
slippagePercentage*: Option[float] # (optional) max slippage percentage allowed in case of a Swap transaction
|
slippagePercentage*: Option[float] # (optional) max slippage percentage allowed in case of a Swap transaction
|
||||||
|
|
||||||
proc `%`*(x: TransactionDataDto): JsonNode =
|
proc `%`*(x: TransactionDataDto): JsonNode =
|
||||||
|
@ -49,6 +52,8 @@ proc `%`*(x: TransactionDataDto): JsonNode =
|
||||||
result["nonce"] = %x.nonce.unsafeGet
|
result["nonce"] = %x.nonce.unsafeGet
|
||||||
if x.chainID.isSome:
|
if x.chainID.isSome:
|
||||||
result["chainId"] = %x.chainID.unsafeGet
|
result["chainId"] = %x.chainID.unsafeGet
|
||||||
|
if x.chainIDTo.isSome:
|
||||||
|
result["chainIdTo"] = %x.chainIDTo.unsafeGet
|
||||||
if x.symbol.isSome:
|
if x.symbol.isSome:
|
||||||
result["symbol"] = %x.symbol.unsafeGet
|
result["symbol"] = %x.symbol.unsafeGet
|
||||||
if x.recipient.isSome:
|
if x.recipient.isSome:
|
||||||
|
@ -61,6 +66,10 @@ proc `%`*(x: TransactionDataDto): JsonNode =
|
||||||
result["bonderFee"] = %x.bonderFee.unsafeGet
|
result["bonderFee"] = %x.bonderFee.unsafeGet
|
||||||
if x.tokenID.isSome:
|
if x.tokenID.isSome:
|
||||||
result["tokenID"] = %x.tokenID.unsafeGet
|
result["tokenID"] = %x.tokenID.unsafeGet
|
||||||
|
if x.tokenIdFrom.isSome:
|
||||||
|
result["tokenIdFrom"] = %x.tokenIdFrom.unsafeGet
|
||||||
|
if x.tokenIdTo.isSome:
|
||||||
|
result["tokenIdTo"] = %x.tokenIdTo.unsafeGet
|
||||||
if x.slippagePercentage.isSome:
|
if x.slippagePercentage.isSome:
|
||||||
result["slippagePercentage"] = %x.slippagePercentage.unsafeGet
|
result["slippagePercentage"] = %x.slippagePercentage.unsafeGet
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,6 @@ import stint
|
||||||
import ../../../backend/backend as backend
|
import ../../../backend/backend as backend
|
||||||
import ../../common/conversion as service_conversion
|
import ../../common/conversion as service_conversion
|
||||||
|
|
||||||
proc sortAsc[T](t1, t2: T): int =
|
|
||||||
if (t1.fromNetwork.chainId > t2.fromNetwork.chainId): return 1
|
|
||||||
elif (t1.fromNetwork.chainId < t2.fromNetwork.chainId): return -1
|
|
||||||
else: return 0
|
|
||||||
|
|
||||||
type
|
type
|
||||||
GetSuggestedRoutesTaskArg* = ref object of QObjectTaskArg
|
GetSuggestedRoutesTaskArg* = ref object of QObjectTaskArg
|
||||||
accountFrom: string
|
accountFrom: string
|
||||||
|
@ -24,62 +19,6 @@ type
|
||||||
sendType: SendType
|
sendType: SendType
|
||||||
lockedInAmounts: string
|
lockedInAmounts: string
|
||||||
|
|
||||||
proc getGasEthValue*(gweiValue: float, gasLimit: uint64): float =
|
|
||||||
let weiValue = service_conversion.gwei2Wei(gweiValue) * u256(gasLimit)
|
|
||||||
let ethValue = parseFloat(service_conversion.wei2Eth(weiValue))
|
|
||||||
return ethValue
|
|
||||||
|
|
||||||
proc getFeesTotal*(paths: seq[TransactionPathDto]): FeesDto =
|
|
||||||
var fees: FeesDto = FeesDto()
|
|
||||||
if(paths.len == 0):
|
|
||||||
return fees
|
|
||||||
|
|
||||||
for path in paths:
|
|
||||||
var optimalPrice = path.gasFees.gasPrice
|
|
||||||
if path.gasFees.eip1559Enabled:
|
|
||||||
optimalPrice = path.gasFees.maxFeePerGasM
|
|
||||||
|
|
||||||
fees.totalFeesInEth += getGasEthValue(optimalPrice, path.gasAmount)
|
|
||||||
fees.totalFeesInEth += parseFloat(service_conversion.wei2Eth(service_conversion.gwei2Wei(path.gasFees.l1GasFee)))
|
|
||||||
fees.totalFeesInEth += path.approvalGasFees
|
|
||||||
fees.totalTokenFees += path.tokenFees
|
|
||||||
fees.totalTime += path.estimatedTime
|
|
||||||
return fees
|
|
||||||
|
|
||||||
proc getTotalAmountToReceive*(paths: seq[TransactionPathDto]): UInt256 =
|
|
||||||
var totalAmountToReceive: UInt256 = stint.u256(0)
|
|
||||||
for path in paths:
|
|
||||||
totalAmountToReceive += path.amountOut
|
|
||||||
|
|
||||||
return totalAmountToReceive
|
|
||||||
|
|
||||||
proc getToNetworksList*(paths: seq[TransactionPathDto]): seq[SendToNetwork] =
|
|
||||||
var networkMap: Table[int, SendToNetwork] = initTable[int, SendToNetwork]()
|
|
||||||
for path in paths:
|
|
||||||
if(networkMap.hasKey(path.toNetwork.chainId)):
|
|
||||||
networkMap[path.toNetwork.chainId].amountOut = networkMap[path.toNetwork.chainId].amountOut + path.amountOut
|
|
||||||
else:
|
|
||||||
networkMap[path.toNetwork.chainId] = SendToNetwork(chainId: path.toNetwork.chainId, chainName: path.toNetwork.chainName, iconUrl: path.toNetwork.iconURL, amountOut: path.amountOut)
|
|
||||||
return toSeq(networkMap.values)
|
|
||||||
|
|
||||||
proc addFirstSimpleBridgeTxFlag(paths: seq[TransactionPathDto]) : seq[TransactionPathDto] =
|
|
||||||
let txPaths = paths
|
|
||||||
var firstSimplePath: bool = false
|
|
||||||
var firstBridgePath: bool = false
|
|
||||||
|
|
||||||
for path in txPaths:
|
|
||||||
if not firstSimplePath:
|
|
||||||
firstSimplePath = true
|
|
||||||
path.isFirstSimpleTx = true
|
|
||||||
if path.bridgeName != "Transfer":
|
|
||||||
if not firstBridgePath:
|
|
||||||
firstBridgePath = false
|
|
||||||
path.isFirstBridgeTx = true
|
|
||||||
|
|
||||||
return txPaths
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
WatchTransactionTaskArg* = ref object of QObjectTaskArg
|
WatchTransactionTaskArg* = ref object of QObjectTaskArg
|
||||||
data: string
|
data: string
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import json, strutils, stint, json_serialization, stew/shims/strformat
|
import json, strutils, stint, json_serialization, stew/shims/strformat
|
||||||
|
import Tables, sequtils
|
||||||
|
|
||||||
import
|
import
|
||||||
web3/ethtypes
|
web3/ethtypes
|
||||||
|
|
||||||
include ../../common/json_utils
|
include ../../common/json_utils
|
||||||
import ../network/dto
|
import ../network/dto, ../token/dto
|
||||||
import ../../common/conversion as service_conversion
|
import ../../common/conversion as service_conversion
|
||||||
|
|
||||||
import ./backend/transactions
|
import ./backend/transactions
|
||||||
|
@ -238,6 +239,8 @@ type
|
||||||
bridgeName*: string
|
bridgeName*: string
|
||||||
fromNetwork*: NetworkDto
|
fromNetwork*: NetworkDto
|
||||||
toNetwork*: NetworkDto
|
toNetwork*: NetworkDto
|
||||||
|
fromToken*: TokenDto # Only populated when converting from V2
|
||||||
|
toToken*: TokenDto # Only populated when converting from V2
|
||||||
maxAmountIn* : UInt256
|
maxAmountIn* : UInt256
|
||||||
amountIn*: UInt256
|
amountIn*: UInt256
|
||||||
amountOut*: UInt256
|
amountOut*: UInt256
|
||||||
|
@ -260,6 +263,8 @@ proc `$`*(self: TransactionPathDto): string =
|
||||||
bridgeName:{self.bridgeName},
|
bridgeName:{self.bridgeName},
|
||||||
fromNetwork:{self.fromNetwork},
|
fromNetwork:{self.fromNetwork},
|
||||||
toNetwork:{self.toNetwork},
|
toNetwork:{self.toNetwork},
|
||||||
|
fromToken:{self.fromToken},
|
||||||
|
toToken:{self.toToken},
|
||||||
maxAmountIn:{self.maxAmountIn},
|
maxAmountIn:{self.maxAmountIn},
|
||||||
amountIn:{self.amountIn},
|
amountIn:{self.amountIn},
|
||||||
amountOut:{self.amountOut},
|
amountOut:{self.amountOut},
|
||||||
|
@ -278,32 +283,6 @@ proc `$`*(self: TransactionPathDto): string =
|
||||||
gasFees:{$self.gasFees}
|
gasFees:{$self.gasFees}
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
proc toTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
|
||||||
result = TransactionPathDto()
|
|
||||||
discard jsonObj.getProp("BridgeName", result.bridgeName)
|
|
||||||
result.fromNetwork = Json.decode($jsonObj["From"], NetworkDto, allowUnknownFields = true)
|
|
||||||
result.toNetwork = Json.decode($jsonObj["To"], NetworkDto, allowUnknownFields = true)
|
|
||||||
result.gasFees = jsonObj["GasFees"].toSuggestedFeesDto()
|
|
||||||
var stringValue: string
|
|
||||||
if jsonObj.getProp("Cost", stringValue) and stringValue.len > 0:
|
|
||||||
result.cost = parseFloat(stringValue)
|
|
||||||
if jsonObj.getProp("TokenFees", stringValue) and stringValue.len > 0:
|
|
||||||
result.tokenFees = parseFloat(stringValue)
|
|
||||||
result.bonderFees = jsonObj{"BonderFees"}.getStr
|
|
||||||
result.maxAmountIn = stint.fromHex(UInt256, jsonObj{"MaxAmountIn"}.getStr)
|
|
||||||
result.amountIn = stint.fromHex(UInt256, jsonObj{"AmountIn"}.getStr)
|
|
||||||
result.amountOut = stint.fromHex(UInt256, jsonObj{"AmountOut"}.getStr)
|
|
||||||
result.estimatedTime = jsonObj{"EstimatedTime"}.getInt
|
|
||||||
discard jsonObj.getProp("GasAmount", result.gasAmount)
|
|
||||||
discard jsonObj.getProp("AmountInLocked", result.amountInLocked)
|
|
||||||
result.isFirstSimpleTx = false
|
|
||||||
result.isFirstBridgeTx = false
|
|
||||||
discard jsonObj.getProp("ApprovalRequired", result.approvalRequired)
|
|
||||||
result.approvalAmountRequired = stint.fromHex(UInt256, jsonObj{"ApprovalAmountRequired"}.getStr)
|
|
||||||
if jsonObj.getProp("ApprovalGasFees", stringValue) and stringValue.len > 0:
|
|
||||||
result.approvalGasFees = parseFloat(stringValue)
|
|
||||||
discard jsonObj.getProp("ApprovalContractAddress", result.approvalContractAddress)
|
|
||||||
|
|
||||||
proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
||||||
result = TransactionPathDto()
|
result = TransactionPathDto()
|
||||||
discard jsonObj.getProp("bridgeName", result.bridgeName)
|
discard jsonObj.getProp("bridgeName", result.bridgeName)
|
||||||
|
@ -326,15 +305,6 @@ proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
||||||
discard jsonObj.getProp("approvalGasFees", result.approvalGasFees)
|
discard jsonObj.getProp("approvalGasFees", result.approvalGasFees)
|
||||||
discard jsonObj.getProp("approvalContractAddress", result.approvalContractAddress)
|
discard jsonObj.getProp("approvalContractAddress", result.approvalContractAddress)
|
||||||
|
|
||||||
proc convertToTransactionPathsDto*(jsonObj: JsonNode): seq[TransactionPathDto] =
|
|
||||||
result = @[]
|
|
||||||
for path in jsonObj.getElems():
|
|
||||||
result.add(path.convertToTransactionPathDto())
|
|
||||||
return result
|
|
||||||
|
|
||||||
proc convertToTransactionPathsDto*(paths: string): seq[TransactionPathDto] =
|
|
||||||
return paths.parseJson.convertToTransactionPathsDto()
|
|
||||||
|
|
||||||
type
|
type
|
||||||
FeesDto* = ref object
|
FeesDto* = ref object
|
||||||
totalFeesInEth*: float
|
totalFeesInEth*: float
|
||||||
|
@ -379,8 +349,61 @@ proc convertSendToNetwork*(jsonObj: JsonNode): SendToNetwork =
|
||||||
type
|
type
|
||||||
SuggestedRoutesDto* = ref object
|
SuggestedRoutesDto* = ref object
|
||||||
best*: seq[TransactionPathDto]
|
best*: seq[TransactionPathDto]
|
||||||
rawBest*: string
|
rawBest*: string # serialized seq[TransactionPathDtoV2]
|
||||||
gasTimeEstimate*: FeesDto
|
gasTimeEstimate*: FeesDto
|
||||||
amountToReceive*: UInt256
|
amountToReceive*: UInt256
|
||||||
toNetworks*: seq[SendToNetwork]
|
toNetworks*: seq[SendToNetwork]
|
||||||
|
|
||||||
|
proc getGasEthValue*(gweiValue: float, gasLimit: uint64): float =
|
||||||
|
let weiValue = service_conversion.gwei2Wei(gweiValue) * u256(gasLimit)
|
||||||
|
let ethValue = parseFloat(service_conversion.wei2Eth(weiValue))
|
||||||
|
return ethValue
|
||||||
|
|
||||||
|
proc getFeesTotal*(paths: seq[TransactionPathDto]): FeesDto =
|
||||||
|
var fees: FeesDto = FeesDto()
|
||||||
|
if(paths.len == 0):
|
||||||
|
return fees
|
||||||
|
|
||||||
|
for path in paths:
|
||||||
|
var optimalPrice = path.gasFees.gasPrice
|
||||||
|
if path.gasFees.eip1559Enabled:
|
||||||
|
optimalPrice = path.gasFees.maxFeePerGasM
|
||||||
|
|
||||||
|
fees.totalFeesInEth += getGasEthValue(optimalPrice, path.gasAmount)
|
||||||
|
fees.totalFeesInEth += parseFloat(service_conversion.wei2Eth(service_conversion.gwei2Wei(path.gasFees.l1GasFee)))
|
||||||
|
fees.totalFeesInEth += path.approvalGasFees
|
||||||
|
fees.totalTokenFees += path.tokenFees
|
||||||
|
fees.totalTime += path.estimatedTime
|
||||||
|
return fees
|
||||||
|
|
||||||
|
proc getTotalAmountToReceive*(paths: seq[TransactionPathDto]): UInt256 =
|
||||||
|
var totalAmountToReceive: UInt256 = stint.u256(0)
|
||||||
|
for path in paths:
|
||||||
|
totalAmountToReceive += path.amountOut
|
||||||
|
|
||||||
|
return totalAmountToReceive
|
||||||
|
|
||||||
|
proc getToNetworksList*(paths: seq[TransactionPathDto]): seq[SendToNetwork] =
|
||||||
|
var networkMap: Table[int, SendToNetwork] = initTable[int, SendToNetwork]()
|
||||||
|
for path in paths:
|
||||||
|
if(networkMap.hasKey(path.toNetwork.chainId)):
|
||||||
|
networkMap[path.toNetwork.chainId].amountOut = networkMap[path.toNetwork.chainId].amountOut + path.amountOut
|
||||||
|
else:
|
||||||
|
networkMap[path.toNetwork.chainId] = SendToNetwork(chainId: path.toNetwork.chainId, chainName: path.toNetwork.chainName, iconUrl: path.toNetwork.iconURL, amountOut: path.amountOut)
|
||||||
|
return toSeq(networkMap.values)
|
||||||
|
|
||||||
|
proc addFirstSimpleBridgeTxFlag*(paths: seq[TransactionPathDto]) : seq[TransactionPathDto] =
|
||||||
|
let txPaths = paths
|
||||||
|
var firstSimplePath: bool = false
|
||||||
|
var firstBridgePath: bool = false
|
||||||
|
|
||||||
|
for path in txPaths:
|
||||||
|
if not firstSimplePath:
|
||||||
|
firstSimplePath = true
|
||||||
|
path.isFirstSimpleTx = true
|
||||||
|
if path.bridgeName != "Transfer":
|
||||||
|
if not firstBridgePath:
|
||||||
|
firstBridgePath = false
|
||||||
|
path.isFirstBridgeTx = true
|
||||||
|
|
||||||
|
return txPaths
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
# include app_service/common/json_utils
|
# include app_service/common/json_utils
|
||||||
|
|
||||||
import json, strutils, stint, json_serialization
|
import json, strutils, stint, json_serialization
|
||||||
|
import sequtils, sugar
|
||||||
|
|
||||||
import
|
import
|
||||||
web3/ethtypes
|
web3/ethtypes
|
||||||
|
@ -24,6 +25,7 @@ type
|
||||||
fromChain*: NetworkDto
|
fromChain*: NetworkDto
|
||||||
toChain*: NetworkDto
|
toChain*: NetworkDto
|
||||||
fromToken*: TokenDto
|
fromToken*: TokenDto
|
||||||
|
toToken*: TokenDto
|
||||||
amountIn*: UInt256
|
amountIn*: UInt256
|
||||||
amountInLocked*: bool
|
amountInLocked*: bool
|
||||||
amountOut*: UInt256
|
amountOut*: UInt256
|
||||||
|
@ -59,6 +61,7 @@ proc toTransactionPathDtoV2*(jsonObj: JsonNode): TransactionPathDtoV2 =
|
||||||
result.fromChain = Json.decode($jsonObj["FromChain"], NetworkDto, allowUnknownFields = true)
|
result.fromChain = Json.decode($jsonObj["FromChain"], NetworkDto, allowUnknownFields = true)
|
||||||
result.toChain = Json.decode($jsonObj["ToChain"], NetworkDto, allowUnknownFields = true)
|
result.toChain = Json.decode($jsonObj["ToChain"], NetworkDto, allowUnknownFields = true)
|
||||||
result.fromToken = Json.decode($jsonObj["FromToken"], TokenDto, allowUnknownFields = true)
|
result.fromToken = Json.decode($jsonObj["FromToken"], TokenDto, allowUnknownFields = true)
|
||||||
|
result.toToken = Json.decode($jsonObj["ToToken"], TokenDto, allowUnknownFields = true)
|
||||||
result.amountIn = stint.fromHex(UInt256, jsonObj{"AmountIn"}.getStr)
|
result.amountIn = stint.fromHex(UInt256, jsonObj{"AmountIn"}.getStr)
|
||||||
discard jsonObj.getProp("AmountInLocked", result.amountInLocked)
|
discard jsonObj.getProp("AmountInLocked", result.amountInLocked)
|
||||||
result.amountOut = stint.fromHex(UInt256, jsonObj{"AmountOut"}.getStr)
|
result.amountOut = stint.fromHex(UInt256, jsonObj{"AmountOut"}.getStr)
|
||||||
|
@ -77,3 +80,9 @@ proc toTransactionPathDtoV2*(jsonObj: JsonNode): TransactionPathDtoV2 =
|
||||||
discard jsonObj.getProp("ApprovalGasAmount", result.approvalGasAmount)
|
discard jsonObj.getProp("ApprovalGasAmount", result.approvalGasAmount)
|
||||||
result.approvalL1Fee = stint.fromHex(UInt256, jsonObj{"ApprovalL1Fee"}.getStr)
|
result.approvalL1Fee = stint.fromHex(UInt256, jsonObj{"ApprovalL1Fee"}.getStr)
|
||||||
result.estimatedTime = jsonObj{"EstimatedTime"}.getInt
|
result.estimatedTime = jsonObj{"EstimatedTime"}.getInt
|
||||||
|
|
||||||
|
proc toTransactionPathsDtoV2*(jsonObj: JsonNode): seq[TransactionPathDtoV2] =
|
||||||
|
return jsonObj.getElems().map(x => x.toTransactionPathDtoV2())
|
||||||
|
|
||||||
|
proc toTransactionPathsDtoV2*(rawPaths: string): seq[TransactionPathDtoV2] =
|
||||||
|
return rawPaths.parseJson.toTransactionPathsDtoV2()
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
import strutils, stint, chronicles, algorithm
|
||||||
|
|
||||||
|
import app_service/common/conversion
|
||||||
|
|
||||||
|
import ./dto, ./dtoV2
|
||||||
|
|
||||||
|
proc sortAsc[T](t1, t2: T): int =
|
||||||
|
if (t1.fromNetwork.chainId > t2.fromNetwork.chainId): return 1
|
||||||
|
elif (t1.fromNetwork.chainId < t2.fromNetwork.chainId): return -1
|
||||||
|
else: return 0
|
||||||
|
|
||||||
|
proc convertToOldRoute*(route: seq[TransactionPathDtoV2]): seq[TransactionPathDto] =
|
||||||
|
const
|
||||||
|
gweiDecimals = 9
|
||||||
|
ethDecimals = 18
|
||||||
|
for p in route:
|
||||||
|
var
|
||||||
|
fees = SuggestedFeesDto()
|
||||||
|
trPath = TransactionPathDto()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# prepare fees
|
||||||
|
fees.gasPrice = 0
|
||||||
|
var value = conversion.wei2Eth(input = p.txBaseFee, decimals = gweiDecimals)
|
||||||
|
fees.baseFee = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.txPriorityFee, decimals = gweiDecimals)
|
||||||
|
fees.maxPriorityFeePerGas = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.low, decimals = gweiDecimals)
|
||||||
|
fees.maxFeePerGasL = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.medium, decimals = gweiDecimals)
|
||||||
|
fees.maxFeePerGasM = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.high, decimals = gweiDecimals)
|
||||||
|
fees.maxFeePerGasH = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.txL1Fee, decimals = gweiDecimals)
|
||||||
|
fees.l1GasFee = parseFloat(value)
|
||||||
|
fees.eip1559Enabled = true
|
||||||
|
|
||||||
|
# prepare tx path
|
||||||
|
trPath.bridgeName = p.processorName
|
||||||
|
trPath.fromNetwork = p.fromChain
|
||||||
|
trPath.toNetwork = p.toChain
|
||||||
|
trPath.fromToken = p.fromToken
|
||||||
|
trPath.toToken = p.toToken
|
||||||
|
trPath.gasFees = fees
|
||||||
|
# trPath.cost = not in use for old approach in the desktop app
|
||||||
|
value = conversion.wei2Eth(input = p.txTokenFees, decimals = p.fromToken.decimals)
|
||||||
|
trPath.tokenFees = parseFloat(value)
|
||||||
|
value = conversion.wei2Eth(input = p.txBonderFees, decimals = p.fromToken.decimals)
|
||||||
|
trPath.bonderFees = value
|
||||||
|
trPath.tokenFees += parseFloat(value) # we add bonder fees to the token fees cause in the UI, atm, we show only token fees
|
||||||
|
trPath.maxAmountIn = stint.fromHex(UInt256, "0x0")
|
||||||
|
trPath.amountIn = p.amountIn
|
||||||
|
trPath.amountOut = p.amountOut
|
||||||
|
trPath.approvalRequired = p.approvalRequired
|
||||||
|
trPath.approvalAmountRequired = p.approvalAmountRequired
|
||||||
|
trPath.approvalContractAddress = p.approvalContractAddress
|
||||||
|
trPath.amountInLocked = p.amountInLocked
|
||||||
|
trPath.estimatedTime = p.estimatedTime
|
||||||
|
trPath.gasAmount = p.txGasAmount
|
||||||
|
|
||||||
|
value = conversion.wei2Eth(p.suggestedLevelsForMaxFeesPerGas.medium, decimals = ethDecimals)
|
||||||
|
trPath.approvalGasFees = parseFloat(value) * float64(p.approvalGasAmount)
|
||||||
|
value = conversion.wei2Eth(p.approvalL1Fee, decimals = ethDecimals)
|
||||||
|
trPath.approvalGasFees += parseFloat(value)
|
||||||
|
|
||||||
|
trPath.isFirstSimpleTx = false
|
||||||
|
trPath.isFirstBridgeTx = false
|
||||||
|
except Exception as e:
|
||||||
|
error "Error converting to old path", msg = e.msg
|
||||||
|
|
||||||
|
# add tx path to the list
|
||||||
|
result.add(trPath)
|
||||||
|
|
||||||
|
result.sort(sortAsc[TransactionPathDto])
|
|
@ -1,4 +1,4 @@
|
||||||
import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, algorithm, uuids, stew/shims/strformat
|
import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, uuids, stew/shims/strformat
|
||||||
|
|
||||||
import backend/collectibles as collectibles
|
import backend/collectibles as collectibles
|
||||||
import backend/transactions as transactions
|
import backend/transactions as transactions
|
||||||
|
@ -6,7 +6,6 @@ import backend/backend
|
||||||
import backend/eth
|
import backend/eth
|
||||||
|
|
||||||
import app_service/service/ens/utils as ens_utils
|
import app_service/service/ens/utils as ens_utils
|
||||||
import app_service/common/conversion as common_conversion
|
|
||||||
import app_service/common/utils as common_utils
|
import app_service/common/utils as common_utils
|
||||||
import app_service/common/types as common_types
|
import app_service/common/types as common_types
|
||||||
|
|
||||||
|
@ -24,9 +23,9 @@ import app_service/service/eth/dto/transaction as transaction_data_dto
|
||||||
import app_service/service/eth/dto/[coder, method_dto]
|
import app_service/service/eth/dto/[coder, method_dto]
|
||||||
import ./dto as transaction_dto
|
import ./dto as transaction_dto
|
||||||
import ./dtoV2
|
import ./dtoV2
|
||||||
|
import ./dto_conversion
|
||||||
import ./cryptoRampDto
|
import ./cryptoRampDto
|
||||||
import app_service/service/eth/utils as eth_utils
|
import app_service/service/eth/utils as eth_utils
|
||||||
import app_service/common/conversion
|
|
||||||
|
|
||||||
|
|
||||||
export transaction_dto
|
export transaction_dto
|
||||||
|
@ -130,7 +129,7 @@ QtObject:
|
||||||
tokenService: token_service.Service
|
tokenService: token_service.Service
|
||||||
|
|
||||||
## Forward declarations
|
## Forward declarations
|
||||||
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], error: string, errCode: string)
|
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, error: string, errCode: string)
|
||||||
|
|
||||||
proc delete*(self: Service) =
|
proc delete*(self: Service) =
|
||||||
self.QObject.delete
|
self.QObject.delete
|
||||||
|
@ -161,7 +160,7 @@ QtObject:
|
||||||
|
|
||||||
self.events.on(SignalType.WalletSuggestedRoutes.event) do(e:Args):
|
self.events.on(SignalType.WalletSuggestedRoutes.event) do(e:Args):
|
||||||
var data = WalletSignal(e)
|
var data = WalletSignal(e)
|
||||||
self.suggestedRoutesV2Ready(data.uuid, data.bestRoute, data.error, data.errorCode)
|
self.suggestedRoutesV2Ready(data.uuid, data.bestRoute, data.bestRouteRaw, data.error, data.errorCode)
|
||||||
|
|
||||||
self.events.on(PendingTransactionTypeDto.WalletTransfer.event) do(e: Args):
|
self.events.on(PendingTransactionTypeDto.WalletTransfer.event) do(e: Args):
|
||||||
try:
|
try:
|
||||||
|
@ -299,7 +298,10 @@ QtObject:
|
||||||
path.eRC1155TransferTx = eRC1155TransferTx
|
path.eRC1155TransferTx = eRC1155TransferTx
|
||||||
elif(route.bridgeName == SWAP_PARASWAP_NAME):
|
elif(route.bridgeName == SWAP_PARASWAP_NAME):
|
||||||
swapTx = txData
|
swapTx = txData
|
||||||
swapTx.chainID = route.toNetwork.chainId.some
|
swapTx.chainID = route.fromNetwork.chainId.some
|
||||||
|
swapTx.chainIDTo = route.toNetwork.chainId.some
|
||||||
|
swapTx.tokenIdFrom = route.fromToken.symbol.some
|
||||||
|
swapTx.tokenIdTo = route.toToken.symbol.some
|
||||||
path.swapTx = swapTx
|
path.swapTx = swapTx
|
||||||
else:
|
else:
|
||||||
cbridgeTx = txData
|
cbridgeTx = txData
|
||||||
|
@ -569,75 +571,14 @@ QtObject:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error getting suggested fees", msg = e.msg
|
error "Error getting suggested fees", msg = e.msg
|
||||||
|
|
||||||
proc convertToOldRoute(route: seq[TransactionPathDtoV2]): seq[TransactionPathDto] =
|
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, error: string, errCode: string) =
|
||||||
const
|
|
||||||
gweiDecimals = 9
|
|
||||||
ethDecimals = 18
|
|
||||||
for p in route:
|
|
||||||
var
|
|
||||||
fees = SuggestedFeesDto()
|
|
||||||
trPath = TransactionPathDto()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# prepare fees
|
|
||||||
fees.gasPrice = 0
|
|
||||||
var value = conversion.wei2Eth(input = p.txBaseFee, decimals = gweiDecimals)
|
|
||||||
fees.baseFee = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.txPriorityFee, decimals = gweiDecimals)
|
|
||||||
fees.maxPriorityFeePerGas = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.low, decimals = gweiDecimals)
|
|
||||||
fees.maxFeePerGasL = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.medium, decimals = gweiDecimals)
|
|
||||||
fees.maxFeePerGasM = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.suggestedLevelsForMaxFeesPerGas.high, decimals = gweiDecimals)
|
|
||||||
fees.maxFeePerGasH = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.txL1Fee, decimals = gweiDecimals)
|
|
||||||
fees.l1GasFee = parseFloat(value)
|
|
||||||
fees.eip1559Enabled = true
|
|
||||||
|
|
||||||
# prepare tx path
|
|
||||||
trPath.bridgeName = p.processorName
|
|
||||||
trPath.fromNetwork = p.fromChain
|
|
||||||
trPath.toNetwork = p.toChain
|
|
||||||
trPath.gasFees = fees
|
|
||||||
# trPath.cost = not in use for old approach in the desktop app
|
|
||||||
value = conversion.wei2Eth(input = p.txTokenFees, decimals = p.fromToken.decimals)
|
|
||||||
trPath.tokenFees = parseFloat(value)
|
|
||||||
value = conversion.wei2Eth(input = p.txBonderFees, decimals = p.fromToken.decimals)
|
|
||||||
trPath.bonderFees = value
|
|
||||||
trPath.tokenFees += parseFloat(value) # we add bonder fees to the token fees cause in the UI, atm, we show only token fees
|
|
||||||
trPath.maxAmountIn = stint.fromHex(UInt256, "0x0")
|
|
||||||
trPath.amountIn = p.amountIn
|
|
||||||
trPath.amountOut = p.amountOut
|
|
||||||
trPath.approvalRequired = p.approvalRequired
|
|
||||||
trPath.approvalAmountRequired = p.approvalAmountRequired
|
|
||||||
trPath.approvalContractAddress = p.approvalContractAddress
|
|
||||||
trPath.amountInLocked = p.amountInLocked
|
|
||||||
trPath.estimatedTime = p.estimatedTime
|
|
||||||
trPath.gasAmount = p.txGasAmount
|
|
||||||
|
|
||||||
value = conversion.wei2Eth(p.suggestedLevelsForMaxFeesPerGas.medium, decimals = ethDecimals)
|
|
||||||
trPath.approvalGasFees = parseFloat(value) * float64(p.approvalGasAmount)
|
|
||||||
value = conversion.wei2Eth(p.approvalL1Fee, decimals = ethDecimals)
|
|
||||||
trPath.approvalGasFees += parseFloat(value)
|
|
||||||
|
|
||||||
trPath.isFirstSimpleTx = false
|
|
||||||
trPath.isFirstBridgeTx = false
|
|
||||||
except Exception as e:
|
|
||||||
error "Error converting to old path", msg = e.msg
|
|
||||||
|
|
||||||
# add tx path to the list
|
|
||||||
result.add(trPath)
|
|
||||||
|
|
||||||
result.sort(sortAsc[TransactionPathDto])
|
|
||||||
|
|
||||||
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], error: string, errCode: string) =
|
|
||||||
# TODO: refactor sending modal part of the app, but for now since we're integrating the router v2 just map params to the old dto
|
# TODO: refactor sending modal part of the app, but for now since we're integrating the router v2 just map params to the old dto
|
||||||
|
|
||||||
var oldRoute = convertToOldRoute(route)
|
var oldRoute = convertToOldRoute(route)
|
||||||
|
|
||||||
let suggestedDto = SuggestedRoutesDto(
|
let suggestedDto = SuggestedRoutesDto(
|
||||||
best: addFirstSimpleBridgeTxFlag(oldRoute),
|
best: addFirstSimpleBridgeTxFlag(oldRoute),
|
||||||
|
rawBest: routeRaw,
|
||||||
gasTimeEstimate: getFeesTotal(oldRoute),
|
gasTimeEstimate: getFeesTotal(oldRoute),
|
||||||
amountToReceive: getTotalAmountToReceive(oldRoute),
|
amountToReceive: getTotalAmountToReceive(oldRoute),
|
||||||
toNetworks: getToNetworksList(oldRoute),
|
toNetworks: getToNetworksList(oldRoute),
|
||||||
|
|
Loading…
Reference in New Issue