Fitter – API/Website’s stapler. Great update

Fitter – API/Website’s stapler. Great update

Good evening everyone!

It’s been quite a while since the last Fitter article, so I wanted to share the updates that have been made.

So, what appeared:

  1. A README.md is written, which is regularly updated with tokens.

  2. Added possibility to use as a library for go

  3. Added go plugin support.

  4. Added proxy support for connectors (server/playwright)

  5. Added ability to send updates to console(stdout)/telegram/http/redis

  6. Removed huge code duplication using generic

  7. Added the ability to download files

  8. Added the ability to make calculated fields, and thanks to this, you can make super links of configurations (more on that below)

  9. Added the ability to create a reference (you can cache data and reuse it) and inject environment variables

  10. Added the ability to fallback to any field if it is empty.

Finally, I would like to show an example of the configuration I made for a friend. And so his task with the preservation of spelling:

1. Well, first you need to get all user positions https://docs.saucerswap.finance/v/developer/saucerswap-v2/liquidity-operations/get-user-positions
2. then all pools https://docs.saucerswap.finance/v/developer/saucerswap-v2/liquidity-operations/fetch-all-pools
3. and then mark user positions with pools to determine which positions are out of pool range

And so it turned out:

{
  "references": {
    "AllPoolRef": {
      "expire": "60",
      "connector_config": {
        "response_type": "json",
        "url": "https://api.saucerswap.finance/v2/pools/",
        "server_config": {
          "method": "GET"
        }
      },
      "model": {
        "array_config": {
          "item_config": {
            "fields": {
              "tokenA": {
                "base_field": {
                  "type": "string",
                  "path": "tokenA.symbol"
                }
              },
              "tokenB": {
                "base_field": {
                  "type": "string",
                  "path": "tokenB.symbol"
                }
              }
            }
          }
        }
      }
    },
    "AccountIdRef": {
      "connector_config": {
        "response_type": "json",
        "static_config": {
          "value": "{{{FromEnv=USER_ID}}}"
        }
      },
      "model": {
        "base_field": {
          "type": "string"
        }
      }
    }
  },
  "items": [
    {
      "name": "user-position",
      "connector_config": {
        "response_type": "json",
        "url": "https://api.saucerswap.finance/V2/nfts/{{{RefName=AccountIdRef}}}/positions",
        "server_config": {
          "method": "GET"
        }
      },
      "model": {
        "array_config": {
          "item_config": {
            "fields": {
              "position": {
                "base_field": {
                  "type": "object",
                  "generated": {
                    "formatted": {
                      "template": "tokenA={{{tokenA.symbol}}} tokenB={{{tokenB.symbol}}}"
                    }
                  }
                }
              },
              "value": {
                "base_field": {
                  "type": "object",
                  "path": "",
                  "generated": {
                    "calculated": {
                      "type": "boolean",
                      "expression": "any(fromJSON('{{{RefName=AllPoolRef}}}'), {.tokenA == '{{{tokenA.symbol}}}' && .tokenB == '{{{tokenB.symbol}}}'})"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "trigger_config": {
        "scheduler_trigger": {
          "interval": 10
        }
      },
      "notifier_config": {
        "expression": "any(fRes, {.value == true})",
        "telegram_bot": {
          "token": "{{{FromEnv=TELEGRAM_TOKEN}}}",
          "users_id": [],
          "pretty": true
        }
      }
    }
  ]
}

There are two parameters from the environment:

  1. TELEGRAM_TOKEN – line 95

  2. USER_ID – line 37

All the friend had to do was run Fitter and add user IDs for notification to the config (line 95):

TELEGRAM_TOKEN=xxx USER_ID=xxx ./fitter --path=./config.json

I will tell you what is happening here:

  1. We create Reference (line 3) for all pools and cache for 60 seconds (line 4). We take and create an array of objects with two fields (symbols of two tokens from the pools)

  2. We create Reference (line 33) on AccountId, it will be just a line

  3. We create an item to monitor every 10 seconds (line 88) that takes data from the server with inject account Id (line 52), which is an array of objects with two fields. The first position (line 66) is a template string with the result of the result. The second is the result of the check containing user tokens in the pool with Reference (item one) of boolean type.

  4. Next, we report if any of the fields has the value true (line 93)

  5. We receive a message in the visa:

Result for: user-position

[
 {
  "position": "tokenA=USDC tokenB=USDC[hts]",
  "value": true
 },
 {
  "value": false,
  "position": "tokenA=USDC tokenB=USDT"
 }
]

PS: the false value could be ignored, but it was not.

Thank you for your attention, I continue to work on the project!

Related posts