Skip to content

Commit

Permalink
feat: upgrade zksync-ethers and ethers versions to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
tx-nikola committed Jan 13, 2025
1 parent a27bdcf commit bc6a7f7
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 850 deletions.
2 changes: 1 addition & 1 deletion components/common/QrAddressInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script lang="ts" setup>
import { isAddress } from "ethers/lib/utils";
import { isAddress } from "ethers";
defineProps({
id: {
Expand Down
16 changes: 7 additions & 9 deletions components/common/input/TransactionAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@

<script lang="ts" setup>
import { LockClosedIcon } from "@heroicons/vue/24/outline";
import { BigNumber } from "ethers";
import type { Token, TokenAmount } from "@/types";
import type { BigNumberish } from "ethers";
const props = defineProps({
modelValue: {
Expand Down Expand Up @@ -130,7 +128,7 @@ const props = defineProps({
type: String,
},
maxAmount: {
type: String as PropType<BigNumberish>,
type: String,
},
error: {
type: String,
Expand Down Expand Up @@ -171,11 +169,11 @@ const inputted = computed({
const totalComputeAmount = computed(() => {
try {
if (!inputted.value || !selectedToken.value) {
return BigNumber.from("0");
return 0n;
}
return decimalToBigNumber(inputted.value, selectedToken.value.decimals);
} catch (error) {
return BigNumber.from("0");
return 0n;
}
});
const totalAmountPrice = computed(() => {
Expand All @@ -202,7 +200,7 @@ const isMaxAmountSet = computed(() => {
if (!props.maxAmount) {
return false;
}
return totalComputeAmount.value.eq(props.maxAmount);
return totalComputeAmount.value === BigInt(props.maxAmount);
});
const setMaxAmount = () => {
if (!maxDecimalAmount.value) return;
Expand All @@ -211,11 +209,11 @@ const setMaxAmount = () => {
const amountError = computed(() => {
if (!selectedToken.value) return;
if (tokenBalance.value && totalComputeAmount.value.gt(tokenBalance.value.amount)) {
if (tokenBalance.value && totalComputeAmount.value > BigInt(tokenBalance.value.amount)) {
return "exceeds_balance";
}
if (props.maxAmount && totalComputeAmount.value.gt(props.maxAmount)) {
if (BigNumber.from(props.maxAmount).isZero()) {
if (props.maxAmount && totalComputeAmount.value > BigInt(props.maxAmount)) {
if (BigInt(props.maxAmount) === BigInt(0)) {
return "insufficient_balance";
}
return "exceeds_max_amount";
Expand Down
4 changes: 1 addition & 3 deletions components/token/TokenBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
</template>

<script lang="ts" setup>
import { BigNumber } from "ethers";
import type { TokenPrice } from "@/types";
import type { BigNumberish } from "ethers";
Expand Down Expand Up @@ -73,7 +71,7 @@ const props = defineProps({
},
});
const isZeroAmount = computed(() => BigNumber.from(props.amount).isZero());
const isZeroAmount = computed(() => BigInt(props.amount) === 0n);
const fullAmount = computed(() => parseTokenAmount(props.amount, props.decimals));
const displayedAmount = computed(() => {
Expand Down
3 changes: 1 addition & 2 deletions components/transaction/TransferLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
PlusIcon,
} from "@heroicons/vue/24/outline";
import { useTimeAgo } from "@vueuse/core";
import { BigNumber } from "ethers";
import TokenAmount from "@/components/transaction/lineItem/TokenAmount.vue";
import TotalPrice from "@/components/transaction/lineItem/TotalPrice.vue";
Expand Down Expand Up @@ -127,7 +126,7 @@ const chainsLabel = computed(() => {
};
});
const computeAmount = computed(() => {
return BigNumber.from(props.transfer.amount || "0").toString();
return BigInt(props.transfer.amount || "0").toString();
});
const token = computed(() => {
return props.transfer.token;
Expand Down
3 changes: 1 addition & 2 deletions components/transaction/TransferWithdrawalLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<script lang="ts" setup>
import { ArrowRightIcon, MinusIcon } from "@heroicons/vue/24/outline";
import { useTimeAgo } from "@vueuse/core";
import { BigNumber } from "ethers";
import TokenAmount from "@/components/transaction/lineItem/TokenAmount.vue";
import TotalPrice from "@/components/transaction/lineItem/TotalPrice.vue";
Expand Down Expand Up @@ -99,7 +98,7 @@ const chainsLabel = computed(() => {
};
});
const computeAmount = computed(() => {
return BigNumber.from(props.transfer.amount || "0").toString();
return BigInt(props.transfer.amount || "0").toString();
});
const token = computed(() => {
return props.transfer.token;
Expand Down
4 changes: 1 addition & 3 deletions components/transaction/lineItem/TotalPrice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
</template>

<script lang="ts" setup>
import { BigNumber } from "ethers";
import type { Token } from "@/types";
import type { BigNumberish } from "ethers";
Expand All @@ -34,6 +32,6 @@ const props = defineProps({
});
const isZeroAmount = computed(() => {
return BigNumber.from(props.amount).isZero();
return BigInt(props.amount) === 0n;
});
</script>
3 changes: 1 addition & 2 deletions composables/transaction/useAllowance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from "ethers";
import { utils } from "zksync-ethers";
import IERC20 from "zksync-ethers/abi/IERC20.json";

Expand Down Expand Up @@ -31,7 +30,7 @@ export default (
functionName: "allowance",
args: [accountAddress.value, contractAddress],
})) as bigint;
return BigNumber.from(allowance);
return BigInt(allowance);
},
{ cache: false }
);
Expand Down
32 changes: 15 additions & 17 deletions composables/zksync/deposit/useFee.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { BigNumber } from "ethers";
import { parseEther } from "ethers/lib/utils";
import { parseEther } from "ethers";
import { utils } from "zksync-ethers";

import type { Token, TokenAmount } from "@/types";
import type { BigNumberish } from "ethers";

export type DepositFeeValues = {
maxFeePerGas?: BigNumber;
maxPriorityFeePerGas?: BigNumber;
gasPrice?: BigNumber;
baseCost?: BigNumber;
l1GasLimit: BigNumber;
l2GasLimit?: BigNumber;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
baseCost?: bigint;
l1GasLimit: bigint;
l2GasLimit?: bigint;
};

export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>) => {
Expand All @@ -31,10 +30,11 @@ export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>)
if (!fee.value) return undefined;

if (fee.value.l1GasLimit && fee.value.maxFeePerGas && fee.value.maxPriorityFeePerGas) {
return fee.value.l1GasLimit
.mul(fee.value.maxFeePerGas)
.add(fee.value.baseCost || "0")
.toString();
// return fee.value.l1GasLimit
// .mul(fee.value.maxFeePerGas)
// .add(fee.value.baseCost || "0")
// .toString();
return String(fee.value.l1GasLimit * fee.value.maxFeePerGas + (fee.value.baseCost || 0n));
} else if (fee.value.l1GasLimit && fee.value.gasPrice) {
return calculateFee(fee.value.l1GasLimit, fee.value.gasPrice).toString();
}
Expand All @@ -50,7 +50,7 @@ export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>)
}
const feeTokenBalance = balances.value.find((e) => e.address === feeToken.value!.address);
if (!feeTokenBalance) return true;
if (totalFee.value && BigNumber.from(totalFee.value).gt(feeTokenBalance.amount)) {
if (totalFee.value && BigInt(totalFee.value) > BigInt(feeTokenBalance.amount)) {
return false;
}
return true;
Expand All @@ -69,13 +69,11 @@ export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>)
};
const getERC20TransactionFee = () => {
return {
l1GasLimit: BigNumber.from(utils.L1_RECOMMENDED_MIN_ERC20_DEPOSIT_GAS_LIMIT),
l1GasLimit: BigInt(utils.L1_RECOMMENDED_MIN_ERC20_DEPOSIT_GAS_LIMIT),
};
};
const getGasPrice = async () => {
return BigNumber.from(await retry(() => getPublicClient().getGasPrice()))
.mul(110)
.div(100);
return (BigInt(await retry(() => getPublicClient().getGasPrice())) * 110n) / 100n;
};
const {
inProgress,
Expand Down
8 changes: 3 additions & 5 deletions composables/zksync/useFee.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { BigNumber } from "ethers";
import { type Provider } from "zksync-ethers";

import type { Token, TokenAmount } from "@/types";
import type { BigNumberish } from "ethers";

export type FeeEstimationParams = {
type: "transfer" | "withdrawal";
Expand All @@ -18,8 +16,8 @@ export default (
) => {
let params: FeeEstimationParams | undefined;

const gasLimit = ref<BigNumberish | undefined>();
const gasPrice = ref<BigNumberish | undefined>();
const gasLimit = ref<bigint | undefined>();
const gasPrice = ref<bigint | undefined>();

const totalFee = computed(() => {
if (!gasLimit.value || !gasPrice.value) return undefined;
Expand All @@ -35,7 +33,7 @@ export default (
}
const feeTokenBalance = balances.value.find((e) => e.address === feeToken.value!.address);
if (!feeTokenBalance) return true;
if (totalFee.value && BigNumber.from(totalFee.value).gt(feeTokenBalance.amount)) {
if (totalFee.value && BigInt(totalFee.value) > feeTokenBalance.amount) {
return false;
}
return true;
Expand Down
9 changes: 4 additions & 5 deletions composables/zksync/useWithdrawalFinalization.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useMemoize } from "@vueuse/core";
import { BigNumber, type BigNumberish } from "ethers";
import { Wallet } from "zksync-ethers";
import IL1SharedBridge from "zksync-ethers/abi/IL1SharedBridge.json";

Expand All @@ -24,8 +23,8 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
.then((network) => network.chainId)
);

const gasLimit = ref<BigNumberish | undefined>();
const gasPrice = ref<BigNumberish | undefined>();
const gasLimit = ref<bigint | undefined>();
const gasPrice = ref<bigint | undefined>();
const finalizeWithdrawalParams = ref<
| {
l1BatchNumber: unknown;
Expand Down Expand Up @@ -88,9 +87,9 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {

const transactionParams = await getTransactionParams();
const [price, limit] = await Promise.all([
retry(async () => BigNumber.from((await publicClient.getGasPrice()).toString())),
retry(async () => BigInt((await publicClient.getGasPrice()).toString())),
retry(async () => {
return BigNumber.from(
return BigInt(
(
await publicClient.estimateContractGas({
...transactionParams,
Expand Down
Loading

0 comments on commit bc6a7f7

Please sign in to comment.