@fluent.xyz/connect 0.7.2 → 0.8.1-rc.1

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.
@@ -1,12 +1,13 @@
1
1
  import { Address, Transport, Chain, PublicClient } from 'viem';
2
- import { F as FluentBatchCallInput } from './batchOperation-CIcgSRv5.js';
3
- export { g as getFluentExplorerBaseUrl, i as isFaucetNetwork, n as normalizeFluentWidgetNetwork } from './batchOperation-CIcgSRv5.js';
2
+ import { F as FluentBatchCallInput } from './batchOperation-B5Fd0-QX.js';
3
+ export { g as getFluentExplorerBaseUrl, i as isFaucetNetwork, n as normalizeFluentWidgetNetwork } from './batchOperation-B5Fd0-QX.js';
4
4
 
5
5
  type FluentNetworkName = "testnet" | "mainnet";
6
6
  /**
7
- * A token as the widget's own lists declare it: a Default token, `native` marking the chain's
8
- * own currency and `gasPriority` its place among the Gas tokens (ADR 0001). Not the root entry's
9
- * `FluentTokenDefinition`, an Integrator token, which carries neither field.
7
+ * A token as the widget's lists hold it: `native` marks the chain's own currency and
8
+ * `gasPriority` its place among the Gas tokens (ADR 0001), and `mergeFluentDisplayTokens` keeps
9
+ * either field only on a Default token. Not the root entry's `FluentTokenDefinition`, an
10
+ * Integrator token, which carries neither field.
10
11
  */
