@anywalletkit/protocol-swap2-near-intents 0.2.1 → 0.3.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 +27 -0
- package/dist/{chunk-BXDRS5SZ.js → chunk-UGGBJUNL.js} +2 -2
- package/dist/{chunk-ZCU6YSV4.js → chunk-X3PXPHCB.js} +29 -8
- package/dist/chunk-X3PXPHCB.js.map +1 -0
- package/dist/index.cjs +27 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/protocol.cjs +27 -6
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +2 -2
- package/dist/provider.cjs +27 -6
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +12 -0
- package/dist/provider.d.ts +12 -0
- package/dist/provider.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-ZCU6YSV4.js.map +0 -1
- /package/dist/{chunk-BXDRS5SZ.js.map → chunk-UGGBJUNL.js.map} +0 -0
package/README.md
CHANGED
|
@@ -16,6 +16,33 @@ npm install @anywalletkit/protocol-swap2-near-intents @anywalletkit/core
|
|
|
16
16
|
|
|
17
17
|
On npm: [@anywalletkit/protocol-swap2-near-intents](https://www.npmjs.com/package/@anywalletkit/protocol-swap2-near-intents), published from the [release workflow](https://github.com/ultratestbro/anywalletkit/blob/main/RELEASING.md) with provenance.
|
|
18
18
|
|
|
19
|
+
## Credit a NEAR Intents (near.com) account
|
|
20
|
+
|
|
21
|
+
By default 1Click withdraws the output to `destAddress` on `destChain`. With `recipientType: "INTENTS"` it credits the
|
|
22
|
+
NEAR Intents account `destAddress` inside `intents.near` instead, the account a near.com user holds (`nearcom:0x…`
|
|
23
|
+
in near.com is the `0x…` account here). Nothing is withdrawn: the asset stays in that account as the intents token,
|
|
24
|
+
so `destChain` must be `near:mainnet` (another chain is refused, so a review never names a chain the output does not
|
|
25
|
+
reach) and `destToken` may be the token id itself, e.g. `nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near`
|
|
26
|
+
for Base USDC held in intents.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const toNearCom = nearIntentsProvider({recipientType: "INTENTS"});
|
|
30
|
+
await toNearCom.getQuote({
|
|
31
|
+
sourceChain: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", sourceToken: "USDC",
|
|
32
|
+
destChain: "near:mainnet", destToken: "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
|
|
33
|
+
destAddress: "0x63428e70a8016d10e8e2f7da440c898063afa299", amountIn: "5000000", refundAddress, dry: false,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
near.com keeps user funds in the Confidential Intents balance. `recipientType: "CONFIDENTIAL_INTENTS"` credits that
|
|
38
|
+
balance directly (1Click settles it with a signed transfer intent). 1Click serves it to partners only, so the provider
|
|
39
|
+
requires `jwt` in this mode and throws at construction without it.
|
|
40
|
+
|
|
41
|
+
`destAddress` must be a NEAR Intents account id: a named account (`alice.near`), an implicit id (64 lowercase hex) or
|
|
42
|
+
an implicit `0x` id (40 lowercase hex); anything else, a top-level name or a chain address such as `bc1q…` included,
|
|
43
|
+
is refused before a request is sent. Because the output never reaches the destination chain, a corridor paused for that chain does not block an
|
|
44
|
+
intents token id.
|
|
45
|
+
|
|
19
46
|
## Behind `remoteProvider`
|
|
20
47
|
|
|
21
48
|
When the provider runs on your server, spread its pins into the app's stub:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nearIntentsProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-X3PXPHCB.js";
|
|
4
4
|
import {
|
|
5
5
|
nearIntents
|
|
6
6
|
} from "./chunk-DIFUONLL.js";
|
|
@@ -24,4 +24,4 @@ var NearIntentsSwap2Protocol = class extends SingleProviderSwap2 {
|
|
|
24
24
|
export {
|
|
25
25
|
NearIntentsSwap2Protocol
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-UGGBJUNL.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-P4T4UJWT.js";
|
|
8
8
|
|
|
9
9
|
// src/provider.ts
|
|
10
|
-
import { timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
10
|
+
import { namespace, timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
11
11
|
import { CC_DEST, ccAsset, ccAssetByToken, ccChain } from "@anywalletkit/swap2-assets";
|
|
12
12
|
var ONE_CLICK_DEFAULT = "https://1click.chaindefuser.com/v0";
|
|
13
13
|
var QUOTE_TTL_MS = 55e3;
|
|
@@ -76,6 +76,12 @@ function txHashOf(entry) {
|
|
|
76
76
|
const h = entry.hash;
|
|
77
77
|
return typeof h === "string" ? h : null;
|
|
78
78
|
}
|
|
79
|
+
var NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
80
|
+
var INTENTS_TOKEN_ID = /^nep(141|245):\S+$/;
|
|
81
|
+
function intentsAccountId(id) {
|
|
82
|
+
if (!NEAR_ACCOUNT_ID.test(id)) return false;
|
|
83
|
+
return id.includes(".") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);
|
|
84
|
+
}
|
|
79
85
|
function nearIntentsProvider(config = {}) {
|
|
80
86
|
config = Object.freeze({ ...config });
|
|
81
87
|
const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);
|
|
@@ -83,6 +89,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
83
89
|
throw new Error("near-intents: apiUrl must use http or https");
|
|
84
90
|
}
|
|
85
91
|
const apiBase = parsedApiUrl.toString().replace(/\/$/, "");
|
|
92
|
+
const recipientType = config.recipientType ?? "DESTINATION_CHAIN";
|
|
93
|
+
if (recipientType !== "DESTINATION_CHAIN" && recipientType !== "INTENTS" && recipientType !== "CONFIDENTIAL_INTENTS") {
|
|
94
|
+
throw new Error("near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS");
|
|
95
|
+
}
|
|
96
|
+
if (recipientType === "CONFIDENTIAL_INTENTS" && !config.jwt) {
|
|
97
|
+
throw new Error("near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt");
|
|
98
|
+
}
|
|
99
|
+
const intents = recipientType !== "DESTINATION_CHAIN";
|
|
100
|
+
const intentsDestOk = (destChain) => !intents || namespace(destChain) === "near";
|
|
101
|
+
const destinationAsset = (destChain, destToken) => intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);
|
|
86
102
|
const hasRecipient = config.feeRecipient !== void 0;
|
|
87
103
|
const hasBps = config.feeBps !== void 0;
|
|
88
104
|
if (hasRecipient !== hasBps) throw new Error("near-intents: feeRecipient and feeBps must be configured together");
|
|
@@ -96,11 +112,11 @@ function nearIntentsProvider(config = {}) {
|
|
|
96
112
|
// Capability discovery comes from the provider itself, so it can run alone
|
|
97
113
|
// or inside the optional aggregator without a central capability table.
|
|
98
114
|
supportsChain: (chain) => nearIntents.supportsChain(chain),
|
|
99
|
-
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain),
|
|
115
|
+
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain) && intentsDestOk(toChain),
|
|
100
116
|
supportsRoute(from, to) {
|
|
101
|
-
if (!nearIntents.supports(from.chain, to.chain)) return false;
|
|
117
|
+
if (!nearIntents.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;
|
|
102
118
|
const asset = ccAsset(from.chain, from.token);
|
|
103
|
-
return !!ccChain(from.chain) && !!asset?.assetId && !!
|
|
119
|
+
return !!ccChain(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);
|
|
104
120
|
},
|
|
105
121
|
async getQuote(params, signal) {
|
|
106
122
|
const refuse = (reason) => {
|
|
@@ -110,11 +126,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
110
126
|
return null;
|
|
111
127
|
};
|
|
112
128
|
const paused = config.suspendedChains ?? {};
|
|
113
|
-
const
|
|
129
|
+
const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);
|
|
130
|
+
const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));
|
|
114
131
|
if (chainRefusal) return refuse(chainRefusal);
|
|
132
|
+
if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);
|
|
133
|
+
if (intents && !intentsAccountId(params.destAddress)) {
|
|
134
|
+
return refuse(`${recipientType} recipient must be a NEAR Intents account id`);
|
|
135
|
+
}
|
|
115
136
|
const origin = ccAsset(params.sourceChain, params.sourceToken);
|
|
116
137
|
if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);
|
|
117
|
-
const destination =
|
|
138
|
+
const destination = destinationAsset(params.destChain, params.destToken);
|
|
118
139
|
if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);
|
|
119
140
|
const dry = params.dry !== false;
|
|
120
141
|
const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : "");
|
|
@@ -134,7 +155,7 @@ function nearIntentsProvider(config = {}) {
|
|
|
134
155
|
refundTo: dcfg.refundTo,
|
|
135
156
|
refundType: dcfg.refundType,
|
|
136
157
|
recipient: params.destAddress,
|
|
137
|
-
recipientType
|
|
158
|
+
recipientType,
|
|
138
159
|
deadline: requestedDeadline
|
|
139
160
|
};
|
|
140
161
|
const fees = appFees(config.feeRecipient, config.feeBps);
|
|
@@ -247,4 +268,4 @@ function nearIntentsProvider(config = {}) {
|
|
|
247
268
|
export {
|
|
248
269
|
nearIntentsProvider
|
|
249
270
|
};
|
|
250
|
-
//# sourceMappingURL=chunk-
|
|
271
|
+
//# sourceMappingURL=chunk-X3PXPHCB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {namespace, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n /**\n * Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to\n * `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account\n * `destAddress` inside intents.near — the account a near.com user holds — with\n * no withdrawal: the asset stays there as the intents token. In this mode\n * `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be\n * the intents token id itself (`nep141:…` / `nep245:…`).\n * `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents\n * balance (where near.com keeps funds); 1Click settles it with a signed\n * transfer intent and serves it to partners only, so it requires `jwt`.\n */\n recipientType?: \"DESTINATION_CHAIN\" | \"INTENTS\" | \"CONFIDENTIAL_INTENTS\";\n}\n\n/** NEAR account id rules (intents.near accounts include implicit hex and 0x ids). */\nconst NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\\d]+[-_])*[a-z\\d]+\\.)*([a-z\\d]+[-_])*[a-z\\d]+$/;\nconst INTENTS_TOKEN_ID = /^nep(141|245):\\S+$/;\n\n/**\n * An intents.near account someone can sign for: a named account (`alice.near`), an\n * implicit ed25519 id (64 hex) or an implicit EVM-style id (`0x` + 40 hex). Any other\n * dot-less id passes the NEAR syntax but is a pasted chain address (`bc1q…`, a padded\n * `0x…`), credited to an account no key controls.\n */\nfunction intentsAccountId(id: string): boolean {\n if (!NEAR_ACCOUNT_ID.test(id)) return false;\n return id.includes(\".\") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const recipientType = config.recipientType ?? \"DESTINATION_CHAIN\";\n if (recipientType !== \"DESTINATION_CHAIN\" && recipientType !== \"INTENTS\" && recipientType !== \"CONFIDENTIAL_INTENTS\") {\n throw new Error(\"near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS\");\n }\n if (recipientType === \"CONFIDENTIAL_INTENTS\" && !config.jwt) {\n throw new Error(\"near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt\");\n }\n /** Output credited inside NEAR Intents (public or confidential), never withdrawn to a chain. */\n const intents = recipientType !== \"DESTINATION_CHAIN\";\n /**\n * An intents credit lands in the intents.near contract on NEAR, whatever token it is, so\n * only a NEAR destChain names it truthfully: a review of \"USDC on Base to 0x…\" must not\n * be a credit that never reaches Base.\n */\n const intentsDestOk = (destChain: string): boolean => !intents || namespace(destChain) === \"near\";\n /** The 1Click destination asset: an intents token id passes through in INTENTS mode. */\n const destinationAsset = (destChain: string, destToken: string): string | null =>\n intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain) && intentsDestOk(toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n // An output credited inside intents.near never touches the destination\n // chain, so only the source corridor can be paused for it.\n const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused)\n ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));\n if (chainRefusal) return refuse(chainRefusal);\n if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);\n if (intents && !intentsAccountId(params.destAddress)) {\n return refuse(`${recipientType} recipient must be a NEAR Intents account id`);\n }\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destinationAsset(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType,\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;AAEA,SAAQ,WAAW,qBAAoB;AACvC,SAAQ,SAAS,SAAS,gBAAgB,eAAc;AAWxD,IAAM,oBAAoB;AAC1B,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AAEtB,SAAS,aAAa,gBAAwB,aAAoC;AAChF,SAAO,GAAG,aAAa,GAAG,mBAAmB,cAAc,CAAC,IAAI,mBAAmB,eAAe,EAAE,CAAC;AACvG;AAEA,SAAS,aAAa,UAAkE;AACtF,MAAI;AACF,QA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AC,OAAO,UAAS;AACrC,cAAM,IAAK,MAAM,IAAI,KAAK;AAI1B,cAAM,MAA6C;AAAA,UACjD,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,UAClB,oBAAoB;AAAA,UACpB,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,QACZ;AACA,cAAM,QAAQ,IAAI,EAAE,UAAU,iBAAiB,KAAK;AAIpD,cAAM,kBAAkB,EAAE,WAAW,sBAAsB,EAAE,WAAW,gBAAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -172,6 +172,12 @@ function txHashOf(entry) {
|
|
|
172
172
|
const h = entry.hash;
|
|
173
173
|
return typeof h === "string" ? h : null;
|
|
174
174
|
}
|
|
175
|
+
var NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
176
|
+
var INTENTS_TOKEN_ID = /^nep(141|245):\S+$/;
|
|
177
|
+
function intentsAccountId(id) {
|
|
178
|
+
if (!NEAR_ACCOUNT_ID.test(id)) return false;
|
|
179
|
+
return id.includes(".") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);
|
|
180
|
+
}
|
|
175
181
|
function nearIntentsProvider(config = {}) {
|
|
176
182
|
config = Object.freeze({ ...config });
|
|
177
183
|
const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);
|
|
@@ -179,6 +185,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
179
185
|
throw new Error("near-intents: apiUrl must use http or https");
|
|
180
186
|
}
|
|
181
187
|
const apiBase = parsedApiUrl.toString().replace(/\/$/, "");
|
|
188
|
+
const recipientType = config.recipientType ?? "DESTINATION_CHAIN";
|
|
189
|
+
if (recipientType !== "DESTINATION_CHAIN" && recipientType !== "INTENTS" && recipientType !== "CONFIDENTIAL_INTENTS") {
|
|
190
|
+
throw new Error("near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS");
|
|
191
|
+
}
|
|
192
|
+
if (recipientType === "CONFIDENTIAL_INTENTS" && !config.jwt) {
|
|
193
|
+
throw new Error("near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt");
|
|
194
|
+
}
|
|
195
|
+
const intents = recipientType !== "DESTINATION_CHAIN";
|
|
196
|
+
const intentsDestOk = (destChain) => !intents || (0, import_util2.namespace)(destChain) === "near";
|
|
197
|
+
const destinationAsset = (destChain, destToken) => intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);
|
|
182
198
|
const hasRecipient = config.feeRecipient !== void 0;
|
|
183
199
|
const hasBps = config.feeBps !== void 0;
|
|
184
200
|
if (hasRecipient !== hasBps) throw new Error("near-intents: feeRecipient and feeBps must be configured together");
|
|
@@ -192,11 +208,11 @@ function nearIntentsProvider(config = {}) {
|
|
|
192
208
|
// Capability discovery comes from the provider itself, so it can run alone
|
|
193
209
|
// or inside the optional aggregator without a central capability table.
|
|
194
210
|
supportsChain: (chain) => nearIntents.supportsChain(chain),
|
|
195
|
-
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain),
|
|
211
|
+
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain) && intentsDestOk(toChain),
|
|
196
212
|
supportsRoute(from, to) {
|
|
197
|
-
if (!nearIntents.supports(from.chain, to.chain)) return false;
|
|
213
|
+
if (!nearIntents.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;
|
|
198
214
|
const asset = (0, import_swap2_assets2.ccAsset)(from.chain, from.token);
|
|
199
|
-
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!
|
|
215
|
+
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);
|
|
200
216
|
},
|
|
201
217
|
async getQuote(params, signal) {
|
|
202
218
|
const refuse = (reason) => {
|
|
@@ -206,11 +222,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
206
222
|
return null;
|
|
207
223
|
};
|
|
208
224
|
const paused = config.suspendedChains ?? {};
|
|
209
|
-
const
|
|
225
|
+
const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);
|
|
226
|
+
const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));
|
|
210
227
|
if (chainRefusal) return refuse(chainRefusal);
|
|
228
|
+
if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);
|
|
229
|
+
if (intents && !intentsAccountId(params.destAddress)) {
|
|
230
|
+
return refuse(`${recipientType} recipient must be a NEAR Intents account id`);
|
|
231
|
+
}
|
|
211
232
|
const origin = (0, import_swap2_assets2.ccAsset)(params.sourceChain, params.sourceToken);
|
|
212
233
|
if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);
|
|
213
|
-
const destination =
|
|
234
|
+
const destination = destinationAsset(params.destChain, params.destToken);
|
|
214
235
|
if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);
|
|
215
236
|
const dry = params.dry !== false;
|
|
216
237
|
const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : "");
|
|
@@ -230,7 +251,7 @@ function nearIntentsProvider(config = {}) {
|
|
|
230
251
|
refundTo: dcfg.refundTo,
|
|
231
252
|
refundType: dcfg.refundType,
|
|
232
253
|
recipient: params.destAddress,
|
|
233
|
-
recipientType
|
|
254
|
+
recipientType,
|
|
234
255
|
deadline: requestedDeadline
|
|
235
256
|
};
|
|
236
257
|
const fees = appFees(config.feeRecipient, config.feeBps);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/activity.ts","../src/provider.ts","../src/protocol.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./provider.js\";\nexport {NearIntentsSwap2Protocol} from \"./protocol.js\";\nexport {NearIntentsSwap2Protocol as default} from \"./protocol.js\";\nexport * from \"./activity.js\";\nexport type { NearIntentsSwap2Config } from \"./protocol.js\"\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n","import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage. Ported\n * from a production 1Click integration:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destAssetId(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? nearIntentsChainRefusal(params.destChain, paused);\n if (chainRefusal) return refuse(chainRefusal);\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destAssetId(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType: \"DESTINATION_CHAIN\",\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n","import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {nearIntents as nearIntentsCfg} from \"./config.js\";\nimport {nearIntentsProvider, type NearIntentsProviderConfig} from \"./provider.js\";\n\nexport interface NearIntentsSwap2Config extends Swap2EngineConfig, NearIntentsProviderConfig {}\n\nexport class NearIntentsSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: NearIntentsSwap2Config) {\n super(account, config);\n this.provider = nearIntentsProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return nearIntentsCfg.supports(caip2, \"eip155:1\") || nearIntentsCfg.supports(\"eip155:1\", caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return nearIntentsCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAwB;AACxB,0BAAsB;AAGtB,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAAU;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAC7D;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAAW;AAAA,EAAW;AAC1D,CAAC;AAWM,SAAS,wBAAwB,OAAe,YAAwC,CAAC,GAAkB;AAChH,MAAI,CAAC,gBAAgB,QAAI,uBAAU,KAAK,CAAC,EAAG,QAAO,yBAAyB,KAAK;AACjF,QAAM,MAAM,UAAU,KAAK;AAC3B,MAAI,IAAK,QAAO,sCAAsC,KAAK,WAAM,GAAG;AAKpE,QAAM,aAAS,6BAAQ,KAAK,GAAG,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,SAAS,CAAC,KAAK;AAC3E,SAAO,SAAS,OAAO,wBAAwB,KAAK;AACtD;AAEO,IAAM,cAAc;AAAA,EACzB,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWf,cAAc,OAAwB;AACpC,WAAO,wBAAwB,KAAK,MAAM;AAAA,EAC5C;AAAA,EACA,SAAS,MAAc,IAAqB;AAC1C,WAAO,KAAK,cAAc,IAAI,KAAK,KAAK,cAAc,EAAE;AAAA,EAC1D;AACF;AAQO,IAAM,kBAA8B,OAAO,OAAO;AAAA,EACvD,aAAa,MAAyB,CAAC;AAAA,EACvC,UAAU,MAAyB,CA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kBAAkB;AAAA,UAClB,oBAAoB;AAAA,UACpB,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,QACZ;AACA,cAAM,QAAQ,IAAI,EAAE,UAAU,iBAAiB,KAAK;AAIpD,cAAM,kBAAkB,EAAE,WAAW,sBAAsB,EAAE,WAAW,gBAAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;;;ACvVA,oBAAkC;AAO3B,IAAM,2BAAN,cAAuC,kCAAoB;AAAA,EAC7C;AAAA,EACnB,YAAY,SAAmC,QAAgC;AAC7E,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,oBAAoB,MAAM;AAAA,EAC5C;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,YAAe,SAAS,OAAO,UAAU,KAAK,YAAe,SAAS,YAAY,KAAK;AAAA,EAChG;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,YAAe,SAAS,WAAW,OAAO;AAAA,EACnD;AACF;","names":["import_util","import_swap2_assets"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/activity.ts","../src/provider.ts","../src/protocol.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./provider.js\";\nexport {NearIntentsSwap2Protocol} from \"./protocol.js\";\nexport {NearIntentsSwap2Protocol as default} from \"./protocol.js\";\nexport * from \"./activity.js\";\nexport type { NearIntentsSwap2Config } from \"./protocol.js\"\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n","import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {namespace, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n /**\n * Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to\n * `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account\n * `destAddress` inside intents.near — the account a near.com user holds — with\n * no withdrawal: the asset stays there as the intents token. In this mode\n * `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be\n * the intents token id itself (`nep141:…` / `nep245:…`).\n * `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents\n * balance (where near.com keeps funds); 1Click settles it with a signed\n * transfer intent and serves it to partners only, so it requires `jwt`.\n */\n recipientType?: \"DESTINATION_CHAIN\" | \"INTENTS\" | \"CONFIDENTIAL_INTENTS\";\n}\n\n/** NEAR account id rules (intents.near accounts include implicit hex and 0x ids). */\nconst NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\\d]+[-_])*[a-z\\d]+\\.)*([a-z\\d]+[-_])*[a-z\\d]+$/;\nconst INTENTS_TOKEN_ID = /^nep(141|245):\\S+$/;\n\n/**\n * An intents.near account someone can sign for: a named account (`alice.near`), an\n * implicit ed25519 id (64 hex) or an implicit EVM-style id (`0x` + 40 hex). Any other\n * dot-less id passes the NEAR syntax but is a pasted chain address (`bc1q…`, a padded\n * `0x…`), credited to an account no key controls.\n */\nfunction intentsAccountId(id: string): boolean {\n if (!NEAR_ACCOUNT_ID.test(id)) return false;\n return id.includes(\".\") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const recipientType = config.recipientType ?? \"DESTINATION_CHAIN\";\n if (recipientType !== \"DESTINATION_CHAIN\" && recipientType !== \"INTENTS\" && recipientType !== \"CONFIDENTIAL_INTENTS\") {\n throw new Error(\"near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS\");\n }\n if (recipientType === \"CONFIDENTIAL_INTENTS\" && !config.jwt) {\n throw new Error(\"near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt\");\n }\n /** Output credited inside NEAR Intents (public or confidential), never withdrawn to a chain. */\n const intents = recipientType !== \"DESTINATION_CHAIN\";\n /**\n * An intents credit lands in the intents.near contract on NEAR, whatever token it is, so\n * only a NEAR destChain names it truthfully: a review of \"USDC on Base to 0x…\" must not\n * be a credit that never reaches Base.\n */\n const intentsDestOk = (destChain: string): boolean => !intents || namespace(destChain) === \"near\";\n /** The 1Click destination asset: an intents token id passes through in INTENTS mode. */\n const destinationAsset = (destChain: string, destToken: string): string | null =>\n intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain) && intentsDestOk(toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n // An output credited inside intents.near never touches the destination\n // chain, so only the source corridor can be paused for it.\n const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused)\n ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));\n if (chainRefusal) return refuse(chainRefusal);\n if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);\n if (intents && !intentsAccountId(params.destAddress)) {\n return refuse(`${recipientType} recipient must be a NEAR Intents account id`);\n }\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destinationAsset(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType,\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n","import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {nearIntents as nearIntentsCfg} from \"./config.js\";\nimport {nearIntentsProvider, type NearIntentsProviderConfig} from \"./provider.js\";\n\nexport interface NearIntentsSwap2Config extends Swap2EngineConfig, NearIntentsProviderConfig {}\n\nexport class NearIntentsSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: NearIntentsSwap2Config) {\n super(account, config);\n this.provider = nearIntentsProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return nearIntentsCfg.supports(caip2, \"eip155:1\") || nearIntentsCfg.supports(\"eip155:1\", caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return nearIntentsCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAwB;AACxB,0BAAsB;AAGtB,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAAU;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAC7D;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAAW;AAAA,EAAW;AAC1D,CAAC;AAWM,SAAS,wBAAwB,OAAe,YAAwC,CAAC,GAAkB;AAChH,MAAI,CAAC,gBAAgB,QAAI,uBAAU,KAAK,CAAC,EAAG,QAAO,yBAAyB,KAAK;AACjF,QAAM,MAAM,UAAU,KAAK;AAC3B,MAAI,IAAK,QAAO,sCAAsC,KAAK,WAAM,GAAG;AAKpE,QAAM,aAAS,6BAAQ,KAAK,GAAG,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,SAAS,CAAC,KAAK;AAC3E,SAAO,SAAS,OAAO,wBAAwB,KAAK;AACtD;AAEO,IAAM,cAAc;AAAA,EACzB,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWf,cAAc,OAAwB;AACpC,WAAO,wBAAwB,KAAK,MAAM;AAAA,EAC5C;AAAA,EACA,SAAS,MAAc,IAAqB;AAC1C,WAAO,KAAK,cAAc,IAAI,KAAK,KAAK,cAAc,EAAE;AAAA,EAC1D;AACF;AAQO,IAAM,kBAA8B,OAA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AAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;;;AC3YA,oBAAkC;AAO3B,IAAM,2BAAN,cAAuC,kCAAoB;AAAA,EAC7C;AAAA,EACnB,YAAY,SAAmC,QAAgC;AAC7E,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,oBAAoB,MAAM;AAAA,EAC5C;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,YAAe,SAAS,OAAO,UAAU,KAAK,YAAe,SAAS,YAAY,KAAK;AAAA,EAChG;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,YAAe,SAAS,WAAW,OAAO;AAAA,EACnD;AACF;","names":["import_util","import_swap2_assets"]}
|
package/dist/index.js
CHANGED
package/dist/protocol.cjs
CHANGED
|
@@ -165,6 +165,12 @@ function txHashOf(entry) {
|
|
|
165
165
|
const h = entry.hash;
|
|
166
166
|
return typeof h === "string" ? h : null;
|
|
167
167
|
}
|
|
168
|
+
var NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
169
|
+
var INTENTS_TOKEN_ID = /^nep(141|245):\S+$/;
|
|
170
|
+
function intentsAccountId(id) {
|
|
171
|
+
if (!NEAR_ACCOUNT_ID.test(id)) return false;
|
|
172
|
+
return id.includes(".") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);
|
|
173
|
+
}
|
|
168
174
|
function nearIntentsProvider(config = {}) {
|
|
169
175
|
config = Object.freeze({ ...config });
|
|
170
176
|
const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);
|
|
@@ -172,6 +178,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
172
178
|
throw new Error("near-intents: apiUrl must use http or https");
|
|
173
179
|
}
|
|
174
180
|
const apiBase = parsedApiUrl.toString().replace(/\/$/, "");
|
|
181
|
+
const recipientType = config.recipientType ?? "DESTINATION_CHAIN";
|
|
182
|
+
if (recipientType !== "DESTINATION_CHAIN" && recipientType !== "INTENTS" && recipientType !== "CONFIDENTIAL_INTENTS") {
|
|
183
|
+
throw new Error("near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS");
|
|
184
|
+
}
|
|
185
|
+
if (recipientType === "CONFIDENTIAL_INTENTS" && !config.jwt) {
|
|
186
|
+
throw new Error("near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt");
|
|
187
|
+
}
|
|
188
|
+
const intents = recipientType !== "DESTINATION_CHAIN";
|
|
189
|
+
const intentsDestOk = (destChain) => !intents || (0, import_util2.namespace)(destChain) === "near";
|
|
190
|
+
const destinationAsset = (destChain, destToken) => intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);
|
|
175
191
|
const hasRecipient = config.feeRecipient !== void 0;
|
|
176
192
|
const hasBps = config.feeBps !== void 0;
|
|
177
193
|
if (hasRecipient !== hasBps) throw new Error("near-intents: feeRecipient and feeBps must be configured together");
|
|
@@ -185,11 +201,11 @@ function nearIntentsProvider(config = {}) {
|
|
|
185
201
|
// Capability discovery comes from the provider itself, so it can run alone
|
|
186
202
|
// or inside the optional aggregator without a central capability table.
|
|
187
203
|
supportsChain: (chain) => nearIntents.supportsChain(chain),
|
|
188
|
-
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain),
|
|
204
|
+
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain) && intentsDestOk(toChain),
|
|
189
205
|
supportsRoute(from, to) {
|
|
190
|
-
if (!nearIntents.supports(from.chain, to.chain)) return false;
|
|
206
|
+
if (!nearIntents.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;
|
|
191
207
|
const asset = (0, import_swap2_assets2.ccAsset)(from.chain, from.token);
|
|
192
|
-
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!
|
|
208
|
+
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);
|
|
193
209
|
},
|
|
194
210
|
async getQuote(params, signal) {
|
|
195
211
|
const refuse = (reason) => {
|
|
@@ -199,11 +215,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
199
215
|
return null;
|
|
200
216
|
};
|
|
201
217
|
const paused = config.suspendedChains ?? {};
|
|
202
|
-
const
|
|
218
|
+
const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);
|
|
219
|
+
const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));
|
|
203
220
|
if (chainRefusal) return refuse(chainRefusal);
|
|
221
|
+
if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);
|
|
222
|
+
if (intents && !intentsAccountId(params.destAddress)) {
|
|
223
|
+
return refuse(`${recipientType} recipient must be a NEAR Intents account id`);
|
|
224
|
+
}
|
|
204
225
|
const origin = (0, import_swap2_assets2.ccAsset)(params.sourceChain, params.sourceToken);
|
|
205
226
|
if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);
|
|
206
|
-
const destination =
|
|
227
|
+
const destination = destinationAsset(params.destChain, params.destToken);
|
|
207
228
|
if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);
|
|
208
229
|
const dry = params.dry !== false;
|
|
209
230
|
const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : "");
|
|
@@ -223,7 +244,7 @@ function nearIntentsProvider(config = {}) {
|
|
|
223
244
|
refundTo: dcfg.refundTo,
|
|
224
245
|
refundType: dcfg.refundType,
|
|
225
246
|
recipient: params.destAddress,
|
|
226
|
-
recipientType
|
|
247
|
+
recipientType,
|
|
227
248
|
deadline: requestedDeadline
|
|
228
249
|
};
|
|
229
250
|
const fees = appFees(config.feeRecipient, config.feeBps);
|
package/dist/protocol.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocol.ts","../src/config.ts","../src/activity.ts","../src/provider.ts"],"sourcesContent":["import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {nearIntents as nearIntentsCfg} from \"./config.js\";\nimport {nearIntentsProvider, type NearIntentsProviderConfig} from \"./provider.js\";\n\nexport interface NearIntentsSwap2Config extends Swap2EngineConfig, NearIntentsProviderConfig {}\n\nexport class NearIntentsSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: NearIntentsSwap2Config) {\n super(account, config);\n this.provider = nearIntentsProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return nearIntentsCfg.supports(caip2, \"eip155:1\") || nearIntentsCfg.supports(\"eip155:1\", caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return nearIntentsCfg.supports(fromChain, toChain);\n }\n}\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n","import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage. Ported\n * from a production 1Click integration:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destAssetId(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? nearIntentsChainRefusal(params.destChain, paused);\n if (chainRefusal) return refuse(chainRefusal);\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destAssetId(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType: \"DESTINATION_CHAIN\",\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};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I,EAAE,UAAU,iBAAiB,KAAK;AAIpD,cAAM,kBAAkB,EAAE,WAAW,sBAAsB,EAAE,WAAW,gBAAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;;;AHhVO,IAAM,2BAAN,cAAuC,kCAAoB;AAAA,EAC7C;AAAA,EACnB,YAAY,SAAmC,QAAgC;AAC7E,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,oBAAoB,MAAM;AAAA,EAC5C;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,YAAe,SAAS,OAAO,UAAU,KAAK,YAAe,SAAS,YAAY,KAAK;AAAA,EAChG;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,YAAe,SAAS,WAAW,OAAO;AAAA,EACnD;AACF;","names":["import_util","import_swap2_assets"]}
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts","../src/config.ts","../src/activity.ts","../src/provider.ts"],"sourcesContent":["import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {nearIntents as nearIntentsCfg} from \"./config.js\";\nimport {nearIntentsProvider, type NearIntentsProviderConfig} from \"./provider.js\";\n\nexport interface NearIntentsSwap2Config extends Swap2EngineConfig, NearIntentsProviderConfig {}\n\nexport class NearIntentsSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: NearIntentsSwap2Config) {\n super(account, config);\n this.provider = nearIntentsProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return nearIntentsCfg.supports(caip2, \"eip155:1\") || nearIntentsCfg.supports(\"eip155:1\", caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return nearIntentsCfg.supports(fromChain, toChain);\n }\n}\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n","import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {namespace, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n /**\n * Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to\n * `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account\n * `destAddress` inside intents.near — the account a near.com user holds — with\n * no withdrawal: the asset stays there as the intents token. In this mode\n * `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be\n * the intents token id itself (`nep141:…` / `nep245:…`).\n * `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents\n * balance (where near.com keeps funds); 1Click settles it with a signed\n * transfer intent and serves it to partners only, so it requires `jwt`.\n */\n recipientType?: \"DESTINATION_CHAIN\" | \"INTENTS\" | \"CONFIDENTIAL_INTENTS\";\n}\n\n/** NEAR account id rules (intents.near accounts include implicit hex and 0x ids). */\nconst NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\\d]+[-_])*[a-z\\d]+\\.)*([a-z\\d]+[-_])*[a-z\\d]+$/;\nconst INTENTS_TOKEN_ID = /^nep(141|245):\\S+$/;\n\n/**\n * An intents.near account someone can sign for: a named account (`alice.near`), an\n * implicit ed25519 id (64 hex) or an implicit EVM-style id (`0x` + 40 hex). Any other\n * dot-less id passes the NEAR syntax but is a pasted chain address (`bc1q…`, a padded\n * `0x…`), credited to an account no key controls.\n */\nfunction intentsAccountId(id: string): boolean {\n if (!NEAR_ACCOUNT_ID.test(id)) return false;\n return id.includes(\".\") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const recipientType = config.recipientType ?? \"DESTINATION_CHAIN\";\n if (recipientType !== \"DESTINATION_CHAIN\" && recipientType !== \"INTENTS\" && recipientType !== \"CONFIDENTIAL_INTENTS\") {\n throw new Error(\"near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS\");\n }\n if (recipientType === \"CONFIDENTIAL_INTENTS\" && !config.jwt) {\n throw new Error(\"near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt\");\n }\n /** Output credited inside NEAR Intents (public or confidential), never withdrawn to a chain. */\n const intents = recipientType !== \"DESTINATION_CHAIN\";\n /**\n * An intents credit lands in the intents.near contract on NEAR, whatever token it is, so\n * only a NEAR destChain names it truthfully: a review of \"USDC on Base to 0x…\" must not\n * be a credit that never reaches Base.\n */\n const intentsDestOk = (destChain: string): boolean => !intents || namespace(destChain) === \"near\";\n /** The 1Click destination asset: an intents token id passes through in INTENTS mode. */\n const destinationAsset = (destChain: string, destToken: string): string | null =>\n intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain) && intentsDestOk(toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n // An output credited inside intents.near never touches the destination\n // chain, so only the source corridor can be paused for it.\n const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused)\n ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));\n if (chainRefusal) return refuse(chainRefusal);\n if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);\n if (intents && !intentsAccountId(params.destAddress)) {\n return refuse(`${recipientType} recipient must be a NEAR Intents account id`);\n }\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destinationAsset(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType,\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkC;;;ACClC,kBAAwB;AACxB,0BAAsB;AAGtB,IA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SAAK,WAAW,oBAAoB,MAAM;AAAA,EAC5C;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,YAAe,SAAS,OAAO,UAAU,KAAK,YAAe,SAAS,YAAY,KAAK;AAAA,EAChG;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,YAAe,SAAS,WAAW,OAAO;AAAA,EACnD;AACF;","names":["import_util","import_swap2_assets"]}
|
package/dist/protocol.js
CHANGED
package/dist/provider.cjs
CHANGED
|
@@ -164,6 +164,12 @@ function txHashOf(entry) {
|
|
|
164
164
|
const h = entry.hash;
|
|
165
165
|
return typeof h === "string" ? h : null;
|
|
166
166
|
}
|
|
167
|
+
var NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
168
|
+
var INTENTS_TOKEN_ID = /^nep(141|245):\S+$/;
|
|
169
|
+
function intentsAccountId(id) {
|
|
170
|
+
if (!NEAR_ACCOUNT_ID.test(id)) return false;
|
|
171
|
+
return id.includes(".") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);
|
|
172
|
+
}
|
|
167
173
|
function nearIntentsProvider(config = {}) {
|
|
168
174
|
config = Object.freeze({ ...config });
|
|
169
175
|
const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);
|
|
@@ -171,6 +177,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
171
177
|
throw new Error("near-intents: apiUrl must use http or https");
|
|
172
178
|
}
|
|
173
179
|
const apiBase = parsedApiUrl.toString().replace(/\/$/, "");
|
|
180
|
+
const recipientType = config.recipientType ?? "DESTINATION_CHAIN";
|
|
181
|
+
if (recipientType !== "DESTINATION_CHAIN" && recipientType !== "INTENTS" && recipientType !== "CONFIDENTIAL_INTENTS") {
|
|
182
|
+
throw new Error("near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS");
|
|
183
|
+
}
|
|
184
|
+
if (recipientType === "CONFIDENTIAL_INTENTS" && !config.jwt) {
|
|
185
|
+
throw new Error("near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt");
|
|
186
|
+
}
|
|
187
|
+
const intents = recipientType !== "DESTINATION_CHAIN";
|
|
188
|
+
const intentsDestOk = (destChain) => !intents || (0, import_util2.namespace)(destChain) === "near";
|
|
189
|
+
const destinationAsset = (destChain, destToken) => intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);
|
|
174
190
|
const hasRecipient = config.feeRecipient !== void 0;
|
|
175
191
|
const hasBps = config.feeBps !== void 0;
|
|
176
192
|
if (hasRecipient !== hasBps) throw new Error("near-intents: feeRecipient and feeBps must be configured together");
|
|
@@ -184,11 +200,11 @@ function nearIntentsProvider(config = {}) {
|
|
|
184
200
|
// Capability discovery comes from the provider itself, so it can run alone
|
|
185
201
|
// or inside the optional aggregator without a central capability table.
|
|
186
202
|
supportsChain: (chain) => nearIntents.supportsChain(chain),
|
|
187
|
-
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain),
|
|
203
|
+
supportsChainPair: (fromChain, toChain) => nearIntents.supports(fromChain, toChain) && intentsDestOk(toChain),
|
|
188
204
|
supportsRoute(from, to) {
|
|
189
|
-
if (!nearIntents.supports(from.chain, to.chain)) return false;
|
|
205
|
+
if (!nearIntents.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;
|
|
190
206
|
const asset = (0, import_swap2_assets2.ccAsset)(from.chain, from.token);
|
|
191
|
-
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!
|
|
207
|
+
return !!(0, import_swap2_assets2.ccChain)(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);
|
|
192
208
|
},
|
|
193
209
|
async getQuote(params, signal) {
|
|
194
210
|
const refuse = (reason) => {
|
|
@@ -198,11 +214,16 @@ function nearIntentsProvider(config = {}) {
|
|
|
198
214
|
return null;
|
|
199
215
|
};
|
|
200
216
|
const paused = config.suspendedChains ?? {};
|
|
201
|
-
const
|
|
217
|
+
const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);
|
|
218
|
+
const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));
|
|
202
219
|
if (chainRefusal) return refuse(chainRefusal);
|
|
220
|
+
if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);
|
|
221
|
+
if (intents && !intentsAccountId(params.destAddress)) {
|
|
222
|
+
return refuse(`${recipientType} recipient must be a NEAR Intents account id`);
|
|
223
|
+
}
|
|
203
224
|
const origin = (0, import_swap2_assets2.ccAsset)(params.sourceChain, params.sourceToken);
|
|
204
225
|
if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);
|
|
205
|
-
const destination =
|
|
226
|
+
const destination = destinationAsset(params.destChain, params.destToken);
|
|
206
227
|
if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);
|
|
207
228
|
const dry = params.dry !== false;
|
|
208
229
|
const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : "");
|
|
@@ -222,7 +243,7 @@ function nearIntentsProvider(config = {}) {
|
|
|
222
243
|
refundTo: dcfg.refundTo,
|
|
223
244
|
refundType: dcfg.refundType,
|
|
224
245
|
recipient: params.destAddress,
|
|
225
|
-
recipientType
|
|
246
|
+
recipientType,
|
|
226
247
|
deadline: requestedDeadline
|
|
227
248
|
};
|
|
228
249
|
const fees = appFees(config.feeRecipient, config.feeBps);
|
package/dist/provider.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/provider.ts","../src/config.ts","../src/activity.ts"],"sourcesContent":["import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage. Ported\n * from a production 1Click integration:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destAssetId(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? nearIntentsChainRefusal(params.destChain, paused);\n if (chainRefusal) return refuse(chainRefusal);\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destAssetId(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType: \"DESTINATION_CHAIN\",\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAwB;AACxB,0BAAsB;AAGtB,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAAU;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAC7D;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAAW;AAAA,EAAW;AAC1D,CAAC;AAWM,SAAS,wBAAwB,OAAe,YAAwC,CAAC,GAAkB;AAChH,MAAI,CAAC,gBAAgB,QAAI,uBAAU,KAAK,CAAC,EAAG,QAAO,yBAAyB,KAAK;AACjF,QAAM,MAAM,UAAU,KAAK;AAC3B,MAAI,IAAK,QAAO,sCAAsC,KAAK,WAAM,GAAG;AAKpE,QAAM,aAAS,6BAAQ,KAAK,GAAG,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,SAAS,CAAC,KAAK;AAC3E,SAAO,SAAS,OAAO,wBAAwB,KAAK;AACtD;AAEO,IAAM,cAAc;AAAA,EACzB,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWf,cAAc,OAAwB;AACpC,WAAO,wBAAwB,KAAK,MAAM;AAAA,EAC5C;AAAA,EACA,SAAS,MAAc,IAAqB;AAC1C,WAAO,KAAK,cA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;AACA,YAAI,CAAC,IAAI,GAAI,QAAO,EAAC,OAAO,UAAS;AACrC,cAAM,IAAK,MAAM,IAAI,KAAK;AAI1B,cAAM,MAA6C;AAAA,UACjD,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,UAClB,oBAAoB;AAAA,UACpB,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,QACZ;AACA,cAAM,QAAQ,IAAI,EAAE,UAAU,iBAAiB,KAAK;AAIpD,cAAM,kBAAkB,EAAE,WAAW,sBAAsB,EAAE,WAAW,gBAAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":["import_util","import_swap2_assets"]}
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts","../src/config.ts","../src/activity.ts"],"sourcesContent":["import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {namespace, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n /**\n * Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to\n * `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account\n * `destAddress` inside intents.near — the account a near.com user holds — with\n * no withdrawal: the asset stays there as the intents token. In this mode\n * `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be\n * the intents token id itself (`nep141:…` / `nep245:…`).\n * `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents\n * balance (where near.com keeps funds); 1Click settles it with a signed\n * transfer intent and serves it to partners only, so it requires `jwt`.\n */\n recipientType?: \"DESTINATION_CHAIN\" | \"INTENTS\" | \"CONFIDENTIAL_INTENTS\";\n}\n\n/** NEAR account id rules (intents.near accounts include implicit hex and 0x ids). */\nconst NEAR_ACCOUNT_ID = /^(?=.{2,64}$)(([a-z\\d]+[-_])*[a-z\\d]+\\.)*([a-z\\d]+[-_])*[a-z\\d]+$/;\nconst INTENTS_TOKEN_ID = /^nep(141|245):\\S+$/;\n\n/**\n * An intents.near account someone can sign for: a named account (`alice.near`), an\n * implicit ed25519 id (64 hex) or an implicit EVM-style id (`0x` + 40 hex). Any other\n * dot-less id passes the NEAR syntax but is a pasted chain address (`bc1q…`, a padded\n * `0x…`), credited to an account no key controls.\n */\nfunction intentsAccountId(id: string): boolean {\n if (!NEAR_ACCOUNT_ID.test(id)) return false;\n return id.includes(\".\") || /^[0-9a-f]{64}$/.test(id) || /^0x[0-9a-f]{40}$/.test(id);\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const recipientType = config.recipientType ?? \"DESTINATION_CHAIN\";\n if (recipientType !== \"DESTINATION_CHAIN\" && recipientType !== \"INTENTS\" && recipientType !== \"CONFIDENTIAL_INTENTS\") {\n throw new Error(\"near-intents: recipientType must be DESTINATION_CHAIN, INTENTS or CONFIDENTIAL_INTENTS\");\n }\n if (recipientType === \"CONFIDENTIAL_INTENTS\" && !config.jwt) {\n throw new Error(\"near-intents: CONFIDENTIAL_INTENTS delivery is partner-only and needs a 1Click jwt\");\n }\n /** Output credited inside NEAR Intents (public or confidential), never withdrawn to a chain. */\n const intents = recipientType !== \"DESTINATION_CHAIN\";\n /**\n * An intents credit lands in the intents.near contract on NEAR, whatever token it is, so\n * only a NEAR destChain names it truthfully: a review of \"USDC on Base to 0x…\" must not\n * be a credit that never reaches Base.\n */\n const intentsDestOk = (destChain: string): boolean => !intents || namespace(destChain) === \"near\";\n /** The 1Click destination asset: an intents token id passes through in INTENTS mode. */\n const destinationAsset = (destChain: string, destToken: string): string | null =>\n intents && INTENTS_TOKEN_ID.test(destToken) ? destToken : destAssetId(destChain, destToken);\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain) && intentsDestOk(toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain) || !intentsDestOk(to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destinationAsset(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n // An output credited inside intents.near never touches the destination\n // chain, so only the source corridor can be paused for it.\n const rawIntentsDest = intents && INTENTS_TOKEN_ID.test(params.destToken);\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused)\n ?? (rawIntentsDest ? null : nearIntentsChainRefusal(params.destChain, paused));\n if (chainRefusal) return refuse(chainRefusal);\n if (!intentsDestOk(params.destChain)) return refuse(`${recipientType} credits intents.near: destChain must be a NEAR chain, not ${params.destChain}`);\n if (intents && !intentsAccountId(params.destAddress)) {\n return refuse(`${recipientType} recipient must be a NEAR Intents account id`);\n }\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destinationAsset(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType,\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n","import type {RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ccChain} from \"@anywalletkit/swap2-assets\";\n\n// ── NEAR Intents (1Click) — core, broadest coverage ─────────────────────────\nconst NEAR_INTENTS_NS = new Set([\n \"eip155\", \"solana\", \"tron\", \"bitcoin\", \"near\", \"sui\", \"ton\", \"zcash\",\n \"litecoin\", \"doge\", \"xrp\", \"bch\", \"cardano\", \"stellar\", \"aptos\",\n]);\n\n/**\n * Corridors the APP has paused (caip2 → why), passed in through the provider\n * config: a venue-side degradation (1Click's HOT omni-bridge assets answering\n * \"not available\" for days) is an operational switch, not SDK knowledge — the\n * wallet flips an env var and lifts it the same way when the venue recovers.\n */\nexport type NearIntentsSuspendedChains = Readonly<Record<string, string>>;\n\n/** Why a chain is refused up front, or null when 1Click can serve it. */\nexport function nearIntentsChainRefusal(chain: string, suspended: NearIntentsSuspendedChains = {}): string | null {\n if (!NEAR_INTENTS_NS.has(namespace(chain))) return `1Click does not serve ${chain}`;\n const why = suspended[chain];\n if (why) return `1Click corridor paused by the app: ${chain} — ${why}`;\n // A chain the catalog knows but carries no 1Click asset id for (World Chain,\n // Sei, Ink, Plume, X Layer, Unichain, MegaETH, Linea, Sonic, …) is LI.FI /\n // CCTP territory: the eip155 namespace alone used to claim it, and every\n // quote then died as \"unknown asset\" (2026-10-16 funded run).\n const listed = ccChain(chain)?.assets.some((a) => a.assetId.length > 0) ?? false;\n return listed ? null : `1Click does not list ${chain}`;\n}\n\nexport const nearIntents = {\n enabled: () => true,\n // Routes between any pair of 1Click-listed chains. 1Click is a NEAR-intents\n // solver network — it settles non-EVM↔non-EVM directly (BTC→Solana, Tron→\n // Base …), so this pre-filter must NOT require an EVM leg (the old \"vault\n // leg is always EVM\" assumption of the off-ramp flow silently blocked those\n // swap routes). A chain counts as listed when the shared catalog carries at\n // least one 1Click asset id for it and it is not suspended above; `getQuote`\n // is the real per-pair check and fail-closes (returns null, naming why) for\n // any pair 1Click can't actually route.\n // 2026-08 sweep: 1Click added LTC/DOGE/XRP/BCH/ADA/XLM/APT (+ the EVM\n // additions Avalanche/Scroll/Berachain, covered by the catalog ids).\n supportsChain(chain: string): boolean {\n return nearIntentsChainRefusal(chain) === null;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n\n/**\n * The app's side of a remote NEAR Intents stub: `remoteProvider({name: \"near_intents\", baseUrl, ...nearIntentsPins})`.\n * Every 1Click route is a send to a deposit address minted per quote, so nothing can be pinned ahead: the stub calls\n * no contract and approves no spender, and is opened to deposit-address routes (scan 2026-10-28, F9). The deposit\n * address is your backend's word — run the backend you trust.\n */\nexport const nearIntentsPins: RemotePins = Object.freeze({\n callTargets: (): readonly string[] => [],\n spenders: (): readonly string[] => [],\n depositAddressRoutes: true,\n});\n","/**\n * Activity recognition for NEAR Intents (1Click).\n *\n * The source leg on EVM / TON / Solana / Tron / BTC is a plain transfer to a\n * one-time 1Click deposit address, and the destination leg is a plain transfer\n * from a solver / bridge account that changes per swap — neither carries a\n * stable on-chain marker, so they are NOT recognizable offline. The kit's\n * intent journal (the `intentId` returned by `swap2()`) ties those legs back to\n * the swap; this hook only answers for the legs that do have a fixed\n * counterparty: on NEAR itself, deposits into and withdrawals out of the\n * `intents.near` verifier contract (NEP-141 `ft_transfer_call` / `ft_withdraw`).\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {describeSwapLike} from \"@anywalletkit/protocol-swap2-core/activity\";\n\nexport const NEAR_INTENTS_MODULE = \"@anywalletkit/protocol-swap2-near-intents\";\n\n/** The NEAR Intents verifier / settlement contract. */\nexport const NEAR_INTENTS_CONTRACT = \"intents.near\";\n\nexport function describeNearIntentsActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!tx.chain.startsWith(\"near:\")) return null;\n const isOwn = (a: string) => ctx.own.has(a);\n const touches = tx.transfers.some((t) => (t.from === NEAR_INTENTS_CONTRACT && isOwn(t.to)) || (t.to === NEAR_INTENTS_CONTRACT && isOwn(t.from)));\n if (!touches) return null;\n return describeSwapLike(tx, ctx, {\n protocol: NEAR_INTENTS_MODULE,\n subtitle: \"NEAR Intents\",\n kind: \"bridge\",\n counterparty: NEAR_INTENTS_CONTRACT,\n inSuffix: \"via NEAR Intents\",\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAwB;AACxB,0BAAsB;AAGtB,IAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAAU;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAC7D;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAO;AAAA,EAAW;AAAA,EAAW;AAC1D,CAAC;AAWM,SAAS,wBAAwB,OAAe,YAAwC,CAAC,GAAkB;AAChH,MAAI,CAAC,gBAAgB,QAAI,uBAAU,KAAK,CAAC,EAAG,QAAO,yBAAyB,KAAK;AACjF,QAAM,MAAM,UAAU,KAAK;AAC3B,MAAI,IAAK,QAAO,sCAAsC,KAAK,WAAM,GAAG;AAKpE,QAAM,aAAS,6BAAQ,KAAK,GAAG,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,SAAS,CAAC,KAAK;AAC3E,SAAO,SAAS,OAAO,wBAAwB,KAAK;AACtD;AAEO,IAAM,cAAc;AAAA,EACzB,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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ACjB,kBAAkB;AAAA,UAClB,oBAAoB;AAAA,UACpB,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,UAAU;AAAA,QACZ;AACA,cAAM,QAAQ,IAAI,EAAE,UAAU,iBAAiB,KAAK;AAIpD,cAAM,kBAAkB,EAAE,WAAW,sBAAsB,EAAE,WAAW,gBAAgB,EAAE,WAAW;AACrG,cAAM,SAAS,SAAS,EAAE,aAAa,2BAA2B,CAAC,CAAC;AACpE,eAAO,EAAC,OAAO,iBAAiB,GAAI,SAAS,EAAC,YAAY,OAAM,IAAI,CAAC,EAAE;AAAA,MACzE,QAAQ;AACN,eAAO,EAAC,OAAO,UAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":["import_util","import_swap2_assets"]}
|
package/dist/provider.d.cts
CHANGED
|
@@ -10,6 +10,18 @@ interface NearIntentsProviderConfig {
|
|
|
10
10
|
feeBps?: number;
|
|
11
11
|
/** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */
|
|
12
12
|
suspendedChains?: NearIntentsSuspendedChains;
|
|
13
|
+
/**
|
|
14
|
+
* Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to
|
|
15
|
+
* `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account
|
|
16
|
+
* `destAddress` inside intents.near — the account a near.com user holds — with
|
|
17
|
+
* no withdrawal: the asset stays there as the intents token. In this mode
|
|
18
|
+
* `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be
|
|
19
|
+
* the intents token id itself (`nep141:…` / `nep245:…`).
|
|
20
|
+
* `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents
|
|
21
|
+
* balance (where near.com keeps funds); 1Click settles it with a signed
|
|
22
|
+
* transfer intent and serves it to partners only, so it requires `jwt`.
|
|
23
|
+
*/
|
|
24
|
+
recipientType?: "DESTINATION_CHAIN" | "INTENTS" | "CONFIDENTIAL_INTENTS";
|
|
13
25
|
}
|
|
14
26
|
declare function nearIntentsProvider(config?: NearIntentsProviderConfig): CrossChainProvider;
|
|
15
27
|
|
package/dist/provider.d.ts
CHANGED
|
@@ -10,6 +10,18 @@ interface NearIntentsProviderConfig {
|
|
|
10
10
|
feeBps?: number;
|
|
11
11
|
/** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */
|
|
12
12
|
suspendedChains?: NearIntentsSuspendedChains;
|
|
13
|
+
/**
|
|
14
|
+
* Where 1Click credits the output. `DESTINATION_CHAIN` (default) withdraws to
|
|
15
|
+
* `destAddress` on `destChain`. `INTENTS` credits the NEAR Intents account
|
|
16
|
+
* `destAddress` inside intents.near — the account a near.com user holds — with
|
|
17
|
+
* no withdrawal: the asset stays there as the intents token. In this mode
|
|
18
|
+
* `destChain` must be the NEAR chain (`near:mainnet`), and `destToken` may be
|
|
19
|
+
* the intents token id itself (`nep141:…` / `nep245:…`).
|
|
20
|
+
* `CONFIDENTIAL_INTENTS` credits the same account's Confidential Intents
|
|
21
|
+
* balance (where near.com keeps funds); 1Click settles it with a signed
|
|
22
|
+
* transfer intent and serves it to partners only, so it requires `jwt`.
|
|
23
|
+
*/
|
|
24
|
+
recipientType?: "DESTINATION_CHAIN" | "INTENTS" | "CONFIDENTIAL_INTENTS";
|
|
13
25
|
}
|
|
14
26
|
declare function nearIntentsProvider(config?: NearIntentsProviderConfig): CrossChainProvider;
|
|
15
27
|
|
package/dist/provider.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anywalletkit/protocol-swap2-near-intents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "NEAR Intents (1Click) cross-chain swaps for Any Wallet Kit: the wallet sends to a one-time deposit address, solvers settle on NEAR and deliver on the destination chain; standalone or as a provider of the swap2 router.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://docs.anywallet.tech",
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@anywalletkit/swap2-assets": "0.2.2",
|
|
53
|
-
"@anywalletkit/protocol-swap2-core": "0.
|
|
53
|
+
"@anywalletkit/protocol-swap2-core": "0.10.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@anywalletkit/core": "0.
|
|
56
|
+
"@anywalletkit/core": "0.8.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^22",
|
|
60
60
|
"vitest": "^5.0.3",
|
|
61
|
-
"@anywalletkit/conformance": "0.
|
|
62
|
-
"@anywalletkit/core": "0.
|
|
61
|
+
"@anywalletkit/conformance": "0.5.0",
|
|
62
|
+
"@anywalletkit/core": "0.8.0"
|
|
63
63
|
},
|
|
64
64
|
"keywords": [
|
|
65
65
|
"swap2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/provider.ts"],"sourcesContent":["import {nearIntents as cfg, nearIntentsChainRefusal, type NearIntentsSuspendedChains} from \"./config.js\";\nimport {describeNearIntentsActivity} from \"./activity.js\";\nimport {timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {CC_DEST, ccAsset, ccAssetByToken, ccChain} from \"@anywalletkit/swap2-assets\";\nimport type {Asset, CrossChainProvider, IntentRef, IntentStatus, Quote, QuoteParams, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\n\n/**\n * NEAR Intents (1Click) provider — the core route, broadest coverage. Ported\n * from a production 1Click integration:\n * dry quote → pricing preview; live quote → depositAddress the user funds\n * from any wallet; status polled by depositAddress.\n * Runs server-side, so the partner JWT stays here (no proxy needed). Defensive:\n * any API error yields a null quote so the provider drops out of that round.\n */\n\nconst ONE_CLICK_DEFAULT = \"https://1click.chaindefuser.com/v0\";\nconst QUOTE_TTL_MS = 55_000;\n\n/** intentId durably carries both status lookup keys (memo is quote-specific). */\nconst INTENT_PREFIX = \"near1click:\";\n\nfunction encodeIntent(depositAddress: string, depositMemo: string | null): string {\n return `${INTENT_PREFIX}${encodeURIComponent(depositAddress)}|${encodeURIComponent(depositMemo ?? \"\")}`;\n}\n\nfunction decodeIntent(intentId: string): {depositAddress: string; depositMemo?: string} {\n try {\n if (!intentId.startsWith(INTENT_PREFIX)) throw new Error(\"unsupported id version\");\n const raw = intentId.slice(INTENT_PREFIX.length);\n const parts = raw.split(\"|\");\n if (parts.length !== 2 || !parts[0]) throw new Error(\"invalid id shape\");\n const depositAddress = decodeURIComponent(parts[0]);\n const memo = decodeURIComponent(parts[1] ?? \"\");\n if (!depositAddress) throw new Error(\"empty deposit address\");\n return {depositAddress, ...(memo ? {depositMemo: memo} : {})};\n } catch {\n throw new Error(\"near-intents: malformed intent id\");\n }\n}\n\nfunction authHeaders(jwtOverride?: string): Record<string, string> {\n const h: Record<string, string> = {\"content-type\": \"application/json\", accept: \"application/json\"};\n const jwt = jwtOverride;\n if (jwt) h.authorization = `Bearer ${jwt}`;\n return h;\n}\n\n/** Our integrator fee, injected server-side when a recipient is configured. */\nfunction appFees(recipient?: string, bps?: number): {recipient: string; fee: number}[] | undefined {\n return recipient !== undefined && bps !== undefined ? [{recipient, fee: bps}] : undefined;\n}\n\n/**\n * Per-source deposit + refund config. Every live default keeps failed-swap\n * ownership on the caller's source-chain address.\n */\nfunction depositConfig(_sourceChain: string, refundAddress: string, _dry: boolean) {\n // Every source refunds to the caller's own source-chain address (Zcash\n // included — a t-address placeholder serves dry quotes since 2026-10-18).\n // Never redirect failed swaps to an integrator-owned NEAR account.\n return {depositType: \"ORIGIN_CHAIN\", refundType: \"ORIGIN_CHAIN\", refundTo: refundAddress};\n}\n\n/** Placeholder sender/recipient for dry quotes (1Click requires the fields). */\nconst PLACEHOLDER: Record<string, string> = {\n bitcoin: \"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq\",\n ton: \"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ\",\n // NOT a token mint: with the USDC mint here, every dry quote whose ORIGIN\n // was Solana USDC answered 500 \"Internal server error\" (2026-10-09) — a\n // refund \"to the asset's own mint\" trips 1Click. The incinerator is a\n // plain, valid system address.\n solana: \"1nc1nerator11111111111111111111111111111111\",\n tron: \"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9\",\n // NEAR refunds go to an account id; the registrar account always exists.\n near: \"near\",\n // A live transparent address (exchange hot wallet); dry quotes only.\n zcash: \"t1KfwsnwJeNRVjQGBDZhwKskpQbih2qx5Ua\",\n eip155: \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\n};\n\nfunction placeholderFor(chain: string): string {\n return PLACEHOLDER[chain.split(\":\")[0] ?? \"\"] ?? PLACEHOLDER.eip155!;\n}\n\nfunction deadlineIn(minutes: number): string {\n return new Date(Date.now() + minutes * 60_000).toISOString().replace(/\\.\\d{3}Z$/, \"Z\");\n}\n\n/**\n * dest asset id for ANY chain in the catalog (inbound → Ethereum, or the step-2\n * off-ramp → any supported chain). Falls back to the Ethereum omft pattern for\n * a mainnet ERC-20 that isn't in the curated catalog.\n */\nfunction destAssetId(destChain: string, destToken: string): string | null {\n const asset = ccAssetByToken(destChain, destToken);\n if (asset) return asset.assetId;\n if (destChain === CC_DEST.caip2 && /^0x[0-9a-fA-F]{40}$/.test(destToken)) {\n return `nep141:eth-${destToken.toLowerCase()}.omft.near`;\n }\n return null;\n}\n\ntype OneClickQuote = {\n quote?: Record<string, unknown>;\n correlationId?: string;\n error?: string;\n message?: string;\n};\n\n/** 1Click returns tx hashes either as strings or {hash, explorerUrl}. */\nfunction txHashOf(entry: unknown): string | null {\n if (!entry) return null;\n if (typeof entry === \"string\") return entry;\n const h = (entry as {hash?: string}).hash;\n return typeof h === \"string\" ? h : null;\n}\n\n/** Explicit constructor configuration; no deployment environment is read. */\nexport interface NearIntentsProviderConfig {\n enabled?: boolean;\n apiUrl?: string;\n jwt?: string;\n feeRecipient?: string;\n feeBps?: number;\n /** Corridors the app has paused (caip2 → reason): refused up front, by name, until the app lifts them. */\n suspendedChains?: NearIntentsSuspendedChains;\n}\n\nexport function nearIntentsProvider(config: NearIntentsProviderConfig = {}): CrossChainProvider {\n config = Object.freeze({...config});\n const parsedApiUrl = new URL(config.apiUrl ?? ONE_CLICK_DEFAULT);\n if (parsedApiUrl.protocol !== \"https:\" && parsedApiUrl.protocol !== \"http:\") {\n throw new Error(\"near-intents: apiUrl must use http or https\");\n }\n const apiBase = parsedApiUrl.toString().replace(/\\/$/, \"\");\n const hasRecipient = config.feeRecipient !== undefined;\n const hasBps = config.feeBps !== undefined;\n if (hasRecipient !== hasBps) throw new Error(\"near-intents: feeRecipient and feeBps must be configured together\");\n if (hasRecipient && (!config.feeRecipient!.trim() || !Number.isInteger(config.feeBps) || config.feeBps! <= 0 || config.feeBps! > 10_000)) {\n throw new Error(\"near-intents: fee config requires a recipient and feeBps between 1 and 10000\");\n }\n return {\n name: \"near_intents\",\n describeActivity: describeNearIntentsActivity,\n enabled: () => config.enabled ?? true,\n\n // Capability discovery comes from the provider itself, so it can run alone\n // or inside the optional aggregator without a central capability table.\n supportsChain: (chain: string) => cfg.supportsChain(chain),\n supportsChainPair: (fromChain: string, toChain: string) => cfg.supports(fromChain, toChain),\n supportsRoute(from: Asset, to: Asset): boolean {\n // Chain-level gate first (namespace, catalog listing, hand-suspended\n // corridors such as TON while the HOT bridge is dark) …\n if (!cfg.supports(from.chain, to.chain)) return false;\n // … then only pairs present in the curated catalog are offered — and only\n // those with a 1Click asset id (LI.FI-only tokens carry an empty assetId).\n // Both ends: a destination 1Click doesn't list (Unichain, MegaETH, …)\n // answered \"unknown asset\" on every quote (589 of the 2026-10-10 matrix).\n const asset = ccAsset(from.chain, from.token);\n return !!ccChain(from.chain) && !!asset?.assetId && !!destAssetId(to.chain, to.token);\n },\n\n async getQuote(params: QuoteParams, signal?: AbortSignal): Promise<Quote | null> {\n // Every refusal below names itself: on the server these lines are the\n // only visibility into WHY a live quote returned null (the wire answer\n // is just `null`), and \"no route\" bugs hide in exactly that silence.\n const refuse = (reason: string): null => {\n const detail = `${reason} [dry=${params.dry !== false} ${params.sourceChain}->${params.destChain} amount=${params.amountIn}]`;\n // Caller fields and 1Click text are untrusted: no control characters in server logs.\n console.warn(`near-intents: no quote — ${detail.replace(/[\\u0000-\\u001f\\u007f]/g, \" \")}`);\n params.onRefusal?.(detail);\n return null;\n };\n // Up-front, named refusals — no wire call for a corridor 1Click cannot\n // serve: a chain outside its list / suspended by hand, or a token the\n // catalog carries without a 1Click asset id (\"1Click does not list …\").\n const paused = config.suspendedChains ?? {};\n const chainRefusal = nearIntentsChainRefusal(params.sourceChain, paused) ?? nearIntentsChainRefusal(params.destChain, paused);\n if (chainRefusal) return refuse(chainRefusal);\n const origin = ccAsset(params.sourceChain, params.sourceToken);\n if (!origin?.assetId) return refuse(`1Click does not list ${params.sourceChain} ${params.sourceToken}`);\n const destination = destAssetId(params.destChain, params.destToken);\n if (!destination) return refuse(`1Click does not list ${params.destChain} ${params.destToken}`);\n const dry = params.dry !== false;\n // A live quote derives the deposit address from the refund config —\n // never create one without a real refund destination.\n const refund = params.refundAddress ?? (dry ? placeholderFor(params.sourceChain) : \"\");\n const dcfg = depositConfig(params.sourceChain, refund, dry);\n if (!dry && !dcfg.refundTo) return refuse(\"live quote without a refund address\");\n\n const requestedDeadline = deadlineIn(60);\n const body: Record<string, unknown> = {\n dry,\n // FLEX_INPUT (exchange flow): the address accepts any amount; amountIn\n // is just the pricing notional. Verified against the live API.\n swapType: params.flex ? \"FLEX_INPUT\" : \"EXACT_INPUT\",\n slippageTolerance: params.slippageBps ?? 100,\n originAsset: origin.assetId,\n depositType: dcfg.depositType,\n destinationAsset: destination,\n amount: params.amountIn,\n refundTo: dcfg.refundTo,\n refundType: dcfg.refundType,\n recipient: params.destAddress,\n recipientType: \"DESTINATION_CHAIN\",\n deadline: requestedDeadline,\n };\n const fees = appFees(config.feeRecipient, config.feeBps);\n if (fees) body.appFees = fees;\n\n try {\n // 1Click's solver auction flaps: the same body can answer 400 \"No\n // liquidity available\" and 201 seconds apart (observed live on\n // TON USDT -> ETH). A transient flap on the EXECUTION quote would\n // surface as a terminal \"no route\" right after a successful display\n // quote, so ride through it: up to two retries on liquidity flaps,\n // 5xx and network errors. Real rejections (bad address, unknown\n // asset) still fail on the first answer.\n let res: Response | null = null;\n let data: OneClickQuote = {};\n for (let attempt = 0; ; attempt++) {\n try {\n res = await fetch(`${apiBase}/quote`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify(body),\n signal: signal ?? timeoutSignal(12_000),\n });\n data = (await res.json().catch(() => ({}))) as OneClickQuote;\n } catch (err) {\n if (attempt >= 2 || signal?.aborted) throw err;\n res = null;\n }\n if (res?.ok) break;\n const flaky =\n res === null ||\n res.status >= 500 ||\n (res.status === 400 && /no liquidity/i.test(String(data.message ?? \"\")));\n if (!flaky || attempt >= 2 || signal?.aborted) break;\n await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));\n }\n if (!res?.ok) return refuse(`1Click ${res?.status ?? \"network error\"}: ${String(data.message ?? \"\").slice(0, 200)}`);\n const q = (data.quote ?? {}) as Record<string, unknown>;\n\n const depositAddress = typeof q.depositAddress === \"string\" ? q.depositAddress : \"\";\n if (!dry && !depositAddress) return refuse(\"live quote came back without a deposit address\");\n const inUsd = Number.parseFloat(String(q.amountInUsd ?? \"0\"));\n const outUsd = Number.parseFloat(String(q.amountOutUsd ?? \"0\"));\n const parsedDeadline = Date.parse(String(q.deadline ?? \"\"));\n if (!dry && (!Number.isFinite(parsedDeadline) || parsedDeadline <= Date.now())) return refuse(`unusable deadline ${String(q.deadline)}`);\n const deadline = Number.isFinite(parsedDeadline) && parsedDeadline > Date.now()\n ? Math.min(parsedDeadline, Date.now() + QUOTE_TTL_MS)\n : Date.now() + QUOTE_TTL_MS;\n\n if (q.amountIn !== undefined && String(q.amountIn) !== params.amountIn) return refuse(`amountIn mismatch (${String(q.amountIn)} vs ${params.amountIn})`);\n\n // amountOut is optimistic, not a guaranteed floor. Live execution must\n // not fabricate a minimum when the provider omits it.\n if (q.minAmountOut === undefined || q.minAmountOut === null) return refuse(\"quote has no minAmountOut\");\n const minDestAmount = String(q.minAmountOut);\n if (params.minAmountOut !== undefined && BigInt(minDestAmount) < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);\n const depositMemo =\n (typeof q.depositMemo === \"string\" && q.depositMemo) ||\n (typeof q.memo === \"string\" && q.memo) ||\n null;\n return {\n provider: \"near_intents\",\n intentId: depositAddress ? encodeIntent(depositAddress, depositMemo) : `dry:${crypto.randomUUID()}`,\n depositAddress,\n depositMemo,\n sourceAmount: params.amountIn,\n destAmount: String(q.amountOut ?? \"0\"),\n minDestAmount,\n feeUsd: Math.max(0, inUsd - outUsd),\n etaSeconds: Number(q.timeEstimate ?? 60),\n reliability: 0.95,\n validUntilMs: deadline,\n };\n } catch (err) {\n return refuse(`threw: ${err instanceof Error ? err.message.slice(0, 200) : String(err).slice(0, 200)}`);\n }\n },\n\n async buildDeposit(quote: Quote): Promise<UnsignedTx> {\n return {\n chain: \"\",\n to: quote.depositAddress,\n value: quote.sourceAmount,\n ...(quote.depositMemo ? {memo: quote.depositMemo} : {}),\n };\n },\n\n async notifyDeposit(intentId: string, txHash: string): Promise<void> {\n const {depositAddress} = decodeIntent(intentId);\n const res = await fetch(`${apiBase}/deposit/submit`, {\n method: \"POST\",\n headers: authHeaders(config.jwt),\n body: JSON.stringify({depositAddress, txHash}),\n signal: timeoutSignal(12_000),\n });\n if (!res.ok) throw new Error(`near-intents: deposit notification failed (${res.status})`);\n },\n\n async trackIntent(ref: IntentRef): Promise<IntentStatus> {\n const {depositAddress, depositMemo} = decodeIntent(ref.intentId);\n // Durable retry: BaseSwap2Protocol embeds the source hash in the swap2\n // id. If the post-broadcast notify failed, every status poll retries it.\n if (ref.sourceTxHash) {\n await this.notifyDeposit?.(ref.intentId, ref.sourceTxHash).catch(() => {});\n }\n try {\n const query = new URLSearchParams({depositAddress});\n if (depositMemo) query.set(\"depositMemo\", depositMemo);\n const res = await fetch(\n `${apiBase}/status?${query.toString()}`,\n {headers: authHeaders(config.jwt), signal: timeoutSignal(12_000)},\n );\n if (!res.ok) return {state: \"pending\"};\n const s = (await res.json()) as {\n status?: string;\n swapDetails?: {destinationChainTxHashes?: unknown[]};\n };\n const map: Record<string, IntentStatus[\"state\"]> = {\n PENDING_DEPOSIT: \"pending\",\n KNOWN_DEPOSIT_TX: \"pending\",\n INCOMPLETE_DEPOSIT: \"pending\",\n PROCESSING: \"pending\",\n SUCCESS: \"completed\",\n FAILED: \"failed\",\n REFUNDED: \"refunded\",\n };\n const state = map[s.status ?? \"PENDING_DEPOSIT\"] ?? \"pending\";\n // KNOWN_DEPOSIT_TX: 1Click has the deposit tx (submitted, not yet\n // credited). Counted as received so a caller with no source hash of\n // its own does not expire a swap that is already on its way.\n const depositReceived = s.status === \"KNOWN_DEPOSIT_TX\" || s.status === \"PROCESSING\" || s.status === \"INCOMPLETE_DEPOSIT\";\n const destTx = txHashOf(s.swapDetails?.destinationChainTxHashes?.[0]);\n return {state, depositReceived, ...(destTx ? {destTxHash: destTx} : {})};\n } catch {\n return {state: \"pending\"};\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;AAEA,SAAQ,qBAAoB;AAC5B,SAAQ,SAAS,SAAS,gBAAgB,eAAc;AAYxD,IAAM,oBAAoB;AAC1B,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AAEtB,SAAS,aAAa,gBAAwB,aAAoC;AAChF,SAAO,GAAG,aAAa,GAAG,mBAAmB,cAAc,CAAC,IAAI,mBAAmB,eAAe,EAAE,CAAC;AACvG;AAEA,SAAS,aAAa,UAAkE;AACtF,MAAI;AACF,QAAI,CAAC,SAAS,WAAW,aAAa,EAAG,OAAM,IAAI,MAAM,wBAAwB;AACjF,UAAM,MAAM,SAAS,MAAM,cAAc,MAAM;AAC/C,UAAM,QA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