@zkp2p/sdk 0.9.0 → 0.10.0-rc.0
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/README.md +53 -13
- package/dist/{chunk-FSIRPX4W.mjs → chunk-7M37EVN5.mjs} +33261 -248
- package/dist/chunk-7M37EVN5.mjs.map +1 -0
- package/dist/{chunk-EIOXBVXP.mjs → chunk-LPJE2MN7.mjs} +3 -39
- package/dist/chunk-LPJE2MN7.mjs.map +1 -0
- package/dist/index.cjs +33760 -400
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +59 -60
- package/dist/index.d.ts +59 -60
- package/dist/index.mjs +389 -19
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-VDFKSVGT.mjs +5 -0
- package/dist/{protocolViewerParsers-ER62YZ5L.mjs.map → protocolViewerParsers-VDFKSVGT.mjs.map} +1 -1
- package/dist/react.cjs +82 -93
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +33 -14
- package/dist/react.d.ts +33 -14
- package/dist/react.mjs +84 -67
- package/dist/react.mjs.map +1 -1
- package/dist/{vaultUtils-aJdIIILM.d.mts → vaultUtils-DtkWNsxi.d.mts} +388 -102
- package/dist/{vaultUtils-aJdIIILM.d.ts → vaultUtils-DtkWNsxi.d.ts} +388 -102
- package/package.json +1 -1
- package/dist/chunk-EIOXBVXP.mjs.map +0 -1
- package/dist/chunk-FSIRPX4W.mjs.map +0 -1
- package/dist/protocolViewerParsers-ER62YZ5L.mjs +0 -5
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ZERO_RATE_MANAGER_ID, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-LPJE2MN7.mjs';
|
|
2
2
|
import { ValidationError, APIError, NetworkError } from './chunk-GHQK65J2.mjs';
|
|
3
3
|
export { APIError, ContractError, ErrorCode, NetworkError, ValidationError, ZKP2PError } from './chunk-GHQK65J2.mjs';
|
|
4
|
-
import { METHOD_NAME_TO_HASH, matchesQuotePaymentMethod, matchesPaymentMethodNameAndHash, getContracts, getRateManagerContracts, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, parseBigIntLike, SUPPORTED_PAYMENT_METHOD_HASHES, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash } from './chunk-
|
|
5
|
-
export { PAYMENT_PLATFORMS, asciiToBytes32, enrichPvDepositView, enrichPvIntentView, ensureBytes32, getContracts, getGatingServiceAddress, getPaymentMethodsCatalog, getRateManagerContracts, parseDepositView, parseIntentView, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-
|
|
4
|
+
import { METHOD_NAME_TO_HASH, matchesQuotePaymentMethod, matchesPaymentMethodNameAndHash, getContracts, getRateManagerContracts, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, parseBigIntLike, SUPPORTED_PAYMENT_METHOD_HASHES, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash } from './chunk-7M37EVN5.mjs';
|
|
5
|
+
export { PAYMENT_PLATFORMS, asciiToBytes32, enrichPvDepositView, enrichPvIntentView, ensureBytes32, getContracts, getGatingServiceAddress, getPaymentMethodsCatalog, getRateManagerContracts, getStakeVaultContract, parseDepositView, parseIntentView, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-7M37EVN5.mjs';
|
|
6
6
|
import { Currency, currencyKeccak256 } from './chunk-ZFBH4HD7.mjs';
|
|
7
7
|
export { Currency, currencyInfo, getCurrencyCodeFromHash, getCurrencyInfoFromCountryCode, getCurrencyInfoFromHash, isSupportedCurrencyHash, mapConversionRatesToOnchainMinRate } from './chunk-ZFBH4HD7.mjs';
|
|
8
8
|
import './chunk-J5LGTIGS.mjs';
|
|
@@ -1968,7 +1968,7 @@ var ProtocolViewerReader = class {
|
|
|
1968
1968
|
if (inputCount === null) {
|
|
1969
1969
|
throw new Error("Configured ProtocolViewer ABI does not expose getDeposit");
|
|
1970
1970
|
}
|
|
1971
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
1971
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
1972
1972
|
if (inputCount >= 3) {
|
|
1973
1973
|
return tryContexts(
|
|
1974
1974
|
protocolViewerContexts,
|
|
@@ -2047,7 +2047,7 @@ var ProtocolViewerReader = class {
|
|
|
2047
2047
|
return Promise.all(ids.map((id) => this.config.host.getPvDepositById(id)));
|
|
2048
2048
|
}
|
|
2049
2049
|
const bn = ids.map((id) => typeof id === "bigint" ? id : parseRawDepositId(id));
|
|
2050
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2050
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2051
2051
|
if (inputCount >= 2) {
|
|
2052
2052
|
const requests = ids.map((id, index) => ({
|
|
2053
2053
|
index,
|
|
@@ -2152,7 +2152,7 @@ var ProtocolViewerReader = class {
|
|
|
2152
2152
|
if (!protocolViewerAddress || !protocolViewerAbi || inputCount === null) {
|
|
2153
2153
|
return this.config.host.getPvAccountDepositsFromIndexer(owner);
|
|
2154
2154
|
}
|
|
2155
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2155
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2156
2156
|
const { address, abi } = this.config.host.requireProtocolViewer();
|
|
2157
2157
|
if (inputCount >= 2) {
|
|
2158
2158
|
const readAndFilter = async (raw2) => {
|
|
@@ -2223,7 +2223,7 @@ var ProtocolViewerReader = class {
|
|
|
2223
2223
|
if (protocolViewerEntries.length === 0) {
|
|
2224
2224
|
throw new Error("ProtocolViewer not available for this network");
|
|
2225
2225
|
}
|
|
2226
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2226
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2227
2227
|
const intentsByHash = /* @__PURE__ */ new Map();
|
|
2228
2228
|
let attemptedRead = false;
|
|
2229
2229
|
let hadSuccessfulRead = false;
|
|
@@ -2331,7 +2331,7 @@ var ProtocolViewerReader = class {
|
|
|
2331
2331
|
if (protocolViewerEntries.length === 0) {
|
|
2332
2332
|
throw new Error("ProtocolViewer not available for this network");
|
|
2333
2333
|
}
|
|
2334
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2334
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2335
2335
|
let lastError;
|
|
2336
2336
|
for (const pvEntry of protocolViewerEntries) {
|
|
2337
2337
|
const inputCount = this.pvEntryFunctionInputCount(pvEntry, "getIntent");
|
|
@@ -4525,13 +4525,26 @@ async function apiGetOwnerDeposits(req, apiKey, baseApiUrl, authToken, timeoutMs
|
|
|
4525
4525
|
statusCode: 200
|
|
4526
4526
|
};
|
|
4527
4527
|
}
|
|
4528
|
-
async function
|
|
4528
|
+
async function apiGetTakerStake(req, baseApiUrl, timeoutMs) {
|
|
4529
4529
|
const normalizedOwner = req.owner.toLowerCase();
|
|
4530
4530
|
const query = new URLSearchParams({
|
|
4531
4531
|
owner: normalizedOwner,
|
|
4532
4532
|
chainId: String(req.chainId)
|
|
4533
4533
|
});
|
|
4534
|
-
const endpoint = `/v2/taker/
|
|
4534
|
+
const endpoint = `/v2/taker/stake?${query.toString()}`;
|
|
4535
|
+
return apiFetch({
|
|
4536
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4537
|
+
method: "GET",
|
|
4538
|
+
timeoutMs
|
|
4539
|
+
});
|
|
4540
|
+
}
|
|
4541
|
+
async function apiGetTakerCapacity(req, baseApiUrl, timeoutMs) {
|
|
4542
|
+
const normalizedOwner = req.owner.toLowerCase();
|
|
4543
|
+
const query = new URLSearchParams({
|
|
4544
|
+
owner: normalizedOwner,
|
|
4545
|
+
chainId: String(req.chainId)
|
|
4546
|
+
});
|
|
4547
|
+
const endpoint = `/v2/taker/capacity?${query.toString()}`;
|
|
4535
4548
|
return apiFetch({
|
|
4536
4549
|
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4537
4550
|
method: "GET",
|
|
@@ -5252,6 +5265,125 @@ var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && ab
|
|
|
5252
5265
|
(item) => item.type === "function" && item.name === functionName
|
|
5253
5266
|
);
|
|
5254
5267
|
|
|
5268
|
+
// src/client/StakeOperations.ts
|
|
5269
|
+
function tupleValue(value, key, index) {
|
|
5270
|
+
if (Array.isArray(value)) return value[index];
|
|
5271
|
+
if (value && typeof value === "object") {
|
|
5272
|
+
return value[key];
|
|
5273
|
+
}
|
|
5274
|
+
return void 0;
|
|
5275
|
+
}
|
|
5276
|
+
function toBigInt2(value, label) {
|
|
5277
|
+
if (typeof value === "bigint") return value;
|
|
5278
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
5279
|
+
return BigInt(value);
|
|
5280
|
+
}
|
|
5281
|
+
throw new Error(`Invalid StakeVault ${label}`);
|
|
5282
|
+
}
|
|
5283
|
+
function toBoolean(value, label) {
|
|
5284
|
+
if (typeof value === "boolean") return value;
|
|
5285
|
+
throw new Error(`Invalid StakeVault ${label}`);
|
|
5286
|
+
}
|
|
5287
|
+
var StakeOperations = class {
|
|
5288
|
+
constructor(config) {
|
|
5289
|
+
this.config = config;
|
|
5290
|
+
}
|
|
5291
|
+
getContract() {
|
|
5292
|
+
const address = this.config.getStakeVaultAddress();
|
|
5293
|
+
const abi = this.config.getStakeVaultAbi();
|
|
5294
|
+
const stakeToken = this.config.getStakeTokenAddress();
|
|
5295
|
+
if (!address || !abi || !stakeToken) {
|
|
5296
|
+
throw new Error("StakeVault not available for this chain/environment");
|
|
5297
|
+
}
|
|
5298
|
+
return { address, abi, stakeToken };
|
|
5299
|
+
}
|
|
5300
|
+
read(functionName, args = []) {
|
|
5301
|
+
const { address, abi } = this.getContract();
|
|
5302
|
+
return this.config.getPublicClient().readContract({
|
|
5303
|
+
address,
|
|
5304
|
+
abi,
|
|
5305
|
+
functionName,
|
|
5306
|
+
args
|
|
5307
|
+
});
|
|
5308
|
+
}
|
|
5309
|
+
getStakeBalance(staker) {
|
|
5310
|
+
return this.read("stakeBalance", [staker]);
|
|
5311
|
+
}
|
|
5312
|
+
getEligibleStake(staker) {
|
|
5313
|
+
return this.read("eligibleStake", [staker]);
|
|
5314
|
+
}
|
|
5315
|
+
getReservedStake(staker) {
|
|
5316
|
+
return this.read("reservedStake", [staker]);
|
|
5317
|
+
}
|
|
5318
|
+
getFreeStake(staker) {
|
|
5319
|
+
return this.read("freeStake", [staker]);
|
|
5320
|
+
}
|
|
5321
|
+
getStakeOwner(taker) {
|
|
5322
|
+
return this.read("stakeOwnerOf", [taker]);
|
|
5323
|
+
}
|
|
5324
|
+
getAllowedStakeOwner(taker) {
|
|
5325
|
+
return this.read("allowedStakeOwner", [taker]);
|
|
5326
|
+
}
|
|
5327
|
+
getStakeDelegationEnabled(taker) {
|
|
5328
|
+
return this.read("stakeDelegationEnabled", [taker]);
|
|
5329
|
+
}
|
|
5330
|
+
async getStakeWithdrawalRequest(staker) {
|
|
5331
|
+
const value = await this.read("getStakeWithdrawalRequest", [staker]);
|
|
5332
|
+
return {
|
|
5333
|
+
amount: toBigInt2(tupleValue(value, "amount", 0), "withdrawal amount"),
|
|
5334
|
+
requestedAt: toBigInt2(tupleValue(value, "requestedAt", 1), "withdrawal requestedAt"),
|
|
5335
|
+
availableAt: toBigInt2(tupleValue(value, "availableAt", 2), "withdrawal availableAt")
|
|
5336
|
+
};
|
|
5337
|
+
}
|
|
5338
|
+
async getStakeExitRequest(staker) {
|
|
5339
|
+
const value = await this.read("getExitRequest", [staker]);
|
|
5340
|
+
return {
|
|
5341
|
+
exiting: toBoolean(tupleValue(value, "exiting", 0), "exit status"),
|
|
5342
|
+
requestedAt: toBigInt2(tupleValue(value, "requestedAt", 1), "exit requestedAt"),
|
|
5343
|
+
availableAt: toBigInt2(tupleValue(value, "availableAt", 2), "exit availableAt")
|
|
5344
|
+
};
|
|
5345
|
+
}
|
|
5346
|
+
async getStakeVaultState(params) {
|
|
5347
|
+
const taker = params.taker ?? params.staker;
|
|
5348
|
+
const { stakeToken } = this.getContract();
|
|
5349
|
+
const [
|
|
5350
|
+
stakeOwner,
|
|
5351
|
+
allowedStakeOwner,
|
|
5352
|
+
delegationEnabled,
|
|
5353
|
+
staked,
|
|
5354
|
+
eligible,
|
|
5355
|
+
reserved,
|
|
5356
|
+
free,
|
|
5357
|
+
withdrawal,
|
|
5358
|
+
exit
|
|
5359
|
+
] = await Promise.all([
|
|
5360
|
+
this.getStakeOwner(taker),
|
|
5361
|
+
this.getAllowedStakeOwner(taker),
|
|
5362
|
+
this.getStakeDelegationEnabled(taker),
|
|
5363
|
+
this.getStakeBalance(params.staker),
|
|
5364
|
+
this.getEligibleStake(params.staker),
|
|
5365
|
+
this.getReservedStake(params.staker),
|
|
5366
|
+
this.getFreeStake(params.staker),
|
|
5367
|
+
this.getStakeWithdrawalRequest(params.staker),
|
|
5368
|
+
this.getStakeExitRequest(params.staker)
|
|
5369
|
+
]);
|
|
5370
|
+
return {
|
|
5371
|
+
staker: params.staker,
|
|
5372
|
+
taker,
|
|
5373
|
+
stakeToken,
|
|
5374
|
+
stakeOwner,
|
|
5375
|
+
allowedStakeOwner,
|
|
5376
|
+
delegationEnabled,
|
|
5377
|
+
staked,
|
|
5378
|
+
eligible,
|
|
5379
|
+
reserved,
|
|
5380
|
+
free,
|
|
5381
|
+
withdrawal,
|
|
5382
|
+
exit
|
|
5383
|
+
};
|
|
5384
|
+
}
|
|
5385
|
+
};
|
|
5386
|
+
|
|
5255
5387
|
// src/indexer/rateManagerService.ts
|
|
5256
5388
|
var DEFAULT_LIMIT2 = 50;
|
|
5257
5389
|
var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
|
|
@@ -6311,6 +6443,46 @@ var Zkp2pClient = class {
|
|
|
6311
6443
|
* @throws Error if walletClient is missing an account
|
|
6312
6444
|
*/
|
|
6313
6445
|
constructor(opts) {
|
|
6446
|
+
/** Deposit USDC stake for the connected taker. */
|
|
6447
|
+
this.depositStake = this.buildStakeVaultMethod(
|
|
6448
|
+
"depositStake",
|
|
6449
|
+
(params) => [params.amount]
|
|
6450
|
+
);
|
|
6451
|
+
/** Deposit USDC stake for a different taker that has enabled delegation. */
|
|
6452
|
+
this.depositStakeFor = this.buildStakeVaultMethod(
|
|
6453
|
+
"depositStakeFor",
|
|
6454
|
+
(params) => [params.taker, params.amount]
|
|
6455
|
+
);
|
|
6456
|
+
/** Begin a partial stake-withdrawal delay. */
|
|
6457
|
+
this.requestStakeWithdrawal = this.buildStakeVaultMethod("requestStakeWithdrawal", (params) => [params.amount]);
|
|
6458
|
+
/** Cancel the connected staker's pending partial withdrawal. */
|
|
6459
|
+
this.cancelStakeWithdrawal = this.buildStakeVaultMethod("cancelStakeWithdrawal", () => []);
|
|
6460
|
+
/** Withdraw a matured partial stake-withdrawal request. */
|
|
6461
|
+
this.withdrawRequestedStake = this.buildStakeVaultMethod("withdrawRequestedStake", (params) => [params.recipient]);
|
|
6462
|
+
/** Begin a full exit, blocking new taking activity for the stake owner. */
|
|
6463
|
+
this.requestExit = this.buildStakeVaultMethod(
|
|
6464
|
+
"requestExit",
|
|
6465
|
+
() => []
|
|
6466
|
+
);
|
|
6467
|
+
/** Cancel a pending full exit. */
|
|
6468
|
+
this.cancelExit = this.buildStakeVaultMethod(
|
|
6469
|
+
"cancelExit",
|
|
6470
|
+
() => []
|
|
6471
|
+
);
|
|
6472
|
+
/** Withdraw all stake after a matured, fully settled exit. */
|
|
6473
|
+
this.withdrawStake = this.buildStakeVaultMethod(
|
|
6474
|
+
"withdrawStake",
|
|
6475
|
+
(params) => [params.recipient]
|
|
6476
|
+
);
|
|
6477
|
+
/** Allow or block third-party stake owners for the connected taker. */
|
|
6478
|
+
this.setStakeDelegationEnabled = this.buildStakeVaultMethod("setStakeDelegationEnabled", (params) => [params.enabled]);
|
|
6479
|
+
/** Select the stake owner whose portfolio backs the connected taker. */
|
|
6480
|
+
this.setAllowedStakeOwner = this.buildStakeVaultMethod("setAllowedStakeOwner", (params) => [params.stakeOwner]);
|
|
6481
|
+
/** Remove the connected taker's selected third-party stake owner. */
|
|
6482
|
+
this.clearStakeOwner = this.buildStakeVaultMethod(
|
|
6483
|
+
"clearStakeOwner",
|
|
6484
|
+
() => []
|
|
6485
|
+
);
|
|
6314
6486
|
// ╔═══════════════════════════════════════════════════════════════════════════╗
|
|
6315
6487
|
// ║ CORE: DEPOSIT MANAGEMENT ║
|
|
6316
6488
|
// ╚═══════════════════════════════════════════════════════════════════════════╝
|
|
@@ -7209,6 +7381,8 @@ var Zkp2pClient = class {
|
|
|
7209
7381
|
this.rateManagerRegistryAbi = abis.rateManagerRegistry ?? this.rateManagerV1Abi;
|
|
7210
7382
|
this.rateManagerControllerAddress = toAddress(addresses.rateManagerController);
|
|
7211
7383
|
this.rateManagerControllerAbi = abis.rateManagerController;
|
|
7384
|
+
this.stakeVaultAddress = toAddress(addresses.stakeVault);
|
|
7385
|
+
this.stakeVaultAbi = abis.stakeVault;
|
|
7212
7386
|
if (!this.rateManagerRegistryAddress || !this.rateManagerRegistryAbi) {
|
|
7213
7387
|
try {
|
|
7214
7388
|
const rateManagerContracts = getRateManagerContracts(this.chainId, this.runtimeEnv);
|
|
@@ -7289,6 +7463,12 @@ var Zkp2pClient = class {
|
|
|
7289
7463
|
prepareContractTransaction: (tx) => this.prepareContractTransaction(tx)
|
|
7290
7464
|
}
|
|
7291
7465
|
});
|
|
7466
|
+
this._stakeOps = new StakeOperations({
|
|
7467
|
+
getPublicClient: () => this.publicClient,
|
|
7468
|
+
getStakeVaultAddress: () => this.stakeVaultAddress,
|
|
7469
|
+
getStakeVaultAbi: () => this.stakeVaultAbi,
|
|
7470
|
+
getStakeTokenAddress: () => this._usdcAddress
|
|
7471
|
+
});
|
|
7292
7472
|
this._intentOps = new IntentOperations({
|
|
7293
7473
|
getWalletClient: () => this.walletClient,
|
|
7294
7474
|
getPublicClient: () => this.publicClient,
|
|
@@ -7746,6 +7926,17 @@ var Zkp2pClient = class {
|
|
|
7746
7926
|
}
|
|
7747
7927
|
);
|
|
7748
7928
|
}
|
|
7929
|
+
buildStakeVaultMethod(functionName, buildArgs) {
|
|
7930
|
+
return this.buildContractMethod(
|
|
7931
|
+
() => ({
|
|
7932
|
+
address: this.stakeVaultAddress,
|
|
7933
|
+
abi: this.stakeVaultAbi,
|
|
7934
|
+
label: "StakeVault"
|
|
7935
|
+
}),
|
|
7936
|
+
functionName,
|
|
7937
|
+
buildArgs
|
|
7938
|
+
);
|
|
7939
|
+
}
|
|
7749
7940
|
buildEscrowMethod(functionName, buildArgs, buildValue) {
|
|
7750
7941
|
return Object.assign(
|
|
7751
7942
|
async (params) => {
|
|
@@ -8203,6 +8394,70 @@ var Zkp2pClient = class {
|
|
|
8203
8394
|
});
|
|
8204
8395
|
return { hadAllowance: false, hash };
|
|
8205
8396
|
}
|
|
8397
|
+
// ╔═══════════════════════════════════════════════════════════════════════════╗
|
|
8398
|
+
// ║ CORE: TAKER STAKING ║
|
|
8399
|
+
// ╚═══════════════════════════════════════════════════════════════════════════╝
|
|
8400
|
+
/**
|
|
8401
|
+
* Return the resolved StakeVault coordinates for advanced wallet, relayer,
|
|
8402
|
+
* or reactive read integrations.
|
|
8403
|
+
*/
|
|
8404
|
+
getStakeVaultContract() {
|
|
8405
|
+
return this._stakeOps.getContract();
|
|
8406
|
+
}
|
|
8407
|
+
/**
|
|
8408
|
+
* Ensure the connected wallet has approved enough USDC for StakeVault.
|
|
8409
|
+
* If an approval is submitted, wait for it to confirm before depositing.
|
|
8410
|
+
*/
|
|
8411
|
+
async ensureStakeAllowance(params) {
|
|
8412
|
+
const { address, stakeToken } = this._stakeOps.getContract();
|
|
8413
|
+
return this.ensureAllowance({
|
|
8414
|
+
token: stakeToken,
|
|
8415
|
+
spender: address,
|
|
8416
|
+
amount: params.amount,
|
|
8417
|
+
maxApprove: params.maxApprove,
|
|
8418
|
+
txOverrides: params.txOverrides
|
|
8419
|
+
});
|
|
8420
|
+
}
|
|
8421
|
+
/** Read total stake owned by an address directly from StakeVault. */
|
|
8422
|
+
getStakeBalance(staker) {
|
|
8423
|
+
return this._stakeOps.getStakeBalance(staker);
|
|
8424
|
+
}
|
|
8425
|
+
/** Read stake that currently backs taking capacity. */
|
|
8426
|
+
getEligibleStake(staker) {
|
|
8427
|
+
return this._stakeOps.getEligibleStake(staker);
|
|
8428
|
+
}
|
|
8429
|
+
/** Read stake reserved against active intents. */
|
|
8430
|
+
getReservedStake(staker) {
|
|
8431
|
+
return this._stakeOps.getReservedStake(staker);
|
|
8432
|
+
}
|
|
8433
|
+
/** Read stake currently available for withdrawal or new reservations. */
|
|
8434
|
+
getFreeStake(staker) {
|
|
8435
|
+
return this._stakeOps.getFreeStake(staker);
|
|
8436
|
+
}
|
|
8437
|
+
/** Resolve the effective stake owner backing a taker. */
|
|
8438
|
+
getStakeOwner(taker) {
|
|
8439
|
+
return this._stakeOps.getStakeOwner(taker);
|
|
8440
|
+
}
|
|
8441
|
+
/** Read the stake owner explicitly selected by a taker. */
|
|
8442
|
+
getAllowedStakeOwner(taker) {
|
|
8443
|
+
return this._stakeOps.getAllowedStakeOwner(taker);
|
|
8444
|
+
}
|
|
8445
|
+
/** Read whether a taker allows third-party stake delegation. */
|
|
8446
|
+
getStakeDelegationEnabled(taker) {
|
|
8447
|
+
return this._stakeOps.getStakeDelegationEnabled(taker);
|
|
8448
|
+
}
|
|
8449
|
+
/** Read the connected staker's pending partial withdrawal. */
|
|
8450
|
+
getStakeWithdrawalRequest(staker) {
|
|
8451
|
+
return this._stakeOps.getStakeWithdrawalRequest(staker);
|
|
8452
|
+
}
|
|
8453
|
+
/** Read the connected staker's pending full exit. */
|
|
8454
|
+
getStakeExitRequest(staker) {
|
|
8455
|
+
return this._stakeOps.getStakeExitRequest(staker);
|
|
8456
|
+
}
|
|
8457
|
+
/** Read the complete authoritative StakeVault state needed by a staking UI. */
|
|
8458
|
+
getStakeVaultState(params) {
|
|
8459
|
+
return this._stakeOps.getStakeVaultState(params);
|
|
8460
|
+
}
|
|
8206
8461
|
/**
|
|
8207
8462
|
* Registers payee details with the curator API and returns hashed on-chain IDs.
|
|
8208
8463
|
*
|
|
@@ -8638,25 +8893,48 @@ var Zkp2pClient = class {
|
|
|
8638
8893
|
return appendReferrerFeeDisplayFieldsToBestByPlatform(enrichedQuote, referrerFeeConfig);
|
|
8639
8894
|
}
|
|
8640
8895
|
// ───────────────────────────────────────────────────────────────────────────
|
|
8641
|
-
// SUPPORTING: TAKER
|
|
8642
|
-
// (Used by frontends to display
|
|
8896
|
+
// SUPPORTING: TAKER STAKE & CAPACITY
|
|
8897
|
+
// (Used by frontends to display the stake portfolio and per-platform taking
|
|
8898
|
+
// capacity; never used to filter quotes)
|
|
8643
8899
|
// ───────────────────────────────────────────────────────────────────────────
|
|
8644
8900
|
/**
|
|
8645
|
-
* **Supporting Method** - Fetches
|
|
8901
|
+
* **Supporting Method** - Fetches the stake portfolio backing a taker:
|
|
8902
|
+
* staked/pending-withdrawal/eligible/reserved/free balances, reservation
|
|
8903
|
+
* aggregates, delegation, and exit state.
|
|
8646
8904
|
*
|
|
8647
|
-
* @param req -
|
|
8648
|
-
* @param req.owner - Taker address
|
|
8905
|
+
* @param req - Stake request parameters
|
|
8906
|
+
* @param req.owner - Taker address (the resolved stake owner may differ)
|
|
8649
8907
|
* @param req.chainId - Chain ID
|
|
8650
8908
|
* @param opts - Optional overrides for API URL and timeout
|
|
8651
|
-
* @returns Taker
|
|
8909
|
+
* @returns Taker stake response
|
|
8652
8910
|
*/
|
|
8653
|
-
async
|
|
8911
|
+
async getTakerStake(req, opts) {
|
|
8654
8912
|
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8655
8913
|
/\/$/,
|
|
8656
8914
|
""
|
|
8657
8915
|
);
|
|
8658
8916
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8659
|
-
return
|
|
8917
|
+
return apiGetTakerStake(req, baseApiUrl, timeoutMs);
|
|
8918
|
+
}
|
|
8919
|
+
/**
|
|
8920
|
+
* **Supporting Method** - Fetches per-platform bonded taking capacity, free
|
|
8921
|
+
* takes, curve terms, warnings, and operational gates for a taker's shared
|
|
8922
|
+
* stake portfolio. Platform capacities are alternative views of one shared
|
|
8923
|
+
* balance and must never be summed.
|
|
8924
|
+
*
|
|
8925
|
+
* @param req - Capacity request parameters
|
|
8926
|
+
* @param req.owner - Taker address (the resolved stake owner may differ)
|
|
8927
|
+
* @param req.chainId - Chain ID
|
|
8928
|
+
* @param opts - Optional overrides for API URL and timeout
|
|
8929
|
+
* @returns Taker capacity response
|
|
8930
|
+
*/
|
|
8931
|
+
async getTakerCapacity(req, opts) {
|
|
8932
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8933
|
+
/\/$/,
|
|
8934
|
+
""
|
|
8935
|
+
);
|
|
8936
|
+
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8937
|
+
return apiGetTakerCapacity(req, baseApiUrl, timeoutMs);
|
|
8660
8938
|
}
|
|
8661
8939
|
/**
|
|
8662
8940
|
* Fetch a referral dashboard. Pass `address` for a public wallet-keyed read;
|
|
@@ -8993,6 +9271,7 @@ var Zkp2pClient = class {
|
|
|
8993
9271
|
unifiedPaymentVerifier: this.unifiedPaymentVerifier,
|
|
8994
9272
|
rateManagerV1: this.rateManagerV1Address,
|
|
8995
9273
|
orchestratorRegistry: this.orchestratorRegistryAddress,
|
|
9274
|
+
stakeVault: this.stakeVaultAddress,
|
|
8996
9275
|
usdc: this._usdcAddress
|
|
8997
9276
|
};
|
|
8998
9277
|
}
|
|
@@ -9067,6 +9346,97 @@ var createPeerExtensionSdk = (options = {}) => ({
|
|
|
9067
9346
|
});
|
|
9068
9347
|
var peerExtensionSdk = createPeerExtensionSdk();
|
|
9069
9348
|
|
|
9070
|
-
|
|
9349
|
+
// src/riskMath.ts
|
|
9350
|
+
var RISK_BPS_DENOMINATOR = 10000n;
|
|
9351
|
+
var RISK_SECONDS_PER_HOUR = 3600n;
|
|
9352
|
+
var RISK_GRIEFING_DENOMINATOR = RISK_BPS_DENOMINATOR * RISK_SECONDS_PER_HOUR;
|
|
9353
|
+
function integer(value, label) {
|
|
9354
|
+
if (typeof value === "number" && (!Number.isSafeInteger(value) || value < 0)) {
|
|
9355
|
+
throw new RangeError(`${label} must be a non-negative safe integer`);
|
|
9356
|
+
}
|
|
9357
|
+
const parsed = BigInt(value.toString());
|
|
9358
|
+
if (parsed < 0n) throw new RangeError(`${label} must be non-negative`);
|
|
9359
|
+
return parsed;
|
|
9360
|
+
}
|
|
9361
|
+
function ceilDiv(numerator, denominator) {
|
|
9362
|
+
if (denominator <= 0n) throw new RangeError("denominator must be positive");
|
|
9363
|
+
if (numerator === 0n) return 0n;
|
|
9364
|
+
return (numerator - 1n) / denominator + 1n;
|
|
9365
|
+
}
|
|
9366
|
+
function calculateMaxGriefingBond(amount, terms) {
|
|
9367
|
+
const bondedAmount = integer(amount, "amount");
|
|
9368
|
+
const maxIntentPeriod = integer(terms.maxIntentPeriod, "maxIntentPeriod");
|
|
9369
|
+
const griefingCliff = integer(terms.griefingCliff, "griefingCliff");
|
|
9370
|
+
const slope = integer(terms.griefingPenaltyBpsPerHour, "griefingPenaltyBpsPerHour");
|
|
9371
|
+
if (slope === 0n || maxIntentPeriod <= griefingCliff) return 0n;
|
|
9372
|
+
return ceilDiv(
|
|
9373
|
+
bondedAmount * slope * (maxIntentPeriod - griefingCliff),
|
|
9374
|
+
RISK_GRIEFING_DENOMINATOR
|
|
9375
|
+
);
|
|
9376
|
+
}
|
|
9377
|
+
function calculateChargebackReserve(amount, reserveBps) {
|
|
9378
|
+
const bondedAmount = integer(amount, "amount");
|
|
9379
|
+
const reserveRatio = integer(reserveBps, "reserveBps");
|
|
9380
|
+
if (reserveRatio > RISK_BPS_DENOMINATOR) {
|
|
9381
|
+
throw new RangeError("reserveBps cannot exceed 10,000");
|
|
9382
|
+
}
|
|
9383
|
+
return ceilDiv(bondedAmount * reserveRatio, RISK_BPS_DENOMINATOR);
|
|
9384
|
+
}
|
|
9385
|
+
function calculateRequiredReservation(amount, terms, reserveBps) {
|
|
9386
|
+
const griefingBond = calculateMaxGriefingBond(amount, terms);
|
|
9387
|
+
const chargebackReserve = calculateChargebackReserve(amount, reserveBps);
|
|
9388
|
+
return griefingBond > chargebackReserve ? griefingBond : chargebackReserve;
|
|
9389
|
+
}
|
|
9390
|
+
function calculateGriefingPenalty(amount, createdAt, cancelledAt, terms) {
|
|
9391
|
+
const bondedAmount = integer(amount, "amount");
|
|
9392
|
+
const created = integer(createdAt, "createdAt");
|
|
9393
|
+
const cancelled = integer(cancelledAt, "cancelledAt");
|
|
9394
|
+
const maxIntentPeriod = integer(terms.maxIntentPeriod, "maxIntentPeriod");
|
|
9395
|
+
const griefingCliff = integer(terms.griefingCliff, "griefingCliff");
|
|
9396
|
+
const slope = integer(terms.griefingPenaltyBpsPerHour, "griefingPenaltyBpsPerHour");
|
|
9397
|
+
if (cancelled <= created) return { penalty: 0n, effectiveElapsed: 0n };
|
|
9398
|
+
const elapsed = cancelled - created;
|
|
9399
|
+
const effectiveElapsed = elapsed < maxIntentPeriod ? elapsed : maxIntentPeriod;
|
|
9400
|
+
if (slope === 0n || effectiveElapsed <= griefingCliff) {
|
|
9401
|
+
return { penalty: 0n, effectiveElapsed };
|
|
9402
|
+
}
|
|
9403
|
+
const chargeableTime = effectiveElapsed - griefingCliff;
|
|
9404
|
+
return {
|
|
9405
|
+
penalty: ceilDiv(bondedAmount * slope * chargeableTime, RISK_GRIEFING_DENOMINATOR),
|
|
9406
|
+
effectiveElapsed
|
|
9407
|
+
};
|
|
9408
|
+
}
|
|
9409
|
+
function calculateBondedTakingCapacity(freeStake, terms, reserveBps) {
|
|
9410
|
+
const available = integer(freeStake, "freeStake");
|
|
9411
|
+
const maxIntentPeriod = integer(terms.maxIntentPeriod, "maxIntentPeriod");
|
|
9412
|
+
const griefingCliff = integer(terms.griefingCliff, "griefingCliff");
|
|
9413
|
+
const slope = integer(terms.griefingPenaltyBpsPerHour, "griefingPenaltyBpsPerHour");
|
|
9414
|
+
const reserveRatio = integer(reserveBps, "reserveBps");
|
|
9415
|
+
if (reserveRatio > RISK_BPS_DENOMINATOR) {
|
|
9416
|
+
throw new RangeError("reserveBps cannot exceed 10,000");
|
|
9417
|
+
}
|
|
9418
|
+
const griefingRateNumerator = maxIntentPeriod > griefingCliff ? slope * (maxIntentPeriod - griefingCliff) : 0n;
|
|
9419
|
+
const griefingCapacity = griefingRateNumerator === 0n ? null : available * RISK_GRIEFING_DENOMINATOR / griefingRateNumerator;
|
|
9420
|
+
const chargebackCapacity = reserveRatio === 0n ? null : available * RISK_BPS_DENOMINATOR / reserveRatio;
|
|
9421
|
+
let bondedTakingCapacity;
|
|
9422
|
+
if (griefingCapacity === null) bondedTakingCapacity = chargebackCapacity;
|
|
9423
|
+
else if (chargebackCapacity === null) bondedTakingCapacity = griefingCapacity;
|
|
9424
|
+
else {
|
|
9425
|
+
bondedTakingCapacity = griefingCapacity < chargebackCapacity ? griefingCapacity : chargebackCapacity;
|
|
9426
|
+
}
|
|
9427
|
+
return { griefingCapacity, chargebackCapacity, bondedTakingCapacity };
|
|
9428
|
+
}
|
|
9429
|
+
function calculateFreeTakeCapacity(freeTakeCount, freeTakesUsed, freeTakeAmount) {
|
|
9430
|
+
const count = integer(freeTakeCount, "freeTakeCount");
|
|
9431
|
+
const used = integer(freeTakesUsed, "freeTakesUsed");
|
|
9432
|
+
const amount = integer(freeTakeAmount, "freeTakeAmount");
|
|
9433
|
+
const remainingFreeTakes = used >= count ? 0n : count - used;
|
|
9434
|
+
return {
|
|
9435
|
+
remainingFreeTakes,
|
|
9436
|
+
freeTakingCapacity: remainingFreeTakes * amount
|
|
9437
|
+
};
|
|
9438
|
+
}
|
|
9439
|
+
|
|
9440
|
+
export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, REFERRAL_SIGNATURE_DOMAIN, REFERRAL_SIGNATURE_TYPES, RISK_BPS_DENOMINATOR, RISK_GRIEFING_DENOMINATOR, RISK_SECONDS_PER_HOUR, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiCreateReferralCode, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOrderbookTable, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetReferralDashboard, apiGetReferralEarnings, apiGetTakerCapacity, apiGetTakerStake, apiLookupReferralCode, apiPostDepositDetails, apiRedeemReferralCode, apiRequestIdentityAttestation, apiUpdateReferralCode, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, apiVerifyBuyerTeePayment, appendAttributionToCalldata, assertValidReferrerFeeConfig, calculateBondedTakingCapacity, calculateChargebackReserve, calculateFreeTakeCapacity, calculateGriefingPenalty, calculateMaxGriefingBond, calculateRequiredReservation, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createEncryptedBuyerTeeSessionMaterial, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferralCode, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, normalizeReferralCode, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
|
|
9071
9441
|
//# sourceMappingURL=index.mjs.map
|
|
9072
9442
|
//# sourceMappingURL=index.mjs.map
|