@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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// <define:__ZKP2P_SDK_BUILD_METADATA__>
|
|
8
|
+
var define_ZKP2P_SDK_BUILD_METADATA_default = { schemaVersion: 2, source: { repository: "zkp2p/zkp2p-clients", commitSha: "6318324893695eb4d5904438fb4c85cde4397a09", kind: "github", distributable: true }, sdkPackageVersion: "0.16.0", contractsPackageVersion: "0.4.4-rc.13", indexerSchemaPackageVersion: "0.23.0-rc.0", activeDisputeStack: { base: { version: 2, selectionHash: "ba40c2954b408d0c658881a8d28e5bfcc9bade5cc3d953fd17eae1eca69d841c" }, baseStaging: { version: 2, selectionHash: "6c49c1ce51eec594a22385c4efcab08aa9926b6b63a725e14a0027ec5d2f4fc9" } } };
|
|
9
|
+
|
|
10
|
+
export { __export, define_ZKP2P_SDK_BUILD_METADATA_default };
|
|
11
|
+
//# sourceMappingURL=chunk-LBUSUTNI.mjs.map
|
|
12
|
+
//# sourceMappingURL=chunk-LBUSUTNI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["%3Cdefine:__ZKP2P_SDK_BUILD_METADATA__%3E"],"names":[],"mappings":";;;;;;;AAAA,IAAA,uCAAA,GAAA,EAAC,aAAA,EAAgB,CAAA,EAAE,MAAA,EAAS,EAAC,YAAa,qBAAA,EAAsB,SAAA,EAAY,0CAAA,EAA2C,IAAA,EAAO,UAAS,aAAA,EAAgB,IAAA,EAAI,EAAE,iBAAA,EAAoB,UAAS,uBAAA,EAA0B,aAAA,EAAc,2BAAA,EAA8B,aAAA,EAAc,oBAAqB,EAAC,IAAA,EAAO,EAAC,OAAA,EAAU,GAAE,aAAA,EAAgB,kEAAA,EAAkE,EAAE,WAAA,EAAc,EAAC,OAAA,EAAU,CAAA,EAAE,aAAA,EAAgB,kEAAA,IAAmE","file":"chunk-LBUSUTNI.mjs","sourcesContent":["{\"schemaVersion\":2,\"source\":{\"repository\":\"zkp2p/zkp2p-clients\",\"commitSha\":\"6318324893695eb4d5904438fb4c85cde4397a09\",\"kind\":\"github\",\"distributable\":true},\"sdkPackageVersion\":\"0.16.0\",\"contractsPackageVersion\":\"0.4.4-rc.13\",\"indexerSchemaPackageVersion\":\"0.23.0-rc.0\",\"activeDisputeStack\":{\"base\":{\"version\":2,\"selectionHash\":\"ba40c2954b408d0c658881a8d28e5bfcc9bade5cc3d953fd17eae1eca69d841c\"},\"baseStaging\":{\"version\":2,\"selectionHash\":\"6c49c1ce51eec594a22385c4efcab08aa9926b6b63a725e14a0027ec5d2f4fc9\"}}}"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Currency, currencyInfo, getCurrencyCodeFromHash, getCurrencyInfoFromCountryCode, getCurrencyInfoFromHash, isSupportedCurrencyHash, mapConversionRatesToOnchain, mapConversionRatesToOnchainMinRate } from './chunk-PMFXZGDQ.mjs';
|
|
2
|
-
import './chunk-
|
|
3
|
-
//# sourceMappingURL=currency-
|
|
4
|
-
//# sourceMappingURL=currency-
|
|
2
|
+
import './chunk-LBUSUTNI.mjs';
|
|
3
|
+
//# sourceMappingURL=currency-6EFHONXS.mjs.map
|
|
4
|
+
//# sourceMappingURL=currency-6EFHONXS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"currency-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"currency-6EFHONXS.mjs"}
|
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,7 @@ var __export = (target, all) => {
|
|
|
21
21
|
var define_ZKP2P_SDK_BUILD_METADATA_default;
|
|
22
22
|
var init_define_ZKP2P_SDK_BUILD_METADATA = __esm({
|
|
23
23
|
"<define:__ZKP2P_SDK_BUILD_METADATA__>"() {
|
|
24
|
-
define_ZKP2P_SDK_BUILD_METADATA_default = { schemaVersion: 2, source: { repository: "zkp2p/zkp2p-clients", commitSha: "
|
|
24
|
+
define_ZKP2P_SDK_BUILD_METADATA_default = { schemaVersion: 2, source: { repository: "zkp2p/zkp2p-clients", commitSha: "6318324893695eb4d5904438fb4c85cde4397a09", kind: "github", distributable: true }, sdkPackageVersion: "0.16.0", contractsPackageVersion: "0.4.4-rc.13", indexerSchemaPackageVersion: "0.23.0-rc.0", activeDisputeStack: { base: { version: 2, selectionHash: "ba40c2954b408d0c658881a8d28e5bfcc9bade5cc3d953fd17eae1eca69d841c" }, baseStaging: { version: 2, selectionHash: "6c49c1ce51eec594a22385c4efcab08aa9926b6b63a725e14a0027ec5d2f4fc9" } } };
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -175081,6 +175081,33 @@ var errors = {
|
|
|
175081
175081
|
},
|
|
175082
175082
|
{ cause }
|
|
175083
175083
|
),
|
|
175084
|
+
sourceCapabilitiesFailed: (cause) => new PeerError(
|
|
175085
|
+
{
|
|
175086
|
+
code: "SOURCE_CAPABILITIES_FAILED",
|
|
175087
|
+
message: `Relay source discovery failed.`,
|
|
175088
|
+
retryable: true,
|
|
175089
|
+
remediation: `Retry peer.sell.sourceCapabilities() shortly, or sell Base USDC directly.`
|
|
175090
|
+
},
|
|
175091
|
+
{ cause }
|
|
175092
|
+
),
|
|
175093
|
+
sourceQuoteFailed: (cause) => new PeerError(
|
|
175094
|
+
{
|
|
175095
|
+
code: "SOURCE_QUOTE_FAILED",
|
|
175096
|
+
message: `Relay did not return a valid route to canonical Base USDC.`,
|
|
175097
|
+
retryable: true,
|
|
175098
|
+
remediation: `Refresh source capabilities and call peer.sell.quoteSource() again. Do not submit transactions from this response.`
|
|
175099
|
+
},
|
|
175100
|
+
{ cause }
|
|
175101
|
+
),
|
|
175102
|
+
sourceStatusFailed: (requestId, cause) => new PeerError(
|
|
175103
|
+
{
|
|
175104
|
+
code: "SOURCE_STATUS_FAILED",
|
|
175105
|
+
message: `Relay status is unavailable for route ${requestId}.`,
|
|
175106
|
+
retryable: true,
|
|
175107
|
+
remediation: `Retry peer.sell.relayStatus() shortly; keep the route identifier and transaction hashes for recovery.`
|
|
175108
|
+
},
|
|
175109
|
+
{ cause }
|
|
175110
|
+
),
|
|
175084
175111
|
payeeVerificationRequired: (platform, cause) => new PeerError(
|
|
175085
175112
|
{
|
|
175086
175113
|
code: "PAYEE_VERIFICATION_REQUIRED",
|
|
@@ -176498,6 +176525,314 @@ function createSellAttributionReader(options) {
|
|
|
176498
176525
|
return (depositIds) => readSellAttributedDepositIds(client, depositIds);
|
|
176499
176526
|
}
|
|
176500
176527
|
|
|
176528
|
+
// src/peer/sell/relay.ts
|
|
176529
|
+
init_define_ZKP2P_SDK_BUILD_METADATA();
|
|
176530
|
+
var RELAY_API_URL = "https://api.relay.link";
|
|
176531
|
+
var RELAY_API_ORIGINS = /* @__PURE__ */ new Set([RELAY_API_URL, "https://api.testnets.relay.link"]);
|
|
176532
|
+
var NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
176533
|
+
var BASE_USDC_ASSET = {
|
|
176534
|
+
chainId: BASE_CHAIN_ID,
|
|
176535
|
+
address: BASE_USDC_ADDRESS,
|
|
176536
|
+
symbol: "USDC",
|
|
176537
|
+
decimals: USDC_DECIMALS,
|
|
176538
|
+
name: "USD Coin"
|
|
176539
|
+
};
|
|
176540
|
+
function resolveRelay(options) {
|
|
176541
|
+
const apiUrl = options.apiUrl ?? RELAY_API_URL;
|
|
176542
|
+
const keyed = options.apiKey && RELAY_API_ORIGINS.has(new URL(apiUrl).origin);
|
|
176543
|
+
return {
|
|
176544
|
+
apiUrl,
|
|
176545
|
+
source: options.source ?? "peer-cash",
|
|
176546
|
+
headers: keyed ? { "x-api-key": options.apiKey } : {},
|
|
176547
|
+
fetch: options.fetch ?? fetch
|
|
176548
|
+
};
|
|
176549
|
+
}
|
|
176550
|
+
async function relayJson(relay, url, init = {}) {
|
|
176551
|
+
const response = await relay.fetch(url, init);
|
|
176552
|
+
if (!response.ok) {
|
|
176553
|
+
throw new Error(
|
|
176554
|
+
`Relay ${init.method ?? "GET"} ${new URL(url).pathname} answered ${response.status}`
|
|
176555
|
+
);
|
|
176556
|
+
}
|
|
176557
|
+
return response.json();
|
|
176558
|
+
}
|
|
176559
|
+
function asRecord2(value) {
|
|
176560
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
176561
|
+
}
|
|
176562
|
+
function asString(value) {
|
|
176563
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
176564
|
+
}
|
|
176565
|
+
function asNumber(value) {
|
|
176566
|
+
const n = Number(value);
|
|
176567
|
+
return Number.isFinite(n) ? n : void 0;
|
|
176568
|
+
}
|
|
176569
|
+
function normalizeToken(chainId, token) {
|
|
176570
|
+
const row = asRecord2(token);
|
|
176571
|
+
const address3 = asString(row.address);
|
|
176572
|
+
const symbol = asString(row.symbol);
|
|
176573
|
+
const decimals = asNumber(row.decimals);
|
|
176574
|
+
const name = asString(row.name);
|
|
176575
|
+
if (!address3 || !symbol || decimals === void 0) {
|
|
176576
|
+
return null;
|
|
176577
|
+
}
|
|
176578
|
+
const metadata = asRecord2(row.metadata);
|
|
176579
|
+
return {
|
|
176580
|
+
chainId,
|
|
176581
|
+
address: address3,
|
|
176582
|
+
symbol,
|
|
176583
|
+
decimals,
|
|
176584
|
+
...name ? { name } : {},
|
|
176585
|
+
...metadata.isNative === true || address3.toLowerCase() === NATIVE_TOKEN_ADDRESS ? { isNative: true } : {}
|
|
176586
|
+
};
|
|
176587
|
+
}
|
|
176588
|
+
function normalizeTx(data212, chainId) {
|
|
176589
|
+
const row = asRecord2(data212);
|
|
176590
|
+
const to = asString(row.to);
|
|
176591
|
+
const calldata = asString(row.data) ?? "0x";
|
|
176592
|
+
if (!to) {
|
|
176593
|
+
return null;
|
|
176594
|
+
}
|
|
176595
|
+
return {
|
|
176596
|
+
to,
|
|
176597
|
+
data: calldata,
|
|
176598
|
+
value: BigInt(String(row.value ?? "0")),
|
|
176599
|
+
chainId: asNumber(row.chainId) ?? chainId
|
|
176600
|
+
};
|
|
176601
|
+
}
|
|
176602
|
+
function normalizeChain(chain) {
|
|
176603
|
+
const row = asRecord2(chain);
|
|
176604
|
+
const tokenRows = [
|
|
176605
|
+
chain.currency,
|
|
176606
|
+
...chain.featuredTokens ?? [],
|
|
176607
|
+
...chain.erc20Currencies ?? [],
|
|
176608
|
+
...chain.solverCurrencies ?? []
|
|
176609
|
+
];
|
|
176610
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
176611
|
+
for (const token of tokenRows) {
|
|
176612
|
+
const normalizedToken = normalizeToken(chain.id, token);
|
|
176613
|
+
if (normalizedToken) {
|
|
176614
|
+
tokens.set(normalizedToken.address.toLowerCase(), normalizedToken);
|
|
176615
|
+
}
|
|
176616
|
+
}
|
|
176617
|
+
return {
|
|
176618
|
+
id: chain.id,
|
|
176619
|
+
name: chain.name,
|
|
176620
|
+
displayName: chain.displayName,
|
|
176621
|
+
disabled: row.disabled === true,
|
|
176622
|
+
depositEnabled: chain.depositEnabled ?? false,
|
|
176623
|
+
blockProductionLagging: chain.blockProductionLagging ?? false,
|
|
176624
|
+
...chain.vmType ? { vmType: chain.vmType } : {},
|
|
176625
|
+
tokens: [...tokens.values()].sort((a, b) => a.symbol.localeCompare(b.symbol))
|
|
176626
|
+
};
|
|
176627
|
+
}
|
|
176628
|
+
function isSupportedEvmChain(chain) {
|
|
176629
|
+
return chain.vmType === void 0 || chain.vmType === "evm";
|
|
176630
|
+
}
|
|
176631
|
+
function isExecutableSourceChain(chain) {
|
|
176632
|
+
return isSupportedEvmChain(chain) && !chain.disabled && chain.depositEnabled && !chain.blockProductionLagging;
|
|
176633
|
+
}
|
|
176634
|
+
function quoteRequestId(quote) {
|
|
176635
|
+
return quote.steps.map((step) => step.requestId).find((id) => id !== void 0);
|
|
176636
|
+
}
|
|
176637
|
+
function isRelaySecretKey(key) {
|
|
176638
|
+
const normalized = key.toLowerCase();
|
|
176639
|
+
return normalized === "headers" || normalized === "apikey";
|
|
176640
|
+
}
|
|
176641
|
+
function redactRelayValue(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
176642
|
+
if (value === null || typeof value !== "object") {
|
|
176643
|
+
return value;
|
|
176644
|
+
}
|
|
176645
|
+
if (value instanceof Date || value instanceof Error) {
|
|
176646
|
+
return value;
|
|
176647
|
+
}
|
|
176648
|
+
const existing = seen.get(value);
|
|
176649
|
+
if (existing !== void 0) {
|
|
176650
|
+
return existing;
|
|
176651
|
+
}
|
|
176652
|
+
if (Array.isArray(value)) {
|
|
176653
|
+
const output2 = [];
|
|
176654
|
+
seen.set(value, output2);
|
|
176655
|
+
for (const entry of value) {
|
|
176656
|
+
output2.push(redactRelayValue(entry, seen));
|
|
176657
|
+
}
|
|
176658
|
+
return output2;
|
|
176659
|
+
}
|
|
176660
|
+
const output = {};
|
|
176661
|
+
seen.set(value, output);
|
|
176662
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
176663
|
+
if (!isRelaySecretKey(key)) {
|
|
176664
|
+
output[key] = redactRelayValue(entry, seen);
|
|
176665
|
+
}
|
|
176666
|
+
}
|
|
176667
|
+
return output;
|
|
176668
|
+
}
|
|
176669
|
+
function redactRelayQuoteRaw(quote) {
|
|
176670
|
+
return redactRelayValue(quote);
|
|
176671
|
+
}
|
|
176672
|
+
async function resolveRelayChains(options, relay) {
|
|
176673
|
+
if (options.chains) {
|
|
176674
|
+
return options.chains;
|
|
176675
|
+
}
|
|
176676
|
+
const query = new URLSearchParams({ referrer: relay.source });
|
|
176677
|
+
const body = asRecord2(
|
|
176678
|
+
await relayJson(relay, `${relay.apiUrl}/chains?${query.toString()}`, {
|
|
176679
|
+
headers: relay.headers
|
|
176680
|
+
})
|
|
176681
|
+
);
|
|
176682
|
+
if (!Array.isArray(body.chains)) {
|
|
176683
|
+
throw new Error("Relay returned no chain data");
|
|
176684
|
+
}
|
|
176685
|
+
return body.chains;
|
|
176686
|
+
}
|
|
176687
|
+
function relayQuoteFromResponse(input, quote) {
|
|
176688
|
+
const details = asRecord2(quote.details);
|
|
176689
|
+
const currencyIn = asRecord2(details.currencyIn);
|
|
176690
|
+
const currencyOut = asRecord2(details.currencyOut);
|
|
176691
|
+
const sourceCurrency = asRecord2(currencyIn.currency);
|
|
176692
|
+
const destinationCurrency = asRecord2(currencyOut.currency);
|
|
176693
|
+
const sourceChainId = asNumber(sourceCurrency.chainId);
|
|
176694
|
+
const sourceAddress = asString(sourceCurrency.address);
|
|
176695
|
+
const sender = asString(details.sender);
|
|
176696
|
+
const recipient = asString(details.recipient);
|
|
176697
|
+
const expectedRecipient = input.recipient ?? input.user;
|
|
176698
|
+
const destinationChainId = asNumber(destinationCurrency.chainId);
|
|
176699
|
+
const destinationAddress = asString(destinationCurrency.address);
|
|
176700
|
+
if (sourceChainId !== input.source.chainId || sourceAddress?.toLowerCase() !== input.source.currency.toLowerCase()) {
|
|
176701
|
+
throw new Error("Relay quote source does not match the requested asset");
|
|
176702
|
+
}
|
|
176703
|
+
if (!sender || sender.toLowerCase() !== input.user.toLowerCase()) {
|
|
176704
|
+
throw new Error("Relay quote sender does not match the requested wallet");
|
|
176705
|
+
}
|
|
176706
|
+
if (!recipient || recipient.toLowerCase() !== expectedRecipient.toLowerCase()) {
|
|
176707
|
+
throw new Error("Relay quote recipient does not match the requested Base recipient");
|
|
176708
|
+
}
|
|
176709
|
+
if (destinationChainId !== BASE_CHAIN_ID || destinationAddress?.toLowerCase() !== BASE_USDC_ADDRESS.toLowerCase()) {
|
|
176710
|
+
throw new Error("Relay quote destination is not canonical Base USDC");
|
|
176711
|
+
}
|
|
176712
|
+
const source = normalizeToken(input.source.chainId, sourceCurrency);
|
|
176713
|
+
if (!source) {
|
|
176714
|
+
throw new Error("Relay quote source metadata is malformed");
|
|
176715
|
+
}
|
|
176716
|
+
const destination = normalizeToken(destinationChainId, destinationCurrency);
|
|
176717
|
+
if (!destination) {
|
|
176718
|
+
throw new Error("Relay quote destination metadata is malformed");
|
|
176719
|
+
}
|
|
176720
|
+
const txs = quote.steps.flatMap(
|
|
176721
|
+
(step) => step.items.map((item) => normalizeTx(item.data, input.source.chainId)).filter((tx) => tx !== null)
|
|
176722
|
+
);
|
|
176723
|
+
const rawOutputAmount = currencyOut.minimumAmount ?? currencyOut.amount;
|
|
176724
|
+
if (rawOutputAmount === void 0 || rawOutputAmount === null) {
|
|
176725
|
+
throw new Error("Relay quote is missing an output amount");
|
|
176726
|
+
}
|
|
176727
|
+
const outputAmount = BigInt(String(rawOutputAmount));
|
|
176728
|
+
if (outputAmount <= 0n) {
|
|
176729
|
+
throw new Error("Relay quote output amount must be positive");
|
|
176730
|
+
}
|
|
176731
|
+
const requestId = quoteRequestId(quote);
|
|
176732
|
+
const rate = asNumber(details.rate);
|
|
176733
|
+
const timeEstimateSeconds = asNumber(details.timeEstimate);
|
|
176734
|
+
return {
|
|
176735
|
+
...requestId ? { requestId } : {},
|
|
176736
|
+
source,
|
|
176737
|
+
destination,
|
|
176738
|
+
inputAmount: BigInt(String(currencyIn.amount)),
|
|
176739
|
+
outputAmount,
|
|
176740
|
+
...rate !== void 0 ? { rate } : {},
|
|
176741
|
+
...timeEstimateSeconds !== void 0 ? { timeEstimateSeconds } : {},
|
|
176742
|
+
...quote.fees !== void 0 ? { fees: quote.fees } : {},
|
|
176743
|
+
txs,
|
|
176744
|
+
raw: redactRelayQuoteRaw(quote)
|
|
176745
|
+
};
|
|
176746
|
+
}
|
|
176747
|
+
async function readRelaySourceCapabilities(options = {}) {
|
|
176748
|
+
try {
|
|
176749
|
+
const chains = await resolveRelayChains(options, resolveRelay(options));
|
|
176750
|
+
return {
|
|
176751
|
+
destination: BASE_USDC_ASSET,
|
|
176752
|
+
chains: chains.map(normalizeChain).filter((chain) => chain.tokens.length > 0 && isExecutableSourceChain(chain)).sort((a, b) => a.displayName.localeCompare(b.displayName)),
|
|
176753
|
+
source: "relay",
|
|
176754
|
+
asOf: Math.floor(Date.now() / 1e3)
|
|
176755
|
+
};
|
|
176756
|
+
} catch (err) {
|
|
176757
|
+
if (isPeerError(err)) {
|
|
176758
|
+
throw err;
|
|
176759
|
+
}
|
|
176760
|
+
throw errors.sourceCapabilitiesFailed(err);
|
|
176761
|
+
}
|
|
176762
|
+
}
|
|
176763
|
+
async function quoteRelayToBaseUsdc(input, options = {}) {
|
|
176764
|
+
try {
|
|
176765
|
+
if (input.amount <= 0n) {
|
|
176766
|
+
throw new Error("Relay quote amount must be positive");
|
|
176767
|
+
}
|
|
176768
|
+
const relay = resolveRelay(options);
|
|
176769
|
+
const request = {
|
|
176770
|
+
url: `${relay.apiUrl}/quote/v2`,
|
|
176771
|
+
method: "post",
|
|
176772
|
+
data: {
|
|
176773
|
+
user: input.user,
|
|
176774
|
+
destinationCurrency: BASE_USDC_ADDRESS,
|
|
176775
|
+
destinationChainId: BASE_CHAIN_ID,
|
|
176776
|
+
originCurrency: input.source.currency,
|
|
176777
|
+
originChainId: input.source.chainId,
|
|
176778
|
+
amount: input.amount.toString(),
|
|
176779
|
+
recipient: input.recipient ?? input.user,
|
|
176780
|
+
tradeType: input.tradeType ?? "EXACT_INPUT",
|
|
176781
|
+
referrer: relay.source
|
|
176782
|
+
}
|
|
176783
|
+
};
|
|
176784
|
+
const body = await relayJson(relay, request.url, {
|
|
176785
|
+
method: "POST",
|
|
176786
|
+
headers: { "content-type": "application/json", ...relay.headers },
|
|
176787
|
+
body: JSON.stringify(request.data)
|
|
176788
|
+
});
|
|
176789
|
+
const quote = asRecord2(body);
|
|
176790
|
+
if (!Array.isArray(quote.steps)) {
|
|
176791
|
+
throw new Error("Relay quote has no steps");
|
|
176792
|
+
}
|
|
176793
|
+
return relayQuoteFromResponse(input, { ...quote, request });
|
|
176794
|
+
} catch (err) {
|
|
176795
|
+
if (isPeerError(err)) {
|
|
176796
|
+
throw err;
|
|
176797
|
+
}
|
|
176798
|
+
throw errors.sourceQuoteFailed(err);
|
|
176799
|
+
}
|
|
176800
|
+
}
|
|
176801
|
+
async function readRelayStatus(requestId, options = {}) {
|
|
176802
|
+
try {
|
|
176803
|
+
const relay = resolveRelay(options);
|
|
176804
|
+
const query = new URLSearchParams({ requestId });
|
|
176805
|
+
const data212 = await relayJson(relay, `${relay.apiUrl}/intents/status/v3?${query.toString()}`);
|
|
176806
|
+
const root = asRecord2(data212);
|
|
176807
|
+
const status = asString(root.status);
|
|
176808
|
+
if (status !== "refund" && status !== "waiting" && status !== "depositing" && status !== "failure" && status !== "pending" && status !== "submitted" && status !== "success") {
|
|
176809
|
+
throw new Error(`Relay returned unknown status: ${String(root.status)}`);
|
|
176810
|
+
}
|
|
176811
|
+
const details = asString(root.details);
|
|
176812
|
+
const updatedAt = asNumber(root.updatedAt);
|
|
176813
|
+
const originChainId = asNumber(root.originChainId);
|
|
176814
|
+
const destinationChainId = asNumber(root.destinationChainId);
|
|
176815
|
+
const quoteCreatedAt = asNumber(root.quoteCreatedAt);
|
|
176816
|
+
return {
|
|
176817
|
+
requestId,
|
|
176818
|
+
status,
|
|
176819
|
+
...details ? { details } : {},
|
|
176820
|
+
inTxHashes: Array.isArray(root.inTxHashes) ? root.inTxHashes.map(String) : [],
|
|
176821
|
+
txHashes: Array.isArray(root.txHashes) ? root.txHashes.map(String) : [],
|
|
176822
|
+
...updatedAt !== void 0 ? { updatedAt } : {},
|
|
176823
|
+
...originChainId !== void 0 ? { originChainId } : {},
|
|
176824
|
+
...destinationChainId !== void 0 ? { destinationChainId } : {},
|
|
176825
|
+
...quoteCreatedAt !== void 0 ? { quoteCreatedAt } : {},
|
|
176826
|
+
raw: data212
|
|
176827
|
+
};
|
|
176828
|
+
} catch (err) {
|
|
176829
|
+
if (isPeerError(err)) {
|
|
176830
|
+
throw err;
|
|
176831
|
+
}
|
|
176832
|
+
throw errors.sourceStatusFailed(requestId, err);
|
|
176833
|
+
}
|
|
176834
|
+
}
|
|
176835
|
+
|
|
176501
176836
|
// src/peer/sell/classify.ts
|
|
176502
176837
|
init_define_ZKP2P_SDK_BUILD_METADATA();
|
|
176503
176838
|
function isSellPayoutSet(payouts, attributedToSell = false) {
|
|
@@ -176982,6 +177317,9 @@ function createPeerSell(context) {
|
|
|
176982
177317
|
};
|
|
176983
177318
|
},
|
|
176984
177319
|
capabilities: () => buildCapabilities(environment),
|
|
177320
|
+
sourceCapabilities: () => readRelaySourceCapabilities(options.relay),
|
|
177321
|
+
quoteSource: (input) => quoteRelayToBaseUsdc(input, options.relay),
|
|
177322
|
+
relayStatus: (requestId) => readRelayStatus(requestId, options.relay),
|
|
176985
177323
|
estimate(input, estimateOptions) {
|
|
176986
177324
|
return readEstimate(readClient.publicClient, input, {
|
|
176987
177325
|
environment,
|