@fastnear/intents 1.6.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.
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Protocol types for NEAR Intents (the verifier contract `intents.near`,
3
+ * the 1Click swap API, and the solver relay).
4
+ *
5
+ * Sources of truth:
6
+ * - 1Click OpenAPI: https://1click.chaindefuser.com/docs/v0/openapi.yaml
7
+ * - Verifier docs: https://docs.near-intents.org/integration/verifier-contract
8
+ * - Solver relay: https://docs.near-intents.org/integration/market-makers/message-bus/rpc.md
9
+ */
10
+ /** The NEAR Intents verifier contract (mainnet). */
11
+ declare const INTENTS_CONTRACT_ID = "intents.near";
12
+ /** Hosted 1Click swap API base URL. */
13
+ declare const ONE_CLICK_BASE_URL = "https://1click.chaindefuser.com";
14
+ /** Hosted solver relay JSON-RPC endpoint. */
15
+ declare const SOLVER_RELAY_URL = "https://solver-relay-v2.chaindefuser.com/rpc";
16
+ /**
17
+ * A multi-token id inside the verifier's NEP-245 ledger:
18
+ * `nep141:<contract>`, `nep171:<contract>:<token_id>`, or
19
+ * `nep245:<contract>:<token_id>`.
20
+ */
21
+ type IntentsTokenId = string;
22
+ /**
23
+ * Trade intent: per-token balance deltas for the signer. Negative amounts are
24
+ * paid by the signer, positive amounts are received. The verifier requires all
25
+ * diffs in a batch to sum to zero per token, so a counterparty (solver) signs
26
+ * the mirror diff.
27
+ */
28
+ interface TokenDiffIntent {
29
+ intent: "token_diff";
30
+ diff: Record<IntentsTokenId, string>;
31
+ memo?: string;
32
+ referral?: string;
33
+ }
34
+ /** Internal ledger transfer to another intents.near account. */
35
+ interface TransferIntent {
36
+ intent: "transfer";
37
+ receiver_id: string;
38
+ tokens: Record<IntentsTokenId, string>;
39
+ memo?: string;
40
+ }
41
+ /**
42
+ * Withdraw a NEP-141 token out of the verifier. `token` is the plain token
43
+ * contract id (no `nep141:` prefix). Omit `msg` for refundable ft_transfer
44
+ * semantics; passing `msg` switches to ft_transfer_call with no refund.
45
+ */
46
+ interface FtWithdrawIntent {
47
+ intent: "ft_withdraw";
48
+ token: string;
49
+ receiver_id: string;
50
+ amount: string;
51
+ memo?: string;
52
+ msg?: string;
53
+ storage_deposit?: string;
54
+ }
55
+ interface NftWithdrawIntent {
56
+ intent: "nft_withdraw";
57
+ token: string;
58
+ receiver_id: string;
59
+ token_id: string;
60
+ memo?: string;
61
+ msg?: string;
62
+ storage_deposit?: string;
63
+ }
64
+ interface MtWithdrawIntent {
65
+ intent: "mt_withdraw";
66
+ token: string;
67
+ receiver_id: string;
68
+ token_ids: string[];
69
+ amounts: string[];
70
+ memo?: string;
71
+ msg?: string;
72
+ storage_deposit?: string;
73
+ }
74
+ /** The only way to withdraw native NEAR: unwraps internal wNEAR on exit. */
75
+ interface NativeWithdrawIntent {
76
+ intent: "native_withdraw";
77
+ receiver_id: string;
78
+ amount: string;
79
+ }
80
+ /**
81
+ * Pay a NEP-145 storage_deposit on a token contract from the signer's
82
+ * internal wNEAR balance (registers a receiver before a withdrawal lands).
83
+ */
84
+ interface StorageDepositIntent {
85
+ intent: "storage_deposit";
86
+ contract_id: string;
87
+ account_id: string;
88
+ amount: string;
89
+ }
90
+ type Intent = TokenDiffIntent | TransferIntent | FtWithdrawIntent | NftWithdrawIntent | MtWithdrawIntent | NativeWithdrawIntent | StorageDepositIntent;
91
+ /**
92
+ * The inner message that gets signed. For the `nep413` standard this JSON
93
+ * string becomes the NEP-413 `message`, while the verifying contract and
94
+ * replay nonce live in the NEP-413 envelope (`recipient` / `nonce`).
95
+ */
96
+ interface IntentMessage {
97
+ signer_id: string;
98
+ /** ISO-8601 timestamp after which the signed intent is invalid. */
99
+ deadline: string;
100
+ intents: Intent[];
101
+ }
102
+ /**
103
+ * A NEP-413-signed intent as `intents.near`, the solver relay, and 1Click
104
+ * accept it. Note the encodings: `nonce` is base64 of 32 bytes, while
105
+ * `signature` and `public_key` are `ed25519:<base58>` strings — NOT the
106
+ * base64 signature NEAR wallets return.
107
+ */
108
+ interface SignedIntentNep413 {
109
+ standard: "nep413";
110
+ payload: {
111
+ message: string;
112
+ nonce: string;
113
+ recipient: string;
114
+ callbackUrl?: string;
115
+ };
116
+ public_key: string;
117
+ signature: string;
118
+ }
119
+ /**
120
+ * Any signed payload standard the verifier accepts. This package produces
121
+ * `nep413`; the other variants (erc191, tip191, raw_ed25519, webauthn,
122
+ * ton_connect, sep53) are documented pass-through shapes.
123
+ */
124
+ type SignedIntent = SignedIntentNep413 | {
125
+ standard: string;
126
+ [key: string]: unknown;
127
+ };
128
+ /**
129
+ * An unsigned NEP-413 payload, as returned by 1Click's generate-intent
130
+ * endpoint (nonce is base64 of 32 bytes when it arrives as a string).
131
+ */
132
+ interface UnsignedNep413Payload {
133
+ message: string;
134
+ nonce: string | Uint8Array;
135
+ recipient: string;
136
+ callbackUrl?: string;
137
+ }
138
+ /**
139
+ * What signPayload accepts: a bare unsigned payload or the
140
+ * { standard, payload } wrapper 1Click's generate-intent returns.
141
+ */
142
+ type GeneratedUnsignedIntent = UnsignedNep413Payload | {
143
+ standard: string;
144
+ payload: UnsignedNep413Payload;
145
+ };
146
+ interface SignPayloadOptions {
147
+ /**
148
+ * The verifying contract the payload's recipient must equal. Defaults to
149
+ * intents.near — a server response naming any other recipient throws
150
+ * instead of being signed. Set explicitly to sign for a different
151
+ * (e.g. staging) verifier deployment.
152
+ */
153
+ expectedRecipient?: string;
154
+ }
155
+ /** The signer surface shared by the wallet and local-key implementations. */
156
+ interface IntentSigner {
157
+ /** Build and sign an intent message this client composes itself. */
158
+ signIntents(params: SignIntentsParams): Promise<SignedIntentNep413>;
159
+ /**
160
+ * Sign a pre-built NEP-413 payload verbatim — the 1Click generate-intent
161
+ * flow, where the server chooses the message, nonce, and recipient. The
162
+ * recipient is pinned to intents.near unless options.expectedRecipient
163
+ * overrides it, so a malicious or buggy server cannot redirect the
164
+ * signature to another contract.
165
+ */
166
+ signPayload(payload: GeneratedUnsignedIntent, options?: SignPayloadOptions): Promise<SignedIntentNep413>;
167
+ }
168
+ interface SignIntentsParams {
169
+ intents: Intent[];
170
+ /** Defaults to the connected wallet account / the local signer account. */
171
+ signerId?: string;
172
+ /** ISO-8601; defaults to 5 minutes from now. */
173
+ deadline?: string;
174
+ /** 32 bytes; defaults to crypto-random. */
175
+ nonce?: Uint8Array;
176
+ /** Defaults to intents.near. Override only for a different verifier deployment. */
177
+ verifyingContract?: string;
178
+ }
179
+ type OneClickSwapType = "EXACT_INPUT" | "EXACT_OUTPUT" | "FLEX_INPUT" | "ANY_INPUT";
180
+ type OneClickDepositType = "ORIGIN_CHAIN" | "INTENTS" | "CONFIDENTIAL_INTENTS";
181
+ type OneClickRecipientType = "DESTINATION_CHAIN" | "INTENTS" | "CONFIDENTIAL_INTENTS";
182
+ type OneClickDepositMode = "SIMPLE" | "MEMO";
183
+ interface OneClickToken {
184
+ assetId: string;
185
+ decimals: number;
186
+ blockchain: string;
187
+ symbol: string;
188
+ price?: number;
189
+ priceUpdatedAt?: string;
190
+ contractAddress?: string;
191
+ coingeckoId?: string;
192
+ }
193
+ interface OneClickAppFee {
194
+ /** intents.near account that collects the fee. */
195
+ recipient: string;
196
+ /** Basis points. */
197
+ fee: number;
198
+ }
199
+ interface OneClickQuoteRequest {
200
+ /** true = price preview only (no depositAddress); false commits the quote. */
201
+ dry: boolean;
202
+ swapType: OneClickSwapType;
203
+ /** Basis points, e.g. 100 = 1%. */
204
+ slippageTolerance: number;
205
+ originAsset: string;
206
+ destinationAsset: string;
207
+ /** Base units of the exact side selected by swapType. */
208
+ amount: string;
209
+ depositType: OneClickDepositType;
210
+ refundTo: string;
211
+ refundType: OneClickDepositType;
212
+ recipient: string;
213
+ recipientType: OneClickRecipientType;
214
+ /** ISO-8601. */
215
+ deadline: string;
216
+ depositMode?: OneClickDepositMode;
217
+ referral?: string;
218
+ quoteWaitingTimeMs?: number;
219
+ appFees?: OneClickAppFee[];
220
+ insured?: boolean;
221
+ connectedWallets?: unknown[];
222
+ sessionId?: string;
223
+ virtualChainRecipient?: string;
224
+ virtualChainRefundRecipient?: string;
225
+ customRecipientMsg?: string;
226
+ }
227
+ interface OneClickQuote {
228
+ depositAddress?: string;
229
+ depositMemo?: string;
230
+ chainDepositAddresses?: Array<{
231
+ chain: string;
232
+ depositAddress?: string;
233
+ memo?: string;
234
+ }>;
235
+ amountIn: string;
236
+ amountInFormatted?: string;
237
+ amountInUsd?: string;
238
+ minAmountIn?: string;
239
+ amountOut: string;
240
+ amountOutFormatted?: string;
241
+ amountOutUsd?: string;
242
+ minAmountOut?: string;
243
+ deadline?: string;
244
+ timeWhenInactive?: string;
245
+ timeEstimate?: number;
246
+ refundFee?: string;
247
+ withdrawFee?: string;
248
+ virtualChainRecipient?: string;
249
+ virtualChainRefundRecipient?: string;
250
+ customRecipientMsg?: string;
251
+ }
252
+ interface OneClickQuoteResponse {
253
+ correlationId?: string;
254
+ timestamp: string;
255
+ /** Server-signed quote (verifiable per the 1Click docs). */
256
+ signature: string;
257
+ quoteRequest: OneClickQuoteRequest;
258
+ quote: OneClickQuote;
259
+ }
260
+ type OneClickStatus = "KNOWN_DEPOSIT_TX" | "PENDING_DEPOSIT" | "INCOMPLETE_DEPOSIT" | "PROCESSING" | "SUCCESS" | "REFUNDED" | "FAILED";
261
+ interface OneClickStatusResponse {
262
+ correlationId?: string;
263
+ quoteResponse: OneClickQuoteResponse;
264
+ status: OneClickStatus;
265
+ updatedAt: string;
266
+ swapDetails?: {
267
+ intentHashes?: string[];
268
+ nearTxHashes?: string[];
269
+ originChainTxHashes?: Array<{
270
+ hash: string;
271
+ explorerUrl?: string;
272
+ }>;
273
+ destinationChainTxHashes?: Array<{
274
+ hash: string;
275
+ explorerUrl?: string;
276
+ }>;
277
+ amountIn?: string;
278
+ amountInFormatted?: string;
279
+ amountInUsd?: string;
280
+ amountOut?: string;
281
+ amountOutFormatted?: string;
282
+ amountOutUsd?: string;
283
+ slippage?: number;
284
+ depositedAmount?: string;
285
+ refundedAmount?: string;
286
+ refundReason?: string;
287
+ withdrawFee?: string;
288
+ referral?: string;
289
+ };
290
+ }
291
+ interface OneClickSubmitDepositRequest {
292
+ txHash: string;
293
+ depositAddress: string;
294
+ nearSenderAccount?: string;
295
+ memo?: string;
296
+ }
297
+ type OneClickSigningStandard = "nep413" | "erc191" | "raw_ed25519" | "webauthn" | "ton_connect" | "sep53" | "tip191";
298
+ interface OneClickGenerateIntentRequest {
299
+ signerId: string;
300
+ depositAddress: string;
301
+ standard?: OneClickSigningStandard;
302
+ }
303
+ interface OneClickGenerateIntentResponse {
304
+ /** Unsigned payload to sign — pass it to an IntentSigner's signPayload. */
305
+ intent: GeneratedUnsignedIntent;
306
+ correlationId?: string;
307
+ }
308
+ interface OneClickSubmitIntentResponse {
309
+ intentHash: string;
310
+ correlationId?: string;
311
+ }
312
+ interface RelayQuoteParams {
313
+ defuse_asset_identifier_in: IntentsTokenId;
314
+ defuse_asset_identifier_out: IntentsTokenId;
315
+ exact_amount_in?: string;
316
+ exact_amount_out?: string;
317
+ /** Milliseconds; relay default is 60000. */
318
+ min_deadline_ms?: number;
319
+ }
320
+ interface RelayQuote {
321
+ quote_hash: string;
322
+ defuse_asset_identifier_in: IntentsTokenId;
323
+ defuse_asset_identifier_out: IntentsTokenId;
324
+ amount_in: string;
325
+ amount_out: string;
326
+ expiration_time: string;
327
+ }
328
+ type RelayIntentStatus = "PENDING" | "TX_BROADCASTED" | "SETTLED" | "NOT_FOUND_OR_NOT_VALID";
329
+ interface RelayPublishResult {
330
+ status: string;
331
+ intent_hash: string;
332
+ }
333
+ interface RelayStatusResult {
334
+ intent_hash: string;
335
+ status: RelayIntentStatus;
336
+ status_details?: string;
337
+ data?: {
338
+ hash?: string;
339
+ };
340
+ filled_amounts?: string[];
341
+ }
342
+
343
+ export { SOLVER_RELAY_URL as A, type SignIntentsParams as B, type SignPayloadOptions as C, type StorageDepositIntent as D, type TransferIntent as E, type FtWithdrawIntent as F, type GeneratedUnsignedIntent as G, type Intent as I, type MtWithdrawIntent as M, type NativeWithdrawIntent as N, type OneClickToken as O, type RelayIntentStatus as R, type SignedIntent as S, type TokenDiffIntent as T, type UnsignedNep413Payload as U, type OneClickQuoteRequest as a, type OneClickQuoteResponse as b, type OneClickStatusResponse as c, type OneClickSubmitDepositRequest as d, type OneClickGenerateIntentRequest as e, type OneClickGenerateIntentResponse as f, type OneClickSubmitIntentResponse as g, type IntentMessage as h, type IntentSigner as i, type SignedIntentNep413 as j, type IntentsTokenId as k, INTENTS_CONTRACT_ID as l, type NftWithdrawIntent as m, ONE_CLICK_BASE_URL as n, type OneClickAppFee as o, type OneClickDepositMode as p, type OneClickDepositType as q, type OneClickQuote as r, type OneClickRecipientType as s, type OneClickSigningStandard as t, type OneClickStatus as u, type OneClickSwapType as v, type RelayPublishResult as w, type RelayQuote as x, type RelayQuoteParams as y, type RelayStatusResult as z };
@@ -0,0 +1,11 @@
1
+ /* ⋈ 🏃🏻💨 FastNear intents - ESM (@fastnear/intents version 1.6.0) */
2
+ /* https://www.npmjs.com/package/@fastnear/intents/v/1.6.0 */
3
+ const INTENTS_CONTRACT_ID = "intents.near";
4
+ const ONE_CLICK_BASE_URL = "https://1click.chaindefuser.com";
5
+ const SOLVER_RELAY_URL = "https://solver-relay-v2.chaindefuser.com/rpc";
6
+ export {
7
+ INTENTS_CONTRACT_ID,
8
+ ONE_CLICK_BASE_URL,
9
+ SOLVER_RELAY_URL
10
+ };
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["/**\n * Protocol types for NEAR Intents (the verifier contract `intents.near`,\n * the 1Click swap API, and the solver relay).\n *\n * Sources of truth:\n * - 1Click OpenAPI: https://1click.chaindefuser.com/docs/v0/openapi.yaml\n * - Verifier docs: https://docs.near-intents.org/integration/verifier-contract\n * - Solver relay: https://docs.near-intents.org/integration/market-makers/message-bus/rpc.md\n */\n\n/** The NEAR Intents verifier contract (mainnet). */\nexport const INTENTS_CONTRACT_ID = \"intents.near\";\n\n/** Hosted 1Click swap API base URL. */\nexport const ONE_CLICK_BASE_URL = \"https://1click.chaindefuser.com\";\n\n/** Hosted solver relay JSON-RPC endpoint. */\nexport const SOLVER_RELAY_URL = \"https://solver-relay-v2.chaindefuser.com/rpc\";\n\n/**\n * A multi-token id inside the verifier's NEP-245 ledger:\n * `nep141:<contract>`, `nep171:<contract>:<token_id>`, or\n * `nep245:<contract>:<token_id>`.\n */\nexport type IntentsTokenId = string;\n\n// ---------------------------------------------------------------------------\n// Intent types executed by intents.near\n// ---------------------------------------------------------------------------\n\n/**\n * Trade intent: per-token balance deltas for the signer. Negative amounts are\n * paid by the signer, positive amounts are received. The verifier requires all\n * diffs in a batch to sum to zero per token, so a counterparty (solver) signs\n * the mirror diff.\n */\nexport interface TokenDiffIntent {\n intent: \"token_diff\";\n diff: Record<IntentsTokenId, string>;\n memo?: string;\n referral?: string;\n}\n\n/** Internal ledger transfer to another intents.near account. */\nexport interface TransferIntent {\n intent: \"transfer\";\n receiver_id: string;\n tokens: Record<IntentsTokenId, string>;\n memo?: string;\n}\n\n/**\n * Withdraw a NEP-141 token out of the verifier. `token` is the plain token\n * contract id (no `nep141:` prefix). Omit `msg` for refundable ft_transfer\n * semantics; passing `msg` switches to ft_transfer_call with no refund.\n */\nexport interface FtWithdrawIntent {\n intent: \"ft_withdraw\";\n token: string;\n receiver_id: string;\n amount: string;\n memo?: string;\n msg?: string;\n storage_deposit?: string;\n}\n\nexport interface NftWithdrawIntent {\n intent: \"nft_withdraw\";\n token: string;\n receiver_id: string;\n token_id: string;\n memo?: string;\n msg?: string;\n storage_deposit?: string;\n}\n\nexport interface MtWithdrawIntent {\n intent: \"mt_withdraw\";\n token: string;\n receiver_id: string;\n token_ids: string[];\n amounts: string[];\n memo?: string;\n msg?: string;\n storage_deposit?: string;\n}\n\n/** The only way to withdraw native NEAR: unwraps internal wNEAR on exit. */\nexport interface NativeWithdrawIntent {\n intent: \"native_withdraw\";\n receiver_id: string;\n amount: string;\n}\n\n/**\n * Pay a NEP-145 storage_deposit on a token contract from the signer's\n * internal wNEAR balance (registers a receiver before a withdrawal lands).\n */\nexport interface StorageDepositIntent {\n intent: \"storage_deposit\";\n contract_id: string;\n account_id: string;\n amount: string;\n}\n\nexport type Intent =\n | TokenDiffIntent\n | TransferIntent\n | FtWithdrawIntent\n | NftWithdrawIntent\n | MtWithdrawIntent\n | NativeWithdrawIntent\n | StorageDepositIntent;\n\n/**\n * The inner message that gets signed. For the `nep413` standard this JSON\n * string becomes the NEP-413 `message`, while the verifying contract and\n * replay nonce live in the NEP-413 envelope (`recipient` / `nonce`).\n */\nexport interface IntentMessage {\n signer_id: string;\n /** ISO-8601 timestamp after which the signed intent is invalid. */\n deadline: string;\n intents: Intent[];\n}\n\n// ---------------------------------------------------------------------------\n// Signed payloads (MultiPayload)\n// ---------------------------------------------------------------------------\n\n/**\n * A NEP-413-signed intent as `intents.near`, the solver relay, and 1Click\n * accept it. Note the encodings: `nonce` is base64 of 32 bytes, while\n * `signature` and `public_key` are `ed25519:<base58>` strings — NOT the\n * base64 signature NEAR wallets return.\n */\nexport interface SignedIntentNep413 {\n standard: \"nep413\";\n payload: {\n message: string;\n nonce: string;\n recipient: string;\n callbackUrl?: string;\n };\n public_key: string;\n signature: string;\n}\n\n/**\n * Any signed payload standard the verifier accepts. This package produces\n * `nep413`; the other variants (erc191, tip191, raw_ed25519, webauthn,\n * ton_connect, sep53) are documented pass-through shapes.\n */\nexport type SignedIntent =\n | SignedIntentNep413\n | { standard: string; [key: string]: unknown };\n\n/**\n * An unsigned NEP-413 payload, as returned by 1Click's generate-intent\n * endpoint (nonce is base64 of 32 bytes when it arrives as a string).\n */\nexport interface UnsignedNep413Payload {\n message: string;\n nonce: string | Uint8Array;\n recipient: string;\n callbackUrl?: string;\n}\n\n/**\n * What signPayload accepts: a bare unsigned payload or the\n * { standard, payload } wrapper 1Click's generate-intent returns.\n */\nexport type GeneratedUnsignedIntent =\n | UnsignedNep413Payload\n | { standard: string; payload: UnsignedNep413Payload };\n\nexport interface SignPayloadOptions {\n /**\n * The verifying contract the payload's recipient must equal. Defaults to\n * intents.near — a server response naming any other recipient throws\n * instead of being signed. Set explicitly to sign for a different\n * (e.g. staging) verifier deployment.\n */\n expectedRecipient?: string;\n}\n\n/** The signer surface shared by the wallet and local-key implementations. */\nexport interface IntentSigner {\n /** Build and sign an intent message this client composes itself. */\n signIntents(params: SignIntentsParams): Promise<SignedIntentNep413>;\n /**\n * Sign a pre-built NEP-413 payload verbatim — the 1Click generate-intent\n * flow, where the server chooses the message, nonce, and recipient. The\n * recipient is pinned to intents.near unless options.expectedRecipient\n * overrides it, so a malicious or buggy server cannot redirect the\n * signature to another contract.\n */\n signPayload(\n payload: GeneratedUnsignedIntent,\n options?: SignPayloadOptions,\n ): Promise<SignedIntentNep413>;\n}\n\nexport interface SignIntentsParams {\n intents: Intent[];\n /** Defaults to the connected wallet account / the local signer account. */\n signerId?: string;\n /** ISO-8601; defaults to 5 minutes from now. */\n deadline?: string;\n /** 32 bytes; defaults to crypto-random. */\n nonce?: Uint8Array;\n /** Defaults to intents.near. Override only for a different verifier deployment. */\n verifyingContract?: string;\n}\n\n// ---------------------------------------------------------------------------\n// 1Click API shapes (v0)\n// ---------------------------------------------------------------------------\n\nexport type OneClickSwapType =\n | \"EXACT_INPUT\"\n | \"EXACT_OUTPUT\"\n | \"FLEX_INPUT\"\n | \"ANY_INPUT\";\n\nexport type OneClickDepositType =\n | \"ORIGIN_CHAIN\"\n | \"INTENTS\"\n | \"CONFIDENTIAL_INTENTS\";\n\nexport type OneClickRecipientType =\n | \"DESTINATION_CHAIN\"\n | \"INTENTS\"\n | \"CONFIDENTIAL_INTENTS\";\n\nexport type OneClickDepositMode = \"SIMPLE\" | \"MEMO\";\n\nexport interface OneClickToken {\n assetId: string;\n decimals: number;\n blockchain: string;\n symbol: string;\n price?: number;\n priceUpdatedAt?: string;\n contractAddress?: string;\n coingeckoId?: string;\n}\n\nexport interface OneClickAppFee {\n /** intents.near account that collects the fee. */\n recipient: string;\n /** Basis points. */\n fee: number;\n}\n\nexport interface OneClickQuoteRequest {\n /** true = price preview only (no depositAddress); false commits the quote. */\n dry: boolean;\n swapType: OneClickSwapType;\n /** Basis points, e.g. 100 = 1%. */\n slippageTolerance: number;\n originAsset: string;\n destinationAsset: string;\n /** Base units of the exact side selected by swapType. */\n amount: string;\n depositType: OneClickDepositType;\n refundTo: string;\n refundType: OneClickDepositType;\n recipient: string;\n recipientType: OneClickRecipientType;\n /** ISO-8601. */\n deadline: string;\n depositMode?: OneClickDepositMode;\n referral?: string;\n quoteWaitingTimeMs?: number;\n appFees?: OneClickAppFee[];\n insured?: boolean;\n connectedWallets?: unknown[];\n sessionId?: string;\n virtualChainRecipient?: string;\n virtualChainRefundRecipient?: string;\n customRecipientMsg?: string;\n}\n\nexport interface OneClickQuote {\n depositAddress?: string;\n depositMemo?: string;\n chainDepositAddresses?: Array<{ chain: string; depositAddress?: string; memo?: string }>;\n amountIn: string;\n amountInFormatted?: string;\n amountInUsd?: string;\n minAmountIn?: string;\n amountOut: string;\n amountOutFormatted?: string;\n amountOutUsd?: string;\n minAmountOut?: string;\n deadline?: string;\n timeWhenInactive?: string;\n timeEstimate?: number;\n refundFee?: string;\n withdrawFee?: string;\n virtualChainRecipient?: string;\n virtualChainRefundRecipient?: string;\n customRecipientMsg?: string;\n}\n\nexport interface OneClickQuoteResponse {\n correlationId?: string;\n timestamp: string;\n /** Server-signed quote (verifiable per the 1Click docs). */\n signature: string;\n quoteRequest: OneClickQuoteRequest;\n quote: OneClickQuote;\n}\n\nexport type OneClickStatus =\n | \"KNOWN_DEPOSIT_TX\"\n | \"PENDING_DEPOSIT\"\n | \"INCOMPLETE_DEPOSIT\"\n | \"PROCESSING\"\n | \"SUCCESS\"\n | \"REFUNDED\"\n | \"FAILED\";\n\nexport interface OneClickStatusResponse {\n correlationId?: string;\n quoteResponse: OneClickQuoteResponse;\n status: OneClickStatus;\n updatedAt: string;\n swapDetails?: {\n intentHashes?: string[];\n nearTxHashes?: string[];\n originChainTxHashes?: Array<{ hash: string; explorerUrl?: string }>;\n destinationChainTxHashes?: Array<{ hash: string; explorerUrl?: string }>;\n amountIn?: string;\n amountInFormatted?: string;\n amountInUsd?: string;\n amountOut?: string;\n amountOutFormatted?: string;\n amountOutUsd?: string;\n slippage?: number;\n depositedAmount?: string;\n refundedAmount?: string;\n refundReason?: string;\n withdrawFee?: string;\n referral?: string;\n };\n}\n\nexport interface OneClickSubmitDepositRequest {\n txHash: string;\n depositAddress: string;\n nearSenderAccount?: string;\n memo?: string;\n}\n\nexport type OneClickSigningStandard =\n | \"nep413\"\n | \"erc191\"\n | \"raw_ed25519\"\n | \"webauthn\"\n | \"ton_connect\"\n | \"sep53\"\n | \"tip191\";\n\nexport interface OneClickGenerateIntentRequest {\n signerId: string;\n depositAddress: string;\n standard?: OneClickSigningStandard;\n}\n\nexport interface OneClickGenerateIntentResponse {\n /** Unsigned payload to sign — pass it to an IntentSigner's signPayload. */\n intent: GeneratedUnsignedIntent;\n correlationId?: string;\n}\n\nexport interface OneClickSubmitIntentResponse {\n intentHash: string;\n correlationId?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Solver relay JSON-RPC shapes\n// ---------------------------------------------------------------------------\n\nexport interface RelayQuoteParams {\n defuse_asset_identifier_in: IntentsTokenId;\n defuse_asset_identifier_out: IntentsTokenId;\n exact_amount_in?: string;\n exact_amount_out?: string;\n /** Milliseconds; relay default is 60000. */\n min_deadline_ms?: number;\n}\n\nexport interface RelayQuote {\n quote_hash: string;\n defuse_asset_identifier_in: IntentsTokenId;\n defuse_asset_identifier_out: IntentsTokenId;\n amount_in: string;\n amount_out: string;\n expiration_time: string;\n}\n\nexport type RelayIntentStatus =\n | \"PENDING\"\n | \"TX_BROADCASTED\"\n | \"SETTLED\"\n | \"NOT_FOUND_OR_NOT_VALID\";\n\nexport interface RelayPublishResult {\n status: string;\n intent_hash: string;\n}\n\nexport interface RelayStatusResult {\n intent_hash: string;\n status: RelayIntentStatus;\n status_details?: string;\n data?: { hash?: string };\n filled_amounts?: string[];\n}\n"],"mappings":";;AAWO,MAAM,sBAAsB;AAG5B,MAAM,qBAAqB;AAG3B,MAAM,mBAAmB;","names":[]}
@@ -0,0 +1,124 @@
1
+ /* ⋈ 🏃🏻💨 FastNear intents - ESM (@fastnear/intents version 1.6.0) */
2
+ /* https://www.npmjs.com/package/@fastnear/intents/v/1.6.0 */
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ import { INTENTS_CONTRACT_ID } from "./types.js";
6
+ const FT_TRANSFER_CALL_GAS = "100000000000000";
7
+ const WITHDRAW_GAS = "100000000000000";
8
+ const WRAP_NEAR_GAS = "30000000000000";
9
+ const ONE_YOCTO = "1";
10
+ const WRAP_NEAR_CONTRACT_ID = "wrap.near";
11
+ function ftDepositAction({
12
+ amount,
13
+ creditTo,
14
+ msg,
15
+ verifierId = INTENTS_CONTRACT_ID,
16
+ gas = FT_TRANSFER_CALL_GAS
17
+ }) {
18
+ if (creditTo !== void 0 && msg !== void 0) {
19
+ throw new Error("Pass either creditTo or msg, not both");
20
+ }
21
+ return {
22
+ type: "FunctionCall",
23
+ methodName: "ft_transfer_call",
24
+ args: {
25
+ receiver_id: verifierId,
26
+ amount,
27
+ msg: msg ?? creditTo ?? ""
28
+ },
29
+ gas,
30
+ deposit: ONE_YOCTO
31
+ };
32
+ }
33
+ __name(ftDepositAction, "ftDepositAction");
34
+ function wrapNearAction({
35
+ amountYocto,
36
+ gas = WRAP_NEAR_GAS
37
+ }) {
38
+ return {
39
+ type: "FunctionCall",
40
+ methodName: "near_deposit",
41
+ args: {},
42
+ gas,
43
+ deposit: amountYocto
44
+ };
45
+ }
46
+ __name(wrapNearAction, "wrapNearAction");
47
+ function ftWithdrawAction({
48
+ token,
49
+ receiverId,
50
+ amount,
51
+ memo,
52
+ msg,
53
+ storageDeposit,
54
+ gas = WITHDRAW_GAS
55
+ }) {
56
+ if (token.includes(":")) {
57
+ throw new Error(
58
+ `ft_withdraw takes the plain token contract id, not a prefixed multi-token id: ${token}`
59
+ );
60
+ }
61
+ return {
62
+ type: "FunctionCall",
63
+ methodName: "ft_withdraw",
64
+ args: {
65
+ token,
66
+ receiver_id: receiverId,
67
+ amount,
68
+ ...memo !== void 0 ? { memo } : {},
69
+ ...msg !== void 0 ? { msg } : {},
70
+ ...storageDeposit !== void 0 ? { storage_deposit: storageDeposit } : {}
71
+ },
72
+ gas,
73
+ deposit: ONE_YOCTO
74
+ };
75
+ }
76
+ __name(ftWithdrawAction, "ftWithdrawAction");
77
+ async function mtBalance({
78
+ accountId,
79
+ tokenId,
80
+ view,
81
+ verifierId = INTENTS_CONTRACT_ID
82
+ }) {
83
+ const result = await view({
84
+ contractId: verifierId,
85
+ methodName: "mt_balance_of",
86
+ args: { account_id: accountId, token_id: tokenId }
87
+ });
88
+ return String(result ?? "0");
89
+ }
90
+ __name(mtBalance, "mtBalance");
91
+ async function mtBatchBalances({
92
+ accountId,
93
+ tokenIds,
94
+ view,
95
+ verifierId = INTENTS_CONTRACT_ID
96
+ }) {
97
+ const result = await view({
98
+ contractId: verifierId,
99
+ methodName: "mt_batch_balance_of",
100
+ args: { account_id: accountId, token_ids: tokenIds }
101
+ });
102
+ if (!Array.isArray(result) || result.length !== tokenIds.length) {
103
+ throw new Error(
104
+ `mt_batch_balance_of returned ${Array.isArray(result) ? result.length : typeof result} results for ${tokenIds.length} token ids`
105
+ );
106
+ }
107
+ return Object.fromEntries(
108
+ tokenIds.map((tokenId, index) => [tokenId, String(result[index] ?? "0")])
109
+ );
110
+ }
111
+ __name(mtBatchBalances, "mtBatchBalances");
112
+ export {
113
+ FT_TRANSFER_CALL_GAS,
114
+ ONE_YOCTO,
115
+ WITHDRAW_GAS,
116
+ WRAP_NEAR_CONTRACT_ID,
117
+ WRAP_NEAR_GAS,
118
+ ftDepositAction,
119
+ ftWithdrawAction,
120
+ mtBalance,
121
+ mtBatchBalances,
122
+ wrapNearAction
123
+ };
124
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/verifier.ts"],"sourcesContent":["import { INTENTS_CONTRACT_ID, type IntentsTokenId } from \"./types.js\";\n\n/** Gas / deposit defaults for verifier interactions. */\nexport const FT_TRANSFER_CALL_GAS = \"100000000000000\"; // 100 TGas\nexport const WITHDRAW_GAS = \"100000000000000\"; // 100 TGas\nexport const WRAP_NEAR_GAS = \"30000000000000\"; // 30 TGas\nexport const ONE_YOCTO = \"1\";\n\n/** wNEAR contract — native NEAR must be wrapped before depositing. */\nexport const WRAP_NEAR_CONTRACT_ID = \"wrap.near\";\n\n/**\n * The flat FastNEAR action shape. near.sendTx serializes these fields\n * directly, and @fastnear/wallet converts flat actions for near-connect\n * wallets — so one shape works on both signing paths.\n */\nexport interface FunctionCallActionShape {\n type: \"FunctionCall\";\n methodName: string;\n args: Record<string, unknown>;\n gas: string;\n deposit: string;\n}\n\n/**\n * Build the `ft_transfer_call` action that deposits a NEP-141 token into the\n * verifier. Apply it ON the token contract:\n *\n * near.sendTx({ receiverId: \"usdt.tether-token.near\",\n * actions: [ftDepositAction({ amount })] })\n *\n * `msg` semantics (per the verifier docs): \"\" credits the sender; an\n * account-id string credits that account (`creditTo`); a JSON string enables\n * execute_intents-on-deposit. Native NEAR is rejected by the verifier —\n * wrap it first (see wrapNearAction).\n */\nexport function ftDepositAction({\n amount,\n creditTo,\n msg,\n verifierId = INTENTS_CONTRACT_ID,\n gas = FT_TRANSFER_CALL_GAS,\n}: {\n amount: string;\n creditTo?: string;\n msg?: string;\n verifierId?: string;\n gas?: string;\n}): FunctionCallActionShape {\n if (creditTo !== undefined && msg !== undefined) {\n throw new Error(\"Pass either creditTo or msg, not both\");\n }\n return {\n type: \"FunctionCall\",\n methodName: \"ft_transfer_call\",\n args: {\n receiver_id: verifierId,\n amount,\n msg: msg ?? creditTo ?? \"\",\n },\n gas,\n deposit: ONE_YOCTO,\n };\n}\n\n/**\n * Build the `near_deposit` action that wraps native NEAR into wNEAR.\n * Apply it ON wrap.near:\n *\n * near.sendTx({ receiverId: \"wrap.near\",\n * actions: [wrapNearAction({ amountYocto })] })\n */\nexport function wrapNearAction({\n amountYocto,\n gas = WRAP_NEAR_GAS,\n}: {\n amountYocto: string;\n gas?: string;\n}): FunctionCallActionShape {\n return {\n type: \"FunctionCall\",\n methodName: \"near_deposit\",\n args: {},\n gas,\n deposit: amountYocto,\n };\n}\n\n/**\n * Build the direct-call `ft_withdraw` action that moves a NEP-141 token out\n * of the verifier back to a NEAR account. Apply it ON intents.near. `token`\n * is the plain contract id (no `nep141:` prefix). Omit `msg` so failed\n * withdrawals stay refundable.\n */\nexport function ftWithdrawAction({\n token,\n receiverId,\n amount,\n memo,\n msg,\n storageDeposit,\n gas = WITHDRAW_GAS,\n}: {\n token: string;\n receiverId: string;\n amount: string;\n memo?: string;\n msg?: string;\n storageDeposit?: string;\n gas?: string;\n}): FunctionCallActionShape {\n if (token.includes(\":\")) {\n throw new Error(\n `ft_withdraw takes the plain token contract id, not a prefixed multi-token id: ${token}`,\n );\n }\n return {\n type: \"FunctionCall\",\n methodName: \"ft_withdraw\",\n args: {\n token,\n receiver_id: receiverId,\n amount,\n ...(memo !== undefined ? { memo } : {}),\n ...(msg !== undefined ? { msg } : {}),\n ...(storageDeposit !== undefined\n ? { storage_deposit: storageDeposit }\n : {}),\n },\n gas,\n deposit: ONE_YOCTO,\n };\n}\n\n/** A near.view-compatible function, injected so this package stays api-free. */\nexport type ViewFunction = (params: {\n contractId: string;\n methodName: string;\n args: Record<string, unknown>;\n}) => Promise<unknown>;\n\n/** Read one internal balance from the verifier's NEP-245 ledger. */\nexport async function mtBalance({\n accountId,\n tokenId,\n view,\n verifierId = INTENTS_CONTRACT_ID,\n}: {\n accountId: string;\n tokenId: IntentsTokenId;\n view: ViewFunction;\n verifierId?: string;\n}): Promise<string> {\n const result = await view({\n contractId: verifierId,\n methodName: \"mt_balance_of\",\n args: { account_id: accountId, token_id: tokenId },\n });\n return String(result ?? \"0\");\n}\n\n/**\n * Read many internal balances in one view call. Returns a map keyed by\n * token id (the RPC returns base-unit strings in request order).\n */\nexport async function mtBatchBalances({\n accountId,\n tokenIds,\n view,\n verifierId = INTENTS_CONTRACT_ID,\n}: {\n accountId: string;\n tokenIds: IntentsTokenId[];\n view: ViewFunction;\n verifierId?: string;\n}): Promise<Record<IntentsTokenId, string>> {\n const result = (await view({\n contractId: verifierId,\n methodName: \"mt_batch_balance_of\",\n args: { account_id: accountId, token_ids: tokenIds },\n })) as unknown[];\n if (!Array.isArray(result) || result.length !== tokenIds.length) {\n throw new Error(\n `mt_batch_balance_of returned ${Array.isArray(result) ? result.length : typeof result} results for ${tokenIds.length} token ids`,\n );\n }\n return Object.fromEntries(\n tokenIds.map((tokenId, index) => [tokenId, String(result[index] ?? \"0\")]),\n );\n}\n"],"mappings":";;;;AAAA,SAAS,2BAAgD;AAGlD,MAAM,uBAAuB;AAC7B,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAGlB,MAAM,wBAAwB;AA2B9B,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,MAAM;AACR,GAM4B;AAC1B,MAAI,aAAa,UAAa,QAAQ,QAAW;AAC/C,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,MAAM;AAAA,MACJ,aAAa;AAAA,MACb;AAAA,MACA,KAAK,OAAO,YAAY;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX;AACF;AA3BgB;AAoCT,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA,MAAM;AACR,GAG4B;AAC1B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,MAAM,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAdgB;AAsBT,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAM;AACR,GAQ4B;AAC1B,MAAI,MAAM,SAAS,GAAG,GAAG;AACvB,UAAM,IAAI;AAAA,MACR,iFAAiF,KAAK;AAAA,IACxF;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,MAAM;AAAA,MACJ;AAAA,MACA,aAAa;AAAA,MACb;AAAA,MACA,GAAI,SAAS,SAAY,EAAE,KAAK,IAAI,CAAC;AAAA,MACrC,GAAI,QAAQ,SAAY,EAAE,IAAI,IAAI,CAAC;AAAA,MACnC,GAAI,mBAAmB,SACnB,EAAE,iBAAiB,eAAe,IAClC,CAAC;AAAA,IACP;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAtCgB;AAgDhB,eAAsB,UAAU;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AACf,GAKoB;AAClB,QAAM,SAAS,MAAM,KAAK;AAAA,IACxB,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,MAAM,EAAE,YAAY,WAAW,UAAU,QAAQ;AAAA,EACnD,CAAC;AACD,SAAO,OAAO,UAAU,GAAG;AAC7B;AAjBsB;AAuBtB,eAAsB,gBAAgB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AACf,GAK4C;AAC1C,QAAM,SAAU,MAAM,KAAK;AAAA,IACzB,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,MAAM,EAAE,YAAY,WAAW,WAAW,SAAS;AAAA,EACrD,CAAC;AACD,MAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,SAAS,QAAQ;AAC/D,UAAM,IAAI;AAAA,MACR,gCAAgC,MAAM,QAAQ,MAAM,IAAI,OAAO,SAAS,OAAO,MAAM,gBAAgB,SAAS,MAAM;AAAA,IACtH;AAAA,EACF;AACA,SAAO,OAAO;AAAA,IACZ,SAAS,IAAI,CAAC,SAAS,UAAU,CAAC,SAAS,OAAO,OAAO,KAAK,KAAK,GAAG,CAAC,CAAC;AAAA,EAC1E;AACF;AAxBsB;","names":[]}