@glowlabs-org/utils 0.2.92 → 0.2.94

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.
@@ -1,3 +1,3 @@
1
1
  export type ContractKeys = "USDC" | "FORWARDER" | "FOUNDATION_WALLET" | "GLW" | "USDG" | "USDG_REDEMPTION" | "IMPACT_CATALYST" | "AUDIT_FEE_WALLET" | "UNISWAP_V2_ROUTER" | "UNISWAP_V2_FACTORY" | "USDG_UNISWAP" | "GLW_UNISWAP";
2
2
  export declare const getAddresses: (CHAIN_ID: number) => Record<ContractKeys, `0x${string}`>;
3
- export declare const DECIMALS_BY_TOKEN: Record<"USDC" | "USDG" | "GCTL" | "GLW", number>;
3
+ export declare const DECIMALS_BY_TOKEN: Record<"USDC" | "USDG" | "GCTL" | "SGCTL" | "GLW", number>;
@@ -22,6 +22,11 @@ const FORWARDER_ABI = [
22
22
  inputs: [
23
23
  { internalType: "contract USDG", name: "_usdg", type: "address" },
24
24
  { internalType: "contract IERC20", name: "_usdc", type: "address" },
25
+ {
26
+ internalType: "contract CounterfactualHolderFactory",
27
+ name: "_cfhFactory",
28
+ type: "address",
29
+ },
25
30
  ],
26
31
  stateMutability: "payable",
27
32
  type: "constructor",
@@ -77,6 +82,11 @@ const FORWARDER_ABI = [
77
82
  { internalType: "address", name: "token", type: "address" },
78
83
  { internalType: "address", name: "to", type: "address" },
79
84
  { internalType: "uint256", name: "amount", type: "uint256" },
85
+ {
86
+ internalType: "bool",
87
+ name: "sendToCounterfactualWallet",
88
+ type: "bool",
89
+ },
80
90
  { internalType: "string", name: "message", type: "string" },
81
91
  ],
82
92
  name: "forward",
@@ -84,6 +94,19 @@ const FORWARDER_ABI = [
84
94
  stateMutability: "nonpayable",
85
95
  type: "function",
86
96
  },
97
+ {
98
+ inputs: [],
99
+ name: "i_CFHFactory",
100
+ outputs: [
101
+ {
102
+ internalType: "contract CounterfactualHolderFactory",
103
+ name: "",
104
+ type: "address",
105
+ },
106
+ ],
107
+ stateMutability: "view",
108
+ type: "function",
109
+ },
87
110
  {
88
111
  inputs: [],
89
112
  name: "i_USDC",
@@ -109,6 +132,11 @@ const FORWARDER_ABI = [
109
132
  inputs: [
110
133
  { internalType: "uint256", name: "amount", type: "uint256" },
111
134
  { internalType: "address", name: "to", type: "address" },
135
+ {
136
+ internalType: "bool",
137
+ name: "sendToCounterfactualWallet",
138
+ type: "bool",
139
+ },
112
140
  { internalType: "string", name: "message", type: "string" },
113
141
  ],
114
142
  name: "swapUSDCAndForwardUSDG",
@@ -192,7 +220,7 @@ const sepoliaAddresses = {
192
220
  USDC: "0x93c898be98cd2618ba84a6dccf5003d3bbe40356",
193
221
  USDG_UNISWAP: "0x2a085A3aEA8982396533327c854753Ce521B666d",
194
222
  GLW_UNISWAP: "0x8e27016D0B866a56CE74A1a280c749dD679bb0Fa",
195
- FORWARDER: "0x1fb285dDFCbC0456d655F8DC7C637E33c5568858",
223
+ FORWARDER: "0xDaC24F18171224eeaf6a9B38f5C5081aDbDff969",
196
224
  FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
197
225
  UNISWAP_V2_ROUTER: "0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3",
198
226
  UNISWAP_V2_FACTORY: "0xF62c03E08ada871A0bEb309762E260a7a6a880E6",
@@ -212,9 +240,34 @@ const DECIMALS_BY_TOKEN = {
212
240
  USDC: 6,
213
241
  USDG: 6,
214
242
  GCTL: 6,
243
+ SGCTL: 6,
215
244
  GLW: 18,
216
245
  };
217
246
 
247
+ // ---------------------------------------------------------------------------
248
+ // Common / Shared Types
249
+ // ---------------------------------------------------------------------------
250
+ const PAYMENT_CURRENCIES = [
251
+ "GCTL",
252
+ "USDC",
253
+ "USDG",
254
+ "GLW",
255
+ "SGCTL",
256
+ ];
257
+ const OFF_CHAIN_PAYMENT_CURRENCIES = ["SGCTL", "GCTL"];
258
+ const TRANSFER_TYPES = {
259
+ PayProtocolFeeAndMintGCTLAndStake: "PayProtocolFeeAndMintGCTLAndStake",
260
+ PayProtocolFee: "PayProtocolFee",
261
+ PayAuditFees: "PayAuditFees",
262
+ CommitKickstarter: "CommitKickstarter",
263
+ MintGCTLAndStake: "MintGCTLAndStake",
264
+ MintGCTL: "MintGCTL",
265
+ BuySolarFarm: "BuySolarFarm",
266
+ SponsorProtocolFee: "SponsorProtocolFee",
267
+ SponsorProtocolFeeAndMintGCTLAndStake: "SponsorProtocolFeeAndMintGCTLAndStake",
268
+ PayProtocolDepositUsingStakedControl: "PayProtocolDepositUsingStakedControl",
269
+ };
270
+
218
271
  var ForwarderError;
219
272
  (function (ForwarderError) {
220
273
  ForwarderError["CONTRACT_NOT_AVAILABLE"] = "Contract not available";
@@ -275,47 +328,47 @@ function useForwarder(signer, CHAIN_ID) {
275
328
  function constructForwardMessage(params) {
276
329
  const { type, applicationId, farmId, regionId, userAddress, kickstarterId, } = params;
277
330
  switch (type) {
278
- case "PayProtocolFeeAndMintGCTLAndStake":
331
+ case TRANSFER_TYPES.PayProtocolFeeAndMintGCTLAndStake:
279
332
  if (!applicationId) {
280
333
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
281
334
  }
282
335
  return `PayProtocolFeeAndMintGCTLAndStake::${applicationId}`;
283
- case "PayProtocolFee":
336
+ case TRANSFER_TYPES.PayProtocolFee:
284
337
  if (!applicationId) {
285
338
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
286
339
  }
287
340
  return `PayProtocolFee::${applicationId}`;
288
- case "SponsorProtocolFee":
341
+ case TRANSFER_TYPES.SponsorProtocolFee:
289
342
  if (!applicationId) {
290
343
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
291
344
  }
292
345
  return `SponsorProtocolFee::${applicationId}`;
293
- case "SponsorProtocolFeeAndMintGCTLAndStake":
346
+ case TRANSFER_TYPES.SponsorProtocolFeeAndMintGCTLAndStake:
294
347
  if (!applicationId) {
295
348
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
296
349
  }
297
350
  return `SponsorProtocolFeeAndMintGCTLAndStake::${applicationId}`;
298
- case "MintGCTLAndStake":
351
+ case TRANSFER_TYPES.MintGCTLAndStake:
299
352
  if (!regionId) {
300
353
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
301
354
  }
302
355
  return `MintGCTLAndStake::${regionId}`;
303
- case "MintGCTL":
356
+ case TRANSFER_TYPES.MintGCTL:
304
357
  if (!userAddress) {
305
358
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
306
359
  }
307
360
  return `MintGCTL::${userAddress}`;
308
- case "BuySolarFarm":
361
+ case TRANSFER_TYPES.BuySolarFarm:
309
362
  if (!farmId) {
310
363
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
311
364
  }
312
365
  return `BuySolarFarm::${farmId}`;
313
- case "PayAuditFees":
366
+ case TRANSFER_TYPES.PayAuditFees:
314
367
  if (!applicationId) {
315
368
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
316
369
  }
317
370
  return `PayAuditFees::${applicationId}`;
318
- case "CommitKickstarter":
371
+ case TRANSFER_TYPES.CommitKickstarter:
319
372
  if (!kickstarterId) {
320
373
  throw new Error(ForwarderError.MISSING_REQUIRED_PARAMS);
321
374
  }
@@ -424,12 +477,12 @@ function useForwarder(signer, CHAIN_ID) {
424
477
  // Construct the appropriate message for this forward type
425
478
  const message = constructForwardMessage(params);
426
479
  // Special handling: PayAuditFees can ONLY be USDC, and must call forward()
427
- const isAuditFees = params.type === "PayAuditFees";
480
+ const isAuditFees = params.type === TRANSFER_TYPES.PayAuditFees;
428
481
  if (isAuditFees && currency !== "USDC") {
429
482
  throw new Error("PayAuditFees only supports USDC");
430
483
  }
431
484
  // CommitKickstarter supports only USDC or USDG (GLW not allowed)
432
- const isCommitKickstarter = params.type === "CommitKickstarter";
485
+ const isCommitKickstarter = params.type === TRANSFER_TYPES.CommitKickstarter;
433
486
  if (isCommitKickstarter && currency === "GLW") {
434
487
  throw new Error("CommitKickstarter supports only USDC or USDG");
435
488
  }
@@ -465,7 +518,7 @@ function useForwarder(signer, CHAIN_ID) {
465
518
  if (!isAuditFees && currency === "USDC") {
466
519
  await forwarderContract
467
520
  .getFunction("swapUSDCAndForwardUSDG")
468
- .staticCall(amount, ADDRESSES.FOUNDATION_WALLET, message, {
521
+ .staticCall(amount, ADDRESSES.FOUNDATION_WALLET, true, message, {
469
522
  from: owner,
470
523
  });
471
524
  }
@@ -474,7 +527,7 @@ function useForwarder(signer, CHAIN_ID) {
474
527
  .getFunction("forward")
475
528
  .staticCall(tokenAddress, isAuditFees
476
529
  ? ADDRESSES.AUDIT_FEE_WALLET
477
- : ADDRESSES.FOUNDATION_WALLET, amount, message, { from: owner });
530
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message, { from: owner });
478
531
  }
479
532
  }
480
533
  catch (staticError) {
@@ -483,12 +536,12 @@ function useForwarder(signer, CHAIN_ID) {
483
536
  // Execute the forward transaction
484
537
  let tx;
485
538
  if (!isAuditFees && currency === "USDC") {
486
- tx = await forwarderContract.getFunction("swapUSDCAndForwardUSDG")(amount, ADDRESSES.FOUNDATION_WALLET, message);
539
+ tx = await forwarderContract.getFunction("swapUSDCAndForwardUSDG")(amount, ADDRESSES.FOUNDATION_WALLET, true, message);
487
540
  }
488
541
  else {
489
542
  tx = await forwarderContract.getFunction("forward")(tokenAddress, isAuditFees
490
543
  ? ADDRESSES.AUDIT_FEE_WALLET
491
- : ADDRESSES.FOUNDATION_WALLET, amount, message);
544
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message);
492
545
  }
493
546
  await tx.wait();
494
547
  return tx.hash;
@@ -512,7 +565,7 @@ function useForwarder(signer, CHAIN_ID) {
512
565
  return forwardTokens({
513
566
  amount,
514
567
  userAddress,
515
- type: "PayProtocolFeeAndMintGCTLAndStake",
568
+ type: TRANSFER_TYPES.PayProtocolFeeAndMintGCTLAndStake,
516
569
  currency,
517
570
  applicationId,
518
571
  regionId,
@@ -529,7 +582,7 @@ function useForwarder(signer, CHAIN_ID) {
529
582
  return forwardTokens({
530
583
  amount,
531
584
  userAddress,
532
- type: "SponsorProtocolFeeAndMintGCTLAndStake",
585
+ type: TRANSFER_TYPES.SponsorProtocolFeeAndMintGCTLAndStake,
533
586
  currency,
534
587
  applicationId,
535
588
  });
@@ -542,7 +595,7 @@ function useForwarder(signer, CHAIN_ID) {
542
595
  return forwardTokens({
543
596
  amount,
544
597
  userAddress,
545
- type: "PayProtocolFee",
598
+ type: TRANSFER_TYPES.PayProtocolFee,
546
599
  currency,
547
600
  applicationId,
548
601
  });
@@ -555,7 +608,7 @@ function useForwarder(signer, CHAIN_ID) {
555
608
  return forwardTokens({
556
609
  amount,
557
610
  userAddress,
558
- type: "SponsorProtocolFee",
611
+ type: TRANSFER_TYPES.SponsorProtocolFee,
559
612
  currency,
560
613
  applicationId,
561
614
  });
@@ -572,7 +625,7 @@ function useForwarder(signer, CHAIN_ID) {
572
625
  return forwardTokens({
573
626
  amount,
574
627
  userAddress,
575
- type: "MintGCTLAndStake",
628
+ type: TRANSFER_TYPES.MintGCTLAndStake,
576
629
  currency,
577
630
  regionId,
578
631
  });
@@ -589,7 +642,7 @@ function useForwarder(signer, CHAIN_ID) {
589
642
  return forwardTokens({
590
643
  amount,
591
644
  userAddress,
592
- type: "MintGCTL",
645
+ type: TRANSFER_TYPES.MintGCTL,
593
646
  currency,
594
647
  });
595
648
  }
@@ -601,7 +654,7 @@ function useForwarder(signer, CHAIN_ID) {
601
654
  return forwardTokens({
602
655
  amount,
603
656
  userAddress,
604
- type: "PayAuditFees",
657
+ type: TRANSFER_TYPES.PayAuditFees,
605
658
  currency: "USDC",
606
659
  applicationId,
607
660
  });
@@ -614,7 +667,7 @@ function useForwarder(signer, CHAIN_ID) {
614
667
  return forwardTokens({
615
668
  amount,
616
669
  userAddress,
617
- type: "BuySolarFarm",
670
+ type: TRANSFER_TYPES.BuySolarFarm,
618
671
  currency,
619
672
  farmId,
620
673
  });
@@ -630,7 +683,7 @@ function useForwarder(signer, CHAIN_ID) {
630
683
  return forwardTokens({
631
684
  amount,
632
685
  userAddress,
633
- type: "CommitKickstarter",
686
+ type: TRANSFER_TYPES.CommitKickstarter,
634
687
  currency,
635
688
  kickstarterId,
636
689
  });
@@ -647,7 +700,7 @@ function useForwarder(signer, CHAIN_ID) {
647
700
  if (!forwarderContract)
648
701
  throw new Error(ForwarderError.CONTRACT_NOT_AVAILABLE);
649
702
  const { amount, currency = "USDC" } = params;
650
- const isAuditFees = params.type === "PayAuditFees";
703
+ const isAuditFees = params.type === TRANSFER_TYPES.PayAuditFees;
651
704
  if (isAuditFees && currency !== "USDC") {
652
705
  throw new Error("PayAuditFees only supports USDC");
653
706
  }
@@ -676,12 +729,12 @@ function useForwarder(signer, CHAIN_ID) {
676
729
  const estimatedGas = !isAuditFees && currency === "USDC"
677
730
  ? await forwarderContract
678
731
  .getFunction("swapUSDCAndForwardUSDG")
679
- .estimateGas(amount, ADDRESSES.FOUNDATION_WALLET, message)
732
+ .estimateGas(amount, ADDRESSES.FOUNDATION_WALLET, true, message)
680
733
  : await forwarderContract
681
734
  .getFunction("forward")
682
735
  .estimateGas(tokenAddress, isAuditFees
683
736
  ? ADDRESSES.AUDIT_FEE_WALLET
684
- : ADDRESSES.FOUNDATION_WALLET, amount, message);
737
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message);
685
738
  const estimatedCost = estimatedGas * gasPrice;
686
739
  if (ethPriceInUSD) {
687
740
  const estimatedCostInEth = formatEther(estimatedCost);
@@ -930,6 +983,7 @@ function ControlRouter(baseUrl) {
930
983
  let isUnstaking = false;
931
984
  let isRestaking = false;
932
985
  let isRetryingFailedOperation = false;
986
+ let isPayingProtocolDepositUsingStakedControl = false;
933
987
  const stakeGctl = async (stakeRequest) => {
934
988
  isStaking = true;
935
989
  try {
@@ -997,6 +1051,23 @@ function ControlRouter(baseUrl) {
997
1051
  isRetryingFailedOperation = false;
998
1052
  }
999
1053
  };
1054
+ const payProtocolDepositUsingStakedControl = async (paymentRequest) => {
1055
+ isPayingProtocolDepositUsingStakedControl = true;
1056
+ try {
1057
+ const response = await request(`/pay-protocol-deposit-staked`, {
1058
+ method: "POST",
1059
+ headers: { "Content-Type": "application/json" },
1060
+ body: JSON.stringify(paymentRequest),
1061
+ });
1062
+ return response;
1063
+ }
1064
+ catch (error) {
1065
+ throw new Error(parseApiError$4(error));
1066
+ }
1067
+ finally {
1068
+ isPayingProtocolDepositUsingStakedControl = false;
1069
+ }
1070
+ };
1000
1071
  // --------------------------- Public API ----------------------------------
1001
1072
  return {
1002
1073
  // Queries
@@ -1019,6 +1090,7 @@ function ControlRouter(baseUrl) {
1019
1090
  unstakeGctl,
1020
1091
  restakeGctl,
1021
1092
  retryFailedOperation,
1093
+ payProtocolDepositUsingStakedControl,
1022
1094
  // Processing flags
1023
1095
  get isStaking() {
1024
1096
  return isStaking;
@@ -1032,6 +1104,9 @@ function ControlRouter(baseUrl) {
1032
1104
  get isRetryingFailedOperation() {
1033
1105
  return isRetryingFailedOperation;
1034
1106
  },
1107
+ get isPayingProtocolDepositUsingStakedControl() {
1108
+ return isPayingProtocolDepositUsingStakedControl;
1109
+ },
1035
1110
  };
1036
1111
  }
1037
1112
 
@@ -2083,5 +2158,5 @@ function FarmsRouter(baseUrl) {
2083
2158
  };
2084
2159
  }
2085
2160
 
2086
- export { ControlRouter as C, DECIMALS_BY_TOKEN as D, FarmsRouter as F, GLOW_WEIGHT_DECIMAL_PRECISION as G, HUB_URL as H, KickstarterRouter as K, MAX_WEIGHT as M, RegionRouter as R, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, ForwarderError as a, allRegions as b, usStates as c, countries as d, FORWARDER_ABI as e, GCA_URLS as f, getAddresses as g, regionMetadata as r, useForwarder as u };
2087
- //# sourceMappingURL=farms-router-DVSHNqsT.js.map
2161
+ export { ControlRouter as C, DECIMALS_BY_TOKEN as D, FarmsRouter as F, GLOW_WEIGHT_DECIMAL_PRECISION as G, HUB_URL as H, KickstarterRouter as K, MAX_WEIGHT as M, OFF_CHAIN_PAYMENT_CURRENCIES as O, PAYMENT_CURRENCIES as P, RegionRouter as R, TRANSFER_TYPES as T, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, ForwarderError as a, allRegions as b, usStates as c, countries as d, FORWARDER_ABI as e, GCA_URLS as f, getAddresses as g, regionMetadata as r, useForwarder as u };
2162
+ //# sourceMappingURL=farms-router-sm5H9Ax6.js.map