Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

872 [2] EVM EIP1559 #891

Merged
merged 9 commits into from
Nov 6, 2023
Merged
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
6 changes: 6 additions & 0 deletions packages/xchain-avax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.3.5 (2023-11-03)

## Update

- EIP1559 params

# v0.3.4 (2023-11-02)

## Update
Expand Down
22 changes: 21 additions & 1 deletion packages/xchain-avax/__e2e__/avax-client.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Balance, Network, OnlineDataProviders, TxType } from '@xchainjs/xchain-client'
import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainjs/xchain-evm'
import { CovalentProvider } from '@xchainjs/xchain-evm-providers'
import { Asset, assetAmount, assetToBase, assetToString } from '@xchainjs/xchain-util'
import { Asset, assetAmount, assetToBase, assetToString, baseAmount } from '@xchainjs/xchain-util'

import AvaxClient from '../src/client'
import { AVAXChain, AssetAVAX, defaultAvaxParams } from '../src/const'
Expand Down Expand Up @@ -108,6 +108,26 @@ describe('xchain-evm (Avax) Integration Tests', () => {
const txHash = await client.transfer({ amount, recipient, memo })
console.log(txHash)
})
it('should transfer 0.01 AVAX following EIP1559 because of maxFeePerGas', async () => {
const recipient = client.getAddress(1)
const amount = assetToBase(assetAmount('0.01', 18))
const txHash = await client.transfer({
amount,
recipient,
maxFeePerGas: baseAmount('51700000000', 18),
})
console.log(txHash)
})
it('should transfer 0.01 AVAX following EIP1559 because of maxPriorityFeePerGas', async () => {
const recipient = client.getAddress(1)
const amount = assetToBase(assetAmount('0.01', 18))
const txHash = await client.transfer({
amount,
recipient,
maxPriorityFeePerGas: baseAmount('1700000000', 18),
})
console.log(txHash)
})
it('should transfer 0.01 RIP(ERC-20) between wallet 0 and 1', async () => {
const recipient = client.getAddress(1)
const amount = assetToBase(assetAmount('0.01', 18))
Expand Down
8 changes: 4 additions & 4 deletions packages/xchain-avax/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-avax",
"version": "0.3.4",
"version": "0.3.5",
"description": "Avax EVM client for XChainJS",
"keywords": [
"XChain",
Expand Down Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
Expand All @@ -46,10 +46,10 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
"ethers": "^5.7.2"
}
}
}
6 changes: 6 additions & 0 deletions packages/xchain-bsc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.3.5 (2023-11-03)

## Update

- EIP1559 params

# v0.3.4 (2023-11-02)

## Update
Expand Down
8 changes: 4 additions & 4 deletions packages/xchain-bsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-bsc",
"version": "0.3.4",
"version": "0.3.5",
"description": "Binance Smart Chain EVM client for XChainJS",
"keywords": [
"XChain",
Expand Down Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
Expand All @@ -46,10 +46,10 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
"ethers": "^5.7.2"
}
}
}
6 changes: 6 additions & 0 deletions packages/xchain-ethereum/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.30.6 (2023-11-03)

## Update

- EIP1559 params

# v0.30.5 (2023-11-02)

## Update
Expand Down
8 changes: 4 additions & 4 deletions packages/xchain-ethereum/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-ethereum",
"version": "0.30.5",
"version": "0.30.6",
"description": "Ethereum EVM client for XChainJS",
"keywords": [
"XChain",
Expand Down Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
Expand All @@ -46,10 +46,10 @@
"peerDependencies": {
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-evm": "^0.3.5",
"@xchainjs/xchain-evm": "^0.3.6",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",
"ethers": "^5.7.2"
}
}
}
6 changes: 6 additions & 0 deletions packages/xchain-evm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.3.6 (2023-11-03)

## Update

- EIP1559 params

# v0.3.5 (2023-11-02)

