Skip to content

Commit

Permalink
bump contracts & add optimism (#1786)
Browse files Browse the repository at this point in the history
* bump contracts

* fix contracts

* add optimism

* use upcoming barge

* update fre tests

* make sure all fres are withMint
  • Loading branch information
alexcos20 authored Nov 24, 2023
1 parent 4e86a2d commit 91460b9
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions src/config/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]

Expand Down
2 changes: 1 addition & 1 deletion test/integration/PublishFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
77 changes: 34 additions & 43 deletions test/unit/FixedRateExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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')
})
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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')
})
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/NftFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 91460b9

Please sign in to comment.