Skip to content

Commit

Permalink
add type column for 1inch tradelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
linhnt3400 committed Nov 29, 2024
1 parent b441c43 commit 133e561
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions v2/cmd/migrations/00007_add_type_column_1inch.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table tradelogs_oneinch_v6 add column type text default ''::text not null;
10 changes: 10 additions & 0 deletions v2/pkg/parser/oneinchv6/order_rfq.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ import (
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"k8s.io/apimachinery/pkg/util/sets"
)

const (
paramName = "order"
takerTraitsParamName = "takerTraits"
argsParamName = "args"
rfqType = "RFQ"
)

var fillContractOrderNameSet = sets.NewString("fillContractOrder", "fillContractOrderArgs")

func ToTradeLog(tradeLog storageTypes.TradeLog, contractCall *tradingTypes.ContractCall) (storageTypes.TradeLog, error) {
if contractCall == nil {
return tradeLog, errors.New("contract call is empty")
}
if fillContractOrderNameSet.Has(contractCall.Name) {
tradeLog.Type = rfqType
}
for _, param := range contractCall.Params {
if param.Name != paramName {
continue
Expand All @@ -49,6 +56,9 @@ func ToTradeLog(tradeLog storageTypes.TradeLog, contractCall *tradingTypes.Contr
if err != nil {
return tradeLog, err
}
if !makerTraitsOption.NoPartialFills && !makerTraitsOption.MultipleFills {
tradeLog.Type = rfqType
}
tradeLog.Expiry = uint64(makerTraitsOption.Expiration)

// if maker is Permit2WitnessProxy
Expand Down
5 changes: 4 additions & 1 deletion v2/pkg/storage/tradelogs/oneinch_v6/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (s *Storage) Insert(orders []storageTypes.TradeLog) error {
taker_token_price=excluded.taker_token_price,
maker_usd_amount=excluded.maker_usd_amount,
taker_usd_amount=excluded.taker_usd_amount,
maker_traits=excluded.maker_traits
maker_traits=excluded.maker_traits,
type=excluded.type
`).ToSql()
if err != nil {
s.l.Errorw("Error build insert", "error", err)
Expand Down Expand Up @@ -179,6 +180,7 @@ func tradeLogSerialize(o *storageTypes.TradeLog) []interface{} {
o.MakerUsdAmount,
o.TakerUsdAmount,
o.MakerTraits,
o.Type,
}
}

Expand Down Expand Up @@ -207,5 +209,6 @@ func tradeLogColumns() []string {
"maker_usd_amount",
"taker_usd_amount",
"maker_traits",
"type",
}
}
1 change: 1 addition & 0 deletions v2/pkg/storage/tradelogs/types/trade_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TradeLog struct {
TakerTokenPrice *float64 `db:"taker_token_price" json:"taker_token_price"`
MakerUsdAmount *float64 `db:"maker_usd_amount" json:"maker_usd_amount"`
TakerUsdAmount *float64 `db:"taker_usd_amount" json:"taker_usd_amount"`
Type string `db:"type" json:"type"`
}

// CommonTradeLogSerialize used for exchanges only storing fields in common trade logs,
Expand Down

0 comments on commit 133e561

Please sign in to comment.