Skip to content

Commit

Permalink
Merge branch 'wevm:main' into sei
Browse files Browse the repository at this point in the history
  • Loading branch information
abs3ntdev committed May 30, 2024
2 parents c78c678 + d4f34cb commit 389f0ae
Show file tree
Hide file tree
Showing 30 changed files with 213 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-dryers-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Improved `.extend` performance with `publicActions` and other large types.
5 changes: 5 additions & 0 deletions .changeset/tidy-toes-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Updated Avalanche explorer URLs.
5 changes: 5 additions & 0 deletions .changeset/warm-radios-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Exported `DecodeFunctionDataReturnType` type.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export { arbitrum } from './definitions/arbitrum.js'
export { zora } from './definitions/zora.js'
```

#### 4. Add changeset
#### 5. Add changeset

Add a `patch` changeset with the description `"Added <your chain here> chain."`.

Expand All @@ -317,7 +317,7 @@ Please enter a summary for this change
+ Added Example chain.
```

#### 5. Open your PR
#### 6. Open your PR

Now you are ready to open your Pull Request.

Expand Down
2 changes: 0 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
### Description

<!-- What is this PR solving? Write a clear description or reference the issues it solves (e.g. `fixes #123`). What other alternatives have you explored? Are there any parts you think require more attention from reviewers? -->

<!----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prune-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Prune tags
run: cd src && npm view --json | jq -r '.["viem"] | .["dist-tags"] | to_entries | .[] | select(.key != "latest") | select(.key != "main") | .key' | xargs -I % npm dist-tag rm viem %
run: cd src && npm view --json | jq -r '.["viem"] | .["dist-tags"] | to_entries | .[] | select(.key != "latest") | select(.key != "canary") | .key' | xargs -I % npm dist-tag rm viem %
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
19 changes: 12 additions & 7 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
typescript-version: ['5.3.2', 'latest']
version: ['5.3.3', '5.4.5']

steps:
- name: Clone repository
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install-dependencies

- run: bun i -d typescript@${{ matrix.typescript-version }}
- run: bun i -d typescript@${{ matrix.version }}

- name: Build contracts
shell: bash
Expand All @@ -74,10 +74,15 @@ jobs:
- name: Check types
run: bun run typecheck

- name: Test types
run: bun run test:typecheck
env:
VITE_ANVIL_BLOCK_NUMBER: ${{ vars.VITE_ANVIL_BLOCK_NUMBER }}
- name: Bench types
run: bun run typebench

# Redundant with `pnpm typecheck`
# If Vitest adds special features in the future, e.g. type coverage, can add this back!
# - name: Test types
# run: bun run test:typecheck
# env:
# VITE_ANVIL_BLOCK_NUMBER: ${{ vars.VITE_ANVIL_BLOCK_NUMBER }}

test:
name: Test
Expand Down Expand Up @@ -211,7 +216,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
typescript-version: ['5.4.2', 'latest']
typescript-version: ['5.4.5']

steps:
- name: Clone repository
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _esm
_types
*.local
.DS_Store
.attest
.eslintcache
.next
bench
Expand Down
12 changes: 12 additions & 0 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,17 @@
"path": "./src/_esm/ens/index.js",
"limit": "19 kB",
"import": "{ getEnsAvatar }"
},
{
"name": "viem/siwe",
"path": "./src/_esm/siwe/index.js",
"limit": "28 kB",
"import": "*"
},
{
"name": "viem/siwe (tree-shaking)",
"path": "./src/_esm/siwe/index.js",
"limit": "27 kB",
"import": "{ verifySiweMessage }"
}
]
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
".vercel",
"**/node_modules",
"CHANGELOG.md",
"bun.lockb",
"cache",
"test/contracts",
"test/kzg/*.json",
Expand Down
Binary file modified bun.lockb
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"test:env:vite": "cd environments/vite && bun run test",
"test:typecheck": "SKIP_GLOBAL_SETUP=true vitest --typecheck.only -c ./test/vitest.config.ts",
"test:ui": "vitest dev -c ./test/vitest.config.ts --ui",
"typebench": "tsx test/typebench.ts --benchPercentThreshold 10 --benchErrorOnThresholdExceeded",
"typecheck": "tsc --noEmit",
"vectors": "bun test vectors/**/*.test.ts",
"vectors:generate": "bun vectors/generate.ts",
"version:update": "bun scripts/updateVersion.ts"
},
"devDependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@arktype/attest": "0.7.5",
"@biomejs/biome": "^1.7.3",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.2",
Expand All @@ -63,6 +63,7 @@
"rimraf": "^4.4.1",
"simple-git-hooks": "^2.8.1",
"size-limit": "^11.1.2",
"tsx": "^4.11.0",
"typescript": "5.4.2",
"vite": "^5.0.7",
"vitest": "^1.0.4"
Expand Down
33 changes: 33 additions & 0 deletions src/actions/public/mulitcall.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { bench } from '@arktype/attest'

