coreum-js 2.18.11 → 2.20.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/dist/main/client/index.d.ts +34 -1
- package/dist/main/client/index.js +162 -0
- package/dist/main/coreum/dex/v1/cosmos/cosmos-sdk/proto/cosmos/msg/v1/msg.d.ts +1 -0
- package/dist/main/coreum/dex/v1/cosmos/cosmos-sdk/proto/cosmos/msg/v1/msg.js +10 -0
- package/dist/main/coreum/dex/v1/event.js +8 -28
- package/dist/main/coreum/dex/v1/genesis.d.ts +2 -1
- package/dist/main/coreum/dex/v1/genesis.js +57 -14
- package/dist/main/coreum/dex/v1/order.d.ts +3 -23
- package/dist/main/coreum/dex/v1/order.js +27 -205
- package/dist/main/coreum/dex/v1/params.d.ts +5 -3
- package/dist/main/coreum/dex/v1/params.js +25 -7
- package/dist/main/coreum/dex/v1/query.d.ts +2 -2
- package/dist/main/coreum/dex/v1/query.js +48 -48
- package/dist/main/coreum/dex/v1/tx.d.ts +1 -1
- package/dist/main/coreum/dex/v1/tx.js +31 -45
- package/dist/module/client/index.d.ts +34 -1
- package/dist/module/client/index.js +162 -0
- package/dist/module/coreum/dex/v1/cosmos/cosmos-sdk/proto/cosmos/msg/v1/msg.d.ts +1 -0
- package/dist/module/coreum/dex/v1/cosmos/cosmos-sdk/proto/cosmos/msg/v1/msg.js +7 -0
- package/dist/module/coreum/dex/v1/event.js +8 -28
- package/dist/module/coreum/dex/v1/genesis.d.ts +2 -1
- package/dist/module/coreum/dex/v1/genesis.js +51 -8
- package/dist/module/coreum/dex/v1/order.d.ts +3 -23
- package/dist/module/coreum/dex/v1/order.js +14 -192
- package/dist/module/coreum/dex/v1/params.d.ts +5 -3
- package/dist/module/coreum/dex/v1/params.js +23 -5
- package/dist/module/coreum/dex/v1/query.d.ts +2 -2
- package/dist/module/coreum/dex/v1/query.js +13 -13
- package/dist/module/coreum/dex/v1/tx.d.ts +1 -1
- package/dist/module/coreum/dex/v1/tx.js +17 -31
- package/package.json +3 -2
- package/tests/README.md +59 -0
- package/tests/client/calculateGas.test.ts +372 -0
|
@@ -2,7 +2,7 @@ import { CoreumNetworkConfig } from "../types/coreum";
|
|
|
2
2
|
import { EncodeObject, OfflineSigner, Registry } from "@cosmjs/proto-signing";
|
|
3
3
|
import { TxRaw } from "../cosmos";
|
|
4
4
|
import { ExtensionWallets, FeeCalculation, ClientQueryClient } from "../types";
|
|
5
|
-
import { DeliverTxResponse, StargateClient } from "@cosmjs/stargate";
|
|
5
|
+
import { DeliverTxResponse, GasPrice, StargateClient } from "@cosmjs/stargate";
|
|
6
6
|
import EventEmitter from "eventemitter3";
|
|
7
7
|
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
|
8
8
|
interface WithExtensionOptions {
|
|
@@ -86,6 +86,27 @@ export declare class Client {
|
|
|
86
86
|
* - gas_wanted: number
|
|
87
87
|
*/
|
|
88
88
|
getTxFee(msgs: readonly EncodeObject[]): Promise<FeeCalculation>;
|
|
89
|
+
/**
|
|
90
|
+
* Calculates gas by simulating the transaction with a dummy signer.
|
|
91
|
+
* Similar to Go's CalculateGas function - works without a signing client.
|
|
92
|
+
*
|
|
93
|
+
* @param msgs Messages to simulate
|
|
94
|
+
* @param options Optional configuration
|
|
95
|
+
* @param options.fromAddress Address to simulate from (optional, uses dummy if not provided)
|
|
96
|
+
* @param options.gasAdjustment Multiplier for gas (default: 1.2)
|
|
97
|
+
* @returns The estimated gas amount
|
|
98
|
+
*/
|
|
99
|
+
calculateGas(msgs: readonly EncodeObject[], options?: {
|
|
100
|
+
fromAddress?: string;
|
|
101
|
+
gasAdjustment?: number;
|
|
102
|
+
}): Promise<number>;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the current gas price without transaction simulation.
|
|
105
|
+
* Equivalent to Go's GetGasPrice function.
|
|
106
|
+
*
|
|
107
|
+
* @returns GasPrice object
|
|
108
|
+
*/
|
|
109
|
+
getGasPrice(): Promise<GasPrice>;
|
|
89
110
|
/**
|
|
90
111
|
*
|
|
91
112
|
* @param transaction Transaction to be submitted
|
|
@@ -128,6 +149,18 @@ export declare class Client {
|
|
|
128
149
|
*/
|
|
129
150
|
createMultisigAccount(addresses: string[], threshold?: number): Promise<import("../types").MultisigAccount>;
|
|
130
151
|
private _getGasPrice;
|
|
152
|
+
/**
|
|
153
|
+
* Builds a transaction for simulation with a dummy signer.
|
|
154
|
+
* Similar to Go's BuildTxForSimulation function.
|
|
155
|
+
*
|
|
156
|
+
* @private
|
|
157
|
+
* @param msgs Messages to simulate
|
|
158
|
+
* @param fromAddress Address to simulate from
|
|
159
|
+
* @param accountNumber Account number
|
|
160
|
+
* @param sequence Sequence number
|
|
161
|
+
* @returns Encoded transaction bytes ready for simulation
|
|
162
|
+
*/
|
|
163
|
+
private _buildTxForSimulation;
|
|
131
164
|
private _isSigningClientInit;
|
|
132
165
|
private _initTendermintClient;
|
|
133
166
|
private _initQueryClient;
|
|
@@ -15,9 +15,16 @@ const coreum_2 = require("../types/coreum");
|
|
|
15
15
|
const query_1 = require("../coreum/feemodel/v1/query");
|
|
16
16
|
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
17
17
|
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
18
|
+
const cosmos_1 = require("../cosmos");
|
|
19
|
+
const signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
|
|
20
|
+
const service_1 = require("cosmjs-types/cosmos/tx/v1beta1/service");
|
|
21
|
+
const keys_1 = require("cosmjs-types/cosmos/crypto/secp256k1/keys");
|
|
22
|
+
const tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
18
23
|
const types_1 = require("../types");
|
|
19
24
|
const utils_1 = require("../utils");
|
|
20
25
|
const stargate_1 = require("@cosmjs/stargate");
|
|
26
|
+
const encoding_1 = require("@cosmjs/encoding");
|
|
27
|
+
const crypto_1 = require("@cosmjs/crypto");
|
|
21
28
|
const extensions_1 = require("../cosmos/extensions");
|
|
22
29
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
23
30
|
const event_1 = require("../utils/event");
|
|
@@ -192,6 +199,73 @@ class Client {
|
|
|
192
199
|
fee: (0, stargate_1.calculateFee)(total_gas_wanted, gasPrice),
|
|
193
200
|
};
|
|
194
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Calculates gas by simulating the transaction with a dummy signer.
|
|
204
|
+
* Similar to Go's CalculateGas function - works without a signing client.
|
|
205
|
+
*
|
|
206
|
+
* @param msgs Messages to simulate
|
|
207
|
+
* @param options Optional configuration
|
|
208
|
+
* @param options.fromAddress Address to simulate from (optional, uses dummy if not provided)
|
|
209
|
+
* @param options.gasAdjustment Multiplier for gas (default: 1.2)
|
|
210
|
+
* @returns The estimated gas amount
|
|
211
|
+
*/
|
|
212
|
+
async calculateGas(msgs, options) {
|
|
213
|
+
if (!this._queryClient) {
|
|
214
|
+
throw new Error("Query client not initialized. Call connect() first.");
|
|
215
|
+
}
|
|
216
|
+
const { fromAddress, gasAdjustment = 1.2 } = options || {};
|
|
217
|
+
// Use provided address or generate a valid dummy bech32 address
|
|
218
|
+
let simAddress;
|
|
219
|
+
if (fromAddress) {
|
|
220
|
+
simAddress = fromAddress;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// Generate a valid bech32 address from a dummy hash
|
|
224
|
+
// This creates a valid address format that the RPC will accept
|
|
225
|
+
const dummyHash = (0, crypto_1.sha256)(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
|
|
226
|
+
const addressBytes = dummyHash.slice(0, 20); // Use first 20 bytes for address
|
|
227
|
+
simAddress = (0, encoding_1.toBech32)(this.config.chain_bech32_prefix, addressBytes);
|
|
228
|
+
}
|
|
229
|
+
// Get account info if address is provided and client is available
|
|
230
|
+
let accountNumber = 0;
|
|
231
|
+
let sequence = 0;
|
|
232
|
+
if (fromAddress && this._client) {
|
|
233
|
+
try {
|
|
234
|
+
const account = await this._client.getAccount(fromAddress);
|
|
235
|
+
accountNumber = account.accountNumber;
|
|
236
|
+
sequence = account.sequence;
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// If account doesn't exist, use defaults (0, 0)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Build transaction for simulation
|
|
243
|
+
// Note: We'll derive the address from the dummy pubkey in _buildTxForSimulation
|
|
244
|
+
// to ensure the fee payer address matches the signer
|
|
245
|
+
const txBytes = await this._buildTxForSimulation(msgs, simAddress, // This will be overridden by derived address if not provided
|
|
246
|
+
accountNumber, sequence);
|
|
247
|
+
// Use tx service client to simulate
|
|
248
|
+
const rpcClient = (0, stargate_1.createProtobufRpcClient)(this._queryClient);
|
|
249
|
+
const txService = new service_1.ServiceClientImpl(rpcClient);
|
|
250
|
+
const simulateResponse = await txService.Simulate({
|
|
251
|
+
txBytes: txBytes,
|
|
252
|
+
});
|
|
253
|
+
if (!simulateResponse.gasInfo) {
|
|
254
|
+
throw new Error("Simulation failed: no gas info returned");
|
|
255
|
+
}
|
|
256
|
+
const gasUsed = Number(simulateResponse.gasInfo.gasUsed || 0);
|
|
257
|
+
const adjustedGas = Math.ceil(gasUsed * gasAdjustment);
|
|
258
|
+
return adjustedGas;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gets the current gas price without transaction simulation.
|
|
262
|
+
* Equivalent to Go's GetGasPrice function.
|
|
263
|
+
*
|
|
264
|
+
* @returns GasPrice object
|
|
265
|
+
*/
|
|
266
|
+
async getGasPrice() {
|
|
267
|
+
return await this._getGasPrice();
|
|
268
|
+
}
|
|
195
269
|
/**
|
|
196
270
|
*
|
|
197
271
|
* @param transaction Transaction to be submitted
|
|
@@ -375,6 +449,94 @@ class Client {
|
|
|
375
449
|
}
|
|
376
450
|
return stargate_1.GasPrice.fromString(`${gasPrice}${minGasPriceRes.minGasPrice?.denom || ""}`);
|
|
377
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Builds a transaction for simulation with a dummy signer.
|
|
454
|
+
* Similar to Go's BuildTxForSimulation function.
|
|
455
|
+
*
|
|
456
|
+
* @private
|
|
457
|
+
* @param msgs Messages to simulate
|
|
458
|
+
* @param fromAddress Address to simulate from
|
|
459
|
+
* @param accountNumber Account number
|
|
460
|
+
* @param sequence Sequence number
|
|
461
|
+
* @returns Encoded transaction bytes ready for simulation
|
|
462
|
+
*/
|
|
463
|
+
async _buildTxForSimulation(msgs, fromAddress, accountNumber = 0, sequence = 0) {
|
|
464
|
+
if (!this._queryClient) {
|
|
465
|
+
throw new Error("Query client not initialized. Call connect() first.");
|
|
466
|
+
}
|
|
467
|
+
const registry = Client.getRegistry();
|
|
468
|
+
// Create dummy public key (33 bytes for secp256k1 compressed pubkey)
|
|
469
|
+
const dummyPubKeyBytes = new Uint8Array(33).fill(0);
|
|
470
|
+
dummyPubKeyBytes[0] = 0x02; // Set compression flag
|
|
471
|
+
const dummyPubKey = {
|
|
472
|
+
key: dummyPubKeyBytes,
|
|
473
|
+
};
|
|
474
|
+
// Derive address from the dummy pubkey to ensure consistency
|
|
475
|
+
// Cosmos SDK derives addresses as: RIPEMD160(SHA256(pubkey))
|
|
476
|
+
const pubkeyHash = (0, crypto_1.sha256)(dummyPubKeyBytes);
|
|
477
|
+
const addressBytes = (0, crypto_1.ripemd160)(pubkeyHash).slice(0, 20);
|
|
478
|
+
const derivedAddress = (0, encoding_1.toBech32)(this.config.chain_bech32_prefix, addressBytes);
|
|
479
|
+
// Use derived address to ensure fee payer matches signer
|
|
480
|
+
// This is important for simulation - the RPC expects consistency
|
|
481
|
+
const finalAddress = fromAddress || derivedAddress;
|
|
482
|
+
// Create dummy signer info
|
|
483
|
+
const signerInfo = {
|
|
484
|
+
publicKey: {
|
|
485
|
+
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
|
486
|
+
value: keys_1.PubKey.encode(dummyPubKey).finish(),
|
|
487
|
+
},
|
|
488
|
+
modeInfo: {
|
|
489
|
+
single: {
|
|
490
|
+
mode: signing_1.SignMode.SIGN_MODE_DIRECT,
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
sequence: BigInt(sequence),
|
|
494
|
+
};
|
|
495
|
+
// Create dummy fee
|
|
496
|
+
// Leave payer empty for simulation - RPC will use the first signer as payer
|
|
497
|
+
const fee = {
|
|
498
|
+
amount: [],
|
|
499
|
+
gasLimit: BigInt(0),
|
|
500
|
+
payer: "",
|
|
501
|
+
granter: "",
|
|
502
|
+
};
|
|
503
|
+
// Create auth info
|
|
504
|
+
const authInfo = {
|
|
505
|
+
signerInfos: [signerInfo],
|
|
506
|
+
fee: fee,
|
|
507
|
+
};
|
|
508
|
+
// Build the transaction body
|
|
509
|
+
const body = {
|
|
510
|
+
messages: msgs.map((msg) => {
|
|
511
|
+
// EncodeObject.value is already a Uint8Array, but we need to encode
|
|
512
|
+
// the message object itself using the registry
|
|
513
|
+
const encoded = registry.encode(msg);
|
|
514
|
+
return {
|
|
515
|
+
typeUrl: msg.typeUrl,
|
|
516
|
+
value: encoded,
|
|
517
|
+
};
|
|
518
|
+
}),
|
|
519
|
+
memo: "",
|
|
520
|
+
timeoutHeight: BigInt(0),
|
|
521
|
+
extensionOptions: [],
|
|
522
|
+
nonCriticalExtensionOptions: [],
|
|
523
|
+
};
|
|
524
|
+
// Encode body and auth info using protobuf encoders
|
|
525
|
+
const bodyBytes = tx_1.TxBody.encode(body).finish();
|
|
526
|
+
const authInfoBytes = tx_1.AuthInfo.encode(authInfo).finish();
|
|
527
|
+
// Create dummy signature (64 bytes for secp256k1 signature)
|
|
528
|
+
const dummySignature = new Uint8Array(64).fill(0);
|
|
529
|
+
// Create TxRaw
|
|
530
|
+
const txRaw = {
|
|
531
|
+
bodyBytes: bodyBytes,
|
|
532
|
+
authInfoBytes: authInfoBytes,
|
|
533
|
+
signatures: [dummySignature],
|
|
534
|
+
};
|
|
535
|
+
// Serialize TxRaw to bytes for simulation
|
|
536
|
+
// TxRaw is already in the correct format, we just need to encode it
|
|
537
|
+
const txBytes = cosmos_1.TxRaw.encode(txRaw).finish();
|
|
538
|
+
return txBytes;
|
|
539
|
+
}
|
|
378
540
|
_isSigningClientInit() {
|
|
379
541
|
if (!this._client || !isSigningClient(this._client))
|
|
380
542
|
throw new Error("Signing Client is not initialized");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const protobufPackage = "cosmos.msg.v1";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
|
+
// versions:
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
|
+
// protoc v6.32.0
|
|
6
|
+
// source: cosmos/cosmos-sdk/proto/cosmos/msg/v1/msg.proto
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.protobufPackage = void 0;
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
exports.protobufPackage = "cosmos.msg.v1";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
5
|
-
// protoc
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
|
+
// protoc v6.32.0
|
|
6
6
|
// source: coreum-protos/dex/event.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.EventOrderClosed = exports.EventOrderCreated = exports.EventOrderReduced = exports.EventOrderPlaced = exports.protobufPackage = void 0;
|
|
@@ -169,12 +169,8 @@ exports.EventOrderReduced = {
|
|
|
169
169
|
creator: isSet(object.creator) ? globalThis.String(object.creator) : "",
|
|
170
170
|
id: isSet(object.id) ? globalThis.String(object.id) : "",
|
|
171
171
|
sequence: isSet(object.sequence) ? globalThis.Number(object.sequence) : 0,
|
|
172
|
-
sentCoin: isSet(object.sentCoin)
|
|
173
|
-
|
|
174
|
-
: "",
|
|
175
|
-
receivedCoin: isSet(object.receivedCoin)
|
|
176
|
-
? globalThis.String(object.receivedCoin)
|
|
177
|
-
: "",
|
|
172
|
+
sentCoin: isSet(object.sentCoin) ? globalThis.String(object.sentCoin) : "",
|
|
173
|
+
receivedCoin: isSet(object.receivedCoin) ? globalThis.String(object.receivedCoin) : "",
|
|
178
174
|
};
|
|
179
175
|
},
|
|
180
176
|
toJSON(message) {
|
|
@@ -210,13 +206,7 @@ exports.EventOrderReduced = {
|
|
|
210
206
|
},
|
|
211
207
|
};
|
|
212
208
|
function createBaseEventOrderCreated() {
|
|
213
|
-
return {
|
|
214
|
-
creator: "",
|
|
215
|
-
id: "",
|
|
216
|
-
sequence: 0,
|
|
217
|
-
remainingBaseQuantity: "",
|
|
218
|
-
remainingSpendableBalance: "",
|
|
219
|
-
};
|
|
209
|
+
return { creator: "", id: "", sequence: 0, remainingBaseQuantity: "", remainingSpendableBalance: "" };
|
|
220
210
|
}
|
|
221
211
|
exports.EventOrderCreated = {
|
|
222
212
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -292,9 +282,7 @@ exports.EventOrderCreated = {
|
|
|
292
282
|
creator: isSet(object.creator) ? globalThis.String(object.creator) : "",
|
|
293
283
|
id: isSet(object.id) ? globalThis.String(object.id) : "",
|
|
294
284
|
sequence: isSet(object.sequence) ? globalThis.Number(object.sequence) : 0,
|
|
295
|
-
remainingBaseQuantity: isSet(object.remainingBaseQuantity)
|
|
296
|
-
? globalThis.String(object.remainingBaseQuantity)
|
|
297
|
-
: "",
|
|
285
|
+
remainingBaseQuantity: isSet(object.remainingBaseQuantity) ? globalThis.String(object.remainingBaseQuantity) : "",
|
|
298
286
|
remainingSpendableBalance: isSet(object.remainingSpendableBalance)
|
|
299
287
|
? globalThis.String(object.remainingSpendableBalance)
|
|
300
288
|
: "",
|
|
@@ -333,13 +321,7 @@ exports.EventOrderCreated = {
|
|
|
333
321
|
},
|
|
334
322
|
};
|
|
335
323
|
function createBaseEventOrderClosed() {
|
|
336
|
-
return {
|
|
337
|
-
creator: "",
|
|
338
|
-
id: "",
|
|
339
|
-
sequence: 0,
|
|
340
|
-
remainingBaseQuantity: "",
|
|
341
|
-
remainingSpendableBalance: "",
|
|
342
|
-
};
|
|
324
|
+
return { creator: "", id: "", sequence: 0, remainingBaseQuantity: "", remainingSpendableBalance: "" };
|
|
343
325
|
}
|
|
344
326
|
exports.EventOrderClosed = {
|
|
345
327
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -415,9 +397,7 @@ exports.EventOrderClosed = {
|
|
|
415
397
|
creator: isSet(object.creator) ? globalThis.String(object.creator) : "",
|
|
416
398
|
id: isSet(object.id) ? globalThis.String(object.id) : "",
|
|
417
399
|
sequence: isSet(object.sequence) ? globalThis.Number(object.sequence) : 0,
|
|
418
|
-
remainingBaseQuantity: isSet(object.remainingBaseQuantity)
|
|
419
|
-
? globalThis.String(object.remainingBaseQuantity)
|
|
420
|
-
: "",
|
|
400
|
+
remainingBaseQuantity: isSet(object.remainingBaseQuantity) ? globalThis.String(object.remainingBaseQuantity) : "",
|
|
421
401
|
remainingSpendableBalance: isSet(object.remainingSpendableBalance)
|
|
422
402
|
? globalThis.String(object.remainingSpendableBalance)
|
|
423
403
|
: "",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BinaryReader, BinaryWriter } from "
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
2
|
import { Order, OrderBookData } from "./order";
|
|
3
3
|
import { Params } from "./params";
|
|
4
4
|
export declare const protobufPackage = "coreum.dex.v1";
|
|
@@ -11,6 +11,7 @@ export interface GenesisState {
|
|
|
11
11
|
/** order_sequence is current order sequence; */
|
|
12
12
|
orderSequence: number;
|
|
13
13
|
accountsDenomsOrdersCounts: AccountDenomOrdersCount[];
|
|
14
|
+
reservedOrderIds: Uint8Array[];
|
|
14
15
|
}
|
|
15
16
|
/** OrderBookDataWithID is a order book data with it's corresponding ID. */
|
|
16
17
|
export interface OrderBookDataWithID {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.
|
|
5
|
-
// protoc
|
|
4
|
+
// protoc-gen-ts_proto v2.7.0
|
|
5
|
+
// protoc v6.32.0
|
|
6
6
|
// source: coreum-protos/dex/genesis.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.AccountDenomOrdersCount = exports.OrderBookDataWithID = exports.GenesisState = exports.protobufPackage = void 0;
|
|
9
9
|
/* eslint-disable */
|
|
10
|
-
const
|
|
10
|
+
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
11
11
|
const order_1 = require("./order");
|
|
12
12
|
const params_1 = require("./params");
|
|
13
13
|
exports.protobufPackage = "coreum.dex.v1";
|
|
@@ -18,29 +18,33 @@ function createBaseGenesisState() {
|
|
|
18
18
|
orders: [],
|
|
19
19
|
orderSequence: 0,
|
|
20
20
|
accountsDenomsOrdersCounts: [],
|
|
21
|
+
reservedOrderIds: [],
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
exports.GenesisState = {
|
|
24
|
-
encode(message, writer = new
|
|
25
|
+
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
25
26
|
if (message.params !== undefined) {
|
|
26
|
-
params_1.Params.encode(message.params, writer.uint32(10).fork()).
|
|
27
|
+
params_1.Params.encode(message.params, writer.uint32(10).fork()).join();
|
|
27
28
|
}
|
|
28
29
|
for (const v of message.orderBooks) {
|
|
29
|
-
exports.OrderBookDataWithID.encode(v, writer.uint32(18).fork()).
|
|
30
|
+
exports.OrderBookDataWithID.encode(v, writer.uint32(18).fork()).join();
|
|
30
31
|
}
|
|
31
32
|
for (const v of message.orders) {
|
|
32
|
-
order_1.Order.encode(v, writer.uint32(26).fork()).
|
|
33
|
+
order_1.Order.encode(v, writer.uint32(26).fork()).join();
|
|
33
34
|
}
|
|
34
35
|
if (message.orderSequence !== 0) {
|
|
35
36
|
writer.uint32(32).uint64(message.orderSequence);
|
|
36
37
|
}
|
|
37
38
|
for (const v of message.accountsDenomsOrdersCounts) {
|
|
38
|
-
exports.AccountDenomOrdersCount.encode(v, writer.uint32(42).fork()).
|
|
39
|
+
exports.AccountDenomOrdersCount.encode(v, writer.uint32(42).fork()).join();
|
|
40
|
+
}
|
|
41
|
+
for (const v of message.reservedOrderIds) {
|
|
42
|
+
writer.uint32(50).bytes(v);
|
|
39
43
|
}
|
|
40
44
|
return writer;
|
|
41
45
|
},
|
|
42
46
|
decode(input, length) {
|
|
43
|
-
const reader = input instanceof
|
|
47
|
+
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
44
48
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
45
49
|
const message = createBaseGenesisState();
|
|
46
50
|
while (reader.pos < end) {
|
|
@@ -81,6 +85,13 @@ exports.GenesisState = {
|
|
|
81
85
|
message.accountsDenomsOrdersCounts.push(exports.AccountDenomOrdersCount.decode(reader, reader.uint32()));
|
|
82
86
|
continue;
|
|
83
87
|
}
|
|
88
|
+
case 6: {
|
|
89
|
+
if (tag !== 50) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
message.reservedOrderIds.push(reader.bytes());
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
84
95
|
}
|
|
85
96
|
if ((tag & 7) === 4 || tag === 0) {
|
|
86
97
|
break;
|
|
@@ -104,6 +115,9 @@ exports.GenesisState = {
|
|
|
104
115
|
accountsDenomsOrdersCounts: globalThis.Array.isArray(object?.accountsDenomsOrdersCounts)
|
|
105
116
|
? object.accountsDenomsOrdersCounts.map((e) => exports.AccountDenomOrdersCount.fromJSON(e))
|
|
106
117
|
: [],
|
|
118
|
+
reservedOrderIds: globalThis.Array.isArray(object?.reservedOrderIds)
|
|
119
|
+
? object.reservedOrderIds.map((e) => bytesFromBase64(e))
|
|
120
|
+
: [],
|
|
107
121
|
};
|
|
108
122
|
},
|
|
109
123
|
toJSON(message) {
|
|
@@ -123,6 +137,9 @@ exports.GenesisState = {
|
|
|
123
137
|
if (message.accountsDenomsOrdersCounts?.length) {
|
|
124
138
|
obj.accountsDenomsOrdersCounts = message.accountsDenomsOrdersCounts.map((e) => exports.AccountDenomOrdersCount.toJSON(e));
|
|
125
139
|
}
|
|
140
|
+
if (message.reservedOrderIds?.length) {
|
|
141
|
+
obj.reservedOrderIds = message.reservedOrderIds.map((e) => base64FromBytes(e));
|
|
142
|
+
}
|
|
126
143
|
return obj;
|
|
127
144
|
},
|
|
128
145
|
create(base) {
|
|
@@ -140,6 +157,7 @@ exports.GenesisState = {
|
|
|
140
157
|
message.orderSequence = object.orderSequence ?? 0;
|
|
141
158
|
message.accountsDenomsOrdersCounts =
|
|
142
159
|
object.accountsDenomsOrdersCounts?.map((e) => exports.AccountDenomOrdersCount.fromPartial(e)) || [];
|
|
160
|
+
message.reservedOrderIds = object.reservedOrderIds?.map((e) => e) || [];
|
|
143
161
|
return message;
|
|
144
162
|
},
|
|
145
163
|
};
|
|
@@ -147,17 +165,17 @@ function createBaseOrderBookDataWithID() {
|
|
|
147
165
|
return { id: 0, data: undefined };
|
|
148
166
|
}
|
|
149
167
|
exports.OrderBookDataWithID = {
|
|
150
|
-
encode(message, writer = new
|
|
168
|
+
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
151
169
|
if (message.id !== 0) {
|
|
152
170
|
writer.uint32(8).uint32(message.id);
|
|
153
171
|
}
|
|
154
172
|
if (message.data !== undefined) {
|
|
155
|
-
order_1.OrderBookData.encode(message.data, writer.uint32(18).fork()).
|
|
173
|
+
order_1.OrderBookData.encode(message.data, writer.uint32(18).fork()).join();
|
|
156
174
|
}
|
|
157
175
|
return writer;
|
|
158
176
|
},
|
|
159
177
|
decode(input, length) {
|
|
160
|
-
const reader = input instanceof
|
|
178
|
+
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
161
179
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
162
180
|
const message = createBaseOrderBookDataWithID();
|
|
163
181
|
while (reader.pos < end) {
|
|
@@ -220,7 +238,7 @@ function createBaseAccountDenomOrdersCount() {
|
|
|
220
238
|
return { accountNumber: 0, denom: "", ordersCount: 0 };
|
|
221
239
|
}
|
|
222
240
|
exports.AccountDenomOrdersCount = {
|
|
223
|
-
encode(message, writer = new
|
|
241
|
+
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
224
242
|
if (message.accountNumber !== 0) {
|
|
225
243
|
writer.uint32(8).uint64(message.accountNumber);
|
|
226
244
|
}
|
|
@@ -233,7 +251,7 @@ exports.AccountDenomOrdersCount = {
|
|
|
233
251
|
return writer;
|
|
234
252
|
},
|
|
235
253
|
decode(input, length) {
|
|
236
|
-
const reader = input instanceof
|
|
254
|
+
const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
|
|
237
255
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
238
256
|
const message = createBaseAccountDenomOrdersCount();
|
|
239
257
|
while (reader.pos < end) {
|
|
@@ -303,6 +321,31 @@ exports.AccountDenomOrdersCount = {
|
|
|
303
321
|
return message;
|
|
304
322
|
},
|
|
305
323
|
};
|
|
324
|
+
function bytesFromBase64(b64) {
|
|
325
|
+
if (globalThis.Buffer) {
|
|
326
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const bin = globalThis.atob(b64);
|
|
330
|
+
const arr = new Uint8Array(bin.length);
|
|
331
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
332
|
+
arr[i] = bin.charCodeAt(i);
|
|
333
|
+
}
|
|
334
|
+
return arr;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function base64FromBytes(arr) {
|
|
338
|
+
if (globalThis.Buffer) {
|
|
339
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
const bin = [];
|
|
343
|
+
arr.forEach((byte) => {
|
|
344
|
+
bin.push(globalThis.String.fromCharCode(byte));
|
|
345
|
+
});
|
|
346
|
+
return globalThis.btoa(bin.join(""));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
306
349
|
function longToNumber(int64) {
|
|
307
350
|
const num = globalThis.Number(int64.toString());
|
|
308
351
|
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BinaryReader, BinaryWriter } from "
|
|
2
|
-
import { Coin } from "
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
|
+
import { Coin } from "./cosmos/cosmos-sdk/proto/cosmos/base/v1beta1/coin";
|
|
3
3
|
export declare const protobufPackage = "coreum.dex.v1";
|
|
4
4
|
/** Side is order side. */
|
|
5
5
|
export declare enum Side {
|
|
@@ -45,7 +45,7 @@ export declare function timeInForceToJSON(object: TimeInForce): string;
|
|
|
45
45
|
/** GoodTil is a good til order settings. */
|
|
46
46
|
export interface GoodTil {
|
|
47
47
|
/** good_til_block_height means that order remains active until a specific blockchain block height is reached. */
|
|
48
|
-
goodTilBlockHeight: number
|
|
48
|
+
goodTilBlockHeight: number;
|
|
49
49
|
/** good_til_block_time means that order remains active until a specific blockchain block time is reached. */
|
|
50
50
|
goodTilBlockTime: Date | undefined;
|
|
51
51
|
}
|
|
@@ -114,25 +114,6 @@ export interface OrderBookData {
|
|
|
114
114
|
/** quote_denom is quote order book denom */
|
|
115
115
|
quoteDenom: string;
|
|
116
116
|
}
|
|
117
|
-
/** OrderBookRecord is a single order book record, it combines both key and value from the store. */
|
|
118
|
-
export interface OrderBookRecord {
|
|
119
|
-
/** order_book_id is order book ID. */
|
|
120
|
-
orderBookId: number;
|
|
121
|
-
/** side is order side. */
|
|
122
|
-
side: Side;
|
|
123
|
-
/** price is order book record price. */
|
|
124
|
-
price: string;
|
|
125
|
-
/** order_sequence is order sequence. */
|
|
126
|
-
orderSequence: number;
|
|
127
|
-
/** order ID provided by the creator. */
|
|
128
|
-
orderId: string;
|
|
129
|
-
/** account_number is account number which corresponds the order creator. */
|
|
130
|
-
accountNumber: number;
|
|
131
|
-
/** remaining_base_quantity - is remaining quantity of base denom which user wants to sell or buy. */
|
|
132
|
-
remainingBaseQuantity: string;
|
|
133
|
-
/** remaining_spendable_balance - is balance up to which user wants to spend to execute the order. */
|
|
134
|
-
remainingSpendableBalance: string;
|
|
135
|
-
}
|
|
136
117
|
/** OrderBookRecordData is a single order book record used for the store. */
|
|
137
118
|
export interface OrderBookRecordData {
|
|
138
119
|
/** order ID provided by the creator. */
|
|
@@ -149,7 +130,6 @@ export declare const CancelGoodTil: MessageFns<CancelGoodTil>;
|
|
|
149
130
|
export declare const Order: MessageFns<Order>;
|
|
150
131
|
export declare const OrderData: MessageFns<OrderData>;
|
|
151
132
|
export declare const OrderBookData: MessageFns<OrderBookData>;
|
|
152
|
-
export declare const OrderBookRecord: MessageFns<OrderBookRecord>;
|
|
153
133
|
export declare const OrderBookRecordData: MessageFns<OrderBookRecordData>;
|
|
154
134
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
155
135
|
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|