Skip to content

invariant-labs/api-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Endpoints

GET /api/config

get config: https://api.invariant.app/api/config

Response

{
  "refreshTime": 1800,
  "pointsDecimal": 8,
  "promotedPools": [
    {
      "address": "HRgVv1pyBLXdsAddq4ubSqo8xdQWRrYbvmXqEDtectce",
      "pointsPerSecond": "64",
      "startCountTimestamp": "6766d8da"
    },
    {
      "address": "86vPh8ctgeQnnn8qPADy5BkzrqoH5XjMCWvkd4tYhhmM",
      "pointsPerSecond": "1e",
      "startCountTimestamp": "67c03de0"
    },
    {
      "address": "E2B7KUFwjxrsy9cC17hmadPsxWHD1NufZXTyrtuz8YxC",
      "pointsPerSecond": "19",
      "startCountTimestamp": "67ce0183"
    },
    {
      "address": "FvVsbwsbGVo6PVfimkkPhpcRfBrRitiV946nMNNuz7f9",
      "pointsPerSecond": "0a",
      "startCountTimestamp": "6772f81b"
    }
  ],
  "lastSnapTimestamp": 1743597998,
  "pointsPerUsd": "c8",
  "swapMultiplier": "01",
  "swapPairs": [
    {
      "tokenX": "AKEWE7Bgh87GPp171b4cJPSSZfmZwQ3KaqYqXoKLNAEE",
      "tokenY": "So11111111111111111111111111111111111111112"
    },
    {
      "tokenX": "GU7NS9xCwgNPiAdJ69iusFrRfawjDDPjeMBovhV1d4kn",
      "tokenY": "So11111111111111111111111111111111111111112"
    },
    {
      "tokenX": "BeRUj3h7BqkbdfFU7FBNYbodgf8GCHodzKvF9aVjNNfL",
      "tokenY": "So11111111111111111111111111111111111111112"
    },
    {
      "tokenX": "AKEWE7Bgh87GPp171b4cJPSSZfmZwQ3KaqYqXoKLNAEE",
      "tokenY": "BeRUj3h7BqkbdfFU7FBNYbodgf8GCHodzKvF9aVjNNfL"
    }
  ]
}

GET /api/:network/total/:address?offset=X&size=Y

URL Params

Name Type Description
network string Network (currently only eclipse-mainnet)
address string / null User address to query, use null if not specified
offset number Starting position in the leaderboard
size number Number of user records to return.

get all users without specifying address: https://api.invariant.app/api/eclipse-mainnet/total/null

get all users and specified address: https://api.invariant.app/api/eclipse-mainnet/total/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE

get all users from range (offset, offset + size) with specified user: https://api.invariant.app/api/eclipse-mainnet/total/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE?offset=1&size=1

Response

{
  "user": {
    "address": "9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE",
    "points": "f31153ab9f700",
    "last24hPoints": "0",
    "lpPoints": "f31153ab9f700",
    "swapPoints": "0",
    "rank": 2
  },
  "leaderboard": [
    {
      "address": "9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE",
      "points": "f31153ab9f700",
      "last24hPoints": "0",
      "lpPoints": "f31153ab9f700",
      "swapPoints": "0",
      "rank": 2
    }
  ],
  "totalItems": 144952
}

GET /api/:network/lp/:address?offset=X&size=Y

URL Params

Name Type Description
network string Network (currently only eclipse-mainnet)
address string / null User address to query, use null if not specified
offset number Starting position in the leaderboard
size number Number of user records to return.

get all users without specifying address: https://api.invariant.app/api/eclipse-mainnet/lp/null

get all users and specified address: https://api.invariant.app/api/eclipse-mainnet/lp/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE

get all users from range (offset, offset + size) with specified user: https://api.invariant.app/api/eclipse-mainnet/lp/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE?offset=1&size=1

Response

