mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
Tracking OPC fees (#593)
* Tracking OPC fees * Updating tests * Updating tests * Using basetoken decimals when tracking oceanFeeAmount * Comparing the value of oceanFeeAmount returned from the event to the value stored in the subgraph * Tracking consumeMarketFeeAmount and marketFeeAmount
This commit is contained in:
parent
957488077b
commit
9c56b00faa
@ -257,6 +257,9 @@ type FixedRateExchangeSwap @entity {
|
||||
block: Int!
|
||||
createdTimestamp: Int!
|
||||
tx: String!
|
||||
oceanFeeAmount: BigDecimal!
|
||||
marketFeeAmount: BigDecimal!
|
||||
consumeMarketFeeAmount: BigDecimal!
|
||||
}
|
||||
|
||||
|
||||
|
@ -191,6 +191,20 @@ export function handleSwap(event: Swapped): void {
|
||||
BigInt.fromI32(18).toI32()
|
||||
)
|
||||
|
||||
// Track fees
|
||||
swap.oceanFeeAmount = weiToDecimal(
|
||||
event.params.oceanFeeAmount.toBigDecimal(),
|
||||
BigInt.fromI32(baseToken.decimals).toI32()
|
||||
)
|
||||
swap.marketFeeAmount = weiToDecimal(
|
||||
event.params.marketFeeAmount.toBigDecimal(),
|
||||
BigInt.fromI32(baseToken.decimals).toI32()
|
||||
)
|
||||
swap.consumeMarketFeeAmount = weiToDecimal(
|
||||
event.params.consumeMarketFeeAmount.toBigDecimal(),
|
||||
BigInt.fromI32(baseToken.decimals).toI32()
|
||||
)
|
||||
|
||||
swap.save()
|
||||
|
||||
updateFixedRateExchangeSupply(event.params.exchangeId, event.address)
|
||||
|
@ -584,6 +584,9 @@ describe('Fixed Rate Exchange tests', async () => {
|
||||
block
|
||||
createdTimestamp
|
||||
tx
|
||||
oceanFeeAmount
|
||||
marketFeeAmount
|
||||
consumeMarketFeeAmount
|
||||
__typename
|
||||
}
|
||||
}}`
|
||||
@ -626,6 +629,17 @@ describe('Fixed Rate Exchange tests', async () => {
|
||||
const tx = (
|
||||
await fixedRate.buyDatatokens(user1, exchangeId, dtAmount, '100')
|
||||
).events?.Swapped
|
||||
|
||||
const oceanFeeAmount = web3.utils.fromWei(
|
||||
new BN(tx.returnValues.oceanFeeAmount)
|
||||
)
|
||||
const marketFeeAmount = web3.utils.fromWei(
|
||||
new BN(tx.returnValues.marketFeeAmount)
|
||||
)
|
||||
const consumeMarketFeeAmount = web3.utils.fromWei(
|
||||
new BN(tx.returnValues.consumeMarketFeeAmount)
|
||||
)
|
||||
|
||||
await sleep(sleepMs)
|
||||
user1Balance = await datatoken.balance(datatokenAddress, user1)
|
||||
// user1 has 1 datatoken
|
||||
@ -648,6 +662,12 @@ describe('Fixed Rate Exchange tests', async () => {
|
||||
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.marketFeeAmount === marketFeeAmount, 'wrong marketFeeAmount')
|
||||
assert(
|
||||
swaps.consumeMarketFeeAmount === consumeMarketFeeAmount,
|
||||
'wrong consumeMarketFeeAmount'
|
||||
)
|
||||
assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
|
||||
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
|
||||
})
|
||||
@ -655,6 +675,9 @@ describe('Fixed Rate Exchange tests', 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 = {
|
||||
@ -668,6 +691,7 @@ describe('Fixed Rate Exchange tests', async () => {
|
||||
block
|
||||
createdTimestamp
|
||||
tx
|
||||
oceanFeeAmount
|
||||
__typename
|
||||
}
|
||||
}}`
|
||||
@ -689,6 +713,7 @@ describe('Fixed Rate Exchange tests', async () => {
|
||||
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.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user