@lifi/sdk-provider-sui 0.0.0-preview-f5cf9f8
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 +8 -0
- package/LICENSE +201 -0
- package/README.md +79 -0
- package/dist/esm/SuiProvider.d.ts +7 -0
- package/dist/esm/SuiProvider.d.ts.map +1 -0
- package/dist/esm/SuiProvider.js +34 -0
- package/dist/esm/SuiProvider.js.map +1 -0
- package/dist/esm/actions/getSuiBalance.d.ts +7 -0
- package/dist/esm/actions/getSuiBalance.d.ts.map +1 -0
- package/dist/esm/actions/getSuiBalance.js +44 -0
- package/dist/esm/actions/getSuiBalance.js.map +1 -0
- package/dist/esm/actions/getSuiNSAddress.d.ts +7 -0
- package/dist/esm/actions/getSuiNSAddress.d.ts.map +1 -0
- package/dist/esm/actions/getSuiNSAddress.js +26 -0
- package/dist/esm/actions/getSuiNSAddress.js.map +1 -0
- package/dist/esm/actions/resolveSuiAddress.d.ts +5 -0
- package/dist/esm/actions/resolveSuiAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveSuiAddress.js +9 -0
- package/dist/esm/actions/resolveSuiAddress.js.map +1 -0
- package/dist/esm/client/suiClient.d.ts +14 -0
- package/dist/esm/client/suiClient.d.ts.map +1 -0
- package/dist/esm/client/suiClient.js +38 -0
- package/dist/esm/client/suiClient.js.map +1 -0
- package/dist/esm/core/SuiStepExecutor.d.ts +16 -0
- package/dist/esm/core/SuiStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/SuiStepExecutor.js +44 -0
- package/dist/esm/core/SuiStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js +26 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js +26 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseSuiErrors.d.ts +7 -0
- package/dist/esm/errors/parseSuiErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseSuiErrors.js +21 -0
- package/dist/esm/errors/parseSuiErrors.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 +30 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +11 -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 +76 -0
- package/src/SuiProvider.ts +56 -0
- package/src/actions/getSuiBalance.ts +92 -0
- package/src/actions/getSuiNSAddress.ts +43 -0
- package/src/actions/resolveSuiAddress.ts +7 -0
- package/src/client/suiClient.ts +43 -0
- package/src/core/SuiStepExecutor.ts +93 -0
- package/src/core/tasks/SuiSignAndExecuteTask.ts +68 -0
- package/src/core/tasks/SuiWaitForTransactionTask.ts +67 -0
- package/src/errors/parseSuiErrors.ts +59 -0
- package/src/index.ts +4 -0
- package/src/types.ts +45 -0
- package/src/version.ts +2 -0
package/CHANGELOG.md
ADDED
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,79 @@
|
|
|
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
|
+
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
|
|
17
|
+
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
|
|
18
|
+
- Easy tracking of the route and quote execution through the robust event and hooks handling
|
|
19
|
+
- 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
|
|
20
|
+
- 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)
|
|
21
|
+
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/), [Wallet Standard](https://github.com/wallet-standard/wallet-standard), [Bigmi](https://github.com/lifinance/bigmi))
|
|
22
|
+
- Support for arbitrary contract calls on the destination chain
|
|
23
|
+
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
|
|
24
|
+
- Compatibility tested with Node.js and popular front-end tools like Vite
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @lifi/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install --save @lifi/sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### Set up the SDK
|
|
41
|
+
|
|
42
|
+
Firstly, create SDK config with your integrator string.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { createConfig } from '@lifi/sdk'
|
|
46
|
+
|
|
47
|
+
createConfig({
|
|
48
|
+
integrator: 'Your dApp/company name',
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Request a Quote
|
|
53
|
+
|
|
54
|
+
Now you can interact with the SDK and for example request a quote.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { ChainId, getQuote } from '@lifi/sdk'
|
|
58
|
+
|
|
59
|
+
const quote = await getQuote({
|
|
60
|
+
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
61
|
+
fromChain: ChainId.ARB,
|
|
62
|
+
toChain: ChainId.OPT,
|
|
63
|
+
fromToken: '0x0000000000000000000000000000000000000000',
|
|
64
|
+
toToken: '0x0000000000000000000000000000000000000000',
|
|
65
|
+
fromAmount: '1000000000000000000',
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
See [examples](/examples) folder in this repository.
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
## Changelog
|
|
78
|
+
|
|
79
|
+
The [changelog](/CHANGELOG.md) is regularly updated to reflect what's changed in each new release.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiProvider.d.ts","names":[],"sources":["../../src/SuiProvider.ts"],"mappings":";;;iBAYgB,WAAA,CAAY,OAAA,GAAU,kBAAA,GAAqB,cAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getSuiBalance } from "./actions/getSuiBalance.js";
|
|
2
|
+
import { resolveSuiAddress } from "./actions/resolveSuiAddress.js";
|
|
3
|
+
import { SuiStepExecutor } from "./core/SuiStepExecutor.js";
|
|
4
|
+
import { ChainType, LiFiErrorCode, ProviderError } from "@lifi/sdk";
|
|
5
|
+
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
6
|
+
//#region src/SuiProvider.ts
|
|
7
|
+
function SuiProvider(options) {
|
|
8
|
+
const _options = options ?? {};
|
|
9
|
+
return {
|
|
10
|
+
get type() {
|
|
11
|
+
return ChainType.MVM;
|
|
12
|
+
},
|
|
13
|
+
isAddress: isValidSuiAddress,
|
|
14
|
+
resolveAddress: resolveSuiAddress,
|
|
15
|
+
getBalance: getSuiBalance,
|
|
16
|
+
async getStepExecutor(options) {
|
|
17
|
+
if (!_options.getClient) throw new ProviderError(LiFiErrorCode.ProviderUnavailable, "getClient is not provided.");
|
|
18
|
+
if (!_options.getSigner) throw new ProviderError(LiFiErrorCode.ProviderUnavailable, "getSigner is not provided.");
|
|
19
|
+
return new SuiStepExecutor({
|
|
20
|
+
client: await _options.getClient(),
|
|
21
|
+
signer: await _options.getSigner(),
|
|
22
|
+
routeId: options.routeId,
|
|
23
|
+
executionOptions: { ...options.executionOptions }
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
setOptions(options) {
|
|
27
|
+
Object.assign(_options, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { SuiProvider };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=SuiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiProvider.js","names":[],"sources":["../../src/SuiProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport { isValidSuiAddress } from '@mysten/sui/utils'\nimport { getSuiBalance } from './actions/getSuiBalance.js'\nimport { resolveSuiAddress } from './actions/resolveSuiAddress.js'\nimport { SuiStepExecutor } from './core/SuiStepExecutor.js'\nimport type { SuiProviderOptions, SuiSDKProvider } from './types.js'\n\nexport function SuiProvider(options?: SuiProviderOptions): SuiSDKProvider {\n const _options: SuiProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.MVM\n },\n isAddress: isValidSuiAddress,\n resolveAddress: resolveSuiAddress,\n getBalance: getSuiBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<SuiStepExecutor> {\n if (!_options.getClient) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getClient is not provided.'\n )\n }\n if (!_options.getSigner) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getSigner is not provided.'\n )\n }\n\n const client = await _options.getClient()\n const signer = await _options.getSigner()\n\n const executor = new SuiStepExecutor({\n client,\n signer,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: SuiProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAYA,SAAgB,YAAY,SAA8C;CACxE,MAAM,WAA+B,WAAW,CAAC;CACjD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,YAAY;EACZ,MAAM,gBACJ,SAC0B;GAC1B,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAEF,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAeF,OAAO,IATc,gBAAgB;IACnC,QAAA,MAJmB,SAAS,UAAU;IAKtC,QAAA,MAJmB,SAAS,UAAU;IAKtC,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAA6B;GACtC,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SDKClient, Token, TokenAmount } from "@lifi/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getSuiBalance.d.ts
|
|
4
|
+
declare function getSuiBalance(client: SDKClient, walletAddress: string, tokens: Token[]): Promise<TokenAmount[]>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getSuiBalance };
|
|
7
|
+
//# sourceMappingURL=getSuiBalance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;;iBASsB,aAAA,CACpB,MAAA,EAAQ,SAAA,EACR,aAAA,UACA,MAAA,EAAQ,KAAA,KACP,OAAA,CAAQ,WAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { callSuiWithRetry } from "../client/suiClient.js";
|
|
2
|
+
import { SuiTokenLongAddress, SuiTokenShortAddress } from "../types.js";
|
|
3
|
+
import { withDedupe } from "@lifi/sdk";
|
|
4
|
+
//#region src/actions/getSuiBalance.ts
|
|
5
|
+
async function getSuiBalance(client, walletAddress, tokens) {
|
|
6
|
+
if (tokens.length === 0) return [];
|
|
7
|
+
const { chainId } = tokens[0];
|
|
8
|
+
for (const token of tokens) if (token.chainId !== chainId) console.warn("Requested tokens have to be on the same chain.");
|
|
9
|
+
return getSuiBalanceDefault(client, chainId, tokens, walletAddress);
|
|
10
|
+
}
|
|
11
|
+
const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) => {
|
|
12
|
+
const [coins, checkpoint] = await Promise.allSettled([withDedupe(() => callSuiWithRetry(client, (client) => client.getAllBalances({ owner: walletAddress })), { id: `${getSuiBalanceDefault.name}.getAllBalances` }), withDedupe(() => callSuiWithRetry(client, (client) => client.getLatestCheckpointSequenceNumber()), { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` })]);
|
|
13
|
+
const coinsOk = coins.status === "fulfilled";
|
|
14
|
+
const coinsResult = coinsOk ? coins.value : [];
|
|
15
|
+
const blockNumber = checkpoint.status === "fulfilled" ? BigInt(checkpoint.value) : 0n;
|
|
16
|
+
const walletTokenAmounts = coinsResult.reduce((tokenAmounts, coin) => {
|
|
17
|
+
const amount = BigInt(coin.totalBalance);
|
|
18
|
+
if (amount > 0n) tokenAmounts[coin.coinType] = amount;
|
|
19
|
+
return tokenAmounts;
|
|
20
|
+
}, {});
|
|
21
|
+
const suiTokenBalance = coinsResult.find((coin) => coin.coinType === SuiTokenShortAddress);
|
|
22
|
+
if (suiTokenBalance?.totalBalance) walletTokenAmounts[SuiTokenLongAddress] = BigInt(suiTokenBalance.totalBalance);
|
|
23
|
+
return tokens.map((token) => {
|
|
24
|
+
const found = walletTokenAmounts[token.address];
|
|
25
|
+
if (found !== void 0) return {
|
|
26
|
+
...token,
|
|
27
|
+
amount: found,
|
|
28
|
+
blockNumber
|
|
29
|
+
};
|
|
30
|
+
if (coinsOk) return {
|
|
31
|
+
...token,
|
|
32
|
+
amount: 0n,
|
|
33
|
+
blockNumber
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...token,
|
|
37
|
+
blockNumber
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { getSuiBalance };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=getSuiBalance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiBalance.js","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../client/suiClient.js'\nimport { SuiTokenLongAddress, SuiTokenShortAddress } from '../types.js'\n\nexport async function getSuiBalance(\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> {\n if (tokens.length === 0) {\n return []\n }\n\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n\n return getSuiBalanceDefault(client, chainId, tokens, walletAddress)\n}\n\nconst getSuiBalanceDefault = async (\n client: SDKClient,\n _chainId: number,\n tokens: Token[],\n walletAddress: string\n): Promise<TokenAmount[]> => {\n const [coins, checkpoint] = await Promise.allSettled([\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getAllBalances({\n owner: walletAddress,\n })\n ),\n { id: `${getSuiBalanceDefault.name}.getAllBalances` }\n ),\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getLatestCheckpointSequenceNumber()\n ),\n { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }\n ),\n ])\n\n const coinsOk = coins.status === 'fulfilled'\n const coinsResult = coinsOk ? coins.value : []\n const blockNumber =\n checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n\n\n const walletTokenAmounts = coinsResult.reduce(\n (tokenAmounts, coin) => {\n const amount = BigInt(coin.totalBalance)\n if (amount > 0n) {\n tokenAmounts[coin.coinType] = amount\n }\n return tokenAmounts\n },\n {} as Record<string, bigint>\n )\n\n const suiTokenBalance = coinsResult.find(\n (coin) => coin.coinType === SuiTokenShortAddress\n )\n if (suiTokenBalance?.totalBalance) {\n walletTokenAmounts[SuiTokenLongAddress] = BigInt(\n suiTokenBalance.totalBalance\n )\n }\n\n const tokenAmounts: TokenAmount[] = tokens.map((token) => {\n const found = walletTokenAmounts[token.address]\n if (found !== undefined) {\n return { ...token, amount: found, blockNumber }\n }\n if (coinsOk) {\n // Wallet genuinely has no coins of this type.\n return { ...token, amount: 0n, blockNumber }\n }\n // RPC failed — leave amount undefined.\n return { ...token, blockNumber }\n })\n return tokenAmounts\n}\n"],"mappings":";;;;AASA,eAAsB,cACpB,QACA,eACA,QACwB;CACxB,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAIjE,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,aAAa;AACpE;AAEA,MAAM,uBAAuB,OAC3B,QACA,UACA,QACA,kBAC2B;CAC3B,MAAM,CAAC,OAAO,cAAc,MAAM,QAAQ,WAAW,CACnD,iBAEI,iBAAiB,SAAS,WACxB,OAAO,eAAe,EACpB,OAAO,cACT,CAAC,CACH,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,iBAAiB,CACtD,GACA,iBAEI,iBAAiB,SAAS,WACxB,OAAO,kCAAkC,CAC3C,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,oCAAoC,CACzE,CACF,CAAC;CAED,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,cAAc,UAAU,MAAM,QAAQ,CAAC;CAC7C,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,MAAM,qBAAqB,YAAY,QACpC,cAAc,SAAS;EACtB,MAAM,SAAS,OAAO,KAAK,YAAY;EACvC,IAAI,SAAS,IACX,aAAa,KAAK,YAAY;EAEhC,OAAO;CACT,GACA,CAAC,CACH;CAEA,MAAM,kBAAkB,YAAY,MACjC,SAAS,KAAK,aAAa,oBAC9B;CACA,IAAI,iBAAiB,cACnB,mBAAmB,uBAAuB,OACxC,gBAAgB,YAClB;CAeF,OAZoC,OAAO,KAAK,UAAU;EACxD,MAAM,QAAQ,mBAAmB,MAAM;EACvC,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAO;EAAY;EAEhD,IAAI,SAEF,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAI;EAAY;EAG7C,OAAO;GAAE,GAAG;GAAO;EAAY;CACjC,CACkB;AACpB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getSuiNSAddress.d.ts
|
|
4
|
+
declare function getSuiNSAddress(name: string, rpcUrl?: string, network?: SuiClientTypes.Network): Promise<string | undefined>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getSuiNSAddress };
|
|
7
|
+
//# sourceMappingURL=getSuiNSAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiNSAddress.d.ts","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"mappings":";;;iBAMsB,eAAA,CACpB,IAAA,UACA,MAAA,WACA,OAAA,GAAU,cAAA,CAAe,OAAA,GACxB,OAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
2
|
+
//#region src/actions/getSuiNSAddress.ts
|
|
3
|
+
const SNS_REGISTRY_ID = "0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4";
|
|
4
|
+
async function getSuiNSAddress(name, rpcUrl, network) {
|
|
5
|
+
const client = new SuiJsonRpcClient({
|
|
6
|
+
url: rpcUrl || "https://fullnode.mainnet.sui.io:443",
|
|
7
|
+
network: network || "mainnet"
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
const result = await client.getObject({
|
|
11
|
+
id: SNS_REGISTRY_ID,
|
|
12
|
+
options: { showContent: true }
|
|
13
|
+
});
|
|
14
|
+
if (!result.data?.content) return;
|
|
15
|
+
const nameRecord = result.data.content.fields.records.find((record) => record.fields.name === name);
|
|
16
|
+
if (!nameRecord) return;
|
|
17
|
+
return nameRecord.fields.address;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Error resolving SuiNS address:", error);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { getSuiNSAddress };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=getSuiNSAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiNSAddress.js","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"sourcesContent":["import type { SuiClientTypes } from '@mysten/sui/client'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst SNS_REGISTRY_ID =\n '0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4'\n\nexport async function getSuiNSAddress(\n name: string,\n rpcUrl?: string,\n network?: SuiClientTypes.Network\n): Promise<string | undefined> {\n const client = new SuiJsonRpcClient({\n url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',\n network: network || 'mainnet',\n })\n\n try {\n const result = await client.getObject({\n id: SNS_REGISTRY_ID,\n options: {\n showContent: true,\n },\n })\n\n if (!result.data?.content) {\n return\n }\n\n const registry = result.data.content as any\n const nameRecord = registry.fields.records.find(\n (record: any) => record.fields.name === name\n )\n\n if (!nameRecord) {\n return\n }\n\n return nameRecord.fields.address\n } catch (error) {\n console.error('Error resolving SuiNS address:', error)\n return\n }\n}\n"],"mappings":";;AAGA,MAAM,kBACJ;AAEF,eAAsB,gBACpB,MACA,QACA,SAC6B;CAC7B,MAAM,SAAS,IAAI,iBAAiB;EAClC,KAAK,UAAU;EACf,SAAS,WAAW;CACtB,CAAC;CAED,IAAI;EACF,MAAM,SAAS,MAAM,OAAO,UAAU;GACpC,IAAI;GACJ,SAAS,EACP,aAAa,KACf;EACF,CAAC;EAED,IAAI,CAAC,OAAO,MAAM,SAChB;EAIF,MAAM,aADW,OAAO,KAAK,QACD,OAAO,QAAQ,MACxC,WAAgB,OAAO,OAAO,SAAS,IAC1C;EAEA,IAAI,CAAC,YACH;EAGF,OAAO,WAAW,OAAO;CAC3B,SAAS,OAAO;EACd,QAAQ,MAAM,kCAAkC,KAAK;EACrD;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSuiAddress.d.ts","names":[],"sources":["../../../src/actions/resolveSuiAddress.ts"],"mappings":";iBAEsB,iBAAA,CACpB,IAAA,WACC,OAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getSuiNSAddress } from "./getSuiNSAddress.js";
|
|
2
|
+
//#region src/actions/resolveSuiAddress.ts
|
|
3
|
+
async function resolveSuiAddress(name) {
|
|
4
|
+
return await getSuiNSAddress(name);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { resolveSuiAddress };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=resolveSuiAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSuiAddress.js","names":[],"sources":["../../../src/actions/resolveSuiAddress.ts"],"sourcesContent":["import { getSuiNSAddress } from './getSuiNSAddress.js'\n\nexport async function resolveSuiAddress(\n name: string\n): Promise<string | undefined> {\n return await getSuiNSAddress(name)\n}\n"],"mappings":";;AAEA,eAAsB,kBACpB,MAC6B;CAC7B,OAAO,MAAM,gBAAgB,IAAI;AACnC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SDKClient } from "@lifi/sdk";
|
|
2
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
3
|
+
|
|
4
|
+
//#region src/client/suiClient.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Calls a function on the SuiJsonRpcClient instances with retry logic.
|
|
7
|
+
* @param client - The SDK client
|
|
8
|
+
* @param fn - The function to call, which receives a SuiJsonRpcClient instance.
|
|
9
|
+
* @returns - The result of the function call.
|
|
10
|
+
*/
|
|
11
|
+
declare function callSuiWithRetry<R>(client: SDKClient, fn: (client: SuiJsonRpcClient) => Promise<R>): Promise<R>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { callSuiWithRetry };
|
|
14
|
+
//# sourceMappingURL=suiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;AAyBA;;;;iBAAsB,gBAAA,GAAA,CACpB,MAAA,EAAQ,SAAA,EACR,EAAA,GAAK,MAAA,EAAQ,gBAAA,KAAqB,OAAA,CAAQ,CAAA,IACzC,OAAA,CAAQ,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ChainId } from "@lifi/sdk";
|
|
2
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
3
|
+
//#region src/client/suiClient.ts
|
|
4
|
+
const clients = /* @__PURE__ */ new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the Sui clients if they haven't been initialized yet.
|
|
7
|
+
* @returns - Promise that resolves when clients are initialized.
|
|
8
|
+
*/
|
|
9
|
+
const ensureClients = async (client) => {
|
|
10
|
+
const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI);
|
|
11
|
+
for (const rpcUrl of rpcUrls) if (!clients.get(rpcUrl)) {
|
|
12
|
+
const client = new SuiJsonRpcClient({
|
|
13
|
+
url: rpcUrl,
|
|
14
|
+
network: "mainnet"
|
|
15
|
+
});
|
|
16
|
+
clients.set(rpcUrl, client);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Calls a function on the SuiJsonRpcClient instances with retry logic.
|
|
21
|
+
* @param client - The SDK client
|
|
22
|
+
* @param fn - The function to call, which receives a SuiJsonRpcClient instance.
|
|
23
|
+
* @returns - The result of the function call.
|
|
24
|
+
*/
|
|
25
|
+
async function callSuiWithRetry(client, fn) {
|
|
26
|
+
await ensureClients(client);
|
|
27
|
+
let lastError = null;
|
|
28
|
+
for (const client of clients.values()) try {
|
|
29
|
+
return await fn(client);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
lastError = error;
|
|
32
|
+
}
|
|
33
|
+
throw lastError;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { callSuiWithRetry };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=suiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiClient.js","names":[],"sources":["../../../src/client/suiClient.ts"],"sourcesContent":["import { ChainId, type SDKClient } from '@lifi/sdk'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst clients = new Map<string, SuiJsonRpcClient>()\n\n/**\n * Initializes the Sui clients if they haven't been initialized yet.\n * @returns - Promise that resolves when clients are initialized.\n */\nconst ensureClients = async (client: SDKClient): Promise<void> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)\n for (const rpcUrl of rpcUrls) {\n if (!clients.get(rpcUrl)) {\n const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'mainnet' })\n clients.set(rpcUrl, client)\n }\n }\n}\n\n/**\n * Calls a function on the SuiJsonRpcClient instances with retry logic.\n * @param client - The SDK client\n * @param fn - The function to call, which receives a SuiJsonRpcClient instance.\n * @returns - The result of the function call.\n */\nexport async function callSuiWithRetry<R>(\n client: SDKClient,\n fn: (client: SuiJsonRpcClient) => Promise<R>\n): Promise<R> {\n // Ensure clients are initialized\n await ensureClients(client)\n let lastError: any = null\n for (const client of clients.values()) {\n try {\n const result = await fn(client)\n return result\n } catch (error) {\n lastError = error\n }\n }\n // Throw the last encountered error\n throw lastError\n}\n"],"mappings":";;;AAGA,MAAM,0BAAU,IAAI,IAA8B;;;;;AAMlD,MAAM,gBAAgB,OAAO,WAAqC;CAChE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,QAAQ,IAAI,MAAM,GAAG;EACxB,MAAM,SAAS,IAAI,iBAAiB;GAAE,KAAK;GAAQ,SAAS;EAAU,CAAC;EACvE,QAAQ,IAAI,QAAQ,MAAM;CAC5B;AAEJ;;;;;;;AAQA,eAAsB,iBACpB,QACA,IACY;CAEZ,MAAM,cAAc,MAAM;CAC1B,IAAI,YAAiB;CACrB,KAAK,MAAM,UAAU,QAAQ,OAAO,GAClC,IAAI;EAEF,OAAO,MADc,GAAG,MAAM;CAEhC,SAAS,OAAO;EACd,YAAY;CACd;CAGF,MAAM;AACR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SuiStepExecutorContext, SuiStepExecutorOptions } from "../types.js";
|
|
2
|
+
import { BaseStepExecutor, ExecutionAction, LiFiStepExtended, SDKError, StepExecutorBaseContext, TaskPipeline } from "@lifi/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/core/SuiStepExecutor.d.ts
|
|
5
|
+
declare class SuiStepExecutor extends BaseStepExecutor {
|
|
6
|
+
private client;
|
|
7
|
+
private signer;
|
|
8
|
+
constructor(options: SuiStepExecutorOptions);
|
|
9
|
+
checkWallet: (step: LiFiStepExtended) => void;
|
|
10
|
+
override parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
|
|
11
|
+
override createContext: (baseContext: StepExecutorBaseContext) => Promise<SuiStepExecutorContext>;
|
|
12
|
+
override createPipeline: (context: SuiStepExecutorContext) => TaskPipeline;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SuiStepExecutor };
|
|
16
|
+
//# sourceMappingURL=SuiStepExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiStepExecutor.d.ts","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"mappings":";;;;cAuBa,eAAA,SAAwB,gBAAA;EAAA,QAC3B,MAAA;EAAA,QACA,MAAA;EAER,WAAA,CAAY,OAAA,EAAS,sBAAA;EAMrB,WAAA,GAAe,IAAA,EAAM,gBAAA;EAAA,SAWZ,WAAA,GACP,KAAA,EAAO,KAAA,EACP,IAAA,GAAO,gBAAA,EACP,MAAA,GAAS,eAAA,KACR,OAAA,CAAQ,QAAA;EAAA,SAEF,aAAA,GACP,WAAA,EAAa,uBAAA,KACZ,OAAA,CAAQ,sBAAA;EAAA,SASF,cAAA,GAAkB,OAAA,EAAS,sBAAA,KAAyB,YAAA;AAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { parseSuiErrors } from "../errors/parseSuiErrors.js";
|
|
2
|
+
import { SuiSignAndExecuteTask } from "./tasks/SuiSignAndExecuteTask.js";
|
|
3
|
+
import { SuiWaitForTransactionTask } from "./tasks/SuiWaitForTransactionTask.js";
|
|
4
|
+
import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, PrepareTransactionTask, TaskPipeline, TransactionError, WaitForTransactionStatusTask } from "@lifi/sdk";
|
|
5
|
+
//#region src/core/SuiStepExecutor.ts
|
|
6
|
+
var SuiStepExecutor = class extends BaseStepExecutor {
|
|
7
|
+
client;
|
|
8
|
+
signer;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
this.client = options.client;
|
|
12
|
+
this.signer = options.signer;
|
|
13
|
+
}
|
|
14
|
+
checkWallet = (step) => {
|
|
15
|
+
if (this.signer.toSuiAddress() !== step.action.fromAddress) throw new TransactionError(LiFiErrorCode.WalletChangedDuringExecution, "The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.");
|
|
16
|
+
};
|
|
17
|
+
parseErrors = (error, step, action) => parseSuiErrors(error, step, action);
|
|
18
|
+
createContext = async (baseContext) => {
|
|
19
|
+
return {
|
|
20
|
+
...baseContext,
|
|
21
|
+
suiClient: this.client,
|
|
22
|
+
signer: this.signer,
|
|
23
|
+
checkWallet: this.checkWallet
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
createPipeline = (context) => {
|
|
27
|
+
const { step, isBridgeExecution } = context;
|
|
28
|
+
const tasks = [
|
|
29
|
+
new CheckBalanceTask(),
|
|
30
|
+
new PrepareTransactionTask(),
|
|
31
|
+
new SuiSignAndExecuteTask(),
|
|
32
|
+
new SuiWaitForTransactionTask(),
|
|
33
|
+
new WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
|
|
34
|
+
];
|
|
35
|
+
const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
36
|
+
const taskName = swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === "DONE" ? WaitForTransactionStatusTask.name : CheckBalanceTask.name;
|
|
37
|
+
const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
|
|
38
|
+
return new TaskPipeline(tasks.slice(firstTaskIndex));
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { SuiStepExecutor };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=SuiStepExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiStepExecutor.js","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { ClientWithCoreApi } from '@mysten/sui/client'\nimport type { Signer } from '@mysten/sui/cryptography'\nimport { parseSuiErrors } from '../errors/parseSuiErrors.js'\nimport type {\n SuiStepExecutorContext,\n SuiStepExecutorOptions,\n} from '../types.js'\nimport { SuiSignAndExecuteTask } from './tasks/SuiSignAndExecuteTask.js'\nimport { SuiWaitForTransactionTask } from './tasks/SuiWaitForTransactionTask.js'\n\nexport class SuiStepExecutor extends BaseStepExecutor {\n private client: ClientWithCoreApi\n private signer: Signer\n\n constructor(options: SuiStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.signer = options.signer\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n // Prevent execution of the quote by wallet different from the one which requested the quote\n const address = this.signer.toSuiAddress()\n if (address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSuiErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SuiStepExecutorContext> => {\n return {\n ...baseContext,\n suiClient: this.client,\n signer: this.signer,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (context: SuiStepExecutorContext): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SuiSignAndExecuteTask(),\n new SuiWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName =\n swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;AAuBA,IAAa,kBAAb,cAAqC,iBAAiB;CACpD;CACA;CAEA,YAAY,SAAiC;EAC3C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IADgB,KAAK,OAAO,aAClB,MAAM,KAAK,OAAO,aAC1B,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,eAAe,OAAO,MAAM,MAAM;CAE1D,gBAAyB,OACvB,gBACoC;EACpC,OAAO;GACL,GAAG;GACH,WAAW,KAAK;GAChB,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBAA2B,YAAkD;EAC3E,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,sBAAsB;GAC1B,IAAI,0BAA0B;GAC9B,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,WACJ,oBAAoB,UAAU,oBAAoB,WAAW,SACzD,6BAA6B,OAC7B,iBAAiB;EAEvB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAIA,OAAO,IAAI,aAFQ,MAAM,MAAM,cAEE,CAAC;CACpC;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SuiStepExecutorContext } from "../../types.js";
|
|
2
|
+
import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/core/tasks/SuiSignAndExecuteTask.d.ts
|
|
5
|
+
declare class SuiSignAndExecuteTask extends BaseStepExecutionTask {
|
|
6
|
+
run(context: SuiStepExecutorContext): Promise<TaskResult>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { SuiSignAndExecuteTask };
|
|
10
|
+
//# sourceMappingURL=SuiSignAndExecuteTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SuiSignAndExecuteTask.ts"],"mappings":";;;;cAUa,qBAAA,SAA8B,qBAAA;EACzC,GAAA,CAAU,OAAA,EAAS,sBAAA,GAAyB,OAAA,CAAQ,UAAA;AAAA"}
|