@bgd-labs/toolbox 0.0.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.
@@ -0,0 +1,88 @@
1
+ import { Address, Hex } from 'viem';
2
+
3
+ /**
4
+ * In solidity it is a quite common practice to encode bit variables in bitmaps opposed to bool structs.
5
+ * The reason for this is that solidity will pack one boolean per byte, while with a bitmap, one can pack one bit.. per bit.
6
+ * These utilities help with extracting the indexes of a given bitmap.
7
+ */
8
+ /**
9
+ * Decodes a bitmap as an array of indexes.
10
+ * @param bitmap The bitmap
11
+ * @returns an array of indexes
12
+ */
13
+ declare function bitmapToIndexes(bitmap: bigint): number[];
14
+ /**
15
+ * Returns the selected bits of a uint256 as bigint
16
+ * @param uint256
17
+ * @param startBit
18
+ * @param endBit
19
+ * @returns
20
+ */
21
+ declare function getBits(uint256: bigint, startBit: bigint, _endBit: bigint): bigint;
22
+
23
+ /**
24
+ * The userConfiguration on aave is stored as an alteranting bitmap.
25
+ * The least significant bit starts with borrowing on reserve 0
26
+ * In practice this means that the following bitmap b'1011 would mean a user
27
+ * is borrowing(bit 0) reserve 0, and supplies(bit 1,3) collateral on reserve 0 and 1
28
+ * @param userConfiguration bitmap
29
+ */
30
+ declare function decodeUserConfiguration(userConfiguration: bigint): {
31
+ borrowedAssetIds: number[];
32
+ collateralAssetIds: number[];
33
+ };
34
+
35
+ type ExplorerConfig = {
36
+ api: string;
37
+ explorer: string;
38
+ };
39
+ /**
40
+ * Fetches what we consider the "best" explorer for a given chain.
41
+ * For our tooling we have a opinionated priorization for explorers:
42
+ * 1. Etherscan
43
+ * 2. Routescan
44
+ * 3. Blockscout and others
45
+ * @param chainId Id of the chain to fetch the explorer for
46
+ */
47
+ declare function getExplorer(chainId: number): ExplorerConfig;
48
+ type GetSourceCodeParams = {
49
+ chainId: number;
50
+ address: Address;
51
+ apiUrl?: string;
52
+ apiKey?: string;
53
+ };
54
+ declare function getSourceCode(params: GetSourceCodeParams): Promise<{
55
+ message: string;
56
+ result: {
57
+ ABI: any;
58
+ CompilerVersion: string;
59
+ ConstructorArguments: Hex;
60
+ ContractName: string;
61
+ EVMVersion: string;
62
+ Implementation: Address;
63
+ Library: string;
64
+ LicenseType: string;
65
+ OptimizationUsed: string;
66
+ Proxy: string;
67
+ Runs: string;
68
+ SimilarMatch: string;
69
+ SourceCode: string;
70
+ }[];
71
+ status: string;
72
+ }>;
73
+ declare function parseApiSourceCode(sourceCode: string): {
74
+ language: string;
75
+ libraries: any;
76
+ settings: {
77
+ evmVersion: string;
78
+ optimizer: {
79
+ enabled: boolean;
80
+ runs: number;
81
+ };
82
+ };
83
+ sources: Record<string, {
84
+ content: string;
85
+ }>;
86
+ };
87
+
88
+ export { type ExplorerConfig, bitmapToIndexes, decodeUserConfiguration, getBits, getExplorer, getSourceCode, parseApiSourceCode };
@@ -0,0 +1,88 @@
1
+ import { Address, Hex } from 'viem';
2
+
3
+ /**
4
+ * In solidity it is a quite common practice to encode bit variables in bitmaps opposed to bool structs.
5
+ * The reason for this is that solidity will pack one boolean per byte, while with a bitmap, one can pack one bit.. per bit.
6
+ * These utilities help with extracting the indexes of a given bitmap.
7
+ */
8
+ /**
9
+ * Decodes a bitmap as an array of indexes.
10
+ * @param bitmap The bitmap
11
+ * @returns an array of indexes
12
+ */
13
+ declare function bitmapToIndexes(bitmap: bigint): number[];
14
+ /**
15
+ * Returns the selected bits of a uint256 as bigint
16
+ * @param uint256
17
+ * @param startBit
18
+ * @param endBit
19
+ * @returns
20
+ */
21
+ declare function getBits(uint256: bigint, startBit: bigint, _endBit: bigint): bigint;
22
+
23
+ /**
24
+ * The userConfiguration on aave is stored as an alteranting bitmap.
25
+ * The least significant bit starts with borrowing on reserve 0
26
+ * In practice this means that the following bitmap b'1011 would mean a user
27
+ * is borrowing(bit 0) reserve 0, and supplies(bit 1,3) collateral on reserve 0 and 1
28
+ * @param userConfiguration bitmap
29
+ */
30
+ declare function decodeUserConfiguration(userConfiguration: bigint): {
31
+ borrowedAssetIds: number[];
32
+ collateralAssetIds: number[];
33
+ };
34
+
35
+ type ExplorerConfig = {
36
+ api: string;
37
+ explorer: string;
38
+ };
39
+ /**
40
+ * Fetches what we consider the "best" explorer for a given chain.
41
+ * For our tooling we have a opinionated priorization for explorers:
42
+ * 1. Etherscan
43
+ * 2. Routescan
44
+ * 3. Blockscout and others
45
+ * @param chainId Id of the chain to fetch the explorer for
46
+ */
47
+ declare function getExplorer(chainId: number): ExplorerConfig;
48
+ type GetSourceCodeParams = {
49
+ chainId: number;
50
+ address: Address;
51
+ apiUrl?: string;
52
+ apiKey?: string;
53
+ };
54
+ declare function getSourceCode(params: GetSourceCodeParams): Promise<{
55
+ message: string;
56
+ result: {
57
+ ABI: any;
58
+ CompilerVersion: string;
59
+ ConstructorArguments: Hex;
60
+ ContractName: string;
61
+ EVMVersion: string;
62
+ Implementation: Address;
63
+ Library: string;
64
+ LicenseType: string;
65
+ OptimizationUsed: string;
66
+ Proxy: string;
67
+ Runs: string;
68
+ SimilarMatch: string;
69
+ SourceCode: string;
70
+ }[];
71
+ status: string;
72
+ }>;
73
+ declare function parseApiSourceCode(sourceCode: string): {
74
+ language: string;
75
+ libraries: any;
76
+ settings: {
77
+ evmVersion: string;
78
+ optimizer: {
79
+ enabled: boolean;
80
+ runs: number;
81
+ };
82
+ };
83
+ sources: Record<string, {
84
+ content: string;
85
+ }>;
86
+ };
87
+
88
+ export { type ExplorerConfig, bitmapToIndexes, decodeUserConfiguration, getBits, getExplorer, getSourceCode, parseApiSourceCode };