Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coinmasters/toolbox-evm

Package Overview
Dependencies
Maintainers
2
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinmasters/toolbox-evm - npm Package Compare versions

Comparing version 11.0.31 to 11.0.32

dist/index-02aaf711.cjs

30

dist/index.d.ts

@@ -102,3 +102,3 @@ import type { Asset } from '@coinmasters/types';

}>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -146,3 +146,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

};
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -270,3 +270,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

};
getBalance(address: any): Promise<(AssetValue | undefined)[]>;
getBalance(pubkey: any): Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -348,3 +348,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

};
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -434,3 +434,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

export declare const estimateMaxSendableAmount: ({ toolbox, from, caip, memo, feeOptionKey, assetValue, abi, funcName, funcParams, contractAddress, txOverrides, }: EVMMaxSendableAmountsParams) => Promise<any>;
export declare const estimateMaxSendableAmount: ({ toolbox, from, caip, memo, feeOptionKey, assetValue, abi, funcName, funcParams, contractAddress, txOverrides, }: EVMMaxSendableAmountsParams) => Promise<0 | AssetValue>;

@@ -478,3 +478,3 @@ export declare type EthereumWindowProvider = BrowserProvider & {

}) => {
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -548,3 +548,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

export declare const getBalance: ({ provider, api, address, chain, }: {
export declare const getBalance: ({ provider, api, pubkey, chain, }: {
provider: JsonRpcProvider | BrowserProvider;

@@ -556,3 +556,3 @@ api: CovalentApiType | EthplorerApiType;

chain: EVMChain;
}) => Promise<any>;
}) => Promise<AssetValue | undefined>;

@@ -592,3 +592,3 @@ export declare const getChecksumAddressFromAsset: (asset: Asset, chain: EVMChain) => string;

};
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -655,3 +655,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

}) => {
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -755,3 +755,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

}>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -808,3 +808,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

}>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean | undefined) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -842,3 +842,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

};
getBalance(address: any): Promise<(AssetValue | undefined)[]>;
getBalance(pubkey: any): Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -938,3 +938,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

};
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -1056,3 +1056,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

}>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<any>;
getBalance: (address: any, potentialScamFilter?: boolean) => Promise<AssetValue | undefined>;
approve: (params: ApproveParams) => Promise<string>;

@@ -1059,0 +1059,0 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>;

@@ -1,2 +0,2 @@

import { aY as s, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as i, bk as A, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as k, bb as g, b5 as w, bi as E, aU as M, bd as p, bj as S, aV as W, b1 as m, ba as C, be as B, bg as V, bf as u, b6 as N, b9 as P, aX as f, bh as D, b7 as H } from "./index-f6365e56.js";
import { aY as s, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as i, bk as A, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as k, bb as g, b5 as w, bi as E, aU as M, bd as p, bj as S, aV as W, b1 as m, ba as C, be as B, bg as V, bf as u, b6 as N, b9 as P, aX as f, bh as D, b7 as H } from "./index-c9196555.js";
import "@pioneer-platform/helpers";

@@ -3,0 +3,0 @@ export {

@@ -6,3 +6,3 @@ {

"ethers": "6.9.0",
"@coinmasters/types": "4.7.31"
"@coinmasters/types": "4.7.32"
},

@@ -19,3 +19,3 @@ "description": "THORSwap evm",

"vitest": "0.34.6",
"@internal/config": "2.7.31"
"@internal/config": "2.7.32"
},

