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.
- checksums.yaml +4 -4
- data/README.md +245 -0
- data/lib/erpc_sdk/bridge.rb +1507 -0
- data/lib/erpc_sdk/client.rb +215 -76
- data/lib/erpc_sdk/config.rb +107 -8
- data/lib/erpc_sdk/dex_catalog.rb +207 -0
- data/lib/erpc_sdk/errors.rb +100 -9
- data/lib/erpc_sdk/generated/bridge_capabilities.rb +9 -0
- data/lib/erpc_sdk/generated/dex_catalog.rb +28 -0
- data/lib/erpc_sdk/generated/swap_execution_capabilities.rb +11 -0
- data/lib/erpc_sdk/generated/token_catalog.rb +216 -0
- data/lib/erpc_sdk/generated/token_rankings.rb +25 -0
- data/lib/erpc_sdk/swap.rb +1367 -0
- data/lib/erpc_sdk/token_catalog.rb +170 -0
- data/lib/erpc_sdk/token_rankings.rb +50 -0
- data/lib/erpc_sdk/transport.rb +69 -20
- data/lib/erpc_sdk/version.rb +1 -1
- data/lib/erpc_sdk/websocket.rb +45 -13
- data/lib/erpc_sdk.rb +5 -0
- metadata +12 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1e41b728c27ddf8d794aa91d44a2503204b00f6953580d0db2498d44a5b041b
|
|
4
|
+
data.tar.gz: 5dc759af0fe505cd30f6fb45cf43344687d2df1f7aff34cb4b66b8e787419e8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 982fb52b52b3e88855eb4405aece06bf5f76518202cd990458ae9955b1796b4756cd61db2373b86072e75db60f4371d9674a4d7b4e927b7deba898a47130bc26
|
|
7
|
+
data.tar.gz: d174e090167c4a1b45a2b35f7d19dacffad5e57b5d8842fbf9335c9c4354f4df7df9c08fa83665ec9f97376f60fc4678696ac39f0e54f5499b664b9333146bed
|
data/README.md
CHANGED
|
@@ -28,11 +28,256 @@ ensure
|
|
|
28
28
|
end
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
## Dedicated RPC endpoints (introduced in 0.8.0)
|
|
32
|
+
|
|
33
|
+
Supply a full HTTP(S) JSON-RPC URL to use a customer-owned node without an
|
|
34
|
+
eRPC API key. The URL path and query are sent exactly as provided. Direct URLs
|
|
35
|
+
are final HTTP request targets; the Ruby adapter does not follow redirects.
|
|
36
|
+
Caller-owned direct endpoint overrides were introduced in `0.8.0` and require
|
|
37
|
+
that gem version when installed from a registry. The published `0.7.0` gem does
|
|
38
|
+
not include them; check the package version badge and the [latest GitHub
|
|
39
|
+
release](https://github.com/elsoul/erpc-sdk/releases/latest) for live
|
|
40
|
+
publication status.
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
config = ERPC::ClientConfig.new(
|
|
44
|
+
ethereum_rpc: ERPC::RpcEndpointConfig.new(
|
|
45
|
+
http_url: "https://node.example/rpc/customer?token=..."
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
erpc = ERPC::Client.new(config)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
An independent WebSocket URL enables subscriptions. Scoped headers apply to
|
|
52
|
+
direct HTTP requests for that RPC endpoint.
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
config = ERPC::ClientConfig.new(
|
|
56
|
+
ethereum_rpc: ERPC::RpcEndpointConfig.new(
|
|
57
|
+
http_url: "https://node.example/rpc",
|
|
58
|
+
websocket_url: "wss://ws.example/socket?token=...",
|
|
59
|
+
headers: { "authorization" => "Bearer node-token" }
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Offline token catalog
|
|
65
|
+
|
|
66
|
+
The gem bundles a generated token catalog for Ethereum, Solana, and Avalanche
|
|
67
|
+
C-Chain. Lookups are synchronous and offline: they do not need a client, API
|
|
68
|
+
key, registry checkout, JSON parsing, or network access.
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
require "erpc_sdk"
|
|
72
|
+
|
|
73
|
+
ethereum_usdc = ERPC::TokenCatalog.find_token_deployments_by_symbol(
|
|
74
|
+
ERPC::TokenChainIDs::ETHEREUM_MAINNET,
|
|
75
|
+
"USDC"
|
|
76
|
+
).first
|
|
77
|
+
native_sol = ERPC::TokenCatalog.get_native_token_deployment(
|
|
78
|
+
ERPC::TokenChainIDs::SOLANA_MAINNET
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
puts ethereum_usdc.fetch(:decimals) # 6
|
|
82
|
+
puts native_sol.fetch(:symbol) # SOL
|
|
83
|
+
puts ERPC::Tokens::Ethereum.fetch(:USDC) # opaque deployment ID
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Deployment records include their flattened asset identity, chain ID, symbol,
|
|
87
|
+
decimals, standard, address, lifecycle status, and replacement reference. Use
|
|
88
|
+
`list_token_deployments(chain_id: ..., stable_currency: ...)` to filter while
|
|
89
|
+
keeping legacy, winding-down, and retired records visible. The canonical
|
|
90
|
+
registry and its evidence are documented in the [token catalog registry
|
|
91
|
+
README](https://github.com/elsoul/erpc-sdk/blob/main/registry/README.md).
|
|
92
|
+
|
|
93
|
+
## Offline token rankings
|
|
94
|
+
|
|
95
|
+
The gem also bundles the generated token-ranking snapshot. Ranking metadata
|
|
96
|
+
uses the exact `schema_version`, `metric`, `as_of`, `content_digest`,
|
|
97
|
+
`status`, `coverage`, and `source_ids` fields from the registry, and all
|
|
98
|
+
nested values are frozen. Read the bundled metadata for the current `status`,
|
|
99
|
+
`metric`, `as_of`, `content_digest`, and `coverage` before presenting a result
|
|
100
|
+
as current; the metadata is the source of truth for whether rows are available
|
|
101
|
+
and how much coverage they represent.
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
rankings = ERPC::TokenRankings.list_token_rankings(
|
|
105
|
+
ERPC::TokenChainIDs::ETHEREUM_MAINNET
|
|
106
|
+
)
|
|
107
|
+
puts ERPC::TokenRankings::TOKEN_RANKINGS_METADATA.fetch(:status)
|
|
108
|
+
puts rankings.length
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`list_token_rankings` matches the complete chain ID exactly. Empty, unknown,
|
|
112
|
+
and special strings return the same frozen empty array. It never performs
|
|
113
|
+
network I/O, reads the current clock, or filters by observation time.
|
|
114
|
+
|
|
115
|
+
When a reviewed snapshot is populated, the approved native metric represents
|
|
116
|
+
total supply multiplied by the direct native-pool price. It does not represent
|
|
117
|
+
circulating market capitalization. Coverage remains explicit in metadata and
|
|
118
|
+
may be `partial`; unavailable observations stay out of ranked rows rather than
|
|
119
|
+
being treated as zero.
|
|
120
|
+
|
|
121
|
+
## Offline DEX and pool catalog
|
|
122
|
+
|
|
123
|
+
The source tree bundles the generated DEX deployment, pool, and native/wrapped
|
|
124
|
+
token catalog. These lookups are synchronous and offline, and the returned
|
|
125
|
+
records are frozen. The published `0.7.0` gem includes these DEX and swap
|
|
126
|
+
exports.
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
pool = ERPC::DexCatalog.get_pool_definition("pool-0001")
|
|
130
|
+
puts pool.fetch(:address)
|
|
131
|
+
puts ERPC::Dexes::Ethereum.fetch(:UNISWAP_V2)
|
|
132
|
+
puts ERPC::Pools::AvalancheC.fetch(:LFJ_LEGACY_WAVAX_USDC)
|
|
133
|
+
|
|
134
|
+
matches = ERPC::DexCatalog.find_pool_definitions_by_pair(
|
|
135
|
+
ERPC::DexChainIDs::SOLANA_MAINNET,
|
|
136
|
+
"deployment-0013",
|
|
137
|
+
"deployment-0006"
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The catalog currently contains Uniswap V2 on Ethereum and LFJ legacy
|
|
142
|
+
constant-product on Avalanche C-Chain, plus lookup-only Orca Whirlpools and
|
|
143
|
+
Raydium CLMM records on Solana. Pair lookup is unordered and returns stable
|
|
144
|
+
pool-ID order. `get_native_wrap_definition` accepts a native token deployment
|
|
145
|
+
ID and returns its chain-bound wrapped deployment.
|
|
146
|
+
|
|
147
|
+
## RPC-only swap quotes
|
|
148
|
+
|
|
149
|
+
`erpc.swap.quote_exact_input` performs an exact-input quote for the two EVM
|
|
150
|
+
constant-product pools through the client's configured RPC transports. It
|
|
151
|
+
reads the factory, pool, reserves, and block snapshot using the EIP-1898 block
|
|
152
|
+
hash selector, validates the final headers, and computes the result locally.
|
|
153
|
+
Amounts and block quantities are decimal strings; no hosted aggregator or
|
|
154
|
+
additional API is required.
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
quote = erpc.swap.quote_exact_input(
|
|
158
|
+
chainId: ERPC::DexChainIDs::ETHEREUM_MAINNET,
|
|
159
|
+
poolDefinitionId: ERPC::Pools::Ethereum.fetch(:UNISWAP_V2_USDC_WETH),
|
|
160
|
+
inputTokenDeploymentId: ERPC::Tokens::Ethereum.fetch(:WETH),
|
|
161
|
+
outputTokenDeploymentId: ERPC::Tokens::Ethereum.fetch(:USDC),
|
|
162
|
+
amountIn: "1000000000000000000"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
puts quote.fetch("amountOut")
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`SwapQuoteError#code` exposes deterministic validation codes such as
|
|
169
|
+
`SWAP_STATE_STALE` and `SWAP_UNSUPPORTED_ADAPTER`. Existing transport,
|
|
170
|
+
timeout, and JSON-RPC errors retain their native class. Solana pool records
|
|
171
|
+
are available for lookup; their CLMM adapters are not yet quote-enabled.
|
|
172
|
+
Quote eligibility is a reviewed handwritten boundary for the exact WETH/USDC
|
|
173
|
+
Uniswap V2 tuple on Ethereum and WAVAX/USDC LFJ legacy tuple on Avalanche,
|
|
174
|
+
including chain, pool, factory, token addresses, decimals, ERC-20 standards,
|
|
175
|
+
adapter, and fee fields. New catalog records do not automatically become
|
|
176
|
+
quote-enabled; an otherwise valid request outside those tuples returns
|
|
177
|
+
`SWAP_UNSUPPORTED_TOKEN` before RPC.
|
|
178
|
+
Transaction building, signing, sending, route search, native wrapping, and
|
|
179
|
+
cross-chain bridging are outside this quote API.
|
|
180
|
+
|
|
181
|
+
## Unsigned swap preparation and simulation
|
|
182
|
+
|
|
183
|
+
For the reviewed Ethereum Uniswap V2 and Avalanche LFJ V1 pools, the client
|
|
184
|
+
can prepare an unsigned ERC-20-to-ERC-20 router call and simulate it against a
|
|
185
|
+
fresh RPC snapshot. The methods use the selected dedicated chain transport
|
|
186
|
+
when one is configured.
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
request = {
|
|
190
|
+
chainId: ERPC::DexChainIDs::ETHEREUM_MAINNET,
|
|
191
|
+
poolDefinitionId: ERPC::Pools::Ethereum.fetch(:UNISWAP_V2_USDC_WETH),
|
|
192
|
+
inputTokenDeploymentId: ERPC::Tokens::Ethereum.fetch(:WETH),
|
|
193
|
+
outputTokenDeploymentId: ERPC::Tokens::Ethereum.fetch(:USDC),
|
|
194
|
+
amountIn: "1000000000000000000",
|
|
195
|
+
sender: "0x1111111111111111111111111111111111111111",
|
|
196
|
+
recipient: "0x2222222222222222222222222222222222222222",
|
|
197
|
+
slippageBps: 50,
|
|
198
|
+
deadline: (Time.now.to_i+300).to_s
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
preparation = erpc.swap.prepare_exact_input_swap(request)
|
|
202
|
+
simulation = erpc.swap.simulate_exact_input_swap(request)
|
|
203
|
+
puts preparation.fetch("minimumAmountOut")
|
|
204
|
+
puts simulation.fetch("amountOut")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The preparation contains a chain-bound transaction envelope. Convert its
|
|
208
|
+
fields to the wallet library's native request type and convert the CAIP-2
|
|
209
|
+
`chainId` separately when that library expects a numeric network ID:
|
|
210
|
+
|
|
211
|
+
```ruby
|
|
212
|
+
envelope = preparation.fetch("transaction")
|
|
213
|
+
wallet_request = {
|
|
214
|
+
chain_id: Integer(envelope.fetch("chainId").delete_prefix("eip155:")),
|
|
215
|
+
from: envelope.fetch("from"),
|
|
216
|
+
to: envelope.fetch("to"),
|
|
217
|
+
data: envelope.fetch("data"),
|
|
218
|
+
value: envelope.fetch("value")
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The SDK never creates approval calldata, changes allowances, signs, or sends
|
|
223
|
+
the envelope. Simulation checks the input-token allowance before calling the
|
|
224
|
+
router and validates the returned amounts. `SwapExecutionError#code` exposes
|
|
225
|
+
stable execution codes such as `SWAP_INSUFFICIENT_ALLOWANCE`,
|
|
226
|
+
`SWAP_SIMULATION_REVERTED`, and `SWAP_INVALID_SIMULATION`; transport and
|
|
227
|
+
non-revert JSON-RPC errors retain their native classes.
|
|
228
|
+
|
|
31
229
|
Both exact wire names (`getSlot`, `eth_chainId`) and idiomatic snake-case
|
|
32
230
|
aliases (`get_slot`, `eth_chain_id`) create inert requests. Network I/O starts
|
|
33
231
|
only when `send` is called. `request` restricts calls to the namespace catalog;
|
|
34
232
|
`raw` is the forward-compatible escape hatch.
|
|
35
233
|
|
|
234
|
+
For Solana v1 transactions, pass numeric `maxSupportedTransactionVersion` in
|
|
235
|
+
the request options for `get_transaction` and `get_block`. Responses remain
|
|
236
|
+
opaque Ruby hashes: v1 values include `transaction.message.transactionConfig`,
|
|
237
|
+
legacy and v0 values omit that field, and unrelated response fields are
|
|
238
|
+
preserved. For serialized transactions larger than 1232 bytes, pass the exact
|
|
239
|
+
base64 payload with `"encoding" => "base64"` to `send_transaction` or
|
|
240
|
+
`simulate_transaction`; the SDK forwards the request and response unchanged.
|
|
241
|
+
See the [Solana v1 guide](https://github.com/elsoul/erpc-sdk/blob/main/packages/typescript/docs/solana-v1.md).
|
|
242
|
+
|
|
243
|
+
## Optional Mayan Swift v2 bridge (introduced in 0.8.0)
|
|
244
|
+
|
|
245
|
+
The `0.8.0` API's `MayanSwiftV2BridgeClient` is an explicit standalone adapter for the reviewed
|
|
246
|
+
issued EURC routes between Ethereum mainnet and Solana mainnet. It does not
|
|
247
|
+
attach to `ERPC::Client`, inherit eRPC credentials or headers, or make any
|
|
248
|
+
request during construction. Configure the Mayan builder and Explorer
|
|
249
|
+
endpoints separately when needed:
|
|
250
|
+
|
|
251
|
+
```ruby
|
|
252
|
+
bridge = ERPC::MayanSwiftV2BridgeClient.new(
|
|
253
|
+
builder_endpoint: "https://tx-builder.mayan.finance",
|
|
254
|
+
explorer_endpoint: "https://explorer-api.mayan.finance/v3",
|
|
255
|
+
builder_api_key: ENV.fetch("MAYAN_BUILDER_API_KEY"),
|
|
256
|
+
http_adapter: ERPC::NetHttpAdapter.new
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
quotes = bridge.quote_exact_input(
|
|
260
|
+
"sourceChainId" => ERPC::TokenChainIDs::ETHEREUM_MAINNET,
|
|
261
|
+
"destinationChainId" => ERPC::TokenChainIDs::SOLANA_MAINNET,
|
|
262
|
+
"sourceTokenDeploymentId" => "deployment-0011",
|
|
263
|
+
"destinationTokenDeploymentId" => "deployment-0013",
|
|
264
|
+
"amountIn" => "100000000",
|
|
265
|
+
"slippageBps" => 50
|
|
266
|
+
)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The adapter exposes `quote_exact_input`, `build_unsigned`, and `get_status`.
|
|
270
|
+
Builds return unsigned, structurally checked provider transactions and an
|
|
271
|
+
Ethereum allowance description; the SDK does not approve, sign, broadcast,
|
|
272
|
+
submit, cancel, refund, or claim settlement verification. Provider source
|
|
273
|
+
swaps use Mayan's disclosed internal USDC path (and Jupiter v6 for Solana
|
|
274
|
+
source orders), so this optional adapter is separate from the SDK's configured
|
|
275
|
+
RPC-only swap helpers. The defaults are `https://tx-builder.mayan.finance` for
|
|
276
|
+
quote/build and `https://explorer-api.mayan.finance/v3` for indexed status; set
|
|
277
|
+
`builder_endpoint` and `explorer_endpoint` to customize them. The
|
|
278
|
+
`builder_api_key` is a separate Mayan build-only key and is never an eRPC
|
|
279
|
+
credential. `BridgeError#code` provides stable secret-free errors.
|
|
280
|
+
|
|
36
281
|
## Namespaces
|
|
37
282
|
|
|
38
283
|
| Namespace | Purpose |
|