Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/shared/blockchain/evm-based/src/lib/evm-based.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ethWallet, { hdkey as ethHdKey } from 'ethereumjs-wallet'
import { ADDRESS_PREFIX, EvmBasedBlockchain, getDerivationPath } from '@tatumio/shared-core'
import { generateMnemonic, mnemonicToSeed } from 'bip39'
import { CreateRecord, Wallet } from '@tatumio/api-client'
import { CreateRecord, Currency, Wallet } from '@tatumio/api-client'
import Web3 from 'web3'
import { TransactionConfig } from 'web3-core'
import { isHex, stringToHex, toHex, toWei, Unit } from 'web3-utils'
Expand All @@ -11,6 +11,7 @@ import BigNumber from 'bignumber.js'
import { Erc20Token } from './contracts'
import { EvmBasedWeb3 } from './services/evm-based.web3'
import { EvmBasedErrorCodesFromNode, EvmBasedSdkError } from './evm-based.sdk.errors'
import { GasPumpChain } from './services/evm-based.gas.pump'

export const evmBasedUtils = {
generateAddressFromXPub: (xpub: string, i: number, prefix = ADDRESS_PREFIX.EVM): string => {
Expand Down Expand Up @@ -60,10 +61,20 @@ export const evmBasedUtils = {
gasLimit?: string,
gasPrice?: string,
provider?: string,
chain?: GasPumpChain,
testnet?: boolean,
) => {
const gasPriceDefined = gasPrice
let gasPriceDefined = gasPrice
? client.utils.toWei(gasPrice, 'gwei')
: await web3.getGasPriceInWei(provider)

if (chain === Currency.MATIC && testnet && !gasPrice) {
const cappedPrice = client.utils.toWei('60', 'gwei')
if (BigInt(cappedPrice) < BigInt(gasPriceDefined)) {
gasPriceDefined = cappedPrice
}
}

const tx: TransactionConfig = {
from: 0,
...transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const evmBasedSmartContract = (web3: EvmBasedWeb3) => {
testnet?: boolean,
) => {
const r = buildSmartContractMethodInvocation(body, params, methodName, abi)
return await smartContractWriteMethodInvocation({ body: r, web3, provider, chain: body.chain })
return await smartContractWriteMethodInvocation({ body: r, web3, provider, chain: body.chain, testnet })
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export const smartContractWriteMethodInvocation = async ({
provider,
chain,
addressTransformer = (address: string) => address,
testnet,
}: {
body: ChainSmartContractMethodInvocation
web3: EvmBasedWeb3
provider?: string
chain?: GasPumpChain
addressTransformer?: AddressTransformer
testnet?: boolean
}) => {
const { fromPrivateKey, fee, params, methodName, methodABI, nonce, amount, signatureId } = body
const contractAddress = addressTransformer(body.contractAddress?.trim())
Expand All @@ -44,6 +46,8 @@ export const smartContractWriteMethodInvocation = async ({
fee?.gasLimit,
fee?.gasPrice,
provider,
chain,
testnet,
)
}

Expand Down