@glowlabs-org/utils 0.2.94 → 0.2.96

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,332 @@
1
+ export const OFFCHAIN_FRACTIONS_ABI = [
2
+ {
3
+ inputs: [
4
+ {
5
+ internalType: "contract CounterfactualHolderFactory",
6
+ name: "_counterfactualHolderFactory",
7
+ type: "address",
8
+ },
9
+ ],
10
+ stateMutability: "nonpayable",
11
+ type: "constructor",
12
+ },
13
+ {
14
+ inputs: [{ internalType: "address", name: "target", type: "address" }],
15
+ name: "AddressEmptyCode",
16
+ type: "error",
17
+ },
18
+ {
19
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
20
+ name: "AddressInsufficientBalance",
21
+ type: "error",
22
+ },
23
+ { inputs: [], name: "AlreadyClaimed", type: "error" },
24
+ { inputs: [], name: "AlreadyClosed", type: "error" },
25
+ { inputs: [], name: "AlreadyExists", type: "error" },
26
+ { inputs: [], name: "AlreadySent", type: "error" },
27
+ {
28
+ inputs: [],
29
+ name: "CannotClaimPayoutWhenRoundNotFullyFilled",
30
+ type: "error",
31
+ },
32
+ { inputs: [], name: "CannotClaimRefundWhenNotExpired", type: "error" },
33
+ { inputs: [], name: "CannotClaimRefundWhenRoundFullyFilled", type: "error" },
34
+ { inputs: [], name: "CannotCloseAFullRound", type: "error" },
35
+ { inputs: [], name: "CannotHaveZeroTotalSteps", type: "error" },
36
+ { inputs: [], name: "Expired", type: "error" },
37
+ { inputs: [], name: "FailedInnerCall", type: "error" },
38
+ { inputs: [], name: "InsufficientSharesAvailable", type: "error" },
39
+ { inputs: [], name: "InvalidToAddress", type: "error" },
40
+ { inputs: [], name: "InvalidToken", type: "error" },
41
+ { inputs: [], name: "MinSharesCannotBeGreaterThanTotalSteps", type: "error" },
42
+ { inputs: [], name: "NoStepsPurchased", type: "error" },
43
+ { inputs: [], name: "NotAllOrNothing", type: "error" },
44
+ { inputs: [], name: "NotFractionsOwner", type: "error" },
45
+ { inputs: [], name: "RecipientCannotBeSelf", type: "error" },
46
+ { inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
47
+ {
48
+ inputs: [{ internalType: "address", name: "token", type: "address" }],
49
+ name: "SafeERC20FailedOperation",
50
+ type: "error",
51
+ },
52
+ { inputs: [], name: "StepMustBeGreaterThanZero", type: "error" },
53
+ { inputs: [], name: "TaxTokenNotSupported", type: "error" },
54
+ { inputs: [], name: "TotalRaisedOverflow", type: "error" },
55
+ { inputs: [], name: "ZeroSteps", type: "error" },
56
+ {
57
+ anonymous: false,
58
+ inputs: [
59
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
60
+ {
61
+ indexed: true,
62
+ internalType: "address",
63
+ name: "token",
64
+ type: "address",
65
+ },
66
+ {
67
+ indexed: true,
68
+ internalType: "address",
69
+ name: "owner",
70
+ type: "address",
71
+ },
72
+ ],
73
+ name: "FractionClosed",
74
+ type: "event",
75
+ },
76
+ {
77
+ anonymous: false,
78
+ inputs: [
79
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
80
+ {
81
+ indexed: true,
82
+ internalType: "address",
83
+ name: "token",
84
+ type: "address",
85
+ },
86
+ {
87
+ indexed: true,
88
+ internalType: "address",
89
+ name: "owner",
90
+ type: "address",
91
+ },
92
+ {
93
+ indexed: false,
94
+ internalType: "uint256",
95
+ name: "step",
96
+ type: "uint256",
97
+ },
98
+ {
99
+ indexed: false,
100
+ internalType: "uint256",
101
+ name: "totalSteps",
102
+ type: "uint256",
103
+ },
104
+ {
105
+ indexed: false,
106
+ internalType: "uint48",
107
+ name: "expiration",
108
+ type: "uint48",
109
+ },
110
+ { indexed: false, internalType: "address", name: "to", type: "address" },
111
+ {
112
+ indexed: false,
113
+ internalType: "bool",
114
+ name: "useCounterfactualAddress",
115
+ type: "bool",
116
+ },
117
+ {
118
+ indexed: false,
119
+ internalType: "uint256",
120
+ name: "minSharesToRaise",
121
+ type: "uint256",
122
+ },
123
+ ],
124
+ name: "FractionCreated",
125
+ type: "event",
126
+ },
127
+ {
128
+ anonymous: false,
129
+ inputs: [
130
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
131
+ {
132
+ indexed: true,
133
+ internalType: "address",
134
+ name: "creator",
135
+ type: "address",
136
+ },
137
+ { indexed: true, internalType: "address", name: "user", type: "address" },
138
+ {
139
+ indexed: false,
140
+ internalType: "uint256",
141
+ name: "amount",
142
+ type: "uint256",
143
+ },
144
+ ],
145
+ name: "FractionRefunded",
146
+ type: "event",
147
+ },
148
+ {
149
+ anonymous: false,
150
+ inputs: [
151
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
152
+ {
153
+ indexed: true,
154
+ internalType: "address",
155
+ name: "creator",
156
+ type: "address",
157
+ },
158
+ {
159
+ indexed: true,
160
+ internalType: "address",
161
+ name: "buyer",
162
+ type: "address",
163
+ },
164
+ {
165
+ indexed: false,
166
+ internalType: "uint256",
167
+ name: "step",
168
+ type: "uint256",
169
+ },
170
+ {
171
+ indexed: false,
172
+ internalType: "uint256",
173
+ name: "amount",
174
+ type: "uint256",
175
+ },
176
+ ],
177
+ name: "FractionSold",
178
+ type: "event",
179
+ },
180
+ {
181
+ anonymous: false,
182
+ inputs: [
183
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
184
+ {
185
+ indexed: true,
186
+ internalType: "address",
187
+ name: "creator",
188
+ type: "address",
189
+ },
190
+ {
191
+ indexed: false,
192
+ internalType: "uint256",
193
+ name: "minShares",
194
+ type: "uint256",
195
+ },
196
+ {
197
+ indexed: false,
198
+ internalType: "uint256",
199
+ name: "newTotalSharesSold",
200
+ type: "uint256",
201
+ },
202
+ ],
203
+ name: "MinSharesReached",
204
+ type: "event",
205
+ },
206
+ {
207
+ anonymous: false,
208
+ inputs: [
209
+ { indexed: true, internalType: "bytes32", name: "id", type: "bytes32" },
210
+ {
211
+ indexed: true,
212
+ internalType: "address",
213
+ name: "creator",
214
+ type: "address",
215
+ },
216
+ ],
217
+ name: "RoundFilled",
218
+ type: "event",
219
+ },
220
+ {
221
+ inputs: [
222
+ { internalType: "address", name: "creator", type: "address" },
223
+ { internalType: "bytes32", name: "id", type: "bytes32" },
224
+ { internalType: "uint256", name: "stepsToBuy", type: "uint256" },
225
+ { internalType: "uint256", name: "minStepsToBuy", type: "uint256" },
226
+ ],
227
+ name: "buyFractions",
228
+ outputs: [],
229
+ stateMutability: "nonpayable",
230
+ type: "function",
231
+ },
232
+ {
233
+ inputs: [
234
+ { internalType: "address", name: "creator", type: "address" },
235
+ { internalType: "bytes32", name: "id", type: "bytes32" },
236
+ ],
237
+ name: "claimRefund",
238
+ outputs: [],
239
+ stateMutability: "nonpayable",
240
+ type: "function",
241
+ },
242
+ {
243
+ inputs: [{ internalType: "bytes32", name: "id", type: "bytes32" }],
244
+ name: "closeFraction",
245
+ outputs: [],
246
+ stateMutability: "nonpayable",
247
+ type: "function",
248
+ },
249
+ {
250
+ inputs: [
251
+ { internalType: "bytes32", name: "id", type: "bytes32" },
252
+ { internalType: "address", name: "token", type: "address" },
253
+ { internalType: "uint256", name: "step", type: "uint256" },
254
+ { internalType: "uint256", name: "totalSteps", type: "uint256" },
255
+ { internalType: "uint48", name: "expiration", type: "uint48" },
256
+ { internalType: "address", name: "to", type: "address" },
257
+ { internalType: "bool", name: "useCounterfactualAddress", type: "bool" },
258
+ { internalType: "uint256", name: "minSharesToRaise", type: "uint256" },
259
+ ],
260
+ name: "createFraction",
261
+ outputs: [],
262
+ stateMutability: "nonpayable",
263
+ type: "function",
264
+ },
265
+ {
266
+ inputs: [
267
+ { internalType: "address", name: "creator", type: "address" },
268
+ { internalType: "bytes32", name: "id", type: "bytes32" },
269
+ ],
270
+ name: "getFraction",
271
+ outputs: [
272
+ {
273
+ components: [
274
+ { internalType: "address", name: "token", type: "address" },
275
+ { internalType: "uint48", name: "expiration", type: "uint48" },
276
+ { internalType: "bool", name: "manuallyClosed", type: "bool" },
277
+ {
278
+ internalType: "uint256",
279
+ name: "minSharesToRaise",
280
+ type: "uint256",
281
+ },
282
+ {
283
+ internalType: "bool",
284
+ name: "useCounterfactualAddress",
285
+ type: "bool",
286
+ },
287
+ {
288
+ internalType: "bool",
289
+ name: "claimedFromMinSharesToRaise",
290
+ type: "bool",
291
+ },
292
+ { internalType: "address", name: "owner", type: "address" },
293
+ { internalType: "uint256", name: "step", type: "uint256" },
294
+ { internalType: "address", name: "to", type: "address" },
295
+ { internalType: "uint256", name: "soldSteps", type: "uint256" },
296
+ { internalType: "uint256", name: "totalSteps", type: "uint256" },
297
+ ],
298
+ internalType: "struct OffchainFractions.FractionData",
299
+ name: "",
300
+ type: "tuple",
301
+ },
302
+ ],
303
+ stateMutability: "view",
304
+ type: "function",
305
+ },
306
+ {
307
+ inputs: [],
308
+ name: "i_CFHFactory",
309
+ outputs: [
310
+ {
311
+ internalType: "contract CounterfactualHolderFactory",
312
+ name: "",
313
+ type: "address",
314
+ },
315
+ ],
316
+ stateMutability: "view",
317
+ type: "function",
318
+ },
319
+ {
320
+ inputs: [
321
+ { internalType: "address", name: "user", type: "address" },
322
+ { internalType: "address", name: "creator", type: "address" },
323
+ { internalType: "bytes32", name: "id", type: "bytes32" },
324
+ ],
325
+ name: "stepsPurchased",
326
+ outputs: [
327
+ { internalType: "uint256", name: "stepsPurchased", type: "uint256" },
328
+ ],
329
+ stateMutability: "view",
330
+ type: "function",
331
+ },
332
+ ] as const;
@@ -336,14 +336,24 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
336
336
  throw new Error(`Unsupported currency for forwarding: ${currency}`);
337
337
  }
