@zkp2p/sdk 0.7.1 → 0.8.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 -12
- package/dist/{chunk-BQINCOSO.mjs → chunk-EIOXBVXP.mjs} +3 -4
- package/dist/chunk-EIOXBVXP.mjs.map +1 -0
- package/dist/{chunk-NMIFJSZ3.mjs → chunk-ZM4ZP5GQ.mjs} +2 -2
- package/dist/{chunk-NMIFJSZ3.mjs.map → chunk-ZM4ZP5GQ.mjs.map} +1 -1
- package/dist/index.cjs +2015 -1737
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +57 -7
- package/dist/index.d.ts +57 -7
- package/dist/index.mjs +2015 -1741
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-GG6UQKLO.mjs +5 -0
- package/dist/{protocolViewerParsers-N5SJ4KHJ.mjs.map → protocolViewerParsers-GG6UQKLO.mjs.map} +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.mjs +2 -2
- package/dist/{vaultUtils-DI-r1LAg.d.mts → vaultUtils-BGDsoxAv.d.mts} +810 -732
- package/dist/{vaultUtils-DI-r1LAg.d.ts → vaultUtils-BGDsoxAv.d.ts} +810 -732
- package/package.json +1 -1
- package/dist/chunk-BQINCOSO.mjs.map +0 -1
- package/dist/protocolViewerParsers-N5SJ4KHJ.mjs +0 -5
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { TAKER_TIER_CAPS, TAKER_TIER_FEE_DISCOUNT_BPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_RATE_MANAGER_ID, classifyDelegationState, getDelegationRoute, getNextTakerTier, getTakerTierFeeDiscountBps, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-
|
|
1
|
+
export { TAKER_TIER_CAPS, TAKER_TIER_FEE_DISCOUNT_BPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_RATE_MANAGER_ID, classifyDelegationState, getDelegationRoute, getNextTakerTier, getTakerTierFeeDiscountBps, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-EIOXBVXP.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 { getContracts, getRateManagerContracts, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, parseBigIntLike, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash } from './chunk-ZM4ZP5GQ.mjs';
|
|
5
|
+
export { asciiToBytes32, enrichPvDepositView, enrichPvIntentView, ensureBytes32, getContracts, getGatingServiceAddress, getPaymentMethodsCatalog, getRateManagerContracts, parseDepositView, parseIntentView, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-ZM4ZP5GQ.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';
|
|
@@ -523,6 +523,7 @@ async function createEncryptedSellerCredentialUploadForPlatform({
|
|
|
523
523
|
return createEncryptedSellerCredentialUpload({
|
|
524
524
|
attestationServiceUrl,
|
|
525
525
|
platform: "wise",
|
|
526
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {},
|
|
526
527
|
sessionMaterial: payload.sessionMaterial,
|
|
527
528
|
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
528
529
|
fetch: attestationTransport.fetch,
|
|
@@ -536,6 +537,7 @@ async function createEncryptedSellerCredentialUploadForPlatform({
|
|
|
536
537
|
return createEncryptedSellerCredentialUpload({
|
|
537
538
|
attestationServiceUrl,
|
|
538
539
|
platform,
|
|
540
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {},
|
|
539
541
|
payeeId: payload.payeeId,
|
|
540
542
|
sessionMaterial: payload.sessionMaterial,
|
|
541
543
|
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
@@ -664,7 +666,10 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
|
|
|
664
666
|
res = await attestationTransport.fetch(`${activeBaseUrl}${endpoint}`, {
|
|
665
667
|
method: "POST",
|
|
666
668
|
headers: headers(),
|
|
667
|
-
body: JSON.stringify({
|
|
669
|
+
body: JSON.stringify({
|
|
670
|
+
encryptedUpload,
|
|
671
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {}
|
|
672
|
+
})
|
|
668
673
|
});
|
|
669
674
|
} catch (error) {
|
|
670
675
|
throw new NetworkError("Failed to connect to Attestation Service", {
|
|
@@ -1125,6 +1130,44 @@ function resolvePlatformAttestationConfig(platformName) {
|
|
|
1125
1130
|
return config;
|
|
1126
1131
|
}
|
|
1127
1132
|
|
|
1133
|
+
// src/utils/logger.ts
|
|
1134
|
+
var currentLevel = "info";
|
|
1135
|
+
function setLogLevel(level) {
|
|
1136
|
+
currentLevel = level;
|
|
1137
|
+
}
|
|
1138
|
+
function shouldLog(level) {
|
|
1139
|
+
switch (currentLevel) {
|
|
1140
|
+
case "debug":
|
|
1141
|
+
return true;
|
|
1142
|
+
case "info":
|
|
1143
|
+
return level !== "debug";
|
|
1144
|
+
case "error":
|
|
1145
|
+
return level === "error";
|
|
1146
|
+
default:
|
|
1147
|
+
return true;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
var logger = {
|
|
1151
|
+
debug: (...args) => {
|
|
1152
|
+
if (shouldLog("debug")) {
|
|
1153
|
+
console.log("[DEBUG]", ...args);
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
info: (...args) => {
|
|
1157
|
+
if (shouldLog("info")) {
|
|
1158
|
+
console.log("[INFO]", ...args);
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
warn: (...args) => {
|
|
1162
|
+
if (shouldLog("info")) {
|
|
1163
|
+
console.warn("[WARN]", ...args);
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
error: (...args) => {
|
|
1167
|
+
console.error("[ERROR]", ...args);
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1128
1171
|
// src/client/IntentOperations.ts
|
|
1129
1172
|
var INTENT_MIN_AT_SIGNAL_ABI = [
|
|
1130
1173
|
{
|
|
@@ -1638,16 +1681,24 @@ var IntentOperations = class {
|
|
|
1638
1681
|
async readIntentMinAtSignal(intentHash, orchestratorAddress) {
|
|
1639
1682
|
const address = orchestratorAddress ?? this.config.getOrchestratorV2Address();
|
|
1640
1683
|
if (!address) return void 0;
|
|
1684
|
+
const read = async () => this.config.getPublicClient().readContract({
|
|
1685
|
+
address,
|
|
1686
|
+
abi: INTENT_MIN_AT_SIGNAL_ABI,
|
|
1687
|
+
functionName: "getIntentMinAtSignal",
|
|
1688
|
+
args: [intentHash]
|
|
1689
|
+
});
|
|
1641
1690
|
try {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1691
|
+
return (await read()).toString();
|
|
1692
|
+
} catch (error) {
|
|
1693
|
+
logger.warn(
|
|
1694
|
+
`[sdk] getIntentMinAtSignal read failed for ${intentHash}; retrying once`,
|
|
1695
|
+
error instanceof Error ? error.message : error
|
|
1696
|
+
);
|
|
1697
|
+
try {
|
|
1698
|
+
return (await read()).toString();
|
|
1699
|
+
} catch {
|
|
1700
|
+
return void 0;
|
|
1701
|
+
}
|
|
1651
1702
|
}
|
|
1652
1703
|
}
|
|
1653
1704
|
};
|
|
@@ -1932,7 +1983,7 @@ var ProtocolViewerReader = class {
|
|
|
1932
1983
|
if (inputCount === null) {
|
|
1933
1984
|
throw new Error("Configured ProtocolViewer ABI does not expose getDeposit");
|
|
1934
1985
|
}
|
|
1935
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
1986
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-GG6UQKLO.mjs');
|
|
1936
1987
|
if (inputCount >= 3) {
|
|
1937
1988
|
return tryContexts(
|
|
1938
1989
|
protocolViewerContexts,
|
|
@@ -2011,7 +2062,7 @@ var ProtocolViewerReader = class {
|
|
|
2011
2062
|
return Promise.all(ids.map((id) => this.config.host.getPvDepositById(id)));
|
|
2012
2063
|
}
|
|
2013
2064
|
const bn = ids.map((id) => typeof id === "bigint" ? id : parseRawDepositId(id));
|
|
2014
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2065
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-GG6UQKLO.mjs');
|
|
2015
2066
|
if (inputCount >= 2) {
|
|
2016
2067
|
const requests = ids.map((id, index) => ({
|
|
2017
2068
|
index,
|
|
@@ -2116,7 +2167,7 @@ var ProtocolViewerReader = class {
|
|
|
2116
2167
|
if (!protocolViewerAddress || !protocolViewerAbi || inputCount === null) {
|
|
2117
2168
|
return this.config.host.getPvAccountDepositsFromIndexer(owner);
|
|
2118
2169
|
}
|
|
2119
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
2170
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-GG6UQKLO.mjs');
|
|
2120
2171
|
const { address, abi } = this.config.host.requireProtocolViewer();
|
|
2121
2172
|
if (inputCount >= 2) {
|
|
2122
2173
|
const readAndFilter = async (raw2) => {
|
|
@@ -2187,7 +2238,7 @@ var ProtocolViewerReader = class {
|
|
|
2187
2238
|
if (protocolViewerEntries.length === 0) {
|
|
2188
2239
|
throw new Error("ProtocolViewer not available for this network");
|
|
2189
2240
|
}
|
|
2190
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2241
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-GG6UQKLO.mjs');
|
|
2191
2242
|
const intentsByHash = /* @__PURE__ */ new Map();
|
|
2192
2243
|
let attemptedRead = false;
|
|
2193
2244
|
let hadSuccessfulRead = false;
|
|
@@ -2295,7 +2346,7 @@ var ProtocolViewerReader = class {
|
|
|
2295
2346
|
if (protocolViewerEntries.length === 0) {
|
|
2296
2347
|
throw new Error("ProtocolViewer not available for this network");
|
|
2297
2348
|
}
|
|
2298
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
2349
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-GG6UQKLO.mjs');
|
|
2299
2350
|
let lastError;
|
|
2300
2351
|
for (const pvEntry of protocolViewerEntries) {
|
|
2301
2352
|
const inputCount = this.pvEntryFunctionInputCount(pvEntry, "getIntent");
|
|
@@ -2350,478 +2401,162 @@ var ProtocolViewerReader = class {
|
|
|
2350
2401
|
}
|
|
2351
2402
|
};
|
|
2352
2403
|
|
|
2353
|
-
// src/client
|
|
2354
|
-
var
|
|
2355
|
-
constructor(
|
|
2356
|
-
|
|
2404
|
+
// src/indexer/client.ts
|
|
2405
|
+
var IndexerHttpError = class extends Error {
|
|
2406
|
+
constructor(status, statusText, options) {
|
|
2407
|
+
super(`Indexer request failed: ${status} ${statusText}`);
|
|
2408
|
+
this.name = "IndexerHttpError";
|
|
2409
|
+
this.status = status;
|
|
2410
|
+
this.retryAfterSeconds = options?.retryAfterSeconds;
|
|
2357
2411
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2412
|
+
};
|
|
2413
|
+
function parseRetryAfterSeconds(rawHeader) {
|
|
2414
|
+
if (!rawHeader) return void 0;
|
|
2415
|
+
const parsedSeconds = Number(rawHeader);
|
|
2416
|
+
if (Number.isFinite(parsedSeconds) && parsedSeconds >= 0) {
|
|
2417
|
+
return Math.ceil(parsedSeconds);
|
|
2363
2418
|
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2419
|
+
const parsedDateMs = Date.parse(rawHeader);
|
|
2420
|
+
if (!Number.isFinite(parsedDateMs)) return void 0;
|
|
2421
|
+
const secondsUntilRetry = Math.ceil((parsedDateMs - Date.now()) / 1e3);
|
|
2422
|
+
return Math.max(0, secondsUntilRetry);
|
|
2423
|
+
}
|
|
2424
|
+
function createAbortError() {
|
|
2425
|
+
const error = new Error("The operation was aborted");
|
|
2426
|
+
error.name = "AbortError";
|
|
2427
|
+
return error;
|
|
2428
|
+
}
|
|
2429
|
+
function delay(ms, signal) {
|
|
2430
|
+
if (ms <= 0) {
|
|
2431
|
+
return Promise.resolve();
|
|
2432
|
+
}
|
|
2433
|
+
return new Promise((resolve, reject) => {
|
|
2434
|
+
if (signal?.aborted) {
|
|
2435
|
+
reject(createAbortError());
|
|
2436
|
+
return;
|
|
2378
2437
|
}
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2438
|
+
const timer = setTimeout(() => {
|
|
2439
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2440
|
+
resolve();
|
|
2441
|
+
}, ms);
|
|
2442
|
+
const onAbort = () => {
|
|
2443
|
+
clearTimeout(timer);
|
|
2444
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2445
|
+
reject(createAbortError());
|
|
2382
2446
|
};
|
|
2447
|
+
signal?.addEventListener("abort", onAbort);
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
var IndexerClient = class {
|
|
2451
|
+
constructor(endpoint, options = {}) {
|
|
2452
|
+
this.endpoint = endpoint;
|
|
2453
|
+
this.options = options;
|
|
2454
|
+
this.hasLoggedTokenProviderError = false;
|
|
2383
2455
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2456
|
+
async resolveAuthorizationToken() {
|
|
2457
|
+
if (this.options.getAuthorizationToken) {
|
|
2458
|
+
try {
|
|
2459
|
+
const token = await this.options.getAuthorizationToken();
|
|
2460
|
+
return token ?? void 0;
|
|
2461
|
+
} catch (error) {
|
|
2462
|
+
if (this.options.onAuthorizationTokenError) {
|
|
2463
|
+
this.options.onAuthorizationTokenError(error);
|
|
2464
|
+
} else if (!this.hasLoggedTokenProviderError) {
|
|
2465
|
+
this.hasLoggedTokenProviderError = true;
|
|
2466
|
+
console.warn(
|
|
2467
|
+
"[IndexerClient] getAuthorizationToken failed; continuing without Authorization header",
|
|
2468
|
+
error
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
return void 0;
|
|
2472
|
+
}
|
|
2388
2473
|
}
|
|
2389
|
-
return
|
|
2390
|
-
`${reason}. Rate manager contracts failed to initialize: ${initError.message}`
|
|
2391
|
-
);
|
|
2474
|
+
return this.options.authorizationToken;
|
|
2392
2475
|
}
|
|
2393
|
-
|
|
2394
|
-
const
|
|
2395
|
-
const
|
|
2396
|
-
|
|
2397
|
-
"
|
|
2398
|
-
"depositHook"
|
|
2399
|
-
);
|
|
2400
|
-
const includeMinLiquidity = abiTupleHasComponent(
|
|
2401
|
-
registryAbi,
|
|
2402
|
-
"createRateManager",
|
|
2403
|
-
"minLiquidity"
|
|
2404
|
-
);
|
|
2405
|
-
const result = {
|
|
2406
|
-
manager: config.manager,
|
|
2407
|
-
feeRecipient: config.feeRecipient,
|
|
2408
|
-
maxFee: config.maxFee,
|
|
2409
|
-
fee: config.fee
|
|
2410
|
-
};
|
|
2411
|
-
if (includeDepositHook) {
|
|
2412
|
-
result.depositHook = config.depositHook ?? ZERO_ADDRESS;
|
|
2476
|
+
async _post(request, init) {
|
|
2477
|
+
const token = await this.resolveAuthorizationToken();
|
|
2478
|
+
const headers2 = new Headers(init?.headers);
|
|
2479
|
+
if (!headers2.has("Content-Type")) {
|
|
2480
|
+
headers2.set("Content-Type", "application/json");
|
|
2413
2481
|
}
|
|
2414
|
-
if (
|
|
2415
|
-
|
|
2482
|
+
if (token && !headers2.has("Authorization")) {
|
|
2483
|
+
headers2.set("Authorization", token.startsWith("Bearer ") ? token : `Bearer ${token}`);
|
|
2416
2484
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
return result;
|
|
2420
|
-
}
|
|
2421
|
-
buildSetRateManagerConfigArgs(params) {
|
|
2422
|
-
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
2423
|
-
const includeHook = abiFunctionHasInput(registryAbi, "setRateManagerConfig", "_newHook") || abiFunctionHasInput(registryAbi, "setRateManagerConfig", "newHook");
|
|
2424
|
-
if (includeHook) {
|
|
2425
|
-
return [
|
|
2426
|
-
params.rateManagerId,
|
|
2427
|
-
params.newManager,
|
|
2428
|
-
params.newFeeRecipient,
|
|
2429
|
-
params.newHook ?? ZERO_ADDRESS,
|
|
2430
|
-
params.newName,
|
|
2431
|
-
params.newUri
|
|
2432
|
-
];
|
|
2485
|
+
if (this.options.apiKey && !headers2.has("x-api-key")) {
|
|
2486
|
+
headers2.set("x-api-key", this.options.apiKey);
|
|
2433
2487
|
}
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
];
|
|
2441
|
-
}
|
|
2442
|
-
prepareRateManagerRegistryTransaction(opts) {
|
|
2443
|
-
const contract = this.resolveRateManagerRegistryContract(opts.registry);
|
|
2444
|
-
const functionName = resolveAbiFunctionName(contract.abi, opts.functionNames);
|
|
2445
|
-
return this.config.host.prepareContractTransaction({
|
|
2446
|
-
address: contract.address,
|
|
2447
|
-
abi: contract.abi,
|
|
2448
|
-
functionName,
|
|
2449
|
-
args: opts.args,
|
|
2450
|
-
txOverrides: opts.txOverrides
|
|
2451
|
-
});
|
|
2452
|
-
}
|
|
2453
|
-
prepareCreateRateManagerTransaction(params) {
|
|
2454
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
2455
|
-
functionNames: ["createRateManager"],
|
|
2456
|
-
args: [this.buildCreateRateManagerConfig(params.config)],
|
|
2457
|
-
txOverrides: params.txOverrides
|
|
2458
|
-
});
|
|
2459
|
-
}
|
|
2460
|
-
prepareSetVaultRateTransaction(params) {
|
|
2461
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
2462
|
-
functionNames: ["setRate", "setMinRate"],
|
|
2463
|
-
args: [params.rateManagerId, params.paymentMethodHash, params.currencyHash, params.rate],
|
|
2464
|
-
txOverrides: params.txOverrides
|
|
2465
|
-
});
|
|
2466
|
-
}
|
|
2467
|
-
prepareSetVaultRatesBatchTransaction(params) {
|
|
2468
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
2469
|
-
functionNames: ["setRateBatch", "setMinRatesBatch"],
|
|
2470
|
-
args: [params.rateManagerId, params.paymentMethods, params.currencies, params.rates],
|
|
2471
|
-
txOverrides: params.txOverrides
|
|
2472
|
-
});
|
|
2473
|
-
}
|
|
2474
|
-
prepareSetOracleRateConfigTransaction(params) {
|
|
2475
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2476
|
-
escrowAddress: params.escrowAddress,
|
|
2477
|
-
depositId: params.depositId
|
|
2488
|
+
const res = await fetch(this.endpoint, {
|
|
2489
|
+
method: "POST",
|
|
2490
|
+
headers: headers2,
|
|
2491
|
+
body: JSON.stringify(request),
|
|
2492
|
+
cache: "no-store",
|
|
2493
|
+
...init
|
|
2478
2494
|
});
|
|
2479
|
-
if (
|
|
2480
|
-
throw new
|
|
2495
|
+
if (!res.ok) {
|
|
2496
|
+
throw new IndexerHttpError(res.status, res.statusText, {
|
|
2497
|
+
retryAfterSeconds: parseRetryAfterSeconds(res.headers.get("Retry-After"))
|
|
2498
|
+
});
|
|
2481
2499
|
}
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
parseRawDepositId(params.depositId),
|
|
2487
|
-
params.paymentMethodHash,
|
|
2488
|
-
params.currencyHash,
|
|
2489
|
-
normalizeOracleRateConfig(params.config)
|
|
2490
|
-
],
|
|
2491
|
-
txOverrides: params.txOverrides,
|
|
2492
|
-
escrowAddress: escrowContext.address,
|
|
2493
|
-
escrowAbi: escrowContext.abi
|
|
2494
|
-
});
|
|
2495
|
-
}
|
|
2496
|
-
prepareRemoveOracleRateConfigTransaction(params) {
|
|
2497
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2498
|
-
escrowAddress: params.escrowAddress,
|
|
2499
|
-
depositId: params.depositId
|
|
2500
|
-
});
|
|
2501
|
-
if (escrowContext.version !== "v2") {
|
|
2502
|
-
throw new Error("removeOracleRateConfig requires EscrowV2");
|
|
2503
|
-
}
|
|
2504
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["removeOracleRateConfig"]);
|
|
2505
|
-
return this.config.host.prepareEscrowTransaction({
|
|
2506
|
-
functionName,
|
|
2507
|
-
args: [parseRawDepositId(params.depositId), params.paymentMethodHash, params.currencyHash],
|
|
2508
|
-
txOverrides: params.txOverrides,
|
|
2509
|
-
escrowAddress: escrowContext.address,
|
|
2510
|
-
escrowAbi: escrowContext.abi
|
|
2511
|
-
});
|
|
2512
|
-
}
|
|
2513
|
-
prepareSetOracleRateConfigBatchTransaction(params) {
|
|
2514
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2515
|
-
escrowAddress: params.escrowAddress,
|
|
2516
|
-
depositId: params.depositId
|
|
2517
|
-
});
|
|
2518
|
-
if (escrowContext.version !== "v2") {
|
|
2519
|
-
throw new Error("setOracleRateConfigBatch requires EscrowV2");
|
|
2520
|
-
}
|
|
2521
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfigBatch"]);
|
|
2522
|
-
return this.config.host.prepareEscrowTransaction({
|
|
2523
|
-
functionName,
|
|
2524
|
-
args: [
|
|
2525
|
-
parseRawDepositId(params.depositId),
|
|
2526
|
-
params.paymentMethods,
|
|
2527
|
-
params.currencies,
|
|
2528
|
-
params.configs.map((group) => group.map((config) => normalizeOracleRateConfig(config)))
|
|
2529
|
-
],
|
|
2530
|
-
txOverrides: params.txOverrides,
|
|
2531
|
-
escrowAddress: escrowContext.address,
|
|
2532
|
-
escrowAbi: escrowContext.abi
|
|
2533
|
-
});
|
|
2534
|
-
}
|
|
2535
|
-
prepareUpdateCurrencyConfigBatchTransaction(params) {
|
|
2536
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2537
|
-
escrowAddress: params.escrowAddress,
|
|
2538
|
-
depositId: params.depositId
|
|
2539
|
-
});
|
|
2540
|
-
if (escrowContext.version !== "v2") {
|
|
2541
|
-
throw new Error("updateCurrencyConfigBatch requires EscrowV2");
|
|
2542
|
-
}
|
|
2543
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["updateCurrencyConfigBatch"]);
|
|
2544
|
-
return this.config.host.prepareEscrowTransaction({
|
|
2545
|
-
functionName,
|
|
2546
|
-
args: [
|
|
2547
|
-
parseRawDepositId(params.depositId),
|
|
2548
|
-
params.paymentMethods,
|
|
2549
|
-
params.updates.map(
|
|
2550
|
-
(group) => group.map((update) => ({
|
|
2551
|
-
code: update.code,
|
|
2552
|
-
minConversionRate: typeof update.minConversionRate === "bigint" ? update.minConversionRate : BigInt(update.minConversionRate),
|
|
2553
|
-
updateOracle: update.updateOracle,
|
|
2554
|
-
oracleRateConfig: normalizeOracleRateConfig(update.oracleRateConfig)
|
|
2555
|
-
}))
|
|
2556
|
-
)
|
|
2557
|
-
],
|
|
2558
|
-
txOverrides: params.txOverrides,
|
|
2559
|
-
escrowAddress: escrowContext.address,
|
|
2560
|
-
escrowAbi: escrowContext.abi
|
|
2561
|
-
});
|
|
2562
|
-
}
|
|
2563
|
-
prepareDeactivateCurrenciesBatchTransaction(params) {
|
|
2564
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2565
|
-
escrowAddress: params.escrowAddress,
|
|
2566
|
-
depositId: params.depositId
|
|
2567
|
-
});
|
|
2568
|
-
if (escrowContext.version !== "v2") {
|
|
2569
|
-
throw new Error("deactivateCurrenciesBatch requires EscrowV2");
|
|
2500
|
+
const json = await res.json();
|
|
2501
|
+
if (json.errors?.length) {
|
|
2502
|
+
const msg = json.errors.map((e) => e.message).join(", ");
|
|
2503
|
+
throw new Error(`GraphQL errors: ${msg}`);
|
|
2570
2504
|
}
|
|
2571
|
-
|
|
2572
|
-
return
|
|
2573
|
-
functionName,
|
|
2574
|
-
args: [parseRawDepositId(params.depositId), params.paymentMethods, params.currencyCodes],
|
|
2575
|
-
txOverrides: params.txOverrides,
|
|
2576
|
-
escrowAddress: escrowContext.address,
|
|
2577
|
-
escrowAbi: escrowContext.abi
|
|
2578
|
-
});
|
|
2579
|
-
}
|
|
2580
|
-
prepareSetVaultConfigTransaction(params) {
|
|
2581
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
2582
|
-
functionNames: ["setRateManagerConfig"],
|
|
2583
|
-
args: this.buildSetRateManagerConfigArgs(params),
|
|
2584
|
-
txOverrides: params.txOverrides
|
|
2585
|
-
});
|
|
2505
|
+
if (!json.data) throw new Error("No data returned from indexer");
|
|
2506
|
+
return json.data;
|
|
2586
2507
|
}
|
|
2587
|
-
async
|
|
2588
|
-
const
|
|
2589
|
-
const
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2508
|
+
async query(request, init) {
|
|
2509
|
+
const retries = Math.max(0, init?.retries ?? 1);
|
|
2510
|
+
const rateLimitRetries = Math.max(0, init?.rateLimitRetries ?? 2);
|
|
2511
|
+
const maxAttempts = 1 + Math.max(retries, rateLimitRetries);
|
|
2512
|
+
const {
|
|
2513
|
+
retries: _unusedRetries,
|
|
2514
|
+
rateLimitRetries: _unusedRateLimitRetries,
|
|
2515
|
+
...requestInit
|
|
2516
|
+
} = init ?? {};
|
|
2517
|
+
let attempts = 0;
|
|
2518
|
+
let rateLimitAttempt = 0;
|
|
2519
|
+
let standardRetryAttempt = 0;
|
|
2520
|
+
let lastErr;
|
|
2521
|
+
while (attempts < maxAttempts) {
|
|
2522
|
+
try {
|
|
2523
|
+
return await this._post(request, requestInit);
|
|
2524
|
+
} catch (e) {
|
|
2525
|
+
lastErr = e;
|
|
2526
|
+
attempts += 1;
|
|
2527
|
+
if (requestInit.signal?.aborted) {
|
|
2528
|
+
throw e;
|
|
2529
|
+
}
|
|
2530
|
+
const hasAttemptsRemaining = attempts < maxAttempts;
|
|
2531
|
+
if (e instanceof IndexerHttpError && e.status === 429 && rateLimitAttempt < rateLimitRetries && hasAttemptsRemaining) {
|
|
2532
|
+
rateLimitAttempt += 1;
|
|
2533
|
+
const waitSeconds = e.retryAfterSeconds !== void 0 ? Math.max(0, e.retryAfterSeconds) : 1;
|
|
2534
|
+
await delay(waitSeconds * 1e3, requestInit.signal ?? void 0);
|
|
2535
|
+
continue;
|
|
2536
|
+
}
|
|
2537
|
+
if (!hasAttemptsRemaining || standardRetryAttempt >= retries) {
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2540
|
+
standardRetryAttempt += 1;
|
|
2541
|
+
await delay(200 * standardRetryAttempt, requestInit.signal ?? void 0);
|
|
2605
2542
|
}
|
|
2606
2543
|
}
|
|
2607
|
-
|
|
2608
|
-
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
2609
|
-
if (!controllerAddress || !controllerAbi) {
|
|
2610
|
-
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
2611
|
-
}
|
|
2612
|
-
const legacyResult = await this.config.getPublicClient().readContract({
|
|
2613
|
-
address: controllerAddress,
|
|
2614
|
-
abi: controllerAbi,
|
|
2615
|
-
functionName: "getDepositRateManager",
|
|
2616
|
-
args: [escrow, id]
|
|
2617
|
-
});
|
|
2618
|
-
return {
|
|
2619
|
-
registry: legacyResult[0],
|
|
2620
|
-
rateManagerId: legacyResult[1]
|
|
2621
|
-
};
|
|
2622
|
-
}
|
|
2623
|
-
async getManagerFee(escrow, depositId) {
|
|
2624
|
-
const id = parseRawDepositId(depositId);
|
|
2625
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2626
|
-
escrowAddress: escrow,
|
|
2627
|
-
depositId
|
|
2628
|
-
});
|
|
2629
|
-
if (getRateManagerReadFunction(escrowContext.abi, "getManagerFee")) {
|
|
2630
|
-
const result2 = await this.config.getPublicClient().readContract({
|
|
2631
|
-
address: escrowContext.address,
|
|
2632
|
-
abi: escrowContext.abi,
|
|
2633
|
-
functionName: "getManagerFee",
|
|
2634
|
-
args: [id]
|
|
2635
|
-
});
|
|
2636
|
-
return parseManagerFeeFromRead(result2);
|
|
2637
|
-
}
|
|
2638
|
-
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
2639
|
-
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
2640
|
-
if (!controllerAddress || !controllerAbi) {
|
|
2641
|
-
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
2642
|
-
}
|
|
2643
|
-
const result = await this.config.getPublicClient().readContract({
|
|
2644
|
-
address: controllerAddress,
|
|
2645
|
-
abi: controllerAbi,
|
|
2646
|
-
functionName: "getManagerFee",
|
|
2647
|
-
args: [escrow, id]
|
|
2648
|
-
});
|
|
2649
|
-
return parseManagerFeeFromRead(result);
|
|
2650
|
-
}
|
|
2651
|
-
async getEffectiveRate(params) {
|
|
2652
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
2653
|
-
escrowAddress: params.escrow,
|
|
2654
|
-
depositId: params.depositId
|
|
2655
|
-
});
|
|
2656
|
-
const id = parseRawDepositId(params.depositId);
|
|
2657
|
-
return await this.config.getPublicClient().readContract({
|
|
2658
|
-
address: escrowContext.address,
|
|
2659
|
-
abi: escrowContext.abi,
|
|
2660
|
-
functionName: "getEffectiveRate",
|
|
2661
|
-
args: [id, params.paymentMethod, params.fiatCurrency]
|
|
2662
|
-
});
|
|
2663
|
-
}
|
|
2664
|
-
};
|
|
2665
|
-
var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && abi.some(
|
|
2666
|
-
(item) => item.type === "function" && item.name === functionName
|
|
2667
|
-
);
|
|
2668
|
-
|
|
2669
|
-
// src/indexer/client.ts
|
|
2670
|
-
var IndexerHttpError = class extends Error {
|
|
2671
|
-
constructor(status, statusText, options) {
|
|
2672
|
-
super(`Indexer request failed: ${status} ${statusText}`);
|
|
2673
|
-
this.name = "IndexerHttpError";
|
|
2674
|
-
this.status = status;
|
|
2675
|
-
this.retryAfterSeconds = options?.retryAfterSeconds;
|
|
2544
|
+
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
2676
2545
|
}
|
|
2677
2546
|
};
|
|
2678
|
-
function
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
error.name = "AbortError";
|
|
2692
|
-
return error;
|
|
2693
|
-
}
|
|
2694
|
-
function delay(ms, signal) {
|
|
2695
|
-
if (ms <= 0) {
|
|
2696
|
-
return Promise.resolve();
|
|
2697
|
-
}
|
|
2698
|
-
return new Promise((resolve, reject) => {
|
|
2699
|
-
if (signal?.aborted) {
|
|
2700
|
-
reject(createAbortError());
|
|
2701
|
-
return;
|
|
2702
|
-
}
|
|
2703
|
-
const timer = setTimeout(() => {
|
|
2704
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2705
|
-
resolve();
|
|
2706
|
-
}, ms);
|
|
2707
|
-
const onAbort = () => {
|
|
2708
|
-
clearTimeout(timer);
|
|
2709
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2710
|
-
reject(createAbortError());
|
|
2711
|
-
};
|
|
2712
|
-
signal?.addEventListener("abort", onAbort);
|
|
2713
|
-
});
|
|
2714
|
-
}
|
|
2715
|
-
var IndexerClient = class {
|
|
2716
|
-
constructor(endpoint, options = {}) {
|
|
2717
|
-
this.endpoint = endpoint;
|
|
2718
|
-
this.options = options;
|
|
2719
|
-
this.hasLoggedTokenProviderError = false;
|
|
2720
|
-
}
|
|
2721
|
-
async resolveAuthorizationToken() {
|
|
2722
|
-
if (this.options.getAuthorizationToken) {
|
|
2723
|
-
try {
|
|
2724
|
-
const token = await this.options.getAuthorizationToken();
|
|
2725
|
-
return token ?? void 0;
|
|
2726
|
-
} catch (error) {
|
|
2727
|
-
if (this.options.onAuthorizationTokenError) {
|
|
2728
|
-
this.options.onAuthorizationTokenError(error);
|
|
2729
|
-
} else if (!this.hasLoggedTokenProviderError) {
|
|
2730
|
-
this.hasLoggedTokenProviderError = true;
|
|
2731
|
-
console.warn(
|
|
2732
|
-
"[IndexerClient] getAuthorizationToken failed; continuing without Authorization header",
|
|
2733
|
-
error
|
|
2734
|
-
);
|
|
2735
|
-
}
|
|
2736
|
-
return void 0;
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
return this.options.authorizationToken;
|
|
2740
|
-
}
|
|
2741
|
-
async _post(request, init) {
|
|
2742
|
-
const token = await this.resolveAuthorizationToken();
|
|
2743
|
-
const headers2 = new Headers(init?.headers);
|
|
2744
|
-
if (!headers2.has("Content-Type")) {
|
|
2745
|
-
headers2.set("Content-Type", "application/json");
|
|
2746
|
-
}
|
|
2747
|
-
if (token && !headers2.has("Authorization")) {
|
|
2748
|
-
headers2.set("Authorization", token.startsWith("Bearer ") ? token : `Bearer ${token}`);
|
|
2749
|
-
}
|
|
2750
|
-
if (this.options.apiKey && !headers2.has("x-api-key")) {
|
|
2751
|
-
headers2.set("x-api-key", this.options.apiKey);
|
|
2752
|
-
}
|
|
2753
|
-
const res = await fetch(this.endpoint, {
|
|
2754
|
-
method: "POST",
|
|
2755
|
-
headers: headers2,
|
|
2756
|
-
body: JSON.stringify(request),
|
|
2757
|
-
cache: "no-store",
|
|
2758
|
-
...init
|
|
2759
|
-
});
|
|
2760
|
-
if (!res.ok) {
|
|
2761
|
-
throw new IndexerHttpError(res.status, res.statusText, {
|
|
2762
|
-
retryAfterSeconds: parseRetryAfterSeconds(res.headers.get("Retry-After"))
|
|
2763
|
-
});
|
|
2764
|
-
}
|
|
2765
|
-
const json = await res.json();
|
|
2766
|
-
if (json.errors?.length) {
|
|
2767
|
-
const msg = json.errors.map((e) => e.message).join(", ");
|
|
2768
|
-
throw new Error(`GraphQL errors: ${msg}`);
|
|
2769
|
-
}
|
|
2770
|
-
if (!json.data) throw new Error("No data returned from indexer");
|
|
2771
|
-
return json.data;
|
|
2772
|
-
}
|
|
2773
|
-
async query(request, init) {
|
|
2774
|
-
const retries = Math.max(0, init?.retries ?? 1);
|
|
2775
|
-
const rateLimitRetries = Math.max(0, init?.rateLimitRetries ?? 2);
|
|
2776
|
-
const maxAttempts = 1 + Math.max(retries, rateLimitRetries);
|
|
2777
|
-
const {
|
|
2778
|
-
retries: _unusedRetries,
|
|
2779
|
-
rateLimitRetries: _unusedRateLimitRetries,
|
|
2780
|
-
...requestInit
|
|
2781
|
-
} = init ?? {};
|
|
2782
|
-
let attempts = 0;
|
|
2783
|
-
let rateLimitAttempt = 0;
|
|
2784
|
-
let standardRetryAttempt = 0;
|
|
2785
|
-
let lastErr;
|
|
2786
|
-
while (attempts < maxAttempts) {
|
|
2787
|
-
try {
|
|
2788
|
-
return await this._post(request, requestInit);
|
|
2789
|
-
} catch (e) {
|
|
2790
|
-
lastErr = e;
|
|
2791
|
-
attempts += 1;
|
|
2792
|
-
if (requestInit.signal?.aborted) {
|
|
2793
|
-
throw e;
|
|
2794
|
-
}
|
|
2795
|
-
const hasAttemptsRemaining = attempts < maxAttempts;
|
|
2796
|
-
if (e instanceof IndexerHttpError && e.status === 429 && rateLimitAttempt < rateLimitRetries && hasAttemptsRemaining) {
|
|
2797
|
-
rateLimitAttempt += 1;
|
|
2798
|
-
const waitSeconds = e.retryAfterSeconds !== void 0 ? Math.max(0, e.retryAfterSeconds) : 1;
|
|
2799
|
-
await delay(waitSeconds * 1e3, requestInit.signal ?? void 0);
|
|
2800
|
-
continue;
|
|
2801
|
-
}
|
|
2802
|
-
if (!hasAttemptsRemaining || standardRetryAttempt >= retries) {
|
|
2803
|
-
break;
|
|
2804
|
-
}
|
|
2805
|
-
standardRetryAttempt += 1;
|
|
2806
|
-
await delay(200 * standardRetryAttempt, requestInit.signal ?? void 0);
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
2810
|
-
}
|
|
2811
|
-
};
|
|
2812
|
-
function defaultIndexerEndpoint(env = "PRODUCTION") {
|
|
2813
|
-
switch (env) {
|
|
2814
|
-
case "PRODUCTION":
|
|
2815
|
-
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
2816
|
-
case "PREPRODUCTION":
|
|
2817
|
-
return "https://indexer-preprod.zkp2p.xyz/v1/graphql";
|
|
2818
|
-
case "STAGING":
|
|
2819
|
-
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
2820
|
-
case "DEV":
|
|
2821
|
-
case "LOCAL":
|
|
2822
|
-
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
2823
|
-
default:
|
|
2824
|
-
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
2547
|
+
function defaultIndexerEndpoint(env = "PRODUCTION") {
|
|
2548
|
+
switch (env) {
|
|
2549
|
+
case "PRODUCTION":
|
|
2550
|
+
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
2551
|
+
case "PREPRODUCTION":
|
|
2552
|
+
return "https://indexer-preprod.zkp2p.xyz/v1/graphql";
|
|
2553
|
+
case "STAGING":
|
|
2554
|
+
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
2555
|
+
case "DEV":
|
|
2556
|
+
case "LOCAL":
|
|
2557
|
+
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
2558
|
+
default:
|
|
2559
|
+
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
2825
2560
|
}
|
|
2826
2561
|
}
|
|
2827
2562
|
|
|
@@ -4265,7 +4000,11 @@ var IndexerDepositService = class {
|
|
|
4265
4000
|
(pm) => (pm.paymentMethodHash ?? "").toLowerCase() === target
|
|
4266
4001
|
);
|
|
4267
4002
|
return match?.payeeDetailsHash ?? null;
|
|
4268
|
-
} catch {
|
|
4003
|
+
} catch (error) {
|
|
4004
|
+
logger.warn(
|
|
4005
|
+
"[sdk] resolvePayeeHash lookup failed; returning null",
|
|
4006
|
+
error instanceof Error ? error.message : error
|
|
4007
|
+
);
|
|
4269
4008
|
return null;
|
|
4270
4009
|
}
|
|
4271
4010
|
}
|
|
@@ -4427,1222 +4166,1785 @@ var IndexerDepositService = class {
|
|
|
4427
4166
|
}
|
|
4428
4167
|
};
|
|
4429
4168
|
|
|
4430
|
-
// src/
|
|
4431
|
-
var
|
|
4432
|
-
var
|
|
4433
|
-
var
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4169
|
+
// src/referral.ts
|
|
4170
|
+
var normalizeReferralCode = (code) => code.trim().toUpperCase();
|
|
4171
|
+
var isValidReferralCode = (code) => /^[A-Z0-9]{6}$/.test(normalizeReferralCode(code));
|
|
4172
|
+
var REFERRAL_SIGNATURE_DOMAIN = { name: "ZKP2PReferral", version: "1" };
|
|
4173
|
+
var REFERRAL_SIGNATURE_TYPES = {
|
|
4174
|
+
CreateCode: [
|
|
4175
|
+
{ name: "wallet", type: "address" },
|
|
4176
|
+
{ name: "audience", type: "string" },
|
|
4177
|
+
{ name: "issuedAt", type: "uint256" }
|
|
4178
|
+
],
|
|
4179
|
+
RedeemCode: [
|
|
4180
|
+
{ name: "wallet", type: "address" },
|
|
4181
|
+
{ name: "code", type: "string" },
|
|
4182
|
+
{ name: "referrer", type: "address" },
|
|
4183
|
+
{ name: "audience", type: "string" },
|
|
4184
|
+
{ name: "issuedAt", type: "uint256" }
|
|
4185
|
+
],
|
|
4186
|
+
RenameCode: [
|
|
4187
|
+
{ name: "wallet", type: "address" },
|
|
4188
|
+
{ name: "oldCode", type: "string" },
|
|
4189
|
+
{ name: "newCode", type: "string" },
|
|
4190
|
+
{ name: "audience", type: "string" },
|
|
4191
|
+
{ name: "issuedAt", type: "uint256" }
|
|
4192
|
+
]
|
|
4193
|
+
};
|
|
4194
|
+
|
|
4195
|
+
// src/adapters/api.ts
|
|
4196
|
+
function createHeaders(apiKey, authorizationToken) {
|
|
4197
|
+
const headers2 = { "Content-Type": "application/json" };
|
|
4198
|
+
if (apiKey) headers2["x-api-key"] = apiKey;
|
|
4199
|
+
if (authorizationToken) {
|
|
4200
|
+
headers2.Authorization = authorizationToken.startsWith("Bearer ") ? authorizationToken : `Bearer ${authorizationToken}`;
|
|
4201
|
+
}
|
|
4202
|
+
return headers2;
|
|
4437
4203
|
}
|
|
4438
|
-
function
|
|
4439
|
-
|
|
4440
|
-
|
|
4204
|
+
function withApiBase(baseApiUrl) {
|
|
4205
|
+
const trimmed = (baseApiUrl || "").trim();
|
|
4206
|
+
let base2 = trimmed.replace(/\/+$/, "");
|
|
4207
|
+
base2 = base2.replace(/\/v1$/i, "");
|
|
4208
|
+
base2 = base2.replace(/\/v2$/i, "");
|
|
4209
|
+
return base2;
|
|
4441
4210
|
}
|
|
4442
|
-
function
|
|
4443
|
-
|
|
4211
|
+
async function apiFetch({
|
|
4212
|
+
url,
|
|
4213
|
+
method = "GET",
|
|
4214
|
+
body,
|
|
4215
|
+
apiKey,
|
|
4216
|
+
authorizationToken,
|
|
4217
|
+
timeoutMs,
|
|
4218
|
+
retryCount = 3,
|
|
4219
|
+
retryDelayMs = 1e3
|
|
4220
|
+
}) {
|
|
4221
|
+
const endpoint = url.replace(/^[^/]*\/\/[^/]*/, "");
|
|
4222
|
+
return withRetry(
|
|
4223
|
+
async () => {
|
|
4224
|
+
let res;
|
|
4225
|
+
try {
|
|
4226
|
+
const options = {
|
|
4227
|
+
method,
|
|
4228
|
+
headers: createHeaders(apiKey, authorizationToken)
|
|
4229
|
+
};
|
|
4230
|
+
if (body && method !== "GET") {
|
|
4231
|
+
options.body = JSON.stringify(body);
|
|
4232
|
+
}
|
|
4233
|
+
res = await fetch(url, options);
|
|
4234
|
+
} catch (error) {
|
|
4235
|
+
throw new NetworkError("Failed to connect to API server", { endpoint, error });
|
|
4236
|
+
}
|
|
4237
|
+
if (!res.ok) {
|
|
4238
|
+
const errorText = await res.text();
|
|
4239
|
+
throw parseAPIError(res, errorText);
|
|
4240
|
+
}
|
|
4241
|
+
return res.json();
|
|
4242
|
+
},
|
|
4243
|
+
retryCount,
|
|
4244
|
+
retryDelayMs,
|
|
4245
|
+
timeoutMs
|
|
4246
|
+
);
|
|
4444
4247
|
}
|
|
4445
|
-
function
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
const separatorIndex = trimmed.indexOf(":");
|
|
4449
|
-
if (separatorIndex <= 0) return null;
|
|
4450
|
-
const rateManagerAddress = normalizeAddress3(trimmed.slice(0, separatorIndex));
|
|
4451
|
-
const rateManagerId = normalizeRateManagerId2(trimmed.slice(separatorIndex + 1));
|
|
4452
|
-
if (!EVM_ADDRESS_REGEX.test(rateManagerAddress) || !rateManagerId) {
|
|
4453
|
-
return null;
|
|
4248
|
+
function unwrapResponseObject(payload) {
|
|
4249
|
+
if (payload && typeof payload === "object" && "responseObject" in payload) {
|
|
4250
|
+
return payload.responseObject;
|
|
4454
4251
|
}
|
|
4455
|
-
return
|
|
4252
|
+
return payload;
|
|
4456
4253
|
}
|
|
4457
|
-
function
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4254
|
+
function requireAuthorizationToken(authorizationToken, endpoint) {
|
|
4255
|
+
if (!authorizationToken) {
|
|
4256
|
+
throw new ValidationError(
|
|
4257
|
+
`authorizationToken is required for ${endpoint}`,
|
|
4258
|
+
"authorizationToken"
|
|
4259
|
+
);
|
|
4260
|
+
}
|
|
4261
|
+
return authorizationToken;
|
|
4461
4262
|
}
|
|
4462
|
-
function
|
|
4463
|
-
if (
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4263
|
+
function requireReferralWriteAuth(authorizationToken, signature, endpoint) {
|
|
4264
|
+
if (authorizationToken && signature) {
|
|
4265
|
+
throw new ValidationError(
|
|
4266
|
+
`Use either authorizationToken or signature for ${endpoint}, not both`,
|
|
4267
|
+
"authorizationToken"
|
|
4268
|
+
);
|
|
4269
|
+
}
|
|
4270
|
+
if (!authorizationToken && !signature) {
|
|
4271
|
+
throw new ValidationError(
|
|
4272
|
+
`authorizationToken or signature is required for ${endpoint}`,
|
|
4273
|
+
"authorizationToken"
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4276
|
+
return authorizationToken;
|
|
4468
4277
|
}
|
|
4469
|
-
function
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
|
|
4278
|
+
function requireEscrowAddress(escrowAddress, endpoint) {
|
|
4279
|
+
if (!escrowAddress) {
|
|
4280
|
+
throw new ValidationError(`escrowAddress is required for ${endpoint}`, "escrowAddress");
|
|
4281
|
+
}
|
|
4282
|
+
return escrowAddress;
|
|
4475
4283
|
}
|
|
4476
|
-
function
|
|
4477
|
-
|
|
4284
|
+
function normalizeReferralAddress(address, field) {
|
|
4285
|
+
const normalized = address.trim().toLowerCase();
|
|
4286
|
+
if (!isValidHexAddress(normalized)) {
|
|
4287
|
+
throw new ValidationError(`${field} must be a valid Ethereum address`, field);
|
|
4288
|
+
}
|
|
4289
|
+
return normalized;
|
|
4478
4290
|
}
|
|
4479
|
-
function
|
|
4480
|
-
const
|
|
4481
|
-
if (
|
|
4482
|
-
|
|
4483
|
-
const normalizedEscrow = normalizeAddress3(escrowAddress);
|
|
4484
|
-
if (normalizedEscrow) {
|
|
4485
|
-
return `${normalizedEscrow}_${normalizedDepositId}`;
|
|
4291
|
+
function inferIndexerEnvFromBaseApiUrl(baseApiUrl) {
|
|
4292
|
+
const normalized = withApiBase(baseApiUrl).toLowerCase();
|
|
4293
|
+
if (normalized.includes("preprod") || normalized.includes("preproduction") || normalized.includes("/preprod/")) {
|
|
4294
|
+
return "PREPRODUCTION";
|
|
4486
4295
|
}
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
function extractDepositIdOnContract(compositeDepositId) {
|
|
4490
|
-
if (!compositeDepositId) return null;
|
|
4491
|
-
const parts = compositeDepositId.split("_");
|
|
4492
|
-
const rawDepositId = parts[parts.length - 1];
|
|
4493
|
-
return rawDepositId && /^\d+$/.test(rawDepositId) ? rawDepositId : null;
|
|
4494
|
-
}
|
|
4495
|
-
function extractEscrowAddressFromCompositeDepositId(compositeDepositId) {
|
|
4496
|
-
if (!compositeDepositId) return null;
|
|
4497
|
-
const [escrowAddress] = compositeDepositId.split("_");
|
|
4498
|
-
return escrowAddress?.startsWith("0x") ? escrowAddress.toLowerCase() : null;
|
|
4499
|
-
}
|
|
4500
|
-
function parseRateManagerFilterIds(rateManagerIds) {
|
|
4501
|
-
const bare = /* @__PURE__ */ new Set();
|
|
4502
|
-
const scoped = /* @__PURE__ */ new Map();
|
|
4503
|
-
for (const value of rateManagerIds) {
|
|
4504
|
-
const scopedRateManager = parseScopedRateManagerFilterId(value);
|
|
4505
|
-
if (scopedRateManager) {
|
|
4506
|
-
scoped.set(
|
|
4507
|
-
getManagerScopeKey(scopedRateManager.rateManagerId, scopedRateManager.rateManagerAddress),
|
|
4508
|
-
scopedRateManager
|
|
4509
|
-
);
|
|
4510
|
-
continue;
|
|
4511
|
-
}
|
|
4512
|
-
if (value.includes(":")) {
|
|
4513
|
-
continue;
|
|
4514
|
-
}
|
|
4515
|
-
const normalizedRateManagerId = normalizeRateManagerId2(value);
|
|
4516
|
-
if (normalizedRateManagerId) {
|
|
4517
|
-
bare.add(normalizedRateManagerId);
|
|
4518
|
-
}
|
|
4296
|
+
if (normalized.includes("staging") || normalized.includes("/staging/") || normalized.includes("localhost") || normalized.includes("127.0.0.1")) {
|
|
4297
|
+
return "STAGING";
|
|
4519
4298
|
}
|
|
4520
|
-
return
|
|
4521
|
-
}
|
|
4522
|
-
function buildDepositScopeKey(scope) {
|
|
4523
|
-
return `${scope.escrow}:${scope.depositIdOnContract}`;
|
|
4299
|
+
return "PRODUCTION";
|
|
4524
4300
|
}
|
|
4525
|
-
function
|
|
4526
|
-
if (!
|
|
4301
|
+
async function withOptionalTimeout(promise, timeoutMs, endpoint) {
|
|
4302
|
+
if (!timeoutMs || timeoutMs <= 0) return promise;
|
|
4303
|
+
let timer;
|
|
4527
4304
|
try {
|
|
4528
|
-
return
|
|
4529
|
-
|
|
4530
|
-
|
|
4305
|
+
return await Promise.race([
|
|
4306
|
+
promise,
|
|
4307
|
+
new Promise((_, reject) => {
|
|
4308
|
+
timer = setTimeout(() => {
|
|
4309
|
+
reject(new NetworkError("Request timed out", { endpoint }));
|
|
4310
|
+
}, timeoutMs);
|
|
4311
|
+
})
|
|
4312
|
+
]);
|
|
4313
|
+
} finally {
|
|
4314
|
+
if (timer) clearTimeout(timer);
|
|
4531
4315
|
}
|
|
4532
4316
|
}
|
|
4533
|
-
function
|
|
4534
|
-
if (
|
|
4535
|
-
|
|
4536
|
-
|
|
4317
|
+
function toDateFromUnixSeconds(value) {
|
|
4318
|
+
if (!value) return void 0;
|
|
4319
|
+
const numeric = Number(value);
|
|
4320
|
+
if (!Number.isFinite(numeric) || numeric <= 0) return void 0;
|
|
4321
|
+
return new Date(numeric * 1e3);
|
|
4537
4322
|
}
|
|
4538
|
-
function
|
|
4539
|
-
if (
|
|
4540
|
-
const [chainIdRaw, blockNumberRaw, logIndexRaw] = id.split("_");
|
|
4541
|
-
if (!chainIdRaw || !blockNumberRaw || !logIndexRaw) return null;
|
|
4542
|
-
if (!/^\d+$/.test(chainIdRaw) || !/^\d+$/.test(blockNumberRaw) || !/^\d+$/.test(logIndexRaw)) {
|
|
4543
|
-
return null;
|
|
4544
|
-
}
|
|
4323
|
+
function toBigIntSafe(value) {
|
|
4324
|
+
if (value === null || value === void 0) return 0n;
|
|
4545
4325
|
try {
|
|
4546
|
-
return
|
|
4547
|
-
chainId: BigInt(chainIdRaw),
|
|
4548
|
-
blockNumber: BigInt(blockNumberRaw),
|
|
4549
|
-
logIndex: BigInt(logIndexRaw)
|
|
4550
|
-
};
|
|
4326
|
+
return BigInt(value);
|
|
4551
4327
|
} catch {
|
|
4552
|
-
return
|
|
4328
|
+
return 0n;
|
|
4553
4329
|
}
|
|
4554
4330
|
}
|
|
4555
|
-
function
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
if (
|
|
4566
|
-
|
|
4331
|
+
function normalizeOwnerDepositsStatus(status) {
|
|
4332
|
+
if (!status) return void 0;
|
|
4333
|
+
if (status === "WITHDRAWN") return "CLOSED";
|
|
4334
|
+
return status;
|
|
4335
|
+
}
|
|
4336
|
+
function buildLegacyVerifierCurrencies(deposit) {
|
|
4337
|
+
const currenciesByMethod = /* @__PURE__ */ new Map();
|
|
4338
|
+
for (const currency of deposit.currencies ?? []) {
|
|
4339
|
+
const methodHash = currency.paymentMethodHash;
|
|
4340
|
+
const resolvedConversionRate = currency.conversionRate ?? currency.minConversionRate;
|
|
4341
|
+
if (resolvedConversionRate === null || resolvedConversionRate === void 0) {
|
|
4342
|
+
logger.warn(
|
|
4343
|
+
`[sdk] Skipping currency with missing conversion rate (deposit ${deposit.depositId}, currency ${currency.currencyCode})`
|
|
4344
|
+
);
|
|
4345
|
+
continue;
|
|
4567
4346
|
}
|
|
4568
|
-
|
|
4347
|
+
const bucket = currenciesByMethod.get(methodHash) ?? [];
|
|
4348
|
+
bucket.push({
|
|
4349
|
+
currencyCode: currency.currencyCode,
|
|
4350
|
+
conversionRate: resolvedConversionRate,
|
|
4351
|
+
minConversionRate: currency.minConversionRate,
|
|
4352
|
+
managerRate: currency.managerRate ?? null,
|
|
4353
|
+
rateManagerId: currency.rateManagerId ?? null
|
|
4354
|
+
});
|
|
4355
|
+
currenciesByMethod.set(methodHash, bucket);
|
|
4569
4356
|
}
|
|
4570
|
-
return
|
|
4571
|
-
}
|
|
4572
|
-
function isAggregateOrderField(field) {
|
|
4573
|
-
return field === "currentDelegatedBalance" || field === "totalFilledVolume";
|
|
4357
|
+
return currenciesByMethod;
|
|
4574
4358
|
}
|
|
4575
|
-
function
|
|
4359
|
+
function convertIndexerDepositToLegacyApiDeposit(deposit) {
|
|
4360
|
+
const currenciesByMethod = buildLegacyVerifierCurrencies(deposit);
|
|
4361
|
+
const verifiers = (deposit.paymentMethods ?? []).filter((paymentMethod) => paymentMethod.active !== false).map((paymentMethod) => ({
|
|
4362
|
+
depositId: Number(deposit.depositId),
|
|
4363
|
+
verifier: "",
|
|
4364
|
+
methodHash: paymentMethod.paymentMethodHash,
|
|
4365
|
+
intentGatingService: paymentMethod.intentGatingService,
|
|
4366
|
+
payeeDetailsHash: paymentMethod.payeeDetailsHash,
|
|
4367
|
+
data: "0x",
|
|
4368
|
+
currencies: currenciesByMethod.get(paymentMethod.paymentMethodHash) ?? []
|
|
4369
|
+
}));
|
|
4370
|
+
const remainingDeposits = toBigIntSafe(deposit.remainingDeposits);
|
|
4371
|
+
const outstandingIntentAmount = toBigIntSafe(deposit.outstandingIntentAmount);
|
|
4372
|
+
const totalAmountTaken = toBigIntSafe(deposit.totalAmountTaken);
|
|
4373
|
+
const totalWithdrawn = toBigIntSafe(deposit.totalWithdrawn);
|
|
4374
|
+
const amount = remainingDeposits + outstandingIntentAmount + totalAmountTaken + totalWithdrawn;
|
|
4576
4375
|
return {
|
|
4577
|
-
|
|
4578
|
-
|
|
4376
|
+
id: Number(deposit.depositId),
|
|
4377
|
+
depositor: deposit.depositor,
|
|
4378
|
+
token: deposit.token,
|
|
4379
|
+
amount: amount.toString(),
|
|
4380
|
+
remainingDeposits: deposit.remainingDeposits,
|
|
4381
|
+
intentAmountMin: deposit.intentAmountMin,
|
|
4382
|
+
intentAmountMax: deposit.intentAmountMax,
|
|
4383
|
+
acceptingIntents: deposit.acceptingIntents,
|
|
4384
|
+
outstandingIntentAmount: deposit.outstandingIntentAmount,
|
|
4385
|
+
availableLiquidity: deposit.remainingDeposits,
|
|
4386
|
+
status: deposit.status,
|
|
4387
|
+
totalIntents: deposit.totalIntents,
|
|
4388
|
+
signaledIntents: deposit.signaledIntents,
|
|
4389
|
+
fulfilledIntents: deposit.fulfilledIntents,
|
|
4390
|
+
prunedIntents: deposit.prunedIntents,
|
|
4391
|
+
totalAmountTaken: deposit.totalAmountTaken,
|
|
4392
|
+
totalWithdrawn: deposit.totalWithdrawn,
|
|
4393
|
+
successRateBps: deposit.successRateBps,
|
|
4394
|
+
rateManagerId: deposit.rateManagerId ?? null,
|
|
4395
|
+
vaultName: null,
|
|
4396
|
+
rateManagerRegistry: null,
|
|
4397
|
+
createdAt: toDateFromUnixSeconds(deposit.timestamp),
|
|
4398
|
+
updatedAt: toDateFromUnixSeconds(deposit.updatedAt),
|
|
4399
|
+
verifiers
|
|
4579
4400
|
};
|
|
4580
4401
|
}
|
|
4581
|
-
function
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
rateManagerId,
|
|
4589
|
-
rateManagerAddress: normalizeAddress3(deposit.rateManagerAddress) || null,
|
|
4590
|
-
depositId: deposit.id,
|
|
4591
|
-
delegatedAt,
|
|
4592
|
-
createdAt: delegatedAt ?? deposit.updatedAt,
|
|
4593
|
-
updatedAt: deposit.updatedAt
|
|
4594
|
-
};
|
|
4402
|
+
async function apiPostDepositDetails(req, baseApiUrl, timeoutMs) {
|
|
4403
|
+
return apiFetch({
|
|
4404
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/create`,
|
|
4405
|
+
method: "POST",
|
|
4406
|
+
body: req,
|
|
4407
|
+
timeoutMs
|
|
4408
|
+
});
|
|
4595
4409
|
}
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
buildRateManagerScopeWhere(rateManagerIds) {
|
|
4601
|
-
if (!rateManagerIds?.length) return void 0;
|
|
4602
|
-
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
4603
|
-
const scopeConditions = [];
|
|
4604
|
-
if (bare.size > 0) {
|
|
4605
|
-
scopeConditions.push({
|
|
4606
|
-
rateManagerId: { _in: [...bare] }
|
|
4607
|
-
});
|
|
4608
|
-
}
|
|
4609
|
-
for (const scopedRateManager of scoped.values()) {
|
|
4610
|
-
scopeConditions.push({
|
|
4611
|
-
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
4612
|
-
rateManagerAddress: { _eq: scopedRateManager.rateManagerAddress }
|
|
4613
|
-
});
|
|
4614
|
-
}
|
|
4615
|
-
if (scopeConditions.length === 1) {
|
|
4616
|
-
return scopeConditions[0];
|
|
4617
|
-
}
|
|
4618
|
-
if (scopeConditions.length > 1) {
|
|
4619
|
-
return { _or: scopeConditions };
|
|
4410
|
+
async function apiGetQuote(req, baseApiUrl, timeoutMs, apiKey) {
|
|
4411
|
+
if (req.quotesToReturn !== void 0) {
|
|
4412
|
+
if (!Number.isInteger(req.quotesToReturn) || req.quotesToReturn < 1) {
|
|
4413
|
+
throw new ValidationError("quotesToReturn must be a positive integer", "quotesToReturn");
|
|
4620
4414
|
}
|
|
4621
|
-
return void 0;
|
|
4622
4415
|
}
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
const where = {};
|
|
4626
|
-
if (filter.manager) {
|
|
4627
|
-
where.manager = { _ilike: filter.manager };
|
|
4628
|
-
}
|
|
4629
|
-
if (filter.name) {
|
|
4630
|
-
where.name = { _ilike: `%${filter.name}%` };
|
|
4631
|
-
}
|
|
4632
|
-
if (filter.maxFee) {
|
|
4633
|
-
where.maxFee = { _lte: filter.maxFee };
|
|
4634
|
-
}
|
|
4635
|
-
const scopeWhere = this.buildRateManagerScopeWhere(filter.rateManagerIds);
|
|
4636
|
-
if (scopeWhere) {
|
|
4637
|
-
Object.assign(where, scopeWhere);
|
|
4638
|
-
}
|
|
4639
|
-
return Object.keys(where).length ? where : void 0;
|
|
4416
|
+
if (!isValidHexAddress(req.user)) {
|
|
4417
|
+
throw new ValidationError("user must be a valid Ethereum address", "user");
|
|
4640
4418
|
}
|
|
4641
|
-
|
|
4642
|
-
|
|
4419
|
+
if (!isValidHexAddress(req.recipient)) {
|
|
4420
|
+
throw new ValidationError("recipient must be a valid Ethereum address", "recipient");
|
|
4643
4421
|
}
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
if (bare.size > 0) {
|
|
4650
|
-
scopeConditions.push({
|
|
4651
|
-
rateManagerId: { _in: [...bare] }
|
|
4652
|
-
});
|
|
4653
|
-
}
|
|
4654
|
-
for (const scopedRateManager of scoped.values()) {
|
|
4655
|
-
scopeConditions.push({
|
|
4656
|
-
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
4657
|
-
id: {
|
|
4658
|
-
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
4659
|
-
scopedRateManager.rateManagerId,
|
|
4660
|
-
scopedRateManager.rateManagerAddress
|
|
4661
|
-
)
|
|
4662
|
-
}
|
|
4663
|
-
});
|
|
4664
|
-
}
|
|
4665
|
-
if (scopeConditions.length === 1) {
|
|
4666
|
-
return scopeConditions[0] ?? {};
|
|
4667
|
-
}
|
|
4668
|
-
if (scopeConditions.length > 1) {
|
|
4669
|
-
return { _or: scopeConditions };
|
|
4670
|
-
}
|
|
4671
|
-
return {};
|
|
4422
|
+
if (!isValidHexAddress(req.destinationToken)) {
|
|
4423
|
+
throw new ValidationError(
|
|
4424
|
+
"destinationToken must be a valid Ethereum address",
|
|
4425
|
+
"destinationToken"
|
|
4426
|
+
);
|
|
4672
4427
|
}
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4428
|
+
const isExactFiat = req.isExactFiat !== false;
|
|
4429
|
+
const endpoint = isExactFiat ? "exact-fiat" : "exact-token";
|
|
4430
|
+
let url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
4431
|
+
if (req.quotesToReturn) url += `?quotesToReturn=${req.quotesToReturn}`;
|
|
4432
|
+
const requestBody = {
|
|
4433
|
+
...req,
|
|
4434
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
4435
|
+
amount: void 0,
|
|
4436
|
+
isExactFiat: void 0,
|
|
4437
|
+
quotesToReturn: void 0,
|
|
4438
|
+
includePrivateOrderbooks: req.includePrivateOrderbooks
|
|
4439
|
+
};
|
|
4440
|
+
Object.keys(requestBody).forEach((k) => requestBody[k] === void 0 && delete requestBody[k]);
|
|
4441
|
+
return apiFetch({
|
|
4442
|
+
url,
|
|
4443
|
+
method: "POST",
|
|
4444
|
+
body: requestBody,
|
|
4445
|
+
apiKey,
|
|
4446
|
+
timeoutMs
|
|
4447
|
+
});
|
|
4448
|
+
}
|
|
4449
|
+
async function apiGetQuotesBestByPlatform(req, baseApiUrl, timeoutMs, apiKey) {
|
|
4450
|
+
const isExactFiat = req.isExactFiat !== false;
|
|
4451
|
+
const endpoint = isExactFiat ? "best-by-platform" : "best-by-platform-exact-token";
|
|
4452
|
+
const url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
4453
|
+
const requestBody = {
|
|
4454
|
+
...req,
|
|
4455
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
4456
|
+
amount: void 0,
|
|
4457
|
+
isExactFiat: void 0,
|
|
4458
|
+
referrerFeeConfig: void 0
|
|
4459
|
+
};
|
|
4460
|
+
Object.keys(requestBody).forEach(
|
|
4461
|
+
(key) => requestBody[key] === void 0 && delete requestBody[key]
|
|
4462
|
+
);
|
|
4463
|
+
return apiFetch({
|
|
4464
|
+
url,
|
|
4465
|
+
method: "POST",
|
|
4466
|
+
body: requestBody,
|
|
4467
|
+
apiKey,
|
|
4468
|
+
timeoutMs
|
|
4469
|
+
});
|
|
4470
|
+
}
|
|
4471
|
+
async function apiGetPayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
4472
|
+
return apiFetch({
|
|
4473
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/${req.processorName}/${req.hashedOnchainId}`,
|
|
4474
|
+
method: "GET",
|
|
4475
|
+
timeoutMs
|
|
4476
|
+
});
|
|
4477
|
+
}
|
|
4478
|
+
async function apiValidatePayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
4479
|
+
const data = await apiFetch({
|
|
4480
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/validate`,
|
|
4481
|
+
method: "POST",
|
|
4482
|
+
body: req,
|
|
4483
|
+
timeoutMs
|
|
4484
|
+
});
|
|
4485
|
+
if (typeof data?.responseObject === "boolean") {
|
|
4486
|
+
return {
|
|
4487
|
+
...data,
|
|
4488
|
+
responseObject: { isValid: data.responseObject }
|
|
4489
|
+
};
|
|
4678
4490
|
}
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4491
|
+
return data;
|
|
4492
|
+
}
|
|
4493
|
+
async function apiGetOwnerDeposits(req, apiKey, baseApiUrl, authToken, timeoutMs) {
|
|
4494
|
+
const escrowAddress = requireEscrowAddress(
|
|
4495
|
+
req.escrowAddress,
|
|
4496
|
+
"apiGetOwnerDeposits requires escrowAddress"
|
|
4497
|
+
);
|
|
4498
|
+
const indexerEndpoint = defaultIndexerEndpoint(inferIndexerEnvFromBaseApiUrl(baseApiUrl));
|
|
4499
|
+
const indexerClient = new IndexerClient(indexerEndpoint, {
|
|
4500
|
+
apiKey,
|
|
4501
|
+
authorizationToken: authToken
|
|
4502
|
+
});
|
|
4503
|
+
const service = new IndexerDepositService(indexerClient);
|
|
4504
|
+
const deposits = await withOptionalTimeout(
|
|
4505
|
+
service.fetchDepositsWithRelations(
|
|
4506
|
+
{
|
|
4507
|
+
depositor: req.ownerAddress,
|
|
4508
|
+
escrowAddress,
|
|
4509
|
+
escrowAddresses: req.escrowAddresses?.length ? req.escrowAddresses : void 0,
|
|
4510
|
+
status: normalizeOwnerDepositsStatus(req.status)
|
|
4511
|
+
},
|
|
4512
|
+
void 0,
|
|
4513
|
+
{ includeIntents: false }
|
|
4514
|
+
),
|
|
4515
|
+
timeoutMs,
|
|
4516
|
+
indexerEndpoint
|
|
4517
|
+
);
|
|
4518
|
+
return {
|
|
4519
|
+
success: true,
|
|
4520
|
+
message: "ok",
|
|
4521
|
+
responseObject: deposits.map(convertIndexerDepositToLegacyApiDeposit),
|
|
4522
|
+
statusCode: 200
|
|
4523
|
+
};
|
|
4524
|
+
}
|
|
4525
|
+
async function apiGetTakerTier(req, baseApiUrl, timeoutMs) {
|
|
4526
|
+
const normalizedOwner = req.owner.toLowerCase();
|
|
4527
|
+
const query = new URLSearchParams({
|
|
4528
|
+
owner: normalizedOwner,
|
|
4529
|
+
chainId: String(req.chainId)
|
|
4530
|
+
});
|
|
4531
|
+
const endpoint = `/v2/taker/tier?${query.toString()}`;
|
|
4532
|
+
return apiFetch({
|
|
4533
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4534
|
+
method: "GET",
|
|
4535
|
+
timeoutMs
|
|
4536
|
+
});
|
|
4537
|
+
}
|
|
4538
|
+
async function apiGetReferralDashboard(opts) {
|
|
4539
|
+
const address = opts.address ? normalizeReferralAddress(opts.address, "address") : void 0;
|
|
4540
|
+
const endpoint = address ? `/v2/referral?${new URLSearchParams({ address }).toString()}` : "/v2/referral";
|
|
4541
|
+
const authorizationToken = address ? void 0 : requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
4542
|
+
const response = await apiFetch({
|
|
4543
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4544
|
+
method: "GET",
|
|
4545
|
+
authorizationToken,
|
|
4546
|
+
timeoutMs: opts.timeoutMs
|
|
4547
|
+
});
|
|
4548
|
+
return unwrapResponseObject(response);
|
|
4549
|
+
}
|
|
4550
|
+
async function apiGetReferralEarnings(opts) {
|
|
4551
|
+
const address = opts.address ? normalizeReferralAddress(opts.address, "address") : void 0;
|
|
4552
|
+
const endpoint = address ? `/v2/referral/earnings?${new URLSearchParams({ address }).toString()}` : "/v2/referral/earnings";
|
|
4553
|
+
const authorizationToken = address ? void 0 : requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
4554
|
+
const response = await apiFetch({
|
|
4555
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4556
|
+
method: "GET",
|
|
4557
|
+
authorizationToken,
|
|
4558
|
+
timeoutMs: opts.timeoutMs
|
|
4559
|
+
});
|
|
4560
|
+
return unwrapResponseObject(response);
|
|
4561
|
+
}
|
|
4562
|
+
async function apiLookupReferralCode(code, opts) {
|
|
4563
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
4564
|
+
const endpoint = `/v2/referral/code/${encodeURIComponent(normalizedCode)}`;
|
|
4565
|
+
const response = await apiFetch({
|
|
4566
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4567
|
+
method: "GET",
|
|
4568
|
+
timeoutMs: opts.timeoutMs
|
|
4569
|
+
});
|
|
4570
|
+
return unwrapResponseObject(response);
|
|
4571
|
+
}
|
|
4572
|
+
async function apiCreateReferralCode(req, opts) {
|
|
4573
|
+
const endpoint = "/v2/referral/code";
|
|
4574
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
4575
|
+
opts.authorizationToken,
|
|
4576
|
+
req.signature,
|
|
4577
|
+
endpoint
|
|
4578
|
+
);
|
|
4579
|
+
const response = await apiFetch({
|
|
4580
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4581
|
+
method: "POST",
|
|
4582
|
+
body: req.signature ? { signature: req.signature } : {},
|
|
4583
|
+
authorizationToken,
|
|
4584
|
+
timeoutMs: opts.timeoutMs
|
|
4585
|
+
});
|
|
4586
|
+
return unwrapResponseObject(response);
|
|
4587
|
+
}
|
|
4588
|
+
async function apiRedeemReferralCode(req, opts) {
|
|
4589
|
+
const endpoint = "/v2/referral/redeem";
|
|
4590
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
4591
|
+
opts.authorizationToken,
|
|
4592
|
+
req.signature,
|
|
4593
|
+
endpoint
|
|
4594
|
+
);
|
|
4595
|
+
const response = await apiFetch({
|
|
4596
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4597
|
+
method: "POST",
|
|
4598
|
+
body: {
|
|
4599
|
+
code: normalizeReferralCode(req.code),
|
|
4600
|
+
...req.signature ? { signature: req.signature } : {}
|
|
4601
|
+
},
|
|
4602
|
+
authorizationToken,
|
|
4603
|
+
timeoutMs: opts.timeoutMs
|
|
4604
|
+
});
|
|
4605
|
+
return unwrapResponseObject(response);
|
|
4606
|
+
}
|
|
4607
|
+
async function apiUpdateReferralCode(req, opts) {
|
|
4608
|
+
const endpoint = "/v2/referral/code";
|
|
4609
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
4610
|
+
opts.authorizationToken,
|
|
4611
|
+
req.signature,
|
|
4612
|
+
endpoint
|
|
4613
|
+
);
|
|
4614
|
+
const response = await apiFetch({
|
|
4615
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
4616
|
+
method: "PATCH",
|
|
4617
|
+
body: {
|
|
4618
|
+
code: normalizeReferralCode(req.code),
|
|
4619
|
+
...req.signature ? { signature: req.signature } : {}
|
|
4620
|
+
},
|
|
4621
|
+
authorizationToken,
|
|
4622
|
+
timeoutMs: opts.timeoutMs
|
|
4623
|
+
});
|
|
4624
|
+
return unwrapResponseObject(response);
|
|
4625
|
+
}
|
|
4626
|
+
async function apiUploadSellerCredential(processorName, payeeDetails, bundle, baseApiUrl, timeoutMs, authorizationToken) {
|
|
4627
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
4628
|
+
payeeDetails
|
|
4629
|
+
)}/seller-credential`;
|
|
4630
|
+
return apiFetch({
|
|
4631
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4632
|
+
method: "POST",
|
|
4633
|
+
body: bundle,
|
|
4634
|
+
timeoutMs,
|
|
4635
|
+
authorizationToken
|
|
4636
|
+
});
|
|
4637
|
+
}
|
|
4638
|
+
async function apiUploadGoogleOAuthSellerCredential(processorName, payeeDetails, body, baseApiUrl, opts) {
|
|
4639
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
4640
|
+
payeeDetails
|
|
4641
|
+
)}/seller-credential/google-oauth`;
|
|
4642
|
+
return apiFetch({
|
|
4643
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4644
|
+
method: "POST",
|
|
4645
|
+
body,
|
|
4646
|
+
timeoutMs: opts?.timeoutMs
|
|
4647
|
+
});
|
|
4648
|
+
}
|
|
4649
|
+
async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApiUrl, timeoutMs) {
|
|
4650
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
4651
|
+
payeeDetails
|
|
4652
|
+
)}/seller-credential/status`;
|
|
4653
|
+
return apiFetch({
|
|
4654
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
4655
|
+
method: "GET",
|
|
4656
|
+
timeoutMs
|
|
4657
|
+
});
|
|
4658
|
+
}
|
|
4659
|
+
async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey) {
|
|
4660
|
+
const body = {
|
|
4661
|
+
txId: req.txId,
|
|
4662
|
+
chainId: req.chainId,
|
|
4663
|
+
intent: req.intent,
|
|
4664
|
+
...req.metadata !== void 0 ? { metadata: req.metadata } : {}
|
|
4665
|
+
};
|
|
4666
|
+
return apiFetch({
|
|
4667
|
+
url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
|
|
4668
|
+
method: "POST",
|
|
4669
|
+
body,
|
|
4670
|
+
apiKey,
|
|
4671
|
+
timeoutMs
|
|
4672
|
+
});
|
|
4673
|
+
}
|
|
4674
|
+
async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs) {
|
|
4675
|
+
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
4676
|
+
baseApiUrl: optsOrBaseApiUrl,
|
|
4677
|
+
timeoutMs
|
|
4678
|
+
} : optsOrBaseApiUrl;
|
|
4679
|
+
const query = new URLSearchParams();
|
|
4680
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
4681
|
+
if (value === void 0 || value === null) return;
|
|
4682
|
+
query.set(key, String(value));
|
|
4683
|
+
});
|
|
4684
|
+
const response = await apiFetch({
|
|
4685
|
+
url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook?${query.toString()}`,
|
|
4686
|
+
method: "GET",
|
|
4687
|
+
timeoutMs: opts.timeoutMs
|
|
4688
|
+
});
|
|
4689
|
+
return response.responseObject;
|
|
4690
|
+
}
|
|
4691
|
+
async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs) {
|
|
4692
|
+
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
4693
|
+
baseApiUrl: optsOrBaseApiUrl,
|
|
4694
|
+
timeoutMs
|
|
4695
|
+
} : optsOrBaseApiUrl;
|
|
4696
|
+
const escrowAddress = requireEscrowAddress(
|
|
4697
|
+
params.escrowAddress,
|
|
4698
|
+
"apiGetDepositBundle requires escrowAddress"
|
|
4699
|
+
);
|
|
4700
|
+
const query = new URLSearchParams({ escrowAddress });
|
|
4701
|
+
if (params.dailySnapshotLimit !== void 0) {
|
|
4702
|
+
query.set("dailySnapshotLimit", String(params.dailySnapshotLimit));
|
|
4693
4703
|
}
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4704
|
+
const response = await apiFetch({
|
|
4705
|
+
url: `${withApiBase(opts.baseApiUrl)}/v2/deposits/${params.depositId}/bundle?${query.toString()}`,
|
|
4706
|
+
method: "GET",
|
|
4707
|
+
timeoutMs: opts.timeoutMs
|
|
4708
|
+
});
|
|
4709
|
+
return response.responseObject;
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4712
|
+
// src/client/ReferralAccountOperations.ts
|
|
4713
|
+
var ReferralAccountOperations = class {
|
|
4714
|
+
constructor(config) {
|
|
4715
|
+
this.config = config;
|
|
4697
4716
|
}
|
|
4698
|
-
async
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
}
|
|
4708
|
-
return this.client.query({
|
|
4709
|
-
query: LEGACY_RATE_MANAGER_LIST_QUERY,
|
|
4710
|
-
variables: legacyVariables
|
|
4711
|
-
});
|
|
4712
|
-
}
|
|
4717
|
+
async getReferralDashboard(opts) {
|
|
4718
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4719
|
+
const authorizationToken = opts?.address ? void 0 : await this.resolveAuthorizationToken(opts);
|
|
4720
|
+
return apiGetReferralDashboard({
|
|
4721
|
+
baseApiUrl,
|
|
4722
|
+
timeoutMs,
|
|
4723
|
+
authorizationToken,
|
|
4724
|
+
address: opts?.address
|
|
4725
|
+
});
|
|
4713
4726
|
}
|
|
4714
|
-
|
|
4715
|
-
const
|
|
4716
|
-
const
|
|
4717
|
-
|
|
4718
|
-
|
|
4727
|
+
async getReferralEarnings(opts) {
|
|
4728
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4729
|
+
const authorizationToken = opts?.address ? void 0 : await this.resolveAuthorizationToken(opts);
|
|
4730
|
+
return apiGetReferralEarnings({
|
|
4731
|
+
baseApiUrl,
|
|
4732
|
+
timeoutMs,
|
|
4733
|
+
authorizationToken,
|
|
4734
|
+
address: opts?.address
|
|
4735
|
+
});
|
|
4719
4736
|
}
|
|
4720
|
-
|
|
4721
|
-
const
|
|
4722
|
-
|
|
4723
|
-
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
4724
|
-
return [{ [field]: direction }];
|
|
4737
|
+
async lookupReferralCode(code, opts) {
|
|
4738
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4739
|
+
return apiLookupReferralCode(code, { baseApiUrl, timeoutMs });
|
|
4725
4740
|
}
|
|
4726
|
-
async
|
|
4727
|
-
const
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
const delegations = await this.fetchRateManagerDelegations(rateManagerId, {
|
|
4731
|
-
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
4732
|
-
offset,
|
|
4733
|
-
orderBy: "delegatedAt",
|
|
4734
|
-
orderDirection: "desc",
|
|
4735
|
-
rateManagerAddress: rateManagerAddress || void 0
|
|
4736
|
-
});
|
|
4737
|
-
for (const delegation of delegations) {
|
|
4738
|
-
const escrow = extractEscrowAddressFromCompositeDepositId(delegation.depositId);
|
|
4739
|
-
const depositIdOnContract = extractDepositIdOnContract(delegation.depositId);
|
|
4740
|
-
if (!escrow || !depositIdOnContract) continue;
|
|
4741
|
-
const scope = { escrow, depositIdOnContract };
|
|
4742
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
4743
|
-
}
|
|
4744
|
-
if (delegations.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
4745
|
-
break;
|
|
4746
|
-
}
|
|
4747
|
-
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
4748
|
-
}
|
|
4749
|
-
return [...scopes.values()];
|
|
4741
|
+
async createReferralCode(opts) {
|
|
4742
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4743
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
4744
|
+
return apiCreateReferralCode({}, { baseApiUrl, timeoutMs, authorizationToken });
|
|
4750
4745
|
}
|
|
4751
|
-
async
|
|
4752
|
-
const
|
|
4753
|
-
const
|
|
4754
|
-
|
|
4755
|
-
const currentScopes = await this.fetchCurrentRateManagerDepositScopes(
|
|
4756
|
-
normalizedId,
|
|
4757
|
-
normalizedRateManagerAddress || void 0
|
|
4758
|
-
);
|
|
4759
|
-
for (const scope of currentScopes) {
|
|
4760
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
4761
|
-
}
|
|
4762
|
-
try {
|
|
4763
|
-
let offset = 0;
|
|
4764
|
-
for (; ; ) {
|
|
4765
|
-
const result = await this.client.query({
|
|
4766
|
-
query: RATE_MANAGER_ASSIGNMENT_EVENTS_QUERY,
|
|
4767
|
-
variables: {
|
|
4768
|
-
setWhere: {
|
|
4769
|
-
rateManagerId: { _eq: normalizedId },
|
|
4770
|
-
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
4771
|
-
},
|
|
4772
|
-
clearedWhere: {
|
|
4773
|
-
rateManagerId: { _eq: normalizedId },
|
|
4774
|
-
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
4775
|
-
},
|
|
4776
|
-
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
4777
|
-
offset
|
|
4778
|
-
}
|
|
4779
|
-
});
|
|
4780
|
-
const setEvents = result.EscrowV2_DepositRateManagerSet ?? [];
|
|
4781
|
-
const clearedEvents = result.EscrowV2_DepositRateManagerCleared ?? [];
|
|
4782
|
-
for (const event of [...setEvents, ...clearedEvents]) {
|
|
4783
|
-
const escrow = normalizeAddress3(event.escrow);
|
|
4784
|
-
const depositIdOnContract = event.depositIdOnContract?.toString() ?? "";
|
|
4785
|
-
if (!escrow || !depositIdOnContract) continue;
|
|
4786
|
-
const scope = { escrow, depositIdOnContract };
|
|
4787
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
4788
|
-
}
|
|
4789
|
-
if (setEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE && clearedEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
4790
|
-
break;
|
|
4791
|
-
}
|
|
4792
|
-
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
4793
|
-
}
|
|
4794
|
-
} catch (error) {
|
|
4795
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
4796
|
-
throw error;
|
|
4797
|
-
}
|
|
4798
|
-
}
|
|
4799
|
-
return [...scopes.values()];
|
|
4746
|
+
async createReferralCodeWithSignature(opts) {
|
|
4747
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4748
|
+
const signature = await this.signCreateReferralCode(opts);
|
|
4749
|
+
return apiCreateReferralCode({ signature }, { baseApiUrl, timeoutMs });
|
|
4800
4750
|
}
|
|
4801
|
-
async
|
|
4802
|
-
const
|
|
4803
|
-
const
|
|
4804
|
-
|
|
4805
|
-
const offset = pagination?.offset ?? 0;
|
|
4806
|
-
const where = this.buildWhere(filter);
|
|
4807
|
-
const aggregateWhere = this.buildAggregateWhere(filter);
|
|
4808
|
-
const legacyAggregateWhere = this.buildLegacyAggregateWhere(filter);
|
|
4809
|
-
if (isAggregateOrderField(orderBy)) {
|
|
4810
|
-
const result2 = await this.queryRateManagerList(
|
|
4811
|
-
{
|
|
4812
|
-
where,
|
|
4813
|
-
aggregateWhere,
|
|
4814
|
-
order_by: [{ createdAt: "desc" }]
|
|
4815
|
-
},
|
|
4816
|
-
{
|
|
4817
|
-
where,
|
|
4818
|
-
aggregateWhere: legacyAggregateWhere,
|
|
4819
|
-
order_by: [{ createdAt: "desc" }]
|
|
4820
|
-
}
|
|
4821
|
-
);
|
|
4822
|
-
const scopedRows = this.applyHookFilter(this.toRateManagerListItems(result2), filter?.hasHook);
|
|
4823
|
-
const sorted = scopedRows.sort((a, b) => {
|
|
4824
|
-
const av = orderBy === "currentDelegatedBalance" ? toSafeBigInt(a.aggregate?.currentDelegatedBalance) : toSafeBigInt(a.aggregate?.totalFilledVolume);
|
|
4825
|
-
const bv = orderBy === "currentDelegatedBalance" ? toSafeBigInt(b.aggregate?.currentDelegatedBalance) : toSafeBigInt(b.aggregate?.totalFilledVolume);
|
|
4826
|
-
const aggregateCmp = compareBigInt(av, bv, direction);
|
|
4827
|
-
if (aggregateCmp !== 0) return aggregateCmp;
|
|
4828
|
-
const createdAtCmp = compareBigInt(
|
|
4829
|
-
toSafeBigInt(a.manager.createdAt),
|
|
4830
|
-
toSafeBigInt(b.manager.createdAt),
|
|
4831
|
-
"desc"
|
|
4832
|
-
);
|
|
4833
|
-
if (createdAtCmp !== 0) return createdAtCmp;
|
|
4834
|
-
return a.manager.rateManagerId.localeCompare(b.manager.rateManagerId);
|
|
4835
|
-
});
|
|
4836
|
-
return sorted.slice(offset, offset + limit);
|
|
4837
|
-
}
|
|
4838
|
-
const result = await this.queryRateManagerList(
|
|
4839
|
-
{
|
|
4840
|
-
where,
|
|
4841
|
-
aggregateWhere,
|
|
4842
|
-
order_by: this.buildOrderBy(pagination),
|
|
4843
|
-
limit,
|
|
4844
|
-
offset
|
|
4845
|
-
},
|
|
4846
|
-
{
|
|
4847
|
-
where,
|
|
4848
|
-
aggregateWhere: legacyAggregateWhere,
|
|
4849
|
-
order_by: this.buildOrderBy(pagination),
|
|
4850
|
-
limit,
|
|
4851
|
-
offset
|
|
4852
|
-
}
|
|
4853
|
-
);
|
|
4854
|
-
return this.applyHookFilter(this.toRateManagerListItems(result), filter?.hasHook);
|
|
4751
|
+
async redeemReferralCode(code, opts) {
|
|
4752
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4753
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
4754
|
+
return apiRedeemReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
4855
4755
|
}
|
|
4856
|
-
async
|
|
4857
|
-
|
|
4858
|
-
const
|
|
4859
|
-
const
|
|
4860
|
-
const
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
rateManagerId: { _eq: normalizedId },
|
|
4894
|
-
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
4895
|
-
}
|
|
4756
|
+
async redeemReferralCodeWithSignature(code, opts) {
|
|
4757
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4758
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
4759
|
+
const lookup = opts?.referrerWalletAddress ? void 0 : await this.lookupReferralCode(normalizedCode, { baseApiUrl, timeoutMs });
|
|
4760
|
+
const referrerWalletAddress = opts?.referrerWalletAddress ?? lookup?.referrerWalletAddress;
|
|
4761
|
+
if (!referrerWalletAddress) {
|
|
4762
|
+
throw new ValidationError(
|
|
4763
|
+
"referrerWalletAddress is required for referral signature auth",
|
|
4764
|
+
"referrerWalletAddress"
|
|
4765
|
+
);
|
|
4766
|
+
}
|
|
4767
|
+
if (lookup && !lookup.isActive) {
|
|
4768
|
+
throw new ValidationError("Referral code is not active", "code");
|
|
4769
|
+
}
|
|
4770
|
+
const signature = await this.signRedeemReferralCode(
|
|
4771
|
+
normalizedCode,
|
|
4772
|
+
referrerWalletAddress,
|
|
4773
|
+
opts
|
|
4774
|
+
);
|
|
4775
|
+
return apiRedeemReferralCode({ code: normalizedCode, signature }, { baseApiUrl, timeoutMs });
|
|
4776
|
+
}
|
|
4777
|
+
async updateReferralCode(code, opts) {
|
|
4778
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4779
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
4780
|
+
return apiUpdateReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
4781
|
+
}
|
|
4782
|
+
async updateReferralCodeWithSignature(code, opts) {
|
|
4783
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
4784
|
+
const signature = await this.signRenameReferralCode(code, opts.oldCode, opts);
|
|
4785
|
+
return apiUpdateReferralCode({ code, signature }, { baseApiUrl, timeoutMs });
|
|
4786
|
+
}
|
|
4787
|
+
resolveRequestOptions(opts) {
|
|
4788
|
+
return {
|
|
4789
|
+
baseApiUrl: this.stripTrailingSlash(
|
|
4790
|
+
opts?.baseApiUrl ?? this.config.getBaseApiUrl() ?? DEFAULT_BASE_API_URL
|
|
4791
|
+
),
|
|
4792
|
+
timeoutMs: opts?.timeoutMs ?? this.config.getApiTimeoutMs()
|
|
4896
4793
|
};
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4794
|
+
}
|
|
4795
|
+
stripTrailingSlash(url) {
|
|
4796
|
+
return url.replace(/\/$/, "");
|
|
4797
|
+
}
|
|
4798
|
+
async resolveAuthorizationToken(opts) {
|
|
4799
|
+
if (opts?.authorizationToken !== void 0) {
|
|
4800
|
+
return opts.authorizationToken;
|
|
4801
|
+
}
|
|
4802
|
+
const provider = opts?.getAuthorizationToken ?? this.config.getAuthorizationTokenProvider();
|
|
4803
|
+
if (provider) {
|
|
4804
|
+
return await provider() ?? void 0;
|
|
4805
|
+
}
|
|
4806
|
+
return this.config.getAuthorizationToken();
|
|
4807
|
+
}
|
|
4808
|
+
resolveAudience(audience) {
|
|
4809
|
+
if (audience) return audience;
|
|
4810
|
+
if (this.config.getChainId() === hardhat.id) return "localhardhat";
|
|
4811
|
+
if (this.config.getRuntimeEnv() === "staging") return "base_staging";
|
|
4812
|
+
return "base_production";
|
|
4813
|
+
}
|
|
4814
|
+
resolveIssuedAt(issuedAt) {
|
|
4815
|
+
const resolved = issuedAt ?? Math.floor(Date.now() / 1e3);
|
|
4816
|
+
if (!Number.isInteger(resolved) || resolved <= 0) {
|
|
4817
|
+
throw new ValidationError("issuedAt must be a positive unix timestamp", "issuedAt");
|
|
4818
|
+
}
|
|
4819
|
+
return resolved;
|
|
4820
|
+
}
|
|
4821
|
+
getSigningAccount() {
|
|
4822
|
+
const walletClient = this.config.getWalletClient();
|
|
4823
|
+
const account = walletClient.account;
|
|
4824
|
+
if (!account) {
|
|
4825
|
+
throw new ValidationError(
|
|
4826
|
+
"walletClient account is required for referral signature auth",
|
|
4827
|
+
"walletClient.account"
|
|
4912
4828
|
);
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4829
|
+
}
|
|
4830
|
+
const rawAddress = typeof account === "string" ? account : account.address;
|
|
4831
|
+
const walletAddress = normalizeAddress(rawAddress);
|
|
4832
|
+
if (!walletAddress) {
|
|
4833
|
+
throw new ValidationError(
|
|
4834
|
+
"walletClient account address is required for referral signature auth",
|
|
4835
|
+
"walletClient.account"
|
|
4919
4836
|
);
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4837
|
+
}
|
|
4838
|
+
return { account, walletAddress };
|
|
4839
|
+
}
|
|
4840
|
+
normalizeReferralWalletAddress(address, field) {
|
|
4841
|
+
const normalized = normalizeAddress(address.toLowerCase());
|
|
4842
|
+
if (!normalized) {
|
|
4843
|
+
throw new ValidationError(`${field} must be a valid Ethereum address`, field);
|
|
4844
|
+
}
|
|
4845
|
+
return normalized;
|
|
4846
|
+
}
|
|
4847
|
+
async signCreateReferralCode(opts) {
|
|
4848
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
4849
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
4850
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
4851
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
4852
|
+
account,
|
|
4853
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
4854
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
4855
|
+
primaryType: "CreateCode",
|
|
4856
|
+
message: { wallet: walletAddress, audience, issuedAt: BigInt(issuedAt) }
|
|
4857
|
+
});
|
|
4858
|
+
return { walletAddress, signature, issuedAt, audience };
|
|
4859
|
+
}
|
|
4860
|
+
async signRedeemReferralCode(code, referrerWalletAddress, opts) {
|
|
4861
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
4862
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
4863
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
4864
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
4865
|
+
const referrer = this.normalizeReferralWalletAddress(
|
|
4866
|
+
referrerWalletAddress,
|
|
4867
|
+
"referrerWalletAddress"
|
|
4868
|
+
);
|
|
4869
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
4870
|
+
account,
|
|
4871
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
4872
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
4873
|
+
primaryType: "RedeemCode",
|
|
4874
|
+
message: {
|
|
4875
|
+
wallet: walletAddress,
|
|
4876
|
+
code: normalizedCode,
|
|
4877
|
+
referrer,
|
|
4878
|
+
audience,
|
|
4879
|
+
issuedAt: BigInt(issuedAt)
|
|
4926
4880
|
}
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4881
|
+
});
|
|
4882
|
+
return { walletAddress, signature, issuedAt, audience, referrer };
|
|
4883
|
+
}
|
|
4884
|
+
async signRenameReferralCode(newCode, oldCode, opts) {
|
|
4885
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
4886
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
4887
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
4888
|
+
const normalizedOldCode = normalizeReferralCode(oldCode);
|
|
4889
|
+
const normalizedNewCode = normalizeReferralCode(newCode);
|
|
4890
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
4891
|
+
account,
|
|
4892
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
4893
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
4894
|
+
primaryType: "RenameCode",
|
|
4895
|
+
message: {
|
|
4896
|
+
wallet: walletAddress,
|
|
4897
|
+
oldCode: normalizedOldCode,
|
|
4898
|
+
newCode: normalizedNewCode,
|
|
4899
|
+
audience,
|
|
4900
|
+
issuedAt: BigInt(issuedAt)
|
|
4901
|
+
}
|
|
4902
|
+
});
|
|
4903
|
+
return { walletAddress, signature, issuedAt, audience, oldCode: normalizedOldCode };
|
|
4904
|
+
}
|
|
4905
|
+
};
|
|
4906
|
+
|
|
4907
|
+
// src/client/VaultOperations.ts
|
|
4908
|
+
var VaultOperations = class {
|
|
4909
|
+
constructor(config) {
|
|
4910
|
+
this.config = config;
|
|
4911
|
+
}
|
|
4912
|
+
supportsInlineOracleRateConfig(params) {
|
|
4913
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
4914
|
+
escrowAddress: params?.escrowAddress
|
|
4915
|
+
});
|
|
4916
|
+
return escrowCurrencyHasOracleConfig(escrowContext.abi);
|
|
4917
|
+
}
|
|
4918
|
+
resolveRateManagerRegistryContract(registryAddress) {
|
|
4919
|
+
const abi = this.config.getRateManagerRegistryAbi();
|
|
4920
|
+
if (!abi) {
|
|
4921
|
+
throw this.buildRateManagerUnavailableError("Rate manager registry not available");
|
|
4922
|
+
}
|
|
4923
|
+
if (registryAddress) {
|
|
4924
|
+
return {
|
|
4925
|
+
address: registryAddress,
|
|
4926
|
+
abi
|
|
4927
|
+
};
|
|
4928
|
+
}
|
|
4929
|
+
const address = this.config.getRateManagerRegistryAddress();
|
|
4930
|
+
if (!address) {
|
|
4931
|
+
throw this.buildRateManagerUnavailableError("Rate manager registry not available");
|
|
4947
4932
|
}
|
|
4948
|
-
if (!managerRaw) return null;
|
|
4949
|
-
const manager = normalizeRateManagerEntity(managerRaw);
|
|
4950
4933
|
return {
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
aggregate,
|
|
4954
|
-
recentStats: scopedRecentStats,
|
|
4955
|
-
delegations: scopedDelegations
|
|
4934
|
+
address,
|
|
4935
|
+
abi
|
|
4956
4936
|
};
|
|
4957
4937
|
}
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4938
|
+
buildRateManagerUnavailableError(reason) {
|
|
4939
|
+
const initError = this.config.getRateManagerInitError();
|
|
4940
|
+
if (!initError) {
|
|
4941
|
+
return new Error(reason);
|
|
4942
|
+
}
|
|
4943
|
+
return new Error(
|
|
4944
|
+
`${reason}. Rate manager contracts failed to initialize: ${initError.message}`
|
|
4945
|
+
);
|
|
4946
|
+
}
|
|
4947
|
+
buildCreateRateManagerConfig(config) {
|
|
4948
|
+
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
4949
|
+
const includeDepositHook = abiTupleHasComponent(
|
|
4950
|
+
registryAbi,
|
|
4951
|
+
"createRateManager",
|
|
4952
|
+
"depositHook"
|
|
4953
|
+
);
|
|
4954
|
+
const includeMinLiquidity = abiTupleHasComponent(
|
|
4955
|
+
registryAbi,
|
|
4956
|
+
"createRateManager",
|
|
4957
|
+
"minLiquidity"
|
|
4958
|
+
);
|
|
4959
|
+
const result = {
|
|
4960
|
+
manager: config.manager,
|
|
4961
|
+
feeRecipient: config.feeRecipient,
|
|
4962
|
+
maxFee: config.maxFee,
|
|
4963
|
+
fee: config.fee
|
|
4970
4964
|
};
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4965
|
+
if (includeDepositHook) {
|
|
4966
|
+
result.depositHook = config.depositHook ?? ZERO_ADDRESS;
|
|
4967
|
+
}
|
|
4968
|
+
if (includeMinLiquidity) {
|
|
4969
|
+
result.minLiquidity = config.minLiquidity ?? 0n;
|
|
4970
|
+
}
|
|
4971
|
+
result.name = config.name;
|
|
4972
|
+
result.uri = config.uri;
|
|
4973
|
+
return result;
|
|
4974
|
+
}
|
|
4975
|
+
buildSetRateManagerConfigArgs(params) {
|
|
4976
|
+
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
4977
|
+
const includeHook = abiFunctionHasInput(registryAbi, "setRateManagerConfig", "_newHook") || abiFunctionHasInput(registryAbi, "setRateManagerConfig", "newHook");
|
|
4978
|
+
if (includeHook) {
|
|
4979
|
+
return [
|
|
4980
|
+
params.rateManagerId,
|
|
4981
|
+
params.newManager,
|
|
4982
|
+
params.newFeeRecipient,
|
|
4983
|
+
params.newHook ?? ZERO_ADDRESS,
|
|
4984
|
+
params.newName,
|
|
4985
|
+
params.newUri
|
|
4986
|
+
];
|
|
4987
|
+
}
|
|
4988
|
+
return [
|
|
4989
|
+
params.rateManagerId,
|
|
4990
|
+
params.newManager,
|
|
4991
|
+
params.newFeeRecipient,
|
|
4992
|
+
params.newName,
|
|
4993
|
+
params.newUri
|
|
4994
|
+
];
|
|
4995
|
+
}
|
|
4996
|
+
prepareRateManagerRegistryTransaction(opts) {
|
|
4997
|
+
const contract = this.resolveRateManagerRegistryContract(opts.registry);
|
|
4998
|
+
const functionName = resolveAbiFunctionName(contract.abi, opts.functionNames);
|
|
4999
|
+
return this.config.host.prepareContractTransaction({
|
|
5000
|
+
address: contract.address,
|
|
5001
|
+
abi: contract.abi,
|
|
5002
|
+
functionName,
|
|
5003
|
+
args: opts.args,
|
|
5004
|
+
txOverrides: opts.txOverrides
|
|
5005
|
+
});
|
|
5006
|
+
}
|
|
5007
|
+
prepareCreateRateManagerTransaction(params) {
|
|
5008
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
5009
|
+
functionNames: ["createRateManager"],
|
|
5010
|
+
args: [this.buildCreateRateManagerConfig(params.config)],
|
|
5011
|
+
txOverrides: params.txOverrides
|
|
5012
|
+
});
|
|
5013
|
+
}
|
|
5014
|
+
prepareSetVaultRateTransaction(params) {
|
|
5015
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
5016
|
+
functionNames: ["setRate", "setMinRate"],
|
|
5017
|
+
args: [params.rateManagerId, params.paymentMethodHash, params.currencyHash, params.rate],
|
|
5018
|
+
txOverrides: params.txOverrides
|
|
5019
|
+
});
|
|
5020
|
+
}
|
|
5021
|
+
prepareSetVaultRatesBatchTransaction(params) {
|
|
5022
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
5023
|
+
functionNames: ["setRateBatch", "setMinRatesBatch"],
|
|
5024
|
+
args: [params.rateManagerId, params.paymentMethods, params.currencies, params.rates],
|
|
5025
|
+
txOverrides: params.txOverrides
|
|
5026
|
+
});
|
|
5027
|
+
}
|
|
5028
|
+
prepareSetOracleRateConfigTransaction(params) {
|
|
5029
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5030
|
+
escrowAddress: params.escrowAddress,
|
|
5031
|
+
depositId: params.depositId
|
|
5032
|
+
});
|
|
5033
|
+
if (escrowContext.version !== "v2") {
|
|
5034
|
+
throw new Error("setOracleRateConfig requires EscrowV2");
|
|
5035
|
+
}
|
|
5036
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfig"]);
|
|
5037
|
+
return this.config.host.prepareEscrowTransaction({
|
|
5038
|
+
functionName,
|
|
5039
|
+
args: [
|
|
5040
|
+
parseRawDepositId(params.depositId),
|
|
5041
|
+
params.paymentMethodHash,
|
|
5042
|
+
params.currencyHash,
|
|
5043
|
+
normalizeOracleRateConfig(params.config)
|
|
5044
|
+
],
|
|
5045
|
+
txOverrides: params.txOverrides,
|
|
5046
|
+
escrowAddress: escrowContext.address,
|
|
5047
|
+
escrowAbi: escrowContext.abi
|
|
5048
|
+
});
|
|
5049
|
+
}
|
|
5050
|
+
prepareRemoveOracleRateConfigTransaction(params) {
|
|
5051
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5052
|
+
escrowAddress: params.escrowAddress,
|
|
5053
|
+
depositId: params.depositId
|
|
5054
|
+
});
|
|
5055
|
+
if (escrowContext.version !== "v2") {
|
|
5056
|
+
throw new Error("removeOracleRateConfig requires EscrowV2");
|
|
4989
5057
|
}
|
|
5058
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["removeOracleRateConfig"]);
|
|
5059
|
+
return this.config.host.prepareEscrowTransaction({
|
|
5060
|
+
functionName,
|
|
5061
|
+
args: [parseRawDepositId(params.depositId), params.paymentMethodHash, params.currencyHash],
|
|
5062
|
+
txOverrides: params.txOverrides,
|
|
5063
|
+
escrowAddress: escrowContext.address,
|
|
5064
|
+
escrowAbi: escrowContext.abi
|
|
5065
|
+
});
|
|
4990
5066
|
}
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
variables: {
|
|
4999
|
-
where: {
|
|
5000
|
-
rateManagerId: { _eq: normalizedId },
|
|
5001
|
-
...normalizedRateManagerAddress ? {
|
|
5002
|
-
id: {
|
|
5003
|
-
_ilike: buildRateManagerScopedIdPattern(
|
|
5004
|
-
normalizedId,
|
|
5005
|
-
normalizedRateManagerAddress
|
|
5006
|
-
)
|
|
5007
|
-
}
|
|
5008
|
-
} : {}
|
|
5009
|
-
},
|
|
5010
|
-
order_by: [{ dayTimestamp: "asc" }],
|
|
5011
|
-
limit: options?.limit ?? 365
|
|
5012
|
-
}
|
|
5013
|
-
});
|
|
5014
|
-
return result.ManagerDailySnapshot ?? [];
|
|
5015
|
-
} catch (error) {
|
|
5016
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
5017
|
-
throw error;
|
|
5018
|
-
}
|
|
5019
|
-
return [];
|
|
5067
|
+
prepareSetOracleRateConfigBatchTransaction(params) {
|
|
5068
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5069
|
+
escrowAddress: params.escrowAddress,
|
|
5070
|
+
depositId: params.depositId
|
|
5071
|
+
});
|
|
5072
|
+
if (escrowContext.version !== "v2") {
|
|
5073
|
+
throw new Error("setOracleRateConfigBatch requires EscrowV2");
|
|
5020
5074
|
}
|
|
5075
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfigBatch"]);
|
|
5076
|
+
return this.config.host.prepareEscrowTransaction({
|
|
5077
|
+
functionName,
|
|
5078
|
+
args: [
|
|
5079
|
+
parseRawDepositId(params.depositId),
|
|
5080
|
+
params.paymentMethods,
|
|
5081
|
+
params.currencies,
|
|
5082
|
+
params.configs.map((group) => group.map((config) => normalizeOracleRateConfig(config)))
|
|
5083
|
+
],
|
|
5084
|
+
txOverrides: params.txOverrides,
|
|
5085
|
+
escrowAddress: escrowContext.address,
|
|
5086
|
+
escrowAbi: escrowContext.abi
|
|
5087
|
+
});
|
|
5021
5088
|
}
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
depositId: normalizedDepositId
|
|
5030
|
-
}
|
|
5031
|
-
});
|
|
5032
|
-
const delegationDeposit = result.Deposit?.[0];
|
|
5033
|
-
if (!delegationDeposit) {
|
|
5034
|
-
return null;
|
|
5035
|
-
}
|
|
5036
|
-
return toDelegationEntityFromDeposit(delegationDeposit) ?? null;
|
|
5037
|
-
} catch (error) {
|
|
5038
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
5039
|
-
throw error;
|
|
5040
|
-
}
|
|
5041
|
-
const legacyResult = await this.client.query({
|
|
5042
|
-
query: LEGACY_DEPOSIT_DELEGATION_QUERY,
|
|
5043
|
-
variables: {
|
|
5044
|
-
depositId: normalizedDepositId
|
|
5045
|
-
}
|
|
5046
|
-
});
|
|
5047
|
-
return legacyResult.RateManagerDelegation?.[0] ?? null;
|
|
5089
|
+
prepareUpdateCurrencyConfigBatchTransaction(params) {
|
|
5090
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5091
|
+
escrowAddress: params.escrowAddress,
|
|
5092
|
+
depositId: params.depositId
|
|
5093
|
+
});
|
|
5094
|
+
if (escrowContext.version !== "v2") {
|
|
5095
|
+
throw new Error("updateCurrencyConfigBatch requires EscrowV2");
|
|
5048
5096
|
}
|
|
5097
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["updateCurrencyConfigBatch"]);
|
|
5098
|
+
return this.config.host.prepareEscrowTransaction({
|
|
5099
|
+
functionName,
|
|
5100
|
+
args: [
|
|
5101
|
+
parseRawDepositId(params.depositId),
|
|
5102
|
+
params.paymentMethods,
|
|
5103
|
+
params.updates.map(
|
|
5104
|
+
(group) => group.map((update) => ({
|
|
5105
|
+
code: update.code,
|
|
5106
|
+
minConversionRate: typeof update.minConversionRate === "bigint" ? update.minConversionRate : BigInt(update.minConversionRate),
|
|
5107
|
+
updateOracle: update.updateOracle,
|
|
5108
|
+
oracleRateConfig: normalizeOracleRateConfig(update.oracleRateConfig)
|
|
5109
|
+
}))
|
|
5110
|
+
)
|
|
5111
|
+
],
|
|
5112
|
+
txOverrides: params.txOverrides,
|
|
5113
|
+
escrowAddress: escrowContext.address,
|
|
5114
|
+
escrowAbi: escrowContext.abi
|
|
5115
|
+
});
|
|
5049
5116
|
}
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
where: {
|
|
5058
|
-
rateManagerId: { _eq: normalizedId }
|
|
5059
|
-
},
|
|
5060
|
-
order_by: [{ id: "desc" }],
|
|
5061
|
-
limit: options?.limit ?? 100
|
|
5062
|
-
}
|
|
5063
|
-
});
|
|
5064
|
-
return (result.RateManagerV1_RateManagerRateUpdated ?? []).map((e) => ({
|
|
5065
|
-
...e,
|
|
5066
|
-
currency: e.currency ?? e.currencyCode ?? "",
|
|
5067
|
-
minRate: e.minRate ?? e.rate ?? "0"
|
|
5068
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5069
|
-
} catch (error) {
|
|
5070
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
5071
|
-
throw error;
|
|
5072
|
-
}
|
|
5073
|
-
return [];
|
|
5117
|
+
prepareDeactivateCurrenciesBatchTransaction(params) {
|
|
5118
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5119
|
+
escrowAddress: params.escrowAddress,
|
|
5120
|
+
depositId: params.depositId
|
|
5121
|
+
});
|
|
5122
|
+
if (escrowContext.version !== "v2") {
|
|
5123
|
+
throw new Error("deactivateCurrenciesBatch requires EscrowV2");
|
|
5074
5124
|
}
|
|
5125
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["deactivateCurrenciesBatch"]);
|
|
5126
|
+
return this.config.host.prepareEscrowTransaction({
|
|
5127
|
+
functionName,
|
|
5128
|
+
args: [parseRawDepositId(params.depositId), params.paymentMethods, params.currencyCodes],
|
|
5129
|
+
txOverrides: params.txOverrides,
|
|
5130
|
+
escrowAddress: escrowContext.address,
|
|
5131
|
+
escrowAbi: escrowContext.abi
|
|
5132
|
+
});
|
|
5075
5133
|
}
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
const result = await this.
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
_and: [
|
|
5096
|
-
{ depositId: { _eq: scope.depositIdOnContract } },
|
|
5097
|
-
{ escrow: { _eq: scope.escrow } }
|
|
5098
|
-
]
|
|
5099
|
-
}))
|
|
5100
|
-
},
|
|
5101
|
-
order_by: [{ id: "desc" }],
|
|
5102
|
-
limit
|
|
5103
|
-
}
|
|
5134
|
+
prepareSetVaultConfigTransaction(params) {
|
|
5135
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
5136
|
+
functionNames: ["setRateManagerConfig"],
|
|
5137
|
+
args: this.buildSetRateManagerConfigArgs(params),
|
|
5138
|
+
txOverrides: params.txOverrides
|
|
5139
|
+
});
|
|
5140
|
+
}
|
|
5141
|
+
async getDepositRateManager(escrow, depositId) {
|
|
5142
|
+
const id = parseRawDepositId(depositId);
|
|
5143
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5144
|
+
escrowAddress: escrow,
|
|
5145
|
+
depositId
|
|
5146
|
+
});
|
|
5147
|
+
if (getRateManagerReadFunction(escrowContext.abi, "getDepositRateManager")) {
|
|
5148
|
+
const result = await this.config.getPublicClient().readContract({
|
|
5149
|
+
address: escrowContext.address,
|
|
5150
|
+
abi: escrowContext.abi,
|
|
5151
|
+
functionName: "getDepositRateManager",
|
|
5152
|
+
args: [id]
|
|
5104
5153
|
});
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
buildDepositScopeKey({
|
|
5111
|
-
escrow,
|
|
5112
|
-
depositIdOnContract
|
|
5113
|
-
})
|
|
5114
|
-
);
|
|
5115
|
-
}).map((e) => ({
|
|
5116
|
-
...e,
|
|
5117
|
-
rateManagerId: normalizedId,
|
|
5118
|
-
escrow: normalizeAddress3(e.escrow) || void 0,
|
|
5119
|
-
currency: e.currency ?? e.currencyCode ?? "",
|
|
5120
|
-
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
5121
|
-
adapter: e.adapter ?? "",
|
|
5122
|
-
spreadBps: e.spreadBps ?? 0
|
|
5123
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5124
|
-
} catch (error) {
|
|
5125
|
-
if (isSchemaCompatibilityError(error)) ; else {
|
|
5126
|
-
throw error;
|
|
5154
|
+
if (result && result.length >= 2) {
|
|
5155
|
+
return {
|
|
5156
|
+
registry: result[0],
|
|
5157
|
+
rateManagerId: result[1]
|
|
5158
|
+
};
|
|
5127
5159
|
}
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5160
|
+
}
|
|
5161
|
+
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
5162
|
+
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
5163
|
+
if (!controllerAddress || !controllerAbi) {
|
|
5164
|
+
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
5165
|
+
}
|
|
5166
|
+
const legacyResult = await this.config.getPublicClient().readContract({
|
|
5167
|
+
address: controllerAddress,
|
|
5168
|
+
abi: controllerAbi,
|
|
5169
|
+
functionName: "getDepositRateManager",
|
|
5170
|
+
args: [escrow, id]
|
|
5171
|
+
});
|
|
5172
|
+
return {
|
|
5173
|
+
registry: legacyResult[0],
|
|
5174
|
+
rateManagerId: legacyResult[1]
|
|
5175
|
+
};
|
|
5176
|
+
}
|
|
5177
|
+
async getManagerFee(escrow, depositId) {
|
|
5178
|
+
const id = parseRawDepositId(depositId);
|
|
5179
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5180
|
+
escrowAddress: escrow,
|
|
5181
|
+
depositId
|
|
5182
|
+
});
|
|
5183
|
+
if (getRateManagerReadFunction(escrowContext.abi, "getManagerFee")) {
|
|
5184
|
+
const result2 = await this.config.getPublicClient().readContract({
|
|
5185
|
+
address: escrowContext.address,
|
|
5186
|
+
abi: escrowContext.abi,
|
|
5187
|
+
functionName: "getManagerFee",
|
|
5188
|
+
args: [id]
|
|
5137
5189
|
});
|
|
5138
|
-
return (
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5190
|
+
return parseManagerFeeFromRead(result2);
|
|
5191
|
+
}
|
|
5192
|
+
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
5193
|
+
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
5194
|
+
if (!controllerAddress || !controllerAbi) {
|
|
5195
|
+
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
5145
5196
|
}
|
|
5197
|
+
const result = await this.config.getPublicClient().readContract({
|
|
5198
|
+
address: controllerAddress,
|
|
5199
|
+
abi: controllerAbi,
|
|
5200
|
+
functionName: "getManagerFee",
|
|
5201
|
+
args: [escrow, id]
|
|
5202
|
+
});
|
|
5203
|
+
return parseManagerFeeFromRead(result);
|
|
5204
|
+
}
|
|
5205
|
+
async getEffectiveRate(params) {
|
|
5206
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
5207
|
+
escrowAddress: params.escrow,
|
|
5208
|
+
depositId: params.depositId
|
|
5209
|
+
});
|
|
5210
|
+
const id = parseRawDepositId(params.depositId);
|
|
5211
|
+
return await this.config.getPublicClient().readContract({
|
|
5212
|
+
address: escrowContext.address,
|
|
5213
|
+
abi: escrowContext.abi,
|
|
5214
|
+
functionName: "getEffectiveRate",
|
|
5215
|
+
args: [id, params.paymentMethod, params.fiatCurrency]
|
|
5216
|
+
});
|
|
5146
5217
|
}
|
|
5147
5218
|
};
|
|
5219
|
+
var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && abi.some(
|
|
5220
|
+
(item) => item.type === "function" && item.name === functionName
|
|
5221
|
+
);
|
|
5148
5222
|
|
|
5149
|
-
// src/indexer/
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5223
|
+
// src/indexer/rateManagerService.ts
|
|
5224
|
+
var DEFAULT_LIMIT2 = 50;
|
|
5225
|
+
var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
|
|
5226
|
+
var EVM_ADDRESS_REGEX = /^0x[a-f0-9]{40}$/;
|
|
5227
|
+
function normalizeRateManagerId2(value) {
|
|
5228
|
+
if (!value) return "";
|
|
5229
|
+
return value.toLowerCase();
|
|
5155
5230
|
}
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
function setLogLevel(level) {
|
|
5160
|
-
currentLevel = level;
|
|
5231
|
+
function normalizeAddress3(value) {
|
|
5232
|
+
if (!value) return "";
|
|
5233
|
+
return value.toLowerCase();
|
|
5161
5234
|
}
|
|
5162
|
-
function
|
|
5163
|
-
|
|
5164
|
-
case "debug":
|
|
5165
|
-
return true;
|
|
5166
|
-
case "info":
|
|
5167
|
-
return level !== "debug";
|
|
5168
|
-
case "error":
|
|
5169
|
-
return level === "error";
|
|
5170
|
-
default:
|
|
5171
|
-
return true;
|
|
5172
|
-
}
|
|
5235
|
+
function escapeLikePatternLiteral(value) {
|
|
5236
|
+
return value.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
5173
5237
|
}
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
}
|
|
5184
|
-
},
|
|
5185
|
-
warn: (...args) => {
|
|
5186
|
-
if (shouldLog("info")) {
|
|
5187
|
-
console.warn("[WARN]", ...args);
|
|
5188
|
-
}
|
|
5189
|
-
},
|
|
5190
|
-
error: (...args) => {
|
|
5191
|
-
console.error("[ERROR]", ...args);
|
|
5192
|
-
}
|
|
5193
|
-
};
|
|
5194
|
-
|
|
5195
|
-
// src/referral.ts
|
|
5196
|
-
var normalizeReferralCode = (code) => code.trim().toUpperCase();
|
|
5197
|
-
var isValidReferralCode = (code) => /^[A-Z0-9]{6}$/.test(normalizeReferralCode(code));
|
|
5198
|
-
|
|
5199
|
-
// src/adapters/api.ts
|
|
5200
|
-
function createHeaders(apiKey, authorizationToken) {
|
|
5201
|
-
const headers2 = { "Content-Type": "application/json" };
|
|
5202
|
-
if (apiKey) headers2["x-api-key"] = apiKey;
|
|
5203
|
-
if (authorizationToken) {
|
|
5204
|
-
headers2.Authorization = authorizationToken.startsWith("Bearer ") ? authorizationToken : `Bearer ${authorizationToken}`;
|
|
5238
|
+
function parseScopedRateManagerFilterId(value) {
|
|
5239
|
+
const trimmed = value.trim().toLowerCase();
|
|
5240
|
+
if (!trimmed) return null;
|
|
5241
|
+
const separatorIndex = trimmed.indexOf(":");
|
|
5242
|
+
if (separatorIndex <= 0) return null;
|
|
5243
|
+
const rateManagerAddress = normalizeAddress3(trimmed.slice(0, separatorIndex));
|
|
5244
|
+
const rateManagerId = normalizeRateManagerId2(trimmed.slice(separatorIndex + 1));
|
|
5245
|
+
if (!EVM_ADDRESS_REGEX.test(rateManagerAddress) || !rateManagerId) {
|
|
5246
|
+
return null;
|
|
5205
5247
|
}
|
|
5206
|
-
return
|
|
5248
|
+
return { rateManagerAddress, rateManagerId };
|
|
5207
5249
|
}
|
|
5208
|
-
function
|
|
5209
|
-
const
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
base2 = base2.replace(/\/v2$/i, "");
|
|
5213
|
-
return base2;
|
|
5250
|
+
function getManagerScopeKey(rateManagerId, rateManagerAddress) {
|
|
5251
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5252
|
+
const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
|
|
5253
|
+
return normalizedRateManagerAddress ? `${normalizedRateManagerAddress}:${normalizedId}` : normalizedId;
|
|
5214
5254
|
}
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
return withRetry(
|
|
5227
|
-
async () => {
|
|
5228
|
-
let res;
|
|
5229
|
-
try {
|
|
5230
|
-
const options = {
|
|
5231
|
-
method,
|
|
5232
|
-
headers: createHeaders(apiKey, authorizationToken)
|
|
5233
|
-
};
|
|
5234
|
-
if (body && method !== "GET") {
|
|
5235
|
-
options.body = JSON.stringify(body);
|
|
5236
|
-
}
|
|
5237
|
-
res = await fetch(url, options);
|
|
5238
|
-
} catch (error) {
|
|
5239
|
-
throw new NetworkError("Failed to connect to API server", { endpoint, error });
|
|
5240
|
-
}
|
|
5241
|
-
if (!res.ok) {
|
|
5242
|
-
const errorText = await res.text();
|
|
5243
|
-
throw parseAPIError(res, errorText);
|
|
5244
|
-
}
|
|
5245
|
-
return res.json();
|
|
5246
|
-
},
|
|
5247
|
-
retryCount,
|
|
5248
|
-
retryDelayMs,
|
|
5249
|
-
timeoutMs
|
|
5255
|
+
function extractRateManagerAddressFromScopedId(id) {
|
|
5256
|
+
if (!id) return null;
|
|
5257
|
+
const parts = id.split("_");
|
|
5258
|
+
if (parts.length < 3) return null;
|
|
5259
|
+
const rateManagerAddress = parts[1] ?? "";
|
|
5260
|
+
return rateManagerAddress.startsWith("0x") ? rateManagerAddress.toLowerCase() : null;
|
|
5261
|
+
}
|
|
5262
|
+
function buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress) {
|
|
5263
|
+
const normalizedId = escapeLikePatternLiteral(normalizeRateManagerId2(rateManagerId));
|
|
5264
|
+
const normalizedRateManagerAddress = escapeLikePatternLiteral(
|
|
5265
|
+
normalizeAddress3(rateManagerAddress)
|
|
5250
5266
|
);
|
|
5267
|
+
return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
|
|
5251
5268
|
}
|
|
5252
|
-
function
|
|
5253
|
-
|
|
5254
|
-
return payload.responseObject;
|
|
5255
|
-
}
|
|
5256
|
-
return payload;
|
|
5269
|
+
function buildRateManagerScopedIdPattern(rateManagerId, rateManagerAddress) {
|
|
5270
|
+
return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}\\_%`;
|
|
5257
5271
|
}
|
|
5258
|
-
function
|
|
5259
|
-
|
|
5260
|
-
|
|
5272
|
+
function normalizeCompositeDepositId(depositId, escrowAddress) {
|
|
5273
|
+
const normalizedDepositId = depositId.trim().toLowerCase();
|
|
5274
|
+
if (!normalizedDepositId) return "";
|
|
5275
|
+
if (normalizedDepositId.includes("_")) return normalizedDepositId;
|
|
5276
|
+
const normalizedEscrow = normalizeAddress3(escrowAddress);
|
|
5277
|
+
if (normalizedEscrow) {
|
|
5278
|
+
return `${normalizedEscrow}_${normalizedDepositId}`;
|
|
5261
5279
|
}
|
|
5262
|
-
return
|
|
5280
|
+
return normalizedDepositId;
|
|
5263
5281
|
}
|
|
5264
|
-
function
|
|
5265
|
-
if (!
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
return
|
|
5282
|
+
function extractDepositIdOnContract(compositeDepositId) {
|
|
5283
|
+
if (!compositeDepositId) return null;
|
|
5284
|
+
const parts = compositeDepositId.split("_");
|
|
5285
|
+
const rawDepositId = parts[parts.length - 1];
|
|
5286
|
+
return rawDepositId && /^\d+$/.test(rawDepositId) ? rawDepositId : null;
|
|
5269
5287
|
}
|
|
5270
|
-
function
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
}
|
|
5275
|
-
if (normalized.includes("staging") || normalized.includes("/staging/") || normalized.includes("localhost") || normalized.includes("127.0.0.1")) {
|
|
5276
|
-
return "STAGING";
|
|
5277
|
-
}
|
|
5278
|
-
return "PRODUCTION";
|
|
5288
|
+
function extractEscrowAddressFromCompositeDepositId(compositeDepositId) {
|
|
5289
|
+
if (!compositeDepositId) return null;
|
|
5290
|
+
const [escrowAddress] = compositeDepositId.split("_");
|
|
5291
|
+
return escrowAddress?.startsWith("0x") ? escrowAddress.toLowerCase() : null;
|
|
5279
5292
|
}
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5293
|
+
function parseRateManagerFilterIds(rateManagerIds) {
|
|
5294
|
+
const bare = /* @__PURE__ */ new Set();
|
|
5295
|
+
const scoped = /* @__PURE__ */ new Map();
|
|
5296
|
+
for (const value of rateManagerIds) {
|
|
5297
|
+
const scopedRateManager = parseScopedRateManagerFilterId(value);
|
|
5298
|
+
if (scopedRateManager) {
|
|
5299
|
+
scoped.set(
|
|
5300
|
+
getManagerScopeKey(scopedRateManager.rateManagerId, scopedRateManager.rateManagerAddress),
|
|
5301
|
+
scopedRateManager
|
|
5302
|
+
);
|
|
5303
|
+
continue;
|
|
5304
|
+
}
|
|
5305
|
+
if (value.includes(":")) {
|
|
5306
|
+
continue;
|
|
5307
|
+
}
|
|
5308
|
+
const normalizedRateManagerId = normalizeRateManagerId2(value);
|
|
5309
|
+
if (normalizedRateManagerId) {
|
|
5310
|
+
bare.add(normalizedRateManagerId);
|
|
5311
|
+
}
|
|
5294
5312
|
}
|
|
5313
|
+
return { bare, scoped };
|
|
5295
5314
|
}
|
|
5296
|
-
function
|
|
5297
|
-
|
|
5298
|
-
const numeric = Number(value);
|
|
5299
|
-
if (!Number.isFinite(numeric) || numeric <= 0) return void 0;
|
|
5300
|
-
return new Date(numeric * 1e3);
|
|
5315
|
+
function buildDepositScopeKey(scope) {
|
|
5316
|
+
return `${scope.escrow}:${scope.depositIdOnContract}`;
|
|
5301
5317
|
}
|
|
5302
|
-
function
|
|
5303
|
-
if (value
|
|
5318
|
+
function toSafeBigInt(value) {
|
|
5319
|
+
if (!value) return 0n;
|
|
5304
5320
|
try {
|
|
5305
|
-
return
|
|
5321
|
+
return parseBigIntLike(value);
|
|
5306
5322
|
} catch {
|
|
5307
5323
|
return 0n;
|
|
5308
5324
|
}
|
|
5309
5325
|
}
|
|
5310
|
-
function
|
|
5311
|
-
if (
|
|
5312
|
-
if (
|
|
5313
|
-
return
|
|
5326
|
+
function compareBigInt(a, b, direction) {
|
|
5327
|
+
if (a === b) return 0;
|
|
5328
|
+
if (direction === "asc") return a < b ? -1 : 1;
|
|
5329
|
+
return a > b ? -1 : 1;
|
|
5314
5330
|
}
|
|
5315
|
-
function
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5331
|
+
function parseEventCursorId(id) {
|
|
5332
|
+
if (!id) return null;
|
|
5333
|
+
const [chainIdRaw, blockNumberRaw, logIndexRaw] = id.split("_");
|
|
5334
|
+
if (!chainIdRaw || !blockNumberRaw || !logIndexRaw) return null;
|
|
5335
|
+
if (!/^\d+$/.test(chainIdRaw) || !/^\d+$/.test(blockNumberRaw) || !/^\d+$/.test(logIndexRaw)) {
|
|
5336
|
+
return null;
|
|
5337
|
+
}
|
|
5338
|
+
try {
|
|
5339
|
+
return {
|
|
5340
|
+
chainId: BigInt(chainIdRaw),
|
|
5341
|
+
blockNumber: BigInt(blockNumberRaw),
|
|
5342
|
+
logIndex: BigInt(logIndexRaw)
|
|
5343
|
+
};
|
|
5344
|
+
} catch {
|
|
5345
|
+
return null;
|
|
5346
|
+
}
|
|
5347
|
+
}
|
|
5348
|
+
function compareEventCursorIdsByRecency(leftId, rightId) {
|
|
5349
|
+
const left = parseEventCursorId(leftId);
|
|
5350
|
+
const right = parseEventCursorId(rightId);
|
|
5351
|
+
if (left && right) {
|
|
5352
|
+
if (left.chainId !== right.chainId) {
|
|
5353
|
+
return left.chainId > right.chainId ? -1 : 1;
|
|
5325
5354
|
}
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
});
|
|
5334
|
-
currenciesByMethod.set(methodHash, bucket);
|
|
5355
|
+
if (left.blockNumber !== right.blockNumber) {
|
|
5356
|
+
return left.blockNumber > right.blockNumber ? -1 : 1;
|
|
5357
|
+
}
|
|
5358
|
+
if (left.logIndex !== right.logIndex) {
|
|
5359
|
+
return left.logIndex > right.logIndex ? -1 : 1;
|
|
5360
|
+
}
|
|
5361
|
+
return 0;
|
|
5335
5362
|
}
|
|
5336
|
-
return
|
|
5363
|
+
return (rightId ?? "").localeCompare(leftId ?? "");
|
|
5337
5364
|
}
|
|
5338
|
-
function
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
verifier: "",
|
|
5343
|
-
methodHash: paymentMethod.paymentMethodHash,
|
|
5344
|
-
intentGatingService: paymentMethod.intentGatingService,
|
|
5345
|
-
payeeDetailsHash: paymentMethod.payeeDetailsHash,
|
|
5346
|
-
data: "0x",
|
|
5347
|
-
currencies: currenciesByMethod.get(paymentMethod.paymentMethodHash) ?? []
|
|
5348
|
-
}));
|
|
5349
|
-
const remainingDeposits = toBigIntSafe(deposit.remainingDeposits);
|
|
5350
|
-
const outstandingIntentAmount = toBigIntSafe(deposit.outstandingIntentAmount);
|
|
5351
|
-
const totalAmountTaken = toBigIntSafe(deposit.totalAmountTaken);
|
|
5352
|
-
const totalWithdrawn = toBigIntSafe(deposit.totalWithdrawn);
|
|
5353
|
-
const amount = remainingDeposits + outstandingIntentAmount + totalAmountTaken + totalWithdrawn;
|
|
5365
|
+
function isAggregateOrderField(field) {
|
|
5366
|
+
return field === "currentDelegatedBalance" || field === "totalFilledVolume";
|
|
5367
|
+
}
|
|
5368
|
+
function normalizeRateManagerEntity(manager) {
|
|
5354
5369
|
return {
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
token: deposit.token,
|
|
5358
|
-
amount: amount.toString(),
|
|
5359
|
-
remainingDeposits: deposit.remainingDeposits,
|
|
5360
|
-
intentAmountMin: deposit.intentAmountMin,
|
|
5361
|
-
intentAmountMax: deposit.intentAmountMax,
|
|
5362
|
-
acceptingIntents: deposit.acceptingIntents,
|
|
5363
|
-
outstandingIntentAmount: deposit.outstandingIntentAmount,
|
|
5364
|
-
availableLiquidity: deposit.remainingDeposits,
|
|
5365
|
-
status: deposit.status,
|
|
5366
|
-
totalIntents: deposit.totalIntents,
|
|
5367
|
-
signaledIntents: deposit.signaledIntents,
|
|
5368
|
-
fulfilledIntents: deposit.fulfilledIntents,
|
|
5369
|
-
prunedIntents: deposit.prunedIntents,
|
|
5370
|
-
totalAmountTaken: deposit.totalAmountTaken,
|
|
5371
|
-
totalWithdrawn: deposit.totalWithdrawn,
|
|
5372
|
-
successRateBps: deposit.successRateBps,
|
|
5373
|
-
rateManagerId: deposit.rateManagerId ?? null,
|
|
5374
|
-
vaultName: null,
|
|
5375
|
-
rateManagerRegistry: null,
|
|
5376
|
-
createdAt: toDateFromUnixSeconds(deposit.timestamp),
|
|
5377
|
-
updatedAt: toDateFromUnixSeconds(deposit.updatedAt),
|
|
5378
|
-
verifiers
|
|
5370
|
+
...manager,
|
|
5371
|
+
rateManagerAddress: normalizeAddress3(manager.rateManagerAddress)
|
|
5379
5372
|
};
|
|
5380
5373
|
}
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5374
|
+
function toDelegationEntityFromDeposit(deposit) {
|
|
5375
|
+
const rateManagerId = normalizeRateManagerId2(deposit.rateManagerId);
|
|
5376
|
+
if (!rateManagerId) return null;
|
|
5377
|
+
const delegatedAt = deposit.delegatedAt ?? null;
|
|
5378
|
+
return {
|
|
5379
|
+
id: deposit.id,
|
|
5380
|
+
chainId: deposit.chainId,
|
|
5381
|
+
rateManagerId,
|
|
5382
|
+
rateManagerAddress: normalizeAddress3(deposit.rateManagerAddress) || null,
|
|
5383
|
+
depositId: deposit.id,
|
|
5384
|
+
delegatedAt,
|
|
5385
|
+
createdAt: delegatedAt ?? deposit.updatedAt,
|
|
5386
|
+
updatedAt: deposit.updatedAt
|
|
5387
|
+
};
|
|
5388
5388
|
}
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5389
|
+
var IndexerRateManagerService = class {
|
|
5390
|
+
constructor(client) {
|
|
5391
|
+
this.client = client;
|
|
5392
|
+
}
|
|
5393
|
+
buildRateManagerScopeWhere(rateManagerIds) {
|
|
5394
|
+
if (!rateManagerIds?.length) return void 0;
|
|
5395
|
+
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
5396
|
+
const scopeConditions = [];
|
|
5397
|
+
if (bare.size > 0) {
|
|
5398
|
+
scopeConditions.push({
|
|
5399
|
+
rateManagerId: { _in: [...bare] }
|
|
5400
|
+
});
|
|
5401
|
+
}
|
|
5402
|
+
for (const scopedRateManager of scoped.values()) {
|
|
5403
|
+
scopeConditions.push({
|
|
5404
|
+
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
5405
|
+
rateManagerAddress: { _eq: scopedRateManager.rateManagerAddress }
|
|
5406
|
+
});
|
|
5407
|
+
}
|
|
5408
|
+
if (scopeConditions.length === 1) {
|
|
5409
|
+
return scopeConditions[0];
|
|
5410
|
+
}
|
|
5411
|
+
if (scopeConditions.length > 1) {
|
|
5412
|
+
return { _or: scopeConditions };
|
|
5413
|
+
}
|
|
5414
|
+
return void 0;
|
|
5415
|
+
}
|
|
5416
|
+
buildWhere(filter) {
|
|
5417
|
+
if (!filter) return void 0;
|
|
5418
|
+
const where = {};
|
|
5419
|
+
if (filter.manager) {
|
|
5420
|
+
where.manager = { _ilike: filter.manager };
|
|
5421
|
+
}
|
|
5422
|
+
if (filter.name) {
|
|
5423
|
+
where.name = { _ilike: `%${filter.name}%` };
|
|
5424
|
+
}
|
|
5425
|
+
if (filter.maxFee) {
|
|
5426
|
+
where.maxFee = { _lte: filter.maxFee };
|
|
5427
|
+
}
|
|
5428
|
+
const scopeWhere = this.buildRateManagerScopeWhere(filter.rateManagerIds);
|
|
5429
|
+
if (scopeWhere) {
|
|
5430
|
+
Object.assign(where, scopeWhere);
|
|
5431
|
+
}
|
|
5432
|
+
return Object.keys(where).length ? where : void 0;
|
|
5433
|
+
}
|
|
5434
|
+
buildAggregateWhere(filter) {
|
|
5435
|
+
return this.buildRateManagerScopeWhere(filter?.rateManagerIds) ?? {};
|
|
5436
|
+
}
|
|
5437
|
+
buildLegacyAggregateWhere(filter) {
|
|
5438
|
+
const rateManagerIds = filter?.rateManagerIds;
|
|
5439
|
+
if (!rateManagerIds?.length) return {};
|
|
5440
|
+
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
5441
|
+
const scopeConditions = [];
|
|
5442
|
+
if (bare.size > 0) {
|
|
5443
|
+
scopeConditions.push({
|
|
5444
|
+
rateManagerId: { _in: [...bare] }
|
|
5445
|
+
});
|
|
5446
|
+
}
|
|
5447
|
+
for (const scopedRateManager of scoped.values()) {
|
|
5448
|
+
scopeConditions.push({
|
|
5449
|
+
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
5450
|
+
id: {
|
|
5451
|
+
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
5452
|
+
scopedRateManager.rateManagerId,
|
|
5453
|
+
scopedRateManager.rateManagerAddress
|
|
5454
|
+
)
|
|
5455
|
+
}
|
|
5456
|
+
});
|
|
5457
|
+
}
|
|
5458
|
+
if (scopeConditions.length === 1) {
|
|
5459
|
+
return scopeConditions[0] ?? {};
|
|
5460
|
+
}
|
|
5461
|
+
if (scopeConditions.length > 1) {
|
|
5462
|
+
return { _or: scopeConditions };
|
|
5463
|
+
}
|
|
5464
|
+
return {};
|
|
5465
|
+
}
|
|
5466
|
+
buildOrderBy(pagination) {
|
|
5467
|
+
const rawField = pagination?.orderBy ?? "createdAt";
|
|
5468
|
+
const field = isAggregateOrderField(rawField) ? "createdAt" : rawField;
|
|
5469
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
5470
|
+
return [{ [field]: direction }];
|
|
5471
|
+
}
|
|
5472
|
+
toRateManagerListItems(result) {
|
|
5473
|
+
const managers = (result.RateManager ?? []).map(normalizeRateManagerEntity);
|
|
5474
|
+
const aggregatesByScope = /* @__PURE__ */ new Map();
|
|
5475
|
+
for (const aggregate of result.ManagerAggregateStats ?? []) {
|
|
5476
|
+
const aggregateRateManagerAddress = normalizeAddress3(aggregate.rateManagerAddress) || extractRateManagerAddressFromScopedId(aggregate.id);
|
|
5477
|
+
const scopeKey = getManagerScopeKey(aggregate.rateManagerId, aggregateRateManagerAddress);
|
|
5478
|
+
aggregatesByScope.set(scopeKey, aggregate);
|
|
5479
|
+
}
|
|
5480
|
+
return managers.map((manager) => ({
|
|
5481
|
+
manager,
|
|
5482
|
+
aggregate: aggregatesByScope.get(
|
|
5483
|
+
getManagerScopeKey(manager.rateManagerId, normalizeAddress3(manager.rateManagerAddress))
|
|
5484
|
+
) ?? aggregatesByScope.get(getManagerScopeKey(manager.rateManagerId)) ?? null
|
|
5485
|
+
}));
|
|
5486
|
+
}
|
|
5487
|
+
applyHookFilter(rows, hasHook) {
|
|
5488
|
+
if (hasHook === void 0) return rows;
|
|
5489
|
+
return hasHook ? [] : rows;
|
|
5490
|
+
}
|
|
5491
|
+
async queryRateManagerList(variables, legacyVariables) {
|
|
5492
|
+
try {
|
|
5493
|
+
return await this.client.query({
|
|
5494
|
+
query: RATE_MANAGER_LIST_QUERY,
|
|
5495
|
+
variables
|
|
5496
|
+
});
|
|
5497
|
+
} catch (error) {
|
|
5498
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5499
|
+
throw error;
|
|
5500
|
+
}
|
|
5501
|
+
return this.client.query({
|
|
5502
|
+
query: LEGACY_RATE_MANAGER_LIST_QUERY,
|
|
5503
|
+
variables: legacyVariables
|
|
5504
|
+
});
|
|
5393
5505
|
}
|
|
5394
5506
|
}
|
|
5395
|
-
|
|
5396
|
-
|
|
5507
|
+
buildDelegationOrderBy(pagination) {
|
|
5508
|
+
const rawField = pagination?.orderBy ?? "updatedAt";
|
|
5509
|
+
const field = rawField === "createdAt" ? "delegatedAt" : rawField;
|
|
5510
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
5511
|
+
return [{ [field]: direction }];
|
|
5397
5512
|
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5513
|
+
buildLegacyDelegationOrderBy(pagination) {
|
|
5514
|
+
const rawField = pagination?.orderBy ?? "updatedAt";
|
|
5515
|
+
const field = rawField === "delegatedAt" ? "createdAt" : rawField;
|
|
5516
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
5517
|
+
return [{ [field]: direction }];
|
|
5400
5518
|
}
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5519
|
+
async fetchCurrentRateManagerDepositScopes(rateManagerId, rateManagerAddress) {
|
|
5520
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
5521
|
+
let offset = 0;
|
|
5522
|
+
for (; ; ) {
|
|
5523
|
+
const delegations = await this.fetchRateManagerDelegations(rateManagerId, {
|
|
5524
|
+
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
5525
|
+
offset,
|
|
5526
|
+
orderBy: "delegatedAt",
|
|
5527
|
+
orderDirection: "desc",
|
|
5528
|
+
rateManagerAddress: rateManagerAddress || void 0
|
|
5529
|
+
});
|
|
5530
|
+
for (const delegation of delegations) {
|
|
5531
|
+
const escrow = extractEscrowAddressFromCompositeDepositId(delegation.depositId);
|
|
5532
|
+
const depositIdOnContract = extractDepositIdOnContract(delegation.depositId);
|
|
5533
|
+
if (!escrow || !depositIdOnContract) continue;
|
|
5534
|
+
const scope = { escrow, depositIdOnContract };
|
|
5535
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
5536
|
+
}
|
|
5537
|
+
if (delegations.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
5538
|
+
break;
|
|
5539
|
+
}
|
|
5540
|
+
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
5541
|
+
}
|
|
5542
|
+
return [...scopes.values()];
|
|
5543
|
+
}
|
|
5544
|
+
async fetchHistoricalRateManagerDepositScopes(rateManagerId, rateManagerAddress) {
|
|
5545
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5546
|
+
const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
|
|
5547
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
5548
|
+
const currentScopes = await this.fetchCurrentRateManagerDepositScopes(
|
|
5549
|
+
normalizedId,
|
|
5550
|
+
normalizedRateManagerAddress || void 0
|
|
5405
5551
|
);
|
|
5552
|
+
for (const scope of currentScopes) {
|
|
5553
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
5554
|
+
}
|
|
5555
|
+
try {
|
|
5556
|
+
let offset = 0;
|
|
5557
|
+
for (; ; ) {
|
|
5558
|
+
const result = await this.client.query({
|
|
5559
|
+
query: RATE_MANAGER_ASSIGNMENT_EVENTS_QUERY,
|
|
5560
|
+
variables: {
|
|
5561
|
+
setWhere: {
|
|
5562
|
+
rateManagerId: { _eq: normalizedId },
|
|
5563
|
+
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
5564
|
+
},
|
|
5565
|
+
clearedWhere: {
|
|
5566
|
+
rateManagerId: { _eq: normalizedId },
|
|
5567
|
+
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
5568
|
+
},
|
|
5569
|
+
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
5570
|
+
offset
|
|
5571
|
+
}
|
|
5572
|
+
});
|
|
5573
|
+
const setEvents = result.EscrowV2_DepositRateManagerSet ?? [];
|
|
5574
|
+
const clearedEvents = result.EscrowV2_DepositRateManagerCleared ?? [];
|
|
5575
|
+
for (const event of [...setEvents, ...clearedEvents]) {
|
|
5576
|
+
const escrow = normalizeAddress3(event.escrow);
|
|
5577
|
+
const depositIdOnContract = event.depositIdOnContract?.toString() ?? "";
|
|
5578
|
+
if (!escrow || !depositIdOnContract) continue;
|
|
5579
|
+
const scope = { escrow, depositIdOnContract };
|
|
5580
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
5581
|
+
}
|
|
5582
|
+
if (setEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE && clearedEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
5583
|
+
break;
|
|
5584
|
+
}
|
|
5585
|
+
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
5586
|
+
}
|
|
5587
|
+
} catch (error) {
|
|
5588
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5589
|
+
throw error;
|
|
5590
|
+
}
|
|
5591
|
+
}
|
|
5592
|
+
return [...scopes.values()];
|
|
5406
5593
|
}
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5594
|
+
async fetchRateManagers(pagination, filter) {
|
|
5595
|
+
const orderBy = pagination?.orderBy ?? "createdAt";
|
|
5596
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
5597
|
+
const limit = pagination?.limit ?? DEFAULT_LIMIT2;
|
|
5598
|
+
const offset = pagination?.offset ?? 0;
|
|
5599
|
+
const where = this.buildWhere(filter);
|
|
5600
|
+
const aggregateWhere = this.buildAggregateWhere(filter);
|
|
5601
|
+
const legacyAggregateWhere = this.buildLegacyAggregateWhere(filter);
|
|
5602
|
+
if (isAggregateOrderField(orderBy)) {
|
|
5603
|
+
const result2 = await this.queryRateManagerList(
|
|
5604
|
+
{
|
|
5605
|
+
where,
|
|
5606
|
+
aggregateWhere,
|
|
5607
|
+
order_by: [{ createdAt: "desc" }]
|
|
5608
|
+
},
|
|
5609
|
+
{
|
|
5610
|
+
where,
|
|
5611
|
+
aggregateWhere: legacyAggregateWhere,
|
|
5612
|
+
order_by: [{ createdAt: "desc" }]
|
|
5613
|
+
}
|
|
5614
|
+
);
|
|
5615
|
+
const scopedRows = this.applyHookFilter(this.toRateManagerListItems(result2), filter?.hasHook);
|
|
5616
|
+
const sorted = scopedRows.sort((a, b) => {
|
|
5617
|
+
const av = orderBy === "currentDelegatedBalance" ? toSafeBigInt(a.aggregate?.currentDelegatedBalance) : toSafeBigInt(a.aggregate?.totalFilledVolume);
|
|
5618
|
+
const bv = orderBy === "currentDelegatedBalance" ? toSafeBigInt(b.aggregate?.currentDelegatedBalance) : toSafeBigInt(b.aggregate?.totalFilledVolume);
|
|
5619
|
+
const aggregateCmp = compareBigInt(av, bv, direction);
|
|
5620
|
+
if (aggregateCmp !== 0) return aggregateCmp;
|
|
5621
|
+
const createdAtCmp = compareBigInt(
|
|
5622
|
+
toSafeBigInt(a.manager.createdAt),
|
|
5623
|
+
toSafeBigInt(b.manager.createdAt),
|
|
5624
|
+
"desc"
|
|
5625
|
+
);
|
|
5626
|
+
if (createdAtCmp !== 0) return createdAtCmp;
|
|
5627
|
+
return a.manager.rateManagerId.localeCompare(b.manager.rateManagerId);
|
|
5628
|
+
});
|
|
5629
|
+
return sorted.slice(offset, offset + limit);
|
|
5630
|
+
}
|
|
5631
|
+
const result = await this.queryRateManagerList(
|
|
5632
|
+
{
|
|
5633
|
+
where,
|
|
5634
|
+
aggregateWhere,
|
|
5635
|
+
order_by: this.buildOrderBy(pagination),
|
|
5636
|
+
limit,
|
|
5637
|
+
offset
|
|
5638
|
+
},
|
|
5639
|
+
{
|
|
5640
|
+
where,
|
|
5641
|
+
aggregateWhere: legacyAggregateWhere,
|
|
5642
|
+
order_by: this.buildOrderBy(pagination),
|
|
5643
|
+
limit,
|
|
5644
|
+
offset
|
|
5645
|
+
}
|
|
5646
|
+
);
|
|
5647
|
+
return this.applyHookFilter(this.toRateManagerListItems(result), filter?.hasHook);
|
|
5648
|
+
}
|
|
5649
|
+
async fetchRateManagerDetail(rateManagerId, options) {
|
|
5650
|
+
if (!rateManagerId) return null;
|
|
5651
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5652
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
5653
|
+
const baseVariables = {
|
|
5654
|
+
managerWhere: {
|
|
5655
|
+
rateManagerId: { _eq: normalizedId },
|
|
5656
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5657
|
+
},
|
|
5658
|
+
rateWhere: {
|
|
5659
|
+
rateManagerId: { _eq: normalizedId },
|
|
5660
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5661
|
+
},
|
|
5662
|
+
aggregateWhere: {
|
|
5663
|
+
rateManagerId: { _eq: normalizedId },
|
|
5664
|
+
...normalizedRateManagerAddress ? {
|
|
5665
|
+
id: {
|
|
5666
|
+
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
5667
|
+
normalizedId,
|
|
5668
|
+
normalizedRateManagerAddress
|
|
5669
|
+
)
|
|
5670
|
+
}
|
|
5671
|
+
} : {}
|
|
5672
|
+
},
|
|
5673
|
+
statsWhere: {
|
|
5674
|
+
rateManagerId: { _eq: normalizedId },
|
|
5675
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5676
|
+
},
|
|
5677
|
+
delegationWhere: {
|
|
5678
|
+
rateManagerId: { _eq: normalizedId },
|
|
5679
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5680
|
+
},
|
|
5681
|
+
statsLimit: options?.statsLimit ?? 20
|
|
5682
|
+
};
|
|
5683
|
+
const legacyVariables = {
|
|
5684
|
+
...baseVariables,
|
|
5685
|
+
floorWhere: {
|
|
5686
|
+
rateManagerId: { _eq: normalizedId },
|
|
5687
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5688
|
+
}
|
|
5689
|
+
};
|
|
5690
|
+
let managerRaw;
|
|
5691
|
+
let scopedRates = [];
|
|
5692
|
+
let scopedRecentStats = [];
|
|
5693
|
+
let scopedDelegations = [];
|
|
5694
|
+
let aggregate = null;
|
|
5695
|
+
try {
|
|
5696
|
+
const result = await this.client.query({
|
|
5697
|
+
query: RATE_MANAGER_DETAIL_QUERY,
|
|
5698
|
+
variables: baseVariables
|
|
5699
|
+
});
|
|
5700
|
+
managerRaw = result.RateManager?.[0];
|
|
5701
|
+
if (!managerRaw) return null;
|
|
5702
|
+
const scopedRateManagerAddress = normalizeAddress3(managerRaw.rateManagerAddress);
|
|
5703
|
+
scopedRates = (result.RateManagerRate ?? []).filter(
|
|
5704
|
+
(rate) => normalizeAddress3(rate.rateManagerAddress) === scopedRateManagerAddress
|
|
5705
|
+
);
|
|
5706
|
+
scopedRecentStats = (result.ManagerStats ?? []).filter((stats) => {
|
|
5707
|
+
const statsRateManagerAddress = normalizeAddress3(stats.rateManagerAddress);
|
|
5708
|
+
return !statsRateManagerAddress || statsRateManagerAddress === scopedRateManagerAddress;
|
|
5709
|
+
});
|
|
5710
|
+
scopedDelegations = (result.Deposit ?? []).map((deposit) => toDelegationEntityFromDeposit(deposit)).filter((delegation) => Boolean(delegation)).filter(
|
|
5711
|
+
(delegation) => normalizeAddress3(delegation.rateManagerAddress) === scopedRateManagerAddress
|
|
5712
|
+
);
|
|
5713
|
+
aggregate = (result.ManagerAggregateStats ?? []).find(
|
|
5714
|
+
(stats) => (normalizeAddress3(stats.rateManagerAddress) || extractRateManagerAddressFromScopedId(stats.id)) === scopedRateManagerAddress
|
|
5715
|
+
) ?? result.ManagerAggregateStats?.[0] ?? null;
|
|
5716
|
+
} catch (error) {
|
|
5717
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5718
|
+
throw error;
|
|
5719
|
+
}
|
|
5720
|
+
const legacyResult = await this.client.query({
|
|
5721
|
+
query: LEGACY_RATE_MANAGER_DETAIL_QUERY,
|
|
5722
|
+
variables: legacyVariables
|
|
5723
|
+
});
|
|
5724
|
+
managerRaw = legacyResult.RateManager?.[0];
|
|
5725
|
+
if (!managerRaw) return null;
|
|
5726
|
+
const scopedRateManagerAddress = normalizeAddress3(managerRaw.rateManagerAddress);
|
|
5727
|
+
scopedRates = (legacyResult.RateManagerRate ?? []).filter(
|
|
5728
|
+
(rate) => normalizeAddress3(rate.rateManagerAddress) === scopedRateManagerAddress
|
|
5729
|
+
);
|
|
5730
|
+
scopedRecentStats = (legacyResult.ManagerStats ?? []).filter((stats) => {
|
|
5731
|
+
const statsRateManagerAddress = normalizeAddress3(stats.rateManagerAddress);
|
|
5732
|
+
return !statsRateManagerAddress || statsRateManagerAddress === scopedRateManagerAddress;
|
|
5733
|
+
});
|
|
5734
|
+
scopedDelegations = (legacyResult.RateManagerDelegation ?? []).filter(
|
|
5735
|
+
(delegation) => normalizeAddress3(delegation.rateManagerAddress) === scopedRateManagerAddress
|
|
5736
|
+
);
|
|
5737
|
+
aggregate = (legacyResult.ManagerAggregateStats ?? []).find(
|
|
5738
|
+
(stats) => (normalizeAddress3(stats.rateManagerAddress) || extractRateManagerAddressFromScopedId(stats.id)) === scopedRateManagerAddress
|
|
5739
|
+
) ?? legacyResult.ManagerAggregateStats?.[0] ?? null;
|
|
5740
|
+
}
|
|
5741
|
+
if (!managerRaw) return null;
|
|
5742
|
+
const manager = normalizeRateManagerEntity(managerRaw);
|
|
5465
5743
|
return {
|
|
5466
|
-
|
|
5467
|
-
|
|
5744
|
+
manager,
|
|
5745
|
+
rates: scopedRates,
|
|
5746
|
+
aggregate,
|
|
5747
|
+
recentStats: scopedRecentStats,
|
|
5748
|
+
delegations: scopedDelegations
|
|
5468
5749
|
};
|
|
5469
5750
|
}
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
const indexerClient = new IndexerClient(indexerEndpoint, {
|
|
5479
|
-
apiKey,
|
|
5480
|
-
authorizationToken: authToken
|
|
5481
|
-
});
|
|
5482
|
-
const service = new IndexerDepositService(indexerClient);
|
|
5483
|
-
const deposits = await withOptionalTimeout(
|
|
5484
|
-
service.fetchDepositsWithRelations(
|
|
5485
|
-
{
|
|
5486
|
-
depositor: req.ownerAddress,
|
|
5487
|
-
escrowAddress,
|
|
5488
|
-
escrowAddresses: req.escrowAddresses?.length ? req.escrowAddresses : void 0,
|
|
5489
|
-
status: normalizeOwnerDepositsStatus(req.status)
|
|
5751
|
+
async fetchRateManagerDelegations(rateManagerId, pagination) {
|
|
5752
|
+
if (!rateManagerId) return [];
|
|
5753
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5754
|
+
const normalizedRateManagerAddress = normalizeAddress3(pagination?.rateManagerAddress);
|
|
5755
|
+
const variables = {
|
|
5756
|
+
where: {
|
|
5757
|
+
rateManagerId: { _eq: normalizedId },
|
|
5758
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
5490
5759
|
},
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
body: { code: normalizeReferralCode(req.code) },
|
|
5546
|
-
authorizationToken,
|
|
5547
|
-
timeoutMs: opts.timeoutMs
|
|
5548
|
-
});
|
|
5549
|
-
return unwrapResponseObject(response);
|
|
5550
|
-
}
|
|
5551
|
-
async function apiUpdateReferralCode(req, opts) {
|
|
5552
|
-
const endpoint = "/v2/referral/code";
|
|
5553
|
-
const authorizationToken = requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
5554
|
-
const response = await apiFetch({
|
|
5555
|
-
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
5556
|
-
method: "PATCH",
|
|
5557
|
-
body: { code: normalizeReferralCode(req.code) },
|
|
5558
|
-
authorizationToken,
|
|
5559
|
-
timeoutMs: opts.timeoutMs
|
|
5560
|
-
});
|
|
5561
|
-
return unwrapResponseObject(response);
|
|
5562
|
-
}
|
|
5563
|
-
async function apiUploadSellerCredential(processorName, payeeDetails, bundle, baseApiUrl, timeoutMs) {
|
|
5564
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
5565
|
-
payeeDetails
|
|
5566
|
-
)}/seller-credential`;
|
|
5567
|
-
return apiFetch({
|
|
5568
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
5569
|
-
method: "POST",
|
|
5570
|
-
body: bundle,
|
|
5571
|
-
timeoutMs
|
|
5572
|
-
});
|
|
5573
|
-
}
|
|
5574
|
-
async function apiUploadGoogleOAuthSellerCredential(processorName, payeeDetails, body, baseApiUrl, opts) {
|
|
5575
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
5576
|
-
payeeDetails
|
|
5577
|
-
)}/seller-credential/google-oauth`;
|
|
5578
|
-
return apiFetch({
|
|
5579
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
5580
|
-
method: "POST",
|
|
5581
|
-
body,
|
|
5582
|
-
timeoutMs: opts?.timeoutMs
|
|
5583
|
-
});
|
|
5584
|
-
}
|
|
5585
|
-
async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApiUrl, timeoutMs) {
|
|
5586
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
5587
|
-
payeeDetails
|
|
5588
|
-
)}/seller-credential/status`;
|
|
5589
|
-
return apiFetch({
|
|
5590
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
5591
|
-
method: "GET",
|
|
5592
|
-
timeoutMs
|
|
5593
|
-
});
|
|
5594
|
-
}
|
|
5595
|
-
async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey) {
|
|
5596
|
-
const body = {
|
|
5597
|
-
txId: req.txId,
|
|
5598
|
-
chainId: req.chainId,
|
|
5599
|
-
intent: req.intent,
|
|
5600
|
-
...req.metadata !== void 0 ? { metadata: req.metadata } : {}
|
|
5601
|
-
};
|
|
5602
|
-
return apiFetch({
|
|
5603
|
-
url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
|
|
5604
|
-
method: "POST",
|
|
5605
|
-
body,
|
|
5606
|
-
apiKey,
|
|
5607
|
-
timeoutMs
|
|
5608
|
-
});
|
|
5609
|
-
}
|
|
5610
|
-
async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs) {
|
|
5611
|
-
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
5612
|
-
baseApiUrl: optsOrBaseApiUrl,
|
|
5613
|
-
timeoutMs
|
|
5614
|
-
} : optsOrBaseApiUrl;
|
|
5615
|
-
const query = new URLSearchParams();
|
|
5616
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
5617
|
-
if (value === void 0 || value === null) return;
|
|
5618
|
-
query.set(key, String(value));
|
|
5619
|
-
});
|
|
5620
|
-
const response = await apiFetch({
|
|
5621
|
-
url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook?${query.toString()}`,
|
|
5622
|
-
method: "GET",
|
|
5623
|
-
timeoutMs: opts.timeoutMs
|
|
5624
|
-
});
|
|
5625
|
-
return response.responseObject;
|
|
5626
|
-
}
|
|
5627
|
-
async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs) {
|
|
5628
|
-
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
5629
|
-
baseApiUrl: optsOrBaseApiUrl,
|
|
5630
|
-
timeoutMs
|
|
5631
|
-
} : optsOrBaseApiUrl;
|
|
5632
|
-
const escrowAddress = requireEscrowAddress(
|
|
5633
|
-
params.escrowAddress,
|
|
5634
|
-
"apiGetDepositBundle requires escrowAddress"
|
|
5635
|
-
);
|
|
5636
|
-
const query = new URLSearchParams({ escrowAddress });
|
|
5637
|
-
if (params.dailySnapshotLimit !== void 0) {
|
|
5638
|
-
query.set("dailySnapshotLimit", String(params.dailySnapshotLimit));
|
|
5760
|
+
order_by: this.buildDelegationOrderBy(pagination),
|
|
5761
|
+
limit: pagination?.limit ?? DEFAULT_LIMIT2,
|
|
5762
|
+
offset: pagination?.offset ?? 0
|
|
5763
|
+
};
|
|
5764
|
+
try {
|
|
5765
|
+
const result = await this.client.query({
|
|
5766
|
+
query: RATE_MANAGER_DELEGATIONS_QUERY,
|
|
5767
|
+
variables
|
|
5768
|
+
});
|
|
5769
|
+
return (result.Deposit ?? []).map((deposit) => toDelegationEntityFromDeposit(deposit)).filter((delegation) => Boolean(delegation));
|
|
5770
|
+
} catch (error) {
|
|
5771
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5772
|
+
throw error;
|
|
5773
|
+
}
|
|
5774
|
+
const legacyResult = await this.client.query({
|
|
5775
|
+
query: LEGACY_RATE_MANAGER_DELEGATIONS_QUERY,
|
|
5776
|
+
variables: {
|
|
5777
|
+
...variables,
|
|
5778
|
+
order_by: this.buildLegacyDelegationOrderBy(pagination)
|
|
5779
|
+
}
|
|
5780
|
+
});
|
|
5781
|
+
return legacyResult.RateManagerDelegation ?? [];
|
|
5782
|
+
}
|
|
5783
|
+
}
|
|
5784
|
+
async fetchManagerDailySnapshots(rateManagerId, options) {
|
|
5785
|
+
if (!rateManagerId) return [];
|
|
5786
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5787
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
5788
|
+
try {
|
|
5789
|
+
const result = await this.client.query({
|
|
5790
|
+
query: MANAGER_DAILY_SNAPSHOTS_QUERY,
|
|
5791
|
+
variables: {
|
|
5792
|
+
where: {
|
|
5793
|
+
rateManagerId: { _eq: normalizedId },
|
|
5794
|
+
...normalizedRateManagerAddress ? {
|
|
5795
|
+
id: {
|
|
5796
|
+
_ilike: buildRateManagerScopedIdPattern(
|
|
5797
|
+
normalizedId,
|
|
5798
|
+
normalizedRateManagerAddress
|
|
5799
|
+
)
|
|
5800
|
+
}
|
|
5801
|
+
} : {}
|
|
5802
|
+
},
|
|
5803
|
+
order_by: [{ dayTimestamp: "asc" }],
|
|
5804
|
+
limit: options?.limit ?? 365
|
|
5805
|
+
}
|
|
5806
|
+
});
|
|
5807
|
+
return result.ManagerDailySnapshot ?? [];
|
|
5808
|
+
} catch (error) {
|
|
5809
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5810
|
+
throw error;
|
|
5811
|
+
}
|
|
5812
|
+
return [];
|
|
5813
|
+
}
|
|
5639
5814
|
}
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5815
|
+
async fetchDelegationForDeposit(depositId, options) {
|
|
5816
|
+
if (!depositId) return null;
|
|
5817
|
+
const normalizedDepositId = normalizeCompositeDepositId(depositId, options?.escrowAddress);
|
|
5818
|
+
try {
|
|
5819
|
+
const result = await this.client.query({
|
|
5820
|
+
query: DEPOSIT_DELEGATION_QUERY,
|
|
5821
|
+
variables: {
|
|
5822
|
+
depositId: normalizedDepositId
|
|
5823
|
+
}
|
|
5824
|
+
});
|
|
5825
|
+
const delegationDeposit = result.Deposit?.[0];
|
|
5826
|
+
if (!delegationDeposit) {
|
|
5827
|
+
return null;
|
|
5828
|
+
}
|
|
5829
|
+
return toDelegationEntityFromDeposit(delegationDeposit) ?? null;
|
|
5830
|
+
} catch (error) {
|
|
5831
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5832
|
+
throw error;
|
|
5833
|
+
}
|
|
5834
|
+
const legacyResult = await this.client.query({
|
|
5835
|
+
query: LEGACY_DEPOSIT_DELEGATION_QUERY,
|
|
5836
|
+
variables: {
|
|
5837
|
+
depositId: normalizedDepositId
|
|
5838
|
+
}
|
|
5839
|
+
});
|
|
5840
|
+
return legacyResult.RateManagerDelegation?.[0] ?? null;
|
|
5841
|
+
}
|
|
5842
|
+
}
|
|
5843
|
+
async fetchManualRateUpdates(rateManagerId, options) {
|
|
5844
|
+
if (!rateManagerId) return [];
|
|
5845
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5846
|
+
try {
|
|
5847
|
+
const result = await this.client.query({
|
|
5848
|
+
query: MANUAL_RATE_UPDATES_QUERY,
|
|
5849
|
+
variables: {
|
|
5850
|
+
where: {
|
|
5851
|
+
rateManagerId: { _eq: normalizedId }
|
|
5852
|
+
},
|
|
5853
|
+
order_by: [{ id: "desc" }],
|
|
5854
|
+
limit: options?.limit ?? 100
|
|
5855
|
+
}
|
|
5856
|
+
});
|
|
5857
|
+
return (result.RateManagerV1_RateManagerRateUpdated ?? []).map((e) => ({
|
|
5858
|
+
...e,
|
|
5859
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
5860
|
+
minRate: e.minRate ?? e.rate ?? "0"
|
|
5861
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5862
|
+
} catch (error) {
|
|
5863
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
5864
|
+
throw error;
|
|
5865
|
+
}
|
|
5866
|
+
return [];
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5869
|
+
async fetchOracleConfigUpdates(rateManagerId, options) {
|
|
5870
|
+
if (!rateManagerId) return [];
|
|
5871
|
+
const normalizedId = normalizeRateManagerId2(rateManagerId);
|
|
5872
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
5873
|
+
const limit = options?.limit ?? 100;
|
|
5874
|
+
try {
|
|
5875
|
+
const depositScopes = await this.fetchHistoricalRateManagerDepositScopes(
|
|
5876
|
+
normalizedId,
|
|
5877
|
+
normalizedRateManagerAddress || void 0
|
|
5878
|
+
);
|
|
5879
|
+
if (!depositScopes.length) {
|
|
5880
|
+
return [];
|
|
5881
|
+
}
|
|
5882
|
+
const scopedKeys = new Set(depositScopes.map((scope) => buildDepositScopeKey(scope)));
|
|
5883
|
+
const result = await this.client.query({
|
|
5884
|
+
query: ORACLE_CONFIG_UPDATES_QUERY,
|
|
5885
|
+
variables: {
|
|
5886
|
+
where: {
|
|
5887
|
+
_or: depositScopes.map((scope) => ({
|
|
5888
|
+
_and: [
|
|
5889
|
+
{ depositId: { _eq: scope.depositIdOnContract } },
|
|
5890
|
+
{ escrow: { _eq: scope.escrow } }
|
|
5891
|
+
]
|
|
5892
|
+
}))
|
|
5893
|
+
},
|
|
5894
|
+
order_by: [{ id: "desc" }],
|
|
5895
|
+
limit
|
|
5896
|
+
}
|
|
5897
|
+
});
|
|
5898
|
+
return (result.EscrowV2_DepositOracleRateConfigSet ?? []).filter((event) => {
|
|
5899
|
+
const escrow = normalizeAddress3(event.escrow);
|
|
5900
|
+
const depositIdOnContract = event.depositIdOnContract ?? event.depositId?.toString?.() ?? "";
|
|
5901
|
+
if (!escrow || !depositIdOnContract) return false;
|
|
5902
|
+
return scopedKeys.has(
|
|
5903
|
+
buildDepositScopeKey({
|
|
5904
|
+
escrow,
|
|
5905
|
+
depositIdOnContract
|
|
5906
|
+
})
|
|
5907
|
+
);
|
|
5908
|
+
}).map((e) => ({
|
|
5909
|
+
...e,
|
|
5910
|
+
rateManagerId: normalizedId,
|
|
5911
|
+
escrow: normalizeAddress3(e.escrow) || void 0,
|
|
5912
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
5913
|
+
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
5914
|
+
adapter: e.adapter ?? "",
|
|
5915
|
+
spreadBps: e.spreadBps ?? 0
|
|
5916
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5917
|
+
} catch (error) {
|
|
5918
|
+
if (isSchemaCompatibilityError(error)) ; else {
|
|
5919
|
+
throw error;
|
|
5920
|
+
}
|
|
5921
|
+
const legacyResult = await this.client.query({
|
|
5922
|
+
query: LEGACY_ORACLE_CONFIG_UPDATES_QUERY,
|
|
5923
|
+
variables: {
|
|
5924
|
+
where: {
|
|
5925
|
+
rateManagerId: { _eq: normalizedId }
|
|
5926
|
+
},
|
|
5927
|
+
order_by: [{ id: "desc" }],
|
|
5928
|
+
limit
|
|
5929
|
+
}
|
|
5930
|
+
});
|
|
5931
|
+
return (legacyResult.RateManagerV1_DepositorFloorSet ?? []).map((e) => ({
|
|
5932
|
+
...e,
|
|
5933
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
5934
|
+
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
5935
|
+
adapter: e.adapter ?? e.oracleAdapter ?? "",
|
|
5936
|
+
spreadBps: e.spreadBps ?? e.floorSpreadBps ?? 0
|
|
5937
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
};
|
|
5941
|
+
|
|
5942
|
+
// src/indexer/intentVerification.ts
|
|
5943
|
+
async function fetchFulfillmentAndPayment(client, intentHash) {
|
|
5944
|
+
return client.query({
|
|
5945
|
+
query: FULFILLMENT_AND_PAYMENT_QUERY,
|
|
5946
|
+
variables: { intentHash }
|
|
5644
5947
|
});
|
|
5645
|
-
return response.responseObject;
|
|
5646
5948
|
}
|
|
5647
5949
|
|
|
5648
5950
|
// src/sellerCredentials.ts
|
|
@@ -5654,7 +5956,7 @@ function assertBundlePlatformMatches(params) {
|
|
|
5654
5956
|
throw new Error("Seller credential bundle platform does not match upload platform");
|
|
5655
5957
|
}
|
|
5656
5958
|
}
|
|
5657
|
-
async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
5959
|
+
async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs, authorizationToken) {
|
|
5658
5960
|
assertBundlePlatformMatches(params);
|
|
5659
5961
|
const normalizedBaseApiUrl = normalizeBaseApiUrl(baseApiUrl);
|
|
5660
5962
|
if (params.platform === "wise") {
|
|
@@ -5663,7 +5965,8 @@ async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
|
5663
5965
|
params.bundle.payeeIdHash,
|
|
5664
5966
|
params.bundle,
|
|
5665
5967
|
normalizedBaseApiUrl,
|
|
5666
|
-
timeoutMs
|
|
5968
|
+
timeoutMs,
|
|
5969
|
+
authorizationToken
|
|
5667
5970
|
);
|
|
5668
5971
|
}
|
|
5669
5972
|
const registeredPayeePayload = {
|
|
@@ -5693,7 +5996,8 @@ async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
|
5693
5996
|
registeredPayee.hashedOnchainId,
|
|
5694
5997
|
params.bundle,
|
|
5695
5998
|
normalizedBaseApiUrl,
|
|
5696
|
-
timeoutMs
|
|
5999
|
+
timeoutMs,
|
|
6000
|
+
authorizationToken
|
|
5697
6001
|
);
|
|
5698
6002
|
}
|
|
5699
6003
|
var formatTokenAmountForDisplay = (amount, decimals) => {
|
|
@@ -5847,9 +6151,7 @@ function isObjectRecord(value) {
|
|
|
5847
6151
|
return true;
|
|
5848
6152
|
}
|
|
5849
6153
|
function normalizeTelegramUsername(value) {
|
|
5850
|
-
if (typeof value !== "string")
|
|
5851
|
-
return value === null ? null : null;
|
|
5852
|
-
}
|
|
6154
|
+
if (typeof value !== "string") return null;
|
|
5853
6155
|
const normalized = value.trim();
|
|
5854
6156
|
return normalized.length > 0 ? normalized : null;
|
|
5855
6157
|
}
|
|
@@ -5896,10 +6198,23 @@ function normalizePayeeDataInputItem(raw) {
|
|
|
5896
6198
|
if (!legacy) {
|
|
5897
6199
|
return null;
|
|
5898
6200
|
}
|
|
6201
|
+
const metadata = legacy.metadata && isObjectRecord(legacy.metadata) ? { ...legacy.metadata } : {};
|
|
6202
|
+
if (candidate.identityAttestation !== void 0 && candidate.identityAttestation !== null) {
|
|
6203
|
+
metadata.identityAttestation = candidate.identityAttestation;
|
|
6204
|
+
}
|
|
5899
6205
|
return {
|
|
5900
6206
|
offchainId: legacy.offchainId,
|
|
5901
6207
|
telegramUsername: legacy.telegramUsername,
|
|
5902
|
-
metadata:
|
|
6208
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null
|
|
6209
|
+
};
|
|
6210
|
+
}
|
|
6211
|
+
function getPayeeRegistrationMetadata(payeeData) {
|
|
6212
|
+
if (payeeData.identityAttestation === void 0 || payeeData.identityAttestation === null) {
|
|
6213
|
+
return payeeData.metadata;
|
|
6214
|
+
}
|
|
6215
|
+
return {
|
|
6216
|
+
...isObjectRecord(payeeData.metadata) ? payeeData.metadata : {},
|
|
6217
|
+
identityAttestation: payeeData.identityAttestation
|
|
5903
6218
|
};
|
|
5904
6219
|
}
|
|
5905
6220
|
function resolvePayeeDataInput(params, methodName) {
|
|
@@ -5926,7 +6241,7 @@ function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
|
5926
6241
|
processorName,
|
|
5927
6242
|
offchainId: payeeData.offchainId,
|
|
5928
6243
|
telegramUsername: payeeData.telegramUsername,
|
|
5929
|
-
metadata: payeeData
|
|
6244
|
+
metadata: getPayeeRegistrationMetadata(payeeData)
|
|
5930
6245
|
};
|
|
5931
6246
|
}
|
|
5932
6247
|
var Zkp2pClient = class {
|
|
@@ -6143,7 +6458,7 @@ var Zkp2pClient = class {
|
|
|
6143
6458
|
() => ({
|
|
6144
6459
|
address: this.rateManagerControllerAddress,
|
|
6145
6460
|
abi: this.rateManagerControllerAbi,
|
|
6146
|
-
label: "Rate manager controller
|
|
6461
|
+
label: "Rate manager controller"
|
|
6147
6462
|
}),
|
|
6148
6463
|
"setDepositRateManager",
|
|
6149
6464
|
(params) => {
|
|
@@ -6157,7 +6472,7 @@ var Zkp2pClient = class {
|
|
|
6157
6472
|
() => ({
|
|
6158
6473
|
address: this.rateManagerControllerAddress,
|
|
6159
6474
|
abi: this.rateManagerControllerAbi,
|
|
6160
|
-
label: "Rate manager controller
|
|
6475
|
+
label: "Rate manager controller"
|
|
6161
6476
|
}),
|
|
6162
6477
|
"clearDepositRateManager",
|
|
6163
6478
|
(params) => {
|
|
@@ -6243,7 +6558,7 @@ var Zkp2pClient = class {
|
|
|
6243
6558
|
() => ({
|
|
6244
6559
|
address: this.rateManagerRegistryAddress,
|
|
6245
6560
|
abi: this.rateManagerRegistryAbi,
|
|
6246
|
-
label: "Rate manager registry
|
|
6561
|
+
label: "Rate manager registry"
|
|
6247
6562
|
}),
|
|
6248
6563
|
"setFee",
|
|
6249
6564
|
(params) => {
|
|
@@ -6728,6 +7043,10 @@ var Zkp2pClient = class {
|
|
|
6728
7043
|
const prepared = await this.prepareFulfillIntent(params);
|
|
6729
7044
|
const txHash = await this.executePreparedTransaction(prepared, params.txOverrides);
|
|
6730
7045
|
params?.callbacks?.onTxSent?.(txHash);
|
|
7046
|
+
if (params?.callbacks?.onTxMined) {
|
|
7047
|
+
await this.publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
7048
|
+
params.callbacks.onTxMined(txHash);
|
|
7049
|
+
}
|
|
6731
7050
|
return txHash;
|
|
6732
7051
|
},
|
|
6733
7052
|
{
|
|
@@ -6746,7 +7065,7 @@ var Zkp2pClient = class {
|
|
|
6746
7065
|
this.walletClient = opts.walletClient;
|
|
6747
7066
|
this.chainId = opts.chainId;
|
|
6748
7067
|
this.runtimeEnv = opts.runtimeEnv ?? "production";
|
|
6749
|
-
const inferredRpc = this.walletClient
|
|
7068
|
+
const inferredRpc = this.walletClient.chain?.rpcUrls?.default?.http?.[0];
|
|
6750
7069
|
const defaultRpcUrls = {
|
|
6751
7070
|
[base.id]: "https://mainnet.base.org",
|
|
6752
7071
|
[hardhat.id]: "http://127.0.0.1:8545"
|
|
@@ -6759,7 +7078,7 @@ var Zkp2pClient = class {
|
|
|
6759
7078
|
const selectedChain = chainMap[this.chainId];
|
|
6760
7079
|
this.publicClient = createPublicClient({
|
|
6761
7080
|
chain: selectedChain,
|
|
6762
|
-
transport: http(rpc, { batch: false })
|
|
7081
|
+
transport: opts.rpcTransport ?? http(rpc, { batch: false })
|
|
6763
7082
|
});
|
|
6764
7083
|
const { addresses, abis } = getContracts(this.chainId, this.runtimeEnv);
|
|
6765
7084
|
const toAddress = (value) => this.isValidHexAddress(value) ? value : void 0;
|
|
@@ -6777,12 +7096,10 @@ var Zkp2pClient = class {
|
|
|
6777
7096
|
};
|
|
6778
7097
|
this.escrowV2Address = toAddress(addresses.escrowV2 ?? addresses.escrow);
|
|
6779
7098
|
this.escrowV2Abi = abis.escrowV2 ?? abis.escrow;
|
|
6780
|
-
this.orchestratorV2Address = toAddress(
|
|
6781
|
-
addresses.orchestratorV2 ?? addresses.orchestrator
|
|
6782
|
-
);
|
|
7099
|
+
this.orchestratorV2Address = toAddress(addresses.orchestratorV2 ?? addresses.orchestrator);
|
|
6783
7100
|
this.orchestratorV2Abi = abis.orchestratorV2 ?? abis.orchestrator;
|
|
6784
|
-
const configuredEscrowAddresses = (addresses.escrowAddresses ?? []).map((value) => toAddress(value)).filter(Boolean);
|
|
6785
|
-
const configuredOrchestratorAddresses = (addresses.orchestratorAddresses ?? []).map((value) => toAddress(value)).filter(Boolean);
|
|
7101
|
+
const configuredEscrowAddresses = (addresses.escrowAddresses ?? []).map((value) => toAddress(value)).filter((value) => Boolean(value));
|
|
7102
|
+
const configuredOrchestratorAddresses = (addresses.orchestratorAddresses ?? []).map((value) => toAddress(value)).filter((value) => Boolean(value));
|
|
6786
7103
|
this.escrowAddresses = uniqAddresses([
|
|
6787
7104
|
this.escrowV2Address ?? toAddress(addresses.escrow),
|
|
6788
7105
|
...configuredEscrowAddresses
|
|
@@ -6848,8 +7165,7 @@ var Zkp2pClient = class {
|
|
|
6848
7165
|
orchestratorV2Abi: this.orchestratorV2Abi,
|
|
6849
7166
|
orchestratorAddresses: this.orchestratorAddresses
|
|
6850
7167
|
});
|
|
6851
|
-
|
|
6852
|
-
if (maybeUsdc) this._usdcAddress = maybeUsdc;
|
|
7168
|
+
if (addresses.usdc) this._usdcAddress = addresses.usdc;
|
|
6853
7169
|
const runtimeToIndexerEnv = {
|
|
6854
7170
|
production: "PRODUCTION",
|
|
6855
7171
|
preproduction: "PREPRODUCTION",
|
|
@@ -6925,6 +7241,15 @@ var Zkp2pClient = class {
|
|
|
6925
7241
|
getPvIntent: (intentHash) => this.getPvIntent(intentHash)
|
|
6926
7242
|
}
|
|
6927
7243
|
});
|
|
7244
|
+
this._referralOps = new ReferralAccountOperations({
|
|
7245
|
+
getWalletClient: () => this.walletClient,
|
|
7246
|
+
getChainId: () => this.chainId,
|
|
7247
|
+
getRuntimeEnv: () => this.runtimeEnv,
|
|
7248
|
+
getBaseApiUrl: () => this.baseApiUrl,
|
|
7249
|
+
getApiTimeoutMs: () => this.apiTimeoutMs,
|
|
7250
|
+
getAuthorizationToken: () => this.authorizationToken,
|
|
7251
|
+
getAuthorizationTokenProvider: () => this.getAuthorizationToken
|
|
7252
|
+
});
|
|
6928
7253
|
}
|
|
6929
7254
|
isValidHexAddress(addr) {
|
|
6930
7255
|
return isValidHexAddress(addr);
|
|
@@ -6962,22 +7287,12 @@ var Zkp2pClient = class {
|
|
|
6962
7287
|
`attestationServiceUrl is required when baseApiUrl is not a supported zkp2p API host: ${baseApiUrl}`
|
|
6963
7288
|
);
|
|
6964
7289
|
}
|
|
6965
|
-
async resolveAuthorizationToken(
|
|
6966
|
-
if (
|
|
6967
|
-
return
|
|
6968
|
-
}
|
|
6969
|
-
const provider = opts?.getAuthorizationToken ?? this.getAuthorizationToken;
|
|
6970
|
-
if (provider) {
|
|
6971
|
-
return await provider() ?? void 0;
|
|
7290
|
+
async resolveAuthorizationToken() {
|
|
7291
|
+
if (this.getAuthorizationToken) {
|
|
7292
|
+
return await this.getAuthorizationToken() ?? void 0;
|
|
6972
7293
|
}
|
|
6973
7294
|
return this.authorizationToken;
|
|
6974
7295
|
}
|
|
6975
|
-
normalizeOracleRateConfig(config) {
|
|
6976
|
-
return normalizeOracleRateConfig(config);
|
|
6977
|
-
}
|
|
6978
|
-
escrowCurrencyHasOracleConfig(abi) {
|
|
6979
|
-
return escrowCurrencyHasOracleConfig(abi);
|
|
6980
|
-
}
|
|
6981
7296
|
/**
|
|
6982
7297
|
* Normalizes currency tuples by appending an empty `oracleRateConfig` when the ABI
|
|
6983
7298
|
* requires it and the caller hasn't provided one.
|
|
@@ -6990,21 +7305,9 @@ var Zkp2pClient = class {
|
|
|
6990
7305
|
escrowAddress: params?.escrowAddress
|
|
6991
7306
|
});
|
|
6992
7307
|
}
|
|
6993
|
-
parseManagerFeeFromRead(result) {
|
|
6994
|
-
return parseManagerFeeFromRead(result);
|
|
6995
|
-
}
|
|
6996
|
-
getAbiFunction(abi, ...names) {
|
|
6997
|
-
return getAbiFunction(abi, ...names);
|
|
6998
|
-
}
|
|
6999
7308
|
resolveAbiFunctionName(abi, names) {
|
|
7000
7309
|
return resolveAbiFunctionName(abi, names);
|
|
7001
7310
|
}
|
|
7002
|
-
abiTupleHasComponent(abi, functionName, componentName) {
|
|
7003
|
-
return abiTupleHasComponent(abi, functionName, componentName);
|
|
7004
|
-
}
|
|
7005
|
-
abiFunctionHasInput(abi, functionName, inputName) {
|
|
7006
|
-
return abiFunctionHasInput(abi, functionName, inputName);
|
|
7007
|
-
}
|
|
7008
7311
|
resolveEscrowAddressOrThrow(escrowAddress, depositId, _methodName) {
|
|
7009
7312
|
const resolved = escrowAddress ?? this.parseEscrowAddressFromCompositeDepositId(depositId);
|
|
7010
7313
|
if (resolved) return resolved;
|
|
@@ -7130,7 +7433,7 @@ var Zkp2pClient = class {
|
|
|
7130
7433
|
async lookupIntentEscrowOnchain(intentHash) {
|
|
7131
7434
|
try {
|
|
7132
7435
|
const view = await this.getPvIntent(intentHash);
|
|
7133
|
-
return this.normalizeAddress(view
|
|
7436
|
+
return this.normalizeAddress(view.intent.escrow);
|
|
7134
7437
|
} catch {
|
|
7135
7438
|
return void 0;
|
|
7136
7439
|
}
|
|
@@ -7195,6 +7498,15 @@ var Zkp2pClient = class {
|
|
|
7195
7498
|
if (fallback) return fallback;
|
|
7196
7499
|
throw new Error("Orchestrator not available");
|
|
7197
7500
|
}
|
|
7501
|
+
/**
|
|
7502
|
+
* Spread helper for viem requests.
|
|
7503
|
+
* justified: TxOverrides mixes legacy gasPrice with EIP-1559 fee fields, which
|
|
7504
|
+
* viem's discriminated request unions reject; keep the suppression in one place.
|
|
7505
|
+
*/
|
|
7506
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7507
|
+
applyTxOverrides(overrides) {
|
|
7508
|
+
return overrides;
|
|
7509
|
+
}
|
|
7198
7510
|
/**
|
|
7199
7511
|
* Simulate a contract call (validation only) and send with ERC-8021 attribution.
|
|
7200
7512
|
* Referrer codes are stripped from overrides for simulation and appended to calldata.
|
|
@@ -7207,7 +7519,7 @@ var Zkp2pClient = class {
|
|
|
7207
7519
|
functionName: opts.functionName,
|
|
7208
7520
|
args: opts.args ?? [],
|
|
7209
7521
|
account: this.walletClient.account,
|
|
7210
|
-
...txOverrides
|
|
7522
|
+
...this.applyTxOverrides(txOverrides)
|
|
7211
7523
|
});
|
|
7212
7524
|
return sendTransactionWithAttribution(
|
|
7213
7525
|
this.walletClient,
|
|
@@ -7234,7 +7546,7 @@ var Zkp2pClient = class {
|
|
|
7234
7546
|
functionName: prepared.functionName,
|
|
7235
7547
|
args: prepared.args,
|
|
7236
7548
|
account: this.walletClient.account,
|
|
7237
|
-
...overrides
|
|
7549
|
+
...this.applyTxOverrides(overrides)
|
|
7238
7550
|
});
|
|
7239
7551
|
return this.walletClient.sendTransaction({
|
|
7240
7552
|
to: prepared.to,
|
|
@@ -7242,7 +7554,7 @@ var Zkp2pClient = class {
|
|
|
7242
7554
|
value: prepared.value,
|
|
7243
7555
|
account: this.walletClient.account,
|
|
7244
7556
|
chain: this.walletClient.chain,
|
|
7245
|
-
...overrides
|
|
7557
|
+
...this.applyTxOverrides(overrides)
|
|
7246
7558
|
});
|
|
7247
7559
|
}
|
|
7248
7560
|
prepareEscrowTransaction(opts) {
|
|
@@ -7848,20 +8160,18 @@ var Zkp2pClient = class {
|
|
|
7848
8160
|
if (params.processorNames.length !== payeeData.length) {
|
|
7849
8161
|
throw new Error("processorNames and payeeData length mismatch");
|
|
7850
8162
|
}
|
|
7851
|
-
const baseApiUrl = (this.baseApiUrl ??
|
|
8163
|
+
const baseApiUrl = (this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(/\/$/, "");
|
|
7852
8164
|
const depositDetails = params.processorNames.map(
|
|
7853
8165
|
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
7854
8166
|
);
|
|
7855
8167
|
const apiResponses = await Promise.all(
|
|
7856
8168
|
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
7857
8169
|
);
|
|
7858
|
-
if (!apiResponses.every((r) => r
|
|
7859
|
-
const failed = apiResponses.find((r) => !r
|
|
8170
|
+
if (!apiResponses.every((r) => r.success)) {
|
|
8171
|
+
const failed = apiResponses.find((r) => !r.success);
|
|
7860
8172
|
throw new Error(failed?.message || "Failed to register payee details");
|
|
7861
8173
|
}
|
|
7862
|
-
const hashedOnchainIds = apiResponses.map(
|
|
7863
|
-
(r) => r.responseObject?.hashedOnchainId
|
|
7864
|
-
);
|
|
8174
|
+
const hashedOnchainIds = apiResponses.map((r) => r.responseObject.hashedOnchainId);
|
|
7865
8175
|
return { depositDetails, hashedOnchainIds };
|
|
7866
8176
|
}
|
|
7867
8177
|
/**
|
|
@@ -7985,17 +8295,15 @@ var Zkp2pClient = class {
|
|
|
7985
8295
|
}
|
|
7986
8296
|
hashedOnchainIds = payeeDetailsHashes;
|
|
7987
8297
|
} else {
|
|
7988
|
-
const baseApiUrl = (this.baseApiUrl ??
|
|
8298
|
+
const baseApiUrl = (this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(/\/$/, "");
|
|
7989
8299
|
const apiResponses = await Promise.all(
|
|
7990
8300
|
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
7991
8301
|
);
|
|
7992
|
-
if (!apiResponses.every((r) => r
|
|
7993
|
-
const failed = apiResponses.find((r) => !r
|
|
8302
|
+
if (!apiResponses.every((r) => r.success)) {
|
|
8303
|
+
const failed = apiResponses.find((r) => !r.success);
|
|
7994
8304
|
throw new Error(failed?.message || "Failed to create deposit details");
|
|
7995
8305
|
}
|
|
7996
|
-
hashedOnchainIds = apiResponses.map(
|
|
7997
|
-
(r) => r.responseObject?.hashedOnchainId
|
|
7998
|
-
);
|
|
8306
|
+
hashedOnchainIds = apiResponses.map((r) => r.responseObject.hashedOnchainId);
|
|
7999
8307
|
}
|
|
8000
8308
|
paymentMethodData = hashedOnchainIds.map((hid) => ({
|
|
8001
8309
|
intentGatingService,
|
|
@@ -8017,10 +8325,10 @@ var Zkp2pClient = class {
|
|
|
8017
8325
|
}
|
|
8018
8326
|
});
|
|
8019
8327
|
const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await import('./currency-MARF3D2J.mjs');
|
|
8020
|
-
|
|
8021
|
-
|
|
8328
|
+
currencies = mapConversionRatesToOnchainMinRate2(
|
|
8329
|
+
params.conversionRates,
|
|
8330
|
+
paymentMethods.length
|
|
8022
8331
|
);
|
|
8023
|
-
currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
|
|
8024
8332
|
}
|
|
8025
8333
|
const escrowContext = this.resolveEscrowContext({
|
|
8026
8334
|
escrowAddress: params.escrowAddress
|
|
@@ -8112,9 +8420,6 @@ var Zkp2pClient = class {
|
|
|
8112
8420
|
async prepareFulfillIntent(params) {
|
|
8113
8421
|
return this._intentOps.prepareFulfillIntent(params);
|
|
8114
8422
|
}
|
|
8115
|
-
defaultAttestationService() {
|
|
8116
|
-
return this._intentOps.defaultAttestationService();
|
|
8117
|
-
}
|
|
8118
8423
|
// ───────────────────────────────────────────────────────────────────────────
|
|
8119
8424
|
// SUPPORTING: QUOTES API
|
|
8120
8425
|
// (Used by frontends to find available liquidity)
|
|
@@ -8162,7 +8467,7 @@ var Zkp2pClient = class {
|
|
|
8162
8467
|
*/
|
|
8163
8468
|
async getQuote(req, opts) {
|
|
8164
8469
|
const referrerFeeConfig = assertValidReferrerFeeConfig(req.referrerFeeConfig, "getQuote");
|
|
8165
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
8470
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8166
8471
|
/\/$/,
|
|
8167
8472
|
""
|
|
8168
8473
|
);
|
|
@@ -8177,9 +8482,8 @@ var Zkp2pClient = class {
|
|
|
8177
8482
|
const quote = await apiGetQuote(reqWithEscrow, baseApiUrl, timeoutMs, this.apiKey);
|
|
8178
8483
|
const quotes = quote?.responseObject?.quotes ?? [];
|
|
8179
8484
|
for (const q of quotes) {
|
|
8180
|
-
const
|
|
8181
|
-
|
|
8182
|
-
if (payeeData && typeof q === "object") {
|
|
8485
|
+
const payeeData = normalizeQuotePayeeData(q.maker);
|
|
8486
|
+
if (payeeData) {
|
|
8183
8487
|
q.payeeData = payeeData;
|
|
8184
8488
|
}
|
|
8185
8489
|
}
|
|
@@ -8200,7 +8504,7 @@ var Zkp2pClient = class {
|
|
|
8200
8504
|
req.referrerFeeConfig,
|
|
8201
8505
|
"getQuotesBestByPlatform"
|
|
8202
8506
|
);
|
|
8203
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
8507
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8204
8508
|
/\/$/,
|
|
8205
8509
|
""
|
|
8206
8510
|
);
|
|
@@ -8249,7 +8553,7 @@ var Zkp2pClient = class {
|
|
|
8249
8553
|
* @returns Taker tier response
|
|
8250
8554
|
*/
|
|
8251
8555
|
async getTakerTier(req, opts) {
|
|
8252
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
8556
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
8253
8557
|
/\/$/,
|
|
8254
8558
|
""
|
|
8255
8559
|
);
|
|
@@ -8257,49 +8561,62 @@ var Zkp2pClient = class {
|
|
|
8257
8561
|
return apiGetTakerTier(req, baseApiUrl, timeoutMs);
|
|
8258
8562
|
}
|
|
8259
8563
|
/**
|
|
8260
|
-
* Fetch
|
|
8261
|
-
*
|
|
8564
|
+
* Fetch a referral dashboard. Pass `address` for a public wallet-keyed read;
|
|
8565
|
+
* omit it to use the authenticated caller mode.
|
|
8262
8566
|
*/
|
|
8263
8567
|
async getReferralDashboard(opts) {
|
|
8264
|
-
|
|
8265
|
-
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
8266
|
-
);
|
|
8267
|
-
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8268
|
-
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
8269
|
-
return apiGetReferralDashboard({ baseApiUrl, timeoutMs, authorizationToken });
|
|
8568
|
+
return this._referralOps.getReferralDashboard(opts);
|
|
8270
8569
|
}
|
|
8271
8570
|
/**
|
|
8272
|
-
* Fetch
|
|
8571
|
+
* Fetch referral earnings. Pass `address` for a public wallet-keyed read;
|
|
8572
|
+
* omit it to use the authenticated caller mode.
|
|
8273
8573
|
*/
|
|
8274
8574
|
async getReferralEarnings(opts) {
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8575
|
+
return this._referralOps.getReferralEarnings(opts);
|
|
8576
|
+
}
|
|
8577
|
+
/**
|
|
8578
|
+
* Publicly look up a referral code's owner wallet and active status.
|
|
8579
|
+
*/
|
|
8580
|
+
async lookupReferralCode(code, opts) {
|
|
8581
|
+
return this._referralOps.lookupReferralCode(code, opts);
|
|
8281
8582
|
}
|
|
8282
8583
|
/**
|
|
8283
|
-
*
|
|
8584
|
+
* Create or fetch the authenticated caller's referral code with bearer auth.
|
|
8585
|
+
*/
|
|
8586
|
+
async createReferralCode(opts) {
|
|
8587
|
+
return this._referralOps.createReferralCode(opts);
|
|
8588
|
+
}
|
|
8589
|
+
/**
|
|
8590
|
+
* Create or fetch the wallet's referral code with EIP-712 signature auth.
|
|
8591
|
+
*/
|
|
8592
|
+
async createReferralCodeWithSignature(opts) {
|
|
8593
|
+
return this._referralOps.createReferralCodeWithSignature(opts);
|
|
8594
|
+
}
|
|
8595
|
+
/**
|
|
8596
|
+
* Apply another user's referral code with bearer auth.
|
|
8284
8597
|
*/
|
|
8285
8598
|
async redeemReferralCode(code, opts) {
|
|
8286
|
-
|
|
8287
|
-
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
8288
|
-
);
|
|
8289
|
-
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8290
|
-
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
8291
|
-
return apiRedeemReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
8599
|
+
return this._referralOps.redeemReferralCode(code, opts);
|
|
8292
8600
|
}
|
|
8293
8601
|
/**
|
|
8294
|
-
*
|
|
8602
|
+
* Apply another user's referral code with EIP-712 signature auth. If
|
|
8603
|
+
* `referrerWalletAddress` is omitted, the SDK looks up the code first and signs
|
|
8604
|
+
* the current owner wallet into the redeem payload.
|
|
8605
|
+
*/
|
|
8606
|
+
async redeemReferralCodeWithSignature(code, opts) {
|
|
8607
|
+
return this._referralOps.redeemReferralCodeWithSignature(code, opts);
|
|
8608
|
+
}
|
|
8609
|
+
/**
|
|
8610
|
+
* Customize the authenticated caller's referral code with bearer auth.
|
|
8295
8611
|
*/
|
|
8296
8612
|
async updateReferralCode(code, opts) {
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8613
|
+
return this._referralOps.updateReferralCode(code, opts);
|
|
8614
|
+
}
|
|
8615
|
+
/**
|
|
8616
|
+
* Customize the wallet's referral code with EIP-712 signature auth.
|
|
8617
|
+
*/
|
|
8618
|
+
async updateReferralCodeWithSignature(code, opts) {
|
|
8619
|
+
return this._referralOps.updateReferralCodeWithSignature(code, opts);
|
|
8303
8620
|
}
|
|
8304
8621
|
/**
|
|
8305
8622
|
* The signed `credentialValidatedAt` field is an upload-time freshness witness minted by
|
|
@@ -8321,46 +8638,17 @@ var Zkp2pClient = class {
|
|
|
8321
8638
|
const attestationServiceUrl = this.stripTrailingSlash(
|
|
8322
8639
|
opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
|
|
8323
8640
|
);
|
|
8324
|
-
const createBundle = (uploadPayload) =>
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
opts.attestationRuntime,
|
|
8333
|
-
requestOptions
|
|
8334
|
-
);
|
|
8335
|
-
}
|
|
8336
|
-
if (opts?.attestationRuntime) {
|
|
8337
|
-
return apiCreateSellerCredentialBundle(
|
|
8338
|
-
uploadPayload,
|
|
8339
|
-
attestationServiceUrl,
|
|
8340
|
-
params.platform,
|
|
8341
|
-
timeoutMs,
|
|
8342
|
-
opts.attestationRuntime
|
|
8343
|
-
);
|
|
8344
|
-
}
|
|
8345
|
-
if (requestOptions) {
|
|
8346
|
-
return apiCreateSellerCredentialBundle(
|
|
8347
|
-
uploadPayload,
|
|
8348
|
-
attestationServiceUrl,
|
|
8349
|
-
params.platform,
|
|
8350
|
-
timeoutMs,
|
|
8351
|
-
void 0,
|
|
8352
|
-
requestOptions
|
|
8353
|
-
);
|
|
8354
|
-
}
|
|
8355
|
-
return apiCreateSellerCredentialBundle(
|
|
8356
|
-
uploadPayload,
|
|
8357
|
-
attestationServiceUrl,
|
|
8358
|
-
params.platform,
|
|
8359
|
-
timeoutMs
|
|
8360
|
-
);
|
|
8361
|
-
};
|
|
8641
|
+
const createBundle = (uploadPayload) => apiCreateSellerCredentialBundle(
|
|
8642
|
+
uploadPayload,
|
|
8643
|
+
attestationServiceUrl,
|
|
8644
|
+
params.platform,
|
|
8645
|
+
timeoutMs,
|
|
8646
|
+
opts?.attestationRuntime,
|
|
8647
|
+
opts?.attestationServiceFallbackUrls ? { fallbackUrls: opts.attestationServiceFallbackUrls } : void 0
|
|
8648
|
+
);
|
|
8362
8649
|
if (params.platform === "wise") {
|
|
8363
8650
|
const bundleResponse2 = await createBundle({
|
|
8651
|
+
...params.callerAddress ? { callerAddress: params.callerAddress } : {},
|
|
8364
8652
|
sessionMaterial: params.sessionMaterial
|
|
8365
8653
|
});
|
|
8366
8654
|
if (!bundleResponse2.success || !bundleResponse2.responseObject) {
|
|
@@ -8375,6 +8663,7 @@ var Zkp2pClient = class {
|
|
|
8375
8663
|
);
|
|
8376
8664
|
}
|
|
8377
8665
|
const bundlePayload = {
|
|
8666
|
+
...params.callerAddress ? { callerAddress: params.callerAddress } : {},
|
|
8378
8667
|
payeeId: params.payeeId,
|
|
8379
8668
|
sessionMaterial: params.sessionMaterial
|
|
8380
8669
|
};
|
|
@@ -8401,7 +8690,8 @@ var Zkp2pClient = class {
|
|
|
8401
8690
|
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
8402
8691
|
);
|
|
8403
8692
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8404
|
-
|
|
8693
|
+
const authorizationToken = await this.resolveAuthorizationToken();
|
|
8694
|
+
return apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs, authorizationToken);
|
|
8405
8695
|
}
|
|
8406
8696
|
/**
|
|
8407
8697
|
* Upload a seller Gmail OAuth authorization code through curator.
|
|
@@ -8504,19 +8794,6 @@ var Zkp2pClient = class {
|
|
|
8504
8794
|
protocolViewerFunctionInputCount(functionName) {
|
|
8505
8795
|
return this._pvReader.protocolViewerFunctionInputCount(functionName);
|
|
8506
8796
|
}
|
|
8507
|
-
/**
|
|
8508
|
-
* Returns the input count for a function on a specific PV entry's ABI.
|
|
8509
|
-
* Used to branch between 1-input (V1) and 2-input (V2) PV call signatures.
|
|
8510
|
-
*/
|
|
8511
|
-
pvEntryFunctionInputCount(entry, functionName) {
|
|
8512
|
-
return this._pvReader.pvEntryFunctionInputCount(entry, functionName);
|
|
8513
|
-
}
|
|
8514
|
-
isZeroAddressValue(value) {
|
|
8515
|
-
return this._pvReader.isZeroAddressValue(value);
|
|
8516
|
-
}
|
|
8517
|
-
toBigIntOrZero(value, fieldName = "numeric field") {
|
|
8518
|
-
return this._pvReader.toBigIntOrZero(value, fieldName);
|
|
8519
|
-
}
|
|
8520
8797
|
buildProtocolViewerContexts(options) {
|
|
8521
8798
|
return this._pvReader.buildProtocolViewerContexts(options);
|
|
8522
8799
|
}
|
|
@@ -8529,9 +8806,6 @@ var Zkp2pClient = class {
|
|
|
8529
8806
|
buildDepositViewFromEscrowDeposit(rawDeposit, depositId) {
|
|
8530
8807
|
return this._pvReader.buildDepositViewFromEscrowDeposit(rawDeposit, depositId);
|
|
8531
8808
|
}
|
|
8532
|
-
convertIndexerDepositToPvView(deposit) {
|
|
8533
|
-
return this._pvReader.convertIndexerDepositToPvView(deposit);
|
|
8534
|
-
}
|
|
8535
8809
|
async getPvAccountDepositsFromIndexer(owner) {
|
|
8536
8810
|
return this._pvReader.getPvAccountDepositsFromIndexer(owner);
|
|
8537
8811
|
}
|
|
@@ -8687,6 +8961,6 @@ var createPeerExtensionSdk = (options = {}) => ({
|
|
|
8687
8961
|
});
|
|
8688
8962
|
var peerExtensionSdk = createPeerExtensionSdk();
|
|
8689
8963
|
|
|
8690
|
-
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, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetReferralDashboard, apiGetReferralEarnings, apiGetTakerTier, apiPostDepositDetails, apiRedeemReferralCode, apiRequestIdentityAttestation, apiUpdateReferralCode, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, apiVerifyBuyerTeePayment, appendAttributionToCalldata, assertValidReferrerFeeConfig, 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 };
|
|
8964
|
+
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, REFERRAL_SIGNATURE_DOMAIN, REFERRAL_SIGNATURE_TYPES, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiCreateReferralCode, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetReferralDashboard, apiGetReferralEarnings, apiGetTakerTier, apiLookupReferralCode, apiPostDepositDetails, apiRedeemReferralCode, apiRequestIdentityAttestation, apiUpdateReferralCode, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, apiVerifyBuyerTeePayment, appendAttributionToCalldata, assertValidReferrerFeeConfig, 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 };
|
|
8691
8965
|
//# sourceMappingURL=index.mjs.map
|
|
8692
8966
|
//# sourceMappingURL=index.mjs.map
|