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

chore(deps): upgrade viem to ^2.7.16 #5022

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"utf8": "^3.0.0",
"uuid": "^9.0.1",
"victory-native": "^36.9.1",
"viem": "^2.5.0",
"viem": "^2.7.16",
"vm-browserify": "^1.1.2",
"web3": "1.10.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/viem/estimateFeesPerGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
export async function estimateFeesPerGas(
client: Client,
feeCurrency?: Address
): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; baseFeePerGas: bigint }> {
): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; baseFeePerGas: bigint | null }> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseFeePerGas from getBlock now has a type of BigInt | null, it used to be any in prior versions. Looks like this will always be returned for the latest block, it's only null for older blocks before the EIP 1559 upgrade https://www.quicknode.com/docs/ethereum/eth_getBlockByHash. Another option to fix this would be to just throw if this is null as it would never happen in practice for the latest block.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference for throwing here, since we're only dealing with EIP-1559 based TXs in the rest of the code.

// Custom path for Celo that can be removed once it's supported in viem
// See https://github.com/wagmi-dev/viem/discussions/914
if (client.chain?.id === networkConfig.viemChain.celo.id) {
Expand Down
15 changes: 10 additions & 5 deletions src/viem/getLockableWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Address,
Chain,
Client,
PrivateKeyAccount,
Transport,
WalletActions,
WalletRpcSchema,
Expand All @@ -22,6 +23,7 @@ import {
signTypedData,
writeContract,
} from 'viem/actions'
import { Prettify } from 'viem/chains'

const TAG = 'viem/getLockableWallet'

Expand All @@ -35,15 +37,18 @@ export function getTransport(chain: Chain): Transport {
return viemTransports[result[0] as Network]
}

// Largely copied from https://github.com/wagmi-dev/viem/blob/main/src/clients/createWalletClient.ts#L32
// Largely copied from https://github.com/wevm/viem/blob/43df39918f990c039b322c05e7130721f7117bbd/src/clients/createWalletClient.ts#L38
export type ViemWallet<
transport extends Transport = Transport,
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined,
> = Client<transport, chain, account, WalletRpcSchema, Actions>
> = Prettify<Client<transport, chain, account, WalletRpcSchema, Actions<chain, account>>>

type Actions = Pick<
WalletActions,
type Actions<
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined,
> = Pick<
WalletActions<chain, account>,
| 'sendRawTransaction'
| 'sendTransaction'
| 'signTransaction'
Expand All @@ -69,7 +74,7 @@ export default function getLockableViemWallet(
chain,
transport: getTransport(chain),
account,
}).extend((client: Client): Actions => {
}).extend((client): Actions<Chain, PrivateKeyAccount> => {
return {
// All wallet functions that we want our ViemWallet to have must go here
// For instance we will later need prepareTransactionRequest which we can add here by
Expand Down
6 changes: 3 additions & 3 deletions src/viem/prepareTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function tryEstimateTransaction({
baseTransaction: TransactionRequest
maxFeePerGas: bigint
maxPriorityFeePerGas?: bigint
baseFeePerGas: bigint
baseFeePerGas?: bigint
feeCurrencySymbol: string
feeCurrencyAddress?: Address
}) {
Expand Down Expand Up @@ -196,7 +196,7 @@ export async function tryEstimateTransactions(
_estimatedGasUse: baseTx._estimatedGasUse
? baseTx._estimatedGasUse + BigInt(feeCurrency.isNative ? 0 : STATIC_GAS_PADDING)
: undefined,
_baseFeePerGas: baseFeePerGas,
_baseFeePerGas: baseFeePerGas ?? undefined,
})
} else {
const tx = await tryEstimateTransaction({
Expand All @@ -206,7 +206,7 @@ export async function tryEstimateTransactions(
feeCurrencyAddress,
maxFeePerGas,
maxPriorityFeePerGas,
baseFeePerGas,
baseFeePerGas: baseFeePerGas ?? undefined,
})
if (!tx) {
return null
Expand Down
6 changes: 3 additions & 3 deletions src/viem/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const mockViemFeeInfo = {
}

const mockViemWallet = {
account: { address: mockAccount },
account: { address: mockAccount2 },
writeContract: jest.fn(),
sendTransaction: jest.fn(),
} as any as ViemWallet
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('sendPayment', () => {
[matchers.call.fn(publicClient.celo.getBlock), { timestamp: 1701102971 }],
])
.call(getViemWallet, networkConfig.viemChain.celo)
.call(encryptComment, 'comment', mockSendPaymentArgs.recipientAddress, mockAccount, true)
.call(encryptComment, 'comment', mockSendPaymentArgs.recipientAddress, mockAccount2, true)
.call(getSendTxFeeDetails, {
recipientAddress: mockSendPaymentArgs.recipientAddress,
amount: BigNumber(2),
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('sendPayment', () => {
[matchers.call.fn(publicClient.celo.getBlock), { timestamp: 1701102971 }],
])
.call(getViemWallet, networkConfig.viemChain.celo)
.call(encryptComment, 'comment', mockSendPaymentArgs.recipientAddress, mockAccount, true)
.call(encryptComment, 'comment', mockSendPaymentArgs.recipientAddress, mockAccount2, true)
.not.call.fn(getSendTxFeeDetails)
.put(
addStandbyTransaction({
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18433,10 +18433,10 @@ victory@^36.9.1:
victory-voronoi-container "^36.9.1"
victory-zoom-container "^36.9.1"

viem@^2.5.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.6.0.tgz#b42fc27fd1500510320aa91da2846fb09457e808"
integrity sha512-6uVtT78SUFBFteBewXNel0AkTa/MP5wTqbWyg8ay4IyMXpSxuZl0QEN5H+/MBbEjILpRnJKD7E5klBLdWXNqXQ==
viem@^2.7.16:
version "2.7.16"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.7.16.tgz#99e66bbec661b2284bc32061474f20a90381bdcb"
integrity sha512-yOPa9yaoJUm44m0Qe3ugHnkHol3QQlFxN3jT+bq+lQip7X7cWdPfmguyfLWX2viCXcmYZUDiQdeFbkPW9lw11Q==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
Expand Down
Loading