fix poolSnapshot (#361)

This commit is contained in:
mihaisc 2022-02-25 11:18:49 +02:00 committed by GitHub
parent f03dce6497
commit f127e2206f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 41 deletions

View File

@ -45,31 +45,11 @@ export function handleJoin(event: LOG_JOIN): void {
if (token.isDatatoken) {
poolTx.datatoken = token.id
poolTx.datatokenValue = ammount
if (pool.isFinalized) {
const poolSnapshot = getPoolSnapshot(
pool.id,
event.block.timestamp.toI32()
)
poolSnapshot.datatokenLiquidity =
poolSnapshot.datatokenLiquidity.plus(ammount)
poolSnapshot.save()
}
pool.datatokenLiquidity = pool.datatokenLiquidity.plus(ammount)
} else {
poolTx.baseToken = token.id
poolTx.baseTokenValue = ammount
if (pool.isFinalized) {
const poolSnapshot = getPoolSnapshot(
pool.id,
event.block.timestamp.toI32()
)
poolSnapshot.baseTokenLiquidity =
poolSnapshot.baseTokenLiquidity.plus(ammount)
poolSnapshot.save()
}
pool.baseTokenLiquidity = pool.baseTokenLiquidity.plus(ammount)
addLiquidity(token.id, ammount)
@ -77,6 +57,14 @@ export function handleJoin(event: LOG_JOIN): void {
poolTx.save()
pool.save()
if (pool.isFinalized) {
const poolSnapshot = getPoolSnapshot(pool.id, event.block.timestamp.toI32())
poolSnapshot.baseTokenLiquidity = pool.baseTokenLiquidity
poolSnapshot.datatokenLiquidity = pool.datatokenLiquidity
poolSnapshot.totalShares = pool.totalShares
poolSnapshot.save()
}
}
export function handleExit(event: LOG_EXIT): void {
@ -98,21 +86,19 @@ export function handleExit(event: LOG_EXIT): void {
poolTx.datatoken = token.id
poolTx.datatokenValue = ammount.neg()
poolSnapshot.datatokenLiquidity =
poolSnapshot.datatokenLiquidity.minus(ammount)
pool.datatokenLiquidity.minus(ammount)
} else {
poolTx.baseToken = token.id
poolTx.baseTokenValue = ammount.neg()
poolSnapshot.baseTokenLiquidity =
poolSnapshot.baseTokenLiquidity.minus(ammount)
pool.baseTokenLiquidity.minus(ammount)
removeLiquidity(token.id, ammount)
}
poolSnapshot.baseTokenLiquidity = pool.baseTokenLiquidity
poolSnapshot.datatokenLiquidity = pool.datatokenLiquidity
poolSnapshot.totalShares = pool.totalShares
poolSnapshot.save()
poolTx.save()
pool.save()
@ -139,17 +125,12 @@ export function handleSwap(event: LOG_SWAP): void {
poolTx.datatokenValue = ammountOut.neg()
pool.datatokenLiquidity = pool.datatokenLiquidity.minus(ammountOut)
poolSnapshot.datatokenLiquidity =
poolSnapshot.datatokenLiquidity.minus(ammountOut)
} else {
poolTx.baseToken = tokenOut.id
poolTx.baseTokenValue = ammountOut.neg()
pool.baseTokenLiquidity = pool.baseTokenLiquidity.minus(ammountOut)
poolSnapshot.baseTokenLiquidity =
poolSnapshot.baseTokenLiquidity.minus(ammountOut)
poolSnapshot.swapVolume = poolSnapshot.swapVolume.plus(ammountOut)
addPoolSwap(tokenOut.id, ammountOut)
removeLiquidity(tokenOut.id, ammountOut)
@ -166,17 +147,12 @@ export function handleSwap(event: LOG_SWAP): void {
poolTx.datatokenValue = ammountIn
pool.datatokenLiquidity = pool.datatokenLiquidity.plus(ammountIn)
poolSnapshot.datatokenLiquidity =
poolSnapshot.datatokenLiquidity.plus(ammountIn)
} else {
poolTx.baseToken = tokenIn.id
poolTx.baseTokenValue = ammountIn
pool.baseTokenLiquidity = pool.baseTokenLiquidity.plus(ammountIn)
poolSnapshot.baseTokenLiquidity =
poolSnapshot.baseTokenLiquidity.plus(ammountIn)
poolSnapshot.swapVolume = poolSnapshot.swapVolume.plus(ammountIn)
addLiquidity(tokenIn.id, ammountIn)
addPoolSwap(tokenIn.id, ammountIn)
@ -192,6 +168,9 @@ export function handleSwap(event: LOG_SWAP): void {
)
pool.spotPrice = spotPrice
poolSnapshot.spotPrice = spotPrice
poolSnapshot.baseTokenLiquidity = pool.baseTokenLiquidity
poolSnapshot.datatokenLiquidity = pool.datatokenLiquidity
poolSnapshot.totalShares = pool.totalShares
poolSnapshot.save()
poolTx.save()

View File

@ -28,7 +28,7 @@ dataSources:
handler: handleNftCreated
- event: TokenCreated(indexed address,indexed address,string,string,uint256,address)
handler: handleNewToken
- kind: ethereum/contract
name: FactoryRouter
network: rinkeby
@ -71,7 +71,6 @@ dataSources:
handler: handleDispenserContractRemoved
templates:
- name: ERC20Template
kind: ethereum/contract
network: rinkeby
@ -263,4 +262,25 @@ templates:
- event: PublishMarketFeeChanged(indexed bytes32,address,address,uint256)
handler: handlePublishMarketFeeChanged
- event: TokenCollected(indexed bytes32,indexed address,indexed address,uint256)
handler: handleTokenCollected
handler: handleTokenCollected
- name: SSContract
kind: ethereum/contract
network: rinkeby
source:
abi: SSContract
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/mappings/sscontract.ts
entities:
- SSContract
abis:
- name: SSContract
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json
eventHandlers:
- event: VestingCreated(indexed address,indexed address,uint256,uint256)
handler: handleVestingCreated
- event: Vesting(indexed address,indexed address,indexed address,uint256)
handler: handleVesting