@glowlabs-org/utils 0.2.142 → 0.2.144

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 CHANGED
@@ -4,14 +4,17 @@ This repository contains utils for interacting with Glow labs data sources
4
4
 
5
5
  ## Install
6
6
 
7
- `npm install ethers@5.7.2 viem merkletreejs @glowlabs-org/utils`
7
+ ```bash
8
+ # peer deps (versions compatible with this library)
9
+ pnpm add @glowlabs-org/utils ethers@^6 viem@^2 merkletreejs decimal.js
10
+ ```
8
11
 
9
12
  ## Requirements
10
13
 
11
14
  - Node >= 16 (tested up to 20)
12
- - Ethers v5 (peer-dependency)
15
+ - Ethers v6 (peer-dependency)
16
+ - Viem v2 (peer-dependency)
13
17
  - MerkletreeJS
14
- - Viem
15
18
 
16
19
  ## Example Usage
17
20
 
@@ -41,12 +44,10 @@ Below is a minimal example showing how to forward USDC using a standard `ethers`
41
44
 
42
45
  ```typescript
43
46
  import { useForwarder } from "@glowlabs-org/utils";
44
- import { Wallet, providers, utils } from "ethers";
47
+ import { Wallet, JsonRpcProvider, parseUnits } from "ethers";
45
48
 
46
49
  // Use Infura, Alchemy or any JSON-RPC endpoint
47
- const provider = new providers.JsonRpcProvider(
48
- "https://sepolia.infura.io/v3/<API_KEY>"
49
- );
50
+ const provider = new JsonRpcProvider("https://sepolia.infura.io/v3/<API_KEY>");
50
51
 
51
52
  // A local private key, or rely on a browser wallet by passing `provider.getSigner()`
52
53
  const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
@@ -55,7 +56,7 @@ const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
55
56
  const forwarder = useForwarder(signer, 11155111);
56
57
 
57
58
  await forwarder.forwardTokens({
58
- amount: utils.parseUnits("10", 6), // 10 USDC (6 dp)
59
+ amount: parseUnits("10", 6), // 10 USDC (6 dp)
59
60
  userAddress: await signer.getAddress(),
60
61
  type: "PayProtocolFee",
61
62
  applicationId: "123",
@@ -71,8 +72,6 @@ See `src/lib/hooks/use-forwarder.ts` for all available helpers (`approveToken`,
71
72
 
72
73
  ### Control-API SDK (framework-agnostic)
73
74
 
74
- All on-chain accounting and staking data can be accessed through the plain-TypeScript helper exported from `src/lib/control-api/control-router.ts`.
75
-
76
75
  ```typescript
77
76
  import { ControlRouter } from "@glowlabs-org/utils";
78
77
 
@@ -82,33 +81,27 @@ const controlApi = ControlRouter("https://control-api.glowlabs.org");
82
81
  // Read-only queries
83
82
  const balance = await controlApi.fetchGctlBalance("0xYourWallet");
84
83
  const price = await controlApi.fetchGctlPrice();
85
- // New – GLW token price in USDC
86
84
  const glwPrice = await controlApi.fetchGlwPrice();
87
85
 
88
- const regions = await controlApi.fetchRegions();
89
-
90
- // Paginated listings (page, limit are optional – default 1/50)
86
+ // Paginated listings
91
87
  const mintedPage2 = await controlApi.fetchMintedEvents(2, 25);
92
88
 
93
89
  // Mutations
94
- await controlApi.stakeGctl(
95
- "0xYourWallet",
96
- /* regionId */ 42,
97
- /* amount */ "1000000"
98
- );
99
-
100
- if (controlApi.isStaking) {
101
- console.log("staking in progress…");
102
- }
90
+ await controlApi.stakeGctl({
91
+ wallet: "0xYourWallet",
92
+ regionId: 42,
93
+ amount: "1000000",
94
+ signature: "0x…",
95
+ deadline: "1728000000",
96
+ nonce: "1",
97
+ });
103
98
  ```
104
99
 
105
- Refer to the source file for the full surface (`fetchMintedEvents`, `unstakeGctl`, `retryFailedOperation`, etc.). All methods are promise-based and contain zero React dependencies – usable in Node, Deno or the browser.
100
+ All methods are promise-based and contain zero React dependencies – usable in Node, Deno or the browser.
106
101
 
107
102
  ---
108
103
 
109
- ### Regions-API SDK (framework-agnostic)
110
-
111
- This tiny helper wraps region CRUD endpoints and provides in-memory caching.
104
+ ### Region-API SDK (framework-agnostic)
112
105
 
113
106
  ```typescript
114
107
  import { RegionRouter } from "@glowlabs-org/utils";
@@ -119,17 +112,92 @@ const regionsApi = RegionRouter("https://control-api.glowlabs.org");
119
112
  await regionsApi.fetchRegions();
120
113
  console.table(regionsApi.regions);
121
114
 