338
338
 
339
+ // Determine sendToCounterfactualWallet based on currency
340
+ const sendToCounterfactualWallet =
341
+ currency === "GLW" || currency === "USDG";
342
+
339
343
  // Run a static call first to surface any revert reason (ethers v6)
340
344
  try {
341
345
  if (!isAuditFees && currency === "USDC") {
342
346
  await forwarderContract
343
347
  .getFunction("swapUSDCAndForwardUSDG")
344
- .staticCall(amount, ADDRESSES.FOUNDATION_WALLET, true, message, {
345
- from: owner,
346
- });
348
+ .staticCall(
349
+ amount,
350
+ ADDRESSES.FOUNDATION_WALLET,
351
+ sendToCounterfactualWallet,
352
+ message,
353
+ {
354
+ from: owner,
355
+ }
356
+ );
347
357
  } else {
348
358
  await forwarderContract
349
359
  .getFunction("forward")
@@ -353,7 +363,7 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
353
363
  ? ADDRESSES.AUDIT_FEE_WALLET
354
364
  : ADDRESSES.FOUNDATION_WALLET,
355
365
  amount,
356
- true,
366
+ sendToCounterfactualWallet,
357
367
  message,
358
368
  { from: owner }
359
369
  );
@@ -368,7 +378,7 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
368
378
  tx = await forwarderContract.getFunction("swapUSDCAndForwardUSDG")(
369
379
  amount,
370
380
  ADDRESSES.FOUNDATION_WALLET,
371
- true,
381
+ sendToCounterfactualWallet,
372
382
  message
373
383
  );
374
384
  } else {
@@ -378,7 +388,7 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
378
388
  ? ADDRESSES.AUDIT_FEE_WALLET
379
389
  : ADDRESSES.FOUNDATION_WALLET,
380
390
  amount,
381
- true,
391
+ sendToCounterfactualWallet,
382
392
  message
383
393
  );
