Skip to content

Commit

Permalink
Merge pull request #42 from ethena-labs/f/e-2069-clean-up-points-adap…
Browse files Browse the repository at this point in the history
…ters-repo

F/e 2069 clean up points adapters repo
  • Loading branch information
deHB6 authored Nov 20, 2024
2 parents 84c98e3 + 1ea22bc commit acb4cac
Show file tree
Hide file tree
Showing 111 changed files with 2,687 additions and 1,328 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main-push-and-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 mypy
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Type check with mypy
run: mypy . --explicit-package-bases --pretty --check-untyped-defs
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# Overview

This repo offers a self service approach to Ethena Sats Campaign integrations.
This repo offers a self service approach to Ethena Points Campaign integrations.

# Instructions

For your protocol to be included and your users to receive sats, you should submit a PR to this repo. Here some guidelines to follow:
For your protocol to be included and your users to receive points, you should submit a PR to this repo. Here some guidelines to follow:

1. Make a copy of `.env.example` and name it `.env`.
2. Run `pip install -r requirements.txt` to install the required packages.
3. Add your integration metadata to `constants/integration_ids.py`.
4. Make a copy of `integrations/template.py`, naming the file `[protocol name].py` and place in the `integrations` directory.
5. Your integration must be a class that inherits from `Integration` and implements the `get_balance` and `get_participants` methods.
6. The `get_balance` method should return the balance of a given user at a given block.
7. The `get_participants` method should return a list of all users that have interacted with the protocol.
3. Add your integration metadata to `integrations/integration_ids.py`.
4. Create a new summary column in `constants/summary_columns.py`.
5. Make a copy of [Template](integrations/template.py), naming the file `[protocol name]_integration.py` and place in the `integrations` directory.
6. Your integration must be a class that inherits from `CachedBalancesIntegration` and implements the `get_block_balances` method.
7. The `get_block_balances` method should return a dict of block numbers to a dict of user addresses to balances at that block. (Note: Not all blocks are queried by this service in production- only a sampling, but your code should be capable of handling any block number.)
8. Write some basic tests at the bottom of the file to ensure your integration is working correctly.
9. Submit a PR to this repo with your integration and ping the Ethena team in Telegram.

# Guidelines

- Integrations must follow this architecture and be written in python.
- Pendle integrations are included as examples of functioning integrations. Run `python -m integrations.pendle_lpt_integration` to see the output.
- The `get_balance` and `get_participants` methods should be as efficient as possible.
- We prefer that on chain RPC calls are used to get information as much as possible due to reliability and trustlessness. For example one could cycle through events for `get_participants` and read from a smart contract for `get_balance`. Off chain calls to apis or subgraphs are acceptable if necessary. If usage is not reasonable or the external service is not reliable, users may not receive their sats.
- The `get_block_balances` method should be as efficient as possible. So the use of the cached data from previous blocks if possible is highly encouraged.
- We prefer that on chain RPC calls are used to get information as much as possible due to reliability and trustlessness. Off chain calls to apis or subgraphs are acceptable if necessary. If usage is not reasonable or the external service is not reliable, users may not receive their points.

# Example Integrations
- [ClaimedEnaIntegration](integrations/claimed_ena_example_integration.py): This integration demonstrates how to track ENA token claims using cached balance snapshots for improved performance. It reads from previous balance snapshots to efficiently track user claim history.
- [BeefyCachedBalanceExampleIntegration](integrations/beefy_cached_balance_example_integration.py): This integration is an example of a cached balance integration that is based on API calls.
- [PendleLPTIntegration](integrations/pendle_lpt_integration.py): (Legacy Example) A basic integration showing Pendle LPT staking tracking. Note: This is a non-cached implementation included only for reference - new integrations should use the cached approach for better efficiency.
- [PendleYTIntegration](integrations/pendle_yt_integration.py): (Legacy Example) A basic integration showing Pendle YT staking tracking. Note: This is a non-cached implementation included only for reference - new integrations should use the cached approach for better efficiency.
92 changes: 92 additions & 0 deletions campaign/campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from typing import List
from constants.example_integrations import (
ACTIVE_ENA_START_BLOCK_EXAMPLE,
BEEFY_ARBITRUM_START_BLOCK_EXAMPLE,
)
from integrations.beefy_cached_balance_example_integration import (
BeefyCachedBalanceIntegration,
)
from integrations.claimed_ena_example_integration import ClaimedEnaIntegration
from utils import pendle
from web3 import Web3

