carbon-js-sdk 0.3.46 → 0.3.47

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.
@@ -148,6 +148,12 @@ exports.EmbedChainInfosInit = {
148
148
  coinDecimals: 6,
149
149
  coinGeckoId: "ion",
150
150
  },
151
+ {
152
+ coinDenom: "axlUSDC",
153
+ coinMinimalDenom: "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858",
154
+ coinDecimals: 6,
155
+ coinGeckoId: "usd-coin",
156
+ },
151
157
  ],
152
158
  feeCurrencies: [
153
159
  {
@@ -0,0 +1,16 @@
1
+ import { SDKProvider } from "../provider";
2
+ import { TypeUtils } from "../util";
3
+ import BigNumber from "bignumber.js";
4
+ import { QueryClientImpl as CosmWasmQueryClient } from "cosmjs-types/cosmwasm/wasm/v1/query";
5
+ import BaseModule from "./base";
6
+ export interface BalanceResponse {
7
+ contractAddress: string;
8
+ balance: BigNumber;
9
+ }
10
+ export declare class CosmWasmModule extends BaseModule {
11
+ private cosmWasmClient;
12
+ constructor(cosmClient: CosmWasmQueryClient, sdkProvider: SDKProvider);
13
+ static instance(tmRpcUrl: string, sdkProvider: SDKProvider): Promise<CosmWasmModule>;
14
+ queryCosmwasmBalance(walletAddress: string, contractAddr: string): Promise<BalanceResponse>;
15
+ queryCosmwasmBalances(walletAddress: string, contractAddresses: string[]): Promise<TypeUtils.SimpleMap<BigNumber>>;
16
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CosmWasmModule = void 0;
16
+ const util_1 = require("../util");
17
+ const query_1 = require("cosmjs-types/cosmwasm/wasm/v1/query");
18
+ const stargate_1 = require("@cosmjs/stargate");
19
+ const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
20
+ const base_1 = __importDefault(require("./base"));
21
+ class CosmWasmModule extends base_1.default {
22
+ constructor(cosmClient, sdkProvider) {
23
+ super(sdkProvider);
24
+ this.cosmWasmClient = cosmClient;
25
+ }
26
+ static instance(tmRpcUrl, sdkProvider) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const tmClient = util_1.GenericUtils.modifyTmClient(yield tendermint_rpc_1.Tendermint34Client.connect(tmRpcUrl));
29
+ const baseClient = new stargate_1.QueryClient(tmClient);
30
+ const rpcClient = stargate_1.createProtobufRpcClient(baseClient);
31
+ const cosmWasmClient = new query_1.QueryClientImpl(rpcClient);
32
+ return new CosmWasmModule(cosmWasmClient, sdkProvider);
33
+ });
34
+ }
35
+ queryCosmwasmBalance(walletAddress, contractAddr) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const finalResult = {
38
+ contractAddress: contractAddr,
39
+ balance: util_1.NumberUtils.BN_ZERO,
40
+ };
41
+ try {
42
+ const smartContract = yield this.cosmWasmClient.SmartContractState({
43
+ address: contractAddr,
44
+ queryData: Buffer.from(JSON.stringify({ balance: { address: walletAddress } }), 'utf-8'),
45
+ });
46
+ const result = Buffer.from(smartContract.data).toString("utf-8");
47
+ const balanceJson = JSON.parse(result);
48
+ finalResult.balance = util_1.NumberUtils.bnOrZero(balanceJson.balance);
49
+ }
50
+ catch (err) {
51
+ console.error(err);
52
+ }
53
+ return finalResult;
54
+ });
55
+ }
56
+ queryCosmwasmBalances(walletAddress, contractAddresses) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const balancesMap = yield Promise.all(contractAddresses.map((contractAddr) => this.queryCosmwasmBalance(walletAddress, contractAddr)));
59
+ return balancesMap.reduce((prev, balance) => {
60
+ prev[balance.contractAddress] = balance.balance;
61
+ return prev;
62
+ }, {});
63
+ });
64
+ }
65
+ ;
66
+ }
67
+ exports.CosmWasmModule = CosmWasmModule;
package/lib/util/ibc.js CHANGED
@@ -31,9 +31,13 @@ exports.totalAssetObj = Object.values(exports.EmbedChainInfos).reduce((prev, cha
31
31
  const channelsObj = constant_1.swthChannels[chainInfo.chainId];
32
32
  chainInfo.currencies.forEach((currency) => {
33
33
  var _a;
34
- const ibcAddr = currency.coinDenom.toLowerCase() === "swth"
34
+ let ibcAddr = currency.coinDenom.toLowerCase() === "swth"
35
35
  ? currency.coinMinimalDenom
36
36
  : makeIBCMinimalDenom((_a = channelsObj === null || channelsObj === void 0 ? void 0 : channelsObj.sourceChannel) !== null && _a !== void 0 ? _a : "channel-0", currency.coinMinimalDenom);
37
+ // TODO: Remove when implementing dynamic ibc chain info
38
+ if (currency.coinMinimalDenom === "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858") {
39
+ ibcAddr = "ibc/7FBDBEEEBA9C50C4BCDF7BF438EAB99E64360833D240B32655C96E319559E911";
40
+ }
37
41
  assetsObj[ibcAddr] = currency;
38
42
  });
39
43
  newAssetObj[chainInfo.chainId] = assetsObj;
@@ -76,6 +80,11 @@ exports.BlockchainMap = Object.values(exports.EmbedChainInfos).reduce((prev, cha
76
80
  const channelsObj = constant_1.swthChannels[chainInfo.chainId];
77
81
  chainInfo.currencies.forEach((currency) => {
78
82
  var _a;
83
+ // TODO: Remove when implementing dynamic ibc chain info
84
+ if (currency.coinMinimalDenom === "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858") {
85
+ newPrev["ibc/7FBDBEEEBA9C50C4BCDF7BF438EAB99E64360833D240B32655C96E319559E911"] = exports.ChainIdBlockchainMap[chainInfo.chainId];
86
+ return;
87
+ }
79
88
  if (currency.coinDenom.toLowerCase() === "swth") {
80
89
  newPrev[currency.coinMinimalDenom] = exports.ChainIdBlockchainMap[chainInfo.chainId];
81
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.3.46",
3
+ "version": "0.3.47",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",