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

Implement UI for l2 transactions #409

Merged
merged 80 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
af71d4c
implement initial l2 ui
torztomasz Jun 8, 2023
4f122d6
implement l2 transaction type free form components
torztomasz Jun 9, 2023
3920133
implement basic l2 transaction details pages
torztomasz Jun 12, 2023
8490516
separate starkware schema into files
torztomasz Jun 12, 2023
3e650a9
refactor L2Transaction -> PerpetualL2Transaction
torztomasz Jun 12, 2023
774172c
add l2 transaction badge
torztomasz Jun 12, 2023
efc6381
add replaced tx indicators
torztomasz Jun 13, 2023
b5d2622
add l2 transaction route for preview
torztomasz Jun 13, 2023
c5f707b
fix l2 transaction table link
torztomasz Jun 13, 2023
37ff812
add findByTransactionId to L2TransactionRepository
torztomasz Jun 13, 2023
2b64824
implement AggregatedL2Transaction and L2TransactionController
torztomasz Jun 13, 2023
6ee9ef9
clean up frontend router
torztomasz Jun 13, 2023
7651f92
refactor l2 transaction free form components
torztomasz Jun 13, 2023
f8a0541
fix displaying trade transaction free form
torztomasz Jun 13, 2023
c624d03
restructure l2-transaction folder
torztomasz Jun 13, 2023
6fbf273
fix linter errors
torztomasz Jun 13, 2023
e9a597a
change replaced icon color
torztomasz Jun 13, 2023
a36c2da
add tooltips
torztomasz Jun 13, 2023
aaae079
use makeQuery in every script
torztomasz Jun 13, 2023
e219f72
fix tooltip content of alternative icon
torztomasz Jun 13, 2023
d878bb5
align styling
torztomasz Jun 13, 2023
2d204ac
change casing of words
torztomasz Jun 13, 2023
b54c0a9
show only user l2 transactions for user on preview
torztomasz Jun 13, 2023
33205d2
rename bucket.ts to Bucket.ts
torztomasz Jun 14, 2023
7c10b98
remove old css
torztomasz Jun 14, 2023
fc95241
add apex logo
torztomasz Jun 14, 2023
2f2fe20
add ForcedWithdrawal free form component
torztomasz Jun 14, 2023
81a5ada
implement correct way of displaying trade transaction in table
torztomasz Jun 14, 2023
c313c45
add L2 transaction trade details component
torztomasz Jun 14, 2023
a43f965
add collateral id sanity check for trade details
torztomasz Jun 14, 2023
310ec12
implement l2 forced trade details
torztomasz Jun 14, 2023
5ce3445
fix L2TransactionRepository method wrapping
torztomasz Jun 14, 2023
e06df02
implement distinct count for transactions
torztomasz Jun 14, 2023
d01ef28
adjust trade details fields
torztomasz Jun 14, 2023
9753b58
implement basic view for multi and alternative transactions
torztomasz Jun 15, 2023
b06e7be
add more routes to preview
torztomasz Jun 15, 2023
1b7aa30
make home l2 transactions page description correct
torztomasz Jun 16, 2023
a0e85eb
extract mutli and alternative notes to separate files
torztomasz Jun 16, 2023
dd23d50
improve alternative and multi notes
torztomasz Jun 16, 2023
315df7c
add multi and alternative transaction notes designs
torztomasz Jun 19, 2023
e9eccf9
add icons to l2 transactions table
torztomasz Jun 19, 2023
c2044f6
implement L2TransactionsList
torztomasz Jun 19, 2023
e315eac
remove l2 multi or altenratives table
torztomasz Jun 19, 2023
7599ebb
remove invalid icon property
torztomasz Jun 19, 2023
04f9484
fix l2 transaction list item href
torztomasz Jun 19, 2023
53bf010
refactor getLink function
torztomasz Jun 19, 2023
178d653
add missing l2 transaction routes
torztomasz Jun 19, 2023
171bba9
add Deleverage details
torztomasz Jun 19, 2023
c06519c
add Liquidate details
torztomasz Jun 19, 2023
64f379d
add funding tick details
torztomasz Jun 19, 2023
87c77b0
implement oracle prices tick details
torztomasz Jun 19, 2023
2830f21
adjust l2 transactions list design
torztomasz Jun 19, 2023
84d6c61
add multi as alternative preview route
torztomasz Jun 20, 2023
80fef23
adjust spacing on l2 details page
torztomasz Jun 20, 2023
5118019
fix linter errors
torztomasz Jun 20, 2023
c979f35
put l2 tx state before free form in table
torztomasz Jun 20, 2023
834c2e1
Merge branch 'master' into implement-ui-for-l2-transactions
torztomasz Jun 20, 2023
213e56b
after merge fixes
torztomasz Jun 20, 2023
361a351
display correct asset price in oracle prices tick details
torztomasz Jun 20, 2023
3ae1a89
Merge branch 'master' into implement-ui-for-l2-transactions
torztomasz Jun 20, 2023
04e1112
clean up L2TransactionController
torztomasz Jun 20, 2023
44243c3
do not show empty div
torztomasz Jun 21, 2023
843a2d7
Merge branch 'master' into implement-ui-for-l2-transactions
torztomasz Jun 21, 2023
9a92dc4
add getPaginatedWithoutMultiByStateUpdateId to L2TransactionRepository
torztomasz Jun 21, 2023
ac6da54
add l2 transactions table to state update page
torztomasz Jun 21, 2023
6c381a1
add state update l2 transactions page
torztomasz Jun 21, 2023
07492a6
fix not found after clicking transaction in preview
torztomasz Jun 21, 2023
a0a82ee
add countAllDistinctTransactionIdsByStateUpdateId
torztomasz Jun 21, 2023
8e26800
remove .only from test files
torztomasz Jun 21, 2023
d1a2f84
add mising controller part of state update l2 transactions
torztomasz Jun 21, 2023
419f381
add state update l2 transactions page to router
torztomasz Jun 21, 2023
76b5418
fix linter errors
torztomasz Jun 21, 2023
317b71a
adjust styling
torztomasz Jun 22, 2023
de065e0
add missing transaction free forms
torztomasz Jun 22, 2023
962667b
move transaction id to the banners if multi or alt
torztomasz Jun 22, 2023
824085e
remove liquidator fee from liquidate details
torztomasz Jun 22, 2023
e4ca5af
fix forced form
torztomasz Jun 23, 2023
c973e19
increase timeout for feeder gateway
torztomasz Jun 23, 2023
524b9b3
sync transactions on every block rather than on every state update
torztomasz Jun 29, 2023
4633b42
Merge branch 'master' into implement-ui-for-l2-transactions
torztomasz Jul 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions packages/backend/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApiServer } from './api/ApiServer'
import { ForcedActionController } from './api/controllers/ForcedActionController'
import { ForcedTradeOfferController } from './api/controllers/ForcedTradeOfferController'
import { HomeController } from './api/controllers/HomeController'
import { L2TransactionController } from './api/controllers/L2TransactionController'
import { MerkleProofController } from './api/controllers/MerkleProofController'
import { SearchController } from './api/controllers/SearchController'
import { StateUpdateController } from './api/controllers/StateUpdateController'
Expand Down Expand Up @@ -88,6 +89,7 @@ import { FeederGatewayClient } from './peripherals/starkware/FeederGatewayClient
import { FetchClient } from './peripherals/starkware/FetchClient'
import { handleServerError, reportError } from './tools/ErrorReporter'
import { Logger } from './tools/Logger'
import { shouldShowL2Transactions } from './utils/shouldShowL2Transactions'

