@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/dist/types.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_query = require("./query-L1m6tP9I.cjs");
|
|
3
|
+
const require_tx = require("./tx-DIg8nbnn.cjs");
|
|
4
|
+
const require_exchange = require("./exchange-CTLbPuA7.cjs");
|
|
5
|
+
const require_errors = require("./errors-CKG7zTvs.cjs");
|
|
6
|
+
const require_stream = require("./stream-D8ZvUQFy.cjs");
|
|
7
|
+
// types/chain/enums.ts
|
|
8
|
+
const ChainId = {
|
|
9
|
+
Mainnet: "injective-1",
|
|
10
|
+
Testnet: "injective-888",
|
|
11
|
+
Devnet: "injective-777"
|
|
12
|
+
};
|
|
13
|
+
const EvmChainId = {
|
|
14
|
+
Mainnet: 1,
|
|
15
|
+
Ropsten: 3,
|
|
16
|
+
Rinkeby: 4,
|
|
17
|
+
Goerli: 5,
|
|
18
|
+
Kovan: 42,
|
|
19
|
+
Injective: 888,
|
|
20
|
+
Sepolia: 0xaa36a7,
|
|
21
|
+
Ganache: 1337,
|
|
22
|
+
HardHat: 31337,
|
|
23
|
+
MainnetEvm: 1776,
|
|
24
|
+
DevnetEvm: 1337,
|
|
25
|
+
TestnetEvm: 1439
|
|
26
|
+
};
|
|
27
|
+
exports.ApiError = require_errors.ApiError;
|
|
28
|
+
exports.BroadcastMode = require_query.BroadcastMode;
|
|
29
|
+
exports.ChainId = ChainId;
|
|
30
|
+
exports.EvmChainId = EvmChainId;
|
|
31
|
+
exports.ExecutionType = require_exchange.ExecutionType;
|
|
32
|
+
exports.MarketStatus = require_exchange.MarketStatus;
|
|
33
|
+
exports.OrderMask = require_exchange.OrderMask;
|
|
34
|
+
exports.OrderSide = require_query.OrderSide;
|
|
35
|
+
exports.OrderType = require_exchange.OrderType;
|
|
36
|
+
exports.SignMode = require_tx.SignMode;
|
|
37
|
+
exports.StreamDisconnectReason = require_stream.StreamDisconnectReason;
|
|
38
|
+
exports.StreamState = require_stream.StreamState;
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { D as OrderType, E as OrderMask, I as SignDoc, L as SignMode, O as MarketStatus, T as ExecutionType, _ as EvmChainId, g as ChainId, k as BroadcastMode, v as OrderSide } from "./MsgIncreasePositionMargin-UQn6vCje.cjs";
|
|
2
|
+
import { n as Eip712TypedDataField, t as Eip712TypedData } from "./eip712-88KVCEnw.cjs";
|
|
3
|
+
import { a as TxRaw, c as PaginationOption, i as StdFee, n as CreateTransactionResult, o as Msg, r as SignerDetails, s as Pagination, t as CreateTransactionParams } from "./tx-CCt0zqng.cjs";
|
|
4
|
+
import { ServiceError } from "@grpc/grpc-js";
|
|
5
|
+
import { i as StreamState, n as StreamDisconnectReason, r as StreamManagerRetryConfig, t as EventTypes } from "./stream-BgKRWG60.cjs";
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
private code;
|
|
8
|
+
private details;
|
|
9
|
+
private serviceName;
|
|
10
|
+
private methodName;
|
|
11
|
+
constructor(err: ServiceError, path: string);
|
|
12
|
+
}
|
|
13
|
+
export { BroadcastMode, ChainId, CreateTransactionParams, CreateTransactionResult, Eip712TypedData, Eip712TypedDataField, EventTypes, EvmChainId, ExecutionType, MarketStatus, Msg, OrderMask, OrderSide, OrderType, Pagination, PaginationOption, type SignDoc, SignMode, SignerDetails, StdFee, StreamDisconnectReason, StreamManagerRetryConfig, StreamState, TxRaw };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { B as OrderMask, H as MarketStatus, M as OrderSide, T as SignMode, V as OrderType, _ as BroadcastMode, g as EvmChainId, h as ChainId, w as SignDoc, z as ExecutionType } from "./MsgIncreasePositionMargin-7_g04vle.js";
|
|
2
|
+
import { n as Eip712TypedDataField, t as Eip712TypedData } from "./eip712-88KVCEnw.js";
|
|
3
|
+
import { a as TxRaw, c as PaginationOption, i as StdFee, n as CreateTransactionResult, o as Msg, r as SignerDetails, s as Pagination, t as CreateTransactionParams } from "./tx-BRaw1C6e.js";
|
|
4
|
+
import { ServiceError } from "@grpc/grpc-js";
|
|
5
|
+
import { i as StreamState, n as StreamDisconnectReason, r as StreamManagerRetryConfig, t as EventTypes } from "./stream-BgKRWG60.js";
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
private code;
|
|
8
|
+
private details;
|
|
9
|
+
private serviceName;
|
|
10
|
+
private methodName;
|
|
11
|
+
constructor(err: ServiceError, path: string);
|
|
12
|
+
}
|
|
13
|
+
export { BroadcastMode, ChainId, CreateTransactionParams, CreateTransactionResult, Eip712TypedData, Eip712TypedDataField, EventTypes, EvmChainId, ExecutionType, MarketStatus, Msg, OrderMask, OrderSide, OrderType, Pagination, PaginationOption, type SignDoc, SignMode, SignerDetails, StdFee, StreamDisconnectReason, StreamManagerRetryConfig, StreamState, TxRaw };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { t as OrderSide, u as BroadcastMode } from "./query-DGTA8Lz_.js";
|
|
2
|
+
import { u as SignMode } from "./tx-GN0SFql2.js";
|
|
3
|
+
import { N as OrderMask, P as OrderType, U as MarketStatus, d as ExecutionType } from "./exchange-BPRx-kFI.js";
|
|
4
|
+
import { t as ApiError } from "./errors-MWG_E5zA.js";
|
|
5
|
+
import { n as StreamState, t as StreamDisconnectReason } from "./stream-RhVNTED5.js";
|
|
6
|
+
// types/chain/enums.ts
|
|
7
|
+
const ChainId = {
|
|
8
|
+
Mainnet: "injective-1",
|
|
9
|
+
Testnet: "injective-888",
|
|
10
|
+
Devnet: "injective-777"
|
|
11
|
+
};
|
|
12
|
+
const EvmChainId = {
|
|
13
|
+
Mainnet: 1,
|
|
14
|
+
Ropsten: 3,
|
|
15
|
+
Rinkeby: 4,
|
|
16
|
+
Goerli: 5,
|
|
17
|
+
Kovan: 42,
|
|
18
|
+
Injective: 888,
|
|
19
|
+
Sepolia: 0xaa36a7,
|
|
20
|
+
Ganache: 1337,
|
|
21
|
+
HardHat: 31337,
|
|
22
|
+
MainnetEvm: 1776,
|
|
23
|
+
DevnetEvm: 1337,
|
|
24
|
+
TestnetEvm: 1439
|
|
25
|
+
};
|
|
26
|
+
export { ApiError, BroadcastMode, ChainId, EvmChainId, ExecutionType, MarketStatus, OrderMask, OrderSide, OrderType, SignMode, StreamDisconnectReason, StreamState };
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _scure_base = require("@scure/base");
|
|
3
|
+
const require_decimal = require("./decimal-DJMaLHQO.cjs");
|
|
4
|
+
const require_tx = require("./tx-BgpasOOk.cjs");
|
|
5
|
+
// utils/encoding.ts
|
|
6
|
+
const HEX_PATTERN = /^[0-9a-fA-F]*$/;
|
|
7
|
+
function hexToBytes(hex) {
|
|
8
|
+
const actualHex = hex.replace(/^0x/i, "");
|
|
9
|
+
if (!HEX_PATTERN.test(actualHex) || actualHex.length % 2 !== 0) throw new Error(`Invalid hex string: ${hex}`);
|
|
10
|
+
const pairs = actualHex.match(/.{1,2}/g) ?? [];
|
|
11
|
+
return Uint8Array.from(pairs.map((byte) => Number.parseInt(byte, 16)));
|
|
12
|
+
}
|
|
13
|
+
function bytesToHex(bytes) {
|
|
14
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
}
|
|
16
|
+
function hexToBase64(hex) {
|
|
17
|
+
const actualHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
18
|
+
if (actualHex.trim() === "") throw new Error("Hex string cannot be empty");
|
|
19
|
+
return _scure_base.base64.encode(hexToBytes(actualHex));
|
|
20
|
+
}
|
|
21
|
+
// utils/address.ts
|
|
22
|
+
function getEthereumAddress(injectiveAddress) {
|
|
23
|
+
if (injectiveAddress.startsWith("0x")) return injectiveAddress;
|
|
24
|
+
return `0x${bytesToHex(_scure_base.bech32.fromWords(_scure_base.bech32.decode(injectiveAddress).words))}`;
|
|
25
|
+
}
|
|
26
|
+
function getInjectiveAddress(ethAddress) {
|
|
27
|
+
const bytes = hexToBytes(ethAddress);
|
|
28
|
+
if (bytes.length !== 20) throw new Error(`Invalid Ethereum address: ${ethAddress}`);
|
|
29
|
+
return _scure_base.bech32.encode("inj", _scure_base.bech32.toWords(bytes));
|
|
30
|
+
}
|
|
31
|
+
// utils/eip712.ts
|
|
32
|
+
/**
|
|
33
|
+
* The typed data an EIP-712 signer signs for a transaction. The message is two
|
|
34
|
+
* JSON strings rather than nested objects, which is what the chain's verifier
|
|
35
|
+
* rebuilds and compares against.
|
|
36
|
+
*
|
|
37
|
+
* Building the payload is as far as the SDK goes: it holds no key, so the
|
|
38
|
+
* caller signs these bytes with whatever account it owns and hands the
|
|
39
|
+
* signature to `createTransaction`.
|
|
40
|
+
*/
|
|
41
|
+
function getEip712TypedDataV2({ msgs, tx, fee, evmChainId }) {
|
|
42
|
+
const eip712Msgs = (Array.isArray(msgs) ? msgs : [msgs]).map((msg) => msg.toEip712V2());
|
|
43
|
+
return {
|
|
44
|
+
types: {
|
|
45
|
+
EIP712Domain: [
|
|
46
|
+
{
|
|
47
|
+
name: "name",
|
|
48
|
+
type: "string"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "version",
|
|
52
|
+
type: "string"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "chainId",
|
|
56
|
+
type: "uint256"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "verifyingContract",
|
|
60
|
+
type: "address"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "salt",
|
|
64
|
+
type: "string"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
Tx: [{
|
|
68
|
+
name: "context",
|
|
69
|
+
type: "string"
|
|
70
|
+
}, {
|
|
71
|
+
name: "msgs",
|
|
72
|
+
type: "string"
|
|
73
|
+
}]
|
|
74
|
+
},
|
|
75
|
+
primaryType: "Tx",
|
|
76
|
+
domain: {
|
|
77
|
+
name: "Injective Web3",
|
|
78
|
+
version: "1.0.0",
|
|
79
|
+
chainId: `0x${evmChainId.toString(16)}`,
|
|
80
|
+
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
|
81
|
+
salt: "0"
|
|
82
|
+
},
|
|
83
|
+
message: {
|
|
84
|
+
context: safeBigIntStringify(getEipTxContext({
|
|
85
|
+
...tx,
|
|
86
|
+
fee
|
|
87
|
+
})),
|
|
88
|
+
msgs: safeBigIntStringify(eip712Msgs)
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function getEipTxContext({ accountNumber, sequence, fee, timeoutHeight, chainId, memo }) {
|
|
93
|
+
return {
|
|
94
|
+
account_number: Number(accountNumber),
|
|
95
|
+
chain_id: chainId,
|
|
96
|
+
...getEip712Fee(fee),
|
|
97
|
+
memo: memo || "",
|
|
98
|
+
sequence: Number(sequence),
|
|
99
|
+
timeout_height: Number(timeoutHeight)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function getEip712Fee({ amount, gas, payer, granter }) {
|
|
103
|
+
return { fee: {
|
|
104
|
+
amount: amount.map((coin) => ({
|
|
105
|
+
denom: coin.denom,
|
|
106
|
+
amount: coin.amount
|
|
107
|
+
})),
|
|
108
|
+
gas: Number(gas),
|
|
109
|
+
...payer && { payer },
|
|
110
|
+
...granter && { granter }
|
|
111
|
+
} };
|
|
112
|
+
}
|
|
113
|
+
function safeBigIntStringify(value) {
|
|
114
|
+
return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() : item);
|
|
115
|
+
}
|
|
116
|
+
exports.bytesToHex = bytesToHex;
|
|
117
|
+
exports.createTransaction = require_tx.createTransaction;
|
|
118
|
+
exports.createTxBytes = require_tx.createTxBytes;
|
|
119
|
+
exports.createTxRawEIP712 = require_tx.createTxRawEIP712;
|
|
120
|
+
exports.createWeb3Extension = require_tx.createWeb3Extension;
|
|
121
|
+
exports.getEip712TypedDataV2 = getEip712TypedDataV2;
|
|
122
|
+
exports.getEthereumAddress = getEthereumAddress;
|
|
123
|
+
exports.getInjectiveAddress = getInjectiveAddress;
|
|
124
|
+
exports.hexToBase64 = hexToBase64;
|
|
125
|
+
exports.hexToBytes = hexToBytes;
|
|
126
|
+
exports.sanitizeBlock = require_tx.sanitizeBlock;
|
|
127
|
+
exports.sanitizeLatestBlock = require_tx.sanitizeLatestBlock;
|
|
128
|
+
exports.toChainFormat = require_decimal.toChainFormat;
|
|
129
|
+
exports.toCosmosSdkDecString = require_decimal.toCosmosSdkDecString;
|
|
130
|
+
exports.toPageRequest = require_tx.toPageRequest;
|
|
131
|
+
exports.toPagination = require_tx.toPagination;
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as sanitizeBlock, c as toPagination, d as hexToBytes, f as getEip712TypedDataV2, g as getInjectiveAddress, h as getEthereumAddress, i as createWeb3Extension, l as bytesToHex, m as toCosmosSdkDecString, n as createTxBytes, o as sanitizeLatestBlock, p as toChainFormat, r as createTxRawEIP712, s as toPageRequest, t as createTransaction, u as hexToBase64 } from "./index-BPpDV6JA.cjs";
|
|
2
|
+
export { bytesToHex, createTransaction, createTxBytes, createTxRawEIP712, createWeb3Extension, getEip712TypedDataV2, getEthereumAddress, getInjectiveAddress, hexToBase64, hexToBytes, sanitizeBlock, sanitizeLatestBlock, toChainFormat, toCosmosSdkDecString, toPageRequest, toPagination };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as sanitizeBlock, c as toPagination, d as hexToBytes, f as getEip712TypedDataV2, g as getInjectiveAddress, h as getEthereumAddress, i as createWeb3Extension, l as bytesToHex, m as toCosmosSdkDecString, n as createTxBytes, o as sanitizeLatestBlock, p as toChainFormat, r as createTxRawEIP712, s as toPageRequest, t as createTransaction, u as hexToBase64 } from "./index-DfoLUPEo.js";
|
|
2
|
+
export { bytesToHex, createTransaction, createTxBytes, createTxRawEIP712, createWeb3Extension, getEip712TypedDataV2, getEthereumAddress, getInjectiveAddress, hexToBase64, hexToBytes, sanitizeBlock, sanitizeLatestBlock, toChainFormat, toCosmosSdkDecString, toPageRequest, toPagination };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { base64, bech32 } from "@scure/base";
|
|
2
|
+
import { n as toCosmosSdkDecString, t as toChainFormat } from "./decimal-CIFXn110.js";
|
|
3
|
+
import { a as sanitizeBlock, c as toPagination, i as createWeb3Extension, n as createTxBytes, o as sanitizeLatestBlock, r as createTxRawEIP712, s as toPageRequest, t as createTransaction } from "./tx-COcDYlg3.js";
|
|
4
|
+
// utils/encoding.ts
|
|
5
|
+
const HEX_PATTERN = /^[0-9a-fA-F]*$/;
|
|
6
|
+
function hexToBytes(hex) {
|
|
7
|
+
const actualHex = hex.replace(/^0x/i, "");
|
|
8
|
+
if (!HEX_PATTERN.test(actualHex) || actualHex.length % 2 !== 0) throw new Error(`Invalid hex string: ${hex}`);
|
|
9
|
+
const pairs = actualHex.match(/.{1,2}/g) ?? [];
|
|
10
|
+
return Uint8Array.from(pairs.map((byte) => Number.parseInt(byte, 16)));
|
|
11
|
+
}
|
|
12
|
+
function bytesToHex(bytes) {
|
|
13
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
14
|
+
}
|
|
15
|
+
function hexToBase64(hex) {
|
|
16
|
+
const actualHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
17
|
+
if (actualHex.trim() === "") throw new Error("Hex string cannot be empty");
|
|
18
|
+
return base64.encode(hexToBytes(actualHex));
|
|
19
|
+
}
|
|
20
|
+
// utils/address.ts
|
|
21
|
+
function getEthereumAddress(injectiveAddress) {
|
|
22
|
+
if (injectiveAddress.startsWith("0x")) return injectiveAddress;
|
|
23
|
+
return `0x${bytesToHex(bech32.fromWords(bech32.decode(injectiveAddress).words))}`;
|
|
24
|
+
}
|
|
25
|
+
function getInjectiveAddress(ethAddress) {
|
|
26
|
+
const bytes = hexToBytes(ethAddress);
|
|
27
|
+
if (bytes.length !== 20) throw new Error(`Invalid Ethereum address: ${ethAddress}`);
|
|
28
|
+
return bech32.encode("inj", bech32.toWords(bytes));
|
|
29
|
+
}
|
|
30
|
+
// utils/eip712.ts
|
|
31
|
+
/**
|
|
32
|
+
* The typed data an EIP-712 signer signs for a transaction. The message is two
|
|
33
|
+
* JSON strings rather than nested objects, which is what the chain's verifier
|
|
34
|
+
* rebuilds and compares against.
|
|
35
|
+
*
|
|
36
|
+
* Building the payload is as far as the SDK goes: it holds no key, so the
|
|
37
|
+
* caller signs these bytes with whatever account it owns and hands the
|
|
38
|
+
* signature to `createTransaction`.
|
|
39
|
+
*/
|
|
40
|
+
function getEip712TypedDataV2({ msgs, tx, fee, evmChainId }) {
|
|
41
|
+
const eip712Msgs = (Array.isArray(msgs) ? msgs : [msgs]).map((msg) => msg.toEip712V2());
|
|
42
|
+
return {
|
|
43
|
+
types: {
|
|
44
|
+
EIP712Domain: [
|
|
45
|
+
{
|
|
46
|
+
name: "name",
|
|
47
|
+
type: "string"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "version",
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "chainId",
|
|
55
|
+
type: "uint256"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "verifyingContract",
|
|
59
|
+
type: "address"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "salt",
|
|
63
|
+
type: "string"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
Tx: [{
|
|
67
|
+
name: "context",
|
|
68
|
+
type: "string"
|
|
69
|
+
}, {
|
|
70
|
+
name: "msgs",
|
|
71
|
+
type: "string"
|
|
72
|
+
}]
|
|
73
|
+
},
|
|
74
|
+
primaryType: "Tx",
|
|
75
|
+
domain: {
|
|
76
|
+
name: "Injective Web3",
|
|
77
|
+
version: "1.0.0",
|
|
78
|
+
chainId: `0x${evmChainId.toString(16)}`,
|
|
79
|
+
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
|
80
|
+
salt: "0"
|
|
81
|
+
},
|
|
82
|
+
message: {
|
|
83
|
+
context: safeBigIntStringify(getEipTxContext({
|
|
84
|
+
...tx,
|
|
85
|
+
fee
|
|
86
|
+
})),
|
|
87
|
+
msgs: safeBigIntStringify(eip712Msgs)
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getEipTxContext({ accountNumber, sequence, fee, timeoutHeight, chainId, memo }) {
|
|
92
|
+
return {
|
|
93
|
+
account_number: Number(accountNumber),
|
|
94
|
+
chain_id: chainId,
|
|
95
|
+
...getEip712Fee(fee),
|
|
96
|
+
memo: memo || "",
|
|
97
|
+
sequence: Number(sequence),
|
|
98
|
+
timeout_height: Number(timeoutHeight)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function getEip712Fee({ amount, gas, payer, granter }) {
|
|
102
|
+
return { fee: {
|
|
103
|
+
amount: amount.map((coin) => ({
|
|
104
|
+
denom: coin.denom,
|
|
105
|
+
amount: coin.amount
|
|
106
|
+
})),
|
|
107
|
+
gas: Number(gas),
|
|
108
|
+
...payer && { payer },
|
|
109
|
+
...granter && { granter }
|
|
110
|
+
} };
|
|
111
|
+
}
|
|
112
|
+
function safeBigIntStringify(value) {
|
|
113
|
+
return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() : item);
|
|
114
|
+
}
|
|
115
|
+
export { bytesToHex, createTransaction, createTxBytes, createTxRawEIP712, createWeb3Extension, getEip712TypedDataV2, getEthereumAddress, getInjectiveAddress, hexToBase64, hexToBytes, sanitizeBlock, sanitizeLatestBlock, toChainFormat, toCosmosSdkDecString, toPageRequest, toPagination };
|
package/package.json
CHANGED
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burningflames/inj-exchange-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Trading messages, query clients and EIP-712 transaction building for the Injective exchange module",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./clients/chain": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/clients/chain.d.ts",
|
|
21
|
+
"default": "./dist/clients/chain.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/clients/chain.d.cts",
|
|
25
|
+
"default": "./dist/clients/chain.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"./clients/indexer": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/clients/indexer.d.ts",
|
|
31
|
+
"default": "./dist/clients/indexer.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/clients/indexer.d.cts",
|
|
35
|
+
"default": "./dist/clients/indexer.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./msgs": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/msgs.d.ts",
|
|
41
|
+
"default": "./dist/msgs.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/msgs.d.cts",
|
|
45
|
+
"default": "./dist/msgs.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./types": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/types.d.ts",
|
|
51
|
+
"default": "./dist/types.js"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/types.d.cts",
|
|
55
|
+
"default": "./dist/types.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./utils": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/utils.d.ts",
|
|
61
|
+
"default": "./dist/utils.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/utils.d.cts",
|
|
65
|
+
"default": "./dist/utils.cjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./package.json": "./package.json"
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"NOTICE"
|
|
73
|
+
],
|
|
74
|
+
"scripts": {
|
|
75
|
+
"lint": "oxlint",
|
|
76
|
+
"lint:fix": "oxlint --fix",
|
|
77
|
+
"format": "oxfmt clients managers msgs tests types utils tsdown.config.ts",
|
|
78
|
+
"format:check": "oxfmt --check clients managers msgs tests types utils tsdown.config.ts",
|
|
79
|
+
"typecheck": "tsc --noEmit",
|
|
80
|
+
"check": "bun run lint && bun run format:check && bun run typecheck && bun test",
|
|
81
|
+
"build": "tsdown",
|
|
82
|
+
"prepublishOnly": "bun run check && bun run build",
|
|
83
|
+
"prepack": "bun run build",
|
|
84
|
+
"test": "bun test",
|
|
85
|
+
"record:fixtures": "bun run scripts/record-encoding-fixtures.ts"
|
|
86
|
+
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"@bufbuild/protobuf": "^2.13.0",
|
|
89
|
+
"@grpc/grpc-js": "^1.14.4",
|
|
90
|
+
"@scure/base": "^2.3.0",
|
|
91
|
+
"eventemitter3": "^5.0.4",
|
|
92
|
+
"viem": "^2.58.0"
|
|
93
|
+
},
|
|
94
|
+
"devDependencies": {
|
|
95
|
+
"@types/bun": "latest",
|
|
96
|
+
"@types/node": "^26.2.0",
|
|
97
|
+
"oxfmt": "^0.79.0",
|
|
98
|
+
"oxlint": "^1.94.0",
|
|
99
|
+
"ts-proto": "^2.12.0",
|
|
100
|
+
"tsdown": "^0.23.7",
|
|
101
|
+
"typescript": "^7.0.2"
|
|
102
|
+
},
|
|
103
|
+
"main": "./dist/index.cjs",
|
|
104
|
+
"types": "./dist/index.d.ts",
|
|
105
|
+
"module": "./dist/index.js",
|
|
106
|
+
"repository": {
|
|
107
|
+
"type": "git",
|
|
108
|
+
"url": "https://github.com/Burningflames86/inj-exchange-sdk.git"
|
|
109
|
+
},
|
|
110
|
+
"homepage": "https://github.com/Burningflames86/inj-exchange-sdk#readme",
|
|
111
|
+
"bugs": {
|
|
112
|
+
"url": "https://github.com/Burningflames86/inj-exchange-sdk/issues"
|
|
113
|
+
},
|
|
114
|
+
"keywords": [
|
|
115
|
+
"injective",
|
|
116
|
+
"grpc",
|
|
117
|
+
"trading",
|
|
118
|
+
"exchange",
|
|
119
|
+
"perpetuals",
|
|
120
|
+
"eip712",
|
|
121
|
+
"sdk"
|
|
122
|
+
],
|
|
123
|
+
"publishConfig": {
|
|
124
|
+
"access": "public"
|
|
125
|
+
}
|
|
126
|
+
}
|