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

Fix error for @reef chain/evm provider 2.0.0 #24

Merged
merged 5 commits into from
Jan 26, 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reef-chain/react-lib",
"version": "2.3.2",
"version": "2.4.0",
"description": "Reef React Library",
"author": "Reef chain",
"license": "MIT",
Expand Down Expand Up @@ -33,7 +33,7 @@
"@polkadot/react-identicon": "^0.86.4",
"@reef-chain/evm-provider": "^2.0.1",
"@reef-chain/ui-kit": "^1.1.6",
"@reef-chain/util-lib": "^2.1.13",
"@reef-chain/util-lib": "^2.2.0",
"@reef-defi/extension-base": "^1.0.14",
"@reef-defi/extension-dapp": "^1.0.14",
"@reef-defi/extension-inject": "^1.0.14",
Expand Down
25 changes: 13 additions & 12 deletions src/hooks/useAddLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { Dispatch, useEffect } from 'react';
import { BigNumber, Contract } from 'ethers';
import { AxiosInstance } from 'axios';
import type {DexProtocolv2 as Network} from "@reef-chain/util-lib/dist/network";
import { toBN } from '@reef-chain/evm-provider/utils';
import { ERC20 } from '../assets/abi/ERC20';
import { getReefswapRouter } from '../rpc';
import {
Expand Down Expand Up @@ -242,16 +243,16 @@ export const onAddLiquidity = ({
const approveExtrinsic1 = signer.signer.provider.api.tx.evm.call(
approveTransaction1.to,
approveTransaction1.data,
BigNumber.from(approveTransaction1.value || 0),
approveResources1.gas,
approveResources1.storage.lt(0) ? BigNumber.from(0) : approveResources1.storage,
toBN(approveTransaction1.value || 0),
toBN(approveResources1.gas),
approveResources1.storage.lt(0) ? toBN(0) : toBN(approveResources1.storage),
);
const approveExtrinsic2 = signer.signer.provider.api.tx.evm.call(
approveTransaction2.to,
approveTransaction2.data,
BigNumber.from(approveTransaction2.value || 0),
approveResources2.gas,
approveResources2.storage.lt(0) ? BigNumber.from(0) : approveResources2.storage,
toBN(approveTransaction2.value || 0),
toBN(approveResources2.gas),
approveResources2.storage.lt(0) ? toBN(0) : toBN(approveResources2.storage),
);

const disableStakeBtn = (): void => {
Expand All @@ -264,9 +265,9 @@ export const onAddLiquidity = ({
const provideExtrinsic = signer.signer.provider.api.tx.evm.call(
provideTransaction.to,
provideTransaction.data,
BigNumber.from(provideTransaction.value || 0),
BigNumber.from(9636498), // Value was used from estimateResources, which can only be ran if tokens are approved
BigNumber.from(68206), // Value was used from estimateResources, which can only be ran if tokens are approved
toBN(provideTransaction.value || 0),
toBN(9636498), // Value was used from estimateResources, which can only be ran if tokens are approved
toBN(68206), // Value was used from estimateResources, which can only be ran if tokens are approved
);

// Batching extrinsics
Expand Down Expand Up @@ -370,9 +371,9 @@ export const onAddLiquidity = ({
const provideExtrinsic = signer.signer.provider.api.tx.evm.call(
provideTransaction.to,
provideTransaction.data,
BigNumber.from(provideTransaction.value || 0),
provideResources.gas,
provideResources.storage.lt(0) ? BigNumber.from(0) : provideResources.storage,
toBN(provideTransaction.value || 0),
toBN(provideResources.gas),
provideResources.storage.lt(0) ? toBN(0) : toBN(provideResources.storage),
);

const signAndSendProvide = new Promise<void>((resolve, reject) => {
Expand Down
21 changes: 11 additions & 10 deletions src/hooks/useRemoveLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import Uik from '@reef-chain/ui-kit';
import BN from 'bignumber.js';
import { BigNumber, Contract } from 'ethers';
import { Contract } from 'ethers';
import React, { Dispatch, useEffect } from 'react';
import { AxiosInstance } from 'axios';
import type {DexProtocolv2 as Network} from "@reef-chain/util-lib/dist/network";
import { toBN } from '@reef-chain/evm-provider/utils';
import { ReefswapPair } from '../assets/abi/ReefswapPair';
import { getReefswapRouter } from '../rpc';
import {
Expand Down Expand Up @@ -177,18 +178,18 @@ export const onRemoveLiquidity = ({
const approveExtrinsic = signer.provider.api.tx.evm.call(
approveTransaction.to,
approveTransaction.data,
BigNumber.from(approveTransaction.value || 0),
approveResources.gas,
approveResources.storage.lt(0) ? BigNumber.from(0) : approveResources.storage,
toBN(approveTransaction.value || 0),
toBN(approveResources.gas),
approveResources.storage.lt(0) ? toBN(0) : toBN(approveResources.storage),
);

if (batchTxs) {
const withdrawExtrinsic = signer.provider.api.tx.evm.call(
withdrawTransaction.to,
withdrawTransaction.data,
BigNumber.from(withdrawTransaction.value || 0),
BigNumber.from(626914).mul(2), // hardcoded gas estimation, multiply by 2 as a safety margin
BigNumber.from(64).mul(2), // hardcoded storage estimation, multiply by 2 as a safety margin
toBN(withdrawTransaction.value || 0),
toBN(626914 * 2), // hardcoded gas estimation, multiply by 2 as a safety margin
toBN(64 * 2), // hardcoded storage estimation, multiply by 2 as a safety margin
);

// Batching extrinsics
Expand Down Expand Up @@ -253,9 +254,9 @@ export const onRemoveLiquidity = ({
const withdrawExtrinsic = signer.provider.api.tx.evm.call(
withdrawTransaction.to,
withdrawTransaction.data,
BigNumber.from(withdrawTransaction.value || 0),
withdrawResources.gas,
withdrawResources.storage.lt(0) ? BigNumber.from(0) : withdrawResources.storage,
toBN(withdrawTransaction.value || 0),
toBN(withdrawResources.gas),
withdrawResources.storage.lt(0) ? toBN(0) : toBN(withdrawResources.storage),
);
const signAndSendWithdraw = new Promise<void>((resolve, reject) => {
withdrawExtrinsic.signAndSend(
Expand Down
19 changes: 10 additions & 9 deletions src/hooks/useSwapState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BigNumber, Contract } from 'ethers';
import { Dispatch, useEffect, useRef } from 'react';
import { AxiosInstance } from 'axios';
import type {DexProtocolv2 as Network} from "@reef-chain/util-lib/dist/network";
import { toBN } from '@reef-chain/evm-provider/utils';
import { ERC20 } from '../assets/abi/ERC20';
import { getReefswapRouter } from '../rpc';
import {
Expand Down Expand Up @@ -253,18 +254,18 @@ export const onSwap = ({
const approveExtrinsic = signer.provider.api.tx.evm.call(
approveTransaction.to,
approveTransaction.data,
BigNumber.from(approveTransaction.value || 0),
approveResources.gas,
approveResources.storage.lt(0) ? BigNumber.from(0) : approveResources.storage,
toBN(approveTransaction.value || 0),
toBN(approveResources.gas),
approveResources.storage.lt(0) ? toBN(0) : toBN(approveResources.storage),
);

if (batchTxs) {
const tradeExtrinsic = signer.provider.api.tx.evm.call(
tradeTransaction.to,
tradeTransaction.data,
BigNumber.from(tradeTransaction.value || 0),
BigNumber.from(582938).mul(2), // hardcoded gas estimation, multiply by 2 as a safety margin
BigNumber.from(64).mul(2), // hardcoded storage estimation, multiply by 2 as a safety margin
toBN(tradeTransaction.value || 0),
toBN(582938 * 2), // hardcoded gas estimation, multiply by 2 as a safety margin
toBN(64 * 2), // hardcoded storage estimation, multiply by 2 as a safety margin
);

// Batching extrinsics
Expand Down Expand Up @@ -330,9 +331,9 @@ export const onSwap = ({
const tradeExtrinsic = signer.provider.api.tx.evm.call(
tradeTransaction.to,
tradeTransaction.data,
BigNumber.from(tradeTransaction.value || 0),
tradeResources.gas,
tradeResources.storage.lt(0) ? BigNumber.from(0) : tradeResources.storage,
toBN(tradeTransaction.value || 0),
toBN(tradeResources.gas),
tradeResources.storage.lt(0) ? toBN(0) : toBN(tradeResources.storage),
);

const signAndSendTrade = new Promise<void>((resolve, reject) => {
Expand Down
Loading
Loading