@zkp2p/sdk 0.8.1 → 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 +57 -15
- package/dist/{chunk-ZM4ZP5GQ.mjs → chunk-7M37EVN5.mjs} +33438 -452
- 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 +35375 -1935
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +62 -64
- package/dist/index.d.ts +62 -64
- package/dist/index.mjs +508 -41
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-VDFKSVGT.mjs +5 -0
- package/dist/{protocolViewerParsers-GG6UQKLO.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-BGDsoxAv.d.mts → vaultUtils-DtkWNsxi.d.mts} +440 -103
- package/dist/{vaultUtils-BGDsoxAv.d.ts → vaultUtils-DtkWNsxi.d.ts} +440 -103
- package/package.json +4 -4
- package/dist/chunk-EIOXBVXP.mjs.map +0 -1
- package/dist/chunk-ZM4ZP5GQ.mjs.map +0 -1
- package/dist/protocolViewerParsers-GG6UQKLO.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 { getContracts, getRateManagerContracts, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, parseBigIntLike, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash } from './chunk-
|
|
5
|
-
export { 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';
|
|
@@ -813,25 +813,10 @@ async function sendTransactionWithAttribution(walletClient, request, referrer, o
|
|
|
813
813
|
});
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
// src/types/index.ts
|
|
817
|
-
var PAYMENT_PLATFORMS = [
|
|
818
|
-
"wise",
|
|
819
|
-
"venmo",
|
|
820
|
-
"revolut",
|
|
821
|
-
"cashapp",
|
|
822
|
-
"mercadopago",
|
|
823
|
-
"zelle",
|
|
824
|
-
"paypal",
|
|
825
|
-
"monzo",
|
|
826
|
-
"chime",
|
|
827
|
-
"luxon",
|
|
828
|
-
"n26"
|
|
829
|
-
];
|
|
830
|
-
|
|
831
816
|
// src/utils/constants.ts
|
|
832
817
|
var DEFAULT_BASE_API_URL = "https://api.zkp2p.xyz";
|
|
833
818
|
|
|
834
|
-
// ../../node_modules/.pnpm/@zkp2p+contracts-v2@0.
|
|
819
|
+
// ../../node_modules/.pnpm/@zkp2p+contracts-v2@0.3.0_ethers@6.16.0_bufferutil@4.1.0_utf-8-validate@5.0.10__typescript@5.9.3_zod@4.2.1/node_modules/@zkp2p/contracts-v2/oracleFeeds/chainlink.json
|
|
835
820
|
var chainlink_default = {
|
|
836
821
|
feeds: [
|
|
837
822
|
{
|
|
@@ -1983,7 +1968,7 @@ var ProtocolViewerReader = class {
|
|
|
1983
1968
|
if (inputCount === null) {
|
|
1984
1969
|
throw new Error("Configured ProtocolViewer ABI does not expose getDeposit");
|
|
1985
1970
|
}
|
|
1986
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
1971
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
1987
1972
|
if (inputCount >= 3) {
|
|
1988
1973
|
return tryContexts(
|
|
1989
1974
|
protocolViewerContexts,
|
|
@@ -2062,7 +2047,7 @@ var ProtocolViewerReader = class {
|
|
|
2062
2047
|
return Promise.all(ids.map((id) => this.config.host.getPvDepositById(id)));
|
|
2063
2048
|
}
|
|
2064
2049
|
const bn = ids.map((id) => typeof id === "bigint" ? id : parseRawDepositId(id));
|
|
2065
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2050
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2066
2051
|
if (inputCount >= 2) {
|
|
2067
2052
|
const requests = ids.map((id, index) => ({
|
|
2068
2053
|
index,
|
|
@@ -2167,7 +2152,7 @@ var ProtocolViewerReader = class {
|
|
|
2167
2152
|
if (!protocolViewerAddress || !protocolViewerAbi || inputCount === null) {
|
|
2168
2153
|
return this.config.host.getPvAccountDepositsFromIndexer(owner);
|
|
2169
2154
|
}
|
|
2170
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2155
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2171
2156
|
const { address, abi } = this.config.host.requireProtocolViewer();
|
|
2172
2157
|
if (inputCount >= 2) {
|
|
2173
2158
|
const readAndFilter = async (raw2) => {
|
|
@@ -2238,7 +2223,7 @@ var ProtocolViewerReader = class {
|
|
|
2238
2223
|
if (protocolViewerEntries.length === 0) {
|
|
2239
2224
|
throw new Error("ProtocolViewer not available for this network");
|
|
2240
2225
|
}
|
|
2241
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2226
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2242
2227
|
const intentsByHash = /* @__PURE__ */ new Map();
|
|
2243
2228
|
let attemptedRead = false;
|
|
2244
2229
|
let hadSuccessfulRead = false;
|
|
@@ -2346,7 +2331,7 @@ var ProtocolViewerReader = class {
|
|
|
2346
2331
|
if (protocolViewerEntries.length === 0) {
|
|
2347
2332
|
throw new Error("ProtocolViewer not available for this network");
|
|
2348
2333
|
}
|
|
2349
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2334
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-VDFKSVGT.mjs');
|
|
2350
2335
|
let lastError;
|
|
2351
2336
|
for (const pvEntry of protocolViewerEntries) {
|
|
2352
2337
|
const inputCount = this.pvEntryFunctionInputCount(pvEntry, "getIntent");
|
|
@@ -3558,7 +3543,7 @@ var MAKER_FUND_ACTIVITIES_QUERY = (
|
|
|
3558
3543
|
`
|
|
3559
3544
|
query GetMakerFundActivities($depositor: String!, $limit: Int) {
|
|
3560
3545
|
DepositFundActivity(
|
|
3561
|
-
where: { depositor: {
|
|
3546
|
+
where: { depositor: { _ilike: $depositor } }
|
|
3562
3547
|
order_by: { timestamp: desc }
|
|
3563
3548
|
limit: $limit
|
|
3564
3549
|
) {
|
|
@@ -4337,6 +4322,7 @@ function buildLegacyVerifierCurrencies(deposit) {
|
|
|
4337
4322
|
const currenciesByMethod = /* @__PURE__ */ new Map();
|
|
4338
4323
|
for (const currency of deposit.currencies ?? []) {
|
|
4339
4324
|
const methodHash = currency.paymentMethodHash;
|
|
4325
|
+
if (!SUPPORTED_PAYMENT_METHOD_HASHES.has(methodHash.toLowerCase())) continue;
|
|
4340
4326
|
const resolvedConversionRate = currency.conversionRate ?? currency.minConversionRate;
|
|
4341
4327
|
if (resolvedConversionRate === null || resolvedConversionRate === void 0) {
|
|
4342
4328
|
logger.warn(
|
|
@@ -4358,7 +4344,9 @@ function buildLegacyVerifierCurrencies(deposit) {
|
|
|
4358
4344
|
}
|
|
4359
4345
|
function convertIndexerDepositToLegacyApiDeposit(deposit) {
|
|
4360
4346
|
const currenciesByMethod = buildLegacyVerifierCurrencies(deposit);
|
|
4361
|
-
const verifiers = (deposit.paymentMethods ?? []).filter(
|
|
4347
|
+
const verifiers = (deposit.paymentMethods ?? []).filter(
|
|
4348
|
+
(paymentMethod) => paymentMethod.active !== false && SUPPORTED_PAYMENT_METHOD_HASHES.has(paymentMethod.paymentMethodHash.toLowerCase())
|
|
4349
|
+
).map((paymentMethod) => ({
|
|
4362
4350
|
depositId: Number(deposit.depositId),
|
|
4363
4351
|
verifier: "",
|
|
4364
4352
|
methodHash: paymentMethod.paymentMethodHash,
|
|
@@ -4460,13 +4448,28 @@ async function apiGetQuotesBestByPlatform(req, baseApiUrl, timeoutMs, apiKey) {
|
|
|
4460
4448
|
Object.keys(requestBody).forEach(
|
|
4461
4449
|
(key) => requestBody[key] === void 0 && delete requestBody[key]
|
|
4462
4450
|
);
|
|
4463
|
-
|
|
4451
|
+
const response = await apiFetch({
|
|
4464
4452
|
url,
|
|
4465
4453
|
method: "POST",
|
|
4466
4454
|
body: requestBody,
|
|
4467
4455
|
apiKey,
|
|
4468
4456
|
timeoutMs
|
|
4469
4457
|
});
|
|
4458
|
+
return {
|
|
4459
|
+
...response,
|
|
4460
|
+
responseObject: {
|
|
4461
|
+
...response.responseObject,
|
|
4462
|
+
platformQuotes: (response.responseObject?.platformQuotes ?? []).filter((platformQuote) => {
|
|
4463
|
+
const platform = platformQuote.platform.trim().toLowerCase();
|
|
4464
|
+
if (!METHOD_NAME_TO_HASH[platform]) return false;
|
|
4465
|
+
if (!platformQuote.bestQuote) return true;
|
|
4466
|
+
return platform === platformQuote.bestQuote.intent.processorName.trim().toLowerCase() && matchesQuotePaymentMethod(
|
|
4467
|
+
platformQuote.bestQuote.intent.processorName,
|
|
4468
|
+
platformQuote.bestQuote.paymentMethod
|
|
4469
|
+
);
|
|
4470
|
+
})
|
|
4471
|
+
}
|
|
4472
|
+
};
|
|
4470
4473
|
}
|
|
4471
4474
|
async function apiGetPayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
4472
4475
|
return apiFetch({
|
|
@@ -4522,13 +4525,26 @@ async function apiGetOwnerDeposits(req, apiKey, baseApiUrl, authToken, timeoutMs
|
|
|
4522
4525
|
statusCode: 200
|
|
4523
4526
|
};
|
|
4524
4527
|
}
|
|
4525
|
-
async function
|
|
4528
|
+
async function apiGetTakerStake(req, baseApiUrl, timeoutMs) {
|
|
4529
|
+
const normalizedOwner = req.owner.toLowerCase();
|
|
4530
|
+
const query = new URLSearchParams({
|
|
4531
|
+
owner: normalizedOwner,
|
|
4532
|
+
chainId: String(req.chainId)
|
|
4533
|
+
});
|
|
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) {
|
|
4526
4542
|
const normalizedOwner = req.owner.toLowerCase();
|
|
4527
4543
|
const query = new URLSearchParams({
|
|
4528
4544
|
owner: normalizedOwner,
|
|
4529
4545
|
chainId: String(req.chainId)
|
|
4530
4546
|
});
|
|
4531
|
-
const endpoint = `/v2/taker/
|
|
4547
|
+
const endpoint = `/v2/taker/capacity?${query.toString()}`;
|
|
4532
4548
|
return apiFetch({
|
|
4533
4549
|
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4534
4550
|
method: "GET",
|
|
@@ -4687,7 +4703,35 @@ async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs) {
|
|
|
4687
4703
|
method: "GET",
|
|
4688
4704
|
timeoutMs: opts.timeoutMs
|
|
4689
4705
|
});
|
|
4690
|
-
return
|
|
4706
|
+
return {
|
|
4707
|
+
...response.responseObject,
|
|
4708
|
+
entries: response.responseObject.entries.filter(
|
|
4709
|
+
(entry) => matchesPaymentMethodNameAndHash(entry.paymentPlatform, entry.paymentMethodHash)
|
|
4710
|
+
)
|
|
4711
|
+
};
|
|
4712
|
+
}
|
|
4713
|
+
async function apiGetOrderbookTable(params, optsOrBaseApiUrl, timeoutMs) {
|
|
4714
|
+
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
4715
|
+
baseApiUrl: optsOrBaseApiUrl,
|
|
4716
|
+
timeoutMs
|
|
4717
|
+
} : optsOrBaseApiUrl;
|
|
4718
|
+
const query = new URLSearchParams();
|
|
4719
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
4720
|
+
if (value === void 0 || value === null) return;
|
|
4721
|
+
query.set(key, String(value));
|
|
4722
|
+
});
|
|
4723
|
+
const response = await apiFetch({
|
|
4724
|
+
url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook/table?${query.toString()}`,
|
|
4725
|
+
method: "GET",
|
|
4726
|
+
timeoutMs: opts.timeoutMs
|
|
4727
|
+
});
|
|
4728
|
+
const responseObject = unwrapResponseObject(response);
|
|
4729
|
+
return {
|
|
4730
|
+
...responseObject,
|
|
4731
|
+
rows: responseObject.rows.filter(
|
|
4732
|
+
(row) => matchesPaymentMethodNameAndHash(row.paymentPlatform, row.paymentMethodHash)
|
|
4733
|
+
)
|
|
4734
|
+
};
|
|
4691
4735
|
}
|
|
4692
4736
|
async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs) {
|
|
4693
4737
|
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
@@ -5221,6 +5265,125 @@ var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && ab
|
|
|
5221
5265
|
(item) => item.type === "function" && item.name === functionName
|
|
5222
5266
|
);
|
|
5223
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
|
+
|
|
5224
5387
|
// src/indexer/rateManagerService.ts
|
|
5225
5388
|
var DEFAULT_LIMIT2 = 50;
|
|
5226
5389
|
var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
|
|
@@ -6187,6 +6350,12 @@ function normalizeQuotePayeeData(maker) {
|
|
|
6187
6350
|
metadata: isObjectRecord(maker?.metadata) ? maker.metadata : legacy?.metadata ?? null
|
|
6188
6351
|
};
|
|
6189
6352
|
}
|
|
6353
|
+
function isActiveQuotePaymentMethod(quote) {
|
|
6354
|
+
if (!quote?.intent || typeof quote.intent.processorName !== "string" || typeof quote.paymentMethod !== "string") {
|
|
6355
|
+
return false;
|
|
6356
|
+
}
|
|
6357
|
+
return matchesQuotePaymentMethod(quote.intent.processorName, quote.paymentMethod);
|
|
6358
|
+
}
|
|
6190
6359
|
function normalizePayeeDataInputItem(raw) {
|
|
6191
6360
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
6192
6361
|
return null;
|
|
@@ -6235,6 +6404,7 @@ function resolvePayeeDataInput(params, methodName) {
|
|
|
6235
6404
|
return normalized;
|
|
6236
6405
|
}
|
|
6237
6406
|
function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
6407
|
+
assertKnownProcessorName(processorName, `processorNames[${index}]`);
|
|
6238
6408
|
if (!payeeData || typeof payeeData.offchainId !== "string" || payeeData.offchainId.length === 0) {
|
|
6239
6409
|
throw new Error(`payeeData[${index}] must include a non-empty offchainId`);
|
|
6240
6410
|
}
|
|
@@ -6245,6 +6415,26 @@ function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
|
6245
6415
|
metadata: getPayeeRegistrationMetadata(payeeData)
|
|
6246
6416
|
};
|
|
6247
6417
|
}
|
|
6418
|
+
function assertKnownProcessorName(processorName, field) {
|
|
6419
|
+
if (!METHOD_NAME_TO_HASH[processorName.toLowerCase()]) {
|
|
6420
|
+
throw new ValidationError(`Unknown processorName: ${processorName}`, field);
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
function assertCatalogPaymentMethods(paymentMethods, chainId, runtimeEnv, field) {
|
|
6424
|
+
const catalogHashes = new Set(
|
|
6425
|
+
Object.values(getPaymentMethodsCatalog(chainId, runtimeEnv)).map(
|
|
6426
|
+
(entry) => entry.paymentMethodHash.toLowerCase()
|
|
6427
|
+
)
|
|
6428
|
+
);
|
|
6429
|
+
paymentMethods.forEach((paymentMethod, index) => {
|
|
6430
|
+
if (!catalogHashes.has(paymentMethod.toLowerCase())) {
|
|
6431
|
+
throw new ValidationError(
|
|
6432
|
+
`Unsupported payment method hash: ${paymentMethod}`,
|
|
6433
|
+
`${field}[${index}]`
|
|
6434
|
+
);
|
|
6435
|
+
}
|
|
6436
|
+
});
|
|
6437
|
+
}
|
|
6248
6438
|
var Zkp2pClient = class {
|
|
6249
6439
|
/**
|
|
6250
6440
|
* Creates a new Zkp2pClient instance.
|
|
@@ -6253,6 +6443,46 @@ var Zkp2pClient = class {
|
|
|
6253
6443
|
* @throws Error if walletClient is missing an account
|
|
6254
6444
|
*/
|
|
6255
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
|
+
);
|
|
6256
6486
|
// ╔═══════════════════════════════════════════════════════════════════════════╗
|
|
6257
6487
|
// ║ CORE: DEPOSIT MANAGEMENT ║
|
|
6258
6488
|
// ╚═══════════════════════════════════════════════════════════════════════════╝
|
|
@@ -6597,6 +6827,12 @@ var Zkp2pClient = class {
|
|
|
6597
6827
|
*/
|
|
6598
6828
|
this.addPaymentMethods = Object.assign(
|
|
6599
6829
|
async (params) => {
|
|
6830
|
+
assertCatalogPaymentMethods(
|
|
6831
|
+
params.paymentMethods,
|
|
6832
|
+
this.chainId,
|
|
6833
|
+
this.runtimeEnv,
|
|
6834
|
+
"paymentMethods"
|
|
6835
|
+
);
|
|
6600
6836
|
const escrowContext = await this.resolveEscrowContextForDepositWrite({
|
|
6601
6837
|
escrowAddress: params.escrowAddress,
|
|
6602
6838
|
depositId: params.depositId,
|
|
@@ -6621,6 +6857,12 @@ var Zkp2pClient = class {
|
|
|
6621
6857
|
},
|
|
6622
6858
|
{
|
|
6623
6859
|
prepare: async (params) => {
|
|
6860
|
+
assertCatalogPaymentMethods(
|
|
6861
|
+
params.paymentMethods,
|
|
6862
|
+
this.chainId,
|
|
6863
|
+
this.runtimeEnv,
|
|
6864
|
+
"paymentMethods"
|
|
6865
|
+
);
|
|
6624
6866
|
const escrowContext = await this.resolveEscrowContextForDepositWrite({
|
|
6625
6867
|
escrowAddress: params.escrowAddress,
|
|
6626
6868
|
depositId: params.depositId,
|
|
@@ -7139,6 +7381,8 @@ var Zkp2pClient = class {
|
|
|
7139
7381
|
this.rateManagerRegistryAbi = abis.rateManagerRegistry ?? this.rateManagerV1Abi;
|
|
7140
7382
|
this.rateManagerControllerAddress = toAddress(addresses.rateManagerController);
|
|
7141
7383
|
this.rateManagerControllerAbi = abis.rateManagerController;
|
|
7384
|
+
this.stakeVaultAddress = toAddress(addresses.stakeVault);
|
|
7385
|
+
this.stakeVaultAbi = abis.stakeVault;
|
|
7142
7386
|
if (!this.rateManagerRegistryAddress || !this.rateManagerRegistryAbi) {
|
|
7143
7387
|
try {
|
|
7144
7388
|
const rateManagerContracts = getRateManagerContracts(this.chainId, this.runtimeEnv);
|
|
@@ -7219,6 +7463,12 @@ var Zkp2pClient = class {
|
|
|
7219
7463
|
prepareContractTransaction: (tx) => this.prepareContractTransaction(tx)
|
|
7220
7464
|
}
|
|
7221
7465
|
});
|
|
7466
|
+
this._stakeOps = new StakeOperations({
|
|
7467
|
+
getPublicClient: () => this.publicClient,
|
|
7468
|
+
getStakeVaultAddress: () => this.stakeVaultAddress,
|
|
7469
|
+
getStakeVaultAbi: () => this.stakeVaultAbi,
|
|
7470
|
+
getStakeTokenAddress: () => this._usdcAddress
|
|
7471
|
+
});
|
|
7222
7472
|
this._intentOps = new IntentOperations({
|
|
7223
7473
|
getWalletClient: () => this.walletClient,
|
|
7224
7474
|
getPublicClient: () => this.publicClient,
|
|
@@ -7676,6 +7926,17 @@ var Zkp2pClient = class {
|
|
|
7676
7926
|
}
|
|
7677
7927
|
);
|
|
7678
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
|
+
}
|
|
7679
7940
|
buildEscrowMethod(functionName, buildArgs, buildValue) {
|
|
7680
7941
|
return Object.assign(
|
|
7681
7942
|
async (params) => {
|
|
@@ -8133,6 +8394,70 @@ var Zkp2pClient = class {
|
|
|
8133
8394
|
});
|
|
8134
8395
|
return { hadAllowance: false, hash };
|
|
8135
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
|
+
}
|
|
8136
8461
|
/**
|
|
8137
8462
|
* Registers payee details with the curator API and returns hashed on-chain IDs.
|
|
8138
8463
|
*
|
|
@@ -8252,6 +8577,9 @@ var Zkp2pClient = class {
|
|
|
8252
8577
|
if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
|
|
8253
8578
|
throw new Error("processorNames must be a non-empty array");
|
|
8254
8579
|
}
|
|
8580
|
+
params.processorNames.forEach(
|
|
8581
|
+
(processorName, index) => assertKnownProcessorName(processorName, `processorNames[${index}]`)
|
|
8582
|
+
);
|
|
8255
8583
|
if (params.processorNames.length !== params.conversionRates.length) {
|
|
8256
8584
|
throw new Error("processorNames and conversionRates length mismatch");
|
|
8257
8585
|
}
|
|
@@ -8280,6 +8608,12 @@ var Zkp2pClient = class {
|
|
|
8280
8608
|
"paymentMethodsOverride, paymentMethodDataOverride, and currenciesOverride length mismatch"
|
|
8281
8609
|
);
|
|
8282
8610
|
}
|
|
8611
|
+
assertCatalogPaymentMethods(
|
|
8612
|
+
params.paymentMethodsOverride,
|
|
8613
|
+
this.chainId,
|
|
8614
|
+
this.runtimeEnv,
|
|
8615
|
+
"paymentMethodsOverride"
|
|
8616
|
+
);
|
|
8283
8617
|
paymentMethods = params.paymentMethodsOverride;
|
|
8284
8618
|
paymentMethodData = params.paymentMethodDataOverride;
|
|
8285
8619
|
currencies = params.currenciesOverride;
|
|
@@ -8468,6 +8802,9 @@ var Zkp2pClient = class {
|
|
|
8468
8802
|
*/
|
|
8469
8803
|
async getQuote(req, opts) {
|
|
8470
8804
|
const referrerFeeConfig = assertValidReferrerFeeConfig(req.referrerFeeConfig, "getQuote");
|
|
8805
|
+
req.paymentPlatforms.forEach(
|
|
8806
|
+
(processorName, index) => assertKnownProcessorName(processorName, `paymentPlatforms[${index}]`)
|
|
8807
|
+
);
|
|
8471
8808
|
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8472
8809
|
/\/$/,
|
|
8473
8810
|
""
|
|
@@ -8481,7 +8818,18 @@ var Zkp2pClient = class {
|
|
|
8481
8818
|
}
|
|
8482
8819
|
}
|
|
8483
8820
|
const quote = await apiGetQuote(reqWithEscrow, baseApiUrl, timeoutMs, this.apiKey);
|
|
8484
|
-
const quotes = quote?.responseObject?.quotes ?? [];
|
|
8821
|
+
const quotes = (quote?.responseObject?.quotes ?? []).filter(isActiveQuotePaymentMethod);
|
|
8822
|
+
quote.responseObject.quotes = quotes;
|
|
8823
|
+
if (quote.responseObject.nearbySuggestions) {
|
|
8824
|
+
quote.responseObject.nearbySuggestions = {
|
|
8825
|
+
below: quote.responseObject.nearbySuggestions.below.filter(
|
|
8826
|
+
(suggestion) => isActiveQuotePaymentMethod(suggestion.quote)
|
|
8827
|
+
),
|
|
8828
|
+
above: quote.responseObject.nearbySuggestions.above.filter(
|
|
8829
|
+
(suggestion) => isActiveQuotePaymentMethod(suggestion.quote)
|
|
8830
|
+
)
|
|
8831
|
+
};
|
|
8832
|
+
}
|
|
8485
8833
|
for (const q of quotes) {
|
|
8486
8834
|
const payeeData = normalizeQuotePayeeData(q.maker);
|
|
8487
8835
|
if (payeeData) {
|
|
@@ -8527,7 +8875,11 @@ var Zkp2pClient = class {
|
|
|
8527
8875
|
...quote,
|
|
8528
8876
|
responseObject: {
|
|
8529
8877
|
...quote.responseObject,
|
|
8530
|
-
platformQuotes: (quote.responseObject?.platformQuotes ?? []).
|
|
8878
|
+
platformQuotes: (quote.responseObject?.platformQuotes ?? []).filter((platformQuote) => {
|
|
8879
|
+
const platform = platformQuote.platform.trim().toLowerCase();
|
|
8880
|
+
if (!METHOD_NAME_TO_HASH[platform]) return false;
|
|
8881
|
+
return !platformQuote.bestQuote || platform === platformQuote.bestQuote.intent.processorName.trim().toLowerCase() && isActiveQuotePaymentMethod(platformQuote.bestQuote);
|
|
8882
|
+
}).map((platformQuote) => {
|
|
8531
8883
|
const bestQuote = platformQuote?.bestQuote;
|
|
8532
8884
|
const payeeData = normalizeQuotePayeeData(bestQuote?.maker);
|
|
8533
8885
|
if (!bestQuote || !payeeData) return platformQuote;
|
|
@@ -8541,25 +8893,48 @@ var Zkp2pClient = class {
|
|
|
8541
8893
|
return appendReferrerFeeDisplayFieldsToBestByPlatform(enrichedQuote, referrerFeeConfig);
|
|
8542
8894
|
}
|
|
8543
8895
|
// ───────────────────────────────────────────────────────────────────────────
|
|
8544
|
-
// SUPPORTING: TAKER
|
|
8545
|
-
// (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)
|
|
8546
8899
|
// ───────────────────────────────────────────────────────────────────────────
|
|
8547
8900
|
/**
|
|
8548
|
-
* **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.
|
|
8549
8904
|
*
|
|
8550
|
-
* @param req -
|
|
8551
|
-
* @param req.owner - Taker address
|
|
8905
|
+
* @param req - Stake request parameters
|
|
8906
|
+
* @param req.owner - Taker address (the resolved stake owner may differ)
|
|
8552
8907
|
* @param req.chainId - Chain ID
|
|
8553
8908
|
* @param opts - Optional overrides for API URL and timeout
|
|
8554
|
-
* @returns Taker
|
|
8909
|
+
* @returns Taker stake response
|
|
8555
8910
|
*/
|
|
8556
|
-
async
|
|
8911
|
+
async getTakerStake(req, opts) {
|
|
8557
8912
|
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8558
8913
|
/\/$/,
|
|
8559
8914
|
""
|
|
8560
8915
|
);
|
|
8561
8916
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8562
|
-
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);
|
|
8563
8938
|
}
|
|
8564
8939
|
/**
|
|
8565
8940
|
* Fetch a referral dashboard. Pass `address` for a public wallet-keyed read;
|
|
@@ -8896,6 +9271,7 @@ var Zkp2pClient = class {
|
|
|
8896
9271
|
unifiedPaymentVerifier: this.unifiedPaymentVerifier,
|
|
8897
9272
|
rateManagerV1: this.rateManagerV1Address,
|
|
8898
9273
|
orchestratorRegistry: this.orchestratorRegistryAddress,
|
|
9274
|
+
stakeVault: this.stakeVaultAddress,
|
|
8899
9275
|
usdc: this._usdcAddress
|
|
8900
9276
|
};
|
|
8901
9277
|
}
|
|
@@ -8970,6 +9346,97 @@ var createPeerExtensionSdk = (options = {}) => ({
|
|
|
8970
9346
|
});
|
|
8971
9347
|
var peerExtensionSdk = createPeerExtensionSdk();
|
|
8972
9348
|
|
|
8973
|
-
|
|
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 };
|
|
8974
9441
|
//# sourceMappingURL=index.mjs.map
|
|
8975
9442
|
//# sourceMappingURL=index.mjs.map
|