Skip to content

Commit

Permalink
docs: configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Sep 6, 2022
1 parent ae667a6 commit dabf83d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-bobcats-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'abitype': patch
---

Expose configuration options
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ ABI canonical [types](https://docs.soliditylang.org/en/latest/abi-spec.html#json
import { AbiType } from 'abitype'
```

### Solidity
### Solidity types

[Solidity types](https://docs.soliditylang.org/en/latest/abi-spec.html#types) as template strings

```ts
import {
Expand All @@ -296,6 +298,25 @@ import {
} from 'abitype'
```

## Configuration

AbiType tries to strike a balance between type exhaustiveness and speed with sensible defaults. In some cases, you might want to tune your configuration (e.g. fixed array length). To do this, the following configuration options are available:

```ts
type FixedArrayLowerBound = 1
type FixedArrayUpperBound = 5
type Fixed2DArrayLowerBound = 1
type Fixed2DArrayUpperBound = 5
```
To change a configuration option, use a module declaration:
```ts
declare module 'abitype/dist/config.d' {
type FixedArrayUpperBound = 10
}
```

## Support

If you find AbiType useful, please consider supporting development. Thank you 🙏
Expand Down
9 changes: 1 addition & 8 deletions src/abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Range } from './types'
import './config'

export type Address = `0x${string}`

Expand Down Expand Up @@ -32,14 +33,6 @@ export type SolidityInt = `${'u' | ''}int${MBits}`
// | `${'u' | ''}fixed`
// | `${'u' | ''}fixed${MBits}x${Range<1, 20>[number]}`

declare global {
type FixedArrayLowerBound = 1
type FixedArrayUpperBound = 5

type Fixed2DArrayLowerBound = 1
type Fixed2DArrayUpperBound = 5
}

export type SolidityFixedArrayRange = Range<
FixedArrayLowerBound,
FixedArrayUpperBound
Expand Down
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
type FixedArrayLowerBound = 1
type FixedArrayUpperBound = 5

type Fixed2DArrayLowerBound = 1
type Fixed2DArrayUpperBound = 5
}

export {}

0 comments on commit dabf83d

Please sign in to comment.