@fluent.xyz/connect 0.6.3 → 0.7.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,293 @@
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';
4
+
5
+ type FluentNetworkName = "testnet" | "mainnet";
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.
10
+ */
11
+ type FluentTokenDefinition = {
12
+ chainId: number;
13
+ address?: Address;
14
+ name: string;
15
+ symbol: string;
16
+ decimals: number;
17
+ logoURI?: string;
18
+ native?: true;
19
+ gasPriority?: number;
20
+ };
21
+ /** Whether `token` is the chain's own currency, read from `native` alone. */
22
+ declare function isFluentNativeToken(token: Pick<FluentTokenDefinition, "native">): boolean;
23
+ /**
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.
26
+ */
27
+ declare function fluentTokenIdentity(token: Pick<FluentTokenDefinition, "chainId" | "address" | "native">): string;
28
+ /**
29
+ * A token with one account's balance of it, as `readFluentTokenBalances` returns it: `raw` in
30
+ * base units and `formatted` in token units while `status` is `"ready"`, both `null` otherwise.
31
+ */
32
+ type FluentTokenBalance = FluentTokenDefinition & {
33
+ raw: bigint | null;
34
+ formatted: string | null;
35
+ status: "ready" | "not-configured" | "error";
36
+ error?: string;
37
+ };
38
+ /** The Default tokens of testnet, by symbol. */
39
+ declare const fluentTestnetTokenDefaults: {
40
+ readonly ETH: {
41
+ readonly chainId: 20994;
42
+ readonly symbol: "ETH";
43
+ readonly name: "Ether";
44
+ readonly decimals: 18;
45
+ readonly native: true;
46
+ readonly gasPriority: 3;
47
+ };
48
+ readonly USDnr: {
49
+ readonly chainId: 20994;
50
+ readonly symbol: "USDnr";
51
+ readonly name: "USDnr";
52
+ readonly decimals: 6;
53
+ readonly address: "0x279a6DC6354374473f6f3CFB3999e6C2e146f8a1";
54
+ readonly gasPriority: 2;
55
+ };
56
+ readonly BLEND: {
57
+ readonly chainId: 20994;
58
+ readonly symbol: "BLEND";
59
+ readonly name: "Mock Blend";
60
+ readonly decimals: 18;
61
+ readonly address: "0x83Fed707A8dDDC2535aE591CF19fB6C91D542D8E";
62
+ readonly gasPriority: 1;
63
+ };
64
+ };
65
+ /** The Default tokens of mainnet, by symbol. */
66
+ declare const fluentMainnetTokenDefaults: {
67
+ readonly ETH: {
68
+ readonly chainId: 25363;
69
+ readonly symbol: "ETH";
70
+ readonly name: "Ether";
71
+ readonly decimals: 18;
72
+ readonly native: true;
73
+ readonly gasPriority: 3;
74
+ };
75
+ readonly USDnr: {
76
+ readonly chainId: 25363;
77
+ readonly symbol: "USDnr";
78
+ readonly name: "USDnr";
79
+ readonly decimals: 6;
80
+ readonly address: "0xD48e565561416dE59DA1050ED70b8d75e8eF28f9";
81
+ readonly gasPriority: 2;
82
+ };
83
+ readonly BLEND: {
84
+ readonly chainId: 25363;
85
+ readonly symbol: "BLEND";
86
+ readonly name: "Fluent";
87
+ readonly decimals: 18;
88
+ readonly address: "0x1385b8f55a84f2bda13eed4099d29eae03d553b2";
89
+ readonly gasPriority: 1;
90
+ };
91
+ };
92
+ /** The Default tokens of a Network, by symbol: mainnet's for `"mainnet"`, testnet's otherwise. */
93
+ declare function getFluentTokenDefaultsForNetwork(network: FluentNetworkName): {
94
+ readonly ETH: {
95
+ readonly chainId: 20994;
96
+ readonly symbol: "ETH";
97
+ readonly name: "Ether";
98
+ readonly decimals: 18;
99
+ readonly native: true;
100
+ readonly gasPriority: 3;
101
+ };
102
+ readonly USDnr: {
103
+ readonly chainId: 20994;
104
+ readonly symbol: "USDnr";
105
+ readonly name: "USDnr";
106
+ readonly decimals: 6;
107
+ readonly address: "0x279a6DC6354374473f6f3CFB3999e6C2e146f8a1";
108
+ readonly gasPriority: 2;
109
+ };
110
+ readonly BLEND: {
111
+ readonly chainId: 20994;
112
+ readonly symbol: "BLEND";
113
+ readonly name: "Mock Blend";
114
+ readonly decimals: 18;
115
+ readonly address: "0x83Fed707A8dDDC2535aE591CF19fB6C91D542D8E";
116
+ readonly gasPriority: 1;
117
+ };
118
+ } | {
119
+ readonly ETH: {
120
+ readonly chainId: 25363;
121
+ readonly symbol: "ETH";
122
+ readonly name: "Ether";
123
+ readonly decimals: 18;
124
+ readonly native: true;
125
+ readonly gasPriority: 3;
126
+ };
127
+ readonly USDnr: {
128
+ readonly chainId: 25363;
129
+ readonly symbol: "USDnr";
130
+ readonly name: "USDnr";
131
+ readonly decimals: 6;
132
+ readonly address: "0xD48e565561416dE59DA1050ED70b8d75e8eF28f9";
133
+ readonly gasPriority: 2;
134
+ };
135
+ readonly BLEND: {
136
+ readonly chainId: 25363;
137
+ readonly symbol: "BLEND";
138
+ readonly name: "Fluent";
139
+ readonly decimals: 18;
140
+ readonly address: "0x1385b8f55a84f2bda13eed4099d29eae03d553b2";
141
+ readonly gasPriority: 1;
142
+ };
143
+ };
144
+ /** The Default tokens of a Network in the order the widget shows them, Gas tokens first. */
145
+ declare function getFluentDefaultWidgetDisplayTokens(network: FluentNetworkName): readonly FluentTokenDefinition[];
146
+ /**
147
+ * Reads `account`'s balance of each of `tokens` through `client`, all in parallel: the chain's
148
+ * balance for a native token, `balanceOf` for the rest. A token with neither `native` nor an
149
+ * address comes back `"not-configured"`, a read that throws comes back `"error"` with the
150
+ * message; the call itself never rejects for one token.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import { createPublicClient, http } from "viem";
155
+ * import { fluentTestnet } from "@fluent.xyz/connect";
156
+ * import {
157
+ * getFluentDefaultWidgetDisplayTokens,
158
+ * readFluentTokenBalances,
159
+ * } from "@fluent.xyz/connect/internal";
160
+ *
161
+ * const client = createPublicClient({ chain: fluentTestnet, transport: http() });
162
+ * const balances = await readFluentTokenBalances({
163
+ * client,
164
+ * account: "0x0000000000000000000000000000000000000001",
165
+ * tokens: getFluentDefaultWidgetDisplayTokens("testnet"),
166
+ * });
167
+ * ```
168
+ */
169
+ declare function readFluentTokenBalances<TTransport extends Transport = Transport, TChain extends Chain = Chain>(params: {
170
+ client: PublicClient<TTransport, TChain>;
171
+ account: Address;
172
+ tokens: readonly FluentTokenDefinition[];
173
+ }): Promise<FluentTokenBalance[]>;
174
+
175
+ /** The tier the service assigns a person within one family. */
176
+ type FluentFamilyTier = "A" | "B" | "C" | "D";
177
+ /** The families the service scores a person in. */
178
+ type FluentFamilyType = "identity" | "tester" | "builder" | "influential" | "predictor";
179
+ /** One family's score for a person: the tier, the service's metadata and its last change. */
180
+ type FluentFamily = {
181
+ tier: FluentFamilyTier;
182
+ metadata?: Record<string, string>;
183
+ lastUpdate?: string;
184
+ };
185
+ /** The service's families answer for one person: the X handle it knows, and every family. */
186
+ type FluentFamilies = {
187
+ xHandle?: string;
188
+ families: Record<FluentFamilyType, FluentFamily>;
189
+ };
190
+ /** The service's base URL and, for a test, the `fetch` to call it with. */
191
+ type FluentFamiliesClientConfig = {
192
+ baseUrl: string;
193
+ fetch?: typeof globalThis.fetch;
194
+ };
195
+ /** Reads one person's families by their Privy DID; see `createFluentFamiliesClient`. */
196
+ type FluentFamiliesClient = {
197
+ getFamilies: (privyId: string) => Promise<FluentFamilies>;
198
+ };
199
+ /**
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.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { createFluentFamiliesClient } from "@fluent.xyz/connect/internal";
208
+ *
209
+ * const client = createFluentFamiliesClient({ baseUrl: "https://api.example.com" });
210
+ * const { families } = await client.getFamilies("did:privy:example");
211
+ * ```
212
+ */
213
+ declare function createFluentFamiliesClient(config: FluentFamiliesClientConfig): FluentFamiliesClient;
214
+
215
+ /** The ERC-20 `transfer(address,uint256)` ABI `buildFluentTransferCall` encodes with. */
216
+ declare const fluentTransferAbi: readonly [{
217
+ readonly name: "transfer";
218
+ readonly type: "function";
219
+ readonly stateMutability: "nonpayable";
220
+ readonly inputs: readonly [{
221
+ readonly type: "address";
222
+ readonly name: "to";
223
+ }, {
224
+ readonly type: "uint256";
225
+ readonly name: "amount";
226
+ }];
227
+ readonly outputs: readonly [{
228
+ readonly type: "bool";
229
+ }];
230
+ }];
231
+ /** `parseFluentTransferRecipient`'s answer: an address, nothing typed yet, or why it is refused. */
232
+ type FluentTransferRecipient = {
233
+ status: "ok";
234
+ address: Address;
235
+ } | {
236
+ status: "empty";
237
+ } | {
238
+ status: "rejected";
239
+ message: string;
240
+ };
241
+ /**
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.
245
+ */
246
+ declare function parseFluentTransferRecipient(params: {
247
+ input: string;
248
+ /** The account the funds leave, which can never be where they arrive. */
249
+ self?: string;
250
+ /** Contract addresses of the listed tokens, lowercased. */
251
+ contracts?: ReadonlySet<string>;
252
+ }): FluentTransferRecipient;
253
+ /** `parseFluentTransferAmount`'s answer: base units, nothing typed yet, or why it is refused. */
254
+ type FluentTransferAmount = {
255
+ status: "ok";
256
+ raw: bigint;
257
+ } | {
258
+ status: "empty";
259
+ } | {
260
+ status: "rejected";
261
+ message: string;
262
+ };
263
+ /**
264
+ * The amount a transfer would move, in the token's own base units.
265
+ *
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.
269
+ */
270
+ declare function parseFluentTransferAmount(params: {
271
+ input: string;
272
+ symbol: string;
273
+ decimals: number;
274
+ balance: bigint;
275
+ }): FluentTransferAmount;
276
+ /**
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.
279
+ */
280
+ declare function buildFluentTransferCall(params: {
281
+ token: Pick<FluentTokenDefinition, "address" | "symbol" | "native">;
282
+ to: Address;
283
+ amount: bigint;
284
+ }): FluentBatchCallInput;
285
+
286
+ /**
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.
290
+ */
291
+ declare function buildFluentBridgeUrl(bridgeUrl: string, recipient?: string | null): string;
292
+
293
+ export { type FluentFamilies, type FluentFamiliesClient, type FluentFamiliesClientConfig, type FluentFamily, type FluentFamilyTier, type FluentFamilyType, type FluentTokenBalance, type FluentTokenDefinition, type FluentTransferAmount, type FluentTransferRecipient, buildFluentBridgeUrl, buildFluentTransferCall, createFluentFamiliesClient, fluentMainnetTokenDefaults, fluentTestnetTokenDefaults, fluentTokenIdentity, fluentTransferAbi, getFluentDefaultWidgetDisplayTokens, getFluentTokenDefaultsForNetwork, isFluentNativeToken, parseFluentTransferAmount, parseFluentTransferRecipient, readFluentTokenBalances };