@moveindustries/near-intents-sdk 0.0.1
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/LICENSE +201 -0
- package/README.md +62 -0
- package/dist/deposit.d.ts +17 -0
- package/dist/deposit.js +15 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/quote.d.ts +18 -0
- package/dist/quote.js +32 -0
- package/dist/registry.d.ts +55 -0
- package/dist/registry.js +41 -0
- package/dist/status.d.ts +6 -0
- package/dist/status.js +11 -0
- package/dist/submit.d.ts +9 -0
- package/dist/submit.js +9 -0
- package/dist/tokens.d.ts +14 -0
- package/dist/tokens.js +39 -0
- package/package.json +50 -0
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 [yyyy] [name of copyright owner]
|
|
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,62 @@
|
|
|
1
|
+
# near-intents-sdk
|
|
2
|
+
|
|
3
|
+
A thin TypeScript SDK for moving USDT or USDC from a supported origin chain onto Movement (as USDCx or MOVE) over NEAR Intents. It wraps the official [1Click API](https://docs.near-intents.org/near-intents/integration/distribution-channels/1click-api) client and pins the destination to Movement so callers can't accidentally land elsewhere. It orchestrates the transfer — quote, deposit address, status — and never holds keys.
|
|
4
|
+
|
|
5
|
+
## Authentication
|
|
6
|
+
|
|
7
|
+
**A 1Click JWT is optional — the full transfer works without one.** Binding quote → deposit address → status tracking all succeed unauthenticated. Verified on mainnet: a Polygon USDC → Movement USDCx transfer completed end-to-end with no token set.
|
|
8
|
+
|
|
9
|
+
Pass a JWT only to waive NEAR's protocol fee — without one, NEAR auto-injects its `appFees` and takes a small cut of the swap — and for attributed rate limits instead of anonymous IP-based ones. Obtain one at the [Partners Portal](https://partners.near-intents.org) and pass it to `configure({ jwt })`; the SDK does not mint or refresh tokens.
|
|
10
|
+
|
|
11
|
+
A JWT is a secret, so in a browser don't ship it to the client. Front 1Click with a server-side proxy that injects the token and point the SDK at it with `configure({ baseUrl: "/api/oneclick" })` (omit `jwt` — the proxy holds it). Without `baseUrl` the SDK calls 1Click directly.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { configure, quoteDeposit, prepareDepositTx, submitDeposit, getStatus, isTerminal } from "@moveindustries/near-intents-sdk";
|
|
17
|
+
|
|
18
|
+
configure({ jwt: process.env.ONE_CLICK_JWT }); // jwt optional; omit configure() entirely to run token-free
|
|
19
|
+
|
|
20
|
+
// 1. Quote: USDC on Ethereum -> USDCx on Movement. Destination is pinned to Movement.
|
|
21
|
+
const res = await quoteDeposit({
|
|
22
|
+
originChain: "ethereum", // "ethereum" | "polygon" | "tron"
|
|
23
|
+
originAsset: "usdc", // "usdc" | "usdt" (tron is usdt-only)
|
|
24
|
+
destinationAsset: "usdcx", // "usdcx" | "move"
|
|
25
|
+
amount: "1000000", // 1.0 USDC, in the origin asset's smallest units
|
|
26
|
+
recipient: "0xYourMovementAddress",
|
|
27
|
+
refundTo: "0xYourEthereumAddress",
|
|
28
|
+
// slippageTolerance: 100, // basis points, defaults to 100 (1%); raise it for `destinationAsset: "move"`
|
|
29
|
+
});
|
|
30
|
+
const { depositAddress, amountOut, deadline } = res.quote;
|
|
31
|
+
|
|
32
|
+
// 2. (Optional) Build the unsigned deposit transfer; your wallet signs + broadcasts it.
|
|
33
|
+
const depositTx = prepareDepositTx("ethereum", "usdc", res);
|
|
34
|
+
// EVM: { family: "evm", to, value, data } Tron: { family: "tron", contractAddress, function, parameter }
|
|
35
|
+
|
|
36
|
+
// 3. (Optional) After broadcasting, hand 1Click the tx hash to speed up deposit detection.
|
|
37
|
+
await submitDeposit(depositAddress!, "0xYourDepositTxHash");
|
|
38
|
+
|
|
39
|
+
// 4. Read execution status. Poll on your own cadence until isTerminal(status).
|
|
40
|
+
const { status } = await getStatus(depositAddress!);
|
|
41
|
+
// isTerminal(status) is true for "SUCCESS" | "REFUNDED" | "FAILED"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The SDK never signs, broadcasts, or holds keys — step 2 returns an *unsigned* transaction for your wallet.
|
|
45
|
+
|
|
46
|
+
## Supported routes
|
|
47
|
+
|
|
48
|
+
Backed by Movement's own solver: origins **Polygon, Ethereum, Tron** (USDC + USDT; Tron is USDT-only) → **USDCx** or **MOVE** on Movement.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
npm i @moveindustries/near-intents-sdk
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Published manually by a maintainer: bump the version, update [CHANGELOG.md](CHANGELOG.md), then `npm publish` (which builds via `prepublishOnly`). See [CHANGELOG.md](CHANGELOG.md) for changes.
|
|
57
|
+
|
|
58
|
+
## Tests
|
|
59
|
+
|
|
60
|
+
- `npm test` — unit only, offline, no secrets.
|
|
61
|
+
- `npm run test:live:noauth` — adds a live dry quote against the real API (no JWT).
|
|
62
|
+
- `npm run test:live:auth` — adds an authenticated quote; requires `ONE_CLICK_JWT` in `.env` (fails if unset).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type QuoteResponse } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
import { type OriginKey, type StableKey } from "./registry.js";
|
|
3
|
+
export type EvmDepositTx = {
|
|
4
|
+
family: "evm";
|
|
5
|
+
to: string;
|
|
6
|
+
value: "0x0";
|
|
7
|
+
data: string;
|
|
8
|
+
};
|
|
9
|
+
export type TronDepositTx = {
|
|
10
|
+
family: "tron";
|
|
11
|
+
contractAddress: string;
|
|
12
|
+
function: "transfer(address,uint256)";
|
|
13
|
+
parameter: [string, string];
|
|
14
|
+
};
|
|
15
|
+
export type DepositTx = EvmDepositTx | TronDepositTx;
|
|
16
|
+
/** Unsigned transfer of the quote's `amountIn` to its `depositAddress`. The caller signs and broadcasts. */
|
|
17
|
+
export declare function prepareDepositTx(origin: OriginKey, originAsset: StableKey, quote: QuoteResponse): DepositTx;
|
package/dist/deposit.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { resolveOrigin, family } from "./registry.js";
|
|
2
|
+
const pad32 = (hex) => hex.replace(/^0x/, "").toLowerCase().padStart(64, "0");
|
|
3
|
+
/** Unsigned transfer of the quote's `amountIn` to its `depositAddress`. The caller signs and broadcasts. */
|
|
4
|
+
export function prepareDepositTx(origin, originAsset, quote) {
|
|
5
|
+
const { tokenAddress } = resolveOrigin(origin, originAsset);
|
|
6
|
+
const { depositAddress, amountIn } = quote.quote;
|
|
7
|
+
if (!depositAddress)
|
|
8
|
+
throw new Error("quote has no depositAddress (dry run?)");
|
|
9
|
+
if (!tokenAddress)
|
|
10
|
+
throw new Error(`no verified L1 token address for ${origin}/${originAsset} (see tasks.md precondition)`);
|
|
11
|
+
if (family(origin) === "tron") {
|
|
12
|
+
return { family: "tron", contractAddress: tokenAddress, function: "transfer(address,uint256)", parameter: [depositAddress, amountIn] };
|
|
13
|
+
}
|
|
14
|
+
return { family: "evm", to: tokenAddress, value: "0x0", data: "0xa9059cbb" + pad32(depositAddress) + pad32(BigInt(amountIn).toString(16)) };
|
|
15
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { configure, quoteDeposit, type QuoteDepositParams } from "./quote.js";
|
|
2
|
+
export { prepareDepositTx, type DepositTx, type EvmDepositTx, type TronDepositTx } from "./deposit.js";
|
|
3
|
+
export { submitDeposit } from "./submit.js";
|
|
4
|
+
export { getStatus, isTerminal } from "./status.js";
|
|
5
|
+
export { listTokens, type SupportedToken } from "./tokens.js";
|
|
6
|
+
export { MOVEMENT, ORIGINS, type OriginKey, type StableKey, type DestKey } from "./registry.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { configure, quoteDeposit } from "./quote.js";
|
|
2
|
+
export { prepareDepositTx } from "./deposit.js";
|
|
3
|
+
export { submitDeposit } from "./submit.js";
|
|
4
|
+
export { getStatus, isTerminal } from "./status.js";
|
|
5
|
+
export { listTokens } from "./tokens.js";
|
|
6
|
+
export { MOVEMENT, ORIGINS } from "./registry.js";
|
package/dist/quote.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type QuoteResponse } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
import { type OriginKey, type StableKey, type DestKey } from "./registry.js";
|
|
3
|
+
export type QuoteDepositParams = {
|
|
4
|
+
originChain: OriginKey;
|
|
5
|
+
originAsset: StableKey;
|
|
6
|
+
destinationAsset: DestKey;
|
|
7
|
+
amount: string;
|
|
8
|
+
recipient: string;
|
|
9
|
+
refundTo: string;
|
|
10
|
+
slippageTolerance?: number;
|
|
11
|
+
deadline?: string;
|
|
12
|
+
dry?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function configure(opts: {
|
|
15
|
+
jwt?: string | (() => Promise<string>);
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
}): void;
|
|
18
|
+
export declare function quoteDeposit(p: QuoteDepositParams): Promise<QuoteResponse>;
|
package/dist/quote.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OneClickService, OpenAPI, QuoteRequest } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
import { resolveOrigin, resolveDest, normalizeRecipient } from "./registry.js";
|
|
3
|
+
// baseUrl points the SDK at a server-side proxy that injects the JWT, so the token
|
|
4
|
+
// never ships to the browser; omit it to call 1Click directly.
|
|
5
|
+
export function configure(opts) {
|
|
6
|
+
OpenAPI.TOKEN = opts.jwt;
|
|
7
|
+
if (opts.baseUrl)
|
|
8
|
+
OpenAPI.BASE = opts.baseUrl;
|
|
9
|
+
}
|
|
10
|
+
export async function quoteDeposit(p) {
|
|
11
|
+
const origin = resolveOrigin(p.originChain, p.originAsset);
|
|
12
|
+
const dest = resolveDest(p.destinationAsset);
|
|
13
|
+
if (!/^[0-9]+$/.test(p.amount) || BigInt(p.amount) <= 0n)
|
|
14
|
+
throw new Error(`amount must be a positive integer string: ${p.amount}`);
|
|
15
|
+
const deadline = p.deadline ?? new Date(Date.now() + 600_000).toISOString();
|
|
16
|
+
if (Date.parse(deadline) <= Date.now())
|
|
17
|
+
throw new Error(`deadline is in the past: ${deadline}`);
|
|
18
|
+
return OneClickService.getQuote({
|
|
19
|
+
dry: p.dry ?? false,
|
|
20
|
+
swapType: QuoteRequest.swapType.EXACT_INPUT,
|
|
21
|
+
slippageTolerance: p.slippageTolerance ?? 100,
|
|
22
|
+
originAsset: origin.assetId,
|
|
23
|
+
destinationAsset: dest.assetId,
|
|
24
|
+
amount: p.amount,
|
|
25
|
+
depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
|
|
26
|
+
recipient: normalizeRecipient(p.recipient),
|
|
27
|
+
recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
28
|
+
refundTo: p.refundTo,
|
|
29
|
+
refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
30
|
+
deadline,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type AssetEntry = {
|
|
2
|
+
assetId: string;
|
|
3
|
+
decimals: number;
|
|
4
|
+
tokenAddress?: string;
|
|
5
|
+
};
|
|
6
|
+
export type OriginKey = keyof typeof ORIGINS;
|
|
7
|
+
export type StableKey = "usdc" | "usdt";
|
|
8
|
+
export type DestKey = keyof typeof MOVEMENT;
|
|
9
|
+
export declare const MOVEMENT: {
|
|
10
|
+
readonly usdcx: {
|
|
11
|
+
readonly assetId: "nep141:movement-6f9a70ef4605e7d9174f1abf8d8d3c15012f48f3.omft.near";
|
|
12
|
+
readonly decimals: 6;
|
|
13
|
+
};
|
|
14
|
+
readonly move: {
|
|
15
|
+
readonly assetId: "nep141:movement.omft.near";
|
|
16
|
+
readonly decimals: 8;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const ORIGINS: {
|
|
20
|
+
readonly ethereum: {
|
|
21
|
+
readonly usdc: {
|
|
22
|
+
readonly assetId: "nep141:eth-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.omft.near";
|
|
23
|
+
readonly decimals: 6;
|
|
24
|
+
readonly tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
|
|
25
|
+
};
|
|
26
|
+
readonly usdt: {
|
|
27
|
+
readonly assetId: "nep141:eth-0xdac17f958d2ee523a2206206994597c13d831ec7.omft.near";
|
|
28
|
+
readonly decimals: 6;
|
|
29
|
+
readonly tokenAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
readonly polygon: {
|
|
33
|
+
readonly usdc: {
|
|
34
|
+
readonly assetId: "nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L";
|
|
35
|
+
readonly decimals: 6;
|
|
36
|
+
readonly tokenAddress: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359";
|
|
37
|
+
};
|
|
38
|
+
readonly usdt: {
|
|
39
|
+
readonly assetId: "nep245:v2_1.omni.hot.tg:137_3hpYoaLtt8MP1Z2GH1U473DMRKgr";
|
|
40
|
+
readonly decimals: 6;
|
|
41
|
+
readonly tokenAddress: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
readonly tron: {
|
|
45
|
+
readonly usdt: {
|
|
46
|
+
readonly assetId: "nep141:tron-d28a265909efecdcee7c5028585214ea0b96f015.omft.near";
|
|
47
|
+
readonly decimals: 6;
|
|
48
|
+
readonly tokenAddress: "41a614f803b6fd780986a42c78ec9c7f77e6ded13c";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare const family: (origin: OriginKey) => "evm" | "tron";
|
|
53
|
+
export declare function resolveOrigin(origin: string, originAsset: string): AssetEntry;
|
|
54
|
+
export declare function resolveDest(destinationAsset: string): AssetEntry;
|
|
55
|
+
export declare function normalizeRecipient(addr: string): string;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const MOVEMENT = {
|
|
2
|
+
usdcx: { assetId: "nep141:movement-6f9a70ef4605e7d9174f1abf8d8d3c15012f48f3.omft.near", decimals: 6 },
|
|
3
|
+
move: { assetId: "nep141:movement.omft.near", decimals: 8 },
|
|
4
|
+
};
|
|
5
|
+
// tokenAddress is the L1 token contract the deposit transfer targets. Provenance (the omft assetId hex
|
|
6
|
+
// equals the L1 contract only on EVM — never derive a non-EVM contract from it):
|
|
7
|
+
// ethereum USDC 0xa0b8…eb48 / USDT 0xdac1…1ec7 — canonical Ethereum contracts (also embedded in the assetId).
|
|
8
|
+
// polygon USDC 0x3c49…3359 (native USDC, NOT USDC.e) / USDT 0xc213…8e8f — canonical Polygon contracts.
|
|
9
|
+
// tron USDT 41a614f803… (TR7NHqje…) — canonical TRC-20 USDT; NOT the omft assetId hex (a bridge id).
|
|
10
|
+
export const ORIGINS = {
|
|
11
|
+
ethereum: {
|
|
12
|
+
usdc: { assetId: "nep141:eth-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.omft.near", decimals: 6, tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" },
|
|
13
|
+
usdt: { assetId: "nep141:eth-0xdac17f958d2ee523a2206206994597c13d831ec7.omft.near", decimals: 6, tokenAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7" },
|
|
14
|
+
},
|
|
15
|
+
polygon: {
|
|
16
|
+
usdc: { assetId: "nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L", decimals: 6, tokenAddress: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359" },
|
|
17
|
+
usdt: { assetId: "nep245:v2_1.omni.hot.tg:137_3hpYoaLtt8MP1Z2GH1U473DMRKgr", decimals: 6, tokenAddress: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f" },
|
|
18
|
+
},
|
|
19
|
+
tron: {
|
|
20
|
+
usdt: { assetId: "nep141:tron-d28a265909efecdcee7c5028585214ea0b96f015.omft.near", decimals: 6, tokenAddress: "41a614f803b6fd780986a42c78ec9c7f77e6ded13c" },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const family = (origin) => (origin === "tron" ? "tron" : "evm");
|
|
24
|
+
export function resolveOrigin(origin, originAsset) {
|
|
25
|
+
const e = ORIGINS[origin]?.[originAsset];
|
|
26
|
+
if (!e)
|
|
27
|
+
throw new Error(`unsupported origin/originAsset: ${origin}/${originAsset}`);
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
export function resolveDest(destinationAsset) {
|
|
31
|
+
const e = MOVEMENT[destinationAsset];
|
|
32
|
+
if (!e)
|
|
33
|
+
throw new Error(`unsupported destination: ${destinationAsset}`);
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
export function normalizeRecipient(addr) {
|
|
37
|
+
const hex = addr.startsWith("0x") ? addr.slice(2) : addr;
|
|
38
|
+
if (!/^[0-9a-fA-F]+$/.test(hex) || hex.length > 64)
|
|
39
|
+
throw new Error(`recipient is not valid: ${addr}`);
|
|
40
|
+
return "0x" + hex.toLowerCase().padStart(64, "0");
|
|
41
|
+
}
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GetExecutionStatusResponse } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
export declare const isTerminal: (status: GetExecutionStatusResponse.status) => boolean;
|
|
3
|
+
/** Fetch the swap's current execution status once. Poll it yourself, checking `isTerminal`. */
|
|
4
|
+
export declare function getStatus(depositAddress: string, opts?: {
|
|
5
|
+
depositMemo?: string;
|
|
6
|
+
}): Promise<GetExecutionStatusResponse>;
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OneClickService, GetExecutionStatusResponse } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
const TERMINAL = new Set([
|
|
3
|
+
GetExecutionStatusResponse.status.SUCCESS,
|
|
4
|
+
GetExecutionStatusResponse.status.REFUNDED,
|
|
5
|
+
GetExecutionStatusResponse.status.FAILED,
|
|
6
|
+
]);
|
|
7
|
+
export const isTerminal = (status) => TERMINAL.has(status);
|
|
8
|
+
/** Fetch the swap's current execution status once. Poll it yourself, checking `isTerminal`. */
|
|
9
|
+
export async function getStatus(depositAddress, opts = {}) {
|
|
10
|
+
return OneClickService.getExecutionStatus(depositAddress, opts.depositMemo);
|
|
11
|
+
}
|
package/dist/submit.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type SubmitDepositTxResponse } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Hand 1Click the deposit tx hash so it can start processing without waiting to
|
|
4
|
+
* detect the deposit on the origin chain. Optional speed-up — status tracking works
|
|
5
|
+
* without it. Goes between broadcasting the deposit and reading status.
|
|
6
|
+
*/
|
|
7
|
+
export declare function submitDeposit(depositAddress: string, txHash: string, opts?: {
|
|
8
|
+
memo?: string;
|
|
9
|
+
}): Promise<SubmitDepositTxResponse>;
|
package/dist/submit.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OneClickService } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Hand 1Click the deposit tx hash so it can start processing without waiting to
|
|
4
|
+
* detect the deposit on the origin chain. Optional speed-up — status tracking works
|
|
5
|
+
* without it. Goes between broadcasting the deposit and reading status.
|
|
6
|
+
*/
|
|
7
|
+
export async function submitDeposit(depositAddress, txHash, opts = {}) {
|
|
8
|
+
return OneClickService.submitDepositTx({ depositAddress, txHash, memo: opts.memo });
|
|
9
|
+
}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type OriginKey, type StableKey, type DestKey } from "./registry.js";
|
|
2
|
+
export type SupportedToken = {
|
|
3
|
+
assetId: string;
|
|
4
|
+
symbol: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
chain: string;
|
|
7
|
+
contractAddress?: string;
|
|
8
|
+
price: number;
|
|
9
|
+
priceUpdatedAt: string;
|
|
10
|
+
originChain?: OriginKey;
|
|
11
|
+
originAsset?: StableKey;
|
|
12
|
+
destinationAsset?: DestKey;
|
|
13
|
+
};
|
|
14
|
+
export declare function listTokens(): Promise<SupportedToken[]>;
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OneClickService } from "@defuse-protocol/one-click-sdk-typescript";
|
|
2
|
+
import { ORIGINS, MOVEMENT } from "./registry.js";
|
|
3
|
+
// assetId -> route tag, built once from the registry so listTokens can label each
|
|
4
|
+
// live token with the keys quoteDeposit expects, instead of callers translating back.
|
|
5
|
+
const ROUTE_BY_ASSET_ID = (() => {
|
|
6
|
+
const m = new Map();
|
|
7
|
+
const origins = ORIGINS;
|
|
8
|
+
for (const origin of Object.keys(origins)) {
|
|
9
|
+
for (const asset of Object.keys(origins[origin])) {
|
|
10
|
+
m.set(origins[origin][asset].assetId, { originChain: origin, originAsset: asset });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const dests = MOVEMENT;
|
|
14
|
+
for (const dest of Object.keys(dests))
|
|
15
|
+
m.set(dests[dest].assetId, { destinationAsset: dest });
|
|
16
|
+
return m;
|
|
17
|
+
})();
|
|
18
|
+
// listTokens — live /v0/tokens, filtered to the routes this SDK supports and each tagged with its
|
|
19
|
+
// route-key, so a caller feeds the result straight into quoteDeposit without translating back.
|
|
20
|
+
export async function listTokens() {
|
|
21
|
+
const tokens = await OneClickService.getTokens();
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const t of tokens) {
|
|
24
|
+
const tag = ROUTE_BY_ASSET_ID.get(t.assetId);
|
|
25
|
+
if (!tag)
|
|
26
|
+
continue;
|
|
27
|
+
out.push({
|
|
28
|
+
assetId: t.assetId,
|
|
29
|
+
symbol: t.symbol,
|
|
30
|
+
decimals: t.decimals,
|
|
31
|
+
chain: t.blockchain,
|
|
32
|
+
contractAddress: t.contractAddress,
|
|
33
|
+
price: t.price,
|
|
34
|
+
priceUpdatedAt: t.priceUpdatedAt,
|
|
35
|
+
...tag,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moveindustries/near-intents-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Thin SDK: USDT/USDC -> Movement USDCx/MOVE over NEAR Intents 1Click.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/MoveIndustries/near-intents-sdk.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/MoveIndustries/near-intents-sdk#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/MoveIndustries/near-intents-sdk/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"movement",
|
|
21
|
+
"near-intents",
|
|
22
|
+
"1click",
|
|
23
|
+
"usdc",
|
|
24
|
+
"usdt",
|
|
25
|
+
"bridge"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:live:noauth": "LIVE=1 node --env-file-if-exists=.env ./node_modules/.bin/vitest run",
|
|
36
|
+
"test:live:auth": "LIVE=1 AUTH=1 node --env-file-if-exists=.env ./node_modules/.bin/vitest run",
|
|
37
|
+
"changeset": "changeset",
|
|
38
|
+
"version-packages": "changeset version",
|
|
39
|
+
"publish-packages": "changeset publish"
|
|
40
|
+
},
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@defuse-protocol/one-click-sdk-typescript": "^0.1.24"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@changesets/cli": "^2.31.0",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"vitest": "^4.1.9"
|
|
49
|
+
}
|
|
50
|
+
}
|