## Update
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-evm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-evm",
"version": "0.3.5",
"version": "0.3.6",
"description": "Genereic EVM client for XChainJS",
"keywords": [
"XChain",
Expand Down
56 changes: 40 additions & 16 deletions packages/xchain-evm/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
FeesWithGasPricesAndLimits,
GasPrices,
IsApprovedParams,
TxOverrides,
} from './types'
import {
call,
Expand Down Expand Up @@ -493,18 +492,47 @@ export default class Client extends BaseXChainClient implements XChainClient {
recipient,
feeOption = FeeOption.Fast,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
gasLimit,
}: TxParams & {
signer?: Signer
feeOption?: FeeOption
gasPrice?: BaseAmount
maxFeePerGas?: BaseAmount
maxPriorityFeePerGas?: BaseAmount
gasLimit?: BigNumber
}): Promise<TxHash> {
const txGasPrice: BigNumber = gasPrice
? BigNumber.from(gasPrice.amount().toFixed())
: await this.estimateGasPrices()
.then((prices) => prices[feeOption])
.then((gp) => BigNumber.from(gp.amount().toFixed()))
if (gasPrice && (maxFeePerGas || maxPriorityFeePerGas)) {
throw new Error('gasPrice is not compatible with EIP 1559 (maxFeePerGas and maxPriorityFeePerGas) params')
}

const feeData: ethers.providers.FeeData = {
lastBaseFeePerGas: null,
maxFeePerGas: null,
maxPriorityFeePerGas: null,
gasPrice: null,
}

if (maxFeePerGas || maxPriorityFeePerGas) {
const feeInfo = await this.getProvider().getFeeData()
if (maxFeePerGas) {
feeData.maxFeePerGas = BigNumber.from(maxFeePerGas.amount().toFixed())
} else if (maxPriorityFeePerGas && feeInfo.lastBaseFeePerGas) {
feeData.maxFeePerGas = feeInfo.lastBaseFeePerGas.mul(2).add(maxPriorityFeePerGas.amount().toFixed())
}
feeData.maxPriorityFeePerGas = maxPriorityFeePerGas
? BigNumber.from(maxPriorityFeePerGas.amount().toFixed())
: feeInfo.maxPriorityFeePerGas
} else {
const txGasPrice: BigNumber = gasPrice
? BigNumber.from(gasPrice.amount().toFixed())
: await this.estimateGasPrices()
.then((prices) => prices[feeOption])
.then((gp) => BigNumber.from(gp.amount().toFixed()))
checkFeeBounds(this.feeBounds, txGasPrice.toNumber())
feeData.gasPrice = txGasPrice
}

const sender = this.getAddress(walletIndex || 0)

Expand All @@ -521,14 +549,6 @@ export default class Client extends BaseXChainClient implements XChainClient {
txGasLimit = gasLimit
}

type SafeTxOverrides = Omit<TxOverrides, 'gasPrice'> & { gasPrice: ethers.BigNumber }
const overrides: SafeTxOverrides = {
gasLimit: txGasLimit,
gasPrice: txGasPrice,
}

checkFeeBounds(this.feeBounds, overrides.gasPrice.toNumber())

const { rawUnsignedTx } = await this.prepareTx({
sender,
recipient,
Expand All @@ -541,13 +561,17 @@ export default class Client extends BaseXChainClient implements XChainClient {

const signer = txSigner || this.getWallet(walletIndex)

const { hash } = await signer.sendTransaction({
const tx = await signer.populateTransaction({
from: transactionRequest.from,
to: transactionRequest.to,
data: transactionRequest.data,
value: transactionRequest.value,
...overrides,
gasLimit: txGasLimit,
gasPrice: feeData.gasPrice || undefined,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas || undefined,
maxFeePerGas: feeData.maxFeePerGas || undefined,
})
const { hash } = await signer.sendTransaction(tx)

return hash
}
Expand Down
1 change: 1 addition & 0 deletions packages/xchain-thorchain-amm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Update

- Force Thorchain estimations

# v0.7.9 (2023-11-03)

## Update
Expand Down
Loading