{
  "user": {
    "rank": 2,
    "address": "9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE",
    "points": "f31153ab9f700",
    "last24hPoints": "0",
    "positions": 1
  },
  "leaderboard": [
    {
      "rank": 2,
      "address": "9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE",
      "points": "f31153ab9f700",
      "last24hPoints": "0",
      "positions": 1
    }
  ],
  "totalItems": 144957
}

GET /api/:network/swaps/:address?offset=X&size=Y

URL Params

Name Type Description
network string Network (currently only eclipse-mainnet)
address string / null User address to query, use null if not specified
offset number Starting position in the leaderboard
size number Number of user records to return.

get all users without specifying address: https://api.invariant.app/api/eclipse-mainnet/swaps/null

get all users and specified address: https://api.invariant.app/api/eclipse-mainnet/swaps/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE

get all users from range (offset, offset + size) with specified user: https://api.invariant.app/api/eclipse-mainnet/swaps/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE?offset=1&size=1

Response

{
  "user": {
    "rank": 142307,
    "address": "9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE",
    "points": "0",
    "last24hPoints": "0",
    "swaps": 0
  },
  "leaderboard": [
    {
      "rank": 2,
      "address": "97Qhv1jG8G5M47FvkvaZCu9y4oVfgdTPHFqtpVjRZ2k2",
      "points": "f5f0a9600bdd",
      "last24hPoints": "0",
      "swaps": 1936,
      "domain": "btc0w.turbo"
    }
  ],
  "totalItems": 144957
}

GET /api/quest/address/:address

URL Params

Name Type Description
address string User address to query

get user quest state https://api.invariant.app/api/quest/address/9BNu7C9f3cGS4fBS5jKvG2XASHGVVnBxR2XAW4q4ZYUE

Response

{ "totalPoints": "0f31153ab9f700", "completed": true }

GET /api/quest/description

get user quest state https://api.invariant.app/api/quest/description

Response

{
  "questProvider": "Invariant",
  "questProviderUrl": "https://eclipse.invariant.app/"
}

GET /api/swap/price-feeds

get available price feeds https://api.invariant.app/api/swap/price-feeds

Response

{
  "AKEWE7Bgh87GPp171b4cJPSSZfmZwQ3KaqYqXoKLNAEE": {
    "pricePublishTime": 1744812314,
    "priceDecimals": 8,
    "price": "99996853"
  },
  "So11111111111111111111111111111111111111112": {
    "pricePublishTime": 1744812314,
    "priceDecimals": 8,
    "price": "157263212041"
  },
  "GU7NS9xCwgNPiAdJ69iusFrRfawjDDPjeMBovhV1d4kn": {
    "pricePublishTime": 1744812314,
    "priceDecimals": 8,
    "price": "159379151733"
  },
  "BeRUj3h7BqkbdfFU7FBNYbodgf8GCHodzKvF9aVjNNfL": {
    "pricePublishTime": 1744812314,
    "priceDecimals": 8,
    "price": "12514977421"
  }
}

GET /api/content-program/:address

URL Params

Name Type Description
address string User address to query

get user content program points https://api.invariant.app/api/content-program/37mo4JWDqEQRzn9wHExRGdvAkExJL9J3jTEzeywJipmA

Response

[
  {
    "startTimestamp": 1734649200,
    "endTimestamp": 1738278000,
    "points": 100000
  },
  { "startTimestamp": 1738368000, "endTimestamp": 1739491200, "points": 50000 },
  { "startTimestamp": 1739491200, "endTimestamp": 1740700800, "points": 50000 },
  {
    "startTimestamp": 1740787201,
    "endTimestamp": 1741910401,
    "points": 200000
  },
  {
    "startTimestamp": 1741996800,
    "endTimestamp": 1743206400,
    "points": 100000
  },
  { "startTimestamp": 1743465600, "endTimestamp": 1744588800, "points": 300000 }
]

GET /price/:address

URL Params

Name Type Description
address string / undefined one or multiple token addresses to query

