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

[API-3583] Track tx costs #57

Merged
merged 23 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a836022
change tx price oracle to be slightly more chain agnostic, pull confi…
mattac21 Nov 19, 2024
526f1ca
add tx cost to submitted txs table and update queries
mattac21 Nov 19, 2024
d000b5f
move evmrpc tx price oracle to chain agnostic oracle package and allo…
mattac21 Nov 19, 2024
c7cabfe
parse fee out of tx result to use as gas cost
mattac21 Nov 19, 2024
fb3d9e5
rename evm tx price oracle -> price oracle
mattac21 Nov 19, 2024
61c4a6c
update interface for calling tx price oracle from hyperlane client
mattac21 Nov 19, 2024
94bb59e
get gas cost in uusdc when verifying a submitted tx
mattac21 Nov 19, 2024
8133aaa
add rebalance_transfer_id column to submitted txs table
mattac21 Nov 20, 2024
1920828
insert fund rebalancer txs into submitted txs table
mattac21 Nov 20, 2024
51c66f4
erc20 approval before gas cost estimation
mattac21 Nov 20, 2024
84b3d8e
Merge branch 'main' into ma/track-profit-in-db
mattac21 Nov 28, 2024
6cd7b23
move evm tx price oracle to generic oracle package to not be evm spec…
mattac21 Dec 2, 2024
44a9465
add db queries to support fund rebalancer to add txns to submitted tx…
mattac21 Dec 2, 2024
8b0cb8c
fund rebalancer adds txs to submitted txs table
mattac21 Dec 2, 2024
4d4f52f
add test for fund rebalancer adding txns to submitted txns table
mattac21 Dec 2, 2024
bee959e
Merge branch 'main' into ma/track-profit-in-db
mattac21 Dec 2, 2024
c666e81
fix imports
mattac21 Dec 2, 2024
10825ff
dont link erc20 approval txs to rebalance txs in fund rebalancer
mattac21 Dec 5, 2024
aa84081
change fee parsing to decode tx auth info bytes and return gas denom fee
mattac21 Dec 5, 2024
a77316f
return an error if fee for gas denom is not found in cosmos tx result
mattac21 Dec 5, 2024
14099d3
Merge branch 'main' into ma/track-profit-in-db
mattac21 Dec 5, 2024
b4f08e5
fix db migration naming and make rebalance_transfer_id a foreign key
mattac21 Dec 6, 2024
5408834
pass chainid to tx price oracle
mattac21 Dec 6, 2024
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
10 changes: 6 additions & 4 deletions cmd/solver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
"flag"
"fmt"
"github.com/skip-mev/go-fast-solver/gasmonitor"
"os/signal"
"syscall"
"time"

"github.com/skip-mev/go-fast-solver/gasmonitor"

"github.com/skip-mev/go-fast-solver/shared/oracle"
"github.com/skip-mev/go-fast-solver/shared/txexecutor/cosmos"
"github.com/skip-mev/go-fast-solver/shared/txexecutor/evm"

Expand Down Expand Up @@ -98,9 +100,9 @@ func main() {
rateLimitedClient := utils.DefaultRateLimitedHTTPClient(3)
coingeckoClient := coingecko.NewCoingeckoClient(rateLimitedClient, "https://api.coingecko.com/api/v3/", "")
cachedCoinGeckoClient := coingecko.NewCachedPriceClient(coingeckoClient, 15*time.Minute)
evmTxPriceOracle := evmrpc.NewOracle(cachedCoinGeckoClient)
txPriceOracle := oracle.NewOracle(cachedCoinGeckoClient)

hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore, evmTxPriceOracle, evmTxExecutor)
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore, txPriceOracle, evmTxExecutor)
if err != nil {
lmt.Logger(ctx).Fatal("creating hyperlane multi client from config", zap.Error(err))
}
Expand Down Expand Up @@ -154,7 +156,7 @@ func main() {
})

eg.Go(func() error {
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager)
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager, txPriceOracle)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/solvercli/cmd/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"time"

