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
This commit is contained in:
Sam Keen 2022-08-11 11:33:45 +01:00 committed by GitHub
parent 1c4231f6fc
commit 1be1a78a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 349 additions and 981 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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],

View File

@ -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) => {
</Callout>
</div>
)}
<WithdrawManager
assets={data.assets || []}
accounts={accounts}
isNewContract={Flags.USE_NEW_BRIDGE_CONTRACT}
/>
<WithdrawManager assets={data.assets || []} accounts={accounts} />
</>
);
};

View File

@ -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) {

View File

@ -87,7 +87,6 @@ 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(true);
const bridgeContract = useBridgeContract();
const getAllowance = useGetAllowance(tokenContract, asset);
const getBalance = useGetBalanceOfERC20Token(tokenContract, asset);
const getDepositMaximum = useGetDepositMaximum(bridgeContract, asset);

View File

@ -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 () => {

View File

@ -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<CollateralBridge, 'deposit_asset'>(
bridgeContract,
'deposit_asset',
config?.confirmations,
true
);
useSubscription<DepositEvent, DepositEventVariables>(DEPOSIT_EVENT_SUB, {
variables: { partyId: partyId ? remove0x(partyId) : '' },

View File

@ -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",

View File

@ -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"
}
]

View File

@ -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<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,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<BigNumber> {
return this.contract.get_deposit_maximum(assetSource);
}
get_deposit_minimum(assetSource: string): Promise<BigNumber> {
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
);

View File

@ -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';

View File

@ -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;
};

View File

@ -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 {

View File

@ -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;
}

View File

@ -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

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_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 }) => (
<MockedProvider mocks={mocks}>{children}</MockedProvider>
);
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<Erc20Approval> = {
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<Erc20Approval> = {
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<Erc20Approval> = {
request: {
query: ERC20_APPROVAL_QUERY_NEW,
query: ERC20_APPROVAL_QUERY,
variables: { withdrawalId },
},
error: new Error('query failed'),

View File

@ -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<Erc20Approval, Erc20ApprovalVariables>({
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(() => {

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(true);
const contract = useBridgeContract();
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_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 }) => (
<MockedProvider mocks={mocks}>{children}</MockedProvider>
);
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<Erc20ApprovalNew>;
let mockERC20Approval: MockedResponse<Erc20Approval>;
beforeEach(() => {
pubkey = 'pubkey';
@ -85,7 +85,7 @@ beforeEach(() => {
};
mockERC20Approval = {
request: {
query: ERC20_APPROVAL_QUERY_NEW,
query: ERC20_APPROVAL_QUERY,
variables: { withdrawalId: derivedWithdrawalId },
},
result: {

View File

@ -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<string | null>(null);
const [approval, setApproval] = useState<
| Erc20Approval_erc20WithdrawalApproval
| Erc20ApprovalNew_erc20WithdrawalApproval
| null
>(null);
const [approval, setApproval] =
useState<Erc20Approval_erc20WithdrawalApproval | null>(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<CollateralBridge, 'withdraw_asset'>(
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<Erc20Approval, Erc20ApprovalVariables>(
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]);

View File

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

View File

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

View File

@ -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<string | undefined>(initialAssetId);
const { ethTx, vegaTx, approval, submit, reset } = useWithdraw(
dialogDismissed.current,
isNewContract
dialogDismissed.current
);
// 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(true);
const { submit, Dialog } = useCompleteWithdraw();
return (
<>