@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.cjs
CHANGED
|
@@ -42469,6 +42469,7 @@ async function createEncryptedSellerCredentialUploadForPlatform({
|
|
|
42469
42469
|
return zkp2pAttestation.createEncryptedSellerCredentialUpload({
|
|
42470
42470
|
attestationServiceUrl,
|
|
42471
42471
|
platform: "wise",
|
|
42472
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {},
|
|
42472
42473
|
sessionMaterial: payload.sessionMaterial,
|
|
42473
42474
|
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
42474
42475
|
fetch: attestationTransport.fetch,
|
|
@@ -42482,6 +42483,7 @@ async function createEncryptedSellerCredentialUploadForPlatform({
|
|
|
42482
42483
|
return zkp2pAttestation.createEncryptedSellerCredentialUpload({
|
|
42483
42484
|
attestationServiceUrl,
|
|
42484
42485
|
platform,
|
|
42486
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {},
|
|
42485
42487
|
payeeId: payload.payeeId,
|
|
42486
42488
|
sessionMaterial: payload.sessionMaterial,
|
|
42487
42489
|
...typeof timeoutMs === "number" ? { timeoutMs } : {},
|
|
@@ -42610,7 +42612,10 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
|
|
|
42610
42612
|
res = await attestationTransport.fetch(`${activeBaseUrl}${endpoint}`, {
|
|
42611
42613
|
method: "POST",
|
|
42612
42614
|
headers: headers(),
|
|
42613
|
-
body: JSON.stringify({
|
|
42615
|
+
body: JSON.stringify({
|
|
42616
|
+
encryptedUpload,
|
|
42617
|
+
...payload.callerAddress ? { callerAddress: payload.callerAddress } : {}
|
|
42618
|
+
})
|
|
42614
42619
|
});
|
|
42615
42620
|
} catch (error) {
|
|
42616
42621
|
throw new exports.NetworkError("Failed to connect to Attestation Service", {
|
|
@@ -43081,6 +43086,44 @@ function resolvePlatformAttestationConfig(platformName) {
|
|
|
43081
43086
|
return config;
|
|
43082
43087
|
}
|
|
43083
43088
|
|
|
43089
|
+
// src/utils/logger.ts
|
|
43090
|
+
var currentLevel = "info";
|
|
43091
|
+
function setLogLevel(level) {
|
|
43092
|
+
currentLevel = level;
|
|
43093
|
+
}
|
|
43094
|
+
function shouldLog(level) {
|
|
43095
|
+
switch (currentLevel) {
|
|
43096
|
+
case "debug":
|
|
43097
|
+
return true;
|
|
43098
|
+
case "info":
|
|
43099
|
+
return level !== "debug";
|
|
43100
|
+
case "error":
|
|
43101
|
+
return level === "error";
|
|
43102
|
+
default:
|
|
43103
|
+
return true;
|
|
43104
|
+
}
|
|
43105
|
+
}
|
|
43106
|
+
var logger = {
|
|
43107
|
+
debug: (...args) => {
|
|
43108
|
+
if (shouldLog("debug")) {
|
|
43109
|
+
console.log("[DEBUG]", ...args);
|
|
43110
|
+
}
|
|
43111
|
+
},
|
|
43112
|
+
info: (...args) => {
|
|
43113
|
+
if (shouldLog("info")) {
|
|
43114
|
+
console.log("[INFO]", ...args);
|
|
43115
|
+
}
|
|
43116
|
+
},
|
|
43117
|
+
warn: (...args) => {
|
|
43118
|
+
if (shouldLog("info")) {
|
|
43119
|
+
console.warn("[WARN]", ...args);
|
|
43120
|
+
}
|
|
43121
|
+
},
|
|
43122
|
+
error: (...args) => {
|
|
43123
|
+
console.error("[ERROR]", ...args);
|
|
43124
|
+
}
|
|
43125
|
+
};
|
|
43126
|
+
|
|
43084
43127
|
// src/client/IntentOperations.ts
|
|
43085
43128
|
var INTENT_MIN_AT_SIGNAL_ABI = [
|
|
43086
43129
|
{
|
|
@@ -43594,16 +43637,24 @@ var IntentOperations = class {
|
|
|
43594
43637
|
async readIntentMinAtSignal(intentHash, orchestratorAddress) {
|
|
43595
43638
|
const address = orchestratorAddress ?? this.config.getOrchestratorV2Address();
|
|
43596
43639
|
if (!address) return void 0;
|
|
43640
|
+
const read = async () => this.config.getPublicClient().readContract({
|
|
43641
|
+
address,
|
|
43642
|
+
abi: INTENT_MIN_AT_SIGNAL_ABI,
|
|
43643
|
+
functionName: "getIntentMinAtSignal",
|
|
43644
|
+
args: [intentHash]
|
|
43645
|
+
});
|
|
43597
43646
|
try {
|
|
43598
|
-
|
|
43599
|
-
|
|
43600
|
-
|
|
43601
|
-
|
|
43602
|
-
|
|
43603
|
-
|
|
43604
|
-
|
|
43605
|
-
|
|
43606
|
-
|
|
43647
|
+
return (await read()).toString();
|
|
43648
|
+
} catch (error) {
|
|
43649
|
+
logger.warn(
|
|
43650
|
+
`[sdk] getIntentMinAtSignal read failed for ${intentHash}; retrying once`,
|
|
43651
|
+
error instanceof Error ? error.message : error
|
|
43652
|
+
);
|
|
43653
|
+
try {
|
|
43654
|
+
return (await read()).toString();
|
|
43655
|
+
} catch {
|
|
43656
|
+
return void 0;
|
|
43657
|
+
}
|
|
43607
43658
|
}
|
|
43608
43659
|
}
|
|
43609
43660
|
};
|
|
@@ -44307,478 +44358,165 @@ var ProtocolViewerReader = class {
|
|
|
44307
44358
|
}
|
|
44308
44359
|
};
|
|
44309
44360
|
|
|
44310
|
-
// src/
|
|
44311
|
-
|
|
44312
|
-
|
|
44313
|
-
|
|
44361
|
+
// src/adapters/api.ts
|
|
44362
|
+
init_errors();
|
|
44363
|
+
|
|
44364
|
+
// src/indexer/client.ts
|
|
44365
|
+
var IndexerHttpError = class extends Error {
|
|
44366
|
+
constructor(status, statusText, options) {
|
|
44367
|
+
super(`Indexer request failed: ${status} ${statusText}`);
|
|
44368
|
+
this.name = "IndexerHttpError";
|
|
44369
|
+
this.status = status;
|
|
44370
|
+
this.retryAfterSeconds = options?.retryAfterSeconds;
|
|
44314
44371
|
}
|
|
44315
|
-
|
|
44316
|
-
|
|
44317
|
-
|
|
44318
|
-
|
|
44319
|
-
|
|
44372
|
+
};
|
|
44373
|
+
function parseRetryAfterSeconds(rawHeader) {
|
|
44374
|
+
if (!rawHeader) return void 0;
|
|
44375
|
+
const parsedSeconds = Number(rawHeader);
|
|
44376
|
+
if (Number.isFinite(parsedSeconds) && parsedSeconds >= 0) {
|
|
44377
|
+
return Math.ceil(parsedSeconds);
|
|
44320
44378
|
}
|
|
44321
|
-
|
|
44322
|
-
|
|
44323
|
-
|
|
44324
|
-
|
|
44325
|
-
|
|
44326
|
-
|
|
44327
|
-
|
|
44328
|
-
|
|
44329
|
-
|
|
44330
|
-
|
|
44331
|
-
|
|
44332
|
-
|
|
44333
|
-
|
|
44334
|
-
|
|
44379
|
+
const parsedDateMs = Date.parse(rawHeader);
|
|
44380
|
+
if (!Number.isFinite(parsedDateMs)) return void 0;
|
|
44381
|
+
const secondsUntilRetry = Math.ceil((parsedDateMs - Date.now()) / 1e3);
|
|
44382
|
+
return Math.max(0, secondsUntilRetry);
|
|
44383
|
+
}
|
|
44384
|
+
function createAbortError() {
|
|
44385
|
+
const error = new Error("The operation was aborted");
|
|
44386
|
+
error.name = "AbortError";
|
|
44387
|
+
return error;
|
|
44388
|
+
}
|
|
44389
|
+
function delay(ms, signal) {
|
|
44390
|
+
if (ms <= 0) {
|
|
44391
|
+
return Promise.resolve();
|
|
44392
|
+
}
|
|
44393
|
+
return new Promise((resolve, reject) => {
|
|
44394
|
+
if (signal?.aborted) {
|
|
44395
|
+
reject(createAbortError());
|
|
44396
|
+
return;
|
|
44335
44397
|
}
|
|
44336
|
-
|
|
44337
|
-
|
|
44338
|
-
|
|
44398
|
+
const timer = setTimeout(() => {
|
|
44399
|
+
signal?.removeEventListener("abort", onAbort);
|
|
44400
|
+
resolve();
|
|
44401
|
+
}, ms);
|
|
44402
|
+
const onAbort = () => {
|
|
44403
|
+
clearTimeout(timer);
|
|
44404
|
+
signal?.removeEventListener("abort", onAbort);
|
|
44405
|
+
reject(createAbortError());
|
|
44339
44406
|
};
|
|
44407
|
+
signal?.addEventListener("abort", onAbort);
|
|
44408
|
+
});
|
|
44409
|
+
}
|
|
44410
|
+
var IndexerClient = class {
|
|
44411
|
+
constructor(endpoint, options = {}) {
|
|
44412
|
+
this.endpoint = endpoint;
|
|
44413
|
+
this.options = options;
|
|
44414
|
+
this.hasLoggedTokenProviderError = false;
|
|
44340
44415
|
}
|
|
44341
|
-
|
|
44342
|
-
|
|
44343
|
-
|
|
44344
|
-
|
|
44416
|
+
async resolveAuthorizationToken() {
|
|
44417
|
+
if (this.options.getAuthorizationToken) {
|
|
44418
|
+
try {
|
|
44419
|
+
const token = await this.options.getAuthorizationToken();
|
|
44420
|
+
return token ?? void 0;
|
|
44421
|
+
} catch (error) {
|
|
44422
|
+
if (this.options.onAuthorizationTokenError) {
|
|
44423
|
+
this.options.onAuthorizationTokenError(error);
|
|
44424
|
+
} else if (!this.hasLoggedTokenProviderError) {
|
|
44425
|
+
this.hasLoggedTokenProviderError = true;
|
|
44426
|
+
console.warn(
|
|
44427
|
+
"[IndexerClient] getAuthorizationToken failed; continuing without Authorization header",
|
|
44428
|
+
error
|
|
44429
|
+
);
|
|
44430
|
+
}
|
|
44431
|
+
return void 0;
|
|
44432
|
+
}
|
|
44345
44433
|
}
|
|
44346
|
-
return
|
|
44347
|
-
`${reason}. Rate manager contracts failed to initialize: ${initError.message}`
|
|
44348
|
-
);
|
|
44434
|
+
return this.options.authorizationToken;
|
|
44349
44435
|
}
|
|
44350
|
-
|
|
44351
|
-
const
|
|
44352
|
-
const
|
|
44353
|
-
|
|
44354
|
-
"
|
|
44355
|
-
"depositHook"
|
|
44356
|
-
);
|
|
44357
|
-
const includeMinLiquidity = abiTupleHasComponent(
|
|
44358
|
-
registryAbi,
|
|
44359
|
-
"createRateManager",
|
|
44360
|
-
"minLiquidity"
|
|
44361
|
-
);
|
|
44362
|
-
const result = {
|
|
44363
|
-
manager: config.manager,
|
|
44364
|
-
feeRecipient: config.feeRecipient,
|
|
44365
|
-
maxFee: config.maxFee,
|
|
44366
|
-
fee: config.fee
|
|
44367
|
-
};
|
|
44368
|
-
if (includeDepositHook) {
|
|
44369
|
-
result.depositHook = config.depositHook ?? ZERO_ADDRESS;
|
|
44436
|
+
async _post(request, init) {
|
|
44437
|
+
const token = await this.resolveAuthorizationToken();
|
|
44438
|
+
const headers2 = new Headers(init?.headers);
|
|
44439
|
+
if (!headers2.has("Content-Type")) {
|
|
44440
|
+
headers2.set("Content-Type", "application/json");
|
|
44370
44441
|
}
|
|
44371
|
-
if (
|
|
44372
|
-
|
|
44442
|
+
if (token && !headers2.has("Authorization")) {
|
|
44443
|
+
headers2.set("Authorization", token.startsWith("Bearer ") ? token : `Bearer ${token}`);
|
|
44373
44444
|
}
|
|
44374
|
-
|
|
44375
|
-
|
|
44376
|
-
return result;
|
|
44377
|
-
}
|
|
44378
|
-
buildSetRateManagerConfigArgs(params) {
|
|
44379
|
-
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
44380
|
-
const includeHook = abiFunctionHasInput(registryAbi, "setRateManagerConfig", "_newHook") || abiFunctionHasInput(registryAbi, "setRateManagerConfig", "newHook");
|
|
44381
|
-
if (includeHook) {
|
|
44382
|
-
return [
|
|
44383
|
-
params.rateManagerId,
|
|
44384
|
-
params.newManager,
|
|
44385
|
-
params.newFeeRecipient,
|
|
44386
|
-
params.newHook ?? ZERO_ADDRESS,
|
|
44387
|
-
params.newName,
|
|
44388
|
-
params.newUri
|
|
44389
|
-
];
|
|
44445
|
+
if (this.options.apiKey && !headers2.has("x-api-key")) {
|
|
44446
|
+
headers2.set("x-api-key", this.options.apiKey);
|
|
44390
44447
|
}
|
|
44391
|
-
|
|
44392
|
-
|
|
44393
|
-
|
|
44394
|
-
|
|
44395
|
-
|
|
44396
|
-
|
|
44397
|
-
];
|
|
44398
|
-
}
|
|
44399
|
-
prepareRateManagerRegistryTransaction(opts) {
|
|
44400
|
-
const contract = this.resolveRateManagerRegistryContract(opts.registry);
|
|
44401
|
-
const functionName = resolveAbiFunctionName(contract.abi, opts.functionNames);
|
|
44402
|
-
return this.config.host.prepareContractTransaction({
|
|
44403
|
-
address: contract.address,
|
|
44404
|
-
abi: contract.abi,
|
|
44405
|
-
functionName,
|
|
44406
|
-
args: opts.args,
|
|
44407
|
-
txOverrides: opts.txOverrides
|
|
44408
|
-
});
|
|
44409
|
-
}
|
|
44410
|
-
prepareCreateRateManagerTransaction(params) {
|
|
44411
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
44412
|
-
functionNames: ["createRateManager"],
|
|
44413
|
-
args: [this.buildCreateRateManagerConfig(params.config)],
|
|
44414
|
-
txOverrides: params.txOverrides
|
|
44415
|
-
});
|
|
44416
|
-
}
|
|
44417
|
-
prepareSetVaultRateTransaction(params) {
|
|
44418
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
44419
|
-
functionNames: ["setRate", "setMinRate"],
|
|
44420
|
-
args: [params.rateManagerId, params.paymentMethodHash, params.currencyHash, params.rate],
|
|
44421
|
-
txOverrides: params.txOverrides
|
|
44422
|
-
});
|
|
44423
|
-
}
|
|
44424
|
-
prepareSetVaultRatesBatchTransaction(params) {
|
|
44425
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
44426
|
-
functionNames: ["setRateBatch", "setMinRatesBatch"],
|
|
44427
|
-
args: [params.rateManagerId, params.paymentMethods, params.currencies, params.rates],
|
|
44428
|
-
txOverrides: params.txOverrides
|
|
44429
|
-
});
|
|
44430
|
-
}
|
|
44431
|
-
prepareSetOracleRateConfigTransaction(params) {
|
|
44432
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44433
|
-
escrowAddress: params.escrowAddress,
|
|
44434
|
-
depositId: params.depositId
|
|
44448
|
+
const res = await fetch(this.endpoint, {
|
|
44449
|
+
method: "POST",
|
|
44450
|
+
headers: headers2,
|
|
44451
|
+
body: JSON.stringify(request),
|
|
44452
|
+
cache: "no-store",
|
|
44453
|
+
...init
|
|
44435
44454
|
});
|
|
44436
|
-
if (
|
|
44437
|
-
throw new
|
|
44455
|
+
if (!res.ok) {
|
|
44456
|
+
throw new IndexerHttpError(res.status, res.statusText, {
|
|
44457
|
+
retryAfterSeconds: parseRetryAfterSeconds(res.headers.get("Retry-After"))
|
|
44458
|
+
});
|
|
44438
44459
|
}
|
|
44439
|
-
const
|
|
44440
|
-
|
|
44441
|
-
|
|
44442
|
-
|
|
44443
|
-
parseRawDepositId(params.depositId),
|
|
44444
|
-
params.paymentMethodHash,
|
|
44445
|
-
params.currencyHash,
|
|
44446
|
-
normalizeOracleRateConfig(params.config)
|
|
44447
|
-
],
|
|
44448
|
-
txOverrides: params.txOverrides,
|
|
44449
|
-
escrowAddress: escrowContext.address,
|
|
44450
|
-
escrowAbi: escrowContext.abi
|
|
44451
|
-
});
|
|
44452
|
-
}
|
|
44453
|
-
prepareRemoveOracleRateConfigTransaction(params) {
|
|
44454
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44455
|
-
escrowAddress: params.escrowAddress,
|
|
44456
|
-
depositId: params.depositId
|
|
44457
|
-
});
|
|
44458
|
-
if (escrowContext.version !== "v2") {
|
|
44459
|
-
throw new Error("removeOracleRateConfig requires EscrowV2");
|
|
44460
|
-
}
|
|
44461
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["removeOracleRateConfig"]);
|
|
44462
|
-
return this.config.host.prepareEscrowTransaction({
|
|
44463
|
-
functionName,
|
|
44464
|
-
args: [parseRawDepositId(params.depositId), params.paymentMethodHash, params.currencyHash],
|
|
44465
|
-
txOverrides: params.txOverrides,
|
|
44466
|
-
escrowAddress: escrowContext.address,
|
|
44467
|
-
escrowAbi: escrowContext.abi
|
|
44468
|
-
});
|
|
44469
|
-
}
|
|
44470
|
-
prepareSetOracleRateConfigBatchTransaction(params) {
|
|
44471
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44472
|
-
escrowAddress: params.escrowAddress,
|
|
44473
|
-
depositId: params.depositId
|
|
44474
|
-
});
|
|
44475
|
-
if (escrowContext.version !== "v2") {
|
|
44476
|
-
throw new Error("setOracleRateConfigBatch requires EscrowV2");
|
|
44477
|
-
}
|
|
44478
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfigBatch"]);
|
|
44479
|
-
return this.config.host.prepareEscrowTransaction({
|
|
44480
|
-
functionName,
|
|
44481
|
-
args: [
|
|
44482
|
-
parseRawDepositId(params.depositId),
|
|
44483
|
-
params.paymentMethods,
|
|
44484
|
-
params.currencies,
|
|
44485
|
-
params.configs.map((group) => group.map((config) => normalizeOracleRateConfig(config)))
|
|
44486
|
-
],
|
|
44487
|
-
txOverrides: params.txOverrides,
|
|
44488
|
-
escrowAddress: escrowContext.address,
|
|
44489
|
-
escrowAbi: escrowContext.abi
|
|
44490
|
-
});
|
|
44491
|
-
}
|
|
44492
|
-
prepareUpdateCurrencyConfigBatchTransaction(params) {
|
|
44493
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44494
|
-
escrowAddress: params.escrowAddress,
|
|
44495
|
-
depositId: params.depositId
|
|
44496
|
-
});
|
|
44497
|
-
if (escrowContext.version !== "v2") {
|
|
44498
|
-
throw new Error("updateCurrencyConfigBatch requires EscrowV2");
|
|
44499
|
-
}
|
|
44500
|
-
const functionName = resolveAbiFunctionName(escrowContext.abi, ["updateCurrencyConfigBatch"]);
|
|
44501
|
-
return this.config.host.prepareEscrowTransaction({
|
|
44502
|
-
functionName,
|
|
44503
|
-
args: [
|
|
44504
|
-
parseRawDepositId(params.depositId),
|
|
44505
|
-
params.paymentMethods,
|
|
44506
|
-
params.updates.map(
|
|
44507
|
-
(group) => group.map((update) => ({
|
|
44508
|
-
code: update.code,
|
|
44509
|
-
minConversionRate: typeof update.minConversionRate === "bigint" ? update.minConversionRate : BigInt(update.minConversionRate),
|
|
44510
|
-
updateOracle: update.updateOracle,
|
|
44511
|
-
oracleRateConfig: normalizeOracleRateConfig(update.oracleRateConfig)
|
|
44512
|
-
}))
|
|
44513
|
-
)
|
|
44514
|
-
],
|
|
44515
|
-
txOverrides: params.txOverrides,
|
|
44516
|
-
escrowAddress: escrowContext.address,
|
|
44517
|
-
escrowAbi: escrowContext.abi
|
|
44518
|
-
});
|
|
44519
|
-
}
|
|
44520
|
-
prepareDeactivateCurrenciesBatchTransaction(params) {
|
|
44521
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44522
|
-
escrowAddress: params.escrowAddress,
|
|
44523
|
-
depositId: params.depositId
|
|
44524
|
-
});
|
|
44525
|
-
if (escrowContext.version !== "v2") {
|
|
44526
|
-
throw new Error("deactivateCurrenciesBatch requires EscrowV2");
|
|
44460
|
+
const json = await res.json();
|
|
44461
|
+
if (json.errors?.length) {
|
|
44462
|
+
const msg = json.errors.map((e) => e.message).join(", ");
|
|
44463
|
+
throw new Error(`GraphQL errors: ${msg}`);
|
|
44527
44464
|
}
|
|
44528
|
-
|
|
44529
|
-
return
|
|
44530
|
-
functionName,
|
|
44531
|
-
args: [parseRawDepositId(params.depositId), params.paymentMethods, params.currencyCodes],
|
|
44532
|
-
txOverrides: params.txOverrides,
|
|
44533
|
-
escrowAddress: escrowContext.address,
|
|
44534
|
-
escrowAbi: escrowContext.abi
|
|
44535
|
-
});
|
|
44536
|
-
}
|
|
44537
|
-
prepareSetVaultConfigTransaction(params) {
|
|
44538
|
-
return this.prepareRateManagerRegistryTransaction({
|
|
44539
|
-
functionNames: ["setRateManagerConfig"],
|
|
44540
|
-
args: this.buildSetRateManagerConfigArgs(params),
|
|
44541
|
-
txOverrides: params.txOverrides
|
|
44542
|
-
});
|
|
44465
|
+
if (!json.data) throw new Error("No data returned from indexer");
|
|
44466
|
+
return json.data;
|
|
44543
44467
|
}
|
|
44544
|
-
async
|
|
44545
|
-
const
|
|
44546
|
-
const
|
|
44547
|
-
|
|
44548
|
-
|
|
44549
|
-
|
|
44550
|
-
|
|
44551
|
-
|
|
44552
|
-
|
|
44553
|
-
|
|
44554
|
-
|
|
44555
|
-
|
|
44556
|
-
|
|
44557
|
-
|
|
44558
|
-
|
|
44559
|
-
|
|
44560
|
-
|
|
44561
|
-
|
|
44468
|
+
async query(request, init) {
|
|
44469
|
+
const retries = Math.max(0, init?.retries ?? 1);
|
|
44470
|
+
const rateLimitRetries = Math.max(0, init?.rateLimitRetries ?? 2);
|
|
44471
|
+
const maxAttempts = 1 + Math.max(retries, rateLimitRetries);
|
|
44472
|
+
const {
|
|
44473
|
+
retries: _unusedRetries,
|
|
44474
|
+
rateLimitRetries: _unusedRateLimitRetries,
|
|
44475
|
+
...requestInit
|
|
44476
|
+
} = init ?? {};
|
|
44477
|
+
let attempts = 0;
|
|
44478
|
+
let rateLimitAttempt = 0;
|
|
44479
|
+
let standardRetryAttempt = 0;
|
|
44480
|
+
let lastErr;
|
|
44481
|
+
while (attempts < maxAttempts) {
|
|
44482
|
+
try {
|
|
44483
|
+
return await this._post(request, requestInit);
|
|
44484
|
+
} catch (e) {
|
|
44485
|
+
lastErr = e;
|
|
44486
|
+
attempts += 1;
|
|
44487
|
+
if (requestInit.signal?.aborted) {
|
|
44488
|
+
throw e;
|
|
44489
|
+
}
|
|
44490
|
+
const hasAttemptsRemaining = attempts < maxAttempts;
|
|
44491
|
+
if (e instanceof IndexerHttpError && e.status === 429 && rateLimitAttempt < rateLimitRetries && hasAttemptsRemaining) {
|
|
44492
|
+
rateLimitAttempt += 1;
|
|
44493
|
+
const waitSeconds = e.retryAfterSeconds !== void 0 ? Math.max(0, e.retryAfterSeconds) : 1;
|
|
44494
|
+
await delay(waitSeconds * 1e3, requestInit.signal ?? void 0);
|
|
44495
|
+
continue;
|
|
44496
|
+
}
|
|
44497
|
+
if (!hasAttemptsRemaining || standardRetryAttempt >= retries) {
|
|
44498
|
+
break;
|
|
44499
|
+
}
|
|
44500
|
+
standardRetryAttempt += 1;
|
|
44501
|
+
await delay(200 * standardRetryAttempt, requestInit.signal ?? void 0);
|
|
44562
44502
|
}
|
|
44563
44503
|
}
|
|
44564
|
-
|
|
44565
|
-
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
44566
|
-
if (!controllerAddress || !controllerAbi) {
|
|
44567
|
-
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
44568
|
-
}
|
|
44569
|
-
const legacyResult = await this.config.getPublicClient().readContract({
|
|
44570
|
-
address: controllerAddress,
|
|
44571
|
-
abi: controllerAbi,
|
|
44572
|
-
functionName: "getDepositRateManager",
|
|
44573
|
-
args: [escrow, id]
|
|
44574
|
-
});
|
|
44575
|
-
return {
|
|
44576
|
-
registry: legacyResult[0],
|
|
44577
|
-
rateManagerId: legacyResult[1]
|
|
44578
|
-
};
|
|
44579
|
-
}
|
|
44580
|
-
async getManagerFee(escrow, depositId) {
|
|
44581
|
-
const id = parseRawDepositId(depositId);
|
|
44582
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44583
|
-
escrowAddress: escrow,
|
|
44584
|
-
depositId
|
|
44585
|
-
});
|
|
44586
|
-
if (getRateManagerReadFunction(escrowContext.abi, "getManagerFee")) {
|
|
44587
|
-
const result2 = await this.config.getPublicClient().readContract({
|
|
44588
|
-
address: escrowContext.address,
|
|
44589
|
-
abi: escrowContext.abi,
|
|
44590
|
-
functionName: "getManagerFee",
|
|
44591
|
-
args: [id]
|
|
44592
|
-
});
|
|
44593
|
-
return parseManagerFeeFromRead(result2);
|
|
44594
|
-
}
|
|
44595
|
-
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
44596
|
-
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
44597
|
-
if (!controllerAddress || !controllerAbi) {
|
|
44598
|
-
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
44599
|
-
}
|
|
44600
|
-
const result = await this.config.getPublicClient().readContract({
|
|
44601
|
-
address: controllerAddress,
|
|
44602
|
-
abi: controllerAbi,
|
|
44603
|
-
functionName: "getManagerFee",
|
|
44604
|
-
args: [escrow, id]
|
|
44605
|
-
});
|
|
44606
|
-
return parseManagerFeeFromRead(result);
|
|
44607
|
-
}
|
|
44608
|
-
async getEffectiveRate(params) {
|
|
44609
|
-
const escrowContext = this.config.host.resolveEscrowContext({
|
|
44610
|
-
escrowAddress: params.escrow,
|
|
44611
|
-
depositId: params.depositId
|
|
44612
|
-
});
|
|
44613
|
-
const id = parseRawDepositId(params.depositId);
|
|
44614
|
-
return await this.config.getPublicClient().readContract({
|
|
44615
|
-
address: escrowContext.address,
|
|
44616
|
-
abi: escrowContext.abi,
|
|
44617
|
-
functionName: "getEffectiveRate",
|
|
44618
|
-
args: [id, params.paymentMethod, params.fiatCurrency]
|
|
44619
|
-
});
|
|
44620
|
-
}
|
|
44621
|
-
};
|
|
44622
|
-
var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && abi.some(
|
|
44623
|
-
(item) => item.type === "function" && item.name === functionName
|
|
44624
|
-
);
|
|
44625
|
-
|
|
44626
|
-
// src/indexer/client.ts
|
|
44627
|
-
var IndexerHttpError = class extends Error {
|
|
44628
|
-
constructor(status, statusText, options) {
|
|
44629
|
-
super(`Indexer request failed: ${status} ${statusText}`);
|
|
44630
|
-
this.name = "IndexerHttpError";
|
|
44631
|
-
this.status = status;
|
|
44632
|
-
this.retryAfterSeconds = options?.retryAfterSeconds;
|
|
44504
|
+
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
44633
44505
|
}
|
|
44634
44506
|
};
|
|
44635
|
-
function
|
|
44636
|
-
|
|
44637
|
-
|
|
44638
|
-
|
|
44639
|
-
|
|
44640
|
-
|
|
44641
|
-
|
|
44642
|
-
|
|
44643
|
-
|
|
44644
|
-
|
|
44645
|
-
|
|
44646
|
-
|
|
44647
|
-
|
|
44648
|
-
error.name = "AbortError";
|
|
44649
|
-
return error;
|
|
44650
|
-
}
|
|
44651
|
-
function delay(ms, signal) {
|
|
44652
|
-
if (ms <= 0) {
|
|
44653
|
-
return Promise.resolve();
|
|
44654
|
-
}
|
|
44655
|
-
return new Promise((resolve, reject) => {
|
|
44656
|
-
if (signal?.aborted) {
|
|
44657
|
-
reject(createAbortError());
|
|
44658
|
-
return;
|
|
44659
|
-
}
|
|
44660
|
-
const timer = setTimeout(() => {
|
|
44661
|
-
signal?.removeEventListener("abort", onAbort);
|
|
44662
|
-
resolve();
|
|
44663
|
-
}, ms);
|
|
44664
|
-
const onAbort = () => {
|
|
44665
|
-
clearTimeout(timer);
|
|
44666
|
-
signal?.removeEventListener("abort", onAbort);
|
|
44667
|
-
reject(createAbortError());
|
|
44668
|
-
};
|
|
44669
|
-
signal?.addEventListener("abort", onAbort);
|
|
44670
|
-
});
|
|
44671
|
-
}
|
|
44672
|
-
var IndexerClient = class {
|
|
44673
|
-
constructor(endpoint, options = {}) {
|
|
44674
|
-
this.endpoint = endpoint;
|
|
44675
|
-
this.options = options;
|
|
44676
|
-
this.hasLoggedTokenProviderError = false;
|
|
44677
|
-
}
|
|
44678
|
-
async resolveAuthorizationToken() {
|
|
44679
|
-
if (this.options.getAuthorizationToken) {
|
|
44680
|
-
try {
|
|
44681
|
-
const token = await this.options.getAuthorizationToken();
|
|
44682
|
-
return token ?? void 0;
|
|
44683
|
-
} catch (error) {
|
|
44684
|
-
if (this.options.onAuthorizationTokenError) {
|
|
44685
|
-
this.options.onAuthorizationTokenError(error);
|
|
44686
|
-
} else if (!this.hasLoggedTokenProviderError) {
|
|
44687
|
-
this.hasLoggedTokenProviderError = true;
|
|
44688
|
-
console.warn(
|
|
44689
|
-
"[IndexerClient] getAuthorizationToken failed; continuing without Authorization header",
|
|
44690
|
-
error
|
|
44691
|
-
);
|
|
44692
|
-
}
|
|
44693
|
-
return void 0;
|
|
44694
|
-
}
|
|
44695
|
-
}
|
|
44696
|
-
return this.options.authorizationToken;
|
|
44697
|
-
}
|
|
44698
|
-
async _post(request, init) {
|
|
44699
|
-
const token = await this.resolveAuthorizationToken();
|
|
44700
|
-
const headers2 = new Headers(init?.headers);
|
|
44701
|
-
if (!headers2.has("Content-Type")) {
|
|
44702
|
-
headers2.set("Content-Type", "application/json");
|
|
44703
|
-
}
|
|
44704
|
-
if (token && !headers2.has("Authorization")) {
|
|
44705
|
-
headers2.set("Authorization", token.startsWith("Bearer ") ? token : `Bearer ${token}`);
|
|
44706
|
-
}
|
|
44707
|
-
if (this.options.apiKey && !headers2.has("x-api-key")) {
|
|
44708
|
-
headers2.set("x-api-key", this.options.apiKey);
|
|
44709
|
-
}
|
|
44710
|
-
const res = await fetch(this.endpoint, {
|
|
44711
|
-
method: "POST",
|
|
44712
|
-
headers: headers2,
|
|
44713
|
-
body: JSON.stringify(request),
|
|
44714
|
-
cache: "no-store",
|
|
44715
|
-
...init
|
|
44716
|
-
});
|
|
44717
|
-
if (!res.ok) {
|
|
44718
|
-
throw new IndexerHttpError(res.status, res.statusText, {
|
|
44719
|
-
retryAfterSeconds: parseRetryAfterSeconds(res.headers.get("Retry-After"))
|
|
44720
|
-
});
|
|
44721
|
-
}
|
|
44722
|
-
const json = await res.json();
|
|
44723
|
-
if (json.errors?.length) {
|
|
44724
|
-
const msg = json.errors.map((e) => e.message).join(", ");
|
|
44725
|
-
throw new Error(`GraphQL errors: ${msg}`);
|
|
44726
|
-
}
|
|
44727
|
-
if (!json.data) throw new Error("No data returned from indexer");
|
|
44728
|
-
return json.data;
|
|
44729
|
-
}
|
|
44730
|
-
async query(request, init) {
|
|
44731
|
-
const retries = Math.max(0, init?.retries ?? 1);
|
|
44732
|
-
const rateLimitRetries = Math.max(0, init?.rateLimitRetries ?? 2);
|
|
44733
|
-
const maxAttempts = 1 + Math.max(retries, rateLimitRetries);
|
|
44734
|
-
const {
|
|
44735
|
-
retries: _unusedRetries,
|
|
44736
|
-
rateLimitRetries: _unusedRateLimitRetries,
|
|
44737
|
-
...requestInit
|
|
44738
|
-
} = init ?? {};
|
|
44739
|
-
let attempts = 0;
|
|
44740
|
-
let rateLimitAttempt = 0;
|
|
44741
|
-
let standardRetryAttempt = 0;
|
|
44742
|
-
let lastErr;
|
|
44743
|
-
while (attempts < maxAttempts) {
|
|
44744
|
-
try {
|
|
44745
|
-
return await this._post(request, requestInit);
|
|
44746
|
-
} catch (e) {
|
|
44747
|
-
lastErr = e;
|
|
44748
|
-
attempts += 1;
|
|
44749
|
-
if (requestInit.signal?.aborted) {
|
|
44750
|
-
throw e;
|
|
44751
|
-
}
|
|
44752
|
-
const hasAttemptsRemaining = attempts < maxAttempts;
|
|
44753
|
-
if (e instanceof IndexerHttpError && e.status === 429 && rateLimitAttempt < rateLimitRetries && hasAttemptsRemaining) {
|
|
44754
|
-
rateLimitAttempt += 1;
|
|
44755
|
-
const waitSeconds = e.retryAfterSeconds !== void 0 ? Math.max(0, e.retryAfterSeconds) : 1;
|
|
44756
|
-
await delay(waitSeconds * 1e3, requestInit.signal ?? void 0);
|
|
44757
|
-
continue;
|
|
44758
|
-
}
|
|
44759
|
-
if (!hasAttemptsRemaining || standardRetryAttempt >= retries) {
|
|
44760
|
-
break;
|
|
44761
|
-
}
|
|
44762
|
-
standardRetryAttempt += 1;
|
|
44763
|
-
await delay(200 * standardRetryAttempt, requestInit.signal ?? void 0);
|
|
44764
|
-
}
|
|
44765
|
-
}
|
|
44766
|
-
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr));
|
|
44767
|
-
}
|
|
44768
|
-
};
|
|
44769
|
-
function defaultIndexerEndpoint(env = "PRODUCTION") {
|
|
44770
|
-
switch (env) {
|
|
44771
|
-
case "PRODUCTION":
|
|
44772
|
-
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
44773
|
-
case "PREPRODUCTION":
|
|
44774
|
-
return "https://indexer-preprod.zkp2p.xyz/v1/graphql";
|
|
44775
|
-
case "STAGING":
|
|
44776
|
-
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
44777
|
-
case "DEV":
|
|
44778
|
-
case "LOCAL":
|
|
44779
|
-
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
44780
|
-
default:
|
|
44781
|
-
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
44507
|
+
function defaultIndexerEndpoint(env = "PRODUCTION") {
|
|
44508
|
+
switch (env) {
|
|
44509
|
+
case "PRODUCTION":
|
|
44510
|
+
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
44511
|
+
case "PREPRODUCTION":
|
|
44512
|
+
return "https://indexer-preprod.zkp2p.xyz/v1/graphql";
|
|
44513
|
+
case "STAGING":
|
|
44514
|
+
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
44515
|
+
case "DEV":
|
|
44516
|
+
case "LOCAL":
|
|
44517
|
+
return "https://indexer-staging.zkp2p.xyz/v1/graphql";
|
|
44518
|
+
default:
|
|
44519
|
+
return "https://indexer.zkp2p.xyz/v1/graphql";
|
|
44782
44520
|
}
|
|
44783
44521
|
}
|
|
44784
44522
|
|
|
@@ -46223,7 +45961,11 @@ var IndexerDepositService = class {
|
|
|
46223
45961
|
(pm) => (pm.paymentMethodHash ?? "").toLowerCase() === target
|
|
46224
45962
|
);
|
|
46225
45963
|
return match?.payeeDetailsHash ?? null;
|
|
46226
|
-
} catch {
|
|
45964
|
+
} catch (error) {
|
|
45965
|
+
logger.warn(
|
|
45966
|
+
"[sdk] resolvePayeeHash lookup failed; returning null",
|
|
45967
|
+
error instanceof Error ? error.message : error
|
|
45968
|
+
);
|
|
46227
45969
|
return null;
|
|
46228
45970
|
}
|
|
46229
45971
|
}
|
|
@@ -46385,1231 +46127,1792 @@ var IndexerDepositService = class {
|
|
|
46385
46127
|
}
|
|
46386
46128
|
};
|
|
46387
46129
|
|
|
46388
|
-
// src/
|
|
46389
|
-
|
|
46390
|
-
var
|
|
46391
|
-
var
|
|
46392
|
-
var
|
|
46393
|
-
|
|
46394
|
-
|
|
46395
|
-
|
|
46396
|
-
}
|
|
46397
|
-
|
|
46398
|
-
|
|
46399
|
-
|
|
46400
|
-
}
|
|
46401
|
-
|
|
46402
|
-
|
|
46403
|
-
}
|
|
46404
|
-
|
|
46405
|
-
|
|
46406
|
-
|
|
46407
|
-
|
|
46408
|
-
|
|
46409
|
-
|
|
46410
|
-
|
|
46411
|
-
|
|
46412
|
-
|
|
46130
|
+
// src/referral.ts
|
|
46131
|
+
var normalizeReferralCode = (code) => code.trim().toUpperCase();
|
|
46132
|
+
var isValidReferralCode = (code) => /^[A-Z0-9]{6}$/.test(normalizeReferralCode(code));
|
|
46133
|
+
var REFERRAL_SIGNATURE_DOMAIN = { name: "ZKP2PReferral", version: "1" };
|
|
46134
|
+
var REFERRAL_SIGNATURE_TYPES = {
|
|
46135
|
+
CreateCode: [
|
|
46136
|
+
{ name: "wallet", type: "address" },
|
|
46137
|
+
{ name: "audience", type: "string" },
|
|
46138
|
+
{ name: "issuedAt", type: "uint256" }
|
|
46139
|
+
],
|
|
46140
|
+
RedeemCode: [
|
|
46141
|
+
{ name: "wallet", type: "address" },
|
|
46142
|
+
{ name: "code", type: "string" },
|
|
46143
|
+
{ name: "referrer", type: "address" },
|
|
46144
|
+
{ name: "audience", type: "string" },
|
|
46145
|
+
{ name: "issuedAt", type: "uint256" }
|
|
46146
|
+
],
|
|
46147
|
+
RenameCode: [
|
|
46148
|
+
{ name: "wallet", type: "address" },
|
|
46149
|
+
{ name: "oldCode", type: "string" },
|
|
46150
|
+
{ name: "newCode", type: "string" },
|
|
46151
|
+
{ name: "audience", type: "string" },
|
|
46152
|
+
{ name: "issuedAt", type: "uint256" }
|
|
46153
|
+
]
|
|
46154
|
+
};
|
|
46155
|
+
|
|
46156
|
+
// src/adapters/api.ts
|
|
46157
|
+
function createHeaders(apiKey, authorizationToken) {
|
|
46158
|
+
const headers2 = { "Content-Type": "application/json" };
|
|
46159
|
+
if (apiKey) headers2["x-api-key"] = apiKey;
|
|
46160
|
+
if (authorizationToken) {
|
|
46161
|
+
headers2.Authorization = authorizationToken.startsWith("Bearer ") ? authorizationToken : `Bearer ${authorizationToken}`;
|
|
46413
46162
|
}
|
|
46414
|
-
return
|
|
46415
|
-
}
|
|
46416
|
-
function getManagerScopeKey(rateManagerId, rateManagerAddress) {
|
|
46417
|
-
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
46418
|
-
const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
|
|
46419
|
-
return normalizedRateManagerAddress ? `${normalizedRateManagerAddress}:${normalizedId}` : normalizedId;
|
|
46163
|
+
return headers2;
|
|
46420
46164
|
}
|
|
46421
|
-
function
|
|
46422
|
-
|
|
46423
|
-
|
|
46424
|
-
|
|
46425
|
-
|
|
46426
|
-
return
|
|
46165
|
+
function withApiBase(baseApiUrl) {
|
|
46166
|
+
const trimmed = (baseApiUrl || "").trim();
|
|
46167
|
+
let base2 = trimmed.replace(/\/+$/, "");
|
|
46168
|
+
base2 = base2.replace(/\/v1$/i, "");
|
|
46169
|
+
base2 = base2.replace(/\/v2$/i, "");
|
|
46170
|
+
return base2;
|
|
46427
46171
|
}
|
|
46428
|
-
function
|
|
46429
|
-
|
|
46430
|
-
|
|
46431
|
-
|
|
46172
|
+
async function apiFetch({
|
|
46173
|
+
url,
|
|
46174
|
+
method = "GET",
|
|
46175
|
+
body,
|
|
46176
|
+
apiKey,
|
|
46177
|
+
authorizationToken,
|
|
46178
|
+
timeoutMs,
|
|
46179
|
+
retryCount = 3,
|
|
46180
|
+
retryDelayMs = 1e3
|
|
46181
|
+
}) {
|
|
46182
|
+
const endpoint = url.replace(/^[^/]*\/\/[^/]*/, "");
|
|
46183
|
+
return withRetry(
|
|
46184
|
+
async () => {
|
|
46185
|
+
let res;
|
|
46186
|
+
try {
|
|
46187
|
+
const options = {
|
|
46188
|
+
method,
|
|
46189
|
+
headers: createHeaders(apiKey, authorizationToken)
|
|
46190
|
+
};
|
|
46191
|
+
if (body && method !== "GET") {
|
|
46192
|
+
options.body = JSON.stringify(body);
|
|
46193
|
+
}
|
|
46194
|
+
res = await fetch(url, options);
|
|
46195
|
+
} catch (error) {
|
|
46196
|
+
throw new exports.NetworkError("Failed to connect to API server", { endpoint, error });
|
|
46197
|
+
}
|
|
46198
|
+
if (!res.ok) {
|
|
46199
|
+
const errorText = await res.text();
|
|
46200
|
+
throw parseAPIError(res, errorText);
|
|
46201
|
+
}
|
|
46202
|
+
return res.json();
|
|
46203
|
+
},
|
|
46204
|
+
retryCount,
|
|
46205
|
+
retryDelayMs,
|
|
46206
|
+
timeoutMs
|
|
46432
46207
|
);
|
|
46433
|
-
return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
|
|
46434
46208
|
}
|
|
46435
|
-
function
|
|
46436
|
-
|
|
46209
|
+
function unwrapResponseObject(payload) {
|
|
46210
|
+
if (payload && typeof payload === "object" && "responseObject" in payload) {
|
|
46211
|
+
return payload.responseObject;
|
|
46212
|
+
}
|
|
46213
|
+
return payload;
|
|
46437
46214
|
}
|
|
46438
|
-
function
|
|
46439
|
-
|
|
46440
|
-
|
|
46441
|
-
|
|
46442
|
-
|
|
46443
|
-
|
|
46444
|
-
return `${normalizedEscrow}_${normalizedDepositId}`;
|
|
46215
|
+
function requireAuthorizationToken(authorizationToken, endpoint) {
|
|
46216
|
+
if (!authorizationToken) {
|
|
46217
|
+
throw new exports.ValidationError(
|
|
46218
|
+
`authorizationToken is required for ${endpoint}`,
|
|
46219
|
+
"authorizationToken"
|
|
46220
|
+
);
|
|
46445
46221
|
}
|
|
46446
|
-
return
|
|
46222
|
+
return authorizationToken;
|
|
46447
46223
|
}
|
|
46448
|
-
function
|
|
46449
|
-
if (
|
|
46450
|
-
|
|
46451
|
-
|
|
46452
|
-
|
|
46224
|
+
function requireReferralWriteAuth(authorizationToken, signature, endpoint) {
|
|
46225
|
+
if (authorizationToken && signature) {
|
|
46226
|
+
throw new exports.ValidationError(
|
|
46227
|
+
`Use either authorizationToken or signature for ${endpoint}, not both`,
|
|
46228
|
+
"authorizationToken"
|
|
46229
|
+
);
|
|
46230
|
+
}
|
|
46231
|
+
if (!authorizationToken && !signature) {
|
|
46232
|
+
throw new exports.ValidationError(
|
|
46233
|
+
`authorizationToken or signature is required for ${endpoint}`,
|
|
46234
|
+
"authorizationToken"
|
|
46235
|
+
);
|
|
46236
|
+
}
|
|
46237
|
+
return authorizationToken;
|
|
46453
46238
|
}
|
|
46454
|
-
function
|
|
46455
|
-
if (!
|
|
46456
|
-
|
|
46457
|
-
|
|
46239
|
+
function requireEscrowAddress(escrowAddress, endpoint) {
|
|
46240
|
+
if (!escrowAddress) {
|
|
46241
|
+
throw new exports.ValidationError(`escrowAddress is required for ${endpoint}`, "escrowAddress");
|
|
46242
|
+
}
|
|
46243
|
+
return escrowAddress;
|
|
46458
46244
|
}
|
|
46459
|
-
function
|
|
46460
|
-
const
|
|
46461
|
-
|
|
46462
|
-
|
|
46463
|
-
const scopedRateManager = parseScopedRateManagerFilterId(value);
|
|
46464
|
-
if (scopedRateManager) {
|
|
46465
|
-
scoped.set(
|
|
46466
|
-
getManagerScopeKey(scopedRateManager.rateManagerId, scopedRateManager.rateManagerAddress),
|
|
46467
|
-
scopedRateManager
|
|
46468
|
-
);
|
|
46469
|
-
continue;
|
|
46470
|
-
}
|
|
46471
|
-
if (value.includes(":")) {
|
|
46472
|
-
continue;
|
|
46473
|
-
}
|
|
46474
|
-
const normalizedRateManagerId = normalizeRateManagerId(value);
|
|
46475
|
-
if (normalizedRateManagerId) {
|
|
46476
|
-
bare.add(normalizedRateManagerId);
|
|
46477
|
-
}
|
|
46245
|
+
function normalizeReferralAddress(address, field) {
|
|
46246
|
+
const normalized = address.trim().toLowerCase();
|
|
46247
|
+
if (!isValidHexAddress(normalized)) {
|
|
46248
|
+
throw new exports.ValidationError(`${field} must be a valid Ethereum address`, field);
|
|
46478
46249
|
}
|
|
46479
|
-
return
|
|
46250
|
+
return normalized;
|
|
46480
46251
|
}
|
|
46481
|
-
function
|
|
46482
|
-
|
|
46252
|
+
function inferIndexerEnvFromBaseApiUrl(baseApiUrl) {
|
|
46253
|
+
const normalized = withApiBase(baseApiUrl).toLowerCase();
|
|
46254
|
+
if (normalized.includes("preprod") || normalized.includes("preproduction") || normalized.includes("/preprod/")) {
|
|
46255
|
+
return "PREPRODUCTION";
|
|
46256
|
+
}
|
|
46257
|
+
if (normalized.includes("staging") || normalized.includes("/staging/") || normalized.includes("localhost") || normalized.includes("127.0.0.1")) {
|
|
46258
|
+
return "STAGING";
|
|
46259
|
+
}
|
|
46260
|
+
return "PRODUCTION";
|
|
46483
46261
|
}
|
|
46484
|
-
function
|
|
46485
|
-
if (!
|
|
46262
|
+
async function withOptionalTimeout(promise, timeoutMs, endpoint) {
|
|
46263
|
+
if (!timeoutMs || timeoutMs <= 0) return promise;
|
|
46264
|
+
let timer;
|
|
46486
46265
|
try {
|
|
46487
|
-
return
|
|
46488
|
-
|
|
46489
|
-
|
|
46266
|
+
return await Promise.race([
|
|
46267
|
+
promise,
|
|
46268
|
+
new Promise((_, reject) => {
|
|
46269
|
+
timer = setTimeout(() => {
|
|
46270
|
+
reject(new exports.NetworkError("Request timed out", { endpoint }));
|
|
46271
|
+
}, timeoutMs);
|
|
46272
|
+
})
|
|
46273
|
+
]);
|
|
46274
|
+
} finally {
|
|
46275
|
+
if (timer) clearTimeout(timer);
|
|
46490
46276
|
}
|
|
46491
46277
|
}
|
|
46492
|
-
function
|
|
46493
|
-
if (
|
|
46494
|
-
|
|
46495
|
-
|
|
46278
|
+
function toDateFromUnixSeconds(value) {
|
|
46279
|
+
if (!value) return void 0;
|
|
46280
|
+
const numeric = Number(value);
|
|
46281
|
+
if (!Number.isFinite(numeric) || numeric <= 0) return void 0;
|
|
46282
|
+
return new Date(numeric * 1e3);
|
|
46496
46283
|
}
|
|
46497
|
-
function
|
|
46498
|
-
if (
|
|
46499
|
-
const [chainIdRaw, blockNumberRaw, logIndexRaw] = id.split("_");
|
|
46500
|
-
if (!chainIdRaw || !blockNumberRaw || !logIndexRaw) return null;
|
|
46501
|
-
if (!/^\d+$/.test(chainIdRaw) || !/^\d+$/.test(blockNumberRaw) || !/^\d+$/.test(logIndexRaw)) {
|
|
46502
|
-
return null;
|
|
46503
|
-
}
|
|
46284
|
+
function toBigIntSafe(value) {
|
|
46285
|
+
if (value === null || value === void 0) return 0n;
|
|
46504
46286
|
try {
|
|
46505
|
-
return
|
|
46506
|
-
chainId: BigInt(chainIdRaw),
|
|
46507
|
-
blockNumber: BigInt(blockNumberRaw),
|
|
46508
|
-
logIndex: BigInt(logIndexRaw)
|
|
46509
|
-
};
|
|
46287
|
+
return BigInt(value);
|
|
46510
46288
|
} catch {
|
|
46511
|
-
return
|
|
46289
|
+
return 0n;
|
|
46512
46290
|
}
|
|
46513
46291
|
}
|
|
46514
|
-
function
|
|
46515
|
-
|
|
46516
|
-
|
|
46517
|
-
|
|
46518
|
-
|
|
46519
|
-
|
|
46520
|
-
|
|
46521
|
-
|
|
46522
|
-
|
|
46523
|
-
|
|
46524
|
-
if (
|
|
46525
|
-
|
|
46292
|
+
function normalizeOwnerDepositsStatus(status) {
|
|
46293
|
+
if (!status) return void 0;
|
|
46294
|
+
if (status === "WITHDRAWN") return "CLOSED";
|
|
46295
|
+
return status;
|
|
46296
|
+
}
|
|
46297
|
+
function buildLegacyVerifierCurrencies(deposit) {
|
|
46298
|
+
const currenciesByMethod = /* @__PURE__ */ new Map();
|
|
46299
|
+
for (const currency of deposit.currencies ?? []) {
|
|
46300
|
+
const methodHash = currency.paymentMethodHash;
|
|
46301
|
+
const resolvedConversionRate = currency.conversionRate ?? currency.minConversionRate;
|
|
46302
|
+
if (resolvedConversionRate === null || resolvedConversionRate === void 0) {
|
|
46303
|
+
logger.warn(
|
|
46304
|
+
`[sdk] Skipping currency with missing conversion rate (deposit ${deposit.depositId}, currency ${currency.currencyCode})`
|
|
46305
|
+
);
|
|
46306
|
+
continue;
|
|
46526
46307
|
}
|
|
46527
|
-
|
|
46308
|
+
const bucket = currenciesByMethod.get(methodHash) ?? [];
|
|
46309
|
+
bucket.push({
|
|
46310
|
+
currencyCode: currency.currencyCode,
|
|
46311
|
+
conversionRate: resolvedConversionRate,
|
|
46312
|
+
minConversionRate: currency.minConversionRate,
|
|
46313
|
+
managerRate: currency.managerRate ?? null,
|
|
46314
|
+
rateManagerId: currency.rateManagerId ?? null
|
|
46315
|
+
});
|
|
46316
|
+
currenciesByMethod.set(methodHash, bucket);
|
|
46528
46317
|
}
|
|
46529
|
-
return
|
|
46530
|
-
}
|
|
46531
|
-
function isAggregateOrderField(field) {
|
|
46532
|
-
return field === "currentDelegatedBalance" || field === "totalFilledVolume";
|
|
46318
|
+
return currenciesByMethod;
|
|
46533
46319
|
}
|
|
46534
|
-
function
|
|
46320
|
+
function convertIndexerDepositToLegacyApiDeposit(deposit) {
|
|
46321
|
+
const currenciesByMethod = buildLegacyVerifierCurrencies(deposit);
|
|
46322
|
+
const verifiers = (deposit.paymentMethods ?? []).filter((paymentMethod) => paymentMethod.active !== false).map((paymentMethod) => ({
|
|
46323
|
+
depositId: Number(deposit.depositId),
|
|
46324
|
+
verifier: "",
|
|
46325
|
+
methodHash: paymentMethod.paymentMethodHash,
|
|
46326
|
+
intentGatingService: paymentMethod.intentGatingService,
|
|
46327
|
+
payeeDetailsHash: paymentMethod.payeeDetailsHash,
|
|
46328
|
+
data: "0x",
|
|
46329
|
+
currencies: currenciesByMethod.get(paymentMethod.paymentMethodHash) ?? []
|
|
46330
|
+
}));
|
|
46331
|
+
const remainingDeposits = toBigIntSafe(deposit.remainingDeposits);
|
|
46332
|
+
const outstandingIntentAmount = toBigIntSafe(deposit.outstandingIntentAmount);
|
|
46333
|
+
const totalAmountTaken = toBigIntSafe(deposit.totalAmountTaken);
|
|
46334
|
+
const totalWithdrawn = toBigIntSafe(deposit.totalWithdrawn);
|
|
46335
|
+
const amount = remainingDeposits + outstandingIntentAmount + totalAmountTaken + totalWithdrawn;
|
|
46535
46336
|
return {
|
|
46536
|
-
|
|
46537
|
-
|
|
46337
|
+
id: Number(deposit.depositId),
|
|
46338
|
+
depositor: deposit.depositor,
|
|
46339
|
+
token: deposit.token,
|
|
46340
|
+
amount: amount.toString(),
|
|
46341
|
+
remainingDeposits: deposit.remainingDeposits,
|
|
46342
|
+
intentAmountMin: deposit.intentAmountMin,
|
|
46343
|
+
intentAmountMax: deposit.intentAmountMax,
|
|
46344
|
+
acceptingIntents: deposit.acceptingIntents,
|
|
46345
|
+
outstandingIntentAmount: deposit.outstandingIntentAmount,
|
|
46346
|
+
availableLiquidity: deposit.remainingDeposits,
|
|
46347
|
+
status: deposit.status,
|
|
46348
|
+
totalIntents: deposit.totalIntents,
|
|
46349
|
+
signaledIntents: deposit.signaledIntents,
|
|
46350
|
+
fulfilledIntents: deposit.fulfilledIntents,
|
|
46351
|
+
prunedIntents: deposit.prunedIntents,
|
|
46352
|
+
totalAmountTaken: deposit.totalAmountTaken,
|
|
46353
|
+
totalWithdrawn: deposit.totalWithdrawn,
|
|
46354
|
+
successRateBps: deposit.successRateBps,
|
|
46355
|
+
rateManagerId: deposit.rateManagerId ?? null,
|
|
46356
|
+
vaultName: null,
|
|
46357
|
+
rateManagerRegistry: null,
|
|
46358
|
+
createdAt: toDateFromUnixSeconds(deposit.timestamp),
|
|
46359
|
+
updatedAt: toDateFromUnixSeconds(deposit.updatedAt),
|
|
46360
|
+
verifiers
|
|
46538
46361
|
};
|
|
46539
46362
|
}
|
|
46540
|
-
function
|
|
46541
|
-
|
|
46542
|
-
|
|
46543
|
-
|
|
46544
|
-
|
|
46545
|
-
|
|
46546
|
-
|
|
46547
|
-
rateManagerId,
|
|
46548
|
-
rateManagerAddress: normalizeAddress3(deposit.rateManagerAddress) || null,
|
|
46549
|
-
depositId: deposit.id,
|
|
46550
|
-
delegatedAt,
|
|
46551
|
-
createdAt: delegatedAt ?? deposit.updatedAt,
|
|
46552
|
-
updatedAt: deposit.updatedAt
|
|
46553
|
-
};
|
|
46363
|
+
async function apiPostDepositDetails(req, baseApiUrl, timeoutMs) {
|
|
46364
|
+
return apiFetch({
|
|
46365
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/create`,
|
|
46366
|
+
method: "POST",
|
|
46367
|
+
body: req,
|
|
46368
|
+
timeoutMs
|
|
46369
|
+
});
|
|
46554
46370
|
}
|
|
46555
|
-
|
|
46556
|
-
|
|
46557
|
-
|
|
46558
|
-
|
|
46559
|
-
buildRateManagerScopeWhere(rateManagerIds) {
|
|
46560
|
-
if (!rateManagerIds?.length) return void 0;
|
|
46561
|
-
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
46562
|
-
const scopeConditions = [];
|
|
46563
|
-
if (bare.size > 0) {
|
|
46564
|
-
scopeConditions.push({
|
|
46565
|
-
rateManagerId: { _in: [...bare] }
|
|
46566
|
-
});
|
|
46567
|
-
}
|
|
46568
|
-
for (const scopedRateManager of scoped.values()) {
|
|
46569
|
-
scopeConditions.push({
|
|
46570
|
-
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
46571
|
-
rateManagerAddress: { _eq: scopedRateManager.rateManagerAddress }
|
|
46572
|
-
});
|
|
46573
|
-
}
|
|
46574
|
-
if (scopeConditions.length === 1) {
|
|
46575
|
-
return scopeConditions[0];
|
|
46576
|
-
}
|
|
46577
|
-
if (scopeConditions.length > 1) {
|
|
46578
|
-
return { _or: scopeConditions };
|
|
46371
|
+
async function apiGetQuote(req, baseApiUrl, timeoutMs, apiKey) {
|
|
46372
|
+
if (req.quotesToReturn !== void 0) {
|
|
46373
|
+
if (!Number.isInteger(req.quotesToReturn) || req.quotesToReturn < 1) {
|
|
46374
|
+
throw new exports.ValidationError("quotesToReturn must be a positive integer", "quotesToReturn");
|
|
46579
46375
|
}
|
|
46580
|
-
return void 0;
|
|
46581
46376
|
}
|
|
46582
|
-
|
|
46583
|
-
|
|
46584
|
-
const where = {};
|
|
46585
|
-
if (filter.manager) {
|
|
46586
|
-
where.manager = { _ilike: filter.manager };
|
|
46587
|
-
}
|
|
46588
|
-
if (filter.name) {
|
|
46589
|
-
where.name = { _ilike: `%${filter.name}%` };
|
|
46590
|
-
}
|
|
46591
|
-
if (filter.maxFee) {
|
|
46592
|
-
where.maxFee = { _lte: filter.maxFee };
|
|
46593
|
-
}
|
|
46594
|
-
const scopeWhere = this.buildRateManagerScopeWhere(filter.rateManagerIds);
|
|
46595
|
-
if (scopeWhere) {
|
|
46596
|
-
Object.assign(where, scopeWhere);
|
|
46597
|
-
}
|
|
46598
|
-
return Object.keys(where).length ? where : void 0;
|
|
46377
|
+
if (!isValidHexAddress(req.user)) {
|
|
46378
|
+
throw new exports.ValidationError("user must be a valid Ethereum address", "user");
|
|
46599
46379
|
}
|
|
46600
|
-
|
|
46601
|
-
|
|
46380
|
+
if (!isValidHexAddress(req.recipient)) {
|
|
46381
|
+
throw new exports.ValidationError("recipient must be a valid Ethereum address", "recipient");
|
|
46602
46382
|
}
|
|
46603
|
-
|
|
46604
|
-
|
|
46605
|
-
|
|
46606
|
-
|
|
46607
|
-
|
|
46608
|
-
if (bare.size > 0) {
|
|
46609
|
-
scopeConditions.push({
|
|
46610
|
-
rateManagerId: { _in: [...bare] }
|
|
46611
|
-
});
|
|
46612
|
-
}
|
|
46613
|
-
for (const scopedRateManager of scoped.values()) {
|
|
46614
|
-
scopeConditions.push({
|
|
46615
|
-
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
46616
|
-
id: {
|
|
46617
|
-
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
46618
|
-
scopedRateManager.rateManagerId,
|
|
46619
|
-
scopedRateManager.rateManagerAddress
|
|
46620
|
-
)
|
|
46621
|
-
}
|
|
46622
|
-
});
|
|
46623
|
-
}
|
|
46624
|
-
if (scopeConditions.length === 1) {
|
|
46625
|
-
return scopeConditions[0] ?? {};
|
|
46626
|
-
}
|
|
46627
|
-
if (scopeConditions.length > 1) {
|
|
46628
|
-
return { _or: scopeConditions };
|
|
46629
|
-
}
|
|
46630
|
-
return {};
|
|
46383
|
+
if (!isValidHexAddress(req.destinationToken)) {
|
|
46384
|
+
throw new exports.ValidationError(
|
|
46385
|
+
"destinationToken must be a valid Ethereum address",
|
|
46386
|
+
"destinationToken"
|
|
46387
|
+
);
|
|
46631
46388
|
}
|
|
46632
|
-
|
|
46633
|
-
|
|
46634
|
-
|
|
46635
|
-
|
|
46636
|
-
|
|
46389
|
+
const isExactFiat = req.isExactFiat !== false;
|
|
46390
|
+
const endpoint = isExactFiat ? "exact-fiat" : "exact-token";
|
|
46391
|
+
let url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
46392
|
+
if (req.quotesToReturn) url += `?quotesToReturn=${req.quotesToReturn}`;
|
|
46393
|
+
const requestBody = {
|
|
46394
|
+
...req,
|
|
46395
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
46396
|
+
amount: void 0,
|
|
46397
|
+
isExactFiat: void 0,
|
|
46398
|
+
quotesToReturn: void 0,
|
|
46399
|
+
includePrivateOrderbooks: req.includePrivateOrderbooks
|
|
46400
|
+
};
|
|
46401
|
+
Object.keys(requestBody).forEach((k) => requestBody[k] === void 0 && delete requestBody[k]);
|
|
46402
|
+
return apiFetch({
|
|
46403
|
+
url,
|
|
46404
|
+
method: "POST",
|
|
46405
|
+
body: requestBody,
|
|
46406
|
+
apiKey,
|
|
46407
|
+
timeoutMs
|
|
46408
|
+
});
|
|
46409
|
+
}
|
|
46410
|
+
async function apiGetQuotesBestByPlatform(req, baseApiUrl, timeoutMs, apiKey) {
|
|
46411
|
+
const isExactFiat = req.isExactFiat !== false;
|
|
46412
|
+
const endpoint = isExactFiat ? "best-by-platform" : "best-by-platform-exact-token";
|
|
46413
|
+
const url = `${withApiBase(baseApiUrl)}/v2/quote/${endpoint}`;
|
|
46414
|
+
const requestBody = {
|
|
46415
|
+
...req,
|
|
46416
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(req.amount),
|
|
46417
|
+
amount: void 0,
|
|
46418
|
+
isExactFiat: void 0,
|
|
46419
|
+
referrerFeeConfig: void 0
|
|
46420
|
+
};
|
|
46421
|
+
Object.keys(requestBody).forEach(
|
|
46422
|
+
(key) => requestBody[key] === void 0 && delete requestBody[key]
|
|
46423
|
+
);
|
|
46424
|
+
return apiFetch({
|
|
46425
|
+
url,
|
|
46426
|
+
method: "POST",
|
|
46427
|
+
body: requestBody,
|
|
46428
|
+
apiKey,
|
|
46429
|
+
timeoutMs
|
|
46430
|
+
});
|
|
46431
|
+
}
|
|
46432
|
+
async function apiGetPayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
46433
|
+
return apiFetch({
|
|
46434
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/${req.processorName}/${req.hashedOnchainId}`,
|
|
46435
|
+
method: "GET",
|
|
46436
|
+
timeoutMs
|
|
46437
|
+
});
|
|
46438
|
+
}
|
|
46439
|
+
async function apiValidatePayeeDetails(req, baseApiUrl, timeoutMs) {
|
|
46440
|
+
const data52 = await apiFetch({
|
|
46441
|
+
url: `${withApiBase(baseApiUrl)}/v2/makers/validate`,
|
|
46442
|
+
method: "POST",
|
|
46443
|
+
body: req,
|
|
46444
|
+
timeoutMs
|
|
46445
|
+
});
|
|
46446
|
+
if (typeof data52?.responseObject === "boolean") {
|
|
46447
|
+
return {
|
|
46448
|
+
...data52,
|
|
46449
|
+
responseObject: { isValid: data52.responseObject }
|
|
46450
|
+
};
|
|
46451
|
+
}
|
|
46452
|
+
return data52;
|
|
46453
|
+
}
|
|
46454
|
+
async function apiGetOwnerDeposits(req, apiKey, baseApiUrl, authToken, timeoutMs) {
|
|
46455
|
+
const escrowAddress = requireEscrowAddress(
|
|
46456
|
+
req.escrowAddress,
|
|
46457
|
+
"apiGetOwnerDeposits requires escrowAddress"
|
|
46458
|
+
);
|
|
46459
|
+
const indexerEndpoint = defaultIndexerEndpoint(inferIndexerEnvFromBaseApiUrl(baseApiUrl));
|
|
46460
|
+
const indexerClient = new IndexerClient(indexerEndpoint, {
|
|
46461
|
+
apiKey,
|
|
46462
|
+
authorizationToken: authToken
|
|
46463
|
+
});
|
|
46464
|
+
const service = new IndexerDepositService(indexerClient);
|
|
46465
|
+
const deposits = await withOptionalTimeout(
|
|
46466
|
+
service.fetchDepositsWithRelations(
|
|
46467
|
+
{
|
|
46468
|
+
depositor: req.ownerAddress,
|
|
46469
|
+
escrowAddress,
|
|
46470
|
+
escrowAddresses: req.escrowAddresses?.length ? req.escrowAddresses : void 0,
|
|
46471
|
+
status: normalizeOwnerDepositsStatus(req.status)
|
|
46472
|
+
},
|
|
46473
|
+
void 0,
|
|
46474
|
+
{ includeIntents: false }
|
|
46475
|
+
),
|
|
46476
|
+
timeoutMs,
|
|
46477
|
+
indexerEndpoint
|
|
46478
|
+
);
|
|
46479
|
+
return {
|
|
46480
|
+
success: true,
|
|
46481
|
+
message: "ok",
|
|
46482
|
+
responseObject: deposits.map(convertIndexerDepositToLegacyApiDeposit),
|
|
46483
|
+
statusCode: 200
|
|
46484
|
+
};
|
|
46485
|
+
}
|
|
46486
|
+
async function apiGetTakerTier(req, baseApiUrl, timeoutMs) {
|
|
46487
|
+
const normalizedOwner = req.owner.toLowerCase();
|
|
46488
|
+
const query = new URLSearchParams({
|
|
46489
|
+
owner: normalizedOwner,
|
|
46490
|
+
chainId: String(req.chainId)
|
|
46491
|
+
});
|
|
46492
|
+
const endpoint = `/v2/taker/tier?${query.toString()}`;
|
|
46493
|
+
return apiFetch({
|
|
46494
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
46495
|
+
method: "GET",
|
|
46496
|
+
timeoutMs
|
|
46497
|
+
});
|
|
46498
|
+
}
|
|
46499
|
+
async function apiGetReferralDashboard(opts) {
|
|
46500
|
+
const address = opts.address ? normalizeReferralAddress(opts.address, "address") : void 0;
|
|
46501
|
+
const endpoint = address ? `/v2/referral?${new URLSearchParams({ address }).toString()}` : "/v2/referral";
|
|
46502
|
+
const authorizationToken = address ? void 0 : requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
46503
|
+
const response = await apiFetch({
|
|
46504
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46505
|
+
method: "GET",
|
|
46506
|
+
authorizationToken,
|
|
46507
|
+
timeoutMs: opts.timeoutMs
|
|
46508
|
+
});
|
|
46509
|
+
return unwrapResponseObject(response);
|
|
46510
|
+
}
|
|
46511
|
+
async function apiGetReferralEarnings(opts) {
|
|
46512
|
+
const address = opts.address ? normalizeReferralAddress(opts.address, "address") : void 0;
|
|
46513
|
+
const endpoint = address ? `/v2/referral/earnings?${new URLSearchParams({ address }).toString()}` : "/v2/referral/earnings";
|
|
46514
|
+
const authorizationToken = address ? void 0 : requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
46515
|
+
const response = await apiFetch({
|
|
46516
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46517
|
+
method: "GET",
|
|
46518
|
+
authorizationToken,
|
|
46519
|
+
timeoutMs: opts.timeoutMs
|
|
46520
|
+
});
|
|
46521
|
+
return unwrapResponseObject(response);
|
|
46522
|
+
}
|
|
46523
|
+
async function apiLookupReferralCode(code, opts) {
|
|
46524
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
46525
|
+
const endpoint = `/v2/referral/code/${encodeURIComponent(normalizedCode)}`;
|
|
46526
|
+
const response = await apiFetch({
|
|
46527
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46528
|
+
method: "GET",
|
|
46529
|
+
timeoutMs: opts.timeoutMs
|
|
46530
|
+
});
|
|
46531
|
+
return unwrapResponseObject(response);
|
|
46532
|
+
}
|
|
46533
|
+
async function apiCreateReferralCode(req, opts) {
|
|
46534
|
+
const endpoint = "/v2/referral/code";
|
|
46535
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
46536
|
+
opts.authorizationToken,
|
|
46537
|
+
req.signature,
|
|
46538
|
+
endpoint
|
|
46539
|
+
);
|
|
46540
|
+
const response = await apiFetch({
|
|
46541
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46542
|
+
method: "POST",
|
|
46543
|
+
body: req.signature ? { signature: req.signature } : {},
|
|
46544
|
+
authorizationToken,
|
|
46545
|
+
timeoutMs: opts.timeoutMs
|
|
46546
|
+
});
|
|
46547
|
+
return unwrapResponseObject(response);
|
|
46548
|
+
}
|
|
46549
|
+
async function apiRedeemReferralCode(req, opts) {
|
|
46550
|
+
const endpoint = "/v2/referral/redeem";
|
|
46551
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
46552
|
+
opts.authorizationToken,
|
|
46553
|
+
req.signature,
|
|
46554
|
+
endpoint
|
|
46555
|
+
);
|
|
46556
|
+
const response = await apiFetch({
|
|
46557
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46558
|
+
method: "POST",
|
|
46559
|
+
body: {
|
|
46560
|
+
code: normalizeReferralCode(req.code),
|
|
46561
|
+
...req.signature ? { signature: req.signature } : {}
|
|
46562
|
+
},
|
|
46563
|
+
authorizationToken,
|
|
46564
|
+
timeoutMs: opts.timeoutMs
|
|
46565
|
+
});
|
|
46566
|
+
return unwrapResponseObject(response);
|
|
46567
|
+
}
|
|
46568
|
+
async function apiUpdateReferralCode(req, opts) {
|
|
46569
|
+
const endpoint = "/v2/referral/code";
|
|
46570
|
+
const authorizationToken = requireReferralWriteAuth(
|
|
46571
|
+
opts.authorizationToken,
|
|
46572
|
+
req.signature,
|
|
46573
|
+
endpoint
|
|
46574
|
+
);
|
|
46575
|
+
const response = await apiFetch({
|
|
46576
|
+
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
46577
|
+
method: "PATCH",
|
|
46578
|
+
body: {
|
|
46579
|
+
code: normalizeReferralCode(req.code),
|
|
46580
|
+
...req.signature ? { signature: req.signature } : {}
|
|
46581
|
+
},
|
|
46582
|
+
authorizationToken,
|
|
46583
|
+
timeoutMs: opts.timeoutMs
|
|
46584
|
+
});
|
|
46585
|
+
return unwrapResponseObject(response);
|
|
46586
|
+
}
|
|
46587
|
+
async function apiUploadSellerCredential(processorName, payeeDetails, bundle, baseApiUrl, timeoutMs, authorizationToken) {
|
|
46588
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
46589
|
+
payeeDetails
|
|
46590
|
+
)}/seller-credential`;
|
|
46591
|
+
return apiFetch({
|
|
46592
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
46593
|
+
method: "POST",
|
|
46594
|
+
body: bundle,
|
|
46595
|
+
timeoutMs,
|
|
46596
|
+
authorizationToken
|
|
46597
|
+
});
|
|
46598
|
+
}
|
|
46599
|
+
async function apiUploadGoogleOAuthSellerCredential(processorName, payeeDetails, body, baseApiUrl, opts) {
|
|
46600
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
46601
|
+
payeeDetails
|
|
46602
|
+
)}/seller-credential/google-oauth`;
|
|
46603
|
+
return apiFetch({
|
|
46604
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
46605
|
+
method: "POST",
|
|
46606
|
+
body,
|
|
46607
|
+
timeoutMs: opts?.timeoutMs
|
|
46608
|
+
});
|
|
46609
|
+
}
|
|
46610
|
+
async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApiUrl, timeoutMs) {
|
|
46611
|
+
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
46612
|
+
payeeDetails
|
|
46613
|
+
)}/seller-credential/status`;
|
|
46614
|
+
return apiFetch({
|
|
46615
|
+
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
46616
|
+
method: "GET",
|
|
46617
|
+
timeoutMs
|
|
46618
|
+
});
|
|
46619
|
+
}
|
|
46620
|
+
async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey) {
|
|
46621
|
+
const body = {
|
|
46622
|
+
txId: req.txId,
|
|
46623
|
+
chainId: req.chainId,
|
|
46624
|
+
intent: req.intent,
|
|
46625
|
+
...req.metadata !== void 0 ? { metadata: req.metadata } : {}
|
|
46626
|
+
};
|
|
46627
|
+
return apiFetch({
|
|
46628
|
+
url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
|
|
46629
|
+
method: "POST",
|
|
46630
|
+
body,
|
|
46631
|
+
apiKey,
|
|
46632
|
+
timeoutMs
|
|
46633
|
+
});
|
|
46634
|
+
}
|
|
46635
|
+
async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs) {
|
|
46636
|
+
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
46637
|
+
baseApiUrl: optsOrBaseApiUrl,
|
|
46638
|
+
timeoutMs
|
|
46639
|
+
} : optsOrBaseApiUrl;
|
|
46640
|
+
const query = new URLSearchParams();
|
|
46641
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
46642
|
+
if (value === void 0 || value === null) return;
|
|
46643
|
+
query.set(key, String(value));
|
|
46644
|
+
});
|
|
46645
|
+
const response = await apiFetch({
|
|
46646
|
+
url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook?${query.toString()}`,
|
|
46647
|
+
method: "GET",
|
|
46648
|
+
timeoutMs: opts.timeoutMs
|
|
46649
|
+
});
|
|
46650
|
+
return response.responseObject;
|
|
46651
|
+
}
|
|
46652
|
+
async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs) {
|
|
46653
|
+
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
46654
|
+
baseApiUrl: optsOrBaseApiUrl,
|
|
46655
|
+
timeoutMs
|
|
46656
|
+
} : optsOrBaseApiUrl;
|
|
46657
|
+
const escrowAddress = requireEscrowAddress(
|
|
46658
|
+
params.escrowAddress,
|
|
46659
|
+
"apiGetDepositBundle requires escrowAddress"
|
|
46660
|
+
);
|
|
46661
|
+
const query = new URLSearchParams({ escrowAddress });
|
|
46662
|
+
if (params.dailySnapshotLimit !== void 0) {
|
|
46663
|
+
query.set("dailySnapshotLimit", String(params.dailySnapshotLimit));
|
|
46637
46664
|
}
|
|
46638
|
-
|
|
46639
|
-
|
|
46640
|
-
|
|
46641
|
-
|
|
46642
|
-
|
|
46643
|
-
|
|
46644
|
-
|
|
46645
|
-
|
|
46646
|
-
|
|
46647
|
-
|
|
46648
|
-
|
|
46649
|
-
|
|
46650
|
-
|
|
46651
|
-
}));
|
|
46665
|
+
const response = await apiFetch({
|
|
46666
|
+
url: `${withApiBase(opts.baseApiUrl)}/v2/deposits/${params.depositId}/bundle?${query.toString()}`,
|
|
46667
|
+
method: "GET",
|
|
46668
|
+
timeoutMs: opts.timeoutMs
|
|
46669
|
+
});
|
|
46670
|
+
return response.responseObject;
|
|
46671
|
+
}
|
|
46672
|
+
|
|
46673
|
+
// src/client/ReferralAccountOperations.ts
|
|
46674
|
+
init_errors();
|
|
46675
|
+
var ReferralAccountOperations = class {
|
|
46676
|
+
constructor(config) {
|
|
46677
|
+
this.config = config;
|
|
46652
46678
|
}
|
|
46653
|
-
|
|
46654
|
-
|
|
46655
|
-
|
|
46679
|
+
async getReferralDashboard(opts) {
|
|
46680
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46681
|
+
const authorizationToken = opts?.address ? void 0 : await this.resolveAuthorizationToken(opts);
|
|
46682
|
+
return apiGetReferralDashboard({
|
|
46683
|
+
baseApiUrl,
|
|
46684
|
+
timeoutMs,
|
|
46685
|
+
authorizationToken,
|
|
46686
|
+
address: opts?.address
|
|
46687
|
+
});
|
|
46656
46688
|
}
|
|
46657
|
-
async
|
|
46658
|
-
|
|
46659
|
-
|
|
46660
|
-
|
|
46661
|
-
|
|
46662
|
-
|
|
46663
|
-
|
|
46664
|
-
|
|
46665
|
-
|
|
46666
|
-
}
|
|
46667
|
-
return this.client.query({
|
|
46668
|
-
query: LEGACY_RATE_MANAGER_LIST_QUERY,
|
|
46669
|
-
variables: legacyVariables
|
|
46670
|
-
});
|
|
46671
|
-
}
|
|
46689
|
+
async getReferralEarnings(opts) {
|
|
46690
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46691
|
+
const authorizationToken = opts?.address ? void 0 : await this.resolveAuthorizationToken(opts);
|
|
46692
|
+
return apiGetReferralEarnings({
|
|
46693
|
+
baseApiUrl,
|
|
46694
|
+
timeoutMs,
|
|
46695
|
+
authorizationToken,
|
|
46696
|
+
address: opts?.address
|
|
46697
|
+
});
|
|
46672
46698
|
}
|
|
46673
|
-
|
|
46674
|
-
const
|
|
46675
|
-
|
|
46676
|
-
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
46677
|
-
return [{ [field]: direction }];
|
|
46699
|
+
async lookupReferralCode(code, opts) {
|
|
46700
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46701
|
+
return apiLookupReferralCode(code, { baseApiUrl, timeoutMs });
|
|
46678
46702
|
}
|
|
46679
|
-
|
|
46680
|
-
const
|
|
46681
|
-
const
|
|
46682
|
-
|
|
46683
|
-
return [{ [field]: direction }];
|
|
46703
|
+
async createReferralCode(opts) {
|
|
46704
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46705
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
46706
|
+
return apiCreateReferralCode({}, { baseApiUrl, timeoutMs, authorizationToken });
|
|
46684
46707
|
}
|
|
46685
|
-
async
|
|
46686
|
-
const
|
|
46687
|
-
|
|
46688
|
-
|
|
46689
|
-
const delegations = await this.fetchRateManagerDelegations(rateManagerId, {
|
|
46690
|
-
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
46691
|
-
offset,
|
|
46692
|
-
orderBy: "delegatedAt",
|
|
46693
|
-
orderDirection: "desc",
|
|
46694
|
-
rateManagerAddress: rateManagerAddress || void 0
|
|
46695
|
-
});
|
|
46696
|
-
for (const delegation of delegations) {
|
|
46697
|
-
const escrow = extractEscrowAddressFromCompositeDepositId(delegation.depositId);
|
|
46698
|
-
const depositIdOnContract = extractDepositIdOnContract(delegation.depositId);
|
|
46699
|
-
if (!escrow || !depositIdOnContract) continue;
|
|
46700
|
-
const scope = { escrow, depositIdOnContract };
|
|
46701
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
46702
|
-
}
|
|
46703
|
-
if (delegations.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
46704
|
-
break;
|
|
46705
|
-
}
|
|
46706
|
-
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
46707
|
-
}
|
|
46708
|
-
return [...scopes.values()];
|
|
46708
|
+
async createReferralCodeWithSignature(opts) {
|
|
46709
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46710
|
+
const signature = await this.signCreateReferralCode(opts);
|
|
46711
|
+
return apiCreateReferralCode({ signature }, { baseApiUrl, timeoutMs });
|
|
46709
46712
|
}
|
|
46710
|
-
async
|
|
46711
|
-
const
|
|
46712
|
-
const
|
|
46713
|
-
|
|
46714
|
-
const currentScopes = await this.fetchCurrentRateManagerDepositScopes(
|
|
46715
|
-
normalizedId,
|
|
46716
|
-
normalizedRateManagerAddress || void 0
|
|
46717
|
-
);
|
|
46718
|
-
for (const scope of currentScopes) {
|
|
46719
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
46720
|
-
}
|
|
46721
|
-
try {
|
|
46722
|
-
let offset = 0;
|
|
46723
|
-
for (; ; ) {
|
|
46724
|
-
const result = await this.client.query({
|
|
46725
|
-
query: RATE_MANAGER_ASSIGNMENT_EVENTS_QUERY,
|
|
46726
|
-
variables: {
|
|
46727
|
-
setWhere: {
|
|
46728
|
-
rateManagerId: { _eq: normalizedId },
|
|
46729
|
-
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
46730
|
-
},
|
|
46731
|
-
clearedWhere: {
|
|
46732
|
-
rateManagerId: { _eq: normalizedId },
|
|
46733
|
-
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
46734
|
-
},
|
|
46735
|
-
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
46736
|
-
offset
|
|
46737
|
-
}
|
|
46738
|
-
});
|
|
46739
|
-
const setEvents = result.EscrowV2_DepositRateManagerSet ?? [];
|
|
46740
|
-
const clearedEvents = result.EscrowV2_DepositRateManagerCleared ?? [];
|
|
46741
|
-
for (const event of [...setEvents, ...clearedEvents]) {
|
|
46742
|
-
const escrow = normalizeAddress3(event.escrow);
|
|
46743
|
-
const depositIdOnContract = event.depositIdOnContract?.toString() ?? "";
|
|
46744
|
-
if (!escrow || !depositIdOnContract) continue;
|
|
46745
|
-
const scope = { escrow, depositIdOnContract };
|
|
46746
|
-
scopes.set(buildDepositScopeKey(scope), scope);
|
|
46747
|
-
}
|
|
46748
|
-
if (setEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE && clearedEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
46749
|
-
break;
|
|
46750
|
-
}
|
|
46751
|
-
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
46752
|
-
}
|
|
46753
|
-
} catch (error) {
|
|
46754
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
46755
|
-
throw error;
|
|
46756
|
-
}
|
|
46757
|
-
}
|
|
46758
|
-
return [...scopes.values()];
|
|
46713
|
+
async redeemReferralCode(code, opts) {
|
|
46714
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46715
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
46716
|
+
return apiRedeemReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
46759
46717
|
}
|
|
46760
|
-
async
|
|
46761
|
-
const
|
|
46762
|
-
const
|
|
46763
|
-
const
|
|
46764
|
-
const
|
|
46765
|
-
|
|
46766
|
-
|
|
46767
|
-
|
|
46768
|
-
|
|
46769
|
-
const result2 = await this.queryRateManagerList(
|
|
46770
|
-
{
|
|
46771
|
-
where,
|
|
46772
|
-
aggregateWhere,
|
|
46773
|
-
order_by: [{ createdAt: "desc" }]
|
|
46774
|
-
},
|
|
46775
|
-
{
|
|
46776
|
-
where,
|
|
46777
|
-
aggregateWhere: legacyAggregateWhere,
|
|
46778
|
-
order_by: [{ createdAt: "desc" }]
|
|
46779
|
-
}
|
|
46718
|
+
async redeemReferralCodeWithSignature(code, opts) {
|
|
46719
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46720
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
46721
|
+
const lookup = opts?.referrerWalletAddress ? void 0 : await this.lookupReferralCode(normalizedCode, { baseApiUrl, timeoutMs });
|
|
46722
|
+
const referrerWalletAddress = opts?.referrerWalletAddress ?? lookup?.referrerWalletAddress;
|
|
46723
|
+
if (!referrerWalletAddress) {
|
|
46724
|
+
throw new exports.ValidationError(
|
|
46725
|
+
"referrerWalletAddress is required for referral signature auth",
|
|
46726
|
+
"referrerWalletAddress"
|
|
46780
46727
|
);
|
|
46781
|
-
const scopedRows = this.applyHookFilter(this.toRateManagerListItems(result2), filter?.hasHook);
|
|
46782
|
-
const sorted = scopedRows.sort((a, b) => {
|
|
46783
|
-
const av = orderBy === "currentDelegatedBalance" ? toSafeBigInt(a.aggregate?.currentDelegatedBalance) : toSafeBigInt(a.aggregate?.totalFilledVolume);
|
|
46784
|
-
const bv = orderBy === "currentDelegatedBalance" ? toSafeBigInt(b.aggregate?.currentDelegatedBalance) : toSafeBigInt(b.aggregate?.totalFilledVolume);
|
|
46785
|
-
const aggregateCmp = compareBigInt(av, bv, direction);
|
|
46786
|
-
if (aggregateCmp !== 0) return aggregateCmp;
|
|
46787
|
-
const createdAtCmp = compareBigInt(
|
|
46788
|
-
toSafeBigInt(a.manager.createdAt),
|
|
46789
|
-
toSafeBigInt(b.manager.createdAt),
|
|
46790
|
-
"desc"
|
|
46791
|
-
);
|
|
46792
|
-
if (createdAtCmp !== 0) return createdAtCmp;
|
|
46793
|
-
return a.manager.rateManagerId.localeCompare(b.manager.rateManagerId);
|
|
46794
|
-
});
|
|
46795
|
-
return sorted.slice(offset, offset + limit);
|
|
46796
46728
|
}
|
|
46797
|
-
|
|
46798
|
-
|
|
46799
|
-
|
|
46800
|
-
|
|
46801
|
-
|
|
46802
|
-
|
|
46803
|
-
|
|
46804
|
-
},
|
|
46805
|
-
{
|
|
46806
|
-
where,
|
|
46807
|
-
aggregateWhere: legacyAggregateWhere,
|
|
46808
|
-
order_by: this.buildOrderBy(pagination),
|
|
46809
|
-
limit,
|
|
46810
|
-
offset
|
|
46811
|
-
}
|
|
46729
|
+
if (lookup && !lookup.isActive) {
|
|
46730
|
+
throw new exports.ValidationError("Referral code is not active", "code");
|
|
46731
|
+
}
|
|
46732
|
+
const signature = await this.signRedeemReferralCode(
|
|
46733
|
+
normalizedCode,
|
|
46734
|
+
referrerWalletAddress,
|
|
46735
|
+
opts
|
|
46812
46736
|
);
|
|
46813
|
-
return
|
|
46737
|
+
return apiRedeemReferralCode({ code: normalizedCode, signature }, { baseApiUrl, timeoutMs });
|
|
46814
46738
|
}
|
|
46815
|
-
async
|
|
46816
|
-
|
|
46817
|
-
const
|
|
46818
|
-
|
|
46819
|
-
|
|
46820
|
-
|
|
46821
|
-
|
|
46822
|
-
|
|
46823
|
-
|
|
46824
|
-
|
|
46825
|
-
|
|
46826
|
-
|
|
46827
|
-
|
|
46828
|
-
|
|
46829
|
-
|
|
46830
|
-
|
|
46831
|
-
id: {
|
|
46832
|
-
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
46833
|
-
normalizedId,
|
|
46834
|
-
normalizedRateManagerAddress
|
|
46835
|
-
)
|
|
46836
|
-
}
|
|
46837
|
-
} : {}
|
|
46838
|
-
},
|
|
46839
|
-
statsWhere: {
|
|
46840
|
-
rateManagerId: { _eq: normalizedId },
|
|
46841
|
-
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
46842
|
-
},
|
|
46843
|
-
delegationWhere: {
|
|
46844
|
-
rateManagerId: { _eq: normalizedId },
|
|
46845
|
-
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
46846
|
-
},
|
|
46847
|
-
statsLimit: options?.statsLimit ?? 20
|
|
46848
|
-
};
|
|
46849
|
-
const legacyVariables = {
|
|
46850
|
-
...baseVariables,
|
|
46851
|
-
floorWhere: {
|
|
46852
|
-
rateManagerId: { _eq: normalizedId },
|
|
46853
|
-
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
46854
|
-
}
|
|
46739
|
+
async updateReferralCode(code, opts) {
|
|
46740
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46741
|
+
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
46742
|
+
return apiUpdateReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
46743
|
+
}
|
|
46744
|
+
async updateReferralCodeWithSignature(code, opts) {
|
|
46745
|
+
const { baseApiUrl, timeoutMs } = this.resolveRequestOptions(opts);
|
|
46746
|
+
const signature = await this.signRenameReferralCode(code, opts.oldCode, opts);
|
|
46747
|
+
return apiUpdateReferralCode({ code, signature }, { baseApiUrl, timeoutMs });
|
|
46748
|
+
}
|
|
46749
|
+
resolveRequestOptions(opts) {
|
|
46750
|
+
return {
|
|
46751
|
+
baseApiUrl: this.stripTrailingSlash(
|
|
46752
|
+
opts?.baseApiUrl ?? this.config.getBaseApiUrl() ?? DEFAULT_BASE_API_URL
|
|
46753
|
+
),
|
|
46754
|
+
timeoutMs: opts?.timeoutMs ?? this.config.getApiTimeoutMs()
|
|
46855
46755
|
};
|
|
46856
|
-
|
|
46857
|
-
|
|
46858
|
-
|
|
46859
|
-
|
|
46860
|
-
|
|
46861
|
-
|
|
46862
|
-
|
|
46863
|
-
|
|
46864
|
-
|
|
46865
|
-
|
|
46866
|
-
|
|
46867
|
-
|
|
46868
|
-
|
|
46869
|
-
|
|
46870
|
-
|
|
46756
|
+
}
|
|
46757
|
+
stripTrailingSlash(url) {
|
|
46758
|
+
return url.replace(/\/$/, "");
|
|
46759
|
+
}
|
|
46760
|
+
async resolveAuthorizationToken(opts) {
|
|
46761
|
+
if (opts?.authorizationToken !== void 0) {
|
|
46762
|
+
return opts.authorizationToken;
|
|
46763
|
+
}
|
|
46764
|
+
const provider = opts?.getAuthorizationToken ?? this.config.getAuthorizationTokenProvider();
|
|
46765
|
+
if (provider) {
|
|
46766
|
+
return await provider() ?? void 0;
|
|
46767
|
+
}
|
|
46768
|
+
return this.config.getAuthorizationToken();
|
|
46769
|
+
}
|
|
46770
|
+
resolveAudience(audience) {
|
|
46771
|
+
if (audience) return audience;
|
|
46772
|
+
if (this.config.getChainId() === chains.hardhat.id) return "localhardhat";
|
|
46773
|
+
if (this.config.getRuntimeEnv() === "staging") return "base_staging";
|
|
46774
|
+
return "base_production";
|
|
46775
|
+
}
|
|
46776
|
+
resolveIssuedAt(issuedAt) {
|
|
46777
|
+
const resolved = issuedAt ?? Math.floor(Date.now() / 1e3);
|
|
46778
|
+
if (!Number.isInteger(resolved) || resolved <= 0) {
|
|
46779
|
+
throw new exports.ValidationError("issuedAt must be a positive unix timestamp", "issuedAt");
|
|
46780
|
+
}
|
|
46781
|
+
return resolved;
|
|
46782
|
+
}
|
|
46783
|
+
getSigningAccount() {
|
|
46784
|
+
const walletClient = this.config.getWalletClient();
|
|
46785
|
+
const account = walletClient.account;
|
|
46786
|
+
if (!account) {
|
|
46787
|
+
throw new exports.ValidationError(
|
|
46788
|
+
"walletClient account is required for referral signature auth",
|
|
46789
|
+
"walletClient.account"
|
|
46871
46790
|
);
|
|
46872
|
-
|
|
46873
|
-
|
|
46874
|
-
|
|
46875
|
-
|
|
46876
|
-
|
|
46877
|
-
|
|
46791
|
+
}
|
|
46792
|
+
const rawAddress = typeof account === "string" ? account : account.address;
|
|
46793
|
+
const walletAddress = normalizeAddress(rawAddress);
|
|
46794
|
+
if (!walletAddress) {
|
|
46795
|
+
throw new exports.ValidationError(
|
|
46796
|
+
"walletClient account address is required for referral signature auth",
|
|
46797
|
+
"walletClient.account"
|
|
46878
46798
|
);
|
|
46879
|
-
|
|
46880
|
-
|
|
46881
|
-
|
|
46882
|
-
|
|
46883
|
-
|
|
46884
|
-
|
|
46799
|
+
}
|
|
46800
|
+
return { account, walletAddress };
|
|
46801
|
+
}
|
|
46802
|
+
normalizeReferralWalletAddress(address, field) {
|
|
46803
|
+
const normalized = normalizeAddress(address.toLowerCase());
|
|
46804
|
+
if (!normalized) {
|
|
46805
|
+
throw new exports.ValidationError(`${field} must be a valid Ethereum address`, field);
|
|
46806
|
+
}
|
|
46807
|
+
return normalized;
|
|
46808
|
+
}
|
|
46809
|
+
async signCreateReferralCode(opts) {
|
|
46810
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
46811
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
46812
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
46813
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
46814
|
+
account,
|
|
46815
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
46816
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
46817
|
+
primaryType: "CreateCode",
|
|
46818
|
+
message: { wallet: walletAddress, audience, issuedAt: BigInt(issuedAt) }
|
|
46819
|
+
});
|
|
46820
|
+
return { walletAddress, signature, issuedAt, audience };
|
|
46821
|
+
}
|
|
46822
|
+
async signRedeemReferralCode(code, referrerWalletAddress, opts) {
|
|
46823
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
46824
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
46825
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
46826
|
+
const normalizedCode = normalizeReferralCode(code);
|
|
46827
|
+
const referrer = this.normalizeReferralWalletAddress(
|
|
46828
|
+
referrerWalletAddress,
|
|
46829
|
+
"referrerWalletAddress"
|
|
46830
|
+
);
|
|
46831
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
46832
|
+
account,
|
|
46833
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
46834
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
46835
|
+
primaryType: "RedeemCode",
|
|
46836
|
+
message: {
|
|
46837
|
+
wallet: walletAddress,
|
|
46838
|
+
code: normalizedCode,
|
|
46839
|
+
referrer,
|
|
46840
|
+
audience,
|
|
46841
|
+
issuedAt: BigInt(issuedAt)
|
|
46885
46842
|
}
|
|
46886
|
-
|
|
46887
|
-
|
|
46888
|
-
|
|
46889
|
-
|
|
46890
|
-
|
|
46891
|
-
|
|
46892
|
-
|
|
46893
|
-
|
|
46894
|
-
|
|
46895
|
-
|
|
46896
|
-
|
|
46897
|
-
|
|
46898
|
-
|
|
46899
|
-
|
|
46900
|
-
|
|
46901
|
-
|
|
46902
|
-
|
|
46903
|
-
|
|
46904
|
-
|
|
46905
|
-
|
|
46843
|
+
});
|
|
46844
|
+
return { walletAddress, signature, issuedAt, audience, referrer };
|
|
46845
|
+
}
|
|
46846
|
+
async signRenameReferralCode(newCode, oldCode, opts) {
|
|
46847
|
+
const { account, walletAddress } = this.getSigningAccount();
|
|
46848
|
+
const issuedAt = this.resolveIssuedAt(opts?.issuedAt);
|
|
46849
|
+
const audience = this.resolveAudience(opts?.audience);
|
|
46850
|
+
const normalizedOldCode = normalizeReferralCode(oldCode);
|
|
46851
|
+
const normalizedNewCode = normalizeReferralCode(newCode);
|
|
46852
|
+
const signature = await this.config.getWalletClient().signTypedData({
|
|
46853
|
+
account,
|
|
46854
|
+
domain: REFERRAL_SIGNATURE_DOMAIN,
|
|
46855
|
+
types: REFERRAL_SIGNATURE_TYPES,
|
|
46856
|
+
primaryType: "RenameCode",
|
|
46857
|
+
message: {
|
|
46858
|
+
wallet: walletAddress,
|
|
46859
|
+
oldCode: normalizedOldCode,
|
|
46860
|
+
newCode: normalizedNewCode,
|
|
46861
|
+
audience,
|
|
46862
|
+
issuedAt: BigInt(issuedAt)
|
|
46863
|
+
}
|
|
46864
|
+
});
|
|
46865
|
+
return { walletAddress, signature, issuedAt, audience, oldCode: normalizedOldCode };
|
|
46866
|
+
}
|
|
46867
|
+
};
|
|
46868
|
+
|
|
46869
|
+
// src/client/VaultOperations.ts
|
|
46870
|
+
var VaultOperations = class {
|
|
46871
|
+
constructor(config) {
|
|
46872
|
+
this.config = config;
|
|
46873
|
+
}
|
|
46874
|
+
supportsInlineOracleRateConfig(params) {
|
|
46875
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
46876
|
+
escrowAddress: params?.escrowAddress
|
|
46877
|
+
});
|
|
46878
|
+
return escrowCurrencyHasOracleConfig(escrowContext.abi);
|
|
46879
|
+
}
|
|
46880
|
+
resolveRateManagerRegistryContract(registryAddress) {
|
|
46881
|
+
const abi = this.config.getRateManagerRegistryAbi();
|
|
46882
|
+
if (!abi) {
|
|
46883
|
+
throw this.buildRateManagerUnavailableError("Rate manager registry not available");
|
|
46884
|
+
}
|
|
46885
|
+
if (registryAddress) {
|
|
46886
|
+
return {
|
|
46887
|
+
address: registryAddress,
|
|
46888
|
+
abi
|
|
46889
|
+
};
|
|
46890
|
+
}
|
|
46891
|
+
const address = this.config.getRateManagerRegistryAddress();
|
|
46892
|
+
if (!address) {
|
|
46893
|
+
throw this.buildRateManagerUnavailableError("Rate manager registry not available");
|
|
46906
46894
|
}
|
|
46907
|
-
if (!managerRaw) return null;
|
|
46908
|
-
const manager = normalizeRateManagerEntity(managerRaw);
|
|
46909
46895
|
return {
|
|
46910
|
-
|
|
46911
|
-
|
|
46912
|
-
aggregate,
|
|
46913
|
-
recentStats: scopedRecentStats,
|
|
46914
|
-
delegations: scopedDelegations
|
|
46896
|
+
address,
|
|
46897
|
+
abi
|
|
46915
46898
|
};
|
|
46916
46899
|
}
|
|
46917
|
-
|
|
46918
|
-
|
|
46919
|
-
|
|
46920
|
-
|
|
46921
|
-
|
|
46922
|
-
|
|
46923
|
-
|
|
46924
|
-
|
|
46925
|
-
|
|
46926
|
-
|
|
46927
|
-
|
|
46928
|
-
|
|
46900
|
+
buildRateManagerUnavailableError(reason) {
|
|
46901
|
+
const initError = this.config.getRateManagerInitError();
|
|
46902
|
+
if (!initError) {
|
|
46903
|
+
return new Error(reason);
|
|
46904
|
+
}
|
|
46905
|
+
return new Error(
|
|
46906
|
+
`${reason}. Rate manager contracts failed to initialize: ${initError.message}`
|
|
46907
|
+
);
|
|
46908
|
+
}
|
|
46909
|
+
buildCreateRateManagerConfig(config) {
|
|
46910
|
+
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
46911
|
+
const includeDepositHook = abiTupleHasComponent(
|
|
46912
|
+
registryAbi,
|
|
46913
|
+
"createRateManager",
|
|
46914
|
+
"depositHook"
|
|
46915
|
+
);
|
|
46916
|
+
const includeMinLiquidity = abiTupleHasComponent(
|
|
46917
|
+
registryAbi,
|
|
46918
|
+
"createRateManager",
|
|
46919
|
+
"minLiquidity"
|
|
46920
|
+
);
|
|
46921
|
+
const result = {
|
|
46922
|
+
manager: config.manager,
|
|
46923
|
+
feeRecipient: config.feeRecipient,
|
|
46924
|
+
maxFee: config.maxFee,
|
|
46925
|
+
fee: config.fee
|
|
46929
46926
|
};
|
|
46930
|
-
|
|
46931
|
-
|
|
46932
|
-
|
|
46933
|
-
|
|
46934
|
-
|
|
46935
|
-
|
|
46936
|
-
|
|
46937
|
-
|
|
46938
|
-
|
|
46939
|
-
|
|
46940
|
-
|
|
46941
|
-
|
|
46942
|
-
|
|
46943
|
-
|
|
46944
|
-
|
|
46945
|
-
|
|
46946
|
-
|
|
46947
|
-
|
|
46927
|
+
if (includeDepositHook) {
|
|
46928
|
+
result.depositHook = config.depositHook ?? ZERO_ADDRESS;
|
|
46929
|
+
}
|
|
46930
|
+
if (includeMinLiquidity) {
|
|
46931
|
+
result.minLiquidity = config.minLiquidity ?? 0n;
|
|
46932
|
+
}
|
|
46933
|
+
result.name = config.name;
|
|
46934
|
+
result.uri = config.uri;
|
|
46935
|
+
return result;
|
|
46936
|
+
}
|
|
46937
|
+
buildSetRateManagerConfigArgs(params) {
|
|
46938
|
+
const registryAbi = this.config.getRateManagerRegistryAbi();
|
|
46939
|
+
const includeHook = abiFunctionHasInput(registryAbi, "setRateManagerConfig", "_newHook") || abiFunctionHasInput(registryAbi, "setRateManagerConfig", "newHook");
|
|
46940
|
+
if (includeHook) {
|
|
46941
|
+
return [
|
|
46942
|
+
params.rateManagerId,
|
|
46943
|
+
params.newManager,
|
|
46944
|
+
params.newFeeRecipient,
|
|
46945
|
+
params.newHook ?? ZERO_ADDRESS,
|
|
46946
|
+
params.newName,
|
|
46947
|
+
params.newUri
|
|
46948
|
+
];
|
|
46949
|
+
}
|
|
46950
|
+
return [
|
|
46951
|
+
params.rateManagerId,
|
|
46952
|
+
params.newManager,
|
|
46953
|
+
params.newFeeRecipient,
|
|
46954
|
+
params.newName,
|
|
46955
|
+
params.newUri
|
|
46956
|
+
];
|
|
46957
|
+
}
|
|
46958
|
+
prepareRateManagerRegistryTransaction(opts) {
|
|
46959
|
+
const contract = this.resolveRateManagerRegistryContract(opts.registry);
|
|
46960
|
+
const functionName = resolveAbiFunctionName(contract.abi, opts.functionNames);
|
|
46961
|
+
return this.config.host.prepareContractTransaction({
|
|
46962
|
+
address: contract.address,
|
|
46963
|
+
abi: contract.abi,
|
|
46964
|
+
functionName,
|
|
46965
|
+
args: opts.args,
|
|
46966
|
+
txOverrides: opts.txOverrides
|
|
46967
|
+
});
|
|
46968
|
+
}
|
|
46969
|
+
prepareCreateRateManagerTransaction(params) {
|
|
46970
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
46971
|
+
functionNames: ["createRateManager"],
|
|
46972
|
+
args: [this.buildCreateRateManagerConfig(params.config)],
|
|
46973
|
+
txOverrides: params.txOverrides
|
|
46974
|
+
});
|
|
46975
|
+
}
|
|
46976
|
+
prepareSetVaultRateTransaction(params) {
|
|
46977
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
46978
|
+
functionNames: ["setRate", "setMinRate"],
|
|
46979
|
+
args: [params.rateManagerId, params.paymentMethodHash, params.currencyHash, params.rate],
|
|
46980
|
+
txOverrides: params.txOverrides
|
|
46981
|
+
});
|
|
46982
|
+
}
|
|
46983
|
+
prepareSetVaultRatesBatchTransaction(params) {
|
|
46984
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
46985
|
+
functionNames: ["setRateBatch", "setMinRatesBatch"],
|
|
46986
|
+
args: [params.rateManagerId, params.paymentMethods, params.currencies, params.rates],
|
|
46987
|
+
txOverrides: params.txOverrides
|
|
46988
|
+
});
|
|
46989
|
+
}
|
|
46990
|
+
prepareSetOracleRateConfigTransaction(params) {
|
|
46991
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
46992
|
+
escrowAddress: params.escrowAddress,
|
|
46993
|
+
depositId: params.depositId
|
|
46994
|
+
});
|
|
46995
|
+
if (escrowContext.version !== "v2") {
|
|
46996
|
+
throw new Error("setOracleRateConfig requires EscrowV2");
|
|
46997
|
+
}
|
|
46998
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfig"]);
|
|
46999
|
+
return this.config.host.prepareEscrowTransaction({
|
|
47000
|
+
functionName,
|
|
47001
|
+
args: [
|
|
47002
|
+
parseRawDepositId(params.depositId),
|
|
47003
|
+
params.paymentMethodHash,
|
|
47004
|
+
params.currencyHash,
|
|
47005
|
+
normalizeOracleRateConfig(params.config)
|
|
47006
|
+
],
|
|
47007
|
+
txOverrides: params.txOverrides,
|
|
47008
|
+
escrowAddress: escrowContext.address,
|
|
47009
|
+
escrowAbi: escrowContext.abi
|
|
47010
|
+
});
|
|
47011
|
+
}
|
|
47012
|
+
prepareRemoveOracleRateConfigTransaction(params) {
|
|
47013
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47014
|
+
escrowAddress: params.escrowAddress,
|
|
47015
|
+
depositId: params.depositId
|
|
47016
|
+
});
|
|
47017
|
+
if (escrowContext.version !== "v2") {
|
|
47018
|
+
throw new Error("removeOracleRateConfig requires EscrowV2");
|
|
46948
47019
|
}
|
|
47020
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["removeOracleRateConfig"]);
|
|
47021
|
+
return this.config.host.prepareEscrowTransaction({
|
|
47022
|
+
functionName,
|
|
47023
|
+
args: [parseRawDepositId(params.depositId), params.paymentMethodHash, params.currencyHash],
|
|
47024
|
+
txOverrides: params.txOverrides,
|
|
47025
|
+
escrowAddress: escrowContext.address,
|
|
47026
|
+
escrowAbi: escrowContext.abi
|
|
47027
|
+
});
|
|
46949
47028
|
}
|
|
46950
|
-
|
|
46951
|
-
|
|
46952
|
-
|
|
46953
|
-
|
|
46954
|
-
|
|
46955
|
-
|
|
46956
|
-
|
|
46957
|
-
variables: {
|
|
46958
|
-
where: {
|
|
46959
|
-
rateManagerId: { _eq: normalizedId },
|
|
46960
|
-
...normalizedRateManagerAddress ? {
|
|
46961
|
-
id: {
|
|
46962
|
-
_ilike: buildRateManagerScopedIdPattern(
|
|
46963
|
-
normalizedId,
|
|
46964
|
-
normalizedRateManagerAddress
|
|
46965
|
-
)
|
|
46966
|
-
}
|
|
46967
|
-
} : {}
|
|
46968
|
-
},
|
|
46969
|
-
order_by: [{ dayTimestamp: "asc" }],
|
|
46970
|
-
limit: options?.limit ?? 365
|
|
46971
|
-
}
|
|
46972
|
-
});
|
|
46973
|
-
return result.ManagerDailySnapshot ?? [];
|
|
46974
|
-
} catch (error) {
|
|
46975
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
46976
|
-
throw error;
|
|
46977
|
-
}
|
|
46978
|
-
return [];
|
|
47029
|
+
prepareSetOracleRateConfigBatchTransaction(params) {
|
|
47030
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47031
|
+
escrowAddress: params.escrowAddress,
|
|
47032
|
+
depositId: params.depositId
|
|
47033
|
+
});
|
|
47034
|
+
if (escrowContext.version !== "v2") {
|
|
47035
|
+
throw new Error("setOracleRateConfigBatch requires EscrowV2");
|
|
46979
47036
|
}
|
|
47037
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["setOracleRateConfigBatch"]);
|
|
47038
|
+
return this.config.host.prepareEscrowTransaction({
|
|
47039
|
+
functionName,
|
|
47040
|
+
args: [
|
|
47041
|
+
parseRawDepositId(params.depositId),
|
|
47042
|
+
params.paymentMethods,
|
|
47043
|
+
params.currencies,
|
|
47044
|
+
params.configs.map((group) => group.map((config) => normalizeOracleRateConfig(config)))
|
|
47045
|
+
],
|
|
47046
|
+
txOverrides: params.txOverrides,
|
|
47047
|
+
escrowAddress: escrowContext.address,
|
|
47048
|
+
escrowAbi: escrowContext.abi
|
|
47049
|
+
});
|
|
46980
47050
|
}
|
|
46981
|
-
|
|
46982
|
-
|
|
46983
|
-
|
|
46984
|
-
|
|
46985
|
-
|
|
46986
|
-
|
|
46987
|
-
|
|
46988
|
-
depositId: normalizedDepositId
|
|
46989
|
-
}
|
|
46990
|
-
});
|
|
46991
|
-
const delegationDeposit = result.Deposit?.[0];
|
|
46992
|
-
if (!delegationDeposit) {
|
|
46993
|
-
return null;
|
|
46994
|
-
}
|
|
46995
|
-
return toDelegationEntityFromDeposit(delegationDeposit) ?? null;
|
|
46996
|
-
} catch (error) {
|
|
46997
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
46998
|
-
throw error;
|
|
46999
|
-
}
|
|
47000
|
-
const legacyResult = await this.client.query({
|
|
47001
|
-
query: LEGACY_DEPOSIT_DELEGATION_QUERY,
|
|
47002
|
-
variables: {
|
|
47003
|
-
depositId: normalizedDepositId
|
|
47004
|
-
}
|
|
47005
|
-
});
|
|
47006
|
-
return legacyResult.RateManagerDelegation?.[0] ?? null;
|
|
47051
|
+
prepareUpdateCurrencyConfigBatchTransaction(params) {
|
|
47052
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47053
|
+
escrowAddress: params.escrowAddress,
|
|
47054
|
+
depositId: params.depositId
|
|
47055
|
+
});
|
|
47056
|
+
if (escrowContext.version !== "v2") {
|
|
47057
|
+
throw new Error("updateCurrencyConfigBatch requires EscrowV2");
|
|
47007
47058
|
}
|
|
47059
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["updateCurrencyConfigBatch"]);
|
|
47060
|
+
return this.config.host.prepareEscrowTransaction({
|
|
47061
|
+
functionName,
|
|
47062
|
+
args: [
|
|
47063
|
+
parseRawDepositId(params.depositId),
|
|
47064
|
+
params.paymentMethods,
|
|
47065
|
+
params.updates.map(
|
|
47066
|
+
(group) => group.map((update) => ({
|
|
47067
|
+
code: update.code,
|
|
47068
|
+
minConversionRate: typeof update.minConversionRate === "bigint" ? update.minConversionRate : BigInt(update.minConversionRate),
|
|
47069
|
+
updateOracle: update.updateOracle,
|
|
47070
|
+
oracleRateConfig: normalizeOracleRateConfig(update.oracleRateConfig)
|
|
47071
|
+
}))
|
|
47072
|
+
)
|
|
47073
|
+
],
|
|
47074
|
+
txOverrides: params.txOverrides,
|
|
47075
|
+
escrowAddress: escrowContext.address,
|
|
47076
|
+
escrowAbi: escrowContext.abi
|
|
47077
|
+
});
|
|
47008
47078
|
}
|
|
47009
|
-
|
|
47010
|
-
|
|
47011
|
-
|
|
47012
|
-
|
|
47013
|
-
|
|
47014
|
-
|
|
47015
|
-
|
|
47016
|
-
where: {
|
|
47017
|
-
rateManagerId: { _eq: normalizedId }
|
|
47018
|
-
},
|
|
47019
|
-
order_by: [{ id: "desc" }],
|
|
47020
|
-
limit: options?.limit ?? 100
|
|
47021
|
-
}
|
|
47022
|
-
});
|
|
47023
|
-
return (result.RateManagerV1_RateManagerRateUpdated ?? []).map((e) => ({
|
|
47024
|
-
...e,
|
|
47025
|
-
currency: e.currency ?? e.currencyCode ?? "",
|
|
47026
|
-
minRate: e.minRate ?? e.rate ?? "0"
|
|
47027
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47028
|
-
} catch (error) {
|
|
47029
|
-
if (!isSchemaCompatibilityError(error)) {
|
|
47030
|
-
throw error;
|
|
47031
|
-
}
|
|
47032
|
-
return [];
|
|
47079
|
+
prepareDeactivateCurrenciesBatchTransaction(params) {
|
|
47080
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47081
|
+
escrowAddress: params.escrowAddress,
|
|
47082
|
+
depositId: params.depositId
|
|
47083
|
+
});
|
|
47084
|
+
if (escrowContext.version !== "v2") {
|
|
47085
|
+
throw new Error("deactivateCurrenciesBatch requires EscrowV2");
|
|
47033
47086
|
}
|
|
47087
|
+
const functionName = resolveAbiFunctionName(escrowContext.abi, ["deactivateCurrenciesBatch"]);
|
|
47088
|
+
return this.config.host.prepareEscrowTransaction({
|
|
47089
|
+
functionName,
|
|
47090
|
+
args: [parseRawDepositId(params.depositId), params.paymentMethods, params.currencyCodes],
|
|
47091
|
+
txOverrides: params.txOverrides,
|
|
47092
|
+
escrowAddress: escrowContext.address,
|
|
47093
|
+
escrowAbi: escrowContext.abi
|
|
47094
|
+
});
|
|
47034
47095
|
}
|
|
47035
|
-
|
|
47036
|
-
|
|
47037
|
-
|
|
47038
|
-
|
|
47039
|
-
|
|
47040
|
-
|
|
47041
|
-
|
|
47042
|
-
|
|
47043
|
-
|
|
47044
|
-
|
|
47045
|
-
|
|
47046
|
-
|
|
47047
|
-
|
|
47048
|
-
|
|
47049
|
-
const result = await this.
|
|
47050
|
-
|
|
47051
|
-
|
|
47052
|
-
|
|
47053
|
-
|
|
47054
|
-
_and: [
|
|
47055
|
-
{ depositId: { _eq: scope.depositIdOnContract } },
|
|
47056
|
-
{ escrow: { _eq: scope.escrow } }
|
|
47057
|
-
]
|
|
47058
|
-
}))
|
|
47059
|
-
},
|
|
47060
|
-
order_by: [{ id: "desc" }],
|
|
47061
|
-
limit
|
|
47062
|
-
}
|
|
47096
|
+
prepareSetVaultConfigTransaction(params) {
|
|
47097
|
+
return this.prepareRateManagerRegistryTransaction({
|
|
47098
|
+
functionNames: ["setRateManagerConfig"],
|
|
47099
|
+
args: this.buildSetRateManagerConfigArgs(params),
|
|
47100
|
+
txOverrides: params.txOverrides
|
|
47101
|
+
});
|
|
47102
|
+
}
|
|
47103
|
+
async getDepositRateManager(escrow, depositId) {
|
|
47104
|
+
const id = parseRawDepositId(depositId);
|
|
47105
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47106
|
+
escrowAddress: escrow,
|
|
47107
|
+
depositId
|
|
47108
|
+
});
|
|
47109
|
+
if (getRateManagerReadFunction(escrowContext.abi, "getDepositRateManager")) {
|
|
47110
|
+
const result = await this.config.getPublicClient().readContract({
|
|
47111
|
+
address: escrowContext.address,
|
|
47112
|
+
abi: escrowContext.abi,
|
|
47113
|
+
functionName: "getDepositRateManager",
|
|
47114
|
+
args: [id]
|
|
47063
47115
|
});
|
|
47064
|
-
|
|
47065
|
-
|
|
47066
|
-
|
|
47067
|
-
|
|
47068
|
-
|
|
47069
|
-
buildDepositScopeKey({
|
|
47070
|
-
escrow,
|
|
47071
|
-
depositIdOnContract
|
|
47072
|
-
})
|
|
47073
|
-
);
|
|
47074
|
-
}).map((e) => ({
|
|
47075
|
-
...e,
|
|
47076
|
-
rateManagerId: normalizedId,
|
|
47077
|
-
escrow: normalizeAddress3(e.escrow) || void 0,
|
|
47078
|
-
currency: e.currency ?? e.currencyCode ?? "",
|
|
47079
|
-
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
47080
|
-
adapter: e.adapter ?? "",
|
|
47081
|
-
spreadBps: e.spreadBps ?? 0
|
|
47082
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47083
|
-
} catch (error) {
|
|
47084
|
-
if (isSchemaCompatibilityError(error)) ; else {
|
|
47085
|
-
throw error;
|
|
47116
|
+
if (result && result.length >= 2) {
|
|
47117
|
+
return {
|
|
47118
|
+
registry: result[0],
|
|
47119
|
+
rateManagerId: result[1]
|
|
47120
|
+
};
|
|
47086
47121
|
}
|
|
47087
|
-
|
|
47088
|
-
|
|
47089
|
-
|
|
47090
|
-
|
|
47091
|
-
|
|
47092
|
-
|
|
47093
|
-
|
|
47094
|
-
|
|
47095
|
-
|
|
47122
|
+
}
|
|
47123
|
+
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
47124
|
+
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
47125
|
+
if (!controllerAddress || !controllerAbi) {
|
|
47126
|
+
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
47127
|
+
}
|
|
47128
|
+
const legacyResult = await this.config.getPublicClient().readContract({
|
|
47129
|
+
address: controllerAddress,
|
|
47130
|
+
abi: controllerAbi,
|
|
47131
|
+
functionName: "getDepositRateManager",
|
|
47132
|
+
args: [escrow, id]
|
|
47133
|
+
});
|
|
47134
|
+
return {
|
|
47135
|
+
registry: legacyResult[0],
|
|
47136
|
+
rateManagerId: legacyResult[1]
|
|
47137
|
+
};
|
|
47138
|
+
}
|
|
47139
|
+
async getManagerFee(escrow, depositId) {
|
|
47140
|
+
const id = parseRawDepositId(depositId);
|
|
47141
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47142
|
+
escrowAddress: escrow,
|
|
47143
|
+
depositId
|
|
47144
|
+
});
|
|
47145
|
+
if (getRateManagerReadFunction(escrowContext.abi, "getManagerFee")) {
|
|
47146
|
+
const result2 = await this.config.getPublicClient().readContract({
|
|
47147
|
+
address: escrowContext.address,
|
|
47148
|
+
abi: escrowContext.abi,
|
|
47149
|
+
functionName: "getManagerFee",
|
|
47150
|
+
args: [id]
|
|
47096
47151
|
});
|
|
47097
|
-
return (
|
|
47098
|
-
|
|
47099
|
-
|
|
47100
|
-
|
|
47101
|
-
|
|
47102
|
-
|
|
47103
|
-
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47152
|
+
return parseManagerFeeFromRead(result2);
|
|
47153
|
+
}
|
|
47154
|
+
const controllerAddress = this.config.getRateManagerControllerAddress();
|
|
47155
|
+
const controllerAbi = this.config.getRateManagerControllerAbi();
|
|
47156
|
+
if (!controllerAddress || !controllerAbi) {
|
|
47157
|
+
throw this.buildRateManagerUnavailableError("Rate manager controller not available");
|
|
47104
47158
|
}
|
|
47159
|
+
const result = await this.config.getPublicClient().readContract({
|
|
47160
|
+
address: controllerAddress,
|
|
47161
|
+
abi: controllerAbi,
|
|
47162
|
+
functionName: "getManagerFee",
|
|
47163
|
+
args: [escrow, id]
|
|
47164
|
+
});
|
|
47165
|
+
return parseManagerFeeFromRead(result);
|
|
47166
|
+
}
|
|
47167
|
+
async getEffectiveRate(params) {
|
|
47168
|
+
const escrowContext = this.config.host.resolveEscrowContext({
|
|
47169
|
+
escrowAddress: params.escrow,
|
|
47170
|
+
depositId: params.depositId
|
|
47171
|
+
});
|
|
47172
|
+
const id = parseRawDepositId(params.depositId);
|
|
47173
|
+
return await this.config.getPublicClient().readContract({
|
|
47174
|
+
address: escrowContext.address,
|
|
47175
|
+
abi: escrowContext.abi,
|
|
47176
|
+
functionName: "getEffectiveRate",
|
|
47177
|
+
args: [id, params.paymentMethod, params.fiatCurrency]
|
|
47178
|
+
});
|
|
47105
47179
|
}
|
|
47106
47180
|
};
|
|
47181
|
+
var getRateManagerReadFunction = (abi, functionName) => Array.isArray(abi) && abi.some(
|
|
47182
|
+
(item) => item.type === "function" && item.name === functionName
|
|
47183
|
+
);
|
|
47107
47184
|
|
|
47108
|
-
// src/indexer/
|
|
47109
|
-
|
|
47110
|
-
|
|
47111
|
-
|
|
47112
|
-
|
|
47113
|
-
|
|
47185
|
+
// src/indexer/rateManagerService.ts
|
|
47186
|
+
init_bigint();
|
|
47187
|
+
var DEFAULT_LIMIT2 = 50;
|
|
47188
|
+
var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
|
|
47189
|
+
var EVM_ADDRESS_REGEX = /^0x[a-f0-9]{40}$/;
|
|
47190
|
+
function normalizeRateManagerId(value) {
|
|
47191
|
+
if (!value) return "";
|
|
47192
|
+
return value.toLowerCase();
|
|
47114
47193
|
}
|
|
47115
|
-
|
|
47116
|
-
|
|
47117
|
-
|
|
47118
|
-
|
|
47119
|
-
// src/adapters/api.ts
|
|
47120
|
-
init_errors();
|
|
47121
|
-
|
|
47122
|
-
// src/utils/logger.ts
|
|
47123
|
-
var currentLevel = "info";
|
|
47124
|
-
function setLogLevel(level) {
|
|
47125
|
-
currentLevel = level;
|
|
47194
|
+
function normalizeAddress3(value) {
|
|
47195
|
+
if (!value) return "";
|
|
47196
|
+
return value.toLowerCase();
|
|
47126
47197
|
}
|
|
47127
|
-
function
|
|
47128
|
-
|
|
47129
|
-
case "debug":
|
|
47130
|
-
return true;
|
|
47131
|
-
case "info":
|
|
47132
|
-
return level !== "debug";
|
|
47133
|
-
case "error":
|
|
47134
|
-
return level === "error";
|
|
47135
|
-
default:
|
|
47136
|
-
return true;
|
|
47137
|
-
}
|
|
47198
|
+
function escapeLikePatternLiteral(value) {
|
|
47199
|
+
return value.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
47138
47200
|
}
|
|
47139
|
-
|
|
47140
|
-
|
|
47141
|
-
|
|
47142
|
-
|
|
47143
|
-
|
|
47144
|
-
|
|
47145
|
-
|
|
47146
|
-
|
|
47147
|
-
|
|
47148
|
-
}
|
|
47149
|
-
},
|
|
47150
|
-
warn: (...args) => {
|
|
47151
|
-
if (shouldLog("info")) {
|
|
47152
|
-
console.warn("[WARN]", ...args);
|
|
47153
|
-
}
|
|
47154
|
-
},
|
|
47155
|
-
error: (...args) => {
|
|
47156
|
-
console.error("[ERROR]", ...args);
|
|
47157
|
-
}
|
|
47158
|
-
};
|
|
47159
|
-
|
|
47160
|
-
// src/referral.ts
|
|
47161
|
-
var normalizeReferralCode = (code) => code.trim().toUpperCase();
|
|
47162
|
-
var isValidReferralCode = (code) => /^[A-Z0-9]{6}$/.test(normalizeReferralCode(code));
|
|
47163
|
-
|
|
47164
|
-
// src/adapters/api.ts
|
|
47165
|
-
function createHeaders(apiKey, authorizationToken) {
|
|
47166
|
-
const headers2 = { "Content-Type": "application/json" };
|
|
47167
|
-
if (apiKey) headers2["x-api-key"] = apiKey;
|
|
47168
|
-
if (authorizationToken) {
|
|
47169
|
-
headers2.Authorization = authorizationToken.startsWith("Bearer ") ? authorizationToken : `Bearer ${authorizationToken}`;
|
|
47201
|
+
function parseScopedRateManagerFilterId(value) {
|
|
47202
|
+
const trimmed = value.trim().toLowerCase();
|
|
47203
|
+
if (!trimmed) return null;
|
|
47204
|
+
const separatorIndex = trimmed.indexOf(":");
|
|
47205
|
+
if (separatorIndex <= 0) return null;
|
|
47206
|
+
const rateManagerAddress = normalizeAddress3(trimmed.slice(0, separatorIndex));
|
|
47207
|
+
const rateManagerId = normalizeRateManagerId(trimmed.slice(separatorIndex + 1));
|
|
47208
|
+
if (!EVM_ADDRESS_REGEX.test(rateManagerAddress) || !rateManagerId) {
|
|
47209
|
+
return null;
|
|
47170
47210
|
}
|
|
47171
|
-
return
|
|
47211
|
+
return { rateManagerAddress, rateManagerId };
|
|
47172
47212
|
}
|
|
47173
|
-
function
|
|
47174
|
-
const
|
|
47175
|
-
|
|
47176
|
-
|
|
47177
|
-
base2 = base2.replace(/\/v2$/i, "");
|
|
47178
|
-
return base2;
|
|
47213
|
+
function getManagerScopeKey(rateManagerId, rateManagerAddress) {
|
|
47214
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47215
|
+
const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
|
|
47216
|
+
return normalizedRateManagerAddress ? `${normalizedRateManagerAddress}:${normalizedId}` : normalizedId;
|
|
47179
47217
|
}
|
|
47180
|
-
|
|
47181
|
-
|
|
47182
|
-
|
|
47183
|
-
|
|
47184
|
-
|
|
47185
|
-
|
|
47186
|
-
|
|
47187
|
-
|
|
47188
|
-
|
|
47189
|
-
|
|
47190
|
-
|
|
47191
|
-
return withRetry(
|
|
47192
|
-
async () => {
|
|
47193
|
-
let res;
|
|
47194
|
-
try {
|
|
47195
|
-
const options = {
|
|
47196
|
-
method,
|
|
47197
|
-
headers: createHeaders(apiKey, authorizationToken)
|
|
47198
|
-
};
|
|
47199
|
-
if (body && method !== "GET") {
|
|
47200
|
-
options.body = JSON.stringify(body);
|
|
47201
|
-
}
|
|
47202
|
-
res = await fetch(url, options);
|
|
47203
|
-
} catch (error) {
|
|
47204
|
-
throw new exports.NetworkError("Failed to connect to API server", { endpoint, error });
|
|
47205
|
-
}
|
|
47206
|
-
if (!res.ok) {
|
|
47207
|
-
const errorText = await res.text();
|
|
47208
|
-
throw parseAPIError(res, errorText);
|
|
47209
|
-
}
|
|
47210
|
-
return res.json();
|
|
47211
|
-
},
|
|
47212
|
-
retryCount,
|
|
47213
|
-
retryDelayMs,
|
|
47214
|
-
timeoutMs
|
|
47218
|
+
function extractRateManagerAddressFromScopedId(id) {
|
|
47219
|
+
if (!id) return null;
|
|
47220
|
+
const parts = id.split("_");
|
|
47221
|
+
if (parts.length < 3) return null;
|
|
47222
|
+
const rateManagerAddress = parts[1] ?? "";
|
|
47223
|
+
return rateManagerAddress.startsWith("0x") ? rateManagerAddress.toLowerCase() : null;
|
|
47224
|
+
}
|
|
47225
|
+
function buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress) {
|
|
47226
|
+
const normalizedId = escapeLikePatternLiteral(normalizeRateManagerId(rateManagerId));
|
|
47227
|
+
const normalizedRateManagerAddress = escapeLikePatternLiteral(
|
|
47228
|
+
normalizeAddress3(rateManagerAddress)
|
|
47215
47229
|
);
|
|
47230
|
+
return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
|
|
47216
47231
|
}
|
|
47217
|
-
function
|
|
47218
|
-
|
|
47219
|
-
return payload.responseObject;
|
|
47220
|
-
}
|
|
47221
|
-
return payload;
|
|
47232
|
+
function buildRateManagerScopedIdPattern(rateManagerId, rateManagerAddress) {
|
|
47233
|
+
return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}\\_%`;
|
|
47222
47234
|
}
|
|
47223
|
-
function
|
|
47224
|
-
|
|
47225
|
-
|
|
47235
|
+
function normalizeCompositeDepositId(depositId, escrowAddress) {
|
|
47236
|
+
const normalizedDepositId = depositId.trim().toLowerCase();
|
|
47237
|
+
if (!normalizedDepositId) return "";
|
|
47238
|
+
if (normalizedDepositId.includes("_")) return normalizedDepositId;
|
|
47239
|
+
const normalizedEscrow = normalizeAddress3(escrowAddress);
|
|
47240
|
+
if (normalizedEscrow) {
|
|
47241
|
+
return `${normalizedEscrow}_${normalizedDepositId}`;
|
|
47226
47242
|
}
|
|
47227
|
-
return
|
|
47243
|
+
return normalizedDepositId;
|
|
47228
47244
|
}
|
|
47229
|
-
function
|
|
47230
|
-
if (!
|
|
47231
|
-
|
|
47232
|
-
|
|
47233
|
-
return
|
|
47245
|
+
function extractDepositIdOnContract(compositeDepositId) {
|
|
47246
|
+
if (!compositeDepositId) return null;
|
|
47247
|
+
const parts = compositeDepositId.split("_");
|
|
47248
|
+
const rawDepositId = parts[parts.length - 1];
|
|
47249
|
+
return rawDepositId && /^\d+$/.test(rawDepositId) ? rawDepositId : null;
|
|
47234
47250
|
}
|
|
47235
|
-
function
|
|
47236
|
-
|
|
47237
|
-
|
|
47238
|
-
|
|
47239
|
-
}
|
|
47240
|
-
if (normalized.includes("staging") || normalized.includes("/staging/") || normalized.includes("localhost") || normalized.includes("127.0.0.1")) {
|
|
47241
|
-
return "STAGING";
|
|
47242
|
-
}
|
|
47243
|
-
return "PRODUCTION";
|
|
47251
|
+
function extractEscrowAddressFromCompositeDepositId(compositeDepositId) {
|
|
47252
|
+
if (!compositeDepositId) return null;
|
|
47253
|
+
const [escrowAddress] = compositeDepositId.split("_");
|
|
47254
|
+
return escrowAddress?.startsWith("0x") ? escrowAddress.toLowerCase() : null;
|
|
47244
47255
|
}
|
|
47245
|
-
|
|
47246
|
-
|
|
47247
|
-
|
|
47248
|
-
|
|
47249
|
-
|
|
47250
|
-
|
|
47251
|
-
|
|
47252
|
-
|
|
47253
|
-
|
|
47254
|
-
|
|
47255
|
-
|
|
47256
|
-
|
|
47257
|
-
|
|
47258
|
-
|
|
47256
|
+
function parseRateManagerFilterIds(rateManagerIds) {
|
|
47257
|
+
const bare = /* @__PURE__ */ new Set();
|
|
47258
|
+
const scoped = /* @__PURE__ */ new Map();
|
|
47259
|
+
for (const value of rateManagerIds) {
|
|
47260
|
+
const scopedRateManager = parseScopedRateManagerFilterId(value);
|
|
47261
|
+
if (scopedRateManager) {
|
|
47262
|
+
scoped.set(
|
|
47263
|
+
getManagerScopeKey(scopedRateManager.rateManagerId, scopedRateManager.rateManagerAddress),
|
|
47264
|
+
scopedRateManager
|
|
47265
|
+
);
|
|
47266
|
+
continue;
|
|
47267
|
+
}
|
|
47268
|
+
if (value.includes(":")) {
|
|
47269
|
+
continue;
|
|
47270
|
+
}
|
|
47271
|
+
const normalizedRateManagerId = normalizeRateManagerId(value);
|
|
47272
|
+
if (normalizedRateManagerId) {
|
|
47273
|
+
bare.add(normalizedRateManagerId);
|
|
47274
|
+
}
|
|
47259
47275
|
}
|
|
47276
|
+
return { bare, scoped };
|
|
47260
47277
|
}
|
|
47261
|
-
function
|
|
47262
|
-
|
|
47263
|
-
const numeric = Number(value);
|
|
47264
|
-
if (!Number.isFinite(numeric) || numeric <= 0) return void 0;
|
|
47265
|
-
return new Date(numeric * 1e3);
|
|
47278
|
+
function buildDepositScopeKey(scope) {
|
|
47279
|
+
return `${scope.escrow}:${scope.depositIdOnContract}`;
|
|
47266
47280
|
}
|
|
47267
|
-
function
|
|
47268
|
-
if (value
|
|
47281
|
+
function toSafeBigInt(value) {
|
|
47282
|
+
if (!value) return 0n;
|
|
47269
47283
|
try {
|
|
47270
|
-
return
|
|
47284
|
+
return parseBigIntLike(value);
|
|
47271
47285
|
} catch {
|
|
47272
47286
|
return 0n;
|
|
47273
47287
|
}
|
|
47274
47288
|
}
|
|
47275
|
-
function
|
|
47276
|
-
if (
|
|
47277
|
-
if (
|
|
47278
|
-
return
|
|
47289
|
+
function compareBigInt(a, b, direction) {
|
|
47290
|
+
if (a === b) return 0;
|
|
47291
|
+
if (direction === "asc") return a < b ? -1 : 1;
|
|
47292
|
+
return a > b ? -1 : 1;
|
|
47279
47293
|
}
|
|
47280
|
-
function
|
|
47281
|
-
|
|
47282
|
-
|
|
47283
|
-
|
|
47284
|
-
|
|
47285
|
-
|
|
47286
|
-
|
|
47287
|
-
|
|
47288
|
-
|
|
47289
|
-
|
|
47294
|
+
function parseEventCursorId(id) {
|
|
47295
|
+
if (!id) return null;
|
|
47296
|
+
const [chainIdRaw, blockNumberRaw, logIndexRaw] = id.split("_");
|
|
47297
|
+
if (!chainIdRaw || !blockNumberRaw || !logIndexRaw) return null;
|
|
47298
|
+
if (!/^\d+$/.test(chainIdRaw) || !/^\d+$/.test(blockNumberRaw) || !/^\d+$/.test(logIndexRaw)) {
|
|
47299
|
+
return null;
|
|
47300
|
+
}
|
|
47301
|
+
try {
|
|
47302
|
+
return {
|
|
47303
|
+
chainId: BigInt(chainIdRaw),
|
|
47304
|
+
blockNumber: BigInt(blockNumberRaw),
|
|
47305
|
+
logIndex: BigInt(logIndexRaw)
|
|
47306
|
+
};
|
|
47307
|
+
} catch {
|
|
47308
|
+
return null;
|
|
47309
|
+
}
|
|
47310
|
+
}
|
|
47311
|
+
function compareEventCursorIdsByRecency(leftId, rightId) {
|
|
47312
|
+
const left = parseEventCursorId(leftId);
|
|
47313
|
+
const right = parseEventCursorId(rightId);
|
|
47314
|
+
if (left && right) {
|
|
47315
|
+
if (left.chainId !== right.chainId) {
|
|
47316
|
+
return left.chainId > right.chainId ? -1 : 1;
|
|
47290
47317
|
}
|
|
47291
|
-
|
|
47292
|
-
|
|
47293
|
-
|
|
47294
|
-
|
|
47295
|
-
|
|
47296
|
-
|
|
47297
|
-
|
|
47298
|
-
});
|
|
47299
|
-
currenciesByMethod.set(methodHash, bucket);
|
|
47318
|
+
if (left.blockNumber !== right.blockNumber) {
|
|
47319
|
+
return left.blockNumber > right.blockNumber ? -1 : 1;
|
|
47320
|
+
}
|
|
47321
|
+
if (left.logIndex !== right.logIndex) {
|
|
47322
|
+
return left.logIndex > right.logIndex ? -1 : 1;
|
|
47323
|
+
}
|
|
47324
|
+
return 0;
|
|
47300
47325
|
}
|
|
47301
|
-
return
|
|
47326
|
+
return (rightId ?? "").localeCompare(leftId ?? "");
|
|
47302
47327
|
}
|
|
47303
|
-
function
|
|
47304
|
-
|
|
47305
|
-
|
|
47306
|
-
|
|
47307
|
-
verifier: "",
|
|
47308
|
-
methodHash: paymentMethod.paymentMethodHash,
|
|
47309
|
-
intentGatingService: paymentMethod.intentGatingService,
|
|
47310
|
-
payeeDetailsHash: paymentMethod.payeeDetailsHash,
|
|
47311
|
-
data: "0x",
|
|
47312
|
-
currencies: currenciesByMethod.get(paymentMethod.paymentMethodHash) ?? []
|
|
47313
|
-
}));
|
|
47314
|
-
const remainingDeposits = toBigIntSafe(deposit.remainingDeposits);
|
|
47315
|
-
const outstandingIntentAmount = toBigIntSafe(deposit.outstandingIntentAmount);
|
|
47316
|
-
const totalAmountTaken = toBigIntSafe(deposit.totalAmountTaken);
|
|
47317
|
-
const totalWithdrawn = toBigIntSafe(deposit.totalWithdrawn);
|
|
47318
|
-
const amount = remainingDeposits + outstandingIntentAmount + totalAmountTaken + totalWithdrawn;
|
|
47328
|
+
function isAggregateOrderField(field) {
|
|
47329
|
+
return field === "currentDelegatedBalance" || field === "totalFilledVolume";
|
|
47330
|
+
}
|
|
47331
|
+
function normalizeRateManagerEntity(manager) {
|
|
47319
47332
|
return {
|
|
47320
|
-
|
|
47321
|
-
|
|
47322
|
-
token: deposit.token,
|
|
47323
|
-
amount: amount.toString(),
|
|
47324
|
-
remainingDeposits: deposit.remainingDeposits,
|
|
47325
|
-
intentAmountMin: deposit.intentAmountMin,
|
|
47326
|
-
intentAmountMax: deposit.intentAmountMax,
|
|
47327
|
-
acceptingIntents: deposit.acceptingIntents,
|
|
47328
|
-
outstandingIntentAmount: deposit.outstandingIntentAmount,
|
|
47329
|
-
availableLiquidity: deposit.remainingDeposits,
|
|
47330
|
-
status: deposit.status,
|
|
47331
|
-
totalIntents: deposit.totalIntents,
|
|
47332
|
-
signaledIntents: deposit.signaledIntents,
|
|
47333
|
-
fulfilledIntents: deposit.fulfilledIntents,
|
|
47334
|
-
prunedIntents: deposit.prunedIntents,
|
|
47335
|
-
totalAmountTaken: deposit.totalAmountTaken,
|
|
47336
|
-
totalWithdrawn: deposit.totalWithdrawn,
|
|
47337
|
-
successRateBps: deposit.successRateBps,
|
|
47338
|
-
rateManagerId: deposit.rateManagerId ?? null,
|
|
47339
|
-
vaultName: null,
|
|
47340
|
-
rateManagerRegistry: null,
|
|
47341
|
-
createdAt: toDateFromUnixSeconds(deposit.timestamp),
|
|
47342
|
-
updatedAt: toDateFromUnixSeconds(deposit.updatedAt),
|
|
47343
|
-
verifiers
|
|
47333
|
+
...manager,
|
|
47334
|
+
rateManagerAddress: normalizeAddress3(manager.rateManagerAddress)
|
|
47344
47335
|
};
|
|
47345
47336
|
}
|
|
47346
|
-
|
|
47347
|
-
|
|
47348
|
-
|
|
47349
|
-
|
|
47350
|
-
|
|
47351
|
-
|
|
47352
|
-
|
|
47337
|
+
function toDelegationEntityFromDeposit(deposit) {
|
|
47338
|
+
const rateManagerId = normalizeRateManagerId(deposit.rateManagerId);
|
|
47339
|
+
if (!rateManagerId) return null;
|
|
47340
|
+
const delegatedAt = deposit.delegatedAt ?? null;
|
|
47341
|
+
return {
|
|
47342
|
+
id: deposit.id,
|
|
47343
|
+
chainId: deposit.chainId,
|
|
47344
|
+
rateManagerId,
|
|
47345
|
+
rateManagerAddress: normalizeAddress3(deposit.rateManagerAddress) || null,
|
|
47346
|
+
depositId: deposit.id,
|
|
47347
|
+
delegatedAt,
|
|
47348
|
+
createdAt: delegatedAt ?? deposit.updatedAt,
|
|
47349
|
+
updatedAt: deposit.updatedAt
|
|
47350
|
+
};
|
|
47353
47351
|
}
|
|
47354
|
-
|
|
47355
|
-
|
|
47356
|
-
|
|
47357
|
-
|
|
47352
|
+
var IndexerRateManagerService = class {
|
|
47353
|
+
constructor(client) {
|
|
47354
|
+
this.client = client;
|
|
47355
|
+
}
|
|
47356
|
+
buildRateManagerScopeWhere(rateManagerIds) {
|
|
47357
|
+
if (!rateManagerIds?.length) return void 0;
|
|
47358
|
+
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
47359
|
+
const scopeConditions = [];
|
|
47360
|
+
if (bare.size > 0) {
|
|
47361
|
+
scopeConditions.push({
|
|
47362
|
+
rateManagerId: { _in: [...bare] }
|
|
47363
|
+
});
|
|
47364
|
+
}
|
|
47365
|
+
for (const scopedRateManager of scoped.values()) {
|
|
47366
|
+
scopeConditions.push({
|
|
47367
|
+
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
47368
|
+
rateManagerAddress: { _eq: scopedRateManager.rateManagerAddress }
|
|
47369
|
+
});
|
|
47370
|
+
}
|
|
47371
|
+
if (scopeConditions.length === 1) {
|
|
47372
|
+
return scopeConditions[0];
|
|
47373
|
+
}
|
|
47374
|
+
if (scopeConditions.length > 1) {
|
|
47375
|
+
return { _or: scopeConditions };
|
|
47376
|
+
}
|
|
47377
|
+
return void 0;
|
|
47378
|
+
}
|
|
47379
|
+
buildWhere(filter) {
|
|
47380
|
+
if (!filter) return void 0;
|
|
47381
|
+
const where = {};
|
|
47382
|
+
if (filter.manager) {
|
|
47383
|
+
where.manager = { _ilike: filter.manager };
|
|
47384
|
+
}
|
|
47385
|
+
if (filter.name) {
|
|
47386
|
+
where.name = { _ilike: `%${filter.name}%` };
|
|
47387
|
+
}
|
|
47388
|
+
if (filter.maxFee) {
|
|
47389
|
+
where.maxFee = { _lte: filter.maxFee };
|
|
47390
|
+
}
|
|
47391
|
+
const scopeWhere = this.buildRateManagerScopeWhere(filter.rateManagerIds);
|
|
47392
|
+
if (scopeWhere) {
|
|
47393
|
+
Object.assign(where, scopeWhere);
|
|
47394
|
+
}
|
|
47395
|
+
return Object.keys(where).length ? where : void 0;
|
|
47396
|
+
}
|
|
47397
|
+
buildAggregateWhere(filter) {
|
|
47398
|
+
return this.buildRateManagerScopeWhere(filter?.rateManagerIds) ?? {};
|
|
47399
|
+
}
|
|
47400
|
+
buildLegacyAggregateWhere(filter) {
|
|
47401
|
+
const rateManagerIds = filter?.rateManagerIds;
|
|
47402
|
+
if (!rateManagerIds?.length) return {};
|
|
47403
|
+
const { bare, scoped } = parseRateManagerFilterIds(rateManagerIds);
|
|
47404
|
+
const scopeConditions = [];
|
|
47405
|
+
if (bare.size > 0) {
|
|
47406
|
+
scopeConditions.push({
|
|
47407
|
+
rateManagerId: { _in: [...bare] }
|
|
47408
|
+
});
|
|
47409
|
+
}
|
|
47410
|
+
for (const scopedRateManager of scoped.values()) {
|
|
47411
|
+
scopeConditions.push({
|
|
47412
|
+
rateManagerId: { _eq: scopedRateManager.rateManagerId },
|
|
47413
|
+
id: {
|
|
47414
|
+
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
47415
|
+
scopedRateManager.rateManagerId,
|
|
47416
|
+
scopedRateManager.rateManagerAddress
|
|
47417
|
+
)
|
|
47418
|
+
}
|
|
47419
|
+
});
|
|
47420
|
+
}
|
|
47421
|
+
if (scopeConditions.length === 1) {
|
|
47422
|
+
return scopeConditions[0] ?? {};
|
|
47423
|
+
}
|
|
47424
|
+
if (scopeConditions.length > 1) {
|
|
47425
|
+
return { _or: scopeConditions };
|
|
47426
|
+
}
|
|
47427
|
+
return {};
|
|
47428
|
+
}
|
|
47429
|
+
buildOrderBy(pagination) {
|
|
47430
|
+
const rawField = pagination?.orderBy ?? "createdAt";
|
|
47431
|
+
const field = isAggregateOrderField(rawField) ? "createdAt" : rawField;
|
|
47432
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
47433
|
+
return [{ [field]: direction }];
|
|
47434
|
+
}
|
|
47435
|
+
toRateManagerListItems(result) {
|
|
47436
|
+
const managers = (result.RateManager ?? []).map(normalizeRateManagerEntity);
|
|
47437
|
+
const aggregatesByScope = /* @__PURE__ */ new Map();
|
|
47438
|
+
for (const aggregate of result.ManagerAggregateStats ?? []) {
|
|
47439
|
+
const aggregateRateManagerAddress = normalizeAddress3(aggregate.rateManagerAddress) || extractRateManagerAddressFromScopedId(aggregate.id);
|
|
47440
|
+
const scopeKey = getManagerScopeKey(aggregate.rateManagerId, aggregateRateManagerAddress);
|
|
47441
|
+
aggregatesByScope.set(scopeKey, aggregate);
|
|
47442
|
+
}
|
|
47443
|
+
return managers.map((manager) => ({
|
|
47444
|
+
manager,
|
|
47445
|
+
aggregate: aggregatesByScope.get(
|
|
47446
|
+
getManagerScopeKey(manager.rateManagerId, normalizeAddress3(manager.rateManagerAddress))
|
|
47447
|
+
) ?? aggregatesByScope.get(getManagerScopeKey(manager.rateManagerId)) ?? null
|
|
47448
|
+
}));
|
|
47449
|
+
}
|
|
47450
|
+
applyHookFilter(rows, hasHook) {
|
|
47451
|
+
if (hasHook === void 0) return rows;
|
|
47452
|
+
return hasHook ? [] : rows;
|
|
47453
|
+
}
|
|
47454
|
+
async queryRateManagerList(variables, legacyVariables) {
|
|
47455
|
+
try {
|
|
47456
|
+
return await this.client.query({
|
|
47457
|
+
query: RATE_MANAGER_LIST_QUERY,
|
|
47458
|
+
variables
|
|
47459
|
+
});
|
|
47460
|
+
} catch (error) {
|
|
47461
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47462
|
+
throw error;
|
|
47463
|
+
}
|
|
47464
|
+
return this.client.query({
|
|
47465
|
+
query: LEGACY_RATE_MANAGER_LIST_QUERY,
|
|
47466
|
+
variables: legacyVariables
|
|
47467
|
+
});
|
|
47358
47468
|
}
|
|
47359
47469
|
}
|
|
47360
|
-
|
|
47361
|
-
|
|
47470
|
+
buildDelegationOrderBy(pagination) {
|
|
47471
|
+
const rawField = pagination?.orderBy ?? "updatedAt";
|
|
47472
|
+
const field = rawField === "createdAt" ? "delegatedAt" : rawField;
|
|
47473
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
47474
|
+
return [{ [field]: direction }];
|
|
47362
47475
|
}
|
|
47363
|
-
|
|
47364
|
-
|
|
47476
|
+
buildLegacyDelegationOrderBy(pagination) {
|
|
47477
|
+
const rawField = pagination?.orderBy ?? "updatedAt";
|
|
47478
|
+
const field = rawField === "delegatedAt" ? "createdAt" : rawField;
|
|
47479
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
47480
|
+
return [{ [field]: direction }];
|
|
47365
47481
|
}
|
|
47366
|
-
|
|
47367
|
-
|
|
47368
|
-
|
|
47369
|
-
|
|
47482
|
+
async fetchCurrentRateManagerDepositScopes(rateManagerId, rateManagerAddress) {
|
|
47483
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
47484
|
+
let offset = 0;
|
|
47485
|
+
for (; ; ) {
|
|
47486
|
+
const delegations = await this.fetchRateManagerDelegations(rateManagerId, {
|
|
47487
|
+
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
47488
|
+
offset,
|
|
47489
|
+
orderBy: "delegatedAt",
|
|
47490
|
+
orderDirection: "desc",
|
|
47491
|
+
rateManagerAddress: rateManagerAddress || void 0
|
|
47492
|
+
});
|
|
47493
|
+
for (const delegation of delegations) {
|
|
47494
|
+
const escrow = extractEscrowAddressFromCompositeDepositId(delegation.depositId);
|
|
47495
|
+
const depositIdOnContract = extractDepositIdOnContract(delegation.depositId);
|
|
47496
|
+
if (!escrow || !depositIdOnContract) continue;
|
|
47497
|
+
const scope = { escrow, depositIdOnContract };
|
|
47498
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
47499
|
+
}
|
|
47500
|
+
if (delegations.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
47501
|
+
break;
|
|
47502
|
+
}
|
|
47503
|
+
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
47504
|
+
}
|
|
47505
|
+
return [...scopes.values()];
|
|
47506
|
+
}
|
|
47507
|
+
async fetchHistoricalRateManagerDepositScopes(rateManagerId, rateManagerAddress) {
|
|
47508
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47509
|
+
const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
|
|
47510
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
47511
|
+
const currentScopes = await this.fetchCurrentRateManagerDepositScopes(
|
|
47512
|
+
normalizedId,
|
|
47513
|
+
normalizedRateManagerAddress || void 0
|
|
47370
47514
|
);
|
|
47515
|
+
for (const scope of currentScopes) {
|
|
47516
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
47517
|
+
}
|
|
47518
|
+
try {
|
|
47519
|
+
let offset = 0;
|
|
47520
|
+
for (; ; ) {
|
|
47521
|
+
const result = await this.client.query({
|
|
47522
|
+
query: RATE_MANAGER_ASSIGNMENT_EVENTS_QUERY,
|
|
47523
|
+
variables: {
|
|
47524
|
+
setWhere: {
|
|
47525
|
+
rateManagerId: { _eq: normalizedId },
|
|
47526
|
+
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
47527
|
+
},
|
|
47528
|
+
clearedWhere: {
|
|
47529
|
+
rateManagerId: { _eq: normalizedId },
|
|
47530
|
+
...normalizedRateManagerAddress ? { rateManager: { _eq: normalizedRateManagerAddress } } : {}
|
|
47531
|
+
},
|
|
47532
|
+
limit: RATE_MANAGER_HISTORY_PAGE_SIZE,
|
|
47533
|
+
offset
|
|
47534
|
+
}
|
|
47535
|
+
});
|
|
47536
|
+
const setEvents = result.EscrowV2_DepositRateManagerSet ?? [];
|
|
47537
|
+
const clearedEvents = result.EscrowV2_DepositRateManagerCleared ?? [];
|
|
47538
|
+
for (const event of [...setEvents, ...clearedEvents]) {
|
|
47539
|
+
const escrow = normalizeAddress3(event.escrow);
|
|
47540
|
+
const depositIdOnContract = event.depositIdOnContract?.toString() ?? "";
|
|
47541
|
+
if (!escrow || !depositIdOnContract) continue;
|
|
47542
|
+
const scope = { escrow, depositIdOnContract };
|
|
47543
|
+
scopes.set(buildDepositScopeKey(scope), scope);
|
|
47544
|
+
}
|
|
47545
|
+
if (setEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE && clearedEvents.length < RATE_MANAGER_HISTORY_PAGE_SIZE) {
|
|
47546
|
+
break;
|
|
47547
|
+
}
|
|
47548
|
+
offset += RATE_MANAGER_HISTORY_PAGE_SIZE;
|
|
47549
|
+
}
|
|
47550
|
+
} catch (error) {
|
|
47551
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47552
|
+
throw error;
|
|
47553
|
+
}
|
|
47554
|
+
}
|
|
47555
|
+
return [...scopes.values()];
|
|
47371
47556
|
}
|
|
47372
|
-
|
|
47373
|
-
|
|
47374
|
-
|
|
47375
|
-
|
|
47376
|
-
|
|
47377
|
-
|
|
47378
|
-
|
|
47379
|
-
|
|
47380
|
-
|
|
47381
|
-
|
|
47382
|
-
|
|
47383
|
-
|
|
47384
|
-
|
|
47385
|
-
|
|
47386
|
-
|
|
47387
|
-
|
|
47388
|
-
|
|
47389
|
-
|
|
47390
|
-
|
|
47391
|
-
|
|
47392
|
-
|
|
47393
|
-
|
|
47394
|
-
|
|
47395
|
-
|
|
47396
|
-
|
|
47397
|
-
|
|
47398
|
-
|
|
47399
|
-
|
|
47400
|
-
|
|
47401
|
-
|
|
47402
|
-
|
|
47403
|
-
|
|
47404
|
-
|
|
47405
|
-
|
|
47406
|
-
|
|
47407
|
-
|
|
47408
|
-
|
|
47409
|
-
|
|
47410
|
-
|
|
47411
|
-
|
|
47412
|
-
|
|
47413
|
-
|
|
47414
|
-
|
|
47415
|
-
|
|
47416
|
-
|
|
47417
|
-
|
|
47418
|
-
|
|
47419
|
-
|
|
47420
|
-
|
|
47421
|
-
|
|
47422
|
-
|
|
47423
|
-
|
|
47424
|
-
|
|
47425
|
-
|
|
47426
|
-
|
|
47427
|
-
|
|
47428
|
-
|
|
47429
|
-
|
|
47557
|
+
async fetchRateManagers(pagination, filter) {
|
|
47558
|
+
const orderBy = pagination?.orderBy ?? "createdAt";
|
|
47559
|
+
const direction = pagination?.orderDirection === "asc" ? "asc" : "desc";
|
|
47560
|
+
const limit = pagination?.limit ?? DEFAULT_LIMIT2;
|
|
47561
|
+
const offset = pagination?.offset ?? 0;
|
|
47562
|
+
const where = this.buildWhere(filter);
|
|
47563
|
+
const aggregateWhere = this.buildAggregateWhere(filter);
|
|
47564
|
+
const legacyAggregateWhere = this.buildLegacyAggregateWhere(filter);
|
|
47565
|
+
if (isAggregateOrderField(orderBy)) {
|
|
47566
|
+
const result2 = await this.queryRateManagerList(
|
|
47567
|
+
{
|
|
47568
|
+
where,
|
|
47569
|
+
aggregateWhere,
|
|
47570
|
+
order_by: [{ createdAt: "desc" }]
|
|
47571
|
+
},
|
|
47572
|
+
{
|
|
47573
|
+
where,
|
|
47574
|
+
aggregateWhere: legacyAggregateWhere,
|
|
47575
|
+
order_by: [{ createdAt: "desc" }]
|
|
47576
|
+
}
|
|
47577
|
+
);
|
|
47578
|
+
const scopedRows = this.applyHookFilter(this.toRateManagerListItems(result2), filter?.hasHook);
|
|
47579
|
+
const sorted = scopedRows.sort((a, b) => {
|
|
47580
|
+
const av = orderBy === "currentDelegatedBalance" ? toSafeBigInt(a.aggregate?.currentDelegatedBalance) : toSafeBigInt(a.aggregate?.totalFilledVolume);
|
|
47581
|
+
const bv = orderBy === "currentDelegatedBalance" ? toSafeBigInt(b.aggregate?.currentDelegatedBalance) : toSafeBigInt(b.aggregate?.totalFilledVolume);
|
|
47582
|
+
const aggregateCmp = compareBigInt(av, bv, direction);
|
|
47583
|
+
if (aggregateCmp !== 0) return aggregateCmp;
|
|
47584
|
+
const createdAtCmp = compareBigInt(
|
|
47585
|
+
toSafeBigInt(a.manager.createdAt),
|
|
47586
|
+
toSafeBigInt(b.manager.createdAt),
|
|
47587
|
+
"desc"
|
|
47588
|
+
);
|
|
47589
|
+
if (createdAtCmp !== 0) return createdAtCmp;
|
|
47590
|
+
return a.manager.rateManagerId.localeCompare(b.manager.rateManagerId);
|
|
47591
|
+
});
|
|
47592
|
+
return sorted.slice(offset, offset + limit);
|
|
47593
|
+
}
|
|
47594
|
+
const result = await this.queryRateManagerList(
|
|
47595
|
+
{
|
|
47596
|
+
where,
|
|
47597
|
+
aggregateWhere,
|
|
47598
|
+
order_by: this.buildOrderBy(pagination),
|
|
47599
|
+
limit,
|
|
47600
|
+
offset
|
|
47601
|
+
},
|
|
47602
|
+
{
|
|
47603
|
+
where,
|
|
47604
|
+
aggregateWhere: legacyAggregateWhere,
|
|
47605
|
+
order_by: this.buildOrderBy(pagination),
|
|
47606
|
+
limit,
|
|
47607
|
+
offset
|
|
47608
|
+
}
|
|
47609
|
+
);
|
|
47610
|
+
return this.applyHookFilter(this.toRateManagerListItems(result), filter?.hasHook);
|
|
47611
|
+
}
|
|
47612
|
+
async fetchRateManagerDetail(rateManagerId, options) {
|
|
47613
|
+
if (!rateManagerId) return null;
|
|
47614
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47615
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
47616
|
+
const baseVariables = {
|
|
47617
|
+
managerWhere: {
|
|
47618
|
+
rateManagerId: { _eq: normalizedId },
|
|
47619
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47620
|
+
},
|
|
47621
|
+
rateWhere: {
|
|
47622
|
+
rateManagerId: { _eq: normalizedId },
|
|
47623
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47624
|
+
},
|
|
47625
|
+
aggregateWhere: {
|
|
47626
|
+
rateManagerId: { _eq: normalizedId },
|
|
47627
|
+
...normalizedRateManagerAddress ? {
|
|
47628
|
+
id: {
|
|
47629
|
+
_ilike: buildRateManagerAddressScopedIdPattern(
|
|
47630
|
+
normalizedId,
|
|
47631
|
+
normalizedRateManagerAddress
|
|
47632
|
+
)
|
|
47633
|
+
}
|
|
47634
|
+
} : {}
|
|
47635
|
+
},
|
|
47636
|
+
statsWhere: {
|
|
47637
|
+
rateManagerId: { _eq: normalizedId },
|
|
47638
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47639
|
+
},
|
|
47640
|
+
delegationWhere: {
|
|
47641
|
+
rateManagerId: { _eq: normalizedId },
|
|
47642
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47643
|
+
},
|
|
47644
|
+
statsLimit: options?.statsLimit ?? 20
|
|
47645
|
+
};
|
|
47646
|
+
const legacyVariables = {
|
|
47647
|
+
...baseVariables,
|
|
47648
|
+
floorWhere: {
|
|
47649
|
+
rateManagerId: { _eq: normalizedId },
|
|
47650
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47651
|
+
}
|
|
47652
|
+
};
|
|
47653
|
+
let managerRaw;
|
|
47654
|
+
let scopedRates = [];
|
|
47655
|
+
let scopedRecentStats = [];
|
|
47656
|
+
let scopedDelegations = [];
|
|
47657
|
+
let aggregate = null;
|
|
47658
|
+
try {
|
|
47659
|
+
const result = await this.client.query({
|
|
47660
|
+
query: RATE_MANAGER_DETAIL_QUERY,
|
|
47661
|
+
variables: baseVariables
|
|
47662
|
+
});
|
|
47663
|
+
managerRaw = result.RateManager?.[0];
|
|
47664
|
+
if (!managerRaw) return null;
|
|
47665
|
+
const scopedRateManagerAddress = normalizeAddress3(managerRaw.rateManagerAddress);
|
|
47666
|
+
scopedRates = (result.RateManagerRate ?? []).filter(
|
|
47667
|
+
(rate) => normalizeAddress3(rate.rateManagerAddress) === scopedRateManagerAddress
|
|
47668
|
+
);
|
|
47669
|
+
scopedRecentStats = (result.ManagerStats ?? []).filter((stats) => {
|
|
47670
|
+
const statsRateManagerAddress = normalizeAddress3(stats.rateManagerAddress);
|
|
47671
|
+
return !statsRateManagerAddress || statsRateManagerAddress === scopedRateManagerAddress;
|
|
47672
|
+
});
|
|
47673
|
+
scopedDelegations = (result.Deposit ?? []).map((deposit) => toDelegationEntityFromDeposit(deposit)).filter((delegation) => Boolean(delegation)).filter(
|
|
47674
|
+
(delegation) => normalizeAddress3(delegation.rateManagerAddress) === scopedRateManagerAddress
|
|
47675
|
+
);
|
|
47676
|
+
aggregate = (result.ManagerAggregateStats ?? []).find(
|
|
47677
|
+
(stats) => (normalizeAddress3(stats.rateManagerAddress) || extractRateManagerAddressFromScopedId(stats.id)) === scopedRateManagerAddress
|
|
47678
|
+
) ?? result.ManagerAggregateStats?.[0] ?? null;
|
|
47679
|
+
} catch (error) {
|
|
47680
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47681
|
+
throw error;
|
|
47682
|
+
}
|
|
47683
|
+
const legacyResult = await this.client.query({
|
|
47684
|
+
query: LEGACY_RATE_MANAGER_DETAIL_QUERY,
|
|
47685
|
+
variables: legacyVariables
|
|
47686
|
+
});
|
|
47687
|
+
managerRaw = legacyResult.RateManager?.[0];
|
|
47688
|
+
if (!managerRaw) return null;
|
|
47689
|
+
const scopedRateManagerAddress = normalizeAddress3(managerRaw.rateManagerAddress);
|
|
47690
|
+
scopedRates = (legacyResult.RateManagerRate ?? []).filter(
|
|
47691
|
+
(rate) => normalizeAddress3(rate.rateManagerAddress) === scopedRateManagerAddress
|
|
47692
|
+
);
|
|
47693
|
+
scopedRecentStats = (legacyResult.ManagerStats ?? []).filter((stats) => {
|
|
47694
|
+
const statsRateManagerAddress = normalizeAddress3(stats.rateManagerAddress);
|
|
47695
|
+
return !statsRateManagerAddress || statsRateManagerAddress === scopedRateManagerAddress;
|
|
47696
|
+
});
|
|
47697
|
+
scopedDelegations = (legacyResult.RateManagerDelegation ?? []).filter(
|
|
47698
|
+
(delegation) => normalizeAddress3(delegation.rateManagerAddress) === scopedRateManagerAddress
|
|
47699
|
+
);
|
|
47700
|
+
aggregate = (legacyResult.ManagerAggregateStats ?? []).find(
|
|
47701
|
+
(stats) => (normalizeAddress3(stats.rateManagerAddress) || extractRateManagerAddressFromScopedId(stats.id)) === scopedRateManagerAddress
|
|
47702
|
+
) ?? legacyResult.ManagerAggregateStats?.[0] ?? null;
|
|
47703
|
+
}
|
|
47704
|
+
if (!managerRaw) return null;
|
|
47705
|
+
const manager = normalizeRateManagerEntity(managerRaw);
|
|
47430
47706
|
return {
|
|
47431
|
-
|
|
47432
|
-
|
|
47707
|
+
manager,
|
|
47708
|
+
rates: scopedRates,
|
|
47709
|
+
aggregate,
|
|
47710
|
+
recentStats: scopedRecentStats,
|
|
47711
|
+
delegations: scopedDelegations
|
|
47433
47712
|
};
|
|
47434
47713
|
}
|
|
47435
|
-
|
|
47436
|
-
|
|
47437
|
-
|
|
47438
|
-
|
|
47439
|
-
|
|
47440
|
-
|
|
47441
|
-
|
|
47442
|
-
|
|
47443
|
-
const indexerClient = new IndexerClient(indexerEndpoint, {
|
|
47444
|
-
apiKey,
|
|
47445
|
-
authorizationToken: authToken
|
|
47446
|
-
});
|
|
47447
|
-
const service = new IndexerDepositService(indexerClient);
|
|
47448
|
-
const deposits = await withOptionalTimeout(
|
|
47449
|
-
service.fetchDepositsWithRelations(
|
|
47450
|
-
{
|
|
47451
|
-
depositor: req.ownerAddress,
|
|
47452
|
-
escrowAddress,
|
|
47453
|
-
escrowAddresses: req.escrowAddresses?.length ? req.escrowAddresses : void 0,
|
|
47454
|
-
status: normalizeOwnerDepositsStatus(req.status)
|
|
47714
|
+
async fetchRateManagerDelegations(rateManagerId, pagination) {
|
|
47715
|
+
if (!rateManagerId) return [];
|
|
47716
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47717
|
+
const normalizedRateManagerAddress = normalizeAddress3(pagination?.rateManagerAddress);
|
|
47718
|
+
const variables = {
|
|
47719
|
+
where: {
|
|
47720
|
+
rateManagerId: { _eq: normalizedId },
|
|
47721
|
+
...normalizedRateManagerAddress ? { rateManagerAddress: { _eq: normalizedRateManagerAddress } } : {}
|
|
47455
47722
|
},
|
|
47456
|
-
|
|
47457
|
-
|
|
47458
|
-
|
|
47459
|
-
|
|
47460
|
-
|
|
47461
|
-
|
|
47462
|
-
|
|
47463
|
-
|
|
47464
|
-
|
|
47465
|
-
|
|
47466
|
-
|
|
47467
|
-
|
|
47468
|
-
|
|
47469
|
-
|
|
47470
|
-
|
|
47471
|
-
|
|
47472
|
-
|
|
47473
|
-
|
|
47474
|
-
|
|
47475
|
-
|
|
47476
|
-
|
|
47477
|
-
|
|
47478
|
-
|
|
47479
|
-
|
|
47480
|
-
|
|
47481
|
-
|
|
47482
|
-
|
|
47483
|
-
|
|
47484
|
-
|
|
47485
|
-
|
|
47486
|
-
|
|
47487
|
-
|
|
47488
|
-
|
|
47489
|
-
|
|
47490
|
-
|
|
47491
|
-
|
|
47492
|
-
|
|
47493
|
-
|
|
47494
|
-
|
|
47495
|
-
|
|
47496
|
-
|
|
47497
|
-
|
|
47498
|
-
|
|
47499
|
-
|
|
47500
|
-
|
|
47501
|
-
|
|
47502
|
-
|
|
47503
|
-
|
|
47504
|
-
|
|
47505
|
-
|
|
47506
|
-
|
|
47507
|
-
|
|
47508
|
-
|
|
47509
|
-
|
|
47510
|
-
body: { code: normalizeReferralCode(req.code) },
|
|
47511
|
-
authorizationToken,
|
|
47512
|
-
timeoutMs: opts.timeoutMs
|
|
47513
|
-
});
|
|
47514
|
-
return unwrapResponseObject(response);
|
|
47515
|
-
}
|
|
47516
|
-
async function apiUpdateReferralCode(req, opts) {
|
|
47517
|
-
const endpoint = "/v2/referral/code";
|
|
47518
|
-
const authorizationToken = requireAuthorizationToken(opts.authorizationToken, endpoint);
|
|
47519
|
-
const response = await apiFetch({
|
|
47520
|
-
url: `${withApiBase(opts.baseApiUrl)}${endpoint}`,
|
|
47521
|
-
method: "PATCH",
|
|
47522
|
-
body: { code: normalizeReferralCode(req.code) },
|
|
47523
|
-
authorizationToken,
|
|
47524
|
-
timeoutMs: opts.timeoutMs
|
|
47525
|
-
});
|
|
47526
|
-
return unwrapResponseObject(response);
|
|
47527
|
-
}
|
|
47528
|
-
async function apiUploadSellerCredential(processorName, payeeDetails, bundle, baseApiUrl, timeoutMs) {
|
|
47529
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
47530
|
-
payeeDetails
|
|
47531
|
-
)}/seller-credential`;
|
|
47532
|
-
return apiFetch({
|
|
47533
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
47534
|
-
method: "POST",
|
|
47535
|
-
body: bundle,
|
|
47536
|
-
timeoutMs
|
|
47537
|
-
});
|
|
47538
|
-
}
|
|
47539
|
-
async function apiUploadGoogleOAuthSellerCredential(processorName, payeeDetails, body, baseApiUrl, opts) {
|
|
47540
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
47541
|
-
payeeDetails
|
|
47542
|
-
)}/seller-credential/google-oauth`;
|
|
47543
|
-
return apiFetch({
|
|
47544
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
47545
|
-
method: "POST",
|
|
47546
|
-
body,
|
|
47547
|
-
timeoutMs: opts?.timeoutMs
|
|
47548
|
-
});
|
|
47549
|
-
}
|
|
47550
|
-
async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApiUrl, timeoutMs) {
|
|
47551
|
-
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
47552
|
-
payeeDetails
|
|
47553
|
-
)}/seller-credential/status`;
|
|
47554
|
-
return apiFetch({
|
|
47555
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
47556
|
-
method: "GET",
|
|
47557
|
-
timeoutMs
|
|
47558
|
-
});
|
|
47559
|
-
}
|
|
47560
|
-
async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey) {
|
|
47561
|
-
const body = {
|
|
47562
|
-
txId: req.txId,
|
|
47563
|
-
chainId: req.chainId,
|
|
47564
|
-
intent: req.intent,
|
|
47565
|
-
...req.metadata !== void 0 ? { metadata: req.metadata } : {}
|
|
47566
|
-
};
|
|
47567
|
-
return apiFetch({
|
|
47568
|
-
url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
|
|
47569
|
-
method: "POST",
|
|
47570
|
-
body,
|
|
47571
|
-
apiKey,
|
|
47572
|
-
timeoutMs
|
|
47573
|
-
});
|
|
47574
|
-
}
|
|
47575
|
-
async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs) {
|
|
47576
|
-
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
47577
|
-
baseApiUrl: optsOrBaseApiUrl,
|
|
47578
|
-
timeoutMs
|
|
47579
|
-
} : optsOrBaseApiUrl;
|
|
47580
|
-
const query = new URLSearchParams();
|
|
47581
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
47582
|
-
if (value === void 0 || value === null) return;
|
|
47583
|
-
query.set(key, String(value));
|
|
47584
|
-
});
|
|
47585
|
-
const response = await apiFetch({
|
|
47586
|
-
url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook?${query.toString()}`,
|
|
47587
|
-
method: "GET",
|
|
47588
|
-
timeoutMs: opts.timeoutMs
|
|
47589
|
-
});
|
|
47590
|
-
return response.responseObject;
|
|
47591
|
-
}
|
|
47592
|
-
async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs) {
|
|
47593
|
-
const opts = typeof optsOrBaseApiUrl === "string" ? {
|
|
47594
|
-
baseApiUrl: optsOrBaseApiUrl,
|
|
47595
|
-
timeoutMs
|
|
47596
|
-
} : optsOrBaseApiUrl;
|
|
47597
|
-
const escrowAddress = requireEscrowAddress(
|
|
47598
|
-
params.escrowAddress,
|
|
47599
|
-
"apiGetDepositBundle requires escrowAddress"
|
|
47600
|
-
);
|
|
47601
|
-
const query = new URLSearchParams({ escrowAddress });
|
|
47602
|
-
if (params.dailySnapshotLimit !== void 0) {
|
|
47603
|
-
query.set("dailySnapshotLimit", String(params.dailySnapshotLimit));
|
|
47723
|
+
order_by: this.buildDelegationOrderBy(pagination),
|
|
47724
|
+
limit: pagination?.limit ?? DEFAULT_LIMIT2,
|
|
47725
|
+
offset: pagination?.offset ?? 0
|
|
47726
|
+
};
|
|
47727
|
+
try {
|
|
47728
|
+
const result = await this.client.query({
|
|
47729
|
+
query: RATE_MANAGER_DELEGATIONS_QUERY,
|
|
47730
|
+
variables
|
|
47731
|
+
});
|
|
47732
|
+
return (result.Deposit ?? []).map((deposit) => toDelegationEntityFromDeposit(deposit)).filter((delegation) => Boolean(delegation));
|
|
47733
|
+
} catch (error) {
|
|
47734
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47735
|
+
throw error;
|
|
47736
|
+
}
|
|
47737
|
+
const legacyResult = await this.client.query({
|
|
47738
|
+
query: LEGACY_RATE_MANAGER_DELEGATIONS_QUERY,
|
|
47739
|
+
variables: {
|
|
47740
|
+
...variables,
|
|
47741
|
+
order_by: this.buildLegacyDelegationOrderBy(pagination)
|
|
47742
|
+
}
|
|
47743
|
+
});
|
|
47744
|
+
return legacyResult.RateManagerDelegation ?? [];
|
|
47745
|
+
}
|
|
47746
|
+
}
|
|
47747
|
+
async fetchManagerDailySnapshots(rateManagerId, options) {
|
|
47748
|
+
if (!rateManagerId) return [];
|
|
47749
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47750
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
47751
|
+
try {
|
|
47752
|
+
const result = await this.client.query({
|
|
47753
|
+
query: MANAGER_DAILY_SNAPSHOTS_QUERY,
|
|
47754
|
+
variables: {
|
|
47755
|
+
where: {
|
|
47756
|
+
rateManagerId: { _eq: normalizedId },
|
|
47757
|
+
...normalizedRateManagerAddress ? {
|
|
47758
|
+
id: {
|
|
47759
|
+
_ilike: buildRateManagerScopedIdPattern(
|
|
47760
|
+
normalizedId,
|
|
47761
|
+
normalizedRateManagerAddress
|
|
47762
|
+
)
|
|
47763
|
+
}
|
|
47764
|
+
} : {}
|
|
47765
|
+
},
|
|
47766
|
+
order_by: [{ dayTimestamp: "asc" }],
|
|
47767
|
+
limit: options?.limit ?? 365
|
|
47768
|
+
}
|
|
47769
|
+
});
|
|
47770
|
+
return result.ManagerDailySnapshot ?? [];
|
|
47771
|
+
} catch (error) {
|
|
47772
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47773
|
+
throw error;
|
|
47774
|
+
}
|
|
47775
|
+
return [];
|
|
47776
|
+
}
|
|
47604
47777
|
}
|
|
47605
|
-
|
|
47606
|
-
|
|
47607
|
-
|
|
47608
|
-
|
|
47778
|
+
async fetchDelegationForDeposit(depositId, options) {
|
|
47779
|
+
if (!depositId) return null;
|
|
47780
|
+
const normalizedDepositId = normalizeCompositeDepositId(depositId, options?.escrowAddress);
|
|
47781
|
+
try {
|
|
47782
|
+
const result = await this.client.query({
|
|
47783
|
+
query: DEPOSIT_DELEGATION_QUERY,
|
|
47784
|
+
variables: {
|
|
47785
|
+
depositId: normalizedDepositId
|
|
47786
|
+
}
|
|
47787
|
+
});
|
|
47788
|
+
const delegationDeposit = result.Deposit?.[0];
|
|
47789
|
+
if (!delegationDeposit) {
|
|
47790
|
+
return null;
|
|
47791
|
+
}
|
|
47792
|
+
return toDelegationEntityFromDeposit(delegationDeposit) ?? null;
|
|
47793
|
+
} catch (error) {
|
|
47794
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47795
|
+
throw error;
|
|
47796
|
+
}
|
|
47797
|
+
const legacyResult = await this.client.query({
|
|
47798
|
+
query: LEGACY_DEPOSIT_DELEGATION_QUERY,
|
|
47799
|
+
variables: {
|
|
47800
|
+
depositId: normalizedDepositId
|
|
47801
|
+
}
|
|
47802
|
+
});
|
|
47803
|
+
return legacyResult.RateManagerDelegation?.[0] ?? null;
|
|
47804
|
+
}
|
|
47805
|
+
}
|
|
47806
|
+
async fetchManualRateUpdates(rateManagerId, options) {
|
|
47807
|
+
if (!rateManagerId) return [];
|
|
47808
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47809
|
+
try {
|
|
47810
|
+
const result = await this.client.query({
|
|
47811
|
+
query: MANUAL_RATE_UPDATES_QUERY,
|
|
47812
|
+
variables: {
|
|
47813
|
+
where: {
|
|
47814
|
+
rateManagerId: { _eq: normalizedId }
|
|
47815
|
+
},
|
|
47816
|
+
order_by: [{ id: "desc" }],
|
|
47817
|
+
limit: options?.limit ?? 100
|
|
47818
|
+
}
|
|
47819
|
+
});
|
|
47820
|
+
return (result.RateManagerV1_RateManagerRateUpdated ?? []).map((e) => ({
|
|
47821
|
+
...e,
|
|
47822
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
47823
|
+
minRate: e.minRate ?? e.rate ?? "0"
|
|
47824
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47825
|
+
} catch (error) {
|
|
47826
|
+
if (!isSchemaCompatibilityError(error)) {
|
|
47827
|
+
throw error;
|
|
47828
|
+
}
|
|
47829
|
+
return [];
|
|
47830
|
+
}
|
|
47831
|
+
}
|
|
47832
|
+
async fetchOracleConfigUpdates(rateManagerId, options) {
|
|
47833
|
+
if (!rateManagerId) return [];
|
|
47834
|
+
const normalizedId = normalizeRateManagerId(rateManagerId);
|
|
47835
|
+
const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
|
|
47836
|
+
const limit = options?.limit ?? 100;
|
|
47837
|
+
try {
|
|
47838
|
+
const depositScopes = await this.fetchHistoricalRateManagerDepositScopes(
|
|
47839
|
+
normalizedId,
|
|
47840
|
+
normalizedRateManagerAddress || void 0
|
|
47841
|
+
);
|
|
47842
|
+
if (!depositScopes.length) {
|
|
47843
|
+
return [];
|
|
47844
|
+
}
|
|
47845
|
+
const scopedKeys = new Set(depositScopes.map((scope) => buildDepositScopeKey(scope)));
|
|
47846
|
+
const result = await this.client.query({
|
|
47847
|
+
query: ORACLE_CONFIG_UPDATES_QUERY,
|
|
47848
|
+
variables: {
|
|
47849
|
+
where: {
|
|
47850
|
+
_or: depositScopes.map((scope) => ({
|
|
47851
|
+
_and: [
|
|
47852
|
+
{ depositId: { _eq: scope.depositIdOnContract } },
|
|
47853
|
+
{ escrow: { _eq: scope.escrow } }
|
|
47854
|
+
]
|
|
47855
|
+
}))
|
|
47856
|
+
},
|
|
47857
|
+
order_by: [{ id: "desc" }],
|
|
47858
|
+
limit
|
|
47859
|
+
}
|
|
47860
|
+
});
|
|
47861
|
+
return (result.EscrowV2_DepositOracleRateConfigSet ?? []).filter((event) => {
|
|
47862
|
+
const escrow = normalizeAddress3(event.escrow);
|
|
47863
|
+
const depositIdOnContract = event.depositIdOnContract ?? event.depositId?.toString?.() ?? "";
|
|
47864
|
+
if (!escrow || !depositIdOnContract) return false;
|
|
47865
|
+
return scopedKeys.has(
|
|
47866
|
+
buildDepositScopeKey({
|
|
47867
|
+
escrow,
|
|
47868
|
+
depositIdOnContract
|
|
47869
|
+
})
|
|
47870
|
+
);
|
|
47871
|
+
}).map((e) => ({
|
|
47872
|
+
...e,
|
|
47873
|
+
rateManagerId: normalizedId,
|
|
47874
|
+
escrow: normalizeAddress3(e.escrow) || void 0,
|
|
47875
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
47876
|
+
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
47877
|
+
adapter: e.adapter ?? "",
|
|
47878
|
+
spreadBps: e.spreadBps ?? 0
|
|
47879
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47880
|
+
} catch (error) {
|
|
47881
|
+
if (isSchemaCompatibilityError(error)) ; else {
|
|
47882
|
+
throw error;
|
|
47883
|
+
}
|
|
47884
|
+
const legacyResult = await this.client.query({
|
|
47885
|
+
query: LEGACY_ORACLE_CONFIG_UPDATES_QUERY,
|
|
47886
|
+
variables: {
|
|
47887
|
+
where: {
|
|
47888
|
+
rateManagerId: { _eq: normalizedId }
|
|
47889
|
+
},
|
|
47890
|
+
order_by: [{ id: "desc" }],
|
|
47891
|
+
limit
|
|
47892
|
+
}
|
|
47893
|
+
});
|
|
47894
|
+
return (legacyResult.RateManagerV1_DepositorFloorSet ?? []).map((e) => ({
|
|
47895
|
+
...e,
|
|
47896
|
+
currency: e.currency ?? e.currencyCode ?? "",
|
|
47897
|
+
depositIdOnContract: e.depositIdOnContract ?? e.depositId ?? "",
|
|
47898
|
+
adapter: e.adapter ?? e.oracleAdapter ?? "",
|
|
47899
|
+
spreadBps: e.spreadBps ?? e.floorSpreadBps ?? 0
|
|
47900
|
+
})).sort((a, b) => compareEventCursorIdsByRecency(a.id, b.id));
|
|
47901
|
+
}
|
|
47902
|
+
}
|
|
47903
|
+
};
|
|
47904
|
+
|
|
47905
|
+
// src/indexer/intentVerification.ts
|
|
47906
|
+
async function fetchFulfillmentAndPayment(client, intentHash) {
|
|
47907
|
+
return client.query({
|
|
47908
|
+
query: FULFILLMENT_AND_PAYMENT_QUERY,
|
|
47909
|
+
variables: { intentHash }
|
|
47609
47910
|
});
|
|
47610
|
-
return response.responseObject;
|
|
47611
47911
|
}
|
|
47612
47912
|
|
|
47913
|
+
// src/client/Zkp2pClient.ts
|
|
47914
|
+
init_contracts();
|
|
47915
|
+
|
|
47613
47916
|
// src/sellerCredentials.ts
|
|
47614
47917
|
function normalizeBaseApiUrl(value) {
|
|
47615
47918
|
return (value?.trim().replace(/\/+$/u, "") || DEFAULT_BASE_API_URL).replace(/\/v1$/u, "");
|
|
@@ -47619,7 +47922,7 @@ function assertBundlePlatformMatches(params) {
|
|
|
47619
47922
|
throw new Error("Seller credential bundle platform does not match upload platform");
|
|
47620
47923
|
}
|
|
47621
47924
|
}
|
|
47622
|
-
async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
47925
|
+
async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs, authorizationToken) {
|
|
47623
47926
|
assertBundlePlatformMatches(params);
|
|
47624
47927
|
const normalizedBaseApiUrl = normalizeBaseApiUrl(baseApiUrl);
|
|
47625
47928
|
if (params.platform === "wise") {
|
|
@@ -47628,7 +47931,8 @@ async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
|
47628
47931
|
params.bundle.payeeIdHash,
|
|
47629
47932
|
params.bundle,
|
|
47630
47933
|
normalizedBaseApiUrl,
|
|
47631
|
-
timeoutMs
|
|
47934
|
+
timeoutMs,
|
|
47935
|
+
authorizationToken
|
|
47632
47936
|
);
|
|
47633
47937
|
}
|
|
47634
47938
|
const registeredPayeePayload = {
|
|
@@ -47658,7 +47962,8 @@ async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
|
47658
47962
|
registeredPayee.hashedOnchainId,
|
|
47659
47963
|
params.bundle,
|
|
47660
47964
|
normalizedBaseApiUrl,
|
|
47661
|
-
timeoutMs
|
|
47965
|
+
timeoutMs,
|
|
47966
|
+
authorizationToken
|
|
47662
47967
|
);
|
|
47663
47968
|
}
|
|
47664
47969
|
|
|
@@ -47820,9 +48125,7 @@ function isObjectRecord(value) {
|
|
|
47820
48125
|
return true;
|
|
47821
48126
|
}
|
|
47822
48127
|
function normalizeTelegramUsername(value) {
|
|
47823
|
-
if (typeof value !== "string")
|
|
47824
|
-
return value === null ? null : null;
|
|
47825
|
-
}
|
|
48128
|
+
if (typeof value !== "string") return null;
|
|
47826
48129
|
const normalized = value.trim();
|
|
47827
48130
|
return normalized.length > 0 ? normalized : null;
|
|
47828
48131
|
}
|
|
@@ -47869,10 +48172,23 @@ function normalizePayeeDataInputItem(raw) {
|
|
|
47869
48172
|
if (!legacy) {
|
|
47870
48173
|
return null;
|
|
47871
48174
|
}
|
|
48175
|
+
const metadata = legacy.metadata && isObjectRecord(legacy.metadata) ? { ...legacy.metadata } : {};
|
|
48176
|
+
if (candidate.identityAttestation !== void 0 && candidate.identityAttestation !== null) {
|
|
48177
|
+
metadata.identityAttestation = candidate.identityAttestation;
|
|
48178
|
+
}
|
|
47872
48179
|
return {
|
|
47873
48180
|
offchainId: legacy.offchainId,
|
|
47874
48181
|
telegramUsername: legacy.telegramUsername,
|
|
47875
|
-
metadata:
|
|
48182
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : null
|
|
48183
|
+
};
|
|
48184
|
+
}
|
|
48185
|
+
function getPayeeRegistrationMetadata(payeeData) {
|
|
48186
|
+
if (payeeData.identityAttestation === void 0 || payeeData.identityAttestation === null) {
|
|
48187
|
+
return payeeData.metadata;
|
|
48188
|
+
}
|
|
48189
|
+
return {
|
|
48190
|
+
...isObjectRecord(payeeData.metadata) ? payeeData.metadata : {},
|
|
48191
|
+
identityAttestation: payeeData.identityAttestation
|
|
47876
48192
|
};
|
|
47877
48193
|
}
|
|
47878
48194
|
function resolvePayeeDataInput(params, methodName) {
|
|
@@ -47899,7 +48215,7 @@ function toPostDepositDetailsRequest(processorName, payeeData, index) {
|
|
|
47899
48215
|
processorName,
|
|
47900
48216
|
offchainId: payeeData.offchainId,
|
|
47901
48217
|
telegramUsername: payeeData.telegramUsername,
|
|
47902
|
-
metadata: payeeData
|
|
48218
|
+
metadata: getPayeeRegistrationMetadata(payeeData)
|
|
47903
48219
|
};
|
|
47904
48220
|
}
|
|
47905
48221
|
var Zkp2pClient = class {
|
|
@@ -48116,7 +48432,7 @@ var Zkp2pClient = class {
|
|
|
48116
48432
|
() => ({
|
|
48117
48433
|
address: this.rateManagerControllerAddress,
|
|
48118
48434
|
abi: this.rateManagerControllerAbi,
|
|
48119
|
-
label: "Rate manager controller
|
|
48435
|
+
label: "Rate manager controller"
|
|
48120
48436
|
}),
|
|
48121
48437
|
"setDepositRateManager",
|
|
48122
48438
|
(params) => {
|
|
@@ -48130,7 +48446,7 @@ var Zkp2pClient = class {
|
|
|
48130
48446
|
() => ({
|
|
48131
48447
|
address: this.rateManagerControllerAddress,
|
|
48132
48448
|
abi: this.rateManagerControllerAbi,
|
|
48133
|
-
label: "Rate manager controller
|
|
48449
|
+
label: "Rate manager controller"
|
|
48134
48450
|
}),
|
|
48135
48451
|
"clearDepositRateManager",
|
|
48136
48452
|
(params) => {
|
|
@@ -48216,7 +48532,7 @@ var Zkp2pClient = class {
|
|
|
48216
48532
|
() => ({
|
|
48217
48533
|
address: this.rateManagerRegistryAddress,
|
|
48218
48534
|
abi: this.rateManagerRegistryAbi,
|
|
48219
|
-
label: "Rate manager registry
|
|
48535
|
+
label: "Rate manager registry"
|
|
48220
48536
|
}),
|
|
48221
48537
|
"setFee",
|
|
48222
48538
|
(params) => {
|
|
@@ -48701,6 +49017,10 @@ var Zkp2pClient = class {
|
|
|
48701
49017
|
const prepared = await this.prepareFulfillIntent(params);
|
|
48702
49018
|
const txHash = await this.executePreparedTransaction(prepared, params.txOverrides);
|
|
48703
49019
|
params?.callbacks?.onTxSent?.(txHash);
|
|
49020
|
+
if (params?.callbacks?.onTxMined) {
|
|
49021
|
+
await this.publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
49022
|
+
params.callbacks.onTxMined(txHash);
|
|
49023
|
+
}
|
|
48704
49024
|
return txHash;
|
|
48705
49025
|
},
|
|
48706
49026
|
{
|
|
@@ -48719,7 +49039,7 @@ var Zkp2pClient = class {
|
|
|
48719
49039
|
this.walletClient = opts.walletClient;
|
|
48720
49040
|
this.chainId = opts.chainId;
|
|
48721
49041
|
this.runtimeEnv = opts.runtimeEnv ?? "production";
|
|
48722
|
-
const inferredRpc = this.walletClient
|
|
49042
|
+
const inferredRpc = this.walletClient.chain?.rpcUrls?.default?.http?.[0];
|
|
48723
49043
|
const defaultRpcUrls = {
|
|
48724
49044
|
[chains.base.id]: "https://mainnet.base.org",
|
|
48725
49045
|
[chains.hardhat.id]: "http://127.0.0.1:8545"
|
|
@@ -48732,7 +49052,7 @@ var Zkp2pClient = class {
|
|
|
48732
49052
|
const selectedChain = chainMap[this.chainId];
|
|
48733
49053
|
this.publicClient = viem.createPublicClient({
|
|
48734
49054
|
chain: selectedChain,
|
|
48735
|
-
transport: viem.http(rpc, { batch: false })
|
|
49055
|
+
transport: opts.rpcTransport ?? viem.http(rpc, { batch: false })
|
|
48736
49056
|
});
|
|
48737
49057
|
const { addresses, abis } = getContracts(this.chainId, this.runtimeEnv);
|
|
48738
49058
|
const toAddress = (value) => this.isValidHexAddress(value) ? value : void 0;
|
|
@@ -48750,12 +49070,10 @@ var Zkp2pClient = class {
|
|
|
48750
49070
|
};
|
|
48751
49071
|
this.escrowV2Address = toAddress(addresses.escrowV2 ?? addresses.escrow);
|
|
48752
49072
|
this.escrowV2Abi = abis.escrowV2 ?? abis.escrow;
|
|
48753
|
-
this.orchestratorV2Address = toAddress(
|
|
48754
|
-
addresses.orchestratorV2 ?? addresses.orchestrator
|
|
48755
|
-
);
|
|
49073
|
+
this.orchestratorV2Address = toAddress(addresses.orchestratorV2 ?? addresses.orchestrator);
|
|
48756
49074
|
this.orchestratorV2Abi = abis.orchestratorV2 ?? abis.orchestrator;
|
|
48757
|
-
const configuredEscrowAddresses = (addresses.escrowAddresses ?? []).map((value) => toAddress(value)).filter(Boolean);
|
|
48758
|
-
const configuredOrchestratorAddresses = (addresses.orchestratorAddresses ?? []).map((value) => toAddress(value)).filter(Boolean);
|
|
49075
|
+
const configuredEscrowAddresses = (addresses.escrowAddresses ?? []).map((value) => toAddress(value)).filter((value) => Boolean(value));
|
|
49076
|
+
const configuredOrchestratorAddresses = (addresses.orchestratorAddresses ?? []).map((value) => toAddress(value)).filter((value) => Boolean(value));
|
|
48759
49077
|
this.escrowAddresses = uniqAddresses([
|
|
48760
49078
|
this.escrowV2Address ?? toAddress(addresses.escrow),
|
|
48761
49079
|
...configuredEscrowAddresses
|
|
@@ -48821,8 +49139,7 @@ var Zkp2pClient = class {
|
|
|
48821
49139
|
orchestratorV2Abi: this.orchestratorV2Abi,
|
|
48822
49140
|
orchestratorAddresses: this.orchestratorAddresses
|
|
48823
49141
|
});
|
|
48824
|
-
|
|
48825
|
-
if (maybeUsdc) this._usdcAddress = maybeUsdc;
|
|
49142
|
+
if (addresses.usdc) this._usdcAddress = addresses.usdc;
|
|
48826
49143
|
const runtimeToIndexerEnv = {
|
|
48827
49144
|
production: "PRODUCTION",
|
|
48828
49145
|
preproduction: "PREPRODUCTION",
|
|
@@ -48898,6 +49215,15 @@ var Zkp2pClient = class {
|
|
|
48898
49215
|
getPvIntent: (intentHash) => this.getPvIntent(intentHash)
|
|
48899
49216
|
}
|
|
48900
49217
|
});
|
|
49218
|
+
this._referralOps = new ReferralAccountOperations({
|
|
49219
|
+
getWalletClient: () => this.walletClient,
|
|
49220
|
+
getChainId: () => this.chainId,
|
|
49221
|
+
getRuntimeEnv: () => this.runtimeEnv,
|
|
49222
|
+
getBaseApiUrl: () => this.baseApiUrl,
|
|
49223
|
+
getApiTimeoutMs: () => this.apiTimeoutMs,
|
|
49224
|
+
getAuthorizationToken: () => this.authorizationToken,
|
|
49225
|
+
getAuthorizationTokenProvider: () => this.getAuthorizationToken
|
|
49226
|
+
});
|
|
48901
49227
|
}
|
|
48902
49228
|
isValidHexAddress(addr) {
|
|
48903
49229
|
return isValidHexAddress(addr);
|
|
@@ -48935,22 +49261,12 @@ var Zkp2pClient = class {
|
|
|
48935
49261
|
`attestationServiceUrl is required when baseApiUrl is not a supported zkp2p API host: ${baseApiUrl}`
|
|
48936
49262
|
);
|
|
48937
49263
|
}
|
|
48938
|
-
async resolveAuthorizationToken(
|
|
48939
|
-
if (
|
|
48940
|
-
return
|
|
48941
|
-
}
|
|
48942
|
-
const provider = opts?.getAuthorizationToken ?? this.getAuthorizationToken;
|
|
48943
|
-
if (provider) {
|
|
48944
|
-
return await provider() ?? void 0;
|
|
49264
|
+
async resolveAuthorizationToken() {
|
|
49265
|
+
if (this.getAuthorizationToken) {
|
|
49266
|
+
return await this.getAuthorizationToken() ?? void 0;
|
|
48945
49267
|
}
|
|
48946
49268
|
return this.authorizationToken;
|
|
48947
49269
|
}
|
|
48948
|
-
normalizeOracleRateConfig(config) {
|
|
48949
|
-
return normalizeOracleRateConfig(config);
|
|
48950
|
-
}
|
|
48951
|
-
escrowCurrencyHasOracleConfig(abi) {
|
|
48952
|
-
return escrowCurrencyHasOracleConfig(abi);
|
|
48953
|
-
}
|
|
48954
49270
|
/**
|
|
48955
49271
|
* Normalizes currency tuples by appending an empty `oracleRateConfig` when the ABI
|
|
48956
49272
|
* requires it and the caller hasn't provided one.
|
|
@@ -48963,21 +49279,9 @@ var Zkp2pClient = class {
|
|
|
48963
49279
|
escrowAddress: params?.escrowAddress
|
|
48964
49280
|
});
|
|
48965
49281
|
}
|
|
48966
|
-
parseManagerFeeFromRead(result) {
|
|
48967
|
-
return parseManagerFeeFromRead(result);
|
|
48968
|
-
}
|
|
48969
|
-
getAbiFunction(abi, ...names) {
|
|
48970
|
-
return getAbiFunction(abi, ...names);
|
|
48971
|
-
}
|
|
48972
49282
|
resolveAbiFunctionName(abi, names) {
|
|
48973
49283
|
return resolveAbiFunctionName(abi, names);
|
|
48974
49284
|
}
|
|
48975
|
-
abiTupleHasComponent(abi, functionName, componentName) {
|
|
48976
|
-
return abiTupleHasComponent(abi, functionName, componentName);
|
|
48977
|
-
}
|
|
48978
|
-
abiFunctionHasInput(abi, functionName, inputName) {
|
|
48979
|
-
return abiFunctionHasInput(abi, functionName, inputName);
|
|
48980
|
-
}
|
|
48981
49285
|
resolveEscrowAddressOrThrow(escrowAddress, depositId, _methodName) {
|
|
48982
49286
|
const resolved = escrowAddress ?? this.parseEscrowAddressFromCompositeDepositId(depositId);
|
|
48983
49287
|
if (resolved) return resolved;
|
|
@@ -49103,7 +49407,7 @@ var Zkp2pClient = class {
|
|
|
49103
49407
|
async lookupIntentEscrowOnchain(intentHash) {
|
|
49104
49408
|
try {
|
|
49105
49409
|
const view = await this.getPvIntent(intentHash);
|
|
49106
|
-
return this.normalizeAddress(view
|
|
49410
|
+
return this.normalizeAddress(view.intent.escrow);
|
|
49107
49411
|
} catch {
|
|
49108
49412
|
return void 0;
|
|
49109
49413
|
}
|
|
@@ -49168,6 +49472,15 @@ var Zkp2pClient = class {
|
|
|
49168
49472
|
if (fallback) return fallback;
|
|
49169
49473
|
throw new Error("Orchestrator not available");
|
|
49170
49474
|
}
|
|
49475
|
+
/**
|
|
49476
|
+
* Spread helper for viem requests.
|
|
49477
|
+
* justified: TxOverrides mixes legacy gasPrice with EIP-1559 fee fields, which
|
|
49478
|
+
* viem's discriminated request unions reject; keep the suppression in one place.
|
|
49479
|
+
*/
|
|
49480
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49481
|
+
applyTxOverrides(overrides) {
|
|
49482
|
+
return overrides;
|
|
49483
|
+
}
|
|
49171
49484
|
/**
|
|
49172
49485
|
* Simulate a contract call (validation only) and send with ERC-8021 attribution.
|
|
49173
49486
|
* Referrer codes are stripped from overrides for simulation and appended to calldata.
|
|
@@ -49180,7 +49493,7 @@ var Zkp2pClient = class {
|
|
|
49180
49493
|
functionName: opts.functionName,
|
|
49181
49494
|
args: opts.args ?? [],
|
|
49182
49495
|
account: this.walletClient.account,
|
|
49183
|
-
...txOverrides
|
|
49496
|
+
...this.applyTxOverrides(txOverrides)
|
|
49184
49497
|
});
|
|
49185
49498
|
return sendTransactionWithAttribution(
|
|
49186
49499
|
this.walletClient,
|
|
@@ -49207,7 +49520,7 @@ var Zkp2pClient = class {
|
|
|
49207
49520
|
functionName: prepared.functionName,
|
|
49208
49521
|
args: prepared.args,
|
|
49209
49522
|
account: this.walletClient.account,
|
|
49210
|
-
...overrides
|
|
49523
|
+
...this.applyTxOverrides(overrides)
|
|
49211
49524
|
});
|
|
49212
49525
|
return this.walletClient.sendTransaction({
|
|
49213
49526
|
to: prepared.to,
|
|
@@ -49215,7 +49528,7 @@ var Zkp2pClient = class {
|
|
|
49215
49528
|
value: prepared.value,
|
|
49216
49529
|
account: this.walletClient.account,
|
|
49217
49530
|
chain: this.walletClient.chain,
|
|
49218
|
-
...overrides
|
|
49531
|
+
...this.applyTxOverrides(overrides)
|
|
49219
49532
|
});
|
|
49220
49533
|
}
|
|
49221
49534
|
prepareEscrowTransaction(opts) {
|
|
@@ -49821,20 +50134,18 @@ var Zkp2pClient = class {
|
|
|
49821
50134
|
if (params.processorNames.length !== payeeData.length) {
|
|
49822
50135
|
throw new Error("processorNames and payeeData length mismatch");
|
|
49823
50136
|
}
|
|
49824
|
-
const baseApiUrl = (this.baseApiUrl ??
|
|
50137
|
+
const baseApiUrl = (this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(/\/$/, "");
|
|
49825
50138
|
const depositDetails = params.processorNames.map(
|
|
49826
50139
|
(processorName, index) => toPostDepositDetailsRequest(processorName, payeeData[index], index)
|
|
49827
50140
|
);
|
|
49828
50141
|
const apiResponses = await Promise.all(
|
|
49829
50142
|
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
49830
50143
|
);
|
|
49831
|
-
if (!apiResponses.every((r) => r
|
|
49832
|
-
const failed = apiResponses.find((r) => !r
|
|
50144
|
+
if (!apiResponses.every((r) => r.success)) {
|
|
50145
|
+
const failed = apiResponses.find((r) => !r.success);
|
|
49833
50146
|
throw new Error(failed?.message || "Failed to register payee details");
|
|
49834
50147
|
}
|
|
49835
|
-
const hashedOnchainIds = apiResponses.map(
|
|
49836
|
-
(r) => r.responseObject?.hashedOnchainId
|
|
49837
|
-
);
|
|
50148
|
+
const hashedOnchainIds = apiResponses.map((r) => r.responseObject.hashedOnchainId);
|
|
49838
50149
|
return { depositDetails, hashedOnchainIds };
|
|
49839
50150
|
}
|
|
49840
50151
|
/**
|
|
@@ -49958,17 +50269,15 @@ var Zkp2pClient = class {
|
|
|
49958
50269
|
}
|
|
49959
50270
|
hashedOnchainIds = payeeDetailsHashes;
|
|
49960
50271
|
} else {
|
|
49961
|
-
const baseApiUrl = (this.baseApiUrl ??
|
|
50272
|
+
const baseApiUrl = (this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(/\/$/, "");
|
|
49962
50273
|
const apiResponses = await Promise.all(
|
|
49963
50274
|
depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
|
|
49964
50275
|
);
|
|
49965
|
-
if (!apiResponses.every((r) => r
|
|
49966
|
-
const failed = apiResponses.find((r) => !r
|
|
50276
|
+
if (!apiResponses.every((r) => r.success)) {
|
|
50277
|
+
const failed = apiResponses.find((r) => !r.success);
|
|
49967
50278
|
throw new Error(failed?.message || "Failed to create deposit details");
|
|
49968
50279
|
}
|
|
49969
|
-
hashedOnchainIds = apiResponses.map(
|
|
49970
|
-
(r) => r.responseObject?.hashedOnchainId
|
|
49971
|
-
);
|
|
50280
|
+
hashedOnchainIds = apiResponses.map((r) => r.responseObject.hashedOnchainId);
|
|
49972
50281
|
}
|
|
49973
50282
|
paymentMethodData = hashedOnchainIds.map((hid) => ({
|
|
49974
50283
|
intentGatingService,
|
|
@@ -49990,10 +50299,10 @@ var Zkp2pClient = class {
|
|
|
49990
50299
|
}
|
|
49991
50300
|
});
|
|
49992
50301
|
const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await Promise.resolve().then(() => (init_currency(), currency_exports));
|
|
49993
|
-
|
|
49994
|
-
|
|
50302
|
+
currencies = mapConversionRatesToOnchainMinRate2(
|
|
50303
|
+
params.conversionRates,
|
|
50304
|
+
paymentMethods.length
|
|
49995
50305
|
);
|
|
49996
|
-
currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
|
|
49997
50306
|
}
|
|
49998
50307
|
const escrowContext = this.resolveEscrowContext({
|
|
49999
50308
|
escrowAddress: params.escrowAddress
|
|
@@ -50085,9 +50394,6 @@ var Zkp2pClient = class {
|
|
|
50085
50394
|
async prepareFulfillIntent(params) {
|
|
50086
50395
|
return this._intentOps.prepareFulfillIntent(params);
|
|
50087
50396
|
}
|
|
50088
|
-
defaultAttestationService() {
|
|
50089
|
-
return this._intentOps.defaultAttestationService();
|
|
50090
|
-
}
|
|
50091
50397
|
// ───────────────────────────────────────────────────────────────────────────
|
|
50092
50398
|
// SUPPORTING: QUOTES API
|
|
50093
50399
|
// (Used by frontends to find available liquidity)
|
|
@@ -50135,7 +50441,7 @@ var Zkp2pClient = class {
|
|
|
50135
50441
|
*/
|
|
50136
50442
|
async getQuote(req, opts) {
|
|
50137
50443
|
const referrerFeeConfig = assertValidReferrerFeeConfig(req.referrerFeeConfig, "getQuote");
|
|
50138
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
50444
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
50139
50445
|
/\/$/,
|
|
50140
50446
|
""
|
|
50141
50447
|
);
|
|
@@ -50150,9 +50456,8 @@ var Zkp2pClient = class {
|
|
|
50150
50456
|
const quote = await apiGetQuote(reqWithEscrow, baseApiUrl, timeoutMs, this.apiKey);
|
|
50151
50457
|
const quotes = quote?.responseObject?.quotes ?? [];
|
|
50152
50458
|
for (const q of quotes) {
|
|
50153
|
-
const
|
|
50154
|
-
|
|
50155
|
-
if (payeeData && typeof q === "object") {
|
|
50459
|
+
const payeeData = normalizeQuotePayeeData(q.maker);
|
|
50460
|
+
if (payeeData) {
|
|
50156
50461
|
q.payeeData = payeeData;
|
|
50157
50462
|
}
|
|
50158
50463
|
}
|
|
@@ -50173,7 +50478,7 @@ var Zkp2pClient = class {
|
|
|
50173
50478
|
req.referrerFeeConfig,
|
|
50174
50479
|
"getQuotesBestByPlatform"
|
|
50175
50480
|
);
|
|
50176
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
50481
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
50177
50482
|
/\/$/,
|
|
50178
50483
|
""
|
|
50179
50484
|
);
|
|
@@ -50222,7 +50527,7 @@ var Zkp2pClient = class {
|
|
|
50222
50527
|
* @returns Taker tier response
|
|
50223
50528
|
*/
|
|
50224
50529
|
async getTakerTier(req, opts) {
|
|
50225
|
-
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ??
|
|
50530
|
+
const baseApiUrl = (opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL).replace(
|
|
50226
50531
|
/\/$/,
|
|
50227
50532
|
""
|
|
50228
50533
|
);
|
|
@@ -50230,49 +50535,62 @@ var Zkp2pClient = class {
|
|
|
50230
50535
|
return apiGetTakerTier(req, baseApiUrl, timeoutMs);
|
|
50231
50536
|
}
|
|
50232
50537
|
/**
|
|
50233
|
-
* Fetch
|
|
50234
|
-
*
|
|
50538
|
+
* Fetch a referral dashboard. Pass `address` for a public wallet-keyed read;
|
|
50539
|
+
* omit it to use the authenticated caller mode.
|
|
50235
50540
|
*/
|
|
50236
50541
|
async getReferralDashboard(opts) {
|
|
50237
|
-
|
|
50238
|
-
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
50239
|
-
);
|
|
50240
|
-
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
50241
|
-
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
50242
|
-
return apiGetReferralDashboard({ baseApiUrl, timeoutMs, authorizationToken });
|
|
50542
|
+
return this._referralOps.getReferralDashboard(opts);
|
|
50243
50543
|
}
|
|
50244
50544
|
/**
|
|
50245
|
-
* Fetch
|
|
50545
|
+
* Fetch referral earnings. Pass `address` for a public wallet-keyed read;
|
|
50546
|
+
* omit it to use the authenticated caller mode.
|
|
50246
50547
|
*/
|
|
50247
50548
|
async getReferralEarnings(opts) {
|
|
50248
|
-
|
|
50249
|
-
|
|
50250
|
-
|
|
50251
|
-
|
|
50252
|
-
|
|
50253
|
-
|
|
50549
|
+
return this._referralOps.getReferralEarnings(opts);
|
|
50550
|
+
}
|
|
50551
|
+
/**
|
|
50552
|
+
* Publicly look up a referral code's owner wallet and active status.
|
|
50553
|
+
*/
|
|
50554
|
+
async lookupReferralCode(code, opts) {
|
|
50555
|
+
return this._referralOps.lookupReferralCode(code, opts);
|
|
50254
50556
|
}
|
|
50255
50557
|
/**
|
|
50256
|
-
*
|
|
50558
|
+
* Create or fetch the authenticated caller's referral code with bearer auth.
|
|
50559
|
+
*/
|
|
50560
|
+
async createReferralCode(opts) {
|
|
50561
|
+
return this._referralOps.createReferralCode(opts);
|
|
50562
|
+
}
|
|
50563
|
+
/**
|
|
50564
|
+
* Create or fetch the wallet's referral code with EIP-712 signature auth.
|
|
50565
|
+
*/
|
|
50566
|
+
async createReferralCodeWithSignature(opts) {
|
|
50567
|
+
return this._referralOps.createReferralCodeWithSignature(opts);
|
|
50568
|
+
}
|
|
50569
|
+
/**
|
|
50570
|
+
* Apply another user's referral code with bearer auth.
|
|
50257
50571
|
*/
|
|
50258
50572
|
async redeemReferralCode(code, opts) {
|
|
50259
|
-
|
|
50260
|
-
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
50261
|
-
);
|
|
50262
|
-
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
50263
|
-
const authorizationToken = await this.resolveAuthorizationToken(opts);
|
|
50264
|
-
return apiRedeemReferralCode({ code }, { baseApiUrl, timeoutMs, authorizationToken });
|
|
50573
|
+
return this._referralOps.redeemReferralCode(code, opts);
|
|
50265
50574
|
}
|
|
50266
50575
|
/**
|
|
50267
|
-
*
|
|
50576
|
+
* Apply another user's referral code with EIP-712 signature auth. If
|
|
50577
|
+
* `referrerWalletAddress` is omitted, the SDK looks up the code first and signs
|
|
50578
|
+
* the current owner wallet into the redeem payload.
|
|
50579
|
+
*/
|
|
50580
|
+
async redeemReferralCodeWithSignature(code, opts) {
|
|
50581
|
+
return this._referralOps.redeemReferralCodeWithSignature(code, opts);
|
|
50582
|
+
}
|
|
50583
|
+
/**
|
|
50584
|
+
* Customize the authenticated caller's referral code with bearer auth.
|
|
50268
50585
|
*/
|
|
50269
50586
|
async updateReferralCode(code, opts) {
|
|
50270
|
-
|
|
50271
|
-
|
|
50272
|
-
|
|
50273
|
-
|
|
50274
|
-
|
|
50275
|
-
|
|
50587
|
+
return this._referralOps.updateReferralCode(code, opts);
|
|
50588
|
+
}
|
|
50589
|
+
/**
|
|
50590
|
+
* Customize the wallet's referral code with EIP-712 signature auth.
|
|
50591
|
+
*/
|
|
50592
|
+
async updateReferralCodeWithSignature(code, opts) {
|
|
50593
|
+
return this._referralOps.updateReferralCodeWithSignature(code, opts);
|
|
50276
50594
|
}
|
|
50277
50595
|
/**
|
|
50278
50596
|
* The signed `credentialValidatedAt` field is an upload-time freshness witness minted by
|
|
@@ -50294,46 +50612,17 @@ var Zkp2pClient = class {
|
|
|
50294
50612
|
const attestationServiceUrl = this.stripTrailingSlash(
|
|
50295
50613
|
opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
|
|
50296
50614
|
);
|
|
50297
|
-
const createBundle = (uploadPayload) =>
|
|
50298
|
-
|
|
50299
|
-
|
|
50300
|
-
|
|
50301
|
-
|
|
50302
|
-
|
|
50303
|
-
|
|
50304
|
-
|
|
50305
|
-
opts.attestationRuntime,
|
|
50306
|
-
requestOptions
|
|
50307
|
-
);
|
|
50308
|
-
}
|
|
50309
|
-
if (opts?.attestationRuntime) {
|
|
50310
|
-
return apiCreateSellerCredentialBundle(
|
|
50311
|
-
uploadPayload,
|
|
50312
|
-
attestationServiceUrl,
|
|
50313
|
-
params.platform,
|
|
50314
|
-
timeoutMs,
|
|
50315
|
-
opts.attestationRuntime
|
|
50316
|
-
);
|
|
50317
|
-
}
|
|
50318
|
-
if (requestOptions) {
|
|
50319
|
-
return apiCreateSellerCredentialBundle(
|
|
50320
|
-
uploadPayload,
|
|
50321
|
-
attestationServiceUrl,
|
|
50322
|
-
params.platform,
|
|
50323
|
-
timeoutMs,
|
|
50324
|
-
void 0,
|
|
50325
|
-
requestOptions
|
|
50326
|
-
);
|
|
50327
|
-
}
|
|
50328
|
-
return apiCreateSellerCredentialBundle(
|
|
50329
|
-
uploadPayload,
|
|
50330
|
-
attestationServiceUrl,
|
|
50331
|
-
params.platform,
|
|
50332
|
-
timeoutMs
|
|
50333
|
-
);
|
|
50334
|
-
};
|
|
50615
|
+
const createBundle = (uploadPayload) => apiCreateSellerCredentialBundle(
|
|
50616
|
+
uploadPayload,
|
|
50617
|
+
attestationServiceUrl,
|
|
50618
|
+
params.platform,
|
|
50619
|
+
timeoutMs,
|
|
50620
|
+
opts?.attestationRuntime,
|
|
50621
|
+
opts?.attestationServiceFallbackUrls ? { fallbackUrls: opts.attestationServiceFallbackUrls } : void 0
|
|
50622
|
+
);
|
|
50335
50623
|
if (params.platform === "wise") {
|
|
50336
50624
|
const bundleResponse2 = await createBundle({
|
|
50625
|
+
...params.callerAddress ? { callerAddress: params.callerAddress } : {},
|
|
50337
50626
|
sessionMaterial: params.sessionMaterial
|
|
50338
50627
|
});
|
|
50339
50628
|
if (!bundleResponse2.success || !bundleResponse2.responseObject) {
|
|
@@ -50348,6 +50637,7 @@ var Zkp2pClient = class {
|
|
|
50348
50637
|
);
|
|
50349
50638
|
}
|
|
50350
50639
|
const bundlePayload = {
|
|
50640
|
+
...params.callerAddress ? { callerAddress: params.callerAddress } : {},
|
|
50351
50641
|
payeeId: params.payeeId,
|
|
50352
50642
|
sessionMaterial: params.sessionMaterial
|
|
50353
50643
|
};
|
|
@@ -50374,7 +50664,8 @@ var Zkp2pClient = class {
|
|
|
50374
50664
|
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
50375
50665
|
);
|
|
50376
50666
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
50377
|
-
|
|
50667
|
+
const authorizationToken = await this.resolveAuthorizationToken();
|
|
50668
|
+
return apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs, authorizationToken);
|
|
50378
50669
|
}
|
|
50379
50670
|
/**
|
|
50380
50671
|
* Upload a seller Gmail OAuth authorization code through curator.
|
|
@@ -50477,19 +50768,6 @@ var Zkp2pClient = class {
|
|
|
50477
50768
|
protocolViewerFunctionInputCount(functionName) {
|
|
50478
50769
|
return this._pvReader.protocolViewerFunctionInputCount(functionName);
|
|
50479
50770
|
}
|
|
50480
|
-
/**
|
|
50481
|
-
* Returns the input count for a function on a specific PV entry's ABI.
|
|
50482
|
-
* Used to branch between 1-input (V1) and 2-input (V2) PV call signatures.
|
|
50483
|
-
*/
|
|
50484
|
-
pvEntryFunctionInputCount(entry, functionName) {
|
|
50485
|
-
return this._pvReader.pvEntryFunctionInputCount(entry, functionName);
|
|
50486
|
-
}
|
|
50487
|
-
isZeroAddressValue(value) {
|
|
50488
|
-
return this._pvReader.isZeroAddressValue(value);
|
|
50489
|
-
}
|
|
50490
|
-
toBigIntOrZero(value, fieldName = "numeric field") {
|
|
50491
|
-
return this._pvReader.toBigIntOrZero(value, fieldName);
|
|
50492
|
-
}
|
|
50493
50771
|
buildProtocolViewerContexts(options) {
|
|
50494
50772
|
return this._pvReader.buildProtocolViewerContexts(options);
|
|
50495
50773
|
}
|
|
@@ -50502,9 +50780,6 @@ var Zkp2pClient = class {
|
|
|
50502
50780
|
buildDepositViewFromEscrowDeposit(rawDeposit, depositId) {
|
|
50503
50781
|
return this._pvReader.buildDepositViewFromEscrowDeposit(rawDeposit, depositId);
|
|
50504
50782
|
}
|
|
50505
|
-
convertIndexerDepositToPvView(deposit) {
|
|
50506
|
-
return this._pvReader.convertIndexerDepositToPvView(deposit);
|
|
50507
|
-
}
|
|
50508
50783
|
async getPvAccountDepositsFromIndexer(owner) {
|
|
50509
50784
|
return this._pvReader.getPvAccountDepositsFromIndexer(owner);
|
|
50510
50785
|
}
|
|
@@ -50683,8 +50958,7 @@ var TAKER_TIER_FEE_DISCOUNT_BPS = {
|
|
|
50683
50958
|
PEER: 5,
|
|
50684
50959
|
PLUS: 10,
|
|
50685
50960
|
PRO: 20,
|
|
50686
|
-
PLATINUM: 30
|
|
50687
|
-
PEER_PRESIDENT: 30
|
|
50961
|
+
PLATINUM: 30
|
|
50688
50962
|
};
|
|
50689
50963
|
function getTakerTierFeeDiscountBps(tier) {
|
|
50690
50964
|
if (!tier) return 0;
|
|
@@ -50751,6 +51025,8 @@ exports.PLATFORM_METADATA = PLATFORM_METADATA;
|
|
|
50751
51025
|
exports.PYTH_CONTRACT_BASE = PYTH_CONTRACT_BASE;
|
|
50752
51026
|
exports.PYTH_ORACLE_ADAPTER = PYTH_ORACLE_ADAPTER;
|
|
50753
51027
|
exports.PYTH_ORACLE_FEEDS = PYTH_ORACLE_FEEDS;
|
|
51028
|
+
exports.REFERRAL_SIGNATURE_DOMAIN = REFERRAL_SIGNATURE_DOMAIN;
|
|
51029
|
+
exports.REFERRAL_SIGNATURE_TYPES = REFERRAL_SIGNATURE_TYPES;
|
|
50754
51030
|
exports.SPREAD_ORACLE_FEEDS = SPREAD_ORACLE_FEEDS;
|
|
50755
51031
|
exports.SUPPORTED_CHAIN_IDS = SUPPORTED_CHAIN_IDS;
|
|
50756
51032
|
exports.TAKER_TIER_CAPS = TAKER_TIER_CAPS;
|
|
@@ -50762,6 +51038,7 @@ exports.ZERO_RATE_MANAGER_ID = ZERO_RATE_MANAGER_ID;
|
|
|
50762
51038
|
exports.ZKP2P_ANDROID_REFERRER = ZKP2P_ANDROID_REFERRER;
|
|
50763
51039
|
exports.ZKP2P_IOS_REFERRER = ZKP2P_IOS_REFERRER;
|
|
50764
51040
|
exports.Zkp2pClient = Zkp2pClient;
|
|
51041
|
+
exports.apiCreateReferralCode = apiCreateReferralCode;
|
|
50765
51042
|
exports.apiCreateSellerCredentialBundle = apiCreateSellerCredentialBundle;
|
|
50766
51043
|
exports.apiGetDepositBundle = apiGetDepositBundle;
|
|
50767
51044
|
exports.apiGetOrderbook = apiGetOrderbook;
|
|
@@ -50771,6 +51048,7 @@ exports.apiGetQuotesBestByPlatform = apiGetQuotesBestByPlatform;
|
|
|
50771
51048
|
exports.apiGetReferralDashboard = apiGetReferralDashboard;
|
|
50772
51049
|
exports.apiGetReferralEarnings = apiGetReferralEarnings;
|
|
50773
51050
|
exports.apiGetTakerTier = apiGetTakerTier;
|
|
51051
|
+
exports.apiLookupReferralCode = apiLookupReferralCode;
|
|
50774
51052
|
exports.apiPostDepositDetails = apiPostDepositDetails;
|
|
50775
51053
|
exports.apiRedeemReferralCode = apiRedeemReferralCode;
|
|
50776
51054
|
exports.apiRequestIdentityAttestation = apiRequestIdentityAttestation;
|