carbon-js-sdk 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/lib/clients/CarbonQueryClient.js +2 -2
  2. package/lib/clients/ETHClient.js +15 -15
  3. package/lib/clients/HydrogenClient.js +1 -1
  4. package/lib/clients/NEOClient.js +6 -6
  5. package/lib/clients/TokenClient.js +4 -2
  6. package/lib/clients/ZILClient.js +16 -16
  7. package/lib/codec/bank/tx.d.ts +64 -0
  8. package/lib/codec/bank/tx.js +236 -0
  9. package/lib/codec/cdp/query.d.ts +14 -2
  10. package/lib/codec/cdp/query.js +40 -2
  11. package/lib/codec/cdp/tx.d.ts +4 -11
  12. package/lib/codec/cdp/tx.js +5 -130
  13. package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
  14. package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
  15. package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
  16. package/lib/codec/index.d.ts +2 -2
  17. package/lib/codec/index.js +11 -13
  18. package/lib/codec/oracle/event.d.ts +1 -33
  19. package/lib/codec/oracle/event.js +1 -166
  20. package/lib/constant/generic.js +1 -1
  21. package/lib/modules/cdp.d.ts +4 -1
  22. package/lib/modules/cdp.js +54 -50
  23. package/lib/modules/gov.js +14 -14
  24. package/lib/modules/liquiditypool.js +1 -1
  25. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  26. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  27. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  28. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  29. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  30. package/lib/provider/amino/types/admin.js +30 -30
  31. package/lib/provider/amino/types/bank.js +1 -1
  32. package/lib/provider/amino/types/broker.js +1 -1
  33. package/lib/provider/amino/types/cdp.js +22 -22
  34. package/lib/provider/amino/types/coin.js +2 -2
  35. package/lib/provider/amino/types/gov.js +4 -4
  36. package/lib/provider/amino/types/ibc.js +1 -1
  37. package/lib/provider/amino/types/leverage.js +1 -1
  38. package/lib/provider/amino/types/liquidityPool.js +7 -7
  39. package/lib/provider/amino/types/market.js +1 -1
  40. package/lib/provider/amino/types/oracle.js +1 -1
  41. package/lib/provider/amino/types/order.js +4 -4
  42. package/lib/provider/amino/types/position.js +1 -1
  43. package/lib/provider/amino/types/profile.js +1 -1
  44. package/lib/provider/amino/types/staking.js +4 -4
  45. package/lib/provider/amino/types/subaccount.js +3 -3
  46. package/lib/provider/amino/utils.js +11 -11
  47. package/lib/provider/keplr/KeplrStore.js +1 -1
  48. package/lib/provider/ledger/ledger.js +2 -2
  49. package/lib/provider/metamask/MetaMask.js +1 -1
  50. package/lib/provider/o3/O3Wallet.js +2 -2
  51. package/lib/util/address.js +13 -13
  52. package/lib/util/api.js +4 -4
  53. package/lib/util/fetch.js +1 -1
  54. package/lib/util/generic.js +3 -3
  55. package/lib/util/number.js +5 -5
  56. package/lib/util/tx.d.ts +5 -1
  57. package/lib/util/tx.js +8 -1
  58. package/lib/wallet/CarbonSigner.js +2 -2
  59. package/lib/wallet/CarbonSigningClient.js +8 -8
  60. package/lib/wallet/CarbonWallet.js +7 -7
  61. package/lib/websocket/connector.js +3 -3
  62. package/package.json +1 -1
package/lib/util/fetch.js CHANGED
@@ -10,7 +10,7 @@ function fetch(url, init) {
10
10
  return window.fetch(url, Object.assign({}, init));
11
11
  }
12
12
  else {
13
- return (0, node_fetch_1.default)(url, init);
13
+ return node_fetch_1.default(url, init);
14
14
  }
15
15
  }
16
16
  exports.fetch = fetch;
