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:
parent
589ec02938
commit
546f516cee
@ -1,3 +1,4 @@
|
|||||||
|
import Web3 from 'web3'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import OPFCommunityFeeCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
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'
|
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 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 Dispenser from '@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json'
|
||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.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 (
|
const estimateGasAndDeployContract = async (
|
||||||
|
web3: Web3,
|
||||||
abi: AbiItem | AbiItem[],
|
abi: AbiItem | AbiItem[],
|
||||||
bytecode: string,
|
bytecode: string,
|
||||||
argumentsArray: any[],
|
argumentsArray: any[],
|
||||||
@ -59,7 +61,7 @@ export interface Addresses {
|
|||||||
usdcAddress: string
|
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 addresses: Addresses = {} as Addresses
|
||||||
const configAddresses = getAddresses()
|
const configAddresses = getAddresses()
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.opfCommunityFeeCollectorAddress =
|
addresses.opfCommunityFeeCollectorAddress =
|
||||||
configAddresses.OPFCommunityFeeCollector ||
|
configAddresses.OPFCommunityFeeCollector ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
OPFCommunityFeeCollector.abi as AbiItem[],
|
OPFCommunityFeeCollector.abi as AbiItem[],
|
||||||
OPFCommunityFeeCollector.bytecode,
|
OPFCommunityFeeCollector.bytecode,
|
||||||
[owner, owner],
|
[owner, owner],
|
||||||
@ -77,6 +80,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.poolTemplateAddress =
|
addresses.poolTemplateAddress =
|
||||||
configAddresses.poolTemplate ||
|
configAddresses.poolTemplate ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
PoolTemplate.abi as AbiItem[],
|
PoolTemplate.abi as AbiItem[],
|
||||||
PoolTemplate.bytecode,
|
PoolTemplate.bytecode,
|
||||||
[],
|
[],
|
||||||
@ -87,6 +91,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.erc20TemplateAddress =
|
addresses.erc20TemplateAddress =
|
||||||
configAddresses.ERC20Template['1'] ||
|
configAddresses.ERC20Template['1'] ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
ERC20Template.abi as AbiItem[],
|
ERC20Template.abi as AbiItem[],
|
||||||
ERC20Template.bytecode,
|
ERC20Template.bytecode,
|
||||||
[],
|
[],
|
||||||
@ -97,6 +102,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.erc721TemplateAddress =
|
addresses.erc721TemplateAddress =
|
||||||
configAddresses.ERC721Template['1'] ||
|
configAddresses.ERC721Template['1'] ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
ERC721Template.abi as AbiItem[],
|
ERC721Template.abi as AbiItem[],
|
||||||
ERC721Template.bytecode,
|
ERC721Template.bytecode,
|
||||||
[],
|
[],
|
||||||
@ -107,6 +113,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.oceanAddress =
|
addresses.oceanAddress =
|
||||||
configAddresses.Ocean ||
|
configAddresses.Ocean ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
MockERC20.bytecode,
|
MockERC20.bytecode,
|
||||||
['OCEAN', 'OCEAN', 18],
|
['OCEAN', 'OCEAN', 18],
|
||||||
@ -117,6 +124,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.routerAddress =
|
addresses.routerAddress =
|
||||||
configAddresses.Router ||
|
configAddresses.Router ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
Router.abi as AbiItem[],
|
Router.abi as AbiItem[],
|
||||||
Router.bytecode,
|
Router.bytecode,
|
||||||
[
|
[
|
||||||
@ -133,6 +141,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.sideStakingAddress =
|
addresses.sideStakingAddress =
|
||||||
configAddresses.Staking ||
|
configAddresses.Staking ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
SideStaking.abi as AbiItem[],
|
SideStaking.abi as AbiItem[],
|
||||||
SideStaking.bytecode,
|
SideStaking.bytecode,
|
||||||
[addresses.routerAddress],
|
[addresses.routerAddress],
|
||||||
@ -143,6 +152,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.fixedRateAddress =
|
addresses.fixedRateAddress =
|
||||||
configAddresses.FixedPrice ||
|
configAddresses.FixedPrice ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
FixedRate.abi as AbiItem[],
|
FixedRate.abi as AbiItem[],
|
||||||
FixedRate.bytecode,
|
FixedRate.bytecode,
|
||||||
[addresses.routerAddress, addresses.opfCommunityFeeCollectorAddress],
|
[addresses.routerAddress, addresses.opfCommunityFeeCollectorAddress],
|
||||||
@ -153,6 +163,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.dispenserAddress =
|
addresses.dispenserAddress =
|
||||||
configAddresses.Dispenser ||
|
configAddresses.Dispenser ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
Dispenser.abi as AbiItem[],
|
Dispenser.abi as AbiItem[],
|
||||||
Dispenser.bytecode,
|
Dispenser.bytecode,
|
||||||
[addresses.routerAddress],
|
[addresses.routerAddress],
|
||||||
@ -163,6 +174,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.erc721FactoryAddress =
|
addresses.erc721FactoryAddress =
|
||||||
configAddresses.ERC721Factory ||
|
configAddresses.ERC721Factory ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
ERC721Factory.abi as AbiItem[],
|
ERC721Factory.abi as AbiItem[],
|
||||||
ERC721Factory.bytecode,
|
ERC721Factory.bytecode,
|
||||||
[
|
[
|
||||||
@ -178,6 +190,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.usdcAddress =
|
addresses.usdcAddress =
|
||||||
configAddresses.MockUSDC ||
|
configAddresses.MockUSDC ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
MockERC20.bytecode,
|
MockERC20.bytecode,
|
||||||
['USDC', 'USDC', 6],
|
['USDC', 'USDC', 6],
|
||||||
@ -188,6 +201,7 @@ export const deployContracts = async (owner: string): Promise<Addresses> => {
|
|||||||
addresses.daiAddress =
|
addresses.daiAddress =
|
||||||
configAddresses.MockDAI ||
|
configAddresses.MockDAI ||
|
||||||
(await estimateGasAndDeployContract(
|
(await estimateGasAndDeployContract(
|
||||||
|
web3,
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
MockERC20.bytecode,
|
MockERC20.bytecode,
|
||||||
['DAI', 'DAI', 18],
|
['DAI', 'DAI', 18],
|
||||||
|
@ -34,7 +34,7 @@ describe('Nft Factory test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
|
@ -33,7 +33,7 @@ describe('Router unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
|
@ -51,7 +51,7 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
// initialize Pool instance
|
// initialize Pool instance
|
||||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||||
|
@ -37,7 +37,7 @@ describe('Dispenser flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initialize Dispenser class', async () => {
|
it('should initialize Dispenser class', async () => {
|
||||||
|
@ -45,7 +45,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
// initialize fixed rate
|
// initialize fixed rate
|
||||||
//
|
//
|
||||||
|
@ -56,7 +56,7 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
sideStakingAddress = contracts.sideStakingAddress
|
sideStakingAddress = contracts.sideStakingAddress
|
||||||
contracts = await deployContracts(factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
// initialize Pool instance
|
// initialize Pool instance
|
||||||
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
pool = new Pool(web3, PoolTemplate.abi as AbiItem[])
|
||||||
|
@ -45,7 +45,7 @@ describe('Datatoken', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(nftOwner)
|
contracts = await deployContracts(web3, nftOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
const daiContract = new web3.eth.Contract(
|
||||||
MockERC20.abi as AbiItem[],
|
MockERC20.abi as AbiItem[],
|
||||||
|
@ -32,7 +32,7 @@ describe('NFT', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
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 () => {
|
it('should initialize NFTFactory instance and create a new NFT', async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user