@glowlabs-org/utils 0.2.109 → 0.2.110
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-DuVI7Pig.js → farms-router-DhAOciuN.js} +311 -25
- package/dist/cjs/farms-router-DhAOciuN.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/abis/offchainFractions.d.ts +176 -21
- package/dist/cjs/lib/hooks/use-offchain-fractions.d.ts +14 -2
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{farms-router-Cncy_gI0.js → farms-router-UmqKWCHo.js} +311 -25
- package/dist/esm/farms-router-UmqKWCHo.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/abis/offchainFractions.d.ts +176 -21
- package/dist/esm/lib/hooks/use-offchain-fractions.d.ts +14 -2
- package/package.json +1 -1
- package/src/lib/abis/offchainFractions.ts +129 -12
- package/src/lib/hooks/use-offchain-fractions.ts +290 -17
- package/dist/cjs/farms-router-DuVI7Pig.js.map +0 -1
- package/dist/esm/farms-router-Cncy_gI0.js.map +0 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -850,31 +850,30 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
850
850
|
name: "AddressInsufficientBalance",
|
|
851
851
|
type: "error",
|
|
852
852
|
},
|
|
853
|
-
{ inputs: [], name: "AlreadyClaimed", type: "error" },
|
|
854
853
|
{ inputs: [], name: "AlreadyClosed", type: "error" },
|
|
855
854
|
{ inputs: [], name: "AlreadyExists", type: "error" },
|
|
856
|
-
{ inputs: [], name: "AlreadySent", type: "error" },
|
|
857
|
-
{
|
|
858
|
-
inputs: [],
|
|
859
|
-
name: "CannotClaimPayoutWhenRoundNotFullyFilled",
|
|
860
|
-
type: "error",
|
|
861
|
-
},
|
|
862
855
|
{ inputs: [], name: "CannotClaimRefundWhenNotExpired", type: "error" },
|
|
863
|
-
{ inputs: [], name: "
|
|
864
|
-
{ inputs: [], name: "
|
|
856
|
+
{ inputs: [], name: "CannotClaimRefundWhenThresholdReached", type: "error" },
|
|
857
|
+
{ inputs: [], name: "CannotCloseWhenThresholdReached", type: "error" },
|
|
865
858
|
{ inputs: [], name: "CannotHaveZeroTotalSteps", type: "error" },
|
|
859
|
+
{ inputs: [], name: "ExpirationMustBeInTheFuture", type: "error" },
|
|
866
860
|
{ inputs: [], name: "Expired", type: "error" },
|
|
867
861
|
{ inputs: [], name: "FailedInnerCall", type: "error" },
|
|
868
862
|
{ inputs: [], name: "InsufficientSharesAvailable", type: "error" },
|
|
869
863
|
{ inputs: [], name: "InvalidToAddress", type: "error" },
|
|
870
864
|
{ inputs: [], name: "InvalidToken", type: "error" },
|
|
871
865
|
{ inputs: [], name: "MinSharesCannotBeGreaterThanTotalSteps", type: "error" },
|
|
866
|
+
{
|
|
867
|
+
inputs: [],
|
|
868
|
+
name: "MinStepsToBuyCannotBeGreaterThanStepsToBuy",
|
|
869
|
+
type: "error",
|
|
870
|
+
},
|
|
871
|
+
{ inputs: [], name: "MinStepsToBuyCannotBeZero", type: "error" },
|
|
872
872
|
{ inputs: [], name: "NoStepsPurchased", type: "error" },
|
|
873
|
-
{ inputs: [], name: "NotAllOrNothing", type: "error" },
|
|
874
873
|
{ inputs: [], name: "NotFractionsCloser", type: "error" },
|
|
875
|
-
{ inputs: [], name: "NotFractionsOwner", type: "error" },
|
|
876
874
|
{ inputs: [], name: "RecipientCannotBeSelf", type: "error" },
|
|
877
875
|
{ inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
|
|
876
|
+
{ inputs: [], name: "RefundOperatorNotApproved", type: "error" },
|
|
878
877
|
{
|
|
879
878
|
inputs: [{ internalType: "address", name: "token", type: "address" }],
|
|
880
879
|
name: "SafeERC20FailedOperation",
|
|
@@ -883,6 +882,11 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
883
882
|
{ inputs: [], name: "StepMustBeGreaterThanZero", type: "error" },
|
|
884
883
|
{ inputs: [], name: "TaxTokenNotSupported", type: "error" },
|
|
885
884
|
{ inputs: [], name: "TotalRaisedOverflow", type: "error" },
|
|
885
|
+
{
|
|
886
|
+
inputs: [],
|
|
887
|
+
name: "UseCounterfactualAddressForRefundNotAllowedIfAddressIsZero",
|
|
888
|
+
type: "error",
|
|
889
|
+
},
|
|
886
890
|
{ inputs: [], name: "ZeroSteps", type: "error" },
|
|
887
891
|
{
|
|
888
892
|
anonymous: false,
|
|
@@ -972,6 +976,12 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
972
976
|
type: "address",
|
|
973
977
|
},
|
|
974
978
|
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
979
|
+
{
|
|
980
|
+
indexed: false,
|
|
981
|
+
internalType: "address",
|
|
982
|
+
name: "refundTo",
|
|
983
|
+
type: "address",
|
|
984
|
+
},
|
|
975
985
|
{
|
|
976
986
|
indexed: false,
|
|
977
987
|
internalType: "uint256",
|
|
@@ -995,6 +1005,12 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
995
1005
|
{
|
|
996
1006
|
indexed: true,
|
|
997
1007
|
internalType: "address",
|
|
1008
|
+
name: "creditTo",
|
|
1009
|
+
type: "address",
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
indexed: false,
|
|
1013
|
+
internalType: "address",
|
|
998
1014
|
name: "buyer",
|
|
999
1015
|
type: "address",
|
|
1000
1016
|
},
|
|
@@ -1040,6 +1056,26 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1040
1056
|
name: "MinSharesReached",
|
|
1041
1057
|
type: "event",
|
|
1042
1058
|
},
|
|
1059
|
+
{
|
|
1060
|
+
anonymous: false,
|
|
1061
|
+
inputs: [
|
|
1062
|
+
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
1063
|
+
{
|
|
1064
|
+
indexed: true,
|
|
1065
|
+
internalType: "address",
|
|
1066
|
+
name: "refundOperator",
|
|
1067
|
+
type: "address",
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
indexed: false,
|
|
1071
|
+
internalType: "bool",
|
|
1072
|
+
name: "isApproved",
|
|
1073
|
+
type: "bool",
|
|
1074
|
+
},
|
|
1075
|
+
],
|
|
1076
|
+
name: "RefundOperatorStatusSet",
|
|
1077
|
+
type: "event",
|
|
1078
|
+
},
|
|
1043
1079
|
{
|
|
1044
1080
|
anonymous: false,
|
|
1045
1081
|
inputs: [
|
|
@@ -1054,12 +1090,26 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1054
1090
|
name: "RoundFilled",
|
|
1055
1091
|
type: "event",
|
|
1056
1092
|
},
|
|
1093
|
+
{
|
|
1094
|
+
inputs: [],
|
|
1095
|
+
name: "REFUND_WILDCARD_OPERATOR",
|
|
1096
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
1097
|
+
stateMutability: "view",
|
|
1098
|
+
type: "function",
|
|
1099
|
+
},
|
|
1057
1100
|
{
|
|
1058
1101
|
inputs: [
|
|
1059
1102
|
{ internalType: "address", name: "creator", type: "address" },
|
|
1060
1103
|
{ internalType: "bytes32", name: "id", type: "bytes32" },
|
|
1061
1104
|
{ internalType: "uint256", name: "stepsToBuy", type: "uint256" },
|
|
1062
1105
|
{ internalType: "uint256", name: "minStepsToBuy", type: "uint256" },
|
|
1106
|
+
{ internalType: "address", name: "refundTo", type: "address" },
|
|
1107
|
+
{ internalType: "address", name: "creditTo", type: "address" },
|
|
1108
|
+
{
|
|
1109
|
+
internalType: "bool",
|
|
1110
|
+
name: "useCounterfactualAddressForRefund",
|
|
1111
|
+
type: "bool",
|
|
1112
|
+
},
|
|
1063
1113
|
],
|
|
1064
1114
|
name: "buyFractions",
|
|
1065
1115
|
outputs: [],
|
|
@@ -1068,6 +1118,7 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1068
1118
|
},
|
|
1069
1119
|
{
|
|
1070
1120
|
inputs: [
|
|
1121
|
+
{ internalType: "address", name: "user", type: "address" },
|
|
1071
1122
|
{ internalType: "address", name: "creator", type: "address" },
|
|
1072
1123
|
{ internalType: "bytes32", name: "id", type: "bytes32" },
|
|
1073
1124
|
],
|
|
@@ -1130,7 +1181,6 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1130
1181
|
name: "claimedFromMinSharesToRaise",
|
|
1131
1182
|
type: "bool",
|
|
1132
1183
|
},
|
|
1133
|
-
{ internalType: "address", name: "owner", type: "address" },
|
|
1134
1184
|
{ internalType: "uint256", name: "step", type: "uint256" },
|
|
1135
1185
|
{ internalType: "address", name: "to", type: "address" },
|
|
1136
1186
|
{ internalType: "uint256", name: "soldSteps", type: "uint256" },
|
|
@@ -1145,6 +1195,31 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1145
1195
|
stateMutability: "view",
|
|
1146
1196
|
type: "function",
|
|
1147
1197
|
},
|
|
1198
|
+
{
|
|
1199
|
+
inputs: [
|
|
1200
|
+
{ internalType: "address", name: "user", type: "address" },
|
|
1201
|
+
{ internalType: "address", name: "creator", type: "address" },
|
|
1202
|
+
{ internalType: "bytes32", name: "id", type: "bytes32" },
|
|
1203
|
+
],
|
|
1204
|
+
name: "getRefundDetails",
|
|
1205
|
+
outputs: [
|
|
1206
|
+
{
|
|
1207
|
+
components: [
|
|
1208
|
+
{ internalType: "address", name: "refundTo", type: "address" },
|
|
1209
|
+
{
|
|
1210
|
+
internalType: "bool",
|
|
1211
|
+
name: "useCounterfactualAddress",
|
|
1212
|
+
type: "bool",
|
|
1213
|
+
},
|
|
1214
|
+
],
|
|
1215
|
+
internalType: "struct OffchainFractions.RefundDetails",
|
|
1216
|
+
name: "",
|
|
1217
|
+
type: "tuple",
|
|
1218
|
+
},
|
|
1219
|
+
],
|
|
1220
|
+
stateMutability: "view",
|
|
1221
|
+
type: "function",
|
|
1222
|
+
},
|
|
1148
1223
|
{
|
|
1149
1224
|
inputs: [],
|
|
1150
1225
|
name: "i_CFHFactory",
|
|
@@ -1158,6 +1233,48 @@ const OFFCHAIN_FRACTIONS_ABI = [
|
|
|
1158
1233
|
stateMutability: "view",
|
|
1159
1234
|
type: "function",
|
|
1160
1235
|
},
|
|
1236
|
+
{
|
|
1237
|
+
inputs: [
|
|
1238
|
+
{ internalType: "address", name: "user", type: "address" },
|
|
1239
|
+
{ internalType: "address", name: "refundOperator", type: "address" },
|
|
1240
|
+
],
|
|
1241
|
+
name: "isRefundOperatorApproved",
|
|
1242
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
1243
|
+
stateMutability: "view",
|
|
1244
|
+
type: "function",
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
inputs: [
|
|
1248
|
+
{ internalType: "address", name: "user", type: "address" },
|
|
1249
|
+
{ internalType: "address", name: "refundOperator", type: "address" },
|
|
1250
|
+
],
|
|
1251
|
+
name: "refundApprovals",
|
|
1252
|
+
outputs: [{ internalType: "bool", name: "isApproved", type: "bool" }],
|
|
1253
|
+
stateMutability: "view",
|
|
1254
|
+
type: "function",
|
|
1255
|
+
},
|
|
1256
|
+
{
|
|
1257
|
+
inputs: [
|
|
1258
|
+
{ internalType: "address", name: "creator", type: "address" },
|
|
1259
|
+
{ internalType: "bytes32", name: "id", type: "bytes32" },
|
|
1260
|
+
{ internalType: "address", name: "refundTo", type: "address" },
|
|
1261
|
+
{ internalType: "bool", name: "useCounterfactualAddress", type: "bool" },
|
|
1262
|
+
],
|
|
1263
|
+
name: "setRefundDetails",
|
|
1264
|
+
outputs: [],
|
|
1265
|
+
stateMutability: "nonpayable",
|
|
1266
|
+
type: "function",
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
inputs: [
|
|
1270
|
+
{ internalType: "address", name: "refundOperator", type: "address" },
|
|
1271
|
+
{ internalType: "bool", name: "isApproved", type: "bool" },
|
|
1272
|
+
],
|
|
1273
|
+
name: "setRefundOperatorStatus",
|
|
1274
|
+
outputs: [],
|
|
1275
|
+
stateMutability: "nonpayable",
|
|
1276
|
+
type: "function",
|
|
1277
|
+
},
|
|
1161
1278
|
{
|
|
1162
1279
|
inputs: [
|
|
1163
1280
|
{ internalType: "address", name: "user", type: "address" },
|
|
@@ -1349,14 +1466,17 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1349
1466
|
if (!contract)
|
|
1350
1467
|
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1351
1468
|
setIsProcessing(true);
|
|
1352
|
-
const { creator, id, stepsToBuy, minStepsToBuy } = params;
|
|
1469
|
+
const { creator, id, stepsToBuy, minStepsToBuy, refundTo, creditTo, useCounterfactualAddressForRefund, } = params;
|
|
1353
1470
|
// Validate parameters
|
|
1354
|
-
if (!creator || !id) {
|
|
1471
|
+
if (!creator || !id || !refundTo || !creditTo) {
|
|
1355
1472
|
throw new Error(exports.OffchainFractionsError.INVALID_PARAMETERS);
|
|
1356
1473
|
}
|
|
1357
1474
|
if (stepsToBuy === 0n) {
|
|
1358
1475
|
throw new Error("stepsToBuy must be greater than zero");
|
|
1359
1476
|
}
|
|
1477
|
+
if (minStepsToBuy === 0n) {
|
|
1478
|
+
throw new Error("minStepsToBuy must be greater than zero");
|
|
1479
|
+
}
|
|
1360
1480
|
// Get fraction data to calculate required amount
|
|
1361
1481
|
const fractionData = await getFraction(creator, id);
|
|
1362
1482
|
const requiredAmount = stepsToBuy * fractionData.step;
|
|
@@ -1377,7 +1497,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1377
1497
|
try {
|
|
1378
1498
|
await contract
|
|
1379
1499
|
.getFunction("buyFractions")
|
|
1380
|
-
.staticCall(creator, id, stepsToBuy, minStepsToBuy, {
|
|
1500
|
+
.staticCall(creator, id, stepsToBuy, minStepsToBuy, refundTo, creditTo, useCounterfactualAddressForRefund, {
|
|
1381
1501
|
from: owner,
|
|
1382
1502
|
});
|
|
1383
1503
|
}
|
|
@@ -1385,7 +1505,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1385
1505
|
throw new Error(parseEthersError(staticError));
|
|
1386
1506
|
}
|
|
1387
1507
|
// Execute the transaction
|
|
1388
|
-
const tx = await contract.getFunction("buyFractions")(creator, id, stepsToBuy, minStepsToBuy);
|
|
1508
|
+
const tx = await contract.getFunction("buyFractions")(creator, id, stepsToBuy, minStepsToBuy, refundTo, creditTo, useCounterfactualAddressForRefund);
|
|
1389
1509
|
await tx.wait();
|
|
1390
1510
|
return tx.hash;
|
|
1391
1511
|
}
|
|
@@ -1398,10 +1518,11 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1398
1518
|
}
|
|
1399
1519
|
/**
|
|
1400
1520
|
* Claim refund from an unfilled sale
|
|
1521
|
+
* @param user The user address claiming the refund
|
|
1401
1522
|
* @param creator The address that created the fraction sale
|
|
1402
1523
|
* @param id The unique identifier of the fraction sale
|
|
1403
1524
|
*/
|
|
1404
|
-
async function claimRefund(creator, id) {
|
|
1525
|
+
async function claimRefund(user, creator, id) {
|
|
1405
1526
|
assertSigner(signer);
|
|
1406
1527
|
try {
|
|
1407
1528
|
const contract = getOffchainFractionsContract();
|
|
@@ -1409,18 +1530,20 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1409
1530
|
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1410
1531
|
setIsProcessing(true);
|
|
1411
1532
|
// Validate parameters
|
|
1412
|
-
if (!creator || !id) {
|
|
1533
|
+
if (!user || !creator || !id) {
|
|
1413
1534
|
throw new Error(exports.OffchainFractionsError.INVALID_PARAMETERS);
|
|
1414
1535
|
}
|
|
1415
1536
|
const owner = await signer.getAddress();
|
|
1416
1537
|
// Check if user has steps purchased
|
|
1417
|
-
const userSteps = await getStepsPurchased(
|
|
1538
|
+
const userSteps = await getStepsPurchased(user, creator, id);
|
|
1418
1539
|
if (userSteps === 0n) {
|
|
1419
1540
|
throw new Error("No steps purchased for this fraction");
|
|
1420
1541
|
}
|
|
1421
1542
|
// Run a static call first to surface any revert reason
|
|
1422
1543
|
try {
|
|
1423
|
-
await contract
|
|
1544
|
+
await contract
|
|
1545
|
+
.getFunction("claimRefund")
|
|
1546
|
+
.staticCall(user, creator, id, {
|
|
1424
1547
|
from: owner,
|
|
1425
1548
|
});
|
|
1426
1549
|
}
|
|
@@ -1428,7 +1551,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1428
1551
|
throw new Error(parseEthersError(staticError));
|
|
1429
1552
|
}
|
|
1430
1553
|
// Execute the transaction
|
|
1431
|
-
const tx = await contract.getFunction("claimRefund")(creator, id);
|
|
1554
|
+
const tx = await contract.getFunction("claimRefund")(user, creator, id);
|
|
1432
1555
|
await tx.wait();
|
|
1433
1556
|
return tx.hash;
|
|
1434
1557
|
}
|
|
@@ -1496,7 +1619,6 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1496
1619
|
minSharesToRaise: result.minSharesToRaise,
|
|
1497
1620
|
useCounterfactualAddress: result.useCounterfactualAddress,
|
|
1498
1621
|
claimedFromMinSharesToRaise: result.claimedFromMinSharesToRaise,
|
|
1499
|
-
owner: result.owner,
|
|
1500
1622
|
step: result.step,
|
|
1501
1623
|
to: result.to,
|
|
1502
1624
|
soldSteps: result.soldSteps,
|
|
@@ -1527,6 +1649,163 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1527
1649
|
throw new Error(parseEthersError(error));
|
|
1528
1650
|
}
|
|
1529
1651
|
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Get the refund wildcard operator address
|
|
1654
|
+
* @returns The wildcard operator address that can perform refunds for any user
|
|
1655
|
+
*/
|
|
1656
|
+
async function getRefundWildcardOperator() {
|
|
1657
|
+
assertSigner(signer);
|
|
1658
|
+
try {
|
|
1659
|
+
const contract = getOffchainFractionsContract();
|
|
1660
|
+
if (!contract)
|
|
1661
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1662
|
+
const result = await contract.getFunction("REFUND_WILDCARD_OPERATOR")();
|
|
1663
|
+
return result;
|
|
1664
|
+
}
|
|
1665
|
+
catch (error) {
|
|
1666
|
+
throw new Error(parseEthersError(error));
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Get refund details for a user's purchase
|
|
1671
|
+
* @param user The user address
|
|
1672
|
+
* @param creator The address that created the fraction sale
|
|
1673
|
+
* @param id The unique identifier of the fraction sale
|
|
1674
|
+
*/
|
|
1675
|
+
async function getRefundDetails(user, creator, id) {
|
|
1676
|
+
assertSigner(signer);
|
|
1677
|
+
try {
|
|
1678
|
+
const contract = getOffchainFractionsContract();
|
|
1679
|
+
if (!contract)
|
|
1680
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1681
|
+
const result = await contract.getFunction("getRefundDetails")(user, creator, id);
|
|
1682
|
+
return {
|
|
1683
|
+
refundTo: result.refundTo,
|
|
1684
|
+
useCounterfactualAddress: result.useCounterfactualAddress,
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
catch (error) {
|
|
1688
|
+
throw new Error(parseEthersError(error));
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Set refund details for a user's purchase
|
|
1693
|
+
* @param creator The address that created the fraction sale
|
|
1694
|
+
* @param id The unique identifier of the fraction sale
|
|
1695
|
+
* @param refundTo The address to receive refunds
|
|
1696
|
+
* @param useCounterfactualAddress Whether to use counterfactual address for refunds
|
|
1697
|
+
*/
|
|
1698
|
+
async function setRefundDetails(creator, id, refundTo, useCounterfactualAddress) {
|
|
1699
|
+
assertSigner(signer);
|
|
1700
|
+
try {
|
|
1701
|
+
const contract = getOffchainFractionsContract();
|
|
1702
|
+
if (!contract)
|
|
1703
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1704
|
+
setIsProcessing(true);
|
|
1705
|
+
// Validate parameters
|
|
1706
|
+
if (!creator || !id || !refundTo) {
|
|
1707
|
+
throw new Error(exports.OffchainFractionsError.INVALID_PARAMETERS);
|
|
1708
|
+
}
|
|
1709
|
+
const owner = await signer.getAddress();
|
|
1710
|
+
// Run a static call first to surface any revert reason
|
|
1711
|
+
try {
|
|
1712
|
+
await contract
|
|
1713
|
+
.getFunction("setRefundDetails")
|
|
1714
|
+
.staticCall(creator, id, refundTo, useCounterfactualAddress, {
|
|
1715
|
+
from: owner,
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
catch (staticError) {
|
|
1719
|
+
throw new Error(parseEthersError(staticError));
|
|
1720
|
+
}
|
|
1721
|
+
// Execute the transaction
|
|
1722
|
+
const tx = await contract.getFunction("setRefundDetails")(creator, id, refundTo, useCounterfactualAddress);
|
|
1723
|
+
await tx.wait();
|
|
1724
|
+
return tx.hash;
|
|
1725
|
+
}
|
|
1726
|
+
catch (error) {
|
|
1727
|
+
throw new Error(parseEthersError(error));
|
|
1728
|
+
}
|
|
1729
|
+
finally {
|
|
1730
|
+
setIsProcessing(false);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Set refund operator approval status
|
|
1735
|
+
* @param refundOperator The address of the refund operator
|
|
1736
|
+
* @param isApproved Whether to approve or revoke the operator
|
|
1737
|
+
*/
|
|
1738
|
+
async function setRefundOperatorStatus(refundOperator, isApproved) {
|
|
1739
|
+
assertSigner(signer);
|
|
1740
|
+
try {
|
|
1741
|
+
const contract = getOffchainFractionsContract();
|
|
1742
|
+
if (!contract)
|
|
1743
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1744
|
+
setIsProcessing(true);
|
|
1745
|
+
// Validate parameters
|
|
1746
|
+
if (!refundOperator) {
|
|
1747
|
+
throw new Error(exports.OffchainFractionsError.INVALID_PARAMETERS);
|
|
1748
|
+
}
|
|
1749
|
+
const owner = await signer.getAddress();
|
|
1750
|
+
// Run a static call first to surface any revert reason
|
|
1751
|
+
try {
|
|
1752
|
+
await contract
|
|
1753
|
+
.getFunction("setRefundOperatorStatus")
|
|
1754
|
+
.staticCall(refundOperator, isApproved, {
|
|
1755
|
+
from: owner,
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
catch (staticError) {
|
|
1759
|
+
throw new Error(parseEthersError(staticError));
|
|
1760
|
+
}
|
|
1761
|
+
// Execute the transaction
|
|
1762
|
+
const tx = await contract.getFunction("setRefundOperatorStatus")(refundOperator, isApproved);
|
|
1763
|
+
await tx.wait();
|
|
1764
|
+
return tx.hash;
|
|
1765
|
+
}
|
|
1766
|
+
catch (error) {
|
|
1767
|
+
throw new Error(parseEthersError(error));
|
|
1768
|
+
}
|
|
1769
|
+
finally {
|
|
1770
|
+
setIsProcessing(false);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Check if a refund operator is approved for a user
|
|
1775
|
+
* @param user The user address
|
|
1776
|
+
* @param refundOperator The refund operator address
|
|
1777
|
+
*/
|
|
1778
|
+
async function isRefundOperatorApproved(user, refundOperator) {
|
|
1779
|
+
assertSigner(signer);
|
|
1780
|
+
try {
|
|
1781
|
+
const contract = getOffchainFractionsContract();
|
|
1782
|
+
if (!contract)
|
|
1783
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1784
|
+
const result = await contract.getFunction("isRefundOperatorApproved")(user, refundOperator);
|
|
1785
|
+
return result;
|
|
1786
|
+
}
|
|
1787
|
+
catch (error) {
|
|
1788
|
+
throw new Error(parseEthersError(error));
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Get refund approval status for a user and operator
|
|
1793
|
+
* @param user The user address
|
|
1794
|
+
* @param refundOperator The refund operator address
|
|
1795
|
+
*/
|
|
1796
|
+
async function getRefundApprovalStatus(user, refundOperator) {
|
|
1797
|
+
assertSigner(signer);
|
|
1798
|
+
try {
|
|
1799
|
+
const contract = getOffchainFractionsContract();
|
|
1800
|
+
if (!contract)
|
|
1801
|
+
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1802
|
+
const result = await contract.getFunction("refundApprovals")(user, refundOperator);
|
|
1803
|
+
return result.isApproved;
|
|
1804
|
+
}
|
|
1805
|
+
catch (error) {
|
|
1806
|
+
throw new Error(parseEthersError(error));
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1530
1809
|
/**
|
|
1531
1810
|
* Check if a fraction sale is expired
|
|
1532
1811
|
* @param creator The address that created the fraction sale
|
|
@@ -1642,7 +1921,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1642
1921
|
const contract = getOffchainFractionsContract();
|
|
1643
1922
|
if (!contract)
|
|
1644
1923
|
throw new Error(exports.OffchainFractionsError.CONTRACT_NOT_AVAILABLE);
|
|
1645
|
-
const { creator, id, stepsToBuy, minStepsToBuy } = params;
|
|
1924
|
+
const { creator, id, stepsToBuy, minStepsToBuy, refundTo, creditTo, useCounterfactualAddressForRefund, } = params;
|
|
1646
1925
|
const feeData = await signer.provider?.getFeeData();
|
|
1647
1926
|
const gasPrice = feeData?.gasPrice ?? feeData?.maxFeePerGas ?? 0n;
|
|
1648
1927
|
if (gasPrice === 0n) {
|
|
@@ -1650,7 +1929,7 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1650
1929
|
}
|
|
1651
1930
|
const estimatedGas = await contract
|
|
1652
1931
|
.getFunction("buyFractions")
|
|
1653
|
-
.estimateGas(creator, id, stepsToBuy, minStepsToBuy);
|
|
1932
|
+
.estimateGas(creator, id, stepsToBuy, minStepsToBuy, refundTo, creditTo, useCounterfactualAddressForRefund);
|
|
1654
1933
|
const estimatedCost = estimatedGas * gasPrice;
|
|
1655
1934
|
if (ethPriceInUSD) {
|
|
1656
1935
|
const estimatedCostInEth = viem.formatEther(estimatedCost);
|
|
@@ -1674,6 +1953,13 @@ function useOffchainFractions(signer, CHAIN_ID) {
|
|
|
1674
1953
|
// View functions
|
|
1675
1954
|
getFraction,
|
|
1676
1955
|
getStepsPurchased,
|
|
1956
|
+
// Refund management functions
|
|
1957
|
+
getRefundWildcardOperator,
|
|
1958
|
+
getRefundDetails,
|
|
1959
|
+
setRefundDetails,
|
|
1960
|
+
setRefundOperatorStatus,
|
|
1961
|
+
isRefundOperatorApproved,
|
|
1962
|
+
getRefundApprovalStatus,
|
|
1677
1963
|
// Token operations
|
|
1678
1964
|
approveToken,
|
|
1679
1965
|
checkTokenAllowance,
|
|
@@ -3118,4 +3404,4 @@ exports.regionMetadata = regionMetadata;
|
|
|
3118
3404
|
exports.usStates = usStates;
|
|
3119
3405
|
exports.useForwarder = useForwarder;
|
|
3120
3406
|
exports.useOffchainFractions = useOffchainFractions;
|
|
3121
|
-
//# sourceMappingURL=farms-router-
|
|
3407
|
+
//# sourceMappingURL=farms-router-DhAOciuN.js.map
|