@berachain/berajs 0.1.0-alpha.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 +21 -0
- package/README.md +86 -0
- package/dist/BeraError-CfcNTfpH.d.ts +69 -0
- package/dist/BexStatusProvider-nS3NcdxI.d.ts +70 -0
- package/dist/RequestError-CtJLUaAc.d.ts +57 -0
- package/dist/abi/index.d.ts +26765 -0
- package/dist/abi/index.mjs +1 -0
- package/dist/actions/index.d.ts +1649 -0
- package/dist/actions/index.mjs +1 -0
- package/dist/aggregatorsRouter-Cny4B_MB.d.ts +593 -0
- package/dist/chunk-4IBBLGNS.mjs +1 -0
- package/dist/chunk-5GPS724E.mjs +1 -0
- package/dist/chunk-5UFI7X4U.mjs +1 -0
- package/dist/chunk-AHAZC5K3.mjs +1 -0
- package/dist/chunk-JQDPAEK2.mjs +2 -0
- package/dist/chunk-K4NZIO2Z.mjs +1 -0
- package/dist/chunk-MTBICGRP.mjs +1 -0
- package/dist/chunk-RNESAHY2.mjs +3 -0
- package/dist/chunk-SMZ3PG6A.mjs +1 -0
- package/dist/chunk-XX77QPIR.mjs +1 -0
- package/dist/chunk-YKNKCICU.mjs +1 -0
- package/dist/contexts/index.d.ts +81 -0
- package/dist/contexts/index.mjs +1 -0
- package/dist/defaultFlags-V-tJs2K8.d.ts +10 -0
- package/dist/dex-BD7Bq3pJ.d.ts +562 -0
- package/dist/dex-DreiokgL.d.ts +562 -0
- package/dist/enum/index.d.ts +31 -0
- package/dist/enum/index.mjs +1 -0
- package/dist/errors/index.d.ts +204 -0
- package/dist/errors/index.mjs +1 -0
- package/dist/getValidatorQueuedOperatorAddress--AXNo9IY.d.ts +440 -0
- package/dist/getValidatorQueuedOperatorAddress-DK2Xv19c.d.ts +440 -0
- package/dist/hooks/index.d.ts +1703 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/polling-BKnyavLI.d.ts +8 -0
- package/dist/pythWrapper-CBjsmmsK.d.ts +1958 -0
- package/dist/staking-Cggi38So.d.ts +246 -0
- package/dist/staking-DYbVFigB.d.ts +246 -0
- package/dist/txnEnum-BQKDfaeH.d.ts +81 -0
- package/dist/txnEnum-Diichv9Z.d.ts +80 -0
- package/dist/types/index.d.ts +56 -0
- package/dist/types/index.mjs +1 -0
- package/dist/useHoneySwapState-CW49RVci.d.ts +32 -0
- package/dist/useHoneySwapState-Ci8_c2bT.d.ts +32 -0
- package/dist/utils/index.d.ts +349 -0
- package/dist/utils/index.mjs +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Berachain Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Berajs
|
|
2
|
+
|
|
3
|
+
Berajs is a TypeScript interface for interacting with Berachain PoL logic and core Dapps. Built on top of the [wagmi v2](https://wagmi.sh/) and [viem](https://viem.sh/) libraries, BeraJs provides a library capable of plugging into your existing [wevm](https://wevm.dev/) projects. Berajs
|
|
4
|
+
provides a suite of React Hooks using [swr](https://swr.vercel.app/) and a suite of typescript functions, called actions.
|
|
5
|
+
|
|
6
|
+
Berajs is documented [here]("")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
| Script | Description |
|
|
12
|
+
| ------------------------ | -------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `pnpm build` | Builds the package |
|
|
14
|
+
| `pnpm test` | Runs tests |
|
|
15
|
+
| `pnpm clean` | Removes build and nod_modules |
|
|
16
|
+
| `pnpm dev` | Builds in watch mode (rebuilds on changes) |
|
|
17
|
+
| `pnpm lint` | Runs linting |
|
|
18
|
+
| `pnpm lint:fix` | Runs linting and applies fixes |
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Guidelines
|
|
22
|
+
|
|
23
|
+
In order for this package to be chain and config agnostic, every function should ideally follow a patter that lets
|
|
24
|
+
consumers of the SDK override any argument. This aims to make the SDK more scalable and more ergonomic to adapt for new chain or testnet
|
|
25
|
+
environment. However, getters should always default their arguments to the config exported by `@berachain/config/internal`. Hooks that consume
|
|
26
|
+
these function might eventually override config or chain based on the app state.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { chainConfigs, defaultChainId } from "@berachain/config/internal";
|
|
30
|
+
import { Address, PublicClient } from "viem";
|
|
31
|
+
import { pythAbi } from "~/abi/pyth/pyth";
|
|
32
|
+
|
|
33
|
+
export async function getPythUpdateFee({
|
|
34
|
+
client,
|
|
35
|
+
priceFeedId,
|
|
36
|
+
}: {
|
|
37
|
+
client: PublicClient;
|
|
38
|
+
priceFeedId: Address[];
|
|
39
|
+
}) {
|
|
40
|
+
|
|
41
|
+
const result = await client.readContract({
|
|
42
|
+
// ❌ this forces the function to read from an hardcoded contracts
|
|
43
|
+
address: config.external.pyth,
|
|
44
|
+
abi: pythAbi,
|
|
45
|
+
functionName: "getUpdateFee",
|
|
46
|
+
args: [priceFeedId],
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
import { chainConfigs, defaultChainId } from "@berachain/config/internal";
|
|
53
|
+
import { Address, PublicClient } from "viem";
|
|
54
|
+
import { pythAbi } from "~/abi/pyth/pyth";
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export async function getPythUpdateFee({
|
|
58
|
+
client,
|
|
59
|
+
priceFeedId,
|
|
60
|
+
}: {
|
|
61
|
+
client: PublicClient;
|
|
62
|
+
priceFeedId: Address[];
|
|
63
|
+
/**
|
|
64
|
+
* Address of pyth contract
|
|
65
|
+
*
|
|
66
|
+
* @default `chainConfigs[chainId].external.pyth`
|
|
67
|
+
*/
|
|
68
|
+
pythAddress?: Address;
|
|
69
|
+
} & BeraJS.BaseFunctionArgs) {
|
|
70
|
+
try {
|
|
71
|
+
const result = await client.readContract({
|
|
72
|
+
// ✅ this defaults to
|
|
73
|
+
address: pythAddress,
|
|
74
|
+
abi: pythAbi,
|
|
75
|
+
functionName: "getUpdateFee",
|
|
76
|
+
args: [priceFeedId],
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error("getPythUpdateFee", e);
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SeverityLevel } from '@sentry/nextjs';
|
|
2
|
+
import { Abi } from 'viem';
|
|
3
|
+
|
|
4
|
+
interface IBeraErrorArgs {
|
|
5
|
+
message?: string;
|
|
6
|
+
displayMessage?: string;
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
reason?: string;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
/**
|
|
11
|
+
* The level of the error to be used for Sentry.
|
|
12
|
+
*/
|
|
13
|
+
level?: SeverityLevel;
|
|
14
|
+
tags?: {
|
|
15
|
+
[key in TagsKey]?: Primitive;
|
|
16
|
+
};
|
|
17
|
+
extra?: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Optional ABI to be used to parse the error.
|
|
20
|
+
*/
|
|
21
|
+
abi?: Abi;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Copy pasted from sentry types
|
|
25
|
+
*/
|
|
26
|
+
type Primitive = number | string | boolean | bigint | symbol | null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* An helper type to make sure we only use the allowed tags. Sync this with docs/errors.md
|
|
29
|
+
*/
|
|
30
|
+
type TagsKey = "wallet.chain" | "wallet.connector" | "wallet.address" | "error.reason" | "operation.type" | "operation.key" | "operation.txn.functionName" | "operation.txn.to" | "operation.txn.status" | "operation.source.url" | "operation.source.name" | "operation.source.queryName" | "operation.source.type";
|
|
31
|
+
/**
|
|
32
|
+
* This is a generic error class that can be used to handle errors in the SDK.
|
|
33
|
+
*/
|
|
34
|
+
declare class BeraError extends Error {
|
|
35
|
+
/**
|
|
36
|
+
* A human-readable message that can be displayed to end user.
|
|
37
|
+
*
|
|
38
|
+
* In berachain dapps, this is shown in the error pop-up.
|
|
39
|
+
*/
|
|
40
|
+
displayMessage: string;
|
|
41
|
+
/**
|
|
42
|
+
* The cause of the error.
|
|
43
|
+
*
|
|
44
|
+
* This is typically the error that was thrown.
|
|
45
|
+
*/
|
|
46
|
+
cause: unknown;
|
|
47
|
+
/**
|
|
48
|
+
* The chain id of the error.
|
|
49
|
+
*/
|
|
50
|
+
chainId?: number;
|
|
51
|
+
/**
|
|
52
|
+
* The code for the reason for the error.
|
|
53
|
+
*
|
|
54
|
+
* This is typically the error code can be found in the errorMap.ts file. I.e. NotEnoughBalance or BAL#508
|
|
55
|
+
*/
|
|
56
|
+
reason: string | null;
|
|
57
|
+
private _tags;
|
|
58
|
+
set tags(tags: {
|
|
59
|
+
[key: string | TagsKey]: Primitive;
|
|
60
|
+
});
|
|
61
|
+
get tags(): {
|
|
62
|
+
[key: string | TagsKey]: Primitive;
|
|
63
|
+
};
|
|
64
|
+
level: SeverityLevel;
|
|
65
|
+
extra: Record<string, unknown>;
|
|
66
|
+
constructor({ message: m, displayMessage: dm, cause, reason, level, abi, tags, chainId, }: IBeraErrorArgs);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { BeraError as B, type IBeraErrorArgs as I };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
4
|
+
import { Hex } from 'viem';
|
|
5
|
+
import { EdgeConfigSchema } from '@berachain/config/internal/edge-config';
|
|
6
|
+
|
|
7
|
+
type FactoryStatus = {
|
|
8
|
+
/**
|
|
9
|
+
* If the composable stable factory is enabled
|
|
10
|
+
*/
|
|
11
|
+
composableStable: "paused" | "enabled";
|
|
12
|
+
/**
|
|
13
|
+
* If the weighted factory is enabled
|
|
14
|
+
*/
|
|
15
|
+
weighted: "paused" | "enabled";
|
|
16
|
+
};
|
|
17
|
+
interface BexStatusProviderProps {
|
|
18
|
+
isVaultPaused: boolean;
|
|
19
|
+
pool?: {
|
|
20
|
+
id: Hex;
|
|
21
|
+
isInRecoveryMode: boolean;
|
|
22
|
+
isPaused: boolean;
|
|
23
|
+
};
|
|
24
|
+
factories: FactoryStatus;
|
|
25
|
+
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
26
|
+
}
|
|
27
|
+
declare const BexStateContext: react.Context<{
|
|
28
|
+
protocol: {
|
|
29
|
+
isPaused: boolean;
|
|
30
|
+
factories: FactoryStatus & {
|
|
31
|
+
allPaused: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
onPoolChange: Dispatch<SetStateAction<BexStatusProviderProps["pool"]>>;
|
|
35
|
+
pool?: {
|
|
36
|
+
id: Hex;
|
|
37
|
+
isInRecoveryMode: boolean;
|
|
38
|
+
isPaused: boolean;
|
|
39
|
+
disablePoolWithdrawals: boolean;
|
|
40
|
+
disablePoolDeposits: boolean;
|
|
41
|
+
};
|
|
42
|
+
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* @description Determines the status of a pool or vault and returns the appropriate messages and flags to disable functionality.
|
|
46
|
+
* More information here https://www.notion.so/berachain/BEX-RecoveryMode-and-Pause-explained-17c6120abced80e0985dd589b57ff018
|
|
47
|
+
*
|
|
48
|
+
* @returns status flags to enable/disable/notify users across the BEX
|
|
49
|
+
*
|
|
50
|
+
**/
|
|
51
|
+
declare function useBexStatus(): {
|
|
52
|
+
protocol: {
|
|
53
|
+
isPaused: boolean;
|
|
54
|
+
factories: FactoryStatus & {
|
|
55
|
+
allPaused: boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
onPoolChange: Dispatch<SetStateAction<BexStatusProviderProps["pool"]>>;
|
|
59
|
+
pool?: {
|
|
60
|
+
id: Hex;
|
|
61
|
+
isInRecoveryMode: boolean;
|
|
62
|
+
isPaused: boolean;
|
|
63
|
+
disablePoolWithdrawals: boolean;
|
|
64
|
+
disablePoolDeposits: boolean;
|
|
65
|
+
};
|
|
66
|
+
labels?: NonNullable<EdgeConfigSchema["bex"]>["emergencyLabels"];
|
|
67
|
+
};
|
|
68
|
+
declare function BexStatusProvider({ children, isVaultPaused, labels, factories, }: PropsWithChildren<BexStatusProviderProps>): react_jsx_runtime.JSX.Element;
|
|
69
|
+
|
|
70
|
+
export { type BexStatusProviderProps as B, BexStateContext as a, BexStatusProvider as b, useBexStatus as u };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ErrorLike } from '@apollo/client';
|
|
2
|
+
import { B as BeraError, I as IBeraErrorArgs } from './BeraError-CfcNTfpH.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This is an error class that should be used to handle errors from fetch requests.
|
|
6
|
+
*/
|
|
7
|
+
declare class RequestError extends BeraError {
|
|
8
|
+
/**
|
|
9
|
+
* The error response from the request.
|
|
10
|
+
*/
|
|
11
|
+
response: Response | ErrorLike | undefined;
|
|
12
|
+
static isCorsError(error: Error): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The endpoint that was requested.
|
|
15
|
+
*/
|
|
16
|
+
endpoint: {
|
|
17
|
+
name?: string;
|
|
18
|
+
url: string;
|
|
19
|
+
type?: "rest" | "graphql" | "rpc";
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A list of domains that should have their query params removed.
|
|
23
|
+
*/
|
|
24
|
+
private queryRichfulDomains;
|
|
25
|
+
statusCode: number | undefined;
|
|
26
|
+
payload?: object;
|
|
27
|
+
static readonly REASON_MAP: {
|
|
28
|
+
readonly 429: "RATE_LIMITED_429";
|
|
29
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
30
|
+
readonly CORS_ERROR: "CORS";
|
|
31
|
+
};
|
|
32
|
+
constructor(args: IBeraErrorArgs & {
|
|
33
|
+
response: Response | ErrorLike | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The payload sent to the request.
|
|
36
|
+
*/
|
|
37
|
+
payload?: object;
|
|
38
|
+
endpoint: string | URL | {
|
|
39
|
+
name?: string;
|
|
40
|
+
url: string | URL;
|
|
41
|
+
type: "rest" | "graphql" | "rpc";
|
|
42
|
+
};
|
|
43
|
+
statusCode?: number;
|
|
44
|
+
});
|
|
45
|
+
setEndpoint(endpoint: string | URL | {
|
|
46
|
+
name?: string;
|
|
47
|
+
url: string | URL;
|
|
48
|
+
type?: "rest" | "graphql" | "rpc";
|
|
49
|
+
}): {
|
|
50
|
+
name?: string;
|
|
51
|
+
url: string;
|
|
52
|
+
type?: "rest" | "graphql" | "rpc";
|
|
53
|
+
};
|
|
54
|
+
private tryMatchNetworkError;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { RequestError as R };
|