@gibs/common 1.7.1 → 1.7.3
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/README.md +597 -7
- package/dist/src/client.d.ts +14 -0
- package/dist/src/client.js +14 -0
- package/dist/src/erc20.d.ts +2 -0
- package/dist/src/erc20.js +2 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/multicall.d.ts +1 -0
- package/dist/src/multicall.js +1 -0
- package/dist/src/serialize.d.ts +3 -0
- package/dist/src/serialize.js +3 -0
- package/dist/src/types.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/client.ts +14 -0
- package/src/erc20.ts +2 -0
- package/src/index.ts +1 -0
- package/src/multicall.ts +1 -0
- package/src/serialize.ts +3 -0
- package/src/types.ts +3 -1
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Chain, type PublicClient, createPublicClient, fallback, http, webSocket } from "viem"
|
|
2
2
|
|
|
3
|
+
/** The default batch config for the client */
|
|
3
4
|
export const defaultBatchConfig = {
|
|
4
5
|
batch: {
|
|
5
6
|
wait: 10,
|
|
@@ -7,15 +8,28 @@ export const defaultBatchConfig = {
|
|
|
7
8
|
},
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Returns the chain key for the given chain id and urls
|
|
13
|
+
* @param chainId - the chain id
|
|
14
|
+
* @param urls - the urls
|
|
15
|
+
* @returns the chain key
|
|
16
|
+
*/
|
|
10
17
|
export const chainKey = (chainId: number, urls: string[]) => {
|
|
11
18
|
return `${chainId},${urls.join(',')}`.toLowerCase()
|
|
12
19
|
}
|
|
13
20
|
|
|
21
|
+
/** The client cache for the given chain id */
|
|
14
22
|
export const clientCache = new Map<number, {
|
|
15
23
|
key: string
|
|
16
24
|
client: PublicClient
|
|
17
25
|
}>()
|
|
18
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Returns the client for the given chain and urls
|
|
29
|
+
* @param chain - the chain
|
|
30
|
+
* @param urls - the urls
|
|
31
|
+
* @returns the client
|
|
32
|
+
*/
|
|
19
33
|
export const clientFromChain = ({
|
|
20
34
|
chain,
|
|
21
35
|
urls,
|
package/src/erc20.ts
CHANGED
|
@@ -11,12 +11,14 @@ import _ from 'lodash'
|
|
|
11
11
|
import type { Erc20Metadata } from './types.js'
|
|
12
12
|
import { multicallRead } from './multicall.js'
|
|
13
13
|
|
|
14
|
+
/** The erc20 metadata calls */
|
|
14
15
|
export const erc20MetadataCalls = [
|
|
15
16
|
{ functionName: 'name' },
|
|
16
17
|
{ functionName: 'symbol' },
|
|
17
18
|
{ functionName: 'decimals' },
|
|
18
19
|
]
|
|
19
20
|
|
|
21
|
+
/** The multicall for the erc20 metadata */
|
|
20
22
|
export const multicallErc20 = _.memoize(
|
|
21
23
|
async ({ client, target, chain }: { client: PublicClient; target: Hex; chain: Chain }) => {
|
|
22
24
|
const options = {
|
package/src/index.ts
CHANGED
package/src/multicall.ts
CHANGED
package/src/serialize.ts
CHANGED
|
@@ -4,6 +4,7 @@ type SerializedBigInt = {
|
|
|
4
4
|
__type__: typeof BIGINT_TYPE
|
|
5
5
|
value: string
|
|
6
6
|
}
|
|
7
|
+
/** The json any stringify for the given key and value */
|
|
7
8
|
export const jsonAnyStringify = (key: string, value: unknown) => {
|
|
8
9
|
if (typeof value === BIGINT_TYPE) {
|
|
9
10
|
return {
|
|
@@ -14,12 +15,14 @@ export const jsonAnyStringify = (key: string, value: unknown) => {
|
|
|
14
15
|
return value
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/** The is serialized big int for the given value */
|
|
17
19
|
export const isSerializedBigInt = (value: unknown): value is SerializedBigInt => {
|
|
18
20
|
return (
|
|
19
21
|
!!value && typeof value === 'object' && (value as SerializedBigInt).__type__ === BIGINT_TYPE
|
|
20
22
|
)
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
/** The json any parse for the given key and value */
|
|
23
26
|
export const jsonAnyParse = (_key: string, value: unknown) => {
|
|
24
27
|
if (isSerializedBigInt(value)) {
|
|
25
28
|
return BigInt(value.value)
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Abi, Hex } from "viem"
|
|
2
2
|
|
|
3
|
+
/** The inputs for a multicall read */
|
|
3
4
|
export type Call = {
|
|
4
5
|
allowFailure?: boolean
|
|
5
6
|
functionName: string
|
|
@@ -7,5 +8,6 @@ export type Call = {
|
|
|
7
8
|
abi?: Abi
|
|
8
9
|
args?: (bigint | Hex | Hex[] | bigint[] | string | string[])[]
|
|
9
10
|
}
|
|
10
|
-
export type Erc20Metadata = [string, string, number]
|
|
11
11
|
|
|
12
|
+
/** The erc20 metadata */
|
|
13
|
+
export type Erc20Metadata = [string, string, number]
|