Revert "Feat/537: remove old contract for collateral bridge (#998)"

This reverts commit 1be1a78a69.
This commit is contained in:
Edd 2022-08-15 15:52:53 +00:00 committed by GitHub
parent 900205ed12
commit 94373c1886
29 changed files with 981 additions and 349 deletions

View File

@ -3,6 +3,7 @@ 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

View File

@ -5,6 +5,7 @@ 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

View File

@ -3,6 +3,7 @@ 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

View File

@ -6,3 +6,4 @@ 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

View File

@ -66,6 +66,9 @@ 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],

View File

@ -15,6 +15,7 @@ import type {
WithdrawPageVariables,
} from './__generated__/WithdrawPage';
import { WithdrawManager } from '@vegaprotocol/withdraws';
import { Flags } from '../../config';
const Withdraw = () => {
const { t } = useTranslation();
@ -149,7 +150,11 @@ export const WithdrawContainer = ({ currVegaKey }: WithdrawContainerProps) => {
</Callout>
</div>
)}
<WithdrawManager assets={data.assets || []} accounts={accounts} />
<WithdrawManager
assets={data.assets || []}
accounts={accounts}
isNewContract={Flags.USE_NEW_BRIDGE_CONTRACT}
/>
</>
);
};

View File

@ -17,6 +17,7 @@ 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();
@ -33,7 +34,7 @@ const Withdrawals = () => {
const WithdrawPendingContainer = () => {
const { t } = useTranslation();
const { submit, Dialog } = useCompleteWithdraw();
const { submit, Dialog } = useCompleteWithdraw(Flags.USE_NEW_BRIDGE_CONTRACT);
const { data, loading, error } = useWithdrawals();
const withdrawals = React.useMemo(() => {
@ -92,7 +93,7 @@ interface WithdrawalProps {
export const Withdrawal = ({ withdrawal, complete }: WithdrawalProps) => {
const { ETHERSCAN_URL } = useEnvironment();
const { t } = useTranslation();
let status;
let status = null;
let footer = null;
if (withdrawal.pendingOnForeignChain) {

View File

@ -87,6 +87,7 @@ export const WithdrawPageContainer = ({
assets={data.assets}
accounts={data.party?.accounts || []}
initialAssetId={assetId}
isNewContract={true}
/>
</>
);

View File

@ -18,7 +18,7 @@ export const useDepositBalances = (isFaucetable: boolean) => {
isAssetTypeERC20(asset) ? asset : undefined,
isFaucetable
);
const bridgeContract = useBridgeContract();
const bridgeContract = useBridgeContract(true);
const getAllowance = useGetAllowance(tokenContract, asset);
const getBalance = useGetBalanceOfERC20Token(tokenContract, asset);
const getDepositMaximum = useGetDepositMaximum(bridgeContract, asset);

View File

@ -3,10 +3,13 @@ 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 } from '@vegaprotocol/smart-contracts';
import type {
CollateralBridge,
CollateralBridgeNew,
} from '@vegaprotocol/smart-contracts';
export const useGetDepositMaximum = (
contract: CollateralBridge | null,
contract: CollateralBridge | CollateralBridgeNew | null,
asset: Asset | undefined
) => {
const getDepositMaximum = useCallback(async () => {

View File

@ -17,7 +17,10 @@ import {
useEthereumTransaction,
useTokenContract,
} from '@vegaprotocol/web3';
import type { CollateralBridge } from '@vegaprotocol/smart-contracts';
import type {
CollateralBridge,
CollateralBridgeNew,
} from '@vegaprotocol/smart-contracts';
import { prepend0x } from '@vegaprotocol/smart-contracts';
import { useDepositStore } from './deposit-store';
import { useGetBalanceOfERC20Token } from './use-get-balance-of-erc20-token';
@ -39,7 +42,7 @@ const DEPOSIT_EVENT_SUB = gql`
export const useSubmitDeposit = () => {
const { asset, update } = useDepositStore();
const { config } = useEthereumConfig();
const bridgeContract = useBridgeContract();
const bridgeContract = useBridgeContract(true);
const tokenContract = useTokenContract(
isAssetTypeERC20(asset) ? asset : undefined,
true
@ -51,12 +54,10 @@ export const useSubmitDeposit = () => {
const getBalance = useGetBalanceOfERC20Token(tokenContract, asset);
const transaction = useEthereumTransaction<CollateralBridge, 'deposit_asset'>(
bridgeContract,
'deposit_asset',
config?.confirmations,
true
);
const transaction = useEthereumTransaction<
CollateralBridgeNew | CollateralBridge,
'deposit_asset'
>(bridgeContract, 'deposit_asset', config?.confirmations, true);
useSubscription<DepositEvent, DepositEventVariables>(DEPOSIT_EVENT_SUB, {
variables: { partyId: partyId ? remove0x(partyId) : '' },

View File

@ -5,11 +5,66 @@
"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": [
@ -41,31 +96,6 @@
"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": [
@ -141,70 +171,6 @@
"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": [
{
@ -228,45 +194,6 @@
"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": [
{
@ -286,6 +213,44 @@
"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",
@ -318,61 +283,6 @@
"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": [
{
@ -392,38 +302,6 @@
"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": [
{
@ -436,16 +314,6 @@
"name": "vega_asset_id",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "lifetime_limit",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "withdraw_threshold",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "nonce",
@ -486,8 +354,29 @@
"type": "function"
},
{
"inputs": [],
"name": "revoke_exempt_depositor",
"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",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
@ -501,12 +390,7 @@
},
{
"internalType": "uint256",
"name": "lifetime_limit",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "threshold",
"name": "minimum_amount",
"type": "uint256"
},
{
@ -520,30 +404,7 @@
"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",
"name": "set_deposit_minimum",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
@ -565,11 +426,6 @@
"name": "target",
"type": "address"
},
{
"internalType": "uint256",
"name": "creation",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "nonce",

View File

@ -0,0 +1,589 @@
[
{
"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"
}
]

View File

@ -0,0 +1,54 @@
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<BigNumber> {
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
);
}
}

View File

@ -4,13 +4,15 @@ import abi from '../abis/erc20_bridge_abi.json';
export class CollateralBridge {
public contract: ethers.Contract;
public isNewContract = true;
public isNewContract = false;
public address: string;
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) {
@ -20,7 +22,10 @@ export class CollateralBridge {
return this.contract.get_asset_source(vegaAssetId);
}
get_deposit_maximum(assetSource: string): Promise<BigNumber> {
return this.contract.get_asset_deposit_lifetime_limit(assetSource);
return this.contract.get_deposit_maximum(assetSource);
}
get_deposit_minimum(assetSource: string): Promise<BigNumber> {
return this.contract.get_deposit_minimum(assetSource);
}
get_multisig_control_address() {
return this.contract.get_multisig_control_address();
@ -38,7 +43,6 @@ export class CollateralBridge {
assetSource: string,
amount: string,
target: string,
creation: string,
nonce: string,
signatures: string
) {
@ -46,7 +50,6 @@ export class CollateralBridge {
assetSource,
amount,
target,
creation,
nonce,
signatures
);

View File

@ -2,6 +2,7 @@ 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';

View File

@ -1,9 +1,12 @@
import { CollateralBridge } from '@vegaprotocol/smart-contracts';
import {
CollateralBridge,
CollateralBridgeNew,
} from '@vegaprotocol/smart-contracts';
import { useWeb3React } from '@web3-react/core';
import { useMemo } from 'react';
import { useEthereumConfig } from './use-ethereum-config';
export const useBridgeContract = () => {
export const useBridgeContract = (isNewContract: boolean) => {
const { provider } = useWeb3React();
const { config } = useEthereumConfig();
@ -14,11 +17,16 @@ export const useBridgeContract = () => {
const signer = provider.getSigner();
return new CollateralBridge(
config.collateral_bridge_contract.address,
signer || provider
);
}, [provider, config]);
return isNewContract
? new CollateralBridgeNew(
config.collateral_bridge_contract.address,
signer || provider
)
: new CollateralBridge(
config.collateral_bridge_contract.address,
signer || provider
);
}, [provider, config, isNewContract]);
return contract;
};

View File

@ -34,10 +34,6 @@ 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 {

View File

@ -0,0 +1,52 @@
/* 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;
}

View File

@ -2,6 +2,19 @@ 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

View File

@ -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 } from './queries';
import { ERC20_APPROVAL_QUERY_NEW } from './queries';
import * as web3 from '@vegaprotocol/web3';
import * as sentry from '@sentry/react';
import type { Erc20Approval_erc20WithdrawalApproval } from './__generated__/Erc20Approval';
import type { Erc20ApprovalNew_erc20WithdrawalApproval } from './__generated__/Erc20ApprovalNew';
jest.mock('@vegaprotocol/web3', () => ({
useBridgeContract: jest.fn().mockReturnValue({
@ -22,12 +22,12 @@ function setup(mocks?: MockedResponse[]) {
const wrapper = ({ children }: { children: ReactNode }) => (
<MockedProvider mocks={mocks}>{children}</MockedProvider>
);
return renderHook(() => useCompleteWithdraw(), { wrapper });
return renderHook(() => useCompleteWithdraw(true), { wrapper });
}
it('Should perform the Ethereum transaction with the fetched approval', async () => {
const withdrawalId = 'withdrawal-id';
const erc20WithdrawalApproval: Erc20Approval_erc20WithdrawalApproval = {
const erc20WithdrawalApproval: Erc20ApprovalNew_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<Erc20Approval> = {
request: {
query: ERC20_APPROVAL_QUERY,
query: ERC20_APPROVAL_QUERY_NEW,
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<Erc20Approval> = {
request: {
query: ERC20_APPROVAL_QUERY,
query: ERC20_APPROVAL_QUERY_NEW,
variables: { withdrawalId },
},
result: {
@ -106,7 +106,7 @@ it('Captures an error if erc20 approval query fails', async () => {
const withdrawalId = 'withdrawal-id';
const mockERC20Approval: MockedResponse<Erc20Approval> = {
request: {
query: ERC20_APPROVAL_QUERY,
query: ERC20_APPROVAL_QUERY_NEW,
variables: { withdrawalId },
},
error: new Error('query failed'),

View File

@ -1,13 +1,17 @@
import { gql, useApolloClient } from '@apollo/client';
import { captureException } from '@sentry/react';
import type { CollateralBridge } from '@vegaprotocol/smart-contracts';
import type {
CollateralBridge,
CollateralBridgeNew,
} from '@vegaprotocol/smart-contracts';
import { useBridgeContract, useEthereumTransaction } from '@vegaprotocol/web3';
import { useCallback, useEffect, useState } from 'react';
import { ERC20_APPROVAL_QUERY } from './queries';
import { ERC20_APPROVAL_QUERY, ERC20_APPROVAL_QUERY_NEW } 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`
@ -17,12 +21,12 @@ export const PENDING_WITHDRAWAL_FRAGMMENT = gql`
}
`;
export const useCompleteWithdraw = () => {
export const useCompleteWithdraw = (isNewContract: boolean) => {
const { query, cache } = useApolloClient();
const contract = useBridgeContract();
const contract = useBridgeContract(isNewContract);
const [id, setId] = useState('');
const { transaction, perform, Dialog } = useEthereumTransaction<
CollateralBridge,
CollateralBridgeNew | CollateralBridge,
'withdraw_asset'
>(contract, 'withdraw_asset');
@ -33,8 +37,13 @@ export const useCompleteWithdraw = () => {
if (!contract) {
return;
}
const res = await query<Erc20Approval, Erc20ApprovalVariables>({
query: ERC20_APPROVAL_QUERY,
const res = await query<
Erc20Approval | Erc20ApprovalNew,
Erc20ApprovalVariables
>({
query: isNewContract
? ERC20_APPROVAL_QUERY_NEW
: ERC20_APPROVAL_QUERY,
variables: { withdrawalId },
});
@ -43,19 +52,29 @@ export const useCompleteWithdraw = () => {
throw new Error('Could not retrieve withdrawal approval');
}
perform(
approval.assetSource,
approval.amount,
approval.targetAddress,
approval.creation,
approval.nonce,
approval.signatures
);
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
);
}
} catch (err) {
captureException(err);
}
},
[contract, query, perform]
[contract, query, isNewContract, perform]
);
useEffect(() => {

View File

@ -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();
const contract = useBridgeContract(true);
const getLimits = useCallback(async () => {
if (!contract || !asset || asset.source.__typename !== 'ERC20') {
return;

View File

@ -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 } from './queries';
import { ERC20_APPROVAL_QUERY_NEW } 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 { Erc20Approval } from './__generated__/Erc20Approval';
import type { Erc20ApprovalNew } from './__generated__/Erc20ApprovalNew';
jest.mock('@vegaprotocol/web3', () => ({
useBridgeContract: jest.fn().mockReturnValue({
@ -30,7 +30,7 @@ function setup(mocks?: MockedResponse[], cancelled = false) {
const wrapper = ({ children }: { children: ReactNode }) => (
<MockedProvider mocks={mocks}>{children}</MockedProvider>
);
return renderHook(() => useWithdraw(cancelled), { wrapper });
return renderHook(() => useWithdraw(cancelled, true), { 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<Erc20Approval>;
let mockERC20Approval: MockedResponse<Erc20ApprovalNew>;
beforeEach(() => {
pubkey = 'pubkey';
@ -85,7 +85,7 @@ beforeEach(() => {
};
mockERC20Approval = {
request: {
query: ERC20_APPROVAL_QUERY,
query: ERC20_APPROVAL_QUERY_NEW,
variables: { withdrawalId: derivedWithdrawalId },
},
result: {

View File

@ -3,13 +3,20 @@ 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 } from './queries';
import { ERC20_APPROVAL_QUERY, ERC20_APPROVAL_QUERY_NEW } from './queries';
import type {
Erc20Approval,
Erc20Approval_erc20WithdrawalApproval,
Erc20ApprovalVariables,
Erc20Approval_erc20WithdrawalApproval,
} from './__generated__/Erc20Approval';
import type { CollateralBridge } from '@vegaprotocol/smart-contracts';
import type {
Erc20ApprovalNew,
Erc20ApprovalNew_erc20WithdrawalApproval,
} from './__generated__/Erc20ApprovalNew';
import type {
CollateralBridge,
CollateralBridgeNew,
} from '@vegaprotocol/smart-contracts';
export interface WithdrawalFields {
amount: string;
@ -17,12 +24,15 @@ export interface WithdrawalFields {
receiverAddress: string;
}
export const useWithdraw = (cancelled: boolean) => {
export const useWithdraw = (cancelled: boolean, isNewContract: boolean) => {
const [withdrawalId, setWithdrawalId] = useState<string | null>(null);
const [approval, setApproval] =
useState<Erc20Approval_erc20WithdrawalApproval | null>(null);
const [approval, setApproval] = useState<
| Erc20Approval_erc20WithdrawalApproval
| Erc20ApprovalNew_erc20WithdrawalApproval
| null
>(null);
const contract = useBridgeContract();
const contract = useBridgeContract(isNewContract);
const { keypair } = useVegaWallet();
const {
transaction: vegaTx,
@ -34,19 +44,19 @@ export const useWithdraw = (cancelled: boolean) => {
transaction: ethTx,
perform,
reset: resetEthTx,
} = useEthereumTransaction<CollateralBridge, 'withdraw_asset'>(
contract,
} = useEthereumTransaction<
CollateralBridgeNew | CollateralBridge,
'withdraw_asset'
);
>(contract, 'withdraw_asset');
const { data, stopPolling } = useQuery<Erc20Approval, Erc20ApprovalVariables>(
ERC20_APPROVAL_QUERY,
{
variables: { withdrawalId: withdrawalId || '' },
skip: !withdrawalId,
pollInterval: 1000,
}
);
const { data, stopPolling } = useQuery<
Erc20Approval | Erc20ApprovalNew,
Erc20ApprovalVariables
>(isNewContract ? ERC20_APPROVAL_QUERY_NEW : ERC20_APPROVAL_QUERY, {
variables: { withdrawalId: withdrawalId || '' },
skip: !withdrawalId,
pollInterval: 1000,
});
const submit = useCallback(
async (withdrawal: WithdrawalFields) => {
@ -87,14 +97,24 @@ export const useWithdraw = (cancelled: boolean) => {
useEffect(() => {
if (approval && contract && !cancelled) {
perform(
approval.assetSource,
approval.amount,
approval.targetAddress,
approval.creation,
approval.nonce,
approval.signatures
);
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
);
}
}
// eslint-disable-next-line
}, [approval, contract]);

View File

@ -21,7 +21,6 @@ const approval: Erc20Approval_erc20WithdrawalApproval = {
signatures: 'signatures',
targetAddress: 'target-address',
expiry: 'expiry',
creation: '1660158537747',
};
const generateJsx = (override?: PartialDeep<WithdrawDialogProps>) => {

View File

@ -34,6 +34,7 @@ beforeEach(() => {
assets: [generateAsset()],
accounts: [generateAccount()],
initialAssetId: undefined,
isNewContract: true,
};
mockSubmit = jest.fn();
mockReset = jest.fn();

View File

@ -16,19 +16,22 @@ 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<string | undefined>(initialAssetId);
const { ethTx, vegaTx, approval, submit, reset } = useWithdraw(
dialogDismissed.current
dialogDismissed.current,
isNewContract
);
// Find the asset object from the select box

View File

@ -21,7 +21,7 @@ export interface WithdrawalsTableProps {
export const WithdrawalsTable = ({ withdrawals }: WithdrawalsTableProps) => {
const { ETHERSCAN_URL } = useEnvironment();
const { submit, Dialog } = useCompleteWithdraw();
const { submit, Dialog } = useCompleteWithdraw(true);
return (
<>