@cryptorubic/core 0.0.18 → 0.0.37-alpha-1212.0

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 (120) hide show
  1. package/package.json +26 -15
  2. package/src/index.d.ts +30 -6
  3. package/src/index.js +31 -6
  4. package/src/lib/blockchains/backend-labels.d.ts +13 -3
  5. package/src/lib/blockchains/backend-labels.js +14 -4
  6. package/src/lib/blockchains/blockchain-id.d.ts +1 -1
  7. package/src/lib/blockchains/blockchain-id.js +14 -3
  8. package/src/lib/blockchains/blockchain-name.d.ts +31 -9
  9. package/src/lib/blockchains/blockchain-name.js +17 -7
  10. package/src/lib/blockchains/blockchains-info.d.ts +3 -2
  11. package/src/lib/blockchains/blockchains-info.js +6 -3
  12. package/src/lib/blockchains/chain-type-storage.d.ts +3 -3
  13. package/src/lib/blockchains/chain-type-storage.js +2 -0
  14. package/src/lib/blockchains/chain-type.d.ts +2 -0
  15. package/src/lib/blockchains/chain-type.js +3 -1
  16. package/src/lib/blockchains/wrapped-addresses.d.ts +2 -2
  17. package/src/lib/blockchains/wrapped-addresses.js +13 -3
  18. package/src/lib/models/api/celer-refund-request.interface.d.ts +5 -0
  19. package/src/lib/models/api/claim-request.interface.d.ts +5 -0
  20. package/src/lib/models/api/cross-chain-provider.interface.d.ts +12 -0
  21. package/src/lib/models/api/error.interface.d.ts +14 -0
  22. package/src/lib/models/api/estimates.interface.d.ts +11 -0
  23. package/src/lib/models/api/failed-quote.interface.d.ts +17 -0
  24. package/src/lib/models/api/fee-info.d.ts +19 -0
  25. package/src/lib/models/api/fee-info.js +2 -0
  26. package/src/lib/models/api/fees.interface.d.ts +14 -0
  27. package/src/lib/models/api/fees.interface.js +2 -0
  28. package/src/lib/models/api/foreign-blacklist.interface.d.ts +4 -0
  29. package/src/lib/models/api/foreign-blacklist.interface.js +6 -0
  30. package/src/lib/models/api/gas-fee.interface.d.ts +6 -0
  31. package/src/lib/models/api/gas-fee.interface.js +2 -0
  32. package/src/lib/models/api/on-chain-provider.interface.d.ts +12 -0
  33. package/src/lib/models/api/on-chain-provider.interface.js +2 -0
  34. package/src/lib/models/api/percent-fee.interface.d.ts +11 -0
  35. package/src/lib/models/api/percent-fee.interface.js +2 -0
  36. package/src/lib/models/api/protocol-fee.interface.d.ts +5 -0
  37. package/src/lib/models/api/protocol-fee.interface.js +2 -0
  38. package/src/lib/models/api/provider-chain.interface.d.ts +11 -0
  39. package/src/lib/models/api/provider-chain.interface.js +2 -0
  40. package/src/lib/models/api/provider-fee.interface.d.ts +5 -0
  41. package/src/lib/models/api/provider-fee.interface.js +2 -0
  42. package/src/lib/models/api/quote-all.interface.d.ts +17 -0
  43. package/src/lib/models/api/quote-all.interface.js +2 -0
  44. package/src/lib/models/api/quote-options.interface.d.ts +15 -0
  45. package/src/lib/models/api/quote-options.interface.js +2 -0
  46. package/src/lib/models/api/quote-request.interface.d.ts +11 -0
  47. package/src/lib/models/api/quote-request.interface.js +2 -0
  48. package/src/lib/models/api/quote-response.interface.d.ts +51 -0
  49. package/src/lib/models/api/quote-response.interface.js +2 -0
  50. package/src/lib/models/api/quote-tokens.interface.d.ts +5 -0
  51. package/src/lib/models/api/quote-tokens.interface.js +2 -0
  52. package/src/lib/models/api/quote-trade.interface.d.ts +8 -0
  53. package/src/lib/models/api/quote-trade.interface.js +2 -0
  54. package/src/lib/models/api/routing.interface.d.ts +7 -0
  55. package/src/lib/models/api/routing.interface.js +2 -0
  56. package/src/lib/models/api/swap-best-request.interface.d.ts +2 -0
  57. package/src/lib/models/api/swap-best-request.interface.js +2 -0
  58. package/src/lib/models/api/swap-request.interface.d.ts +10 -0
  59. package/src/lib/models/api/swap-request.interface.js +2 -0
  60. package/src/lib/models/api/swap-response.interface.d.ts +24 -0
  61. package/src/lib/models/api/swap-response.interface.js +2 -0
  62. package/src/lib/models/api/swap-type.d.ts +1 -0
  63. package/src/lib/models/api/swap-type.js +2 -0
  64. package/src/lib/models/api/token-amount.interface.d.ts +4 -0
  65. package/src/lib/models/api/token-amount.interface.js +2 -0
  66. package/src/lib/models/api/token.inerface.d.ts +11 -0
  67. package/src/lib/models/api/token.inerface.js +2 -0
  68. package/src/lib/models/api/ton-transaction.interface.d.ts +6 -0
  69. package/src/lib/models/api/ton-transaction.interface.js +2 -0
  70. package/src/lib/models/api/transaction.interface.d.ts +11 -0
  71. package/src/lib/models/api/transaction.interface.js +2 -0
  72. package/src/lib/models/api/unique-provider-info.interface.d.ts +13 -0
  73. package/src/lib/models/api/unique-provider-info.interface.js +2 -0
  74. package/src/lib/models/api/ws-quote-error.interface.d.ts +21 -0
  75. package/src/lib/models/api/ws-quote-error.interface.js +2 -0
  76. package/src/lib/models/api/ws-quote-request.interface.d.ts +4 -0
  77. package/src/lib/models/api/ws-quote-request.interface.js +2 -0
  78. package/src/lib/models/api/ws-quote-response.interface.d.ts +21 -0
  79. package/src/lib/models/api/ws-quote-response.interface.js +2 -0
  80. package/src/lib/models/custom-logger.d.ts +2 -1
  81. package/src/lib/providers/backend-onchain-providers.d.ts +279 -0
  82. package/src/lib/providers/backend-onchain-providers.js +178 -0
  83. package/src/lib/providers/cross-chain-trade-type.d.ts +16 -1
  84. package/src/lib/providers/cross-chain-trade-type.js +17 -2
  85. package/src/lib/providers/from-backend-cross-chain-providers.js +17 -2
  86. package/src/lib/providers/on-chain-trade-type.d.ts +21 -2
  87. package/src/lib/providers/on-chain-trade-type.js +25 -6
  88. package/src/lib/providers/to-backend-cross-chain-providers.d.ts +16 -1
  89. package/src/lib/providers/to-backend-cross-chain-providers.js +17 -2
  90. package/src/lib/tokens/constants/native-token-list.d.ts +2 -2
  91. package/src/lib/tokens/constants/native-token-list.js +291 -19
  92. package/src/lib/tokens/constants/wrapped-native-tokens.d.ts +1 -1
  93. package/src/lib/tokens/constants/wrapped-native-tokens.js +80 -17
  94. package/src/lib/tokens/price-token-amount-struct.d.ts +1 -1
  95. package/src/lib/tokens/price-token-amount.d.ts +2 -1
  96. package/src/lib/tokens/price-token-amount.js +5 -2
  97. package/src/lib/tokens/price-token-struct.d.ts +1 -1
  98. package/src/lib/tokens/price-token.d.ts +16 -1
  99. package/src/lib/tokens/price-token.js +22 -0
  100. package/src/lib/tokens/token-amount-struct.d.ts +1 -1
  101. package/src/lib/tokens/token-amount.d.ts +2 -1
  102. package/src/lib/tokens/token-amount.js +4 -1
  103. package/src/lib/tokens/token-base-struct.d.ts +1 -1
  104. package/src/lib/tokens/token-struct.d.ts +1 -1
  105. package/src/lib/tokens/token.d.ts +3 -2
  106. package/src/lib/tokens/token.js +16 -11
  107. package/src/lib/utils/cache.decorator.d.ts +1 -1
  108. package/src/lib/utils/cache.decorator.js +2 -2
  109. package/src/lib/models/quote-all-response.d.ts +0 -15
  110. package/src/lib/models/quote-best-response.d.ts +0 -3
  111. package/src/lib/models/quote-request.d.ts +0 -18
  112. package/src/lib/models/route.d.ts +0 -80
  113. package/src/lib/models/swap-request.d.ts +0 -7
  114. package/src/lib/models/swap-response.d.ts +0 -82
  115. /package/src/lib/models/{quote-all-response.js → api/celer-refund-request.interface.js} +0 -0
  116. /package/src/lib/models/{quote-best-response.js → api/claim-request.interface.js} +0 -0
  117. /package/src/lib/models/{quote-request.js → api/cross-chain-provider.interface.js} +0 -0
  118. /package/src/lib/models/{route.js → api/error.interface.js} +0 -0
  119. /package/src/lib/models/{swap-request.js → api/estimates.interface.js} +0 -0
  120. /package/src/lib/models/{swap-response.js → api/failed-quote.interface.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  import { TokenStruct } from './token-struct';
2
2
  import { TokenBaseStruct } from './token-base-struct';
3
3
  import BigNumber from 'bignumber.js';
4
- import { BlockchainName } from "../blockchains/blockchain-name";
5
- import { ICustomLogger } from "../models/custom-logger";
4
+ import { BlockchainName } from '../blockchains/blockchain-name';
5
+ import { ICustomLogger } from '../models/custom-logger';
6
6
  export declare class Token<Blockchain extends BlockchainName = BlockchainName> {
7
7
  /**
8
8
  * Maps provided tokens to their addresses.
@@ -20,6 +20,7 @@ export declare class Token<Blockchain extends BlockchainName = BlockchainName> {
20
20
  constructor(tokenStruct: TokenStruct<Blockchain>);
21
21
  isEqualTo(token: TokenBaseStruct): boolean;
22
22
  isEqualToTokens(tokens: TokenBaseStruct[]): boolean;
23
+ clone(tokenStruct?: Partial<TokenStruct>): Token;
23
24
  static toWei(amount: BigNumber | string | number, decimals?: number, roundingMode?: BigNumber.RoundingMode): string;
24
25
  /**
25
26
  * Converts amount from Wei to Ether units.
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Token = void 0;
4
4
  const bignumber_js_1 = require("bignumber.js");
5
- const blockchains_info_1 = require("../blockchains/blockchains-info");
6
5
  const wrapped_addresses_1 = require("../blockchains/wrapped-addresses");
6
+ const blockchain_name_1 = require("../blockchains/blockchain-name");
7
7
  class Token {
8
8
  /**
9
9
  * Maps provided tokens to their addresses.
@@ -12,18 +12,20 @@ class Token {
12
12
  return tokens.map((token) => token.address);
13
13
  }
14
14
  get isNative() {
15
- const nativeAddress = '0x0000000000000000000000000000000000000000';
16
- return nativeAddress.toLowerCase() === this.address.toLowerCase();
15
+ if (this.blockchain === blockchain_name_1.BLOCKCHAIN_NAME.NEAR)
16
+ return this.address.toLowerCase() === 'near';
17
+ if (this.blockchain === blockchain_name_1.BLOCKCHAIN_NAME.SOLANA)
18
+ return this.address.toLowerCase() === 'so11111111111111111111111111111111111111111';
19
+ if (this.blockchain === blockchain_name_1.BLOCKCHAIN_NAME.SUI)
20
+ return this.address.toLowerCase() === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::sui';
21
+ return this.address.toLowerCase() === '0x0000000000000000000000000000000000000000';
17
22
  }
18
23
  get isWrapped() {
19
- if (blockchains_info_1.BlockchainsInfo.isEvmBlockchainName(this.blockchain)) {
20
- const address = wrapped_addresses_1.wrappedAddress[this.blockchain];
21
- if (!address) {
22
- return false;
23
- }
24
- return address.toLowerCase() === this.address.toLowerCase();
24
+ const address = wrapped_addresses_1.wrappedAddress[this.blockchain];
25
+ if (!address) {
26
+ return false;
25
27
  }
26
- return false;
28
+ return address.toLowerCase() === this.address.toLowerCase();
27
29
  }
28
30
  get asStruct() {
29
31
  return {
@@ -42,11 +44,14 @@ class Token {
42
44
  this.decimals = tokenStruct.decimals;
43
45
  }
44
46
  isEqualTo(token) {
45
- return token.blockchain === this.blockchain && (token.address.toLowerCase() === this.address.toLowerCase());
47
+ return token.blockchain === this.blockchain && token.address.toLowerCase() === this.address.toLowerCase();
46
48
  }
47
49
  isEqualToTokens(tokens) {
48
50
  return tokens.some((token) => this.isEqualTo(token));
49
51
  }
52
+ clone(tokenStruct) {
53
+ return new Token({ ...this, ...tokenStruct });
54
+ }
50
55
  static toWei(amount, decimals = 18, roundingMode) {
51
56
  return new bignumber_js_1.default(amount || 0).times(new bignumber_js_1.default(10).pow(decimals)).toFixed(0, roundingMode);
52
57
  }
@@ -1,4 +1,4 @@
1
- import { CacheConfig } from "./models/cache-config";
1
+ import { CacheConfig } from './models/cache-config';
2
2
  type DecoratorSignature = <T>(_: Object, __: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
3
3
  /**
4
4
  * Decorator, used to cache calculated result of functions.
@@ -48,7 +48,7 @@ function modifyMethodCacheDescriptor(cacheConfig, descriptor) {
48
48
  }
49
49
  return resolved.value;
50
50
  })
51
- .catch(err => {
51
+ .catch((err) => {
52
52
  instanceStore.delete(key);
53
53
  throw err;
54
54
  });
@@ -65,7 +65,7 @@ function modifyMethodCacheDescriptor(cacheConfig, descriptor) {
65
65
  return result.value;
66
66
  }
67
67
  if (result instanceof Promise) {
68
- const handledPromise = result.catch(err => {
68
+ const handledPromise = result.catch((err) => {
69
69
  instanceStore.delete(key);
70
70
  throw err;
71
71
  });
@@ -1,15 +0,0 @@
1
- import { QuoteRequest } from "./quote-request";
2
- import { Route } from "./route";
3
- import { CrossChainTradeType, OnChainTradeType } from "@cryptorubic/core";
4
- export interface QuoteAllResponse {
5
- quote: QuoteRequest;
6
- routes: Route;
7
- failed?: {
8
- providerType: CrossChainTradeType | OnChainTradeType;
9
- data: {
10
- code: number;
11
- reason: string;
12
- data?: object;
13
- };
14
- }[];
15
- }
@@ -1,3 +0,0 @@
1
- import { Route } from "./route";
2
- export interface QuoteBestResponse extends Route {
3
- }
@@ -1,18 +0,0 @@
1
- import { BlockchainName, CrossChainTradeType, OnChainTradeType } from "@cryptorubic/core";
2
- export interface QuoteRequest {
3
- showFailedRoutes?: boolean;
4
- srcTokenAddress: string;
5
- srcTokenBlockchain: BlockchainName;
6
- srcTokenAmount: string;
7
- dstTokenAddress: string;
8
- dstTokenBlockchain: BlockchainName;
9
- integratorAddress?: string;
10
- fromAddress?: string;
11
- slippage?: number;
12
- receiver?: string | undefined;
13
- nativeBlacklist?: (CrossChainTradeType | OnChainTradeType)[];
14
- preferredProvider?: CrossChainTradeType | OnChainTradeType;
15
- foreignBlacklist?: string;
16
- timeout?: number;
17
- enableTestnets?: boolean;
18
- }
@@ -1,80 +0,0 @@
1
- import { CrossChainTradeType, OnChainTradeType } from "@cryptorubic/core";
2
- export interface Route {
3
- id: string;
4
- swapType: 'cross-chain' | 'on-chain';
5
- providerType: CrossChainTradeType | OnChainTradeType;
6
- estimate: {
7
- destinationTokenAmount: string;
8
- destinationTokenMinAmount: string;
9
- destinationWeiAmount: string;
10
- destinationWeiMinAmount: string;
11
- destinationUsdAmount?: number;
12
- destinationUsdMinAmount?: number;
13
- durationInMinutes: number;
14
- slippage: number;
15
- priceImpact: number | null;
16
- };
17
- fees: {
18
- gasTokenFees: {
19
- gas: {
20
- gasPrice: string;
21
- gasLimit: string;
22
- totalWeiAmount: string;
23
- totalUsdAmount: number;
24
- };
25
- protocol: {
26
- fixedAmount: string;
27
- fixedWeiAmount: string;
28
- fixedUsdAmount: number;
29
- };
30
- provider: {
31
- fixedAmount: string;
32
- fixedWeiAmount: string;
33
- fixedUsdAmount: number;
34
- };
35
- nativeToken: {
36
- address: string;
37
- decimals: number;
38
- symbol: string;
39
- name: string;
40
- blockchainId: number;
41
- };
42
- };
43
- percentFees: {
44
- percent: number;
45
- token: {
46
- address: string;
47
- decimals: number;
48
- symbol: string;
49
- name: string;
50
- blockchainId: number;
51
- } | null;
52
- };
53
- };
54
- routing: {
55
- type: 'cross-chain' | 'on-chain';
56
- provider: string;
57
- path: {
58
- address: string;
59
- decimals: number;
60
- symbol: string;
61
- name: string;
62
- blockchainId: number;
63
- amount: string;
64
- }[];
65
- }[];
66
- transaction: {
67
- approvalAddress?: string;
68
- data?: string;
69
- to?: string;
70
- value?: string;
71
- depositAddress?: string;
72
- extraFields?: object;
73
- feeLimit?: string;
74
- };
75
- warnings: {
76
- code: number;
77
- reason: string;
78
- data?: object;
79
- }[];
80
- }
@@ -1,7 +0,0 @@
1
- import { QuoteRequest } from "./quote-request";
2
- export interface SwapRequest extends Omit<QuoteRequest, 'nativeBlacklist' | 'fromAddress' | 'showFailedRoutes' | 'preferredProvider' | 'enableTestnets'> {
3
- id: string;
4
- enableChecks?: boolean;
5
- fromAddress: string;
6
- receiver: string | undefined;
7
- }
@@ -1,82 +0,0 @@
1
- import { QuoteRequest } from "./quote-request";
2
- export interface SwapResponse {
3
- quote: QuoteRequest;
4
- estimate: {
5
- destinationTokenAmount: string;
6
- destinationTokenMinAmount: string;
7
- destinationWeiAmount: string;
8
- destinationWeiMinAmount: string;
9
- destinationUsdAmount?: number;
10
- destinationUsdMinAmount?: number;
11
- durationInMinutes: number;
12
- slippage: number;
13
- priceImpact: number | null;
14
- };
15
- fees: {
16
- gasTokenFees: {
17
- gas: {
18
- gasPrice: string;
19
- gasLimit: string;
20
- totalWeiAmount: string;
21
- totalUsdAmount: number;
22
- };
23
- protocol: {
24
- fixedAmount: string;
25
- fixedWeiAmount: string;
26
- fixedUsdAmount: number;
27
- };
28
- provider: {
29
- fixedAmount: string;
30
- fixedWeiAmount: string;
31
- fixedUsdAmount: number;
32
- };
33
- nativeToken: {
34
- address: string;
35
- decimals: number;
36
- symbol: string;
37
- name: string;
38
- blockchainId: number;
39
- };
40
- };
41
- percentFees: {
42
- percent: number;
43
- token: {
44
- address: string;
45
- decimals: number;
46
- symbol: string;
47
- name: string;
48
- blockchainId: number;
49
- } | null;
50
- };
51
- };
52
- routing: {
53
- type: 'cross-chain' | 'on-chain';
54
- provider: string;
55
- path: {
56
- address: string;
57
- decimals: number;
58
- symbol: string;
59
- name: string;
60
- blockchainId: number;
61
- amount: string;
62
- }[];
63
- }[];
64
- transaction: {
65
- approvalAddress?: string;
66
- data?: string;
67
- to?: string;
68
- value?: string;
69
- depositAddress?: string;
70
- extraFields?: object;
71
- feeLimit?: string;
72
- };
73
- warnings: {
74
- code: number;
75
- reason: string;
76
- data?: object;
77
- }[];
78
- uniqueInfo?: {
79
- changenowId?: string;
80
- rangoRequestId?: string;
81
- };
82
- }