11
12
  type FluentTokenDefinition = {
12
13
  chainId: number;
@@ -18,11 +19,12 @@ type FluentTokenDefinition = {
18
19
  native?: true;
19
20
  gasPriority?: number;
20
21
  };
21
- /** Whether `token` is the chain's own currency, read from `native` alone. */
22
+ /** Reports whether `token` is the chain's own currency, read from `native` alone. */
22
23
  declare function isFluentNativeToken(token: Pick<FluentTokenDefinition, "native">): boolean;
23
24
  /**
24
- * The Token identity: `<chainId>:<address>`, the address lowercased; `<chainId>:native` for the
25
- * chain's own currency and `<chainId>:unknown` for a token with no address.
25
+ * Returns the Token identity of `token`: `<chainId>:<address>`, the address lowercased;
26
+ * `<chainId>:native` for the chain's own currency and `<chainId>:unknown` for a token with no
27
+ * address.
26
28
  */
27
29
  declare function fluentTokenIdentity(token: Pick<FluentTokenDefinition, "chainId" | "address" | "native">): string;
28
30
  /**
@@ -89,7 +91,7 @@ declare const fluentMainnetTokenDefaults: {
89
91
  readonly gasPriority: 1;
90
92
  };
91
93
  };
92
- /** The Default tokens of a Network, by symbol: mainnet's for `"mainnet"`, testnet's otherwise. */
94
+ /** Returns the Default tokens of a Network, by symbol: mainnet's or else testnet's. */
93
95
  declare function getFluentTokenDefaultsForNetwork(network: FluentNetworkName): {
94
96
  readonly ETH: {
95
97
  readonly chainId: 20994;
@@ -141,13 +143,16 @@ declare function getFluentTokenDefaultsForNetwork(network: FluentNetworkName): {
141
143
  readonly gasPriority: 1;
142
144
  };
143
145
  };
144
- /** The Default tokens of a Network in the order the widget shows them, Gas tokens first. */
146
+ /**
147
+ * Returns the Default tokens of a Network in the order the widget lists them, the order their
148
+ * defaults object declares; every call for a Network returns the same frozen array.
149
+ */
145
150
  declare function getFluentDefaultWidgetDisplayTokens(network: FluentNetworkName): readonly FluentTokenDefinition[];
146
151
  /**
147
152
  * Reads `account`'s balance of each of `tokens` through `client`, all in parallel: the chain's
148
153
  * balance for a native token, `balanceOf` for the rest. A token with neither `native` nor an
149
154
  * address comes back `"not-configured"`, a read that throws comes back `"error"` with the
150
- * message; the call itself never rejects for one token.
155
+ * message; the call itself never rejects for one token's failure.
151
156
  *
152
157
  * @example
153
158
  * ```ts
@@ -192,15 +197,15 @@ type FluentFamiliesClientConfig = {
192
197
  baseUrl: string;
193
198
  fetch?: typeof globalThis.fetch;
194
199
  };
195
- /** Reads one person's families by their Privy DID; see `createFluentFamiliesClient`. */
200
+ /** A client of one person's families, read by their Privy DID; see `createFluentFamiliesClient`. */
196
201
  type FluentFamiliesClient = {
197
202
  getFamilies: (privyId: string) => Promise<FluentFamilies>;
198
203
  };
199
204
  /**
200
- * A client of the service's families endpoint,
201
- * `GET <baseUrl>/profile/families/?privy_id=<id>`. `getFamilies` rejects with an `Error`
202
- * carrying the service's message when the response is not `ok`, and with "Privy ID is
203
- * required" for a blank id.
205
+ * Creates a client of the service's families endpoint,
206
+ * `GET <baseUrl>/profile/families/?privy_id=<id>`. `getFamilies` throws an `Error` with the
207
+ * service's message, or `Request failed with <status>` when it sends none, for a response that
208
+ * is not `ok`, and an `Error` "Privy ID is required" for a blank id without calling the service.
204
209
  *
205
210
  * @example
206
211
  * ```ts
@@ -239,9 +244,19 @@ type FluentTransferRecipient = {
239
244
  message: string;
240
245
  };
241
246
  /**
242
- * The address a transfer would pay. Rejected rather than merely unparsed for
243
- * the two destinations that look valid and still lose the money: the sending
244
- * account itself, and a token's own contract.
247
+ * Parses the recipient typed for a transfer. Besides an input that is not an address or fails
248
+ * its checksum, it refuses the two destinations that look valid and still lose the money: the
249
+ * sending account itself (`self`), and a token's own contract (`contracts`).
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { parseFluentTransferRecipient } from "@fluent.xyz/connect/internal";
254
+ *
255
+ * const recipient = parseFluentTransferRecipient({
256
+ * input: "0x000000000000000000000000000000000000dEaD",
257
+ * });
258
+ * console.log(recipient.status); // "ok"
259
+ * ```
245
260
  */
246
261
  declare function parseFluentTransferRecipient(params: {
247
262
  input: string;
@@ -261,11 +276,25 @@ type FluentTransferAmount = {
261
276
  message: string;
262
277
  };
263
278
  /**
264
- * The amount a transfer would move, in the token's own base units.
279
+ * Parses the amount typed for a transfer into the token's base units. It refuses an input that
280
+ * is not a plain decimal number (a comma, a sign, an exponent), has more decimals than the
281
+ * token, is 0, or exceeds `balance`.
282
+ *
283
+ * `balance` is required and not nullable on purpose: every answer is checked against it, so a
284
+ * caller whose balance has not arrived yet must wait rather than pass a stand-in.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { parseFluentTransferAmount } from "@fluent.xyz/connect/internal";
265
289
  *
266
- * `balance` is required and not nullable on purpose: every answer here is
267
- * checked against it, so a caller whose balance has not arrived yet has nothing
268
- * to validate against and must wait rather than pass a stand-in.
290
+ * const amount = parseFluentTransferAmount({
291
+ * input: "12.5",
292
+ * symbol: "USDC",
293
+ * decimals: 6,
294
+ * balance: 20_000_000n,
295
+ * });
296
+ * console.log(amount); // { status: "ok", raw: 12500000n }
297
+ * ```
269
298
  */
270
299
  declare function parseFluentTransferAmount(params: {
271
300
  input: string;
@@ -274,8 +303,21 @@ declare function parseFluentTransferAmount(params: {
274
303
  balance: bigint;
275
304
  }): FluentTransferAmount;
276
305
  /**
277
- * The one call that moves `amount` of `token` to `to`: a plain value send for
278
- * the chain's own currency, an ERC-20 `transfer` for everything else.
306
+ * Builds the one call that moves `amount` of `token` to `to`: a plain value send for the chain's
307
+ * own currency, an ERC-20 `transfer` for everything else. Throws an `Error` when a token that is
308
+ * not native has no `address`.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import { buildFluentTransferCall } from "@fluent.xyz/connect/internal";
313
+ *
314
+ * const call = buildFluentTransferCall({
315
+ * token: { symbol: "ETH", native: true },
316
+ * to: "0x000000000000000000000000000000000000dEaD",
317
+ * amount: 10n ** 15n,
318
+ * });
319
+ * console.log(call.value); // 1000000000000000n
320
+ * ```
279
321
  */
280
322
  declare function buildFluentTransferCall(params: {
281
323
  token: Pick<FluentTokenDefinition, "address" | "symbol" | "native">;
@@ -284,9 +326,17 @@ declare function buildFluentTransferCall(params: {
284
326
  }): FluentBatchCallInput;
285
327
 
286
328
  /**
287
- * The portal bridge URL with `recipient` as a query parameter, so the Deposit is credited to that
288
- * account; `bridgeUrl` itself when there is no recipient. A `bridgeUrl` the `URL` parser refuses
289
- * gets the parameter appended as text.
329
+ * Returns the portal bridge URL with `recipient` as a query parameter, so the Deposit made there
330
+ * is credited to that account; `bridgeUrl` itself when there is no recipient. A `bridgeUrl` the
331
+ * `URL` parser refuses gets the parameter appended as text.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * import { buildFluentBridgeUrl } from "@fluent.xyz/connect/internal";
336
+ *
337
+ * buildFluentBridgeUrl("https://portal.fluent.xyz/user/bridge", "0xabc123");
338
+ * // "https://portal.fluent.xyz/user/bridge?recipient=0xabc123"
339
+ * ```
290
340
  */
291
341
  declare function buildFluentBridgeUrl(bridgeUrl: string, recipient?: string | null): string;
292
342
 
package/dist/internal.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { parseAbi, defineChain, formatUnits, isAddress, parseUnits } from 'viem';
2
3
 
3
4
  var __defProp = Object.defineProperty;
@@ -19,9 +20,7 @@ var fluent_mainnet_default = {
19
20
  },
20
21
  rpcUrls: {
21
22
  default: {
22
- http: [
23
- "https://rpc.fluent.xyz/"
24
- ]
23
+ http: ["https://rpc.fluent.xyz/"]
25
24
  }
26
25
  },
27
26
  blockExplorers: {
@@ -65,12 +64,8 @@ var fluent_testnet_default = {
65
64
  },
66
65
  rpcUrls: {
67
66
  default: {
68
- http: [
69
- "https://rpc.testnet.fluent.xyz/"
70
- ],
71
- webSocket: [
72
- "wss://rpc.testnet.fluent.xyz/ws"
73
- ]
67
+ http: ["https://rpc.testnet.fluent.xyz/"],
68
+ webSocket: ["wss://rpc.testnet.fluent.xyz/ws"]
74
69
  }
75
70
  },
76
71
  blockExplorers: {
@@ -80,9 +75,7 @@ var fluent_testnet_default = {
80
75
  }
81
76
  },
82
77
  infoURL: "https://docs.fluent.xyz/",
83
- faucets: [
84
- "https://testnet.fluent.xyz/dev-portal"
85
- ],
78
+ faucets: ["https://testnet.fluent.xyz/dev-portal"],
86
79
  parent: {
87
80
  type: "L2",
88
81
  chainId: 11155111,
@@ -177,9 +170,7 @@ var sepolia_default = {
177
170
  },
178
171
  rpcUrls: {
179
172
  default: {
180
- http: [
181
- "https://ethereum-sepolia-rpc.publicnode.com"
182
- ]
173
+ http: ["https://ethereum-sepolia-rpc.publicnode.com"]
183
174
  }
184
175
  },
185
176
  blockExplorers: {
@@ -4390,10 +4381,13 @@ var appSchema = external_exports.object({
4390
4381
  category: external_exports.string(),
4391
4382
  description: external_exports.string().optional(),
4392
4383
  docs: external_exports.string().url().optional(),
4393
- deployments: external_exports.record(external_exports.string(), external_exports.object({
4394
- contract: external_exports.string(),
4395
- address: addressSchema
4396
- }))
4384
+ deployments: external_exports.record(
4385
+ external_exports.string(),
4386
+ external_exports.object({
4387
+ contract: external_exports.string(),
4388
+ address: addressSchema
4389
+ })
4390
+ )
4397
4391
  });
4398
4392
  var zerodevIntegrationSchema = external_exports.object({
4399
4393
  id: external_exports.literal("zerodev"),
@@ -4445,17 +4439,13 @@ function fluentDefinitionToViemChain(definition) {
4445
4439
  viemContracts.fluentBridge = toContract(contracts.fluentBridge);
4446
4440
  }
4447
4441
  if (contracts?.universalTokenFactory) {
4448
- viemContracts.universalTokenFactory = toContract(
4449
- contracts.universalTokenFactory
4450
- );
4442
+ viemContracts.universalTokenFactory = toContract(contracts.universalTokenFactory);
4451
4443
  }
4452
4444
  if (contracts?.paymentGateway) {
4453
4445
  viemContracts.paymentGateway = toContract(contracts.paymentGateway);
4454
4446
  }
4455
4447
  if (contracts?.peggedTokenPrecompile) {
4456
- viemContracts.peggedTokenPrecompile = toContract(
4457
- contracts.peggedTokenPrecompile
4458
- );
4448
+ viemContracts.peggedTokenPrecompile = toContract(contracts.peggedTokenPrecompile);
4459
4449
  }
4460
4450
  return defineChain({
4461
4451
  id: definition.chainId,
@@ -4555,10 +4545,9 @@ function getFluentTokenDefaultsForNetwork(network) {
4555
4545
  }
4556
4546
  }
4557
4547
  new Set(
4558
- [
4559
- ...Object.values(fluentTestnetTokenDefaults),
4560
- ...Object.values(fluentMainnetTokenDefaults)
4561
- ].map(fluentTokenIdentity)
4548
+ [...Object.values(fluentTestnetTokenDefaults), ...Object.values(fluentMainnetTokenDefaults)].map(
4549
+ fluentTokenIdentity
4550
+ )
4562
4551
  );
4563
4552
  function sortFluentGasTokens(tokens) {
4564
4553
  return tokens.filter((token) => token.gasPriority !== void 0).sort((left, right) => left.gasPriority - right.gasPriority);
@@ -4587,7 +4576,8 @@ async function readFluentTokenBalances(params) {
4587
4576
  return Promise.all(
4588
4577
  params.tokens.map(async (token) => {
4589
4578
  const native = isFluentNativeToken(token);
4590
- if (!native && !token.address) {
4579
+ const address = native ? void 0 : token.address;
4580
+ if (!native && !address) {
4591
4581
  return {
4592
4582
  ...token,
4593
4583
  raw: null,
@@ -4596,12 +4586,12 @@ async function readFluentTokenBalances(params) {
4596
4586
  };
4597
4587
  }
4598
4588
  try {
4599
- const raw = native ? await params.client.getBalance({ address: params.account }) : await params.client.readContract({
4600
- address: token.address,
4589
+ const raw = address ? await params.client.readContract({
4590
+ address,
4601
4591
  abi: balanceOfAbi,
4602
4592
  functionName: "balanceOf",
4603
4593
  args: [params.account]
4604
- });
4594
+ }) : await params.client.getBalance({ address: params.account });
4605
4595
  return {
4606
4596
  ...token,
4607
4597
  raw,