Code Monkey home page Code Monkey logo

safe-locking-service's Introduction

Python CI Coverage Status pre-commit Python 3.12 Django 5 Docker Image Version (latest semver)

Safe Locking Service

Keeps track emitted events by Safe token locking contract. https://github.com/safe-global/safe-locking

Configuration

cp .env.sample .env

Configure environment variables on .env:

  • DJANGO_SECRET_KEY: IMPORTANT: Update it with a secure generated string.
  • ETHEREUM_NODE_URL: RPC node url.

Execution

docker compose build
docker compose up

Then go to http://localhost:8000 to see the service documentation.

Endpoints

  • /v1/about

Setup for development

Use a virtualenv if possible:

python -m venv venv

Then enter the virtualenv and install the dependencies:

source venv/bin/activate
pip install -r requirements-dev.txt
pre-commit install -f
cp .env.sample .env
./run_tests.sh

Contributors

See contributors

safe-locking-service's People

Contributors

dependabot[bot] avatar moisses89 avatar fmrsabino avatar falvaradorodriguez avatar uxio0 avatar

Watchers

Lucian avatar Richard Meissner avatar  avatar  avatar  avatar  avatar  avatar

safe-locking-service's Issues

Add boolean field to hide campaigns

What is needed?

We should able to prepare campaigns without to publishing them and just unhidden them when they are released.
To achieve this would be necessary add to the model the boolean field to indicate if the campaign is public or not and be able to handle it from admin view.
The related campaign endpoints won´t show hidden campaigns.

Add admin views

What is needed?

Add admin views for:

  • EthereumTx
  • LockEvents
  • UnlockEvents
  • WithdrawnEvents

Add campaign fields

What is needed?

We would like to add new campaign fields to database model, and return them accordingly in the endpoint view.
New campaign fields:
rewardValue - number eg: 600,000
rewardText - string e.g. "Some text description of reward"
iconUrl - string
safeAppUrl - string
partnerUrl - string

iconUrl should return the stored icon link and the admin page must support upload an icon per campaign.
All the previous fields can be nullable

Add LeaderBoard endpoint

What is needed?

An endpoint to return a list of top holders and the position for one Safe.

GET /api/v1/leaderboard

Response:

[{
			"holder": "<HexString>",
			"position": "<int>",
			"lockedAmount": "<uint96>", // sum(lockEvents) - sum(unlockEvents)
			"unlockedAmount": "<uint96>", // sum(unlockEvents)
			"withdrawnAmount": "<uint96>", // sum(withdrawnEvents)
},...]

GET /api/v1/leaderboard/{holder_address}

Response:

{
			"holder": "<HexString>",
			"position": "<int>",
			"lockedAmount": "<uint96>", // sum(lockEvents) - sum(unlockEvents)
			"unlockedAmount": "<uint96>", // sum(unlockEvents)
			"withdrawnAmount": "<uint96>", // sum(withdrawnEvents)
}

Add Leaderboard campaign cache

What is needed?

Campaign leaderboard will change more or less in a weekly basis, that means have a cache of 1 minute is not the better solution.
We would like to add cache for 5 days and be able to invalidate this cache when the activitys campaign data is updated.

Create database models for events

Events

One table for every event type, all of of them with a ForeignKey to a EthereumTx table. Remember to store the logIndex

    event Locked(address indexed holder, uint96 amount);
    event Unlocked(address indexed holder, uint32 indexed index, uint96 amount);
    event Withdrawn(address indexed holder, uint32 indexed index, uint96 amount);
  • No need for EthereumBlock table. It should be enough with only a EthereumTx table with:
    • tx_hash (primary key)
    • block_hash
    • block_number

Dependencies

Source

https://github.com/safe-global/safe-locking/blob/main/contracts/interfaces/ISafeTokenLock.sol

Add GET Locked events by holder

GET /api/v1/locked/{holder-address} → paginated list of locked events

Response:

[
    {
			"executionDate": "timestamp",
			"transactionHash": "StringHAsh",
			"holder": "ChecksumedAddress",
			"amount": "uint96",
			"logIndex": "int32",
		}...
]
			

Tasks:

  • Add view
  • Add happy path tests

/lock-events endpoint - older events first shown instead of the newest ones

Describe the bug
We need to change the order of the results shown so that the newest events are shown first instead of the oldest ones:

