Skip to content

Commit

Permalink
Merge branch 'main' into feat/bridge-ui--integrate-thrirdparty-nft-su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
KorbinianK authored May 2, 2024
2 parents 38f0292 + 811fecb commit 90b4230
Show file tree
Hide file tree
Showing 36 changed files with 1,210 additions and 2,050 deletions.
33 changes: 15 additions & 18 deletions packages/bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@sveltejs/adapter-auto": "^2.1.1",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.30.4",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.7",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@types/debug": "^4.1.12",
"@types/object-hash": "^3.0.6",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitest/coverage-v8": "^1.4.0",
"@wagmi/cli": "^2.1.4",
"abitype": "^1.0.2",
"ajv": "^8.12.0",
"autoprefixer": "^10.4.18",
"daisyui": "^4.7.2",
"daisyui": "^4.10.3",
"dotenv": "^16.4.5",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -45,24 +45,23 @@
"lokijs": "^1.5.12",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"svelte": "^4.2.12",
"svelte-check": "^3.6.9",
"prettier-plugin-svelte": "^3.2.3",
"svelte": "^4.2.15",
"svelte-check": "^3.7.0",
"tailwindcss": "^3.4.3",
"ts-morph": "^19.0.0",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^4.5.3",
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^0.32.4",
"vitest": "^1.5.3",
"vitest-fetch-mock": "^0.2.2",
"vitest-mock-extended": "1.3.1"
},
"type": "module",
"dependencies": {
"@moralisweb3/common-evm-utils": "^2.26.1",
"@wagmi/connectors": "^4.1.18",
"@wagmi/core": "^2.8.0",
"@wagmi/connectors": "^4.3.1",
"@wagmi/core": "^2.8.1",
"@walletconnect/ethereum-provider": "^2.12.2",
"@walletconnect/modal": "^2.6.2",
"@web3modal/wagmi": "^4.1.11",
Expand All @@ -71,10 +70,8 @@
"buffer": "^6.0.3",
"debug": "^4.3.4",
"events": "^3.3.0",
"moralis": "^2.26.1",
"object-hash": "^3.0.0",
"pino-pretty": "^11.0.0",
"svelte-i18n": "^3.7.4",
"viem": "^2.7.11"
"svelte-i18n": "^4.0.0",
"viem": "^2.9.29"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@

<script lang="ts">
import { SvelteToast } from '@zerodevx/svelte-toast';
import type { SvelteToastOptions } from '@zerodevx/svelte-toast/stores';
const options: SvelteToastOptions = {
const options = {
duration: toastConfig.duration,
};
</script>
Expand Down
29 changes: 29 additions & 0 deletions packages/bridge-ui/src/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@ import dotenv from 'dotenv';
dotenv.config({ path: './.env.test' });

vi.mock('@wagmi/core');

// Source: https://github.com/vitest-dev/vitest/issues/4043#issuecomment-1905172846
// This snippet is needed in order to support Uint8Array with vitest and jsdom.
if (process.env.VITEST === 'true') {
class ESBuildAndJSDOMCompatibleTextEncoder extends TextEncoder {
constructor() {
super();
}

encode(input: string) {
if (typeof input !== 'string') {
throw new TypeError('`input` must be a string');
}

const decodedURI = decodeURIComponent(encodeURIComponent(input));
const arr = new Uint8Array(decodedURI.length);
const chars = decodedURI.split('');
for (let i = 0; i < chars.length; i++) {
arr[i] = decodedURI[i].charCodeAt(0);
}
return arr;
}
}

Object.defineProperty(global, 'TextEncoder', {
value: ESBuildAndJSDOMCompatibleTextEncoder,
writable: true,
});
}
2 changes: 1 addition & 1 deletion packages/bridge-ui/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sveltekit } from '@sveltejs/kit/vite';
import dotenv from 'dotenv';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineProject } from 'vitest/dist/config';

import { generateBridgeConfig } from './scripts/vite-plugins/generateBridgeConfig';
import { generateChainConfig } from './scripts/vite-plugins/generateChainConfig';
Expand All @@ -13,7 +13,7 @@ if (process.env.NODE_ENV === 'test') {
dotenv.config({ path: './.env.test' });
}

