@burningflames/inj-exchange-sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +198 -2
- package/dist/ApiManager-BcwRSg4p.cjs +14 -0
- package/dist/ApiManager-VsZ_7GMj.js +9 -0
- package/dist/MsgIncreasePositionMargin-7_g04vle.d.ts +2285 -0
- package/dist/MsgIncreasePositionMargin-UQn6vCje.d.cts +2284 -0
- package/dist/bank-c5iv-fbg.cjs +480 -0
- package/dist/bank-xWl_W05K.js +451 -0
- package/dist/chain-CgjV0b1c.js +5868 -0
- package/dist/chain-LTb0TjXc.cjs +5903 -0
- package/dist/clients/chain.cjs +8 -0
- package/dist/clients/chain.d.cts +2 -0
- package/dist/clients/chain.d.ts +2 -0
- package/dist/clients/chain.js +1 -0
- package/dist/clients/indexer.cjs +14 -0
- package/dist/clients/indexer.d.cts +2 -0
- package/dist/clients/indexer.d.ts +2 -0
- package/dist/clients/indexer.js +1 -0
- package/dist/coin-8_Vn0T8-.cjs +73 -0
- package/dist/coin-CowdNxVV.js +68 -0
- package/dist/decimal-CIFXn110.js +27 -0
- package/dist/decimal-DJMaLHQO.cjs +38 -0
- package/dist/eip712-88KVCEnw.d.cts +21 -0
- package/dist/eip712-88KVCEnw.d.ts +21 -0
- package/dist/errors-CKG7zTvs.cjs +36 -0
- package/dist/errors-MWG_E5zA.js +25 -0
- package/dist/exchange-BPRx-kFI.js +4637 -0
- package/dist/exchange-CTLbPuA7.cjs +4966 -0
- package/dist/index-B3bDzB4S.d.cts +2169 -0
- package/dist/index-BHLUinQA.d.ts +220 -0
- package/dist/index-BPpDV6JA.d.cts +182 -0
- package/dist/index-BT_zyZW9.d.cts +220 -0
- package/dist/index-DcQT-y4U.d.ts +2169 -0
- package/dist/index-DfoLUPEo.d.ts +183 -0
- package/dist/index.cjs +73 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/indexer-D7XfYsAZ.js +21699 -0
- package/dist/indexer-DI7-gHOA.cjs +21770 -0
- package/dist/msgs-Bi5b52-R.js +11359 -0
- package/dist/msgs-DNyc0UtV.cjs +11442 -0
- package/dist/msgs.cjs +16 -0
- package/dist/msgs.d.cts +2 -0
- package/dist/msgs.d.ts +2 -0
- package/dist/msgs.js +1 -0
- package/dist/query-DGTA8Lz_.js +13375 -0
- package/dist/query-L1m6tP9I.cjs +13530 -0
- package/dist/stream-BgKRWG60.d.cts +46 -0
- package/dist/stream-BgKRWG60.d.ts +46 -0
- package/dist/stream-D8ZvUQFy.cjs +29 -0
- package/dist/stream-RhVNTED5.js +18 -0
- package/dist/tendermint-CF_W9U6D.d.ts +49 -0
- package/dist/tendermint-zj8c-dVM.d.cts +49 -0
- package/dist/tx-BRaw1C6e.d.ts +66 -0
- package/dist/tx-BgpasOOk.cjs +464 -0
- package/dist/tx-CCt0zqng.d.cts +66 -0
- package/dist/tx-COcDYlg3.js +411 -0
- package/dist/tx-DIg8nbnn.cjs +1091 -0
- package/dist/tx-GN0SFql2.js +1026 -0
- package/dist/types.cjs +38 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +26 -0
- package/dist/utils.cjs +131 -0
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +115 -0
- package/package.json +124 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Akhilesh Nautiyal
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
@burningflames/inj-exchange-sdk
|
|
2
|
+
Copyright 2026 Akhilesh Nautiyal
|
|
3
|
+
|
|
4
|
+
This product includes code generated by ts-proto from the Injective protocol
|
|
5
|
+
definitions (https://github.com/InjectiveLabs/injective-proto), which are
|
|
6
|
+
licensed under the Apache License, Version 2.0, Copyright Injective Labs Inc.
|
|
7
|
+
The generated sources are in gen/ and are redistributed inside dist/.
|
package/README.md
CHANGED
|
@@ -1,3 +1,199 @@
|
|
|
1
|
-
#
|
|
1
|
+
# inj-exchange-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native gRPC clients and exchange messages for the Injective backend, with the
|
|
4
|
+
EIP-712 transaction assembly that goes with them. It holds no key: you sign, and
|
|
5
|
+
the SDK hands you the bytes.
|
|
6
|
+
|
|
7
|
+
## Why this exists
|
|
8
|
+
|
|
9
|
+
`@injectivelabs/sdk-ts` talks to the chain and the indexer over **gRPC-web**. In a
|
|
10
|
+
browser that is the only option; in a backend it is the wrong one — gRPC-web needs
|
|
11
|
+
a proxy hop in front of the node, and it is meaningfully slower than the native
|
|
12
|
+
protocol for the number of calls a trading service makes.
|
|
13
|
+
|
|
14
|
+
This SDK speaks native gRPC over `@grpc/grpc-js` to the same endpoints, so a
|
|
15
|
+
backend calls the chain and the indexer directly with no proxy in the path.
|
|
16
|
+
|
|
17
|
+
## Scope
|
|
18
|
+
|
|
19
|
+
This is **not** a complete copy of `injective-sdk`, and it is not trying to be. It
|
|
20
|
+
is written for **Falq**, which is in development, and it implements the parts Falq
|
|
21
|
+
needs: the trading messages, the queries around accounts, markets, orders and
|
|
22
|
+
positions, and the transaction assembly to submit them.
|
|
23
|
+
|
|
24
|
+
Everything else is absent on purpose — governance and admin messages, market
|
|
25
|
+
launch, fee delegation, bridge and Mito services, the gRPC-web transports, and
|
|
26
|
+
wallet handling of any kind. If Falq grows a need, the class gets added; until
|
|
27
|
+
then the surface stays small enough to read.
|
|
28
|
+
|
|
29
|
+
Every exchange message class here has been carried in a mainnet transaction, and
|
|
30
|
+
`MsgSend` has moved real INJ. The account was left flat afterwards: no positions,
|
|
31
|
+
no resting orders.
|
|
32
|
+
|
|
33
|
+
There is no message for decreasing a position's margin. Mainnet answers
|
|
34
|
+
`code 92: The current feature has been disabled` for it, so the class is not
|
|
35
|
+
shipped rather than shipped and guaranteed to fail.
|
|
36
|
+
|
|
37
|
+
## What is in the box
|
|
38
|
+
|
|
39
|
+
Six entry points, each a layer:
|
|
40
|
+
|
|
41
|
+
| Import | What it gives you |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `@burningflames/inj-exchange-sdk` | everything below, in one import |
|
|
44
|
+
| `@burningflames/inj-exchange-sdk/clients/chain` | native gRPC clients for the chain: account, bank, exchange, tx, tendermint, authz |
|
|
45
|
+
| `@burningflames/inj-exchange-sdk/clients/indexer` | native gRPC clients for the indexer: markets, orders, positions, trades, balances, and the stream clients |
|
|
46
|
+
| `@burningflames/inj-exchange-sdk/msgs` | 14 message classes: the 13 exchange actions plus bank `MsgSend` |
|
|
47
|
+
| `@burningflames/inj-exchange-sdk/types` | orders, pagination, fees, EIP-712 shape, enums, `ApiError`, stream state |
|
|
48
|
+
| `@burningflames/inj-exchange-sdk/utils` | `getEip712TypedDataV2`, the transaction builders, decimal scaling, address conversion |
|
|
49
|
+
|
|
50
|
+
TypeScript sources are compiled to `dist/` in both ESM and CommonJS, with
|
|
51
|
+
declarations for each.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
bun add @burningflames/inj-exchange-sdk # or: npm i @burningflames/inj-exchange-sdk
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
From a checkout instead: `bun pm pack` builds and packs the tarball —
|
|
60
|
+
`dist/`, `package.json`, `README.md`, `LICENSE` and `NOTICE` — which installs
|
|
61
|
+
with `bun add ./burningflames-inj-exchange-sdk-0.1.0.tgz`.
|
|
62
|
+
|
|
63
|
+
## Sending a transaction
|
|
64
|
+
|
|
65
|
+
The SDK builds and encodes. You sign, because the key is yours — Turnkey, Privy,
|
|
66
|
+
or an exported key. Six calls:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { hashTypedData } from "viem";
|
|
70
|
+
import {
|
|
71
|
+
ChainAuthApiClient,
|
|
72
|
+
ChainTendermintApiClient,
|
|
73
|
+
ChainTxApiClient,
|
|
74
|
+
} from "@burningflames/inj-exchange-sdk/clients/chain";
|
|
75
|
+
import { MsgDeposit } from "@burningflames/inj-exchange-sdk/msgs";
|
|
76
|
+
import { ChainId, EvmChainId, SignMode, type StdFee } from "@burningflames/inj-exchange-sdk/types";
|
|
77
|
+
import {
|
|
78
|
+
createTransaction,
|
|
79
|
+
createTxBytes,
|
|
80
|
+
createTxRawEIP712,
|
|
81
|
+
createWeb3Extension,
|
|
82
|
+
getEip712TypedDataV2,
|
|
83
|
+
} from "@burningflames/inj-exchange-sdk/utils";
|
|
84
|
+
|
|
85
|
+
const endpoint = "sentry.chain.grpc.injective.network:443";
|
|
86
|
+
const auth = new ChainAuthApiClient(endpoint);
|
|
87
|
+
const tendermint = new ChainTendermintApiClient(endpoint);
|
|
88
|
+
const txClient = new ChainTxApiClient(endpoint);
|
|
89
|
+
|
|
90
|
+
const sender = "inj1...";
|
|
91
|
+
const message = new MsgDeposit({
|
|
92
|
+
injectiveAddress: sender,
|
|
93
|
+
subaccountId: "0x<address>00000000000000000000000000000000000000000000000000000000000001",
|
|
94
|
+
amount: { denom: "erc20:0xa00C59fF5a080D2b954d0c75e46E22a0c371235a", amount: "3000" },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// 1. what the chain knows about the account, and how long this may take
|
|
98
|
+
const { baseAccount } = await auth.fetchAccount(sender);
|
|
99
|
+
const { block } = await tendermint.fetchLatestBlock();
|
|
100
|
+
const fee: StdFee = { amount: [{ denom: "inj", amount: "112000000000000" }], gas: "400000" };
|
|
101
|
+
|
|
102
|
+
// 2. the typed data the chain verifies against
|
|
103
|
+
const typedData = getEip712TypedDataV2({
|
|
104
|
+
msgs: message,
|
|
105
|
+
tx: {
|
|
106
|
+
accountNumber: baseAccount.accountNumber,
|
|
107
|
+
sequence: baseAccount.sequence,
|
|
108
|
+
chainId: ChainId.Mainnet,
|
|
109
|
+
timeoutHeight: block.header.height + 60,
|
|
110
|
+
},
|
|
111
|
+
fee,
|
|
112
|
+
evmChainId: EvmChainId.Mainnet,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// 3. sign it. Turnkey signs the hash; Privy signs the typed data itself.
|
|
116
|
+
const signature = await signer.signTypedData(typedData); // or signer.sign(hashTypedData(typedData))
|
|
117
|
+
|
|
118
|
+
// 4. assemble, 5. attach the web3 extension, 6. broadcast
|
|
119
|
+
const { txRaw } = createTransaction({
|
|
120
|
+
message,
|
|
121
|
+
signMode: SignMode.SIGN_MODE_EIP712_V2,
|
|
122
|
+
fee,
|
|
123
|
+
pubKey: baseAccount.pubKey?.key ?? "",
|
|
124
|
+
accountNumber: baseAccount.accountNumber,
|
|
125
|
+
sequence: baseAccount.sequence,
|
|
126
|
+
timeoutHeight: block.header.height + 60,
|
|
127
|
+
chainId: ChainId.Mainnet,
|
|
128
|
+
});
|
|
129
|
+
const withExtension = createTxRawEIP712({
|
|
130
|
+
txRaw,
|
|
131
|
+
extension: createWeb3Extension({ evmChainId: EvmChainId.Mainnet }),
|
|
132
|
+
});
|
|
133
|
+
withExtension.signatures = [Buffer.from(signature.replace("0x", ""), "hex")];
|
|
134
|
+
|
|
135
|
+
await txClient.broadcast(withExtension);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
A fresh account has no public key on chain yet; `auth.fetchAccount` returns
|
|
139
|
+
`baseAccount.pubKey.key` once it has sent something, and until then you supply
|
|
140
|
+
the key yourself.
|
|
141
|
+
|
|
142
|
+
## What the chain enforces
|
|
143
|
+
|
|
144
|
+
**Order values are the human number × 1e18.** Price, quantity and margin alike.
|
|
145
|
+
`toChainFormat` does that conversion and every message class calls it — do not
|
|
146
|
+
scale anything yourself.
|
|
147
|
+
|
|
148
|
+
**`expiration_block` is part of the signature, and its position matters.** The
|
|
149
|
+
chain rebuilds the EIP-712 payload from its own field order and compares; the
|
|
150
|
+
order has to be `market_id, order_info, order_type, [margin,] trigger_price,
|
|
151
|
+
expiration_block`. Anywhere else and signature verification fails with
|
|
152
|
+
`unauthorized`. `getEip712TypedDataV2` emits that order, and `tests/msgs/eip712.test.ts`
|
|
153
|
+
asserts it.
|
|
154
|
+
|
|
155
|
+
**Prices sit on the market's tick grid.** A slippage bound computed as
|
|
156
|
+
`lastPrice × 1.05` will land at `6.5932` and be rejected: `must be a multiple of
|
|
157
|
+
the minimum price tick size 0.001`. Round to the tick.
|
|
158
|
+
|
|
159
|
+
**Orders have a minimum notional of 1 USDC.** `price × quantity` has to clear it,
|
|
160
|
+
so a 0.6 INJ bid at 1.0 is rejected with `invalid notional`.
|
|
161
|
+
|
|
162
|
+
**A market order's price bound is a real price.** It fills at the book and only
|
|
163
|
+
fails if the book is past the bound, so a couple of percent is enough — and the
|
|
164
|
+
initial-margin check uses the bound, not the fill, so a generous bound costs you
|
|
165
|
+
margin headroom.
|
|
166
|
+
|
|
167
|
+
**`countTotal` is refused by public endpoints.** Counting the full set walks all of
|
|
168
|
+
it; over gRPC the call hangs until the upstream times out. Paginate with the
|
|
169
|
+
cursor.
|
|
170
|
+
|
|
171
|
+
**Order types.** Spot orders accept `BUY`, `SELL` and the post-only variants;
|
|
172
|
+
`TAKE_BUY` is rejected. Derivative `TAKE_BUY`/`TAKE_SELL` are conditional orders
|
|
173
|
+
and need a trigger price.
|
|
174
|
+
|
|
175
|
+
**Deposits cannot target the default subaccount.** Use nonce ≥ 1.
|
|
176
|
+
|
|
177
|
+
## Markets used for the proofs
|
|
178
|
+
|
|
179
|
+
- INJ/USDC PERP `0x790aee464fbbd02cf4476444554c71d1225f7edfe15e6dc7f874c455fd883d31` — quote USDC `erc20:0xa00C59fF5a080D2b954d0c75e46E22a0c371235a`, initial margin ratio 0.0333 (30x), minimum quantity 0.01 INJ
|
|
180
|
+
- INJ/USDC spot `0xa8c14f892f7f7d2516442220a05b652d5afee3f57a5495981dfad7c99ef78e84` — base `inj`, quote the same USDC, minimum notional 1 USDC
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```sh
|
|
185
|
+
bun run check # oxlint, oxfmt --check, tsc --noEmit, bun test
|
|
186
|
+
bun test # 59 tests: encodings, EIP-712 payload, decimal scaling, pagination
|
|
187
|
+
bun run build # tsdown → dist/, ESM and CJS with declarations
|
|
188
|
+
bun pm pack # the publishable tarball
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`tests/msgs/encoding.fixtures.json` freezes the bytes of every message class — the bytes
|
|
192
|
+
mainnet transactions carried. If a change alters them, `bun run record:fixtures`
|
|
193
|
+
re-records them, and the diff is the review.
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
Apache-2.0, see [LICENSE](LICENSE). The generated sources under `gen/` come from
|
|
198
|
+
Injective's protocol definitions and keep their attribution, as [NOTICE](NOTICE)
|
|
199
|
+
records.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const require_errors = require("./errors-CKG7zTvs.cjs");
|
|
2
|
+
// managers/ApiManager.ts
|
|
3
|
+
async function ApiManager(un, req, path) {
|
|
4
|
+
return new Promise((res, rej) => un(req, (err, resp) => {
|
|
5
|
+
if (err) rej(new require_errors.ApiError(err, path));
|
|
6
|
+
res(resp);
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(exports, "ApiManager", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return ApiManager;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as ApiError } from "./errors-MWG_E5zA.js";
|
|
2
|
+
// managers/ApiManager.ts
|
|
3
|
+
async function ApiManager(un, req, path) {
|
|
4
|
+
return new Promise((res, rej) => un(req, (err, resp) => {
|
|
5
|
+
if (err) rej(new ApiError(err, path));
|
|
6
|
+
res(resp);
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
export { ApiManager as t };
|