1637 lines
70 KiB
TypeScript
1637 lines
70 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 ForwarderEventArgs = ForwarderOwnershipTransferredEventArgs;
|
|
|
|
export enum ForwarderEvents {
|
|
OwnershipTransferred = 'OwnershipTransferred',
|
|
}
|
|
|
|
export interface ForwarderOwnershipTransferredEventArgs extends DecodedLogArgs {
|
|
previousOwner: string;
|
|
newOwner: string;
|
|
}
|
|
|
|
/* istanbul ignore next */
|
|
// tslint:disable:array-type
|
|
// tslint:disable:no-parameter-reassignment
|
|
// tslint:disable-next-line:class-name
|
|
export class ForwarderContract extends BaseContract {
|
|
/**
|
|
* @ignore
|
|
*/
|
|
public static deployedBytecode: string | undefined;
|
|
public static contractName = 'Forwarder';
|
|
private readonly _methodABIIndex: { [name: string]: number } = {};
|
|
private readonly _subscriptionManager: SubscriptionManager<ForwarderEventArgs, ForwarderEvents>;
|
|
public static async deployFrom0xArtifactAsync(
|
|
artifact: ContractArtifact | SimpleContractArtifact,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
|
_exchange: string,
|
|
_exchangeV2: string,
|
|
_weth: string,
|
|
): Promise<ForwarderContract> {
|
|
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 ForwarderContract.deployAsync(
|
|
bytecode,
|
|
abi,
|
|
provider,
|
|
txDefaults,
|
|
logDecodeDependenciesAbiOnly,
|
|
_exchange,
|
|
_exchangeV2,
|
|
_weth,
|
|
);
|
|
}
|
|
|
|
public static async deployWithLibrariesFrom0xArtifactAsync(
|
|
artifact: ContractArtifact,
|
|
libraryArtifacts: { [libraryName: string]: ContractArtifact },
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
|
_exchange: string,
|
|
_exchangeV2: string,
|
|
_weth: string,
|
|
): Promise<ForwarderContract> {
|
|
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 ForwarderContract._deployLibrariesAsync(
|
|
artifact,
|
|
libraryArtifacts,
|
|
new Web3Wrapper(provider),
|
|
txDefaults,
|
|
);
|
|
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
|
|
return ForwarderContract.deployAsync(
|
|
bytecode,
|
|
abi,
|
|
provider,
|
|
txDefaults,
|
|
logDecodeDependenciesAbiOnly,
|
|
_exchange,
|
|
_exchangeV2,
|
|
_weth,
|
|
);
|
|
}
|
|
|
|
public static async deployAsync(
|
|
bytecode: string,
|
|
abi: ContractAbi,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults: Partial<TxData>,
|
|
logDecodeDependencies: { [contractName: string]: ContractAbi },
|
|
_exchange: string,
|
|
_exchangeV2: string,
|
|
_weth: string,
|
|
): Promise<ForwarderContract> {
|
|
assert.isHexString('bytecode', bytecode);
|
|
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema);
|
|
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
|
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
|
|
[_exchange, _exchangeV2, _weth] = BaseContract._formatABIDataItemList(
|
|
constructorAbi.inputs,
|
|
[_exchange, _exchangeV2, _weth],
|
|
BaseContract._bigNumberToString,
|
|
);
|
|
const iface = new ethers.utils.Interface(abi);
|
|
const deployInfo = iface.deployFunction;
|
|
const txData = deployInfo.encode(bytecode, [_exchange, _exchangeV2, _weth]);
|
|
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(`Forwarder successfully deployed at ${txReceipt.contractAddress}`);
|
|
const contractInstance = new ForwarderContract(
|
|
txReceipt.contractAddress as string,
|
|
provider,
|
|
txDefaults,
|
|
logDecodeDependencies,
|
|
);
|
|
contractInstance.constructorArgs = [_exchange, _exchangeV2, _weth];
|
|
return contractInstance;
|
|
}
|
|
|
|
/**
|
|
* @returns The contract ABI
|
|
*/
|
|
public static ABI(): ContractAbi {
|
|
const abi = [
|
|
{
|
|
inputs: [
|
|
{
|
|
name: '_exchange',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: '_exchangeV2',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: '_weth',
|
|
type: 'address',
|
|
},
|
|
],
|
|
outputs: [],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
type: 'constructor',
|
|
},
|
|
{
|
|
anonymous: false,
|
|
inputs: [
|
|
{
|
|
name: 'previousOwner',
|
|
type: 'address',
|
|
indexed: true,
|
|
},
|
|
{
|
|
name: 'newOwner',
|
|
type: 'address',
|
|
indexed: true,
|
|
},
|
|
],
|
|
name: 'OwnershipTransferred',
|
|
outputs: [],
|
|
type: 'event',
|
|
},
|
|
{
|
|
inputs: [],
|
|
outputs: [],
|
|
payable: true,
|
|
stateMutability: 'payable',
|
|
type: 'fallback',
|
|
},
|
|
{
|
|
constant: true,
|
|
inputs: [],
|
|
name: 'ERC1155_BATCH_RECEIVED',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'bytes4',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: true,
|
|
inputs: [],
|
|
name: 'ERC1155_RECEIVED',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'bytes4',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: true,
|
|
inputs: [],
|
|
name: 'EXCHANGE_V2_ORDER_ID',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'bytes4',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'assetData',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
name: 'approveMakerAssetProxy',
|
|
outputs: [],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'orders',
|
|
type: 'tuple[]',
|
|
components: [
|
|
{
|
|
name: 'makerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'takerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'feeRecipientAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'senderAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'makerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'expirationTimeSeconds',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'salt',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'makerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'makerAssetBuyAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'signatures',
|
|
type: 'bytes[]',
|
|
},
|
|
{
|
|
name: 'ethFeeAmounts',
|
|
type: 'uint256[]',
|
|
},
|
|
{
|
|
name: 'feeRecipients',
|
|
type: 'address[]',
|
|
},
|
|
],
|
|
name: 'marketBuyOrdersWithEth',
|
|
outputs: [
|
|
{
|
|
name: 'wethSpentAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetAcquiredAmount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
payable: true,
|
|
stateMutability: 'payable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'orders',
|
|
type: 'tuple[]',
|
|
components: [
|
|
{
|
|
name: 'makerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'takerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'feeRecipientAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'senderAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'makerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'expirationTimeSeconds',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'salt',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'makerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'ethSellAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'signatures',
|
|
type: 'bytes[]',
|
|
},
|
|
{
|
|
name: 'ethFeeAmounts',
|
|
type: 'uint256[]',
|
|
},
|
|
{
|
|
name: 'feeRecipients',
|
|
type: 'address[]',
|
|
},
|
|
],
|
|
name: 'marketSellAmountWithEth',
|
|
outputs: [
|
|
{
|
|
name: 'wethSpentAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetAcquiredAmount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
payable: true,
|
|
stateMutability: 'payable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'orders',
|
|
type: 'tuple[]',
|
|
components: [
|
|
{
|
|
name: 'makerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'takerAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'feeRecipientAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'senderAddress',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'makerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerAssetAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'takerFee',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'expirationTimeSeconds',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'salt',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'makerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'takerFeeAssetData',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'signatures',
|
|
type: 'bytes[]',
|
|
},
|
|
{
|
|
name: 'ethFeeAmounts',
|
|
type: 'uint256[]',
|
|
},
|
|
{
|
|
name: 'feeRecipients',
|
|
type: 'address[]',
|
|
},
|
|
],
|
|
name: 'marketSellOrdersWithEth',
|
|
outputs: [
|
|
{
|
|
name: 'wethSpentAmount',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'makerAssetAcquiredAmount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
payable: true,
|
|
stateMutability: 'payable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'operator',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'from',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'ids',
|
|
type: 'uint256[]',
|
|
},
|
|
{
|
|
name: 'values',
|
|
type: 'uint256[]',
|
|
},
|
|
{
|
|
name: 'data',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
name: 'onERC1155BatchReceived',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'bytes4',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'operator',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'from',
|
|
type: 'address',
|
|
},
|
|
{
|
|
name: 'id',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'value',
|
|
type: 'uint256',
|
|
},
|
|
{
|
|
name: 'data',
|
|
type: 'bytes',
|
|
},
|
|
],
|
|
name: 'onERC1155Received',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'bytes4',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: true,
|
|
inputs: [],
|
|
name: 'owner',
|
|
outputs: [
|
|
{
|
|
name: '',
|
|
type: 'address',
|
|
},
|
|
],
|
|
payable: false,
|
|
stateMutability: 'view',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'newOwner',
|
|
type: 'address',
|
|
},
|
|
],
|
|
name: 'transferOwnership',
|
|
outputs: [],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
type: 'function',
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: 'assetData',
|
|
type: 'bytes',
|
|
},
|
|
{
|
|
name: 'amount',
|
|
type: 'uint256',
|
|
},
|
|
],
|
|
name: 'withdrawAsset',
|
|
outputs: [],
|
|
payable: false,
|
|
stateMutability: 'nonpayable',
|
|
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 ForwarderContract._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 = ForwarderContract.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 ForwarderContract;
|
|
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 ForwarderContract;
|
|
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 ForwarderContract;
|
|
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
|
return abiEncoder.getSelector();
|
|
}
|
|
|
|
public ERC1155_BATCH_RECEIVED(): ContractFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
const functionSignature = 'ERC1155_BATCH_RECEIVED()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
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, []);
|
|
},
|
|
};
|
|
}
|
|
public ERC1155_RECEIVED(): ContractFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
const functionSignature = 'ERC1155_RECEIVED()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
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, []);
|
|
},
|
|
};
|
|
}
|
|
public EXCHANGE_V2_ORDER_ID(): ContractFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
const functionSignature = 'EXCHANGE_V2_ORDER_ID()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
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, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Approves the respective proxy for a given asset to transfer tokens on the Forwarder contract's behalf.
|
|
* This is necessary because an order fee denominated in the maker asset (i.e. a percentage fee) is sent by the
|
|
* Forwarder contract to the fee recipient.
|
|
* This method needs to be called before forwarding orders of a maker asset that hasn't
|
|
* previously been approved.
|
|
* @param assetData Byte array encoded for the respective asset proxy.
|
|
*/
|
|
public approveMakerAssetProxy(assetData: string): ContractTxFunctionObj<void> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isString('assetData', assetData);
|
|
const functionSignature = 'approveMakerAssetProxy(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<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, [assetData]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Attempt to buy makerAssetBuyAmount of makerAsset by selling ETH provided with transaction.
|
|
* The Forwarder may *fill* more than makerAssetBuyAmount of the makerAsset so that it can
|
|
* pay takerFees where takerFeeAssetData == makerAssetData (i.e. percentage fees).
|
|
* Any ETH not spent will be refunded to sender.
|
|
* @param orders Array of order specifications used containing desired
|
|
* makerAsset and WETH as takerAsset.
|
|
* @param makerAssetBuyAmount Desired amount of makerAsset to purchase.
|
|
* @param signatures Proofs that orders have been created by makers.
|
|
* @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to
|
|
* corresponding feeRecipients.
|
|
* @param feeRecipients Addresses that will receive ETH when orders are filled.
|
|
* @returns wethSpentAmount Amount of WETH spent on the given set of orders.makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
|
|
*/
|
|
public marketBuyOrdersWithEth(
|
|
orders: Array<{
|
|
makerAddress: string;
|
|
takerAddress: string;
|
|
feeRecipientAddress: string;
|
|
senderAddress: string;
|
|
makerAssetAmount: BigNumber;
|
|
takerAssetAmount: BigNumber;
|
|
makerFee: BigNumber;
|
|
takerFee: BigNumber;
|
|
expirationTimeSeconds: BigNumber;
|
|
salt: BigNumber;
|
|
makerAssetData: string;
|
|
takerAssetData: string;
|
|
makerFeeAssetData: string;
|
|
takerFeeAssetData: string;
|
|
}>,
|
|
makerAssetBuyAmount: BigNumber,
|
|
signatures: string[],
|
|
ethFeeAmounts: BigNumber[],
|
|
feeRecipients: string[],
|
|
): ContractTxFunctionObj<[BigNumber, BigNumber]> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isArray('orders', orders);
|
|
assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount);
|
|
assert.isArray('signatures', signatures);
|
|
assert.isArray('ethFeeAmounts', ethFeeAmounts);
|
|
assert.isArray('feeRecipients', feeRecipients);
|
|
const functionSignature =
|
|
'marketBuyOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256[],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, 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, BigNumber]>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [
|
|
orders,
|
|
makerAssetBuyAmount,
|
|
signatures,
|
|
ethFeeAmounts,
|
|
feeRecipients,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Purchases as much of orders' makerAssets as possible by selling the specified amount of ETH
|
|
* accounting for order and forwarder fees. This functions throws if ethSellAmount was not reached.
|
|
* @param orders Array of order specifications used containing desired
|
|
* makerAsset and WETH as takerAsset.
|
|
* @param ethSellAmount Desired amount of ETH to sell.
|
|
* @param signatures Proofs that orders have been created by makers.
|
|
* @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to
|
|
* corresponding feeRecipients.
|
|
* @param feeRecipients Addresses that will receive ETH when orders are filled.
|
|
* @returns wethSpentAmount Amount of WETH spent on the given set of orders.makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
|
|
*/
|
|
public marketSellAmountWithEth(
|
|
orders: Array<{
|
|
makerAddress: string;
|
|
takerAddress: string;
|
|
feeRecipientAddress: string;
|
|
senderAddress: string;
|
|
makerAssetAmount: BigNumber;
|
|
takerAssetAmount: BigNumber;
|
|
makerFee: BigNumber;
|
|
takerFee: BigNumber;
|
|
expirationTimeSeconds: BigNumber;
|
|
salt: BigNumber;
|
|
makerAssetData: string;
|
|
takerAssetData: string;
|
|
makerFeeAssetData: string;
|
|
takerFeeAssetData: string;
|
|
}>,
|
|
ethSellAmount: BigNumber,
|
|
signatures: string[],
|
|
ethFeeAmounts: BigNumber[],
|
|
feeRecipients: string[],
|
|
): ContractTxFunctionObj<[BigNumber, BigNumber]> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isArray('orders', orders);
|
|
assert.isBigNumber('ethSellAmount', ethSellAmount);
|
|
assert.isArray('signatures', signatures);
|
|
assert.isArray('ethFeeAmounts', ethFeeAmounts);
|
|
assert.isArray('feeRecipients', feeRecipients);
|
|
const functionSignature =
|
|
'marketSellAmountWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256[],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, 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, BigNumber]>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [
|
|
orders,
|
|
ethSellAmount,
|
|
signatures,
|
|
ethFeeAmounts,
|
|
feeRecipients,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Purchases as much of orders' makerAssets as possible by selling as much of the ETH value sent
|
|
* as possible, accounting for order and forwarder fees.
|
|
* @param orders Array of order specifications used containing desired
|
|
* makerAsset and WETH as takerAsset.
|
|
* @param signatures Proofs that orders have been created by makers.
|
|
* @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to
|
|
* corresponding feeRecipients.
|
|
* @param feeRecipients Addresses that will receive ETH when orders are filled.
|
|
* @returns wethSpentAmount Amount of WETH spent on the given set of orders.makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
|
|
*/
|
|
public marketSellOrdersWithEth(
|
|
orders: Array<{
|
|
makerAddress: string;
|
|
takerAddress: string;
|
|
feeRecipientAddress: string;
|
|
senderAddress: string;
|
|
makerAssetAmount: BigNumber;
|
|
takerAssetAmount: BigNumber;
|
|
makerFee: BigNumber;
|
|
takerFee: BigNumber;
|
|
expirationTimeSeconds: BigNumber;
|
|
salt: BigNumber;
|
|
makerAssetData: string;
|
|
takerAssetData: string;
|
|
makerFeeAssetData: string;
|
|
takerFeeAssetData: string;
|
|
}>,
|
|
signatures: string[],
|
|
ethFeeAmounts: BigNumber[],
|
|
feeRecipients: string[],
|
|
): ContractTxFunctionObj<[BigNumber, BigNumber]> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isArray('orders', orders);
|
|
assert.isArray('signatures', signatures);
|
|
assert.isArray('ethFeeAmounts', ethFeeAmounts);
|
|
assert.isArray('feeRecipients', feeRecipients);
|
|
const functionSignature =
|
|
'marketSellOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],uint256[],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, 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, BigNumber]>(rawCallResult);
|
|
},
|
|
getABIEncodedTransactionData(): string {
|
|
return self._strictEncodeArguments(functionSignature, [
|
|
orders,
|
|
signatures,
|
|
ethFeeAmounts,
|
|
feeRecipients,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* The smart contract calls this function on the recipient after a `safeTransferFrom`. This function MAY throw to revert and reject the transfer. Return of other than the magic value MUST result in the transaction being reverted Note: the contract address is always the message sender
|
|
* @param operator The address which called `safeTransferFrom` function
|
|
* @param from The address which previously owned the token
|
|
* @param ids An array containing ids of each token being transferred
|
|
* @param values An array containing amounts of each token being transferred
|
|
* @param data Additional data with no specified format
|
|
* @returns `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
|
|
*/
|
|
public onERC1155BatchReceived(
|
|
operator: string,
|
|
from: string,
|
|
ids: BigNumber[],
|
|
values: BigNumber[],
|
|
data: string,
|
|
): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isString('operator', operator);
|
|
assert.isString('from', from);
|
|
assert.isArray('ids', ids);
|
|
assert.isArray('values', values);
|
|
assert.isString('data', data);
|
|
const functionSignature = 'onERC1155BatchReceived(address,address,uint256[],uint256[],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<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, [
|
|
operator.toLowerCase(),
|
|
from.toLowerCase(),
|
|
ids,
|
|
values,
|
|
data,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* The smart contract calls this function on the recipient after a `safeTransferFrom`. This function MAY throw to revert and reject the transfer. Return of other than the magic value MUST result in the transaction being reverted Note: the contract address is always the message sender
|
|
* @param operator The address which called `safeTransferFrom` function
|
|
* @param from The address which previously owned the token
|
|
* @param id An array containing the ids of the token being transferred
|
|
* @param value An array containing the amount of tokens being transferred
|
|
* @param data Additional data with no specified format
|
|
* @returns `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
|
|
*/
|
|
public onERC1155Received(
|
|
operator: string,
|
|
from: string,
|
|
id: BigNumber,
|
|
value: BigNumber,
|
|
data: string,
|
|
): ContractTxFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isString('operator', operator);
|
|
assert.isString('from', from);
|
|
assert.isBigNumber('id', id);
|
|
assert.isBigNumber('value', value);
|
|
assert.isString('data', data);
|
|
const functionSignature = 'onERC1155Received(address,address,uint256,uint256,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<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, [
|
|
operator.toLowerCase(),
|
|
from.toLowerCase(),
|
|
id,
|
|
value,
|
|
data,
|
|
]);
|
|
},
|
|
};
|
|
}
|
|
public owner(): ContractFunctionObj<string> {
|
|
const self = (this as any) as ForwarderContract;
|
|
const functionSignature = 'owner()';
|
|
|
|
return {
|
|
selector: self._lookupAbiEncoder(functionSignature).getSelector(),
|
|
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, []);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Change the owner of this contract.
|
|
* @param newOwner New owner address.
|
|
*/
|
|
public transferOwnership(newOwner: string): ContractTxFunctionObj<void> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isString('newOwner', newOwner);
|
|
const functionSignature = 'transferOwnership(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, [newOwner.toLowerCase()]);
|
|
},
|
|
};
|
|
}
|
|
/**
|
|
* Withdraws assets from this contract. It may be used by the owner to withdraw assets
|
|
* that were accidentally sent to this contract.
|
|
* @param assetData Byte array encoded for the respective asset proxy.
|
|
* @param amount Amount of the asset to withdraw.
|
|
*/
|
|
public withdrawAsset(assetData: string, amount: BigNumber): ContractTxFunctionObj<void> {
|
|
const self = (this as any) as ForwarderContract;
|
|
assert.isString('assetData', assetData);
|
|
assert.isBigNumber('amount', amount);
|
|
const functionSignature = 'withdrawAsset(bytes,uint256)';
|
|
|
|
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, [assetData, amount]);
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Subscribe to an event type emitted by the Forwarder contract.
|
|
* @param eventName The Forwarder 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 ForwarderEventArgs>(
|
|
eventName: ForwarderEvents,
|
|
indexFilterValues: IndexedFilterValues,
|
|
callback: EventCallback<ArgsType>,
|
|
isVerbose: boolean = false,
|
|
blockPollingIntervalMs?: number,
|
|
): string {
|
|
assert.doesBelongToStringEnum('eventName', eventName, ForwarderEvents);
|
|
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
|
|
assert.isFunction('callback', callback);
|
|
const subscriptionToken = this._subscriptionManager.subscribe<ArgsType>(
|
|
this.address,
|
|
eventName,
|
|
indexFilterValues,
|
|
ForwarderContract.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 Forwarder 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 ForwarderEventArgs>(
|
|
eventName: ForwarderEvents,
|
|
blockRange: BlockRange,
|
|
indexFilterValues: IndexedFilterValues,
|
|
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
|
|
assert.doesBelongToStringEnum('eventName', eventName, ForwarderEvents);
|
|
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
|
|
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
|
|
const logs = await this._subscriptionManager.getLogsAsync<ArgsType>(
|
|
this.address,
|
|
eventName,
|
|
blockRange,
|
|
indexFilterValues,
|
|
ForwarderContract.ABI(),
|
|
);
|
|
return logs;
|
|
}
|
|
|
|
constructor(
|
|
address: string,
|
|
supportedProvider: SupportedProvider,
|
|
txDefaults?: Partial<TxData>,
|
|
logDecodeDependencies?: { [contractName: string]: ContractAbi },
|
|
deployedBytecode: string | undefined = ForwarderContract.deployedBytecode,
|
|
encoderOverrides?: Partial<EncoderOverrides>,
|
|
) {
|
|
super(
|
|
'Forwarder',
|
|
ForwarderContract.ABI(),
|
|
address,
|
|
supportedProvider,
|
|
txDefaults,
|
|
logDecodeDependencies,
|
|
deployedBytecode,
|
|
encoderOverrides,
|
|
);
|
|
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
|
|
this._subscriptionManager = new SubscriptionManager<ForwarderEventArgs, ForwarderEvents>(
|
|
ForwarderContract.ABI(),
|
|
this._web3Wrapper,
|
|
);
|
|
ForwarderContract.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
|