@burningflames/inj-exchange-sdk 0.0.0-stage → 0.1.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.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +228 -2
  4. package/dist/ApiManager-BcwRSg4p.cjs +14 -0
  5. package/dist/ApiManager-VsZ_7GMj.js +9 -0
  6. package/dist/MsgIncreasePositionMargin-7_g04vle.d.ts +2285 -0
  7. package/dist/MsgIncreasePositionMargin-UQn6vCje.d.cts +2284 -0
  8. package/dist/bank-c5iv-fbg.cjs +480 -0
  9. package/dist/bank-xWl_W05K.js +451 -0
  10. package/dist/chain-CgjV0b1c.js +5868 -0
  11. package/dist/chain-LTb0TjXc.cjs +5903 -0
  12. package/dist/clients/chain.cjs +8 -0
  13. package/dist/clients/chain.d.cts +2 -0
  14. package/dist/clients/chain.d.ts +2 -0
  15. package/dist/clients/chain.js +1 -0
  16. package/dist/clients/indexer.cjs +14 -0
  17. package/dist/clients/indexer.d.cts +2 -0
  18. package/dist/clients/indexer.d.ts +2 -0
  19. package/dist/clients/indexer.js +1 -0
  20. package/dist/coin-8_Vn0T8-.cjs +73 -0
  21. package/dist/coin-CowdNxVV.js +68 -0
  22. package/dist/decimal-CIFXn110.js +27 -0
  23. package/dist/decimal-DJMaLHQO.cjs +38 -0
  24. package/dist/eip712-88KVCEnw.d.cts +21 -0
  25. package/dist/eip712-88KVCEnw.d.ts +21 -0
  26. package/dist/errors-CKG7zTvs.cjs +36 -0
  27. package/dist/errors-MWG_E5zA.js +25 -0
  28. package/dist/exchange-BPRx-kFI.js +4637 -0
  29. package/dist/exchange-CTLbPuA7.cjs +4966 -0
  30. package/dist/index-B3bDzB4S.d.cts +2169 -0
  31. package/dist/index-BHLUinQA.d.ts +220 -0
  32. package/dist/index-BPpDV6JA.d.cts +182 -0
  33. package/dist/index-BT_zyZW9.d.cts +220 -0
  34. package/dist/index-DcQT-y4U.d.ts +2169 -0
  35. package/dist/index-DfoLUPEo.d.ts +183 -0
  36. package/dist/index.cjs +73 -0
  37. package/dist/index.d.cts +11 -0
  38. package/dist/index.d.ts +11 -0
  39. package/dist/index.js +13 -0
  40. package/dist/indexer-D7XfYsAZ.js +21699 -0
  41. package/dist/indexer-DI7-gHOA.cjs +21770 -0
  42. package/dist/msgs-Bi5b52-R.js +11359 -0
  43. package/dist/msgs-DNyc0UtV.cjs +11442 -0
  44. package/dist/msgs.cjs +16 -0
  45. package/dist/msgs.d.cts +2 -0
  46. package/dist/msgs.d.ts +2 -0
  47. package/dist/msgs.js +1 -0
  48. package/dist/query-DGTA8Lz_.js +13375 -0
  49. package/dist/query-L1m6tP9I.cjs +13530 -0
  50. package/dist/stream-BgKRWG60.d.cts +46 -0
  51. package/dist/stream-BgKRWG60.d.ts +46 -0
  52. package/dist/stream-D8ZvUQFy.cjs +29 -0
  53. package/dist/stream-RhVNTED5.js +18 -0
  54. package/dist/tendermint-CF_W9U6D.d.ts +49 -0
  55. package/dist/tendermint-zj8c-dVM.d.cts +49 -0
  56. package/dist/tx-BRaw1C6e.d.ts +66 -0
  57. package/dist/tx-BgpasOOk.cjs +464 -0
  58. package/dist/tx-CCt0zqng.d.cts +66 -0
  59. package/dist/tx-COcDYlg3.js +411 -0
  60. package/dist/tx-DIg8nbnn.cjs +1091 -0
  61. package/dist/tx-GN0SFql2.js +1026 -0
  62. package/dist/types.cjs +38 -0
  63. package/dist/types.d.cts +13 -0
  64. package/dist/types.d.ts +13 -0
  65. package/dist/types.js +26 -0
  66. package/dist/utils.cjs +131 -0
  67. package/dist/utils.d.cts +2 -0
  68. package/dist/utils.d.ts +2 -0
  69. package/dist/utils.js +115 -0
  70. package/package.json +125 -4
