@gibs/common 1.10.1 → 1.13.0
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/LICENSE +15 -0
- package/dist/assert.d.ts +18 -0
- package/dist/assert.js +27 -0
- package/dist/{src/cache.js → cache.js} +1 -1
- package/dist/client.d.ts +48 -0
- package/dist/client.js +164 -0
- package/dist/erc20.d.ts +20 -0
- package/dist/{src/erc20.js → erc20.js} +10 -2
- package/dist/{src/index.d.ts → index.d.ts} +5 -4
- package/dist/{src/index.js → index.js} +5 -4
- package/dist/multicall.d.ts +56 -0
- package/dist/multicall.js +213 -0
- package/dist/rpcPacer.d.ts +88 -0
- package/dist/rpcPacer.js +153 -0
- package/dist/{src/serialize.d.ts → serialize.d.ts} +9 -2
- package/dist/serialize.js +42 -0
- package/dist/{src/types.d.ts → types.d.ts} +1 -1
- package/package.json +90 -20
- package/dist/src/client.d.ts +0 -30
- package/dist/src/client.js +0 -55
- package/dist/src/erc20.d.ts +0 -13
- package/dist/src/multicall.d.ts +0 -10
- package/dist/src/multicall.js +0 -44
- package/dist/src/serialize.js +0 -22
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/cache.ts +0 -48
- package/src/client.ts +0 -73
- package/src/erc20.ts +0 -43
- package/src/index.ts +0 -6
- package/src/multicall.ts +0 -68
- package/src/serialize.ts +0 -31
- package/src/types.ts +0 -13
- package/tsconfig.json +0 -16
- /package/dist/{src/cache.d.ts → cache.d.ts} +0 -0
- /package/dist/{src/types.js → types.js} +0 -0
package/src/erc20.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Chain,
|
|
3
|
-
type PublicClient,
|
|
4
|
-
type Hex,
|
|
5
|
-
type Abi,
|
|
6
|
-
erc20Abi,
|
|
7
|
-
erc20Abi_bytes32,
|
|
8
|
-
getAddress,
|
|
9
|
-
} from 'viem'
|
|
10
|
-
import _ from 'lodash'
|
|
11
|
-
import type { Erc20Metadata } from './types.js'
|
|
12
|
-
import { multicallRead } from './multicall.js'
|
|
13
|
-
|
|
14
|
-
/** The erc20 metadata calls */
|
|
15
|
-
export const erc20MetadataCalls = [
|
|
16
|
-
{ functionName: 'name' },
|
|
17
|
-
{ functionName: 'symbol' },
|
|
18
|
-
{ functionName: 'decimals' },
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
/** The multicall for the erc20 metadata */
|
|
22
|
-
export const multicallErc20 = _.memoize(
|
|
23
|
-
async ({ client, target, chain }: { client: PublicClient; target: Hex; chain: Chain }) => {
|
|
24
|
-
const options = {
|
|
25
|
-
chain: chain,
|
|
26
|
-
client: client,
|
|
27
|
-
abi: erc20Abi,
|
|
28
|
-
target,
|
|
29
|
-
calls: erc20MetadataCalls,
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
return await multicallRead<Erc20Metadata>(options)
|
|
33
|
-
} catch {
|
|
34
|
-
return await multicallRead<Erc20Metadata>({
|
|
35
|
-
...options,
|
|
36
|
-
abi: erc20Abi_bytes32,
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
({ target, chain }) => {
|
|
41
|
-
return !target ? chain.id : getAddress(target, chain.id)
|
|
42
|
-
},
|
|
43
|
-
)
|
package/src/index.ts
DELETED
package/src/multicall.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Chain,
|
|
3
|
-
type PublicClient,
|
|
4
|
-
type Hex,
|
|
5
|
-
type Abi,
|
|
6
|
-
getContract,
|
|
7
|
-
encodeFunctionData,
|
|
8
|
-
decodeFunctionResult,
|
|
9
|
-
multicall3Abi,
|
|
10
|
-
} from 'viem'
|
|
11
|
-
import _ from 'lodash'
|
|
12
|
-
import type { Call } from './types.js'
|
|
13
|
-
|
|
14
|
-
/** The multicall for the given chain, client, abi, calls, and target */
|
|
15
|
-
export const multicallRead = async <T>({
|
|
16
|
-
chain,
|
|
17
|
-
client,
|
|
18
|
-
abi,
|
|
19
|
-
calls,
|
|
20
|
-
target,
|
|
21
|
-
}: {
|
|
22
|
-
chain: Chain
|
|
23
|
-
client: PublicClient
|
|
24
|
-
abi: Abi
|
|
25
|
-
calls: Call[]
|
|
26
|
-
target?: Hex
|
|
27
|
-
}) => {
|
|
28
|
-
const multicall = getContract({
|
|
29
|
-
abi: multicall3Abi,
|
|
30
|
-
address: chain.contracts!.multicall3!.address!,
|
|
31
|
-
// this seems like a bug in viem, it should be able to infer the type of the client
|
|
32
|
-
client: client as any,
|
|
33
|
-
}) as any
|
|
34
|
-
const arg = calls.map((call) => ({
|
|
35
|
-
callData: encodeFunctionData({
|
|
36
|
-
abi: call.abi || abi,
|
|
37
|
-
functionName: call.functionName,
|
|
38
|
-
// this seems like a bug in viem, it should be able to infer the type of the args
|
|
39
|
-
args: (call.args || []) as any,
|
|
40
|
-
}),
|
|
41
|
-
allowFailure: call.allowFailure || false,
|
|
42
|
-
target: (call.target || target) as Hex,
|
|
43
|
-
}))
|
|
44
|
-
let reads: null | Awaited<ReturnType<typeof multicall.read.aggregate3>> = null
|
|
45
|
-
try {
|
|
46
|
-
reads = await multicall.read.aggregate3([arg])
|
|
47
|
-
if (!reads) throw reads
|
|
48
|
-
const r = reads
|
|
49
|
-
return calls.map((call, i) =>
|
|
50
|
-
call.allowFailure
|
|
51
|
-
? r[i].success
|
|
52
|
-
? decodeFunctionResult({
|
|
53
|
-
abi: call.abi || abi,
|
|
54
|
-
functionName: call.functionName,
|
|
55
|
-
data: r[i].returnData,
|
|
56
|
-
})
|
|
57
|
-
: r[i].returnData
|
|
58
|
-
: decodeFunctionResult({
|
|
59
|
-
abi: call.abi || abi,
|
|
60
|
-
functionName: call.functionName,
|
|
61
|
-
data: r[i].returnData,
|
|
62
|
-
}),
|
|
63
|
-
) as T
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.error(client.chain?.id, target, calls, reads)
|
|
66
|
-
throw err
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/serialize.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const BIGINT_TYPE = 'bigint' as const
|
|
3
|
-
type SerializedBigInt = {
|
|
4
|
-
__type__: typeof BIGINT_TYPE
|
|
5
|
-
value: string
|
|
6
|
-
}
|
|
7
|
-
/** The json any stringify for the given key and value */
|
|
8
|
-
export const jsonAnyStringify = (key: string, value: unknown) => {
|
|
9
|
-
if (typeof value === BIGINT_TYPE) {
|
|
10
|
-
return {
|
|
11
|
-
__type__: BIGINT_TYPE,
|
|
12
|
-
value: (value as bigint).toString(),
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return value
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** The is serialized big int for the given value */
|
|
19
|
-
export const isSerializedBigInt = (value: unknown): value is SerializedBigInt => {
|
|
20
|
-
return (
|
|
21
|
-
!!value && typeof value === 'object' && (value as SerializedBigInt).__type__ === BIGINT_TYPE
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** The json any parse for the given key and value */
|
|
26
|
-
export const jsonAnyParse = (_key: string, value: unknown) => {
|
|
27
|
-
if (isSerializedBigInt(value)) {
|
|
28
|
-
return BigInt(value.value)
|
|
29
|
-
}
|
|
30
|
-
return value
|
|
31
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Abi, Hex } from "viem"
|
|
2
|
-
|
|
3
|
-
/** The inputs for a multicall read */
|
|
4
|
-
export type Call = {
|
|
5
|
-
allowFailure?: boolean
|
|
6
|
-
functionName: string
|
|
7
|
-
target?: Hex
|
|
8
|
-
abi?: Abi
|
|
9
|
-
args?: (bigint | Hex | Hex[] | bigint[] | string | string[])[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** The erc20 metadata */
|
|
13
|
-
export type Erc20Metadata = [string, string, number]
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "NodeNext",
|
|
6
|
-
"composite": true,
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"isolatedModules": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"moduleDetection": "force",
|
|
13
|
-
"moduleResolution": "nodenext"
|
|
14
|
-
},
|
|
15
|
-
"include": ["src/**/*.ts", "src/**/*.js"]
|
|
16
|
-
}
|
|
File without changes
|
|
File without changes
|