Skip to content

Commit b825fb4

Browse files
authored
[API-3583] Track tx costs (#57)
* change tx price oracle to be slightly more chain agnostic, pull config when getting gas cost instead of passing in coin gecko id * add tx cost to submitted txs table and update queries * move evmrpc tx price oracle to chain agnostic oracle package and allow users to call gas cost uusdc * parse fee out of tx result to use as gas cost * rename evm tx price oracle -> price oracle * update interface for calling tx price oracle from hyperlane client * get gas cost in uusdc when verifying a submitted tx * add rebalance_transfer_id column to submitted txs table * insert fund rebalancer txs into submitted txs table * erc20 approval before gas cost estimation * move evm tx price oracle to generic oracle package to not be evm specific * add db queries to support fund rebalancer to add txns to submitted txs table * fund rebalancer adds txs to submitted txs table * add test for fund rebalancer adding txns to submitted txns table * fix imports * dont link erc20 approval txs to rebalance txs in fund rebalancer * change fee parsing to decode tx auth info bytes and return gas denom fee * return an error if fee for gas denom is not found in cosmos tx result * fix db migration naming and make rebalance_transfer_id a foreign key * pass chainid to tx price oracle
1 parent d1439fd commit b825fb4

25 files changed

+672
-383
lines changed

.mockery.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ packages:
66
interfaces:
77
EVMRPCClientManager:
88
EVMChainRPC:
9-
IOracle:
9+
github.com/skip-mev/go-fast-solver/shared/oracle:
10+
interfaces:
11+
TxPriceOracle:
1012
github.com/skip-mev/go-fast-solver/shared/http:
1113
interfaces:
1214
Client:

cmd/solver/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

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

13+
"github.com/skip-mev/go-fast-solver/shared/oracle"
1314
"github.com/skip-mev/go-fast-solver/shared/txexecutor/cosmos"
1415
"github.com/skip-mev/go-fast-solver/shared/txexecutor/evm"
1516

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

102-
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore, evmTxPriceOracle, evmTxExecutor)
103+
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore, txPriceOracle, evmTxExecutor)
103104
if err != nil {
104105
lmt.Logger(ctx).Fatal("creating hyperlane multi client from config", zap.Error(err))
105106
}
@@ -144,7 +145,7 @@ func main() {
144145
})
145146

146147
eg.Go(func() error {
147-
r, err := fundrebalancer.NewFundRebalancer(ctx, keyStore, skipgo, evmManager, db.New(dbConn), evmTxPriceOracle, evmTxExecutor)
148+
r, err := fundrebalancer.NewFundRebalancer(ctx, keyStore, skipgo, evmManager, db.New(dbConn), txPriceOracle, evmTxExecutor)
148149
if err != nil {
149150
return fmt.Errorf("creating fund rebalancer: %w", err)
150151
}
@@ -153,7 +154,7 @@ func main() {
153154
})
154155

155156
eg.Go(func() error {
156-
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager)
157+
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager, txPriceOracle)
157158
if err != nil {
158159
return err
159160
}

cmd/solvercli/cmd/relay.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"time"
99

10+
"github.com/skip-mev/go-fast-solver/shared/oracle"
1011
"github.com/skip-mev/go-fast-solver/shared/txexecutor/evm"
1112

1213
"os/signal"
@@ -97,9 +98,9 @@ var relayCmd = &cobra.Command{
9798
rateLimitedClient := utils.DefaultRateLimitedHTTPClient(3)
9899
coingeckoClient := coingecko.NewCoingeckoClient(rateLimitedClient, "https://api.coingecko.com/api/v3/", "")
99100
cachedCoinGeckoClient := coingecko.NewCachedPriceClient(coingeckoClient, 15*time.Minute)
100-
evmTxPriceOracle := evmrpc.NewOracle(cachedCoinGeckoClient)
101+
txPriceOracle := oracle.NewOracle(cachedCoinGeckoClient)
101102
evmTxExecutor := evm.DefaultEVMTxExecutor()
102-
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore, evmTxPriceOracle, evmTxExecutor)
103+
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore, txPriceOracle, evmTxExecutor)
103104
if err != nil {
104105
lmt.Logger(ctx).Error("Error creating hyperlane multi client from config", zap.Error(err))
105106
}

db/gen/db/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/gen/db/transactions.sql.go

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/migrations/000004_add_submitted_tx_table.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ WHERE order_settlement_id IS NOT NULL;
2525

2626
CREATE UNIQUE INDEX submitted_txs_chain_tx_key
2727
ON submitted_txs(chain_id, tx_hash)
28-
WHERE order_settlement_id IS NULL;
28+
WHERE order_settlement_id IS NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE submitted_txs DROP COLUMN tx_cost_uusdc;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE submitted_txs ADD tx_cost_uusdc TEXT;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE submitted_txs DROP COLUMN rebalance_transfer_id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE submitted_txs ADD COLUMN rebalance_transfer_id INT REFERENCES rebalance_transfers(id);

0 commit comments

Comments
 (0)