@zkp2p/sdk 0.2.4 → 0.3.1
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 +6 -6
- package/dist/index.cjs +279 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.mjs +278 -77
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +4 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +4 -10
- package/dist/react.d.ts +4 -10
- package/dist/react.mjs +4 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{vaultUtils-C2wT1ZYY.d.mts → vaultUtils-DATqc35J.d.mts} +125 -40
- package/dist/{vaultUtils-C2wT1ZYY.d.ts → vaultUtils-DATqc35J.d.ts} +125 -40
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -11,16 +11,8 @@ import { AbiCoder } from 'ethers';
|
|
|
11
11
|
import { Attribution } from 'ox/erc8021';
|
|
12
12
|
import chainlinkFeeds from '@zkp2p/contracts-v2/oracleFeeds/chainlink.json';
|
|
13
13
|
|
|
14
|
-
// src/
|
|
14
|
+
// src/utils/address.ts
|
|
15
15
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
16
|
-
var MIN_ORACLE_SPREAD_BPS = -32768;
|
|
17
|
-
var MAX_ORACLE_SPREAD_BPS = 32767;
|
|
18
|
-
var EMPTY_ORACLE_RATE_CONFIG = {
|
|
19
|
-
adapter: ZERO_ADDRESS,
|
|
20
|
-
adapterConfig: "0x",
|
|
21
|
-
spreadBps: 0,
|
|
22
|
-
maxStaleness: 0
|
|
23
|
-
};
|
|
24
16
|
var isValidHexAddress = (addr) => {
|
|
25
17
|
if (typeof addr !== "string") return false;
|
|
26
18
|
return /^0x[0-9a-fA-F]{40}$/.test(addr);
|
|
@@ -29,6 +21,16 @@ var normalizeAddress = (addr) => {
|
|
|
29
21
|
if (!isValidHexAddress(addr)) return void 0;
|
|
30
22
|
return addr;
|
|
31
23
|
};
|
|
24
|
+
|
|
25
|
+
// src/client/clientUtils.ts
|
|
26
|
+
var MIN_ORACLE_SPREAD_BPS = -32768;
|
|
27
|
+
var MAX_ORACLE_SPREAD_BPS = 32767;
|
|
28
|
+
var EMPTY_ORACLE_RATE_CONFIG = {
|
|
29
|
+
adapter: ZERO_ADDRESS,
|
|
30
|
+
adapterConfig: "0x",
|
|
31
|
+
spreadBps: 0,
|
|
32
|
+
maxStaleness: 0
|
|
33
|
+
};
|
|
32
34
|
var parseEscrowAddressFromCompositeDepositId = (depositId) => {
|
|
33
35
|
if (typeof depositId !== "string") return void 0;
|
|
34
36
|
const parts = depositId.split("_");
|
|
@@ -331,9 +333,6 @@ function parseAPIError(response, responseText) {
|
|
|
331
333
|
} catch {
|
|
332
334
|
if (responseText && responseText.length < 200) message = responseText;
|
|
333
335
|
}
|
|
334
|
-
if (response.status === 429) {
|
|
335
|
-
message = "Too many requests. Please try again later.";
|
|
336
|
-
}
|
|
337
336
|
return new APIError(message, response.status, { url: response.url });
|
|
338
337
|
}
|
|
339
338
|
async function withRetry(fn, maxRetries = 3, delayMs = 1e3, timeoutMs) {
|
|
@@ -368,7 +367,7 @@ function createHeaders(apiKey, authorizationToken) {
|
|
|
368
367
|
return headers2;
|
|
369
368
|
}
|
|
370
369
|
async function apiSignIntentV3(request, opts) {
|
|
371
|
-
const url = `${opts.baseApiUrl.replace(/\/$/, "")}/v3/intent`;
|
|
370
|
+
const url = `${opts.baseApiUrl.replace(/\/$/, "")}/v3/intent/sign`;
|
|
372
371
|
const json = await withRetry(
|
|
373
372
|
async () => {
|
|
374
373
|
let res;
|
|
@@ -380,7 +379,7 @@ async function apiSignIntentV3(request, opts) {
|
|
|
380
379
|
});
|
|
381
380
|
} catch (error) {
|
|
382
381
|
throw new NetworkError("Failed to connect to API server", {
|
|
383
|
-
endpoint: "/v3/intent",
|
|
382
|
+
endpoint: "/v3/intent/sign",
|
|
384
383
|
error
|
|
385
384
|
});
|
|
386
385
|
}
|
|
@@ -397,11 +396,13 @@ async function apiSignIntentV3(request, opts) {
|
|
|
397
396
|
const sig = json?.responseObject?.signedIntent;
|
|
398
397
|
const expStr = json?.responseObject?.intentData?.signatureExpiration ?? json?.responseObject?.signatureExpiration;
|
|
399
398
|
const preIntentHookData = json?.responseObject?.intentData?.preIntentHookData ?? json?.responseObject?.preIntentHookData;
|
|
400
|
-
|
|
399
|
+
const referralFees = json?.responseObject?.intentData?.referralFees ?? json?.responseObject?.referralFees;
|
|
400
|
+
if (!sig || !expStr) throw new Error("v3/intent/sign missing signature or expiration");
|
|
401
401
|
return {
|
|
402
402
|
signature: sig,
|
|
403
403
|
signatureExpiration: BigInt(expStr),
|
|
404
|
-
preIntentHookData
|
|
404
|
+
preIntentHookData,
|
|
405
|
+
referralFees
|
|
405
406
|
};
|
|
406
407
|
}
|
|
407
408
|
|
|
@@ -820,7 +821,7 @@ var IntentOperations = class {
|
|
|
820
821
|
const depositId = parseRawDepositId(params.depositId);
|
|
821
822
|
const amount = typeof params.amount === "bigint" ? params.amount : BigInt(params.amount);
|
|
822
823
|
const conversionRate = typeof params.conversionRate === "bigint" ? params.conversionRate : BigInt(params.conversionRate);
|
|
823
|
-
|
|
824
|
+
let referralFees = referrerFeeConfig !== void 0 ? [
|
|
824
825
|
{
|
|
825
826
|
recipient: referrerFeeConfig.recipient,
|
|
826
827
|
fee: referrerFeeConfigToPreciseUnits(referrerFeeConfig)
|
|
@@ -862,6 +863,23 @@ var IntentOperations = class {
|
|
|
862
863
|
gatingServiceSignature = response.signature;
|
|
863
864
|
signatureExpiration = response.signatureExpiration;
|
|
864
865
|
preIntentHookData = response.preIntentHookData ?? preIntentHookData;
|
|
866
|
+
if (response.referralFees !== void 0) {
|
|
867
|
+
referralFees = response.referralFees.map((referralFee) => {
|
|
868
|
+
if (!isValidReferrerFeeRecipient(referralFee.recipient)) {
|
|
869
|
+
throw new Error("v3/intent/sign returned invalid referral fee recipient");
|
|
870
|
+
}
|
|
871
|
+
let fee;
|
|
872
|
+
try {
|
|
873
|
+
fee = BigInt(referralFee.fee);
|
|
874
|
+
} catch {
|
|
875
|
+
throw new Error("v3/intent/sign returned non-integer referral fee value");
|
|
876
|
+
}
|
|
877
|
+
return {
|
|
878
|
+
recipient: referralFee.recipient,
|
|
879
|
+
fee
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
}
|
|
865
883
|
}
|
|
866
884
|
if (!gatingServiceSignature || !signatureExpiration) {
|
|
867
885
|
throw new Error("Missing gatingServiceSignature/signatureExpiration");
|
|
@@ -3489,9 +3507,10 @@ function convertIndexerDepositToEscrowView(deposit, _chainId, _escrowAddress) {
|
|
|
3489
3507
|
verifiers
|
|
3490
3508
|
};
|
|
3491
3509
|
}
|
|
3492
|
-
function convertDepositsForLiquidity(deposits, chainId, escrowAddress) {
|
|
3510
|
+
function convertDepositsForLiquidity(deposits, chainId, escrowAddress, options = {}) {
|
|
3511
|
+
const { includePrivateOrderbooks = false } = options;
|
|
3493
3512
|
return deposits.filter(
|
|
3494
|
-
(d) => d.depositor && d.depositor.toLowerCase() !== ZERO && normalizeAddress2(d.whitelistHookAddress).toLowerCase() === ZERO && d.acceptingIntents && toBigInt(d.remainingDeposits) > 0n && d.status === "ACTIVE"
|
|
3513
|
+
(d) => d.depositor && d.depositor.toLowerCase() !== ZERO && (includePrivateOrderbooks || normalizeAddress2(d.whitelistHookAddress).toLowerCase() === ZERO) && d.acceptingIntents && toBigInt(d.remainingDeposits) > 0n && d.status === "ACTIVE"
|
|
3495
3514
|
).map((d) => convertIndexerDepositToEscrowView(d));
|
|
3496
3515
|
}
|
|
3497
3516
|
function convertIndexerIntentsToEscrowViews(intents, depositViewsById) {
|
|
@@ -4821,13 +4840,11 @@ function convertIndexerDepositToLegacyApiDeposit(deposit) {
|
|
|
4821
4840
|
verifiers
|
|
4822
4841
|
};
|
|
4823
4842
|
}
|
|
4824
|
-
async function apiPostDepositDetails(req, baseApiUrl, timeoutMs,
|
|
4843
|
+
async function apiPostDepositDetails(req, baseApiUrl, timeoutMs, _apiKey, _authToken) {
|
|
4825
4844
|
return apiFetch({
|
|
4826
|
-
url: `${withApiBase(baseApiUrl)}/
|
|
4845
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/create`,
|
|
4827
4846
|
method: "POST",
|
|
4828
4847
|
body: req,
|
|
4829
|
-
apiKey,
|
|
4830
|
-
authToken,
|
|
4831
4848
|
timeoutMs
|
|
4832
4849
|
});
|
|
4833
4850
|
}
|
|
@@ -4837,16 +4854,29 @@ async function apiGetQuote(req, baseApiUrl, timeoutMs, apiKey, authToken) {
|
|
|
4837
4854
|
throw new ValidationError("quotesToReturn must be a positive integer", "quotesToReturn");
|
|
4838
4855
|
}
|
|
4839
4856
|
}
|
|
4857
|
+
if (!isValidHexAddress(req.user)) {
|
|
4858
|
+
throw new ValidationError("user must be a valid Ethereum address", "user");
|
|
4859
|
+
}
|
|
4860
|
+
if (!isValidHexAddress(req.recipient)) {
|
|
4861
|
+
throw new ValidationError("recipient must be a valid Ethereum address", "recipient");
|
|
4862
|
+
}
|
|
4863
|
+
if (!isValidHexAddress(req.destinationToken)) {
|
|
4864
|
+
throw new ValidationError(
|
|
4865
|
+
"destinationToken must be a valid Ethereum address",
|
|
4866
|
+
"destinationToken"
|
|
4867
|
+
);
|
|
4868
|
+
}
|
|
4840
4869
|
const isExactFiat = req.isExactFiat !== false;
|
|
4841
4870
|
const endpoint = isExactFiat ? "exact-fiat" : "exact-token";
|
|
4842
4871
|
let url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
4843
4872
|
if (req.quotesToReturn) url += `?quotesToReturn=${req.quotesToReturn}`;
|
|
4844
4873
|
const requestBody = {
|
|
4845
4874
|
...req,
|
|
4846
|
-
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: req.amount,
|
|
4875
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
4847
4876
|
amount: void 0,
|
|
4848
4877
|
isExactFiat: void 0,
|
|
4849
|
-
quotesToReturn: void 0
|
|
4878
|
+
quotesToReturn: void 0,
|
|
4879
|
+
includePrivateOrderbooks: req.includePrivateOrderbooks
|
|
4850
4880
|
};
|
|
4851
4881
|
Object.keys(requestBody).forEach((k) => requestBody[k] === void 0 && delete requestBody[k]);
|
|
4852
4882
|
return apiFetch({
|
|
@@ -4858,9 +4888,32 @@ async function apiGetQuote(req, baseApiUrl, timeoutMs, apiKey, authToken) {
|
|
|
4858
4888
|
timeoutMs
|
|
4859
4889
|
});
|
|
4860
4890
|
}
|
|
4891
|
+
async function apiGetQuotesBestByPlatform(req, baseApiUrl, timeoutMs, apiKey, authToken) {
|
|
4892
|
+
const isExactFiat = req.isExactFiat !== false;
|
|
4893
|
+
const endpoint = isExactFiat ? "best-by-platform" : "best-by-platform-exact-token";
|
|
4894
|
+
const url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
4895
|
+
const requestBody = {
|
|
4896
|
+
...req,
|
|
4897
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
4898
|
+
amount: void 0,
|
|
4899
|
+
isExactFiat: void 0,
|
|
4900
|
+
referrerFeeConfig: void 0
|
|
4901
|
+
};
|
|
4902
|
+
Object.keys(requestBody).forEach(
|
|
4903
|
+
(key) => requestBody[key] === void 0 && delete requestBody[key]
|
|
4904
|
+
);
|
|
4905
|
+
return apiFetch({
|
|
4906
|
+
url,
|
|
4907
|
+
method: "POST",
|
|
4908
|
+
body: requestBody,
|
|
4909
|
+
apiKey,
|
|
4910
|
+
authToken,
|
|
4911
|
+
timeoutMs
|
|
4912
|
+
});
|
|
4913
|
+
}
|
|
4861
4914
|
async function apiGetPayeeDetails(req, apiKey, baseApiUrl, authToken, timeoutMs) {
|
|
4862
4915
|
return apiFetch({
|
|
4863
|
-
url: `${baseApiUrl.replace(/\/$/, "")}/
|
|
4916
|
+
url: `${baseApiUrl.replace(/\/$/, "")}/v2/makers/${req.processorName}/${req.hashedOnchainId}`,
|
|
4864
4917
|
method: "GET",
|
|
4865
4918
|
apiKey,
|
|
4866
4919
|
authToken,
|
|
@@ -4869,7 +4922,7 @@ async function apiGetPayeeDetails(req, apiKey, baseApiUrl, authToken, timeoutMs)
|
|
|
4869
4922
|
}
|
|
4870
4923
|
async function apiValidatePayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
4871
4924
|
const data = await apiFetch({
|
|
4872
|
-
url: `${baseApiUrl.replace(/\/$/, "")}/
|
|
4925
|
+
url: `${baseApiUrl.replace(/\/$/, "")}/v2/makers/validate`,
|
|
4873
4926
|
method: "POST",
|
|
4874
4927
|
body: req,
|
|
4875
4928
|
timeoutMs
|
|
@@ -4924,7 +4977,6 @@ async function apiGetTakerTier(req, apiKey, baseApiUrl, timeoutMs) {
|
|
|
4924
4977
|
return apiFetch({
|
|
4925
4978
|
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4926
4979
|
method: "GET",
|
|
4927
|
-
apiKey,
|
|
4928
4980
|
timeoutMs
|
|
4929
4981
|
});
|
|
4930
4982
|
}
|
|
@@ -5021,6 +5073,23 @@ var appendReferrerFeeDisplayFields = (quoteResponse, referrerFeeConfig) => {
|
|
|
5021
5073
|
}
|
|
5022
5074
|
};
|
|
5023
5075
|
};
|
|
5076
|
+
var appendReferrerFeeDisplayFieldsToBestByPlatform = (quoteResponse, referrerFeeConfig) => {
|
|
5077
|
+
if (!referrerFeeConfig) {
|
|
5078
|
+
return quoteResponse;
|
|
5079
|
+
}
|
|
5080
|
+
const decimals = quoteResponse.responseObject?.token?.decimals ?? 6;
|
|
5081
|
+
const enrichedPlatformQuotes = (quoteResponse.responseObject?.platformQuotes ?? []).map((platformQuote) => ({
|
|
5082
|
+
...platformQuote,
|
|
5083
|
+
bestQuote: platformQuote.available && platformQuote.bestQuote ? applyReferrerFeeDisplayFieldsToQuote(platformQuote.bestQuote, referrerFeeConfig, decimals) : platformQuote.bestQuote
|
|
5084
|
+
}));
|
|
5085
|
+
return {
|
|
5086
|
+
...quoteResponse,
|
|
5087
|
+
responseObject: {
|
|
5088
|
+
...quoteResponse.responseObject,
|
|
5089
|
+
platformQuotes: enrichedPlatformQuotes
|
|
5090
|
+
}
|
|
5091
|
+
};
|
|
5092
|
+
};
|
|
5024
5093
|
|
|
5025
5094
|
// src/utils/erc20.ts
|
|
5026
5095
|
var ERC20_ABI = [
|
|
@@ -5047,6 +5116,95 @@ var ERC20_ABI = [
|
|
|
5047
5116
|
];
|
|
5048
5117
|
|
|
5049
5118
|
// src/client/Zkp2pClient.ts
|
|
5119
|
+
function isStringRecord(value) {
|
|
5120
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5121
|
+
return false;
|
|
5122
|
+
}
|
|
5123
|
+
return Object.values(value).every((entry) => typeof entry === "string");
|
|
5124
|
+
}
|
|
5125
|
+
function normalizeTelegramUsername(value) {
|
|
5126
|
+
if (typeof value !== "string") {
|
|
5127
|
+
return value === null ? null : null;
|
|
5128
|
+
}
|
|
5129
|
+
const normalized = value.trim();
|
|
5130
|
+
return normalized.length > 0 ? normalized : null;
|
|
5131
|
+
}
|
|
5132
|
+
function extractLegacyQuotePayeeData(depositData) {
|
|
5133
|
+
if (!depositData || typeof depositData !== "object" || Array.isArray(depositData)) {
|
|
5134
|
+
return void 0;
|
|
5135
|
+
}
|
|
5136
|
+
const stringEntries = Object.entries(depositData).filter(
|
|
5137
|
+
(entry) => typeof entry[1] === "string" && entry[1].trim().length > 0
|
|
5138
|
+
);
|
|
5139
|
+
const telegramUsername = stringEntries.find(([key]) => key === "telegramUsername")?.[1] ?? null;
|
|
5140
|
+
const identifierEntries = stringEntries.filter(([key]) => key !== "telegramUsername");
|
|
5141
|
+
const [primaryEntry, ...metadataEntries] = identifierEntries;
|
|
5142
|
+
if (!primaryEntry) {
|
|
5143
|
+
return void 0;
|
|
5144
|
+
}
|
|
5145
|
+
return {
|
|
5146
|
+
offchainId: primaryEntry[1],
|
|
5147
|
+
telegramUsername,
|
|
5148
|
+
metadata: metadataEntries.length > 0 ? Object.fromEntries(metadataEntries) : null
|
|
5149
|
+
};
|
|
5150
|
+
}
|
|
5151
|
+
function normalizeQuotePayeeData(maker) {
|
|
5152
|
+
const legacy = extractLegacyQuotePayeeData(maker?.depositData);
|
|
5153
|
+
const offchainId = typeof maker?.offchainId === "string" && maker.offchainId.trim().length > 0 ? maker.offchainId : legacy?.offchainId;
|
|
5154
|
+
if (!offchainId) {
|
|
5155
|
+
return void 0;
|
|
5156
|
+
}
|
|
5157
|
+
return {
|
|
5158
|
+
offchainId,
|
|
5159
|
+
telegramUsername: normalizeTelegramUsername(maker?.telegramUsername) ?? legacy?.telegramUsername ?? null,
|
|
5160
|
+
metadata: isStringRecord(maker?.metadata) ? maker.metadata : legacy?.metadata ?? null
|
|
5161
|
+
};
|
|
5162
|
+
}
|
|
5163
|
+
function normalizePayeeDataInputItem(raw) {
|
|
5164
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
5165
|
+
return null;
|
|
5166
|
+
}
|
|
5167
|
+
const candidate = raw;
|
|
5168
|
+
if (typeof candidate.offchainId === "string" && candidate.offchainId.trim().length > 0) {
|
|
5169
|
+
return candidate;
|
|
5170
|
+
}
|
|
5171
|
+
const legacy = extractLegacyQuotePayeeData(raw);
|
|
5172
|
+
if (!legacy) {
|
|
5173
|
+
return null;
|
|
5174
|
+
}
|
|
5175
|
+
return {
|
|
5176
|
+
offchainId: legacy.offchainId,
|
|
5177
|
+
telegramUsername: legacy.telegramUsername,
|
|
5178
|
+
metadata: legacy.metadata
|
|
5179
|
+
};
|
|
5180
|
+
}
|
|
5181
|
+
function resolvePayeeDataInput(params, methodName) {
|
|
5182
|
+
const payeeData = params.payeeData ?? params.depositData;
|
|
5183
|
+
if (!Array.isArray(payeeData)) {
|
|
5184
|
+
throw new Error(`${methodName} requires payeeData`);
|
|
5185
|
+
}
|
|
5186
|
+
const normalized = payeeData.map((item, index) => {
|
|
5187
|
+
const result = normalizePayeeDataInputItem(item);
|
|
5188
|
+
if (!result) {
|
|
5189
|
+
throw new Error(
|
|
5190
|
+
`${methodName}: payeeData[${index}] must include a non-empty offchainId or a recognizable legacy identifier`
|
|
5191
|
+
);
|
|
5192
|
+
}
|
|
5193
|
+
return result;
|
|
5194
|
+
});
|
|
5195
|
+
return normalized;
|
|
5196
|
+
}
|
|
5197
|
+
function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
5198
|
+
if (!payeeData || typeof payeeData.offchainId !== "string" || payeeData.offchainId.length === 0) {
|
|
5199
|
+
throw new Error(`payeeData[${index}] must include a non-empty offchainId`);
|
|
5200
|
+
}
|
|
5201
|
+
return {
|
|
5202
|
+
processorName,
|
|
5203
|
+
offchainId: payeeData.offchainId,
|
|
5204
|
+
telegramUsername: payeeData.telegramUsername,
|
|
5205
|
+
metadata: payeeData.metadata
|
|
5206
|
+
};
|
|
5207
|
+
}
|
|
5050
5208
|
var Zkp2pClient = class {
|
|
5051
5209
|
/**
|
|
5052
5210
|
* Creates a new Zkp2pClient instance.
|
|
@@ -5593,7 +5751,9 @@ var Zkp2pClient = class {
|
|
|
5593
5751
|
* sending fiat payment to the deposit's payee.
|
|
5594
5752
|
*
|
|
5595
5753
|
* If `gatingServiceSignature` is not provided, the SDK will automatically
|
|
5596
|
-
* fetch one from
|
|
5754
|
+
* fetch one from curator `/v3/intent/sign` when `apiKey` or `authorizationToken`
|
|
5755
|
+
* is available. Otherwise you must provide `gatingServiceSignature` and
|
|
5756
|
+
* `signatureExpiration` yourself.
|
|
5597
5757
|
*
|
|
5598
5758
|
* **Prepare Mode**: Use `.prepare()` to get the transaction calldata without sending:
|
|
5599
5759
|
* ```typescript
|
|
@@ -6905,42 +7065,32 @@ var Zkp2pClient = class {
|
|
|
6905
7065
|
* register maker payment details with the curator service.
|
|
6906
7066
|
*
|
|
6907
7067
|
* @param params.processorNames - Payment platforms (e.g., ['wise', 'revolut'])
|
|
6908
|
-
* @param params.
|
|
7068
|
+
* @param params.payeeData - Payee details per processor (e.g., [{ offchainId: 'you@example.com' }]). Required when the SDK needs to register payee details with the curator.
|
|
6909
7069
|
* @returns The posted deposit details and their corresponding hashed on-chain IDs
|
|
6910
7070
|
*
|
|
6911
7071
|
* @example
|
|
6912
7072
|
* ```typescript
|
|
6913
7073
|
* const { hashedOnchainIds } = await client.registerPayeeDetails({
|
|
6914
7074
|
* processorNames: ['wise'],
|
|
6915
|
-
*
|
|
7075
|
+
* payeeData: [{ offchainId: 'you@example.com' }],
|
|
6916
7076
|
* });
|
|
6917
7077
|
* // Then pass hashedOnchainIds to createDeposit
|
|
6918
7078
|
* ```
|
|
6919
7079
|
*/
|
|
6920
7080
|
async registerPayeeDetails(params) {
|
|
7081
|
+
const payeeData = resolvePayeeDataInput(params, "registerPayeeDetails");
|
|
6921
7082
|
if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
|
|
6922
7083
|
throw new Error("processorNames must be a non-empty array");
|
|
6923
7084
|
}
|
|
6924
|
-
if (params.processorNames.length !==
|
|
6925
|
-
throw new Error("processorNames and
|
|
7085
|
+
if (params.processorNames.length !== payeeData.length) {
|
|
7086
|
+
throw new Error("processorNames and payeeData length mismatch");
|
|
6926
7087
|
}
|
|
6927
7088
|
const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
|
|
6928
7089
|
const depositDetails = params.processorNames.map(
|
|
6929
|
-
(processorName, index) => (
|
|
6930
|
-
processorName,
|
|
6931
|
-
depositData: params.depositData[index] || {}
|
|
6932
|
-
})
|
|
7090
|
+
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
6933
7091
|
);
|
|
6934
7092
|
const apiResponses = await Promise.all(
|
|
6935
|
-
depositDetails.map(
|
|
6936
|
-
(req) => apiPostDepositDetails(
|
|
6937
|
-
req,
|
|
6938
|
-
baseApiUrl,
|
|
6939
|
-
this.apiTimeoutMs,
|
|
6940
|
-
this.apiKey,
|
|
6941
|
-
this.authorizationToken
|
|
6942
|
-
)
|
|
6943
|
-
)
|
|
7093
|
+
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
6944
7094
|
);
|
|
6945
7095
|
if (!apiResponses.every((r) => r?.success)) {
|
|
6946
7096
|
const failed = apiResponses.find((r) => !r?.success);
|
|
@@ -6964,16 +7114,17 @@ var Zkp2pClient = class {
|
|
|
6964
7114
|
* @param params.amount - Total deposit amount in token units (6 decimals for USDC)
|
|
6965
7115
|
* @param params.intentAmountRange - Min/max amount per intent
|
|
6966
7116
|
* @param params.processorNames - Payment platforms to accept (e.g., ['wise', 'revolut'])
|
|
6967
|
-
* @param params.
|
|
7117
|
+
* @param params.payeeData - Payee details per processor (e.g., [{ offchainId: 'you@example.com' }])
|
|
6968
7118
|
* @param params.conversionRates - Conversion rates per processor, grouped by currency
|
|
6969
7119
|
* @param params.payeeDetailsHashes - Pre-computed hashed on-chain IDs (from registerPayeeDetails). When provided, skips the curator API call entirely.
|
|
6970
7120
|
* @param params.delegate - Optional delegate address that can manage the deposit
|
|
6971
7121
|
* @param params.intentGuardian - Optional guardian for intent approval
|
|
6972
7122
|
* @param params.retainOnEmpty - Keep deposit active when balance reaches zero
|
|
6973
7123
|
* @param params.txOverrides - Optional viem transaction overrides
|
|
6974
|
-
* @returns The deposit details posted to API and the transaction hash
|
|
7124
|
+
* @returns The deposit details posted to API (empty when payee registration is skipped) and the transaction hash
|
|
6975
7125
|
*
|
|
6976
|
-
* @throws Error if processorNames,
|
|
7126
|
+
* @throws Error if processorNames, payeeData, and conversionRates lengths don't match
|
|
7127
|
+
* @throws Error if payeeData is missing and neither payeeDetailsHashes nor full payment method overrides are provided
|
|
6977
7128
|
* @throws Error if a currency is not supported by the specified processor
|
|
6978
7129
|
*
|
|
6979
7130
|
* @example
|
|
@@ -6984,7 +7135,7 @@ var Zkp2pClient = class {
|
|
|
6984
7135
|
* amount: 1000_000000n,
|
|
6985
7136
|
* intentAmountRange: { min: 10_000000n, max: 500_000000n },
|
|
6986
7137
|
* processorNames: ['wise'],
|
|
6987
|
-
*
|
|
7138
|
+
* payeeData: [{ offchainId: 'you@example.com' }],
|
|
6988
7139
|
* conversionRates: [[
|
|
6989
7140
|
* { currency: 'USD', conversionRate: '1020000000000000000' }, // 1.02
|
|
6990
7141
|
* { currency: 'EUR', conversionRate: '1100000000000000000' }, // 1.10
|
|
@@ -7017,24 +7168,30 @@ var Zkp2pClient = class {
|
|
|
7017
7168
|
};
|
|
7018
7169
|
}
|
|
7019
7170
|
async prepareCreateDepositInternal(params) {
|
|
7171
|
+
const hasOverrides = Boolean(
|
|
7172
|
+
params.paymentMethodsOverride || params.paymentMethodDataOverride || params.currenciesOverride
|
|
7173
|
+
);
|
|
7174
|
+
const payeeDetailsHashes = params.payeeDetailsHashes;
|
|
7175
|
+
const hasPayeeHashes = payeeDetailsHashes !== void 0;
|
|
7176
|
+
const shouldResolvePayeeData = params.payeeData !== void 0 || params.depositData !== void 0;
|
|
7177
|
+
const payeeData = shouldResolvePayeeData ? resolvePayeeDataInput(params, "createDeposit") : null;
|
|
7020
7178
|
if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
|
|
7021
7179
|
throw new Error("processorNames must be a non-empty array");
|
|
7022
7180
|
}
|
|
7023
7181
|
if (params.processorNames.length !== params.conversionRates.length) {
|
|
7024
7182
|
throw new Error("processorNames and conversionRates length mismatch");
|
|
7025
7183
|
}
|
|
7026
|
-
if (params.processorNames.length !==
|
|
7027
|
-
throw new Error("processorNames and
|
|
7184
|
+
if (payeeData && params.processorNames.length !== payeeData.length) {
|
|
7185
|
+
throw new Error("processorNames and payeeData length mismatch");
|
|
7028
7186
|
}
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
);
|
|
7187
|
+
if (!hasOverrides && !hasPayeeHashes && !payeeData) {
|
|
7188
|
+
throw new Error(
|
|
7189
|
+
"createDeposit requires payeeData unless payeeDetailsHashes or full payment method overrides are provided"
|
|
7190
|
+
);
|
|
7191
|
+
}
|
|
7192
|
+
const depositDetails = payeeData ? params.processorNames.map(
|
|
7193
|
+
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
7194
|
+
) : [];
|
|
7038
7195
|
let paymentMethods;
|
|
7039
7196
|
let paymentMethodData;
|
|
7040
7197
|
let currencies;
|
|
@@ -7059,23 +7216,15 @@ var Zkp2pClient = class {
|
|
|
7059
7216
|
);
|
|
7060
7217
|
const intentGatingService = getGatingServiceAddress(this.chainId, this.runtimeEnv);
|
|
7061
7218
|
let hashedOnchainIds;
|
|
7062
|
-
if (
|
|
7063
|
-
if (
|
|
7219
|
+
if (payeeDetailsHashes !== void 0) {
|
|
7220
|
+
if (payeeDetailsHashes.length !== params.processorNames.length) {
|
|
7064
7221
|
throw new Error("payeeDetailsHashes length must match processorNames length");
|
|
7065
7222
|
}
|
|
7066
|
-
hashedOnchainIds =
|
|
7223
|
+
hashedOnchainIds = payeeDetailsHashes;
|
|
7067
7224
|
} else {
|
|
7068
7225
|
const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
|
|
7069
7226
|
const apiResponses = await Promise.all(
|
|
7070
|
-
depositDetails.map(
|
|
7071
|
-
(req) => apiPostDepositDetails(
|
|
7072
|
-
req,
|
|
7073
|
-
baseApiUrl,
|
|
7074
|
-
this.apiTimeoutMs,
|
|
7075
|
-
this.apiKey,
|
|
7076
|
-
this.authorizationToken
|
|
7077
|
-
)
|
|
7078
|
-
)
|
|
7227
|
+
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
7079
7228
|
);
|
|
7080
7229
|
if (!apiResponses.every((r) => r?.success)) {
|
|
7081
7230
|
const failed = apiResponses.find((r) => !r?.success);
|
|
@@ -7272,12 +7421,64 @@ var Zkp2pClient = class {
|
|
|
7272
7421
|
const quotes = quote?.responseObject?.quotes ?? [];
|
|
7273
7422
|
for (const q of quotes) {
|
|
7274
7423
|
const maker = q?.maker;
|
|
7275
|
-
|
|
7276
|
-
|
|
7424
|
+
const payeeData = normalizeQuotePayeeData(maker);
|
|
7425
|
+
if (payeeData && typeof q === "object") {
|
|
7426
|
+
q.payeeData = payeeData;
|
|
7277
7427
|
}
|
|
7278
7428
|
}
|
|
7279
7429
|
return appendReferrerFeeDisplayFields(quote, referrerFeeConfig);
|
|
7280
7430
|
}
|
|
7431
|
+
/**
|
|
7432
|
+
* **Supporting Method** - Fetches the best available quote per supported payment platform.
|
|
7433
|
+
*
|
|
7434
|
+
* Returns one quote per platform when available. When authenticated, the API
|
|
7435
|
+
* returns payee details in each platform's best quote.
|
|
7436
|
+
*
|
|
7437
|
+
* @param req - Best-by-platform quote request parameters
|
|
7438
|
+
* @param opts - Optional overrides for API URL and timeout
|
|
7439
|
+
* @returns Best-by-platform quote response
|
|
7440
|
+
*/
|
|
7441
|
+
async getQuotesBestByPlatform(req, opts) {
|
|
7442
|
+
const referrerFeeConfig = assertValidReferrerFeeConfig(
|
|
7443
|
+
req.referrerFeeConfig,
|
|
7444
|
+
"getQuotesBestByPlatform"
|
|
7445
|
+
);
|
|
7446
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(
|
|
7447
|
+
/\/$/,
|
|
7448
|
+
""
|
|
7449
|
+
);
|
|
7450
|
+
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
7451
|
+
const reqWithEscrow = { ...req };
|
|
7452
|
+
if (!reqWithEscrow.escrowAddresses || reqWithEscrow.escrowAddresses.length === 0) {
|
|
7453
|
+
const configuredEscrows = this.escrowAddresses.length > 0 ? [...this.escrowAddresses] : this.escrowAddress ? [this.escrowAddress] : [];
|
|
7454
|
+
if (configuredEscrows.length > 0) {
|
|
7455
|
+
reqWithEscrow.escrowAddresses = configuredEscrows;
|
|
7456
|
+
}
|
|
7457
|
+
}
|
|
7458
|
+
const quote = await apiGetQuotesBestByPlatform(
|
|
7459
|
+
reqWithEscrow,
|
|
7460
|
+
baseApiUrl,
|
|
7461
|
+
timeoutMs,
|
|
7462
|
+
this.apiKey,
|
|
7463
|
+
this.authorizationToken
|
|
7464
|
+
);
|
|
7465
|
+
const enrichedQuote = quote ? {
|
|
7466
|
+
...quote,
|
|
7467
|
+
responseObject: {
|
|
7468
|
+
...quote.responseObject,
|
|
7469
|
+
platformQuotes: (quote.responseObject?.platformQuotes ?? []).map((platformQuote) => {
|
|
7470
|
+
const bestQuote = platformQuote?.bestQuote;
|
|
7471
|
+
const payeeData = normalizeQuotePayeeData(bestQuote?.maker);
|
|
7472
|
+
if (!bestQuote || !payeeData) return platformQuote;
|
|
7473
|
+
return {
|
|
7474
|
+
...platformQuote,
|
|
7475
|
+
bestQuote: { ...bestQuote, payeeData }
|
|
7476
|
+
};
|
|
7477
|
+
})
|
|
7478
|
+
}
|
|
7479
|
+
} : quote;
|
|
7480
|
+
return appendReferrerFeeDisplayFieldsToBestByPlatform(enrichedQuote, referrerFeeConfig);
|
|
7481
|
+
}
|
|
7281
7482
|
// ───────────────────────────────────────────────────────────────────────────
|
|
7282
7483
|
// SUPPORTING: TAKER TIER
|
|
7283
7484
|
// (Used by frontends to display taker limits)
|
|
@@ -7297,7 +7498,7 @@ var Zkp2pClient = class {
|
|
|
7297
7498
|
""
|
|
7298
7499
|
);
|
|
7299
7500
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
7300
|
-
return apiGetTakerTier(req,
|
|
7501
|
+
return apiGetTakerTier(req, void 0, baseApiUrl, timeoutMs);
|
|
7301
7502
|
}
|
|
7302
7503
|
// ╔═══════════════════════════════════════════════════════════════════════════╗
|
|
7303
7504
|
// ║ CORE: ON-CHAIN DEPOSIT VIEWS ║
|
|
@@ -7666,6 +7867,6 @@ var logger = {
|
|
|
7666
7867
|
}
|
|
7667
7868
|
};
|
|
7668
7869
|
|
|
7669
|
-
export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetTakerTier, apiPostDepositDetails, apiValidatePayeeDetails, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
|
|
7870
|
+
export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetTakerTier, apiPostDepositDetails, apiValidatePayeeDetails, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
|
|
7670
7871
|
//# sourceMappingURL=index.mjs.map
|
|
7671
7872
|
//# sourceMappingURL=index.mjs.map
|