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",
|
"release": "release-it --non-interactive",
|
||||||
"changelog": "auto-changelog -p",
|
"changelog": "auto-changelog -p",
|
||||||
"prepublishOnly": "npm run build",
|
"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: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: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": "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: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'",
|
"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 { Contract } from 'web3-eth-contract'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
import BigNumber from 'bignumber.js'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
@ -37,7 +38,7 @@ interface ErcCreateData {
|
|||||||
|
|
||||||
interface PoolData {
|
interface PoolData {
|
||||||
addresses: string[]
|
addresses: string[]
|
||||||
ssParams: (string | number)[]
|
ssParams: (string | number | BigNumber)[]
|
||||||
swapFees: number[]
|
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} address
|
||||||
* @param {String} tokenAddress template address to add
|
* @param {String} tokenAddress token address we want to add
|
||||||
* @return {Promise<TransactionReceipt>}
|
* @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
|
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await this.router.methods
|
estGas = await routerContract.methods
|
||||||
.addOceanToken(tokenAddress)
|
.addOceanToken(tokenAddress)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} 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
|
* Add a new token to oceanTokens list, pools with basetoken in this list have NO opf Fee
|
||||||
* @param {String} address
|
* @param {String} address caller address
|
||||||
* @param {String} tokenAddress template address to add
|
* @param {String} tokenAddress token address to add
|
||||||
* @return {Promise<TransactionReceipt>}
|
* @return {Promise<TransactionReceipt>}
|
||||||
*/
|
*/
|
||||||
public async addOceanToken(
|
public async addOceanToken(
|
||||||
@ -175,25 +182,28 @@ export class Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate gas cost for removeOceanToken method
|
* Estimate gas cost for removeOceanToken
|
||||||
* @param {String} address
|
* @param {String} address caller address
|
||||||
* @param {String} tokenAddress address to remove
|
* @param {String} tokenAddress token address we want to add
|
||||||
* @return {Promise<TransactionReceipt>}
|
* @param {Contract} routerContract optional contract instance
|
||||||
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async estGasRemoveOceanToken(
|
public async estGasRemoveOceanToken(
|
||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string,
|
||||||
): Promise<any> {
|
contractInstance?: Contract
|
||||||
|
) {
|
||||||
|
const routerContract = contractInstance || this.router
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await this.router.methods
|
estGas = await routerContract.methods
|
||||||
.removeOceanToken(tokenAddress)
|
.removeOceanToken(tokenAddress)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
return estGas
|
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 './Pool'
|
||||||
export * from './OceanPool'
|
|
||||||
|
@ -2,8 +2,7 @@ import Web3 from 'web3'
|
|||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
// TODO: add OPF deployment
|
|
||||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
|
||||||
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||||
export class TestContractHandler {
|
export class TestContractHandler {
|
||||||
public accounts: string[]
|
public accounts: string[]
|
||||||
@ -29,6 +28,7 @@ export class TestContractHandler {
|
|||||||
public PoolTemplateBytecode: string
|
public PoolTemplateBytecode: string
|
||||||
public OPFCollectorBytecode: string
|
public OPFCollectorBytecode: string
|
||||||
public MockERC20Bytecode: string
|
public MockERC20Bytecode: string
|
||||||
|
public OPFBytecode: string
|
||||||
|
|
||||||
public factory721Address: string
|
public factory721Address: string
|
||||||
public template721Address: string
|
public template721Address: string
|
||||||
@ -54,6 +54,7 @@ export class TestContractHandler {
|
|||||||
SideStakingABI?: AbiItem | AbiItem[],
|
SideStakingABI?: AbiItem | AbiItem[],
|
||||||
FixedRateABI?: AbiItem | AbiItem[],
|
FixedRateABI?: AbiItem | AbiItem[],
|
||||||
DispenserABI?: AbiItem | AbiItem[],
|
DispenserABI?: AbiItem | AbiItem[],
|
||||||
|
OPFABI?: AbiItem | AbiItem[],
|
||||||
|
|
||||||
template721Bytecode?: string,
|
template721Bytecode?: string,
|
||||||
template20Bytecode?: string,
|
template20Bytecode?: string,
|
||||||
@ -62,7 +63,8 @@ export class TestContractHandler {
|
|||||||
routerBytecode?: string,
|
routerBytecode?: string,
|
||||||
sideStakingBytecode?: string,
|
sideStakingBytecode?: string,
|
||||||
fixedRateBytecode?: string,
|
fixedRateBytecode?: string,
|
||||||
dispenserBytecode?: string
|
dispenserBytecode?: string,
|
||||||
|
opfBytecode?: string
|
||||||
) {
|
) {
|
||||||
this.web3 = web3
|
this.web3 = web3
|
||||||
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
||||||
@ -74,6 +76,7 @@ export class TestContractHandler {
|
|||||||
this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
|
this.FixedRate = new this.web3.eth.Contract(FixedRateABI)
|
||||||
this.Dispenser = new this.web3.eth.Contract(DispenserABI)
|
this.Dispenser = new this.web3.eth.Contract(DispenserABI)
|
||||||
this.MockERC20 = new this.web3.eth.Contract(MockERC20.abi as AbiItem[])
|
this.MockERC20 = new this.web3.eth.Contract(MockERC20.abi as AbiItem[])
|
||||||
|
this.OPFCollector = new this.web3.eth.Contract(OPFABI)
|
||||||
|
|
||||||
this.ERC721FactoryBytecode = factory721Bytecode
|
this.ERC721FactoryBytecode = factory721Bytecode
|
||||||
this.ERC20TemplateBytecode = template20Bytecode
|
this.ERC20TemplateBytecode = template20Bytecode
|
||||||
@ -84,6 +87,7 @@ export class TestContractHandler {
|
|||||||
this.FixedRateBytecode = fixedRateBytecode
|
this.FixedRateBytecode = fixedRateBytecode
|
||||||
this.DispenserBytecode = dispenserBytecode
|
this.DispenserBytecode = dispenserBytecode
|
||||||
this.MockERC20Bytecode = MockERC20.bytecode
|
this.MockERC20Bytecode = MockERC20.bytecode
|
||||||
|
this.OPFBytecode = opfBytecode
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAccounts(): Promise<string[]> {
|
public async getAccounts(): Promise<string[]> {
|
||||||
@ -94,6 +98,29 @@ export class TestContractHandler {
|
|||||||
public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) {
|
public async deployContracts(owner: string, routerABI?: AbiItem | AbiItem[]) {
|
||||||
let estGas
|
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
|
// DEPLOY POOL TEMPLATE
|
||||||
// get est gascost
|
// get est gascost
|
||||||
estGas = await this.PoolTemplate.deploy({
|
estGas = await this.PoolTemplate.deploy({
|
||||||
@ -193,7 +220,7 @@ export class TestContractHandler {
|
|||||||
owner,
|
owner,
|
||||||
this.oceanAddress,
|
this.oceanAddress,
|
||||||
this.poolTemplateAddress,
|
this.poolTemplateAddress,
|
||||||
communityCollector,
|
this.opfCollectorAddress,
|
||||||
[]
|
[]
|
||||||
]
|
]
|
||||||
}).estimateGas(function (err, estGas) {
|
}).estimateGas(function (err, estGas) {
|
||||||
@ -207,7 +234,7 @@ export class TestContractHandler {
|
|||||||
owner,
|
owner,
|
||||||
this.oceanAddress,
|
this.oceanAddress,
|
||||||
this.poolTemplateAddress,
|
this.poolTemplateAddress,
|
||||||
communityCollector,
|
this.opfCollectorAddress,
|
||||||
[]
|
[]
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@ -245,7 +272,7 @@ export class TestContractHandler {
|
|||||||
// DEPLOY FIXED RATE
|
// DEPLOY FIXED RATE
|
||||||
estGas = await this.FixedRate.deploy({
|
estGas = await this.FixedRate.deploy({
|
||||||
data: this.FixedRateBytecode,
|
data: this.FixedRateBytecode,
|
||||||
arguments: [this.routerAddress, communityCollector]
|
arguments: [this.routerAddress, this.opfCollectorAddress]
|
||||||
}).estimateGas(function (err, estGas) {
|
}).estimateGas(function (err, estGas) {
|
||||||
if (err) console.log('DeployContracts: ' + err)
|
if (err) console.log('DeployContracts: ' + err)
|
||||||
return estGas
|
return estGas
|
||||||
@ -253,7 +280,7 @@ export class TestContractHandler {
|
|||||||
// deploy the contract and get it's address
|
// deploy the contract and get it's address
|
||||||
this.fixedRateAddress = await this.FixedRate.deploy({
|
this.fixedRateAddress = await this.FixedRate.deploy({
|
||||||
data: this.FixedRateBytecode,
|
data: this.FixedRateBytecode,
|
||||||
arguments: [this.routerAddress, communityCollector]
|
arguments: [this.routerAddress, this.opfCollectorAddress]
|
||||||
})
|
})
|
||||||
.send({
|
.send({
|
||||||
from: owner,
|
from: owner,
|
||||||
@ -292,7 +319,7 @@ export class TestContractHandler {
|
|||||||
arguments: [
|
arguments: [
|
||||||
this.template721Address,
|
this.template721Address,
|
||||||
this.template20Address,
|
this.template20Address,
|
||||||
communityCollector,
|
this.opfCollectorAddress,
|
||||||
this.routerAddress
|
this.routerAddress
|
||||||
]
|
]
|
||||||
}).estimateGas(function (err, estGas) {
|
}).estimateGas(function (err, estGas) {
|
||||||
@ -305,7 +332,7 @@ export class TestContractHandler {
|
|||||||
arguments: [
|
arguments: [
|
||||||
this.template721Address,
|
this.template721Address,
|
||||||
this.template20Address,
|
this.template20Address,
|
||||||
communityCollector,
|
this.opfCollectorAddress,
|
||||||
this.routerAddress
|
this.routerAddress
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@ -378,7 +405,7 @@ export class TestContractHandler {
|
|||||||
.send({ from: owner })
|
.send({ from: owner })
|
||||||
// TODO: add OPF deployment
|
// TODO: add OPF deployment
|
||||||
// await RouterContract.methods
|
// await RouterContract.methods
|
||||||
// .changeRouterOwner(communityCollector)
|
// .changeRouterOwner(this.opfCollectorAddress)
|
||||||
// .send({ from: owner })
|
// .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