mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge branch 'v4main' into feature/integrate-erc721-erc20-template-contracts and fix merge conflicts
This commit is contained in:
commit
919e182bc8
@ -24,9 +24,10 @@
|
||||
"release": "release-it --non-interactive",
|
||||
"changelog": "auto-changelog -p",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'",
|
||||
"test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Pool.test.ts'",
|
||||
"test:dt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/Datatoken.test.ts'",
|
||||
"test:nftDt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NFTDatatoken.test.ts'",
|
||||
"test:router": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'",
|
||||
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'",
|
||||
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
||||
"test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import Web3 from 'web3'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||
@ -37,7 +38,7 @@ interface ErcCreateData {
|
||||
|
||||
interface PoolData {
|
||||
addresses: string[]
|
||||
ssParams: (string | number)[]
|
||||
ssParams: (string | number | BigNumber)[]
|
||||
swapFees: number[]
|
||||
}
|
||||
|
||||
|
@ -130,16 +130,23 @@ export class Router {
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for addOceanToken method
|
||||
* Estimate gas cost for addOceanToken
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress template address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
* @param {String} tokenAddress token address we want to add
|
||||
* @param {Contract} routerContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasAddOceanToken(address: string, tokenAddress: string): Promise<any> {
|
||||
public async estGasAddOceanToken(
|
||||
address: string,
|
||||
tokenAddress: string,
|
||||
contractInstance?: Contract
|
||||
) {
|
||||
const routerContract = contractInstance || this.router
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
estGas = await routerContract.methods
|
||||
.addOceanToken(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
@ -150,8 +157,8 @@ export class Router {
|
||||
|
||||
/**
|
||||
* Add a new token to oceanTokens list, pools with basetoken in this list have NO opf Fee
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress template address to add
|
||||
* @param {String} address caller address
|
||||
* @param {String} tokenAddress token address to add
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
*/
|
||||
public async addOceanToken(
|
||||
@ -175,25 +182,28 @@ export class Router {
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas cost for removeOceanToken method
|
||||
* @param {String} address
|
||||
* @param {String} tokenAddress address to remove
|
||||
* @return {Promise<TransactionReceipt>}
|
||||
* Estimate gas cost for removeOceanToken
|
||||
* @param {String} address caller address
|
||||
* @param {String} tokenAddress token address we want to add
|
||||
* @param {Contract} routerContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasRemoveOceanToken(
|
||||
address: string,
|
||||
tokenAddress: string
|
||||
): Promise<any> {
|
||||
tokenAddress: string,
|
||||
contractInstance?: Contract
|
||||
) {
|
||||
const routerContract = contractInstance || this.router
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await this.router.methods
|
||||
estGas = await routerContract.methods
|
||||
.removeOceanToken(tokenAddress)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
|
1636
src/pools/balancer/Pool.ts
Normal file
1636
src/pools/balancer/Pool.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,2 +1 @@
|
||||
export * from './PoolFactory'
|
||||
export * from './OceanPool'
|
||||
export * from './Pool'
|
||||
|
@ -2,8 +2,7 @@ import Web3 from 'web3'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||
// TODO: add OPF deployment
|
||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||
|
||||
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||
export class TestContractHandler {
|
||||
public accounts: string[]
|
||||
@ -29,6 +28,7 @@ export class TestContractHandler {
|
||||
public PoolTemplateBytecode: string
|
||||
public OPFCollectorBytecode: string
|
||||
public MockERC20Bytecode: string
|
||||
public OPFBytecode: string
|
||||
|
||||
public factory721Address: string
|
||||
public template721Address: string
|
||||
@ -54,6 +54,7 @@ export class TestContractHandler {
|
||||
SideStakingABI?: AbiItem | AbiItem[],
|
||||
FixedRateABI?: AbiItem | AbiItem[],
|
||||
DispenserABI?: AbiItem | AbiItem[],
|
||||
OPFABI?: AbiItem | AbiItem[],
|
||||
|
||||
template721Bytecode?: string,
|
||||
template20Bytecode?: string,
|
||||
@ -62,7 +63,8 @@ export class TestContractHandler {
|
||||
routerBytecode?: string,
|
||||
sideStakingBytecode?: string,
|
||||
fixedRateBytecode?: string,
|
||||
dispenserBytecode?: string
|
||||
dispenserBytecode?: string,
|
||||
opfBytecode?: string
|
||||
) {
|
||||
this.web3 = web3
|
||||
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
||||
@ -74,6 +76,7 @@ export class TestContractHandler {
|
||||
this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
|
||||
this.Dispenser = new this.web3.eth.Contract(DispenserABI)
|
||||
this.MockERC20 = new this.web3.eth.Contract(MockERC20.abi as AbiItem[])
|
||||
this.OPFCollector = new this.web3.eth.Contract(OPFABI)
|
||||
|
||||
this.ERC721FactoryBytecode = factory721Bytecode
|
||||
this.ERC20TemplateBytecode = template20Bytecode
|
||||
@ -84,6 +87,7 @@ export class TestContractHandler {
|
||||
this.FixedRateBytecode = fixedRateBytecode
|
||||
this.DispenserBytecode = dispenserBytecode
|
||||
this.MockERC20Bytecode = MockERC20.bytecode
|
||||
this.OPFBytecode = opfBytecode
|
||||
}
|
||||
|
||||
public async getAccounts(): Promise<string[]> {
|
||||
@ -94,6 +98,29 @@ export class TestContractHandler {
|
||||
public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) {
|
||||
let estGas
|
||||
|
||||
// DEPLOY OPF Fee Collector
|
||||
// get est gascost
|
||||
estGas = await this.OPFCollector.deploy({
|
||||
data: this.OPFBytecode,
|
||||
arguments: [owner, owner]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// deploy the contract and get it's address
|
||||
this.opfCollectorAddress = await this.OPFCollector.deploy({
|
||||
data: this.OPFBytecode,
|
||||
arguments: [owner, owner]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
.then(function (contract) {
|
||||
return contract.options.address
|
||||
})
|
||||
|
||||
// DEPLOY POOL TEMPLATE
|
||||
// get est gascost
|
||||
estGas = await this.PoolTemplate.deploy({
|
||||
@ -193,7 +220,7 @@ export class TestContractHandler {
|
||||
owner,
|
||||
this.oceanAddress,
|
||||
this.poolTemplateAddress,
|
||||
communityCollector,
|
||||
this.opfCollectorAddress,
|
||||
[]
|
||||
]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
@ -207,7 +234,7 @@ export class TestContractHandler {
|
||||
owner,
|
||||
this.oceanAddress,
|
||||
this.poolTemplateAddress,
|
||||
communityCollector,
|
||||
this.opfCollectorAddress,
|
||||
[]
|
||||
]
|
||||
})
|
||||
@ -245,7 +272,7 @@ export class TestContractHandler {
|
||||
// DEPLOY FIXED RATE
|
||||
estGas = await this.FixedRate.deploy({
|
||||
data: this.FixedRateBytecode,
|
||||
arguments: [this.routerAddress, communityCollector]
|
||||
arguments: [this.routerAddress, this.opfCollectorAddress]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
if (err) console.log('DeployContracts: ' + err)
|
||||
return estGas
|
||||
@ -253,7 +280,7 @@ export class TestContractHandler {
|
||||
// deploy the contract and get it's address
|
||||
this.fixedRateAddress = await this.FixedRate.deploy({
|
||||
data: this.FixedRateBytecode,
|
||||
arguments: [this.routerAddress, communityCollector]
|
||||
arguments: [this.routerAddress, this.opfCollectorAddress]
|
||||
})
|
||||
.send({
|
||||
from: owner,
|
||||
@ -292,7 +319,7 @@ export class TestContractHandler {
|
||||
arguments: [
|
||||
this.template721Address,
|
||||
this.template20Address,
|
||||
communityCollector,
|
||||
this.opfCollectorAddress,
|
||||
this.routerAddress
|
||||
]
|
||||
}).estimateGas(function (err, estGas) {
|
||||
@ -305,7 +332,7 @@ export class TestContractHandler {
|
||||
arguments: [
|
||||
this.template721Address,
|
||||
this.template20Address,
|
||||
communityCollector,
|
||||
this.opfCollectorAddress,
|
||||
this.routerAddress
|
||||
]
|
||||
})
|
||||
@ -378,7 +405,7 @@ export class TestContractHandler {
|
||||
.send({ from: owner })
|
||||
// TODO: add OPF deployment
|
||||
// await RouterContract.methods
|
||||
// .changeRouterOwner(communityCollector)
|
||||
// .changeRouterOwner(this.opfCollectorAddress)
|
||||
// .send({ from: owner })
|
||||
}
|
||||
}
|
||||
|
1025
test/unit/pools/balancer/Pool.test.ts
Normal file
1025
test/unit/pools/balancer/Pool.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user