@injectivelabs/sdk-ts 1.16.6-alpha.0 → 1.16.6
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/README.md +1 -1
- package/dist/cjs/client/indexer/grpc/IndexerGrpcTransactionApi.d.ts +3 -3
- package/dist/cjs/client/indexer/grpc/IndexerGrpcWeb3GwApi.d.ts +2 -2
- package/dist/cjs/client/indexer/transformers/IndexerGrpcDerivativeTransformer.js +1 -0
- package/dist/cjs/client/indexer/types/derivatives.d.ts +1 -0
- package/dist/cjs/core/accounts/PrivateKey.d.ts +2 -2
- package/dist/cjs/core/accounts/PrivateKey.js +17 -17
- package/dist/cjs/core/modules/wasm/msgs/MsgExecuteContract.d.ts +0 -1
- package/dist/cjs/core/modules/wasm/msgs/MsgExecuteContract.js +7 -3
- package/dist/cjs/core/tx/broadcaster/MsgBroadcasterWithPk.d.ts +3 -3
- package/dist/cjs/core/tx/broadcaster/MsgBroadcasterWithPk.js +7 -6
- package/dist/cjs/core/tx/eip712/eip712.d.ts +5 -5
- package/dist/cjs/core/tx/eip712/eip712.js +4 -4
- package/dist/cjs/core/tx/eip712/utils.d.ts +3 -3
- package/dist/cjs/core/tx/eip712/utils.js +4 -4
- package/dist/cjs/core/tx/utils/tx.d.ts +3 -3
- package/dist/cjs/core/tx/utils/tx.js +2 -2
- package/dist/cjs/utils/grpc.d.ts +1 -1
- package/dist/cjs/utils/pagination.d.ts +1 -1
- package/dist/cjs/utils/pagination.js +12 -5
- package/dist/esm/client/indexer/grpc/IndexerGrpcTransactionApi.d.ts +3 -3
- package/dist/esm/client/indexer/grpc/IndexerGrpcWeb3GwApi.d.ts +2 -2
- package/dist/esm/client/indexer/transformers/IndexerGrpcDerivativeTransformer.js +1 -0
- package/dist/esm/client/indexer/types/derivatives.d.ts +1 -0
- package/dist/esm/core/accounts/PrivateKey.d.ts +2 -2
- package/dist/esm/core/accounts/PrivateKey.js +17 -17
- package/dist/esm/core/modules/wasm/msgs/MsgExecuteContract.d.ts +0 -1
- package/dist/esm/core/modules/wasm/msgs/MsgExecuteContract.js +7 -3
- package/dist/esm/core/tx/broadcaster/MsgBroadcasterWithPk.d.ts +3 -3
- package/dist/esm/core/tx/broadcaster/MsgBroadcasterWithPk.js +7 -6
- package/dist/esm/core/tx/eip712/eip712.d.ts +5 -5
- package/dist/esm/core/tx/eip712/eip712.js +5 -5
- package/dist/esm/core/tx/eip712/utils.d.ts +3 -3
- package/dist/esm/core/tx/eip712/utils.js +4 -4
- package/dist/esm/core/tx/utils/tx.d.ts +3 -3
- package/dist/esm/core/tx/utils/tx.js +2 -2
- package/dist/esm/utils/grpc.d.ts +1 -1
- package/dist/esm/utils/pagination.d.ts +1 -1
- package/dist/esm/utils/pagination.js +12 -5
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AccountAddress,
|
|
1
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js';
|
|
5
5
|
interface PrepareTxArgs {
|
|
6
6
|
address: AccountAddress;
|
|
7
|
-
chainId:
|
|
7
|
+
chainId: EthereumChainId;
|
|
8
8
|
message: any;
|
|
9
9
|
estimateGas?: boolean;
|
|
10
10
|
gasLimit?: number;
|
|
@@ -41,7 +41,7 @@ export declare class IndexerGrpcTransactionApi extends BaseGrpcConsumer {
|
|
|
41
41
|
*/
|
|
42
42
|
broadcastTxRequest({ signature, chainId, message, txResponse, }: {
|
|
43
43
|
signature: string;
|
|
44
|
-
chainId:
|
|
44
|
+
chainId: EthereumChainId;
|
|
45
45
|
useCorrectEIP712Hash?: boolean;
|
|
46
46
|
txResponse: InjectiveExchangeRpc.PrepareTxResponse;
|
|
47
47
|
message: Record<string, any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountAddress,
|
|
1
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
import { IndexerGrpcTransactionApi } from './IndexerGrpcTransactionApi.js';
|
|
4
4
|
/**
|
|
@@ -9,7 +9,7 @@ export declare class IndexerGrpcWeb3GwApi extends IndexerGrpcTransactionApi {
|
|
|
9
9
|
constructor(endpoint: string);
|
|
10
10
|
prepareEip712Request({ address, chainId, message, memo, sequence, accountNumber, estimateGas, gasLimit, feeDenom, feePrice, timeoutHeight, eip712Version, }: {
|
|
11
11
|
address: AccountAddress;
|
|
12
|
-
chainId:
|
|
12
|
+
chainId: EthereumChainId;
|
|
13
13
|
message: any;
|
|
14
14
|
estimateGas?: boolean;
|
|
15
15
|
gasLimit?: number;
|
|
@@ -203,6 +203,7 @@ class IndexerGrpcDerivativeTransformer {
|
|
|
203
203
|
oracleQuote: market.oracleQuote,
|
|
204
204
|
oracleType: market.oracleType,
|
|
205
205
|
oracleScaleFactor: market.oracleScaleFactor,
|
|
206
|
+
reduceMarginRatio: market.reduceMarginRatio,
|
|
206
207
|
initialMarginRatio: market.initialMarginRatio,
|
|
207
208
|
maintenanceMarginRatio: market.maintenanceMarginRatio,
|
|
208
209
|
isPerpetual: market.isPerpetual,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
2
|
-
import { Address } from './Address.js';
|
|
3
1
|
import { PublicKey } from './PublicKey.js';
|
|
2
|
+
import { Address } from './Address.js';
|
|
3
|
+
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
/**
|
|
5
5
|
* Class for wrapping SigningKey that is used for signature creation and public key derivation.
|
|
6
6
|
*
|
|
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PrivateKey = void 0;
|
|
7
|
-
const secp256k1_1 = __importDefault(require("secp256k1"));
|
|
8
|
-
const keccak256_1 = __importDefault(require("keccak256"));
|
|
9
7
|
const bip39_1 = require("bip39");
|
|
10
|
-
const core_proto_ts_1 = require("@injectivelabs/core-proto-ts");
|
|
11
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
12
|
-
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
13
8
|
const ethers_1 = require("ethers");
|
|
9
|
+
const secp256k1_1 = __importDefault(require("secp256k1"));
|
|
10
|
+
const keccak256_1 = __importDefault(require("keccak256"));
|
|
11
|
+
const PublicKey_js_1 = require("./PublicKey.js");
|
|
12
|
+
const Address_js_1 = require("./Address.js");
|
|
14
13
|
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
15
14
|
const index_js_1 = require("../../utils/index.js");
|
|
16
|
-
const
|
|
17
|
-
const PublicKey_js_1 = require("./PublicKey.js");
|
|
15
|
+
const core_proto_ts_1 = require("@injectivelabs/core-proto-ts");
|
|
18
16
|
const tx_js_1 = require("../tx/utils/tx.js");
|
|
19
17
|
const index_js_2 = require("../tx/eip712/index.js");
|
|
18
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
19
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
20
20
|
/**
|
|
21
21
|
* Class for wrapping SigningKey that is used for signature creation and public key derivation.
|
|
22
22
|
*
|
|
@@ -266,31 +266,31 @@ class PrivateKey {
|
|
|
266
266
|
const getChainIds = () => {
|
|
267
267
|
if (!body.extensionOptions.length) {
|
|
268
268
|
return {
|
|
269
|
+
ethereumChainId: ts_types_1.EthereumChainId.Mainnet,
|
|
269
270
|
chainId: ts_types_1.ChainId.Mainnet,
|
|
270
|
-
EvmChainId: ts_types_1.EvmChainId.Mainnet,
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
const extension = body.extensionOptions.find((extension) => extension.typeUrl.includes('ExtensionOptionsWeb3Tx'));
|
|
274
274
|
if (!extension) {
|
|
275
275
|
return {
|
|
276
|
+
ethereumChainId: ts_types_1.EthereumChainId.Mainnet,
|
|
276
277
|
chainId: ts_types_1.ChainId.Mainnet,
|
|
277
|
-
EvmChainId: ts_types_1.EvmChainId.Mainnet,
|
|
278
278
|
};
|
|
279
279
|
}
|
|
280
280
|
const decodedExtension = core_proto_ts_1.InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode(extension.value);
|
|
281
|
-
const
|
|
281
|
+
const ethereumChainId = Number(decodedExtension.typedDataChainID);
|
|
282
282
|
return {
|
|
283
|
-
|
|
283
|
+
ethereumChainId: ethereumChainId,
|
|
284
284
|
chainId: [
|
|
285
|
-
ts_types_1.
|
|
286
|
-
ts_types_1.
|
|
287
|
-
ts_types_1.
|
|
288
|
-
].includes(
|
|
285
|
+
ts_types_1.EthereumChainId.Goerli,
|
|
286
|
+
ts_types_1.EthereumChainId.Kovan,
|
|
287
|
+
ts_types_1.EthereumChainId.Sepolia,
|
|
288
|
+
].includes(ethereumChainId)
|
|
289
289
|
? ts_types_1.ChainId.Testnet
|
|
290
290
|
: ts_types_1.ChainId.Mainnet,
|
|
291
291
|
};
|
|
292
292
|
};
|
|
293
|
-
const {
|
|
293
|
+
const { ethereumChainId, chainId } = getChainIds();
|
|
294
294
|
const [signerInfo] = authInfo.signerInfos;
|
|
295
295
|
const [signature] = signatures;
|
|
296
296
|
const [msg] = body.messages;
|
|
@@ -305,7 +305,7 @@ class PrivateKey {
|
|
|
305
305
|
timeoutHeight: body.timeoutHeight.toString(),
|
|
306
306
|
chainId,
|
|
307
307
|
},
|
|
308
|
-
|
|
308
|
+
ethereumChainId,
|
|
309
309
|
});
|
|
310
310
|
return this.verifySignature({
|
|
311
311
|
eip712: eip712TypedData,
|
|
@@ -62,9 +62,13 @@ class MsgExecuteContract extends MsgBase_js_1.MsgBase {
|
|
|
62
62
|
...value,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
toEip712() {
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
// public toEip712(): never {
|
|
66
|
+
// throw new GeneralException(
|
|
67
|
+
// new Error(
|
|
68
|
+
// 'EIP712_v1 is not supported for MsgExecuteContract. Please use EIP712_v2',
|
|
69
|
+
// ),
|
|
70
|
+
// )
|
|
71
|
+
// }
|
|
68
72
|
toDirectSign() {
|
|
69
73
|
const proto = this.toProto();
|
|
70
74
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrivateKey } from '../../accounts/index.js';
|
|
2
2
|
import { Msgs } from '../../modules/msgs.js';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { Network, NetworkEndpoints } from '@injectivelabs/networks';
|
|
5
5
|
import { AccountDetails } from '../../../types/auth.js';
|
|
6
6
|
interface MsgBroadcasterTxOptions {
|
|
@@ -25,7 +25,7 @@ interface MsgBroadcasterWithPkOptions {
|
|
|
25
25
|
rest: string;
|
|
26
26
|
};
|
|
27
27
|
privateKey: string | PrivateKey;
|
|
28
|
-
|
|
28
|
+
ethereumChainId?: EthereumChainId;
|
|
29
29
|
chainId?: ChainId;
|
|
30
30
|
simulateTx?: boolean;
|
|
31
31
|
loggingEnabled?: boolean;
|
|
@@ -45,7 +45,7 @@ interface MsgBroadcasterWithPkOptions {
|
|
|
45
45
|
export declare class MsgBroadcasterWithPk {
|
|
46
46
|
endpoints: NetworkEndpoints;
|
|
47
47
|
chainId: ChainId;
|
|
48
|
-
|
|
48
|
+
ethereumChainId?: EthereumChainId;
|
|
49
49
|
privateKey: PrivateKey;
|
|
50
50
|
simulateTx: boolean;
|
|
51
51
|
txTimeoutOnFeeDelegation: boolean;
|
|
@@ -23,7 +23,7 @@ const index_js_5 = require("../../../json/index.js");
|
|
|
23
23
|
class MsgBroadcasterWithPk {
|
|
24
24
|
endpoints;
|
|
25
25
|
chainId;
|
|
26
|
-
|
|
26
|
+
ethereumChainId;
|
|
27
27
|
privateKey;
|
|
28
28
|
simulateTx = false;
|
|
29
29
|
txTimeoutOnFeeDelegation = false;
|
|
@@ -39,7 +39,8 @@ class MsgBroadcasterWithPk {
|
|
|
39
39
|
this.simulateTx = options.simulateTx || false;
|
|
40
40
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
41
41
|
this.txTimeout = options.txTimeout || utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
42
|
-
this.
|
|
42
|
+
this.ethereumChainId =
|
|
43
|
+
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
43
44
|
this.endpoints = { ...endpoints, ...(options.endpoints || {}) };
|
|
44
45
|
this.privateKey =
|
|
45
46
|
options.privateKey instanceof index_js_1.PrivateKey
|
|
@@ -69,7 +70,7 @@ class MsgBroadcasterWithPk {
|
|
|
69
70
|
* @returns {string} transaction hash
|
|
70
71
|
*/
|
|
71
72
|
async broadcastWithFeeDelegation(transaction) {
|
|
72
|
-
const {
|
|
73
|
+
const { simulateTx, privateKey, ethereumChainId, endpoints, txTimeoutOnFeeDelegation, txTimeout, } = this;
|
|
73
74
|
const ethereumWallet = this.privateKey.toHex();
|
|
74
75
|
if (index_js_5.ofacWallets.includes(ethereumWallet)) {
|
|
75
76
|
throw new exceptions_1.GeneralException(new Error('You cannot execute this transaction'));
|
|
@@ -83,7 +84,7 @@ class MsgBroadcasterWithPk {
|
|
|
83
84
|
ethereumAddress: ethereumWallet,
|
|
84
85
|
};
|
|
85
86
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
86
|
-
if (!
|
|
87
|
+
if (!ethereumChainId) {
|
|
87
88
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
88
89
|
}
|
|
89
90
|
let timeoutHeight = undefined;
|
|
@@ -99,7 +100,7 @@ class MsgBroadcasterWithPk {
|
|
|
99
100
|
memo: tx.memo,
|
|
100
101
|
message: web3Msgs,
|
|
101
102
|
address: tx.ethereumAddress,
|
|
102
|
-
chainId:
|
|
103
|
+
chainId: ethereumChainId,
|
|
103
104
|
gasLimit: (0, msgs_js_1.getGasPriceBasedOnMessage)(msgs),
|
|
104
105
|
estimateGas: simulateTx || false,
|
|
105
106
|
timeoutHeight,
|
|
@@ -108,7 +109,7 @@ class MsgBroadcasterWithPk {
|
|
|
108
109
|
const response = await transactionApi.broadcastTxRequest({
|
|
109
110
|
txResponse,
|
|
110
111
|
message: web3Msgs,
|
|
111
|
-
chainId:
|
|
112
|
+
chainId: ethereumChainId,
|
|
112
113
|
signature: `0x${Buffer.from(signature).toString('hex')}`,
|
|
113
114
|
});
|
|
114
115
|
return await new TxGrpcApi_js_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Msgs } from '../../modules/msgs.js';
|
|
2
|
-
import {
|
|
2
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
3
|
import { Eip712ConvertFeeArgs, Eip712ConvertTxArgs } from './types.js';
|
|
4
|
-
export declare const getEip712TypedData: ({ msgs, tx, fee,
|
|
4
|
+
export declare const getEip712TypedData: ({ msgs, tx, fee, ethereumChainId, }: {
|
|
5
5
|
msgs: Msgs | Msgs[];
|
|
6
6
|
tx: Eip712ConvertTxArgs;
|
|
7
7
|
fee?: Eip712ConvertFeeArgs;
|
|
8
|
-
|
|
8
|
+
ethereumChainId: EthereumChainId;
|
|
9
9
|
}) => {
|
|
10
10
|
message: {
|
|
11
11
|
msgs: {
|
|
@@ -57,11 +57,11 @@ export declare const getEip712TypedData: ({ msgs, tx, fee, evmChainId, }: {
|
|
|
57
57
|
}[];
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
-
export declare const getEip712TypedDataV2: ({ msgs, tx, fee,
|
|
60
|
+
export declare const getEip712TypedDataV2: ({ msgs, tx, fee, ethereumChainId, }: {
|
|
61
61
|
msgs: Msgs | Msgs[];
|
|
62
62
|
tx: Eip712ConvertTxArgs;
|
|
63
63
|
fee?: Eip712ConvertFeeArgs;
|
|
64
|
-
|
|
64
|
+
ethereumChainId: EthereumChainId;
|
|
65
65
|
}) => {
|
|
66
66
|
message: {
|
|
67
67
|
context: string;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getEip712TypedDataV2 = exports.getEip712TypedData = void 0;
|
|
4
4
|
const utils_js_1 = require("./utils.js");
|
|
5
5
|
const utils_js_2 = require("./utils.js");
|
|
6
|
-
const getEip712TypedData = ({ msgs, tx, fee,
|
|
6
|
+
const getEip712TypedData = ({ msgs, tx, fee, ethereumChainId, }) => {
|
|
7
7
|
const messages = Array.isArray(msgs) ? msgs : [msgs];
|
|
8
8
|
const eip712Msgs = messages.map((m) => m.toEip712());
|
|
9
9
|
const eip712MessageTypes = messages[0].toEip712Types();
|
|
@@ -21,7 +21,7 @@ const getEip712TypedData = ({ msgs, tx, fee, evmChainId, }) => {
|
|
|
21
21
|
return {
|
|
22
22
|
...typesWithFeePayer,
|
|
23
23
|
primaryType: 'Tx',
|
|
24
|
-
...(0, utils_js_1.getEip712Domain)(
|
|
24
|
+
...(0, utils_js_1.getEip712Domain)(ethereumChainId),
|
|
25
25
|
message: {
|
|
26
26
|
...(0, utils_js_1.getEipTxDetails)(tx),
|
|
27
27
|
...(0, utils_js_1.getEip712Fee)(fee),
|
|
@@ -30,14 +30,14 @@ const getEip712TypedData = ({ msgs, tx, fee, evmChainId, }) => {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
exports.getEip712TypedData = getEip712TypedData;
|
|
33
|
-
const getEip712TypedDataV2 = ({ msgs, tx, fee,
|
|
33
|
+
const getEip712TypedDataV2 = ({ msgs, tx, fee, ethereumChainId, }) => {
|
|
34
34
|
const messages = Array.isArray(msgs) ? msgs : [msgs];
|
|
35
35
|
const eip712Msgs = messages.map((m) => m.toEip712V2());
|
|
36
36
|
const types = (0, utils_js_1.getDefaultEip712TypesV2)();
|
|
37
37
|
return {
|
|
38
38
|
...types,
|
|
39
39
|
primaryType: 'Tx',
|
|
40
|
-
...(0, utils_js_1.getEip712DomainV2)(
|
|
40
|
+
...(0, utils_js_1.getEip712DomainV2)(ethereumChainId),
|
|
41
41
|
message: {
|
|
42
42
|
context: JSON.stringify((0, utils_js_2.getEipTxContext)({ ...tx, fee })),
|
|
43
43
|
msgs: JSON.stringify(eip712Msgs),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { Eip712ConvertFeeArgs, Eip712ConvertTxArgs } from './types.js';
|
|
3
|
-
export declare const getEip712Domain: (
|
|
3
|
+
export declare const getEip712Domain: (ethereumChainId: EthereumChainId) => {
|
|
4
4
|
domain: {
|
|
5
5
|
name: string;
|
|
6
6
|
version: string;
|
|
@@ -9,7 +9,7 @@ export declare const getEip712Domain: (evmChainId: EvmChainId) => {
|
|
|
9
9
|
verifyingContract: string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export declare const getEip712DomainV2: (
|
|
12
|
+
export declare const getEip712DomainV2: (ethereumChainId: EthereumChainId) => {
|
|
13
13
|
domain: {
|
|
14
14
|
name: string;
|
|
15
15
|
version: string;
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEipTxContext = exports.getEipTxDetails = exports.getTypesIncludingFeePayer = exports.getEip712FeeV2 = exports.getEip712Fee = exports.getDefaultEip712TypesV2 = exports.getDefaultEip712Types = exports.getEip712DomainV2 = exports.getEip712Domain = void 0;
|
|
4
4
|
const utils_1 = require("@injectivelabs/utils");
|
|
5
|
-
const getEip712Domain = (
|
|
5
|
+
const getEip712Domain = (ethereumChainId) => {
|
|
6
6
|
return {
|
|
7
7
|
domain: {
|
|
8
8
|
name: 'Injective Web3',
|
|
9
9
|
version: '1.0.0',
|
|
10
|
-
chainId: '0x' + new utils_1.BigNumberInBase(
|
|
10
|
+
chainId: '0x' + new utils_1.BigNumberInBase(ethereumChainId).toString(16),
|
|
11
11
|
salt: '0',
|
|
12
12
|
verifyingContract: 'cosmos',
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
exports.getEip712Domain = getEip712Domain;
|
|
17
|
-
const getEip712DomainV2 = (
|
|
17
|
+
const getEip712DomainV2 = (ethereumChainId) => {
|
|
18
18
|
return {
|
|
19
19
|
domain: {
|
|
20
20
|
name: 'Injective Web3',
|
|
21
21
|
version: '1.0.0',
|
|
22
|
-
chainId: '0x' + new utils_1.BigNumberInBase(
|
|
22
|
+
chainId: '0x' + new utils_1.BigNumberInBase(ethereumChainId).toString(16),
|
|
23
23
|
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
|
24
24
|
salt: '0',
|
|
25
25
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId,
|
|
1
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { Msgs } from '../../modules/msgs.js';
|
|
3
3
|
import { GoogleProtobufAny, CosmosTxV1Beta1Tx, InjectiveTypesV1Beta1TxExt, CosmosTxSigningV1Beta1Signing } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
export declare const getPublicKey: ({ chainId, key, }: {
|
|
@@ -49,8 +49,8 @@ export declare const createSignDocFromTransaction: (args: {
|
|
|
49
49
|
accountNumber: number;
|
|
50
50
|
}) => CosmosTxV1Beta1Tx.SignDoc;
|
|
51
51
|
export declare const createTxRawEIP712: (txRaw: CosmosTxV1Beta1Tx.TxRaw, extension: InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx, nonCriticalExtension?: GoogleProtobufAny.Any | GoogleProtobufAny.Any[]) => CosmosTxV1Beta1Tx.TxRaw;
|
|
52
|
-
export declare const createWeb3Extension: ({
|
|
53
|
-
|
|
52
|
+
export declare const createWeb3Extension: ({ ethereumChainId, feePayer, feePayerSig, }: {
|
|
53
|
+
ethereumChainId: EthereumChainId;
|
|
54
54
|
feePayer?: string;
|
|
55
55
|
feePayerSig?: Uint8Array;
|
|
56
56
|
}) => InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx;
|
|
@@ -120,9 +120,9 @@ const createTxRawEIP712 = (txRaw, extension, nonCriticalExtension) => {
|
|
|
120
120
|
return txRaw;
|
|
121
121
|
};
|
|
122
122
|
exports.createTxRawEIP712 = createTxRawEIP712;
|
|
123
|
-
const createWeb3Extension = ({
|
|
123
|
+
const createWeb3Extension = ({ ethereumChainId, feePayer, feePayerSig, }) => {
|
|
124
124
|
const web3Extension = core_proto_ts_1.InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.create();
|
|
125
|
-
web3Extension.typedDataChainID =
|
|
125
|
+
web3Extension.typedDataChainID = ethereumChainId.toString();
|
|
126
126
|
if (feePayer) {
|
|
127
127
|
web3Extension.feePayer = feePayer;
|
|
128
128
|
}
|
package/dist/cjs/utils/grpc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as grpcPkg from '@injectivelabs/grpc-web';
|
|
2
2
|
declare const grpc: typeof grpcPkg.grpc;
|
|
3
|
-
export declare const getGrpcTransport: () =>
|
|
3
|
+
export declare const getGrpcTransport: () => import("@injectivelabs/grpc-web").grpc.TransportFactory;
|
|
4
4
|
export { grpc, grpcPkg };
|
|
@@ -19,4 +19,4 @@ export declare const fetchAllWithPagination: <T extends {
|
|
|
19
19
|
pagination: PaginationOption | undefined;
|
|
20
20
|
} | PaginationOption | undefined, Q extends {
|
|
21
21
|
pagination: Pagination;
|
|
22
|
-
}>(args: T, method: (args: T) => Promise<Q
|
|
22
|
+
}>(args: T, method: (args: T) => Promise<Q>) => Promise<Q>;
|
|
@@ -97,17 +97,24 @@ const grpcPagingToPaging = (pagination) => {
|
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
99
|
exports.grpcPagingToPaging = grpcPagingToPaging;
|
|
100
|
-
const fetchAllWithPagination = async (args, method
|
|
100
|
+
const fetchAllWithPagination = async (args, method) => {
|
|
101
|
+
let result = [];
|
|
101
102
|
let response = await method(args);
|
|
102
103
|
if (!args) {
|
|
103
104
|
return response;
|
|
104
105
|
}
|
|
106
|
+
const paginationOption = args.pagination;
|
|
107
|
+
if (!paginationOption) {
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
105
110
|
const keys = Object.keys(response);
|
|
106
111
|
const valueKey = keys.find((key) => key !== 'pagination');
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
while (response.pagination.next) {
|
|
113
|
+
result.push(response[valueKey]);
|
|
114
|
+
response = await method({
|
|
115
|
+
...args,
|
|
116
|
+
pagination: { ...paginationOption, key: response.pagination.next },
|
|
117
|
+
});
|
|
111
118
|
}
|
|
112
119
|
return { [valueKey]: result, pagination: response.pagination };
|
|
113
120
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AccountAddress,
|
|
1
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js';
|
|
5
5
|
interface PrepareTxArgs {
|
|
6
6
|
address: AccountAddress;
|
|
7
|
-
chainId:
|
|
7
|
+
chainId: EthereumChainId;
|
|
8
8
|
message: any;
|
|
9
9
|
estimateGas?: boolean;
|
|
10
10
|
gasLimit?: number;
|
|
@@ -41,7 +41,7 @@ export declare class IndexerGrpcTransactionApi extends BaseGrpcConsumer {
|
|
|
41
41
|
*/
|
|
42
42
|
broadcastTxRequest({ signature, chainId, message, txResponse, }: {
|
|
43
43
|
signature: string;
|
|
44
|
-
chainId:
|
|
44
|
+
chainId: EthereumChainId;
|
|
45
45
|
useCorrectEIP712Hash?: boolean;
|
|
46
46
|
txResponse: InjectiveExchangeRpc.PrepareTxResponse;
|
|
47
47
|
message: Record<string, any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountAddress,
|
|
1
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
import { IndexerGrpcTransactionApi } from './IndexerGrpcTransactionApi.js';
|
|
4
4
|
/**
|
|
@@ -9,7 +9,7 @@ export declare class IndexerGrpcWeb3GwApi extends IndexerGrpcTransactionApi {
|
|
|
9
9
|
constructor(endpoint: string);
|
|
10
10
|
prepareEip712Request({ address, chainId, message, memo, sequence, accountNumber, estimateGas, gasLimit, feeDenom, feePrice, timeoutHeight, eip712Version, }: {
|
|
11
11
|
address: AccountAddress;
|
|
12
|
-
chainId:
|
|
12
|
+
chainId: EthereumChainId;
|
|
13
13
|
message: any;
|
|
14
14
|
estimateGas?: boolean;
|
|
15
15
|
gasLimit?: number;
|
|
@@ -200,6 +200,7 @@ export class IndexerGrpcDerivativeTransformer {
|
|
|
200
200
|
oracleQuote: market.oracleQuote,
|
|
201
201
|
oracleType: market.oracleType,
|
|
202
202
|
oracleScaleFactor: market.oracleScaleFactor,
|
|
203
|
+
reduceMarginRatio: market.reduceMarginRatio,
|
|
203
204
|
initialMarginRatio: market.initialMarginRatio,
|
|
204
205
|
maintenanceMarginRatio: market.maintenanceMarginRatio,
|
|
205
206
|
isPerpetual: market.isPerpetual,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
2
|
-
import { Address } from './Address.js';
|
|
3
1
|
import { PublicKey } from './PublicKey.js';
|
|
2
|
+
import { Address } from './Address.js';
|
|
3
|
+
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
/**
|
|
5
5
|
* Class for wrapping SigningKey that is used for signature creation and public key derivation.
|
|
6
6
|
*
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import secp256k1 from 'secp256k1';
|
|
2
|
-
import keccak256 from 'keccak256';
|
|
3
1
|
import { generateMnemonic } from 'bip39';
|
|
4
|
-
import { InjectiveTypesV1Beta1TxExt, } from '@injectivelabs/core-proto-ts';
|
|
5
|
-
import { GeneralException } from '@injectivelabs/exceptions';
|
|
6
|
-
import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
7
2
|
import { Wallet, HDNodeWallet, Signature, getBytes, concat } from 'ethers';
|
|
3
|
+
import secp256k1 from 'secp256k1';
|
|
4
|
+
import keccak256 from 'keccak256';
|
|
5
|
+
import { PublicKey } from './PublicKey.js';
|
|
6
|
+
import { Address } from './Address.js';
|
|
8
7
|
import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
|
|
9
8
|
import { DEFAULT_DERIVATION_PATH, recoverTypedSignaturePubKey, } from '../../utils/index.js';
|
|
10
|
-
import {
|
|
11
|
-
import { PublicKey } from './PublicKey.js';
|
|
9
|
+
import { InjectiveTypesV1Beta1TxExt, } from '@injectivelabs/core-proto-ts';
|
|
12
10
|
import { getTransactionPartsFromTxRaw } from '../tx/utils/tx.js';
|
|
13
11
|
import { getEip712TypedData, MsgDecoder } from '../tx/eip712/index.js';
|
|
12
|
+
import { GeneralException } from '@injectivelabs/exceptions';
|
|
13
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
14
14
|
/**
|
|
15
15
|
* Class for wrapping SigningKey that is used for signature creation and public key derivation.
|
|
16
16
|
*
|
|
@@ -260,31 +260,31 @@ export class PrivateKey {
|
|
|
260
260
|
const getChainIds = () => {
|
|
261
261
|
if (!body.extensionOptions.length) {
|
|
262
262
|
return {
|
|
263
|
+
ethereumChainId: EthereumChainId.Mainnet,
|
|
263
264
|
chainId: ChainId.Mainnet,
|
|
264
|
-
EvmChainId: EvmChainId.Mainnet,
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
const extension = body.extensionOptions.find((extension) => extension.typeUrl.includes('ExtensionOptionsWeb3Tx'));
|
|
268
268
|
if (!extension) {
|
|
269
269
|
return {
|
|
270
|
+
ethereumChainId: EthereumChainId.Mainnet,
|
|
270
271
|
chainId: ChainId.Mainnet,
|
|
271
|
-
EvmChainId: EvmChainId.Mainnet,
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
const decodedExtension = InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode(extension.value);
|
|
275
|
-
const
|
|
275
|
+
const ethereumChainId = Number(decodedExtension.typedDataChainID);
|
|
276
276
|
return {
|
|
277
|
-
|
|
277
|
+
ethereumChainId: ethereumChainId,
|
|
278
278
|
chainId: [
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
].includes(
|
|
279
|
+
EthereumChainId.Goerli,
|
|
280
|
+
EthereumChainId.Kovan,
|
|
281
|
+
EthereumChainId.Sepolia,
|
|
282
|
+
].includes(ethereumChainId)
|
|
283
283
|
? ChainId.Testnet
|
|
284
284
|
: ChainId.Mainnet,
|
|
285
285
|
};
|
|
286
286
|
};
|
|
287
|
-
const {
|
|
287
|
+
const { ethereumChainId, chainId } = getChainIds();
|
|
288
288
|
const [signerInfo] = authInfo.signerInfos;
|
|
289
289
|
const [signature] = signatures;
|
|
290
290
|
const [msg] = body.messages;
|
|
@@ -299,7 +299,7 @@ export class PrivateKey {
|
|
|
299
299
|
timeoutHeight: body.timeoutHeight.toString(),
|
|
300
300
|
chainId,
|
|
301
301
|
},
|
|
302
|
-
|
|
302
|
+
ethereumChainId,
|
|
303
303
|
});
|
|
304
304
|
return this.verifySignature({
|
|
305
305
|
eip712: eip712TypedData,
|
|
@@ -57,9 +57,13 @@ export default class MsgExecuteContract extends MsgBase {
|
|
|
57
57
|
...value,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
toEip712() {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
// public toEip712(): never {
|
|
61
|
+
// throw new GeneralException(
|
|
62
|
+
// new Error(
|
|
63
|
+
// 'EIP712_v1 is not supported for MsgExecuteContract. Please use EIP712_v2',
|
|
64
|
+
// ),
|
|
65
|
+
// )
|
|
66
|
+
// }
|
|
63
67
|
toDirectSign() {
|
|
64
68
|
const proto = this.toProto();
|
|
65
69
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrivateKey } from '../../accounts/index.js';
|
|
2
2
|
import { Msgs } from '../../modules/msgs.js';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { Network, NetworkEndpoints } from '@injectivelabs/networks';
|
|
5
5
|
import { AccountDetails } from '../../../types/auth.js';
|
|
6
6
|
interface MsgBroadcasterTxOptions {
|
|
@@ -25,7 +25,7 @@ interface MsgBroadcasterWithPkOptions {
|
|
|
25
25
|
rest: string;
|
|
26
26
|
};
|
|
27
27
|
privateKey: string | PrivateKey;
|
|
28
|
-
|
|
28
|
+
ethereumChainId?: EthereumChainId;
|
|
29
29
|
chainId?: ChainId;
|
|
30
30
|
simulateTx?: boolean;
|
|
31
31
|
loggingEnabled?: boolean;
|
|
@@ -45,7 +45,7 @@ interface MsgBroadcasterWithPkOptions {
|
|
|
45
45
|
export declare class MsgBroadcasterWithPk {
|
|
46
46
|
endpoints: NetworkEndpoints;
|
|
47
47
|
chainId: ChainId;
|
|
48
|
-
|
|
48
|
+
ethereumChainId?: EthereumChainId;
|
|
49
49
|
privateKey: PrivateKey;
|
|
50
50
|
simulateTx: boolean;
|
|
51
51
|
txTimeoutOnFeeDelegation: boolean;
|
|
@@ -20,7 +20,7 @@ import { ofacWallets } from '../../../json/index.js';
|
|
|
20
20
|
export class MsgBroadcasterWithPk {
|
|
21
21
|
endpoints;
|
|
22
22
|
chainId;
|
|
23
|
-
|
|
23
|
+
ethereumChainId;
|
|
24
24
|
privateKey;
|
|
25
25
|
simulateTx = false;
|
|
26
26
|
txTimeoutOnFeeDelegation = false;
|
|
@@ -36,7 +36,8 @@ export class MsgBroadcasterWithPk {
|
|
|
36
36
|
this.simulateTx = options.simulateTx || false;
|
|
37
37
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
38
38
|
this.txTimeout = options.txTimeout || DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
39
|
-
this.
|
|
39
|
+
this.ethereumChainId =
|
|
40
|
+
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
40
41
|
this.endpoints = { ...endpoints, ...(options.endpoints || {}) };
|
|
41
42
|
this.privateKey =
|
|
42
43
|
options.privateKey instanceof PrivateKey
|
|
@@ -66,7 +67,7 @@ export class MsgBroadcasterWithPk {
|
|
|
66
67
|
* @returns {string} transaction hash
|
|
67
68
|
*/
|
|
68
69
|
async broadcastWithFeeDelegation(transaction) {
|
|
69
|
-
const {
|
|
70
|
+
const { simulateTx, privateKey, ethereumChainId, endpoints, txTimeoutOnFeeDelegation, txTimeout, } = this;
|
|
70
71
|
const ethereumWallet = this.privateKey.toHex();
|
|
71
72
|
if (ofacWallets.includes(ethereumWallet)) {
|
|
72
73
|
throw new GeneralException(new Error('You cannot execute this transaction'));
|
|
@@ -80,7 +81,7 @@ export class MsgBroadcasterWithPk {
|
|
|
80
81
|
ethereumAddress: ethereumWallet,
|
|
81
82
|
};
|
|
82
83
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
83
|
-
if (!
|
|
84
|
+
if (!ethereumChainId) {
|
|
84
85
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
85
86
|
}
|
|
86
87
|
let timeoutHeight = undefined;
|
|
@@ -96,7 +97,7 @@ export class MsgBroadcasterWithPk {
|
|
|
96
97
|
memo: tx.memo,
|
|
97
98
|
message: web3Msgs,
|
|
98
99
|
address: tx.ethereumAddress,
|
|
99
|
-
chainId:
|
|
100
|
+
chainId: ethereumChainId,
|
|
100
101
|
gasLimit: getGasPriceBasedOnMessage(msgs),
|
|
101
102
|
estimateGas: simulateTx || false,
|
|
102
103
|
timeoutHeight,
|
|
@@ -105,7 +106,7 @@ export class MsgBroadcasterWithPk {
|
|
|
105
106
|
const response = await transactionApi.broadcastTxRequest({
|
|
106
107
|
txResponse,
|
|
107
108
|
message: web3Msgs,
|
|
108
|
-
chainId:
|
|
109
|
+
chainId: ethereumChainId,
|
|
109
110
|
signature: `0x${Buffer.from(signature).toString('hex')}`,
|
|
110
111
|
});
|
|
111
112
|
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Msgs } from '../../modules/msgs.js';
|
|
2
|
-
import {
|
|
2
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
3
|
import { Eip712ConvertFeeArgs, Eip712ConvertTxArgs } from './types.js';
|
|
4
|
-
export declare const getEip712TypedData: ({ msgs, tx, fee,
|
|
4
|
+
export declare const getEip712TypedData: ({ msgs, tx, fee, ethereumChainId, }: {
|
|
5
5
|
msgs: Msgs | Msgs[];
|
|
6
6
|
tx: Eip712ConvertTxArgs;
|
|
7
7
|
fee?: Eip712ConvertFeeArgs;
|
|
8
|
-
|
|
8
|
+
ethereumChainId: EthereumChainId;
|
|
9
9
|
}) => {
|
|
10
10
|
message: {
|
|
11
11
|
msgs: {
|
|
@@ -57,11 +57,11 @@ export declare const getEip712TypedData: ({ msgs, tx, fee, evmChainId, }: {
|
|
|
57
57
|
}[];
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
-
export declare const getEip712TypedDataV2: ({ msgs, tx, fee,
|
|
60
|
+
export declare const getEip712TypedDataV2: ({ msgs, tx, fee, ethereumChainId, }: {
|
|
61
61
|
msgs: Msgs | Msgs[];
|
|
62
62
|
tx: Eip712ConvertTxArgs;
|
|
63
63
|
fee?: Eip712ConvertFeeArgs;
|
|
64
|
-
|
|
64
|
+
ethereumChainId: EthereumChainId;
|
|
65
65
|
}) => {
|
|
66
66
|
message: {
|
|
67
67
|
context: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getEip712Fee, getEipTxDetails, getEip712Domain, getEip712DomainV2, getDefaultEip712Types,
|
|
1
|
+
import { getEip712Fee, getEipTxDetails, getEip712Domain, getEip712DomainV2, getDefaultEip712Types, getTypesIncludingFeePayer, getDefaultEip712TypesV2, } from './utils.js';
|
|
2
2
|
import { getEipTxContext } from './utils.js';
|
|
3
|
-
export const getEip712TypedData = ({ msgs, tx, fee,
|
|
3
|
+
export const getEip712TypedData = ({ msgs, tx, fee, ethereumChainId, }) => {
|
|
4
4
|
const messages = Array.isArray(msgs) ? msgs : [msgs];
|
|
5
5
|
const eip712Msgs = messages.map((m) => m.toEip712());
|
|
6
6
|
const eip712MessageTypes = messages[0].toEip712Types();
|
|
@@ -18,7 +18,7 @@ export const getEip712TypedData = ({ msgs, tx, fee, evmChainId, }) => {
|
|
|
18
18
|
return {
|
|
19
19
|
...typesWithFeePayer,
|
|
20
20
|
primaryType: 'Tx',
|
|
21
|
-
...getEip712Domain(
|
|
21
|
+
...getEip712Domain(ethereumChainId),
|
|
22
22
|
message: {
|
|
23
23
|
...getEipTxDetails(tx),
|
|
24
24
|
...getEip712Fee(fee),
|
|
@@ -26,14 +26,14 @@ export const getEip712TypedData = ({ msgs, tx, fee, evmChainId, }) => {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
export const getEip712TypedDataV2 = ({ msgs, tx, fee,
|
|
29
|
+
export const getEip712TypedDataV2 = ({ msgs, tx, fee, ethereumChainId, }) => {
|
|
30
30
|
const messages = Array.isArray(msgs) ? msgs : [msgs];
|
|
31
31
|
const eip712Msgs = messages.map((m) => m.toEip712V2());
|
|
32
32
|
const types = getDefaultEip712TypesV2();
|
|
33
33
|
return {
|
|
34
34
|
...types,
|
|
35
35
|
primaryType: 'Tx',
|
|
36
|
-
...getEip712DomainV2(
|
|
36
|
+
...getEip712DomainV2(ethereumChainId),
|
|
37
37
|
message: {
|
|
38
38
|
context: JSON.stringify(getEipTxContext({ ...tx, fee })),
|
|
39
39
|
msgs: JSON.stringify(eip712Msgs),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { Eip712ConvertFeeArgs, Eip712ConvertTxArgs } from './types.js';
|
|
3
|
-
export declare const getEip712Domain: (
|
|
3
|
+
export declare const getEip712Domain: (ethereumChainId: EthereumChainId) => {
|
|
4
4
|
domain: {
|
|
5
5
|
name: string;
|
|
6
6
|
version: string;
|
|
@@ -9,7 +9,7 @@ export declare const getEip712Domain: (evmChainId: EvmChainId) => {
|
|
|
9
9
|
verifyingContract: string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export declare const getEip712DomainV2: (
|
|
12
|
+
export declare const getEip712DomainV2: (ethereumChainId: EthereumChainId) => {
|
|
13
13
|
domain: {
|
|
14
14
|
name: string;
|
|
15
15
|
version: string;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { BigNumberInBase, DEFAULT_GAS_LIMIT, DEFAULT_STD_FEE, } from '@injectivelabs/utils';
|
|
2
|
-
export const getEip712Domain = (
|
|
2
|
+
export const getEip712Domain = (ethereumChainId) => {
|
|
3
3
|
return {
|
|
4
4
|
domain: {
|
|
5
5
|
name: 'Injective Web3',
|
|
6
6
|
version: '1.0.0',
|
|
7
|
-
chainId: '0x' + new BigNumberInBase(
|
|
7
|
+
chainId: '0x' + new BigNumberInBase(ethereumChainId).toString(16),
|
|
8
8
|
salt: '0',
|
|
9
9
|
verifyingContract: 'cosmos',
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export const getEip712DomainV2 = (
|
|
13
|
+
export const getEip712DomainV2 = (ethereumChainId) => {
|
|
14
14
|
return {
|
|
15
15
|
domain: {
|
|
16
16
|
name: 'Injective Web3',
|
|
17
17
|
version: '1.0.0',
|
|
18
|
-
chainId: '0x' + new BigNumberInBase(
|
|
18
|
+
chainId: '0x' + new BigNumberInBase(ethereumChainId).toString(16),
|
|
19
19
|
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
|
20
20
|
salt: '0',
|
|
21
21
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId,
|
|
1
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { Msgs } from '../../modules/msgs.js';
|
|
3
3
|
import { GoogleProtobufAny, CosmosTxV1Beta1Tx, InjectiveTypesV1Beta1TxExt, CosmosTxSigningV1Beta1Signing } from '@injectivelabs/core-proto-ts';
|
|
4
4
|
export declare const getPublicKey: ({ chainId, key, }: {
|
|
@@ -49,8 +49,8 @@ export declare const createSignDocFromTransaction: (args: {
|
|
|
49
49
|
accountNumber: number;
|
|
50
50
|
}) => CosmosTxV1Beta1Tx.SignDoc;
|
|
51
51
|
export declare const createTxRawEIP712: (txRaw: CosmosTxV1Beta1Tx.TxRaw, extension: InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx, nonCriticalExtension?: GoogleProtobufAny.Any | GoogleProtobufAny.Any[]) => CosmosTxV1Beta1Tx.TxRaw;
|
|
52
|
-
export declare const createWeb3Extension: ({
|
|
53
|
-
|
|
52
|
+
export declare const createWeb3Extension: ({ ethereumChainId, feePayer, feePayerSig, }: {
|
|
53
|
+
ethereumChainId: EthereumChainId;
|
|
54
54
|
feePayer?: string;
|
|
55
55
|
feePayerSig?: Uint8Array;
|
|
56
56
|
}) => InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx;
|
|
@@ -108,9 +108,9 @@ export const createTxRawEIP712 = (txRaw, extension, nonCriticalExtension) => {
|
|
|
108
108
|
txRaw.bodyBytes = CosmosTxV1Beta1Tx.TxBody.encode(body).finish();
|
|
109
109
|
return txRaw;
|
|
110
110
|
};
|
|
111
|
-
export const createWeb3Extension = ({
|
|
111
|
+
export const createWeb3Extension = ({ ethereumChainId, feePayer, feePayerSig, }) => {
|
|
112
112
|
const web3Extension = InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.create();
|
|
113
|
-
web3Extension.typedDataChainID =
|
|
113
|
+
web3Extension.typedDataChainID = ethereumChainId.toString();
|
|
114
114
|
if (feePayer) {
|
|
115
115
|
web3Extension.feePayer = feePayer;
|
|
116
116
|
}
|
package/dist/esm/utils/grpc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as grpcPkg from '@injectivelabs/grpc-web';
|
|
2
2
|
declare const grpc: typeof grpcPkg.grpc;
|
|
3
|
-
export declare const getGrpcTransport: () =>
|
|
3
|
+
export declare const getGrpcTransport: () => import("@injectivelabs/grpc-web").grpc.TransportFactory;
|
|
4
4
|
export { grpc, grpcPkg };
|
|
@@ -19,4 +19,4 @@ export declare const fetchAllWithPagination: <T extends {
|
|
|
19
19
|
pagination: PaginationOption | undefined;
|
|
20
20
|
} | PaginationOption | undefined, Q extends {
|
|
21
21
|
pagination: Pagination;
|
|
22
|
-
}>(args: T, method: (args: T) => Promise<Q
|
|
22
|
+
}>(args: T, method: (args: T) => Promise<Q>) => Promise<Q>;
|
|
@@ -88,17 +88,24 @@ export const grpcPagingToPaging = (pagination) => {
|
|
|
88
88
|
total: parseInt(pagination.total || '0', 10),
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
-
export const fetchAllWithPagination = async (args, method
|
|
91
|
+
export const fetchAllWithPagination = async (args, method) => {
|
|
92
|
+
let result = [];
|
|
92
93
|
let response = await method(args);
|
|
93
94
|
if (!args) {
|
|
94
95
|
return response;
|
|
95
96
|
}
|
|
97
|
+
const paginationOption = args.pagination;
|
|
98
|
+
if (!paginationOption) {
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
96
101
|
const keys = Object.keys(response);
|
|
97
102
|
const valueKey = keys.find((key) => key !== 'pagination');
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
while (response.pagination.next) {
|
|
104
|
+
result.push(response[valueKey]);
|
|
105
|
+
response = await method({
|
|
106
|
+
...args,
|
|
107
|
+
pagination: { ...paginationOption, key: response.pagination.next },
|
|
108
|
+
});
|
|
102
109
|
}
|
|
103
110
|
return { [valueKey]: result, pagination: response.pagination };
|
|
104
111
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/sdk-ts",
|
|
3
3
|
"description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
|
|
4
|
-
"version": "1.16.6
|
|
4
|
+
"version": "1.16.6",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": {
|
|
@@ -102,10 +102,10 @@
|
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
104
|
"fetch:ofac": "node --experimental-fetch ./../../etc/ofac.js",
|
|
105
|
-
"build": "
|
|
105
|
+
"build": "yarn build:cjs && yarn build:esm && yarn build:post",
|
|
106
106
|
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
107
107
|
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
108
|
-
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json &&
|
|
108
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post",
|
|
109
109
|
"build:post": "shx cp ../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../etc/stub/package.esm.json.stub dist/esm/package.json",
|
|
110
110
|
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
|
|
111
111
|
"test": "jest",
|
|
@@ -123,16 +123,16 @@
|
|
|
123
123
|
"@cosmjs/stargate": "^0.33.0",
|
|
124
124
|
"@injectivelabs/abacus-proto-ts": "1.14.0",
|
|
125
125
|
"@injectivelabs/core-proto-ts": "1.16.1",
|
|
126
|
-
"@injectivelabs/exceptions": "1.16.6
|
|
126
|
+
"@injectivelabs/exceptions": "^1.16.6",
|
|
127
127
|
"@injectivelabs/grpc-web": "^0.0.1",
|
|
128
128
|
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
|
|
129
129
|
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
|
|
130
130
|
"@injectivelabs/indexer-proto-ts": "1.13.14",
|
|
131
131
|
"@injectivelabs/mito-proto-ts": "1.13.2",
|
|
132
|
-
"@injectivelabs/networks": "1.16.6
|
|
132
|
+
"@injectivelabs/networks": "^1.16.6",
|
|
133
133
|
"@injectivelabs/olp-proto-ts": "1.13.4",
|
|
134
|
-
"@injectivelabs/ts-types": "1.16.6
|
|
135
|
-
"@injectivelabs/utils": "1.16.6
|
|
134
|
+
"@injectivelabs/ts-types": "^1.16.6",
|
|
135
|
+
"@injectivelabs/utils": "^1.16.6",
|
|
136
136
|
"@metamask/eth-sig-util": "^8.2.0",
|
|
137
137
|
"@noble/curves": "^1.8.1",
|
|
138
138
|
"@noble/hashes": "^1.7.1",
|
|
@@ -147,17 +147,21 @@
|
|
|
147
147
|
"graphql": "^16.10.0",
|
|
148
148
|
"http-status-codes": "^2.2.0",
|
|
149
149
|
"keccak256": "^1.0.6",
|
|
150
|
-
"rxjs": "7.8.2",
|
|
151
150
|
"secp256k1": "^4.0.3",
|
|
152
151
|
"shx": "^0.3.4",
|
|
153
152
|
"snakecase-keys": "^5.4.1"
|
|
154
153
|
},
|
|
155
|
-
"gitHead": "
|
|
154
|
+
"gitHead": "41794b09a1047a01dbb1d0e0a473a2f26305752d",
|
|
156
155
|
"typedoc": {
|
|
157
156
|
"entryPoint": "./src/index.ts",
|
|
158
157
|
"readmeFile": "./README.md",
|
|
159
158
|
"displayName": "sdk-ts API documentation"
|
|
160
159
|
},
|
|
160
|
+
"resolutions": {
|
|
161
|
+
"@ethereumjs/tx": "^4.1.1",
|
|
162
|
+
"**/libsodium": "npm:@bangjelkoski/noop",
|
|
163
|
+
"**/libsodium-wrappers": "npm:@bangjelkoski/noop"
|
|
164
|
+
},
|
|
161
165
|
"devDependencies": {
|
|
162
166
|
"@types/crypto-js": "^4.2.2",
|
|
163
167
|
"@types/lodash.toarray": "^4.4.7"
|