Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking OPC fees #593

Merged
merged 7 commits into from Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.graphql
Expand Up @@ -257,6 +257,7 @@ type FixedRateExchangeSwap @entity {
block: Int!
createdTimestamp: Int!
tx: String!
oceanFeeAmount: BigDecimal!
}


Expand Down
6 changes: 6 additions & 0 deletions src/mappings/fixedRateExchange.ts
Expand Up @@ -191,6 +191,12 @@ export function handleSwap(event: Swapped): void {
BigInt.fromI32(18).toI32()
)

// Track OPC swap fee
swap.oceanFeeAmount = weiToDecimal(
event.params.oceanFeeAmount.toBigDecimal(),
BigInt.fromI32(baseToken.decimals).toI32()
)

swap.save()

updateFixedRateExchangeSupply(event.params.exchangeId, event.address)
Expand Down
12 changes: 12 additions & 0 deletions test/integration/FixedRateExchange.test.ts
Expand Up @@ -584,6 +584,7 @@ describe('Fixed Rate Exchange tests', async () => {
block
createdTimestamp
tx
oceanFeeAmount
__typename
}
}}`
Expand Down Expand Up @@ -626,6 +627,11 @@ 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)
)

await sleep(sleepMs)
user1Balance = await datatoken.balance(datatokenAddress, user1)
// user1 has 1 datatoken
Expand All @@ -648,13 +654,17 @@ 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should compare the value from event to whatever is stored on subgraph
Let's not do math here, because that can change anytime

IE:
const oceanFeeAmount = String((Number(dtAmount) * Number(feeAmount)) / 100)
what if OPCFee amount is changed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point. I've updated this, thanks for the feedback

assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
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 = {
Expand All @@ -668,6 +678,7 @@ describe('Fixed Rate Exchange tests', async () => {
block
createdTimestamp
tx
oceanFeeAmount
__typename
}
}}`
Expand All @@ -689,6 +700,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')
})
Expand Down