carbon-js-sdk 0.11.0 → 0.11.1

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.
@@ -16,6 +16,7 @@ declare class TokenClient {
16
16
  readonly bridges: BridgeMap;
17
17
  readonly symbols: TypeUtils.SimpleMap<string>;
18
18
  readonly usdValues: TypeUtils.SimpleMap<BigNumber>;
19
+ readonly commonAssetNames: TypeUtils.SimpleMap<string>;
19
20
  readonly geckoTokenNames: TypeUtils.SimpleMap<string>;
20
21
  initialUsdValuesLoaded: boolean;
21
22
  private additionalGeckoDenoms;
@@ -23,13 +24,14 @@ declare class TokenClient {
23
24
  static instance(query: CarbonQueryClient, configProvider: NetworkConfigProvider): TokenClient;
24
25
  initialize(): Promise<void>;
25
26
  registerGeckoIdMap(map: TypeUtils.SimpleMap<string>): void;
27
+ getCommonDenom(denom: string): string;
26
28
  getDecimals(denom: string): number | undefined;
27
29
  getBlockchain(denom: string): BlockchainUtils.Blockchain | BlockchainUtils.BlockchainV2 | undefined;
28
30
  getBlockchainV2(denom: string | undefined): BlockchainUtils.BlockchainV2 | undefined;
29
31
  /**
30
32
  * use getTokenName directly instead
31
33
  * @deprecated
32
- */
34
+ */
33
35
  getSymbol(denom: string): string;
34
36
  getUSDValue(denom: string): BigNumber | undefined;
35
37
  toHuman(denom: string, unitlessAmt: BigNumber): BigNumber;
@@ -80,6 +82,6 @@ declare class TokenClient {
80
82
  processTokenPrices(tokenPrices: Carbon.Pricing.TokenPrice[]): TypeUtils.SimpleMap<BigNumber>;
81
83
  getUSDValuesFromPricingModule(): Promise<TypeUtils.SimpleMap<BigNumber>>;
82
84
  getDenomToGeckoIdMap(): Promise<TypeUtils.SimpleMap<string>>;
83
- setGeckoTokenNames(): void;
85
+ setCommonAssetConfig(): void;
84
86
  }
85
87
  export default TokenClient;
@@ -51,6 +51,7 @@ class TokenClient {
51
51
  this.bridges = { polynetwork: [], ibc: [] };
52
52
  this.symbols = {};
53
53
  this.usdValues = {};
54
+ this.commonAssetNames = constant_1.CommonAssetName;
54
55
  this.geckoTokenNames = constant_1.CoinGeckoTokenNames;
55
56
  this.initialUsdValuesLoaded = false;
56
57
  this.additionalGeckoDenoms = {};
@@ -67,7 +68,7 @@ class TokenClient {
67
68
  }
68
69
  initialize() {
69
70
  return __awaiter(this, void 0, void 0, function* () {
70
- this.setGeckoTokenNames();
71
+ this.setCommonAssetConfig();
71
72
  try {
72
73
  yield Promise.all([
73
74
  this.reloadTokens(),
@@ -86,6 +87,10 @@ class TokenClient {
86
87
  registerGeckoIdMap(map) {
87
88
  this.additionalGeckoDenoms = Object.assign(Object.assign({}, this.additionalGeckoDenoms), map);
88
89
  }
90
+ getCommonDenom(denom) {
91
+ var _a;
92
+ return (_a = this.commonAssetNames[denom]) !== null && _a !== void 0 ? _a : denom;
93
+ }
89
94
  getDecimals(denom) {
90
95
  var _a, _b, _c;
91
96
  return (_c = ((_b = (_a = this.tokens[denom]) !== null && _a !== void 0 ? _a : this.poolTokens[denom]) !== null && _b !== void 0 ? _b : this.cdpTokens[denom])) === null || _c === void 0 ? void 0 : _c.decimals.toNumber();
@@ -122,10 +127,14 @@ class TokenClient {
122
127
  /**
123
128
  * use getTokenName directly instead
124
129
  * @deprecated
125
- */
130
+ */
126
131
  getSymbol(denom) {
127
- var _a;
128
- return (_a = this.symbols[denom]) !== null && _a !== void 0 ? _a : denom;
132
+ var _a, _b;
133
+ if (TokenClient.isCdpToken(denom)) {
134
+ return (_a = this.symbols[denom]) !== null && _a !== void 0 ? _a : denom;
135
+ }
136
+ const commonDenom = this.getCommonDenom(denom);
137
+ return (_b = this.symbols[commonDenom]) !== null && _b !== void 0 ? _b : commonDenom.toUpperCase();
129
138
  }
130
139
  getUSDValue(denom) {
131
140
  return this.usdValues[denom];
@@ -170,13 +179,13 @@ class TokenClient {
170
179
  });
171
180
  }
172
181
  getTokenName(denom, overrideMap) {
173
- var _a, _b;
182
+ var _a;
174
183
  if (typeof denom !== "string")
175
184
  return "";
176
185
  if (!TokenClient.isIBCDenom(denom) && !TokenClient.isCdpIbcDenom(denom)) {
177
186
  denom = denom.toLowerCase();
178
187
  }
179
- const symbol = (_a = this.symbols[denom]) !== null && _a !== void 0 ? _a : denom;
188
+ const symbol = this.getSymbol(denom);
180
189
  if (TokenClient.isPoolTokenLegacy(denom)) {
181
190
  const match = symbol.match(/^([a-z\d.-/]+)-(\d+)-([a-z\d.-/]+)-(\d+)-lp\d+$/i);
182
191
  // inconsistent implementation of isPoolToken, exit
@@ -191,7 +200,7 @@ class TokenClient {
191
200
  if (TokenClient.isIBCDenom(denom)) {
192
201
  const splitDenom = denom.split("/");
193
202
  denom = `${splitDenom[0].toLowerCase()}/${splitDenom[1].toUpperCase()}`;
194
- return (_b = this.symbols[denom]) !== null && _b !== void 0 ? _b : denom.toUpperCase();
203
+ return (_a = this.symbols[denom]) !== null && _a !== void 0 ? _a : denom.toUpperCase();
195
204
  }
196
205
  if (SYMBOL_OVERRIDE[symbol]) {
197
206
  return SYMBOL_OVERRIDE[symbol];
@@ -661,12 +670,21 @@ class TokenClient {
661
670
  return tokens;
662
671
  });
663
672
  }
664
- setGeckoTokenNames() {
673
+ setCommonAssetConfig() {
665
674
  // whitelisted ibc tokens
666
675
  ibc_1.ibcWhitelist.forEach((chainId) => {
676
+ var _a;
667
677
  const currencies = util_1.IBCUtils.EmbedChainInfos[chainId].currencies;
678
+ const channelObj = (_a = ibc_1.swthChannels[chainId]) === null || _a === void 0 ? void 0 : _a.ibc;
668
679
  currencies.forEach((asset) => {
680
+ var _a, _b;
681
+ const channel = asset.coinMinimalDenom !== "swth" ? (_a = channelObj === null || channelObj === void 0 ? void 0 : channelObj.sourceChannel) !== null && _a !== void 0 ? _a : "channel-0" : (_b = channelObj === null || channelObj === void 0 ? void 0 : channelObj.dstChannel) !== null && _b !== void 0 ? _b : "channel-0";
682
+ const assetDenom = TokenClient.isIBCDenom(asset.coinMinimalDenom)
683
+ ? asset.coinMinimalDenom
684
+ : util_1.IBCUtils.makeIBCMinimalDenom(channel, asset.coinMinimalDenom);
669
685
  const symbolSmall = asset.coinDenom.toLowerCase();
686
+ if (!this.commonAssetNames[assetDenom])
687
+ this.commonAssetNames[assetDenom] = symbolSmall;
670
688
  if (asset.coinGeckoId && !this.geckoTokenNames[symbolSmall])
671
689
  this.geckoTokenNames[symbolSmall] = asset.coinGeckoId;
672
690
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",