@@ -51,3 +51,3 @@ "eslintConfig": {

"types": "./dist/index.d.ts",
"version": "11.0.31",
"version": "11.0.32",
"scripts": {

@@ -54,0 +54,0 @@ "build": "vite build",

@@ -184,6 +184,5 @@ import {

if (!caip) throw new Error('Missing caip');
const balanceData = await toolbox.getBalance([{ address: from }]);
const balanceData = await toolbox.getBalance({ address: from });
if (!balanceData) return 0;
console.log(tag, 'balanceData: ', balanceData);
console.log(tag, 'assetValue: ', assetValue);

@@ -207,25 +206,6 @@ //caip is the chain address identifier protocol

const balance = balanceData.find(({ symbol, chain }) => {
if (assetValue) {
console.log(tag, 'assetValue.symbol: ', assetValue.symbol);
return symbol === assetValue.symbol;
} else {
console.log(tag, 'chain: ', chain);
const assetSymbol = AssetValue.fromChainOrSignature(chain)?.symbol;
return symbol === assetSymbol;
}
});
console.log(tag, 'balance: ', balance);
const fees = (await toolbox.estimateGasPrices())[feeOptionKey];
console.log(tag, 'fees: ', fees);
if (!balance) return AssetValue.fromChainOrSignature(assetValue.chain, 0);
if (
assetValue &&
(balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol)
) {
return balance;
}
//TODO this makes no sense to me. If you are sending native token, its not a smart contract fee

@@ -272,3 +252,3 @@ //and if you are sending a token the fee amount of the gass asset has nothing to do with the token max sendable amount

// return AssetValue.fromChainOrSignature(balance.chain, maxSendableAmount.getValue('string'));
return balance;
return balanceData;
} catch (e) {

@@ -400,3 +380,3 @@ console.error(tag, 'e: ', e);

api,
address,
pubkey,
chain,

@@ -411,11 +391,11 @@ }: {

try {
console.log(tag, 'EVM toolbox getBalance: ', address[0].address);
console.log(tag, 'EVM toolbox getBalance: ', pubkey.address);
const tokenBalances = await api.getBalance(address[0].address).catch((e) => {
console.error(`Error fetching token balances for address ${address[0].address}:`, e);
return []; // Return an empty array on failure to allow processing to continue
});
// const tokenBalances = await api.getBalance(pubkey.address).catch((e) => {
// console.error(`Error fetching token balances for address ${pubkey.address}:`, e);
// return []; // Return an empty array on failure to allow processing to continue
// });
const evmGasTokenBalance = await provider.getBalance(address[0].address).catch((e) => {
console.error(`Error fetching gas token balance for address ${address[0].address}:`, e);
const evmGasTokenBalance = await provider.getBalance(pubkey.address).catch((e) => {
console.error(`Error fetching gas token balance for address ${pubkey.address}:`, e);
return BigInt(0); // Return 0 on failure

@@ -425,3 +405,2 @@ });

console.log(tag, 'chain: ', chain);
console.log(tag, 'tokenBalances: ', tokenBalances);
console.log(tag, 'evmGasTokenBalance: ', evmGasTokenBalance.toString());

@@ -438,39 +417,42 @@ let safeValue = formatBigIntToSafeValue({

console.log(tag, 'gasTokenBalance: ', gasTokenBalance);
let balances: any = [];
balances.push(gasTokenBalance);
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < tokenBalances.length; i++) {
let tokenBalance = tokenBalances[i];
if (tokenBalance.symbol && tokenBalance.chain && tokenBalance.chain === chain) {
try {
console.log(tag, 'tokenBalance: ', tokenBalance);
let tokenString = `${tokenBalance.chain}.${tokenBalance.symbol.toUpperCase()}`;
console.log(tag, 'tokenString: ', tokenString);
console.log(tag, 'tokenBalance.value: ', tokenBalance.value);
if (tokenString.includes('HTTPS://')) {
console.log('Spam detected: ', tokenString);
} else {
let formattedBalance = AssetValue.fromIdentifierSync(
//@ts-ignore
tokenString,
tokenBalance.value,
);
if (formattedBalance.ticker && formattedBalance.ticker !== 'undefined') {
// formattedBalance.address = address[0].address;
balances.push(formattedBalance);
} else {
console.error('Missing ticker for:', tokenBalance);
}
}
} catch (error) {
console.error(`Error formatting balance for token ${tokenBalance.symbol}:`, error);
}
} else {
console.log('Mismatched chain or missing token data:', { chain, tokenBalance });
}
}
// let balances: any = [];
// balances.push(gasTokenBalance);
console.log(tag, ' final: balances: ', balances);
return balances;
//
// // eslint-disable-next-line @typescript-eslint/prefer-for-of
// for (let i = 0; i < tokenBalances.length; i++) {
// let tokenBalance = tokenBalances[i];
// if (tokenBalance.symbol && tokenBalance.chain && tokenBalance.chain === chain) {
// try {
// console.log(tag, 'tokenBalance: ', tokenBalance);
// let tokenString = `${tokenBalance.chain}.${tokenBalance.symbol.toUpperCase()}`;
// console.log(tag, 'tokenString: ', tokenString);
// console.log(tag, 'tokenBalance.value: ', tokenBalance.value);
// if (tokenString.includes('HTTPS://')) {
// console.log('Spam detected: ', tokenString);
// } else {
// let formattedBalance = AssetValue.fromIdentifierSync(
// //@ts-ignore
// tokenString,
// tokenBalance.value,
// );
// if (formattedBalance.ticker && formattedBalance.ticker !== 'undefined') {
// // formattedBalance.address = address[0].address;
// balances.push(formattedBalance);
// } else {
// console.error('Missing ticker for:', tokenBalance);
// }
// }
// } catch (error) {
// console.error(`Error formatting balance for token ${tokenBalance.symbol}:`, error);
// }
// } else {
// console.log('Mismatched chain or missing token data:', { chain, tokenBalance });
// }
// }
//
// console.log(tag, ' final: balances: ', balances);
return gasTokenBalance;
} catch (error) {

@@ -477,0 +459,0 @@ console.error('Unexpected error in getBalance:', error);

@@ -38,9 +38,17 @@ import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl } from '@coinmasters/types';

getNetworkParams,
async getBalance(address: any) {
async getBalance(pubkey: any) {
let tag = TAG + ' | getBalance | ';
try {
let address;
if (Array.isArray(pubkey)) {
address = pubkey[0].address;
} else {
address = pubkey.address;
}
console.log(tag, 'address: ', address);
// const tokenBalances = await api.getBalance(address[0].address);
// console.log('tokenBalances: ', tokenBalances);
const evmGasTokenBalance = await provider.getBalance(address[0].address);
const evmGasTokenBalance = await provider.getBalance(address);
console.log(tag, 'evmGasTokenBalance: ', evmGasTokenBalance);

@@ -65,41 +73,40 @@ let safeValue = formatBigIntToSafeValue({

// The token's contract address
const tokenAddress = '0xef743df8eda497bcf1977393c401a636518dd630';
const userAddress = address[0].address;
// The ERC-20 token ABI
const ERC20_ABI = [
{
constant: true,
inputs: [{ name: 'owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function',
},
];
const { Contract } = await import('ethers');
// Assuming `provider` is correctly initialized earlier in your code
// Create an instance of a contract connected to the ERC-20 token
const contract = new Contract(tokenAddress, ERC20_ABI, provider);
// const tokenAddress = '0xef743df8eda497bcf1977393c401a636518dd630';
// const userAddress = pubkey.address;
// // The ERC-20 token ABI
// const ERC20_ABI = [
// {
// constant: true,
// inputs: [{ name: 'owner', type: 'address' }],
// name: 'balanceOf',
// outputs: [{ name: '', type: 'uint256' }],
// payable: false,
// stateMutability: 'view',
// type: 'function',
// },
// ];
// const { Contract } = await import('ethers');
// // Assuming `provider` is correctly initialized earlier in your code
// // Create an instance of a contract connected to the ERC-20 token
// const contract = new Contract(tokenAddress, ERC20_ABI, provider);
//
// // const contract = await baseToolbox.createContract(tokenAddress, ERC20_ABI, provider);
// console.log(tag, 'contract: ', contract);
// if (!contract) throw new Error('Failed to create contract instance');
//
// // Replace 'address[0].address' with the actual wallet address you're querying
// const tokenBalanceBigNumber = await contract.balanceOf(userAddress);
// console.log(tag, 'Token Balance (raw Big Number): ', tokenBalanceBigNumber.toString());
// const contract = await baseToolbox.createContract(tokenAddress, ERC20_ABI, provider);
console.log(tag, 'contract: ', contract);
if (!contract) throw new Error('Failed to create contract instance');
// Replace 'address[0].address' with the actual wallet address you're querying
const tokenBalanceBigNumber = await contract.balanceOf(userAddress);
console.log(tag, 'Token Balance (raw Big Number): ', tokenBalanceBigNumber.toString());
// Process the token balance
const assetStringToken = 'BASE.PRO-0XEF743DF8EDA497BCF1977393C401A636518DD630';
let tokenAssetValue = AssetValue.fromStringSync(assetStringToken, tokenBalanceBigNumber);
tokenAssetValue.address = '0xef743df8eda497bcf1977393c401a636518dd630';
tokenAssetValue.caip = 'eip155:8453/erc20:0xef743df8eda497bcf1977393c401a636518dd630';
console.log(tag, 'Token Asset Value: ', tokenAssetValue);
// const assetStringToken = 'BASE.PRO-0XEF743DF8EDA497BCF1977393C401A636518DD630';
// let tokenAssetValue = AssetValue.fromStringSync(assetStringToken, tokenBalanceBigNumber);
// tokenAssetValue.address = '0xef743df8eda497bcf1977393c401a636518dd630';
// tokenAssetValue.caip = 'eip155:8453/erc20:0xef743df8eda497bcf1977393c401a636518dd630';
// console.log(tag, 'Token Asset Value: ', tokenAssetValue);
//TODO get tokens from covalent
//TODO move tokens to getBalances*
let balances = [gasTokenBalance, tokenAssetValue];
console.log(tag, 'balances: ', balances);
return balances;
return gasTokenBalance;
} catch (e) {

@@ -106,0 +113,0 @@ console.log('getBalance error: ', e);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc