feat(@wallet): multi tx approval/nonce

This commit is contained in:
Anthony Laibe 2022-12-19 13:39:35 +01:00 committed by Anthony Laibe
parent cc4ebc0ec8
commit e7b746795f
6 changed files with 81 additions and 43 deletions

View File

@ -89,8 +89,10 @@ proc buildTransaction*(
else:
result.txType = "0x00"
proc buildTokenTransaction*(source, contractAddress: Address, gas = "", gasPrice = "", isEIP1559Enabled = false,
maxPriorityFeePerGas = "", maxFeePerGas = ""): TransactionDataDto =
proc buildTokenTransaction*(
source, contractAddress: Address, gas = "", gasPrice = "", isEIP1559Enabled = false,
maxPriorityFeePerGas = "", maxFeePerGas = ""
): TransactionDataDto =
result = buildTransaction(source, 0.u256, gas, gasPrice, isEIP1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
result.to = contractAddress.some

View File

@ -6,50 +6,13 @@ import json, tables, json_serialization
include ../../../common/json_utils
type
BuyToken* = object
packId*: Stuint[256]
address*: Address
price*: Stuint[256]
Register* = object
label*: FixedBytes[32]
account*: Address
x*: FixedBytes[32]
y*: FixedBytes[32]
SetPubkey* = object
label*: FixedBytes[32]
x*: FixedBytes[32]
y*: FixedBytes[32]
ExpirationTime* = object
label*: FixedBytes[32]
Release* = object
label*: FixedBytes[32]
ApproveAndCall*[N: static[int]] = object
to*: Address
value*: Stuint[256]
data*: DynamicBytes[N]
Transfer* = object
to*: Address
value*: Stuint[256]
BalanceOf* = object
address*: Address
TokenOfOwnerByIndex* = object
address*: Address
index*: Stuint[256]
TokenPackId* = object
tokenId*: Stuint[256]
TokenUri* = object
tokenId*: Stuint[256]
Approve* = object
to*: Address
value*: Stuint[256]
# TODO: Figure out a way to parse a bool as a Bool instead of bool, as it is
# done in nim-web3

View File

@ -1,4 +1,9 @@
import json, strutils, stint, json_serialization, strformat
import
web3/ethtypes, json_serialization
from web3/conversions import `$`
include ../../common/json_utils
import ../network/dto
import ../../common/conversion as service_conversion
@ -166,6 +171,10 @@ type
amountInLocked*: bool
isFirstSimpleTx*: bool
isFirstBridgeTx*: bool
approvalRequired*: bool
approvalGasFees*: float
approvalAmountRequired*: UInt256
approvalContractAddress*: string
proc `$`*(self: TransactionPathDto): string =
return fmt"""TransactionPath(
@ -183,6 +192,10 @@ proc `$`*(self: TransactionPathDto): string =
amountInLocked:{self.amountInLocked},
isFirstSimpleTx:{self.isFirstSimpleTx},
isFirstBridgeTx:{self.isFirstBridgeTx}
approvalRequired:{self.approvalRequired},
approvalGasFees:{self.approvalGasFees},
approvalAmountRequired:{self.approvalAmountRequired},
approvalContractAddress:{self.approvalContractAddress},
)"""
proc toTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
@ -202,6 +215,10 @@ proc toTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
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)
result.approvalGasFees = parseFloat(jsonObj{"ApprovalGasFees"}.getStr)
discard jsonObj.getProp("ApprovalContractAddress", result.approvalContractAddress)
proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
result = TransactionPathDto()
@ -217,6 +234,10 @@ proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
result.amountOut = stint.u256(jsonObj{"amountOut"}.getStr)
result.estimatedTime = jsonObj{"estimatedTime"}.getInt
discard jsonObj.getProp("gasAmount", result.gasAmount)
discard jsonObj.getProp("approvalRequired", result.approvalRequired)
result.approvalAmountRequired = stint.u256(jsonObj{"approvalAmountRequired"}.getStr)
discard jsonObj.getProp("approvalGasFees", result.approvalGasFees)
discard jsonObj.getProp("approvalContractAddress", result.approvalContractAddress)
type
Fees* = ref object

View File

@ -1,4 +1,5 @@
import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, strformat, algorithm, math
import ../../../backend/transactions as transactions
import ../../../backend/backend
import ../../../backend/eth
@ -21,6 +22,7 @@ import ./cryptoRampDto
import ../eth/utils as eth_utils
import ../../common/conversion
export transaction_dto
logScope:
@ -274,6 +276,26 @@ QtObject:
if( not route.gasFees.eip1559Enabled):
gasFees = $route.gasFees.gasPrice
if route.approvalRequired:
let approve = Approve(
to: parseAddress(route.approvalContractAddress),
value: route.approvalAmountRequired,
)
data = ERC20_procS.toTable["approve"].encodeAbi(approve)
txData = ens_utils.buildTokenTransaction(
parseAddress(from_addr),
toAddress,
$route.gasAmount,
gasFees,
route.gasFees.eip1559Enabled,
$route.gasFees.maxPriorityFeePerGas,
$route.gasFees.maxFeePerGasM
)
txData.data = data
var path = TransactionBridgeDto(bridgeName: "Simple", chainID: route.fromNetwork.chainId)
path.simpleTx = txData
paths.add(path)
if(isEthTx) :
txData = ens_utils.buildTransaction(parseAddress(from_addr), eth2Wei(parseFloat(value), 18),
$route.gasAmount, gasFees, route.gasFees.eip1559Enabled, $route.gasFees.maxPriorityFeePerGas, $route.gasFees.maxFeePerGasM)

View File

@ -70,6 +70,36 @@ Item {
}
}
// Approval transaction
Repeater {
model: root.bestRoutes
StatusListItem {
id: listItem
color: Theme.palette.statusListItem.backgroundColor
width: parent.width
asset.name: "tiny/checkmark"
asset.color: Theme.palette.directColor1
statusListItemIcon.active: true
statusListItemIcon.opacity: modelData.isFirstSimpleTx
title: qsTr("Approve %1 %2 Bridge").arg(modelData.fromNetwork.chainName).arg(root.selectedTokenSymbol)
subTitle: "%1 eth".arg(LocaleUtils.numberToLocaleString(modelData.approvalGasFees))
statusListItemSubTitle.width: listItem.width/2 - Style.current.smallPadding
statusListItemSubTitle.elide: Text.ElideMiddle
statusListItemSubTitle.wrapMode: Text.NoWrap
visible: modelData.approvalRequired
components: [
StatusBaseText {
Layout.alignment: Qt.AlignRight
text: "%1%2".arg(currentCurrencySymbol).arg(LocaleUtils.numberToLocaleString(parseFloat(root.getFiatValue(modelData.approvalGasFees, "ETH", root.currentCurrency))))
font.pixelSize: 15
color: Theme.palette.baseColor1
width: listItem.width/2 - Style.current.padding
elide: Text.ElideRight
}
]
}
}
// Bridge
Repeater {
id: bridgeRepeater

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 186454528ba030a793cdeec254272578a2c70f49
Subproject commit 883f9677c593494eceadef004932c0434575a5be