@cryptorubic/web3 0.11.0-alpha.1 → 0.11.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.
package/package.json CHANGED
@@ -1,27 +1,25 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.11.0-alpha.1",
3
+ "version": "0.11.0",
4
4
  "dependencies": {
5
- "tslib": "^2.3.0",
6
- "bignumber.js": "9.1.2",
7
- "@cryptorubic/core": "0.11.0-alpha.1",
8
- "viem": "^2.19.1",
9
- "web3-utils": "^4.3.1",
10
- "@ton/ton": "^15.1.0",
5
+ "@ethersproject/bignumber": "^5.8.0",
6
+ "@mysten/sui": "^1.24.0",
7
+ "@solana/spl-token": "*",
11
8
  "@solana/web3.js": "1.95.3",
12
9
  "@solflare-wallet/utl-sdk": "^1.4.0",
13
- "@ethersproject/bignumber": "^5.7.0",
14
- "@cryptorubic/tron-types": "0.11.0-alpha.1",
10
+ "@suiet/wallet-sdk": "^0.3.3",
11
+ "@ton/ton": "^15.1.0",
12
+ "axios": "*",
13
+ "bignumber.js": "9.1.2",
15
14
  "bitcoin-address-validation": "^2.2.3",
16
- "axios": "0.27.2",
15
+ "bs58": "^6.0.0",
17
16
  "crc-32": "^1.2.2",
17
+ "js-base64": "^3.7.8",
18
18
  "tronweb": "^6.0.0-beta.4",
19
- "@solana/spl-token": "0.2.0",
20
- "@mysten/sui": "^1.24.0",
21
- "@suiet/wallet-sdk": "^0.3.3",
22
- "bs58": "^6.0.0",
23
- "ethers": "5.7.2"
19
+ "tslib": "*",
20
+ "viem": "^2.33.1"
24
21
  },
22
+ "peerDependencies": {},
25
23
  "type": "commonjs",
26
24
  "main": "./src/index.js",
27
25
  "typings": "./src/index.d.ts",
@@ -31,5 +29,12 @@
31
29
  "author": {
32
30
  "name": "Sleta Dmitrii"
33
31
  },
32
+ "exports": {
33
+ "./package.json": "./package.json",
34
+ ".": {
35
+ "types": "./src/index.d.ts",
36
+ "default": "./src/index.js"
37
+ }
38
+ },
34
39
  "types": "./src/index.d.ts"
35
40
  }
@@ -1,2 +1,2 @@
1
- import { AbiItem } from 'web3-utils';
1
+ import { AbiItem } from '../../../utils/models/abi-types';
2
2
  export declare const TRON_MULTICALL_ABI: AbiItem[];
@@ -2,7 +2,7 @@ import { BlockchainName, TokenAmount } from '@cryptorubic/core';
2
2
  import { AllowanceInfo } from './common-types';
3
3
  import { AbstractAdapter } from '../abstract-adapter';
4
4
  import { EvmTransactionConfig } from '../../../utils/models/evm-transaction-config';
