@cryptorubic/web3 0.12.7-alpha-rub-67.0 → 0.12.7-alpha-rub-121.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.
package/README.md CHANGED
@@ -1 +1 @@
1
- # web3
1
+ # web3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.12.7-alpha-rub-67.0",
3
+ "version": "0.12.7-alpha-rub-121.1",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -72,13 +72,13 @@ export interface TonApiTokenInfoForWalletResp {
72
72
  [k: string]: string;
73
73
  };
74
74
  };
75
- wallet_address: {
75
+ wallet_address?: {
76
76
  /** address of user's contract for this token */
77
77
  address: string;
78
78
  is_scam: boolean;
79
79
  is_wallet: boolean;
80
80
  };
81
- jetton: {
81
+ jetton?: {
82
82
  /** address of token(jetton) contract. Similaer to ERC20 contract address in EVM */
83
83
  address: string;
84
84
  name: string;
@@ -10,7 +10,7 @@ const web3_pure_1 = require("../../utils/web3-pure");
10
10
  class TonAdapter extends abstract_adapter_1.AbstractAdapter {
11
11
  constructor(httpClient, config, logger) {
12
12
  super(core_1.BLOCKCHAIN_NAME.TON, logger);
13
- this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig);
13
+ this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
14
14
  this.tonClient = new ton_1.TonClient(config.tonClientConfig);
15
15
  }
16
16
  async callForTokensInfo(tokenAddresses) {
@@ -1,14 +1,15 @@
1
1
  import { TonApiAccountInfoResp, TonApiAllNonNullableTokenInfoForWalletResp, TonApiParseAddressResp, TonApiTokenInfoForWalletResp, TonApiTokenInfoResp, TonApiTxDataByBocResp } from '../models/tonapi-models';
2
2
  import { TonCenterBlockInfo } from '../models/toncenter-types';
3
- import { HttpClient } from '@cryptorubic/core';
3
+ import { HttpClient, ICustomLogger } from '@cryptorubic/core';
4
4
  import { TonApiConfig } from '../models/ton-api-config';
5
5
  import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
6
6
  export declare class TonApiService {
7
7
  private readonly httpClient;
8
+ private readonly logger?;
8
9
  private readonly tonApiUrl;
9
10
  private readonly apiKey;
10
11
  private readonly tonCenterV3Url;
11
- constructor(httpClient: HttpClient, params: TonApiConfig);
12
+ constructor(httpClient: HttpClient, params: TonApiConfig, logger?: ICustomLogger | undefined);
12
13
  /**
13
14
  * @param walletAddress in any format: raw or friendly
14
15
  */
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TonApiService = void 0;
4
4
  class TonApiService {
5
- constructor(httpClient, params) {
5
+ constructor(httpClient, params, logger) {
6
6
  this.httpClient = httpClient;
7
+ this.logger = logger;
7
8
  this.apiKey = params.tonApiKey;
8
9
  this.tonApiUrl = params?.tonApiUrl || 'https://tonapi.io';
9
10
  this.tonCenterV3Url = params.tonCenterV3Url || 'https://toncenter.com/api/v3';
@@ -148,16 +149,23 @@ class TonApiService {
148
149
  * @returns balance, decimals, name, symbol, walletJettonAddress, jettonAddress
149
150
  */
150
151
  async fetchTokenInfoForWallet(walletAddress, tokenAddress) {
151
- const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons/${tokenAddress}`, {
152
- headers: {
153
- apiKey: this.apiKey,
154
- referer: 'https://app.rubic.exchange'
152
+ try {
153
+ const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons/${tokenAddress}`, {
154
+ headers: {
155
+ apiKey: this.apiKey,
156
+ referer: 'https://app.rubic.exchange'
157
+ }
158
+ });
159
+ if ('error' in res) {
160
+ this.logger?.customError('[TonApiService] ERROR IN fetchTokenInfoForWallet', res.error);
161
+ return { balance: '0' };
155
162
  }
156
- });
157
- if ('error' in res) {
158
- throw new Error(`[TonApiService] Error in fetchTokenInfoForWallet - ${res.error}`);
163
+ return res;
164
+ }
165
+ catch (err) {
166
+ this.logger?.customError('[TonApiService] ERROR IN fetchTokenInfoForWallet', err);
167
+ return { balance: '0' };
159
168
  }
160
- return res;
161
169
  }
162
170
  async fetchAllNonNullableTokensInfoForWallet(walletAddress) {
163
171
  const res = await this.httpClient.get(`${this.tonApiUrl}/v2/accounts/${walletAddress}/jettons`, {
@@ -2,15 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.web3PureStore = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
- const evm_web3_pure_1 = require("../web3-types/evm-web3-pure");
6
- const tron_web3_pure_1 = require("../web3-types/tron-web3-pure");
7
5
  const bitcoin_web3_pure_1 = require("../web3-types/bitcoin-web3-pure");
8
- const changenow_api_blockchain_1 = require("./changenow-api-blockchain");
6
+ const common_web3_pure_1 = require("../web3-types/common-web3-pure");
7
+ const evm_web3_pure_1 = require("../web3-types/evm-web3-pure");
9
8
  const icp_web3_pure_1 = require("../web3-types/icp-web3-pure");
9
+ const near_web3_pure_1 = require("../web3-types/near-web3-pure");
10
10
  const solana_web3_pure_1 = require("../web3-types/solana-web3-pure");
11
- const common_web3_pure_1 = require("../web3-types/common-web3-pure");
12
- const ton_web3_pure_1 = require("../web3-types/ton-web3-pure");
13
11
  const sui_web3_pure_1 = require("../web3-types/sui-web3-pure");
12
+ const ton_web3_pure_1 = require("../web3-types/ton-web3-pure");
13
+ const tron_web3_pure_1 = require("../web3-types/tron-web3-pure");
14
+ const changenow_api_blockchain_1 = require("./changenow-api-blockchain");
14
15
  exports.web3PureStore = {
15
16
  [core_1.CHAIN_TYPE.EVM]: new evm_web3_pure_1.EvmWeb3Pure(),
16
17
  [core_1.CHAIN_TYPE.SUI]: new sui_web3_pure_1.SuiWeb3Pure(),
@@ -21,6 +22,7 @@ exports.web3PureStore = {
21
22
  [core_1.CHAIN_TYPE.BITCOIN_DIAMOND]: new bitcoin_web3_pure_1.BitcoinWeb3Pure(),
22
23
  [core_1.CHAIN_TYPE.BITCOIN_GOLD]: new bitcoin_web3_pure_1.BitcoinWeb3Pure(),
23
24
  [core_1.CHAIN_TYPE.BSV]: new bitcoin_web3_pure_1.BitcoinWeb3Pure(),
25
+ [core_1.CHAIN_TYPE.NEAR]: new near_web3_pure_1.NearWeb3Pure(),
24
26
  // Common Web3
25
27
  [core_1.CHAIN_TYPE.RIPPLE]: new common_web3_pure_1.CommonWeb3Pure({
26
28
  cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.RIPPLE,
@@ -46,10 +48,6 @@ exports.web3PureStore = {
46
48
  cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.MONERO,
47
49
  regex: /^[48][a-zA-Z|\d]{94}([a-zA-Z|\d]{11})?$/
48
50
  }),
49
- [core_1.CHAIN_TYPE.NEAR]: new common_web3_pure_1.CommonWeb3Pure({
50
- cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.NEAR,
51
- regex: /(^[a-z0-9_-]{2,64}\.near$)|(^[0-9a-f]{64}$)/
52
- }),
53
51
  [core_1.CHAIN_TYPE.ALGORAND]: new common_web3_pure_1.CommonWeb3Pure({
54
52
  cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.ALGORAND,
55
53
  regex: /^[A-Z0-9]{58}/
@@ -0,0 +1,6 @@
1
+ import { CommonWeb3Pure } from './common-web3-pure';
2
+ export declare class NearWeb3Pure extends CommonWeb3Pure {
3
+ readonly nativeTokenAddress = "near";
4
+ constructor();
5
+ isAddressCorrect(address: string): Promise<boolean>;
6
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NearWeb3Pure = void 0;
4
+ const changenow_api_blockchain_1 = require("../constants/changenow-api-blockchain");
5
+ const common_web3_pure_1 = require("./common-web3-pure");
6
+ class NearWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
7
+ constructor() {
8
+ super({
9
+ cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.NEAR,
10
+ regex: /(^(?=.{2,64}$)([a-z0-9][a-z0-9\-_]*(?<![-_])\.)*[a-z0-9][a-z0-9\-_]*(?<![-_])(\.near)$)|(^[0-9a-f]{64}$)/
11
+ });
12
+ this.nativeTokenAddress = 'near';
13
+ }
14
+ async isAddressCorrect(address) {
15
+ if (this.isNativeAddress(address)) {
16
+ return true;
17
+ }
18
+ if (this.regEx) {
19
+ return this.regEx.test(address);
20
+ }
21
+ throw new Error(`Validation function is not implemented for ${this.constructor.name}`);
22
+ }
23
+ }
24
+ exports.NearWeb3Pure = NearWeb3Pure;