From d85bd3b1e9f7f1491036965035bb5c8b54c868a6 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Tue, 3 Sep 2024 09:46:46 +0800 Subject: [PATCH 1/5] chore: remove `/assets` api (#514) --- docs/openapi.json | 299 +----------------- internal/node/component/info/component.go | 1 - internal/node/component/info/handler_asset.go | 108 ------- schema/worker/decentralized/worker.go | 27 -- schema/worker/rss/worker.go | 4 - 5 files changed, 1 insertion(+), 438 deletions(-) delete mode 100644 internal/node/component/info/handler_asset.go diff --git a/docs/openapi.json b/docs/openapi.json index 558d62b3..6e82fbfb 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -329,26 +329,6 @@ } } }, - "/assets": { - "get": { - "summary": "Get Node Assets", - "description": "Retrieve node assets details.", - "tags": [ - "Info" - ], - "responses": { - "200": { - "$ref": "#/components/responses/AssetsResponse" - }, - "400": { - "$ref": "#/components/responses/BadRequest" - }, - "500": { - "$ref": "#/components/responses/InternalError" - } - } - } - }, "/info": { "get": { "summary": "Get Node Status", @@ -885,250 +865,6 @@ }, "type": "object" }, - "AssetsResponse": { - "properties": { - "data": { - "type": "object", - "properties": { - "networks": { - "type": "array", - "items":{ - "$ref": "#/components/schemas/AssetDetail" - } - }, - "workers": { - "type": "array", - "items":{ - "$ref": "#/components/schemas/AssetDetail" - } - } - } - } - }, - "type": "object", - "example": { - "data": { - "networks": { - "arbitrum": { - "type": "ethereum", - "name": "Arbitrum", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/arbitrum.svg" - }, - "arweave": { - "type": "arweave", - "name": "Arweave", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/arweave.svg" - }, - "avax": { - "type": "ethereum", - "name": "Avalanche", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/avalanche.svg" - }, - "base": { - "type": "ethereum", - "name": "Base", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/base.svg" - }, - "binance-smart-chain": { - "type": "ethereum", - "name": "Binance Smart Chain", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/binance-smart-chain.svg" - }, - "crossbell": { - "type": "ethereum", - "name": "Crossbell", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/crossbell.svg" - }, - "ethereum": { - "type": "ethereum", - "name": "Ethereum", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/ethereum.svg" - }, - "farcaster": { - "type": "farcaster", - "name": "Farcaster", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/farcaster.svg" - }, - "gnosis": { - "type": "ethereum", - "name": "Gnosis", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/gnosis-chain.svg" - }, - "linea": { - "type": "ethereum", - "name": "Linea", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/linea.svg" - }, - "optimism": { - "type": "ethereum", - "name": "Optimism", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/optimism.svg" - }, - "polygon": { - "type": "ethereum", - "name": "Polygon", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/polygon.svg" - }, - "vsl": { - "type": "ethereum", - "name": "VSL", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3-vsl.svg" - }, - "x-layer": { - "type": "ethereum", - "name": "X Layer", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/x-layer.svg" - } - }, - "workers": { - "1inch": { - "type": "decentralized", - "name": "1inch", - "platform": "1inch", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/1inch.svg" - }, - "aave": { - "type": "decentralized", - "name": "aave", - "platform": "AAVE", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/aave.svg" - }, - "aavegotchi": { - "type": "decentralized", - "name": "aavegotchi", - "platform": "Aavegotchi", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/aavegotchi.svg" - }, - "core": { - "type": "decentralized", - "name": "core", - "platform": "Unknown", - "icon_url": "" - }, - "crossbell": { - "type": "decentralized", - "name": "crossbell", - "platform": "Crossbell", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/crossbell.svg" - }, - "curve": { - "type": "decentralized", - "name": "curve", - "platform": "Curve", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/curve.svg" - }, - "ens": { - "type": "decentralized", - "name": "ens", - "platform": "ENS", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/ens.svg" - }, - "highlight": { - "type": "decentralized", - "name": "highlight", - "platform": "Highlight", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/highlight.svg" - }, - "iqwiki": { - "type": "decentralized", - "name": "iqwiki", - "platform": "IQWiki", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/iqwiki.svg" - }, - "kiwistand": { - "type": "decentralized", - "name": "kiwistand", - "platform": "KiwiStand", - "icon_url": "https://storage.googleapis.com/rss3-icon/kiwistand.png" - }, - "lens": { - "type": "decentralized", - "name": "lens", - "platform": "Lens", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/lens.svg" - }, - "lido": { - "type": "decentralized", - "name": "lido", - "platform": "Lido", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/lido.svg" - }, - "looksrare": { - "type": "decentralized", - "name": "looksrare", - "platform": "LooksRare", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/looks-rare.svg" - }, - "matters": { - "type": "decentralized", - "name": "matters", - "platform": "Matters", - "icon_url": "https://storage.googleapis.com/rss3-icon/matters.jpg" - }, - "mirror": { - "type": "decentralized", - "name": "mirror", - "platform": "Mirror", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/mirror.svg" - }, - "momoka": { - "type": "decentralized", - "name": "momoka", - "platform": "Lens", - "icon_url": "https://storage.googleapis.com/rss3-icon/momoka.png" - }, - "opensea": { - "type": "decentralized", - "name": "opensea", - "platform": "OpenSea", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/opensea.svg" - }, - "optimism": { - "type": "decentralized", - "name": "optimism", - "platform": "Optimism", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/optimism.svg" - }, - "paragraph": { - "type": "decentralized", - "name": "paragraph", - "platform": "Paragraph", - "icon_url": "https://storage.googleapis.com/rss3-icon/paragraph.png" - }, - "rss3": { - "type": "decentralized", - "name": "rss3", - "platform": "RSS3", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3.svg" - }, - "rsshub": { - "type": "rss", - "name": "rsshub", - "platform": "RSSHub", - "icon_url": "https://storage.googleapis.com/rss3-icon/rsshub.png" - }, - "stargate": { - "type": "decentralized", - "name": "stargate", - "platform": "Stargate", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/stargate.svg" - }, - "uniswap": { - "type": "decentralized", - "name": "uniswap", - "platform": "Uniswap", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/uniswap.svg" - }, - "vsl": { - "type": "decentralized", - "name": "vsl", - "platform": "VSL", - "icon_url": "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3-vsl.svg" - } - } - } - } - }, "NodeInfo": { "properties": { "operator": { @@ -1449,29 +1185,6 @@ }, "type": "object" }, - "AssetDetail": { - "description": "The details of an asset (network or worker).", - "properties": { - "type": { - "description": "The type of the asset.", - "type": "string" - }, - "name": { - "description": "The name of the asset.", - "type": "string" - }, - "platform": { - "description": "The platform of the asset (for workers only).", - "type": "string" - }, - "icon_url": { - "description": "The URL of the asset's icon.", - "type": "string" - } - }, - "required": ["type", "name", "icon_url"], - "type": "object" - }, "ConfigDetail": { "type": "object", "required": ["is_required", "type", "value", "description"], @@ -1571,7 +1284,7 @@ "description": "The network on which activities occur.", "type": "string", "example": "ethereum", - "enum": ["arbitrum","arweave","avax","base","binance-smart-chain","crossbell","ethereum","farcaster","gnosis","linea","optimism","polygon","vsl","x-layer"] + "enum": ["arbitrum","arweave","avax","base","binance-smart-chain","crossbell","ethereum","farcaster","gnosis","linea","mastodon","optimism","polygon","vsl","x-layer"] }, "Platform": { "description": "The platform on which activities occur.", @@ -1707,16 +1420,6 @@ } } }, - "AssetsResponse": { - "description": "The request was successful.", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AssetsResponse" - } - } - } - }, "BadRequest": { "description": "The request is malformed or contains invalid parameters.", "content": { diff --git a/internal/node/component/info/component.go b/internal/node/component/info/component.go index be5f7080..79633b26 100644 --- a/internal/node/component/info/component.go +++ b/internal/node/component/info/component.go @@ -49,7 +49,6 @@ func NewComponent(_ context.Context, apiServer *echo.Echo, config *config.File, apiServer.GET("/version", c.GetVersion) apiServer.GET("/activity_count", c.GetActivityCount) apiServer.GET("/workers_status", c.GetWorkersStatus) - apiServer.GET("/assets", c.GetNodeAssets) networks := apiServer.Group("/networks") diff --git a/internal/node/component/info/handler_asset.go b/internal/node/component/info/handler_asset.go deleted file mode 100644 index 852bc0ee..00000000 --- a/internal/node/component/info/handler_asset.go +++ /dev/null @@ -1,108 +0,0 @@ -package info - -import ( - "net/http" - - "github.com/labstack/echo/v4" - "github.com/rss3-network/node/schema/worker/decentralized" - "github.com/rss3-network/node/schema/worker/rss" - "github.com/rss3-network/protocol-go/schema/network" -) - -type AssetsResponse struct { - Data struct { - Networks map[string]AssetDetail `json:"networks"` - Workers map[string]AssetDetail `json:"workers"` - } `json:"data"` -} - -type AssetDetail struct { - Type string `json:"type"` - Name string `json:"name"` - Platform string `json:"platform,omitempty"` - IconURL string `json:"icon_url"` -} - -// GetNodeAssets returns the network, workers, and assets info. -func (c *Component) GetNodeAssets(ctx echo.Context) error { - response := AssetsResponse{} - response.Data.Networks = make(map[string]AssetDetail) - response.Data.Workers = make(map[string]AssetDetail) - - // Aggregate networks - for _, n := range network.NetworkValues() { - if n == network.Unknown || n == network.Bitcoin || n == network.Mastodon || n == network.RSS || n == network.SatoshiVM { - continue - } - - response.Data.Networks[n.String()] = AssetDetail{ - Type: string(n.Source()), - Name: NetworkToNameMap[n], - IconURL: NetworkToIconURLMap[n], - } - } - - // Aggregate decentralized workers - for _, w := range decentralized.WorkerValues() { - if w.Name() == decentralized.SAVM.Name() { - continue - } - - platform := decentralized.ToPlatformMap[w] - response.Data.Workers[w.Name()] = AssetDetail{ - Name: w.Name(), - Platform: platform.String(), - Type: w.Component(), - IconURL: decentralized.ToIconURLMap[w], - } - } - - // Aggregate RSS workers - for _, w := range rss.WorkerValues() { - response.Data.Workers[w.Name()] = AssetDetail{ - Name: w.Name(), - Platform: "RSSHub", - Type: w.Component(), - IconURL: rss.ToIconURLMap[w], - } - } - - return ctx.JSON(http.StatusOK, response) -} - -var NetworkToNameMap = map[network.Network]string{ - network.Arbitrum: "Arbitrum", - network.Arweave: "Arweave", - network.Avalanche: "Avalanche", - network.Base: "Base", - network.BinanceSmartChain: "Binance Smart Chain", - network.Bitcoin: "Bitcoin", - network.Crossbell: "Crossbell", - network.Ethereum: "Ethereum", - network.Farcaster: "Farcaster", - network.Gnosis: "Gnosis", - network.Linea: "Linea", - network.Mastodon: "Mastodon", - network.Optimism: "Optimism", - network.Polygon: "Polygon", - network.SatoshiVM: "SatoshiVM", - network.VSL: "VSL", - network.XLayer: "X Layer", -} - -var NetworkToIconURLMap = map[network.Network]string{ - network.Arbitrum: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/arbitrum.svg", - network.Arweave: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/arweave-mono.svg", - network.Avalanche: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/avalanche.svg", - network.Base: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/base.svg", - network.BinanceSmartChain: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/binance-smart-chain.svg", - network.Crossbell: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/crossbell.svg", - network.Ethereum: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/ethereum-mono.svg", - network.Farcaster: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/farcaster.svg", - network.Gnosis: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/gnosis-chain-mono.svg", - network.Linea: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/linea-mono.svg", - network.Optimism: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/optimism.svg", - network.Polygon: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/polygon.svg", - network.VSL: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3-vsl.svg", - network.XLayer: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/x-layer-mono.svg", -} diff --git a/schema/worker/decentralized/worker.go b/schema/worker/decentralized/worker.go index be86dd58..bf99e309 100644 --- a/schema/worker/decentralized/worker.go +++ b/schema/worker/decentralized/worker.go @@ -87,30 +87,3 @@ var ToTagsMap = map[Worker][]tag.Tag{ Uniswap: {tag.Exchange, tag.Transaction}, VSL: {tag.Transaction}, } - -var ToIconURLMap = map[Worker]string{ - Aave: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/aave.svg", - Aavegotchi: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/aavegotchi.svg", - Core: "", - Crossbell: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/crossbell-alt.svg", - Curve: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/curve.svg", - ENS: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/ens.svg", - Highlight: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/highlight.svg", - IQWiki: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/iqwiki.svg", - KiwiStand: "https://storage.googleapis.com/rss3-icon/kiwistand.png", - Lens: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/lens.svg", - Lido: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/lido.svg", - Looksrare: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/looks-rare.svg", - Matters: "https://storage.googleapis.com/rss3-icon/matters.jpg", - Mirror: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/mirror.svg", - Momoka: "https://storage.googleapis.com/rss3-icon/momoka.png", - Oneinch: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/1inch.svg", - OpenSea: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/opensea.svg", - Optimism: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/optimism.svg", - Paragraph: "https://storage.googleapis.com/rss3-icon/paragraph.png", - RSS3: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3.svg", - SAVM: "", - Stargate: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/stargate.svg", - Uniswap: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/uniswap.svg", - VSL: "https://unpkg.com/@rss3/web3-icons-svg@latest/icons/rss3-vsl.svg", -} diff --git a/schema/worker/rss/worker.go b/schema/worker/rss/worker.go index 9c97d31f..f8417834 100644 --- a/schema/worker/rss/worker.go +++ b/schema/worker/rss/worker.go @@ -41,7 +41,3 @@ func GetValueByWorkerStr(workerStr string) Worker { var ToTagsMap = map[Worker][]tag.Tag{ RSSHub: {tag.RSS}, } - -var ToIconURLMap = map[Worker]string{ - RSSHub: "https://storage.googleapis.com/rss3-icon/rsshub.png", -} From 21d25da1ee17e514468eeb45fb41d38b4bd9706e Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Wed, 4 Sep 2024 10:12:24 +0800 Subject: [PATCH 2/5] fix(worker/aave): unexpected double loop (#487) --- .../decentralized/contract/aave/worker.go | 163 +++++++----------- 1 file changed, 65 insertions(+), 98 deletions(-) diff --git a/internal/engine/worker/decentralized/contract/aave/worker.go b/internal/engine/worker/decentralized/contract/aave/worker.go index f76da776..157a82e1 100644 --- a/internal/engine/worker/decentralized/contract/aave/worker.go +++ b/internal/engine/worker/decentralized/contract/aave/worker.go @@ -150,11 +150,11 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac switch { case w.matchLiquidityV1Pool(ethereumTask, log): - actions, err = w.handleV1LendingPool(ctx, ethereumTask) + actions, err = w.handleV1LendingPool(ctx, ethereumTask, log) case w.matchLiquidityV2LendingPool(ethereumTask, log): - actions, err = w.handleV2LendingPool(ctx, ethereumTask) + actions, err = w.handleV2LendingPool(ctx, ethereumTask, log) case w.matchLiquidityV3Pool(ethereumTask, log): - actions, err = w.handleV3Pool(ctx, ethereumTask) + actions, err = w.handleV3Pool(ctx, ethereumTask, log) default: continue } @@ -164,7 +164,10 @@ func (w *worker) Transform(ctx context.Context, task engine.Task) (*activityx.Ac } activity.Type = typex.ExchangeLiquidity - activity.Actions = append(activity.Actions, actions...) + + if actions != nil { + activity.Actions = append(activity.Actions, actions...) + } } return activity, nil @@ -266,116 +269,80 @@ func (w *worker) matchLiquidityV3Pool(task *source.Task, log *ethereum.Log) bool ) } -func (w *worker) handleV1LendingPool(ctx context.Context, task *source.Task) ([]*activityx.Action, error) { - actions := make([]*activityx.Action, 0) - - for _, log := range task.Receipt.Logs { - if len(log.Topics) == 0 { - continue - } - - var ( - action *activityx.Action - err error - ) - - switch { - case w.matchEthereumV1LendingPoolDepositLog(log): - action, err = w.transformV1LendingPoolDepositLog(ctx, task, log) - case w.matchEthereumV1LendingPoolBorrowLog(log): - action, err = w.transformV1LendingPoolBorrowLog(ctx, task, log) - case w.matchEthereumV1LendingPoolRepayLog(log): - action, err = w.transformV1LendingPoolRepayLog(ctx, task, log) - default: - continue - } +func (w *worker) handleV1LendingPool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { + var ( + action *activityx.Action + err error + ) - if err != nil { - return nil, fmt.Errorf("handle ethereum v3 pool: %w", err) - } + switch { + case w.matchEthereumV1LendingPoolDepositLog(log): + action, err = w.transformV1LendingPoolDepositLog(ctx, task, log) + case w.matchEthereumV1LendingPoolBorrowLog(log): + action, err = w.transformV1LendingPoolBorrowLog(ctx, task, log) + case w.matchEthereumV1LendingPoolRepayLog(log): + action, err = w.transformV1LendingPoolRepayLog(ctx, task, log) + default: + return nil, nil + } - if action != nil { - actions = append(actions, action) - } + if err != nil { + return nil, fmt.Errorf("handle v1 pool: %w", err) } - return actions, nil + return []*activityx.Action{action}, nil } -func (w *worker) handleV2LendingPool(ctx context.Context, task *source.Task) ([]*activityx.Action, error) { - actions := make([]*activityx.Action, 0) - - for _, log := range task.Receipt.Logs { - if len(log.Topics) == 0 { - continue - } - - var ( - action *activityx.Action - err error - ) - - switch { - case w.matchEthereumV2LendingPoolDepositLog(log): - action, err = w.transformV2LendingPoolDepositLog(ctx, task, log) - case w.matchEthereumV2LendingPoolWithdrawLog(log): - action, err = w.transformV2LendingPoolWithdrawLog(ctx, task, log) - case w.matchEthereumV2LendingPoolBorrowLog(log): - action, err = w.transformV2LendingPoolBorrowLog(ctx, task, log) - case w.matchEthereumV2LendingPoolRepayLog(log): - action, err = w.transformV2LendingPoolRepayLog(ctx, task, log) - default: - continue - } +func (w *worker) handleV2LendingPool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { + var ( + action *activityx.Action + err error + ) - if err != nil { - return nil, fmt.Errorf("handle ethereum v3 pool: %w", err) - } + switch { + case w.matchEthereumV2LendingPoolDepositLog(log): + action, err = w.transformV2LendingPoolDepositLog(ctx, task, log) + case w.matchEthereumV2LendingPoolWithdrawLog(log): + action, err = w.transformV2LendingPoolWithdrawLog(ctx, task, log) + case w.matchEthereumV2LendingPoolBorrowLog(log): + action, err = w.transformV2LendingPoolBorrowLog(ctx, task, log) + case w.matchEthereumV2LendingPoolRepayLog(log): + action, err = w.transformV2LendingPoolRepayLog(ctx, task, log) + default: + return nil, nil + } - if action != nil { - actions = append(actions, action) - } + if err != nil { + return nil, fmt.Errorf("handle v2 pool: %w", err) } - return actions, nil + return []*activityx.Action{action}, nil } -func (w *worker) handleV3Pool(ctx context.Context, task *source.Task) ([]*activityx.Action, error) { - actions := make([]*activityx.Action, 0) - - for _, log := range task.Receipt.Logs { - if len(log.Topics) == 0 { - continue - } - - var ( - action *activityx.Action - err error - ) - - switch { - case w.matchEthereumV3PoolSupplyLog(log): - action, err = w.transformV3PoolSupplyLog(ctx, task, log) - case w.matchEthereumV3PoolWithdrawLog(log): - action, err = w.transformV3PoolWithdrawLog(ctx, task, log) - case w.matchEthereumV3PoolBorrowLog(log): - action, err = w.transformV3PoolBorrowLog(ctx, task, log) - case w.matchEthereumV3PoolRepayLog(log): - action, err = w.transformV3PoolRepayLog(ctx, task, log) - default: - continue - } +func (w *worker) handleV3Pool(ctx context.Context, task *source.Task, log *ethereum.Log) ([]*activityx.Action, error) { + var ( + action *activityx.Action + err error + ) - if err != nil { - return nil, fmt.Errorf("handle ethereum v3 pool: %w", err) - } + switch { + case w.matchEthereumV3PoolSupplyLog(log): + action, err = w.transformV3PoolSupplyLog(ctx, task, log) + case w.matchEthereumV3PoolWithdrawLog(log): + action, err = w.transformV3PoolWithdrawLog(ctx, task, log) + case w.matchEthereumV3PoolBorrowLog(log): + action, err = w.transformV3PoolBorrowLog(ctx, task, log) + case w.matchEthereumV3PoolRepayLog(log): + action, err = w.transformV3PoolRepayLog(ctx, task, log) + default: + return nil, nil + } - if action != nil { - actions = append(actions, action) - } + if err != nil { + return nil, fmt.Errorf("handle v3 pool: %w", err) } - return actions, nil + return []*activityx.Action{action}, nil } func (w *worker) matchEthereumV1LendingPoolDepositLog(log *ethereum.Log) bool { From ed9c693acf3879146d89ab0271a664067227a9d3 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Wed, 4 Sep 2024 15:05:19 +0800 Subject: [PATCH 3/5] fix: add network in ethereum testcase template (#520) --- tool/testcase/main.go | 21 ++++++++++++++++++--- tool/testcase/template/ethereum.tmpl | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tool/testcase/main.go b/tool/testcase/main.go index 1e735498..698ed8ee 100644 --- a/tool/testcase/main.go +++ b/tool/testcase/main.go @@ -6,6 +6,7 @@ import ( "log" "math/big" "os" + "strings" "text/template" "unicode" @@ -45,9 +46,23 @@ var command = &cobra.Command{ return (*hexutil.Big)(value).String() }, "UppercaseFirst": func(network networkx.Network) string { - a := []rune(network.String()) - a[0] = unicode.ToUpper(a[0]) - return string(a) + networkStr := network.String() + switch networkStr { + case "": + return "Ethereum" + case "vsl": + return "VSL" + default: + words := strings.Split(networkStr, "-") + for i, word := range words { + if word != "" { + r := []rune(word) + r[0] = unicode.ToUpper(r[0]) + words[i] = string(r) + } + } + return strings.Join(words, "") + } }, }) diff --git a/tool/testcase/template/ethereum.tmpl b/tool/testcase/template/ethereum.tmpl index 0494050b..58f58369 100644 --- a/tool/testcase/template/ethereum.tmpl +++ b/tool/testcase/template/ethereum.tmpl @@ -1,6 +1,6 @@ {{ define "ethereum" }} { - Network: network.Ethereum, + Network: {{ if .Network }}network.{{ UppercaseFirst .Network }}{{ else }}network.Ethereum{{ end }}, ChainID: {{ .ChainID }}, Header: ðereum.Header{ Hash: common.HexToHash("{{ .Header.Hash}}"), From 8b36c72beea1bdef007720d4029305a6e1876ad5 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Wed, 4 Sep 2024 17:15:11 +0800 Subject: [PATCH 4/5] fix: add missing 1inch config (#521) --- internal/node/component/info/network_config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/node/component/info/network_config.go b/internal/node/component/info/network_config.go index 2e80edbf..5f976fbe 100644 --- a/internal/node/component/info/network_config.go +++ b/internal/node/component/info/network_config.go @@ -337,6 +337,7 @@ var WorkerToConfigMap = map[network.Source]map[worker.Worker]workerConfig{ decentralized.Lido: defaultWorkerConfig(decentralized.Lido, network.EthereumSource, nil), decentralized.Looksrare: defaultWorkerConfig(decentralized.Looksrare, network.EthereumSource, nil), decentralized.Matters: customWorkerConfigWithIPFS(decentralized.Matters, network.EthereumSource, ""), + decentralized.Oneinch: defaultWorkerConfig(decentralized.Oneinch, network.EthereumSource, nil), decentralized.OpenSea: defaultWorkerConfig(decentralized.OpenSea, network.EthereumSource, nil), decentralized.Optimism: defaultWorkerConfig(decentralized.Optimism, network.EthereumSource, nil), decentralized.RSS3: defaultWorkerConfig(decentralized.RSS3, network.EthereumSource, nil), From 9dc02833a2c431bc7d1cce1dc949936f8d838869 Mon Sep 17 00:00:00 2001 From: incubator4 Date: Wed, 4 Sep 2024 18:47:07 +0800 Subject: [PATCH 5/5] chore: use google artifact registry (#523) --- .github/workflows/docker-build.yaml | 56 ++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 75f59f3e..7ad8a429 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -9,6 +9,15 @@ on: - "*" pull_request: +permissions: + contents: read + id-token: write + pull-requests: write + packages: write + +env: + GAR_REGISTRY: us-central1-docker.pkg.dev/rss3-409706/docker + jobs: build: runs-on: @@ -31,17 +40,27 @@ jobs: uses: docker/setup-buildx-action@v3 with: platforms: ${{ matrix.platform }} - - name: Log in to the Container registry + + - name: Google auth + id: auth + uses: google-github-actions/auth@v2 + with: + token_format: access_token + workload_identity_provider: projects/987979088361/locations/global/workloadIdentityPools/github/providers/github-action + service_account: gh-action@naturalselectionlabs.iam.gserviceaccount.com + create_credentials_file: true + + - name: Login to GAR uses: docker/login-action@v3 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ github.token }} + registry: us-central1-docker.pkg.dev + username: oauth2accesstoken + password: ${{ steps.auth.outputs.access_token }} - name: Docker meta id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/rss3-network/node + images: ${{ env.GAR_REGISTRY }}/node - name: Build and push by digest id: build uses: docker/build-push-action@v6 @@ -49,7 +68,7 @@ jobs: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=ghcr.io/rss3-network/node,push-by-digest=true,name-canonical=true,push=${{ github.actor != 'dependabot[bot]' }} + outputs: type=image,name=${{ env.GAR_REGISTRY }}/node,push-by-digest=true,name-canonical=true,push=${{ github.actor != 'dependabot[bot]' }} - name: Export digest if: github.actor != 'dependabot[bot]' run: | @@ -66,10 +85,6 @@ jobs: retention-days: 1 merge: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - id-token: write needs: - build if: github.actor != 'dependabot[bot]' @@ -96,6 +111,22 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Google auth + id: auth + uses: google-github-actions/auth@v2 + with: + token_format: access_token + workload_identity_provider: projects/987979088361/locations/global/workloadIdentityPools/github/providers/github-action + service_account: gh-action@naturalselectionlabs.iam.gserviceaccount.com + create_credentials_file: true + + - name: Login to GAR + uses: docker/login-action@v3 + with: + registry: us-central1-docker.pkg.dev + username: oauth2accesstoken + password: ${{ steps.auth.outputs.access_token }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 @@ -103,6 +134,7 @@ jobs: images: | rss3/node ghcr.io/${{ github.repository }} + ${{ env.GAR_REGISTRY }}/node tags: | type=raw,value=latest,enable={{is_default_branch}} type=raw,value=${{ matrix.arch }},enable={{is_default_branch}} @@ -120,8 +152,8 @@ jobs: ARGS="--dry-run" fi docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf 'ghcr.io/rss3-network/node@sha256:%s ' *) $ARGS + $(printf '${{ env.GAR_REGISTRY }}/node@sha256:%s ' *) $ARGS - name: Inspect image if: github.event_name != 'pull_request' run: | - docker buildx imagetools inspect ghcr.io/rss3-network/node:${{ steps.meta.outputs.version }} + docker buildx imagetools inspect ${{ env.GAR_REGISTRY }}/node:${{ steps.meta.outputs.version }}