@glowlabs-org/utils 0.2.98 → 0.2.100
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.
- package/dist/cjs/browser.js +1 -1
- package/dist/cjs/{farms-router-CDsqKkP6.js → farms-router-DaFmKLaa.js} +44 -15
- package/dist/cjs/farms-router-DaFmKLaa.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/abis/offchainFractions.d.ts +21 -0
- package/dist/cjs/lib/control-api/farms-router.d.ts +2 -1
- package/dist/cjs/lib/hooks/use-offchain-fractions.d.ts +3 -1
- package/dist/cjs/lib/types/index.d.ts +20 -0
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{farms-router-Da1P3B8g.js → farms-router-CzfB_qrp.js} +44 -15
- package/dist/esm/farms-router-CzfB_qrp.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/abis/offchainFractions.d.ts +21 -0
- package/dist/esm/lib/control-api/farms-router.d.ts +2 -1
- package/dist/esm/lib/hooks/use-offchain-fractions.d.ts +3 -1
- package/dist/esm/lib/types/index.d.ts +20 -0
- package/package.json +1 -1
- package/src/constants/addresses.ts +1 -1
- package/src/lib/abis/offchainFractions.ts +13 -1
- package/src/lib/control-api/farms-router.ts +33 -11
- package/src/lib/hooks/use-offchain-fractions.ts +17 -8
- package/src/lib/types/index.ts +28 -0
- package/dist/cjs/farms-router-CDsqKkP6.js.map +0 -1
- package/dist/esm/farms-router-Da1P3B8g.js.map +0 -1
|
@@ -418,4 +418,24 @@ export interface RewardScoreResponse {
|
|
|
418
418
|
export interface EstimateRewardScoreErrorResponse {
|
|
419
419
|
error: string;
|
|
420
420
|
}
|
|
421
|
+
export interface EstimateRewardScoresBatchParams {
|
|
422
|
+
farms: EstimateRewardScoreParams[];
|
|
423
|
+
}
|
|
424
|
+
export interface BatchRewardScoreSuccessResult {
|
|
425
|
+
success: true;
|
|
426
|
+
data: RewardScoreResponse;
|
|
427
|
+
}
|
|
428
|
+
export interface BatchRewardScoreFailureResult {
|
|
429
|
+
success: false;
|
|
430
|
+
error: string;
|
|
431
|
+
farmData: {
|
|
432
|
+
userId: string;
|
|
433
|
+
regionId: number;
|
|
434
|
+
paymentCurrency: string;
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
export type BatchRewardScoreResult = BatchRewardScoreSuccessResult | BatchRewardScoreFailureResult;
|
|
438
|
+
export interface EstimateRewardScoresBatchResponse {
|
|
439
|
+
results: BatchRewardScoreResult[];
|
|
440
|
+
}
|
|
421
441
|
export type { MintedEvent as ControlMintedEvent };
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TRANSFER_TYPES } from './farms-router-
|
|
2
|
-
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, g as FORWARDER_ABI, F as FarmsRouter, b as ForwarderError, i as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, K as KickstarterRouter, M as MAX_WEIGHT, c as OFF_CHAIN_PAYMENT_CURRENCIES, O as OffchainFractionsError, P as PAYMENT_CURRENCIES, R as RegionRouter, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, d as allRegions, f as countries, h as getAddresses, r as regionMetadata, e as usStates, u as useForwarder, a as useOffchainFractions } from './farms-router-
|
|
1
|
+
import { T as TRANSFER_TYPES } from './farms-router-CzfB_qrp.js';
|
|
2
|
+
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, g as FORWARDER_ABI, F as FarmsRouter, b as ForwarderError, i as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, K as KickstarterRouter, M as MAX_WEIGHT, c as OFF_CHAIN_PAYMENT_CURRENCIES, O as OffchainFractionsError, P as PAYMENT_CURRENCIES, R as RegionRouter, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, d as allRegions, f as countries, h as getAddresses, r as regionMetadata, e as usStates, u as useForwarder, a as useOffchainFractions } from './farms-router-CzfB_qrp.js';
|
|
3
3
|
import { verifyTypedData, getAddress } from 'viem';
|
|
4
4
|
import 'ethers';
|
|
5
5
|
|
|
@@ -223,7 +223,7 @@ const sepoliaAddresses = {
|
|
|
223
223
|
USDG_UNISWAP: "0x2a085A3aEA8982396533327c854753Ce521B666d",
|
|
224
224
|
GLW_UNISWAP: "0x8e27016D0B866a56CE74A1a280c749dD679bb0Fa",
|
|
225
225
|
FORWARDER: "0xDaC24F18171224eeaf6a9B38f5C5081aDbDff969",
|
|
226
|
-
OFFCHAIN_FRACTIONS: "
|
|
226
|
+
OFFCHAIN_FRACTIONS: "0x0095F2F0C7bbEEd97eCF058D28a8b768Ece32Ac3",
|
|
227
227
|
COUNTERFACTUAL_HOLDER_FACTORY: "0x2c3AB887746F6f4a8a4b9Db6aC800eb71945509A",
|
|
228
228
|
FOUNDATION_WALLET: "0x5e230FED487c86B90f6508104149F087d9B1B0A7",
|
|
229
229
|
UNISWAP_V2_ROUTER: "0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3",
|
|
@@ -862,6 +862,7 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
862
862
|
{ inputs: [], name: "MinSharesCannotBeGreaterThanTotalSteps", type: "error" },
|
|
863
863
|
{ inputs: [], name: "NoStepsPurchased", type: "error" },
|
|
864
864
|
{ inputs: [], name: "NotAllOrNothing", type: "error" },
|
|
865
|
+
{ inputs: [], name: "NotFractionsCloser", type: "error" },
|
|
865
866
|
{ inputs: [], name: "NotFractionsOwner", type: "error" },
|
|
866
867
|
{ inputs: [], name: "RecipientCannotBeSelf", type: "error" },
|
|
867
868
|
{ inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
|
|
@@ -941,6 +942,12 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
941
942
|
name: "minSharesToRaise",
|
|
942
943
|
type: "uint256",
|
|
943
944
|
},
|
|
945
|
+
{
|
|
946
|
+
indexed: false,
|
|
947
|
+
internalType: "address",
|
|
948
|
+
name: "closer",
|
|
949
|
+
type: "address",
|
|
950
|
+
},
|
|
944
951
|
],
|
|
945
952
|
name: "FractionCreated",
|
|
946
953
|
type: "event",
|
|
@@ -1061,7 +1068,10 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1061
1068
|
type: "function",
|
|
1062
1069
|
},
|
|
1063
1070
|
{
|
|
1064
|
-
inputs: [
|
|
1071
|
+
inputs: [
|
|
1072
|
+
{ internalType: "address", name: "creator", type: "address" },
|
|
1073
|
+
{ internalType: "bytes32", name: "id", type: "bytes32" },
|
|
1074
|
+
],
|
|
1065
1075
|
name: "closeFraction",
|
|
1066
1076
|
outputs: [],
|
|
1067
1077
|
stateMutability: "nonpayable",
|
|
@@ -1077,6 +1087,7 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1077
1087
|
{ internalType: "address", name: "to", type: "address" },
|
|
1078
1088
|
{ internalType: "bool", name: "useCounterfactualAddress", type: "bool" },
|
|
1079
1089
|
{ internalType: "uint256", name: "minSharesToRaise", type: "uint256" },
|
|
1090
|
+
{ internalType: "address", name: "closer", type: "address" },
|
|
1080
1091
|
],
|
|
1081
1092
|
name: "createFraction",
|
|
1082
1093
|
outputs: [],
|
|
@@ -1115,6 +1126,7 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1115
1126
|
{ internalType: "address", name: "to", type: "address" },
|
|
1116
1127
|
{ internalType: "uint256", name: "soldSteps", type: "uint256" },
|
|
1117
1128
|
{ internalType: "uint256", name: "totalSteps", type: "uint256" },
|
|
1129
|
+
{ internalType: "address", name: "closer", type: "address" },
|
|
1118
1130
|
],
|
|
1119
1131
|
internalType: "struct OffchainFractions.FractionData",
|
|
1120
1132
|
name: "",
|
|
@@ -1285,7 +1297,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1285
1297
|
if (!contract)
|
|
1286
1298
|
throw new Error(OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1287
1299
|
setIsProcessing(true);
|
|
1288
|
-
const { id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, } = params;
|
|
1300
|
+
const { id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, closer, } = params;
|
|
1289
1301
|
// Validate parameters
|
|
1290
1302
|
if (!id || !token || !to) {
|
|
1291
1303
|
throw new Error(OffchainFractionsError.INVALID_PARAMETERS);
|
|
@@ -1300,13 +1312,13 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1300
1312
|
try {
|
|
1301
1313
|
await contract
|
|
1302
1314
|
.getFunction("createFraction")
|
|
1303
|
-
.staticCall(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise);
|
|
1315
|
+
.staticCall(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, closer);
|
|
1304
1316
|
}
|
|
1305
1317
|
catch (staticError) {
|
|
1306
1318
|
throw new Error(parseEthersError(staticError));
|
|
1307
1319
|
}
|
|
1308
1320
|
// Execute the transaction
|
|
1309
|
-
const tx = await contract.getFunction("createFraction")(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise);
|
|
1321
|
+
const tx = await contract.getFunction("createFraction")(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, closer);
|
|
1310
1322
|
await tx.wait();
|
|
1311
1323
|
return tx.hash;
|
|
1312
1324
|
}
|
|
@@ -1419,10 +1431,11 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1419
1431
|
}
|
|
1420
1432
|
}
|
|
1421
1433
|
/**
|
|
1422
|
-
* Close a fraction sale manually (only by
|
|
1434
|
+
* Close a fraction sale manually (only by closer)
|
|
1435
|
+
* @param creator The address that created the fraction sale
|
|
1423
1436
|
* @param id The unique identifier of the fraction sale to close
|
|
1424
1437
|
*/
|
|
1425
|
-
async function closeFraction(id) {
|
|
1438
|
+
async function closeFraction(creator, id) {
|
|
1426
1439
|
assertSigner(signer);
|
|
1427
1440
|
try {
|
|
1428
1441
|
const contract = getOffchainFractionsContract();
|
|
@@ -1430,13 +1443,13 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1430
1443
|
throw new Error(OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1431
1444
|
setIsProcessing(true);
|
|
1432
1445
|
// Validate parameters
|
|
1433
|
-
if (!id) {
|
|
1446
|
+
if (!creator || !id) {
|
|
1434
1447
|
throw new Error(OffchainFractionsError.INVALID_PARAMETERS);
|
|
1435
1448
|
}
|
|
1436
1449
|
const owner = await signer.getAddress();
|
|
1437
1450
|
// Run a static call first to surface any revert reason
|
|
1438
1451
|
try {
|
|
1439
|
-
await contract.getFunction("closeFraction").staticCall(id, {
|
|
1452
|
+
await contract.getFunction("closeFraction").staticCall(creator, id, {
|
|
1440
1453
|
from: owner,
|
|
1441
1454
|
});
|
|
1442
1455
|
}
|
|
@@ -1444,7 +1457,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1444
1457
|
throw new Error(parseEthersError(staticError));
|
|
1445
1458
|
}
|
|
1446
1459
|
// Execute the transaction
|
|
1447
|
-
const tx = await contract.getFunction("closeFraction")(id);
|
|
1460
|
+
const tx = await contract.getFunction("closeFraction")(creator, id);
|
|
1448
1461
|
await tx.wait();
|
|
1449
1462
|
return tx.hash;
|
|
1450
1463
|
}
|
|
@@ -1479,6 +1492,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1479
1492
|
to: result.to,
|
|
1480
1493
|
soldSteps: result.soldSteps,
|
|
1481
1494
|
totalSteps: result.totalSteps,
|
|
1495
|
+
closer: result.closer,
|
|
1482
1496
|
};
|
|
1483
1497
|
}
|
|
1484
1498
|
catch (error) {
|
|
@@ -1585,7 +1599,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1585
1599
|
const contract = getOffchainFractionsContract();
|
|
1586
1600
|
if (!contract)
|
|
1587
1601
|
throw new Error(OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1588
|
-
const { id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, } = params;
|
|
1602
|
+
const { id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, closer, } = params;
|
|
1589
1603
|
const feeData = await signer.provider?.getFeeData();
|
|
1590
1604
|
const gasPrice = feeData?.gasPrice ?? feeData?.maxFeePerGas ?? 0n;
|
|
1591
1605
|
if (gasPrice === 0n) {
|
|
@@ -1593,7 +1607,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1593
1607
|
}
|
|
1594
1608
|
const estimatedGas = await contract
|
|
1595
1609
|
.getFunction("createFraction")
|
|
1596
|
-
.estimateGas(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise);
|
|
1610
|
+
.estimateGas(id, token, step, totalSteps, expiration, to, useCounterfactualAddress, minSharesToRaise, closer);
|
|
1597
1611
|
const estimatedCost = estimatedGas * gasPrice;
|
|
1598
1612
|
if (ethPriceInUSD) {
|
|
1599
1613
|
const estimatedCostInEth = formatEther(estimatedCost);
|
|
@@ -3018,7 +3032,6 @@ function FarmsRouter(baseUrl) {
|
|
|
3018
3032
|
};
|
|
3019
3033
|
const estimateRewardScore = async (params) => {
|
|
3020
3034
|
try {
|
|
3021
|
-
// First try to get the success response
|
|
3022
3035
|
const data = await request("/farms/estimate-reward-score", {
|
|
3023
3036
|
method: "POST",
|
|
3024
3037
|
headers: {
|
|
@@ -3030,7 +3043,7 @@ function FarmsRouter(baseUrl) {
|
|
|
3030
3043
|
if ("error" in data) {
|
|
3031
3044
|
throw new Error(data.error);
|
|
3032
3045
|
}
|
|
3033
|
-
// At this point, TypeScript knows it's
|
|
3046
|
+
// At this point, TypeScript knows it's RewardScoreResponse
|
|
3034
3047
|
// All fields are required in the success response based on the API spec
|
|
3035
3048
|
return data;
|
|
3036
3049
|
}
|
|
@@ -3038,11 +3051,27 @@ function FarmsRouter(baseUrl) {
|
|
|
3038
3051
|
throw new Error(parseApiError(error));
|
|
3039
3052
|
}
|
|
3040
3053
|
};
|
|
3054
|
+
const estimateRewardScoresBatch = async (params) => {
|
|
3055
|
+
try {
|
|
3056
|
+
const data = await request("/farms/estimate-reward-scores-batch", {
|
|
3057
|
+
method: "POST",
|
|
3058
|
+
headers: {
|
|
3059
|
+
"Content-Type": "application/json",
|
|
3060
|
+
},
|
|
3061
|
+
body: JSON.stringify(params),
|
|
3062
|
+
});
|
|
3063
|
+
return data;
|
|
3064
|
+
}
|
|
3065
|
+
catch (error) {
|
|
3066
|
+
throw new Error(parseApiError(error));
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3041
3069
|
return {
|
|
3042
3070
|
fetchSponsoredFarms,
|
|
3043
3071
|
estimateRewardScore,
|
|
3072
|
+
estimateRewardScoresBatch,
|
|
3044
3073
|
};
|
|
3045
3074
|
}
|
|
3046
3075
|
|
|
3047
3076
|
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, OffchainFractionsError as O, PAYMENT_CURRENCIES as P, RegionRouter as R, TRANSFER_TYPES as T, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, useOffchainFractions as a, ForwarderError as b, OFF_CHAIN_PAYMENT_CURRENCIES as c, allRegions as d, usStates as e, countries as f, FORWARDER_ABI as g, getAddresses as h, GCA_URLS as i, regionMetadata as r, useForwarder as u };
|
|
3048
|
-
//# sourceMappingURL=farms-router-
|
|
3077
|
+
//# sourceMappingURL=farms-router-CzfB_qrp.js.map
|