@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>;
@@ -24,6 +24,11 @@ const FORWARDER_ABI = [
24
24
  inputs: [
25
25
  { internalType: "contract USDG", name: "_usdg", type: "address" },
26
26
  { internalType: "contract IERC20", name: "_usdc", type: "address" },
27
+ {
28
+ internalType: "contract CounterfactualHolderFactory",
29
+ name: "_cfhFactory",
30
+ type: "address",
31
+ },
27
32
  ],
28
33
  stateMutability: "payable",
29
34
  type: "constructor",
@@ -79,6 +84,11 @@ const FORWARDER_ABI = [
79
84
  { internalType: "address", name: "token", type: "address" },
80
85
  { internalType: "address", name: "to", type: "address" },
81
86
  { internalType: "uint256", name: "amount", type: "uint256" },
87
+ {
88
+ internalType: "bool",
89
+ name: "sendToCounterfactualWallet",
90
+ type: "bool",
91
+ },
82
92
  { internalType: "string", name: "message", type: "string" },
83
93
  ],
84
94
  name: "forward",
@@ -86,6 +96,19 @@ const FORWARDER_ABI = [
86
96
  stateMutability: "nonpayable",
87
97
  type: "function",
88
98
  },
99
+ {
100
+ inputs: [],
101
+ name: "i_CFHFactory",
102
+ outputs: [
103
+ {
104
+ internalType: "contract CounterfactualHolderFactory",
105
+ name: "",
106
+ type: "address",
107
+ },
108
+ ],
109
+ stateMutability: "view",
110
+ type: "function",
111
+ },
89
112
  {
90
113
  inputs: [],
91
114
  name: "i_USDC",
@@ -111,6 +134,11 @@ const FORWARDER_ABI = [
111
134
  inputs: [
112
135
  { internalType: "uint256", name: "amount", type: "uint256" },
113
136
  { internalType: "address", name: "to", type: "address" },
137
+ {
138
+ internalType: "bool",
139
+ name: "sendToCounterfactualWallet",
140
+ type: "bool",
141
+ },
114
142
  { internalType: "string", name: "message", type: "string" },
115
143
  ],
116
144
  name: "swapUSDCAndForwardUSDG",
@@ -194,7 +222,7 @@ const sepoliaAddresses = {
194
222
  USDC: "0x93c898be98cd2618ba84a6dccf5003d3bbe40356",
195
223
  USDG_UNISWAP: "0x2a085A3aEA8982396533327c854753Ce521B666d",
196
224
  GLW_UNISWAP: "0x8e27016D0B866a56CE74A1a280c749dD679bb0Fa",
197
- FORWARDER: "0x1fb285dDFCbC0456d655F8DC7C637E33c5568858",
225
+ FORWARDER: "0xDaC24F18171224eeaf6a9B38f5C5081aDbDff969",
198
226
  FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
199
227
  UNISWAP_V2_ROUTER: "0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3",
200
228
  UNISWAP_V2_FACTORY: "0xF62c03E08ada871A0bEb309762E260a7a6a880E6",
@@ -214,9 +242,34 @@ const DECIMALS_BY_TOKEN = {
214
242
  USDC: 6,
215
243
  USDG: 6,
216
244
  GCTL: 6,
245
+ SGCTL: 6,
217
246
  GLW: 18,
218
247
  };
219
248
 
249
+ // ---------------------------------------------------------------------------
250
+ // Common / Shared Types
251
+ // ---------------------------------------------------------------------------
252
+ const PAYMENT_CURRENCIES = [
253
+ "GCTL",
254
+ "USDC",
255
+ "USDG",
256
+ "GLW",
257
+ "SGCTL",
258
+ ];
259
+ const OFF_CHAIN_PAYMENT_CURRENCIES = ["SGCTL", "GCTL"];
260
+ const TRANSFER_TYPES = {
261
+ PayProtocolFeeAndMintGCTLAndStake: "PayProtocolFeeAndMintGCTLAndStake",
262
+ PayProtocolFee: "PayProtocolFee",
263
+ PayAuditFees: "PayAuditFees",
264
+ CommitKickstarter: "CommitKickstarter",
265
+ MintGCTLAndStake: "MintGCTLAndStake",
266
+ MintGCTL: "MintGCTL",
267
+ BuySolarFarm: "BuySolarFarm",
268
+ SponsorProtocolFee: "SponsorProtocolFee",
269
+ SponsorProtocolFeeAndMintGCTLAndStake: "SponsorProtocolFeeAndMintGCTLAndStake",
270
+ PayProtocolDepositUsingStakedControl: "PayProtocolDepositUsingStakedControl",
271
+ };
272
+
220
273
  exports.ForwarderError = void 0;
221
274
  (function (ForwarderError) {
222
275
  ForwarderError["CONTRACT_NOT_AVAILABLE"] = "Contract not available";
@@ -277,47 +330,47 @@ function useForwarder(signer, CHAIN_ID) {
277
330
  function constructForwardMessage(params) {
278
331
  const { type, applicationId, farmId, regionId, userAddress, kickstarterId, } = params;
279
332
  switch (type) {
280
- case "PayProtocolFeeAndMintGCTLAndStake":
333
+ case TRANSFER_TYPES.PayProtocolFeeAndMintGCTLAndStake:
281
334
  if (!applicationId) {
282
335
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
283
336
  }
284
337
  return `PayProtocolFeeAndMintGCTLAndStake::${applicationId}`;
285
- case "PayProtocolFee":
338
+ case TRANSFER_TYPES.PayProtocolFee:
286
339
  if (!applicationId) {
287
340
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
288
341
  }
289
342
  return `PayProtocolFee::${applicationId}`;
290
- case "SponsorProtocolFee":
343
+ case TRANSFER_TYPES.SponsorProtocolFee:
291
344
  if (!applicationId) {
292
345
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
293
346
  }
294
347
  return `SponsorProtocolFee::${applicationId}`;
295
- case "SponsorProtocolFeeAndMintGCTLAndStake":
348
+ case TRANSFER_TYPES.SponsorProtocolFeeAndMintGCTLAndStake:
296
349
  if (!applicationId) {
297
350
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
298
351
  }
299
352
  return `SponsorProtocolFeeAndMintGCTLAndStake::${applicationId}`;
300
- case "MintGCTLAndStake":
353
+ case TRANSFER_TYPES.MintGCTLAndStake:
301
354
  if (!regionId) {
302
355
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
303
356
  }
304
357
  return `MintGCTLAndStake::${regionId}`;
305
- case "MintGCTL":
358
+ case TRANSFER_TYPES.MintGCTL:
306
359
  if (!userAddress) {
307
360
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
308
361
  }
309
362
  return `MintGCTL::${userAddress}`;
310
- case "BuySolarFarm":
363
+ case TRANSFER_TYPES.BuySolarFarm:
311
364
  if (!farmId) {
312
365
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
313
366
  }
314
367
  return `BuySolarFarm::${farmId}`;
315
- case "PayAuditFees":
368
+ case TRANSFER_TYPES.PayAuditFees:
316
369
  if (!applicationId) {
317
370
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
318
371
  }
319
372
  return `PayAuditFees::${applicationId}`;
320
- case "CommitKickstarter":
373
+ case TRANSFER_TYPES.CommitKickstarter:
321
374
  if (!kickstarterId) {
322
375
  throw new Error(exports.ForwarderError.MISSING_REQUIRED_PARAMS);
323
376
  }
@@ -426,12 +479,12 @@ function useForwarder(signer, CHAIN_ID) {
426
479
  // Construct the appropriate message for this forward type
427
480
  const message = constructForwardMessage(params);
428
481
  // Special handling: PayAuditFees can ONLY be USDC, and must call forward()
429
- const isAuditFees = params.type === "PayAuditFees";
482
+ const isAuditFees = params.type === TRANSFER_TYPES.PayAuditFees;
430
483
  if (isAuditFees && currency !== "USDC") {
431
484
  throw new Error("PayAuditFees only supports USDC");
432
485
  }
433
486
  // CommitKickstarter supports only USDC or USDG (GLW not allowed)
434
- const isCommitKickstarter = params.type === "CommitKickstarter";
487
+ const isCommitKickstarter = params.type === TRANSFER_TYPES.CommitKickstarter;
435
488
  if (isCommitKickstarter && currency === "GLW") {
436
489
  throw new Error("CommitKickstarter supports only USDC or USDG");
437
490
  }
@@ -467,7 +520,7 @@ function useForwarder(signer, CHAIN_ID) {
467
520
  if (!isAuditFees && currency === "USDC") {
468
521
  await forwarderContract
469
522
  .getFunction("swapUSDCAndForwardUSDG")
470
- .staticCall(amount, ADDRESSES.FOUNDATION_WALLET, message, {
523
+ .staticCall(amount, ADDRESSES.FOUNDATION_WALLET, true, message, {
471
524
  from: owner,
472
525
  });
473
526
  }
@@ -476,7 +529,7 @@ function useForwarder(signer, CHAIN_ID) {
476
529
  .getFunction("forward")
477
530
  .staticCall(tokenAddress, isAuditFees
478
531
  ? ADDRESSES.AUDIT_FEE_WALLET
479
- : ADDRESSES.FOUNDATION_WALLET, amount, message, { from: owner });
532
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message, { from: owner });
480
533
  }
481
534
  }
482
535
  catch (staticError) {
@@ -485,12 +538,12 @@ function useForwarder(signer, CHAIN_ID) {
485
538
  // Execute the forward transaction
486
539
  let tx;
487
540
  if (!isAuditFees && currency === "USDC") {
488
- tx = await forwarderContract.getFunction("swapUSDCAndForwardUSDG")(amount, ADDRESSES.FOUNDATION_WALLET, message);
541
+ tx = await forwarderContract.getFunction("swapUSDCAndForwardUSDG")(amount, ADDRESSES.FOUNDATION_WALLET, true, message);
489
542
  }
490
543
  else {
491
544
  tx = await forwarderContract.getFunction("forward")(tokenAddress, isAuditFees
492
545
  ? ADDRESSES.AUDIT_FEE_WALLET
493
- : ADDRESSES.FOUNDATION_WALLET, amount, message);
546
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message);
494
547
  }
495
548
  await tx.wait();
496
549
  return tx.hash;
@@ -514,7 +567,7 @@ function useForwarder(signer, CHAIN_ID) {
514
567
  return forwardTokens({
515
568
  amount,
516
569
  userAddress,
517
- type: "PayProtocolFeeAndMintGCTLAndStake",
570
+ type: TRANSFER_TYPES.PayProtocolFeeAndMintGCTLAndStake,
518
571
  currency,
519
572
  applicationId,
520
573
  regionId,
@@ -531,7 +584,7 @@ function useForwarder(signer, CHAIN_ID) {
531
584
  return forwardTokens({
532
585
  amount,
533
586
  userAddress,
534
- type: "SponsorProtocolFeeAndMintGCTLAndStake",
587
+ type: TRANSFER_TYPES.SponsorProtocolFeeAndMintGCTLAndStake,
535
588
  currency,
536
589
  applicationId,
537
590
  });
@@ -544,7 +597,7 @@ function useForwarder(signer, CHAIN_ID) {
544
597
  return forwardTokens({
545
598
  amount,
546
599
  userAddress,
547
- type: "PayProtocolFee",
600
+ type: TRANSFER_TYPES.PayProtocolFee,
548
601
  currency,
549
602
  applicationId,
550
603
  });
@@ -557,7 +610,7 @@ function useForwarder(signer, CHAIN_ID) {
557
610
  return forwardTokens({
558
611
  amount,
559
612
  userAddress,
560
- type: "SponsorProtocolFee",
613
+ type: TRANSFER_TYPES.SponsorProtocolFee,
561
614
  currency,
562
615
  applicationId,
563
616
  });
@@ -574,7 +627,7 @@ function useForwarder(signer, CHAIN_ID) {
574
627
  return forwardTokens({
575
628
  amount,
576
629
  userAddress,
577
- type: "MintGCTLAndStake",
630
+ type: TRANSFER_TYPES.MintGCTLAndStake,
578
631
  currency,
579
632
  regionId,
580
633
  });
@@ -591,7 +644,7 @@ function useForwarder(signer, CHAIN_ID) {
591
644
  return forwardTokens({
592
645
  amount,
593
646
  userAddress,
594
- type: "MintGCTL",
647
+ type: TRANSFER_TYPES.MintGCTL,
595
648
  currency,
596
649
  });
597
650
  }
@@ -603,7 +656,7 @@ function useForwarder(signer, CHAIN_ID) {
603
656
  return forwardTokens({
604
657
  amount,
605
658
  userAddress,
606
- type: "PayAuditFees",
659
+ type: TRANSFER_TYPES.PayAuditFees,
607
660
  currency: "USDC",
608
661
  applicationId,
609
662
  });
@@ -616,7 +669,7 @@ function useForwarder(signer, CHAIN_ID) {
616
669
  return forwardTokens({
617
670
  amount,
618
671
  userAddress,
619
- type: "BuySolarFarm",
672
+ type: TRANSFER_TYPES.BuySolarFarm,
620
673
  currency,
621
674
  farmId,
622
675
  });
@@ -632,7 +685,7 @@ function useForwarder(signer, CHAIN_ID) {
632
685
  return forwardTokens({
633
686
  amount,
634
687
  userAddress,
635
- type: "CommitKickstarter",
688
+ type: TRANSFER_TYPES.CommitKickstarter,
636
689
  currency,
637
690
  kickstarterId,
638
691
  });
@@ -649,7 +702,7 @@ function useForwarder(signer, CHAIN_ID) {
649
702
  if (!forwarderContract)
650
703
  throw new Error(exports.ForwarderError.CONTRACT_NOT_AVAILABLE);
651
704
  const { amount, currency = "USDC" } = params;
652
- const isAuditFees = params.type === "PayAuditFees";
705
+ const isAuditFees = params.type === TRANSFER_TYPES.PayAuditFees;
653
706
  if (isAuditFees && currency !== "USDC") {
654
707
  throw new Error("PayAuditFees only supports USDC");
655
708
  }
@@ -678,12 +731,12 @@ function useForwarder(signer, CHAIN_ID) {
678
731
  const estimatedGas = !isAuditFees && currency === "USDC"
679
732
  ? await forwarderContract
680
733
  .getFunction("swapUSDCAndForwardUSDG")
681
- .estimateGas(amount, ADDRESSES.FOUNDATION_WALLET, message)
734
+ .estimateGas(amount, ADDRESSES.FOUNDATION_WALLET, true, message)
682
735
  : await forwarderContract
683
736
  .getFunction("forward")
684
737
  .estimateGas(tokenAddress, isAuditFees
685
738
  ? ADDRESSES.AUDIT_FEE_WALLET
686
- : ADDRESSES.FOUNDATION_WALLET, amount, message);
739
+ : ADDRESSES.FOUNDATION_WALLET, amount, true, message);
687
740
  const estimatedCost = estimatedGas * gasPrice;
688
741
  if (ethPriceInUSD) {
689
742
  const estimatedCostInEth = viem.formatEther(estimatedCost);
@@ -932,6 +985,7 @@ function ControlRouter(baseUrl) {
932
985
  let isUnstaking = false;
933
986
  let isRestaking = false;
934
987
  let isRetryingFailedOperation = false;
988
+ let isPayingProtocolDepositUsingStakedControl = false;
935
989
  const stakeGctl = async (stakeRequest) => {
936
990
  isStaking = true;
937
991
  try {
@@ -999,6 +1053,23 @@ function ControlRouter(baseUrl) {
999
1053
  isRetryingFailedOperation = false;
1000
1054
  }
1001
1055
  };
1056
+ const payProtocolDepositUsingStakedControl = async (paymentRequest) => {
1057
+ isPayingProtocolDepositUsingStakedControl = true;
1058
+ try {
1059
+ const response = await request(`/pay-protocol-deposit-staked`, {
1060
+ method: "POST",
1061
+ headers: { "Content-Type": "application/json" },
1062
+ body: JSON.stringify(paymentRequest),
1063
+ });
1064
+ return response;
1065
+ }
1066
+ catch (error) {
1067
+ throw new Error(parseApiError$4(error));
1068
+ }
1069
+ finally {
1070
+ isPayingProtocolDepositUsingStakedControl = false;
1071
+ }
1072
+ };
1002
1073
  // --------------------------- Public API ----------------------------------
1003
1074
  return {
1004
1075
  // Queries
@@ -1021,6 +1092,7 @@ function ControlRouter(baseUrl) {
1021
1092
  unstakeGctl,
1022
1093
  restakeGctl,
1023
1094
  retryFailedOperation,
1095
+ payProtocolDepositUsingStakedControl,
1024
1096
  // Processing flags
1025
1097
  get isStaking() {
1026
1098
  return isStaking;
@@ -1034,6 +1106,9 @@ function ControlRouter(baseUrl) {
1034
1106
  get isRetryingFailedOperation() {
1035
1107
  return isRetryingFailedOperation;
1036
1108
  },
1109
+ get isPayingProtocolDepositUsingStakedControl() {
1110
+ return isPayingProtocolDepositUsingStakedControl;
1111
+ },
1037
1112
  };
1038
1113
  }
1039
1114
 
@@ -2094,7 +2169,10 @@ exports.GLOW_WEIGHT_DECIMAL_PRECISION = GLOW_WEIGHT_DECIMAL_PRECISION;
2094
2169
  exports.HUB_URL = HUB_URL;
2095
2170
  exports.KickstarterRouter = KickstarterRouter;
2096
2171
  exports.MAX_WEIGHT = MAX_WEIGHT;
2172
+ exports.OFF_CHAIN_PAYMENT_CURRENCIES = OFF_CHAIN_PAYMENT_CURRENCIES;
2173
+ exports.PAYMENT_CURRENCIES = PAYMENT_CURRENCIES;
2097
2174
  exports.RegionRouter = RegionRouter;
2175
+ exports.TRANSFER_TYPES = TRANSFER_TYPES;
2098
2176
  exports.USDG_WEIGHT_DECIMAL_PRECISION = USDG_WEIGHT_DECIMAL_PRECISION;
2099
2177
  exports.WalletsRouter = WalletsRouter;
2100
2178
  exports.allRegions = allRegions;
@@ -2103,4 +2181,4 @@ exports.getAddresses = getAddresses;
2103
2181
  exports.regionMetadata = regionMetadata;
2104
2182
  exports.usStates = usStates;
2105
2183
  exports.useForwarder = useForwarder;
2106
- //# sourceMappingURL=farms-router-ClIWm9AQ.js.map
2184
+ //# sourceMappingURL=farms-router-pMZv3N9H.js.map