Skip to content

BlazeWasHere/points-adapters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Points Adapters

An adapter is just a piece code that takes in an address and returns the number of points accumulated or a record of labelled points accumulated. A label can be anything such as {pointsFromPendle: 420}.

Join the Discord

Discord Banner

Getting Started

Requirements

Installation

  1. Clone the repository:
git clone https://github.com/blazewashere/points-adapters.git
  1. Install dependencies:
deno install

Testing an adapter

deno run -A test.ts adapters/sonic.ts 0x3c2573b002cf51e64ab6d051814648eb3a305363

Basic Example

An example adapter for Sonic which gives us total points and a more detailed points.

import type { AdapterExport } from "../utils/adapter.ts";
import { maybeWrapCORSProxy } from "../utils/cors.ts";

const API_URL = await maybeWrapCORSProxy(
  "https://www.data-openblocklabs.com/sonic/user-points-stats?wallet_address={address}"
);

export default {
  fetch: async (address: string) => {
    return await (await fetch(API_URL.replace("{address}", address))).json();
  },
  points: (data: Record<string, number>) => ({
    sonic_points: data.sonic_points,
    loyalty_multiplier: data.loyalty_multiplier,
    ecosystem_points: data.ecosystem_points,
    passive_liquidity_points: data.passive_liquidity_points,
    activity_points: data.activity_points,
    rank: data.rank,
  }),
  total: (data: Record<string, number>) => data.sonic_points,
} as AdapterExport;
Breakdown
const API_URL = await maybeWrapCORSProxy(
  "https://www.data-openblocklabs.com/sonic/user-points-stats?wallet_address={address}"
);

All adapters should target the browser and this includes using Browser APIs and CORS. The function maybeWrapCORSProxy will deal with the latter issue for all remote APIs.

// [...]
  fetch: async (address: string) => {
    return await (await fetch(API_URL.replace("{address}", address))).json();
  },
// [...]

The first export is fetch. Just like the browser fetch, you provide some data and then you get some data back. This data does not need to be normalized but it is passed to all other "normalizing" method (points, total, claimable, etc.).

// [...]
  total: (data: Record<string, number>) => data.sonic_points,
// [...]

The second export is total which gives us the aggregate points for a wallet. This can also be a Record<string, number> to give aggregate season points as done in the ether.fi adapter. This is displayed on "total" info on a protocol.

// [...]
  points: (data: Record<string, number>) => ({
    sonic_points: data.sonic_points,
    loyalty_multiplier: data.loyalty_multiplier,
    ecosystem_points: data.ecosystem_points,
    passive_liquidity_points: data.passive_liquidity_points,
    activity_points: data.activity_points,
    rank: data.rank,
  }),
// [...]

The third export is points which returns a Record<string, string | number> of labelled points and data. This is displayed on "detailed" info on a protocol.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published