From 63aa8021cb775020fb52a0d1932fcd2f78dcc502 Mon Sep 17 00:00:00 2001 From: eli-d <64763513+eli-d@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:07:53 +1030 Subject: [PATCH] support filtering a counterpart token in pool swaps resolver --- cmd/faucet.superposition/graph/generated.go | 156 ++++++++++++++---- cmd/graphql.ethereum/graph/generated.go | 39 ++++- .../graph/schema.resolvers.go | 12 +- cmd/graphql.ethereum/schema.graphqls | 4 +- 4 files changed, 167 insertions(+), 44 deletions(-) diff --git a/cmd/faucet.superposition/graph/generated.go b/cmd/faucet.superposition/graph/generated.go index 9a9d02c7..c6eb3a85 100644 --- a/cmd/faucet.superposition/graph/generated.go +++ b/cmd/faucet.superposition/graph/generated.go @@ -240,71 +240,157 @@ var parsedSchema = gqlparser.MustLoadSchema(sources...) func (ec *executionContext) field_Mutation_requestTokens_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["wallet"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("wallet")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Mutation_requestTokens_argsWallet(ctx, rawArgs) + if err != nil { + return nil, err } args["wallet"] = arg0 - var arg1 string - if tmp, ok := rawArgs["turnstileToken"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("turnstileToken")) - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Mutation_requestTokens_argsTurnstileToken(ctx, rawArgs) + if err != nil { + return nil, err } args["turnstileToken"] = arg1 return args, nil } +func (ec *executionContext) field_Mutation_requestTokens_argsWallet( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["wallet"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("wallet")) + if tmp, ok := rawArgs["wallet"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Mutation_requestTokens_argsTurnstileToken( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["turnstileToken"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("turnstileToken")) + if tmp, ok := rawArgs["turnstileToken"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query___type_argsName(ctx, rawArgs) + if err != nil { + return nil, err } args["name"] = arg0 return args, nil } +func (ec *executionContext) field_Query___type_argsName( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["name"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + if tmp, ok := rawArgs["name"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err } args["includeDeprecated"] = arg0 return args, nil } +func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err } args["includeDeprecated"] = arg0 return args, nil } +func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} // endregion ***************************** args.gotpl ***************************** diff --git a/cmd/graphql.ethereum/graph/generated.go b/cmd/graphql.ethereum/graph/generated.go index 7206e1f1..c6e724c6 100644 --- a/cmd/graphql.ethereum/graph/generated.go +++ b/cmd/graphql.ethereum/graph/generated.go @@ -169,7 +169,7 @@ type ComplexityRoot struct { Price func(childComplexity int) int PriceOverTime func(childComplexity int) int Served func(childComplexity int) int - Swaps func(childComplexity int, first *int, after *int) int + Swaps func(childComplexity int, first *int, after *int, filter *string) int TickSpacing func(childComplexity int) int Token func(childComplexity int) int TotalFee func(childComplexity int) int @@ -328,7 +328,7 @@ type SeawaterPoolResolver interface { Positions(ctx context.Context, obj *seawater.Pool, first *int, after *int) (model.SeawaterPositionsGlobal, error) PositionsForUser(ctx context.Context, obj *seawater.Pool, wallet string, first *int, after *int) (model.SeawaterPositionsUser, error) Liquidity(ctx context.Context, obj *seawater.Pool) ([]model.SeawaterLiquidity, error) - Swaps(ctx context.Context, obj *seawater.Pool, first *int, after *int) (model.SeawaterSwaps, error) + Swaps(ctx context.Context, obj *seawater.Pool, first *int, after *int, filter *string) (model.SeawaterSwaps, error) Amounts(ctx context.Context, obj *seawater.Pool) (model.PairAmount, error) Config(ctx context.Context, obj *seawater.Pool) (model.SeawaterConfig, error) } @@ -965,7 +965,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.SeawaterPool.Swaps(childComplexity, args["first"].(*int), args["after"].(*int)), true + return e.complexity.SeawaterPool.Swaps(childComplexity, args["first"].(*int), args["after"].(*int), args["filter"].(*string)), true case "SeawaterPool.tickSpacing": if e.complexity.SeawaterPool.TickSpacing == nil { @@ -1734,8 +1734,10 @@ type SeawaterPool { """ Swaps that were made using this pool. + If filter is set, only swaps between the pool token and the filter token will be returned. + If filter isn't set, only swaps between the pool token and fUSDC will be returned. """ - swaps(first: Int, after: Int): SeawaterSwaps! + swaps(first: Int, after: Int, filter: String): SeawaterSwaps! """ Amounts currently contained in this pool. @@ -3036,6 +3038,11 @@ func (ec *executionContext) field_SeawaterPool_swaps_args(ctx context.Context, r return nil, err } args["after"] = arg1 + arg2, err := ec.field_SeawaterPool_swaps_argsFilter(ctx, rawArgs) + if err != nil { + return nil, err + } + args["filter"] = arg2 return args, nil } func (ec *executionContext) field_SeawaterPool_swaps_argsFirst( @@ -3082,6 +3089,28 @@ func (ec *executionContext) field_SeawaterPool_swaps_argsAfter( return zeroVal, nil } +func (ec *executionContext) field_SeawaterPool_swaps_argsFilter( + ctx context.Context, + rawArgs map[string]interface{}, +) (*string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["filter"] + if !ok { + var zeroVal *string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) + if tmp, ok := rawArgs["filter"]; ok { + return ec.unmarshalOString2áš–string(ctx, tmp) + } + + var zeroVal *string + return zeroVal, nil +} + func (ec *executionContext) field_SeawaterPositionsGlobal_next_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -7492,7 +7521,7 @@ func (ec *executionContext) _SeawaterPool_swaps(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.SeawaterPool().Swaps(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*int)) + return ec.resolvers.SeawaterPool().Swaps(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*int), fc.Args["filter"].(*string)) }) if err != nil { ec.Error(ctx, err) diff --git a/cmd/graphql.ethereum/graph/schema.resolvers.go b/cmd/graphql.ethereum/graph/schema.resolvers.go index 9b4c9299..8d37abf3 100644 --- a/cmd/graphql.ethereum/graph/schema.resolvers.go +++ b/cmd/graphql.ethereum/graph/schema.resolvers.go @@ -8,9 +8,9 @@ import ( "context" "errors" "fmt" + "log/slog" "math/big" "strconv" - "log/slog" "time" "github.com/fluidity-money/long.so/cmd/graphql.ethereum/graph/model" @@ -1248,7 +1248,7 @@ func (r *seawaterPoolResolver) Liquidity(ctx context.Context, obj *seawater.Pool } // Swaps is the resolver for the swaps field. -func (r *seawaterPoolResolver) Swaps(ctx context.Context, obj *seawater.Pool, first *int, after *int) (swaps model.SeawaterSwaps, err error) { +func (r *seawaterPoolResolver) Swaps(ctx context.Context, obj *seawater.Pool, first *int, after *int, filter *string) (swaps model.SeawaterSwaps, err error) { if obj == nil { return swaps, fmt.Errorf("empty pool") } @@ -1266,10 +1266,16 @@ func (r *seawaterPoolResolver) Swaps(ctx context.Context, obj *seawater.Pool, fi swaps = MockSwaps(r.C.FusdcAddr, 150, obj.Token) return } + var filterAddress types.Address + if filter != nil { + filterAddress = types.Address(*filter) + } else { + filterAddress = r.C.FusdcAddr + } // DB.RAW doesn't support chaining err = r.DB.Raw( "SELECT * FROM seawater_swaps_pool_3(?, ?, ?, ?, ?)", - r.C.FusdcAddr, + filterAddress, r.C.FusdcDecimals, obj.Token, time.Unix(int64(*after), 0), diff --git a/cmd/graphql.ethereum/schema.graphqls b/cmd/graphql.ethereum/schema.graphqls index ae3d37b6..4d81336a 100644 --- a/cmd/graphql.ethereum/schema.graphqls +++ b/cmd/graphql.ethereum/schema.graphqls @@ -264,8 +264,10 @@ type SeawaterPool { """ Swaps that were made using this pool. + If filter is set, only swaps between the pool token and the filter token will be returned. + If filter isn't set, only swaps between the pool token and fUSDC will be returned. """ - swaps(first: Int, after: Int): SeawaterSwaps! + swaps(first: Int, after: Int, filter: String): SeawaterSwaps! """ Amounts currently contained in this pool.