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.29 to 11.0.30

dist/index-33aa4e4f.js

40

dist/index.d.ts

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

symbol: string;
caip: any;
}[]>;

@@ -102,3 +103,3 @@ } | undefined;

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

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

symbol: string;
caip: any;
}[]>;

@@ -146,3 +148,3 @@ } | undefined;

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

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

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

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

symbol: string;
caip: any;
}[]>;

@@ -348,3 +351,3 @@ } | undefined;

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

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

symbol: string;
caip: any;
}[]>;

@@ -434,3 +438,3 @@ };

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

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

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

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

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

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

chain: EVMChain;
potentialScamFilter?: boolean | undefined;
}) => Promise<AssetValue[]>;
}) => Promise<any>;

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

symbol: string;
caip: any;
}[]>;

@@ -593,3 +597,3 @@ } | undefined;

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

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

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

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

symbol: string;
caip: any;
}[]>;

@@ -756,3 +761,3 @@ } | undefined;

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

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

symbol: string;
caip: any;
}[]>;

@@ -809,3 +815,3 @@ } | undefined;

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

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

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

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

symbol: string;
caip: any;
}[]>;

@@ -939,3 +946,3 @@ } | undefined;

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

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

symbol: string;
caip: any;
}[]>;

@@ -1057,3 +1065,3 @@ } | undefined;

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

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

2

dist/index.es.js

@@ -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-cf913d21.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-f6365e56.js";
import "@pioneer-platform/helpers";

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

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

"ethers": "6.9.0",
"@coinmasters/types": "4.7.29"
"@coinmasters/types": "4.7.30"
},

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

"vitest": "0.34.6",
"@internal/config": "2.7.29"
"@internal/config": "2.7.30"
},

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

"peerDependencies": {
"@pioneer-platform/helpers": "latest"
"@pioneer-platform/helpers": "^4.0.6"
},