{
    "count": 4,
    "next": "https://safe-locking-sepolia.staging.5afe.dev/api/v1/lock-events/0x0A64A32c010aa70fe79Ac32acAeFF0B3a7EE76b3/?limit=2&offset=2",
    "previous": null,
    "results": [
        {
            "executionDate": "2024-03-21T14:52:12Z",
            "transactionHash": "0xf68a7b792d5b6de473522435093a706606685035d7cc4941d3b58f0f0fa25116",
            "holder": "0x0A64A32c010aa70fe79Ac32acAeFF0B3a7EE76b3",
            "amount": "100000000000",
            "logIndex": "255"
        },
        {
            "executionDate": "2024-04-05T14:38:24Z",
            "transactionHash": "0x9d043871926caf2fe57192bdbc2d5490c0d57fd3f9e1996a72fe77e8e61829db",
            "holder": "0x0A64A32c010aa70fe79Ac32acAeFF0B3a7EE76b3",
            "amount": "200000000000000000000",
            "logIndex": "18"
        }
    ]
}

Add endpoint to list campaigns

What is needed?

Add an endpoint to return a list of campaigns ordered by descending period start time.

GET /api/v1/campaigns/

Add GET Unlocked events by holder

GET /api/v1/unlocked/{holder-address} → paginated list of unlocked events

Response:

[
    {
			"executionDate": "timestamp",
			"transactionHash": "StringHAsh",
			"holder": "ChecksumedAddress",
			"amount": "uint96",
			"unlockIndex": "int32",
			"logIndex": "int32",
		}...
]

Tasks:

  • Add view
  • Add happy path tests

Add Upload Role

What is needed?

Create a admin user role without superuser permission that can do:

  • Create/List/Update campaigns
  • Create/List/Update periods
  • Create/List/Update file per period.

Add leaderboard endpoint by campaign

What is needed?

An endpoint by campaign that returns a list with all the holders ordered by total gotten points for the provided campaign

GET /api/v2/leaderboard/campaign

Missing serializer in about view

Describe the bug
A warning message is logged when request about view because the serializer is not defined.

2024-04-03 14:50:35,360 [WARNING] [MainProcess] view's AboutView raised exception during schema generation; use `getattr(self, 'swagger_fake_view', False)` to detect and short-circuit this
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/drf_yasg/inspectors/base.py", line 42, in call_view_method
    return view_method()
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/generics.py", line 108, in get_serializer
    serializer_class = self.get_serializer_class()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/generics.py", line 122, in get_serializer_class
    assert self.serializer_class is not None, (
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'AboutView' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method.

Add an endpoint to return period points.

What is needed?

Add a GET endpoint for a campaign and address that return a list of period points.

GET /api/v1/campaign/{resourceID}/periods/{address}

Response

To Be Defined

Add GET all-events by holder

Implement paginated endpoint to return all-events:

[
                {
			"eventType": "LOCKED",
			"executionDate": "<timestamp>",
			"transactionHash": "<HexString>",
			"holder": "<HexString>",
			"amount": "<uint96>",
			"logIndex": "<int32>",
		},{
			"eventType": "UNLOCKED",
			"executionDate": "<timestamp>",
			"transactionHash": "<HexString>",
			"holder": "<HexString>",
			"amount": "<uint96>",
			"unlockIndex": "<int32>",
			"logIndex": "<int32>",
		},{
			"eventType": "WITHDRAWN",
			"executionDate": "<timestamp>",
			"transactionHash": "<HexString>",
			"holder": "<HexString>",
			"amount": "<uint96>",
			"unlockIndex": "<int32>",
			"logIndex": "<int32>",
		},
]

What is needed?

  • Add serializer and view
  • Add happy path tests

Add GET Withdrawn events by holder

GET /api/v1/withdrawn/{holder-address} → paginated list of withdrawn events

Response:

[
    {
			"executionDate": "timestamp",
			"transactionHash": "StringHAsh",
			"holder": "ChecksumedAddress",
			"amount": "uint96",
			"unlockIndex": "int32",
			"logIndex": "int32",
		}...
]

Tasks:

  • Add View
  • Add happy path tests

Add Activities Model

What is needed?

A model that fits with the CSV activities file.
In this stage we will store all the necessary fields from the activity CSV file in a table.

Adds a Reorgs checker.

What is needed?

Reorgs are going to happen and this service should be able to manage them.

Add coverage

Coverage we will disable at the beginning of the project because is private, this is a reminder to add it later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.