@coinmasters/toolbox-evm
Advanced tools
Comparing version 9.0.9 to 10.0.0
@@ -266,3 +266,3 @@ import type { Asset } from '@coinmasters/types'; | ||
}; | ||
getBalance(address: any): Promise<AssetValue[] | undefined>; | ||
getBalance(address: any): Promise<(AssetValue | undefined)[] | undefined>; | ||
approve: (params: ApproveParams) => Promise<string>; | ||
@@ -822,3 +822,3 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>; | ||
}; | ||
getBalance(address: any): Promise<AssetValue[] | undefined>; | ||
getBalance(address: any): Promise<(AssetValue | undefined)[] | undefined>; | ||
approve: (params: ApproveParams) => Promise<string>; | ||
@@ -825,0 +825,0 @@ approvedAmount: (params: ApprovedParams) => Promise<bigint>; |
@@ -1,2 +0,2 @@ | ||
import { aY as o, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as A, bj as i, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as g, bb as k, b5 as w, bh as p, aU as E, bd as M, bi as S, aV as W, b1 as m, ba as C, be as B, bf as V, b6 as u, b9 as N, aX as P, bg as f, b7 as D } from "./index-385953a1.js"; | ||
import { aY as o, aZ as t, a_ as b, a$ as l, aS as r, aT as d, b0 as A, bj as i, b2 as T, aW as c, b3 as h, bc as n, b8 as x, b4 as g, bb as k, b5 as w, bh as p, aU as E, bd as M, bi as S, aV as W, b1 as m, ba as C, be as B, bf as V, b6 as u, b9 as N, aX as P, bg as f, b7 as D } from "./index-69ad43b4.js"; | ||
import "@coinmasters/helpers"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -5,3 +5,3 @@ { | ||
"ethers": "6.9.0", | ||
"@coinmasters/types": "4.5.0" | ||
"@coinmasters/types": "4.6.0" | ||
}, | ||
@@ -18,4 +18,4 @@ "description": "THORSwap evm", | ||
"vitest": "0.34.6", | ||
"@coinmasters/helpers": "9.0.9", | ||
"@internal/config": "2.5.0" | ||
"@internal/config": "2.6.0", | ||
"@coinmasters/helpers": "10.0.0" | ||
}, | ||
@@ -26,3 +26,3 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/helpers": "9.0.9" | ||
"@coinmasters/helpers": "10.0.0" | ||
}, | ||
@@ -52,3 +52,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "9.0.9", | ||
"version": "10.0.0", | ||
"scripts": { | ||
@@ -55,0 +55,0 @@ "build": "vite build", |
@@ -9,13 +9,27 @@ import { formatBigIntToSafeValue, RequestClient } from '@coinmasters/helpers'; | ||
getBalance: async (address: string) => { | ||
const { tokens = [] } = await RequestClient.get<AddressInfo>( | ||
`${baseUrl}/getAddressInfo/${address}`, | ||
{ searchParams: { apiKey } }, | ||
); | ||
try { | ||
// Assuming RequestClient.get is correctly implemented elsewhere | ||
const { tokens = [] } = await RequestClient.get<AddressInfo>( | ||
`${baseUrl}/getAddressInfo/${address}`, | ||
{ searchParams: { apiKey } } | ||
); | ||
console.log("tokens: ", tokens); | ||
return tokens.map(({ tokenInfo: { symbol, decimals, address: tokenAddress }, rawBalance }) => ({ | ||
chain: Chain.Ethereum, | ||
symbol: tokenAddress ? `${symbol}-${tokenAddress}` : symbol, | ||
value: formatBigIntToSafeValue({ value: BigInt(rawBalance), decimal: parseInt(decimals) }), | ||
decimal: parseInt(decimals), | ||
})); | ||
const tokenBalances = []; | ||
for (const token of tokens) { | ||
const { tokenInfo: { symbol, decimals, address: tokenAddress }, rawBalance } = token; | ||
tokenBalances.push({ | ||
chain: Chain.Ethereum, | ||
symbol: tokenAddress ? `${symbol}-${tokenAddress}` : symbol, | ||
value: formatBigIntToSafeValue({ value: BigInt(rawBalance), decimal: parseInt(decimals) }), | ||
decimal: parseInt(decimals) || 0, | ||
}); | ||
} | ||
console.log("tokenBalances: ", tokenBalances); | ||
return tokenBalances; | ||
} catch (error) { | ||
console.error(`Error fetching balance: ${error}`); | ||
// Depending on your use case, you might want to rethrow the error or handle it differently | ||
throw error; | ||
} | ||
}, | ||
@@ -22,0 +36,0 @@ }); |
@@ -177,4 +177,4 @@ import { AssetValue, formatBigIntToSafeValue, SwapKitNumber } from '@coinmasters/helpers'; | ||
try { | ||
console.log(tag, 'checkpoint '); | ||
const balance = (await toolbox.getBalance([{address:from}])).find(({ symbol, chain }) => | ||
//console.log(tag, 'checkpoint '); | ||
const balance = (await toolbox.getBalance([{ address: from }])).find(({ symbol, chain }) => | ||
assetValue | ||
@@ -184,6 +184,6 @@ ? symbol === assetValue.symbol | ||
); | ||
console.log(tag, 'balance: ', balance); | ||
//console.log(tag, 'balance: ', balance); | ||
const fees = (await toolbox.estimateGasPrices())[feeOptionKey]; | ||
console.log(tag, 'fees: ', fees); | ||
//console.log(tag, 'fees: ', fees); | ||
@@ -218,3 +218,3 @@ if (!balance) return AssetValue.fromChainOrSignature(assetValue.chain, 0); | ||
}); | ||
console.log(tag, 'gasLimit: ', gasLimit); | ||
//console.log(tag, 'gasLimit: ', gasLimit); | ||
@@ -235,7 +235,7 @@ const isFeeEIP1559Compatible = 'maxFeePerGas' in fees; | ||
); | ||
console.log(tag, 'fee: ', fee); | ||
//console.log(tag, 'fee: ', fee); | ||
return AssetValue.fromChainOrSignature(balance.chain, maxSendableAmount.getValue('string')); | ||
} catch (e) { | ||
console.error(tag,"e: ",e); | ||
console.error(tag, 'e: ', e); | ||
throw e; | ||
@@ -360,37 +360,61 @@ } | ||
api: CovalentApiType | EthplorerApiType; | ||
address: any; | ||
address: any; // Consider using a more specific type if possible | ||
chain: EVMChain; | ||
potentialScamFilter?: boolean; | ||
}) => { | ||
//console.log('EVM toolbox getBalance: ', address[0].address); | ||
const tokenBalances = await api.getBalance(address[0].address); | ||
const evmGasTokenBalance = await provider.getBalance(address[0].address); | ||
console.log('tokenBalances: ', tokenBalances); | ||
console.log('evmGasTokenBalance: ', evmGasTokenBalance); | ||
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) { | ||
let formatedBalance = AssetValue.fromIdentifierSync( | ||
//@ts-ignore | ||
tokenBalance.chain + '.' + tokenBalance.symbol.toUpperCase(), | ||
tokenBalance.value, | ||
); | ||
// formatedBalance.address = address[0].address; | ||
balances.push(formatedBalance); | ||
} else { | ||
console.log('chain: ', chain); | ||
console.log('tokenBalance.chain: ', tokenBalance.chain); | ||
console.error('invalid balance: ', tokenBalance); | ||
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 { | ||
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; | ||
} | ||
// return filteredBalances; | ||
return balances; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { AssetValue, formatBigIntToSafeValue } from '@coinmasters/helpers'; | ||
import { AssetValue } from '@coinmasters/helpers'; | ||
import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl } from '@coinmasters/types'; | ||
@@ -37,2 +37,3 @@ import type { BrowserProvider, JsonRpcProvider, Signer } from 'ethers'; | ||
try { | ||
console.log('address: ', address); | ||
// const tokenBalances = await api.getBalance(address[0].address); | ||
@@ -43,17 +44,51 @@ // console.log('tokenBalances: ', tokenBalances); | ||
//console.log('tokenBalances: ', tokenBalances); | ||
//console.log('evmGasTokenBalance: ', evmGasTokenBalance); | ||
let gasTokenBalance = AssetValue.fromChainOrSignature( | ||
Chain.Base, | ||
formatBigIntToSafeValue({ | ||
value: evmGasTokenBalance, | ||
decimal: 18, | ||
}), | ||
); | ||
console.log('evmGasTokenBalance: ', evmGasTokenBalance); | ||
await AssetValue.loadStaticAssets(); | ||
let assetStringGas = 'BASE.ETH'; | ||
let gasTokenBalance = AssetValue.fromStringSync(assetStringGas, evmGasTokenBalance); | ||
gasTokenBalance.address = address[0].address; | ||
//get tokens | ||
console.log('gasTokenBalance: ', gasTokenBalance); | ||
let balances = [gasTokenBalance]; | ||
//pro token balances | ||
// The token's contract address | ||
const tokenAddress = '0xef743df8eda497bcf1977393c401a636518dd630'; | ||
const userAddress = address[0].address; | ||
// The ERC-20 token ABI | ||
// 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('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('Token Balance (raw Big Number): ', tokenBalanceBigNumber.toString()); | ||
// Process the token balance | ||
const assetStringToken = 'BASE.PRO-0XEF743DF8EDA497BCF1977393C401A636518DD630'; | ||
let tokenAssetValue = AssetValue.fromStringSync(assetStringToken, tokenBalanceBigNumber); | ||
tokenAssetValue.address = userAddress; | ||
console.log('Token Asset Value: ', tokenAssetValue); | ||
//TODO get tokens from covalent | ||
let balances = [gasTokenBalance, tokenAssetValue]; | ||
return balances; | ||
} catch (e) { | ||
//console.log('getBalance error: ', e); | ||
console.log('getBalance error: ', e); | ||
} | ||
@@ -60,0 +95,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
866016
18394
3
+ Added@coinmasters/helpers@10.0.0(transitive)
+ Added@coinmasters/tokens@3.6.0(transitive)
+ Added@coinmasters/types@4.6.0(transitive)
- Removed@coinmasters/helpers@9.0.9(transitive)
- Removed@coinmasters/tokens@3.5.9(transitive)
- Removed@coinmasters/types@4.5.0(transitive)
Updated@coinmasters/types@4.6.0