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 bridge withdraw and speed #115

Merged
merged 2 commits into from
Feb 9, 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
2 changes: 1 addition & 1 deletion apps/auth-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@auth/core": "^0.25.1"
"@auth/core": "^0.26.3"
},
"devDependencies": {
"@realms-world/eslint-config": "workspace:*",
Expand Down
14 changes: 7 additions & 7 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@mdx-js/loader": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"@mui/material": "^5.15.7",
"@mui/styles": "^5.15.7",
"@mui/styles": "^5.15.8",
"@next/mdx": "^14.1.0",
"@rainbow-me/rainbowkit": "2.0.0-beta.2",
"@realms-world/api": "workspace:*",
Expand All @@ -31,7 +31,7 @@
"@realms-world/styles": "workspace:*",
"@realms-world/ui": "workspace:*",
"@realms-world/utils": "workspace:*",
"@reservoir0x/reservoir-kit-ui": "^1.25.2",
"@reservoir0x/reservoir-kit-ui": "^1.25.6",
"@starknet-react/chains": "^0.1.6",
"@starknet-react/core": "^2.2.4",
"@starkware-industries/commons-js-enums": "^1.2.0",
Expand All @@ -51,15 +51,15 @@
"framer-motion": "^11.0.3",
"inngest": "^3.13.0",
"lodash": "4.17.21",
"lucide-react": "^0.321.0",
"lucide-react": "^0.323.0",
"next": "^14.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"starknet": "^5.24.3",
"starknetkit": "^1.1.3",
"superjson": "2.2.1",
"viem": "^2.7.3",
"wagmi": "2.5.5",
"viem": "^2.7.6",
"wagmi": "2.5.6",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -69,8 +69,8 @@
"@realms-world/tsconfig": "workspace:*",
"@types/mdx": "^2.0.11",
"@types/node": "^20.11.16",
"@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"dotenv-cli": "^7.3.0",
"eslint": "^8.56.0",
"prettier": "^3.2.5",
Expand Down
22 changes: 13 additions & 9 deletions apps/nextjs/src/app/providers/WalletsProvider/WalletsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import React, {
import { ERC20 as L1_ERC20_ABI } from "@/abi/L1/ERC20";
import L2_C1ERC20 from "@/abi/L2/C1ERC20.json";
import L2_ERC20 from "@/abi/L2/ERC20.json";
import { NETWORK_NAME } from "@/constants/env";
import {
NETWORK_NAME,
SUPPORTED_L1_CHAIN_ID,
SUPPORTED_L2_CHAIN_ID,
} from "@/constants/env";
import { ChainType, tokens as tokensConst } from "@/constants/tokens";
import {
useContractRead,
Expand All @@ -21,6 +25,8 @@ import {
import { hash, uint256 } from "starknet";
import { useBalance, useAccount as useL1Account } from "wagmi";

import { ETH, LORDS } from "@realms-world/constants";

import { initialState, reducer } from "./wallets-reducer";

interface WalletsProviderContextValue {
Expand Down Expand Up @@ -76,7 +82,9 @@ export const WalletsProvider: React.FC<WalletsContextProviderProps> = ({
isFetching: l2LordsIsLoading,
refetch: l2LordsRefetch,
} = useContractRead({
address: tokensConst.L2.LORDS.tokenAddress[ChainType.L2[NETWORK_NAME]]!,
address:
LORDS[SUPPORTED_L2_CHAIN_ID]
?.address /*tokensConst.L2.LORDS.tokenAddress[ChainType.L2[NETWORK_NAME]]!,*/,
abi: L2_C1ERC20,
functionName: "balance_of",
enabled: !!l2Account,
Expand All @@ -85,7 +93,7 @@ export const WalletsProvider: React.FC<WalletsContextProviderProps> = ({
});

const { data: l2EthBalance, isFetching: l2EthIsLoading } = useContractRead({
address: tokensConst.L2.ETH.tokenAddress[ChainType.L2[NETWORK_NAME]]!,
address: ETH[SUPPORTED_L2_CHAIN_ID]?.address,
abi: L2_ERC20,
functionName: "balanceOf",
enabled: !!l2Account,
Expand All @@ -94,18 +102,14 @@ export const WalletsProvider: React.FC<WalletsContextProviderProps> = ({
});

const l1ERC20Contract = {
address: tokensConst.L1.LORDS.tokenAddress[
ChainType.L1[NETWORK_NAME]
] as `0x${string}`,
address: LORDS[SUPPORTED_L1_CHAIN_ID]?.address,
abi: L1_ERC20_ABI,
};

const { data: l1LordsBalance, refetch: l1LordsRefetch } = useBalance({
...l1ERC20Contract,
address: l1Account!,
token: tokensConst.L1.LORDS.tokenAddress[
ChainType.L1[NETWORK_NAME]
] as `0x${string}`,
token: LORDS[SUPPORTED_L1_CHAIN_ID]?.address as `0x${string}`,
});

const { data: l1EthBalance } = useBalance({
Expand Down
11 changes: 6 additions & 5 deletions apps/nextjs/src/hooks/bridge/useWriteDepositLords.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useCallback } from "react";
import { StarknetBridgeLords as L1_BRIDGE_ABI } from "@/abi/L1/StarknetBridgeLords";
import { SUPPORTED_L1_CHAIN_ID } from "@/constants/env";
import { tokens } from "@/constants/tokens";
import { useAccount as useL2Account } from "@starknet-react/core";
import { parseEther } from "viem";
import { useWriteContract } from "wagmi";

import { LORDS_BRIDGE_ADDRESS } from "@realms-world/constants";

const FUNCTION = "deposit";

export function useWriteDepositLords() {
Expand All @@ -17,12 +18,12 @@ export function useWriteDepositLords() {
console.log(l2Address, amount);

return await writeContractAsync({
address: tokens.L1.LORDS.bridgeAddress?.[
SUPPORTED_L1_CHAIN_ID
] as `0x${string}`,
address: LORDS_BRIDGE_ADDRESS[SUPPORTED_L1_CHAIN_ID] as `0x${string}`,
abi: L1_BRIDGE_ABI,
functionName: FUNCTION,
args: [amount, BigInt(l2Address), BigInt(1)],
//@ts-expect-error should accept value
value: parseEther("0.000000000001"),
});
},
[writeContractAsync],
Expand Down
7 changes: 3 additions & 4 deletions apps/nextjs/src/hooks/bridge/useWriteFinalizeWithdrawLords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { useCallback } from "react";
import { StarknetBridgeLords as L1_BRIDGE_ABI } from "@/abi/L1/StarknetBridgeLords";
import { SUPPORTED_L1_CHAIN_ID } from "@/constants/env";
import { tokens } from "@/constants/tokens";
import { useWriteContract } from "wagmi";

import { LORDS_BRIDGE_ADDRESS } from "@realms-world/constants";

const FUNCTION = "withdraw";

export function useWriteFinalizeWithdrawLords() {
Expand All @@ -24,9 +25,7 @@ export function useWriteFinalizeWithdrawLords() {
console.log(l1Address, amount);

return await writeContractAsync({
address: tokens.L1.LORDS.bridgeAddress?.[
SUPPORTED_L1_CHAIN_ID
] as `0x${string}`,
address: LORDS_BRIDGE_ADDRESS[SUPPORTED_L1_CHAIN_ID] as `0x${string}`,
abi: L1_BRIDGE_ABI,
functionName: FUNCTION,
args: [amount, l1Address],
Expand Down
10 changes: 5 additions & 5 deletions apps/nextjs/src/hooks/bridge/useWriteInitiateWithdrawLords.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import type { Call } from "starknet";
import { useMemo, useState } from "react";
import { useMemo } from "react";
import L2BridgeABI from "@/abi/L2/LordsBridge.json";
import { NETWORK_NAME } from "@/constants/env";
import { ChainType, tokens } from "@/constants/tokens";
import { SUPPORTED_L2_CHAIN_ID } from "@/constants/env";
import {
useContract,
useContractWrite as useL2ContractWrite,
} from "@starknet-react/core";
import { parseEther } from "viem";
import { useAccount as useL1Account } from "wagmi";

import { LORDS_BRIDGE_ADDRESS } from "@realms-world/constants";

export const useWriteInitiateWithdrawLords = ({
amount,
}: {
amount: string | null;
}) => {
const { address: addressL1 } = useL1Account();

const l2BridgeAddress =
tokens.L2.LORDS.bridgeAddress?.[ChainType.L2[NETWORK_NAME]];
const l2BridgeAddress = LORDS_BRIDGE_ADDRESS[SUPPORTED_L2_CHAIN_ID];
const { contract } = useContract({
abi: L2BridgeABI,
address: l2BridgeAddress as `0x${string}`,
Expand Down
14 changes: 5 additions & 9 deletions apps/nextjs/src/hooks/useTokenContract.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use client";

import { ERC20 as L1_ERC20_ABI } from "@/abi/L1/ERC20";
import { NETWORK_NAME } from "@/constants/env";
import { ChainType, tokens } from "@/constants/tokens";
import { SUPPORTED_L1_CHAIN_ID } from "@/constants/env";
import { isEth } from "@/utils/utils";
import { useAccount as useL2Account } from "@starknet-react/core";
import {
useAccount as useL1Account,
useWriteContract as useL1ContractWrite,
useReadContract,
} from "wagmi";

import { LORDS, LORDS_BRIDGE_ADDRESS } from "@realms-world/constants";

export const useTokenContractAPI = (
symbol: "LORDS" | "ETH",
spender?: boolean | string,
Expand All @@ -20,16 +20,12 @@ export const useTokenContractAPI = (
const l2BridgeAddress = tokens.L2.LORDS.bridgeAddress?.[ChainType.L2[network]]
const l2LordsAddress = tokens.L2.LORDS.tokenAddress?.[ChainType.L2[network]]*/

const l1Token = tokens.L1[symbol];
const l2Token = tokens.L2[symbol];

const { address: l1Account } = useL1Account();
const { address: l2Account } = useL2Account();

const l1ERC20Contract = {
address: isEth(symbol)
? "0x0000000000000000"
: (l1Token.tokenAddress[ChainType.L1[NETWORK_NAME]] as `0x${string}`),
: (LORDS[SUPPORTED_L1_CHAIN_ID]?.address as `0x${string}`),
abi: L1_ERC20_ABI,
};

Expand All @@ -45,7 +41,7 @@ export const useTokenContractAPI = (
args: [
l1Account!,
(spender == true
? l1Token.bridgeAddress[ChainType.L1[NETWORK_NAME]]
? LORDS_BRIDGE_ADDRESS[SUPPORTED_L1_CHAIN_ID]
: spender) as `0x${string}`,
],
//enabled: !!(l1Account && spender),
Expand Down
3 changes: 1 addition & 2 deletions apps/nextjs/src/hooks/useTransferToL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
TransferStep,
TransferToL1Steps,
} from "@/constants/transferSteps";
import { useWriteInitiateWithdrawLords } from "@/hooks/bridge/useWriteInitiateWithdrawLords";
import { useAccount as useL2Account } from "@starknet-react/core";
import { useAccount, useWaitForTransactionReceipt } from "wagmi";

Expand Down Expand Up @@ -151,7 +150,7 @@ export const useCompleteTransferToL1 = () => {
console.log("Calling withdraw", withdrawalEvents.amount);
if (!l1Address) return "L1 Address not defined";
const hash = await writeAsync({
amount: withdrawalEvents.amount,
amount: withdrawalEvents[0].amount,
l1Address,
});
onTransactionHash(null, hash);
Expand Down
6 changes: 4 additions & 2 deletions apps/nextjs/src/hooks/useTransferToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
useWaitForTransactionReceipt,
} from "wagmi";

import { LORDS_BRIDGE_ADDRESS } from "@realms-world/constants";

import { useWriteDepositLords } from "./bridge/useWriteDepositLords";
import { useTokenContractAPI } from "./useTokenContract";
import { useTransfer } from "./useTransfer";
Expand Down Expand Up @@ -54,7 +56,7 @@ export const useTransferToL2 = () => {

const { refetch } = useTransferLog();

const l1BridgeAddress = tokens.L1.LORDS.bridgeAddress?.[
const l1BridgeAddress = LORDS_BRIDGE_ADDRESS[
SUPPORTED_L1_CHAIN_ID
] as `0x${string}`;

Expand Down Expand Up @@ -82,7 +84,7 @@ export const useTransferToL2 = () => {
type: ActionType.TRANSFER_TO_L2,
sender: l1Account,
recipient: l2Address,
l1hash: event.transactionHash,
l1hash: event,
name: "Lords",
symbol: "LORDS",
amount: amount.toString(),
Expand Down
54 changes: 27 additions & 27 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"class-variance-authority": "^0.7.0",
"date-fns": "^3.3.1",
"react-day-picker": "^8.10.0",
"lucide-react": "^0.321.0"
"lucide-react": "^0.323.0"
},
"devDependencies": {
"@realms-world/eslint-config": "workspace:*",
Expand All @@ -57,46 +57,46 @@
"@realms-world/utils": "workspace:*",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"@storybook/addon-actions": "^7.6.12",
"@storybook/addon-backgrounds": "^7.6.12",
"@storybook/addon-docs": "^7.6.12",
"@storybook/addon-essentials": "^7.6.12",
"@storybook/addon-interactions": "^7.6.12",
"@storybook/addon-links": "^7.6.12",
"@storybook/addon-measure": "^7.6.12",
"@storybook/addon-outline": "^7.6.12",
"@storybook/addon-actions": "^7.6.13",
"@storybook/addon-backgrounds": "^7.6.13",
"@storybook/addon-docs": "^7.6.13",
"@storybook/addon-essentials": "^7.6.13",
"@storybook/addon-interactions": "^7.6.13",
"@storybook/addon-links": "^7.6.13",
"@storybook/addon-measure": "^7.6.13",
"@storybook/addon-outline": "^7.6.13",
"@storybook/addon-styling": "^1.3.7",
"@storybook/addon-themes": "^7.6.12",
"@storybook/addons": "^7.6.12",
"@storybook/blocks": "^7.6.12",
"@storybook/channel-postmessage": "^7.6.12",
"@storybook/channel-websocket": "^7.6.12",
"@storybook/client-api": "^7.6.12",
"@storybook/nextjs": "^7.6.12",
"@storybook/preview-api": "^7.6.12",
"@storybook/preview-web": "^7.6.12",
"@storybook/react": "^7.6.12",
"@storybook/react-vite": "^7.6.12",
"@storybook/addon-themes": "^7.6.13",
"@storybook/addons": "^7.6.13",
"@storybook/blocks": "^7.6.13",
"@storybook/channel-postmessage": "^7.6.13",
"@storybook/channel-websocket": "^7.6.13",
"@storybook/client-api": "^7.6.13",
"@storybook/nextjs": "^7.6.13",
"@storybook/preview-api": "^7.6.13",
"@storybook/preview-web": "^7.6.13",
"@storybook/react": "^7.6.13",
"@storybook/react-vite": "^7.6.13",
"@storybook/testing-library": "^0.2.2",
"@storybook/theming": "^7.6.12",
"@storybook/theming": "^7.6.13",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.4.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/jsdom": "^21.1.6",
"@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.2.2",
"autoprefixer": "^10.4.17",
"chromatic": "^10.7.1",
"chromatic": "^10.9.0",
"eslint-plugin-storybook": "^0.6.15",
"jsdom": "^24.0.0",
"postcss": "^8.4.33",
"postcss": "^8.4.35",
"prop-types": "^15.8.1",
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^5.0.5",
"storybook": "^7.6.12",
"storybook": "^7.6.13",
"tailwindcss": "3.4.1",
"tsc-alias": "^1.8.8",
"vite": "^5.0.12",
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
},
"devDependencies": {
"@manypkg/cli": "^0.21.2",
"@turbo/gen": "^1.12.2",
"@turbo/gen": "^1.12.3",
"npm-check-updates": "^16.14.14",
"prettier": "^3.2.5",
"tsup": "^8.0.1",
"turbo": "^1.12.2",
"turbo": "^1.12.3",
"typescript": "^5.3.3"
},
"prettier": "@realms-world/prettier-config",
Expand Down
Loading