@deserialize/multi-vm-wallet 1.2.21 → 1.2.23

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.
@@ -610,30 +610,4 @@ async function parseTransferLogs(
610
610
  return { tokens, nfts };
611
611
  }
612
612
 
613
- /**
614
- * Helper function to create a client
615
- */
616
- export function createEVMClient(rpcUrl: string) {
617
- return createPublicClient({
618
- transport: http(rpcUrl),
619
- });
620
- }
621
-
622
- // Example usage:
623
- /*
624
- import { mainnet } from 'viem/chains';
625
-
626
- const client = createPublicClient({
627
- chain: mainnet,
628
- transport: http('https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY'),
629
- });
630
-
631
- const history = await getEVMTransactionHistoryWithAPI(
632
- client,
633
- '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb' as Address,
634
- 'https://api.etherscan.io/api',
635
- 'YOUR_ETHERSCAN_API_KEY'
636
- );
637
613
 
638
- console.log(history);
639
- */
@@ -2,6 +2,7 @@ import { Balance, ChainWalletConfig, SUPPORTED_VM, UserTokenBalance, TokenInfo }
2
2
  import { JsonRpcProvider, Contract, Wallet, TransactionRequest, TransactionResponse, TransactionReceipt, parseUnits, formatUnits } from 'ethers'
3
3
  import BN from 'bn.js'
4
4
  import { HelperAPI } from '../helpers';
5
+ import BigNumber from 'bignumber.js';
5
6
 
6
7
  const KYBER_BASE_URL = 'https://aggregator-api.kyberswap.com';
7
8
 
@@ -654,6 +655,24 @@ export const discoverTokens = async (wallet: string, chain: ChainWalletConfig):
654
655
  return formatBalances
655
656
  }
656
657
 
658
+ export function calcGasTotal(gasLimit = '0', gasPrice = '0') {
659
+ return new BN(gasLimit, 16).mul(new BN(gasPrice, 16)).toString();
660
+ }
661
+ export function toPrecisionWithoutTrailingZeros(n: number, precision: number) {
662
+ return new BigNumber(n)
663
+ .toPrecision(precision)
664
+ .replace(/(\.[0-9]*[1-9])0*|(\.0*)/u, '$1');
665
+ }
666
+
667
+ /**
668
+ * @param {number|string|BigNumber} value
669
+ * @param {number=} decimals
670
+ * @returns {BigNumber}
671
+ */
672
+ export function calcTokenAmount(value: number | string | BigNumber, decimals?: number): BigNumber {
673
+ const divisor = new BigNumber(10).pow(decimals ?? 0);
674
+ return new BigNumber(String(value)).div(divisor);
675
+ }
657
676
  //swaps
658
677
 
659
678
 
@@ -5,7 +5,15 @@ import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram, Transa
5
5
  import { ChainWalletConfig, UserTokenBalance, TokenInfo } from "../types";
6
6
  import { transactionSenderAndConfirmationWaiter } from "./transactionSender";
7
7
  import { BN } from "bn.js";
8
- import { Metaplex } from "@metaplex-foundation/js";
8
+ import { generateSigner, percentAmount } from '@metaplex-foundation/umi'
9
+ import {
10
+ createNft,
11
+ fetchDigitalAsset,
12
+ mplTokenMetadata,
13
+ } from '@metaplex-foundation/mpl-token-metadata'
14
+ import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
15
+
16
+ import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi-public-keys"
9
17
 
10
18
  const JUPITER_BASE_URL = 'https://lite-api.jup.ag';
11
19
 
@@ -271,15 +279,16 @@ export const getTransferNativeTransaction = async (from: Keypair, to: PublicKey,
271
279
  console.log('getTransferNativeTransaction: Completed');
272
280
  return transaction;
273
281
  }
