// 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, 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, SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, 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 StrategyAPIEventArgs = | StrategyAPIHarvestedEventArgs; export enum StrategyAPIEvents { Harvested = 'Harvested', } export interface StrategyAPIHarvestedEventArgs extends DecodedLogArgs { profit: BigNumber; loss: BigNumber; debtPayment: BigNumber; debtOutstanding: BigNumber; } /* istanbul ignore next */ // tslint:disable:array-type // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class StrategyAPIContract extends BaseContract { /** * @ignore */ public static deployedBytecode: string | undefined; public static contractName = 'StrategyAPI'; private readonly _methodABIIndex: { [name: string]: number } = {}; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, supportedProvider: SupportedProvider, txDefaults: Partial, logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, ): Promise { assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ schemas.addressSchema, schemas.numberSchema, schemas.jsNumber, ]); if (artifact.compilerOutput === undefined) { throw new Error('Compiler output not found in the artifact file'); } const provider = providerUtils.standardizeOrThrow(supportedProvider); const bytecode = artifact.compilerOutput.evm.bytecode.object; const abi = artifact.compilerOutput.abi; const logDecodeDependenciesAbiOnly: { [contractName: string]: ContractAbi } = {}; if (Object.keys(logDecodeDependencies) !== undefined) { for (const key of Object.keys(logDecodeDependencies)) { logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; } } return StrategyAPIContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); } public static async deployWithLibrariesFrom0xArtifactAsync( artifact: ContractArtifact, libraryArtifacts: { [libraryName: string]: ContractArtifact }, supportedProvider: SupportedProvider, txDefaults: Partial, logDecodeDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) }, ): Promise { assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ schemas.addressSchema, schemas.numberSchema, schemas.jsNumber, ]); if (artifact.compilerOutput === undefined) { throw new Error('Compiler output not found in the artifact file'); } const provider = providerUtils.standardizeOrThrow(supportedProvider); const 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 StrategyAPIContract._deployLibrariesAsync( artifact, libraryArtifacts, new Web3Wrapper(provider), txDefaults ); const bytecode = linkLibrariesInBytecode( artifact, libraryAddresses, ); return StrategyAPIContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, ); } public static async deployAsync( bytecode: string, abi: ContractAbi, supportedProvider: SupportedProvider, txDefaults: Partial, logDecodeDependencies: { [contractName: string]: ContractAbi }, ): Promise { assert.isHexString('bytecode', bytecode); assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ schemas.addressSchema, schemas.numberSchema, schemas.jsNumber, ]); const provider = providerUtils.standardizeOrThrow(supportedProvider); const constructorAbi = BaseContract._lookupConstructorAbi(abi); [] = BaseContract._formatABIDataItemList( constructorAbi.inputs, [], BaseContract._bigNumberToString, ); const iface = new ethers.utils.Interface(abi); const deployInfo = iface.deployFunction; const txData = deployInfo.encode(bytecode, []); const web3Wrapper = new Web3Wrapper(provider); const txDataWithDefaults = await BaseContract._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(`StrategyAPI successfully deployed at ${txReceipt.contractAddress}`); const contractInstance = new StrategyAPIContract(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: 'profit', type: 'uint256', indexed: false, }, { name: 'loss', type: 'uint256', indexed: false, }, { name: 'debtPayment', type: 'uint256', indexed: false, }, { name: 'debtOutstanding', type: 'uint256', indexed: false, }, ], name: 'Harvested', outputs: [ ], type: 'event', }, { inputs: [ ], name: 'apiVersion', outputs: [ { name: '', type: 'string', }, ], stateMutability: 'pure', type: 'function', }, { inputs: [ ], name: 'delegatedAssets', outputs: [ { name: '', type: 'uint256', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'harvest', outputs: [ ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { name: 'callCost', type: 'uint256', }, ], name: 'harvestTrigger', outputs: [ { name: '', type: 'bool', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'isActive', outputs: [ { name: '', type: 'bool', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'keeper', outputs: [ { name: '', type: 'address', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'name', outputs: [ { name: '', type: 'string', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'tend', outputs: [ ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { name: 'callCost', type: 'uint256', }, ], name: 'tendTrigger', outputs: [ { name: '', type: 'bool', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ ], name: 'vault', outputs: [ { name: '', type: 'address', }, ], stateMutability: 'view', type: 'function', }, ] as ContractAbi; return abi; } protected static async _deployLibrariesAsync( artifact: ContractArtifact, libraryArtifacts: { [libraryName: string]: ContractArtifact }, web3Wrapper: Web3Wrapper, txDefaults: Partial, 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 StrategyAPIContract._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 = StrategyAPIContract.ABI()[index] as MethodAbi; // tslint:disable-line:no-unnecessary-type-assertion const functionSignature = methodAbiToFunctionSignature(methodAbi); return functionSignature; } public getABIDecodedTransactionData(methodName: string, callData: string): T { const functionSignature = this.getFunctionSignature(methodName); const self = (this as any) as StrategyAPIContract; const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiDecodedCallData = abiEncoder.strictDecode(callData); return abiDecodedCallData; } public getABIDecodedReturnData(methodName: string, callData: string): T { const functionSignature = this.getFunctionSignature(methodName); const self = (this as any) as StrategyAPIContract; const abiEncoder = self._lookupAbiEncoder(functionSignature); const abiDecodedCallData = abiEncoder.strictDecodeReturnValue(callData); return abiDecodedCallData; } public getSelector(methodName: string): string { const functionSignature = this.getFunctionSignature(methodName); const self = (this as any) as StrategyAPIContract; const abiEncoder = self._lookupAbiEncoder(functionSignature); return abiEncoder.getSelector(); } public apiVersion( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'apiVersion()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; if (self._deployedBytecodeIfExists) { rawCallResult = await self._evmExecAsync(this.getABIEncodedTransactionData()); } else { rawCallResult = await self._performCallAsync({ data: this.getABIEncodedTransactionData(), ...callData }, defaultBlock); } const abiEncoder = self._lookupAbiEncoder(functionSignature); BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); return abiEncoder.strictDecodeReturnValue(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public delegatedAssets( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'delegatedAssets()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public harvest( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'harvest()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public harvestTrigger( callCost: BigNumber, ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; assert.isBigNumber('callCost', callCost); const functionSignature = 'harvestTrigger(uint256)'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, [callCost ]); }, } }; public isActive( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'isActive()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public keeper( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'keeper()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public name( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'name()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public tend( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'tend()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; public tendTrigger( callCost: BigNumber, ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; assert.isBigNumber('callCost', callCost); const functionSignature = 'tendTrigger(uint256)'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, [callCost ]); }, } }; public vault( ): ContractTxFunctionObj { const self = this as any as StrategyAPIContract; const functionSignature = 'vault()'; return { async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { 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, opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); }, async estimateGasAsync( txData?: Partial | undefined, ): Promise { const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( { data: this.getABIEncodedTransactionData(), ...txData } ); return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); }, async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, ): Promise { 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(rawCallResult); }, getABIEncodedTransactionData(): string { return self._strictEncodeArguments(functionSignature, []); }, } }; /** * Subscribe to an event type emitted by the StrategyAPI contract. * @param eventName The StrategyAPI 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( eventName: StrategyAPIEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, isVerbose: boolean = false, blockPollingIntervalMs?: number, ): string { assert.doesBelongToStringEnum('eventName', eventName, StrategyAPIEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const subscriptionToken = this._subscriptionManager.subscribe( this.address, eventName, indexFilterValues, StrategyAPIContract.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 StrategyAPI 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( eventName: StrategyAPIEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise>> { assert.doesBelongToStringEnum('eventName', eventName, StrategyAPIEvents); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const logs = await this._subscriptionManager.getLogsAsync( this.address, eventName, blockRange, indexFilterValues, StrategyAPIContract.ABI(), ); return logs; } constructor( address: string, supportedProvider: SupportedProvider, txDefaults?: Partial, logDecodeDependencies?: { [contractName: string]: ContractAbi }, deployedBytecode: string | undefined = StrategyAPIContract.deployedBytecode, ) { super('StrategyAPI', StrategyAPIContract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies, deployedBytecode); classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); this._subscriptionManager = new SubscriptionManager( StrategyAPIContract.ABI(), this._web3Wrapper, ); StrategyAPIContract.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