1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

add web3 parameter

This commit is contained in:
Miquel A. Cabot 2022-03-20 19:03:14 +01:00
parent 589ec02938
commit 546f516cee
9 changed files with 24 additions and 10 deletions

View File

@ -1,3 +1,4 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import OPFCommunityFeeCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
@ -9,9 +10,10 @@ import SideStaking from '@oceanprotocol/contracts/artifacts/contracts/pools/ssCo
import FixedRate from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
import Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
import { web3, getAddresses, GAS_PRICE } from './config'
import { getAddresses, GAS_PRICE } from './config'
const estimateGasAndDeployContract = async (
web3: Web3,
abi: AbiItem | AbiItem[],
bytecode: string,
argumentsArray: any[],
@ -59,7 +61,7 @@ export interface Addresses {
usdcAddress: string
}
export const deployContracts = async (owner: string): Promise<Addresses> => {
export const deployContracts = async (web3: Web3, owner: string): Promise<Addresses> => {
const addresses: Addresses = {} as Addresses
const configAddresses = getAddresses()
@ -67,6 +69,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.opfCommunityFeeCollectorAddress =
configAddresses.OPFCommunityFeeCollector ||
(await estimateGasAndDeployContract(
web3,
OPFCommunityFeeCollector.abi as AbiItem[],
OPFCommunityFeeCollector.bytecode,
[owner, owner],
@ -77,6 +80,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.poolTemplateAddress =
configAddresses.poolTemplate ||
(await estimateGasAndDeployContract(
web3,
PoolTemplate.abi as AbiItem[],
PoolTemplate.bytecode,
[],
@ -87,6 +91,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.erc20TemplateAddress =
configAddresses.ERC20Template['1'] ||
(await estimateGasAndDeployContract(
web3,
ERC20Template.abi as AbiItem[],
ERC20Template.bytecode,
[],
@ -97,6 +102,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.erc721TemplateAddress =
configAddresses.ERC721Template['1'] ||
(await estimateGasAndDeployContract(
web3,
ERC721Template.abi as AbiItem[],
ERC721Template.bytecode,
[],
@ -107,6 +113,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.oceanAddress =
configAddresses.Ocean ||
(await estimateGasAndDeployContract(
web3,
MockERC20.abi as AbiItem[],
MockERC20.bytecode,
['OCEAN', 'OCEAN', 18],
@ -117,6 +124,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.routerAddress =
configAddresses.Router ||
(await estimateGasAndDeployContract(
web3,
Router.abi as AbiItem[],
Router.bytecode,
[
@ -133,6 +141,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.sideStakingAddress =
configAddresses.Staking ||
(await estimateGasAndDeployContract(
web3,
SideStaking.abi as AbiItem[],
SideStaking.bytecode,
[addresses.routerAddress],
@ -143,6 +152,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.fixedRateAddress =
configAddresses.FixedPrice ||
(await estimateGasAndDeployContract(
web3,
FixedRate.abi as AbiItem[],
FixedRate.bytecode,
[addresses.routerAddress, addresses.opfCommunityFeeCollectorAddress],
@ -153,6 +163,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.dispenserAddress =
configAddresses.Dispenser ||
(await estimateGasAndDeployContract(
web3,
Dispenser.abi as AbiItem[],
Dispenser.bytecode,
[addresses.routerAddress],
@ -163,6 +174,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.erc721FactoryAddress =
configAddresses.ERC721Factory ||
(await estimateGasAndDeployContract(
web3,
ERC721Factory.abi as AbiItem[],
ERC721Factory.bytecode,
[
@ -178,6 +190,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.usdcAddress =
configAddresses.MockUSDC ||
(await estimateGasAndDeployContract(
web3,
MockERC20.abi as AbiItem[],
MockERC20.bytecode,
['USDC', 'USDC', 6],
@ -188,6 +201,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
addresses.daiAddress =
configAddresses.MockDAI ||
(await estimateGasAndDeployContract(
web3,
MockERC20.abi as AbiItem[],
MockERC20.bytecode,
['DAI', 'DAI', 18],

View File

@ -34,7 +34,7 @@ describe('Nft Factory test', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
const daiContract = new web3.eth.Contract(
MockERC20.abi as AbiItem[],

View File

@ -33,7 +33,7 @@ describe('Router unit test', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
const daiContract = new web3.eth.Contract(
MockERC20.abi as AbiItem[],

View File

@ -51,7 +51,7 @@ describe('Pool unit test', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
// initialize Pool instance
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])

View File

@ -37,7 +37,7 @@ describe('Dispenser flow', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
})
it('should initialize Dispenser class', async () => {

View File

@ -45,7 +45,7 @@ describe('Fixed Rate unit test', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
// initialize fixed rate
//

View File

@ -56,7 +56,7 @@ describe('SideStaking unit test', () => {
it('should deploy contracts', async () => {
sideStakingAddress = contracts.sideStakingAddress
contracts = await deployContracts(factoryOwner)
contracts = await deployContracts(web3, factoryOwner)
// initialize Pool instance
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])

View File

@ -45,7 +45,7 @@ describe('Datatoken', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(nftOwner)
contracts = await deployContracts(web3, nftOwner)
const daiContract = new web3.eth.Contract(
MockERC20.abi as AbiItem[],

View File

@ -32,7 +32,7 @@ describe('NFT', () => {
})
it('should deploy contracts', async () => {
contracts = await deployContracts(nftOwner)
contracts = await deployContracts(web3, nftOwner)
})
it('should initialize NFTFactory instance and create a new NFT', async () => {