From 91460b9cf5d3efe46b3f0c6ec9d5a48fe0e9e36f Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 24 Nov 2023 15:12:21 +0200 Subject: [PATCH] bump contracts & add optimism (#1786) * bump contracts * fix contracts * add optimism * use upcoming barge * update fre tests * make sure all fres are withMint --- .github/workflows/ci.yml | 2 + package-lock.json | 14 ++--- package.json | 2 +- src/config/ConfigHelper.ts | 18 +++++++ test/integration/PublishFlows.test.ts | 2 +- test/unit/FixedRateExchange.test.ts | 77 ++++++++++++--------------- test/unit/NftFactory.test.ts | 2 +- test/unit/Router.test.ts | 2 +- 8 files changed, 65 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf43932ea..0667037b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,7 @@ jobs: with: repository: 'oceanprotocol/barge' path: 'barge' + ref: feature/bump_contracts_and_subgraph - name: Run Ganache with Barge working-directory: ${{ github.workspace }}/barge @@ -103,6 +104,7 @@ jobs: with: repository: 'oceanprotocol/barge' path: 'barge' + ref: feature/bump_contracts_and_subgraph - name: Login to Docker Hub if: ${{ env.DOCKERHUB_PASSWORD && env.DOCKERHUB_USERNAME }} diff --git a/package-lock.json b/package-lock.json index a90e75886..cd484bdcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.1.4", "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^1.1.14", + "@oceanprotocol/contracts": "^2.0.3", "cross-fetch": "^4.0.0", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -2963,9 +2963,9 @@ } }, "node_modules/@oceanprotocol/contracts": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz", - "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.0.3.tgz", + "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==" }, "node_modules/@octokit/auth-token": { "version": "3.0.3", @@ -19724,9 +19724,9 @@ } }, "@oceanprotocol/contracts": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz", - "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.0.3.tgz", + "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==" }, "@octokit/auth-token": { "version": "3.0.3", diff --git a/package.json b/package.json index ab4f41e84..b00fca454 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "web3": "^1.8.0" }, "dependencies": { - "@oceanprotocol/contracts": "^1.1.14", + "@oceanprotocol/contracts": "^2.0.3", "cross-fetch": "^4.0.0", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", diff --git a/src/config/ConfigHelper.ts b/src/config/ConfigHelper.ts index 2c2ea3f3f..45dc0ebc7 100644 --- a/src/config/ConfigHelper.ts +++ b/src/config/ConfigHelper.ts @@ -136,6 +136,24 @@ export const configHelperNetworks: Config[] = [ subgraphUri: 'https://subgraph.v4.genx.minimal-gaia-x.eu', explorerUri: 'https://explorer.genx.minimal-gaia-x.eu/', gasFeeMultiplier: 1 + }, + { + ...configHelperNetworksBase, + chainId: 10, + network: 'optimism', + nodeUri: 'https://mainnet.optimism.io', + subgraphUri: 'https://v4.subgraph.optimism.oceanprotocol.com', + explorerUri: 'https://optimistic.etherscan.io/', + gasFeeMultiplier: 1.1 + }, + { + ...configHelperNetworksBase, + chainId: 11155420, + network: 'optimism-sepolia', + nodeUri: 'https://sepolia.optimism.io', + subgraphUri: 'https://v4.subgraph.optimism-sepolia.oceanprotocol.com', + explorerUri: 'https://sepolia-optimism.etherscan.io/', + gasFeeMultiplier: 1.1 } ] diff --git a/test/integration/PublishFlows.test.ts b/test/integration/PublishFlows.test.ts index 84afb72aa..66af328e2 100644 --- a/test/integration/PublishFlows.test.ts +++ b/test/integration/PublishFlows.test.ts @@ -138,7 +138,7 @@ describe('Publish tests', async () => { fixedRate: '1', marketFee: '0', allowedConsumer: await publisherAccount.getAddress(), - withMint: false + withMint: true } const bundleNFT = await factory.createNftWithDatatokenWithFixedRate( diff --git a/test/unit/FixedRateExchange.test.ts b/test/unit/FixedRateExchange.test.ts index b615f6590..4e7156d2b 100644 --- a/test/unit/FixedRateExchange.test.ts +++ b/test/unit/FixedRateExchange.test.ts @@ -81,7 +81,7 @@ describe('Fixed Rate unit test', () => { fixedRate: '1', marketFee: '0.001', allowedConsumer: ZERO_ADDRESS, - withMint: false + withMint: true } const tx = await nftFactory.createNftWithDatatokenWithFixedRate( @@ -134,19 +134,16 @@ describe('Fixed Rate unit test', () => { await fixedRate.activate(exchangeId) expect(await fixedRate.isActive(exchangeId)).to.equal(true) }) - - it('#activateMint - should activate Mint(allows fixed rate contract to mint dts if required), if exchangeOwner', async () => { - expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) - await fixedRate.activateMint(exchangeId) - expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) - }) - it('#dectivateMint - should deactivate Mint if exchangeOwner', async () => { expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) await fixedRate.deactivateMint(exchangeId) expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) }) - + it('#activateMint - should activate Mint(allows fixed rate contract to mint dts if required), if exchangeOwner', async () => { + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) + await fixedRate.activateMint(exchangeId) + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) + }) it('#generate exchangeId - should generate a specific exchangeId', async () => { expect(await fixedRate.generateExchangeId(addresses.MockDAI, dtAddress)).to.equal( exchangeId @@ -175,7 +172,8 @@ describe('Fixed Rate unit test', () => { it('#getDatatokenSupply - should get the dt supply in the exchange', async () => { // exchange owner hasn't approved any DT for sell - expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('0.0') + // since fre is withMint, dtSupply is 2^256 + expect(parseFloat(await fixedRate.getDatatokenSupply(exchangeId))).to.greaterThan(0) }) it('#getBasetokenSupply - should get the bt supply in the exchange', async () => { @@ -319,8 +317,6 @@ describe('Fixed Rate unit test', () => { expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('10.0') // no BTs in the contract (except for the fees, but not accounted here) expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0.0') - // DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate) - expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('1000.0') }) it('#getExchange - should return exchange details', async () => { @@ -331,10 +327,11 @@ describe('Fixed Rate unit test', () => { expect(result.baseToken).to.equal(addresses.MockDAI) expect(result.datatoken).to.equal(dtAddress) expect(result.exchangeOwner).to.equal(await exchangeOwner.getAddress()) - expect(result.withMint).to.equal(false) + expect(result.withMint).to.equal(true) expect(result.dtBalance).to.equal('10.0') // balance in the fixedRate expect(result.btBalance).to.equal('0.0') // balance in the fixedRate - expect(result.dtSupply).to.equal('1000.0') // total supply available (owner allowance + dtBalance) + // since fre is withMint, dtSupply is 2^256 + expect(parseFloat(result.dtSupply)).to.gt(0) // total supply available (owner allowance + dtBalance) expect(result.btSupply).to.equal('0.0') // total supply available of baseToken in the contract expect(result.fixedRate).to.equal('1.0') }) @@ -391,9 +388,10 @@ describe('Fixed Rate unit test', () => { await fixedRate.collectDatatokens(exchangeId, result.dtBalance) // no more dts in the contract const result2 = await fixedRate.getExchange(exchangeId) + // since fre is withMint, dtSupply is 2^256 expect(result2.dtBalance).to.equal('0.0') - // Only allowance left since dt is ZERO - expect(result2.dtSupply).to.equal('990.0') + // since fre is withMint, dtSupply is 2^256 + expect(parseFloat(result2.dtSupply)).to.gt(0) }) it('#collectMarketFee- should collect marketFee and send it to marketFeeCollector, anyone can call it', async () => { @@ -462,7 +460,9 @@ describe('Fixed Rate unit test', () => { describe('Test a Fixed Rate Exchange with USDC (6 Decimals) as Basetoken', () => { it('#create an exchange', async () => { // CREATE AN Exchange + // since FRE is created without mint rights, owner has to send dt to that exchange // we prepare transaction parameters objects + const nftFactory = new NftFactory(addresses.ERC721Factory, exchangeOwner) const freParams: FreCreationParams = { @@ -475,7 +475,7 @@ describe('Fixed Rate unit test', () => { fixedRate: '1', marketFee: '0.001', allowedConsumer: ZERO_ADDRESS, - withMint: false + withMint: true } const tx = await nftFactory.createNftWithDatatokenWithFixedRate( @@ -528,18 +528,16 @@ describe('Fixed Rate unit test', () => { await fixedRate.activate(exchangeId) expect(await fixedRate.isActive(exchangeId)).to.equal(true) }) - - it('#activateMint - should activate Mint(allows fixed rate contract to mint dts if required), if exchangeOwner', async () => { - expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) - await fixedRate.activateMint(exchangeId) - expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) - }) - it('#dectivateMint - should deactivate Mint if exchangeOwner', async () => { expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) await fixedRate.deactivateMint(exchangeId) expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) }) + it('#activateMint - should activate Mint(allows fixed rate contract to mint dts if required), if exchangeOwner', async () => { + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) + await fixedRate.activateMint(exchangeId) + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) + }) it('#generate exchangeId - should generate a specific exchangeId', async () => { expect(await fixedRate.generateExchangeId(addresses.MockUSDC, dtAddress)).to.equal( @@ -564,8 +562,8 @@ describe('Fixed Rate unit test', () => { }) it('#getDatatokenSupply - should get the dt supply in the exchange', async () => { - // exchange owner hasn't approved any DT for sell - expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('0.0') + // fre has mint rights + expect(parseFloat(await fixedRate.getDatatokenSupply(exchangeId))).to.gt(0) }) it('#getBasetokenSupply - should get the bt supply in the exchange', async () => { @@ -594,15 +592,7 @@ describe('Fixed Rate unit test', () => { dtAddress, await exchangeOwner.getAddress(), '1000', - await exchangeOwner.getAddress() - ) - await approve( - exchangeOwner, - config, - await exchangeOwner.getAddress(), - dtAddress, - addresses.FixedPrice, - '1000' + fixedRate.address ) // user1 gets 100 USDC so he can buy DTs await transfer( @@ -709,8 +699,8 @@ describe('Fixed Rate unit test', () => { expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('10.0') // no BTs in the contract (except for the fees, but not accounted here) expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0.0') - // DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate) - expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('1000.0') + // DT supply is huge, cause fre has mint rights + expect(parseFloat(await fixedRate.getDatatokenSupply(exchangeId))).to.gt(1000) }) it('#getExchange - should return exchange details', async () => { @@ -721,10 +711,11 @@ describe('Fixed Rate unit test', () => { expect(result.baseToken).to.equal(addresses.MockUSDC) expect(result.datatoken).to.equal(dtAddress) expect(result.exchangeOwner).to.equal(await exchangeOwner.getAddress()) - expect(result.withMint).to.equal(false) + expect(result.withMint).to.equal(true) expect(result.dtBalance).to.equal('10.0') // balance in the fixedRate expect(result.btBalance).to.equal('0.0') // balance in the fixedRate - expect(result.dtSupply).to.equal('1000.0') // total supply available (owner allowance + dtBalance) + // since fre has mint rights, dtSupply is huge + expect(parseFloat(result.dtSupply)).to.gt(1000) // total supply available (owner allowance + dtBalance) expect(result.btSupply).to.equal('0.0') // total supply available of baseToken in the contract expect(result.fixedRate).to.equal('1.0') }) @@ -785,8 +776,8 @@ describe('Fixed Rate unit test', () => { // no more dts in the contract const result2 = await fixedRate.getExchange(exchangeId) expect(result2.dtBalance).to.equal('0.0') - // Only allowance left since dt is ZERO - expect(result2.dtSupply).to.equal('990.0') + // since fre has mint rights, dtSupply is huge + expect(parseFloat(result2.dtSupply)).to.gt(990) }) it('#updateMarketFee- should update Market fee if market fee collector', async () => { @@ -829,7 +820,7 @@ describe('Fixed Rate unit test', () => { fixedRate: '1', marketFee: '0.001', allowedConsumer: ZERO_ADDRESS, - withMint: false + withMint: true } dtParams.feeToken = addresses.MockDAI @@ -871,7 +862,7 @@ describe('Fixed Rate unit test', () => { fixedRate: '1', marketFee: '0.001', allowedConsumer: ZERO_ADDRESS, - withMint: false + withMint: true } dtParams.feeToken = addresses.MockUSDC diff --git a/test/unit/NftFactory.test.ts b/test/unit/NftFactory.test.ts index 4906b32a4..8fcd6a628 100644 --- a/test/unit/NftFactory.test.ts +++ b/test/unit/NftFactory.test.ts @@ -132,7 +132,7 @@ describe('Nft Factory test', () => { fixedRate: '1', marketFee: FEE, allowedConsumer: await user1.getAddress(), - withMint: false + withMint: true } const tx = await nftFactory.createNftWithDatatokenWithFixedRate( diff --git a/test/unit/Router.test.ts b/test/unit/Router.test.ts index 911415122..b2b73cf6f 100644 --- a/test/unit/Router.test.ts +++ b/test/unit/Router.test.ts @@ -130,7 +130,7 @@ describe('Router unit test', () => { fixedRate: RATE, marketFee: FEE, allowedConsumer: ZERO_ADDRESS, - withMint: false + withMint: true } const nftFactory = new NftFactory(addresses.ERC721Factory, factoryOwner)