Skip to content

Commit

Permalink
Upgrade axios and web3 (#77)
Browse files Browse the repository at this point in the history
* chore: upgrade deps axios and web3.

* chore: bump version.
  • Loading branch information
gdethier committed Apr 9, 2024
1 parent 8484da6 commit af40ab2
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 1,503 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/AstarNetwork/astar.js.git"
},
"sideEffects": false,
"version": "0.2.8",
"version": "0.2.9",
"workspaces": [
"packages/*",
"examples/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/api-derive/package.json
@@ -1,6 +1,6 @@
{
"name": "@astar-network/astar-api-derive",
"version": "0.2.8",
"version": "0.2.9",
"description": "Astar JS API",
"main": "index.js",
"author": "Astar Network <info@astar.network>",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
@@ -1,6 +1,6 @@
{
"name": "@astar-network/astar-api",
"version": "0.2.8",
"version": "0.2.9",
"description": "Astar JS API",
"main": "index.js",
"author": "Astar Network <info@astar.network>",
Expand Down
17 changes: 3 additions & 14 deletions packages/api/src/index.spec.ts
@@ -1,8 +1,6 @@
import { options } from '@astar-network/astar-api';
import { ApiPromise, WsProvider } from '@polkadot/api';

const getAddressEnum = (address: string) => ({ Evm: address });

const endpoint = 'wss://shiden.api.onfinality.io/public-ws';
const provider = new WsProvider(endpoint);

Expand All @@ -12,21 +10,12 @@ describe('astar-api', () => {
await api.isReadyOrError;
});

test('api.query.dappsStaking.contractEraStake.entries', async (): Promise<void> => {
const address = '0x072416b9df2382a62Df34956DffB7B0aDdf668F9';
test('api.query.dappStaking.contractStake', async (): Promise<void> => {
if (api === null) {
fail('API is not initialized');
}
const stakingByEra = await api.query.dappsStaking.contractEraStake.entries(getAddressEnum(address));
// stakingByEra.forEach(([era, stakeInfo]) => {
stakingByEra.forEach(([_, stakeInfo]) => {
// console.log({
// era: (era.toHuman() as any[])[1],
// stakeInfo: `${Object.keys(stakeInfo.unwrap().stakers.toHuman()).length} stakers`
// });
// expect(era).toBeInstanceOf(StorageKey);
expect(stakeInfo).not.toBeNull();
});
const stakingByEra = await api.query.dappStaking.contractStake(0);
expect(stakingByEra).not.toBeNull();
});

afterAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-core/package.json
@@ -1,6 +1,6 @@
{
"name": "@astar-network/astar-sdk-core",
"version": "0.2.8",
"version": "0.2.9",
"description": "the core for astar SDK",
"main": "index.js",
"author": "Astar Network <info@astar.network>",
Expand All @@ -25,10 +25,10 @@
"@ethersproject/bignumber": "^5.6.2",
"@polkadot/util": "^12.3.2",
"@polkadot/util-crypto": "^12.3.2",
"axios": "^0.24.0",
"axios": "^1.6.8",
"bn.js": "^5.2.1",
"ethers": "^5.6.9",
"web3": "^1.7.3"
"web3": "^4.7.0"
},
"devDependencies": {
"@types/jest": "^28.1.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk-core/src/modules/gas-api/utils/index.ts
Expand Up @@ -2,13 +2,13 @@ import axios from 'axios';
import { BN } from '@polkadot/util';
import { ethers } from 'ethers';
import Web3 from 'web3';
import { TransactionConfig } from 'web3-eth';
import { TransactionCall } from 'web3-types';
import { ApiGasNow, GasPrice, GAS_API_URL } from '../index';
import { astarChain } from '../../config';

export const getEvmGas = async (web3: Web3, selectedGasPrice: string): Promise<string> => {
const gasPriceFallback = await web3.eth.getGasPrice();
const gasPrice = selectedGasPrice !== '0' ? selectedGasPrice : gasPriceFallback;
const gasPrice = selectedGasPrice !== '0' ? selectedGasPrice : gasPriceFallback.toString();
return gasPrice;
};

Expand All @@ -27,7 +27,7 @@ export const getEvmGasCost = async ({ isNativeToken,
value: string;
encodedData?: string;
}): Promise<GasPrice> => {
const tx: TransactionConfig = isNativeToken
const tx: TransactionCall = isNativeToken
? {
from: fromAddress,
to: toAddress,
Expand All @@ -42,7 +42,7 @@ export const getEvmGasCost = async ({ isNativeToken,
};

const numEstimatedGas = await web3.eth.estimateGas(tx);
const estimatedGas = new BN(numEstimatedGas);
const estimatedGas = new BN(numEstimatedGas.toString());
const data = {
...evmGasPrice,
slow: ethers.utils.formatEther(estimatedGas.mul(new BN(evmGasPrice.slow)).toString()),
Expand Down
2 changes: 1 addition & 1 deletion packages/type-definitions/package.json
@@ -1,6 +1,6 @@
{
"name": "@astar-network/astar-type-definitions",
"version": "0.2.8",
"version": "0.2.9",
"description": "Polkadot.js type definitions for astar Network",
"main": "index.js",
"author": "Astar Network <info@astar.network>",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
@@ -1,6 +1,6 @@
{
"name": "@astar-network/astar-types",
"version": "0.2.8",
"version": "0.2.9",
"description": "Polkadot.js type definitions for Astar Network",
"main": "index.js",
"author": "Astar Network <info@astar.network>",
Expand Down

0 comments on commit af40ab2

Please sign in to comment.