Feature/add_optimism & use graph-node 0.33.0 (#742)

* bump contracts

* remove ss contracts

* add optimism

* fix

* use upcoming barge

* move deactivateMint and delete sell test

* add withMint=True and delete sell test

* fix lint

* more fixes

* more fixes
This commit is contained in:
Alex Coseru 2023-11-22 09:09:40 +02:00 committed by GitHub
parent fc07962311
commit 8bc4dab920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 371 additions and 636 deletions

View File

@ -37,7 +37,7 @@ jobs:
with:
repository: 'oceanprotocol/barge'
path: 'barge'
ref: main
ref: feature/bump_contracts_and_subgraph
- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_PASSWORD && env.DOCKERHUB_USERNAME }}
@ -51,8 +51,6 @@ jobs:
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh --with-thegraph --skip-subgraph-deploy --no-dashboard 2>&1 > start_ocean.log &
env:
CONTRACTS_VERSION: predictoor3
- run: npm ci

651
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,8 @@
"quickstart:bsc": "node ./scripts/generatenetworkssubgraphs.js bsc && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:oasis_saphire_testnet": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire_testnet && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:oasis_saphire": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:optimism": "node ./scripts/generatenetworkssubgraphs.js optimism && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:optimism_sepolia": "node ./scripts/generatenetworkssubgraphs.js optimism_sepolia && npm run codegen && npm run create:local && npm run deploy:local",
"create:thegraph": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://172.15.0.15:8020",
@ -79,7 +81,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@oceanprotocol/contracts": "^2.0.2",
"@oceanprotocol/contracts": "^2.0.3",
"@oceanprotocol/lib": "^2.7.0",
"cross-fetch": "^3.1.6",
"ethereumjs-util": "^7.1.5"

View File

@ -403,7 +403,6 @@ type Template @entity{
id: ID!
fixedRateTemplates: [String!]
dispenserTemplates: [String!]
ssTemplates: [String!]
}
# Not tracking allocationToId or idToAllocation

View File

