* add LibERC721Order.sol * Add ERC721 interface to vendor/ * Add ERC721OrdersFeature interface * Storage lib for ERC721 orders feature * Implement basic functionality for ERC721 orders (buy, sell, cancel, etc) * Add isValidERC721OrderSignature to interface * implement onERC721Received * Implement batchBuyERC721s * left/right orders -> sell/buy orders * Add missing @return comments * Implement matching functions * Use SafeMath where necessary * add rich errors for ERC721OrdersFeature * Add comments * Add presign support for ERC721 orders * Cancel using just the order nonce * Add IERC721OrdersFeature to IZeroEx * Add taker callback * Assembly optimizations in LibERC721Order * Add ERC721Orders TS class * create zero-ex/contracts/test/integration/ and tokens/ directories * TestMintableERC721Token * tmp * address feedback from original PR (#391) * address feedback from original PR * Update contracts/zero-ex/contracts/src/features/ERC721OrdersFeature.sol Co-authored-by: Kim Persson <kimpers@users.noreply.github.com> * address review feedback and improve order parameter naming * Add batchCancel function * Emit order fields in preSign * Fix tests Co-authored-by: Lawrence Forman <me@merklejerk.com> Co-authored-by: Kim Persson <kimpers@users.noreply.github.com> Co-authored-by: Michael Zhu <mchl.zhu.96@gmail.com> * Remove revertIfIncomplete from batchMatch * Sanity check maker address in preSign * ERC1155OrdersFeature contracts * Commence refactor, abstract base contract * ERC721OrdersFeature inherits from NFTOrders * Refactor ERC1155OrdersFeature to inherit from NFTOrders * Fix order hashing * Fix ERC721OrdersFeature tests * Typos * Remove maker address from preSigned mapping * disable dex sampler tests * Refactor TS tooling * Address PR feedback * Rearrange event fields to better align with struct fields * Update comments * update AbiEncoder.create params * Add ERC1155Order to protocol-utils * Add ERC1155OrdersFeeature tests * Bump package versions and regenerate contract wrappers * Add ERC165Feature * NFT orders: address audit findings (#417) * CVF-1: use pragma solidity ^0.6 instead of ^0.6.5 * CVF-11: fix inaccurate comment * CVF-16: Enable taker callbacks for batchBuyERC1155s * CVF-17: use internal call if revertIfIncomplete is true * CVF-21: avoid duplicate SLOAD * CVF-23: merge if statements * CVF-24: Reorder status checks to be consistent with ERC721OrdersFeature * CVF-25: Update unclear comment (canonical hash -> EIP-712 hash) * CVF-31: Document keys of orderState mapping * CVF-45: DRY up fees/properties hashing * CVF-47, CVF-50, CVF-57: calculate properties.length once; hash propertyStructHashArray in-place using assembly * CVF-56: More descriptive names for assembly variables * CVF-71: Update confusing comment about rounding in _payFees * CVF-72: Move ETH assertions outside of loop in _payFees * CVF-74: Move property validation loop to else branch * CVF-82: Update inaccurate comment * CVF-86: Enable taker callbacks for batchBuyERC721s * CVF-87: use internal call if revertIfIncomplete is true * CVF-89: Perform token mismatch checks before stateful operations * CVF-90, CVF-91: Defer ERC20 token mismatch check * CVF-93: Add inline comments for _payFees parameters in matchERC721Orders * CVF-94: Fix comment (Step 7 -> Step 5) * CVF-98: Use binary & operator instead of mod * CVF-99: Update unclear comment (canonical hash -> EIP-712 hash) * CVF-65, CVF-66, CVF-67: Copy params.ethAvailable into local variable; check that ethSpent does not exceed ethAvailable; remove ethAvailable < erc20FillAmount check * CVF-52, CVF-55, CVF-59: calculate fees.length once; hash feeStructHashArray in-place using assembly * CVF-14, CVF-32: OrderState struct; separate storage mapping for 1155 cancellations so orders can be cancelled by nonce * Update changelogs, IZeroEx artifact/wrapper Co-authored-by: Lawrence Forman <lawrence@0xproject.com> Co-authored-by: Lawrence Forman <me@merklejerk.com> Co-authored-by: Kim Persson <kimpers@users.noreply.github.com>
1126 lines
50 KiB
TypeScript
1126 lines
50 KiB
TypeScript
// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming
|
|
// tslint:disable:whitespace no-unbound-method no-trailing-whitespace
|
|
// tslint:disable:no-unused-variable
|
|
import {
|
|
AwaitTransactionSuccessOpts,
|
|
EncoderOverrides,
|
|
ContractFunctionObj,
|
|
ContractTxFunctionObj,
|
|
SendTransactionOpts,
|
|
BaseContract,
|
|
SubscriptionManager,
|
|
PromiseWithTransactionHash,
|
|
methodAbiToFunctionSignature,
|
|
linkLibrariesInBytecode,
|
|
} from '@0x/base-contract';
|
|
import { schemas } from '@0x/json-schemas';
|
|
import {
|
|
BlockParam,
|
|
BlockParamLiteral,
|
|
BlockRange,
|
|
CallData,
|
|
ContractAbi,
|
|
ContractArtifact,
|
|
DecodedLogArgs,
|
|
LogWithDecodedArgs,
|
|
MethodAbi,
|
|
TransactionReceiptWithDecodedLogs,
|
|
TxData,
|
|
TxDataPayable,
|
|
TxAccessListWithGas,
|
|
SupportedProvider,
|
|
} from 'ethereum-types';
|
|
import { AbiEncoder, BigNumber, classUtils, EncodingRules, hexUtils, logUtils, providerUtils } from '@0x/utils';
|
|
import { EventCallback, IndexedFilterValues, 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
|
|
|
|
export type ITransformERC20EventArgs =
|
|
| ITransformERC20QuoteSignerUpdatedEventArgs
|
|
| ITransformERC20TransformedERC20EventArgs
|
|
| ITransformERC20TransformerDeployerUpdatedEventArgs;
|
|
|
|
export enum ITransformERC20Events {
|
|
QuoteSignerUpdated = 'QuoteSignerUpdated',
|
|
TransformedERC20 = 'TransformedERC20',
|
|
TransformerDeployerUpdated = 'TransformerDeployerUpdated',
|
|
}
|
|
|
|
export interface ITransformERC20QuoteSignerUpdatedEventArgs extends DecodedLogArgs {
|
|
quoteSigner: string;
|
|
}
|
|
|
|
export interface ITransformERC20TransformedERC20EventArgs extends DecodedLogArgs {
|
|
taker: string;
|
|
inputToken: string;
|
|
outputToken: string;
|
|
inputTokenAmount: BigNumber;
|
|
outputTokenAmount: BigNumber;
|
|
}
|
|
|
|
export interface ITransformERC20TransformerDeployerUpdatedEventArgs extends DecodedLogArgs {
|
|
transformerDeployer: string;
|
|
}
|
|
|
|
/* istanbul ignore next */
|
|
// tslint:disable:array-type
|
|
// tslint:disable:no-parameter-reassignment
|
|
// tslint:disable-next-line:class-name
|
|
export class ITransformERC20Contract extends BaseContract {
|
|
/**
|
|
* @ignore
|
|
*/
|
|
public static deployedBytecode: string | undefined;
|
|
public static contractName = 'ITransformERC20';
|
|
private readonly _methodABIIndex: { [name: string]: number } = {};
|
|
private readonly _subscriptionManager: SubscriptionManager<ITransformERC20EventArgs, ITransformERC20Events>;
|
|
public static async deployFrom0xArtifactAsync(
|
|
artifact: ContractArtifact | SimpleContractArtifact,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
|
): Promise<ITransformERC20Contract> {
|
|
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema);
|
|
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 ITransformERC20Contract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
|
|
}
|
|
|
|
public static async deployWithLibrariesFrom0xArtifactAsync(
|
|
artifact: ContractArtifact,
|
|
libraryArtifacts: { [libraryName: string]: ContractArtifact },
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
|
): Promise<ITransformERC20Contract> {
|
|
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema);
|
|
if (artifact.compilerOutput === undefined) {
|
|
throw new Error('Compiler output not found in the artifact file');
|
|
}
|
|
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
|
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;
|
|
}
|
|
}
|
|
const libraryAddresses = await ITransformERC20Contract._deployLibrariesAsync(
|
|
artifact,
|
|
libraryArtifacts,
|
|
new Web3Wrapper(provider),
|
|
txDefaults,
|
|
);
|
|
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
|
|
return ITransformERC20Contract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
|
|
}
|
|
|
|
public static async deployAsync(
|
|
bytecode: string,
|
|
abi: ContractAbi,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractAbi },
|
|
): Promise<ITransformERC20Contract> {
|
|
assert.isHexString('bytecode', bytecode);
|
|
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema);
|
|
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._applyDefaultsToContractTxDataAsync(
|
|
{
|
|
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(`ITransformERC20 successfully deployed at ${txReceipt.contractAddress}`);
|
|
const contractInstance = new ITransformERC20Contract(
|
|
txReceipt.contractAddress as string,
|
|
provider,
|
|
txDefaults,
|
|
logDecodeDependencies,
|
|
);
|
|
contractInstance.constructorArgs = [];
|
|
return contractInstance;
|
|
}
|
|
|
|
/**
|
|
* @returns The contract ABI
|
|
*/
|
|
public static ABI(): ContractAbi {
|
|
const abi = [
|
|
{
|
|
anonymous: false,
|
|
inputs: [
|
|
{
|
|
name: 'quoteSigner',
|
|
type: 'address',
|
|
indexed: false,
|
|
},
|
|
],
|
|
name: 'QuoteSignerUpdated',
|
|
outputs: [],
|
|
type: 'event',
|
|
},
|
|
{
|
|
anonymous: false,
|
|
inputs: [
|
|
{
|
|
name: 'taker',
|
|
type: 'address',
|
|
indexed: true,
|
|
},
|
|
{
|
|
name: 'inputToken',
|
|
type: 'address',
|
|
indexed: false,
|
|
},
|
|
{
|
|
name: 'outputToken',
|
|
type: 'address',
|
|
indexed: false,
|
|
},
|
|
{
|
|
name: 'inputTokenAmount',
|
|
type: 'uint256',
|
|
indexed: false,
|
|
},
|
|
{
|
|
name: 'outputTokenAmount',
|
|
type: 'uint256',
|
|
indexed: false,
|
|
},
|
|
],
|
|
name: 'TransformedERC20',
|
|
outputs: [],
|
|
type: 'event',
|
|
},
|
|
{
|
|
anonymous: false,
|
|
inputs: [
|
|
{
|
|
name: 'transformerDeployer',
|
|
type: 'address',
|
|
indexed: false,
|
|
},
|
|
],
|
|
name: 'TransformerDeployerUpdated',
|
|
outputs: [],
|
|
type: 'event',
|
|
},
|
|
{
|
|
inputs: [
|
|
{
|
|
name: 'args',
|
|
type: 'tuple',
|
|
components: [
|
|
{
|
|
name: 'taker',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'inputToken',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'outputToken',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'inputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'minOutputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'transformations',
|
|
type: 'tuple[]',
|
|
components: [
|
|
{
|
|
name: 'deploymentNonce',
|
|
type: 'uint32',
|
|
},
|
|
{
|
|
name: 'data',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'useSelfBalance',
|
|
type: 'bool',
|
|
},
|
|
{
|
|
name: 'recipient',
|
|
type: 'address',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
name: '_transformERC20',
|
|
outputs: [
|
|
{
|
|
name: 'outputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
stateMutability: 'payable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'createTransformWallet',
|
|
outputs: [
|
|
{
|
|
name: 'wallet',
|
|
type: 'address',
|
|
},
|
|
],
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'getQuoteSigner',
|
|
outputs: [
|
|
{
|
|
name: 'signer',
|
|
type: 'address',
|
|
},
|
|
],
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'getTransformWallet',
|
|
outputs: [
|
|
{
|
|
name: 'wallet',
|
|
type: 'address',
|
|
},
|
|
],
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [],
|
|
name: 'getTransformerDeployer',
|
|
outputs: [
|
|
{
|
|
name: 'deployer',
|
|
type: 'address',
|
|
},
|
|
],
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [
|
|
{
|
|
name: 'quoteSigner',
|
|
type: 'address',
|
|
},
|
|
],
|
|
name: 'setQuoteSigner',
|
|
outputs: [],
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [
|
|
{
|
|
name: 'transformerDeployer',
|
|
type: 'address',
|
|
},
|
|
],
|
|
name: 'setTransformerDeployer',
|
|
outputs: [],
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
inputs: [
|
|
{
|
|
name: 'inputToken',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'outputToken',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'inputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'minOutputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'transformations',
|
|
type: 'tuple[]',
|
|
components: [
|
|
{
|
|
name: 'deploymentNonce',
|
|
type: 'uint32',
|
|
},
|
|
{
|
|
name: 'data',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
name: 'transformERC20',
|
|
outputs: [
|
|
{
|
|
name: 'outputTokenAmount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
stateMutability: 'payable',
|
|
type: 'function',
|
|
},
|
|
] as ContractAbi;
|
|
return abi;
|
|
}
|
|
|
|
protected static async _deployLibrariesAsync(
|
|
artifact: ContractArtifact,
|
|
libraryArtifacts: { [libraryName: string]: ContractArtifact },
|
|
web3Wrapper: Web3Wrapper,
|
|
txDefaults: Partial<TxData>,
|
|
libraryAddresses: { [libraryName: string]: string } = {},
|
|
): Promise<{ [libraryName: string]: string }> {
|
|
const links = artifact.compilerOutput.evm.bytecode.linkReferences;
|
|
// Go through all linked libraries, recursively deploying them if necessary.
|
|
for (const link of Object.values(links)) {
|
|
for (const libraryName of Object.keys(link)) {
|
|
if (!libraryAddresses[libraryName]) {
|
|
// Library not yet deployed.
|
|
const libraryArtifact = libraryArtifacts[libraryName];
|
|
if (!libraryArtifact) {
|
|
throw new Error(`Missing artifact for linked library "${libraryName}"`);
|
|
}
|
|
// Deploy any dependent libraries used by this library.
|
|
await ITransformERC20Contract._deployLibrariesAsync(
|
|
libraryArtifact,
|
|
libraryArtifacts,
|
|
web3Wrapper,
|
|
txDefaults,
|
|
libraryAddresses,
|
|
);
|
|
// Deploy this library.
|
|
const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
|
|
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
|
|
{
|
|
data: linkedLibraryBytecode,
|
|
...txDefaults,
|
|
},
|
|
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
|
|
);
|
|
const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
|
logUtils.log(`transactionHash: ${txHash}`);
|
|
const { contractAddress } = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
|
logUtils.log(`${libraryArtifact.contractName} successfully deployed at ${contractAddress}`);
|
|
libraryAddresses[libraryArtifact.contractName] = contractAddress as string;
|
|
}
|
|
}
|
|
}
|
|
return libraryAddresses;
|
|
}
|
|
|
|
public getFunctionSignature(methodName: string): string {
|
|
const index = this._methodABIIndex[methodName];
|
|
const methodAbi = ITransformERC20Contract.ABI()[index] as MethodAbi; // tslint:disable-line:no-unnecessary-type-assertion
|
|
const functionSignature = methodAbiToFunctionSignature(methodAbi);
|
|
return functionSignature;
|
|
}
|
|
|
|
public getABIDecodedTransactionData<T>(methodName: string, callData: string): T {
|
|
const functionSignature = this.getFunctionSignature(methodName);
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
const abiDecodedCallData = abiEncoder.strictDecode<T>(callData);
|
|
return abiDecodedCallData;
|
|
}
|
|
|
|
public getABIDecodedReturnData<T>(methodName: string, callData: string): T {
|
|
if (this._encoderOverrides.decodeOutput) {
|
|
return this._encoderOverrides.decodeOutput(methodName, callData);
|
|
}
|
|
const functionSignature = this.getFunctionSignature(methodName);
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
const abiDecodedCallData = abiEncoder.strictDecodeReturnValue<T>(callData);
|
|
return abiDecodedCallData;
|
|
}
|
|
|
|
public getSelector(methodName: string): string {
|
|
const functionSignature = this.getFunctionSignature(methodName);
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
return abiEncoder.getSelector();
|
|
}
|
|
|
|
/**
|
|
* Internal version of `transformERC20()`. Only callable from within.
|
|
* @param args A `TransformERC20Args` struct.
|
|
*/
|
|
public _transformERC20(args: {
|
|
taker: string;
|
|
inputToken: string;
|
|
outputToken: string;
|
|
inputTokenAmount: BigNumber;
|
|
minOutputTokenAmount: BigNumber;
|
|
transformations: Array<{ deploymentNonce: number | BigNumber; data: string }>;
|
|
useSelfBalance: boolean;
|
|
recipient: string;
|
|
}): ContractTxFunctionObj<BigNumber> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
|
|
const functionSignature =
|
|
'_transformERC20((address,address,address,uint256,uint256,(uint32,bytes)[],bool,address))';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [args]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Deploy a new flash wallet instance and replace the current one with it.
|
|
* Useful if we somehow break the current wallet instance.
|
|
* Only callable by the owner.
|
|
*/
|
|
public createTransformWallet(): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const functionSignature = 'createTransformWallet()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Return the optional signer for `transformERC20()` calldata.
|
|
*/
|
|
public getQuoteSigner(): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const functionSignature = 'getQuoteSigner()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Return the current wallet instance that will serve as the execution
|
|
* context for transformations.
|
|
*/
|
|
public getTransformWallet(): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const functionSignature = 'getTransformWallet()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Return the allowed deployer for transformers.
|
|
*/
|
|
public getTransformerDeployer(): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
const functionSignature = 'getTransformerDeployer()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Replace the optional signer for `transformERC20()` calldata.
|
|
* Only callable by the owner.
|
|
* @param quoteSigner The address of the new calldata signer.
|
|
*/
|
|
public setQuoteSigner(quoteSigner: string): ContractTxFunctionObj<void> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
assert.isString('quoteSigner', quoteSigner);
|
|
const functionSignature = 'setQuoteSigner(address)';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [quoteSigner.toLowerCase()]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Replace the allowed deployer for transformers.
|
|
* Only callable by the owner.
|
|
* @param transformerDeployer The address of the new 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 {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
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`.
|
|
* @param inputToken The token being provided by the sender. If
|
|
* `0xeee...`, ETH is implied and should be provided with the call.`
|
|
* @param outputToken The token to be acquired by the sender. `0xeee...`
|
|
* implies ETH.
|
|
* @param inputTokenAmount The amount of `inputToken` to take from the sender.
|
|
* @param minOutputTokenAmount The minimum amount of `outputToken` the sender
|
|
* must receive for the entire transformation to succeed.
|
|
* @param transformations The transformations to execute on the token
|
|
* balance(s) in sequence.
|
|
*/
|
|
public transformERC20(
|
|
inputToken: string,
|
|
outputToken: string,
|
|
inputTokenAmount: BigNumber,
|
|
minOutputTokenAmount: BigNumber,
|
|
transformations: Array<{ deploymentNonce: number | BigNumber; data: string }>,
|
|
): ContractTxFunctionObj<BigNumber> {
|
|
const self = (this as any) as ITransformERC20Contract;
|
|
assert.isString('inputToken', inputToken);
|
|
assert.isString('outputToken', outputToken);
|
|
assert.isBigNumber('inputTokenAmount', inputTokenAmount);
|
|
assert.isBigNumber('minOutputTokenAmount', minOutputTokenAmount);
|
|
assert.isArray('transformations', transformations);
|
|
const functionSignature = 'transformERC20(address,address,uint256,uint256,(uint32,bytes)[])';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
async sendTransactionAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
opts: SendTransactionOpts = { shouldValidate: true },
|
|
): Promise<string> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...txData },
|
|
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({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
},
|
|
async createAccessListAsync(
|
|
txData?: Partial<TxData> | undefined,
|
|
defaultBlock?: BlockParam,
|
|
): Promise<TxAccessListWithGas> {
|
|
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
|
data: this.getABIEncodedTransactionData(),
|
|
...txData,
|
|
});
|
|
return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock);
|
|
},
|
|
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
|
|
BaseContract._assertCallParams(callData, defaultBlock);
|
|
const rawCallResult = await self._performCallAsync(
|
|
{ data: this.getABIEncodedTransactionData(), ...callData },
|
|
defaultBlock,
|
|
);
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
|
return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [
|
|
inputToken.toLowerCase(),
|
|
outputToken.toLowerCase(),
|
|
inputTokenAmount,
|
|
minOutputTokenAmount,
|
|
transformations,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Subscribe to an event type emitted by the ITransformERC20 contract.
|
|
* @param eventName The ITransformERC20 contract event you would like to subscribe to.
|
|
* @param indexFilterValues An object where the keys are indexed args returned by the event and
|
|
* the value is the value you are interested in. E.g `{maker: aUserAddressHex}`
|
|
* @param callback Callback that gets called when a log is added/removed
|
|
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
|
|
* @return Subscription token used later to unsubscribe
|
|
*/
|
|
public subscribe<ArgsType extends ITransformERC20EventArgs>(
|
|
eventName: ITransformERC20Events,
|
|
indexFilterValues: IndexedFilterValues,
|
|
callback: EventCallback<ArgsType>,
|
|
isVerbose: boolean = false,
|
|
blockPollingIntervalMs?: number,
|
|
): string {
|
|
assert.doesBelongToStringEnum('eventName', eventName, ITransformERC20Events);
|
|
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
|
|
assert.isFunction('callback', callback);
|
|
const subscriptionToken = this._subscriptionManager.subscribe<ArgsType>(
|
|
this.address,
|
|
eventName,
|
|
indexFilterValues,
|
|
ITransformERC20Contract.ABI(),
|
|
callback,
|
|
isVerbose,
|
|
blockPollingIntervalMs,
|
|
);
|
|
return subscriptionToken;
|
|
}
|
|
|
|
/**
|
|
* Cancel a subscription
|
|
* @param subscriptionToken Subscription token returned by `subscribe()`
|
|
*/
|
|
public unsubscribe(subscriptionToken: string): void {
|
|
this._subscriptionManager.unsubscribe(subscriptionToken);
|
|
}
|
|
|
|
/**
|
|
* Cancels all existing subscriptions
|
|
*/
|
|
public unsubscribeAll(): void {
|
|
this._subscriptionManager.unsubscribeAll();
|
|
}
|
|
|
|
/**
|
|
* Gets historical logs without creating a subscription
|
|
* @param eventName The ITransformERC20 contract event you would like to subscribe to.
|
|
* @param blockRange Block range to get logs from.
|
|
* @param indexFilterValues An object where the keys are indexed args returned by the event and
|
|
* the value is the value you are interested in. E.g `{_from: aUserAddressHex}`
|
|
* @return Array of logs that match the parameters
|
|
*/
|
|
public async getLogsAsync<ArgsType extends ITransformERC20EventArgs>(
|
|
eventName: ITransformERC20Events,
|
|
blockRange: BlockRange,
|
|
indexFilterValues: IndexedFilterValues,
|
|
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
|
|
assert.doesBelongToStringEnum('eventName', eventName, ITransformERC20Events);
|
|
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
|
|
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
|
|
const logs = await this._subscriptionManager.getLogsAsync<ArgsType>(
|
|
this.address,
|
|
eventName,
|
|
blockRange,
|
|
indexFilterValues,
|
|
ITransformERC20Contract.ABI(),
|
|
);
|
|
return logs;
|
|
}
|
|
|
|
constructor(
|
|
address: string,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults?: Partial<TxData>,
|
|
logDecodeDependencies?: { [contractName: string]: ContractAbi },
|
|
deployedBytecode: string | undefined = ITransformERC20Contract.deployedBytecode,
|
|
encoderOverrides?: Partial<EncoderOverrides>,
|
|
) {
|
|
super(
|
|
'ITransformERC20',
|
|
ITransformERC20Contract.ABI(),
|
|
address,
|
|
supportedProvider,
|
|
txDefaults,
|
|
logDecodeDependencies,
|
|
deployedBytecode,
|
|
encoderOverrides,
|
|
);
|
|
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
|
|
this._subscriptionManager = new SubscriptionManager<ITransformERC20EventArgs, ITransformERC20Events>(
|
|
ITransformERC20Contract.ABI(),
|
|
this._web3Wrapper,
|
|
);
|
|
ITransformERC20Contract.ABI().forEach((item, index) => {
|
|
if (item.type === 'function') {
|
|
const methodAbi = item as MethodAbi;
|
|
this._methodABIIndex[methodAbi.name] = index;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// 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
|