from constants.chains import Chain
from constants.pendle import PENDLE_USDE_JULY_DEPLOYMENT_BLOCK
from constants.summary_columns import SummaryColumn
from integrations.integration import Integration
from integrations.integration_ids import IntegrationID
from integrations.pendle_lpt_integration import PendleLPTIntegration
from integrations.pendle_yt_integration import PendleYTIntegration
from integrations.template import ProtocolNameIntegration

# TODO: Add your integration here
INTEGRATIONS: List[Integration] = [
# Template integration
ProtocolNameIntegration(
integration_id=IntegrationID.EXAMPLE,
start_block=20000000,
summary_cols=[SummaryColumn.TEMPLATE_PTS],
chain=Chain.ETHEREUM,
reward_multiplier=20,
excluded_addresses={
Web3.to_checksum_address("0x0000000000000000000000000000000000000000")
},
end_block=40000000,
),
# Example integration using cached user balances for improved performance,
# reads from previous balance snapshots
ClaimedEnaIntegration(
integration_id=IntegrationID.CLAIMED_ENA_EXAMPLE,
start_block=ACTIVE_ENA_START_BLOCK_EXAMPLE,
summary_cols=[SummaryColumn.CLAIMED_ENA_PTS_EXAMPLE],
reward_multiplier=1,
),
# Cached balances integration example, based on API calls
BeefyCachedBalanceIntegration(
integration_id=IntegrationID.BEEFY_CACHED_BALANCE_EXAMPLE,
start_block=BEEFY_ARBITRUM_START_BLOCK_EXAMPLE,
summary_cols=[SummaryColumn.BEEFY_CACHED_BALANCE_EXAMPLE],
chain=Chain.ARBITRUM,
reward_multiplier=1,
),
# Simple Integration class examples (outdated),
# don't use these anymore
PendleLPTIntegration(
integration_id=IntegrationID.PENDLE_USDE_LPT,
start_block=PENDLE_USDE_JULY_DEPLOYMENT_BLOCK,
sy_contract=pendle.sy_contract,
lp_contract=pendle.lpt_contract,
summary_cols=[SummaryColumn.PENDLE_SHARDS],
chain=Chain.ETHEREUM,
reward_multiplier=20,
),
PendleLPTIntegration(
integration_id=IntegrationID.PENDLE_ARBITRUM_USDE_LPT,
start_block=PENDLE_USDE_JULY_DEPLOYMENT_BLOCK,
sy_contract=pendle.usde_arb_SY_contract,
lp_contract=pendle.usde_arb_LPT_contract,
summary_cols=[SummaryColumn.PENDLE_ARBITRUM_SHARDS],
chain=Chain.ARBITRUM,
reward_multiplier=20,
),
PendleYTIntegration(
integration_id=IntegrationID.PENDLE_USDE_YT,
start_block=PENDLE_USDE_JULY_DEPLOYMENT_BLOCK,
summary_cols=[SummaryColumn.PENDLE_SHARDS],
yt_contract=pendle.yt_contract,
chain=Chain.ETHEREUM,
reward_multiplier=20,
),
PendleYTIntegration(
integration_id=IntegrationID.PENDLE_ARBITRUM_USDE_YT,
start_block=PENDLE_USDE_JULY_DEPLOYMENT_BLOCK,
summary_cols=[SummaryColumn.PENDLE_ARBITRUM_SHARDS],
yt_contract=pendle.usde_arb_YT_contract,
chain=Chain.ARBITRUM,
reward_multiplier=20,
),
]


def get_integrations() -> List[Integration]:
return INTEGRATIONS
25 changes: 19 additions & 6 deletions constants/allstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,54 @@
from web3.contract.contract import Contract
from web3 import Web3
from constants.chains import Chain
from constants.integration_ids import IntegrationID
from integrations.integration_ids import IntegrationID

with open("abi/ERC20_abi.json") as f:
erc20_abi = json.load(f)