384
394
  }
@@ -626,6 +636,10 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
626
636
  // Construct the appropriate message for this forward type
627
637
  const message = constructForwardMessage(params);
628
638
 
639
+ // Determine sendToCounterfactualWallet based on currency
640
+ const sendToCounterfactualWallet =
641
+ currency === "GLW" || currency === "USDG";
642
+
629
643
  // Get token address
630
644
  let tokenAddress: string;
631
645
  switch (currency) {
@@ -654,7 +668,12 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
654
668
  !isAuditFees && currency === "USDC"
655
669
  ? await forwarderContract
656
670
  .getFunction("swapUSDCAndForwardUSDG")
657
- .estimateGas(amount, ADDRESSES.FOUNDATION_WALLET, true, message)
671
+ .estimateGas(
672
+ amount,
673
+ ADDRESSES.FOUNDATION_WALLET,
674
+ sendToCounterfactualWallet,
675
+ message
676
+ )
658
677
  : await forwarderContract
659
678
  .getFunction("forward")
660
679
  .estimateGas(
@@ -663,7 +682,7 @@ export function useForwarder(signer: Signer | undefined, CHAIN_ID: number) {
663
682
  ? ADDRESSES.AUDIT_FEE_WALLET
664
683
  : ADDRESSES.FOUNDATION_WALLET,
665
684
  amount,
666
- true,
685
+ sendToCounterfactualWallet,
667
686
  message
668
687
  );
669
688
  const estimatedCost: bigint = estimatedGas * gasPrice;