carbon-js-sdk 0.2.11-dev.1 → 0.2.11-dev.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.
@@ -10,6 +10,7 @@ declare class TokenClient {
10
10
  readonly tokens: TypeUtils.SimpleMap<Token>;
11
11
  readonly wrapperMap: TypeUtils.SimpleMap<string>;
12
12
  readonly poolTokens: TypeUtils.SimpleMap<Token>;
13
+ readonly cdpTokens: TypeUtils.SimpleMap<Token>;
13
14
  readonly symbols: TypeUtils.SimpleMap<string>;
14
15
  readonly usdValues: TypeUtils.SimpleMap<BigNumber>;
15
16
  readonly commonAssetNames: TypeUtils.SimpleMap<string>;
@@ -34,6 +35,7 @@ declare class TokenClient {
34
35
  static isPoolTokenNew(denom: string): boolean;
35
36
  static isPoolTokenLegacy(denom: string): boolean;
36
37
  static isPoolToken(denom: string): boolean;
38
+ static isCdpToken(denom: string): boolean;
37
39
  static isIBCDenom(denom: string): boolean;
38
40
  isWrappedToken(denom?: string): boolean;
39
41
  hasWrappedToken(denom?: string): boolean;
@@ -41,7 +43,9 @@ declare class TokenClient {
41
43
  getWrappedToken(denom: string, blockchain?: BlockchainUtils.Blockchain): Token | null;
42
44
  getSourceToken(denom: string): Token | null;
43
45
  getNativeToken(): Token | undefined;
46
+ getNativeStablecoin(): Token | undefined;
44
47
  isNativeToken(denom: string): boolean;
48
+ isNativeStablecoin(denom: string): boolean;
45
49
  getDepositTokenFor(tokenDenom: string, chain: BlockchainUtils.Blockchain): Token | undefined;
46
50
  getAllTokens(): Promise<Token[]>;
47
51
  reloadTokens(): Promise<TypeUtils.SimpleMap<Token>>;
@@ -39,6 +39,7 @@ class TokenClient {
39
39
  this.tokens = {};
40
40
  this.wrapperMap = {};
41
41
  this.poolTokens = {};
42
+ this.cdpTokens = {};
42
43
  this.symbols = {};
43
44
  this.usdValues = {};
44
45
  this.commonAssetNames = constant_1.CommonAssetName;
@@ -72,16 +73,16 @@ class TokenClient {
72
73
  return (_a = this.commonAssetNames[denom]) !== null && _a !== void 0 ? _a : denom;
73
74
  }
74
75
  getDecimals(denom) {
75
- var _a, _b;
76
- return (_b = ((_a = this.tokens[denom]) !== null && _a !== void 0 ? _a : this.poolTokens[denom])) === null || _b === void 0 ? void 0 : _b.decimals.toNumber();
76
+ var _a, _b, _c;
77
+ 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();
77
78
  }
78
79
  getBlockchain(denom) {
79
80
  var _a, _b, _c;
80
81
  // chainId defaults to 3 so that blockchain will be undefined
81
82
  let chainId = (_c = (_b = (_a = this.tokens[denom]) === null || _a === void 0 ? void 0 : _a.chainId) === null || _b === void 0 ? void 0 : _b.toNumber()) !== null && _c !== void 0 ? _c : 3;
82
- if (this.isNativeToken(denom) || TokenClient.isPoolToken(denom)) {
83
- // native denom "swth" should be native.
84
- // pool tokens are on the Native blockchain, hence 0
83
+ if (this.isNativeToken(denom) || this.isNativeStablecoin(denom) || TokenClient.isPoolToken(denom) || TokenClient.isCdpToken(denom)) {
84
+ // native denoms "swth" and "usc" should be native.
85
+ // pool and cdp tokens are on the Native blockchain, hence 0
85
86
  chainId = 0;
86
87
  }
87
88
  if (TokenClient.isIBCDenom(denom)) {
@@ -155,7 +156,7 @@ class TokenClient {
155
156
  return symbol;
156
157
  }
157
158
  getTokenDesc(denom) {
158
- var _a, _b;
159
+ var _a, _b, _c, _d;
159
160
  if (typeof denom !== 'string')
160
161
  return '';
161
162
  denom = denom.toLowerCase();
@@ -172,7 +173,10 @@ class TokenClient {
172
173
  const symbolB = this.getTokenName(denomB);
173
174
  return `${weightA}% ${symbolA} / ${weightB}% ${symbolB}`;
174
175
  }
175
- return (_b = (_a = this.tokens[denom]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : this.getSymbol(denom);
176
+ if (TokenClient.isCdpToken(denom)) {
177
+ return (_b = (_a = this.cdpTokens[denom]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : this.getSymbol(denom);
178
+ }
179
+ return (_d = (_c = this.tokens[denom]) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : this.getSymbol(denom);
176
180
  }
177
181
  static isPoolTokenNew(denom) {
178
182
  return denom.match(/^clpt\/(\d+)$/i) !== null;
@@ -183,6 +187,9 @@ class TokenClient {
183
187
  static isPoolToken(denom) {
184
188
  return this.isPoolTokenNew(denom) || this.isPoolTokenLegacy(denom);
185
189
  }
190
+ static isCdpToken(denom) {
191
+ return denom.includes('cdp/');
192
+ }
186
193
  static isIBCDenom(denom) {
187
194
  return denom.match(ibc_1.ibcTokenRegex) !== null;
188
195
  }
@@ -252,9 +259,15 @@ class TokenClient {
252
259
  getNativeToken() {
253
260
  return this.tokenForId("swth");
254
261
  }
262
+ getNativeStablecoin() {
263
+ return this.tokenForId("usc");
264
+ }
255
265
  isNativeToken(denom) {
256
266
  return denom === "swth";
257
267
  }
268
+ isNativeStablecoin(denom) {
269
+ return denom === "usc";
270
+ }
258
271
  getDepositTokenFor(tokenDenom, chain) {
259
272
  const token = this.tokenForDenom(tokenDenom);
260
273
  if (!token) {
@@ -300,6 +313,9 @@ class TokenClient {
300
313
  if (TokenClient.isPoolToken(token.denom)) {
301
314
  this.poolTokens[token.denom] = token;
302
315
  }
316
+ else if (TokenClient.isCdpToken(token.denom)) {
317
+ this.cdpTokens[token.denom] = token;
318
+ }
303
319
  else {
304
320
  if (this.isNativeToken(token.denom)) {
305
321
  // Change token name to Carbon
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.2.11-dev.1",
3
+ "version": "0.2.11-dev.2",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",