@glowlabs-org/utils 0.2.167 → 0.2.169
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 +71 -1
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/{calculate-farm-efficiency-DabpqtXj.js → calculate-farm-efficiency-BVpffn8k.js} +105 -1
- package/dist/cjs/calculate-farm-efficiency-BVpffn8k.js.map +1 -0
- package/dist/cjs/constants/addresses.d.ts +2 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/control-api/control-router.d.ts +34 -0
- package/dist/cjs/utils/stake-control.d.ts +38 -0
- package/dist/esm/browser.js +67 -3
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/{calculate-farm-efficiency-HjxTADsE.js → calculate-farm-efficiency-Cq10L_Uq.js} +104 -2
- package/dist/esm/calculate-farm-efficiency-Cq10L_Uq.js.map +1 -0
- package/dist/esm/constants/addresses.d.ts +2 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/control-api/control-router.d.ts +34 -0
- package/dist/esm/utils/stake-control.d.ts +38 -0
- package/package.json +1 -1
- package/src/constants/addresses.ts +5 -0
- package/src/lib/control-api/control-router.ts +147 -0
- package/src/utils/stake-control.ts +86 -0
- package/dist/cjs/calculate-farm-efficiency-DabpqtXj.js.map +0 -1
- package/dist/esm/calculate-farm-efficiency-HjxTADsE.js.map +0 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var calculateFarmEfficiency = require('./calculate-farm-efficiency-
|
|
3
|
+
var calculateFarmEfficiency = require('./calculate-farm-efficiency-BVpffn8k.js');
|
|
4
4
|
require('decimal.js');
|
|
5
5
|
var viem = require('viem');
|
|
6
6
|
require('ethers');
|
|
@@ -12013,6 +12013,15 @@ const verifyUserEIP712Types = {
|
|
|
12013
12013
|
{ name: "deadline", type: "uint256" },
|
|
12014
12014
|
],
|
|
12015
12015
|
};
|
|
12016
|
+
const delegateSgctlEIP712Types = {
|
|
12017
|
+
DelegateSgctl: [
|
|
12018
|
+
{ name: "nonce", type: "uint256" },
|
|
12019
|
+
{ name: "amount", type: "uint256" },
|
|
12020
|
+
{ name: "applicationId", type: "string" },
|
|
12021
|
+
{ name: "fractionId", type: "string" },
|
|
12022
|
+
{ name: "deadline", type: "uint256" },
|
|
12023
|
+
],
|
|
12024
|
+
};
|
|
12016
12025
|
// Separate request schemas for clarity between stake and unstake
|
|
12017
12026
|
const stakeSignatureRequestSchema = z.object({
|
|
12018
12027
|
wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
@@ -12077,6 +12086,15 @@ const verifyUserSignatureRequestSchema = z.object({
|
|
|
12077
12086
|
nonce: z.string(),
|
|
12078
12087
|
deadline: z.string(),
|
|
12079
12088
|
});
|
|
12089
|
+
const delegateSgctlSignatureRequestSchema = z.object({
|
|
12090
|
+
wallet: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
12091
|
+
signature: z.string().regex(/^0x[a-fA-F0-9]{130}$/),
|
|
12092
|
+
nonce: z.string(),
|
|
12093
|
+
amount: z.string(),
|
|
12094
|
+
applicationId: z.string(),
|
|
12095
|
+
fractionId: z.string(),
|
|
12096
|
+
deadline: z.string(),
|
|
12097
|
+
});
|
|
12080
12098
|
function isDeadlineExpired(deadline) {
|
|
12081
12099
|
const nowSeconds = BigInt(Math.floor(Date.now() / 1000));
|
|
12082
12100
|
return deadline < nowSeconds;
|
|
@@ -12194,6 +12212,24 @@ function buildVerifyUserMessage(req) {
|
|
|
12194
12212
|
throw new Error("Deadline must be non-negative");
|
|
12195
12213
|
return { nonce, deadline };
|
|
12196
12214
|
}
|
|
12215
|
+
function buildDelegateSgctlMessage(req) {
|
|
12216
|
+
const nonce = BigInt(req.nonce);
|
|
12217
|
+
const amount = BigInt(req.amount);
|
|
12218
|
+
const deadline = BigInt(req.deadline);
|
|
12219
|
+
const applicationId = req.applicationId;
|
|
12220
|
+
const fractionId = req.fractionId;
|
|
12221
|
+
if (nonce < 0n)
|
|
12222
|
+
throw new Error("Nonce must be non-negative");
|
|
12223
|
+
if (amount < 0n)
|
|
12224
|
+
throw new Error("Amount must be non-negative");
|
|
12225
|
+
if (deadline < 0n)
|
|
12226
|
+
throw new Error("Deadline must be non-negative");
|
|
12227
|
+
if (!applicationId)
|
|
12228
|
+
throw new Error("applicationId must be non-empty");
|
|
12229
|
+
if (!fractionId)
|
|
12230
|
+
throw new Error("fractionId must be non-empty");
|
|
12231
|
+
return { nonce, amount, applicationId, fractionId, deadline };
|
|
12232
|
+
}
|
|
12197
12233
|
// Helper to validate the signature using viem
|
|
12198
12234
|
async function validateStakeSignature(input, domain = stakeControlEIP712Domain(Number(process.env.CHAIN_ID) || 1)) {
|
|
12199
12235
|
const message = buildStakeMessage({
|
|
@@ -12410,6 +12446,34 @@ async function validateVerifyUserSignature(input, domain = stakeControlEIP712Dom
|
|
|
12410
12446
|
return { valid: false, recovered: null, reason: "signature_failed" };
|
|
12411
12447
|
}
|
|
12412
12448
|
}
|
|
12449
|
+
async function validateDelegateSgctlSignature(input, domain = stakeControlEIP712Domain(Number(process.env.CHAIN_ID) || 1)) {
|
|
12450
|
+
const message = buildDelegateSgctlMessage({
|
|
12451
|
+
nonce: input.nonce,
|
|
12452
|
+
amount: input.amount,
|
|
12453
|
+
applicationId: input.applicationId,
|
|
12454
|
+
fractionId: input.fractionId,
|
|
12455
|
+
deadline: input.deadline,
|
|
12456
|
+
});
|
|
12457
|
+
if (isDeadlineExpired(message.deadline)) {
|
|
12458
|
+
return { valid: false, recovered: null, reason: "deadline_expired" };
|
|
12459
|
+
}
|
|
12460
|
+
try {
|
|
12461
|
+
const verified = await viem.verifyTypedData({
|
|
12462
|
+
address: viem.checksumAddress(input.wallet),
|
|
12463
|
+
domain,
|
|
12464
|
+
types: delegateSgctlEIP712Types,
|
|
12465
|
+
primaryType: "DelegateSgctl",
|
|
12466
|
+
message,
|
|
12467
|
+
signature: input.signature,
|
|
12468
|
+
});
|
|
12469
|
+
return verified
|
|
12470
|
+
? { valid: true, recovered: input.wallet, reason: null }
|
|
12471
|
+
: { valid: false, recovered: null, reason: "signer_mismatch" };
|
|
12472
|
+
}
|
|
12473
|
+
catch (_) {
|
|
12474
|
+
return { valid: false, recovered: null, reason: "signature_failed" };
|
|
12475
|
+
}
|
|
12476
|
+
}
|
|
12413
12477
|
|
|
12414
12478
|
exports.ControlRouter = calculateFarmEfficiency.ControlRouter;
|
|
12415
12479
|
exports.DECIMALS_BY_TOKEN = calculateFarmEfficiency.DECIMALS_BY_TOKEN;
|
|
@@ -12420,6 +12484,7 @@ Object.defineProperty(exports, "ForwarderError", {
|
|
|
12420
12484
|
get: function () { return calculateFarmEfficiency.ForwarderError; }
|
|
12421
12485
|
});
|
|
12422
12486
|
exports.GCA_URLS = calculateFarmEfficiency.GCA_URLS;
|
|
12487
|
+
exports.GCTL_OFFCHAIN_TOKEN_ADDRESS = calculateFarmEfficiency.GCTL_OFFCHAIN_TOKEN_ADDRESS;
|
|
12423
12488
|
exports.GLOW_WEIGHT_DECIMAL_PRECISION = calculateFarmEfficiency.GLOW_WEIGHT_DECIMAL_PRECISION;
|
|
12424
12489
|
exports.HUB_URL = calculateFarmEfficiency.HUB_URL;
|
|
12425
12490
|
Object.defineProperty(exports, "KICKSTARTER_STATUS", {
|
|
@@ -12445,6 +12510,7 @@ Object.defineProperty(exports, "RewardsKernelError", {
|
|
|
12445
12510
|
enumerable: true,
|
|
12446
12511
|
get: function () { return calculateFarmEfficiency.RewardsKernelError; }
|
|
12447
12512
|
});
|
|
12513
|
+
exports.SGCTL_OFFCHAIN_TOKEN_ADDRESS = calculateFarmEfficiency.SGCTL_OFFCHAIN_TOKEN_ADDRESS;
|
|
12448
12514
|
Object.defineProperty(exports, "STAKING_DIRECTIONS", {
|
|
12449
12515
|
enumerable: true,
|
|
12450
12516
|
get: function () { return calculateFarmEfficiency.STAKING_DIRECTIONS; }
|
|
@@ -12470,6 +12536,7 @@ exports.applyCertifiedInstallerEIP712Types = applyCertifiedInstallerEIP712Types;
|
|
|
12470
12536
|
exports.applyCertifiedInstallerSignatureRequestSchema = applyCertifiedInstallerSignatureRequestSchema;
|
|
12471
12537
|
exports.buildApplyCertifiedInstallerMessage = buildApplyCertifiedInstallerMessage;
|
|
12472
12538
|
exports.buildCommitKickstarterMessage = buildCommitKickstarterMessage;
|
|
12539
|
+
exports.buildDelegateSgctlMessage = buildDelegateSgctlMessage;
|
|
12473
12540
|
exports.buildPayProtocolDepositUsingStakedControlMessage = buildPayProtocolDepositUsingStakedControlMessage;
|
|
12474
12541
|
exports.buildRestakeMessage = buildRestakeMessage;
|
|
12475
12542
|
exports.buildStakeMessage = buildStakeMessage;
|
|
@@ -12478,6 +12545,8 @@ exports.buildUnstakeUnlockMessage = buildUnstakeUnlockMessage;
|
|
|
12478
12545
|
exports.buildVerifyUserMessage = buildVerifyUserMessage;
|
|
12479
12546
|
exports.commitKickstarterEIP712Types = commitKickstarterEIP712Types;
|
|
12480
12547
|
exports.commitKickstarterSignatureRequestSchema = commitKickstarterSignatureRequestSchema;
|
|
12548
|
+
exports.delegateSgctlEIP712Types = delegateSgctlEIP712Types;
|
|
12549
|
+
exports.delegateSgctlSignatureRequestSchema = delegateSgctlSignatureRequestSchema;
|
|
12481
12550
|
exports.payProtocolDepositUsingStakedControlEIP712Types = payProtocolDepositUsingStakedControlEIP712Types;
|
|
12482
12551
|
exports.payProtocolDepositUsingStakedControlSignatureRequestSchema = payProtocolDepositUsingStakedControlSignatureRequestSchema;
|
|
12483
12552
|
exports.restakeEIP712Types = restakeEIP712Types;
|
|
@@ -12491,6 +12560,7 @@ exports.unstakeUnlockEIP712Types = unstakeUnlockEIP712Types;
|
|
|
12491
12560
|
exports.unstakeUnlockSignatureRequestSchema = unstakeUnlockSignatureRequestSchema;
|
|
12492
12561
|
exports.validateApplyCertifiedInstallerSignature = validateApplyCertifiedInstallerSignature;
|
|
12493
12562
|
exports.validateCommitKickstarterSignature = validateCommitKickstarterSignature;
|
|
12563
|
+
exports.validateDelegateSgctlSignature = validateDelegateSgctlSignature;
|
|
12494
12564
|
exports.validatePayProtocolDepositUsingStakedControlSignature = validatePayProtocolDepositUsingStakedControlSignature;
|
|
12495
12565
|
exports.validateRestakeSignature = validateRestakeSignature;
|
|
12496
12566
|
exports.validateStakeSignature = validateStakeSignature;
|