@ -3,8 +3,6 @@ import {
TokenRemoved,
OPCFeeChanged,
FactoryRouter,
SSContractAdded,
SSContractRemoved,
FixedRateContractAdded,
FixedRateContractRemoved,
DispenserContractAdded,
@ -91,32 +89,6 @@ export function handleTokenRemoved(event: TokenRemoved): void {
opc.approvedTokens = newList
opc.save()
}
export function handleSSContractAdded(event: SSContractAdded): void {
// add token to approvedTokens
const templates = getTemplates()
let existingContracts: string[]
if (!templates.ssTemplates) existingContracts = []
else existingContracts = templates.ssTemplates as string[]
if (!existingContracts.includes(event.params.contractAddress.toHexString()))
existingContracts.push(event.params.contractAddress.toHexString())
templates.ssTemplates = existingContracts
templates.save()
}
export function handleSSContractRemoved(event: SSContractRemoved): void {
const templates = getTemplates()
const newList: string[] = []
let existingContracts: string[]
if (!templates.ssTemplates) existingContracts = []
else existingContracts = templates.ssTemplates as string[]
if (!existingContracts || existingContracts.length < 1) return
while (existingContracts.length > 0) {
const role = existingContracts.shift().toString()
if (!role) break
if (role != event.params.contractAddress.toHexString()) newList.push(role)
}
templates.ssTemplates = newList
templates.save()
}
export function handleFixedRateContractAdded(
event: FixedRateContractAdded

View File

@ -52,6 +52,11 @@ export function updateFixedRateExchangeSupply(
fixedRateDetails.value.value8.toBigDecimal(),
baseToken.decimals
)
// update withMint state
fixedRateExchange.withMint = fixedRateDetails.value.value11
// update active state
fixedRateExchange.active = fixedRateDetails.value.value6
fixedRateExchange.save()
}

View File

@ -268,10 +268,6 @@ dataSources:
handler: handleTokenRemoved
- event: OPCFeeChanged(indexed address,uint256,uint256,uint256,uint256)
handler: handleOPCFeeChanged
- event: SSContractAdded(indexed address,indexed address)
handler: handleSSContractAdded
- event: SSContractRemoved(indexed address,indexed address)
handler: handleSSContractRemoved
- event: FixedRateContractAdded(indexed address,indexed address)
handler: handleFixedRateContractAdded
- event: FixedRateContractRemoved(indexed address,indexed address)

View File

@ -44,7 +44,7 @@ describe('Fixed Rate Exchange tests', async () => {
const publishMarketSwapFee = '0.003'
const templateIndex = 1
const dtAmount = '10'
const datatoken = new Datatoken(web3, 8996)
// const datatoken = new Datatoken(web3, 8996)
let datatokenAddress: string
let fixedRateAddress: string
let baseTokenAddress: string
@ -108,7 +108,7 @@ describe('Fixed Rate Exchange tests', async () => {
fixedRate: price,
marketFee: publishMarketSwapFee,
allowedConsumer: ZERO_ADDRESS,
withMint: false
withMint: true
}
const result = await Factory.createNftWithDatatokenWithFixedRate(
@ -356,7 +356,8 @@ describe('Fixed Rate Exchange tests', async () => {
'incorrect value for: baseToken.id'
)
assert(
fixed.datatokenSupply === '0',
fixed.datatokenSupply ===
'115792089237316195423570985008687900000000000000000000000000',
'incorrect value for: datatokenSupply'
)
assert(
@ -378,7 +379,7 @@ describe('Fixed Rate Exchange tests', async () => {
fixed.allowedSwapper === ZERO_ADDRESS,
'incorrect value for: allowedSwapper'
)
assert(fixed.withMint === null, 'incorrect value for: withMint')
assert(fixed.withMint === true, 'incorrect value for: withMint')
assert(fixed.isMinter === null, 'incorrect value for: isMinter')
assert(fixed.updates, 'incorrect value for: updates.id')
assert(fixed.swaps, 'incorrect value for: swaps')
@ -496,125 +497,6 @@ describe('Fixed Rate Exchange tests', async () => {
'incorrect value: 3nd eventIndex'
)
})
it('Deactivates exchange', async () => {
const deactiveQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(deactiveQuery)
})
const initialActive = (await initialResponse.json()).data.fixedRateExchange
.active
assert(initialActive === true, 'incorrect value for: initialActive')
// Deactivate exchange
await fixedRate.deactivate(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(deactiveQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
'incorrect value: eventIndex'
)
})
it('Activates exchange', async () => {
const activeQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(activeQuery)
})
const initialActive = (await initialResponse.json()).data.fixedRateExchange
.active
assert(initialActive === false, 'incorrect value for: initialActive')
// Activate exchange
await fixedRate.activate(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(activeQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
'incorrect value: eventIndex'
)
})
it('Activate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const initialMint = (await initialResponse.json()).data.fixedRateExchange
.withMint
assert(initialMint === null, 'incorrect value for: initialMint')
// Activate minting
const tx = await fixedRate.activateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedMint.withMint === true, 'incorrect value for: updatedMint')
assert(
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
})
it('Deactivate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const initialMint = (await initialResponse.json()).data.fixedRateExchange
.withMint
assert(initialMint === true, 'incorrect value for: initialMint')
// Activate minting
const tx = await fixedRate.deactivateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedMint.withMint === false, 'incorrect value for: updatedMint')
assert(
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
})
it('User1 buys a datatoken', async () => {
const swapsQuery = {
@ -721,57 +603,63 @@ describe('Fixed Rate Exchange tests', async () => {
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
})
it('User1 sells a datatoken', async () => {
await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1)
const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9'))
.events?.Swapped
const oceanFeeAmount = web3.utils.fromWei(
new BN(tx.returnValues.oceanFeeAmount)
)
assert(tx != null)
await sleep(sleepMs)
const swapsQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){
swaps(orderBy: createdTimestamp, orderDirection: desc){
id
exchangeId{id}
by{id}
baseTokenAmount
dataTokenAmount
block
createdTimestamp
tx
eventIndex
oceanFeeAmount
__typename
}
}}`
it('Deactivate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
// Check initial swaps
const response = await fetch(subgraphUrl, {
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(swapsQuery)
body: JSON.stringify(mintingQuery)
})
const swaps = (await response.json()).data.fixedRateExchange.swaps[0]
const swappedAmount = web3.utils.fromWei(
new BN(tx.returnValues.baseTokenSwappedAmount)
)
const initialMint = (await initialResponse.json()).data.fixedRateExchange
.withMint
assert(initialMint === true, 'incorrect value for: initialMint')
// Activate minting
const tx = await fixedRate.deactivateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedMint.withMint === false, 'incorrect value for: updatedMint')
assert(
swaps.id ===
`${tx.transactionHash}-${fixedRateId}-${tx.logIndex.toFixed(1)}`,
'incorrect: id'
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
})
it('Activate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const initialMint = (await initialResponse.json()).data.fixedRateExchange
.withMint
assert(initialMint === false, 'incorrect value for: initialMint')
// Activate minting
const tx = await fixedRate.activateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(mintingQuery)
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedMint.withMint === true, 'incorrect value for: updatedMint')
assert(
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
assert(swaps.exchangeId.id === fixedRateId, 'incorrect: exchangeId')
assert(swaps.by.id === user1, 'incorrect value for: id')
assert(swaps.baseTokenAmount === swappedAmount, 'incorrect baseTokenAmount')
assert(swaps.dataTokenAmount === dtAmount, 'incorrect: dataTokenAmount')
assert(swaps.block === tx.blockNumber, 'incorrect value for: block')
assert(swaps.createdTimestamp >= time, 'incorrect: createdTimestamp')
assert(swaps.createdTimestamp < time + 25, 'incorrect: createdTimestamp 2')
assert(swaps.oceanFeeAmount === oceanFeeAmount, 'incorrect: oceanFeeAmount')
assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
})
it('Updates allowed swapper', async () => {
@ -810,4 +698,63 @@ describe('Fixed Rate Exchange tests', async () => {
'incorrect value for: eventIndex'
)
})
it('Deactivates exchange', async () => {
const deactiveQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(deactiveQuery)
})
const initialActive = (await initialResponse.json()).data.fixedRateExchange
.active
assert(initialActive === true, 'incorrect value for: initialActive')
// Deactivate exchange
await fixedRate.deactivate(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(deactiveQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex >= 0,
'incorrect value: eventIndex'
)
})
it('Activates exchange', async () => {
const activeQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(activeQuery)
})
const initialActive = (await initialResponse.json()).data.fixedRateExchange
.active
assert(initialActive === false, 'incorrect value for: initialActive')
// Activate exchange
await fixedRate.activate(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
const updatedResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(activeQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex >= 0,
'incorrect value: eventIndex'
)
})
})

View File

@ -64,7 +64,7 @@ describe('User tests', async () => {
const publishMarketSwapFee = '0.003'
const templateIndex = 1
const dtAmount = '10'
const datatoken = new Datatoken(web3, 8996)
// const datatoken = new Datatoken(web3, 8996)
let datatokenAddress: string
let fixedRateAddress: string
let baseTokenAddress: string
@ -123,7 +123,7 @@ describe('User tests', async () => {
fixedRate: price,
marketFee: publishMarketSwapFee,
allowedConsumer: ZERO_ADDRESS,
withMint: false
withMint: true
}
const result = await Factory.createNftWithDatatokenWithFixedRate(
@ -196,27 +196,6 @@ describe('User tests', async () => {
assert(user.totalSales === '0', 'incorrect value for: totalSales')
assert(user.__typename === 'User', 'incorrect value for: __typename')
})
it('User1 sells a datatoken', async () => {
const initialUser = await userQuery(user1)
await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1)
const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9'))
.events?.Swapped
assert(tx != null)
const user = await userQuery(user1)
assert(user.id === user1, 'incorrect value for: id')
assert(user.tokenBalancesOwned.length === 0, 'incorrect tokenBalancesOwned')
assert(user.orders.length === 0, 'incorrect value for: orders')
assert(
user.freSwaps.length === initialUser.freSwaps.length,
'incorrect value for: freSwaps'
)
assert(user.totalOrders === '0', 'incorrect value for: totalOrders')
assert(user.totalSales === '0', 'incorrect value for: totalSales')
assert(user.__typename === 'User', 'incorrect value for: __typename')
})
it('Check user fields after publishing & ordering a datatoken', async () => {
// Start with publishing a new datatoken
const nftParams: NftCreateData = {