@lifi/sdk-provider-stellar 0.0.0-preview-5e098f3
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/CHANGELOG.md +12 -0
- package/LICENSE +201 -0
- package/README.md +162 -0
- package/dist/esm/StellarProvider.d.ts +6 -0
- package/dist/esm/StellarProvider.d.ts.map +1 -0
- package/dist/esm/StellarProvider.js +34 -0
- package/dist/esm/StellarProvider.js.map +1 -0
- package/dist/esm/actions/getStellarBalance.d.ts +15 -0
- package/dist/esm/actions/getStellarBalance.d.ts.map +1 -0
- package/dist/esm/actions/getStellarBalance.js +47 -0
- package/dist/esm/actions/getStellarBalance.js.map +1 -0
- package/dist/esm/actions/resolveStellarAddress.d.ts +10 -0
- package/dist/esm/actions/resolveStellarAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveStellarAddress.js +20 -0
- package/dist/esm/actions/resolveStellarAddress.js.map +1 -0
- package/dist/esm/client/getStellarRpc.d.ts +12 -0
- package/dist/esm/client/getStellarRpc.d.ts.map +1 -0
- package/dist/esm/client/getStellarRpc.js +35 -0
- package/dist/esm/client/getStellarRpc.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/types.d.ts +76 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/version.d.ts +6 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +7 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +77 -0
- package/src/StellarProvider.ts +61 -0
- package/src/actions/getStellarBalance.ts +85 -0
- package/src/actions/resolveStellarAddress.ts +23 -0
- package/src/client/getStellarRpc.ts +50 -0
- package/src/index.ts +11 -0
- package/src/types.ts +99 -0
- package/src/version.ts +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @lifi/sdk-provider-stellar
|
|
2
|
+
|
|
3
|
+
## 0.0.0-preview-5e098f3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#427](https://github.com/lifinance/sdk/pull/427) [`03c1562`](https://github.com/lifinance/sdk/commit/03c15625c7d5515f91e24a555ec3b6b5e99dd6b5) Thanks [@chybisov](https://github.com/chybisov)! - Add Stellar (STL) ecosystem support. Introduces the `@lifi/sdk-provider-stellar` package (address validation, Federation resolution, and SAC-based balance reads) and registers `ChainType.STL` in the SDK client's chain fetching so Stellar chains and RPC URLs load. Transaction execution is not yet implemented and will follow once backend transaction generation lands.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`03c1562`](https://github.com/lifinance/sdk/commit/03c15625c7d5515f91e24a555ec3b6b5e99dd6b5)]:
|
|
12
|
+
- @lifi/sdk@0.0.0-preview-5e098f3
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright LI.FI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
[](/LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@lifi/sdk)
|
|
5
|
+
[](https://www.npmjs.com/package/@lifi/sdk)
|
|
6
|
+
[](https://twitter.com/lifiprotocol)
|
|
7
|
+
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<h1 align="center">LI.FI SDK</h1>
|
|
11
|
+
|
|
12
|
+
[**LI.FI SDK**](https://docs.li.fi/sdk/overview) provides a powerful toolkit for developers to enable seamless cross-chain and on-chain swaps and bridging within their applications. Our JavaScript/TypeScript SDK can be implemented in front-end or back-end environments, allowing you to build robust UX/UI around our advanced bridge and swap functionalities. LI.FI SDK efficiently manages all communications between our smart routing API and smart contracts and ensures optimal performance, security, and scalability for your cross-chain and on-chain needs.
|
|
13
|
+
|
|
14
|
+
[**LI.FI SDK**](https://docs.li.fi/sdk/overview) features include:
|
|
15
|
+
|
|
16
|
+
- **Modular architecture** - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron)
|
|
17
|
+
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
|
|
18
|
+
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
|
|
19
|
+
- Easy tracking of the route and quote execution through the robust event and hooks handling
|
|
20
|
+
- Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
|
|
21
|
+
- Supports widely adopted industry standards, including [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
|
|
22
|
+
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/) for EVM, [Solana Kit](https://github.com/solana-labs/solana-web3.js) for Solana, [Bigmi](https://github.com/lifinance/bigmi) for Bitcoin, [Mysten Sui SDK](https://github.com/MystenLabs/sui/tree/main/sdk) for Sui, [TronWeb](https://tronweb.network/) for Tron)
|
|
23
|
+
- Support for arbitrary contract calls on the destination chain
|
|
24
|
+
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
|
|
25
|
+
- Compatibility tested with Node.js and popular front-end tools like Vite
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
The LI.FI SDK follows a modular architecture. Install the core SDK package and the provider packages for the blockchain ecosystems you need:
|
|
30
|
+
|
|
31
|
+
### Core SDK
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add @lifi/sdk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
or
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install --save @lifi/sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Provider Packages
|
|
44
|
+
|
|
45
|
+
Install provider packages based on the blockchain ecosystems you want to support:
|
|
46
|
+
|
|
47
|
+
**EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)**
|
|
48
|
+
```bash
|
|
49
|
+
pnpm add @lifi/sdk-provider-ethereum
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Solana**
|
|
53
|
+
```bash
|
|
54
|
+
pnpm add @lifi/sdk-provider-solana
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Bitcoin**
|
|
58
|
+
```bash
|
|
59
|
+
pnpm add @lifi/sdk-provider-bitcoin
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Sui**
|
|
63
|
+
```bash
|
|
64
|
+
pnpm add @lifi/sdk-provider-sui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Tron**
|
|
68
|
+
```bash
|
|
69
|
+
pnpm add @lifi/sdk-provider-tron
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Architecture
|
|
73
|
+
|
|
74
|
+
The LI.FI SDK uses a modular provider architecture:
|
|
75
|
+
|
|
76
|
+
- **`@lifi/sdk`** - Core SDK package containing shared functionality, actions, and execution logic
|
|
77
|
+
- **Provider packages** - Ecosystem-specific packages that handle wallet interactions and transaction execution for different blockchain types
|
|
78
|
+
|
|
79
|
+
This architecture allows you to:
|
|
80
|
+
- Install only the providers you need, reducing bundle size
|
|
81
|
+
- Use ecosystem-specific libraries optimized for each blockchain
|
|
82
|
+
- Maintain clean separation between core SDK logic and blockchain-specific implementations
|
|
83
|
+
|
|
84
|
+
## Quick Start
|
|
85
|
+
|
|
86
|
+
### Set up the SDK
|
|
87
|
+
|
|
88
|
+
Create SDK config with your integrator string and configure the providers for the blockchain ecosystems you want to support.
|
|
89
|
+
|
|
90
|
+
**For EVM chains:**
|
|
91
|
+
```ts
|
|
92
|
+
import { createClient } from '@lifi/sdk'
|
|
93
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
94
|
+
import { createWalletClient, http } from 'viem'
|
|
95
|
+
import { mainnet } from 'viem/chains'
|
|
96
|
+
|
|
97
|
+
// Add your account (e.g. privateKeyToAccount, mnemonicToAccount)
|
|
98
|
+
const walletClient = createWalletClient({
|
|
99
|
+
account,
|
|
100
|
+
chain: mainnet,
|
|
101
|
+
transport: http(),
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const client = createClient({
|
|
105
|
+
integrator: 'Your dApp/company name',
|
|
106
|
+
providers: [
|
|
107
|
+
EthereumProvider({
|
|
108
|
+
getWalletClient: () => Promise.resolve(walletClient),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**For multiple ecosystems:**
|
|
115
|
+
```ts
|
|
116
|
+
import { createClient } from '@lifi/sdk'
|
|
117
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
118
|
+
import { SolanaProvider } from '@lifi/sdk-provider-solana'
|
|
119
|
+
import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
120
|
+
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
121
|
+
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
122
|
+
|
|
123
|
+
const client = createClient({
|
|
124
|
+
integrator: 'Your dApp/company name',
|
|
125
|
+
providers: [
|
|
126
|
+
EthereumProvider({ /* options */ }),
|
|
127
|
+
SolanaProvider({ /* options */ }),
|
|
128
|
+
BitcoinProvider({ /* options */ }),
|
|
129
|
+
SuiProvider({ /* options */ }),
|
|
130
|
+
TronProvider({ /* options */ }),
|
|
131
|
+
],
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Request a Quote
|
|
136
|
+
|
|
137
|
+
Now you can interact with the SDK and for example request a quote.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { ChainId, getQuote } from '@lifi/sdk'
|
|
141
|
+
|
|
142
|
+
const quote = await getQuote(client, {
|
|
143
|
+
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
144
|
+
fromChain: ChainId.ARB,
|
|
145
|
+
toChain: ChainId.OPT,
|
|
146
|
+
fromToken: '0x0000000000000000000000000000000000000000',
|
|
147
|
+
toToken: '0x0000000000000000000000000000000000000000',
|
|
148
|
+
fromAmount: '1000000000000000000',
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Examples
|
|
153
|
+
|
|
154
|
+
See [examples](/examples) folder in this repository.
|
|
155
|
+
|
|
156
|
+
## Documentation
|
|
157
|
+
|
|
158
|
+
Please checkout the [SDK documentation](https://docs.li.fi/sdk/overview) and our [API reference](https://docs.li.fi/api-reference/introduction) for further information.
|
|
159
|
+
|
|
160
|
+
## Changelog
|
|
161
|
+
|
|
162
|
+
The [changelog](/CHANGELOG.md) is regularly updated to reflect what's changed in each new release.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StellarProviderOptions, StellarSDKProvider } from "./types.js";
|
|
2
|
+
//#region src/StellarProvider.d.ts
|
|
3
|
+
declare function StellarProvider(options?: StellarProviderOptions): StellarSDKProvider;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { StellarProvider };
|
|
6
|
+
//# sourceMappingURL=StellarProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StellarProvider.d.ts","names":[],"sources":["../../src/StellarProvider.ts"],"mappings":";;iBAwBgB,gBACd,UAAU,yBACT"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getStellarBalance } from "./actions/getStellarBalance.js";
|
|
2
|
+
import { resolveStellarAddress } from "./actions/resolveStellarAddress.js";
|
|
3
|
+
import { ChainType, LiFiErrorCode, ProviderError } from "@lifi/sdk";
|
|
4
|
+
import { Networks, StrKey } from "@stellar/stellar-sdk";
|
|
5
|
+
//#region src/StellarProvider.ts
|
|
6
|
+
/**
|
|
7
|
+
* Validates a Stellar account address. Only ed25519 G-addresses are accepted as
|
|
8
|
+
* senders — muxed `M`-addresses and contract `C`-addresses are intentionally
|
|
9
|
+
* rejected (see backend EXBE-227: muxed senders validate-and-throw).
|
|
10
|
+
*/
|
|
11
|
+
function isStellarAddress(address) {
|
|
12
|
+
return StrKey.isValidEd25519PublicKey(address);
|
|
13
|
+
}
|
|
14
|
+
function StellarProvider(options) {
|
|
15
|
+
const _options = options ?? {};
|
|
16
|
+
return {
|
|
17
|
+
get type() {
|
|
18
|
+
return ChainType.STL;
|
|
19
|
+
},
|
|
20
|
+
isAddress: isStellarAddress,
|
|
21
|
+
resolveAddress: resolveStellarAddress,
|
|
22
|
+
getBalance: (client, walletAddress, tokens) => getStellarBalance(client, walletAddress, tokens, _options.networkPassphrase ?? Networks.PUBLIC),
|
|
23
|
+
async getStepExecutor(_stepOptions) {
|
|
24
|
+
throw new ProviderError(LiFiErrorCode.ConfigError, "Stellar transaction execution is not yet implemented.");
|
|
25
|
+
},
|
|
26
|
+
setOptions(options) {
|
|
27
|
+
Object.assign(_options, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { StellarProvider };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=StellarProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StellarProvider.js","names":[],"sources":["../../src/StellarProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type SDKClient,\n type StepExecutor,\n type StepExecutorOptions,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { Networks, StrKey } from '@stellar/stellar-sdk'\nimport { getStellarBalance } from './actions/getStellarBalance.js'\nimport { resolveStellarAddress } from './actions/resolveStellarAddress.js'\nimport type { StellarProviderOptions, StellarSDKProvider } from './types.js'\n\n/**\n * Validates a Stellar account address. Only ed25519 G-addresses are accepted as\n * senders — muxed `M`-addresses and contract `C`-addresses are intentionally\n * rejected (see backend EXBE-227: muxed senders validate-and-throw).\n */\nfunction isStellarAddress(address: string): boolean {\n return StrKey.isValidEd25519PublicKey(address)\n}\n\nexport function StellarProvider(\n options?: StellarProviderOptions\n): StellarSDKProvider {\n const _options: StellarProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.STL\n },\n isAddress: isStellarAddress,\n resolveAddress: resolveStellarAddress,\n getBalance: (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n ): Promise<TokenAmount[]> =>\n getStellarBalance(\n client,\n walletAddress,\n tokens,\n _options.networkPassphrase ?? Networks.PUBLIC\n ),\n async getStepExecutor(\n _stepOptions: StepExecutorOptions\n ): Promise<StepExecutor> {\n // Phase 2: transaction execution is gated on backend tx-generation\n // (EXBE-227). Until StellarStepExecutor lands, fail loudly rather than\n // silently.\n throw new ProviderError(\n LiFiErrorCode.ConfigError,\n 'Stellar transaction execution is not yet implemented.'\n )\n },\n setOptions(options: StellarProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;;;;AAoBA,SAAS,iBAAiB,SAA0B;CAClD,OAAO,OAAO,wBAAwB,OAAO;AAC/C;AAEA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,aACE,QACA,eACA,WAEA,kBACE,QACA,eACA,QACA,SAAS,qBAAqB,SAAS,MACzC;EACF,MAAM,gBACJ,cACuB;GAIvB,MAAM,IAAI,cACR,cAAc,aACd,uDACF;EACF;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SDKClient, Token, TokenAmount } from "@lifi/sdk";
|
|
2
|
+
//#region src/actions/getStellarBalance.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Fetches Stellar token balances for a wallet.
|
|
5
|
+
*
|
|
6
|
+
* Every LI.FI Stellar token — including native XLM — is addressed by its Soroban
|
|
7
|
+
* Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore
|
|
8
|
+
* read each balance uniformly by simulating the SAC `balance(account)` call over
|
|
9
|
+
* Stellar RPC, which works for native XLM, wrapped classic assets, and
|
|
10
|
+
* Soroban-native tokens alike.
|
|
11
|
+
*/
|
|
12
|
+
declare const getStellarBalance: (client: SDKClient, walletAddress: string, tokens: Token[], networkPassphrase?: string) => Promise<TokenAmount[]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { getStellarBalance };
|
|
15
|
+
//# sourceMappingURL=getStellarBalance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStellarBalance.d.ts","names":[],"sources":["../../../src/actions/getStellarBalance.ts"],"mappings":";;;;;;;;;;;cA2Ba,oBACX,QAAQ,WACR,uBACA,QAAQ,SACR,+BACC,QAAQ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { callStellarRpcsWithRetry } from "../client/getStellarRpc.js";
|
|
2
|
+
import { withDedupe } from "@lifi/sdk";
|
|
3
|
+
import { Account, Address, BASE_FEE, Contract, Networks, TransactionBuilder, rpc, scValToNative } from "@stellar/stellar-sdk";
|
|
4
|
+
//#region src/actions/getStellarBalance.ts
|
|
5
|
+
/**
|
|
6
|
+
* Fetches Stellar token balances for a wallet.
|
|
7
|
+
*
|
|
8
|
+
* Every LI.FI Stellar token — including native XLM — is addressed by its Soroban
|
|
9
|
+
* Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore
|
|
10
|
+
* read each balance uniformly by simulating the SAC `balance(account)` call over
|
|
11
|
+
* Stellar RPC, which works for native XLM, wrapped classic assets, and
|
|
12
|
+
* Soroban-native tokens alike.
|
|
13
|
+
*/
|
|
14
|
+
const getStellarBalance = async (client, walletAddress, tokens, networkPassphrase = Networks.PUBLIC) => {
|
|
15
|
+
if (tokens.length === 0) return [];
|
|
16
|
+
const results = await Promise.all(tokens.map((token) => withDedupe(() => getSacBalance(client, walletAddress, token, networkPassphrase), { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }).catch(() => void 0)));
|
|
17
|
+
return tokens.map((token, index) => {
|
|
18
|
+
const amount = results[index];
|
|
19
|
+
return amount !== void 0 ? {
|
|
20
|
+
...token,
|
|
21
|
+
amount
|
|
22
|
+
} : { ...token };
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Simulates a read-only `balance(account)` call on the token's SAC and decodes
|
|
27
|
+
* the returned i128 into a bigint. Returns `undefined` when the balance cannot
|
|
28
|
+
* be read (e.g. contract not found, account not funded).
|
|
29
|
+
*/
|
|
30
|
+
const getSacBalance = async (client, walletAddress, token, networkPassphrase) => {
|
|
31
|
+
return callStellarRpcsWithRetry(client, async (server) => {
|
|
32
|
+
const source = new Account(walletAddress, "0");
|
|
33
|
+
const contract = new Contract(token.address);
|
|
34
|
+
const transaction = new TransactionBuilder(source, {
|
|
35
|
+
fee: BASE_FEE,
|
|
36
|
+
networkPassphrase
|
|
37
|
+
}).addOperation(contract.call("balance", Address.fromString(walletAddress).toScVal())).setTimeout(30).build();
|
|
38
|
+
const simulation = await server.simulateTransaction(transaction);
|
|
39
|
+
if (!rpc.Api.isSimulationSuccess(simulation) || !simulation.result) return;
|
|
40
|
+
const value = scValToNative(simulation.result.retval);
|
|
41
|
+
return value != null ? BigInt(value) : void 0;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { getStellarBalance };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=getStellarBalance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStellarBalance.js","names":[],"sources":["../../../src/actions/getStellarBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport {\n Account,\n Address,\n BASE_FEE,\n Contract,\n Networks,\n rpc,\n scValToNative,\n TransactionBuilder,\n} from '@stellar/stellar-sdk'\nimport { callStellarRpcsWithRetry } from '../client/getStellarRpc.js'\n\n/**\n * Fetches Stellar token balances for a wallet.\n *\n * Every LI.FI Stellar token — including native XLM — is addressed by its Soroban\n * Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore\n * read each balance uniformly by simulating the SAC `balance(account)` call over\n * Stellar RPC, which works for native XLM, wrapped classic assets, and\n * Soroban-native tokens alike.\n */\nexport const getStellarBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[],\n networkPassphrase: string = Networks.PUBLIC\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n\n const results = await Promise.all(\n tokens.map((token) =>\n withDedupe(\n () => getSacBalance(client, walletAddress, token, networkPassphrase),\n { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }\n ).catch(() => undefined)\n )\n )\n\n return tokens.map((token, index) => {\n const amount = results[index]\n return amount !== undefined ? { ...token, amount } : { ...token }\n })\n}\n\n/**\n * Simulates a read-only `balance(account)` call on the token's SAC and decodes\n * the returned i128 into a bigint. Returns `undefined` when the balance cannot\n * be read (e.g. contract not found, account not funded).\n */\nconst getSacBalance = async (\n client: SDKClient,\n walletAddress: string,\n token: Token,\n networkPassphrase: string\n): Promise<bigint | undefined> => {\n return callStellarRpcsWithRetry(client, async (server) => {\n // A zero-sequence account is sufficient for read-only simulation.\n const source = new Account(walletAddress, '0')\n const contract = new Contract(token.address)\n const transaction = new TransactionBuilder(source, {\n fee: BASE_FEE,\n networkPassphrase,\n })\n .addOperation(\n contract.call('balance', Address.fromString(walletAddress).toScVal())\n )\n .setTimeout(30)\n .build()\n\n const simulation = await server.simulateTransaction(transaction)\n if (!rpc.Api.isSimulationSuccess(simulation) || !simulation.result) {\n return undefined\n }\n const value = scValToNative(simulation.result.retval)\n return value != null ? BigInt(value) : undefined\n })\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAa,oBAAoB,OAC/B,QACA,eACA,QACA,oBAA4B,SAAS,WACV;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,KAAK,UACV,iBACQ,cAAc,QAAQ,eAAe,OAAO,iBAAiB,GACnE,EAAE,IAAI,GAAG,kBAAkB,KAAK,GAAG,cAAc,GAAG,MAAM,UAAU,CACtE,CAAC,CAAC,YAAY,KAAA,CAAS,CACzB,CACF;CAEA,OAAO,OAAO,KAAK,OAAO,UAAU;EAClC,MAAM,SAAS,QAAQ;EACvB,OAAO,WAAW,KAAA,IAAY;GAAE,GAAG;GAAO;EAAO,IAAI,EAAE,GAAG,MAAM;CAClE,CAAC;AACH;;;;;;AAOA,MAAM,gBAAgB,OACpB,QACA,eACA,OACA,sBACgC;CAChC,OAAO,yBAAyB,QAAQ,OAAO,WAAW;EAExD,MAAM,SAAS,IAAI,QAAQ,eAAe,GAAG;EAC7C,MAAM,WAAW,IAAI,SAAS,MAAM,OAAO;EAC3C,MAAM,cAAc,IAAI,mBAAmB,QAAQ;GACjD,KAAK;GACL;EACF,CAAC,CAAC,CACC,aACC,SAAS,KAAK,WAAW,QAAQ,WAAW,aAAa,CAAC,CAAC,QAAQ,CAAC,CACtE,CAAC,CACA,WAAW,EAAE,CAAC,CACd,MAAM;EAET,MAAM,aAAa,MAAM,OAAO,oBAAoB,WAAW;EAC/D,IAAI,CAAC,IAAI,IAAI,oBAAoB,UAAU,KAAK,CAAC,WAAW,QAC1D;EAEF,MAAM,QAAQ,cAAc,WAAW,OAAO,MAAM;EACpD,OAAO,SAAS,OAAO,OAAO,KAAK,IAAI,KAAA;CACzC,CAAC;AACH"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/actions/resolveStellarAddress.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.
|
|
4
|
+
* Returns the input unchanged when it is already a valid G-address, and
|
|
5
|
+
* `undefined` when it is neither a federation address nor resolvable.
|
|
6
|
+
*/
|
|
7
|
+
declare function resolveStellarAddress(name: string): Promise<string | undefined>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { resolveStellarAddress };
|
|
10
|
+
//# sourceMappingURL=resolveStellarAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStellarAddress.d.ts","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"mappings":";;;;;;iBAOsB,sBACpB,eACC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Federation, StrKey } from "@stellar/stellar-sdk";
|
|
2
|
+
//#region src/actions/resolveStellarAddress.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.
|
|
5
|
+
* Returns the input unchanged when it is already a valid G-address, and
|
|
6
|
+
* `undefined` when it is neither a federation address nor resolvable.
|
|
7
|
+
*/
|
|
8
|
+
async function resolveStellarAddress(name) {
|
|
9
|
+
if (StrKey.isValidEd25519PublicKey(name)) return name;
|
|
10
|
+
if (!name.includes("*")) return;
|
|
11
|
+
try {
|
|
12
|
+
return (await Federation.Server.resolve(name)).account_id;
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveStellarAddress };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=resolveStellarAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStellarAddress.js","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"sourcesContent":["import { Federation, StrKey } from '@stellar/stellar-sdk'\n\n/**\n * Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.\n * Returns the input unchanged when it is already a valid G-address, and\n * `undefined` when it is neither a federation address nor resolvable.\n */\nexport async function resolveStellarAddress(\n name: string\n): Promise<string | undefined> {\n if (StrKey.isValidEd25519PublicKey(name)) {\n return name\n }\n if (!name.includes('*')) {\n return undefined\n }\n try {\n const record = await Federation.Server.resolve(name)\n return record.account_id\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;;;;;AAOA,eAAsB,sBACpB,MAC6B;CAC7B,IAAI,OAAO,wBAAwB,IAAI,GACrC,OAAO;CAET,IAAI,CAAC,KAAK,SAAS,GAAG,GACpB;CAEF,IAAI;EAEF,QAAO,MADc,WAAW,OAAO,QAAQ,IAAI,EAAA,CACrC;CAChB,QAAQ;EACN;CACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SDKClient } from "@lifi/sdk";
|
|
2
|
+
import { rpc } from "@stellar/stellar-sdk";
|
|
3
|
+
//#region src/client/getStellarRpc.d.ts
|
|
4
|
+
declare const getStellarRpcs: (client: SDKClient) => Promise<rpc.Server[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Calls a function on Stellar RPC instances with retry logic. Tries each RPC in
|
|
7
|
+
* sequence until one succeeds.
|
|
8
|
+
*/
|
|
9
|
+
declare const callStellarRpcsWithRetry: <R>(client: SDKClient, fn: (server: rpc.Server) => Promise<R>) => Promise<R>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { callStellarRpcsWithRetry, getStellarRpcs };
|
|
12
|
+
//# sourceMappingURL=getStellarRpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStellarRpc.d.ts","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"mappings":";;;cAmBa,iBACX,QAAQ,cACP,QAAQ,IAAI;;;;;cAWF,2BAAkC,GAC7C,QAAQ,WACR,KAAK,QAAQ,IAAI,WAAW,QAAQ,OACnC,QAAQ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ChainId, LruMap } from "@lifi/sdk";
|
|
2
|
+
import { rpc } from "@stellar/stellar-sdk";
|
|
3
|
+
//#region src/client/getStellarRpc.ts
|
|
4
|
+
const stellarRpcs = new LruMap(12);
|
|
5
|
+
/**
|
|
6
|
+
* Resolves and caches a Stellar RPC (JSON-RPC / Soroban RPC) server for each RPC
|
|
7
|
+
* URL configured for the Stellar chain on the SDK client.
|
|
8
|
+
*/
|
|
9
|
+
const ensureStellarRpcs = async (client) => {
|
|
10
|
+
const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM);
|
|
11
|
+
for (const rpcUrl of rpcUrls) if (!stellarRpcs.has(rpcUrl)) stellarRpcs.set(rpcUrl, new rpc.Server(rpcUrl, { allowHttp: true }));
|
|
12
|
+
return rpcUrls;
|
|
13
|
+
};
|
|
14
|
+
const getStellarRpcs = async (client) => {
|
|
15
|
+
return (await ensureStellarRpcs(client)).map((rpcUrl) => stellarRpcs.get(rpcUrl)).filter((server) => Boolean(server));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Calls a function on Stellar RPC instances with retry logic. Tries each RPC in
|
|
19
|
+
* sequence until one succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const callStellarRpcsWithRetry = async (client, fn) => {
|
|
22
|
+
const servers = await getStellarRpcs(client);
|
|
23
|
+
if (servers.length === 0) throw new Error("No Stellar RPCs available");
|
|
24
|
+
const errors = [];
|
|
25
|
+
for (const server of servers) try {
|
|
26
|
+
return await fn(server);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
29
|
+
}
|
|
30
|
+
throw new AggregateError(errors, `All ${servers.length} Stellar RPCs failed`);
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { callStellarRpcsWithRetry, getStellarRpcs };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=getStellarRpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStellarRpc.js","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'\nimport { rpc } from '@stellar/stellar-sdk'\n\nconst stellarRpcs = new LruMap<rpc.Server>(12)\n\n/**\n * Resolves and caches a Stellar RPC (JSON-RPC / Soroban RPC) server for each RPC\n * URL configured for the Stellar chain on the SDK client.\n */\nconst ensureStellarRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM)\n for (const rpcUrl of rpcUrls) {\n if (!stellarRpcs.has(rpcUrl)) {\n stellarRpcs.set(rpcUrl, new rpc.Server(rpcUrl, { allowHttp: true }))\n }\n }\n return rpcUrls\n}\n\nexport const getStellarRpcs = async (\n client: SDKClient\n): Promise<rpc.Server[]> => {\n const rpcUrls = await ensureStellarRpcs(client)\n return rpcUrls\n .map((rpcUrl) => stellarRpcs.get(rpcUrl))\n .filter((server): server is rpc.Server => Boolean(server))\n}\n\n/**\n * Calls a function on Stellar RPC instances with retry logic. Tries each RPC in\n * sequence until one succeeds.\n */\nexport const callStellarRpcsWithRetry = async <R>(\n client: SDKClient,\n fn: (server: rpc.Server) => Promise<R>\n): Promise<R> => {\n const servers = await getStellarRpcs(client)\n if (servers.length === 0) {\n throw new Error('No Stellar RPCs available')\n }\n const errors: Error[] = []\n for (const server of servers) {\n try {\n return await fn(server)\n } catch (error) {\n errors.push(error instanceof Error ? error : new Error(String(error)))\n }\n }\n throw new AggregateError(errors, `All ${servers.length} Stellar RPCs failed`)\n}\n"],"mappings":";;;AAGA,MAAM,cAAc,IAAI,OAAmB,EAAE;;;;;AAM7C,MAAM,oBAAoB,OAAO,WAAyC;CACxE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,YAAY,IAAI,MAAM,GACzB,YAAY,IAAI,QAAQ,IAAI,IAAI,OAAO,QAAQ,EAAE,WAAW,KAAK,CAAC,CAAC;CAGvE,OAAO;AACT;AAEA,MAAa,iBAAiB,OAC5B,WAC0B;CAE1B,QAAO,MADe,kBAAkB,MAAM,EAAA,CAE3C,KAAK,WAAW,YAAY,IAAI,MAAM,CAAC,CAAC,CACxC,QAAQ,WAAiC,QAAQ,MAAM,CAAC;AAC7D;;;;;AAMA,MAAa,2BAA2B,OACtC,QACA,OACe;CACf,MAAM,UAAU,MAAM,eAAe,MAAM;CAC3C,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,2BAA2B;CAE7C,MAAM,SAAkB,CAAC;CACzB,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,MAAM,GAAG,MAAM;CACxB,SAAS,OAAO;EACd,OAAO,KAAK,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;CACvE;CAEF,MAAM,IAAI,eAAe,QAAQ,OAAO,QAAQ,OAAO,qBAAqB;AAC9E"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { StellarProviderOptions, StellarSDKProvider, StellarSignOptions, StellarSignedAuthEntry, StellarSignedTransaction, StellarWallet, isStellarProvider } from "./types.js";
|
|
2
|
+
import { StellarProvider } from "./StellarProvider.js";
|
|
3
|
+
export { StellarProvider, type StellarProviderOptions, type StellarSDKProvider, type StellarSignOptions, type StellarSignedAuthEntry, type StellarSignedTransaction, type StellarWallet, isStellarProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","sideEffects":false}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Options passed to a wallet signing call. Mirrors the Stellar Wallets Kit
|
|
5
|
+
* (`@creit.tech/stellar-wallets-kit`) signing surface so a widget adapter can
|
|
6
|
+
* forward calls directly.
|
|
7
|
+
*/
|
|
8
|
+
interface StellarSignOptions {
|
|
9
|
+
networkPassphrase?: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Result of signing a transaction envelope — a base64 XDR string plus the
|
|
14
|
+
* signer's public key. Matches the Stellar Wallets Kit `signTransaction` return.
|
|
15
|
+
*/
|
|
16
|
+
interface StellarSignedTransaction {
|
|
17
|
+
signedTxXdr: string;
|
|
18
|
+
signerAddress?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result of signing a Soroban authorization entry. Matches the Stellar Wallets
|
|
22
|
+
* Kit `signAuthEntry` return. Not required for the router routes (source-account
|
|
23
|
+
* auth), exposed for future-proofing.
|
|
24
|
+
*/
|
|
25
|
+
interface StellarSignedAuthEntry {
|
|
26
|
+
signedAuthEntry: string;
|
|
27
|
+
signerAddress?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The minimal signer surface the SDK provider needs from a connected wallet.
|
|
31
|
+
* The widget builds this adapter from the Stellar Wallets Kit instance.
|
|
32
|
+
*/
|
|
33
|
+
interface StellarWallet {
|
|
34
|
+
/** The connected G-address (source account). */
|
|
35
|
+
address: string;
|
|
36
|
+
/** The network passphrase the wallet is expected to sign against. */
|
|
37
|
+
networkPassphrase: string;
|
|
38
|
+
signTransaction: (xdr: string, opts?: StellarSignOptions) => Promise<StellarSignedTransaction>;
|
|
39
|
+
signAuthEntry: (authEntry: string, opts?: StellarSignOptions) => Promise<StellarSignedAuthEntry>;
|
|
40
|
+
}
|
|
41
|
+
interface StellarProviderOptions {
|
|
42
|
+
getWallet?: () => Promise<StellarWallet>;
|
|
43
|
+
/**
|
|
44
|
+
* Network passphrase for the Stellar network this provider targets.
|
|
45
|
+
* Defaults to the public (mainnet) network.
|
|
46
|
+
*/
|
|
47
|
+
networkPassphrase?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Optional Horizon REST endpoint used for balance/account reads. When omitted
|
|
50
|
+
* the provider falls back to the Stellar RPC URLs resolved from the SDK client.
|
|
51
|
+
*/
|
|
52
|
+
horizonUrl?: string;
|
|
53
|
+
}
|
|
54
|
+
interface StellarSDKProvider extends SDKProvider {
|
|
55
|
+
setOptions(options: StellarProviderOptions): void;
|
|
56
|
+
}
|
|
57
|
+
declare function isStellarProvider(provider: SDKProvider): provider is StellarSDKProvider;
|
|
58
|
+
/** Phase 2 (execution) context — consumed by StellarStepExecutor + its tasks. */
|
|
59
|
+
interface StellarTaskContext {
|
|
60
|
+
/** Hash of the submitted transaction. */
|
|
61
|
+
transactionHash?: string;
|
|
62
|
+
}
|
|
63
|
+
interface StellarStepExecutorContext extends StepExecutorContext, StellarTaskContext {
|
|
64
|
+
wallet: StellarWallet;
|
|
65
|
+
networkPassphrase: string;
|
|
66
|
+
/** Base URLs for the Stellar RPC (JSON-RPC) endpoints used to submit + poll. */
|
|
67
|
+
rpcUrls: string[];
|
|
68
|
+
}
|
|
69
|
+
interface StellarStepExecutorOptions extends StepExecutorOptions {
|
|
70
|
+
wallet: StellarWallet;
|
|
71
|
+
networkPassphrase: string;
|
|
72
|
+
rpcUrls: string[];
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { StellarProviderOptions, StellarSDKProvider, StellarSignOptions, StellarSignedAuthEntry, StellarSignedTransaction, StellarStepExecutorContext, StellarStepExecutorOptions, StellarTaskContext, StellarWallet, isStellarProvider };
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;;;;UAYiB;EACf;EACA;;;;;;UAOe;EACf;EACA;;;;;;;UAQe;EACf;EACA;;;;;;UAOe;;EAEf;;EAEA;EACA,kBACE,aACA,OAAO,uBACJ,QAAQ;EACb,gBACE,mBACA,OAAO,uBACJ,QAAQ;;UAGE;EACf,kBAAkB,QAAQ;;;;;EAK1B;;;;;EAKA;;UAGe,2BAA2B;EAC1C,WAAW,SAAS;;iBAGN,kBACd,UAAU,cACT,YAAY;;UAKE;;EAEf;;UAGe,mCACP,qBACN;EACF,QAAQ;EACR;;EAEA;;UAGe,mCAAmC;EAClD,QAAQ;EACR;EACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import {\n ChainType,\n type SDKProvider,\n type StepExecutorContext,\n type StepExecutorOptions,\n} from '@lifi/sdk'\n\n/**\n * Options passed to a wallet signing call. Mirrors the Stellar Wallets Kit\n * (`@creit.tech/stellar-wallets-kit`) signing surface so a widget adapter can\n * forward calls directly.\n */\nexport interface StellarSignOptions {\n networkPassphrase?: string\n address?: string\n}\n\n/**\n * Result of signing a transaction envelope — a base64 XDR string plus the\n * signer's public key. Matches the Stellar Wallets Kit `signTransaction` return.\n */\nexport interface StellarSignedTransaction {\n signedTxXdr: string\n signerAddress?: string\n}\n\n/**\n * Result of signing a Soroban authorization entry. Matches the Stellar Wallets\n * Kit `signAuthEntry` return. Not required for the router routes (source-account\n * auth), exposed for future-proofing.\n */\nexport interface StellarSignedAuthEntry {\n signedAuthEntry: string\n signerAddress?: string\n}\n\n/**\n * The minimal signer surface the SDK provider needs from a connected wallet.\n * The widget builds this adapter from the Stellar Wallets Kit instance.\n */\nexport interface StellarWallet {\n /** The connected G-address (source account). */\n address: string\n /** The network passphrase the wallet is expected to sign against. */\n networkPassphrase: string\n signTransaction: (\n xdr: string,\n opts?: StellarSignOptions\n ) => Promise<StellarSignedTransaction>\n signAuthEntry: (\n authEntry: string,\n opts?: StellarSignOptions\n ) => Promise<StellarSignedAuthEntry>\n}\n\nexport interface StellarProviderOptions {\n getWallet?: () => Promise<StellarWallet>\n /**\n * Network passphrase for the Stellar network this provider targets.\n * Defaults to the public (mainnet) network.\n */\n networkPassphrase?: string\n /**\n * Optional Horizon REST endpoint used for balance/account reads. When omitted\n * the provider falls back to the Stellar RPC URLs resolved from the SDK client.\n */\n horizonUrl?: string\n}\n\nexport interface StellarSDKProvider extends SDKProvider {\n setOptions(options: StellarProviderOptions): void\n}\n\nexport function isStellarProvider(\n provider: SDKProvider\n): provider is StellarSDKProvider {\n return provider.type === ChainType.STL\n}\n\n/** Phase 2 (execution) context — consumed by StellarStepExecutor + its tasks. */\nexport interface StellarTaskContext {\n /** Hash of the submitted transaction. */\n transactionHash?: string\n}\n\nexport interface StellarStepExecutorContext\n extends StepExecutorContext,\n StellarTaskContext {\n wallet: StellarWallet\n networkPassphrase: string\n /** Base URLs for the Stellar RPC (JSON-RPC) endpoints used to submit + poll. */\n rpcUrls: string[]\n}\n\nexport interface StellarStepExecutorOptions extends StepExecutorOptions {\n wallet: StellarWallet\n networkPassphrase: string\n rpcUrls: string[]\n}\n"],"mappings":";;AAyEA,SAAgB,kBACd,UACgC;CAChC,OAAO,SAAS,SAAS,UAAU;AACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","names":[],"sources":["../../src/version.ts"],"mappings":";cAAa;cACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-stellar'\nexport const version = '0.0.0-preview-5e098f3'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lifi/sdk-provider-stellar",
|
|
3
|
+
"version": "0.0.0-preview-5e098f3",
|
|
4
|
+
"description": "LI.FI Stellar SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
|
+
"homepage": "https://github.com/lifinance/sdk",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/lifinance/sdk/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/lifinance/sdk.git",
|
|
12
|
+
"directory": "packages/sdk-provider-stellar"
|
|
13
|
+
},
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"author": "Eugene Chybisov <eugene@li.finance>",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"main": "./dist/esm/index.js",
|
|
19
|
+
"module": "./dist/esm/index.js",
|
|
20
|
+
"types": "./dist/esm/index.d.ts",
|
|
21
|
+
"typings": "./dist/esm/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/esm/index.d.ts",
|
|
25
|
+
"import": "./dist/esm/index.js",
|
|
26
|
+
"default": "./dist/esm/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@stellar/stellar-sdk": "^16.0.1",
|
|
32
|
+
"@lifi/sdk": "0.0.0-preview-5e098f3"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"CHANGELOG.md",
|
|
39
|
+
"dist/**",
|
|
40
|
+
"!dist/**/*.tsbuildinfo",
|
|
41
|
+
"src/**/*.ts",
|
|
42
|
+
"!src/**/*.spec.ts",
|
|
43
|
+
"!src/**/*.test.ts",
|
|
44
|
+
"!src/**/*.mock.ts",
|
|
45
|
+
"!src/**/*.spec.ts",
|
|
46
|
+
"!src/**/*.handlers.ts",
|
|
47
|
+
"!src/**/*.tsbuildinfo",
|
|
48
|
+
"!**/__mocks__/**",
|
|
49
|
+
"!*.tmp",
|
|
50
|
+
"!*.env",
|
|
51
|
+
"!tsconfig.json"
|
|
52
|
+
],
|
|
53
|
+
"keywords": [
|
|
54
|
+
"swap",
|
|
55
|
+
"bridge",
|
|
56
|
+
"bridge-aggregation",
|
|
57
|
+
"cross-chain",
|
|
58
|
+
"cross-chain-applications",
|
|
59
|
+
"cross-chain-bridge",
|
|
60
|
+
"dapp",
|
|
61
|
+
"defi",
|
|
62
|
+
"ethereum",
|
|
63
|
+
"bitcoin",
|
|
64
|
+
"solana",
|
|
65
|
+
"stellar",
|
|
66
|
+
"sui",
|
|
67
|
+
"tron",
|
|
68
|
+
"lifi",
|
|
69
|
+
"multi-chain",
|
|
70
|
+
"sdk",
|
|
71
|
+
"ethers",
|
|
72
|
+
"viem",
|
|
73
|
+
"wagmi",
|
|
74
|
+
"web3",
|
|
75
|
+
"web3-react"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainType,
|
|
3
|
+
LiFiErrorCode,
|
|
4
|
+
ProviderError,
|
|
5
|
+
type SDKClient,
|
|
6
|
+
type StepExecutor,
|
|
7
|
+
type StepExecutorOptions,
|
|
8
|
+
type Token,
|
|
9
|
+
type TokenAmount,
|
|
10
|
+
} from '@lifi/sdk'
|
|
11
|
+
import { Networks, StrKey } from '@stellar/stellar-sdk'
|
|
12
|
+
import { getStellarBalance } from './actions/getStellarBalance.js'
|
|
13
|
+
import { resolveStellarAddress } from './actions/resolveStellarAddress.js'
|
|
14
|
+
import type { StellarProviderOptions, StellarSDKProvider } from './types.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Validates a Stellar account address. Only ed25519 G-addresses are accepted as
|
|
18
|
+
* senders — muxed `M`-addresses and contract `C`-addresses are intentionally
|
|
19
|
+
* rejected (see backend EXBE-227: muxed senders validate-and-throw).
|
|
20
|
+
*/
|
|
21
|
+
function isStellarAddress(address: string): boolean {
|
|
22
|
+
return StrKey.isValidEd25519PublicKey(address)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function StellarProvider(
|
|
26
|
+
options?: StellarProviderOptions
|
|
27
|
+
): StellarSDKProvider {
|
|
28
|
+
const _options: StellarProviderOptions = options ?? {}
|
|
29
|
+
return {
|
|
30
|
+
get type() {
|
|
31
|
+
return ChainType.STL
|
|
32
|
+
},
|
|
33
|
+
isAddress: isStellarAddress,
|
|
34
|
+
resolveAddress: resolveStellarAddress,
|
|
35
|
+
getBalance: (
|
|
36
|
+
client: SDKClient,
|
|
37
|
+
walletAddress: string,
|
|
38
|
+
tokens: Token[]
|
|
39
|
+
): Promise<TokenAmount[]> =>
|
|
40
|
+
getStellarBalance(
|
|
41
|
+
client,
|
|
42
|
+
walletAddress,
|
|
43
|
+
tokens,
|
|
44
|
+
_options.networkPassphrase ?? Networks.PUBLIC
|
|
45
|
+
),
|
|
46
|
+
async getStepExecutor(
|
|
47
|
+
_stepOptions: StepExecutorOptions
|
|
48
|
+
): Promise<StepExecutor> {
|
|
49
|
+
// Phase 2: transaction execution is gated on backend tx-generation
|
|
50
|
+
// (EXBE-227). Until StellarStepExecutor lands, fail loudly rather than
|
|
51
|
+
// silently.
|
|
52
|
+
throw new ProviderError(
|
|
53
|
+
LiFiErrorCode.ConfigError,
|
|
54
|
+
'Stellar transaction execution is not yet implemented.'
|
|
55
|
+
)
|
|
56
|
+
},
|
|
57
|
+
setOptions(options: StellarProviderOptions) {
|
|
58
|
+
Object.assign(_options, options)
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SDKClient,
|
|
3
|
+
type Token,
|
|
4
|
+
type TokenAmount,
|
|
5
|
+
withDedupe,
|
|
6
|
+
} from '@lifi/sdk'
|
|
7
|
+
import {
|
|
8
|
+
Account,
|
|
9
|
+
Address,
|
|
10
|
+
BASE_FEE,
|
|
11
|
+
Contract,
|
|
12
|
+
Networks,
|
|
13
|
+
rpc,
|
|
14
|
+
scValToNative,
|
|
15
|
+
TransactionBuilder,
|
|
16
|
+
} from '@stellar/stellar-sdk'
|
|
17
|
+
import { callStellarRpcsWithRetry } from '../client/getStellarRpc.js'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Fetches Stellar token balances for a wallet.
|
|
21
|
+
*
|
|
22
|
+
* Every LI.FI Stellar token — including native XLM — is addressed by its Soroban
|
|
23
|
+
* Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore
|
|
24
|
+
* read each balance uniformly by simulating the SAC `balance(account)` call over
|
|
25
|
+
* Stellar RPC, which works for native XLM, wrapped classic assets, and
|
|
26
|
+
* Soroban-native tokens alike.
|
|
27
|
+
*/
|
|
28
|
+
export const getStellarBalance = async (
|
|
29
|
+
client: SDKClient,
|
|
30
|
+
walletAddress: string,
|
|
31
|
+
tokens: Token[],
|
|
32
|
+
networkPassphrase: string = Networks.PUBLIC
|
|
33
|
+
): Promise<TokenAmount[]> => {
|
|
34
|
+
if (tokens.length === 0) {
|
|
35
|
+
return []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const results = await Promise.all(
|
|
39
|
+
tokens.map((token) =>
|
|
40
|
+
withDedupe(
|
|
41
|
+
() => getSacBalance(client, walletAddress, token, networkPassphrase),
|
|
42
|
+
{ id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }
|
|
43
|
+
).catch(() => undefined)
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return tokens.map((token, index) => {
|
|
48
|
+
const amount = results[index]
|
|
49
|
+
return amount !== undefined ? { ...token, amount } : { ...token }
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Simulates a read-only `balance(account)` call on the token's SAC and decodes
|
|
55
|
+
* the returned i128 into a bigint. Returns `undefined` when the balance cannot
|
|
56
|
+
* be read (e.g. contract not found, account not funded).
|
|
57
|
+
*/
|
|
58
|
+
const getSacBalance = async (
|
|
59
|
+
client: SDKClient,
|
|
60
|
+
walletAddress: string,
|
|
61
|
+
token: Token,
|
|
62
|
+
networkPassphrase: string
|
|
63
|
+
): Promise<bigint | undefined> => {
|
|
64
|
+
return callStellarRpcsWithRetry(client, async (server) => {
|
|
65
|
+
// A zero-sequence account is sufficient for read-only simulation.
|
|
66
|
+
const source = new Account(walletAddress, '0')
|
|
67
|
+
const contract = new Contract(token.address)
|
|
68
|
+
const transaction = new TransactionBuilder(source, {
|
|
69
|
+
fee: BASE_FEE,
|
|
70
|
+
networkPassphrase,
|
|
71
|
+
})
|
|
72
|
+
.addOperation(
|
|
73
|
+
contract.call('balance', Address.fromString(walletAddress).toScVal())
|
|
74
|
+
)
|
|
75
|
+
.setTimeout(30)
|
|
76
|
+
.build()
|
|
77
|
+
|
|
78
|
+
const simulation = await server.simulateTransaction(transaction)
|
|
79
|
+
if (!rpc.Api.isSimulationSuccess(simulation) || !simulation.result) {
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
const value = scValToNative(simulation.result.retval)
|
|
83
|
+
return value != null ? BigInt(value) : undefined
|
|
84
|
+
})
|
|
85
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Federation, StrKey } from '@stellar/stellar-sdk'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.
|
|
5
|
+
* Returns the input unchanged when it is already a valid G-address, and
|
|
6
|
+
* `undefined` when it is neither a federation address nor resolvable.
|
|
7
|
+
*/
|
|
8
|
+
export async function resolveStellarAddress(
|
|
9
|
+
name: string
|
|
10
|
+
): Promise<string | undefined> {
|
|
11
|
+
if (StrKey.isValidEd25519PublicKey(name)) {
|
|
12
|
+
return name
|
|
13
|
+
}
|
|
14
|
+
if (!name.includes('*')) {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const record = await Federation.Server.resolve(name)
|
|
19
|
+
return record.account_id
|
|
20
|
+
} catch {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'
|
|
2
|
+
import { rpc } from '@stellar/stellar-sdk'
|
|
3
|
+
|
|
4
|
+
const stellarRpcs = new LruMap<rpc.Server>(12)
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolves and caches a Stellar RPC (JSON-RPC / Soroban RPC) server for each RPC
|
|
8
|
+
* URL configured for the Stellar chain on the SDK client.
|
|
9
|
+
*/
|
|
10
|
+
const ensureStellarRpcs = async (client: SDKClient): Promise<string[]> => {
|
|
11
|
+
const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM)
|
|
12
|
+
for (const rpcUrl of rpcUrls) {
|
|
13
|
+
if (!stellarRpcs.has(rpcUrl)) {
|
|
14
|
+
stellarRpcs.set(rpcUrl, new rpc.Server(rpcUrl, { allowHttp: true }))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return rpcUrls
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getStellarRpcs = async (
|
|
21
|
+
client: SDKClient
|
|
22
|
+
): Promise<rpc.Server[]> => {
|
|
23
|
+
const rpcUrls = await ensureStellarRpcs(client)
|
|
24
|
+
return rpcUrls
|
|
25
|
+
.map((rpcUrl) => stellarRpcs.get(rpcUrl))
|
|
26
|
+
.filter((server): server is rpc.Server => Boolean(server))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Calls a function on Stellar RPC instances with retry logic. Tries each RPC in
|
|
31
|
+
* sequence until one succeeds.
|
|
32
|
+
*/
|
|
33
|
+
export const callStellarRpcsWithRetry = async <R>(
|
|
34
|
+
client: SDKClient,
|
|
35
|
+
fn: (server: rpc.Server) => Promise<R>
|
|
36
|
+
): Promise<R> => {
|
|
37
|
+
const servers = await getStellarRpcs(client)
|
|
38
|
+
if (servers.length === 0) {
|
|
39
|
+
throw new Error('No Stellar RPCs available')
|
|
40
|
+
}
|
|
41
|
+
const errors: Error[] = []
|
|
42
|
+
for (const server of servers) {
|
|
43
|
+
try {
|
|
44
|
+
return await fn(server)
|
|
45
|
+
} catch (error) {
|
|
46
|
+
errors.push(error instanceof Error ? error : new Error(String(error)))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new AggregateError(errors, `All ${servers.length} Stellar RPCs failed`)
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: module entrypoint
|
|
2
|
+
export { StellarProvider } from './StellarProvider.js'
|
|
3
|
+
export type {
|
|
4
|
+
StellarProviderOptions,
|
|
5
|
+
StellarSDKProvider,
|
|
6
|
+
StellarSignedAuthEntry,
|
|
7
|
+
StellarSignedTransaction,
|
|
8
|
+
StellarSignOptions,
|
|
9
|
+
StellarWallet,
|
|
10
|
+
} from './types.js'
|
|
11
|
+
export { isStellarProvider } from './types.js'
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainType,
|
|
3
|
+
type SDKProvider,
|
|
4
|
+
type StepExecutorContext,
|
|
5
|
+
type StepExecutorOptions,
|
|
6
|
+
} from '@lifi/sdk'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options passed to a wallet signing call. Mirrors the Stellar Wallets Kit
|
|
10
|
+
* (`@creit.tech/stellar-wallets-kit`) signing surface so a widget adapter can
|
|
11
|
+
* forward calls directly.
|
|
12
|
+
*/
|
|
13
|
+
export interface StellarSignOptions {
|
|
14
|
+
networkPassphrase?: string
|
|
15
|
+
address?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Result of signing a transaction envelope — a base64 XDR string plus the
|
|
20
|
+
* signer's public key. Matches the Stellar Wallets Kit `signTransaction` return.
|
|
21
|
+
*/
|
|
22
|
+
export interface StellarSignedTransaction {
|
|
23
|
+
signedTxXdr: string
|
|
24
|
+
signerAddress?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Result of signing a Soroban authorization entry. Matches the Stellar Wallets
|
|
29
|
+
* Kit `signAuthEntry` return. Not required for the router routes (source-account
|
|
30
|
+
* auth), exposed for future-proofing.
|
|
31
|
+
*/
|
|
32
|
+
export interface StellarSignedAuthEntry {
|
|
33
|
+
signedAuthEntry: string
|
|
34
|
+
signerAddress?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The minimal signer surface the SDK provider needs from a connected wallet.
|
|
39
|
+
* The widget builds this adapter from the Stellar Wallets Kit instance.
|
|
40
|
+
*/
|
|
41
|
+
export interface StellarWallet {
|
|
42
|
+
/** The connected G-address (source account). */
|
|
43
|
+
address: string
|
|
44
|
+
/** The network passphrase the wallet is expected to sign against. */
|
|
45
|
+
networkPassphrase: string
|
|
46
|
+
signTransaction: (
|
|
47
|
+
xdr: string,
|
|
48
|
+
opts?: StellarSignOptions
|
|
49
|
+
) => Promise<StellarSignedTransaction>
|
|
50
|
+
signAuthEntry: (
|
|
51
|
+
authEntry: string,
|
|
52
|
+
opts?: StellarSignOptions
|
|
53
|
+
) => Promise<StellarSignedAuthEntry>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface StellarProviderOptions {
|
|
57
|
+
getWallet?: () => Promise<StellarWallet>
|
|
58
|
+
/**
|
|
59
|
+
* Network passphrase for the Stellar network this provider targets.
|
|
60
|
+
* Defaults to the public (mainnet) network.
|
|
61
|
+
*/
|
|
62
|
+
networkPassphrase?: string
|
|
63
|
+
/**
|
|
64
|
+
* Optional Horizon REST endpoint used for balance/account reads. When omitted
|
|
65
|
+
* the provider falls back to the Stellar RPC URLs resolved from the SDK client.
|
|
66
|
+
*/
|
|
67
|
+
horizonUrl?: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface StellarSDKProvider extends SDKProvider {
|
|
71
|
+
setOptions(options: StellarProviderOptions): void
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isStellarProvider(
|
|
75
|
+
provider: SDKProvider
|
|
76
|
+
): provider is StellarSDKProvider {
|
|
77
|
+
return provider.type === ChainType.STL
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Phase 2 (execution) context — consumed by StellarStepExecutor + its tasks. */
|
|
81
|
+
export interface StellarTaskContext {
|
|
82
|
+
/** Hash of the submitted transaction. */
|
|
83
|
+
transactionHash?: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface StellarStepExecutorContext
|
|
87
|
+
extends StepExecutorContext,
|
|
88
|
+
StellarTaskContext {
|
|
89
|
+
wallet: StellarWallet
|
|
90
|
+
networkPassphrase: string
|
|
91
|
+
/** Base URLs for the Stellar RPC (JSON-RPC) endpoints used to submit + poll. */
|
|
92
|
+
rpcUrls: string[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface StellarStepExecutorOptions extends StepExecutorOptions {
|
|
96
|
+
wallet: StellarWallet
|
|
97
|
+
networkPassphrase: string
|
|
98
|
+
rpcUrls: string[]
|
|
99
|
+
}
|
package/src/version.ts
ADDED