@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.
@@ -0,0 +1,13 @@
1
+ export declare const ERC20_ABI: {
2
+ inputs: {
3
+ name: string;
4
+ type: string;
5
+ }[];
6
+ name: string;
7
+ outputs: {
8
+ name: string;
9
+ type: string;
10
+ }[];
11
+ stateMutability: string;
12
+ type: string;
13
+ }[];
@@ -0,0 +1,99 @@
1
+ export declare const FORWARDER_ABI: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly internalType: "address";
4
+ readonly name: "_forwarder";
5
+ readonly type: "address";
6
+ }];
7
+ readonly stateMutability: "nonpayable";
8
+ readonly type: "constructor";
9
+ }, {
10
+ readonly inputs: readonly [{
11
+ readonly internalType: "address";
12
+ readonly name: "target";
13
+ readonly type: "address";
14
+ }];
15
+ readonly name: "AddressEmptyCode";
16
+ readonly type: "error";
17
+ }, {
18
+ readonly inputs: readonly [{
19
+ readonly internalType: "address";
20
+ readonly name: "account";
21
+ readonly type: "address";
22
+ }];
23
+ readonly name: "AddressInsufficientBalance";
24
+ readonly type: "error";
25
+ }, {
26
+ readonly inputs: readonly [];
27
+ readonly name: "FailedInnerCall";
28
+ readonly type: "error";
29
+ }, {
30
+ readonly inputs: readonly [{
31
+ readonly internalType: "address";
32
+ readonly name: "token";
33
+ readonly type: "address";
34
+ }];
35
+ readonly name: "SafeERC20FailedOperation";
36
+ readonly type: "error";
37
+ }, {
38
+ readonly anonymous: false;
39
+ readonly inputs: readonly [{
40
+ readonly indexed: true;
41
+ readonly internalType: "address";
42
+ readonly name: "from";
43
+ readonly type: "address";
44
+ }, {
45
+ readonly indexed: true;
46
+ readonly internalType: "address";
47
+ readonly name: "to";
48
+ readonly type: "address";
49
+ }, {
50
+ readonly indexed: true;
51
+ readonly internalType: "address";
52
+ readonly name: "token";
53
+ readonly type: "address";
54
+ }, {
55
+ readonly indexed: false;
56
+ readonly internalType: "uint256";
57
+ readonly name: "amount";
58
+ readonly type: "uint256";
59
+ }, {
60
+ readonly indexed: false;
61
+ readonly internalType: "string";
62
+ readonly name: "message";
63
+ readonly type: "string";
64
+ }];
65
+ readonly name: "Forward";
66
+ readonly type: "event";
67
+ }, {
68
+ readonly inputs: readonly [];
69
+ readonly name: "FORWARD_ADDRESS";
70
+ readonly outputs: readonly [{
71
+ readonly internalType: "address";
72
+ readonly name: "";
73
+ readonly type: "address";
74
+ }];
75
+ readonly stateMutability: "view";
76
+ readonly type: "function";
77
+ }, {
78
+ readonly inputs: readonly [{
79
+ readonly internalType: "address";
80
+ readonly name: "token";
81
+ readonly type: "address";
82
+ }, {
83
+ readonly internalType: "address";
84
+ readonly name: "to";
85
+ readonly type: "address";
86
+ }, {
87
+ readonly internalType: "uint256";
88
+ readonly name: "amount";
89
+ readonly type: "uint256";
90
+ }, {
91
+ readonly internalType: "string";
92
+ readonly name: "message";
93
+ readonly type: "string";
94
+ }];
95
+ readonly name: "forward";
96
+ readonly outputs: readonly [];
97
+ readonly stateMutability: "nonpayable";
98
+ readonly type: "function";
99
+ }];
@@ -0,0 +1,36 @@
1
+ import { BigNumber, ethers } from "ethers";
2
+ export declare enum ForwarderError {
3
+ CONTRACT_NOT_AVAILABLE = "Contract not available",
4
+ SIGNER_NOT_AVAILABLE = "Signer not available",
5
+ UNKNOWN_ERROR = "Unknown error",
6
+ INVALID_FORWARD_TYPE = "Invalid forward type",
7
+ MISSING_REQUIRED_PARAMS = "Missing required parameters"
8
+ }
9
+ export type ForwardType = "PayProtocolFeeAndMintGCTLAndStake" | "PayProtocolFee" | "MintGCTLAndStake" | "MintGCTL" | "BuySolarFarm";
10
+ export type Currency = "USDC" | "GLW" | "USDG";
11
+ export interface ForwardParams {
12
+ amount: BigNumber;
13
+ userAddress: string;
14
+ type: ForwardType;
15
+ currency?: Currency;
16
+ applicationId?: string;
17
+ farmId?: string;
18
+ regionId?: number;
19
+ }
20
+ export declare function useForwarder(signer: ethers.providers.JsonRpcSigner | undefined, CHAIN_ID: number): {
21
+ forwardTokens: (params: ForwardParams) => Promise<string>;
22
+ payProtocolFeeAndMintGCTLAndStake: (amount: BigNumber, userAddress: string, applicationId: string, regionId?: number, currency?: Currency) => Promise<string>;
23
+ payProtocolFee: (amount: BigNumber, userAddress: string, applicationId: string, currency?: Currency) => Promise<string>;
24
+ mintGCTLAndStake: (amount: BigNumber, userAddress: string, regionId?: number) => Promise<string>;
25
+ mintGCTL: (amount: BigNumber, userAddress: string) => Promise<string>;
26
+ buySolarFarm: (amount: BigNumber, userAddress: string, farmId: string, currency?: Currency) => Promise<string>;
27
+ approveToken: (amount: BigNumber, currency?: Currency) => Promise<boolean>;
28
+ checkTokenAllowance: (owner: string, currency?: Currency) => Promise<BigNumber>;
29
+ checkTokenBalance: (owner: string, currency?: Currency) => Promise<BigNumber>;
30
+ estimateGasForForward: (params: ForwardParams, ethPriceInUSD: number | null) => Promise<string>;
31
+ mintTestUSDC: (amount: BigNumber, recipient: string) => Promise<string>;
32
+ constructForwardMessage: (params: ForwardParams) => string;
33
+ readonly isProcessing: boolean;
34
+ addresses: Record<"USDC" | "GLW" | "USDG" | "FORWARDER" | "FOUNDATION_WALLET", `0x${string}`>;
35
+ isSignerAvailable: boolean;
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -0,0 +1,34 @@
1
+ type ContractKeys = "USDC" | "FORWARDER" | "FOUNDATION_WALLET" | "GLW" | "USDG";
2
+
3
+ // Contract-specific addresses
4
+ const mainnetAddresses: Record<ContractKeys, `0x${string}`> = {
5
+ USDG: "0xe010ec500720bE9EF3F82129E7eD2Ee1FB7955F2",
6
+ GLW: "0xf4fbC617A5733EAAF9af08E1Ab816B103388d8B6",
7
+ USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
8
+ FORWARDER: "0x0000000000000000000000000000000000000000", // TODO: Update with actual mainnet address
9
+ FOUNDATION_WALLET: "0x0000000000000000000000000000000000000000", // TODO: Update with actual mainnet foundation wallet
10
+ };
11
+
12
+ const sepoliaAddresses: Record<ContractKeys, `0x${string}`> = {
13
+ USDG: "0xda78313A3fF949890112c1B746AB1c75d1b1c17B",
14
+ GLW: "0x2039161fcE4C8e5CF5FE64e17Fd290E8dFF3c9BD",
15
+ USDC: "0x93c898be98cd2618ba84a6dccf5003d3bbe40356",
16
+ FORWARDER: "0x9c1d61303D46BFAb1eC5F25c12A1Bf4cB3d06416",
17
+ FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
18
+ };
19
+
20
+ export const getAddresses = (
21
+ CHAIN_ID: number
22
+ ): Record<ContractKeys, `0x${string}`> => {
23
+ switch (CHAIN_ID) {
24
+ case 1:
25
+ return mainnetAddresses;
26
+ case 11155111:
27
+ return sepoliaAddresses;
28
+ default:
29
+ console.warn(
30
+ `Unsupported chain ID: ${CHAIN_ID}, falling back to mainnet addresses`
31
+ );
32
+ return mainnetAddresses;
33
+ }
34
+ };
package/src/index.ts CHANGED
@@ -4,3 +4,5 @@ export {
4
4
  createWeeklyReport,
5
5
  createWeeklyReportLegacy,
6
6
  } from "./lib/create-weekly-report/index";
7
+
8
+ export { useForwarder } from "./lib/hooks/use-forwarder";
@@ -0,0 +1,49 @@
1
+ export const ERC20_ABI = [
2
+ {
3
+ inputs: [
4
+ { name: "spender", type: "address" },
5
+ { name: "amount", type: "uint256" },
6
+ ],
7
+ name: "approve",
8
+ outputs: [{ name: "", type: "bool" }],
9
+ stateMutability: "nonpayable",
10
+ type: "function",
11
+ },
12
+ {
13
+ inputs: [
14
+ { name: "owner", type: "address" },
15
+ { name: "spender", type: "address" },
16
+ ],
17
+ name: "allowance",
18
+ outputs: [{ name: "", type: "uint256" }],
19
+ stateMutability: "view",
20
+ type: "function",
21
+ },
22
+ {
23
+ inputs: [
24
+ { name: "to", type: "address" },
25
+ { name: "amount", type: "uint256" },
26
+ ],
27
+ name: "transfer",
28
+ outputs: [{ name: "", type: "bool" }],
29
+ stateMutability: "nonpayable",
30
+ type: "function",
31
+ },
32
+ {
33
+ inputs: [{ name: "account", type: "address" }],
34
+ name: "balanceOf",
35
+ outputs: [{ name: "", type: "uint256" }],
36
+ stateMutability: "view",
37
+ type: "function",
38
+ },
39
+ {
40
+ inputs: [
41
+ { name: "account", type: "address" },
42
+ { name: "amount", type: "uint256" },
43
+ ],
44
+ name: "mint",
45
+ outputs: [{ name: "", type: "bool" }],
46
+ stateMutability: "nonpayable",
47
+ type: "function",
48
+ },
49
+ ];
@@ -0,0 +1,69 @@
1
+ export const FORWARDER_ABI = [
2
+ {
3
+ inputs: [{ internalType: "address", name: "_forwarder", type: "address" }],
4
+ stateMutability: "nonpayable",
5
+ type: "constructor",
6
+ },
7
+ {
8
+ inputs: [{ internalType: "address", name: "target", type: "address" }],
9
+ name: "AddressEmptyCode",
10
+ type: "error",
11
+ },
12
+ {
13
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
14
+ name: "AddressInsufficientBalance",
15
+ type: "error",
16
+ },
17
+ { inputs: [], name: "FailedInnerCall", type: "error" },
18
+ {
19
+ inputs: [{ internalType: "address", name: "token", type: "address" }],
20
+ name: "SafeERC20FailedOperation",
21
+ type: "error",
22
+ },
23
+ {
24
+ anonymous: false,
25
+ inputs: [
26
+ { indexed: true, internalType: "address", name: "from", type: "address" },
27
+ { indexed: true, internalType: "address", name: "to", type: "address" },
28
+ {
29
+ indexed: true,
30
+ internalType: "address",
31
+ name: "token",
32
+ type: "address",
33
+ },
34
+ {
35
+ indexed: false,
36
+ internalType: "uint256",
37
+ name: "amount",
38
+ type: "uint256",
39
+ },
40
+ {
41
+ indexed: false,
42
+ internalType: "string",
43
+ name: "message",
44
+ type: "string",
45
+ },
46
+ ],
47
+ name: "Forward",
48
+ type: "event",
49
+ },
50
+ {
51
+ inputs: [],
52
+ name: "FORWARD_ADDRESS",
53
+ outputs: [{ internalType: "address", name: "", type: "address" }],
54
+ stateMutability: "view",
55
+ type: "function",
56
+ },
57
+ {
58
+ inputs: [
59
+ { internalType: "address", name: "token", type: "address" },
60
+ { internalType: "address", name: "to", type: "address" },
61
+ { internalType: "uint256", name: "amount", type: "uint256" },
62
+ { internalType: "string", name: "message", type: "string" },
63
+ ],
64
+ name: "forward",
65
+ outputs: [],
66
+ stateMutability: "nonpayable",
67
+ type: "function",
68
+ },
69
+ ] as const;