Make registerAssetProxy append only
This commit is contained in:
@@ -32,43 +32,28 @@ contract MixinAssetProxyDispatcher is
|
||||
// Mapping from Asset Proxy Id's to their respective Asset Proxy
|
||||
mapping (bytes4 => IAssetProxy) public assetProxies;
|
||||
|
||||
/// @dev Registers an asset proxy to an asset proxy id.
|
||||
/// An id can only be assigned to a single proxy at a given time.
|
||||
/// @param assetProxyId Id to register`newAssetProxy` under.
|
||||
/// @param newAssetProxy Address of new asset proxy to register, or 0x0 to unset assetProxyId.
|
||||
/// @param oldAssetProxy Existing asset proxy to overwrite, or 0x0 if assetProxyId is currently unused.
|
||||
function registerAssetProxy(
|
||||
bytes4 assetProxyId,
|
||||
address newAssetProxy,
|
||||
address oldAssetProxy
|
||||
)
|
||||
/// @dev Registers an asset proxy to its asset proxy id.
|
||||
/// Once an asset proxy is registered, it cannot be unregistered.
|
||||
/// @param assetProxy Address of new asset proxy to register.
|
||||
function registerAssetProxy(address assetProxy)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
// Ensure the existing asset proxy is not unintentionally overwritten
|
||||
IAssetProxy assetProxyContract = IAssetProxy(assetProxy);
|
||||
|
||||
// Ensure that no asset proxy exists with current id.
|
||||
bytes4 assetProxyId = assetProxyContract.getProxyId();
|
||||
address currentAssetProxy = assetProxies[assetProxyId];
|
||||
require(
|
||||
oldAssetProxy == currentAssetProxy,
|
||||
"ASSET_PROXY_MISMATCH"
|
||||
currentAssetProxy == address(0),
|
||||
"ASSET_PROXY_ALREADY_EXISTS"
|
||||
);
|
||||
|
||||
IAssetProxy assetProxy = IAssetProxy(newAssetProxy);
|
||||
|
||||
// Ensure that the id of newAssetProxy matches the passed in assetProxyId, unless it is being reset to 0.
|
||||
if (newAssetProxy != address(0)) {
|
||||
bytes4 newAssetProxyId = assetProxy.getProxyId();
|
||||
require(
|
||||
newAssetProxyId == assetProxyId,
|
||||
"ASSET_PROXY_ID_MISMATCH"
|
||||
);
|
||||
}
|
||||
|
||||
// Add asset proxy and log registration.
|
||||
assetProxies[assetProxyId] = assetProxy;
|
||||
emit AssetProxySet(
|
||||
assetProxies[assetProxyId] = assetProxyContract;
|
||||
emit AssetProxyRegistered(
|
||||
assetProxyId,
|
||||
newAssetProxy,
|
||||
oldAssetProxy
|
||||
assetProxy
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,7 +97,7 @@ contract MixinAssetProxyDispatcher is
|
||||
0xFFFFFFFF00000000000000000000000000000000000000000000000000000000
|
||||
)
|
||||
}
|
||||
IAssetProxy assetProxy = assetProxies[assetProxyId];
|
||||
address assetProxy = assetProxies[assetProxyId];
|
||||
|
||||
// Ensure that assetProxy exists
|
||||
require(
|
||||
|
@@ -20,16 +20,10 @@ pragma solidity ^0.4.24;
|
||||
|
||||
contract IAssetProxyDispatcher {
|
||||
|
||||
/// @dev Registers an asset proxy to an asset proxy id.
|
||||
/// An id can only be assigned to a single proxy at a given time.
|
||||
/// @param assetProxyId Id to register`newAssetProxy` under.
|
||||
/// @param newAssetProxy Address of new asset proxy to register, or 0x0 to unset assetProxyId.
|
||||
/// @param oldAssetProxy Existing asset proxy to overwrite, or 0x0 if assetProxyId is currently unused.
|
||||
function registerAssetProxy(
|
||||
bytes4 assetProxyId,
|
||||
address newAssetProxy,
|
||||
address oldAssetProxy
|
||||
)
|
||||
/// @dev Registers an asset proxy to its asset proxy id.
|
||||
/// Once an asset proxy is registered, it cannot be unregistered.
|
||||
/// @param assetProxy Address of new asset proxy to register.
|
||||
function registerAssetProxy(address assetProxy)
|
||||
external;
|
||||
|
||||
/// @dev Gets an asset proxy.
|
||||
|
@@ -54,8 +54,7 @@ contract LibExchangeErrors {
|
||||
string constant FAILED_EXECUTION = "FAILED_EXECUTION"; // Transaction execution failed.
|
||||
|
||||
/// registerAssetProxy errors ///
|
||||
string constant ASSET_PROXY_MISMATCH = "ASSET_PROXY_MISMATCH"; // oldAssetProxy proxy does not match currentAssetProxy.
|
||||
string constant ASSET_PROXY_ID_MISMATCH = "ASSET_PROXY_ID_MISMATCH"; // newAssetProxyId does not match given assetProxyId.
|
||||
string constant ASSET_PROXY_ALREADY_EXISTS = "ASSET_PROXY_ALREADY_EXISTS"; // AssetProxy with same id already exists.
|
||||
|
||||
/// dispatchTransferFrom errors ///
|
||||
string constant ASSET_PROXY_DOES_NOT_EXIST = "ASSET_PROXY_DOES_NOT_EXIST"; // No assetProxy registered at given id.
|
||||
|
@@ -26,10 +26,9 @@ contract MAssetProxyDispatcher is
|
||||
{
|
||||
|
||||
// Logs registration of new asset proxy
|
||||
event AssetProxySet(
|
||||
event AssetProxyRegistered(
|
||||
bytes4 id, // Id of new registered AssetProxy.
|
||||
address newAssetProxy, // Address of new registered AssetProxy.
|
||||
address oldAssetProxy // Address of AssetProxy that was overwritten at given id (or null address).
|
||||
address assetProxy // Address of new registered AssetProxy.
|
||||
);
|
||||
|
||||
/// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws.
|
||||
|
@@ -96,8 +96,8 @@ export async function coreCombinatorialUtilsFactoryAsync(
|
||||
zrxAssetData,
|
||||
);
|
||||
const exchangeWrapper = new ExchangeWrapper(exchangeContract, provider);
|
||||
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, ownerAddress);
|
||||
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, ownerAddress);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, ownerAddress);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc721Proxy.address, ownerAddress);
|
||||
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeContract.address, {
|
||||
|
@@ -1,12 +1,10 @@
|
||||
import { AssetProxyId, SignedOrder } from '@0xproject/types';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { ExchangeContract } from '../generated_contract_wrappers/exchange';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { formatters } from './formatters';
|
||||
import { LogDecoder } from './log_decoder';
|
||||
import { orderUtils } from './order_utils';
|
||||
@@ -192,20 +190,10 @@ export class ExchangeWrapper {
|
||||
return tx;
|
||||
}
|
||||
public async registerAssetProxyAsync(
|
||||
assetProxyId: AssetProxyId,
|
||||
assetProxyAddress: string,
|
||||
from: string,
|
||||
opts: { oldAssetProxyAddressIfExists?: string } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const oldAssetProxyAddress = _.isUndefined(opts.oldAssetProxyAddressIfExists)
|
||||
? constants.NULL_ADDRESS
|
||||
: opts.oldAssetProxyAddressIfExists;
|
||||
const txHash = await this._exchange.registerAssetProxy.sendTransactionAsync(
|
||||
assetProxyId,
|
||||
assetProxyAddress,
|
||||
oldAssetProxyAddress,
|
||||
{ from },
|
||||
);
|
||||
const txHash = await this._exchange.registerAssetProxy.sendTransactionAsync(assetProxyAddress, { from });
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
}
|
||||
|
Reference in New Issue
Block a user