Switch to using deployment nonce instead of transformer addresses.

This commit is contained in:
Lawrence Forman 2020-06-09 13:37:32 -04:00
parent 7ce7dd7252
commit f1f6aa7d80
6 changed files with 126 additions and 14 deletions

View File

@ -35,6 +35,7 @@
"multiBridge": "0xc03117a8c9bde203f70aa911cb64a7a0df5ba1e1",
"exchangeProxy": "0x0000000000000000000000000000000000000000",
"exchangeProxyAllowanceTarget": "0x0000000000000000000000000000000000000000",
"exchangeProxyTransformerDeployer": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x0000000000000000000000000000000000000000",
"payTakerTransformer": "0x0000000000000000000000000000000000000000",
@ -77,6 +78,7 @@
"multiBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxy": "0x0000000000000000000000000000000000000000",
"exchangeProxyAllowanceTarget": "0x0000000000000000000000000000000000000000",
"exchangeProxyTransformerDeployer": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x0000000000000000000000000000000000000000",
"payTakerTransformer": "0x0000000000000000000000000000000000000000",
@ -119,6 +121,7 @@
"multiBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxy": "0x0000000000000000000000000000000000000000",
"exchangeProxyAllowanceTarget": "0x0000000000000000000000000000000000000000",
"exchangeProxyTransformerDeployer": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x0000000000000000000000000000000000000000",
"payTakerTransformer": "0x0000000000000000000000000000000000000000",
@ -161,6 +164,7 @@
"multiBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxy": "0x0000000000000000000000000000000000000000",
"exchangeProxyAllowanceTarget": "0x0000000000000000000000000000000000000000",
"exchangeProxyTransformerDeployer": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x0000000000000000000000000000000000000000",
"payTakerTransformer": "0x0000000000000000000000000000000000000000",
@ -203,6 +207,7 @@
"multiBridge": "0x0000000000000000000000000000000000000000",
"exchangeProxy": "0x0000000000000000000000000000000000000000",
"exchangeProxyAllowanceTarget": "0x0000000000000000000000000000000000000000",
"exchangeProxyTransformerDeployer": "0x0000000000000000000000000000000000000000",
"transformers": {
"wethTransformer": "0x0000000000000000000000000000000000000000",
"payTakerTransformer": "0x0000000000000000000000000000000000000000",

View File

@ -36,6 +36,7 @@ export interface ContractAddresses {
multiBridge: string;
exchangeProxy: string;
exchangeProxyAllowanceTarget: string;
exchangeProxyTransformerDeployer: string;
transformers: {
wethTransformer: string;
payTakerTransformer: string;

View File

@ -15,6 +15,14 @@
"name": "TransformedERC20",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "address", "name": "transformerDeployer", "type": "address" }
],
"name": "TransformerDeployerUpdated",
"type": "event"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "callDataHash", "type": "bytes32" },
@ -25,7 +33,7 @@
{ "internalType": "uint256", "name": "minOutputTokenAmount", "type": "uint256" },
{
"components": [
{ "internalType": "contract IERC20Transformer", "name": "transformer", "type": "address" },
{ "internalType": "uint32", "name": "deploymentNonce", "type": "uint32" },
{ "internalType": "bytes", "name": "data", "type": "bytes" }
],
"internalType": "struct ITransformERC20.Transformation[]",
@ -59,6 +67,13 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "transformerDeployer", "type": "address" }],
"name": "setTransformerDeployer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "contract IERC20TokenV06", "name": "inputToken", "type": "address" },
@ -67,7 +82,7 @@
{ "internalType": "uint256", "name": "minOutputTokenAmount", "type": "uint256" },
{
"components": [
{ "internalType": "contract IERC20Transformer", "name": "transformer", "type": "address" },
{ "internalType": "uint32", "name": "deploymentNonce", "type": "uint32" },
{ "internalType": "bytes", "name": "data", "type": "bytes" }
],
"internalType": "struct ITransformERC20.Transformation[]",
@ -84,7 +99,7 @@
"devdoc": {
"details": "Feature to composably transform between ERC20 tokens.",
"methods": {
"_transformERC20(bytes32,address,address,address,uint256,uint256,(address,bytes)[])": {
"_transformERC20(bytes32,address,address,address,uint256,uint256,(uint32,bytes)[])": {
"details": "Internal version of `transformERC20()`. Only callable from within.",
"params": {
"callDataHash": "Hash of the ingress calldata.",
@ -109,7 +124,11 @@
"details": "Return the allowed deployer for transformers.",
"returns": { "deployer": "The transform deployer address." }
},
"transformERC20(address,address,uint256,uint256,(address,bytes)[])": {
"setTransformerDeployer(address)": {
"details": "Replace the allowed deployer for transformers. Only callable by the owner.",
"params": { "transformerDeployer": "The address of the trusted deployer for transformers." }
},
"transformERC20(address,address,uint256,uint256,(uint32,bytes)[])": {
"details": "Executes a series of transformations to convert an ERC20 `inputToken` to an ERC20 `outputToken`.",
"params": {
"inputToken": "The token being provided by the sender. If `0xeee...`, ETH is implied and should be provided with the call.`",
@ -126,7 +145,7 @@
},
"compiler": {
"name": "solc",
"version": "0.6.8+commit.0bbfe453",
"version": "0.6.9+commit.3e3065ac",
"settings": {
"optimizer": {
"enabled": true,

View File

@ -35,10 +35,13 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers';
// tslint:enable:no-unused-variable
export type ITransformERC20EventArgs = ITransformERC20TransformedERC20EventArgs;
export type ITransformERC20EventArgs =
| ITransformERC20TransformedERC20EventArgs
| ITransformERC20TransformerDeployerUpdatedEventArgs;
export enum ITransformERC20Events {
TransformedERC20 = 'TransformedERC20',
TransformerDeployerUpdated = 'TransformerDeployerUpdated',
}
export interface ITransformERC20TransformedERC20EventArgs extends DecodedLogArgs {
@ -49,6 +52,10 @@ export interface ITransformERC20TransformedERC20EventArgs extends DecodedLogArgs
outputTokenAmount: BigNumber;
}
export interface ITransformERC20TransformerDeployerUpdatedEventArgs extends DecodedLogArgs {
transformerDeployer: string;
}
/* istanbul ignore next */
// tslint:disable:array-type
// tslint:disable:no-parameter-reassignment
@ -199,6 +206,19 @@ export class ITransformERC20Contract extends BaseContract {
outputs: [],
type: 'event',
},
{
anonymous: false,
inputs: [
{
name: 'transformerDeployer',
type: 'address',
indexed: false,
},
],
name: 'TransformerDeployerUpdated',
outputs: [],
type: 'event',
},
{
inputs: [
{
@ -230,8 +250,8 @@ export class ITransformERC20Contract extends BaseContract {
type: 'tuple[]',
components: [
{
name: 'transformer',
type: 'address',
name: 'deploymentNonce',
type: 'uint32',
},
{
name: 'data',
@ -286,6 +306,18 @@ export class ITransformERC20Contract extends BaseContract {
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
name: 'transformerDeployer',
type: 'address',
},
],
name: 'setTransformerDeployer',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
@ -309,8 +341,8 @@ export class ITransformERC20Contract extends BaseContract {
type: 'tuple[]',
components: [
{
name: 'transformer',
type: 'address',
name: 'deploymentNonce',
type: 'uint32',
},
{
name: 'data',
@ -429,7 +461,7 @@ export class ITransformERC20Contract extends BaseContract {
outputToken: string,
inputTokenAmount: BigNumber,
minOutputTokenAmount: BigNumber,
transformations: Array<{ transformer: string; data: string }>,
transformations: Array<{ deploymentNonce: number | BigNumber; data: string }>,
): ContractTxFunctionObj<BigNumber> {
const self = (this as any) as ITransformERC20Contract;
assert.isString('callDataHash', callDataHash);
@ -439,7 +471,7 @@ export class ITransformERC20Contract extends BaseContract {
assert.isBigNumber('inputTokenAmount', inputTokenAmount);
assert.isBigNumber('minOutputTokenAmount', minOutputTokenAmount);
assert.isArray('transformations', transformations);
const functionSignature = '_transformERC20(bytes32,address,address,address,uint256,uint256,(address,bytes)[])';
const functionSignature = '_transformERC20(bytes32,address,address,address,uint256,uint256,(uint32,bytes)[])';
return {
async sendTransactionAsync(
@ -641,6 +673,59 @@ export class ITransformERC20Contract extends BaseContract {
},
};
}
/**
* Replace the allowed deployer for transformers.
* Only callable by the owner.
* @param transformerDeployer The address of the trusted deployer for
* transformers.
*/
public setTransformerDeployer(transformerDeployer: string): ContractTxFunctionObj<void> {
const self = (this as any) as ITransformERC20Contract;
assert.isString('transformerDeployer', transformerDeployer);
const functionSignature = 'setTransformerDeployer(address)';
return {
async sendTransactionAsync(
txData?: Partial<TxData> | undefined,
opts: SendTransactionOpts = { shouldValidate: true },
): Promise<string> {
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
{ ...txData, data: this.getABIEncodedTransactionData() },
this.estimateGasAsync.bind(this),
);
if (opts.shouldValidate !== false) {
await this.callAsync(txDataWithDefaults);
}
return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults);
},
awaitTransactionSuccessAsync(
txData?: Partial<TxData>,
opts: AwaitTransactionSuccessOpts = { shouldValidate: true },
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts);
},
async estimateGasAsync(txData?: Partial<TxData> | undefined): Promise<number> {
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
...txData,
data: this.getABIEncodedTransactionData(),
});
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
},
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
},
getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [transformerDeployer.toLowerCase()]);
},
};
}
/**
* Executes a series of transformations to convert an ERC20 `inputToken`
* to an ERC20 `outputToken`.
@ -659,7 +744,7 @@ export class ITransformERC20Contract extends BaseContract {
outputToken: string,
inputTokenAmount: BigNumber,
minOutputTokenAmount: BigNumber,
transformations: Array<{ transformer: string; data: string }>,
transformations: Array<{ deploymentNonce: number | BigNumber; data: string }>,
): ContractTxFunctionObj<BigNumber> {
const self = (this as any) as ITransformERC20Contract;
assert.isString('inputToken', inputToken);
@ -667,7 +752,7 @@ export class ITransformERC20Contract extends BaseContract {
assert.isBigNumber('inputTokenAmount', inputTokenAmount);
assert.isBigNumber('minOutputTokenAmount', minOutputTokenAmount);
assert.isArray('transformations', transformations);
const functionSignature = 'transformERC20(address,address,uint256,uint256,(address,bytes)[])';
const functionSignature = 'transformERC20(address,address,uint256,uint256,(uint32,bytes)[])';
return {
async sendTransactionAsync(

View File

@ -87,6 +87,7 @@ export {
ITransformERC20Contract,
ITransformERC20EventArgs,
ITransformERC20Events,
ITransformERC20TransformerDeployerUpdatedEventArgs,
ITransformERC20TransformedERC20EventArgs,
} from './generated-wrappers/i_transform_erc20';
export {

View File

@ -327,6 +327,7 @@ export async function runMigrationsAsync(
multiBridge: NULL_ADDRESS,
exchangeProxy: NULL_ADDRESS,
exchangeProxyAllowanceTarget: NULL_ADDRESS,
exchangeProxyTransformerDeployer: NULL_ADDRESS,
transformers: {
wethTransformer: NULL_ADDRESS,
payTakerTransformer: NULL_ADDRESS,