Socket
Socket
Sign inDemoInstall

@stardust-collective/dag4-xchain-ethereum

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stardust-collective/dag4-xchain-ethereum - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

13

cjs/account-tracker.js

@@ -39,6 +39,6 @@ "use strict";

if (this.provider) {
this.provider.off('block');
this.subscription.unsubscribe();
}
this.provider = new ethers_1.ethers.providers.InfuraProvider(this.chainId, this.infuraProjectId);
rxjs_1.fromEvent(this.provider, 'block')
this.subscription = rxjs_1.fromEvent(this.provider, 'block')
.pipe(

@@ -60,3 +60,5 @@ // @ts-ignore

stop() {
this.provider.off('block');
// this.provider.off('block');
this.subscription.unsubscribe();
this.subscription = null;
this.isRunning = false;

@@ -66,9 +68,10 @@ this.provider = null;

async getTokenBalances() {
// if (!this.provider) return;
const ethBalance = await this.provider.getBalance(this.ethAddress);
const ethBalanceNum = Number(ethers_1.ethers.utils.formatUnits(ethBalance, 18)) || 0;
const tokenAddresses = this.accounts.map(t => t.address);
const tokenAddresses = this.accounts.map(t => t.contractAddress);
const rawTokenBalances = await token_contract_service_1.tokenContractService.getAddressBalances(this.provider, this.ethAddress, tokenAddresses, this.chainId);
const tokenBalances = {};
this.accounts.forEach(t => {
tokenBalances[t.address] = Number(ethers_1.ethers.utils.formatUnits(rawTokenBalances[t.address], t.decimals)) || 0;
tokenBalances[t.contractAddress] = Number(ethers_1.ethers.utils.formatUnits(rawTokenBalances[t.contractAddress], t.decimals)) || 0;
});

@@ -75,0 +78,0 @@ this.callback(ethBalanceNum, tokenBalances);

@@ -40,6 +40,2 @@ "use strict";

}
getTokenInfo(tokenContractAddress, chainId = 1) {
const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);
return token_contract_service_1.tokenContractService.getTokenInfo(infuraProvider, tokenContractAddress);
}
getTransactionCount(address, chainId = 1) {

@@ -58,2 +54,27 @@ const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);

}
async getTokenInfo(address, chainId = 1) {
if (this.isValidEthereumAddress(address)) {
const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);
try {
const result = await token_contract_service_1.tokenContractService.getTokenInfo(infuraProvider, address);
console.log('getTokenInfo');
return result;
}
catch (e) {
console.log('getTokenInfo.ERROR -', e.message);
return null;
}
}
return null;
}
async isContractAddress(address, chainId = 1) {
if (this.isValidEthereumAddress(address)) {
const provider = new InfuraProvider(chainId, this.infuraProjectId);
const code = await provider.getCode(address);
console.log('isContractAddress');
console.log(code);
return code !== '0x';
}
return false;
}
}

@@ -60,0 +81,0 @@ exports.XChainEthClient = XChainEthClient;

@@ -36,6 +36,6 @@ import { ethers } from 'ethers';

