diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5b58957..dcd8ffe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,6 @@ jobs: key: ${{ runner.os }}-lint-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} restore-keys: ${{ runner.os }}-lint-${{ env.cache-name }}- - run: npm ci - - run: npm i --verbose --force @oceanprotocol/contracts@"github:oceanprotocol/contracts#v4main_postaudit" - run: npm run lint test_unit: @@ -61,7 +60,6 @@ jobs: cd .. - run: npm ci - - run: npm i --verbose --force @oceanprotocol/contracts@"github:oceanprotocol/contracts#v4main_postaudit" - run: npm run build:metadata - run: npm run test:unit:cover - uses: actions/upload-artifact@v2 @@ -86,7 +84,6 @@ jobs: key: ${{ runner.os }}-test-integration-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} restore-keys: ${{ runner.os }}-test-integration-${{ env.cache-name }}- - run: npm ci - - run: npm i --verbose --force @oceanprotocol/contracts@"github:oceanprotocol/contracts#v4main_postaudit" - run: npm run build:metadata # Env var expansion workaround @@ -149,7 +146,6 @@ jobs: key: ${{ runner.os }}-${{ matrix.node }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} restore-keys: ${{ runner.os }}-${{ matrix.node }}-build-${{ env.cache-name }}- - run: npm ci - - run: npm i --verbose --force @oceanprotocol/contracts@"github:oceanprotocol/contracts#v4main_postaudit" - run: npm run build - run: npm run doc:json diff --git a/package-lock.json b/package-lock.json index 7fc363cc..7bce53ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-next.8", "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^1.0.0-alpha.1", + "@oceanprotocol/contracts": "^1.0.0-alpha.15", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.4", "crypto-js": "^4.0.0", @@ -3016,9 +3016,9 @@ } }, "node_modules/@oceanprotocol/contracts": { - "name": "hardhat-project", - "version": "v1.0.0-alpha.1", - "resolved": "git+ssh://git@github.com/oceanprotocol/contracts.git#36e8bf296163690a23cfe012c4468caba4504709", + "version": "1.0.0-alpha.15", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.15.tgz", + "integrity": "sha512-m8vF38uKKCZTRnNE84xQEL81hCpGvhWqbMMqkuJqdJTeRoLoJJmHqHMi3xqkferMrH7Bmt4znuRSiWnbd75s3A==", "dependencies": { "@openzeppelin/contracts": "^4.3.3", "@openzeppelin/test-helpers": "^0.5.15", @@ -27489,8 +27489,9 @@ } }, "@oceanprotocol/contracts": { - "version": "git+ssh://git@github.com/oceanprotocol/contracts.git#36e8bf296163690a23cfe012c4468caba4504709", - "from": "@oceanprotocol/contracts@^1.0.0-alpha.1", + "version": "1.0.0-alpha.15", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.15.tgz", + "integrity": "sha512-m8vF38uKKCZTRnNE84xQEL81hCpGvhWqbMMqkuJqdJTeRoLoJJmHqHMi3xqkferMrH7Bmt4znuRSiWnbd75s3A==", "requires": { "@openzeppelin/contracts": "^4.3.3", "@openzeppelin/test-helpers": "^0.5.15", diff --git a/package.json b/package.json index ee3b4fe5..a1df629d 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "web3": ">=1.3.5" }, "dependencies": { - "@oceanprotocol/contracts": "^1.0.0-alpha.1", + "@oceanprotocol/contracts": "^1.0.0-alpha.15", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.4", "crypto-js": "^4.0.0", @@ -81,10 +81,10 @@ "chai-spies": "^1.0.0", "cross-env": "^7.0.3", "eslint": "^7.17.0", - "fs": "0.0.1-security", "eslint-config-oceanprotocol": "^1.5.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", + "fs": "0.0.1-security", "microbundle": "^0.14.2", "mocha": "^9.1.2", "mock-local-storage": "^1.1.17", diff --git a/src/factories/NFTFactory.ts b/src/factories/NFTFactory.ts index a3dbc0f6..d1052a3e 100644 --- a/src/factories/NFTFactory.ts +++ b/src/factories/NFTFactory.ts @@ -30,6 +30,7 @@ interface Template { export interface TokenOrder { tokenAddress: string consumer: string + ammount: string serviceIndex: number _providerFees: ProviderFees } diff --git a/src/pools/Router.ts b/src/pools/Router.ts index f000a01c..be2ba2a2 100644 --- a/src/pools/Router.ts +++ b/src/pools/Router.ts @@ -521,16 +521,16 @@ export class Router { } /** Get OPF Fee per token - * @return {Promise} OPF fee for a specific baseToken + * @return {Promise} OPC fee for a specific baseToken */ - public async getOPFFee(baseToken: string): Promise { - return await this.router.methods.getOPFFee(baseToken).call() + public async getOPCFee(baseToken: string): Promise { + return await this.router.methods.getOPCFee(baseToken).call() } /** Get Current OPF Fee * @return {Promise} OPF fee */ - public async getCurrentOPFFee(): Promise { + public async getCurrentOPCFee(): Promise { return await this.router.methods.swapOceanFee().call() } @@ -540,12 +540,18 @@ export class Router { * @param {String} newFee new OPF Fee * @return {Promise} */ - public async estGasUpdateOPFFee(address: string, newFee: number): Promise { + public async estGasUpdateOPCFee( + address: string, + newSwapOceanFee: number, + newSwapNonOceanFee: number, + newConsumeFee: number, + newProviderFee: number + ): Promise { const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas try { estGas = await this.router.methods - .updateOPFFee(newFee) + .updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee) .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { estGas = gasLimitDefault @@ -557,26 +563,39 @@ export class Router { /** * Add a new contract to fixedRate list, after is added, can be used when deploying a new pool * @param {String} address - * @param {String} newFee new OPF Fee + * @param {number} newSwapOceanFee Amount charged for swapping with ocean approved tokens + * @param {number} newSwapNonOceanFee Amount charged for swapping with non ocean approved tokens + * @param {number} newConsumeFee Amount charged from consumeFees + * @param {number} newProviderFee Amount charged for providerFees * @return {Promise} */ - public async updateOPFFee( + public async updateOPCFee( address: string, - newFee: number + newSwapOceanFee: number, + newSwapNonOceanFee: number, + newConsumeFee: number, + newProviderFee: number ): Promise { if ((await this.getOwner()) !== address) { throw new Error(`Caller is not Router Owner`) } - const gasLimitDefault = this.GASLIMIT_DEFAULT - const estGas = await this.estGasUpdateOPFFee(address, newFee) + const estGas = await this.estGasUpdateOPCFee( + address, + newSwapOceanFee, + newSwapNonOceanFee, + newConsumeFee, + newProviderFee + ) // Invoke createToken function of the contract - const trxReceipt = await this.router.methods.updateOPFFee(newFee, newFee).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.router.methods + .updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } diff --git a/src/pools/balancer/Pool.ts b/src/pools/balancer/Pool.ts index aedd5c42..45d08eb1 100644 --- a/src/pools/balancer/Pool.ts +++ b/src/pools/balancer/Pool.ts @@ -290,18 +290,18 @@ export class Pool { } /** - * Get OPF Collector of this pool + * Get OPC Collector of this pool * @param {String} poolAddress * @return {String} */ - async getOPFCollector(poolAddress: string): Promise { + async getOPCCollector(poolAddress: string): Promise { const pool = setContractDefaults( new this.web3.eth.Contract(this.poolAbi, poolAddress), this.config ) let result = null try { - result = await pool.methods._opfCollector().call() + result = await pool.methods._opcCollector().call() } catch (e) { this.logger.error(`ERROR: Failed to get OPF Collector address: ${e.message}`) } @@ -483,7 +483,7 @@ export class Pool { this.config ) try { - const currentMarketFees = await pool.methods.getCurrentOPFFees().call() + const currentMarketFees = await pool.methods.getCurrentOPCFees().call() return currentMarketFees } catch (e) { this.logger.error(`ERROR: Failed to get community fees for a token: ${e.message}`) @@ -494,13 +494,13 @@ export class Pool { * Get getCurrentOPFFees Get the current amount of fees which can be withdrawned by OPF * @return {CurrentFees} */ - async getCurrentOPFFees(poolAddress: string): Promise { + async getCurrentOPCFees(poolAddress: string): Promise { const pool = setContractDefaults( new this.web3.eth.Contract(this.poolAbi, poolAddress), this.config ) try { - const currentMarketFees = await pool.methods.getCurrentOPFFees().call() + const currentMarketFees = await pool.methods.getCurrentOPCFees().call() return currentMarketFees } catch (e) { this.logger.error(`ERROR: Failed to get community fees for a token: ${e.message}`) @@ -535,7 +535,7 @@ export class Pool { * @param {Contract} contractInstance optional contract instance * @return {Promise} */ - public async estCollectOPF( + public async estCollectOPC( address: string, poolAddress: string, contractInstance?: Contract @@ -551,7 +551,7 @@ export class Pool { let estGas try { estGas = await poolContract.methods - .collectOPF() + .collectOPC() .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { estGas = gasLimitDefault @@ -565,16 +565,16 @@ export class Pool { * @param {String} poolAddress * @return {TransactionReceipt} */ - async collectOPF(address: string, poolAddress: string): Promise { + async collectOPC(address: string, poolAddress: string): Promise { const pool = setContractDefaults( new this.web3.eth.Contract(this.poolAbi, poolAddress), this.config ) let result = null - const estGas = await this.estCollectOPF(address, poolAddress) + const estGas = await this.estCollectOPC(address, poolAddress) try { - result = await pool.methods.collectOPF().send({ + result = await pool.methods.collectOPC().send({ from: address, gas: estGas + 1, gasPrice: await getFairGasPrice(this.web3, this.config) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index 941c180d..b6c23dae 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -31,7 +31,7 @@ export interface FixedPriceExchange { } export interface FeesInfo { - opfFee: string + opcFee: string marketFee: string marketFeeCollector: string marketFeeAvailable: string @@ -640,7 +640,7 @@ export class FixedRateExchange { */ public async getFeesInfo(exchangeId: string): Promise { const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call() - result.opfFee = this.web3.utils.fromWei(result.opfFee.toString()) + result.opcFee = this.web3.utils.fromWei(result.opcFee.toString()) result.marketFee = this.web3.utils.fromWei(result.marketFee.toString()) result.marketFeeAvailable = await this.unitsToAmount( @@ -974,12 +974,12 @@ export class FixedRateExchange { * Get OPF Collector of fixed rate contract * @return {String} */ - async getOPFCollector(): Promise { + async getOPCCollector(): Promise { let result = null try { - result = await this.contract.methods.opfCollector().call() + result = await this.contract.methods.opcCollector().call() } catch (e) { - LoggerInstance.error(`ERROR: Failed to get OPF Collector address: ${e.message}`) + LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`) } return result } diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index dcf19ad8..8ec1cf48 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -26,6 +26,7 @@ interface Roles { export interface OrderParams { consumer: string serviceIndex: number + ammount: string _providerFees: ProviderFees } diff --git a/test/unit/NftFactory.test.ts b/test/unit/NftFactory.test.ts index b0a2b308..865bc3e9 100644 --- a/test/unit/NftFactory.test.ts +++ b/test/unit/NftFactory.test.ts @@ -378,6 +378,7 @@ describe('Nft Factory test', () => { const providerData = JSON.stringify({ timeout: 0 }) const providerValidUntil = '0' + const message = web3.utils.soliditySha3( { t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) }, { t: 'address', v: consumeFeeAddress }, @@ -402,13 +403,15 @@ describe('Nft Factory test', () => { tokenAddress: dtAddress, consumer: consumer, serviceIndex: serviceIndex, - _providerFees: providerFees + _providerFees: providerFees, + ammount: dtAmount }, { tokenAddress: dtAddress2, consumer: consumer, serviceIndex: serviceIndex, - _providerFees: providerFees + _providerFees: providerFees, + ammount: dtAmount } ] await nftFactory.startMultipleTokenOrder(user2, orders) diff --git a/test/unit/pools/Router.test.ts b/test/unit/pools/Router.test.ts index 68cc1c09..b4cf43e3 100644 --- a/test/unit/pools/Router.test.ts +++ b/test/unit/pools/Router.test.ts @@ -122,23 +122,29 @@ describe('Router unit test', () => { expect(await router.isFixedPrice(contracts.daiAddress)).to.equal(true) }) - it('#getOPFFee - should return actual OPF fee for a given baseToken', async () => { - const opfFee = 1e15 - expect(await router.getOPFFee(contracts.oceanAddress)).to.equal('0') - expect(await router.getOPFFee(contracts.daiAddress)).to.equal(opfFee.toString()) + it('#getOPCFee - should return actual OPF fee for a given baseToken', async () => { + const opcFee = 1e15 + expect(await router.getOPCFee(contracts.oceanAddress)).to.equal('0') + expect(await router.getOPCFee(contracts.daiAddress)).to.equal(opcFee.toString()) }) it('#getCurrentOPFFee - should return actual OPF Fee', async () => { const opfFee = 0 - expect(await router.getCurrentOPFFee()).to.equal(opfFee.toString()) + expect(await router.getCurrentOPCFee()).to.equal(opfFee.toString()) }) - it('#updateOPFFee - should update opf fee if Router Owner', async () => { + it('#updateOPCFee - should update opf fee if Router Owner', async () => { const opfFee = 0 - expect(await router.getCurrentOPFFee()).to.equal(opfFee.toString()) + expect(await router.getCurrentOPCFee()).to.equal(opfFee.toString()) const newOPFFee = 1e14 - await router.updateOPFFee(contracts.accounts[0], 1e14) - expect(await router.getCurrentOPFFee()).to.equal(newOPFFee.toString()) + await router.updateOPCFee( + contracts.accounts[0], + newOPFFee, + newOPFFee, + newOPFFee, + newOPFFee + ) + expect(await router.getCurrentOPCFee()).to.equal(newOPFFee.toString()) }) it('#addPoolTemplate - should add a new token into poolTemplates mapping if Router Owner', async () => { diff --git a/test/unit/pools/balancer/Pool.test.ts b/test/unit/pools/balancer/Pool.test.ts index 969daabc..c4c4b473 100644 --- a/test/unit/pools/balancer/Pool.test.ts +++ b/test/unit/pools/balancer/Pool.test.ts @@ -549,8 +549,8 @@ describe('Pool unit test', () => { assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0]) }) - it('#getOPFCollector- should get market fees for each token', async () => { - assert((await pool.getOPFCollector(poolAddress)) === contracts.opfCollectorAddress) + it('#getOPCCollector- should get market fees for each token', async () => { + assert((await pool.getOPCCollector(poolAddress)) === contracts.opfCollectorAddress) }) it('#collectCommunityFee- should get community fees for each token', async () => { @@ -568,7 +568,7 @@ describe('Pool unit test', () => { '0' ) // anyone can call callectOPF - await pool.collectOPF(contracts.accounts[0], poolAddress) + await pool.collectOPC(contracts.accounts[0], poolAddress) // DAI fees have been collected assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) === '0') // OPF collector got DAI @@ -1101,8 +1101,8 @@ describe('Pool unit test', () => { assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0]) }) - it('#getOPFCollector- should get market fees for each token', async () => { - assert((await pool.getOPFCollector(poolAddress)) === contracts.opfCollectorAddress) + it('#getOPCCollector- should get market fees for each token', async () => { + assert((await pool.getOPCCollector(poolAddress)) === contracts.opfCollectorAddress) }) it('#getCurrentMarketFees- should get curent market fees for each token', async () => { @@ -1111,7 +1111,7 @@ describe('Pool unit test', () => { }) it('#getCurrentOPFFees- should get curent market fees for each token', async () => { - const curentOPFFees: CurrentFees = await pool.getCurrentOPFFees(poolAddress) + const curentOPFFees: CurrentFees = await pool.getCurrentOPCFees(poolAddress) assert(curentOPFFees !== null) }) @@ -1130,7 +1130,7 @@ describe('Pool unit test', () => { '0' ) // anyone can call callectOPF - await pool.collectOPF(contracts.accounts[0], poolAddress) + await pool.collectOPC(contracts.accounts[0], poolAddress) // USDC fees have been collected assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) === '0') // OPF collector got USDC diff --git a/test/unit/pools/fixedRate/FixedRateExchange.test.ts b/test/unit/pools/fixedRate/FixedRateExchange.test.ts index 7f8181e3..e2993086 100644 --- a/test/unit/pools/fixedRate/FixedRateExchange.test.ts +++ b/test/unit/pools/fixedRate/FixedRateExchange.test.ts @@ -160,7 +160,7 @@ describe('Fixed Rate unit test', () => { expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner) }) it('#getOPFCollector - should get OPF collector', async () => { - expect(await fixedRate.getOPFCollector()).to.equal(contracts.opfCollectorAddress) + expect(await fixedRate.getOPCCollector()).to.equal(contracts.opfCollectorAddress) }) it('#getRouter - should get Router address', async () => { expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress) @@ -325,7 +325,7 @@ describe('Fixed Rate unit test', () => { expect(result.marketFeeAvailable).to.equal('0.02') // formatted for baseToken decimals expect(result.oceanFeeAvailable).to.equal('0.02') // formatted for baseToken decimals expect(result.marketFeeCollector).to.equal(user3) - expect(result.opfFee).to.equal('0.001') + expect(result.opcFee).to.equal('0.001') }) it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => { @@ -396,7 +396,7 @@ describe('Fixed Rate unit test', () => { expect(result.oceanFeeAvailable).to.equal('0') // OPF collector got the fee expect( - await daiContract.methods.balanceOf(await fixedRate.getOPFCollector()).call() + await daiContract.methods.balanceOf(await fixedRate.getOPCCollector()).call() ).to.equal(web3.utils.toWei('0.021')) }) @@ -488,7 +488,7 @@ describe('Fixed Rate unit test', () => { expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner) }) it('#getOPFCollector - should get OPF collector', async () => { - expect(await fixedRate.getOPFCollector()).to.equal(contracts.opfCollectorAddress) + expect(await fixedRate.getOPCCollector()).to.equal(contracts.opfCollectorAddress) }) it('#getRouter - should get Router address', async () => { expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress) @@ -655,7 +655,7 @@ describe('Fixed Rate unit test', () => { expect(result.marketFeeAvailable).to.equal('0.02') // formatted for baseToken decimals expect(result.oceanFeeAvailable).to.equal('0.02') // formatted for baseToken decimals expect(result.marketFeeCollector).to.equal(user3) - expect(result.opfFee).to.equal('0.001') + expect(result.opcFee).to.equal('0.001') }) it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => { @@ -726,7 +726,7 @@ describe('Fixed Rate unit test', () => { expect(result.oceanFeeAvailable).to.equal('0') // OPF collector got the fee expect( - await usdcContract.methods.balanceOf(await fixedRate.getOPFCollector()).call() + await usdcContract.methods.balanceOf(await fixedRate.getOPCCollector()).call() ).to.equal((0.021 * 1e6).toString()) }) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index fe0416b1..5db06c1a 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -390,6 +390,7 @@ describe('Datatoken', () => { const providerData = JSON.stringify({ timeout: 0 }) const providerFeeToken = ZERO_ADDRESS const providerFeeAmount = '0' + const dtAmount = web3.utils.toWei('1') const message = web3.utils.soliditySha3( { t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) }, { t: 'address', v: user3 }, @@ -411,7 +412,8 @@ describe('Datatoken', () => { const order: OrderParams = { consumer: user1, serviceIndex: 1, - _providerFees: providerFees + _providerFees: providerFees, + ammount: dtAmount } const buyFromDispenseTx = await datatoken.buyFromDispenserAndOrder( datatokenAddress, @@ -426,6 +428,7 @@ describe('Datatoken', () => { const providerData = JSON.stringify({ timeout: 0 }) const providerFeeToken = ZERO_ADDRESS const providerFeeAmount = '0' + const dtAmount = web3.utils.toWei('1') const message = web3.utils.soliditySha3( { t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) }, { t: 'address', v: user3 }, @@ -447,6 +450,7 @@ describe('Datatoken', () => { const order: OrderParams = { consumer: user1, serviceIndex: 1, + ammount: dtAmount, _providerFees: providerFees } diff --git a/test/unit/tokens/Nft.test.ts b/test/unit/tokens/Nft.test.ts index a15eab74..a614ad5b 100644 --- a/test/unit/tokens/Nft.test.ts +++ b/test/unit/tokens/Nft.test.ts @@ -83,7 +83,6 @@ describe('NFT', () => { it('#getTokenURI', async () => { const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1) assert(tokenURI === 'https://oceanprotocol.com/nft/') - console.log(tokenURI) }) it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {