carbon-js-sdk 0.4.4 → 0.4.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.
Files changed (82) 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/InsightsQueryClient.d.ts +1 -0
  5. package/lib/clients/InsightsQueryClient.js +8 -0
  6. package/lib/clients/NEOClient.js +7 -7
  7. package/lib/clients/TokenClient.js +11 -3
  8. package/lib/clients/ZILClient.js +17 -17
  9. package/lib/codec/cdp/e_mode_category.d.ts +23 -0
  10. package/lib/codec/cdp/e_mode_category.js +135 -0
  11. package/lib/codec/cosmos/gov/v1/query.js +2 -2
  12. package/lib/codec/cosmos/gov/v1/tx.js +2 -2
  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/group/v1/events.js +2 -2
  16. package/lib/codec/cosmos/group/v1/tx.js +4 -4
  17. package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
  18. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.d.ts +1 -0
  19. package/lib/codec/ethermint/crypto/v1/ethsecp256k1/export.js +6 -0
  20. package/lib/codec/ethermint/evm/v1/export.d.ts +5 -0
  21. package/lib/codec/ethermint/evm/v1/export.js +53 -0
  22. package/lib/codec/ethermint/feemarket/v1/export.d.ts +4 -0
  23. package/lib/codec/ethermint/feemarket/v1/export.js +18 -0
  24. package/lib/codec/ethermint/types/v1/export.d.ts +4 -0
  25. package/lib/codec/ethermint/types/v1/export.js +11 -0
  26. package/lib/codec/ethermint-models.d.ts +4 -0
  27. package/lib/codec/ethermint-models.js +26 -0
  28. package/lib/constant/eip712.d.ts +28 -0
  29. package/lib/constant/eip712.js +40 -0
  30. package/lib/constant/generic.js +1 -1
  31. package/lib/insights/common.d.ts +1 -0
  32. package/lib/insights/common.js +1 -0
  33. package/lib/insights/competition.d.ts +20 -0
  34. package/lib/modules/cdp.js +43 -43
  35. package/lib/modules/cosmwasm.js +1 -1
  36. package/lib/modules/evm.d.ts +46 -0
  37. package/lib/modules/evm.js +127 -0
  38. package/lib/modules/evmmerge.d.ts +12 -0
  39. package/lib/modules/evmmerge.js +35 -0
  40. package/lib/modules/feemarket.d.ts +20 -0
  41. package/lib/modules/feemarket.js +45 -0
  42. package/lib/modules/gov.js +12 -12
  43. package/lib/modules/liquiditypool.js +1 -1
  44. package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
  45. package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
  46. package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
  47. package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
  48. package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
  49. package/lib/provider/amino/types/admin.js +27 -27
  50. package/lib/provider/amino/types/bank.js +1 -1
  51. package/lib/provider/amino/types/broker.js +1 -1
  52. package/lib/provider/amino/types/cdp.js +22 -22
  53. package/lib/provider/amino/types/coin.js +4 -4
  54. package/lib/provider/amino/types/gov.js +4 -4
  55. package/lib/provider/amino/types/ibc.js +1 -1
  56. package/lib/provider/amino/types/leverage.js +1 -1
  57. package/lib/provider/amino/types/liquidityPool.js +7 -7
  58. package/lib/provider/amino/types/market.js +1 -1
  59. package/lib/provider/amino/types/oracle.js +1 -1
  60. package/lib/provider/amino/types/order.js +4 -4
  61. package/lib/provider/amino/types/position.js +1 -1
  62. package/lib/provider/amino/types/profile.js +1 -1
  63. package/lib/provider/amino/types/staking.js +4 -4
  64. package/lib/provider/amino/types/subaccount.js +3 -3
  65. package/lib/provider/amino/utils.js +11 -11
  66. package/lib/provider/ledger/ledger.js +2 -2
  67. package/lib/provider/metamask/MetaMask.js +1 -1
  68. package/lib/provider/o3/O3Wallet.js +2 -2
  69. package/lib/util/address.js +13 -13
  70. package/lib/util/api.js +4 -4
  71. package/lib/util/eip712.d.ts +10 -0
  72. package/lib/util/eip712.js +46 -0
  73. package/lib/util/ethermint.d.ts +4 -0
  74. package/lib/util/ethermint.js +26 -0
  75. package/lib/util/fetch.js +1 -1
  76. package/lib/util/generic.js +3 -3
  77. package/lib/util/number.js +5 -5
  78. package/lib/wallet/CarbonSigner.js +2 -2
  79. package/lib/wallet/CarbonSigningClient.js +8 -8
  80. package/lib/wallet/CarbonWallet.js +6 -6
  81. package/lib/websocket/connector.js +3 -3
  82. package/package.json +1 -1
@@ -47,7 +47,7 @@ class CarbonQueryClient {
47
47
  constructor(tmClient) {
48
48
  this.tmClient = tmClient;
49
49
  this.baseClient = new stargate_1.QueryClient(this.tmClient);
50
- const rpcClient = (0, stargate_1.createProtobufRpcClient)(this.baseClient);
50
+ const rpcClient = stargate_1.createProtobufRpcClient(this.baseClient);
51
51
  this.chain = BlockchainClient_1.default.connectWithTm(this.tmClient);
52
52
  this.adl = new query_1.QueryClientImpl(rpcClient);
53
53
  this.book = new query_2.QueryClientImpl(rpcClient);
@@ -91,7 +91,7 @@ class CarbonQueryClient {
91
91
  };
92
92
  }
93
93
  getProtobufRpcClient() {
94
- return (0, stargate_1.createProtobufRpcClient)(this.baseClient);
94
+ return stargate_1.createProtobufRpcClient(this.baseClient);
95
95
  }
96
96
  }
97
97
  exports.default = CarbonQueryClient;
@@ -39,13 +39,13 @@ class ETHClient {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  const tokenQueryResults = yield api.token.getAllTokens();
41
41
  const lockProxyAddress = this.getLockProxyAddress().toLowerCase();
42
- const tokens = tokenQueryResults.filter((token) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), api.network) == this.blockchain &&
42
+ const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), api.network) == this.blockchain &&
43
43
  token.tokenAddress.length == 40 &&
44
- token.bridgeAddress.toLowerCase() == (0, generic_1.stripHexPrefix)(lockProxyAddress) &&
44
+ token.bridgeAddress.toLowerCase() == generic_1.stripHexPrefix(lockProxyAddress) &&
45
45
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)) &&
46
- this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress)));
46
+ this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress)));
47
47
  const assetIds = tokens.map((token) => {
48
- return this.verifyChecksum((0, generic_1.appendHexPrefix)(token.tokenAddress));
48
+ return this.verifyChecksum(generic_1.appendHexPrefix(token.tokenAddress));
49
49
  });
50
50
  const provider = this.getProvider();
51
51
  const contractAddress = this.getBalanceReaderAddress();
@@ -96,14 +96,14 @@ class ETHClient {
96
96
  }
97
97
  const carbonNetwork = networkConfig.network;
98
98
  const fromTokenId = fromToken.id;
99
- const fromTokenAddress = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
99
+ const fromTokenAddress = generic_1.appendHexPrefix(fromToken.tokenAddress);
100
100
  const toTokenDenom = toToken.denom;
101
101
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(util_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
102
102
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
103
103
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
104
104
  const nonce = yield rpcProvider.getTransactionCount(fromAddress);
105
105
  const contract = new ethers_1.ethers.Contract(this.getBridgeEntranceAddr(), eth_1.ABIs.bridgeEntrance, rpcProvider);
106
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
106
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
107
107
  const tokenCreator = fromToken.creator;
108
108
  const targetAddressBytes = util_1.AddressUtils.SWTHAddress.getAddressBytes(tokenCreator, carbonNetwork);
109
109
  const targetProxyHash = ethers_1.ethers.utils.hexlify(targetAddressBytes);
@@ -138,9 +138,9 @@ class ETHClient {
138
138
  throw new Error("Minimum gas required: 150,000");
139
139
  }
140
140
  const networkConfig = this.getNetworkConfig();
141
- const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
142
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
143
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
141
+ const assetId = generic_1.appendHexPrefix(token.tokenAddress);
142
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
143
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
144
144
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
145
145
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
146
146
  const contractAddress = this.getLockProxyAddress();
@@ -191,16 +191,16 @@ class ETHClient {
191
191
  return "insufficient balance";
192
192
  }
193
193
  const networkConfig = this.getNetworkConfig();
194
- const assetId = (0, generic_1.appendHexPrefix)(tokenWithExternalBalances.tokenAddress);
195
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(tokenWithExternalBalances));
196
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
194
+ const assetId = generic_1.appendHexPrefix(tokenWithExternalBalances.tokenAddress);
195
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(tokenWithExternalBalances));
196
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
197
197
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(tokenWithExternalBalances.id));
198
198
  const nonce = Math.floor(Math.random() * 1000000000); // random nonce to prevent replay attacks
199
199
  const message = ethers_1.ethers.utils.solidityKeccak256(["string", "address", "bytes", "bytes", "bytes", "uint256", "uint256", "uint256"], ["sendTokens", assetId, targetProxyHash, toAssetHash, feeAddress, amount, feeAmount, nonce]);
200
200
  // logger("sendDeposit message", message)
201
201
  let signatureResult;
202
202
  const { address, signature } = yield getSignatureCallback(message);
203
- const signatureBytes = ethers_1.ethers.utils.arrayify((0, generic_1.appendHexPrefix)(signature));
203
+ const signatureBytes = ethers_1.ethers.utils.arrayify(generic_1.appendHexPrefix(signature));
204
204
  const rsv = ethers_1.ethers.utils.splitSignature(signatureBytes);
205
205
  // logger("sign result", address, signature)
206
206
  signatureResult = {
@@ -239,7 +239,7 @@ class ETHClient {
239
239
  if (!feeInfo.deposit_fee) {
240
240
  throw new Error("unsupported token");
241
241
  }
242
- if ((0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
242
+ if (blockchain_1.blockchainForChainId(token.chainId.toNumber(), this.configProvider.getConfig().network) !== this.blockchain) {
243
243
  throw new Error("unsupported token");
244
244
  }
245
245
  let feeAmount = ethers_1.ethers.BigNumber.from(feeInfo.deposit_fee);
@@ -305,7 +305,7 @@ class ETHClient {
305
305
  getTargetProxyHash(token) {
306
306
  const networkConfig = this.getNetworkConfig();
307
307
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
308
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
308
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
309
309
  return addressHex;
310
310
  }
311
311
  getProvider() {
@@ -29,7 +29,7 @@ exports.HydrogenEndpoints = {
29
29
  const formatDateField = (value) => {
30
30
  if (typeof value !== "string")
31
31
  return null;
32
- return (0, dayjs_1.default)(value);
32
+ return dayjs_1.default(value);
33
33
  };
34
34
  // temporary function to parse okt/okc blockchain
35
35
  // to remove when automatic deposit/withdraw feature is deployed
@@ -19,6 +19,7 @@ declare class InsightsQueryClient {
19
19
  CompetitionList(req?: Insights.QueryGetCompetitionListRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetCompetitionListResponse>>;
20
20
  VolumeCompetitionLeaderboard(req: Insights.QueryGetVolumeCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetVolumeCompetitionLeaderboardResponse>>;
21
21
  PNLCompetitionLeaderboard(req: Insights.QueryGetPNLCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPNLCompetitionLeaderboardResponse>>;
22
+ LotteryCompetitionLeaderboard(req: Insights.QueryGetLotteryCompetitionLeaderboardRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetLotteryCompetitionLeaderboardResponse>>;
22
23
  PoolsLiquidity(req?: Insights.QueryGetPoolsLiquidityRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolsLiquidityResponse>>;
23
24
  MarketsVolume(req?: Insights.QueryGetMarketVolumeRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetMarketVolumeResponse>>;
24
25
  Nodes(req?: Insights.QueryGetNodesRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetNodesResponse>>;
@@ -158,6 +158,14 @@ class InsightsQueryClient {
158
158
  return response.data;
159
159
  });
160
160
  }
161
+ LotteryCompetitionLeaderboard(req) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const queryParams = Object.assign({ competitionId: req.competitionId }, (req.market && { market: req.market }));
164
+ const request = this.apiManager.path("competition/leaderboardlottery", {}, queryParams);
165
+ const response = yield request.get();
166
+ return response.data;
167
+ });
168
+ }
161
169
  PoolsLiquidity(req = {}) {
162
170
  return __awaiter(this, void 0, void 0, function* () {
163
171
  const queryParams = {
@@ -64,13 +64,13 @@ class NEOClient {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  const tokenQueryResults = yield sdk.token.getAllTokens();
66
66
  const account = new Neon.wallet.Account(address);
67
- const tokens = tokenQueryResults.filter((token) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), sdk.network) == this.blockchain &&
67
+ const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain &&
68
68
  token.tokenAddress.length == 40 &&
69
69
  token.bridgeAddress.length == 40);
70
70
  const client = new Neon.rpc.RPCClient(url, "2.5.2"); // TODO: should we change the RPC version??
71
71
  // NOTE: fetching of tokens is chunked in sets of 15 as we may hit
72
72
  // the gas limit on the RPC node and error out otherwise
73
- const promises = (0, lodash_1.chunk)(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
73
+ const promises = lodash_1.chunk(tokens, 75).map((partition) => __awaiter(this, void 0, void 0, function* () {
74
74
  var _a, _b, _c;
75
75
  let acc = {};
76
76
  for (const token of partition) {
@@ -112,8 +112,8 @@ class NEOClient {
112
112
  const targetProxyHash = this.getTargetProxyHash(token);
113
113
  const toAssetHash = Neon.u.str2hexstring(token.id);
114
114
  const addressBytes = address_1.SWTHAddress.getAddressBytes(swthAddress, networkConfig.network);
115
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
116
- const zeroAddressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
115
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
116
+ const zeroAddressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(constant_1.ZeroAddress));
117
117
  const amount = ethers_1.ethers.BigNumber.from(token.externalBalance);
118
118
  const feeAmount = ethers_1.ethers.BigNumber.from(feeAmountInput !== null && feeAmountInput !== void 0 ? feeAmountInput : "100000000");
119
119
  const feeAddress = feeAmount.isZero() ? zeroAddressHex : networkConfig.feeAddress;
@@ -160,7 +160,7 @@ class NEOClient {
160
160
  const fromAddress = util_1.AddressUtils.NEOAddress.publicKeyToAddress(publicKeyOutput.publicKey);
161
161
  const targetProxyHash = this.getTargetProxyHash(token);
162
162
  const toAssetHash = Neon.u.str2hexstring(token.id);
163
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
163
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
164
164
  const nonce = Math.floor(Math.random() * 1000000);
165
165
  if (amount.lt(feeAmount)) {
166
166
  throw new Error("Invalid amount");
@@ -196,7 +196,7 @@ class NEOClient {
196
196
  const fromAddress = ledger.scriptHash;
197
197
  const targetProxyHash = this.getTargetProxyHash(token);
198
198
  const toAssetHash = Neon.u.str2hexstring(token.id);
199
- const toAddress = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(address));
199
+ const toAddress = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(address));
200
200
  const feeAddress = networkConfig.feeAddress;
201
201
  const nonce = Math.floor(Math.random() * 1000000);
202
202
  if (amount.lt(feeAmount)) {
@@ -316,7 +316,7 @@ class NEOClient {
316
316
  getTargetProxyHash(token) {
317
317
  const networkConfig = this.getNetworkConfig();
318
318
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
319
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
319
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
320
320
  return addressHex;
321
321
  }
322
322
  getNetworkConfig() {
@@ -117,10 +117,18 @@ class TokenClient {
117
117
  return (_a = util_1.NumberUtils.toUnitless(humanAmt, decimals)) !== null && _a !== void 0 ? _a : number_1.BN_ZERO;
118
118
  }
119
119
  tokenForId(id) {
120
- return Object.values(this.tokens).find((token) => token.id === id);
120
+ let tokensList = Object.values(this.tokens);
121
+ if (TokenClient.isPoolToken(id)) {
122
+ tokensList = Object.values(this.poolTokens);
123
+ }
124
+ else if (TokenClient.isCdpToken(id)) {
125
+ tokensList = Object.values(this.cdpTokens);
126
+ }
127
+ return tokensList.find((token) => token.id === id);
121
128
  }
122
129
  tokenForDenom(denom) {
123
- return this.tokens[denom];
130
+ var _a, _b;
131
+ return (_b = (_a = this.poolTokens[denom]) !== null && _a !== void 0 ? _a : this.cdpTokens[denom]) !== null && _b !== void 0 ? _b : this.tokens[denom];
124
132
  }
125
133
  getFeeInfo(denom) {
126
134
  return __awaiter(this, void 0, void 0, function* () {
@@ -459,7 +467,7 @@ class TokenClient {
459
467
  processTokenPrices(tokenPrices) {
460
468
  return tokenPrices.reduce((prevPrices, price) => {
461
469
  const newPrev = prevPrices;
462
- newPrev[price.denom] = (0, number_1.bnOrZero)(price.twap).shiftedBy(-constant_1.decTypeDecimals);
470
+ newPrev[price.denom] = number_1.bnOrZero(price.twap).shiftedBy(-constant_1.decTypeDecimals);
463
471
  return newPrev;
464
472
  }, {});
465
473
  }
@@ -72,12 +72,12 @@ class ZILClient {
72
72
  getExternalBalances(sdk, address, whitelistDenoms) {
73
73
  return __awaiter(this, void 0, void 0, function* () {
74
74
  const tokenQueryResults = yield sdk.token.getAllTokens();
75
- const tokens = tokenQueryResults.filter((token) => (0, blockchain_1.blockchainForChainId)(token.chainId.toNumber(), sdk.network) == this.blockchain &&
75
+ const tokens = tokenQueryResults.filter((token) => blockchain_1.blockchainForChainId(token.chainId.toNumber(), sdk.network) == this.blockchain &&
76
76
  token.tokenAddress.length == 40 &&
77
77
  (!whitelistDenoms || whitelistDenoms.includes(token.denom)));
78
78
  const requests = tokens.map((token) => token.tokenAddress === zeroAddress
79
- ? (0, exports.balanceBatchRequest)(address.replace(/^0x/i, ""))
80
- : (0, exports.tokenBalanceBatchRequest)(token.tokenAddress, address));
79
+ ? exports.balanceBatchRequest(address.replace(/^0x/i, ""))
80
+ : exports.tokenBalanceBatchRequest(token.tokenAddress, address));
81
81
  const response = yield fetch(this.getProviderUrl(), {
82
82
  method: "post",
83
83
  headers: { "content-type": "application/json" },
@@ -102,7 +102,7 @@ class ZILClient {
102
102
  // if (!isValidAddress) {
103
103
  // throw new Error("invalid address")
104
104
  // }
105
- return (0, zilliqa_1.fromBech32Address)(bech32Address).toLowerCase().substr(2);
105
+ return zilliqa_1.fromBech32Address(bech32Address).toLowerCase().substr(2);
106
106
  });
107
107
  }
108
108
  // see examplesV2/zil_client.ts on how to confirm the transactions
@@ -148,7 +148,7 @@ class ZILClient {
148
148
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
149
149
  }
150
150
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
151
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
151
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
152
152
  if (balanceAndNonceResp.error !== undefined) {
153
153
  throw new Error(balanceAndNonceResp.error.message);
154
154
  }
@@ -166,7 +166,7 @@ class ZILClient {
166
166
  vname: "spender",
167
167
  type: "ByStr20",
168
168
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
169
- value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : (0, generic_1.appendHexPrefix)(token.bridgeAddress),
169
+ value: spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : generic_1.appendHexPrefix(token.bridgeAddress),
170
170
  },
171
171
  {
172
172
  vname: "amount",
@@ -184,7 +184,7 @@ class ZILClient {
184
184
  }
185
185
  checkAllowanceZRC2(token, owner, spender) {
186
186
  return __awaiter(this, void 0, void 0, function* () {
187
- const contractAddress = (0, generic_1.appendHexPrefix)(token.tokenAddress);
187
+ const contractAddress = generic_1.appendHexPrefix(token.tokenAddress);
188
188
  const zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
189
189
  const resp = yield zilliqa.blockchain.getSmartContractSubState(contractAddress, "allowances", [owner, spender]);
190
190
  if (resp.error !== undefined) {
@@ -206,13 +206,13 @@ class ZILClient {
206
206
  }
207
207
  const carbonNetwork = networkConfig.network;
208
208
  const fromTokenId = fromToken.id;
209
- const fromTokenAddr = (0, generic_1.appendHexPrefix)(fromToken.tokenAddress);
209
+ const fromTokenAddr = generic_1.appendHexPrefix(fromToken.tokenAddress);
210
210
  const toTokenDenom = toToken.denom;
211
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(fromToken));
211
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(fromToken));
212
212
  const recoveryAddressHex = ethers_1.ethers.utils.hexlify(index_1.AddressUtils.SWTHAddress.getAddressBytes(recoveryAddress, carbonNetwork));
213
213
  const fromAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(fromTokenId));
214
214
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(toTokenDenom));
215
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
215
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
216
216
  const contractAddress = this.getBridgeEntranceAddr();
217
217
  let zilliqa;
218
218
  if (typeof signer === "string") {
@@ -227,7 +227,7 @@ class ZILClient {
227
227
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
228
228
  }
229
229
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
230
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(fromAddress));
230
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(fromAddress));
231
231
  if (balanceAndNonceResp.error !== undefined) {
232
232
  throw new Error(balanceAndNonceResp.error.message);
233
233
  }
@@ -304,13 +304,13 @@ class ZILClient {
304
304
  return __awaiter(this, void 0, void 0, function* () {
305
305
  const { address, amount, token, gasPrice, gasLimit, zilAddress, signer } = params;
306
306
  const networkConfig = this.getNetworkConfig();
307
- const assetId = (0, generic_1.appendHexPrefix)(token.tokenAddress);
308
- const targetProxyHash = (0, generic_1.appendHexPrefix)(this.getTargetProxyHash(token));
309
- const feeAddress = (0, generic_1.appendHexPrefix)(networkConfig.feeAddress);
307
+ const assetId = generic_1.appendHexPrefix(token.tokenAddress);
308
+ const targetProxyHash = generic_1.appendHexPrefix(this.getTargetProxyHash(token));
309
+ const feeAddress = generic_1.appendHexPrefix(networkConfig.feeAddress);
310
310
  const toAssetHash = ethers_1.ethers.utils.hexlify(ethers_1.ethers.utils.toUtf8Bytes(token.id));
311
311
  const swthAddress = ethers_1.ethers.utils.hexlify(address);
312
312
  // TODO: Check if bridgeAddress corresponds to carbon token lock_proxy_hash
313
- const contractAddress = (0, generic_1.appendHexPrefix)(token.bridgeAddress);
313
+ const contractAddress = generic_1.appendHexPrefix(token.bridgeAddress);
314
314
  let zilliqa;
315
315
  if (typeof signer === "string") {
316
316
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
@@ -324,7 +324,7 @@ class ZILClient {
324
324
  zilliqa = new zilliqa_1.Zilliqa(this.getProviderUrl());
325
325
  }
326
326
  const deployedContract = (this.walletProvider || zilliqa).contracts.at(contractAddress);
327
- const balanceAndNonceResp = yield zilliqa.blockchain.getBalance((0, generic_1.stripHexPrefix)(zilAddress));
327
+ const balanceAndNonceResp = yield zilliqa.blockchain.getBalance(generic_1.stripHexPrefix(zilAddress));
328
328
  if (balanceAndNonceResp.error !== undefined) {
329
329
  throw new Error(balanceAndNonceResp.error.message);
330
330
  }
@@ -409,7 +409,7 @@ class ZILClient {
409
409
  getTargetProxyHash(token) {
410
410
  const networkConfig = this.getNetworkConfig();
411
411
  const addressBytes = address_1.SWTHAddress.getAddressBytes(token.creator, networkConfig.network);
412
- const addressHex = (0, generic_1.stripHexPrefix)(ethers_1.ethers.utils.hexlify(addressBytes));
412
+ const addressHex = generic_1.stripHexPrefix(ethers_1.ethers.utils.hexlify(addressBytes));
413
413
  return addressHex;
414
414
  }
415
415
  getNetworkConfig() {
@@ -0,0 +1,23 @@
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal";
3
+ export declare const protobufPackage = "Switcheo.carbon.cdp";
4
+ export interface EModeCategory {
5
+ name: string;
6
+ denoms: string[];
7
+ loanToValue: string;
8
+ liquidationThreshold: string;
9
+ liquidationDiscount: string;
10
+ isActive: boolean;
11
+ }
12
+ export declare const EModeCategory: {
13
+ encode(message: EModeCategory, writer?: _m0.Writer): _m0.Writer;
14
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): EModeCategory;
15
+ fromJSON(object: any): EModeCategory;
16
+ toJSON(message: EModeCategory): unknown;
17
+ fromPartial(object: DeepPartial<EModeCategory>): EModeCategory;
18
+ };
19
+ declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
20
+ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
21
+ [K in keyof T]?: DeepPartial<T[K]>;
22
+ } : Partial<T>;
23
+ export {};
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EModeCategory = exports.protobufPackage = void 0;
7
+ /* eslint-disable */
8
+ const long_1 = __importDefault(require("long"));
9
+ const minimal_1 = __importDefault(require("protobufjs/minimal"));
10
+ exports.protobufPackage = "Switcheo.carbon.cdp";
11
+ const baseEModeCategory = {
12
+ name: "",
13
+ denoms: "",
14
+ loanToValue: "",
15
+ liquidationThreshold: "",
16
+ liquidationDiscount: "",
17
+ isActive: false,
18
+ };
19
+ exports.EModeCategory = {
20
+ encode(message, writer = minimal_1.default.Writer.create()) {
21
+ if (message.name !== "") {
22
+ writer.uint32(10).string(message.name);
23
+ }
24
+ for (const v of message.denoms) {
25
+ writer.uint32(18).string(v);
26
+ }
27
+ if (message.loanToValue !== "") {
28
+ writer.uint32(26).string(message.loanToValue);
29
+ }
30
+ if (message.liquidationThreshold !== "") {
31
+ writer.uint32(34).string(message.liquidationThreshold);
32
+ }
33
+ if (message.liquidationDiscount !== "") {
34
+ writer.uint32(42).string(message.liquidationDiscount);
35
+ }
36
+ if (message.isActive === true) {
37
+ writer.uint32(48).bool(message.isActive);
38
+ }
39
+ return writer;
40
+ },
41
+ decode(input, length) {
42
+ const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
43
+ let end = length === undefined ? reader.len : reader.pos + length;
44
+ const message = Object.assign({}, baseEModeCategory);
45
+ message.denoms = [];
46
+ while (reader.pos < end) {
47
+ const tag = reader.uint32();
48
+ switch (tag >>> 3) {
49
+ case 1:
50
+ message.name = reader.string();
51
+ break;
52
+ case 2:
53
+ message.denoms.push(reader.string());
54
+ break;
55
+ case 3:
56
+ message.loanToValue = reader.string();
57
+ break;
58
+ case 4:
59
+ message.liquidationThreshold = reader.string();
60
+ break;
61
+ case 5:
62
+ message.liquidationDiscount = reader.string();
63
+ break;
64
+ case 6:
65
+ message.isActive = reader.bool();
66
+ break;
67
+ default:
68
+ reader.skipType(tag & 7);
69
+ break;
70
+ }
71
+ }
72
+ return message;
73
+ },
74
+ fromJSON(object) {
75
+ var _a;
76
+ const message = Object.assign({}, baseEModeCategory);
77
+ message.name =
78
+ object.name !== undefined && object.name !== null
79
+ ? String(object.name)
80
+ : "";
81
+ message.denoms = ((_a = object.denoms) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
82
+ message.loanToValue =
83
+ object.loanToValue !== undefined && object.loanToValue !== null
84
+ ? String(object.loanToValue)
85
+ : "";
86
+ message.liquidationThreshold =
87
+ object.liquidationThreshold !== undefined &&
88
+ object.liquidationThreshold !== null
89
+ ? String(object.liquidationThreshold)
90
+ : "";
91
+ message.liquidationDiscount =
92
+ object.liquidationDiscount !== undefined &&
93
+ object.liquidationDiscount !== null
94
+ ? String(object.liquidationDiscount)
95
+ : "";
96
+ message.isActive =
97
+ object.isActive !== undefined && object.isActive !== null
98
+ ? Boolean(object.isActive)
99
+ : false;
100
+ return message;
101
+ },
102
+ toJSON(message) {
103
+ const obj = {};
104
+ message.name !== undefined && (obj.name = message.name);
105
+ if (message.denoms) {
106
+ obj.denoms = message.denoms.map((e) => e);
107
+ }
108
+ else {
109
+ obj.denoms = [];
110
+ }
111
+ message.loanToValue !== undefined &&
112
+ (obj.loanToValue = message.loanToValue);
113
+ message.liquidationThreshold !== undefined &&
114
+ (obj.liquidationThreshold = message.liquidationThreshold);
115
+ message.liquidationDiscount !== undefined &&
116
+ (obj.liquidationDiscount = message.liquidationDiscount);
117
+ message.isActive !== undefined && (obj.isActive = message.isActive);
118
+ return obj;
119
+ },
120
+ fromPartial(object) {
121
+ var _a, _b, _c, _d, _e, _f;
122
+ const message = Object.assign({}, baseEModeCategory);
123
+ message.name = (_a = object.name) !== null && _a !== void 0 ? _a : "";
124
+ message.denoms = ((_b = object.denoms) !== null && _b !== void 0 ? _b : []).map((e) => e);
125
+ message.loanToValue = (_c = object.loanToValue) !== null && _c !== void 0 ? _c : "";
126
+ message.liquidationThreshold = (_d = object.liquidationThreshold) !== null && _d !== void 0 ? _d : "";
127
+ message.liquidationDiscount = (_e = object.liquidationDiscount) !== null && _e !== void 0 ? _e : "";
128
+ message.isActive = (_f = object.isActive) !== null && _f !== void 0 ? _f : false;
129
+ return message;
130
+ },
131
+ };
132
+ if (minimal_1.default.util.Long !== long_1.default) {
133
+ minimal_1.default.util.Long = long_1.default;
134
+ minimal_1.default.configure();
135
+ }
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
159
159
  const message = Object.assign({}, baseQueryProposalsRequest);
160
160
  message.proposalStatus =
161
161
  object.proposalStatus !== undefined && object.proposalStatus !== null
162
- ? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
162
+ ? gov_1.proposalStatusFromJSON(object.proposalStatus)
163
163
  : 0;
164
164
  message.voter =
165
165
  object.voter !== undefined && object.voter !== null
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
178
178
  toJSON(message) {
179
179
  const obj = {};
180
180
  message.proposalStatus !== undefined &&
181
- (obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
181
+ (obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
182
182
  message.voter !== undefined && (obj.voter = message.voter);
183
183
  message.depositor !== undefined && (obj.depositor = message.depositor);
184
184
  message.pagination !== undefined &&
@@ -300,7 +300,7 @@ exports.MsgVote = {
300
300
  : "";
301
301
  message.option =
302
302
  object.option !== undefined && object.option !== null
303
- ? (0, gov_1.voteOptionFromJSON)(object.option)
303
+ ? gov_1.voteOptionFromJSON(object.option)
304
304
  : 0;
305
305
  message.metadata =
306
306
  object.metadata !== undefined && object.metadata !== null
@@ -314,7 +314,7 @@ exports.MsgVote = {
314
314
  (obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
315
315
  message.voter !== undefined && (obj.voter = message.voter);
316
316
  message.option !== undefined &&
317
- (obj.option = (0, gov_1.voteOptionToJSON)(message.option));
317
+ (obj.option = gov_1.voteOptionToJSON(message.option));
318
318
  message.metadata !== undefined && (obj.metadata = message.metadata);
319
319
  return obj;
320
320
  },
@@ -159,7 +159,7 @@ exports.QueryProposalsRequest = {
159
159
  const message = Object.assign({}, baseQueryProposalsRequest);
160
160
  message.proposalStatus =
161
161
  object.proposalStatus !== undefined && object.proposalStatus !== null
162
- ? (0, gov_1.proposalStatusFromJSON)(object.proposalStatus)
162
+ ? gov_1.proposalStatusFromJSON(object.proposalStatus)
163
163
  : 0;
164
164
  message.voter =
165
165
  object.voter !== undefined && object.voter !== null
@@ -178,7 +178,7 @@ exports.QueryProposalsRequest = {
178
178
  toJSON(message) {
179
179
  const obj = {};
180
180
  message.proposalStatus !== undefined &&
181
- (obj.proposalStatus = (0, gov_1.proposalStatusToJSON)(message.proposalStatus));
181
+ (obj.proposalStatus = gov_1.proposalStatusToJSON(message.proposalStatus));
182
182
  message.voter !== undefined && (obj.voter = message.voter);
183
183
  message.depositor !== undefined && (obj.depositor = message.depositor);
184
184
  message.pagination !== undefined &&
@@ -185,7 +185,7 @@ exports.MsgVote = {
185
185
  : "";
186
186
  message.option =
187
187
  object.option !== undefined && object.option !== null
188
- ? (0, gov_1.voteOptionFromJSON)(object.option)
188
+ ? gov_1.voteOptionFromJSON(object.option)
189
189
  : 0;
190
190
  return message;
191
191
  },
@@ -195,7 +195,7 @@ exports.MsgVote = {
195
195
  (obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
196
196
  message.voter !== undefined && (obj.voter = message.voter);
197
197
  message.option !== undefined &&
198
- (obj.option = (0, gov_1.voteOptionToJSON)(message.option));
198
+ (obj.option = gov_1.voteOptionToJSON(message.option));
199
199
  return obj;
200
200
  },
201
201
  fromPartial(object) {
@@ -384,7 +384,7 @@ exports.EventExec = {
384
384
  : long_1.default.UZERO;
385
385
  message.result =
386
386
  object.result !== undefined && object.result !== null
387
- ? (0, types_1.proposalExecutorResultFromJSON)(object.result)
387
+ ? types_1.proposalExecutorResultFromJSON(object.result)
388
388
  : 0;
389
389
  message.logs =
390
390
  object.logs !== undefined && object.logs !== null
@@ -397,7 +397,7 @@ exports.EventExec = {
397
397
  message.proposalId !== undefined &&
398
398
  (obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
399
399
  message.result !== undefined &&
400
- (obj.result = (0, types_1.proposalExecutorResultToJSON)(message.result));
400
+ (obj.result = types_1.proposalExecutorResultToJSON(message.result));
401
401
  message.logs !== undefined && (obj.logs = message.logs);
402
402
  return obj;
403
403
  },
@@ -1474,7 +1474,7 @@ exports.MsgVote = {
1474
1474
  : "";
1475
1475
  message.option =
1476
1476
  object.option !== undefined && object.option !== null
1477
- ? (0, types_1.voteOptionFromJSON)(object.option)
1477
+ ? types_1.voteOptionFromJSON(object.option)
1478
1478
  : 0;
1479
1479
  message.metadata =
1480
1480
  object.metadata !== undefined && object.metadata !== null
@@ -1492,7 +1492,7 @@ exports.MsgVote = {
1492
1492
  (obj.proposalId = (message.proposalId || long_1.default.UZERO).toString());
1493
1493
  message.voter !== undefined && (obj.voter = message.voter);
1494
1494
  message.option !== undefined &&
1495
- (obj.option = (0, types_1.voteOptionToJSON)(message.option));
1495
+ (obj.option = types_1.voteOptionToJSON(message.option));
1496
1496
  message.metadata !== undefined && (obj.metadata = message.metadata);
1497
1497
  message.exec !== undefined && (obj.exec = execToJSON(message.exec));
1498
1498
  return obj;
@@ -1633,14 +1633,14 @@ exports.MsgExecResponse = {
1633
1633
  const message = Object.assign({}, baseMsgExecResponse);
1634
1634
  message.result =
1635
1635
  object.result !== undefined && object.result !== null
1636
- ? (0, types_1.proposalExecutorResultFromJSON)(object.result)
1636
+ ? types_1.proposalExecutorResultFromJSON(object.result)
1637
1637
  : 0;
1638
1638
  return message;
1639
1639
  },
1640
1640
  toJSON(message) {
1641
1641
  const obj = {};
1642
1642
  message.result !== undefined &&
1643
- (obj.result = (0, types_1.proposalExecutorResultToJSON)(message.result));
1643
+ (obj.result = types_1.proposalExecutorResultToJSON(message.result));
1644
1644
  return obj;
1645
1645
  },
1646
1646
  fromPartial(object) {