"github.com/skip-mev/go-fast-solver/shared/oracle"
"github.com/skip-mev/go-fast-solver/shared/txexecutor/evm"

"os/signal"
Expand Down Expand Up @@ -97,9 +98,9 @@ var relayCmd = &cobra.Command{
rateLimitedClient := utils.DefaultRateLimitedHTTPClient(3)
coingeckoClient := coingecko.NewCoingeckoClient(rateLimitedClient, "https://api.coingecko.com/api/v3/", "")
cachedCoinGeckoClient := coingecko.NewCachedPriceClient(coingeckoClient, 15*time.Minute)
evmTxPriceOracle := evmrpc.NewOracle(cachedCoinGeckoClient)
txPriceOracle := oracle.NewOracle(cachedCoinGeckoClient)
evmTxExecutor := evm.DefaultEVMTxExecutor()
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore, evmTxPriceOracle, evmTxExecutor)
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore, txPriceOracle, evmTxExecutor)
if err != nil {
lmt.Logger(ctx).Error("Error creating hyperlane multi client from config", zap.Error(err))
}
Expand Down
2 changes: 2 additions & 0 deletions db/gen/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions db/gen/db/transactions.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/migrations/000004_add_submitted_tx_table.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ WHERE order_settlement_id IS NOT NULL;

CREATE UNIQUE INDEX submitted_txs_chain_tx_key
ON submitted_txs(chain_id, tx_hash)
WHERE order_settlement_id IS NULL;
WHERE order_settlement_id IS NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submitted_txs DROP COLUMN tx_cost_uusdc;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submitted_txs ADD tx_cost_uusdc TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submitted_txs DROP COLUMN rebalance_transfer_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE submitted_txs ADD rebalance_transfer_id INT;
6 changes: 4 additions & 2 deletions db/queries/transactions.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- name: InsertSubmittedTx :one
INSERT INTO submitted_txs (order_id, order_settlement_id, hyperlane_transfer_id, chain_id, tx_hash, raw_tx, tx_type, tx_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING *;
INSERT INTO submitted_txs (order_id, order_settlement_id, hyperlane_transfer_id, rebalance_transfer_id, chain_id, tx_hash, raw_tx, tx_type, tx_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *;

-- name: GetSubmittedTxsByOrderIdAndType :many
SELECT * FROM submitted_txs WHERE order_id = ? AND tx_type = ?;
Expand All @@ -11,7 +11,9 @@ SELECT * FROM submitted_txs WHERE hyperlane_transfer_id = ?;
SELECT * FROM submitted_txs WHERE tx_status = ?;

-- name: SetSubmittedTxStatus :one
UPDATE submitted_txs SET tx_status = ?, tx_status_message = ?, updated_at = CURRENT_TIMESTAMP WHERE tx_hash = ? AND chain_id = ? RETURNING *;
UPDATE submitted_txs SET
tx_status = ?, tx_status_message = ?, tx_cost_uusdc = ?, updated_at = CURRENT_TIMESTAMP
WHERE tx_hash = ? AND chain_id = ? RETURNING *;

-- name: GetSubmittedTxsByOrderStatusAndType :many
SELECT submitted_txs.* FROM submitted_txs INNER JOIN orders on submitted_txs.order_id = orders.id WHERE orders.order_status = ? AND submitted_txs.tx_type = ?;
2 changes: 2 additions & 0 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
TxTypeSettlement string = "SETTLEMENT"
TxTypeHyperlaneMessageDelivery string = "HYPERLANE_MESSAGE_DELIVERY"
TxTypeInitiateTimeout string = "INITIATE_TIMEOUT"
TxTypeERC20Approval string = "ERC20_APPROVAL"
TxTypeFundRebalnance string = "FUND_REBALANCE"

RebalanceTransactionStatusPending string = "PENDING"
RebalanceTransactionStatusSuccess string = "SUCCESS"
Expand Down
Loading