Completed feedback
This commit is contained in:
parent
d8498134ad
commit
659e8991de
@ -10,10 +10,12 @@ import { Order } from '@0x/types';
|
||||
import { BigNumber, hexUtils } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { DummyLiquidityProviderContract, DummyLiquidityProviderRegistryContract } from '../src';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { TestERC20BridgeSamplerContract } from './wrappers';
|
||||
import {
|
||||
DummyLiquidityProviderContract,
|
||||
DummyLiquidityProviderRegistryContract,
|
||||
TestERC20BridgeSamplerContract,
|
||||
} from './wrappers';
|
||||
|
||||
blockchainTests('erc20-bridge-sampler', env => {
|
||||
let testContract: TestERC20BridgeSamplerContract;
|
||||
@ -718,7 +720,7 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('getLiquidityProviderFromRegistry', () => {
|
||||
describe('getLiquidityProviderFromRegistry', () => {
|
||||
const xAsset = randomAddress();
|
||||
const yAsset = randomAddress();
|
||||
const sampleAmounts = getSampleAmounts(yAsset);
|
||||
@ -726,9 +728,6 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
let registryContract: DummyLiquidityProviderRegistryContract;
|
||||
|
||||
before(async () => {
|
||||
await testContract.createTokenExchanges([MAKER_TOKEN, TAKER_TOKEN]).awaitTransactionSuccessAsync()
|
||||
.txHashPromise;
|
||||
|
||||
liquidityProvider = await DummyLiquidityProviderContract.deployFrom0xArtifactAsync(
|
||||
artifacts.DummyLiquidityProvider,
|
||||
env.provider,
|
||||
@ -744,7 +743,7 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
);
|
||||
await registryContract
|
||||
.setLiquidityProviderForMarket(xAsset, yAsset, liquidityProvider.address)
|
||||
.awaitTransactionSuccessAsync().txHashPromise;
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('should be able to get the liquidity provider', async () => {
|
||||
|
@ -31,7 +31,7 @@
|
||||
"wrappers:generate": "abi-gen --abis ${npm_package_config_abis} --output src/generated-wrappers --backend ethers"
|
||||
},
|
||||
"config": {
|
||||
"abis": "../contract-artifacts/artifacts/@(DevUtils|ERC20Token|ERC721Token|Exchange|Forwarder|IAssetData|LibTransactionDecoder|WETH9|Coordinator|Staking|StakingProxy|IERC20BridgeSampler|ERC20BridgeSampler|GodsUnchainedValidator|Broker|ILiquidityProvider|ILiquidityProviderRegistry|DummyLiquidityProvider|DummyLiquidityProviderRegistry|MaximumGasPrice).json"
|
||||
"abis": "../contract-artifacts/artifacts/@(DevUtils|ERC20Token|ERC721Token|Exchange|Forwarder|IAssetData|LibTransactionDecoder|WETH9|Coordinator|Staking|StakingProxy|IERC20BridgeSampler|ERC20BridgeSampler|GodsUnchainedValidator|Broker|ILiquidityProvider|ILiquidityProviderRegistry|MaximumGasPrice).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -1,392 +0,0 @@
|
||||
// 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,
|
||||
PromiseWithTransactionHash,
|
||||
methodAbiToFunctionSignature,
|
||||
linkLibrariesInBytecode,
|
||||
} from '@0x/base-contract';
|
||||
import { schemas } from '@0x/json-schemas';
|
||||
import {
|
||||
BlockParam,
|
||||
BlockParamLiteral,
|
||||
BlockRange,
|
||||
CallData,
|
||||
ContractAbi,
|
||||
ContractArtifact,
|
||||
DecodedLogArgs,
|
||||
MethodAbi,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
TxData,
|
||||
TxDataPayable,
|
||||
SupportedProvider,
|
||||
} from 'ethereum-types';
|
||||
import { BigNumber, classUtils, 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
|
||||
|
||||
/* istanbul ignore next */
|
||||
// tslint:disable:array-type
|
||||
// tslint:disable:no-parameter-reassignment
|
||||
// tslint:disable-next-line:class-name
|
||||
export class DummyLiquidityProviderContract extends BaseContract {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'DummyLiquidityProvider';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
artifact: ContractArtifact | SimpleContractArtifact,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
||||
): Promise<DummyLiquidityProviderContract> {
|
||||
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 DummyLiquidityProviderContract.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<DummyLiquidityProviderContract> {
|
||||
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 DummyLiquidityProviderContract._deployLibrariesAsync(
|
||||
artifact,
|
||||
libraryArtifacts,
|
||||
new Web3Wrapper(provider),
|
||||
txDefaults,
|
||||
);
|
||||
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
|
||||
return DummyLiquidityProviderContract.deployAsync(
|
||||
bytecode,
|
||||
abi,
|
||||
provider,
|
||||
txDefaults,
|
||||
logDecodeDependenciesAbiOnly,
|
||||
);
|
||||
}
|
||||
|
||||
public static async deployAsync(
|
||||
bytecode: string,
|
||||
abi: ContractAbi,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
logDecodeDependencies: { [contractName: string]: ContractAbi },
|
||||
): Promise<DummyLiquidityProviderContract> {
|
||||
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(`DummyLiquidityProvider successfully deployed at ${txReceipt.contractAddress}`);
|
||||
const contractInstance = new DummyLiquidityProviderContract(
|
||||
txReceipt.contractAddress as string,
|
||||
provider,
|
||||
txDefaults,
|
||||
logDecodeDependencies,
|
||||
);
|
||||
contractInstance.constructorArgs = [];
|
||||
return contractInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The contract ABI
|
||||
*/
|
||||
public static ABI(): ContractAbi {
|
||||
const abi = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [
|
||||
{
|
||||
name: 'index_0',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'index_1',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'buyAmount',
|
||||
type: 'uint256',
|
||||
},
|
||||
],
|
||||
name: 'getBuyQuote',
|
||||
outputs: [
|
||||
{
|
||||
name: 'takerTokenAmount',
|
||||
type: 'uint256',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: 'view',
|
||||
type: 'function',
|
||||
},
|
||||
{
|
||||
constant: true,
|
||||
inputs: [
|
||||
{
|
||||
name: 'index_0',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'index_1',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'sellAmount',
|
||||
type: 'uint256',
|
||||
},
|
||||
],
|
||||
name: 'getSellQuote',
|
||||
outputs: [
|
||||
{
|
||||
name: 'makerTokenAmount',
|
||||
type: 'uint256',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: 'view',
|
||||
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 DummyLiquidityProviderContract._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 = DummyLiquidityProviderContract.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 DummyLiquidityProviderContract;
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<T>(callData);
|
||||
return abiDecodedCallData;
|
||||
}
|
||||
|
||||
public getABIDecodedReturnData<T>(methodName: string, callData: string): T {
|
||||
const functionSignature = this.getFunctionSignature(methodName);
|
||||
const self = (this as any) as DummyLiquidityProviderContract;
|
||||
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 DummyLiquidityProviderContract;
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
return abiEncoder.getSelector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quotes the amount of `takerToken` that would need to be sold in
|
||||
* order to obtain `buyAmount` of `makerToken`.
|
||||
* @param buyAmount Amount of `makerToken` to buy.
|
||||
* @returns takerTokenAmount Amount of `takerToken` that would need to be sold.
|
||||
*/
|
||||
public getBuyQuote(index_0: string, index_1: string, buyAmount: BigNumber): ContractFunctionObj<BigNumber> {
|
||||
const self = (this as any) as DummyLiquidityProviderContract;
|
||||
assert.isString('index_0', index_0);
|
||||
assert.isString('index_1', index_1);
|
||||
assert.isBigNumber('buyAmount', buyAmount);
|
||||
const functionSignature = 'getBuyQuote(address,address,uint256)';
|
||||
|
||||
return {
|
||||
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
|
||||
BaseContract._assertCallParams(callData, defaultBlock);
|
||||
const rawCallResult = await self._performCallAsync(
|
||||
{ ...callData, data: this.getABIEncodedTransactionData() },
|
||||
defaultBlock,
|
||||
);
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
||||
return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
|
||||
},
|
||||
getABIEncodedTransactionData(): string {
|
||||
return self._strictEncodeArguments(functionSignature, [
|
||||
index_0.toLowerCase(),
|
||||
index_1.toLowerCase(),
|
||||
buyAmount,
|
||||
]);
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Quotes the amount of `makerToken` that would be obtained by
|
||||
* selling `sellAmount` of `takerToken`.
|
||||
* @param sellAmount Amount of `takerToken` to sell.
|
||||
* @returns makerTokenAmount Amount of `makerToken` that would be obtained.
|
||||
*/
|
||||
public getSellQuote(index_0: string, index_1: string, sellAmount: BigNumber): ContractFunctionObj<BigNumber> {
|
||||
const self = (this as any) as DummyLiquidityProviderContract;
|
||||
assert.isString('index_0', index_0);
|
||||
assert.isString('index_1', index_1);
|
||||
assert.isBigNumber('sellAmount', sellAmount);
|
||||
const functionSignature = 'getSellQuote(address,address,uint256)';
|
||||
|
||||
return {
|
||||
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
|
||||
BaseContract._assertCallParams(callData, defaultBlock);
|
||||
const rawCallResult = await self._performCallAsync(
|
||||
{ ...callData, data: this.getABIEncodedTransactionData() },
|
||||
defaultBlock,
|
||||
);
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
||||
return abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
|
||||
},
|
||||
getABIEncodedTransactionData(): string {
|
||||
return self._strictEncodeArguments(functionSignature, [
|
||||
index_0.toLowerCase(),
|
||||
index_1.toLowerCase(),
|
||||
sellAmount,
|
||||
]);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
constructor(
|
||||
address: string,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults?: Partial<TxData>,
|
||||
logDecodeDependencies?: { [contractName: string]: ContractAbi },
|
||||
deployedBytecode: string | undefined = DummyLiquidityProviderContract.deployedBytecode,
|
||||
) {
|
||||
super(
|
||||
'DummyLiquidityProvider',
|
||||
DummyLiquidityProviderContract.ABI(),
|
||||
address,
|
||||
supportedProvider,
|
||||
txDefaults,
|
||||
logDecodeDependencies,
|
||||
deployedBytecode,
|
||||
);
|
||||
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
|
||||
DummyLiquidityProviderContract.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
|
@ -1,408 +0,0 @@
|
||||
// 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,
|
||||
PromiseWithTransactionHash,
|
||||
methodAbiToFunctionSignature,
|
||||
linkLibrariesInBytecode,
|
||||
} from '@0x/base-contract';
|
||||
import { schemas } from '@0x/json-schemas';
|
||||
import {
|
||||
BlockParam,
|
||||
BlockParamLiteral,
|
||||
BlockRange,
|
||||
CallData,
|
||||
ContractAbi,
|
||||
ContractArtifact,
|
||||
DecodedLogArgs,
|
||||
MethodAbi,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
TxData,
|
||||
TxDataPayable,
|
||||
SupportedProvider,
|
||||
} from 'ethereum-types';
|
||||
import { BigNumber, classUtils, 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
|
||||
|
||||
/* istanbul ignore next */
|
||||
// tslint:disable:array-type
|
||||
// tslint:disable:no-parameter-reassignment
|
||||
// tslint:disable-next-line:class-name
|
||||
export class DummyLiquidityProviderRegistryContract extends BaseContract {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
public static deployedBytecode: string | undefined;
|
||||
public static contractName = 'DummyLiquidityProviderRegistry';
|
||||
private readonly _methodABIIndex: { [name: string]: number } = {};
|
||||
public static async deployFrom0xArtifactAsync(
|
||||
artifact: ContractArtifact | SimpleContractArtifact,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact },
|
||||
): Promise<DummyLiquidityProviderRegistryContract> {
|
||||
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 DummyLiquidityProviderRegistryContract.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<DummyLiquidityProviderRegistryContract> {
|
||||
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 DummyLiquidityProviderRegistryContract._deployLibrariesAsync(
|
||||
artifact,
|
||||
libraryArtifacts,
|
||||
new Web3Wrapper(provider),
|
||||
txDefaults,
|
||||
);
|
||||
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
|
||||
return DummyLiquidityProviderRegistryContract.deployAsync(
|
||||
bytecode,
|
||||
abi,
|
||||
provider,
|
||||
txDefaults,
|
||||
logDecodeDependenciesAbiOnly,
|
||||
);
|
||||
}
|
||||
|
||||
public static async deployAsync(
|
||||
bytecode: string,
|
||||
abi: ContractAbi,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
logDecodeDependencies: { [contractName: string]: ContractAbi },
|
||||
): Promise<DummyLiquidityProviderRegistryContract> {
|
||||
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(`DummyLiquidityProviderRegistry successfully deployed at ${txReceipt.contractAddress}`);
|
||||
const contractInstance = new DummyLiquidityProviderRegistryContract(
|
||||
txReceipt.contractAddress as string,
|
||||
provider,
|
||||
txDefaults,
|
||||
logDecodeDependencies,
|
||||
);
|
||||
contractInstance.constructorArgs = [];
|
||||
return contractInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The contract ABI
|
||||
*/
|
||||
public static ABI(): ContractAbi {
|
||||
const abi = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [
|
||||
{
|
||||
name: 'xToken',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'yToken',
|
||||
type: 'address',
|
||||
},
|
||||
],
|
||||
name: 'getLiquidityProviderForMarket',
|
||||
outputs: [
|
||||
{
|
||||
name: 'poolAddress',
|
||||
type: 'address',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: 'view',
|
||||
type: 'function',
|
||||
},
|
||||
{
|
||||
constant: false,
|
||||
inputs: [
|
||||
{
|
||||
name: 'xToken',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'yToken',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
name: 'poolAddress',
|
||||
type: 'address',
|
||||
},
|
||||
],
|
||||
name: 'setLiquidityProviderForMarket',
|
||||
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 DummyLiquidityProviderRegistryContract._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 = DummyLiquidityProviderRegistryContract.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 DummyLiquidityProviderRegistryContract;
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
const abiDecodedCallData = abiEncoder.strictDecode<T>(callData);
|
||||
return abiDecodedCallData;
|
||||
}
|
||||
|
||||
public getABIDecodedReturnData<T>(methodName: string, callData: string): T {
|
||||
const functionSignature = this.getFunctionSignature(methodName);
|
||||
const self = (this as any) as DummyLiquidityProviderRegistryContract;
|
||||
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 DummyLiquidityProviderRegistryContract;
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
return abiEncoder.getSelector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the address of pool for a market given market (xAsset, yAsset), or reverts if pool does not exist.
|
||||
* @param xToken First asset managed by pool.
|
||||
* @param yToken Second asset managed by pool.
|
||||
* @returns Address of pool.
|
||||
*/
|
||||
public getLiquidityProviderForMarket(xToken: string, yToken: string): ContractFunctionObj<string> {
|
||||
const self = (this as any) as DummyLiquidityProviderRegistryContract;
|
||||
assert.isString('xToken', xToken);
|
||||
assert.isString('yToken', yToken);
|
||||
const functionSignature = 'getLiquidityProviderForMarket(address,address)';
|
||||
|
||||
return {
|
||||
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<string> {
|
||||
BaseContract._assertCallParams(callData, defaultBlock);
|
||||
const rawCallResult = await self._performCallAsync(
|
||||
{ ...callData, data: this.getABIEncodedTransactionData() },
|
||||
defaultBlock,
|
||||
);
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
||||
return abiEncoder.strictDecodeReturnValue<string>(rawCallResult);
|
||||
},
|
||||
getABIEncodedTransactionData(): string {
|
||||
return self._strictEncodeArguments(functionSignature, [xToken.toLowerCase(), yToken.toLowerCase()]);
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Sets address of pool for a market given market (xAsset, yAsset).
|
||||
* @param xToken First asset managed by pool.
|
||||
* @param yToken Second asset managed by pool.
|
||||
* @param poolAddress Address of pool.
|
||||
*/
|
||||
public setLiquidityProviderForMarket(
|
||||
xToken: string,
|
||||
yToken: string,
|
||||
poolAddress: string,
|
||||
): ContractTxFunctionObj<void> {
|
||||
const self = (this as any) as DummyLiquidityProviderRegistryContract;
|
||||
assert.isString('xToken', xToken);
|
||||
assert.isString('yToken', yToken);
|
||||
assert.isString('poolAddress', poolAddress);
|
||||
const functionSignature = 'setLiquidityProviderForMarket(address,address,address)';
|
||||
|
||||
return {
|
||||
async sendTransactionAsync(
|
||||
txData?: Partial<TxData> | undefined,
|
||||
opts: SendTransactionOpts = { shouldValidate: true },
|
||||
): Promise<string> {
|
||||
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
|
||||
{ ...txData, data: this.getABIEncodedTransactionData() },
|
||||
this.estimateGasAsync.bind(this),
|
||||
);
|
||||
if (opts.shouldValidate !== false) {
|
||||
await this.callAsync(txDataWithDefaults);
|
||||
}
|
||||
return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
||||
},
|
||||
awaitTransactionSuccessAsync(
|
||||
txData?: Partial<TxData>,
|
||||
opts: AwaitTransactionSuccessOpts = { shouldValidate: true },
|
||||
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
|
||||
return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts);
|
||||
},
|
||||
async estimateGasAsync(txData?: Partial<TxData> | undefined): Promise<number> {
|
||||
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({
|
||||
...txData,
|
||||
data: this.getABIEncodedTransactionData(),
|
||||
});
|
||||
return self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
||||
},
|
||||
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
|
||||
BaseContract._assertCallParams(callData, defaultBlock);
|
||||
const rawCallResult = await self._performCallAsync(
|
||||
{ ...callData, data: this.getABIEncodedTransactionData() },
|
||||
defaultBlock,
|
||||
);
|
||||
const abiEncoder = self._lookupAbiEncoder(functionSignature);
|
||||
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
|
||||
return abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
|
||||
},
|
||||
getABIEncodedTransactionData(): string {
|
||||
return self._strictEncodeArguments(functionSignature, [
|
||||
xToken.toLowerCase(),
|
||||
yToken.toLowerCase(),
|
||||
poolAddress.toLowerCase(),
|
||||
]);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
constructor(
|
||||
address: string,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults?: Partial<TxData>,
|
||||
logDecodeDependencies?: { [contractName: string]: ContractAbi },
|
||||
deployedBytecode: string | undefined = DummyLiquidityProviderRegistryContract.deployedBytecode,
|
||||
) {
|
||||
super(
|
||||
'DummyLiquidityProviderRegistry',
|
||||
DummyLiquidityProviderRegistryContract.ABI(),
|
||||
address,
|
||||
supportedProvider,
|
||||
txDefaults,
|
||||
logDecodeDependencies,
|
||||
deployedBytecode,
|
||||
);
|
||||
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
|
||||
DummyLiquidityProviderRegistryContract.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
|
@ -1,5 +1,3 @@
|
||||
export { DummyLiquidityProviderContract } from './generated-wrappers/dummy_liquidity_provider';
|
||||
export { DummyLiquidityProviderRegistryContract } from './generated-wrappers/dummy_liquidity_provider_registry';
|
||||
export { ERC20BridgeSamplerContract } from './generated-wrappers/erc20_bridge_sampler';
|
||||
|
||||
export { ContractAddresses } from '@0x/contract-addresses';
|
||||
|
Loading…
x
Reference in New Issue
Block a user