export default defineProject({
export default defineConfig({
build: {
sourcemap: true,
},
Expand Down
6 changes: 0 additions & 6 deletions packages/eventindexer/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ func InitFromConfig(ctx context.Context, api *API, cfg *Config) error {
return err
}

statRepository, err := repo.NewStatRepository(db)
if err != nil {
return err
}

nftBalanceRepository, err := repo.NewNFTBalanceRepository(db)
if err != nil {
return err
Expand All @@ -79,7 +74,6 @@ func InitFromConfig(ctx context.Context, api *API, cfg *Config) error {

srv, err := http.NewServer(http.NewServerOpts{
EventRepo: eventRepository,
StatRepo: statRepository,
NFTBalanceRepo: nftBalanceRepository,
ChartRepo: chartRepository,
Echo: echo.New(),
Expand Down
2 changes: 2 additions & 0 deletions packages/eventindexer/disperser/disperser.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (d *Disperser) Start() error {
return err
}

slog.Info("addresses", "addresses", addresses)

for _, address := range addresses {
slog.Info("dispersing to", "address", address)

Expand Down
104 changes: 0 additions & 104 deletions packages/eventindexer/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,110 +403,6 @@ func (g *Generator) queryByTask(task string, date time.Time) error {

// return early for array processing data
return nil
case tasks.TotalProofRewards:
var feeTokenAddresses []string = make([]string, 0)
// get unique fee token addresses
query := "SELECT DISTINCT(fee_token_address) FROM stats WHERE stat_type = ?"

err = g.db.GormDB().
Raw(query, eventindexer.StatTypeProofReward).
Scan(&feeTokenAddresses).Error
if err != nil {
return err
}

slog.Info("feeTokenAddresses", "addresses", feeTokenAddresses)

for _, feeTokenAddress := range feeTokenAddresses {
f := feeTokenAddress

var dailyProofRewards decimal.NullDecimal

// nolint: lll
query := "SELECT COALESCE(SUM(proof_reward), 0) FROM events WHERE event = ? AND DATE(transacted_at) = ? AND fee_token_address = ?"
err = g.db.GormDB().
Raw(query, eventindexer.EventNameBlockAssigned, dateString, f).
Scan(&dailyProofRewards).Error

if err != nil {
return err
}

tsdResult, err := g.previousDayTsdResultByTask(task, date, &f, nil)
if err != nil {
return err
}

result := tsdResult.Decimal.Add(dailyProofRewards.Decimal)

slog.Info("Query successful",
"task", task,
"date", dateString,
"result", result.String(),
"feeTokenAddress", f,
)

insertStmt := `
INSERT INTO time_series_data(task, value, date, fee_token_address)
VALUES (?, ?, ?, ?)`

err = g.db.GormDB().Exec(insertStmt, task, result, dateString, f).Error
if err != nil {
slog.Info("Insert failed", "task", task, "date", dateString, "error", err.Error())
return err
}
}

// return early for array processing data
return nil
case tasks.ProofRewardsPerDay:
var feeTokenAddresses []string = make([]string, 0)
// get unique fee token addresses
query := "SELECT DISTINCT(fee_token_address) FROM stats WHERE stat_type = ?"

err = g.db.GormDB().
Raw(query, eventindexer.EventNameBlockAssigned).
Scan(&feeTokenAddresses).Error
if err != nil {
return err
}

for _, feeTokenAddress := range feeTokenAddresses {
f := feeTokenAddress

var result decimal.Decimal

// nolint: lll
query := `SELECT COALESCE(SUM(proof_reward), 0) FROM events WHERE event = ? AND DATE(transacted_at) = ? AND fee_token_address = ?`
err = g.db.GormDB().
Raw(query, eventindexer.EventNameBlockAssigned, dateString, f).
Scan(&result).Error

if err != nil {
return err
}

slog.Info("Query successful",
"task", task,
"date", dateString,
"result", result.String(),
"feeTokenAddress", f,
)

insertStmt := `
INSERT INTO time_series_data(task, value, date, fee_token_address)
VALUES (?, ?, ?, ?)`

err = g.db.GormDB().Exec(insertStmt, task, result, dateString, f).Error
if err != nil {
slog.Info("Insert failed", "task", task, "date", dateString, "error", err.Error())
return err
}
}

// return early for array processing data
return nil

case tasks.BridgeMessagesSentPerDay:
err = g.eventCount(task, date, eventindexer.EventNameMessageSent, &result)
case tasks.TotalBridgeMessagesSent:
Expand Down
2 changes: 1 addition & 1 deletion packages/eventindexer/indexer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
L1TaikoAddress: common.HexToAddress(c.String(flags.L1TaikoAddress.Name)),
BridgeAddress: common.HexToAddress(c.String(flags.BridgeAddress.Name)),
AssignmentHookAddress: common.HexToAddress(c.String(flags.AssignmentHookAddress.Name)),
SgxVerifierAddress: common.HexToAddress(flags.SgxVerifierAddress.Name),
SgxVerifierAddress: common.HexToAddress(c.String(flags.SgxVerifierAddress.Name)),
SwapAddresses: swaps,
BlockBatchSize: c.Uint64(flags.BlockBatchSize.Name),
SubscriptionBackoff: c.Uint64(flags.SubscriptionBackoff.Name),
Expand Down
7 changes: 0 additions & 7 deletions packages/eventindexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var (
type Indexer struct {
accountRepo eventindexer.AccountRepository
eventRepo eventindexer.EventRepository
statRepo eventindexer.StatRepository
nftBalanceRepo eventindexer.NFTBalanceRepository
txRepo eventindexer.TransactionRepository

Expand Down Expand Up @@ -132,11 +131,6 @@ func InitFromConfig(ctx context.Context, i *Indexer, cfg *Config) error {
return err
}

statRepository, err := repo.NewStatRepository(db)
if err != nil {
return err
}

nftBalanceRepository, err := repo.NewNFTBalanceRepository(db)
if err != nil {
return err
Expand Down Expand Up @@ -209,7 +203,6 @@ func InitFromConfig(ctx context.Context, i *Indexer, cfg *Config) error {
i.blockSaveMutex = &sync.Mutex{}
i.accountRepo = accountRepository
i.eventRepo = eventRepository
i.statRepo = statRepository
i.nftBalanceRepo = nftBalanceRepository
i.txRepo = txRepository

Expand Down
Loading

0 comments on commit 90b4230

Please sign in to comment.