class StrategyConfig(TypedDict):
start: int
chain: str
chain: Chain
underlying: Contract
strategy: Contract
page_size: int


contract = W3_BY_CHAIN[Chain.ETHEREUM]["w3"].eth.contract

ALLSTAKE_STRATEGIES: Dict[IntegrationID, StrategyConfig] = {
IntegrationID.ALLSTAKE_USDE: StrategyConfig(
start=20810640,
chain=Chain.ETHEREUM,
underlying=contract(
address=Web3.to_checksum_address("0x4c9edd5852cd905f086c759e8383e09bff1e68b3"), abi=erc20_abi
address=Web3.to_checksum_address(
"0x4c9edd5852cd905f086c759e8383e09bff1e68b3"
),
abi=erc20_abi,
),
strategy=contract(
address=Web3.to_checksum_address("0x8B6bF38B812BE4749577303FB8D222576957ff44"), abi=erc20_abi
address=Web3.to_checksum_address(
"0x8B6bF38B812BE4749577303FB8D222576957ff44"
),
abi=erc20_abi,
),
page_size=5000,
),
IntegrationID.ALLSTAKE_SUSDE: StrategyConfig(
start=20811020,
chain=Chain.ETHEREUM,
underlying=contract(
address=Web3.to_checksum_address("0x9d39a5de30e57443bff2a8307a4256c8797a3497"), abi=erc20_abi
address=Web3.to_checksum_address(
"0x9d39a5de30e57443bff2a8307a4256c8797a3497"
),
abi=erc20_abi,
),
strategy=contract(
address=Web3.to_checksum_address("0x5d083d71F7A531F543070b78740880F5A346B53a"), abi=erc20_abi
address=Web3.to_checksum_address(
"0x5d083d71F7A531F543070b78740880F5A346B53a"
),
abi=erc20_abi,
),
page_size=5000,
),
Expand Down
24 changes: 12 additions & 12 deletions constants/balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, Optional

from constants.chains import Chain
from constants.integration_ids import IntegrationID
from integrations.integration_ids import IntegrationID

## If you want to integrate another Balancer Pool, first add it to the IntegrationID enum in integration_ids.py
## Then, add a new entry to the INTEGRATION_CONFIGS dictionary below. Aura integration is optional.
Expand Down Expand Up @@ -42,7 +42,7 @@ class IntegrationConfig:
aura_address="0x56bA1E88340fD53968f686490519Fb0fBB692a39",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_ARBITRUM_GHO_USDE.value: IntegrationConfig(
IntegrationID.BALANCER_ARBITRUM_GHO_USDE: IntegrationConfig(
chain=Chain.ARBITRUM,
start_block=225688025,
incentivized_token=Token.USDE.value,
Expand All @@ -51,7 +51,7 @@ class IntegrationConfig:
gauge_address="0xf2d151c40C18d8097AAa5157eE8f447CBe217269",
aura_address="0x106398c0a78AE85F501FEE16d53A81401469b9B8",
),
IntegrationID.BALANCER_ARBITRUM_WAGHO_USDE.value: IntegrationConfig(
IntegrationID.BALANCER_ARBITRUM_WAGHO_USDE: IntegrationConfig(
chain=Chain.ARBITRUM,
start_block=245277323,
incentivized_token=Token.USDE.value,
Expand All @@ -60,7 +60,7 @@ class IntegrationConfig:
gauge_address="0xcfab2efef3affdd158568dc896115eac26b3c498",
aura_address="0x8f2c4c4ad0b45a3c740e7f7fbc5a106659adeee7",
),
IntegrationID.BALANCER_ARBITRUM_GYD_SUSDE.value: IntegrationConfig(
IntegrationID.BALANCER_ARBITRUM_GYD_SUSDE: IntegrationConfig(
chain=Chain.ARBITRUM,
start_block=240466292,
incentivized_token=Token.SUSDE.value,
Expand All @@ -69,7 +69,7 @@ class IntegrationConfig:
gauge_address="0xdEC026525FE4FEF54857bCF551aEA97aBc24A673",
aura_address="0x2d7cFe43BcDf10137924a20445B763Fb40E5871c",
),
IntegrationID.BALANCER_ARBITRUM_SUSDE_SFRAX.value: IntegrationConfig(
IntegrationID.BALANCER_ARBITRUM_SUSDE_SFRAX: IntegrationConfig(
chain=Chain.ARBITRUM,
start_block=197330091,
incentivized_token=Token.SUSDE.value,
Expand All @@ -79,7 +79,7 @@ class IntegrationConfig:
aura_address="0x0a6a427867a3274909A04276cB5589AE8Cc2dfc7",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_ARBITRUM_SUSDE_USDC.value: IntegrationConfig(
IntegrationID.BALANCER_ARBITRUM_SUSDE_USDC: IntegrationConfig(
chain=Chain.ARBITRUM,
start_block=197316005,
incentivized_token=Token.SUSDE.value,
Expand All @@ -89,7 +89,7 @@ class IntegrationConfig:
aura_address="0x043A59D13884DddCa18b99C3C184C29aAd973b35",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_ETHEREUM_WSTETH_SUSDE.value: IntegrationConfig(
IntegrationID.BALANCER_ETHEREUM_WSTETH_SUSDE: IntegrationConfig(
chain=Chain.ETHEREUM,
start_block=20005052,
incentivized_token=Token.SUSDE.value,
Expand All @@ -98,7 +98,7 @@ class IntegrationConfig:
gauge_address="0xbd00c7cbe59dddbd784c899ac173b7ba514b9997",
aura_address="0x99d9e4d3078f7c9c5b792999749290a54fb87257",
),
IntegrationID.BALANCER_ETHEREUM_BAOUSD_SUSDE.value: IntegrationConfig(
IntegrationID.BALANCER_ETHEREUM_BAOUSD_SUSDE: IntegrationConfig(
chain=Chain.ETHEREUM,
start_block=20169334,
incentivized_token=Token.SUSDE.value,
Expand All @@ -108,7 +108,7 @@ class IntegrationConfig:
aura_address="0xd34793bf42d922b04e7e53253f7195725a4a7e9d",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_ETHEREUM_SUSDE_USDC.value: IntegrationConfig(
IntegrationID.BALANCER_ETHEREUM_SUSDE_USDC: IntegrationConfig(
chain=Chain.ETHEREUM,
start_block=19663564,
incentivized_token=Token.SUSDE.value,
Expand All @@ -118,7 +118,7 @@ class IntegrationConfig:
aura_address="0x4b87dcff2f45535775a9564229119dca5e697a10",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_ETHEREUM_SUSDE_GYD.value: IntegrationConfig(
IntegrationID.BALANCER_ETHEREUM_SUSDE_GYD: IntegrationConfig(
chain=Chain.ETHEREUM,
start_block=20569775,
incentivized_token=Token.SUSDE.value,
Expand All @@ -127,7 +127,7 @@ class IntegrationConfig:
gauge_address="0x146b6030E6d6a6398B918E9854652a71C9537180",
aura_address="0x1f2b312c30b08c1957bd3ada616e77bc7bff51ff",
),
IntegrationID.BALANCER_FRAXTAL_SFRAX_SDAI_SUSDE.value: IntegrationConfig(
IntegrationID.BALANCER_FRAXTAL_SFRAX_SDAI_SUSDE: IntegrationConfig(
chain=Chain.FRAXTAL,
start_block=5931675,
incentivized_token=Token.SUSDE.value,
Expand All @@ -137,7 +137,7 @@ class IntegrationConfig:
aura_address="0x8bb2303ab3ff8bcb1833b71ca14fde75cb88d0b8",
has_preminted_bpts=True,
),
IntegrationID.BALANCER_FRAXTAL_FRAX_USDE_DAI_USDT_USDC.value: IntegrationConfig(
IntegrationID.BALANCER_FRAXTAL_FRAX_USDE_DAI_USDT_USDC: IntegrationConfig(
chain=Chain.FRAXTAL,
start_block=6859850,
incentivized_token=Token.USDE.value,
Expand Down
2 changes: 1 addition & 1 deletion constants/curve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from constants.summary_columns import SummaryColumn
from dataclasses import dataclass
from constants.chains import Chain
from constants.integration_ids import IntegrationID
from integrations.integration_ids import IntegrationID


@dataclass
Expand Down
Loading

0 comments on commit acb4cac

Please sign in to comment.