2019-10-01 22:14:01 -07:00

356 lines
18 KiB
TypeScript
Generated

// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma
// tslint:disable:whitespace no-unbound-method no-trailing-whitespace
// tslint:disable:no-unused-variable
import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract';
import { schemas } from '@0x/json-schemas';
import {
BlockParam,
BlockParamLiteral,
BlockRange,
CallData,
ContractAbi,
ContractArtifact,
DecodedLogArgs,
MethodAbi,
TransactionReceiptWithDecodedLogs,
TxData,
TxDataPayable,
SupportedProvider,
} from 'ethereum-types';
import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils';
import { SimpleContractArtifact } from '@0x/types';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { assert } from '@0x/assert';
import * as ethers from 'ethers';
// tslint:enable:no-unused-variable
/* istanbul ignore next */
// tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
export class StaticCallProxyContract extends BaseContract {
public static deployedBytecode =
'0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063a85e59e41461003b578063ae25532e146100d3575b600080fd5b6100d16004803603608081101561005157600080fd5b81019060208101813564010000000081111561006c57600080fd5b82018360208201111561007e57600080fd5b803590602001918460018302840111640100000000831117156100a057600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610110565b005b6100db6103a5565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b6000606060006101656004898990508a8a8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092949392505063ffffffff6103c5169050565b806020019051606081101561017957600080fd5b8151602083018051604051929492938301929190846401000000008211156101a057600080fd5b9083019060208201858111156101b557600080fd5b82516401000000008111828201881017156101cf57600080fd5b82525081516020918201929091019080838360005b838110156101fc5781810151838201526020016101e4565b50505050905090810190601f1680156102295780820380516001836020036101000a031916815260200191505b5060405260200180519060200190929190505050925092509250600060608473ffffffffffffffffffffffffffffffffffffffff16846040518082805190602001908083835b602083106102ac57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161026f565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d806000811461030c576040519150601f19603f3d011682016040523d82523d6000602084013e610311565b606091505b50915091508161032357805160208201fd5b8051602082012083811461039857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f554e45585045435445445f5354415449435f43414c4c5f524553554c54000000604482015290519081900360640190fd5b5050505050505050505050565b600060405180806104b06021913960210190506040518091039020905090565b6060818311156103e3576103e36103de60008585610408565b6104a7565b83518211156103fc576103fc6103de6001848751610408565b50819003910190815290565b6060632800659560e01b8484846040516024018084600781111561042857fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe53746174696343616c6c28616464726573732c62797465732c6279746573333229a265627a7a72315820c55cf13cfcaaf322238d786911313ce7d45854692241ae9b56709bdbfed4f54c64736f6c634300050b0032';
/**
* Makes a staticcall to a target address and verifies that the data returned matches the expected return data.
*/
public transferFrom = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
* @param assetData Byte array encoded with staticCallTarget, staticCallData,
* and expectedCallResultHash
* @param from This value is ignored.
* @param to This value is ignored.
* @param amount This value is ignored.
*/
async callAsync(
assetData: string,
from: string,
to: string,
amount: BigNumber,
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<void> {
assert.isString('assetData', assetData);
assert.isString('from', from);
assert.isString('to', to);
assert.isBigNumber('amount', amount);
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as StaticCallProxyContract;
const encodedData = self._strictEncodeArguments('transferFrom(bytes,address,address,uint256)', [
assetData,
from.toLowerCase(),
to.toLowerCase(),
amount,
]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
let rawCallResult;
try {
rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
} catch (err) {
BaseContract._throwIfThrownErrorIsRevertError(err);
throw err;
}
BaseContract._throwIfCallResultIsRevertError(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
* @param assetData Byte array encoded with staticCallTarget, staticCallData,
* and expectedCallResultHash
* @param from This value is ignored.
* @param to This value is ignored.
* @param amount This value is ignored.
* @returns The ABI encoded transaction data as a string
*/
getABIEncodedTransactionData(assetData: string, from: string, to: string, amount: BigNumber): string {
assert.isString('assetData', assetData);
assert.isString('from', from);
assert.isString('to', to);
assert.isBigNumber('amount', amount);
const self = (this as any) as StaticCallProxyContract;
const abiEncodedTransactionData = self._strictEncodeArguments(
'transferFrom(bytes,address,address,uint256)',
[assetData, from.toLowerCase(), to.toLowerCase(), amount],
);
return abiEncodedTransactionData;
},
/**
* Decode the ABI-encoded transaction data into its input arguments
* @param callData The ABI-encoded transaction data
* @returns An array representing the input arguments in order. Keynames of nested structs are preserved.
*/
getABIDecodedTransactionData(callData: string): [string, string, string, BigNumber] {
const self = (this as any) as StaticCallProxyContract;
const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<[string, string, string, BigNumber]>(callData);
return abiDecodedCallData;
},
/**
* Decode the ABI-encoded return data from a transaction
* @param returnData the data returned after transaction execution
* @returns An array representing the output results in order. Keynames of nested structs are preserved.
*/
getABIDecodedReturnData(returnData: string): void {
const self = (this as any) as StaticCallProxyContract;
const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<void>(returnData);
return abiDecodedReturnData;
},
};
/**
* Gets the proxy id associated with the proxy address.
*/
public getProxyId = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
* @returns Proxy id.
*/
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as StaticCallProxyContract;
const encodedData = self._strictEncodeArguments('getProxyId()', []);
const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex');
let rawCallResult;
try {
rawCallResult = await self.evmExecAsync(encodedDataBytes);
} catch (err) {
BaseContract._throwIfThrownErrorIsRevertError(err);
throw err;
}
BaseContract._throwIfCallResultIsRevertError(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('getProxyId()');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
* @returns The ABI encoded transaction data as a string
*/
getABIEncodedTransactionData(): string {
const self = (this as any) as StaticCallProxyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []);
return abiEncodedTransactionData;
},
/**
* Decode the ABI-encoded transaction data into its input arguments
* @param callData The ABI-encoded transaction data
* @returns An array representing the input arguments in order. Keynames of nested structs are preserved.
*/
getABIDecodedTransactionData(callData: string): void {
const self = (this as any) as StaticCallProxyContract;
const abiEncoder = self._lookupAbiEncoder('getProxyId()');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<void>(callData);
return abiDecodedCallData;
},
/**
* Decode the ABI-encoded return data from a transaction
* @param returnData the data returned after transaction execution
* @returns An array representing the output results in order. Keynames of nested structs are preserved.
*/
getABIDecodedReturnData(returnData: string): string {
const self = (this as any) as StaticCallProxyContract;
const abiEncoder = self._lookupAbiEncoder('getProxyId()');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<string>(returnData);
return abiDecodedReturnData;
},
};
public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
): Promise<StaticCallProxyContract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (artifact.compilerOutput === undefined) {
throw new Error('Compiler output not found in the artifact file');
}
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const bytecode = artifact.compilerOutput.evm.bytecode.object;
const abi = artifact.compilerOutput.abi;
const logDecodeDependenciesAbiOnly: { [contractName: string]: ContractAbi } = {};
if (Object.keys(logDecodeDependencies) !== undefined) {
for (const key of Object.keys(logDecodeDependencies)) {
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
}
}
return StaticCallProxyContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
}
public static async deployAsync(
bytecode: string,
abi: ContractAbi,
supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>,
logDecodeDependencies: { [contractName: string]: ContractAbi },
): Promise<StaticCallProxyContract> {
assert.isHexString('bytecode', bytecode);
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []);
const web3Wrapper = new Web3Wrapper(provider);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{ data: txData },
txDefaults,
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
);
const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults);
logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`StaticCallProxy successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new StaticCallProxyContract(
txReceipt.contractAddress as string,
provider,
txDefaults,
logDecodeDependencies,
);
contractInstance.constructorArgs = [];
return contractInstance;
}
/**
* @returns The contract ABI
*/
public static ABI(): ContractAbi {
const abi = [
{
constant: true,
inputs: [
{
name: 'assetData',
type: 'bytes',
},
{
name: 'from',
type: 'address',
},
{
name: 'to',
type: 'address',
},
{
name: 'amount',
type: 'uint256',
},
],
name: 'transferFrom',
outputs: [],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'getProxyId',
outputs: [
{
name: '',
type: 'bytes4',
},
],
payable: false,
stateMutability: 'pure',
type: 'function',
},
] as ContractAbi;
return abi;
}
constructor(
address: string,
supportedProvider: SupportedProvider,
txDefaults?: Partial<TxData>,
logDecodeDependencies?: { [contractName: string]: ContractAbi },
deployedBytecode: string | undefined = StaticCallProxyContract.deployedBytecode,
) {
super(
'StaticCallProxy',
StaticCallProxyContract.ABI(),
address,
supportedProvider,
txDefaults,
logDecodeDependencies,
deployedBytecode,
);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
}
}
// tslint:disable:max-file-line-count
// tslint:enable:no-unbound-method no-parameter-reassignment no-consecutive-blank-lines ordered-imports align
// tslint:enable:trailing-comma whitespace no-trailing-whitespace