@glowlabs-org/utils 0.2.168 → 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 +69 -1
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/{calculate-farm-efficiency-D-hx2uPV.js → calculate-farm-efficiency-BVpffn8k.js} +101 -1
- package/dist/cjs/calculate-farm-efficiency-BVpffn8k.js.map +1 -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-DXMSn59D.js → calculate-farm-efficiency-Cq10L_Uq.js} +101 -1
- package/dist/esm/calculate-farm-efficiency-Cq10L_Uq.js.map +1 -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/lib/control-api/control-router.ts +147 -0
- package/src/utils/stake-control.ts +86 -0
- package/dist/cjs/calculate-farm-efficiency-D-hx2uPV.js.map +0 -1
- package/dist/esm/calculate-farm-efficiency-DXMSn59D.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;
|
|
@@ -12472,6 +12536,7 @@ exports.applyCertifiedInstallerEIP712Types = applyCertifiedInstallerEIP712Types;
|
|
|
12472
12536
|
exports.applyCertifiedInstallerSignatureRequestSchema = applyCertifiedInstallerSignatureRequestSchema;
|
|
12473
12537
|
exports.buildApplyCertifiedInstallerMessage = buildApplyCertifiedInstallerMessage;
|
|
12474
12538
|
exports.buildCommitKickstarterMessage = buildCommitKickstarterMessage;
|
|
12539
|
+
exports.buildDelegateSgctlMessage = buildDelegateSgctlMessage;
|
|
12475
12540
|
exports.buildPayProtocolDepositUsingStakedControlMessage = buildPayProtocolDepositUsingStakedControlMessage;
|
|
12476
12541
|
exports.buildRestakeMessage = buildRestakeMessage;
|
|
12477
12542
|
exports.buildStakeMessage = buildStakeMessage;
|
|
@@ -12480,6 +12545,8 @@ exports.buildUnstakeUnlockMessage = buildUnstakeUnlockMessage;
|
|
|
12480
12545
|
exports.buildVerifyUserMessage = buildVerifyUserMessage;
|
|
12481
12546
|
exports.commitKickstarterEIP712Types = commitKickstarterEIP712Types;
|
|
12482
12547
|
exports.commitKickstarterSignatureRequestSchema = commitKickstarterSignatureRequestSchema;
|
|
12548
|
+
exports.delegateSgctlEIP712Types = delegateSgctlEIP712Types;
|
|
12549
|
+
exports.delegateSgctlSignatureRequestSchema = delegateSgctlSignatureRequestSchema;
|
|
12483
12550
|
exports.payProtocolDepositUsingStakedControlEIP712Types = payProtocolDepositUsingStakedControlEIP712Types;
|
|
12484
12551
|
exports.payProtocolDepositUsingStakedControlSignatureRequestSchema = payProtocolDepositUsingStakedControlSignatureRequestSchema;
|
|
12485
12552
|
exports.restakeEIP712Types = restakeEIP712Types;
|
|
@@ -12493,6 +12560,7 @@ exports.unstakeUnlockEIP712Types = unstakeUnlockEIP712Types;
|
|
|
12493
12560
|
exports.unstakeUnlockSignatureRequestSchema = unstakeUnlockSignatureRequestSchema;
|
|
12494
12561
|
exports.validateApplyCertifiedInstallerSignature = validateApplyCertifiedInstallerSignature;
|
|
12495
12562
|
exports.validateCommitKickstarterSignature = validateCommitKickstarterSignature;
|
|
12563
|
+
exports.validateDelegateSgctlSignature = validateDelegateSgctlSignature;
|
|
12496
12564
|
exports.validatePayProtocolDepositUsingStakedControlSignature = validatePayProtocolDepositUsingStakedControlSignature;
|
|
12497
12565
|
exports.validateRestakeSignature = validateRestakeSignature;
|
|
12498
12566
|
exports.validateStakeSignature = validateStakeSignature;
|