-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PT-3255): update approval on bid execution (#714)
* feat(PT-3255): update approval on bid execution * feat(PT-3255): update approval on bid execution * feat(PT-3255): update approval on bid execution
- Loading branch information
1 parent
3e91402
commit ebb7b95
Showing
13 changed files
with
420 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...src/main/kotlin/com/rarible/protocol/erc20/listener/listener/OrderActivityEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.rarible.protocol.erc20.listener.listener | ||
|
||
import com.rarible.core.kafka.RaribleKafkaEventHandler | ||
import com.rarible.protocol.dto.Erc20AssetTypeDto | ||
import com.rarible.protocol.dto.EthActivityEventDto | ||
import com.rarible.protocol.dto.OrderActivityMatchDto | ||
import com.rarible.protocol.dto.OrderActivityMatchSideDto | ||
import com.rarible.protocol.dto.toModel | ||
import com.rarible.protocol.erc20.core.misc.addIndexerIn | ||
import com.rarible.protocol.erc20.core.model.BalanceId | ||
import com.rarible.protocol.erc20.core.service.Erc20AllowanceService | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class OrderActivityEventHandler( | ||
private val erc20AllowanceService: Erc20AllowanceService, | ||
) : RaribleKafkaEventHandler<EthActivityEventDto> { | ||
|
||
override suspend fun handle(event: EthActivityEventDto) { | ||
val activity = event.activity | ||
if (activity !is OrderActivityMatchDto) { | ||
return | ||
} | ||
logger.info("Handle event: $event") | ||
if (activity.type == OrderActivityMatchDto.Type.ACCEPT_BID) { | ||
handleActivity(activity, event) | ||
} | ||
} | ||
|
||
private suspend fun handleActivity( | ||
activity: OrderActivityMatchDto, | ||
event: EthActivityEventDto | ||
) { | ||
val sideDto = if (activity.left.type == OrderActivityMatchSideDto.Type.BID) { | ||
activity.left | ||
} else { | ||
activity.right | ||
} | ||
val assetType = sideDto.asset.assetType | ||
if (assetType is Erc20AssetTypeDto) { | ||
val owner = sideDto.maker | ||
val token = assetType.contract | ||
logger.info( | ||
"Will recalculate erc20 balance owner=$owner, token=$token. " + | ||
"After bid execution id=${sideDto.hash}" | ||
) | ||
erc20AllowanceService.onChainUpdate( | ||
balanceId = BalanceId(token = token, owner = owner), | ||
eventTimeMarks = event.eventTimeMarks.toModel().addIndexerIn(), | ||
event = null, | ||
) | ||
} | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(OrderActivityEventHandler::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.