5
- import { TronTransactionConfig } from '@cryptorubic/tron-types';
5
+ import { TronTransactionConfig } from '../../../utils/models/tron-transaction-config';
6
6
  export interface ApproveAdapter<T> extends AbstractAdapter<any, any, BlockchainName> {
7
7
  /**
8
8
  * @param fromTokenAddress erc20 address of checked token
@@ -1,6 +1,6 @@
1
1
  import { Abi, MulticallResponse, MulticallParameters } from 'viem';
2
2
  import { AbstractAdapter } from './abstract-adapter';
3
- import { AddressLookupTableAccount, Connection, Keypair, PublicKey, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
+ import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
4
4
  import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
5
5
  import { EvmTransactionConfig } from '../../utils/models/evm-transaction-config';
6
6
  import BigNumber from 'bignumber.js';
@@ -32,4 +32,8 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, Connectio
32
32
  getTxWithPayer(tx: VersionedTransaction, feePayer: string): Promise<VersionedTransaction>;
33
33
  deserializeTransaction(data: string): VersionedTransaction;
34
34
  serializeTransactionToBase58(tx: VersionedTransaction): string;
35
+ createTransferData(fromToken: PriceTokenAmount, walletAddress: string, receiver: string, convertToVersionedTx: boolean): Promise<Transaction | VersionedTransaction>;
36
+ createNativeTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromWeiAmount: string): Transaction;
37
+ createTokenTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromTokenAddress: string, fromWeiAmount: string): Promise<Transaction>;
38
+ getLatestBlockhash(): Promise<string>;
35
39
  }
@@ -9,7 +9,7 @@ const web3_pure_1 = require("../../utils/web3-pure");
9
9
  const bignumber_js_1 = require("bignumber.js");
10
10
  const solana_tokens_service_1 = require("./utils/solana-tokens-service");
11
11
  const bs58_1 = require("bs58");
12
- const utils_1 = require("ethers/lib/utils");
12
+ const js_base64_1 = require("js-base64");
13
13
  exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
14
14
  class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
15
15
  constructor(rpcList, httpClient, logger) {
@@ -115,7 +115,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
115
115
  return accounts.filter((v) => !!v);
116
116
  }
117
117
  async createVersionedTransaction(instructions, walletAddress, addressLookupTableAccounts = []) {
118
- const { blockhash } = await this.public.getLatestBlockhash();
118
+ const blockhash = await this.getLatestBlockhash();
119
119
  const message = new web3_js_1.TransactionMessage({
120
120
  instructions,
121
121
  payerKey: new web3_js_1.PublicKey(walletAddress),
@@ -157,11 +157,53 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
157
157
  return new web3_js_1.VersionedTransaction(newMsg);
158
158
  }
159
159
  deserializeTransaction(data) {
160
- const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') : utils_1.base64.decode(data);
160
+ const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') : js_base64_1.Base64.toUint8Array(data);
161
161
  return web3_js_1.VersionedTransaction.deserialize(decodedData);
162
162
  }
163
163
  serializeTransactionToBase58(tx) {
164
164
  return bs58_1.default.encode(tx.serialize());
165
165
  }
166
+ async createTransferData(fromToken, walletAddress, receiver, convertToVersionedTx) {
167
+ const fromAddress = new web3_js_1.PublicKey(walletAddress);
168
+ const toAddress = new web3_js_1.PublicKey(receiver);
169
+ const transaction = fromToken.isNative
170
+ ? this.createNativeTransfer(fromAddress, toAddress, fromToken.stringWeiAmount)
171
+ : await this.createTokenTransfer(fromAddress, toAddress, fromToken.address, fromToken.stringWeiAmount);
172
+ if (convertToVersionedTx) {
173
+ const blockhash = await this.getLatestBlockhash();
174
+ const message = new web3_js_1.TransactionMessage({
175
+ payerKey: fromAddress,
176
+ recentBlockhash: blockhash,
177
+ instructions: transaction.instructions
178
+ }).compileToV0Message();
179
+ return new web3_js_1.VersionedTransaction(message);
180
+ }
181
+ return transaction;
182
+ }
183
+ createNativeTransfer(fromAddress, toAddress, fromWeiAmount) {
184
+ return new web3_js_1.Transaction().add(web3_js_1.SystemProgram.transfer({
185
+ fromPubkey: fromAddress,
186
+ toPubkey: toAddress,
187
+ lamports: BigInt(fromWeiAmount)
188
+ }));
189
+ }
190
+ async createTokenTransfer(fromAddress, toAddress, fromTokenAddress, fromWeiAmount) {
191
+ const mintTokenAccount = new web3_js_1.PublicKey(fromTokenAddress);
192
+ const [fromATA, toATA] = await Promise.all([
193
+ (0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, fromAddress),
194
+ (0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, toAddress)
195
+ ]);
196
+ const transaction = new web3_js_1.Transaction();
197
+ const receiverAccountInfo = await this.public.getAccountInfo(toATA);
198
+ if (!receiverAccountInfo) {
199
+ transaction.add((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromAddress, toATA, toAddress, mintTokenAccount));
200
+ }
201
+ transaction.add((0, spl_token_1.createTransferInstruction)(fromATA, toATA, fromAddress, BigInt(fromWeiAmount)));
202
+ return transaction;
203
+ }
204
+ async getLatestBlockhash() {
205
+ const { blockhash } = await this.public.getLatestBlockhash();
206
+ return blockhash;
207
+ }
166
208
  }
167
209
  exports.SolanaAdapter = SolanaAdapter;
@@ -1,25 +1,26 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { AbstractAdapter } from './abstract-adapter';
3
- import { ContractMulticallResponse, MethodData, TronWeb3PrimitiveType } from '@cryptorubic/tron-types';
4
3
  import { TronWeb } from 'tronweb';
5
- import { AbiFragment } from 'tronweb/lib/commonjs/types';
6
4
  import { ICustomLogger, PriceTokenAmount, Token, TokenAmount, TronBlockchainName } from '@cryptorubic/core';
7
5
  import { TronTransactionConfig } from '../../utils/models/tron-transaction-config';
8
6
  import { TronParameters } from '../../utils/models/tron-parameters';
9
7
  import { Abi } from 'viem';
10
8
  import { ApproveAdapter } from './models/approve-adapter';
11
9
  import { AllowanceInfo } from './models/common-types';
10
+ import { ContractMulticallResponse } from '../../utils/models/contract-multicall-response';
11
+ import { TronWeb3PrimitiveType } from '../../utils/models/primitive-types';
12
+ import { MethodData } from '../../utils/models/method-data';
12
13
  export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> implements ApproveAdapter<TronTransactionConfig> {
13
14
  private readonly multicallAddress;
14
15
  needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
15
16
  constructor(rpcList: string[], logger?: ICustomLogger);
16
17
  checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
17
- multicallContractsMethods<Output extends TronWeb3PrimitiveType>(contractAbi: readonly AbiFragment[], contractsData: {
18
+ multicallContractsMethods<Output extends TronWeb3PrimitiveType>(contractAbi: any, contractsData: {
18
19
  contractAddress: string;
19
20
  methodsData: MethodData[];
20
- }[]): Promise<ContractMulticallResponse<Output>[][]>;
21
+ }[]): Promise<ContractMulticallResponse<any>[][]>;
21
22
  private multicall;
22
- read<T>(contractAddress: string, contractAbi: readonly AbiFragment[], methodName: string, methodArguments?: unknown[]): Promise<T>;
23
+ read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
23
24
  private multicallContractsMethodsByOne;
24
25
  getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
25
26
  callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
@@ -4,7 +4,7 @@ export interface SolanaWeb3 {
4
4
  toBytes(): Uint8Array;
5
5
  };
6
6
  isConnected: boolean;
7
- signTransaction(transaction: Transaction): Promise<Transaction>;
7
+ signTransaction(transaction: Transaction): Promise<Transaction | VersionedTransaction>;
8
8
  signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
9
9
  signMessage(message: Uint8Array, encoding: string): Promise<{
10
10
  signature: Uint8Array;
@@ -2,7 +2,6 @@ import { CommonWeb3Pure } from './common-web3-pure';
2
2
  import { TronTransactionConfig } from '../models/tron-transaction-config';
3
3
  import { TronParameters } from '../models/tron-parameters';
4
4
  import { TronWeb3PrimitiveType, Web3PrimitiveType } from '../models/primitive-types';
5
- import { FunctionFragment } from 'tronweb/src/types/ABI';
6
5
  import { AbiItem } from '../models/abi-types';
7
6
  export declare class TronWeb3Pure extends CommonWeb3Pure {
8
7
  constructor();
@@ -16,7 +15,7 @@ export declare class TronWeb3Pure extends CommonWeb3Pure {
16
15
  * @param methodArguments Parameters to encode.
17
16
  * @returns An ABI encoded function call. Means function signature + parameters.
18
17
  */
19
- static encodeFunctionCall(contractAbi: FunctionFragment[], methodName: string, methodArguments: unknown[]): string;
18
+ static encodeFunctionCall(contractAbi: any[], methodName: string, methodArguments: unknown[]): string;
20
19
  static encodeMethodSignature(methodSignature: string, parameters: TronParameters): string;
21
20
  /**
22
21
  * Decodes method result using its JSON interface object and given parameters.
@@ -24,7 +23,7 @@ export declare class TronWeb3Pure extends CommonWeb3Pure {
24
23
  * @param response Bytes code returned after method call.
25
24
  * @returns Parsed method output.
26
25
  */
27
- static decodeMethodOutput(outputAbi: FunctionFragment[], response: string): Web3PrimitiveType;
26
+ static decodeMethodOutput(outputAbi: any[], response: string): Web3PrimitiveType;
28
27
  private static flattenTypesToString;
29
28
  private static flattenTypesToArray;
30
29
  private static flattenParameters;