@@ -52,3 +52,3 @@ "exports": {

"types": "./dist/index.d.ts",
"version": "11.0.29",
"version": "11.0.30",
"scripts": {

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

import type { ChainId } from '@coinmasters/types';
import { ChainIdToChain } from '@coinmasters/types';
import { formatBigIntToSafeValue, RequestClient } from '@pioneer-platform/helpers';
// @ts-ignore
import { thorchainToCaip } from '@pioneer-platform/pioneer-caip';

@@ -31,26 +33,79 @@ type CovalentBalanceResponse = {

};
export const covalentApi = ({ apiKey, chainId }: { apiKey: string; chainId: ChainId }) => ({
getBalance: async (address: any) => {
//console.log('address: ', address);
//console.log('address: ', address);
// console.log(
// 'URL: ',
// `https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`,
// );
const { data } = await RequestClient.get<{ data: CovalentBalanceResponse }>(
`https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`,
{ searchParams: { key: apiKey } },
);
//console.log('data: ', data);
return (data?.items || []).map(
({ balance, contract_decimals, contract_ticker_symbol, contract_address, native_token }) => ({
value: formatBigIntToSafeValue({ value: BigInt(balance), decimal: contract_decimals }),
decimal: contract_decimals,
chain: ChainIdToChain[chainId],
symbol: `${contract_ticker_symbol}${native_token ? '' : `-${contract_address}`}`,
}),
);
try {
const { data } = await RequestClient.get<{ data: CovalentBalanceResponse }>(
`https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`,
{ searchParams: { key: apiKey } },
);
const balances = [];
const items = data?.items || [];
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < items.length; i++) {
const {
balance,
contract_decimals,
contract_ticker_symbol,
contract_address,
native_token,
} = items[i];
console.log('item: ', items[i]);
const caip = thorchainToCaip(
`${contract_ticker_symbol}${native_token ? '' : `-${contract_address}`}`,
);
// If thorchainToCaip does not return a value, skip this item
if (!caip) {
console.error('Error Unknown balance! :', items[i]);
continue;
}
balances.push({
value: formatBigIntToSafeValue({ value: BigInt(balance), decimal: contract_decimals }),
decimal: contract_decimals,
chain: ChainIdToChain[chainId],
symbol: `${contract_ticker_symbol}${native_token ? '' : `-${contract_address}`}`,
caip,
});
}
return balances;
} catch (error) {
console.error('Error fetching balance:', error);
return [];
}
},
});
// export const covalentApi = ({ apiKey, chainId }: { apiKey: string; chainId: ChainId }) => ({
// getBalance: async (address: any) => {
// //console.log('address: ', address);
// //console.log('address: ', address);
// // console.log(
// // 'URL: ',
// // `https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`,
// // );
// const { data } = await RequestClient.get<{ data: CovalentBalanceResponse }>(
// `https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`,
// { searchParams: { key: apiKey } },
// );
// //console.log('data: ', data);
// return (data?.items || []).map(
// ({ balance, contract_decimals, contract_ticker_symbol, contract_address, native_token }) => ({
// value: formatBigIntToSafeValue({ value: BigInt(balance), decimal: contract_decimals }),
// decimal: contract_decimals,
// chain: ChainIdToChain[chainId],
// symbol: `${contract_ticker_symbol}${native_token ? '' : `-${contract_address}`}`,
// caip: thorchainToCaip(
// `${contract_ticker_symbol}${native_token ? '' : `-${contract_address}`}`,
// ),
// }),
// );
// },
// });
export type CovalentApiType = ReturnType<typeof covalentApi>;

@@ -399,3 +399,2 @@ import {

chain,
potentialScamFilter,
}: {

@@ -406,6 +405,6 @@ provider: JsonRpcProvider | BrowserProvider;

chain: EVMChain;
potentialScamFilter?: boolean;
}) => {
let tag = TAG + ' | getBalance | ';
try {
console.log('EVM toolbox getBalance: ', address[0].address);
console.log(tag, 'EVM toolbox getBalance: ', address[0].address);

@@ -422,16 +421,19 @@ const tokenBalances = await api.getBalance(address[0].address).catch((e) => {

console.log('tokenBalances: ', tokenBalances);
console.log('evmGasTokenBalance: ', evmGasTokenBalance.toString());
let gasTokenBalance = AssetValue.fromChainOrSignature(
chain,
formatBigIntToSafeValue({ value: evmGasTokenBalance, decimal: BaseDecimal[chain] }),
);
console.log(tag, 'chain: ', chain);
console.log(tag, 'tokenBalances: ', tokenBalances);
console.log(tag, 'evmGasTokenBalance: ', evmGasTokenBalance.toString());
let safeValue = formatBigIntToSafeValue({
value: evmGasTokenBalance,
decimal: BaseDecimal[chain] || 18,
});
console.log('safeValue: ', safeValue);
//@ts-ignore
let gasTokenBalance = AssetValue.fromChainOrSignature(chain, safeValue);
gasTokenBalance.isGasAsset = true; // Marking it as gas asset
console.log('gasTokenBalance: ', gasTokenBalance);
gasTokenBalance.caip = ChainToCaip[chain];
let balances = [gasTokenBalance];
console.log(tag, 'gasTokenBalance: ', gasTokenBalance);
let balances: any = [];
balances.push(gasTokenBalance);
await AssetValue.loadStaticAssets();
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < tokenBalances.length; i++) {

@@ -441,6 +443,6 @@ let tokenBalance = tokenBalances[i];

try {
console.log('tokenBalance: ', tokenBalance);
console.log(tag, 'tokenBalance: ', tokenBalance);
let tokenString = `${tokenBalance.chain}.${tokenBalance.symbol.toUpperCase()}`;
console.log('tokenString: ', tokenString);
console.log('tokenBalance.value: ', tokenBalance.value);
console.log(tag, 'tokenString: ', tokenString);
console.log(tag, 'tokenBalance.value: ', tokenBalance.value);
if (tokenString.includes('HTTPS://')) {

@@ -457,2 +459,4 @@ console.log('Spam detected: ', tokenString);

balances.push(formattedBalance);
} else {
console.error('Missing ticker for:', tokenBalance);
}

@@ -468,2 +472,3 @@ }

console.log(tag, ' final: balances: ', balances);
return balances;

@@ -475,77 +480,1 @@ } catch (error) {

};
// Utility function to format BigInt values
const formatBigIntToSafeValue = ({ value, decimal }: { value: bigint; decimal: number }) => {
return Number(value) / Math.pow(10, decimal);
};
// export const getBalance = async ({
// provider,
// api,
// address,
// chain,
// potentialScamFilter,
// }: {
// provider: JsonRpcProvider | BrowserProvider;
// api: CovalentApiType | EthplorerApiType;
// address: any; // Consider using a more specific type if possible
// chain: EVMChain;
// potentialScamFilter?: boolean;
// }) => {
// try {
// //console.log('EVM toolbox getBalance: ', address[0].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 evmGasTokenBalance = await provider.getBalance(address[0].address).catch((e) => {
// console.error(`Error fetching gas token balance for address ${address[0].address}:`, e);
// return BigInt(0); // Return 0 on failure
// });
// //console.log('tokenBalances: ', tokenBalances);
// //console.log('evmGasTokenBalance: ', evmGasTokenBalance.toString());
//
// let gasTokenBalance = AssetValue.fromChainOrSignature(
// chain,
// formatBigIntToSafeValue({ value: evmGasTokenBalance, decimal: BaseDecimal[chain] }),
// );
// gasTokenBalance.address = address[0].address;
// let balances = [gasTokenBalance];
//
// await AssetValue.loadStaticAssets();
//
// // 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("tokenBalance: ", tokenBalance);
// let tokenString = `${tokenBalance.chain}.${tokenBalance.symbol.toUpperCase()}`
// console.log("tokenString: ", tokenString);
// console.log("tokenBalance.value: ", tokenBalance.value);
// let formattedBalance = AssetValue.fromIdentifierSync(
// //@ts-ignore
// tokenString,
// tokenBalance.value,
// );
// //console.log('formattedBalance: ', formattedBalance);
// //this hack removes all the tokens that are not in assetBalance token list package
// if (formattedBalance.ticker && formattedBalance.ticker !== 'undefined') {
// // formattedBalance.address = address[0].address;
// balances.push(formattedBalance);
// }
// } catch (error) {
// console.error(`Error formatting balance for token ${tokenBalance.symbol}:`, error);
// }
// } else {
// //console.log('Mismatched chain or missing token data:', { chain, tokenBalance });
// }
// }
//
// return balances;
// } catch (error) {
// console.error('Unexpected error in getBalance:', error);
// // Decide how to handle unexpected errors - rethrow, return empty array, etc.
// throw error;
// }
// };

@@ -1,3 +0,5 @@

import { AssetValue } from '@pioneer-platform/helpers';
import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl } from '@coinmasters/types';
import { AssetValue, formatBigIntToSafeValue } from '@pioneer-platform/helpers';
//@ts-ignore
import { ChainToCaip } from '@pioneer-platform/pioneer-caip';
import type { BrowserProvider, JsonRpcProvider, Signer } from 'ethers';

@@ -9,2 +11,3 @@

import { BaseEVMToolbox } from './BaseEVMToolbox.ts';
const TAG = ' | evm/base.ts | ';

@@ -37,17 +40,26 @@ export const getNetworkParams = () => ({

async getBalance(address: any) {
let tag = TAG + ' | getBalance | ';
try {
console.log('address: ', 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);
console.log(tag, 'evmGasTokenBalance: ', evmGasTokenBalance);
let safeValue = formatBigIntToSafeValue({
value: evmGasTokenBalance,
decimal: BaseDecimal['BASE'] || 18,
});
const evmGasTokenBalance = await provider.getBalance(address[0].address);
//console.log('tokenBalances: ', tokenBalances);
console.log('evmGasTokenBalance: ', evmGasTokenBalance);
console.log(tag, 'evmGasTokenBalance safeValue: ', safeValue);
//safe
await AssetValue.loadStaticAssets();
let assetStringGas = 'BASE.ETH';
let gasTokenBalance = AssetValue.fromStringSync(assetStringGas, evmGasTokenBalance);
gasTokenBalance.address = address[0].address;
console.log('gasTokenBalance: ', gasTokenBalance);
//@ts-ignore
let gasTokenBalance = AssetValue.fromChainOrSignature(Chain.Base, safeValue);
gasTokenBalance.caip = ChainToCaip['BASE'];
console.log(tag, 'gasTokenBalance: ', gasTokenBalance);
console.log(tag, 'gasTokenBalance: ', gasTokenBalance.getValue('string'));
//pro token balances
//pro token balances
// The token's contract address

@@ -57,3 +69,2 @@ const tokenAddress = '0xef743df8eda497bcf1977393c401a636518dd630';

// The ERC-20 token ABI
// The ERC-20 token ABI
const ERC20_ABI = [

@@ -76,3 +87,3 @@ {

// const contract = await baseToolbox.createContract(tokenAddress, ERC20_ABI, provider);
console.log('contract: ', contract);
console.log(tag, 'contract: ', contract);
if (!contract) throw new Error('Failed to create contract instance');

@@ -82,3 +93,3 @@

const tokenBalanceBigNumber = await contract.balanceOf(userAddress);
console.log('Token Balance (raw Big Number): ', tokenBalanceBigNumber.toString());
console.log(tag, 'Token Balance (raw Big Number): ', tokenBalanceBigNumber.toString());

@@ -88,4 +99,5 @@ // Process the token balance

let tokenAssetValue = AssetValue.fromStringSync(assetStringToken, tokenBalanceBigNumber);
tokenAssetValue.address = userAddress;
console.log('Token Asset Value: ', tokenAssetValue);
tokenAssetValue.address = '0xef743df8eda497bcf1977393c401a636518dd630';
tokenAssetValue.caip = 'eip155:8453/erc20:0xef743df8eda497bcf1977393c401a636518dd630';
console.log(tag, 'Token Asset Value: ', tokenAssetValue);

@@ -95,5 +107,7 @@ //TODO get tokens from covalent

let balances = [gasTokenBalance, tokenAssetValue];
console.log(tag, 'balances: ', balances);
return balances;
} catch (e) {
console.log('getBalance error: ', e);
throw e;
}

@@ -100,0 +114,0 @@ },

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