@elsoul/erpc-sdk 0.6.0 → 0.8.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 CHANGED
@@ -1,9 +1,10 @@
1
1
  # `@elsoul/erpc-sdk`
2
2
 
3
3
  Official type-safe TypeScript client for [ERPC](https://erpc.global). Use one
4
- client and one API key for Solana, Ethereum, Avalanche C/P/X chains, price data,
4
+ client and an API key for Solana, Ethereum, Avalanche C/P/X chains, price data,
5
5
  indexed data, leader and validator data, analytics, subscriptions, and account
6
- information.
6
+ information. Caller-owned direct endpoints can be selected for Solana,
7
+ Ethereum, and Avalanche C-Chain JSON-RPC.
7
8
 
8
9
  ## Install
9
10
 
@@ -36,6 +37,265 @@ erpc.close()
36
37
  JSON-RPC method calls return pending requests. Call `.send()` to perform the
37
38
  network request.
38
39
 
40
+ ## Direct RPC endpoints (introduced in 0.8.0)
41
+
42
+ Caller-owned direct endpoint overrides were introduced in `0.8.0` and require
43
+ that package when installed from a registry. The `0.7.0` package does not
44
+ include this API; check the package version badge and the [latest GitHub
45
+ release](https://github.com/elsoul/erpc-sdk/releases/latest) for live
46
+ publication status.
47
+
48
+ Use a caller-owned endpoint without an eRPC API key by supplying at least one
49
+ chain override. The HTTP URL is the complete JSON-RPC request target, so its
50
+ path and query are preserved:
51
+
52
+ ```ts
53
+ const erpc = createErpcClient({
54
+ ethereumRpc: {
55
+ httpUrl: 'https://node.example/customer/path?region=eu',
56
+ },
57
+ })
58
+
59
+ const chainId = await erpc.ethereum.rpc.eth_chainId().send()
60
+ ```
61
+
62
+ The configured HTTP URL is treated as the final target. Redirect responses are
63
+ returned as HTTP errors, and no redirected request is made.
64
+
65
+ Direct HTTP requests use `credentials: 'omit'`, so ambient browser cookies and
66
+ authentication are not sent implicitly. Add authentication explicitly through
67
+ the endpoint's scoped headers when needed.
68
+
69
+ Provide an independent WebSocket URL and headers when the node requires them:
70
+
71
+ ```ts
72
+ import type { RpcEndpointConfig } from '@elsoul/erpc-sdk'
73
+
74
+ const ethereumRpc: RpcEndpointConfig = {
75
+ httpUrl: 'https://node.example/rpc',
76
+ webSocketUrl: 'wss://node.example/socket',
77
+ headers: {
78
+ authorization: 'Bearer node-token',
79
+ },
80
+ }
81
+
82
+ const erpc = createErpcClient({
83
+ ethereumRpc,
84
+ })
85
+ ```
86
+
87
+ `solanaRpc`, `ethereumRpc`, and `avalancheCRpc` select direct Solana, Ethereum,
88
+ and Avalanche C-Chain JSON-RPC transports. Without an API key, non-overridden
89
+ chains and ERPC REST, native, and index services fail locally. The
90
+ `RpcEndpointConfig.headers` field applies to direct HTTP requests only; those
91
+ headers are never sent on WSS connections.
92
+
93
+ ## Offline token catalog
94
+
95
+ The token catalog is bundled with the package, so lookups do not need an
96
+ `ErpcClient`, API key, or network request. Deployment IDs are opaque and the
97
+ chain aliases expose those IDs directly:
98
+
99
+ ```ts
100
+ import {
101
+ TOKEN_CHAIN_IDS,
102
+ findTokenDeploymentsBySymbol,
103
+ listTokenDeployments,
104
+ tokens,
105
+ } from '@elsoul/erpc-sdk'
106
+
107
+ const usdcByChain = {
108
+ ethereum: findTokenDeploymentsBySymbol(
109
+ TOKEN_CHAIN_IDS.ethereumMainnet,
110
+ 'USDC',
111
+ ),
112
+ solana: findTokenDeploymentsBySymbol(TOKEN_CHAIN_IDS.solanaMainnet, 'USDC'),
113
+ avalancheC: findTokenDeploymentsBySymbol(
114
+ TOKEN_CHAIN_IDS.avalancheCMainnet,
115
+ 'USDC',
116
+ ),
117
+ }
118
+
119
+ const canonicalEthereumUsdcId = tokens.ethereum.USDC
120
+ const usdDeployments = listTokenDeployments({ stableCurrency: 'USD' })
121
+ ```
122
+
123
+ The result includes every matching deployment and its status, decimals,
124
+ standard, address, and flattened asset metadata. See the
125
+ [canonical registry guide](https://github.com/elsoul/erpc-sdk/blob/main/registry/README.md)
126
+ for the source data and ID policy.
127
+
128
+ ## Offline token rankings
129
+
130
+ Ranking data is bundled as an immutable snapshot and is available without an
131
+ API key or network request:
132
+
133
+ ```ts
134
+ import {
135
+ TOKEN_CHAIN_IDS,
136
+ TOKEN_RANKINGS_METADATA,
137
+ listTokenRankings,
138
+ } from '@elsoul/erpc-sdk'
139
+
140
+ const ethereumRankings = listTokenRankings(TOKEN_CHAIN_IDS.ethereumMainnet)
141
+ console.log({ status: TOKEN_RANKINGS_METADATA.status, ethereumRankings })
142
+ ```
143
+
144
+ Rows use the reviewed ranking metric recorded in
145
+ `TOKEN_RANKINGS_METADATA`. For the native total-supply-value metric, values are
146
+ exact rational values in atomic native units. The snapshot can be unconfigured
147
+ or partial, has no current-time filtering, and does not fetch live prices or
148
+ supply data; check its metadata before presenting a ranking as current.
149
+
150
+ ## Offline DEX and pool catalog
151
+
152
+ DEX deployments, pool addresses, native/wrapped relationships, and
153
+ chain-qualified aliases are bundled as generated data. These lookups are
154
+ offline and use opaque IDs, so an Ethereum USDC address cannot be confused
155
+ with an Avalanche or Solana deployment:
156
+
157
+ The reviewed DEX catalog and swap exports were introduced in `0.7.0`.
158
+ Unsigned EVM preparation and simulation below were introduced in `0.8.0` and
159
+ require that package.
160
+
161
+ ```ts
162
+ import {
163
+ DEX_CHAIN_IDS,
164
+ dexes,
165
+ findPoolDefinitionsByPair,
166
+ getNativeWrapDefinition,
167
+ pools,
168
+ tokens,
169
+ } from '@elsoul/erpc-sdk'
170
+
171
+ const ethereumPools = findPoolDefinitionsByPair(
172
+ DEX_CHAIN_IDS.ethereum,
173
+ tokens.ethereum.WETH,
174
+ tokens.ethereum.USDC,
175
+ )
176
+ const uniswap = dexes.ethereum.UNISWAP_V2
177
+ const weth = getNativeWrapDefinition(tokens.ethereum.ETH)
178
+ const pool = pools.ethereum.UNISWAP_V2_USDC_WETH
179
+ ```
180
+
181
+ The reviewed Ethereum Uniswap V2 and Avalanche LFJ legacy constant-product
182
+ pools support RPC-only exact-input quotes. Solana Orca and Raydium records are
183
+ available for lookup while their CLMM quote adapters are being added. Catalog
184
+ growth adds lookup and monitoring data; it does not implicitly add swap
185
+ eligibility:
186
+
187
+ ```ts
188
+ const quote = await erpc.swap.quoteExactInput({
189
+ chainId: DEX_CHAIN_IDS.ethereum,
190
+ poolDefinitionId: pool,
191
+ inputTokenDeploymentId: tokens.ethereum.WETH,
192
+ outputTokenDeploymentId: tokens.ethereum.USDC,
193
+ amountIn: '1000000000000000000',
194
+ })
195
+
196
+ console.log(quote.amountOut)
197
+ ```
198
+
199
+ Quotes read the configured EVM RPC at one EIP-1898 block snapshot and apply
200
+ the constant-product formula locally. The request does not build, sign,
201
+ simulate, or broadcast a transaction; route selection, slippage, bridging,
202
+ and Solana CLMM execution are separate capabilities.
203
+
204
+ The two reviewed EVM pools also support unsigned ERC-20 exact-input
205
+ preparation and RPC simulation:
206
+
207
+ ```ts
208
+ const request = {
209
+ chainId: DEX_CHAIN_IDS.ethereum,
210
+ poolDefinitionId: 'pool-0001',
211
+ inputTokenDeploymentId: tokens.ethereum.WETH,
212
+ outputTokenDeploymentId: tokens.ethereum.USDC,
213
+ amountIn: '1000000000000000000',
214
+ sender: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
215
+ recipient: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
216
+ slippageBps: 50,
217
+ deadline: String(Math.floor(Date.now()/1000)+300),
218
+ }
219
+
220
+ const prepared = await erpc.swap.prepareExactInputSwap(request)
221
+
222
+ const simulation = await erpc.swap.simulateExactInputSwap(request)
223
+ ```
224
+
225
+ Preparation performs a fresh quote, validates the reviewed router and wrapped
226
+ native deployment, and returns an immutable chain-bound unsigned transaction
227
+ envelope. It does not create approval calldata, sign, send, or fill wallet
228
+ fields. When a wallet API needs a raw transaction object, explicitly convert
229
+ the envelope, for example:
230
+
231
+ ```ts
232
+ const { chainId: _chainId, kind: _kind, ...walletTransaction } =
233
+ prepared.transaction
234
+ await wallet.sendTransaction(walletTransaction)
235
+ ```
236
+
237
+ Use the `simulation` result to inspect the canonical allowance and router
238
+ amounts before asking the caller's wallet to manage allowance, signing, or
239
+ broadcasting. The simulation call itself is read-only and uses only the
240
+ configured RPC transport.
241
+
242
+ ## Optional Mayan Swift v2 bridge (introduced in 0.8.0)
243
+
244
+ The `0.8.0` API adds the Mayan Swift v2 client as an explicit standalone adapter
245
+ for the reviewed
246
+ issued EURC routes between Ethereum and Solana. It is not attached to the
247
+ default `ErpcClient`; construct it separately when the external provider and
248
+ its solver, relayer, and explorer dependencies are acceptable:
249
+
250
+ ```ts
251
+ import {
252
+ createMayanSwiftV2BridgeClient,
253
+ TOKEN_CHAIN_IDS,
254
+ } from '@elsoul/erpc-sdk'
255
+
256
+ const mayan = createMayanSwiftV2BridgeClient({
257
+ builderEndpoint: 'https://tx-builder.mayan.finance',
258
+ explorerEndpoint: 'https://explorer-api.mayan.finance/v3',
259
+ builderApiKey: 'provider-key',
260
+ })
261
+ const quotes = await mayan.quoteExactInput({
262
+ sourceChainId: TOKEN_CHAIN_IDS.ethereumMainnet,
263
+ destinationChainId: TOKEN_CHAIN_IDS.solanaMainnet,
264
+ sourceTokenDeploymentId: 'deployment-0011',
265
+ destinationTokenDeploymentId: 'deployment-0013',
266
+ amountIn: '1000000',
267
+ slippageBps: 50,
268
+ })
269
+ ```
270
+
271
+ The adapter posts the exact route request to Mayan's `/quote`, preserves the
272
+ provider-signed quote text, and can build a structurally checked unsigned
273
+ source transaction with `buildUnsigned`. It does not verify the provider
274
+ signature locally or prove settlement, and it does not sign, approve, submit,
275
+ refund, or broadcast transactions. For an EVM build, convert the returned
276
+ chain-bound envelope before passing fields to a wallet API:
277
+
278
+ ```ts
279
+ const built = await mayan.buildUnsigned({
280
+ quote: quotes[0],
281
+ swapperAddress: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
282
+ destinationAddress: '11111111111111111111111111111111',
283
+ })
284
+ if (built.transaction.kind === 'evm-unsigned-transaction') {
285
+ const { chainId: _chainId, kind: _kind, ...walletTransaction } =
286
+ built.transaction
287
+ await wallet.sendTransaction(walletTransaction)
288
+ }
289
+ ```
290
+
291
+ `builderEndpoint` and `explorerEndpoint` default to
292
+ `https://tx-builder.mayan.finance` and `https://explorer-api.mayan.finance/v3`;
293
+ set them to caller-approved base URLs to customize the provider endpoints.
294
+ `getStatus` reads the indexed status endpoint and reports the provider assertion
295
+ as unverified local settlement state. `builderApiKey` is a separate Mayan
296
+ build-only key sent only to `/build`; quote and status calls do not receive it,
297
+ and no eRPC credential is forwarded.
298
+
39
299
  ## Namespaces
40
300
 
41
301
  | Namespace | Purpose |
@@ -141,6 +401,7 @@ const result = await erpc.solana.rpc
141
401
  ## Documentation
142
402
 
143
403
  - [Complete guide](https://github.com/elsoul/erpc-sdk#readme)
404
+ - [Solana transaction v1 guide](https://github.com/elsoul/erpc-sdk/blob/main/packages/typescript/docs/solana-v1.md)
144
405
  - [Method availability](https://github.com/elsoul/erpc-sdk/blob/main/docs/METHODS.md)
145
406
  - [Roadmap](https://github.com/elsoul/erpc-sdk/blob/main/ROADMAP.md)
146
407
  - [Security policy](https://github.com/elsoul/erpc-sdk/blob/main/SECURITY.md)