@@ -22,7 +22,7 @@ const overrideConfig = (defaults, override) => {
22
22
  continue;
23
23
  if (typeof member === "object") {
24
24
  // @ts-ignore
25
- result[key] = (0, exports.overrideConfig)(result[key], member);
25
+ result[key] = exports.overrideConfig(result[key], member);
26
26
  }
27
27
  else {
28
28
  // @ts-ignore
@@ -41,7 +41,7 @@ const sortObject = (input) => {
41
41
  Object.keys(input)
42
42
  .sort()
43
43
  // @ts-ignore noImplicitAny
44
- .forEach((key) => (output[key] = (0, exports.sortObject)(input[key])));
44
+ .forEach((key) => (output[key] = exports.sortObject(input[key])));
45
45
  return output;
46
46
  };
47
47
  exports.sortObject = sortObject;
@@ -56,7 +56,7 @@ exports.appendHexPrefix = appendHexPrefix;
56
56
  const computeTxHash = (bytes) => {
57
57
  if (!bytes)
58
58
  return bytes;
59
- return (0, exports.toTxHash)((0, crypto_1.sha256)(bytes));
59
+ return exports.toTxHash(crypto_1.sha256(bytes));
60
60
  };
61
61
  exports.computeTxHash = computeTxHash;
62
62
  const toTxHash = (bytes) => {
@@ -18,26 +18,26 @@ const parseBN = (input, defaultValue) => {
18
18
  };
19
19
  exports.parseBN = parseBN;
20
20
  const bnOrZero = (input, defaultValue = exports.BN_ZERO) => {
21
- return (0, exports.parseBN)(input, defaultValue);
21
+ return exports.parseBN(input, defaultValue);
22
22
  };
23
23
  exports.bnOrZero = bnOrZero;
24
24
  const toHuman = (value, decimals) => {
25
25
  if (value === undefined || value === null)
26
26
  return undefined;
27
- const valueBN = (0, exports.bnOrZero)(value);
27
+ const valueBN = exports.bnOrZero(value);
28
28
  if (!decimals)
29
29
  return valueBN; // decimals = 0 or nullish
30
- const decimalsBN = (0, exports.bnOrZero)(decimals);
30
+ const decimalsBN = exports.bnOrZero(decimals);
31
31
  return valueBN.shiftedBy(decimalsBN.negated().toNumber());
32
32
  };
33
33
  exports.toHuman = toHuman;
34
34
  const toUnitless = (value, decimals) => {
35
35
  if (value === undefined || value === null)
36
36
  return undefined;
37
- const valueBN = (0, exports.bnOrZero)(value);
37
+ const valueBN = exports.bnOrZero(value);
38
38
  if (!decimals)
39
39
  return valueBN; // decimals = 0 or nullish
40
- const decimalsBN = (0, exports.bnOrZero)(decimals);
40
+ const decimalsBN = exports.bnOrZero(decimals);
41
41
  return valueBN.shiftedBy(decimalsBN.toNumber());
42
42
  };
43
43
  exports.toUnitless = toUnitless;
package/lib/util/tx.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import * as CosmosModels from "../codec/cosmos-models";
3
3
  import { StdFee } from "@cosmjs/amino";
4
- import { SignerData } from "@cosmjs/stargate";
4
+ import { DeliverTxResponse, SignerData } from "@cosmjs/stargate";
5
5
  import { SWTHAddressOptions } from "./address";
6
6
  export { StdSignDoc } from "@cosmjs/amino";
7
7
  export interface TxBody extends Omit<CosmosModels.Tx.TxBody, "messages"> {
@@ -47,6 +47,10 @@ export interface TxResponse {
47
47
  code?: number;
48
48
  codespace?: string;
49
49
  }
50
+ export declare class CarbonTxError extends Error {
51
+ readonly response: DeliverTxResponse;
52
+ constructor(msg: string, response: DeliverTxResponse);
53
+ }
50
54
  export declare const Types: {
51
55
  MsgSetTradingFlag: string;
52
56
  MsgSetTradingFlagResponse: string;
package/lib/util/tx.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.BroadcastTxMode = exports.getSender = exports.decode = void 0;
22
+ exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.CarbonTxError = exports.BroadcastTxMode = exports.getSender = exports.decode = void 0;
23
23
  const codec_1 = require("../codec");
24
24
  const CosmosModels = __importStar(require("../codec/cosmos-models"));
25
25
  const constant_1 = require("../constant");
@@ -104,6 +104,13 @@ var BroadcastTxMode;
104
104
  BroadcastTxMode["BroadcastTxSync"] = "sync";
105
105
  BroadcastTxMode["BroadcastTxBlock"] = "block";
106
106
  })(BroadcastTxMode = exports.BroadcastTxMode || (exports.BroadcastTxMode = {}));
107
+ class CarbonTxError extends Error {
108
+ constructor(msg, response) {
109
+ super(msg);
110
+ this.response = response;
111
+ }
112
+ }
113
+ exports.CarbonTxError = CarbonTxError;
107
114
  exports.Types = codec_1.TxTypes;
108
115
  exports.DEFAULT_SIGN_OPTS = {
109
116
  fee: constant_1.DEFAULT_FEE,
@@ -106,9 +106,9 @@ class CarbonLedgerSigner {
106
106
  return __awaiter(this, void 0, void 0, function* () {
107
107
  const account = yield this.retrieveAccount();
108
108
  const { pubkey } = account;
109
- const msg = JSON.stringify((0, generic_1.sortObject)(doc));
109
+ const msg = JSON.stringify(generic_1.sortObject(doc));
110
110
  const signBytes = yield this.ledger.sign(msg);
111
- const signature = (0, amino_1.encodeSecp256k1Signature)(pubkey, signBytes);
111
+ const signature = amino_1.encodeSecp256k1Signature(pubkey, signBytes);
112
112
  return {
113
113
  signed: doc,
114
114
  signature,
@@ -87,7 +87,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
87
87
  */
88
88
  sign(signerAddress, messages, fee, memo, signerData) {
89
89
  return __awaiter(this, void 0, void 0, function* () {
90
- return (0, proto_signing_1.isOfflineDirectSigner)(this.signer)
90
+ return proto_signing_1.isOfflineDirectSigner(this.signer)
91
91
  ? this.signDirect(signerAddress, messages, fee, memo, signerData)
92
92
  : this.signAmino(signerAddress, messages, fee, memo, signerData);
93
93
  });
@@ -99,7 +99,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
99
99
  if (!accountFromSigner) {
100
100
  throw new Error("Failed to retrieve account from signer");
101
101
  }
102
- const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
102
+ const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
103
103
  const txBodyEncodeObject = {
104
104
  typeUrl: "/cosmos.tx.v1beta1.TxBody",
105
105
  value: Object.assign({ messages: messages, memo: memo }, timeoutHeight && {
@@ -108,13 +108,13 @@ class CarbonSigningClient extends stargate_1.StargateClient {
108
108
  };
109
109
  const txBodyBytes = this.registry.encode(txBodyEncodeObject);
110
110
  const gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
111
- const authInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence }], fee.amount, gasLimit);
112
- const signDoc = (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, accountNumber);
111
+ const authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit);
112
+ const signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
113
113
  const { signature, signed } = yield signer.signDirect(signerAddress, signDoc);
114
114
  return tx_1.TxRaw.fromPartial({
115
115
  bodyBytes: signed.bodyBytes,
116
116
  authInfoBytes: signed.authInfoBytes,
117
- signatures: [(0, encoding_1.fromBase64)(signature.signature)],
117
+ signatures: [encoding_1.fromBase64(signature.signature)],
118
118
  });
119
119
  });
120
120
  }
@@ -125,7 +125,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
125
125
  if (!accountFromSigner) {
126
126
  throw new Error("Failed to retrieve account from signer");
127
127
  }
128
- const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
128
+ const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
129
129
  const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
130
130
  const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
131
131
  const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight !== null && timeoutHeight !== void 0 ? timeoutHeight : 0);
@@ -140,11 +140,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
140
140
  const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
141
141
  const signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
142
142
  const signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
143
- const signedAuthInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
143
+ const signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
144
144
  return tx_1.TxRaw.fromPartial({
145
145
  bodyBytes: signedTxBodyBytes,
146
146
  authInfoBytes: signedAuthInfoBytes,
147
- signatures: [(0, encoding_1.fromBase64)(signature.signature)],
147
+ signatures: [encoding_1.fromBase64(signature.signature)],
148
148
  });
149
149
  });
150
150
  }
@@ -148,7 +148,7 @@ class CarbonWallet {
148
148
  const signerData = Object.assign({ accountNumber: this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData);
149
149
  const fee = (_a = opts === null || opts === void 0 ? void 0 : opts.fee) !== null && _a !== void 0 ? _a : this.estimateTxFee(messages, feeDenom);
150
150
  const txRaw = yield signingClient.sign(signerAddress, messages, fee, memo, signerData);
151
- signature = (0, amino_1.encodeSecp256k1Signature)(account.pubkey, txRaw.signatures[0]);
151
+ signature = amino_1.encodeSecp256k1Signature(account.pubkey, txRaw.signatures[0]);
152
152
  return txRaw;
153
153
  }
154
154
  finally {
@@ -166,9 +166,9 @@ class CarbonWallet {
166
166
  const tx = CarbonWallet.TxRaw.encode(txRaw).finish();
167
167
  const carbonClient = this.getSigningClient();
168
168
  const response = yield carbonClient.broadcastTx(tx, timeoutMs, pollIntervalMs);
169
- if ((0, stargate_1.isDeliverTxFailure)(response)) {
169
+ if (stargate_1.isDeliverTxFailure(response)) {
170
170
  // tx failed
171
- throw new Error(`[${response.code}] ${response.rawLog}`);
171
+ throw new tx_1.CarbonTxError(`[${response.code}] ${response.rawLog}`, response);
172
172
  }
173
173
  return response;
174
174
  });
@@ -205,9 +205,9 @@ class CarbonWallet {
205
205
  try {
206
206
  if (!this.accountInfo || this.sequenceInvalidated)
207
207
  yield this.reloadAccountSequence();
208
- const heightResponse = yield (0, fetch_1.fetch)(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
208
+ const heightResponse = yield fetch_1.fetch(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
209
209
  const heightRes = yield heightResponse.json();
210
- const height = (0, number_1.bnOrZero)((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
210
+ const height = number_1.bnOrZero((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
211
211
  const timeoutHeight = height.isZero() ? undefined : height.toNumber() + this.defaultTimeoutBlocks;
212
212
  const sequence = this.accountInfo.sequence;
213
213
  this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
@@ -341,12 +341,12 @@ class CarbonWallet {
341
341
  const queryClient = this.getQueryClient();
342
342
  const { msgGasCosts } = yield queryClient.fee.MsgGasCostAll({});
343
343
  this.txGasCosts = msgGasCosts.reduce((result, item) => {
344
- result[item.msgType] = (0, number_1.bnOrZero)(item.gasCost);
344
+ result[item.msgType] = number_1.bnOrZero(item.gasCost);
345
345
  return result;
346
346
  }, {});
347
347
  const { minGasPrices } = yield queryClient.fee.MinGasPriceAll({});
348
348
  this.txGasPrices = minGasPrices.reduce((result, item) => {
349
- result[item.denom] = (0, number_1.bnOrZero)(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
349
+ result[item.denom] = number_1.bnOrZero(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
350
350
  return result;
351
351
  }, {});
352
352
  if (!this.txGasPrices[this.defaultFeeDenom]) {
@@ -171,7 +171,7 @@ class WSConnector {
171
171
  params = [params]; // eslint-disable-line no-param-reassign
172
172
  }
173
173
  for (const param of params) {
174
- const channelId = (0, channel_1.generateChannelId)(param);
174
+ const channelId = channel_1.generateChannelId(param);
175
175
  const shouldSubscribe = this.channelHandlers[channelId] === undefined;
176
176
  this.channelHandlers[channelId] = handler;
177
177
  if (shouldSubscribe) {
@@ -193,7 +193,7 @@ class WSConnector {
193
193
  }
194
194
  const channelIds = [];
195
195
  for (const param of params) {
196
- const channelId = (0, channel_1.generateChannelId)(param);
196
+ const channelId = channel_1.generateChannelId(param);
197
197
  delete this.channelHandlers[channelId];
198
198
  }
199
199
  this.send('unsubscribe', {
@@ -279,7 +279,7 @@ class WSConnector {
279
279
  if (!channelHandler) {
280
280
  this.debugLog(`handler not found for channel: ${message.channel}`);
281
281
  try {
282
- const params = (0, channel_1.parseChannelId)(message.channel);
282
+ const params = channel_1.parseChannelId(message.channel);
283
283
  this.unsubscribe({ channel: params.channel });
284
284
  }
285
285
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",