get all available prices https://api.invariant.app/price/eclipse-mainnet

get price for one token https://api.invariant.app/price/eclipse-mainnet?address=64mggk2nXg6vHC1qCdsZdEFzd5QGN4id54Vbho4PswCF

get price for multiple tokens https://api.invariant.app/price/eclipse-mainnet?address=64mggk2nXg6vHC1qCdsZdEFzd5QGN4id54Vbho4PswCF&address=2tGbYEm4nuPFyS6zjDTELzEhvVKizgKewi6xT7AaSKzn

Response

{
  "data": {
    "2tGbYEm4nuPFyS6zjDTELzEhvVKizgKewi6xT7AaSKzn": { "price": 3.197401 },
    "64mggk2nXg6vHC1qCdsZdEFzd5QGN4id54Vbho4PswCF": {
      "price": 41.4892796967324
    }
  },
  "lastUpdateTimestamp": 1744812724
}

Migration & Configuration

Locally

  1. Start mongo database from leaderboard-backend repo with ./setup.sh script
  2. Migrate data to mognodb from leaderboard repo using ts-node scripts/migrate.ts
  3. Create data backup file with npm run backup command in leaderboard-backend repo
  4. Change the backup file name in the scripts/insert-backup.ts to created file in step 3, path: backups/<FILE_NAME>.json
  5. Copy the files to server using scp command (ensure that node_modules are excluded)

Server

  1. Install dependencies in main directory and api directory

  2. Start mongo database using ./setup.sh script

  3. Insert backup with npm run insert-backup

  4. Start the instances of cron job and api using screen command

    4.1 Create screen for cron screen -S cron

    4.2 Start job with npm run start

    4.3 Detach scren using CTRL A + D

    4.4 Create screen for api screen -S api

    4.5 Start job with cd api && npm run start

    4.6 Detach screen CTRL A + D

    4.7 Create screen for price api screen -S price

    4.8 Start job with cd price && npm run start

    4.9 Detach screen CTRL A + D

    4.10 To reconnect to screen list them using screen -ls and then connect to choosen one with screen -r <SESSION_ID || NAME>

  5. Close ssh conenction with exit

Changing endpoints in case of failures

Changing leaderboard endpoint

  1. Enable deploy on cron job run in leaderboard repository
  2. Change LEADERBOARD_API_URL constant in the webapp repository to start with points prefix instead of api

Changing price endpoint

  1. Change PRICE_API_URL constant in the webapp repository from https://api.invariant.app/price to https://price.invariant.app

Adding Content Program Points

Hetzner

Highly recomended to test it locally and then update on prod. Repository: leaderboard-backend

  1. Create backup npm run backup in case of some failures
  2. Copy the backup from hetzner to your local machine using scp, insert the backup to mongo database
  3. Put the content program json inside scripts/content-program/data/<NAME>.json (ensure that timestamps are correct)
  4. Assign step3 json <NAME> to FILE_NAME variable in scripts/content-program/add-points.ts
  5. Using HTTP requests check if users have recevied the points
  6. If everyting is correct repeat steps 3 and 4 on hetzner.
  7. Change next content program dates in ./api/src/controllers/config.ts, contentProgramDateStart and contentProgramDateEnd

Vercel

Repository: leaderboard

  1. Put the content program json inside scripts/content-program/<NAME>.json (ensure that timestamps are correct)
  2. Update the import of POINTS_TO_ADD to json moved in step1 in file scripts/content-program/add-points.ts
  3. Check if the content program points are assigned correctly in data/content-program.json file
  4. Change next content program dates in ./api/config.ts, contentProgramDateStart and contentProgramDateEnd

Changing points distribution on specified pool

Repository: leaderboard-backend

  1. Change points distribution for specified pool in consts.ts and update the pool address in scripts/remove-pool-boost.ts
  2. Stop cron job updates
  3. Run script with npm run remove-pool-boost
  4. Restart cron job updates & api instance to display recent pool distributions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •