From 1be1a78a6994256045d4f3c10c1e2667e87d42cf Mon Sep 17 00:00:00 2001 From: Sam Keen Date: Thu, 11 Aug 2022 11:33:45 +0100 Subject: [PATCH] Feat/537: remove old contract for collateral bridge (#998) * Feat/537: Removed old contract and branching logic for collateral bridge * Feat/537: Renamed all 'new' name instances in functions, files and types. Regenerated types. * Feat/537: Added 'creation' field to withdraw-dialog.spec.tsx test --- apps/token-e2e/.env | 1 - apps/token/.env | 1 - apps/token/.env.capsule | 1 - apps/token/.env.stagnet1 | 1 - apps/token/src/config/env.ts | 3 - apps/token/src/routes/withdraw/index.tsx | 7 +- apps/token/src/routes/withdrawals/index.tsx | 5 +- .../withdraw/withdraw-page-container.tsx | 1 - libs/deposits/src/lib/use-deposit-balances.ts | 2 +- .../src/lib/use-get-deposit-maximum.ts | 7 +- libs/deposits/src/lib/use-submit-deposit.tsx | 17 +- .../src/abis/erc20_bridge_abi.json | 380 +++++++---- .../src/abis/erc20_bridge_new_abi.json | 589 ------------------ .../src/contracts/collateral-bridge-new.ts | 54 -- .../src/contracts/collateral-bridge.ts | 11 +- libs/smart-contracts/src/contracts/index.ts | 1 - libs/web3/src/lib/use-bridge-contract.ts | 22 +- .../src/lib/__generated__/Erc20Approval.ts | 4 + .../src/lib/__generated__/Erc20ApprovalNew.ts | 52 -- libs/withdraws/src/lib/queries.ts | 13 - .../src/lib/use-complete-withdraw.spec.tsx | 14 +- .../src/lib/use-complete-withdraw.ts | 51 +- .../src/lib/use-get-withdraw-limits.tsx | 2 +- libs/withdraws/src/lib/use-withdraw.spec.tsx | 10 +- libs/withdraws/src/lib/use-withdraw.ts | 72 +-- .../src/lib/withdraw-dialog.spec.tsx | 1 + .../src/lib/withdraw-manager.spec.tsx | 1 - libs/withdraws/src/lib/withdraw-manager.tsx | 5 +- libs/withdraws/src/lib/withdrawals-table.tsx | 2 +- 29 files changed, 349 insertions(+), 981 deletions(-) delete mode 100644 libs/smart-contracts/src/abis/erc20_bridge_new_abi.json delete mode 100644 libs/smart-contracts/src/contracts/collateral-bridge-new.ts delete mode 100644 libs/withdraws/src/lib/__generated__/Erc20ApprovalNew.ts diff --git a/apps/token-e2e/.env b/apps/token-e2e/.env index 253cd8dda..56481a4fb 100644 --- a/apps/token-e2e/.env +++ b/apps/token-e2e/.env @@ -3,7 +3,6 @@ NX_VEGA_ENV=TESTNET NX_ETHEREUM_PROVIDER_URL=http://localhost:8545 NX_ETHERSCAN_URL=https://ropsten.etherscan.io NX_FAIRGROUND=false -NX_IS_NEW_BRIDGE_CONTRACT=true NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_VEGA_URL=http://localhost:3028/query diff --git a/apps/token/.env b/apps/token/.env index b254c7be6..127c44b63 100644 --- a/apps/token/.env +++ b/apps/token/.env @@ -5,7 +5,6 @@ NX_VEGA_URL=https://lb.testnet.vega.xyz/query NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8 NX_ETHERSCAN_URL=https://ropsten.etherscan.io NX_FAIRGROUND=false -NX_IS_NEW_BRIDGE_CONTRACT=true NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions NX_VEGA_WALLET_URL=http://localhost:1789/api/v1 diff --git a/apps/token/.env.capsule b/apps/token/.env.capsule index 0dc6175ed..ee8a0feae 100644 --- a/apps/token/.env.capsule +++ b/apps/token/.env.capsule @@ -3,7 +3,6 @@ NX_VEGA_ENV=TESTNET NX_ETHEREUM_PROVIDER_URL=http://localhost:8545 NX_ETHERSCAN_URL=https://ropsten.etherscan.io NX_FAIRGROUND=false -NX_IS_NEW_BRIDGE_CONTRACT=true NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}' NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions diff --git a/apps/token/.env.stagnet1 b/apps/token/.env.stagnet1 index 828bfb30e..b2a941f51 100644 --- a/apps/token/.env.stagnet1 +++ b/apps/token/.env.stagnet1 @@ -6,4 +6,3 @@ NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev. NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8 NX_ETHERSCAN_URL=https://ropsten.etherscan.io NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions -NX_IS_NEW_BRIDGE_CONTRACT=false diff --git a/apps/token/src/config/env.ts b/apps/token/src/config/env.ts index 1e5d972c8..972b34557 100644 --- a/apps/token/src/config/env.ts +++ b/apps/token/src/config/env.ts @@ -66,9 +66,6 @@ export const ENV = { MOCK: TRUTHY.includes(windowOrDefault('NX_MOCKED')), FAIRGROUND: TRUTHY.includes(windowOrDefault('NX_FAIRGROUND')), NETWORK_LIMITS: TRUTHY.includes(windowOrDefault('NX_NETWORK_LIMITS')), - USE_NEW_BRIDGE_CONTRACT: TRUTHY.includes( - process.env['NX_IS_NEW_BRIDGE_CONTRACT'] as string - ), }, addresses: ContractAddresses[(envName === 'local' ? 'CUSTOM' : envName) as Networks], diff --git a/apps/token/src/routes/withdraw/index.tsx b/apps/token/src/routes/withdraw/index.tsx index ec76da827..f6737e3b8 100644 --- a/apps/token/src/routes/withdraw/index.tsx +++ b/apps/token/src/routes/withdraw/index.tsx @@ -15,7 +15,6 @@ import type { WithdrawPageVariables, } from './__generated__/WithdrawPage'; import { WithdrawManager } from '@vegaprotocol/withdraws'; -import { Flags } from '../../config'; const Withdraw = () => { const { t } = useTranslation(); @@ -150,11 +149,7 @@ export const WithdrawContainer = ({ currVegaKey }: WithdrawContainerProps) => { )} - + ); }; diff --git a/apps/token/src/routes/withdrawals/index.tsx b/apps/token/src/routes/withdrawals/index.tsx index add2c6e83..750665742 100644 --- a/apps/token/src/routes/withdrawals/index.tsx +++ b/apps/token/src/routes/withdrawals/index.tsx @@ -17,7 +17,6 @@ import { truncateMiddle } from '../../lib/truncate-middle'; import type { Withdrawals_party_withdrawals } from '@vegaprotocol/withdraws'; import { useCompleteWithdraw, useWithdrawals } from '@vegaprotocol/withdraws'; import { WithdrawalStatus } from '../../__generated__/globalTypes'; -import { Flags } from '../../config'; const Withdrawals = () => { const { t } = useTranslation(); @@ -34,7 +33,7 @@ const Withdrawals = () => { const WithdrawPendingContainer = () => { const { t } = useTranslation(); - const { submit, Dialog } = useCompleteWithdraw(Flags.USE_NEW_BRIDGE_CONTRACT); + const { submit, Dialog } = useCompleteWithdraw(); const { data, loading, error } = useWithdrawals(); const withdrawals = React.useMemo(() => { @@ -93,7 +92,7 @@ interface WithdrawalProps { export const Withdrawal = ({ withdrawal, complete }: WithdrawalProps) => { const { ETHERSCAN_URL } = useEnvironment(); const { t } = useTranslation(); - let status = null; + let status; let footer = null; if (withdrawal.pendingOnForeignChain) { diff --git a/apps/trading/pages/portfolio/withdraw/withdraw-page-container.tsx b/apps/trading/pages/portfolio/withdraw/withdraw-page-container.tsx index 2002ff27e..c1a64eefb 100644 --- a/apps/trading/pages/portfolio/withdraw/withdraw-page-container.tsx +++ b/apps/trading/pages/portfolio/withdraw/withdraw-page-container.tsx @@ -87,7 +87,6 @@ export const WithdrawPageContainer = ({ assets={data.assets} accounts={data.party?.accounts || []} initialAssetId={assetId} - isNewContract={true} /> ); diff --git a/libs/deposits/src/lib/use-deposit-balances.ts b/libs/deposits/src/lib/use-deposit-balances.ts index 67b2c20df..d50defcc8 100644 --- a/libs/deposits/src/lib/use-deposit-balances.ts +++ b/libs/deposits/src/lib/use-deposit-balances.ts @@ -18,7 +18,7 @@ export const useDepositBalances = (isFaucetable: boolean) => { isAssetTypeERC20(asset) ? asset : undefined, isFaucetable ); - const bridgeContract = useBridgeContract(true); + const bridgeContract = useBridgeContract(); const getAllowance = useGetAllowance(tokenContract, asset); const getBalance = useGetBalanceOfERC20Token(tokenContract, asset); const getDepositMaximum = useGetDepositMaximum(bridgeContract, asset); diff --git a/libs/deposits/src/lib/use-get-deposit-maximum.ts b/libs/deposits/src/lib/use-get-deposit-maximum.ts index beec6d081..267588d77 100644 --- a/libs/deposits/src/lib/use-get-deposit-maximum.ts +++ b/libs/deposits/src/lib/use-get-deposit-maximum.ts @@ -3,13 +3,10 @@ import * as Sentry from '@sentry/react'; import BigNumber from 'bignumber.js'; import type { Asset } from '@vegaprotocol/react-helpers'; import { addDecimal } from '@vegaprotocol/react-helpers'; -import type { - CollateralBridge, - CollateralBridgeNew, -} from '@vegaprotocol/smart-contracts'; +import type { CollateralBridge } from '@vegaprotocol/smart-contracts'; export const useGetDepositMaximum = ( - contract: CollateralBridge | CollateralBridgeNew | null, + contract: CollateralBridge | null, asset: Asset | undefined ) => { const getDepositMaximum = useCallback(async () => { diff --git a/libs/deposits/src/lib/use-submit-deposit.tsx b/libs/deposits/src/lib/use-submit-deposit.tsx index ca9630913..cae10003d 100644 --- a/libs/deposits/src/lib/use-submit-deposit.tsx +++ b/libs/deposits/src/lib/use-submit-deposit.tsx @@ -17,10 +17,7 @@ import { useEthereumTransaction, useTokenContract, } from '@vegaprotocol/web3'; -import type { - CollateralBridge, - CollateralBridgeNew, -} from '@vegaprotocol/smart-contracts'; +import type { CollateralBridge } from '@vegaprotocol/smart-contracts'; import { prepend0x } from '@vegaprotocol/smart-contracts'; import { useDepositStore } from './deposit-store'; import { useGetBalanceOfERC20Token } from './use-get-balance-of-erc20-token'; @@ -42,7 +39,7 @@ const DEPOSIT_EVENT_SUB = gql` export const useSubmitDeposit = () => { const { asset, update } = useDepositStore(); const { config } = useEthereumConfig(); - const bridgeContract = useBridgeContract(true); + const bridgeContract = useBridgeContract(); const tokenContract = useTokenContract( isAssetTypeERC20(asset) ? asset : undefined, true @@ -54,10 +51,12 @@ export const useSubmitDeposit = () => { const getBalance = useGetBalanceOfERC20Token(tokenContract, asset); - const transaction = useEthereumTransaction< - CollateralBridgeNew | CollateralBridge, - 'deposit_asset' - >(bridgeContract, 'deposit_asset', config?.confirmations, true); + const transaction = useEthereumTransaction( + bridgeContract, + 'deposit_asset', + config?.confirmations, + true + ); useSubscription(DEPOSIT_EVENT_SUB, { variables: { partyId: partyId ? remove0x(partyId) : '' }, diff --git a/libs/smart-contracts/src/abis/erc20_bridge_abi.json b/libs/smart-contracts/src/abis/erc20_bridge_abi.json index 0c3ea7b6d..e2a19660b 100644 --- a/libs/smart-contracts/src/abis/erc20_bridge_abi.json +++ b/libs/smart-contracts/src/abis/erc20_bridge_abi.json @@ -5,66 +5,11 @@ "internalType": "address payable", "name": "erc20_asset_pool", "type": "address" - }, - { - "internalType": "address", - "name": "multisig_control", - "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "new_maximum", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "Asset_Deposit_Maximum_Set", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "new_minimum", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "Asset_Deposit_Minimum_Set", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -96,6 +41,31 @@ "name": "Asset_Deposited", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "asset_source", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lifetime_limit", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "withdraw_threshold", + "type": "uint256" + } + ], + "name": "Asset_Limits_Updated", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -171,6 +141,70 @@ "name": "Asset_Withdrawn", "type": "event" }, + { + "anonymous": false, + "inputs": [], + "name": "Bridge_Resumed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "Bridge_Stopped", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "withdraw_delay", + "type": "uint256" + } + ], + "name": "Bridge_Withdraw_Delay_Set", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "depositor", + "type": "address" + } + ], + "name": "Depositor_Exempted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "depositor", + "type": "address" + } + ], + "name": "Depositor_Exemption_Revoked", + "type": "event" + }, + { + "inputs": [], + "name": "default_withdraw_delay", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -194,6 +228,45 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "erc20_asset_pool_address", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "exempt_depositor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset_source", + "type": "address" + } + ], + "name": "get_asset_deposit_lifetime_limit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -213,44 +286,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "get_deposit_maximum", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "get_deposit_minimum", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "get_multisig_control_address", @@ -283,6 +318,61 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset_source", + "type": "address" + } + ], + "name": "get_withdraw_threshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signatures", + "type": "bytes" + } + ], + "name": "global_resume", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signatures", + "type": "bytes" + } + ], + "name": "global_stop", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -302,6 +392,38 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "depositor", + "type": "address" + } + ], + "name": "is_exempt_depositor", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "is_stopped", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -314,6 +436,16 @@ "name": "vega_asset_id", "type": "bytes32" }, + { + "internalType": "uint256", + "name": "lifetime_limit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdraw_threshold", + "type": "uint256" + }, { "internalType": "uint256", "name": "nonce", @@ -354,29 +486,8 @@ "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "uint256", - "name": "maximum_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "set_deposit_maximum", + "inputs": [], + "name": "revoke_exempt_depositor", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -390,7 +501,12 @@ }, { "internalType": "uint256", - "name": "minimum_amount", + "name": "lifetime_limit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "threshold", "type": "uint256" }, { @@ -404,7 +520,30 @@ "type": "bytes" } ], - "name": "set_deposit_minimum", + "name": "set_asset_limits", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "delay", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signatures", + "type": "bytes" + } + ], + "name": "set_withdraw_delay", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -426,6 +565,11 @@ "name": "target", "type": "address" }, + { + "internalType": "uint256", + "name": "creation", + "type": "uint256" + }, { "internalType": "uint256", "name": "nonce", diff --git a/libs/smart-contracts/src/abis/erc20_bridge_new_abi.json b/libs/smart-contracts/src/abis/erc20_bridge_new_abi.json deleted file mode 100644 index e2a19660b..000000000 --- a/libs/smart-contracts/src/abis/erc20_bridge_new_abi.json +++ /dev/null @@ -1,589 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "address payable", - "name": "erc20_asset_pool", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "user_address", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "vega_public_key", - "type": "bytes32" - } - ], - "name": "Asset_Deposited", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "lifetime_limit", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "withdraw_threshold", - "type": "uint256" - } - ], - "name": "Asset_Limits_Updated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "vega_asset_id", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "Asset_Listed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "Asset_Removed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "user_address", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "Asset_Withdrawn", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "Bridge_Resumed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "Bridge_Stopped", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "withdraw_delay", - "type": "uint256" - } - ], - "name": "Bridge_Withdraw_Delay_Set", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "depositor", - "type": "address" - } - ], - "name": "Depositor_Exempted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "depositor", - "type": "address" - } - ], - "name": "Depositor_Exemption_Revoked", - "type": "event" - }, - { - "inputs": [], - "name": "default_withdraw_delay", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "vega_public_key", - "type": "bytes32" - } - ], - "name": "deposit_asset", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "erc20_asset_pool_address", - "outputs": [ - { - "internalType": "address payable", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "exempt_depositor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "get_asset_deposit_lifetime_limit", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "vega_asset_id", - "type": "bytes32" - } - ], - "name": "get_asset_source", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "get_multisig_control_address", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "get_vega_asset_id", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "get_withdraw_threshold", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "global_resume", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "global_stop", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - } - ], - "name": "is_asset_listed", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "depositor", - "type": "address" - } - ], - "name": "is_exempt_depositor", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "is_stopped", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "vega_asset_id", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "lifetime_limit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdraw_threshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "list_asset", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "remove_asset", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "revoke_exempt_depositor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "uint256", - "name": "lifetime_limit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "threshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "set_asset_limits", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "delay", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "set_withdraw_delay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset_source", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "target", - "type": "address" - }, - { - "internalType": "uint256", - "name": "creation", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signatures", - "type": "bytes" - } - ], - "name": "withdraw_asset", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/libs/smart-contracts/src/contracts/collateral-bridge-new.ts b/libs/smart-contracts/src/contracts/collateral-bridge-new.ts deleted file mode 100644 index 963eefb9c..000000000 --- a/libs/smart-contracts/src/contracts/collateral-bridge-new.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { BigNumber } from 'ethers'; -import { ethers } from 'ethers'; -import abi from '../abis/erc20_bridge_new_abi.json'; - -export class CollateralBridgeNew { - public contract: ethers.Contract; - public isNewContract = true; - - constructor( - address: string, - signerOrProvider: ethers.Signer | ethers.providers.Provider - ) { - this.contract = new ethers.Contract(address, abi, signerOrProvider); - } - - deposit_asset(assetSource: string, amount: string, vegaPublicKey: string) { - return this.contract.deposit_asset(assetSource, amount, vegaPublicKey); - } - get_asset_source(vegaAssetId: string) { - return this.contract.get_asset_source(vegaAssetId); - } - get_deposit_maximum(assetSource: string): Promise { - return this.contract.get_asset_deposit_lifetime_limit(assetSource); - } - get_multisig_control_address() { - return this.contract.get_multisig_control_address(); - } - get_vega_asset_id(address: string) { - return this.contract.get_vega_asset_id(address); - } - is_asset_listed(address: string) { - return this.contract.is_asset_listed(address); - } - get_withdraw_threshold(assetSource: string) { - return this.contract.get_withdraw_threshold(assetSource); - } - withdraw_asset( - assetSource: string, - amount: string, - target: string, - creation: string, - nonce: string, - signatures: string - ) { - return this.contract.withdraw_asset( - assetSource, - amount, - target, - creation, - nonce, - signatures - ); - } -} diff --git a/libs/smart-contracts/src/contracts/collateral-bridge.ts b/libs/smart-contracts/src/contracts/collateral-bridge.ts index 29d3705c4..c7124d855 100644 --- a/libs/smart-contracts/src/contracts/collateral-bridge.ts +++ b/libs/smart-contracts/src/contracts/collateral-bridge.ts @@ -4,15 +4,13 @@ import abi from '../abis/erc20_bridge_abi.json'; export class CollateralBridge { public contract: ethers.Contract; - public isNewContract = false; - public address: string; + public isNewContract = true; constructor( address: string, signerOrProvider: ethers.Signer | ethers.providers.Provider ) { this.contract = new ethers.Contract(address, abi, signerOrProvider); - this.address = address; } deposit_asset(assetSource: string, amount: string, vegaPublicKey: string) { @@ -22,10 +20,7 @@ export class CollateralBridge { return this.contract.get_asset_source(vegaAssetId); } get_deposit_maximum(assetSource: string): Promise { - return this.contract.get_deposit_maximum(assetSource); - } - get_deposit_minimum(assetSource: string): Promise { - return this.contract.get_deposit_minimum(assetSource); + return this.contract.get_asset_deposit_lifetime_limit(assetSource); } get_multisig_control_address() { return this.contract.get_multisig_control_address(); @@ -43,6 +38,7 @@ export class CollateralBridge { assetSource: string, amount: string, target: string, + creation: string, nonce: string, signatures: string ) { @@ -50,6 +46,7 @@ export class CollateralBridge { assetSource, amount, target, + creation, nonce, signatures ); diff --git a/libs/smart-contracts/src/contracts/index.ts b/libs/smart-contracts/src/contracts/index.ts index 1f5a6bd57..15ec967b1 100644 --- a/libs/smart-contracts/src/contracts/index.ts +++ b/libs/smart-contracts/src/contracts/index.ts @@ -2,7 +2,6 @@ export * from './vega-web3-types'; export * from './claim'; export * from './collateral-bridge'; -export * from './collateral-bridge-new'; export * from './staking-bridge'; export * from './token-vesting'; export * from './token'; diff --git a/libs/web3/src/lib/use-bridge-contract.ts b/libs/web3/src/lib/use-bridge-contract.ts index f3c15eadc..db7637bf2 100644 --- a/libs/web3/src/lib/use-bridge-contract.ts +++ b/libs/web3/src/lib/use-bridge-contract.ts @@ -1,12 +1,9 @@ -import { - CollateralBridge, - CollateralBridgeNew, -} from '@vegaprotocol/smart-contracts'; +import { CollateralBridge } from '@vegaprotocol/smart-contracts'; import { useWeb3React } from '@web3-react/core'; import { useMemo } from 'react'; import { useEthereumConfig } from './use-ethereum-config'; -export const useBridgeContract = (isNewContract: boolean) => { +export const useBridgeContract = () => { const { provider } = useWeb3React(); const { config } = useEthereumConfig(); @@ -17,16 +14,11 @@ export const useBridgeContract = (isNewContract: boolean) => { const signer = provider.getSigner(); - return isNewContract - ? new CollateralBridgeNew( - config.collateral_bridge_contract.address, - signer || provider - ) - : new CollateralBridge( - config.collateral_bridge_contract.address, - signer || provider - ); - }, [provider, config, isNewContract]); + return new CollateralBridge( + config.collateral_bridge_contract.address, + signer || provider + ); + }, [provider, config]); return contract; }; diff --git a/libs/withdraws/src/lib/__generated__/Erc20Approval.ts b/libs/withdraws/src/lib/__generated__/Erc20Approval.ts index bb0c69bfb..357cbaeb2 100644 --- a/libs/withdraws/src/lib/__generated__/Erc20Approval.ts +++ b/libs/withdraws/src/lib/__generated__/Erc20Approval.ts @@ -34,6 +34,10 @@ export interface Erc20Approval_erc20WithdrawalApproval { * Timestamp in seconds for expiry of the approval */ expiry: string; + /** + * Timestamp at which the withdrawal was created + */ + creation: string; } export interface Erc20Approval { diff --git a/libs/withdraws/src/lib/__generated__/Erc20ApprovalNew.ts b/libs/withdraws/src/lib/__generated__/Erc20ApprovalNew.ts deleted file mode 100644 index 9a48ec9b6..000000000 --- a/libs/withdraws/src/lib/__generated__/Erc20ApprovalNew.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: Erc20ApprovalNew -// ==================================================== - -export interface Erc20ApprovalNew_erc20WithdrawalApproval { - __typename: "Erc20WithdrawalApproval"; - /** - * The source asset in the ethereum network - */ - assetSource: string; - /** - * The amount to be withdrawn - */ - amount: string; - /** - * The nonce to be used in the request - */ - nonce: string; - /** - * Signature aggregate from the nodes, in the following format: - * 0x + sig1 + sig2 + ... + sigN - */ - signatures: string; - /** - * The target address which will receive the funds - */ - targetAddress: string; - /** - * Timestamp in seconds for expiry of the approval - */ - expiry: string; - /** - * Timestamp at which the withdrawal was created - */ - creation: string; -} - -export interface Erc20ApprovalNew { - /** - * find an erc20 withdrawal approval using its withdrawal id - */ - erc20WithdrawalApproval: Erc20ApprovalNew_erc20WithdrawalApproval | null; -} - -export interface Erc20ApprovalNewVariables { - withdrawalId: string; -} diff --git a/libs/withdraws/src/lib/queries.ts b/libs/withdraws/src/lib/queries.ts index 0347c90b1..096c14b82 100644 --- a/libs/withdraws/src/lib/queries.ts +++ b/libs/withdraws/src/lib/queries.ts @@ -2,19 +2,6 @@ import { gql } from '@apollo/client'; export const ERC20_APPROVAL_QUERY = gql` query Erc20Approval($withdrawalId: ID!) { - erc20WithdrawalApproval(withdrawalId: $withdrawalId) { - assetSource - amount - nonce - signatures - targetAddress - expiry - } - } -`; - -export const ERC20_APPROVAL_QUERY_NEW = gql` - query Erc20ApprovalNew($withdrawalId: ID!) { erc20WithdrawalApproval(withdrawalId: $withdrawalId) { assetSource amount diff --git a/libs/withdraws/src/lib/use-complete-withdraw.spec.tsx b/libs/withdraws/src/lib/use-complete-withdraw.spec.tsx index f3ddb33db..b125ff0fa 100644 --- a/libs/withdraws/src/lib/use-complete-withdraw.spec.tsx +++ b/libs/withdraws/src/lib/use-complete-withdraw.spec.tsx @@ -5,10 +5,10 @@ import { MockedProvider } from '@apollo/client/testing'; import type { ReactNode } from 'react'; import { useCompleteWithdraw } from './use-complete-withdraw'; import type { Erc20Approval } from './__generated__/Erc20Approval'; -import { ERC20_APPROVAL_QUERY_NEW } from './queries'; +import { ERC20_APPROVAL_QUERY } from './queries'; import * as web3 from '@vegaprotocol/web3'; import * as sentry from '@sentry/react'; -import type { Erc20ApprovalNew_erc20WithdrawalApproval } from './__generated__/Erc20ApprovalNew'; +import type { Erc20Approval_erc20WithdrawalApproval } from './__generated__/Erc20Approval'; jest.mock('@vegaprotocol/web3', () => ({ useBridgeContract: jest.fn().mockReturnValue({ @@ -22,12 +22,12 @@ function setup(mocks?: MockedResponse[]) { const wrapper = ({ children }: { children: ReactNode }) => ( {children} ); - return renderHook(() => useCompleteWithdraw(true), { wrapper }); + return renderHook(() => useCompleteWithdraw(), { wrapper }); } it('Should perform the Ethereum transaction with the fetched approval', async () => { const withdrawalId = 'withdrawal-id'; - const erc20WithdrawalApproval: Erc20ApprovalNew_erc20WithdrawalApproval = { + const erc20WithdrawalApproval: Erc20Approval_erc20WithdrawalApproval = { __typename: 'Erc20WithdrawalApproval', assetSource: 'asset-source', amount: '100', @@ -39,7 +39,7 @@ it('Should perform the Ethereum transaction with the fetched approval', async () }; const mockERC20Approval: MockedResponse = { request: { - query: ERC20_APPROVAL_QUERY_NEW, + query: ERC20_APPROVAL_QUERY, variables: { withdrawalId }, }, result: { @@ -75,7 +75,7 @@ it('Captures an error if the erc20Withdrawal is not found', async () => { const withdrawalId = 'withdrawal-id'; const mockERC20Approval: MockedResponse = { request: { - query: ERC20_APPROVAL_QUERY_NEW, + query: ERC20_APPROVAL_QUERY, variables: { withdrawalId }, }, result: { @@ -106,7 +106,7 @@ it('Captures an error if erc20 approval query fails', async () => { const withdrawalId = 'withdrawal-id'; const mockERC20Approval: MockedResponse = { request: { - query: ERC20_APPROVAL_QUERY_NEW, + query: ERC20_APPROVAL_QUERY, variables: { withdrawalId }, }, error: new Error('query failed'), diff --git a/libs/withdraws/src/lib/use-complete-withdraw.ts b/libs/withdraws/src/lib/use-complete-withdraw.ts index 7e1e414db..354ae2285 100644 --- a/libs/withdraws/src/lib/use-complete-withdraw.ts +++ b/libs/withdraws/src/lib/use-complete-withdraw.ts @@ -1,17 +1,13 @@ import { gql, useApolloClient } from '@apollo/client'; import { captureException } from '@sentry/react'; -import type { - CollateralBridge, - CollateralBridgeNew, -} from '@vegaprotocol/smart-contracts'; +import type { CollateralBridge } from '@vegaprotocol/smart-contracts'; import { useBridgeContract, useEthereumTransaction } from '@vegaprotocol/web3'; import { useCallback, useEffect, useState } from 'react'; -import { ERC20_APPROVAL_QUERY, ERC20_APPROVAL_QUERY_NEW } from './queries'; +import { ERC20_APPROVAL_QUERY } from './queries'; import type { Erc20Approval, Erc20ApprovalVariables, } from './__generated__/Erc20Approval'; -import type { Erc20ApprovalNew } from './__generated__/Erc20ApprovalNew'; import type { PendingWithdrawal } from './__generated__/PendingWithdrawal'; export const PENDING_WITHDRAWAL_FRAGMMENT = gql` @@ -21,12 +17,12 @@ export const PENDING_WITHDRAWAL_FRAGMMENT = gql` } `; -export const useCompleteWithdraw = (isNewContract: boolean) => { +export const useCompleteWithdraw = () => { const { query, cache } = useApolloClient(); - const contract = useBridgeContract(isNewContract); + const contract = useBridgeContract(); const [id, setId] = useState(''); const { transaction, perform, Dialog } = useEthereumTransaction< - CollateralBridgeNew | CollateralBridge, + CollateralBridge, 'withdraw_asset' >(contract, 'withdraw_asset'); @@ -37,13 +33,8 @@ export const useCompleteWithdraw = (isNewContract: boolean) => { if (!contract) { return; } - const res = await query< - Erc20Approval | Erc20ApprovalNew, - Erc20ApprovalVariables - >({ - query: isNewContract - ? ERC20_APPROVAL_QUERY_NEW - : ERC20_APPROVAL_QUERY, + const res = await query({ + query: ERC20_APPROVAL_QUERY, variables: { withdrawalId }, }); @@ -52,29 +43,19 @@ export const useCompleteWithdraw = (isNewContract: boolean) => { throw new Error('Could not retrieve withdrawal approval'); } - if (contract.isNewContract && 'creation' in approval) { - perform( - approval.assetSource, - approval.amount, - approval.targetAddress, - approval.creation, - approval.nonce, - approval.signatures - ); - } else { - perform( - approval.assetSource, - approval.amount, - approval.targetAddress, - approval.nonce, - approval.signatures - ); - } + perform( + approval.assetSource, + approval.amount, + approval.targetAddress, + approval.creation, + approval.nonce, + approval.signatures + ); } catch (err) { captureException(err); } }, - [contract, query, isNewContract, perform] + [contract, query, perform] ); useEffect(() => { diff --git a/libs/withdraws/src/lib/use-get-withdraw-limits.tsx b/libs/withdraws/src/lib/use-get-withdraw-limits.tsx index 44556b04a..a1cc7bcf1 100644 --- a/libs/withdraws/src/lib/use-get-withdraw-limits.tsx +++ b/libs/withdraws/src/lib/use-get-withdraw-limits.tsx @@ -5,7 +5,7 @@ import type { Asset } from '@vegaprotocol/react-helpers'; import { addDecimal } from '@vegaprotocol/react-helpers'; export const useGetWithdrawLimits = (asset?: Asset) => { - const contract = useBridgeContract(true); + const contract = useBridgeContract(); const getLimits = useCallback(async () => { if (!contract || !asset || asset.source.__typename !== 'ERC20') { return; diff --git a/libs/withdraws/src/lib/use-withdraw.spec.tsx b/libs/withdraws/src/lib/use-withdraw.spec.tsx index 47fddadcd..c94d91175 100644 --- a/libs/withdraws/src/lib/use-withdraw.spec.tsx +++ b/libs/withdraws/src/lib/use-withdraw.spec.tsx @@ -2,12 +2,12 @@ import { act, renderHook } from '@testing-library/react'; import type { MockedResponse } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing'; import type { ReactNode } from 'react'; -import { ERC20_APPROVAL_QUERY_NEW } from './queries'; +import { ERC20_APPROVAL_QUERY } from './queries'; import * as web3 from '@vegaprotocol/web3'; import * as wallet from '@vegaprotocol/wallet'; import type { WithdrawalFields } from './use-withdraw'; import { useWithdraw } from './use-withdraw'; -import type { Erc20ApprovalNew } from './__generated__/Erc20ApprovalNew'; +import type { Erc20Approval } from './__generated__/Erc20Approval'; jest.mock('@vegaprotocol/web3', () => ({ useBridgeContract: jest.fn().mockReturnValue({ @@ -30,7 +30,7 @@ function setup(mocks?: MockedResponse[], cancelled = false) { const wrapper = ({ children }: { children: ReactNode }) => ( {children} ); - return renderHook(() => useWithdraw(cancelled, true), { wrapper }); + return renderHook(() => useWithdraw(cancelled), { wrapper }); } const signature = @@ -52,7 +52,7 @@ let mockPerform: jest.Mock; let mockEthReset: jest.Mock; let mockVegaReset: jest.Mock; let withdrawalInput: WithdrawalFields; -let mockERC20Approval: MockedResponse; +let mockERC20Approval: MockedResponse; beforeEach(() => { pubkey = 'pubkey'; @@ -85,7 +85,7 @@ beforeEach(() => { }; mockERC20Approval = { request: { - query: ERC20_APPROVAL_QUERY_NEW, + query: ERC20_APPROVAL_QUERY, variables: { withdrawalId: derivedWithdrawalId }, }, result: { diff --git a/libs/withdraws/src/lib/use-withdraw.ts b/libs/withdraws/src/lib/use-withdraw.ts index 25a411a7d..6a670a0c7 100644 --- a/libs/withdraws/src/lib/use-withdraw.ts +++ b/libs/withdraws/src/lib/use-withdraw.ts @@ -3,20 +3,13 @@ import { determineId } from '@vegaprotocol/react-helpers'; import { useBridgeContract, useEthereumTransaction } from '@vegaprotocol/web3'; import { useVegaTransaction, useVegaWallet } from '@vegaprotocol/wallet'; import { useCallback, useEffect, useState } from 'react'; -import { ERC20_APPROVAL_QUERY, ERC20_APPROVAL_QUERY_NEW } from './queries'; +import { ERC20_APPROVAL_QUERY } from './queries'; import type { Erc20Approval, - Erc20ApprovalVariables, Erc20Approval_erc20WithdrawalApproval, + Erc20ApprovalVariables, } from './__generated__/Erc20Approval'; -import type { - Erc20ApprovalNew, - Erc20ApprovalNew_erc20WithdrawalApproval, -} from './__generated__/Erc20ApprovalNew'; -import type { - CollateralBridge, - CollateralBridgeNew, -} from '@vegaprotocol/smart-contracts'; +import type { CollateralBridge } from '@vegaprotocol/smart-contracts'; export interface WithdrawalFields { amount: string; @@ -24,15 +17,12 @@ export interface WithdrawalFields { receiverAddress: string; } -export const useWithdraw = (cancelled: boolean, isNewContract: boolean) => { +export const useWithdraw = (cancelled: boolean) => { const [withdrawalId, setWithdrawalId] = useState(null); - const [approval, setApproval] = useState< - | Erc20Approval_erc20WithdrawalApproval - | Erc20ApprovalNew_erc20WithdrawalApproval - | null - >(null); + const [approval, setApproval] = + useState(null); - const contract = useBridgeContract(isNewContract); + const contract = useBridgeContract(); const { keypair } = useVegaWallet(); const { transaction: vegaTx, @@ -44,19 +34,19 @@ export const useWithdraw = (cancelled: boolean, isNewContract: boolean) => { transaction: ethTx, perform, reset: resetEthTx, - } = useEthereumTransaction< - CollateralBridgeNew | CollateralBridge, + } = useEthereumTransaction( + contract, 'withdraw_asset' - >(contract, 'withdraw_asset'); + ); - const { data, stopPolling } = useQuery< - Erc20Approval | Erc20ApprovalNew, - Erc20ApprovalVariables - >(isNewContract ? ERC20_APPROVAL_QUERY_NEW : ERC20_APPROVAL_QUERY, { - variables: { withdrawalId: withdrawalId || '' }, - skip: !withdrawalId, - pollInterval: 1000, - }); + const { data, stopPolling } = useQuery( + ERC20_APPROVAL_QUERY, + { + variables: { withdrawalId: withdrawalId || '' }, + skip: !withdrawalId, + pollInterval: 1000, + } + ); const submit = useCallback( async (withdrawal: WithdrawalFields) => { @@ -97,24 +87,14 @@ export const useWithdraw = (cancelled: boolean, isNewContract: boolean) => { useEffect(() => { if (approval && contract && !cancelled) { - if (contract.isNewContract && 'creation' in approval) { - perform( - approval.assetSource, - approval.amount, - approval.targetAddress, - approval.creation, - approval.nonce, - approval.signatures - ); - } else { - perform( - approval.assetSource, - approval.amount, - approval.targetAddress, - approval.nonce, - approval.signatures - ); - } + perform( + approval.assetSource, + approval.amount, + approval.targetAddress, + approval.creation, + approval.nonce, + approval.signatures + ); } // eslint-disable-next-line }, [approval, contract]); diff --git a/libs/withdraws/src/lib/withdraw-dialog.spec.tsx b/libs/withdraws/src/lib/withdraw-dialog.spec.tsx index 6998a4576..0afb0a634 100644 --- a/libs/withdraws/src/lib/withdraw-dialog.spec.tsx +++ b/libs/withdraws/src/lib/withdraw-dialog.spec.tsx @@ -21,6 +21,7 @@ const approval: Erc20Approval_erc20WithdrawalApproval = { signatures: 'signatures', targetAddress: 'target-address', expiry: 'expiry', + creation: '1660158537747', }; const generateJsx = (override?: PartialDeep) => { diff --git a/libs/withdraws/src/lib/withdraw-manager.spec.tsx b/libs/withdraws/src/lib/withdraw-manager.spec.tsx index 3985b86c0..9c3a42d51 100644 --- a/libs/withdraws/src/lib/withdraw-manager.spec.tsx +++ b/libs/withdraws/src/lib/withdraw-manager.spec.tsx @@ -34,7 +34,6 @@ beforeEach(() => { assets: [generateAsset()], accounts: [generateAccount()], initialAssetId: undefined, - isNewContract: true, }; mockSubmit = jest.fn(); mockReset = jest.fn(); diff --git a/libs/withdraws/src/lib/withdraw-manager.tsx b/libs/withdraws/src/lib/withdraw-manager.tsx index 27fc4319d..7f13a7265 100644 --- a/libs/withdraws/src/lib/withdraw-manager.tsx +++ b/libs/withdraws/src/lib/withdraw-manager.tsx @@ -16,22 +16,19 @@ export interface WithdrawManagerProps { assets: Asset[]; accounts: Account[]; initialAssetId?: string; - isNewContract: boolean; } export const WithdrawManager = ({ assets, accounts, initialAssetId, - isNewContract, }: WithdrawManagerProps) => { const dialogDismissed = useRef(false); const [dialogOpen, setDialogOpen] = useState(false); const [assetId, setAssetId] = useState(initialAssetId); const { ethTx, vegaTx, approval, submit, reset } = useWithdraw( - dialogDismissed.current, - isNewContract + dialogDismissed.current ); // Find the asset object from the select box diff --git a/libs/withdraws/src/lib/withdrawals-table.tsx b/libs/withdraws/src/lib/withdrawals-table.tsx index 862cd5e24..8d34959b1 100644 --- a/libs/withdraws/src/lib/withdrawals-table.tsx +++ b/libs/withdraws/src/lib/withdrawals-table.tsx @@ -21,7 +21,7 @@ export interface WithdrawalsTableProps { export const WithdrawalsTable = ({ withdrawals }: WithdrawalsTableProps) => { const { ETHERSCAN_URL } = useEnvironment(); - const { submit, Dialog } = useCompleteWithdraw(true); + const { submit, Dialog } = useCompleteWithdraw(); return ( <>