@xchainjs/xchain-evm
Advanced tools
Comparing version 0.1.3 to 0.1.4
import { Provider, TransactionResponse } from '@ethersproject/abstract-provider'; | ||
import { Balance, BaseXChainClient, FeeOption, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client'; | ||
import { Balance, BaseXChainClient, ExplorerProviders, FeeOption, Fees, Network, OnlineDataProviders, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client'; | ||
import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util'; | ||
import { BigNumber, Signer, ethers } from 'ethers'; | ||
import { ApproveParams, CallParams, EstimateApproveParams, EstimateCallParams, FeesWithGasPricesAndLimits, GasPrices, IsApprovedParams } from './types'; | ||
import { ExplorerProviders, OnlineDataProviders } from './types/provider-types'; | ||
/** | ||
@@ -8,0 +7,0 @@ * Interface for custom EVM client |
@@ -549,3 +549,6 @@ import { BaseXChainClient, Network, FeeOption, checkFeeBounds, standardFeeRates, FeeType, TxType } from '@xchainjs/xchain-client'; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.dataProviders[this.network].getBalance(address, assets); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getBalance(address, assets); | ||
}); | ||
@@ -569,3 +572,6 @@ } | ||
}; | ||
return yield this.dataProviders[this.network].getTransactions(filteredParams); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getTransactions(filteredParams); | ||
}); | ||
@@ -585,3 +591,6 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.dataProviders[this.network].getTransactionData(txId, assetAddress); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getTransactionData(txId, assetAddress); | ||
}); | ||
@@ -684,2 +693,3 @@ } | ||
const contract = new ethers.Contract(contractAddress, erc20ABI, this.getProvider()); | ||
/* as same as ethers.TransactionResponse expected by `sendTransaction` */ | ||
const unsignedTx = yield contract.populateTransaction.approve(spenderAddress, valueToApprove); | ||
@@ -906,18 +916,253 @@ const result = yield signer.sendTransaction(Object.assign(Object.assign({}, unsignedTx), { from: fromAddress, gasPrice, | ||
class ExplorerProvider { | ||
constructor(explorerUrl, explorerAddressUrlTemplate, explorerTxUrlTemplate) { | ||
this.explorerUrl = explorerUrl; | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; | ||
var erc20ABI$1 = [ | ||
{ | ||
inputs: [ | ||
], | ||
stateMutability: "nonpayable", | ||
type: "constructor" | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "owner", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "spender", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Approval", | ||
type: "event" | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "from", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Transfer", | ||
type: "event" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
} | ||
], | ||
name: "allowance", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "spender", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "approve", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
} | ||
], | ||
name: "balanceOf", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "decimals", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "name", | ||
outputs: [ | ||
{ | ||
internalType: "string", | ||
name: "", | ||
type: "string" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "symbol", | ||
outputs: [ | ||
{ | ||
internalType: "string", | ||
name: "", | ||
type: "string" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "totalSupply", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "transfer", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "from", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "transferFrom", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
} | ||
]; | ||
const MAX_APPROVAL$1 = ethers.BigNumber.from(2).pow(256).sub(1); | ||
/** | ||
* Validate the given address. | ||
* | ||
* @param {Address} address | ||
* @returns {boolean} `true` or `false` | ||
*/ | ||
const validateAddress$1 = (address) => { | ||
try { | ||
ethers.utils.getAddress(address); | ||
return true; | ||
} | ||
getExplorerUrl() { | ||
return this.explorerUrl; | ||
catch (error) { | ||
return false; | ||
} | ||
getExplorerAddressUrl(address) { | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); | ||
} | ||
getExplorerTxUrl(txID) { | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); | ||
} | ||
} | ||
}; | ||
@@ -984,3 +1229,3 @@ const getApiKeyQueryParameter = (apiKey) => (!!apiKey ? `&apiKey=${apiKey}` : ''); | ||
const address = tx.contractAddress; | ||
if (validateSymbol(symbol) && validateAddress(address)) { | ||
if (validateSymbol(symbol) && validateAddress$1(address)) { | ||
const tokenAsset = assetFromString(`${chain}.${symbol}-${address}`); | ||
@@ -1141,3 +1386,3 @@ if (tokenAsset) { | ||
}; | ||
const contract = new ethers.Contract(contractAddress, erc20ABI, this.provider); | ||
const contract = new ethers.Contract(contractAddress, erc20ABI$1, this.provider); | ||
const balance = (yield contract.balanceOf(address)).toString(); | ||
@@ -1690,3 +1935,3 @@ const decimals = (yield contract.decimals()).toString(); | ||
export { Client, EtherscanProvider, ExplorerProvider, MAX_APPROVAL, abi, call, estimateApprove, estimateCall, getApprovalAmount, getPrefix, getTokenAddress, isApproved, strip0x, validateAddress }; | ||
export { Client, EtherscanProvider, MAX_APPROVAL, abi, call, estimateApprove, estimateCall, getApprovalAmount, getPrefix, getTokenAddress, isApproved, strip0x, validateAddress }; | ||
//# sourceMappingURL=index.esm.js.map |
284
lib/index.js
@@ -557,3 +557,6 @@ 'use strict'; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.dataProviders[this.network].getBalance(address, assets); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getBalance(address, assets); | ||
}); | ||
@@ -577,3 +580,6 @@ } | ||
}; | ||
return yield this.dataProviders[this.network].getTransactions(filteredParams); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getTransactions(filteredParams); | ||
}); | ||
@@ -593,3 +599,6 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.dataProviders[this.network].getTransactionData(txId, assetAddress); | ||
const prov = this.dataProviders[this.network]; | ||
if (!prov) | ||
throw Error('Provider unidefined'); | ||
return yield prov.getTransactionData(txId, assetAddress); | ||
}); | ||
@@ -692,2 +701,3 @@ } | ||
const contract = new ethers.ethers.Contract(contractAddress, erc20ABI, this.getProvider()); | ||
/* as same as ethers.TransactionResponse expected by `sendTransaction` */ | ||
const unsignedTx = yield contract.populateTransaction.approve(spenderAddress, valueToApprove); | ||
@@ -914,18 +924,253 @@ const result = yield signer.sendTransaction(Object.assign(Object.assign({}, unsignedTx), { from: fromAddress, gasPrice, | ||
class ExplorerProvider { | ||
constructor(explorerUrl, explorerAddressUrlTemplate, explorerTxUrlTemplate) { | ||
this.explorerUrl = explorerUrl; | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; | ||
var erc20ABI$1 = [ | ||
{ | ||
inputs: [ | ||
], | ||
stateMutability: "nonpayable", | ||
type: "constructor" | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "owner", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "spender", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Approval", | ||
type: "event" | ||
}, | ||
{ | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "from", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: true, | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
indexed: false, | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "Transfer", | ||
type: "event" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
} | ||
], | ||
name: "allowance", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "spender", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "approve", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address" | ||
} | ||
], | ||
name: "balanceOf", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "decimals", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "name", | ||
outputs: [ | ||
{ | ||
internalType: "string", | ||
name: "", | ||
type: "string" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "symbol", | ||
outputs: [ | ||
{ | ||
internalType: "string", | ||
name: "", | ||
type: "string" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
], | ||
name: "totalSupply", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256" | ||
} | ||
], | ||
stateMutability: "view", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "transfer", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "from", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "address", | ||
name: "to", | ||
type: "address" | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "value", | ||
type: "uint256" | ||
} | ||
], | ||
name: "transferFrom", | ||
outputs: [ | ||
{ | ||
internalType: "bool", | ||
name: "success", | ||
type: "bool" | ||
} | ||
], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
} | ||
]; | ||
const MAX_APPROVAL$1 = ethers.ethers.BigNumber.from(2).pow(256).sub(1); | ||
/** | ||
* Validate the given address. | ||
* | ||
* @param {Address} address | ||
* @returns {boolean} `true` or `false` | ||
*/ | ||
const validateAddress$1 = (address) => { | ||
try { | ||
ethers.ethers.utils.getAddress(address); | ||
return true; | ||
} | ||
getExplorerUrl() { | ||
return this.explorerUrl; | ||
catch (error) { | ||
return false; | ||
} | ||
getExplorerAddressUrl(address) { | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); | ||
} | ||
getExplorerTxUrl(txID) { | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); | ||
} | ||
} | ||
}; | ||
@@ -992,3 +1237,3 @@ const getApiKeyQueryParameter = (apiKey) => (!!apiKey ? `&apiKey=${apiKey}` : ''); | ||
const address = tx.contractAddress; | ||
if (validateSymbol(symbol) && validateAddress(address)) { | ||
if (validateSymbol(symbol) && validateAddress$1(address)) { | ||
const tokenAsset = xchainUtil.assetFromString(`${chain}.${symbol}-${address}`); | ||
@@ -1149,3 +1394,3 @@ if (tokenAsset) { | ||
}; | ||
const contract = new ethers.ethers.Contract(contractAddress, erc20ABI, this.provider); | ||
const contract = new ethers.ethers.Contract(contractAddress, erc20ABI$1, this.provider); | ||
const balance = (yield contract.balanceOf(address)).toString(); | ||
@@ -1700,3 +1945,2 @@ const decimals = (yield contract.decimals()).toString(); | ||
exports.EtherscanProvider = EtherscanProvider; | ||
exports.ExplorerProvider = ExplorerProvider; | ||
exports.MAX_APPROVAL = MAX_APPROVAL; | ||
@@ -1703,0 +1947,0 @@ exports.abi = abi; |
@@ -1,5 +0,3 @@ | ||
import { Balance, Fees, Tx, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client'; | ||
import { Balance, Fees, OnlineDataProvider, Tx, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client'; | ||
import { Address, Asset, Chain } from '@xchainjs/xchain-util'; | ||
import { GasPrices } from '../../types'; | ||
import { OnlineDataProvider } from '../../types/provider-types'; | ||
export declare class CovalentProvider implements OnlineDataProvider { | ||
@@ -13,3 +11,2 @@ private baseUrl; | ||
constructor(apiKey: string, chain: Chain, chainId: number, nativeAsset: Asset, nativeAssetDecimals: number); | ||
estimateGasPrices(): Promise<GasPrices>; | ||
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>; | ||
@@ -16,0 +13,0 @@ private buildNativeTx; |
import { Provider } from '@ethersproject/abstract-provider'; | ||
import { Balance, Tx, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client'; | ||
import { Balance, OnlineDataProvider, Tx, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client'; | ||
import { Address, Asset, Chain } from '@xchainjs/xchain-util'; | ||
import { OnlineDataProvider } from '../../types/provider-types'; | ||
export declare class EtherscanProvider implements OnlineDataProvider { | ||
@@ -6,0 +5,0 @@ private provider; |
@@ -1,3 +0,2 @@ | ||
export * from './explorer-provider'; | ||
export * from './etherscan/types'; | ||
export * from './etherscan/etherscan-data-provider'; |
export * from './client-types'; | ||
export * from './provider-types'; |
{ | ||
"name": "@xchainjs/xchain-evm", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Genereic EVM client for XChainJS", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@xchainjs/xchain-client": "^0.13.5", | ||
"@xchainjs/xchain-client": "^0.13.6", | ||
"@xchainjs/xchain-crypto": "^0.2.6", | ||
@@ -45,3 +45,3 @@ "@xchainjs/xchain-util": "^0.12.0", | ||
"peerDependencies": { | ||
"@xchainjs/xchain-client": "^0.13.5", | ||
"@xchainjs/xchain-client": "^0.13.6", | ||
"@xchainjs/xchain-crypto": "^0.2.6", | ||
@@ -48,0 +48,0 @@ "@xchainjs/xchain-util": "^0.12.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
330255
4967
20
1