@gibs/common 1.13.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +70 -0
- package/package.json +3 -2
package/llms.txt
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @gibs/common
|
|
2
|
+
|
|
3
|
+
> Low-level blockchain helpers shared across the Gibs Finance packages:
|
|
4
|
+
> cached viem clients with fallback URLs, Multicall3 batching, ERC-20
|
|
5
|
+
> metadata reads, memoizing caches and bigint-safe JSON. Nothing in it is
|
|
6
|
+
> specific to the bridge.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
- Run `npm install @gibs/common viem`.
|
|
11
|
+
- The package is ESM only. Use `import`, not `require`.
|
|
12
|
+
- It needs Node 20 or later.
|
|
13
|
+
- viem is a peer dependency. The range is `>=2.37.0 <3`.
|
|
14
|
+
- Version note: 1.12.0 and older on npm are broken. 1.13.0 is the first usable version.
|
|
15
|
+
|
|
16
|
+
## Entry points
|
|
17
|
+
|
|
18
|
+
- `@gibs/common`: everything below.
|
|
19
|
+
- `@gibs/common/client`: `clientFromChain({ chain, urls })`, `chainKey`, `clientCache`.
|
|
20
|
+
- `@gibs/common/erc20`: `multicallErc20`, `erc20MetadataCalls`.
|
|
21
|
+
- `@gibs/common/multicall`: `multicallRead`.
|
|
22
|
+
- `@gibs/common/cache`: `maxMemoize`, `ttlMemoizeSingle`.
|
|
23
|
+
- `@gibs/common/serialize`: `jsonAnyStringify`, `jsonAnyParse`, `isSerializedBigInt`.
|
|
24
|
+
- `@gibs/common/types`: `Call`, `Erc20Metadata`.
|
|
25
|
+
|
|
26
|
+
## Read a token's name, symbol and decimals
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { clientFromChain } from '@gibs/common/client'
|
|
30
|
+
import { multicallErc20 } from '@gibs/common/erc20'
|
|
31
|
+
import { mainnet } from 'viem/chains'
|
|
32
|
+
|
|
33
|
+
const client = clientFromChain({ chain: mainnet, urls: ['https://ethereum-rpc.publicnode.com'] })
|
|
34
|
+
const [name, symbol, decimals] = await multicallErc20({
|
|
35
|
+
client,
|
|
36
|
+
chain: mainnet,
|
|
37
|
+
target: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Keep a bigint through JSON
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { jsonAnyParse, jsonAnyStringify } from '@gibs/common/serialize'
|
|
45
|
+
|
|
46
|
+
const text = JSON.stringify({ balance: 10n ** 18n }, jsonAnyStringify)
|
|
47
|
+
const restored = JSON.parse(text, jsonAnyParse)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Memoize
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { maxMemoize, ttlMemoizeSingle } from '@gibs/common/cache'
|
|
54
|
+
|
|
55
|
+
const square = maxMemoize((x: number) => x * x, 100)
|
|
56
|
+
const price = ttlMemoizeSingle(async (symbol: string) => symbol, 30_000)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Rules
|
|
60
|
+
|
|
61
|
+
- `multicallRead` and `multicallErc20` need a chain object that carries a Multicall3 deployment. A chain without one fails.
|
|
62
|
+
- `clientFromChain` caches by chain id and URL list. The same URLs in a different order make a different client.
|
|
63
|
+
- `@gibs/common/client` takes a viem chain and URLs. `@gibs/bridge-client/client` takes a chain id. They are different functions.
|
|
64
|
+
- `multicallErc20` memoizes its answers. A repeat call with the same inputs does not read the chain again.
|
|
65
|
+
- The `@gibs/common/test-utils/fuzz` subpath is for tests inside the source repository. It is not in the npm package.
|
|
66
|
+
|
|
67
|
+
## Links
|
|
68
|
+
|
|
69
|
+
- [README](https://github.com/gibsfinance/bridge/blob/staging/packages/common/README.md)
|
|
70
|
+
- [Gibs Finance llms.txt](https://next.gibs.finance/llms.txt): the whole platform.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gibs/common",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Low-level blockchain helpers shared across the Gibs Finance packages: caching, multicall, and serialization.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"!dist/tsconfig.tsbuildinfo",
|
|
74
74
|
"!dist/**/*.test-d.*",
|
|
75
75
|
"!dist/test-utils",
|
|
76
|
-
"LICENSE"
|
|
76
|
+
"LICENSE",
|
|
77
|
+
"llms.txt"
|
|
77
78
|
],
|
|
78
79
|
"scripts": {
|
|
79
80
|
"prepublishOnly": "npx tsc",
|