Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ethers & eth fee request #1396

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@
"dependencies": {
"@metamask/detect-provider": "^2.0.0",
"@soramitsu/soraneo-wallet-web": "1.33.1",
"@walletconnect/ethereum-provider": "^2.11.2",
"@walletconnect/ethereum-provider": "^2.12.2",
"@walletconnect/modal": "^2.6.2",
"core-js": "^3.36.0",
"core-js": "^3.37.0",
"country-code-emoji": "^2.3.0",
"country-flag-emoji-polyfill": "^0.1.8",
"direct-vuex": "^0.12.1",
"echarts": "^5.5.0",
"email-validator": "^2.0.4",
"ethers": "6.8.0",
"ethers": "6.12.1",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"uuidv4": "^6.2.13",
"vue": "2.7.14",
"vue-class-component": "^7.2.6",
"vue-echarts": "^6.6.9",
"vue-echarts": "^6.7.1",
"vue-i18n": "^8.28.2",
"vue-property-decorator": "^9.1.2",
"vue-router": "^3.6.5",
"vuex": "^3.6.2"
},
"devDependencies": {
"@babel/runtime": "^7.23.9",
"@babel/runtime": "^7.24.5",
"@types/electron-devtools-installer": "^2.2.5",
"@types/jest": "^29.5.12",
"@types/jsdom": "^21.1.6",
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.21",
"@types/lodash": "^4.17.1",
"@types/node": "^20.12.8",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vue/cli-plugin-babel": "5.0.8",
Expand Down Expand Up @@ -86,10 +86,10 @@
"lint-staged": "^9.5.0",
"node-polyfill-webpack-plugin": "^3.0.0",
"prettier": "^2.8.8",
"sass": "^1.71.1",
"sass-loader": "^14.1.1",
"sass": "^1.76.0",
"sass-loader": "^14.2.1",
"ts-jest": "^27.1.5",
"typescript": "~5.3.3",
"typescript": "~5.4.5",
"vue-cli-plugin-electron-builder": "^3.0.0-alpha.4",
"vue-cli-plugin-test-attrs": "^0.1.5",
"vue-template-compiler": "2.7.14"
Expand Down
10 changes: 7 additions & 3 deletions src/store/assets/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,23 @@ async function getRegisteredAssets(context: ActionContext<any, any>): Promise<Re
const actions = defineActions({
// for common usage
async getRegisteredAssets(context): Promise<void> {
const { commit } = assetsActionContext(context);
const { commit, dispatch } = assetsActionContext(context);

commit.resetRegisteredAssets();
commit.setRegisteredAssets();
commit.setRegisteredAssetsFetching(true);

try {
const list = await getRegisteredAssets(context);
const registeredAssets = list.reduce((buffer, asset) => ({ ...buffer, ...asset }), {});

commit.setRegisteredAssets(registeredAssets);
// update assets data (for Eth bridge)
await dispatch.updateRegisteredAssets();
} catch (error) {
console.error(error);
commit.resetRegisteredAssets();
commit.setRegisteredAssets();
} finally {
commit.setRegisteredAssetsFetching(false);
}
},

Expand Down
7 changes: 1 addition & 6 deletions src/store/assets/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ const mutations = defineMutations<AssetsState>()({
setRegisteredAssetsFetching(state, value: boolean): void {
state.registeredAssetsFetching = value;
},
setRegisteredAssets(state, assets: Record<string, BridgeRegisteredAsset>): void {
setRegisteredAssets(state, assets: Record<string, BridgeRegisteredAsset> = {}): void {
state.registeredAssets = Object.freeze({ ...assets });
state.registeredAssetsFetching = false;
},
resetRegisteredAssets(state): void {
state.registeredAssets = {};
state.registeredAssetsFetching = false;
},
});

Expand Down
6 changes: 2 additions & 4 deletions src/utils/ethers-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,10 @@ async function getEvmNetworkId(): Promise<number> {
}

async function getEvmGasPrice(): Promise<bigint> {
const toBN = (value: bigint | null) => value ?? BigInt(0);
const ethersInstance = getEthersInstance();
const { maxFeePerGas, maxPriorityFeePerGas } = await ethersInstance.getFeeData();
const priorityFee = BigInt('1500000000'); // 1.5 GWEI
const maxFee = toBN(maxFeePerGas);
const baseFee = (maxFee - toBN(maxPriorityFeePerGas)) / BigInt(2);
const baseFeeHex = await ethersInstance.send('eth_gasPrice', []); // hex
const baseFee = BigInt(parseInt(baseFeeHex, 16));
const baseFeeMarket = (baseFee * BigInt(1355)) / BigInt(1000); // market rate like in Metamask
const gasPrice = baseFeeMarket + priorityFee;

Expand Down
Loading