@glowlabs-org/utils 0.2.95 → 0.2.97

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.
Files changed (34) hide show
  1. package/dist/cjs/browser.d.ts +1 -0
  2. package/dist/cjs/browser.js +6 -1
  3. package/dist/cjs/browser.js.map +1 -1
  4. package/dist/cjs/constants/addresses.d.ts +1 -1
  5. package/dist/cjs/{farms-router-DCCy-acA.js → farms-router-CDsqKkP6.js} +1093 -210
  6. package/dist/cjs/farms-router-CDsqKkP6.js.map +1 -0
  7. package/dist/cjs/index.d.ts +1 -0
  8. package/dist/cjs/index.js +2 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/lib/abis/offchainFractions.d.ts +473 -0
  11. package/dist/cjs/lib/control-api/farms-router.d.ts +2 -1
  12. package/dist/cjs/lib/hooks/use-offchain-fractions.d.ts +60 -0
  13. package/dist/cjs/lib/types/index.d.ts +64 -0
  14. package/dist/esm/browser.d.ts +1 -0
  15. package/dist/esm/browser.js +2 -2
  16. package/dist/esm/constants/addresses.d.ts +1 -1
  17. package/dist/esm/{farms-router-XDjQOQ-c.js → farms-router-Da1P3B8g.js} +1093 -211
  18. package/dist/esm/farms-router-Da1P3B8g.js.map +1 -0
  19. package/dist/esm/index.d.ts +1 -0
  20. package/dist/esm/index.js +2 -2
  21. package/dist/esm/lib/abis/offchainFractions.d.ts +473 -0
  22. package/dist/esm/lib/control-api/farms-router.d.ts +2 -1
  23. package/dist/esm/lib/hooks/use-offchain-fractions.d.ts +60 -0
  24. package/dist/esm/lib/types/index.d.ts +64 -0
  25. package/package.json +1 -1
  26. package/src/browser.ts +1 -0
  27. package/src/constants/addresses.ts +7 -1
  28. package/src/index.ts +1 -0
  29. package/src/lib/abis/offchainFractions.ts +332 -0
  30. package/src/lib/control-api/farms-router.ts +37 -2
  31. package/src/lib/hooks/use-offchain-fractions.ts +737 -0
  32. package/src/lib/types/index.ts +69 -0
  33. package/dist/cjs/farms-router-DCCy-acA.js.map +0 -1
  34. package/dist/esm/farms-router-XDjQOQ-c.js.map +0 -1
@@ -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;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
 
3
- import type { SponsoredFarm } from "../types";
4
- import type { SponsoredFarmsResponse } from "../types";
3
+ import type {
4
+ SponsoredFarm,
5
+ SponsoredFarmsResponse,
6
+ EstimateRewardScoreParams,
7
+ RewardScoreResponse,
8
+ EstimateRewardScoreApiResponse,
9
+ EstimateRewardScoreErrorResponse,
10
+ } from "../types";
5
11
 
6
12
  function parseApiError(error: unknown): string {
7
13
  if (!error) return "Unknown error";
@@ -38,7 +44,36 @@ export function FarmsRouter(baseUrl: string) {
38
44
  }
39
45
  };
40
46
 
47
+ const estimateRewardScore = async (
48
+ params: EstimateRewardScoreParams
49
+ ): Promise<RewardScoreResponse> => {
50
+ try {
51
+ // First try to get the success response
52
+ const data = await request<
53
+ EstimateRewardScoreApiResponse | EstimateRewardScoreErrorResponse
54
+ >("/farms/estimate-reward-score", {
55
+ method: "POST",
56
+ headers: {
57
+ "Content-Type": "application/json",
58
+ },
59
+ body: JSON.stringify(params),
60
+ });
61
+
62
+ // Check if it's an error response
63
+ if ("error" in data) {
64
+ throw new Error(data.error);
65
+ }
66
+
67
+ // At this point, TypeScript knows it's EstimateRewardScoreApiResponse
68
+ // All fields are required in the success response based on the API spec
69
+ return data as RewardScoreResponse;
70
+ } catch (error) {
71
+ throw new Error(parseApiError(error));
72
+ }
73
+ };
74
+
41
75
  return {
42
76
  fetchSponsoredFarms,
77
+ estimateRewardScore,
43
78
  } as const;
44
79
  }