122
- // Create a new region
123
- await regionsApi.createRegion({
124
- code: "FR",
125
- name: "France",
126
- isUs: false,
115
+ // Convenience helper merges bundled metadata with fetched regions
116
+ const maybeFlorida = regionsApi.getRegionByCode("US-FL");
117
+ ```
118
+
119
+ `getRegionByCode()` merges locally-bundled metadata (flag, description, etc.) from `src/lib/region-metadata.ts`.
120
+
121
+ ---
122
+
123
+ ## Optional Sentry integration (Next.js)
124
+
125
+ This library ships with built-in, optional Sentry hooks. If Sentry isn’t configured, everything no-ops safely.
126
+
127
+ #### 1) Install Sentry for Next.js
128
+
129
+ ```bash
130
+ pnpm add @sentry/nextjs
131
+ # or: npx @sentry/wizard -i nextjs
132
+ ```
133
+
134
+ Set env vars (build-time for source maps, and runtime DSN):
135
+
136
+ ```env
137
+ # build-time (CI) – for source maps upload
138
+ SENTRY_AUTH_TOKEN=... # keep secret
139
+ SENTRY_ORG=your-org
140
+ SENTRY_PROJECT=your-project
141
+
142
+ # runtime (browser/server)
143
+ NEXT_PUBLIC_SENTRY_DSN=https://<key>@o<org>.ingest.sentry.io/<project>
144
+ NEXT_PUBLIC_SENTRY_ENABLED=true
145
+ ```
146
+
147
+ Wrap your Next config to enable source maps upload (optional but recommended):
148
+
149
+ ```js
150
+ // next.config.js
151
+ const { withSentryConfig } = require("@sentry/nextjs");
152
+
153
+ const nextConfig = {
154
+ /* your config */
155
+ };
156
+ module.exports = withSentryConfig(nextConfig, { silent: true });
157
+ ```
158
+
159
+ #### 2) Initialize Sentry and wire the utils once
160
+
161
+ App Router (recommended):
162
+
163
+ ```ts
164
+ // sentry.client.config.ts
165
+ import * as Sentry from "@sentry/nextjs";
166
+ import { configureSentry } from "@glowlabs-org/utils/browser";
167
+
168
+ Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN });
169
+
170
+ configureSentry({
171
+ enabled: process.env.NEXT_PUBLIC_SENTRY_ENABLED !== "false",
172
+ client: Sentry,
173
+ defaultContext: { app: "web", env: process.env.NEXT_PUBLIC_VERCEL_ENV },
127
174
  });
175
+ ```
176
+
177
+ ```ts
178
+ // sentry.server.config.ts
179
+ import * as Sentry from "@sentry/nextjs";
180
+ import { configureSentry } from "@glowlabs-org/utils";
181
+
182
+ Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN });
183
+
184
+ configureSentry({
185
+ enabled: process.env.NEXT_PUBLIC_SENTRY_ENABLED !== "false",
186
+ client: Sentry,
187
+ defaultContext: { runtime: "server" },
188
+ });
189
+ ```
190
+
191
+ That’s it. All mutations in `ControlRouter`, `FarmsRouter`, `KickstarterRouter`, and the hooks (`useForwarder`, `useOffchainFractions`) will automatically add breadcrumbs and capture exceptions with useful context (wallets, ids, region, baseUrl, etc.).
192
+
193
+ #### Disable Sentry (locally or per environment)
128
194
 
129
- console.log("isCreatingRegion", regionsApi.isCreatingRegion);
195
+ ```ts
196
+ import { configureSentry } from "@glowlabs-org/utils";
197
+ configureSentry({ enabled: false });
130
198
  ```
131
199
 
132
- `getRegionByCode()` also merges locally-bundled metadata (flag, description, etc.) from `src/lib/region-metadata.ts`.
200
+ You can also skip calling `configureSentry` entirely the library will quietly no-op unless a Sentry client is provided or found globally.
133
201
 
134
202
  The metadata file re-exports handy arrays:
135
203
 
@@ -14,3 +14,4 @@ export * from "./constants/weights";
14
14
  export * from "./constants/urls";
15
15
  export * from "./utils/stake-control";
16
16
  export * from "./utils/transaction-utils";
17
+ export { configureSentry, type SentryClientLike } from "./utils/sentry";
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var farmsRouter = require('./farms-router-CCva--xp.js');
3
+ var farmsRouter = require('./farms-router-Bvy7r2pJ.js');
4
4
  var viem = require('viem');
5
5
  require('ethers');
6
6
 
@@ -12447,6 +12447,7 @@ exports.TRANSFER_TYPES = farmsRouter.TRANSFER_TYPES;
12447
12447
  exports.USDG_WEIGHT_DECIMAL_PRECISION = farmsRouter.USDG_WEIGHT_DECIMAL_PRECISION;
12448
12448
  exports.WalletsRouter = farmsRouter.WalletsRouter;
12449
12449
  exports.allRegions = farmsRouter.allRegions;
12450
+ exports.configureSentry = farmsRouter.configureSentry;
12450
12451
  exports.countries = farmsRouter.countries;
12451
12452
  exports.getAddresses = farmsRouter.getAddresses;
12452
12453
  exports.parseEthersError = farmsRouter.parseEthersError;