export class Application {
start: () => Promise<void>
Expand Down Expand Up @@ -159,6 +161,11 @@ export class Application {
logger
)

const l2TransactionRepository = new L2TransactionRepository(
database,
logger
)

const ethereumClient = new EthereumClient(
config.starkex.blockchain.jsonRpcUrl,
config.starkex.blockchain.safeBlockDistance
Expand Down Expand Up @@ -234,10 +241,7 @@ export class Application {
config.starkex.contracts.perpetual
)
stateTransitionCollector = perpetualValidiumStateTransitionCollector
const transactionRepository = new L2TransactionRepository(
database,
logger
)

const feederGatewayClient = config.starkex.feederGateway
? new FeederGatewayClient(
config.starkex.feederGateway,
Expand All @@ -248,7 +252,7 @@ export class Application {
feederGatewayCollector = feederGatewayClient
? new FeederGatewayCollector(
feederGatewayClient,
transactionRepository,
l2TransactionRepository,
stateUpdateRepository,
logger
)
Expand Down Expand Up @@ -523,13 +527,16 @@ export class Application {

// #endregion core
// #region api
const showL2Transactions = shouldShowL2Transactions(config)
const homeController = new HomeController(
pageContextService,
assetDetailsService,
forcedTradeOfferViewService,
userTransactionRepository,
forcedTradeOfferRepository,
preprocessedStateDetailsRepository
l2TransactionRepository,
preprocessedStateDetailsRepository,
showL2Transactions
)

const userController = new UserController(
Expand All @@ -539,19 +546,22 @@ export class Application {
sentTransactionRepository,
userTransactionRepository,
forcedTradeOfferRepository,
l2TransactionRepository,
userRegistrationEventRepository,
forcedTradeOfferViewService,
withdrawableAssetRepository,
preprocessedUserStatisticsRepository,
config.starkex.contracts.perpetual,
collateralAsset
showL2Transactions
)
const stateUpdateController = new StateUpdateController(
pageContextService,
assetDetailsService,
stateUpdateRepository,
userTransactionRepository,
preprocessedAssetHistoryRepository
l2TransactionRepository,
preprocessedAssetHistoryRepository,
showL2Transactions
)
const transactionController = new TransactionController(
pageContextService,
Expand All @@ -576,6 +586,11 @@ export class Application {
config.starkex.tradingMode
)

const l2TransactionController = new L2TransactionController(
pageContextService,
l2TransactionRepository
)

const userTransactionController = new TransactionSubmitController(
ethereumClient,
sentTransactionRepository,
Expand All @@ -601,9 +616,9 @@ export class Application {
forcedActionsController,
forcedTradeOfferController,
merkleProofController,
collateralAsset,
config.starkex.tradingMode,
searchController
searchController,
l2TransactionController,
config
),
createTransactionRouter(
forcedTradeOfferController,
Expand Down
77 changes: 58 additions & 19 deletions packages/backend/src/api/controllers/HomeController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
renderHomeL2TransactionsPage,
renderHomePage,
renderHomeStateUpdatesPage,
renderHomeTransactionsPage,
Expand All @@ -10,10 +11,12 @@ import { ForcedTradeOfferViewService } from '../../core/ForcedTradeOfferViewServ
import { PageContextService } from '../../core/PageContextService'
import { PaginationOptions } from '../../model/PaginationOptions'
import { ForcedTradeOfferRepository } from '../../peripherals/database/ForcedTradeOfferRepository'
import { L2TransactionRepository } from '../../peripherals/database/L2TransactionRepository'
import { PreprocessedStateDetailsRepository } from '../../peripherals/database/PreprocessedStateDetailsRepository'
import { UserTransactionData } from '../../peripherals/database/transactions/UserTransaction'
import { UserTransactionRepository } from '../../peripherals/database/transactions/UserTransactionRepository'
import { ControllerResult } from './ControllerResult'
import { l2TransactionToEntry } from './l2TransactionToEntry'
import { userTransactionToEntry } from './userTransactionToEntry'

const FORCED_TRANSACTION_TYPES: UserTransactionData['type'][] = [
Expand All @@ -29,7 +32,9 @@ export class HomeController {
private readonly forcedTradeOfferViewService: ForcedTradeOfferViewService,
private readonly userTransactionRepository: UserTransactionRepository,
private readonly forcedTradeOfferRepository: ForcedTradeOfferRepository,
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository
private readonly l2TransactionRepository: L2TransactionRepository,
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository,
private readonly showL2Transactions: boolean
) {}

async getHomePage(
Expand All @@ -38,13 +43,17 @@ export class HomeController {
const context = await this.pageContextService.getPageContext(givenUser)
const paginationOpts = { offset: 0, limit: 6 }
const [
l2Transactions,
l2TransactionsCount,
stateUpdates,
totalStateUpdates,
stateUpdatesCount,
forcedUserTransactions,
forcedUserTransactionsCount,
availableOffers,
availableOffersCount,
] = await Promise.all([
this.l2TransactionRepository.getPaginatedWithoutMulti(paginationOpts),
this.l2TransactionRepository.countAllDistinctTransactionIds(),
this.preprocessedStateDetailsRepository.getPaginated(paginationOpts),
this.preprocessedStateDetailsRepository.countAll(),
this.userTransactionRepository.getPaginated({
Expand All @@ -61,22 +70,30 @@ export class HomeController {
})

const collateralAsset = this.pageContextService.getCollateralAsset(context)
const transactions = forcedUserTransactions.map((t) =>
const forcedTransactionEntries = forcedUserTransactions.map((t) =>
userTransactionToEntry(t, collateralAsset, assetDetailsMap)
)

const stateUpdateEntries = stateUpdates.map((update) => ({
timestamp: update.timestamp,
id: update.stateUpdateId.toString(),
hash: update.stateTransitionHash,
updateCount: update.assetUpdateCount,
forcedTransactionCount: update.forcedTransactionCount,
}))

const content = renderHomePage({
context,
tutorials: [], // explicitly no tutorials
stateUpdates: stateUpdates.map((update) => ({
timestamp: update.timestamp,
id: update.stateUpdateId.toString(),
hash: update.stateTransitionHash,
updateCount: update.assetUpdateCount,
forcedTransactionCount: update.forcedTransactionCount,
})),
totalStateUpdates,
transactions,
l2Transactions: this.showL2Transactions
? {
data: l2Transactions.map(l2TransactionToEntry),
total: l2TransactionsCount,
}
: undefined,
stateUpdates: stateUpdateEntries,
totalStateUpdates: stateUpdatesCount,
forcedTransactions: forcedTransactionEntries,
totalForcedTransactions: forcedUserTransactionsCount,
// We use forcedTradeOfferToEntry here because we only need status from the offer,
// as we do not show other statuses on this page
Expand All @@ -88,6 +105,26 @@ export class HomeController {
return { type: 'success', content }
}

async getHomeL2TransactionsPage(
givenUser: Partial<UserDetails>,
pagination: PaginationOptions
): Promise<ControllerResult> {
const context = await this.pageContextService.getPageContext(givenUser)

const [total, l2Transactions] = await Promise.all([
this.l2TransactionRepository.countAllDistinctTransactionIds(),
this.l2TransactionRepository.getPaginatedWithoutMulti(pagination),
])

const content = renderHomeL2TransactionsPage({
context,
l2Transactions: l2Transactions.map(l2TransactionToEntry),
...pagination,
total,
})
return { type: 'success', content }
}

async getHomeStateUpdatesPage(
givenUser: Partial<UserDetails>,
pagination: PaginationOptions
Expand All @@ -99,15 +136,17 @@ export class HomeController {
this.preprocessedStateDetailsRepository.getPaginated(pagination),
])

const stateUpdateEntries = stateUpdates.map((update) => ({
timestamp: update.timestamp,
id: update.stateUpdateId.toString(),
hash: update.stateTransitionHash,
updateCount: update.assetUpdateCount,
forcedTransactionCount: update.forcedTransactionCount,
}))

const content = renderHomeStateUpdatesPage({
context,
stateUpdates: stateUpdates.map((update) => ({
timestamp: update.timestamp,
id: update.stateUpdateId.toString(),
hash: update.stateTransitionHash,
updateCount: update.assetUpdateCount,
forcedTransactionCount: update.forcedTransactionCount,
})),
stateUpdates: stateUpdateEntries,
...pagination,
total,
})
Expand Down
Loading