@glowlabs-org/utils 0.1.5 → 0.2.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/README.md CHANGED
@@ -8,10 +8,10 @@ This repository contains utils for interacting with Glow labs data sources
8
8
 
9
9
  ## Requirements
10
10
 
11
- - Ethers V5
11
+ - Node >= 16 (tested up to 20)
12
+ - Ethers v5 (peer-dependency)
12
13
  - MerkletreeJS
13
14
  - Viem
14
- - Node version >= 16
15
15
 
16
16
  ## Example Usage
17
17
 
@@ -31,11 +31,42 @@ const main = async () => {
31
31
  //Save to 37.json
32
32
  fs.writeFileSync("37.json", JSON.stringify(report, null, 4));
33
33
  };
34
- ``;
34
+ ```
35
+
36
+ ---
37
+
38
+ ### Forwarder SDK (framework-agnostic)
39
+
40
+ Below is a minimal example showing how to forward USDC using a standard `ethers` signer. The same call works in Node or in a browser (e.g. MetaMask’s `window.ethereum`).
41
+
42
+ ```typescript
43
+ import { useForwarder } from "@glowlabs-org/utils";
44
+ import { Wallet, providers, utils } from "ethers";
35
45
 
36
- main();
46
+ // Use Infura, Alchemy or any JSON-RPC endpoint
47
+ const provider = new providers.JsonRpcProvider(
48
+ "https://sepolia.infura.io/v3/<API_KEY>"
49
+ );
50
+
51
+ // A local private key, or rely on a browser wallet by passing `provider.getSigner()`
52
+ const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
53
+
54
+ // Chain id 11155111 = Sepolia
55
+ const forwarder = useForwarder(signer, 11155111);
56
+
57
+ await forwarder.forwardTokens({
58
+ amount: utils.parseUnits("10", 6), // 10 USDC (6 dp)
59
+ userAddress: await signer.getAddress(),
60
+ type: "PayProtocolFee",
61
+ applicationId: "123",
62
+ currency: "USDC",
63
+ });
64
+
65
+ console.log("Tx hash:", forwarder.isProcessing ? "pending…" : "sent");
37
66
  ```
38
67
 
68
+ See `src/lib/hooks/use-forwarder.ts` for all available helpers (`approveToken`, `checkTokenBalance`, `estimateGasForForward`, etc.).
69
+
39
70
  ## Contributions
40
71
 
41
72
  For contributions, feel free to open a PR or raise an issue.
@@ -0,0 +1,3 @@
1
+ type ContractKeys = "USDC" | "FORWARDER" | "FOUNDATION_WALLET" | "GLW" | "USDG";
2
+ export declare const getAddresses: (CHAIN_ID: number) => Record<ContractKeys, `0x${string}`>;
3
+ export {};
@@ -1,3 +1,4 @@
1
1
  export * from "./lib/create-weekly-report/types/index";
2
2
  export * from "./constants/index";
3
3
  export { createWeeklyReport, createWeeklyReportLegacy, } from "./lib/create-weekly-report/index";
4
+ export { useForwarder } from "./lib/hooks/use-forwarder";