-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get onchain asset average cost (#1398)
- Loading branch information
1 parent
4a3203e
commit 8f39eb2
Showing
23 changed files
with
1,981 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/defipod/mochi/pkg/config" | ||
"github.com/defipod/mochi/pkg/entities" | ||
"github.com/defipod/mochi/pkg/job" | ||
"github.com/defipod/mochi/pkg/logger" | ||
"github.com/defipod/mochi/pkg/service" | ||
) | ||
|
||
func main() { | ||
cfg := config.LoadConfig(config.DefaultConfigLoaders()) | ||
log := logger.NewLogrusLogger() | ||
// *** entities *** | ||
err := entities.Init(cfg, log) | ||
if err != nil { | ||
log.Fatal(err, "failed to init entities") | ||
} | ||
|
||
service, err := service.NewService(cfg, log) | ||
if err != nil { | ||
log.Fatal(err, "failed to init service") | ||
} | ||
defer service.Sentry.Flush(2 * time.Second) | ||
|
||
if err := job.NewUpdateUserOnchainAssetAvgCostJob(entities.Get()).Run(); err != nil { | ||
log.Fatal(err, "failed to run job") | ||
} | ||
|
||
log.Info("done") | ||
} |
15 changes: 15 additions & 0 deletions
15
migrations/schemas/20240531090511-add-onchain-asset-avg-costs-table.sql
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,15 @@ | ||
-- +migrate Up | ||
CREATE TABLE IF NOT EXISTS onchain_asset_avg_costs ( | ||
wallet_address TEXT NOT NULL, | ||
token_address TEXT NOT NULL, | ||
symbol TEXT NOT NULL, | ||
blockchain TEXT NOT NULL, | ||
average_cost FLOAT NOT NULL, | ||
created_at TIMESTAMPTZ DEFAULT now(), | ||
updated_at TIMESTAMPTZ DEFAULT now() | ||
); | ||
|
||
CREATE UNIQUE INDEX "uidx_wallet_address_token_address_chain" ON onchain_asset_avg_costs (wallet_address, token_address, blockchain); | ||
|
||
-- +migrate Down | ||
DELETE TABLE IF EXISTS onchain_asset_avg_costs; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package entities | ||
|
||
import ( | ||
"github.com/defipod/mochi/pkg/model" | ||
) | ||
|
||
func (e *Entity) UpsertManyOnchainAssetAvgCost(assets []model.OnchainAssetAvgCost) error { | ||
err := e.repo.OnchainAssetAverageCost.UpsertMany(assets) | ||
if err != nil { | ||
e.log.Error(err, "[entities.UpsertManyOnchainAssetAvgCost] - repo.OnchainAssetAverageCost.UpsertMany failed") | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (e *Entity) GetOnchainAssetAvgCostByWalletAddress(walletAddress string) ([]model.OnchainAssetAvgCost, error) { | ||
assets, err := e.repo.OnchainAssetAverageCost.GetByWalletAddr(walletAddress) | ||
if err != nil { | ||
e.log.Error(err, "[entities.GetOnchainAssetAvgCostByWalletAddress] - repo.OnchainAssetAverageCost.GetByWalletAddress failed") | ||
return nil, err | ||
} | ||
return assets, nil | ||
} |
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
Oops, something went wrong.