carbon-js-sdk 0.4.16-beta.1 → 0.4.16-beta.2

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.
@@ -15,6 +15,8 @@ import { QueryClientImpl as SlashingQueryClient } from "../codec/cosmos/slashing
15
15
  import { QueryClientImpl as StakingQueryClient } from "../codec/cosmos/staking/v1beta1/query";
16
16
  import { QueryClientImpl as UpgradeQueryClient } from "../codec/cosmos/upgrade/v1beta1/query";
17
17
  import { QueryClientImpl as EthermintEVMQueryClient } from "../codec/ethermint/evm/v1/query";
18
+ import { QueryClientImpl as EvmMergeQueryClient } from "../codec/evmmerge/query";
19
+ import { QueryClientImpl as EvmBankQueryClient } from "../codec/evmbank/query";
18
20
  import { QueryClientImpl as EthermintFeeMarketQueryClient } from "../codec/ethermint/feemarket/v1/query";
19
21
  import { QueryClientImpl as FeeQueryClient } from "../codec/fee/query";
20
22
  import { QueryClientImpl as HeadersyncQueryClient } from "../codec/headersync/query";
@@ -89,6 +91,8 @@ declare class CarbonQueryClient {
89
91
  chain: BlockchainClient;
90
92
  ibc: IBCClientGroup;
91
93
  ethermint: EthermintClientGroup;
94
+ evmmerge: EvmMergeQueryClient;
95
+ evmbank: EvmBankQueryClient;
92
96
  private baseClient;
93
97
  constructor(tmClient: Tendermint34Client);
94
98
  getProtobufRpcClient(): import("@cosmjs/stargate").ProtobufRpcClient;
@@ -20,29 +20,31 @@ const query_14 = require("../codec/cosmos/slashing/v1beta1/query");
20
20
  const query_15 = require("../codec/cosmos/staking/v1beta1/query");
21
21
  const query_16 = require("../codec/cosmos/upgrade/v1beta1/query");
22
22
  const query_17 = require("../codec/ethermint/evm/v1/query");
23
- const query_18 = require("../codec/ethermint/feemarket/v1/query");
24
- const query_19 = require("../codec/fee/query");
25
- const query_20 = require("../codec/headersync/query");
26
- const query_21 = require("../codec/ibc/applications/interchain_accounts/controller/v1/query");
27
- const query_22 = require("../codec/ibc/applications/interchain_accounts/host/v1/query");
28
- const query_23 = require("../codec/ibc/applications/transfer/v1/query");
29
- const query_24 = require("../codec/ibc/core/client/v1/query");
30
- const query_25 = require("../codec/ibc/core/connection/v1/query");
31
- const query_26 = require("../codec/ibc/core/channel/v1/query");
32
- const query_27 = require("../codec/inflation/query");
33
- const query_28 = require("../codec/insurance/query");
34
- const query_29 = require("../codec/leverage/query");
35
- const query_30 = require("../codec/liquidation/query");
36
- const query_31 = require("../codec/liquiditypool/query");
37
- const query_32 = require("../codec/market/query");
38
- const query_33 = require("../codec/marketstats/query");
39
- const query_34 = require("../codec/misc/query");
40
- const query_35 = require("../codec/oracle/query");
41
- const query_36 = require("../codec/order/query");
42
- const query_37 = require("../codec/position/query");
43
- const query_38 = require("../codec/pricing/query");
44
- const query_39 = require("../codec/profile/query");
45
- const query_40 = require("../codec/subaccount/query");
23
+ const query_18 = require("../codec/evmmerge/query");
24
+ const query_19 = require("../codec/evmbank/query");
25
+ const query_20 = require("../codec/ethermint/feemarket/v1/query");
26
+ const query_21 = require("../codec/fee/query");
27
+ const query_22 = require("../codec/headersync/query");
28
+ const query_23 = require("../codec/ibc/applications/interchain_accounts/controller/v1/query");
29
+ const query_24 = require("../codec/ibc/applications/interchain_accounts/host/v1/query");
30
+ const query_25 = require("../codec/ibc/applications/transfer/v1/query");
31
+ const query_26 = require("../codec/ibc/core/client/v1/query");
32
+ const query_27 = require("../codec/ibc/core/connection/v1/query");
33
+ const query_28 = require("../codec/ibc/core/channel/v1/query");
34
+ const query_29 = require("../codec/inflation/query");
35
+ const query_30 = require("../codec/insurance/query");
36
+ const query_31 = require("../codec/leverage/query");
37
+ const query_32 = require("../codec/liquidation/query");
38
+ const query_33 = require("../codec/liquiditypool/query");
39
+ const query_34 = require("../codec/market/query");
40
+ const query_35 = require("../codec/marketstats/query");
41
+ const query_36 = require("../codec/misc/query");
42
+ const query_37 = require("../codec/oracle/query");
43
+ const query_38 = require("../codec/order/query");
44
+ const query_39 = require("../codec/position/query");
45
+ const query_40 = require("../codec/pricing/query");
46
+ const query_41 = require("../codec/profile/query");
47
+ const query_42 = require("../codec/subaccount/query");
46
48
  const stargate_1 = require("@cosmjs/stargate");
47
49
  const BlockchainClient_1 = __importDefault(require("./BlockchainClient"));
48
50
  class CarbonQueryClient {
@@ -56,22 +58,24 @@ class CarbonQueryClient {
56
58
  this.broker = new query_3.QueryClientImpl(rpcClient);
57
59
  this.coin = new query_5.QueryClientImpl(rpcClient);
58
60
  this.cdp = new query_4.QueryClientImpl(rpcClient);
59
- this.fee = new query_19.QueryClientImpl(rpcClient);
60
- this.inflation = new query_27.QueryClientImpl(rpcClient);
61
- this.insurance = new query_28.QueryClientImpl(rpcClient);
62
- this.leverage = new query_29.QueryClientImpl(rpcClient);
63
- this.liquidation = new query_30.QueryClientImpl(rpcClient);
64
- this.liquiditypool = new query_31.QueryClientImpl(rpcClient);
65
- this.market = new query_32.QueryClientImpl(rpcClient);
66
- this.marketstats = new query_33.QueryClientImpl(rpcClient);
67
- this.misc = new query_34.QueryClientImpl(rpcClient);
68
- this.oracle = new query_35.QueryClientImpl(rpcClient);
69
- this.order = new query_36.QueryClientImpl(rpcClient);
70
- this.position = new query_37.QueryClientImpl(rpcClient);
71
- this.pricing = new query_38.QueryClientImpl(rpcClient);
72
- this.profile = new query_39.QueryClientImpl(rpcClient);
73
- this.subaccount = new query_40.QueryClientImpl(rpcClient);
74
- this.headersync = new query_20.QueryClientImpl(rpcClient);
61
+ this.fee = new query_21.QueryClientImpl(rpcClient);
62
+ this.inflation = new query_29.QueryClientImpl(rpcClient);
63
+ this.insurance = new query_30.QueryClientImpl(rpcClient);
64
+ this.leverage = new query_31.QueryClientImpl(rpcClient);
65
+ this.liquidation = new query_32.QueryClientImpl(rpcClient);
66
+ this.liquiditypool = new query_33.QueryClientImpl(rpcClient);
67
+ this.market = new query_34.QueryClientImpl(rpcClient);
68
+ this.marketstats = new query_35.QueryClientImpl(rpcClient);
69
+ this.misc = new query_36.QueryClientImpl(rpcClient);
70
+ this.oracle = new query_37.QueryClientImpl(rpcClient);
71
+ this.order = new query_38.QueryClientImpl(rpcClient);
72
+ this.position = new query_39.QueryClientImpl(rpcClient);
73
+ this.pricing = new query_40.QueryClientImpl(rpcClient);
74
+ this.profile = new query_41.QueryClientImpl(rpcClient);
75
+ this.subaccount = new query_42.QueryClientImpl(rpcClient);
76
+ this.headersync = new query_22.QueryClientImpl(rpcClient);
77
+ this.evmmerge = new query_18.QueryClientImpl(rpcClient);
78
+ this.evmbank = new query_19.QueryClientImpl(rpcClient);
75
79
  this.auth = new query_6.QueryClientImpl(rpcClient);
76
80
  this.bank = new query_7.QueryClientImpl(rpcClient);
77
81
  this.distribution = new query_9.QueryClientImpl(rpcClient);
@@ -84,16 +88,16 @@ class CarbonQueryClient {
84
88
  this.upgrade = new query_16.QueryClientImpl(rpcClient);
85
89
  this.cosmosTm = new query_8.ServiceClientImpl(rpcClient);
86
90
  this.ibc = {
87
- controller: new query_21.QueryClientImpl(rpcClient),
88
- host: new query_22.QueryClientImpl(rpcClient),
89
- transfer: new query_23.QueryClientImpl(rpcClient),
90
- client: new query_24.QueryClientImpl(rpcClient),
91
- connection: new query_25.QueryClientImpl(rpcClient),
92
- channel: new query_26.QueryClientImpl(rpcClient),
91
+ controller: new query_23.QueryClientImpl(rpcClient),
92
+ host: new query_24.QueryClientImpl(rpcClient),
93
+ transfer: new query_25.QueryClientImpl(rpcClient),
94
+ client: new query_26.QueryClientImpl(rpcClient),
95
+ connection: new query_27.QueryClientImpl(rpcClient),
96
+ channel: new query_28.QueryClientImpl(rpcClient),
93
97
  };
94
98
  this.ethermint = {
95
99
  evm: new query_17.QueryClientImpl(rpcClient),
96
- feeMarket: new query_18.QueryClientImpl(rpcClient),
100
+ feeMarket: new query_20.QueryClientImpl(rpcClient),
97
101
  };
98
102
  }
99
103
  getProtobufRpcClient() {
@@ -127,7 +127,7 @@ exports.NetworkConfigs = {
127
127
  byteCodeHash: "0xeb1f732f12a0448d8692018a6d6d381cc7afc84d7e0729007931d966c0c9dc6d",
128
128
  },
129
129
  bsc: {
130
- rpcURL: "https://data-seed-prebsc-2-s3.binance.org:8545/",
130
+ rpcURL: "https://data-seed-prebsc-1-s2.binance.org:8545/",
131
131
  wsURL: "",
132
132
  payerURL: `https://test-payer.carbon.network`,
133
133
  bridgeEntranceAddr: "",
@@ -195,7 +195,7 @@ exports.NetworkConfigs = {
195
195
  feeURL: `https://dev-fees.carbon.network`,
196
196
  feeAddress: "989761fb0c0eb0c05605e849cae77d239f98ac7f",
197
197
  eth: {
198
- rpcURL: "https://eth-rinkeby.alchemyapi.io/v2/2KD9F3mFPNMfflSqZsPuTKmK_w7fFfut",
198
+ rpcURL: "https://eth-goerli.g.alchemy.com/v2/OTTRiEhTje49mmrrm4WbuPbZmuZMivEu",
199
199
  wsURL: "",
200
200
  payerURL: `https://dev-payer.carbon.network`,
201
201
  lockProxyAddr: "0x7f7317167e90afa38972e46b031bb4da0b1f6f73",
@@ -204,7 +204,7 @@ exports.NetworkConfigs = {
204
204
  byteCodeHash: "0xeb1f732f12a0448d8692018a6d6d381cc7afc84d7e0729007931d966c0c9dc6d",
205
205
  },
206
206
  bsc: {
207
- rpcURL: "https://data-seed-prebsc-2-s3.binance.org:8545/",
207
+ rpcURL: "https://data-seed-prebsc-1-s2.binance.org:8545/",
208
208
  wsURL: "",
209
209
  payerURL: `https://dev-payer.carbon.network`,
210
210
  bridgeEntranceAddr: "",
@@ -272,7 +272,7 @@ exports.NetworkConfigs = {
272
272
  feeURL: `http://localhost:9001`,
273
273
  feeAddress: "989761fb0c0eb0c05605e849cae77d239f98ac7f",
274
274
  eth: {
275
- rpcURL: "https://ropsten.infura.io/v3/e4dd457b33124bbda7e17500e6efbc27",
275
+ rpcURL: "https://eth-goerli.g.alchemy.com/v2/OTTRiEhTje49mmrrm4WbuPbZmuZMivEu",
276
276
  wsURL: "wss://ropsten.dagger.matic.network",
277
277
  payerURL: `http://localhost:8001`,
278
278
  bridgeEntranceAddr: "",
@@ -281,7 +281,7 @@ exports.NetworkConfigs = {
281
281
  byteCodeHash: "",
282
282
  },
283
283
  bsc: {
284
- rpcURL: "https://data-seed-prebsc-2-s3.binance.org:8545/",
284
+ rpcURL: "https://data-seed-prebsc-1-s2.binance.org:8545/",
285
285
  wsURL: "",
286
286
  payerURL: `http://localhost:8001`,
287
287
  bridgeEntranceAddr: "",
@@ -6,4 +6,3 @@ export declare enum ProviderAgent {
6
6
  MetamaskExtension = "metamask-extension",
7
7
  Metamask = "metamask"
8
8
  }
9
- export declare function isEvmWallet(providerAgent?: string): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEvmWallet = exports.ProviderAgent = void 0;
3
+ exports.ProviderAgent = void 0;
4
4
  var ProviderAgent;
5
5
  (function (ProviderAgent) {
6
6
  ProviderAgent["Ledger"] = "ledger";
@@ -11,7 +11,3 @@ var ProviderAgent;
11
11
  // For legacy metamask
12
12
  ProviderAgent["Metamask"] = "metamask";
13
13
  })(ProviderAgent = exports.ProviderAgent || (exports.ProviderAgent = {}));
14
- function isEvmWallet(providerAgent) {
15
- return ProviderAgent.MetamaskExtension.toString() === providerAgent;
16
- }
17
- exports.isEvmWallet = isEvmWallet;
@@ -38,6 +38,10 @@ export interface MetaMaskSyncResult {
38
38
  blockchain?: Blockchain | BlockchainV2;
39
39
  chainId?: number;
40
40
  }
41
+ export interface StoredMnemonicInfo {
42
+ chain: EVMChainV2;
43
+ mnemonics: string;
44
+ }
41
45
  /**
42
46
  * TODO: Add docs
43
47
  */
@@ -45,10 +49,11 @@ export declare class MetaMask {
45
49
  readonly network: Network;
46
50
  readonly legacyEip712SignMode: boolean;
47
51
  private blockchain;
52
+ private legacyEncryptedLogin;
48
53
  static createMetamaskSigner(metamask: MetaMask, evmChainId: string, pubKeyBase64: string, addressOptions: SWTHAddressOptions): CarbonSigner;
49
54
  static getNetworkParams(network: Network, blockchain?: EVMChain): MetaMaskChangeNetworkParam;
50
55
  static getCarbonEvmNetworkParams(network: Network): MetaMaskChangeNetworkParam;
51
- static getRequiredChainId(network: Network, blockchain?: BlockchainV2): number;
56
+ static getRequiredChainId(network: Network, blockchain?: BlockchainV2): 1 | 5 | 66 | 56 | 137 | 42161 | 97 | 65 | 80001 | 421611;
52
57
  constructor(network: Network, legacyEip712SignMode?: boolean);
53
58
  private checkProvider;
54
59
  getBlockchain(): BlockchainV2;
@@ -58,6 +63,8 @@ export declare class MetaMask {
58
63
  getConnectedAPI(): Promise<MetaMaskAPI>;
59
64
  connect(): Promise<MetaMaskAPI>;
60
65
  defaultAccount(): Promise<string>;
66
+ getEncryptedLegacyAccount(connectedBlockchain?: EVMChainV2): Promise<StoredMnemonicInfo | undefined>;
67
+ getMnemonicInfo(connectedBlockchain: EVMChainV2): Promise<StoredMnemonicInfo | undefined>;
61
68
  getStoredMnemonicCipher(account: string, blockchain?: EVMChain): Promise<string | undefined>;
62
69
  encryptMnemonic(mnemonic: string): Promise<string>;
63
70
  signPublicKeyMergeAccount(publicKey: string, address: string, metamaskAPI?: MetaMaskAPI): Promise<string>;
@@ -70,5 +77,6 @@ export declare class MetaMask {
70
77
  login(blockchain?: EVMChain): Promise<string | null>;
71
78
  private getRequiredChain;
72
79
  private getContractHash;
80
+ isLegacyEncryptedLogin(): boolean;
73
81
  }
74
82
  export {};
@@ -86,7 +86,7 @@ const CONTRACT_HASH = {
86
86
  [constant_1.Network.MainNet]: "0x7e8D8c98a016877Cb3103e837Fc71D41b155aF70",
87
87
  },
88
88
  Carbon: {
89
- //Carbon does not support Metamask legacy mnemonic sign in
89
+ //Carbon does not support Metamask legacy mnemonic sign in
90
90
  [constant_1.Network.TestNet]: "",
91
91
  [constant_1.Network.DevNet]: "",
92
92
  [constant_1.Network.LocalHost]: "",
@@ -264,6 +264,7 @@ class MetaMask {
264
264
  this.network = network;
265
265
  this.legacyEip712SignMode = legacyEip712SignMode;
266
266
  this.blockchain = 'Ethereum';
267
+ this.legacyEncryptedLogin = false;
267
268
  }
268
269
  static createMetamaskSigner(metamask, evmChainId, pubKeyBase64, addressOptions) {
269
270
  const signDirect = (_, doc) => __awaiter(this, void 0, void 0, function* () {
@@ -403,9 +404,6 @@ class MetaMask {
403
404
  }
404
405
  }
405
406
  static getRequiredChainId(network, blockchain = 'Ethereum') {
406
- if (blockchain === 'Carbon') {
407
- return Number(ethermint_1.parseChainId(constant_1.CarbonEvmChainIDs[network]));
408
- }
409
407
  if (network === constant_1.Network.MainNet) {
410
408
  switch (blockchain) {
411
409
  case 'Binance Smart Chain':
@@ -494,6 +492,43 @@ class MetaMask {
494
492
  return defaultAccount;
495
493
  });
496
494
  }
495
+ getEncryptedLegacyAccount(connectedBlockchain) {
496
+ return __awaiter(this, void 0, void 0, function* () {
497
+ if (connectedBlockchain && connectedBlockchain !== 'Carbon') {
498
+ const mnemonicInfo = yield this.getMnemonicInfo(connectedBlockchain);
499
+ if (mnemonicInfo) {
500
+ return mnemonicInfo;
501
+ }
502
+ }
503
+ const chainMnemonicSearch = blockchain_1.EvmChains.map((blockchain) => __awaiter(this, void 0, void 0, function* () {
504
+ if (blockchain !== 'Carbon' && CONTRACT_HASH[blockchain][this.network]) {
505
+ return yield this.getMnemonicInfo(blockchain);
506
+ }
507
+ }));
508
+ const results = yield Promise.all(chainMnemonicSearch);
509
+ return results.find(result => !result);
510
+ });
511
+ }
512
+ getMnemonicInfo(connectedBlockchain) {
513
+ return __awaiter(this, void 0, void 0, function* () {
514
+ const defaultAccount = yield this.defaultAccount();
515
+ let result;
516
+ if (connectedBlockchain !== 'Carbon' && connectedBlockchain) {
517
+ yield this.getStoredMnemonicCipher(defaultAccount, connectedBlockchain).then(mnemonics => {
518
+ if (mnemonics) {
519
+ result = {
520
+ chain: connectedBlockchain,
521
+ mnemonics
522
+ };
523
+ }
524
+ }).catch(err => {
525
+ console.error('Unable to retrieve stored mnemonic cipher from ', connectedBlockchain);
526
+ console.error(err);
527
+ }).finally(() => { return result; });
528
+ }
529
+ return result;
530
+ });
531
+ }
497
532
  getStoredMnemonicCipher(account, blockchain) {
498
533
  return __awaiter(this, void 0, void 0, function* () {
499
534
  const contractHash = this.getContractHash(blockchain);
@@ -661,6 +696,7 @@ class MetaMask {
661
696
  console.error(decryptedCipherText);
662
697
  throw new Error("Retrieved invalid account on blockchain, please check console for more information.");
663
698
  }
699
+ this.legacyEncryptedLogin = true;
664
700
  return (_b = match[1]) === null || _b === void 0 ? void 0 : _b.trim();
665
701
  });
666
702
  }
@@ -722,5 +758,8 @@ class MetaMask {
722
758
  }
723
759
  return contractHash;
724
760
  }
761
+ isLegacyEncryptedLogin() {
762
+ return this.legacyEncryptedLogin;
763
+ }
725
764
  }
726
765
  exports.MetaMask = MetaMask;
@@ -86,7 +86,6 @@ export declare const getBlockchainFromChain: (chainId?: number | undefined) => B
86
86
  export declare const blockchainForChainId: (chainId?: number | undefined, network?: Network) => Blockchain | undefined;
87
87
  export declare const getBlockchainFromChainV2: (chainId?: number | undefined) => "Carbon" | "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "Okc" | "Zilliqa" | undefined;
88
88
  export declare const blockchainForChainIdV2: (chainId?: number | undefined, network?: Network) => Blockchain | BlockchainV2 | undefined;
89
- declare const evmChains: readonly ["Ethereum", "Binance Smart Chain", "Arbitrum", "Polygon", "OKC", "Carbon"];
90
- export declare type EVMChain = (typeof evmChains)[number];
89
+ export declare const EvmChains: readonly ["Ethereum", "Binance Smart Chain", "Arbitrum", "Polygon", "OKC", "Carbon"];
90
+ export declare type EVMChain = (typeof EvmChains)[number];
91
91
  export declare const isEvmChain: (chain: string) => chain is "Carbon" | "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "OKC";
92
- export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEvmChain = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = void 0;
3
+ exports.isEvmChain = exports.EvmChains = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = void 0;
4
4
  const network_1 = require("../constant/network");
5
5
  const ethermint_1 = require("./ethermint");
6
6
  var Blockchain;
@@ -422,6 +422,6 @@ const blockchainForChainIdV2 = (chainId, network = network_1.Network.MainNet) =>
422
422
  }
423
423
  };
424
424
  exports.blockchainForChainIdV2 = blockchainForChainIdV2;
425
- const evmChains = ['Ethereum', 'Binance Smart Chain', 'Arbitrum', 'Polygon', 'OKC', 'Carbon'];
426
- const isEvmChain = (chain) => evmChains.includes(chain);
425
+ exports.EvmChains = ['Ethereum', 'Binance Smart Chain', 'Arbitrum', 'Polygon', 'OKC', 'Carbon'];
426
+ const isEvmChain = (chain) => exports.EvmChains.includes(chain);
427
427
  exports.isEvmChain = isEvmChain;
package/lib/util/tx.d.ts CHANGED
@@ -25,6 +25,7 @@ export interface SignTxOpts {
25
25
  feeDenom?: string;
26
26
  memo?: string;
27
27
  sequence?: number;
28
+ accountNumber?: number;
28
29
  explicitSignerData?: Partial<CarbonSignerData>;
29
30
  }
30
31
  export interface BroadcastTxOpts {
@@ -80,6 +80,7 @@ export declare class CarbonWallet {
80
80
  evmBech32Address: string;
81
81
  hexAddress: string;
82
82
  evmHexAddress: string;
83
+ accountMerged: boolean;
83
84
  publicKey: Buffer;
84
85
  query?: CarbonQueryClient;
85
86
  /**
@@ -127,6 +128,7 @@ export declare class CarbonWallet {
127
128
  private signTx;
128
129
  private dispatchTx;
129
130
  sendTxs(msgs: EncodeObject[], opts?: CarbonTx.SignTxOpts): Promise<CarbonWallet.SendTxResponse>;
131
+ sendInitialMergeAccountTx(opts?: CarbonTx.SignTxOpts): Promise<void>;
130
132
  sendTxsWithoutConfirm(msgs: EncodeObject[], opts?: CarbonTx.SignTxOpts): Promise<CarbonWallet.SendTxWithoutConfirmResponse>;
131
133
  sendTx(msg: EncodeObject, opts?: CarbonTx.SignTxOpts): Promise<CarbonWallet.SendTxResponse>;
132
134
  getSigningClient(): CarbonSigningClient;
@@ -142,10 +144,12 @@ export declare class CarbonWallet {
142
144
  getFee(msgTypeUrl: string, denom?: string): BigNumber;
143
145
  reconnectTmClient(): Promise<void>;
144
146
  reloadTxFees(): Promise<void>;
147
+ private reloadAccountInfo;
148
+ private getAccount;
145
149
  reloadAccountSequence(): Promise<void>;
150
+ reloadMergeAccountStatus(): Promise<void>;
146
151
  private estimateTxFee;
147
- private isNewAccountError;
148
- private EthPublicKeyError;
152
+ private isAccountNotFoundError;
149
153
  private isNonceMismatchError;
150
154
  private getQueryClient;
151
155
  }
@@ -28,19 +28,17 @@ const CarbonSigningClient_1 = require("./CarbonSigningClient");
28
28
  const ethermint_1 = require("../util/ethermint");
29
29
  const web3_1 = require("../codec/ethermint/types/v1/web3");
30
30
  const auth_1 = require("../codec/cosmos/auth/v1beta1/auth");
31
+ const codec_1 = require("../codec");
31
32
  class CarbonWallet {
32
33
  constructor(opts) {
33
34
  var _a, _b, _c, _d;
35
+ this.accountMerged = false;
34
36
  this.defaultFeeDenom = constant_1.DEFAULT_FEE_DENOM;
35
37
  this.initialized = false;
36
38
  this.sequenceInvalidated = false;
37
- this.isNewAccountError = (error) => {
39
+ this.isAccountNotFoundError = (error, address) => {
38
40
  var _a;
39
- return (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes("Account does not exist on chain. Send some tokens there before trying to query sequence.");
40
- };
41
- this.EthPublicKeyError = (error) => {
42
- var _a;
43
- return (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes("Pubkey type_url /ethermint.crypto.v1.ethsecp256k1.PubKey not recognized");
41
+ return (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(`account ${address} not found: key not found`);
44
42
  };
45
43
  this.isNonceMismatchError = (error) => {
46
44
  const regex = /^Broadcasting transaction failed with code 32 \(codespace: sdk\)\. Log: account sequence mismatch, expected (\d+), got (\d+): incorrect account sequence/;
@@ -142,7 +140,7 @@ class CarbonWallet {
142
140
  initialize(queryClient) {
143
141
  return __awaiter(this, void 0, void 0, function* () {
144
142
  this.query = queryClient;
145
- yield Promise.all([this.reconnectTmClient(), this.reloadTxFees(), this.reloadAccountSequence()]);
143
+ yield Promise.all([this.reconnectTmClient(), this.reloadTxFees(), this.reloadAccountSequence(), this.reloadMergeAccountStatus()]);
146
144
  this.initialized = true;
147
145
  return this;
148
146
  });
@@ -156,14 +154,14 @@ class CarbonWallet {
156
154
  getSignedTx(signerAddress, messages, sequence, opts) {
157
155
  var _a;
158
156
  return __awaiter(this, void 0, void 0, function* () {
159
- const { memo = "", explicitSignerData, feeDenom } = opts;
157
+ const { memo = "", accountNumber, explicitSignerData, feeDenom } = opts;
160
158
  const signingClient = this.getSigningClient();
161
159
  const [account] = yield this.signer.getAccounts();
162
160
  let signature = null;
163
161
  const evmChainId = this.evmChainId;
164
162
  try {
165
163
  yield util_1.GenericUtils.callIgnoreError(() => { var _a; return (_a = this.onRequestSign) === null || _a === void 0 ? void 0 : _a.call(this, messages); });
166
- const signerData = Object.assign(Object.assign({ accountNumber: this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData), { evmChainId });
164
+ const signerData = Object.assign(Object.assign({ accountNumber: accountNumber !== null && accountNumber !== void 0 ? accountNumber : this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData), { evmChainId });
167
165
  const fee = (_a = opts === null || opts === void 0 ? void 0 : opts.fee) !== null && _a !== void 0 ? _a : this.estimateTxFee(messages, feeDenom);
168
166
  const txRaw = yield signingClient.sign(signerAddress, messages, fee, memo, signerData);
169
167
  let sig;
@@ -230,7 +228,7 @@ class CarbonWallet {
230
228
  });
231
229
  }
232
230
  signTx(txRequest) {
233
- var _a;
231
+ var _a, _b;
234
232
  return __awaiter(this, void 0, void 0, function* () {
235
233
  const { reattempts, signerAddress, signOpts, messages, broadcastOpts, handler: { resolve, reject }, } = txRequest;
236
234
  try {
@@ -244,8 +242,14 @@ class CarbonWallet {
244
242
  if (!CarbonSigner_1.isCarbonEIP712Signer(this.signer)) {
245
243
  timeoutHeight = height.isZero() ? undefined : height.toNumber() + this.defaultTimeoutBlocks;
246
244
  }
247
- const sequence = this.accountInfo.sequence;
248
- this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
245
+ let sequence;
246
+ if (!this.accountInfo) {
247
+ sequence = (_b = signOpts === null || signOpts === void 0 ? void 0 : signOpts.sequence) !== null && _b !== void 0 ? _b : 0;
248
+ }
249
+ else {
250
+ sequence = this.accountInfo.sequence;
251
+ this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
252
+ }
249
253
  const _signOpts = Object.assign(Object.assign({}, signOpts), { explicitSignerData: Object.assign({ timeoutHeight }, signOpts === null || signOpts === void 0 ? void 0 : signOpts.explicitSignerData) });
250
254
  const signedTx = yield this.getSignedTx(signerAddress, messages, sequence, _signOpts);
251
255
  this.txDispatchManager.enqueue({
@@ -296,10 +300,39 @@ class CarbonWallet {
296
300
  }
297
301
  sendTxs(msgs, opts) {
298
302
  return __awaiter(this, void 0, void 0, function* () {
303
+ yield this.reloadMergeAccountStatus();
304
+ if (!this.accountMerged && msgs[0].typeUrl !== util_1.CarbonTx.Types.MsgMergeAccount) {
305
+ yield this.sendInitialMergeAccountTx(opts);
306
+ // refresh accountInfo after merging is done
307
+ yield this.reloadAccountSequence();
308
+ }
299
309
  const result = yield this.signAndBroadcast(msgs, opts, { mode: tx_1.BroadcastTxMode.BroadcastTxBlock });
310
+ yield this.reloadMergeAccountStatus();
300
311
  return result;
301
312
  });
302
313
  }
314
+ sendInitialMergeAccountTx(opts) {
315
+ return __awaiter(this, void 0, void 0, function* () {
316
+ try {
317
+ const account = yield this.getQueryClient().auth.Account({ address: this.bech32Address }).then(res => res.account).catch((err) => __awaiter(this, void 0, void 0, function* () {
318
+ return (yield this.getQueryClient().auth.Account({ address: this.evmBech32Address })).account;
319
+ }));
320
+ const { address, sequence, accountNumber } = auth_1.BaseAccount.decode(account.value);
321
+ const msg = {
322
+ typeUrl: util_1.CarbonTx.Types.MsgMergeAccount,
323
+ value: codec_1.MsgMergeAccount.fromPartial({
324
+ creator: address,
325
+ pubKey: this.publicKey.toString('hex')
326
+ })
327
+ };
328
+ const modifiedOpts = Object.assign(Object.assign({}, opts), { sequence: sequence.toNumber(), accountNumber: accountNumber.toNumber() });
329
+ yield this.signAndBroadcast([msg], modifiedOpts, { mode: tx_1.BroadcastTxMode.BroadcastTxBlock });
330
+ }
331
+ catch (error) {
332
+ throw error;
333
+ }
334
+ });
335
+ }
303
336
  sendTxsWithoutConfirm(msgs, opts) {
304
337
  return __awaiter(this, void 0, void 0, function* () {
305
338
  const result = yield this.signAndBroadcast(msgs, opts, { mode: tx_1.BroadcastTxMode.BroadcastTxSync });
@@ -399,42 +432,76 @@ class CarbonWallet {
399
432
  }
400
433
  });
401
434
  }
435
+ reloadAccountInfo() {
436
+ var _a;
437
+ return __awaiter(this, void 0, void 0, function* () {
438
+ try {
439
+ //carbon account always takes priority
440
+ const accountAny = (_a = yield this.getAccount(this.bech32Address)) !== null && _a !== void 0 ? _a : yield this.getAccount(this.evmBech32Address);
441
+ if (!accountAny)
442
+ return undefined;
443
+ const { accountNumber, sequence, address } = auth_1.BaseAccount.decode(accountAny.value);
444
+ return {
445
+ address,
446
+ accountNumber: accountNumber.toNumber(),
447
+ sequence: sequence.toNumber()
448
+ };
449
+ }
450
+ catch (error) {
451
+ throw error;
452
+ }
453
+ });
454
+ }
455
+ getAccount(address) {
456
+ return __awaiter(this, void 0, void 0, function* () {
457
+ let account;
458
+ try {
459
+ account = (yield this.getQueryClient().auth.Account({ address })).account;
460
+ }
461
+ catch (error) {
462
+ if (!this.isAccountNotFoundError(error, address))
463
+ throw error;
464
+ }
465
+ finally {
466
+ return account;
467
+ }
468
+ });
469
+ }
402
470
  reloadAccountSequence() {
403
471
  var _a, _b, _c, _d, _e;
404
472
  return __awaiter(this, void 0, void 0, function* () {
405
473
  if (this.sequenceInvalidated)
406
474
  this.sequenceInvalidated = false;
407
475
  try {
408
- const evmWallet = walletProvider_1.isEvmWallet(this.providerAgent);
409
- const address = evmWallet ? this.evmBech32Address : this.bech32Address;
410
- // Alternative way to get account info since cosmjs dont support eth pub key for now
411
- const info = yield this.getQueryClient().chain.getSequence(address).then(res => res).catch((err) => __awaiter(this, void 0, void 0, function* () {
412
- if (this.EthPublicKeyError(err)) {
413
- const accountAny = (yield this.getQueryClient().auth.Account({ address })).account;
414
- if (!accountAny) {
415
- throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
416
- }
417
- const { accountNumber, sequence } = auth_1.BaseAccount.decode(accountAny.value);
418
- const sequenceResponse = {
419
- accountNumber: accountNumber.toNumber(),
420
- sequence: sequence.toNumber()
421
- };
422
- return sequenceResponse;
423
- }
424
- throw err;
425
- }));
476
+ const info = yield this.reloadAccountInfo();
426
477
  const pubkey = (_b = (_a = this.accountInfo) === null || _a === void 0 ? void 0 : _a.pubkey) !== null && _b !== void 0 ? _b : {
427
478
  type: "tendermint/PubKeySecp256k1",
428
479
  value: this.publicKey.toString("base64"),
429
480
  };
430
481
  const chainId = (_e = (_d = (_c = this.accountInfo) === null || _c === void 0 ? void 0 : _c.chainId) !== null && _d !== void 0 ? _d : this.chainId) !== null && _e !== void 0 ? _e : (yield this.getQueryClient().chain.getChainId());
431
- this.accountInfo = Object.assign(Object.assign({}, info), { address,
432
- pubkey,
433
- chainId });
482
+ if (info) {
483
+ this.accountInfo = Object.assign(Object.assign({}, info), { pubkey,
484
+ chainId });
485
+ }
434
486
  }
435
487
  catch (error) {
436
- if (!this.isNewAccountError(error))
437
- throw error;
488
+ throw error;
489
+ }
490
+ });
491
+ }
492
+ reloadMergeAccountStatus() {
493
+ return __awaiter(this, void 0, void 0, function* () {
494
+ try {
495
+ if (this.accountMerged)
496
+ return;
497
+ const queryClient = this.getQueryClient();
498
+ const response = yield queryClient.evmmerge.MappedAddress({ address: this.bech32Address });
499
+ if (response && response.mappedAddress) {
500
+ this.accountMerged = true;
501
+ }
502
+ }
503
+ catch (error) {
504
+ throw error;
438
505
  }
439
506
  });
440
507
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.4.16-beta.1+d2658610",
3
+ "version": "0.4.16-beta.2+dc3aed17",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",