mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-18 10:32:53 +00:00
feat(@desktop/communitytokens): Add l1 fees to community token estimations
There is only one status-go call for all fees: suggested fees, gas and l1 fee. Issue #14166
This commit is contained in:
parent
26923bc603
commit
93f62a1672
@ -61,6 +61,10 @@ proc wei2Eth*(input: Stuint[256], decimals: int = 18): string =
|
|||||||
|
|
||||||
fmt"{eth}.{leading_zeros}{remainder}"
|
fmt"{eth}.{leading_zeros}{remainder}"
|
||||||
|
|
||||||
|
proc gwei2Eth*(gwei: float): string =
|
||||||
|
let weis = gwei2Wei(gwei)
|
||||||
|
return wei2Eth(weis)
|
||||||
|
|
||||||
proc wei2Eth*(input: string, decimals: int): string =
|
proc wei2Eth*(input: string, decimals: int): string =
|
||||||
try:
|
try:
|
||||||
var input256: Stuint[256]
|
var input256: Stuint[256]
|
||||||
|
@ -41,11 +41,11 @@ const asyncGetDeployOwnerContractsFeesTask: Task = proc(argEncoded: string) {.gc
|
|||||||
try:
|
try:
|
||||||
var gasTable: Table[ContractTuple, int] # gas per contract
|
var gasTable: Table[ContractTuple, int] # gas per contract
|
||||||
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
||||||
let response = eth.suggestedFees(arg.chainId).result
|
|
||||||
feeTable[arg.chainId] = response.toSuggestedFeesDto()
|
|
||||||
|
|
||||||
let deployGas = community_tokens.deployOwnerTokenEstimate(arg.chainId, arg.addressFrom, arg.ownerParams, arg.masterParams, arg.communityId, arg.signerPubKey).result.getInt
|
let estimations = community_tokens.deployOwnerTokenEstimate(arg.chainId, arg.addressFrom, arg.ownerParams, arg.masterParams, arg.communityId, arg.signerPubKey).result
|
||||||
gasTable[(arg.chainId, "")] = deployGas
|
gasTable[(arg.chainId, "")] = estimations{"gasUnits"}.getInt
|
||||||
|
feeTable[arg.chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
|
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -72,12 +72,12 @@ const asyncGetDeployFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.
|
|||||||
try:
|
try:
|
||||||
var gasTable: Table[ContractTuple, int] # gas per contract
|
var gasTable: Table[ContractTuple, int] # gas per contract
|
||||||
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
||||||
let response = eth.suggestedFees(arg.chainId).result
|
|
||||||
feeTable[arg.chainId] = response.toSuggestedFeesDto()
|
let estimations = if arg.tokenType == TokenType.ERC721: community_tokens.deployCollectiblesEstimate(arg.chainId, arg.addressFrom).result
|
||||||
let deployGas = if arg.tokenType == TokenType.ERC721: community_tokens.deployCollectiblesEstimate(arg.chainId, arg.addressFrom).result.getInt
|
else: community_tokens.deployAssetsEstimate(arg.chainId, arg.addressFrom).result
|
||||||
else: community_tokens.deployAssetsEstimate(arg.chainId, arg.addressFrom).result.getInt
|
gasTable[(arg.chainId, "")] = estimations{"gasUnits"}.getInt
|
||||||
|
feeTable[arg.chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
gasTable[(arg.chainId, "")] = deployGas
|
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -105,10 +105,11 @@ const asyncSetSignerFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.
|
|||||||
try:
|
try:
|
||||||
var gasTable: Table[ContractTuple, int] # gas per contract
|
var gasTable: Table[ContractTuple, int] # gas per contract
|
||||||
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
||||||
let response = eth.suggestedFees(arg.chainId).result
|
|
||||||
feeTable[arg.chainId] = response.toSuggestedFeesDto()
|
let estimations = community_tokens.estimateSetSignerPubKey(arg.chainId, arg.contractAddress, arg.addressFrom, arg.newSignerPubKey).result
|
||||||
let gasUsed = community_tokens.estimateSetSignerPubKey(arg.chainId, arg.contractAddress, arg.addressFrom, arg.newSignerPubKey).result.getInt
|
gasTable[(arg.chainId, arg.contractAddress)] = estimations{"gasUnits"}.getInt
|
||||||
gasTable[(arg.chainId, "")] = gasUsed
|
feeTable[arg.chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
|
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -136,10 +137,11 @@ const asyncGetRemoteBurnFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimc
|
|||||||
try:
|
try:
|
||||||
var gasTable: Table[ContractTuple, int] # gas per contract
|
var gasTable: Table[ContractTuple, int] # gas per contract
|
||||||
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
||||||
let fee = eth.suggestedFees(arg.chainId).result.toSuggestedFeesDto()
|
|
||||||
let burnGas = community_tokens.estimateRemoteBurn(arg.chainId, arg.contractAddress, arg.addressFrom, arg.tokenIds).result.getInt
|
let estimations = community_tokens.estimateRemoteBurn(arg.chainId, arg.contractAddress, arg.addressFrom, arg.tokenIds).result
|
||||||
feeTable[arg.chainId] = fee
|
gasTable[(arg.chainId, arg.contractAddress)] = estimations{"gasUnits"}.getInt
|
||||||
gasTable[(arg.chainId, arg.contractAddress)] = burnGas
|
feeTable[arg.chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
|
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -167,10 +169,11 @@ const asyncGetBurnFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
|||||||
try:
|
try:
|
||||||
var gasTable: Table[ContractTuple, int] # gas per contract
|
var gasTable: Table[ContractTuple, int] # gas per contract
|
||||||
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
var feeTable: Table[int, SuggestedFeesDto] # fees for chain
|
||||||
let fee = eth.suggestedFees(arg.chainId).result.toSuggestedFeesDto()
|
|
||||||
let burnGas = community_tokens.estimateBurn(arg.chainId, arg.contractAddress, arg.addressFrom, arg.amount).result.getInt
|
let estimations = community_tokens.estimateBurn(arg.chainId, arg.contractAddress, arg.addressFrom, arg.amount).result
|
||||||
feeTable[arg.chainId] = fee
|
gasTable[(arg.chainId, arg.contractAddress)] = estimations{"gasUnits"}.getInt
|
||||||
gasTable[(arg.chainId, arg.contractAddress)] = burnGas
|
feeTable[arg.chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
|
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -200,15 +203,12 @@ const asyncGetMintFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
|||||||
for collectibleAndAmount in arg.collectiblesAndAmounts:
|
for collectibleAndAmount in arg.collectiblesAndAmounts:
|
||||||
# get fees if we do not have for this chain yet
|
# get fees if we do not have for this chain yet
|
||||||
let chainId = collectibleAndAmount.communityToken.chainId
|
let chainId = collectibleAndAmount.communityToken.chainId
|
||||||
if not feeTable.hasKey(chainId):
|
|
||||||
let feesResponse = eth.suggestedFees(chainId).result
|
|
||||||
feeTable[chainId] = feesResponse.toSuggestedFeesDto()
|
|
||||||
|
|
||||||
# get gas for smart contract
|
# get gas for smart contract
|
||||||
let gas = community_tokens.estimateMintTokens(chainId,
|
let estimations = community_tokens.estimateMintTokens(chainId,
|
||||||
collectibleAndAmount.communityToken.address, arg.addressFrom,
|
collectibleAndAmount.communityToken.address, arg.addressFrom,
|
||||||
arg.walletAddresses, collectibleAndAmount.amount).result.getInt
|
arg.walletAddresses, collectibleAndAmount.amount).result
|
||||||
gasTable[(chainId, collectibleAndAmount.communityToken.address)] = gas
|
gasTable[(chainId, collectibleAndAmount.communityToken.address)] = estimations{"gasUnits"}.getInt
|
||||||
|
feeTable[chainId] = estimations{"suggestedFees"}.toSuggestedFeesDto()
|
||||||
arg.finish(%* {
|
arg.finish(%* {
|
||||||
"feeTable": tableToJsonArray(feeTable),
|
"feeTable": tableToJsonArray(feeTable),
|
||||||
"gasTable": tableToJsonArray(gasTable),
|
"gasTable": tableToJsonArray(gasTable),
|
||||||
@ -311,7 +311,6 @@ const fetchAssetOwnersTaskArg: Task = proc(argEncoded: string) {.gcsafe, nimcall
|
|||||||
}
|
}
|
||||||
arg.finish(output)
|
arg.finish(output)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
echo "Exception", e.msg
|
|
||||||
let output = %* {
|
let output = %* {
|
||||||
"chainId": arg.chainId,
|
"chainId": arg.chainId,
|
||||||
"contractAddress": arg.contractAddress,
|
"contractAddress": arg.contractAddress,
|
||||||
|
@ -614,10 +614,7 @@ QtObject:
|
|||||||
if suggestedFees == nil:
|
if suggestedFees == nil:
|
||||||
error "Can't find suggested fees for chainId", chainId=chainId
|
error "Can't find suggested fees for chainId", chainId=chainId
|
||||||
return
|
return
|
||||||
return ens_utils.buildTransaction(parseAddress(addressFrom), 0.u256, $gasUnits,
|
return ens_utils.buildTransactionDataDto(gasUnits, suggestedFees, addressFrom, chainId, contractAddress)
|
||||||
if suggestedFees.eip1559Enabled: "" else: $suggestedFees.gasPrice, suggestedFees.eip1559Enabled,
|
|
||||||
if suggestedFees.eip1559Enabled: $suggestedFees.maxPriorityFeePerGas else: "",
|
|
||||||
if suggestedFees.eip1559Enabled: $suggestedFees.maxFeePerGasM else: "")
|
|
||||||
|
|
||||||
proc temporaryMasterContractAddress*(ownerContractTransactionHash: string): string =
|
proc temporaryMasterContractAddress*(ownerContractTransactionHash: string): string =
|
||||||
return ownerContractTransactionHash & "-master"
|
return ownerContractTransactionHash & "-master"
|
||||||
@ -1083,13 +1080,15 @@ QtObject:
|
|||||||
let (ethCurrency, fiatCurrency) = self.create0CurrencyAmounts()
|
let (ethCurrency, fiatCurrency) = self.create0CurrencyAmounts()
|
||||||
return ComputeFeeArgs(ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode)
|
return ComputeFeeArgs(ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode)
|
||||||
|
|
||||||
|
# Returns eth value with l1 fee included
|
||||||
proc computeEthValue(self:Service, gasUnits: int, suggestedFees: SuggestedFeesDto): float =
|
proc computeEthValue(self:Service, gasUnits: int, suggestedFees: SuggestedFeesDto): float =
|
||||||
try:
|
try:
|
||||||
let maxFees = suggestedFees.maxFeePerGasM
|
let maxFees = suggestedFees.maxFeePerGasM
|
||||||
let gasPrice = if suggestedFees.eip1559Enabled: maxFees else: suggestedFees.gasPrice
|
let gasPrice = if suggestedFees.eip1559Enabled: maxFees else: suggestedFees.gasPrice
|
||||||
|
|
||||||
let weiValue = gwei2Wei(gasPrice) * gasUnits.u256
|
let weiValue = gwei2Wei(gasPrice) * gasUnits.u256
|
||||||
let ethValueStr = wei2Eth(weiValue)
|
let l1FeeInWei = gwei2Wei(suggestedFees.l1GasFee)
|
||||||
|
let ethValueStr = wei2Eth(weiValue + l1FeeInWei)
|
||||||
return parseFloat(ethValueStr)
|
return parseFloat(ethValueStr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error computing eth value", msg = e.msg
|
error "Error computing eth value", msg = e.msg
|
||||||
@ -1115,7 +1114,7 @@ QtObject:
|
|||||||
proc createComputeFeeArgs(self: Service, gasUnits: int, suggestedFees: SuggestedFeesDto, chainId: int, walletAddress: string): ComputeFeeArgs =
|
proc createComputeFeeArgs(self: Service, gasUnits: int, suggestedFees: SuggestedFeesDto, chainId: int, walletAddress: string): ComputeFeeArgs =
|
||||||
let ethValue = self.computeEthValue(gasUnits, suggestedFees)
|
let ethValue = self.computeEthValue(gasUnits, suggestedFees)
|
||||||
let balance = self.getWalletBalanceForChain(walletAddress, chainId)
|
let balance = self.getWalletBalanceForChain(walletAddress, chainId)
|
||||||
debug "computing fees", walletBalance=balance, ethValue=ethValue
|
debug "computing fees", walletBalance=balance, ethValueWithL1Fee=ethValue, l1Fee=gwei2Eth(suggestedFees.l1GasFee)
|
||||||
return self.createComputeFeeArgsFromEthAndBalance(ethValue, balance)
|
return self.createComputeFeeArgsFromEthAndBalance(ethValue, balance)
|
||||||
|
|
||||||
# convert json returned from async task into gas table
|
# convert json returned from async task into gas table
|
||||||
|
@ -7,6 +7,7 @@ import ../eth/dto/transaction as eth_transaction_dto
|
|||||||
import ../../../backend/ens as status_ens
|
import ../../../backend/ens as status_ens
|
||||||
import ../../common/account_constants
|
import ../../common/account_constants
|
||||||
import ../../common/utils
|
import ../../common/utils
|
||||||
|
import ../../service/transaction/dto
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "ens-utils"
|
topics = "ens-utils"
|
||||||
@ -87,6 +88,15 @@ proc buildTransaction*(
|
|||||||
else:
|
else:
|
||||||
result.txType = "0x00"
|
result.txType = "0x00"
|
||||||
|
|
||||||
|
proc buildTransactionDataDto*(gasUnits: int, suggestedFees: SuggestedFeesDto, addressFrom: string, chainId: int, contractAddress: string): TransactionDataDto =
|
||||||
|
if suggestedFees == nil:
|
||||||
|
error "Can't find suggested fees for chainId", chainId=chainId
|
||||||
|
return
|
||||||
|
return buildTransaction(parseAddress(addressFrom), 0.u256, $gasUnits,
|
||||||
|
if suggestedFees.eip1559Enabled: "" else: $suggestedFees.gasPrice, suggestedFees.eip1559Enabled,
|
||||||
|
if suggestedFees.eip1559Enabled: $suggestedFees.maxPriorityFeePerGas else: "",
|
||||||
|
if suggestedFees.eip1559Enabled: $suggestedFees.maxFeePerGasM else: "")
|
||||||
|
|
||||||
proc buildTokenTransaction*(
|
proc buildTokenTransaction*(
|
||||||
source, contractAddress: Address, gas = "", gasPrice = "", isEIP1559Enabled = false,
|
source, contractAddress: Address, gas = "", gasPrice = "", isEIP1559Enabled = false,
|
||||||
maxPriorityFeePerGas = "", maxFeePerGas = ""
|
maxPriorityFeePerGas = "", maxFeePerGas = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user