274
- const getMetaTokenMetaplexData = (mintAddress: PublicKey, connection: Connection) => {
275
- const metaplex = Metaplex.make(connection);
276
- return metaplex.nfts().findByMint({ mintAddress: mintAddress });
282
+ const getMetaTokenMetaplexData = async (mintAddress: PublicKey, connection: Connection) => {
283
+ const umi = createUmi(connection.rpcEndpoint).use(mplTokenMetadata())
284
+ const ass = await fetchDigitalAsset(umi, mintAddress.toBase58() as unknown as UmiPublicKey)
285
+ return ass.metadata
286
+
277
287
  }
278
288
 
279
289
  export const getTokenInfo = async (tokenAddress: PublicKey, connection: Connection, programId?: PublicKey): Promise<TokenInfo> => {
280
290
  let mint: Mint
281
291
 
282
-
283
292
  const metaplexData = await getMetaTokenMetaplexData(tokenAddress, connection).catch(() => null);
284
293
  if (programId) {
285
294
  const mint = await getMint(connection, tokenAddress, "confirmed", programId)
package/utils/test.ts CHANGED
@@ -13,6 +13,7 @@ import { } from "./svm/transactionParsing";
13
13
  import { getEVMTransactionHistory } from "./evm/transactionParsing";
14
14
  import { createPublicClient, http, PublicClient } from "viem";
15
15
  import { base, baseGoerli } from "viem/chains";
16
+ import { getTokenInfo } from "./svm/utils";
16
17
  // const mnemonic = GenerateNewMnemonic()
17
18
 
18
19
 
@@ -54,10 +55,10 @@ const evmChainConfig: ChainWalletConfig = {
54
55
  }
55
56
 
56
57
 
57
- // const wallet = new SVMChainWallet(chainConfig, testUserKeyPair, 0)
58
- const wallet = new EVMChainWallet(evmChainConfig, evmPrivateKey2, 0)
58
+ const wallet = new SVMChainWallet(chainConfig, testUserKeyPair, 0)
59
+ // const wallet = new EVMChainWallet(evmChainConfig, evmPrivateKey2, 0)
59
60
  // console.log('wallet: ', wallet);
60
-
61
+ // getTokenInfo(new PublicKey("9BB6NFEcjBCtnNLFko2FqVQBq8HHM13kCyYcdQbgpump"), wallet.connection!).then(e => console.log('token info: ', e))
61
62
  // wallet.discoverToken().then(e => console.log('discovered tokens: ', e))
62
63
  // wallet.getNativeBalance().then(e => console.log('native balance: ', e))
63
64
  console.log('address: ', wallet.address);
@@ -99,17 +100,18 @@ const connection = new Connection(RPC_URL);
99
100
  // }).catch((error: any) => {
100
101
  // console.error("Error fetching transaction history:", error);
101
102
  // });
102
- const client = createPublicClient({
103
- chain: base,
104
- transport: http(base.rpcUrls.default.http[0]),
105
- })
106
-
107
- getEVMTransactionHistory(client as PublicClient, "0x9C82CE0e125F61AdE50BC0c19638F6Ba93d71D5e", {
108
- startBlock: BigInt(37427020)
109
- // before: "0xabc..."
110
- }).then((history: any) => {
111
- console.log("EVM Transaction History:", history);
112
- }).catch((error: any) => {
113
- console.error("Error fetching EVM transaction history:", error);
114
- });
103
+ // const client = createPublicClient({
104
+ // chain: base,
105
+ // transport: http(base.rpcUrls.default.http[0]),
106
+ // })
107
+
108
+ // getEVMTransactionHistory(client as PublicClient, "0x9C82CE0e125F61AdE50BC0c19638F6Ba93d71D5e", {
109
+ // startBlock: BigInt(37427020)
110
+ // // before: "0xabc..."
111
+ // }).then((history: any) => {
112
+ // console.log("EVM Transaction History:", history);
113
+ // }).catch((error: any) => {
114
+ // console.error("Error fetching EVM transaction history:", error);
115
+ // });
116
+
115
117