@@ -0,0 +1,411 @@
1
+ import { a as SignDoc, c as TxBody, i as ModeInfo_Single, l as TxRaw, n as Fee, o as SignerInfo, r as ModeInfo, t as AuthInfo } from "./tx-GN0SFql2.js";
2
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
3
+ import { base64 } from "@scure/base";
4
+ import { keccak256 } from "viem";
5
+ // gen/injective/crypto/v1beta1/ethsecp256k1/keys.ts
6
+ function createBasePubKey$1() {
7
+ return { key: Buffer.alloc(0) };
8
+ }
9
+ const PubKey$1 = {
10
+ encode(message, writer = new BinaryWriter()) {
11
+ if (message.key.length !== 0) writer.uint32(10).bytes(message.key);
12
+ return writer;
13
+ },
14
+ decode(input, length) {
15
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
16
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
17
+ if (previousRecursionDepth >= 100) throw new globalThis.Error("protobuf decode recursion limit exceeded");
18
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
19
+ try {
20
+ const end = length === void 0 ? reader.len : reader.pos + length;
21
+ const message = createBasePubKey$1();
22
+ while (reader.pos < end) {
23
+ const tag = reader.uint32();
24
+ switch (tag >>> 3) {
25
+ case 1:
26
+ if (tag !== 10) break;
27
+ message.key = Buffer.from(reader.bytes());
28
+ continue;
29
+ }
30
+ if ((tag & 7) === 4 || tag === 0) break;
31
+ reader.skip(tag & 7);
32
+ }
33
+ return message;
34
+ } finally {
35
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
36
+ }
37
+ },
38
+ fromJSON(object) {
39
+ return { key: isSet$2(object.key) ? Buffer.from(bytesFromBase64$2(object.key)) : Buffer.alloc(0) };
40
+ },
41
+ toJSON(message) {
42
+ const obj = {};
43
+ if (message.key.length !== 0) obj.key = base64FromBytes$2(message.key);
44
+ return obj;
45
+ },
46
+ create(base) {
47
+ return PubKey$1.fromPartial(base ?? {});
48
+ },
49
+ fromPartial(object) {
50
+ const message = createBasePubKey$1();
51
+ message.key = object.key ?? Buffer.alloc(0);
52
+ return message;
53
+ }
54
+ };
55
+ function bytesFromBase64$2(b64) {
56
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
57
+ }
58
+ function base64FromBytes$2(arr) {
59
+ return globalThis.Buffer.from(arr).toString("base64");
60
+ }
61
+ function isSet$2(value) {
62
+ return value !== null && value !== void 0;
63
+ }
64
+ // utils/pagination.ts
65
+ /** Turns a caller's paging request into the proto request, key decoded. */
66
+ function toPageRequest(option) {
67
+ return option ? {
68
+ key: option.key ? Buffer.from(base64.decode(option.key)) : Buffer.from([]),
69
+ offset: option.offset || 0,
70
+ limit: option.limit || 0,
71
+ countTotal: option.countTotal || false,
72
+ reverse: option.reverse || false
73
+ } : void 0;
74
+ }
75
+ /** Turns the proto response's paging into the shape a caller receives. */
76
+ function toPagination(response) {
77
+ return {
78
+ total: response?.total ? response.total : 0,
79
+ next: response?.nextKey?.length ? base64.encode(response.nextKey) : null
80
+ };
81
+ }
82
+ // utils/tendermint.ts
83
+ function encode(bytes) {
84
+ return Buffer.from(bytes ?? []).toString("base64");
85
+ }
86
+ function sanitizeBlockId(blockId) {
87
+ if (!blockId) return void 0;
88
+ return {
89
+ hash: encode(blockId.hash),
90
+ partSetHeader: {
91
+ total: blockId.partSetHeader?.total ?? 0,
92
+ hash: encode(blockId.partSetHeader?.hash)
93
+ }
94
+ };
95
+ }
96
+ function sanitizeBlock(block) {
97
+ const header = block.header;
98
+ return {
99
+ header: {
100
+ version: header.version,
101
+ chainId: header.chainId,
102
+ height: Number(header.height),
103
+ time: header.time.toISOString(),
104
+ lastBlockId: sanitizeBlockId(header.lastBlockId),
105
+ lastCommitHash: encode(header.lastCommitHash),
106
+ dataHash: encode(header.dataHash),
107
+ validatorsHash: encode(header.validatorsHash),
108
+ nextValidatorsHash: encode(header.nextValidatorsHash),
109
+ consensusHash: encode(header.consensusHash),
110
+ appHash: encode(header.appHash),
111
+ lastResultsHash: encode(header.lastResultsHash),
112
+ evidenceHash: encode(header.evidenceHash),
113
+ proposerAddress: String(header.proposerAddress)
114
+ },
115
+ data: { txs: (block.data?.txs ?? []).map(encode) },
116
+ evidence: block.evidence,
117
+ lastCommit: block.lastCommit ? {
118
+ height: Number(block.lastCommit.height),
119
+ round: block.lastCommit.round,
120
+ blockId: sanitizeBlockId(block.lastCommit.blockId),
121
+ signatures: (block.lastCommit.signatures ?? []).map((sig) => ({
122
+ blockIdFlag: sig.blockIdFlag,
123
+ validatorAddress: encode(sig.validatorAddress),
124
+ timestamp: sig.timestamp.toISOString(),
125
+ signature: encode(sig.signature)
126
+ }))
127
+ } : void 0
128
+ };
129
+ }
130
+ function sanitizeLatestBlock(response) {
131
+ return {
132
+ blockId: sanitizeBlockId(response.blockId),
133
+ block: sanitizeBlock(response.sdkBlock ?? response.block)
134
+ };
135
+ }
136
+ // gen/cosmos/crypto/secp256k1/keys.ts
137
+ function createBasePubKey() {
138
+ return { key: Buffer.alloc(0) };
139
+ }
140
+ const PubKey = {
141
+ encode(message, writer = new BinaryWriter()) {
142
+ if (message.key.length !== 0) writer.uint32(10).bytes(message.key);
143
+ return writer;
144
+ },
145
+ decode(input, length) {
146
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
147
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
148
+ if (previousRecursionDepth >= 100) throw new globalThis.Error("protobuf decode recursion limit exceeded");
149
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
150
+ try {
151
+ const end = length === void 0 ? reader.len : reader.pos + length;
152
+ const message = createBasePubKey();
153
+ while (reader.pos < end) {
154
+ const tag = reader.uint32();
155
+ switch (tag >>> 3) {
156
+ case 1:
157
+ if (tag !== 10) break;
158
+ message.key = Buffer.from(reader.bytes());
159
+ continue;
160
+ }
161
+ if ((tag & 7) === 4 || tag === 0) break;
162
+ reader.skip(tag & 7);
163
+ }
164
+ return message;
165
+ } finally {
166
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
167
+ }
168
+ },
169
+ fromJSON(object) {
170
+ return { key: isSet$1(object.key) ? Buffer.from(bytesFromBase64$1(object.key)) : Buffer.alloc(0) };
171
+ },
172
+ toJSON(message) {
173
+ const obj = {};
174
+ if (message.key.length !== 0) obj.key = base64FromBytes$1(message.key);
175
+ return obj;
176
+ },
177
+ create(base) {
178
+ return PubKey.fromPartial(base ?? {});
179
+ },
180
+ fromPartial(object) {
181
+ const message = createBasePubKey();
182
+ message.key = object.key ?? Buffer.alloc(0);
183
+ return message;
184
+ }
185
+ };
186
+ function bytesFromBase64$1(b64) {
187
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
188
+ }
189
+ function base64FromBytes$1(arr) {
190
+ return globalThis.Buffer.from(arr).toString("base64");
191
+ }
192
+ function isSet$1(value) {
193
+ return value !== null && value !== void 0;
194
+ }
195
+ // gen/injective/types/v1beta1/tx_ext.ts
196
+ function createBaseExtensionOptionsWeb3Tx() {
197
+ return {
198
+ typedDataChainID: 0,
199
+ feePayer: "",
200
+ feePayerSig: Buffer.alloc(0)
201
+ };
202
+ }
203
+ const ExtensionOptionsWeb3Tx = {
204
+ encode(message, writer = new BinaryWriter()) {
205
+ if (message.typedDataChainID !== 0) writer.uint32(8).uint64(message.typedDataChainID);
206
+ if (message.feePayer !== "") writer.uint32(18).string(message.feePayer);
207
+ if (message.feePayerSig.length !== 0) writer.uint32(26).bytes(message.feePayerSig);
208
+ return writer;
209
+ },
210
+ decode(input, length) {
211
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
212
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
213
+ if (previousRecursionDepth >= 100) throw new globalThis.Error("protobuf decode recursion limit exceeded");
214
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
215
+ try {
216
+ const end = length === void 0 ? reader.len : reader.pos + length;
217
+ const message = createBaseExtensionOptionsWeb3Tx();
218
+ while (reader.pos < end) {
219
+ const tag = reader.uint32();
220
+ switch (tag >>> 3) {
221
+ case 1:
222
+ if (tag !== 8) break;
223
+ message.typedDataChainID = longToNumber(reader.uint64());
224
+ continue;
225
+ case 2:
226
+ if (tag !== 18) break;
227
+ message.feePayer = reader.string();
228
+ continue;
229
+ case 3:
230
+ if (tag !== 26) break;
231
+ message.feePayerSig = Buffer.from(reader.bytes());
232
+ continue;
233
+ }
234
+ if ((tag & 7) === 4 || tag === 0) break;
235
+ reader.skip(tag & 7);
236
+ }
237
+ return message;
238
+ } finally {
239
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
240
+ }
241
+ },
242
+ fromJSON(object) {
243
+ return {
244
+ typedDataChainID: isSet(object.typedDataChainID) ? globalThis.Number(object.typedDataChainID) : 0,
245
+ feePayer: isSet(object.feePayer) ? globalThis.String(object.feePayer) : "",
246
+ feePayerSig: isSet(object.feePayerSig) ? Buffer.from(bytesFromBase64(object.feePayerSig)) : Buffer.alloc(0)
247
+ };
248
+ },
249
+ toJSON(message) {
250
+ const obj = {};
251
+ if (message.typedDataChainID !== 0) obj.typedDataChainID = Math.round(message.typedDataChainID);
252
+ if (message.feePayer !== "") obj.feePayer = message.feePayer;
253
+ if (message.feePayerSig.length !== 0) obj.feePayerSig = base64FromBytes(message.feePayerSig);
254
+ return obj;
255
+ },
256
+ create(base) {
257
+ return ExtensionOptionsWeb3Tx.fromPartial(base ?? {});
258
+ },
259
+ fromPartial(object) {
260
+ const message = createBaseExtensionOptionsWeb3Tx();
261
+ message.typedDataChainID = object.typedDataChainID ?? 0;
262
+ message.feePayer = object.feePayer ?? "";
263
+ message.feePayerSig = object.feePayerSig ?? Buffer.alloc(0);
264
+ return message;
265
+ }
266
+ };
267
+ function bytesFromBase64(b64) {
268
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
269
+ }
270
+ function base64FromBytes(arr) {
271
+ return globalThis.Buffer.from(arr).toString("base64");
272
+ }
273
+ function longToNumber(int64) {
274
+ const num = globalThis.Number(int64.toString());
275
+ if (num > globalThis.Number.MAX_SAFE_INTEGER) throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
276
+ if (num < globalThis.Number.MIN_SAFE_INTEGER) throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
277
+ return num;
278
+ }
279
+ function isSet(value) {
280
+ return value !== null && value !== void 0;
281
+ }
282
+ // utils/tx.ts
283
+ function createTxBytes(txRaw) {
284
+ return Buffer.from(TxRaw.encode(TxRaw.create(txRaw)).finish());
285
+ }
286
+ /**
287
+ * The extension a web3 transaction carries: the EVM chain id it was signed
288
+ * for and, when the fee is delegated, the paying account and its signature.
289
+ */
290
+ function createWeb3Extension({ evmChainId, feePayer, feePayerSig }) {
291
+ return ExtensionOptionsWeb3Tx.create({
292
+ typedDataChainID: evmChainId,
293
+ feePayer,
294
+ feePayerSig
295
+ });
296
+ }
297
+ /**
298
+ * Appends the web3 extension to a transaction body, which is what makes the
299
+ * transaction readable by an EIP-712 signer.
300
+ */
301
+ function createTxRawEIP712({ txRaw, extension, nonCriticalExtension }) {
302
+ const body = TxBody.decode(txRaw.bodyBytes);
303
+ body.extensionOptions = [{
304
+ typeUrl: "/injective.types.v1beta1.ExtensionOptionsWeb3Tx",
305
+ value: Buffer.from(ExtensionOptionsWeb3Tx.encode(extension).finish())
306
+ }];
307
+ if (nonCriticalExtension) body.nonCriticalExtensionOptions = Array.isArray(nonCriticalExtension) ? nonCriticalExtension : [nonCriticalExtension];
308
+ return {
309
+ ...txRaw,
310
+ bodyBytes: Buffer.from(TxBody.encode(body).finish())
311
+ };
312
+ }
313
+ /**
314
+ * Builds a transaction body and auth info for one signer and returns everything
315
+ * a DIRECT signer needs, without signing anything.
316
+ */
317
+ function createTransaction(params) {
318
+ const signer = {
319
+ pubKey: params.pubKey,
320
+ accountNumber: params.accountNumber,
321
+ sequence: params.sequence
322
+ };
323
+ const message = Array.isArray(params.message) ? params.message : [params.message];
324
+ const bodyBytes = Buffer.from(TxBody.encode(createBody({
325
+ message,
326
+ memo: params.memo || "",
327
+ timeoutHeight: params.timeoutHeight
328
+ })).finish());
329
+ const authInfoBytes = Buffer.from(AuthInfo.encode(createAuthInfo({
330
+ signerInfo: [createSignerInfo({
331
+ chainId: params.chainId,
332
+ publicKey: signer.pubKey,
333
+ sequence: signer.sequence,
334
+ mode: params.signMode ?? 1
335
+ })],
336
+ fee: createFee(params.fee)
337
+ })).finish());
338
+ const signDoc = SignDoc.create({
339
+ bodyBytes,
340
+ authInfoBytes,
341
+ chainId: params.chainId,
342
+ accountNumber: signer.accountNumber
343
+ });
344
+ const signBytes = Buffer.from(SignDoc.encode(signDoc).finish());
345
+ return {
346
+ txRaw: {
347
+ bodyBytes,
348
+ authInfoBytes,
349
+ signatures: []
350
+ },
351
+ signDoc,
352
+ signBytes,
353
+ signHashedBytes: Buffer.from(keccak256(signBytes, "bytes")),
354
+ bodyBytes,
355
+ authInfoBytes,
356
+ signer
357
+ };
358
+ }
359
+ function createBody({ message, memo, timeoutHeight }) {
360
+ return TxBody.create({
361
+ messages: message.map(createAnyMessage),
362
+ memo,
363
+ timeoutHeight: timeoutHeight || 0
364
+ });
365
+ }
366
+ function createAnyMessage(msg) {
367
+ return {
368
+ typeUrl: msg.toDirectSign().type,
369
+ value: msg.toBinary()
370
+ };
371
+ }
372
+ function createFee({ amount, gas, payer, granter }) {
373
+ if (!amount.length) throw new Error("fee.amount needs at least one coin to pay the fee with");
374
+ return Fee.create({
375
+ amount: amount.map((coin) => ({
376
+ denom: coin.denom,
377
+ amount: coin.amount
378
+ })),
379
+ gasLimit: Number(gas),
380
+ payer: payer || "",
381
+ granter: granter || ""
382
+ });
383
+ }
384
+ function createSignerInfo({ chainId, publicKey, sequence, mode }) {
385
+ return SignerInfo.create({
386
+ publicKey: createPublicKey({
387
+ chainId,
388
+ key: publicKey
389
+ }),
390
+ sequence,
391
+ modeInfo: ModeInfo.create({ single: ModeInfo_Single.create({ mode }) })
392
+ });
393
+ }
394
+ function createPublicKey({ chainId, key }) {
395
+ const bytes = Buffer.from(base64.decode(key));
396
+ if (chainId.startsWith("injective")) return {
397
+ typeUrl: "/injective.crypto.v1beta1.ethsecp256k1.PubKey",
398
+ value: Buffer.from(PubKey$1.encode(PubKey$1.create({ key: bytes })).finish())
399
+ };
400
+ return {
401
+ typeUrl: chainId.startsWith("evmos") ? "/ethermint.crypto.v1.ethsecp256k1.PubKey" : "/cosmos.crypto.secp256k1.PubKey",
402
+ value: Buffer.from(PubKey.encode(PubKey.create({ key: bytes })).finish())
403
+ };
404
+ }
405
+ function createAuthInfo({ signerInfo, fee }) {
406
+ return AuthInfo.create({
407
+ signerInfos: signerInfo,
408
+ fee
409
+ });
410
+ }
411
+ export { sanitizeBlock as a, toPagination as c, createWeb3Extension as i, PubKey$1 as l, createTxBytes as n, sanitizeLatestBlock as o, createTxRawEIP712 as r, toPageRequest as s, createTransaction as t };