import {
baycContractConfig,
usdcContractConfig,
} from '../../../test/src/abis.js'
import { anvil } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { http } from '../../clients/transports/http.js'
import { multicall } from './multicall.js'

bench('multicall return type', async () => {
const client = createClient({ chain: anvil, transport: http() })
const res = multicall(client, {
allowFailure: false,
contracts: [
{
...usdcContractConfig,
functionName: 'totalSupply',
},
{
...usdcContractConfig,
functionName: 'balanceOf',
args: ['0x...'],
},
{
...baycContractConfig,
functionName: 'name',
},
],
})
return {} as typeof res
}).types([192503, 'instantiations'])
1 change: 0 additions & 1 deletion src/actions/public/multicall.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ test('MulticallParameters', async () => {
| readonly [`0x${string}`]
| readonly [`0x${string}`, `0x${string}`]
| undefined
value?: undefined
}>()
})

Expand Down
17 changes: 17 additions & 0 deletions src/actions/public/readContract.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { bench } from '@arktype/attest'

import { usdcContractConfig } from '../../../test/src/abis.js'
import { anvil } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { http } from '../../clients/transports/http.js'
import { readContract } from './readContract.js'

bench('readContract return type', async () => {
const client = createClient({ chain: anvil, transport: http() })
const res = readContract(client, {
...usdcContractConfig,
functionName: 'balanceOf',
args: ['0x...'],
})
return {} as typeof res
}).types([152288, 'instantiations'])
6 changes: 3 additions & 3 deletions src/chains/definitions/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const avalanche = /*#__PURE__*/ defineChain({
},
blockExplorers: {
default: {
name: 'SnowScan',
url: 'https://snowscan.xyz',
apiUrl: 'https://api.snowscan.xyz/api',
name: 'SnowTrace',
url: 'https://snowtrace.io',
apiUrl: 'https://api.snowtrace.io',
},
},
contracts: {
Expand Down
6 changes: 3 additions & 3 deletions src/chains/definitions/avalancheFuji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const avalancheFuji = /*#__PURE__*/ defineChain({
},
blockExplorers: {
default: {
name: 'SnowScan',
url: 'https://testnet.snowscan.xyz',
apiUrl: 'https://api-testnet.snowscan.xyz',
name: 'SnowTrace',
url: 'https://testnet.snowtrace.io',
apiUrl: 'https://api-testnet.snowtrace.io',
},
},
contracts: {
Expand Down
16 changes: 16 additions & 0 deletions src/clients/createPublicClient.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { bench } from '@arktype/attest'

import { createClient } from './createClient.js'
import { createPublicClient } from './createPublicClient.js'
import { publicActions } from './decorators/public.js'
import { http } from './transports/http.js'

bench('createPublicClient', () => {
const client = createPublicClient({ transport: http() })
return {} as typeof client
}).types([13470, 'instantiations'])

bench('createClient.extend + publicActions', () => {
const client = createClient({ transport: http() }).extend(publicActions)
return {} as typeof client
}).types([246356, 'instantiations'])
18 changes: 18 additions & 0 deletions src/clients/createTestClient.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bench } from '@arktype/attest'

import { createClient } from './createClient.js'
import { createTestClient } from './createTestClient.js'
import { testActions } from './decorators/test.js'
import { http } from './transports/http.js'

bench('createTestClient', () => {
const client = createTestClient({ mode: 'anvil', transport: http() })
return {} as typeof client
}).types([668, 'instantiations'])

bench('createClient.extend + testActions', () => {
const client = createClient({ transport: http() }).extend(
testActions({ mode: 'anvil' }),
)
return {} as typeof client
}).types([6275, 'instantiations'])
16 changes: 16 additions & 0 deletions src/clients/createWalletClient.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { bench } from '@arktype/attest'

import { createClient } from './createClient.js'
import { createWalletClient } from './createWalletClient.js'
import { walletActions } from './decorators/wallet.js'
import { http } from './transports/http.js'

bench('createWalletClient', () => {
const client = createWalletClient({ transport: http() })
return {} as typeof client
}).types([1384, 'instantiations'])

bench('createClient.extend + walletActions', () => {
const client = createClient({ transport: http() }).extend(walletActions)
return {} as typeof client
}).types([193153, 'instantiations'])
42 changes: 38 additions & 4 deletions src/experimental/eip5792/actions/writeContracts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type { AbiStateMutability, Narrow } from 'abitype'
import type { Abi, AbiStateMutability, Address, Narrow } from 'abitype'

import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { ErrorType } from '../../../errors/utils.js'
import type { Account, GetAccountParameter } from '../../../types/account.js'
import type { Chain, GetChainParameter } from '../../../types/chain.js'
import type { ContractFunctionParameters } from '../../../types/contract.js'
import type {
ContractFunctionArgs,
ContractFunctionName,
GetValue,
UnionWiden,
Widen,
} from '../../../types/contract.js'
import type { MulticallContracts } from '../../../types/multicall.js'
import {
type EncodeFunctionDataErrorType,
Expand All @@ -19,7 +25,8 @@ import {
} from './sendCalls.js'

export type WriteContractsParameters<
contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
contracts extends
readonly unknown[] = readonly WriteContractFunctionParameters[],
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined,
chainOverride extends Chain | undefined = Chain | undefined,
Expand Down Expand Up @@ -98,7 +105,7 @@ export async function writeContracts<
chainOverride
>,
): Promise<WriteContractsReturnType> {
const contracts = parameters.contracts as ContractFunctionParameters[]
const contracts = parameters.contracts as WriteContractFunctionParameters[]
const calls = contracts.map((contract) => {
const { address, abi, functionName, args, value } = contract
return {
Expand All @@ -113,3 +120,30 @@ export async function writeContracts<
})
return sendCalls(client, { ...parameters, calls } as SendCallsParameters)
}

export type WriteContractFunctionParameters<
abi extends Abi | readonly unknown[] = Abi,
mutability extends AbiStateMutability = AbiStateMutability,
functionName extends ContractFunctionName<
abi,
mutability
> = ContractFunctionName<abi, mutability>,
args extends ContractFunctionArgs<
abi,
mutability,
functionName
> = ContractFunctionArgs<abi, mutability, functionName>,
///
allFunctionNames = ContractFunctionName<abi, mutability>,
allArgs = ContractFunctionArgs<abi, mutability, functionName>,
// when `args` is inferred to `readonly []` ("inputs": []) or `never` (`abi` declared as `Abi` or not inferrable), allow `args` to be optional.
// important that both branches return same structural type
> = {
address: Address
abi: abi
functionName:
| allFunctionNames // show all options
| (functionName extends allFunctionNames ? functionName : never) // infer value
args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined
} & (readonly [] extends allArgs ? {} : { args: Widen<args> }) &
GetValue<abi, functionName>
1 change: 1 addition & 0 deletions src/experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
type WriteContractsErrorType,
type WriteContractsParameters,
type WriteContractsReturnType,
type WriteContractFunctionParameters,
writeContracts,
} from './eip5792/actions/writeContracts.js'
export {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ export {
export {
type DecodeFunctionDataErrorType,
type DecodeFunctionDataParameters,
type DecodeFunctionDataReturnType,
decodeFunctionData,
} from './utils/abi/decodeFunctionData.js'
export {
Expand Down
7 changes: 6 additions & 1 deletion src/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
},
"publish": {
"include": ["LICENSE", "README.md", "CHANGELOG.md", "**/*.ts"],
"exclude": ["**/*.bench.ts", "**/*.test.ts", "**/*.test-d.ts"]
"exclude": [
"**/*.bench.ts",
"**/*.bench-d.ts",
"**/*.test.ts",
"**/*.test-d.ts"
]
}
}
Loading

0 comments on commit 389f0ae

Please sign in to comment.