Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function scenarioAsync(): Promise {
await runMigrationsOnceIfRequiredAsync();
let txHash;
PrintUtils.printScenario('Create Staking Pool');
// account information, balances, general contract logs
const web3Wrapper = new Web3Wrapper(providerEngine);
const [maker, otherMaker] = await web3Wrapper.getAvailableAddressesAsync();
const contractWrappers = new ContractWrappers(providerEngine, { chainId: NETWORK_CONFIGS.chainId });
const zrxTokenAddress = contractWrappers.contractAddresses.zrxToken;
const printUtils = new PrintUtils(web3Wrapper, contractWrappers, { maker }, { ZRX: zrxTokenAddress });
// Staking Proxy is a delegate contract. We initialize a Staking Contract (ABI) pointing to the delegate proxy
// at stakingProxyContractAddress
const stakingContract = new StakingContract(contractWrappers.contractAddresses.stakingProxy, providerEngine, {
from: maker,
});
// A small share is kept for the operator, note 1,000,000 represents all rebates
// going to the operator
const operatorSharePpm = new BigNumber(900000); // 90 %
const stakingPoolReceipt = await stakingContract
.createStakingPool(operatorSharePpm, true)
.awaitTransactionSuccessAsync({
from: maker,
constructor(provider: Web3ProviderEngine, networkId: number) {
const contractWrappers = new ContractWrappers(provider, { networkId });
this._exchangeWrapper = contractWrappers.exchange;
}
this.networkId = networkId;
const injectedProviderIfExists = await this._getInjectedProviderIfExistsAsync();
const [provider, ledgerSubproviderIfExists] = await Blockchain._getProviderAsync(
injectedProviderIfExists,
networkId,
shouldUserLedgerProvider,
);
this._web3Wrapper = new Web3Wrapper(provider);
this.networkId = await this._web3Wrapper.getNetworkIdAsync();
if (!_.isUndefined(this._contractWrappers)) {
this._contractWrappers.unsubscribeAll();
}
const contractWrappersConfig = {
networkId,
};
this._contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
if (!_.isUndefined(this._blockchainWatcher)) {
this._blockchainWatcher.destroy();
}
this._blockchainWatcher = new BlockchainWatcher(this._dispatcher, this._web3Wrapper, shouldPollUserAddress);
if (shouldUserLedgerProvider && !_.isUndefined(ledgerSubproviderIfExists)) {
delete this._userAddressIfExists;
this._ledgerSubprovider = ledgerSubproviderIfExists;
this._dispatcher.updateUserAddress(undefined);
this._dispatcher.updateProviderType(ProviderType.Ledger);
} else {
delete this._ledgerSubprovider;
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
this._userAddressIfExists = userAddresses[0];
this._dispatcher.updateUserAddress(this._userAddressIfExists);
if (!_.isUndefined(injectedProviderIfExists)) {
this._dispatcher.updateProviderType(ProviderType.Injected);
const [provider, ledgerSubproviderIfExists] = await this._getProviderAsync(
injectedProviderIfExists,
networkId,
shouldUserLedgerProvider,
);
this._web3Wrapper = new Web3Wrapper(provider);
this._providerEngine = provider;
this.networkId = await this._web3Wrapper.getNetworkIdAsync();
this._providerName = this._getNameGivenProvider(provider);
if (this._contractWrappers !== undefined) {
this._contractWrappers.unsubscribeAll();
}
const contractWrappersConfig = {
networkId,
};
this._contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
if (shouldUserLedgerProvider && ledgerSubproviderIfExists !== undefined) {
delete this._userAddressIfExists;
this._ledgerSubprovider = ledgerSubproviderIfExists;
} else {
delete this._ledgerSubprovider;
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
this._userAddressIfExists = userAddresses[0];
}
}
private async _getUserAddressesAsync(): Promise {
constructor(supportedProvider: SupportedProvider, options: Partial = {}) {
const { networkId } = _.merge({}, constants.DEFAULT_SWAP_QUOTER_OPTS, options);
assert.isNumber('networkId', networkId);
const provider = providerUtils.standardizeOrThrow(supportedProvider);
this.provider = provider;
this.networkId = networkId;
this._contractWrappers = new ContractWrappers(this.provider, {
networkId,
});
}
_.each(chainIdToProvider, (provider: Web3ProviderEngine, chainIdStr: string) => {
const chainId = _.parseInt(chainIdStr);
const contractAddresses = configs.CHAIN_ID_TO_CONTRACT_ADDRESSES
? configs.CHAIN_ID_TO_CONTRACT_ADDRESSES[chainId]
: undefined;
const contractWrappers = new ContractWrappers(provider, {
chainId,
contractAddresses,
});
this._chainIdToContractWrappers[chainId] = contractWrappers;
});
}