if (this.provider) {
this.provider.off('block');
this.subscription.unsubscribe();
}
this.provider = new ethers.providers.InfuraProvider(this.chainId, this.infuraProjectId);
fromEvent(this.provider, 'block')
this.subscription = fromEvent(this.provider, 'block')
.pipe(

@@ -57,3 +57,5 @@ // @ts-ignore

stop() {
this.provider.off('block');
// this.provider.off('block');
this.subscription.unsubscribe();
this.subscription = null;
this.isRunning = false;

@@ -63,9 +65,10 @@ this.provider = null;

async getTokenBalances() {
// if (!this.provider) return;
const ethBalance = await this.provider.getBalance(this.ethAddress);
const ethBalanceNum = Number(ethers.utils.formatUnits(ethBalance, 18)) || 0;
const tokenAddresses = this.accounts.map(t => t.address);
const tokenAddresses = this.accounts.map(t => t.contractAddress);
const rawTokenBalances = await tokenContractService.getAddressBalances(this.provider, this.ethAddress, tokenAddresses, this.chainId);
const tokenBalances = {};
this.accounts.forEach(t => {
tokenBalances[t.address] = Number(ethers.utils.formatUnits(rawTokenBalances[t.address], t.decimals)) || 0;
tokenBalances[t.contractAddress] = Number(ethers.utils.formatUnits(rawTokenBalances[t.contractAddress], t.decimals)) || 0;
});

@@ -72,0 +75,0 @@ this.callback(ethBalanceNum, tokenBalances);

@@ -18,6 +18,2 @@ import { BigNumber, ethers, FixedNumber } from 'ethers';

}
getTokenInfo(tokenContractAddress, chainId = 1) {
const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);
return tokenContractService.getTokenInfo(infuraProvider, tokenContractAddress);
}
getTransactionCount(address, chainId = 1) {

@@ -36,2 +32,27 @@ const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);

}
async getTokenInfo(address, chainId = 1) {
if (this.isValidEthereumAddress(address)) {
const infuraProvider = new InfuraProvider(chainId, this.infuraProjectId);
try {
const result = await tokenContractService.getTokenInfo(infuraProvider, address);
console.log('getTokenInfo');
return result;
}
catch (e) {
console.log('getTokenInfo.ERROR -', e.message);
return null;
}
}
return null;
}
async isContractAddress(address, chainId = 1) {
if (this.isValidEthereumAddress(address)) {
const provider = new InfuraProvider(chainId, this.infuraProjectId);
const code = await provider.getCode(address);
console.log('isContractAddress');
console.log(code);
return code !== '0x';
}
return false;
}
}

@@ -38,0 +59,0 @@ //Get Token Info by ContractAddress

{
"name": "@stardust-collective/dag4-xchain-ethereum",
"version": "0.1.9",
"version": "0.1.10",
"description": "Cross chain communication with Ethereum",

@@ -20,6 +20,6 @@ "author": "Frank Fox",

"erc-20-abi": "^1.0.0",
"single-call-balance-checker-abi": "^1.0.0",
"ethers": "^5.0.32",
"rxjs": "^7.0.0",
"single-call-balance-checker-abi": "^1.0.0"
"rxjs": "^7.0.0"
}
}

@@ -10,2 +10,3 @@ export declare class AccountTracker {

private debounceTimeSec;
private subscription;
constructor({ infuraCreds }: {

@@ -23,3 +24,3 @@ infuraCreds: any;

declare type TokenInfo = {
"address": string;
"contractAddress": string;
"decimals": number;

@@ -26,0 +27,0 @@ "balance"?: string;

@@ -18,3 +18,6 @@ import { ExplorerUrl, InfuraCreds } from '@xchainjs/xchain-ethereum';

isValidEthereumAddress(address: string): boolean;
getTokenInfo(tokenContractAddress: string, chainId?: number): Promise<{
getTransactionCount(address: string, chainId?: number): Promise<number>;
getTokenBalance(ethAddress: string, token: TokenInfo, chainId?: number): Promise<number>;
waitForTransaction(hash: string, chainId?: number): Promise<ethers.providers.TransactionReceipt>;
getTokenInfo(address: string, chainId?: number): Promise<{
address: string;

@@ -25,5 +28,3 @@ decimals: any;

}>;
getTransactionCount(address: string, chainId?: number): Promise<number>;
getTokenBalance(ethAddress: string, token: TokenInfo, chainId?: number): Promise<number>;
waitForTransaction(hash: string, chainId?: number): Promise<ethers.providers.TransactionReceipt>;
isContractAddress(address: string, chainId?: number): Promise<boolean>;
}

@@ -30,0 +31,0 @@ declare type TokenInfo = {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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