@zkp2p/sdk 0.16.0-rc.1 → 0.16.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 +25 -4
- package/dist/build-metadata.json +2 -2
- package/dist/{chunk-MQPNWX5B.mjs → chunk-4UV5XMBU.mjs} +3 -3
- package/dist/{chunk-MQPNWX5B.mjs.map → chunk-4UV5XMBU.mjs.map} +1 -1
- package/dist/chunk-LBUSUTNI.mjs +12 -0
- package/dist/chunk-LBUSUTNI.mjs.map +1 -0
- package/dist/{currency-6XW25YEF.mjs → currency-6EFHONXS.mjs} +3 -3
- package/dist/{currency-6XW25YEF.mjs.map → currency-6EFHONXS.mjs.map} +1 -1
- package/dist/index.cjs +339 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +127 -4
- package/dist/index.d.ts +127 -4
- package/dist/index.mjs +347 -10
- package/dist/index.mjs.map +1 -1
- package/dist/protocolViewerParsers-LD72M77T.mjs +5 -0
- package/dist/{protocolViewerParsers-UMFCZESM.mjs.map → protocolViewerParsers-LD72M77T.mjs.map} +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.mjs +1 -1
- package/dist/{vaultUtils-DZMTnUHJ.d.mts → vaultUtils-Dc5ez76H.d.mts} +1 -1
- package/dist/{vaultUtils-DZMTnUHJ.d.ts → vaultUtils-Dc5ez76H.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/chunk-6ZIKILBZ.mjs +0 -12
- package/dist/chunk-6ZIKILBZ.mjs.map +0 -1
- package/dist/protocolViewerParsers-UMFCZESM.mjs +0 -5
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IntentGuardianOperations } from './chunk-RZFNRIED.mjs';
|
|
2
2
|
export { ZERO_RATE_MANAGER_ID, classifyDelegationState, classifyIntentGuardianError, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-RZFNRIED.mjs';
|
|
3
|
-
import { STAKE_VAULT_V2_ABI, ORCHESTRATOR_V4_ABI, METHOD_NAME_TO_HASH, matchesQuotePaymentMethod, matchesPaymentMethodNameAndHash, getDisputeStackAbis, getContracts, getRateManagerContracts, DISPUTE_PROTECTION_POLICY_ABI, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, DISPUTE_PROTECTION_POLICY_V2_ABI, parseBigIntLike, SUPPORTED_PAYMENT_METHOD_HASHES, getKnownStakeVaultContracts, getOrchestratorV4Contract, getOrchestratorV3Contract, getDisputeProtectionPolicyV2Contract, getDisputeProtectionPolicyContract, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash, pickAddress, baseStaging_default, base_default } from './chunk-
|
|
4
|
-
export { DISPUTE_PROTECTION_POLICY_ABI, DISPUTE_PROTECTION_POLICY_V2_ABI, ORCHESTRATOR_V3_ABI, ORCHESTRATOR_V4_ABI, PAYMENT_PLATFORMS, STAKE_VAULT_ABI, STAKE_VAULT_V2_ABI, asciiToBytes32, enrichPvDepositView, enrichPvIntentView, ensureBytes32, getContracts, getDisputeProtectionPolicyContract, getDisputeProtectionPolicyV2Contract, getGatingServiceAddress, getIntentGuardianContract, getOrchestratorV3Contract, getOrchestratorV4Contract, getPaymentMethodsCatalog, getRateManagerContracts, getStakeVaultContract, getStakeVaultV2Contract, hasIntentGuardian, parseDepositView, parseIntentView, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-
|
|
3
|
+
import { STAKE_VAULT_V2_ABI, ORCHESTRATOR_V4_ABI, METHOD_NAME_TO_HASH, matchesQuotePaymentMethod, matchesPaymentMethodNameAndHash, getDisputeStackAbis, getContracts, getRateManagerContracts, DISPUTE_PROTECTION_POLICY_ABI, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, DISPUTE_PROTECTION_POLICY_V2_ABI, parseBigIntLike, SUPPORTED_PAYMENT_METHOD_HASHES, getKnownStakeVaultContracts, getOrchestratorV4Contract, getOrchestratorV3Contract, getDisputeProtectionPolicyV2Contract, getDisputeProtectionPolicyContract, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash, pickAddress, baseStaging_default, base_default } from './chunk-4UV5XMBU.mjs';
|
|
4
|
+
export { DISPUTE_PROTECTION_POLICY_ABI, DISPUTE_PROTECTION_POLICY_V2_ABI, ORCHESTRATOR_V3_ABI, ORCHESTRATOR_V4_ABI, PAYMENT_PLATFORMS, STAKE_VAULT_ABI, STAKE_VAULT_V2_ABI, asciiToBytes32, enrichPvDepositView, enrichPvIntentView, ensureBytes32, getContracts, getDisputeProtectionPolicyContract, getDisputeProtectionPolicyV2Contract, getGatingServiceAddress, getIntentGuardianContract, getOrchestratorV3Contract, getOrchestratorV4Contract, getPaymentMethodsCatalog, getRateManagerContracts, getStakeVaultContract, getStakeVaultV2Contract, hasIntentGuardian, parseDepositView, parseIntentView, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-4UV5XMBU.mjs';
|
|
5
5
|
import { Currency, currencyKeccak256, getCurrencyCodeFromHash, currencyInfo } from './chunk-PMFXZGDQ.mjs';
|
|
6
6
|
export { Currency, currencyInfo, getCurrencyCodeFromHash, getCurrencyInfoFromCountryCode, getCurrencyInfoFromHash, isSupportedCurrencyHash, mapConversionRatesToOnchainMinRate } from './chunk-PMFXZGDQ.mjs';
|
|
7
|
-
import { define_ZKP2P_SDK_BUILD_METADATA_default } from './chunk-
|
|
7
|
+
import { define_ZKP2P_SDK_BUILD_METADATA_default } from './chunk-LBUSUTNI.mjs';
|
|
8
8
|
import { parseUnits, parseAbi, keccak256, isAddress, isAddressEqual, zeroAddress, decodeEventLog, isHex, concatHex, encodeFunctionData, encodeAbiParameters, zeroHash, createPublicClient, http, getAddress, stringToBytes, createWalletClient, parseEventLogs, formatUnits } from 'viem';
|
|
9
9
|
import { hardhat, base } from 'viem/chains';
|
|
10
10
|
import { hashUtf8, createNitroAttestationClient, verifySellerCredentialBundle, NitroAttestationError, createEncryptedBuyerTeeSessionMaterial as createEncryptedBuyerTeeSessionMaterial$1, createEncryptedDisputeSessionMaterial as createEncryptedDisputeSessionMaterial$1, createEncryptedSellerCredentialUpload } from '@zkp2p/zkp2p-attestation';
|
|
@@ -3190,7 +3190,7 @@ var ProtocolViewerReader = class {
|
|
|
3190
3190
|
if (inputCount === null) {
|
|
3191
3191
|
throw new Error("Configured ProtocolViewer ABI does not expose getDeposit");
|
|
3192
3192
|
}
|
|
3193
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
3193
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3194
3194
|
if (inputCount >= 3) {
|
|
3195
3195
|
return tryContexts(
|
|
3196
3196
|
protocolViewerContexts,
|
|
@@ -3280,7 +3280,7 @@ var ProtocolViewerReader = class {
|
|
|
3280
3280
|
return Promise.all(ids.map((id) => this.config.host.getPvDepositById(id)));
|
|
3281
3281
|
}
|
|
3282
3282
|
const bn = ids.map((id) => typeof id === "bigint" ? id : parseRawDepositId(id));
|
|
3283
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
3283
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3284
3284
|
if (inputCount >= 2) {
|
|
3285
3285
|
const requests = ids.map((id, index) => ({
|
|
3286
3286
|
index,
|
|
@@ -3397,7 +3397,7 @@ var ProtocolViewerReader = class {
|
|
|
3397
3397
|
if (!protocolViewerAddress || !protocolViewerAbi || inputCount === null) {
|
|
3398
3398
|
return this.config.host.getPvAccountDepositsFromIndexer(owner);
|
|
3399
3399
|
}
|
|
3400
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
3400
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3401
3401
|
const { address: address3, abi } = this.config.host.requireProtocolViewer();
|
|
3402
3402
|
if (inputCount >= 2) {
|
|
3403
3403
|
const readAndFilter = async (raw2) => {
|
|
@@ -3485,7 +3485,7 @@ var ProtocolViewerReader = class {
|
|
|
3485
3485
|
if (typeof raw !== "object" || raw === null || !("intentHash" in raw) || !isHex(raw.intentHash, { strict: true }) || raw.intentHash.length !== 66 || !("intent" in raw) || !("deposit" in raw)) {
|
|
3486
3486
|
throw new Error("Malformed ProtocolViewerV4 intent view");
|
|
3487
3487
|
}
|
|
3488
|
-
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-
|
|
3488
|
+
const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3489
3489
|
const { depositId, deposit, availableLiquidity, paymentMethods } = parseDepositView2(
|
|
3490
3490
|
raw.deposit
|
|
3491
3491
|
);
|
|
@@ -3515,7 +3515,7 @@ var ProtocolViewerReader = class {
|
|
|
3515
3515
|
if (protocolViewerEntries.length === 0 && !v4) {
|
|
3516
3516
|
throw new Error("ProtocolViewer not available for this network");
|
|
3517
3517
|
}
|
|
3518
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
3518
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3519
3519
|
const intentsByHash = /* @__PURE__ */ new Map();
|
|
3520
3520
|
let attemptedRead = Boolean(v4);
|
|
3521
3521
|
let hadSuccessfulRead = false;
|
|
@@ -3660,7 +3660,7 @@ var ProtocolViewerReader = class {
|
|
|
3660
3660
|
if (protocolViewerEntries.length === 0) {
|
|
3661
3661
|
throw new Error("ProtocolViewer not available for this network");
|
|
3662
3662
|
}
|
|
3663
|
-
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-
|
|
3663
|
+
const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-LD72M77T.mjs');
|
|
3664
3664
|
for (const pvEntry of protocolViewerEntries) {
|
|
3665
3665
|
const inputCount = this.pvEntryFunctionInputCount(pvEntry, "getIntent");
|
|
3666
3666
|
if (inputCount === null) {
|
|
@@ -13641,7 +13641,7 @@ var Zkp2pClient = class {
|
|
|
13641
13641
|
}
|
|
13642
13642
|
}
|
|
13643
13643
|
});
|
|
13644
|
-
const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await import('./currency-
|
|
13644
|
+
const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await import('./currency-6EFHONXS.mjs');
|
|
13645
13645
|
currencies = mapConversionRatesToOnchainMinRate2(
|
|
13646
13646
|
params.conversionRates,
|
|
13647
13647
|
paymentMethods.length
|
|
@@ -14838,6 +14838,33 @@ var errors = {
|
|
|
14838
14838
|
},
|
|
14839
14839
|
{ cause }
|
|
14840
14840
|
),
|
|
14841
|
+
sourceCapabilitiesFailed: (cause) => new PeerError(
|
|
14842
|
+
{
|
|
14843
|
+
code: "SOURCE_CAPABILITIES_FAILED",
|
|
14844
|
+
message: `Relay source discovery failed.`,
|
|
14845
|
+
retryable: true,
|
|
14846
|
+
remediation: `Retry peer.sell.sourceCapabilities() shortly, or sell Base USDC directly.`
|
|
14847
|
+
},
|
|
14848
|
+
{ cause }
|
|
14849
|
+
),
|
|
14850
|
+
sourceQuoteFailed: (cause) => new PeerError(
|
|
14851
|
+
{
|
|
14852
|
+
code: "SOURCE_QUOTE_FAILED",
|
|
14853
|
+
message: `Relay did not return a valid route to canonical Base USDC.`,
|
|
14854
|
+
retryable: true,
|
|
14855
|
+
remediation: `Refresh source capabilities and call peer.sell.quoteSource() again. Do not submit transactions from this response.`
|
|
14856
|
+
},
|
|
14857
|
+
{ cause }
|
|
14858
|
+
),
|
|
14859
|
+
sourceStatusFailed: (requestId, cause) => new PeerError(
|
|
14860
|
+
{
|
|
14861
|
+
code: "SOURCE_STATUS_FAILED",
|
|
14862
|
+
message: `Relay status is unavailable for route ${requestId}.`,
|
|
14863
|
+
retryable: true,
|
|
14864
|
+
remediation: `Retry peer.sell.relayStatus() shortly; keep the route identifier and transaction hashes for recovery.`
|
|
14865
|
+
},
|
|
14866
|
+
{ cause }
|
|
14867
|
+
),
|
|
14841
14868
|
payeeVerificationRequired: (platform, cause) => new PeerError(
|
|
14842
14869
|
{
|
|
14843
14870
|
code: "PAYEE_VERIFICATION_REQUIRED",
|
|
@@ -16217,6 +16244,313 @@ function createSellAttributionReader(options) {
|
|
|
16217
16244
|
return (depositIds) => readSellAttributedDepositIds(client, depositIds);
|
|
16218
16245
|
}
|
|
16219
16246
|
|
|
16247
|
+
// src/peer/sell/relay.ts
|
|
16248
|
+
var RELAY_API_URL = "https://api.relay.link";
|
|
16249
|
+
var RELAY_API_ORIGINS = /* @__PURE__ */ new Set([RELAY_API_URL, "https://api.testnets.relay.link"]);
|
|
16250
|
+
var NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
16251
|
+
var BASE_USDC_ASSET = {
|
|
16252
|
+
chainId: BASE_CHAIN_ID,
|
|
16253
|
+
address: BASE_USDC_ADDRESS,
|
|
16254
|
+
symbol: "USDC",
|
|
16255
|
+
decimals: USDC_DECIMALS,
|
|
16256
|
+
name: "USD Coin"
|
|
16257
|
+
};
|
|
16258
|
+
function resolveRelay(options) {
|
|
16259
|
+
const apiUrl = options.apiUrl ?? RELAY_API_URL;
|
|
16260
|
+
const keyed = options.apiKey && RELAY_API_ORIGINS.has(new URL(apiUrl).origin);
|
|
16261
|
+
return {
|
|
16262
|
+
apiUrl,
|
|
16263
|
+
source: options.source ?? "peer-cash",
|
|
16264
|
+
headers: keyed ? { "x-api-key": options.apiKey } : {},
|
|
16265
|
+
fetch: options.fetch ?? fetch
|
|
16266
|
+
};
|
|
16267
|
+
}
|
|
16268
|
+
async function relayJson(relay, url, init = {}) {
|
|
16269
|
+
const response = await relay.fetch(url, init);
|
|
16270
|
+
if (!response.ok) {
|
|
16271
|
+
throw new Error(
|
|
16272
|
+
`Relay ${init.method ?? "GET"} ${new URL(url).pathname} answered ${response.status}`
|
|
16273
|
+
);
|
|
16274
|
+
}
|
|
16275
|
+
return response.json();
|
|
16276
|
+
}
|
|
16277
|
+
function asRecord2(value) {
|
|
16278
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
16279
|
+
}
|
|
16280
|
+
function asString(value) {
|
|
16281
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
16282
|
+
}
|
|
16283
|
+
function asNumber(value) {
|
|
16284
|
+
const n = Number(value);
|
|
16285
|
+
return Number.isFinite(n) ? n : void 0;
|
|
16286
|
+
}
|
|
16287
|
+
function normalizeToken(chainId, token) {
|
|
16288
|
+
const row = asRecord2(token);
|
|
16289
|
+
const address3 = asString(row.address);
|
|
16290
|
+
const symbol = asString(row.symbol);
|
|
16291
|
+
const decimals = asNumber(row.decimals);
|
|
16292
|
+
const name = asString(row.name);
|
|
16293
|
+
if (!address3 || !symbol || decimals === void 0) {
|
|
16294
|
+
return null;
|
|
16295
|
+
}
|
|
16296
|
+
const metadata = asRecord2(row.metadata);
|
|
16297
|
+
return {
|
|
16298
|
+
chainId,
|
|
16299
|
+
address: address3,
|
|
16300
|
+
symbol,
|
|
16301
|
+
decimals,
|
|
16302
|
+
...name ? { name } : {},
|
|
16303
|
+
...metadata.isNative === true || address3.toLowerCase() === NATIVE_TOKEN_ADDRESS ? { isNative: true } : {}
|
|
16304
|
+
};
|
|
16305
|
+
}
|
|
16306
|
+
function normalizeTx(data3, chainId) {
|
|
16307
|
+
const row = asRecord2(data3);
|
|
16308
|
+
const to = asString(row.to);
|
|
16309
|
+
const calldata = asString(row.data) ?? "0x";
|
|
16310
|
+
if (!to) {
|
|
16311
|
+
return null;
|
|
16312
|
+
}
|
|
16313
|
+
return {
|
|
16314
|
+
to,
|
|
16315
|
+
data: calldata,
|
|
16316
|
+
value: BigInt(String(row.value ?? "0")),
|
|
16317
|
+
chainId: asNumber(row.chainId) ?? chainId
|
|
16318
|
+
};
|
|
16319
|
+
}
|
|
16320
|
+
function normalizeChain(chain) {
|
|
16321
|
+
const row = asRecord2(chain);
|
|
16322
|
+
const tokenRows = [
|
|
16323
|
+
chain.currency,
|
|
16324
|
+
...chain.featuredTokens ?? [],
|
|
16325
|
+
...chain.erc20Currencies ?? [],
|
|
16326
|
+
...chain.solverCurrencies ?? []
|
|
16327
|
+
];
|
|
16328
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
16329
|
+
for (const token of tokenRows) {
|
|
16330
|
+
const normalizedToken = normalizeToken(chain.id, token);
|
|
16331
|
+
if (normalizedToken) {
|
|
16332
|
+
tokens.set(normalizedToken.address.toLowerCase(), normalizedToken);
|
|
16333
|
+
}
|
|
16334
|
+
}
|
|
16335
|
+
return {
|
|
16336
|
+
id: chain.id,
|
|
16337
|
+
name: chain.name,
|
|
16338
|
+
displayName: chain.displayName,
|
|
16339
|
+
disabled: row.disabled === true,
|
|
16340
|
+
depositEnabled: chain.depositEnabled ?? false,
|
|
16341
|
+
blockProductionLagging: chain.blockProductionLagging ?? false,
|
|
16342
|
+
...chain.vmType ? { vmType: chain.vmType } : {},
|
|
16343
|
+
tokens: [...tokens.values()].sort((a, b) => a.symbol.localeCompare(b.symbol))
|
|
16344
|
+
};
|
|
16345
|
+
}
|
|
16346
|
+
function isSupportedEvmChain(chain) {
|
|
16347
|
+
return chain.vmType === void 0 || chain.vmType === "evm";
|
|
16348
|
+
}
|
|
16349
|
+
function isExecutableSourceChain(chain) {
|
|
16350
|
+
return isSupportedEvmChain(chain) && !chain.disabled && chain.depositEnabled && !chain.blockProductionLagging;
|
|
16351
|
+
}
|
|
16352
|
+
function quoteRequestId(quote) {
|
|
16353
|
+
return quote.steps.map((step) => step.requestId).find((id) => id !== void 0);
|
|
16354
|
+
}
|
|
16355
|
+
function isRelaySecretKey(key) {
|
|
16356
|
+
const normalized = key.toLowerCase();
|
|
16357
|
+
return normalized === "headers" || normalized === "apikey";
|
|
16358
|
+
}
|
|
16359
|
+
function redactRelayValue(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
16360
|
+
if (value === null || typeof value !== "object") {
|
|
16361
|
+
return value;
|
|
16362
|
+
}
|
|
16363
|
+
if (value instanceof Date || value instanceof Error) {
|
|
16364
|
+
return value;
|
|
16365
|
+
}
|
|
16366
|
+
const existing = seen.get(value);
|
|
16367
|
+
if (existing !== void 0) {
|
|
16368
|
+
return existing;
|
|
16369
|
+
}
|
|
16370
|
+
if (Array.isArray(value)) {
|
|
16371
|
+
const output2 = [];
|
|
16372
|
+
seen.set(value, output2);
|
|
16373
|
+
for (const entry of value) {
|
|
16374
|
+
output2.push(redactRelayValue(entry, seen));
|
|
16375
|
+
}
|
|
16376
|
+
return output2;
|
|
16377
|
+
}
|
|
16378
|
+
const output = {};
|
|
16379
|
+
seen.set(value, output);
|
|
16380
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
16381
|
+
if (!isRelaySecretKey(key)) {
|
|
16382
|
+
output[key] = redactRelayValue(entry, seen);
|
|
16383
|
+
}
|
|
16384
|
+
}
|
|
16385
|
+
return output;
|
|
16386
|
+
}
|
|
16387
|
+
function redactRelayQuoteRaw(quote) {
|
|
16388
|
+
return redactRelayValue(quote);
|
|
16389
|
+
}
|
|
16390
|
+
async function resolveRelayChains(options, relay) {
|
|
16391
|
+
if (options.chains) {
|
|
16392
|
+
return options.chains;
|
|
16393
|
+
}
|
|
16394
|
+
const query = new URLSearchParams({ referrer: relay.source });
|
|
16395
|
+
const body = asRecord2(
|
|
16396
|
+
await relayJson(relay, `${relay.apiUrl}/chains?${query.toString()}`, {
|
|
16397
|
+
headers: relay.headers
|
|
16398
|
+
})
|
|
16399
|
+
);
|
|
16400
|
+
if (!Array.isArray(body.chains)) {
|
|
16401
|
+
throw new Error("Relay returned no chain data");
|
|
16402
|
+
}
|
|
16403
|
+
return body.chains;
|
|
16404
|
+
}
|
|
16405
|
+
function relayQuoteFromResponse(input, quote) {
|
|
16406
|
+
const details = asRecord2(quote.details);
|
|
16407
|
+
const currencyIn = asRecord2(details.currencyIn);
|
|
16408
|
+
const currencyOut = asRecord2(details.currencyOut);
|
|
16409
|
+
const sourceCurrency = asRecord2(currencyIn.currency);
|
|
16410
|
+
const destinationCurrency = asRecord2(currencyOut.currency);
|
|
16411
|
+
const sourceChainId = asNumber(sourceCurrency.chainId);
|
|
16412
|
+
const sourceAddress = asString(sourceCurrency.address);
|
|
16413
|
+
const sender = asString(details.sender);
|
|
16414
|
+
const recipient = asString(details.recipient);
|
|
16415
|
+
const expectedRecipient = input.recipient ?? input.user;
|
|
16416
|
+
const destinationChainId = asNumber(destinationCurrency.chainId);
|
|
16417
|
+
const destinationAddress = asString(destinationCurrency.address);
|
|
16418
|
+
if (sourceChainId !== input.source.chainId || sourceAddress?.toLowerCase() !== input.source.currency.toLowerCase()) {
|
|
16419
|
+
throw new Error("Relay quote source does not match the requested asset");
|
|
16420
|
+
}
|
|
16421
|
+
if (!sender || sender.toLowerCase() !== input.user.toLowerCase()) {
|
|
16422
|
+
throw new Error("Relay quote sender does not match the requested wallet");
|
|
16423
|
+
}
|
|
16424
|
+
if (!recipient || recipient.toLowerCase() !== expectedRecipient.toLowerCase()) {
|
|
16425
|
+
throw new Error("Relay quote recipient does not match the requested Base recipient");
|
|
16426
|
+
}
|
|
16427
|
+
if (destinationChainId !== BASE_CHAIN_ID || destinationAddress?.toLowerCase() !== BASE_USDC_ADDRESS.toLowerCase()) {
|
|
16428
|
+
throw new Error("Relay quote destination is not canonical Base USDC");
|
|
16429
|
+
}
|
|
16430
|
+
const source = normalizeToken(input.source.chainId, sourceCurrency);
|
|
16431
|
+
if (!source) {
|
|
16432
|
+
throw new Error("Relay quote source metadata is malformed");
|
|
16433
|
+
}
|
|
16434
|
+
const destination = normalizeToken(destinationChainId, destinationCurrency);
|
|
16435
|
+
if (!destination) {
|
|
16436
|
+
throw new Error("Relay quote destination metadata is malformed");
|
|
16437
|
+
}
|
|
16438
|
+
const txs = quote.steps.flatMap(
|
|
16439
|
+
(step) => step.items.map((item) => normalizeTx(item.data, input.source.chainId)).filter((tx) => tx !== null)
|
|
16440
|
+
);
|
|
16441
|
+
const rawOutputAmount = currencyOut.minimumAmount ?? currencyOut.amount;
|
|
16442
|
+
if (rawOutputAmount === void 0 || rawOutputAmount === null) {
|
|
16443
|
+
throw new Error("Relay quote is missing an output amount");
|
|
16444
|
+
}
|
|
16445
|
+
const outputAmount = BigInt(String(rawOutputAmount));
|
|
16446
|
+
if (outputAmount <= 0n) {
|
|
16447
|
+
throw new Error("Relay quote output amount must be positive");
|
|
16448
|
+
}
|
|
16449
|
+
const requestId = quoteRequestId(quote);
|
|
16450
|
+
const rate = asNumber(details.rate);
|
|
16451
|
+
const timeEstimateSeconds = asNumber(details.timeEstimate);
|
|
16452
|
+
return {
|
|
16453
|
+
...requestId ? { requestId } : {},
|
|
16454
|
+
source,
|
|
16455
|
+
destination,
|
|
16456
|
+
inputAmount: BigInt(String(currencyIn.amount)),
|
|
16457
|
+
outputAmount,
|
|
16458
|
+
...rate !== void 0 ? { rate } : {},
|
|
16459
|
+
...timeEstimateSeconds !== void 0 ? { timeEstimateSeconds } : {},
|
|
16460
|
+
...quote.fees !== void 0 ? { fees: quote.fees } : {},
|
|
16461
|
+
txs,
|
|
16462
|
+
raw: redactRelayQuoteRaw(quote)
|
|
16463
|
+
};
|
|
16464
|
+
}
|
|
16465
|
+
async function readRelaySourceCapabilities(options = {}) {
|
|
16466
|
+
try {
|
|
16467
|
+
const chains = await resolveRelayChains(options, resolveRelay(options));
|
|
16468
|
+
return {
|
|
16469
|
+
destination: BASE_USDC_ASSET,
|
|
16470
|
+
chains: chains.map(normalizeChain).filter((chain) => chain.tokens.length > 0 && isExecutableSourceChain(chain)).sort((a, b) => a.displayName.localeCompare(b.displayName)),
|
|
16471
|
+
source: "relay",
|
|
16472
|
+
asOf: Math.floor(Date.now() / 1e3)
|
|
16473
|
+
};
|
|
16474
|
+
} catch (err) {
|
|
16475
|
+
if (isPeerError(err)) {
|
|
16476
|
+
throw err;
|
|
16477
|
+
}
|
|
16478
|
+
throw errors.sourceCapabilitiesFailed(err);
|
|
16479
|
+
}
|
|
16480
|
+
}
|
|
16481
|
+
async function quoteRelayToBaseUsdc(input, options = {}) {
|
|
16482
|
+
try {
|
|
16483
|
+
if (input.amount <= 0n) {
|
|
16484
|
+
throw new Error("Relay quote amount must be positive");
|
|
16485
|
+
}
|
|
16486
|
+
const relay = resolveRelay(options);
|
|
16487
|
+
const request = {
|
|
16488
|
+
url: `${relay.apiUrl}/quote/v2`,
|
|
16489
|
+
method: "post",
|
|
16490
|
+
data: {
|
|
16491
|
+
user: input.user,
|
|
16492
|
+
destinationCurrency: BASE_USDC_ADDRESS,
|
|
16493
|
+
destinationChainId: BASE_CHAIN_ID,
|
|
16494
|
+
originCurrency: input.source.currency,
|
|
16495
|
+
originChainId: input.source.chainId,
|
|
16496
|
+
amount: input.amount.toString(),
|
|
16497
|
+
recipient: input.recipient ?? input.user,
|
|
16498
|
+
tradeType: input.tradeType ?? "EXACT_INPUT",
|
|
16499
|
+
referrer: relay.source
|
|
16500
|
+
}
|
|
16501
|
+
};
|
|
16502
|
+
const body = await relayJson(relay, request.url, {
|
|
16503
|
+
method: "POST",
|
|
16504
|
+
headers: { "content-type": "application/json", ...relay.headers },
|
|
16505
|
+
body: JSON.stringify(request.data)
|
|
16506
|
+
});
|
|
16507
|
+
const quote = asRecord2(body);
|
|
16508
|
+
if (!Array.isArray(quote.steps)) {
|
|
16509
|
+
throw new Error("Relay quote has no steps");
|
|
16510
|
+
}
|
|
16511
|
+
return relayQuoteFromResponse(input, { ...quote, request });
|
|
16512
|
+
} catch (err) {
|
|
16513
|
+
if (isPeerError(err)) {
|
|
16514
|
+
throw err;
|
|
16515
|
+
}
|
|
16516
|
+
throw errors.sourceQuoteFailed(err);
|
|
16517
|
+
}
|
|
16518
|
+
}
|
|
16519
|
+
async function readRelayStatus(requestId, options = {}) {
|
|
16520
|
+
try {
|
|
16521
|
+
const relay = resolveRelay(options);
|
|
16522
|
+
const query = new URLSearchParams({ requestId });
|
|
16523
|
+
const data3 = await relayJson(relay, `${relay.apiUrl}/intents/status/v3?${query.toString()}`);
|
|
16524
|
+
const root = asRecord2(data3);
|
|
16525
|
+
const status = asString(root.status);
|
|
16526
|
+
if (status !== "refund" && status !== "waiting" && status !== "depositing" && status !== "failure" && status !== "pending" && status !== "submitted" && status !== "success") {
|
|
16527
|
+
throw new Error(`Relay returned unknown status: ${String(root.status)}`);
|
|
16528
|
+
}
|
|
16529
|
+
const details = asString(root.details);
|
|
16530
|
+
const updatedAt = asNumber(root.updatedAt);
|
|
16531
|
+
const originChainId = asNumber(root.originChainId);
|
|
16532
|
+
const destinationChainId = asNumber(root.destinationChainId);
|
|
16533
|
+
const quoteCreatedAt = asNumber(root.quoteCreatedAt);
|
|
16534
|
+
return {
|
|
16535
|
+
requestId,
|
|
16536
|
+
status,
|
|
16537
|
+
...details ? { details } : {},
|
|
16538
|
+
inTxHashes: Array.isArray(root.inTxHashes) ? root.inTxHashes.map(String) : [],
|
|
16539
|
+
txHashes: Array.isArray(root.txHashes) ? root.txHashes.map(String) : [],
|
|
16540
|
+
...updatedAt !== void 0 ? { updatedAt } : {},
|
|
16541
|
+
...originChainId !== void 0 ? { originChainId } : {},
|
|
16542
|
+
...destinationChainId !== void 0 ? { destinationChainId } : {},
|
|
16543
|
+
...quoteCreatedAt !== void 0 ? { quoteCreatedAt } : {},
|
|
16544
|
+
raw: data3
|
|
16545
|
+
};
|
|
16546
|
+
} catch (err) {
|
|
16547
|
+
if (isPeerError(err)) {
|
|
16548
|
+
throw err;
|
|
16549
|
+
}
|
|
16550
|
+
throw errors.sourceStatusFailed(requestId, err);
|
|
16551
|
+
}
|
|
16552
|
+
}
|
|
16553
|
+
|
|
16220
16554
|
// src/peer/sell/classify.ts
|
|
16221
16555
|
function isSellPayoutSet(payouts, attributedToSell = false) {
|
|
16222
16556
|
return payouts.length > 0 && payouts.every(
|
|
@@ -16700,6 +17034,9 @@ function createPeerSell(context) {
|
|
|
16700
17034
|
};
|
|
16701
17035
|
},
|
|
16702
17036
|
capabilities: () => buildCapabilities(environment),
|
|
17037
|
+
sourceCapabilities: () => readRelaySourceCapabilities(options.relay),
|
|
17038
|
+
quoteSource: (input) => quoteRelayToBaseUsdc(input, options.relay),
|
|
17039
|
+
relayStatus: (requestId) => readRelayStatus(requestId, options.relay),
|
|
16703
17040
|
estimate(input, estimateOptions) {
|
|
16704
17041
|
return readEstimate(readClient.publicClient, input, {
|
|
16705
17042
|
environment,
|