Skip to content

Commit 1cfe520

Browse files
authored
fix lp fee and publish market fee (#368)
* add lp fee * add publish market fee * fix lint
1 parent ab2d804 commit 1cfe520

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

schema.graphql

+9-8
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ type Pool @entity {
135135
datatokenLiquidity: BigDecimal!
136136
datatokenWeight: BigDecimal!
137137

138-
"publisher market fee : SWAP, JOIN , EXIT"
139-
marketSwapFee: BigDecimal!
138+
"publisher market fee value"
139+
publishMarketSwapFee: BigDecimal!
140+
"publisher market fee total amount"
141+
publishMarketSwapFeeAmount: BigDecimal
140142

141-
"liquidity provider fee"
142-
liquidityProviderFee: BigDecimal!
143+
"Liquidty provider fee value"
144+
liquidityProviderSwapFee: BigDecimal
145+
"liquidity provider fee total amount"
146+
liquidityProviderSwapFeeAmount: BigDecimal!
143147

144148
"OPF Fee percent, fee that goes to Ocean Protocol Foundation : SWAP"
145149
opcFee: BigDecimal!
@@ -177,11 +181,8 @@ type Pool @entity {
177181
"address of the market where the datatoken was created. This address collects market fees."
178182
publishMarketFeeAddress: String
179183

180-
"fee amount. Fixed value, expressed in wei in contracts, needs conversion in decimals."
181-
publishMarketSwapFee: BigDecimal
184+
182185

183-
"LP fee amount. Fixed value, expressed in wei in contracts, needs conversion in decimals."
184-
liquidityProviderSwapFee: BigDecimal
185186

186187
}
187188

src/mappings/pool.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import {
2121
getPool,
2222
getPoolTransaction,
2323
getPoolShare,
24-
getPoolSnapshot
24+
getPoolSnapshot,
25+
getPoolLpSwapFee,
26+
getPoolPublisherMarketFee
2527
} from './utils/poolUtils'
2628
import { getToken } from './utils/tokenUtils'
2729
import { getUser } from './utils/userUtils'
@@ -219,6 +221,12 @@ export function handleSetup(event: LOG_SETUP): void {
219221
pool.save()
220222
poolTx.save()
221223

224+
const lpFee = getPoolLpSwapFee(event.address)
225+
pool.liquidityProviderSwapFee = lpFee
226+
const publisherMarketFee = getPoolPublisherMarketFee(event.address)
227+
pool.publishMarketSwapFee = publisherMarketFee
228+
229+
pool.save()
222230
const poolSnapshot = getPoolSnapshot(pool.id, event.block.timestamp.toI32())
223231
poolSnapshot.spotPrice = spotPrice
224232
poolSnapshot.baseTokenLiquidity = pool.baseTokenLiquidity

src/mappings/utils/poolUtils.ts

+13
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,16 @@ export function getPoolSnapshot(
128128

129129
return snapshot
130130
}
131+
132+
export function getPoolLpSwapFee(poolAddress: Address): BigDecimal {
133+
const contract = BPool.bind(poolAddress)
134+
const lpFeeWei = contract.getSwapFee()
135+
const lpFee = weiToDecimal(lpFeeWei.toBigDecimal(), 18)
136+
return lpFee
137+
}
138+
export function getPoolPublisherMarketFee(poolAddress: Address): BigDecimal {
139+
const contract = BPool.bind(poolAddress)
140+
const marketFeeWei = contract.getMarketFee()
141+
const marketFee = weiToDecimal(marketFeeWei.toBigDecimal(), 18)
142+
return marketFee
143+
}

0 commit comments

Comments
 (0)