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

feat: bump ethers to v6 #6224

Merged
merged 68 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7536f77
[skip ci] wip: bump ethers to v6
gomesalexandre Feb 15, 2024
6704547
feat: fragments bs
gomesalexandre Feb 15, 2024
4c1223f
feat: almost there
gomesalexandre Feb 15, 2024
f87a43d
feat: almost there
gomesalexandre Feb 15, 2024
a992e5e
fix: all types
gomesalexandre Feb 17, 2024
d646d52
feat: start migrating unchained-client to v6
gomesalexandre Feb 17, 2024
0674d03
feat: enforce unchained-client to workspace version
gomesalexandre Feb 17, 2024
6d0c7d3
feat: more resolutions enforcement
gomesalexandre Feb 17, 2024
2a0036c
fix: derp mocks
gomesalexandre Feb 17, 2024
450e971
fix: many tests
gomesalexandre Feb 17, 2024
8162f43
fix: most tests
gomesalexandre Feb 19, 2024
ddfae0e
fix: all tests
gomesalexandre Feb 19, 2024
20ee753
feat: yarn v5 aliased node_module
gomesalexandre Feb 19, 2024
2563e79
feat: don't install ethers as direct dep in unchained-client
gomesalexandre Feb 19, 2024
6d576d0
feat: cleanup package.json monkey patch
gomesalexandre Feb 19, 2024
8c0af33
feat: bring back v6 resolution in unchained-client
gomesalexandre Feb 19, 2024
566db58
feat: default export shenanigans
gomesalexandre Feb 19, 2024
dc47e9c
fix: uni-v2 DeFi opportunities resolver
gomesalexandre Feb 19, 2024
4531a5f
feat: revert console log
gomesalexandre Feb 19, 2024
b8d75f6
fix: ci
gomesalexandre Feb 19, 2024
8588b38
fix: derp
gomesalexandre Feb 19, 2024
dae0541
fix: investor-foxy access .target vs. .address
gomesalexandre Feb 19, 2024
7543a79
feat: more BigInt / bignumber.js shenanigans
gomesalexandre Feb 19, 2024
69e599f
feat: everything is saner with types
gomesalexandre Feb 19, 2024
d877645
fix: tests
gomesalexandre Feb 19, 2024
e19e201
Merge remote-tracking branch 'origin/develop' into feat_ethers_v6
gomesalexandre Feb 20, 2024
db30dd5
feat: temporarily exclude tests
gomesalexandre Feb 20, 2024
c057be8
Merge branch 'develop' into feat_ethers_v6
gomesalexandre Feb 20, 2024
e711535
feat: import zeroAddress from viem
gomesalexandre Feb 21, 2024
ee8e6c3
feat: viem getAddress
gomesalexandre Feb 21, 2024
efc5f1b
feat: viem isHex
gomesalexandre Feb 21, 2024
6d83357
feat: viem isAddress
gomesalexandre Feb 21, 2024
a526412
feat: viem toHex
gomesalexandre Feb 21, 2024
5ed9d65
feat: viem hexlify -> toHex
gomesalexandre Feb 21, 2024
57bcfca
feat: viem stringToBytes
gomesalexandre Feb 21, 2024
604bf05
feat: viem keccak256
gomesalexandre Feb 21, 2024
214c676
feat: cleanup
gomesalexandre Feb 21, 2024
c28d394
Merge remote-tracking branch 'origin/develop' into feat_ethers_v6
gomesalexandre Feb 21, 2024
b8919ab
fix tests and remove mock
kaladinlight Feb 22, 2024
89dab36
utils.ts @ethersproject -> ethers
kaladinlight Feb 22, 2024
37884a5
feat: viem stringToBytes
gomesalexandre Feb 21, 2024
7e2f644
feat: viem keccak256
gomesalexandre Feb 21, 2024
24becf9
feat: cleanup
gomesalexandre Feb 21, 2024
807ce48
fix: use correct account id for matching buy account (#6263)
kaladinlight Feb 20, 2024
b50b749
Merge branch 'main' into develop (#6271)
0xApotheosis Feb 21, 2024
0882ccb
feat: enable chain selection for assets (#6176)
woodenfurniture Feb 22, 2024
5e87fd1
chore: add 'remove liquidity' fees (#6175)
0xApotheosis Feb 22, 2024
4fa2c10
chore: wire remove liquidity confirm page (#6266)
0xApotheosis Feb 22, 2024
f7add3a
fix: merge
gomesalexandre Feb 22, 2024
5fb8d20
Merge remote-tracking branch 'origin/develop' into feat_ethers_v6
gomesalexandre Feb 22, 2024
043cbbf
remove remaining copy pasta mocks
kaladinlight Feb 22, 2024
27e1d9f
Merge branch 'feat_ethers_v6' of github.com:shapeshift/web into feat_…
kaladinlight Feb 22, 2024
ceca8eb
unchained-client cleanup
kaladinlight Feb 22, 2024
486af28
use v5 alias for yearn
kaladinlight Feb 22, 2024
fcfde46
remove extra getAddress calls
kaladinlight Feb 22, 2024
dfc9511
static provider
kaladinlight Feb 22, 2024
ba37703
mock works now
kaladinlight Feb 22, 2024
1ed5765
use viem cleanup
kaladinlight Feb 22, 2024
772b1ad
final ethers -> viem updates
kaladinlight Feb 22, 2024
e40efe1
update yarn lock
kaladinlight Feb 22, 2024
1cb3680
Merge branch 'develop' into feat_ethers_v6
kaladinlight Feb 22, 2024
965f432
Merge branch 'develop' into feat_ethers_v6
gomesalexandre Feb 26, 2024
009a04a
feat: toHex from string without intermediary bytes
gomesalexandre Feb 26, 2024
fbb0f62
feat: big brain no-useless-cast
gomesalexandre Feb 26, 2024
4832335
feat: 0n shorthand without BigInt constructor
gomesalexandre Feb 26, 2024
576b69a
feat: no-useless-getAddress on zeroAddress
gomesalexandre Feb 26, 2024
c5010e1
fix: lint
gomesalexandre Feb 26, 2024
bc842a4
Merge branch 'develop' into feat_ethers_v6
gomesalexandre Feb 27, 2024
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
114 changes: 48 additions & 66 deletions __mocks__/ethers.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,54 @@
import {
BigNumber,
Bytes,
BytesLike,
ethers,
providers,
Signature,
Signer,
UnsignedTransaction,
utils,
} from 'ethers'
import { ethers } from 'ethers'
import { vi } from 'vitest'

const Contract = vi.fn().mockImplementation(address => ({
decimals: () => {
switch (address as string) {
case '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48':
return 6
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 18
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 18
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 18
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
name: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'Uniswap V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'Wrapped Ether'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
symbol: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'UNI-V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'WETH'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
}))

const JsonRpcProvider = vi.fn()

const ethersMock = {
...ethers,
providers: {
JsonRpcProvider: vi.fn(),
StaticJsonRpcProvider: vi.fn(),
},
Contract: vi.fn().mockImplementation(address => ({
decimals: () => {
switch (address as string) {
case '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48':
return 6
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 18
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 18
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 18
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
name: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'Uniswap V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'Wrapped Ether'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
symbol: () => {
switch (address as string) {
case '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d':
return 'FOX'
case '0x470e8de2eBaef52014A47Cb5E6aF86884947F08c':
return 'UNI-V2'
case '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2':
return 'WETH'
default:
throw new Error(`no decimals mock for address: ${address}`)
}
},
})),
JsonRpcProvider,
Contract,
}

export {
ethersMock as ethers,
BigNumber,
Bytes,
BytesLike,
Signature,
Signer,
UnsignedTransaction,
providers,
utils,
}
export * from 'ethers'
export { ethersMock as ethers, Contract, JsonRpcProvider }
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
"envalid": "^7.3.1",
"eslint-plugin-react-memo": "^0.0.3",
"eth-url-parser": "^1.0.4",
"ethers": "^5.7.2",
"ethers": "^6.11.1",
"ethers5": "npm:[email protected]",
"framer-motion": "^11.0.3",
"friendly-challenge": "0.9.2",
"grapheme-splitter": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/caip/src/adapters/yearn/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Token, Vault } from '@yfi/sdk'
import { Yearn } from '@yfi/sdk'
import { ethers } from 'ethers'
import { ethers } from 'ethers5'
import fs from 'fs'
import toLower from 'lodash/toLower'
import uniqBy from 'lodash/uniqBy'
Expand Down
6 changes: 3 additions & 3 deletions packages/chain-adapters/src/evm/EvmBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { BIP44Params } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import type * as unchained from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'
import { utils } from 'ethers'
import { isAddress, toHex } from 'viem'
import { numberToHex } from 'web3-utils'

import type { ChainAdapter as IChainAdapter } from '../api'
Expand Down Expand Up @@ -247,7 +247,7 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap
}[this.chainId]

await wallet.ethSwitchChain({
chainId: utils.hexValue(adapterChainReference),
chainId: toHex(adapterChainReference),
chainName: this.getDisplayName(),
nativeCurrency: {
name: targetNetwork.name,
Expand Down Expand Up @@ -538,7 +538,7 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap

// eslint-disable-next-line require-await
async validateAddress(address: string): Promise<ValidAddressResult> {
const isValidAddress = utils.isAddress(address)
const isValidAddress = isAddress(address)
if (isValidAddress) return { valid: true, result: ValidAddressResultType.Valid }
return { valid: false, result: ValidAddressResultType.Invalid }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Test GnosisChainAdapter
* @group unit
*/
import { AddressZero } from '@ethersproject/constants'
import { ASSET_REFERENCE, fromChainId, gnosisAssetId, gnosisChainId } from '@shapeshiftoss/caip'
import type { ETHSignMessage, ETHSignTx, ETHWallet } from '@shapeshiftoss/hdwallet-core'
import type { NativeAdapterArgs } from '@shapeshiftoss/hdwallet-native'
Expand All @@ -13,6 +12,7 @@ import type { BIP44Params } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import type * as unchained from '@shapeshiftoss/unchained-client'
import { merge } from 'lodash'
import { zeroAddress } from 'viem'
import { describe, expect, it, vi } from 'vitest'
import { numberToHex } from 'web3-utils'

Expand Down Expand Up @@ -134,7 +134,7 @@ describe('GnosisChainAdapter', () => {
to: '0x642F4Bda144C63f6DC47EE0fDfbac0a193e2eDb7',
value: '123',
chainSpecific: {
from: AddressZero,
from: zeroAddress,
data: '0x',
},
}
Expand Down Expand Up @@ -460,7 +460,7 @@ describe('GnosisChainAdapter', () => {
const adapter = new gnosis.ChainAdapter(args)

const wallet = await getWallet()
wallet.ethGetAddress = async () => await Promise.resolve(AddressZero)
wallet.ethGetAddress = async () => await Promise.resolve(zeroAddress)

const tx = {
wallet,
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('GnosisChainAdapter', () => {
const tx = {
wallet: await getWallet(),
accountNumber,
to: AddressZero,
to: zeroAddress,
value,
chainSpecific: makeChainSpecific({ contractAddress }),
} as unknown as BuildSendTxInput<KnownChainIds.GnosisMainnet>
Expand Down
3 changes: 0 additions & 3 deletions packages/chain-adapters/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { AssetNamespace, ChainId } from '@shapeshiftoss/caip'
import { CHAIN_NAMESPACE, CHAIN_REFERENCE, fromChainId } from '@shapeshiftoss/caip'
import { BigNumber } from 'ethers'

export * from './bignumber'
export * from './bip44'
Expand Down Expand Up @@ -70,5 +69,3 @@ export const chainIdToChainLabel = (chainId: ChainId): string => {
throw new Error(`chainNamespace ${chainNamespace} not supported.`)
}
}

export const convertNumberToHex = (value: string): string => BigNumber.from(value).toHexString()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

const bep20: JsonFragment[] = [
const bep20: InterfaceAbi = [
{
anonymous: false,
inputs: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ChainId } from '@shapeshiftoss/caip'
import { toAssetId } from '@shapeshiftoss/caip'
import type { BigNumber } from 'ethers'
import { ethers } from 'ethers'

import type { BaseTxMetadata } from '../../../types'
Expand All @@ -16,17 +15,17 @@ export interface TxMetadata extends BaseTxMetadata {

interface ParserArgs {
chainId: ChainId
provider: ethers.providers.StaticJsonRpcProvider
provider: ethers.JsonRpcProvider
}

export class Parser<T extends Tx> implements SubParser<T> {
provider: ethers.providers.StaticJsonRpcProvider
provider: ethers.JsonRpcProvider

readonly chainId: ChainId
readonly abiInterface = new ethers.utils.Interface(bep20)
readonly abiInterface = new ethers.Interface(bep20)

readonly supportedFunctions = {
approveSigHash: this.abiInterface.getSighash('approve'),
approveSigHash: this.abiInterface.getFunction('approve')!.selector,
}

constructor(args: ParserArgs) {
Expand Down Expand Up @@ -58,9 +57,9 @@ export class Parser<T extends Tx> implements SubParser<T> {

switch (txSigHash) {
case this.supportedFunctions.approveSigHash: {
const amount = decoded.args.amount as BigNumber
const amount = decoded.args.amount as BigInt
const value = amount.toString()
if (amount.isZero()) {
if (amount === BigInt(0)) {
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
return await Promise.resolve({ data: { ...data, method: 'revoke', value } })
}
return await Promise.resolve({ data: { ...data, value } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const FOXY_STAKING_ABI: JsonFragment[] = [
export const FOXY_STAKING_ABI: InterfaceAbi = [
{
inputs: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const SHAPESHIFT_ROUTER_ABI: JsonFragment[] = [
export const SHAPESHIFT_ROUTER_ABI: InterfaceAbi = [
{
inputs: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const THOR_AVALANCHE_ABI: JsonFragment[] = [
export const THOR_AVALANCHE_ABI: InterfaceAbi = [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{
anonymous: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const THOR_ETHEREUM_ABI: JsonFragment[] = [
export const THOR_ETHEREUM_ABI: InterfaceAbi = [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{
anonymous: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const UNIV2_ABI: JsonFragment[] = [
export const UNIV2_ABI: InterfaceAbi = [
{
inputs: [
{ internalType: 'address', name: '_factory', type: 'address' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const UNIV2_STAKING_REWARDS_ABI: JsonFragment[] = [
export const UNIV2_STAKING_REWARDS_ABI: InterfaceAbi = [
{
inputs: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const WETH_ABI: JsonFragment[] = [
export const WETH_ABI: InterfaceAbi = [
{
constant: true,
inputs: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonFragment } from '@ethersproject/abi/lib/fragments'
import type { InterfaceAbi } from 'ethers'

export const YEARN_VAULT_ABI: JsonFragment[] = [
export const YEARN_VAULT_ABI: InterfaceAbi = [
{
name: 'Transfer',
inputs: [
Expand Down
10 changes: 5 additions & 5 deletions packages/unchained-client/src/evm/ethereum/parser/foxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export interface TxMetadata extends BaseTxMetadata {
}

export class Parser implements SubParser<Tx> {
readonly abiInterface = new ethers.utils.Interface(FOXY_STAKING_ABI)
readonly abiInterface = new ethers.Interface(FOXY_STAKING_ABI)

readonly supportedFunctions = {
stakeSigHash: this.abiInterface.getSighash('stake(uint256,address)'),
unstakeSigHash: this.abiInterface.getSighash('unstake'),
instantUnstakeSigHash: this.abiInterface.getSighash('instantUnstake'),
claimWithdrawSigHash: this.abiInterface.getSighash('claimWithdraw'),
stakeSigHash: this.abiInterface.getFunction('stake(uint256,address)')!.selector,
unstakeSigHash: this.abiInterface.getFunction('unstake')!.selector,
instantUnstakeSigHash: this.abiInterface.getFunction('instantUnstake')!.selector,
claimWithdrawSigHash: this.abiInterface.getFunction('claimWithdraw')!.selector,
}

async parse(tx: Tx): Promise<TxSpecific | undefined> {
Expand Down
Loading
Loading