-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guoshijiang
committed
Mar 27, 2024
1 parent
66c9f31
commit 50cc635
Showing
14 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# encoding=utf-8 | ||
|
||
import json | ||
from common.helpers import ok_json, error_json | ||
from l3staking.models import ( | ||
StakingChain, | ||
StakingStrategy, | ||
Node, | ||
) | ||
|
||
|
||
# @check_api_token | ||
def get_staking_chains(request): | ||
staking_chains = StakingChain.objects.all() | ||
staking_chain_list = [] | ||
for sc in staking_chains: | ||
staking_chain_list.append(sc.as_dict()) | ||
return ok_json(staking_chain_list) | ||
|
||
|
||
# @check_api_token | ||
def get_staking_node_list(request): | ||
params = json.loads(request.body.decode()) | ||
chain_id = params.get('chain_id', 0) | ||
staking_chain = StakingChain.objects.filter(id=chain_id).first() | ||
if staking_chain is None: | ||
return error_json("No support chain", 4000) | ||
staking_strategies = StakingStrategy.objects.filter(chain=staking_chain) | ||
staking_strategies_node_list = [] | ||
for ss in staking_strategies: | ||
staking_nodes = Node.objects.filter(chain_id=ss.chain, strategy=ss).order_by("-id") | ||
staking_node_list = [] | ||
for node in staking_nodes: | ||
staking_node_list.append(node.as_dict()) | ||
staking_strategies_node_list.append({ | ||
"stategy_name": ss.name, | ||
"node_list": staking_node_list | ||
}) | ||
return ok_json(staking_strategies_node_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"channels", | ||
'airdrop', | ||
'website', | ||
'l3staking', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# encoding=utf-8 | ||
|
||
from django.contrib import admin | ||
from l3staking.models import ( | ||
StakingChain, | ||
StakingStrategy, | ||
Node | ||
) | ||
|
||
@admin.register(StakingChain) | ||
class AddressAmountStatAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'name', 'chain_id', 'rpc_url') | ||
|
||
|
||
@admin.register(StakingStrategy) | ||
class AddressAmountStatAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'name') | ||
|
||
|
||
@admin.register(Node) | ||
class AddressAmountStatAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'name', 'eth_income', 'eth_income_rate', 'dp_income', 'dp_income_rate', 'eth_evil', 'eth_evil_rate', 'dp_evil', 'dp_evil_rate', 'tvl') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class L3StakingConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'l3staking' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Generated by Django 4.1.1 on 2024-03-27 11:39 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='StakingChain', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, db_index=True)), | ||
('name', models.CharField(default='', max_length=100, verbose_name='链名称')), | ||
('chain_id', models.CharField(default='', max_length=100, verbose_name='链ID')), | ||
('rpc_url', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='节点 rpc')), | ||
], | ||
options={ | ||
'verbose_name': 'StakingChain', | ||
'verbose_name_plural': 'StakingChain', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='StakingStrategy', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, db_index=True)), | ||
('name', models.CharField(default='Social', max_length=100, verbose_name='质押模块名称')), | ||
], | ||
options={ | ||
'verbose_name': 'StakingStrategy', | ||
'verbose_name_plural': 'StakingStrategy', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Node', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, db_index=True)), | ||
('name', models.CharField(default='unknown', max_length=500, verbose_name='节点名称')), | ||
('eth_income', models.CharField(default='0', max_length=500, verbose_name='Eth 收益金额')), | ||
('eth_income_rate', models.CharField(default='0', max_length=500, verbose_name='Eth 收益率')), | ||
('dp_income', models.CharField(default='0', max_length=500, verbose_name='DP 收益金额')), | ||
('dp_income_rate', models.CharField(default='0', max_length=500, verbose_name='DP 收益率')), | ||
('eth_evil', models.CharField(default='0', max_length=500, verbose_name='Eth 惩罚金额')), | ||
('eth_evil_rate', models.CharField(default='0', max_length=500, verbose_name='Eth 惩罚率')), | ||
('dp_evil', models.CharField(default='0', max_length=500, verbose_name='DP 惩罚金额')), | ||
('dp_evil_rate', models.CharField(default='0', max_length=500, verbose_name='DP 惩罚率')), | ||
('tvl', models.CharField(default='0', max_length=500, verbose_name='总质押量')), | ||
('chain', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='staking_chain', to='l3staking.stakingchain', verbose_name='质押的链')), | ||
('strategy', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='staking_chain', to='l3staking.stakingstrategy', verbose_name='质押策略')), | ||
], | ||
options={ | ||
'verbose_name': 'Node', | ||
'verbose_name_plural': 'Node', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.1.1 on 2024-03-27 11:42 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('l3staking', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='stakingstrategy', | ||
name='chain', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='staking_chain_strategies', to='l3staking.stakingchain', verbose_name='质押的链'), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
# encoding=utf-8 | ||
import pytz | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from common.models import BaseModel, Asset | ||
|
||
|
||
class StakingChain(BaseModel): | ||
name = models.CharField( | ||
default="", | ||
max_length=100, | ||
unique=False, | ||
verbose_name='链名称' | ||
) | ||
chain_id = models.CharField( | ||
default="", | ||
max_length=100, | ||
unique=False, | ||
verbose_name='链ID' | ||
) | ||
rpc_url = models.CharField( | ||
max_length=100, | ||
default="", | ||
blank=True, | ||
null=True, | ||
verbose_name="节点 rpc", | ||
) | ||
|
||
class Meta: | ||
verbose_name = 'StakingChain' | ||
verbose_name_plural = verbose_name | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
def as_dict(self): | ||
tz = pytz.timezone(settings.TIME_ZONE) | ||
return { | ||
'id': self.id, | ||
'title': self.name, | ||
'chain_id': self.chain_id, | ||
'rpc_url': str(self.rpc_url), | ||
'created_at': self.created_at.astimezone(tz).strftime("%Y-%m-%d %H:%M:%S") | ||
} | ||
|
||
|
||
class StakingStrategy(BaseModel): | ||
chain = models.ForeignKey( | ||
StakingChain, | ||
blank=True, | ||
related_name='staking_chain_strategies', | ||
null=True, | ||
on_delete=models.CASCADE, | ||
verbose_name='质押的链' | ||
) | ||
name = models.CharField( | ||
default="Social", | ||
max_length=100, | ||
unique=False, | ||
verbose_name='质押模块名称' | ||
) | ||
|
||
class Meta: | ||
verbose_name = 'StakingStrategy' | ||
verbose_name_plural = verbose_name | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
def as_dict(self): | ||
return { | ||
'id': self.id, | ||
'name': self.name, | ||
} | ||
|
||
|
||
class Node(BaseModel): | ||
chain = models.ForeignKey( | ||
StakingChain, | ||
blank=True, | ||
related_name='staking_chain', | ||
null=True, | ||
on_delete=models.CASCADE, | ||
verbose_name='质押的链' | ||
) | ||
strategy = models.ForeignKey( | ||
StakingStrategy, | ||
blank=True, | ||
related_name='staking_chain', | ||
null=True, | ||
on_delete=models.CASCADE, | ||
verbose_name='质押策略' | ||
) | ||
name = models.CharField( | ||
default="unknown", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='节点名称' | ||
) | ||
eth_income = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='Eth 收益金额' | ||
) | ||
eth_income_rate = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='Eth 收益率' | ||
) | ||
dp_income = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='DP 收益金额' | ||
) | ||
dp_income_rate = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='DP 收益率' | ||
) | ||
eth_evil = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='Eth 惩罚金额' | ||
) | ||
eth_evil_rate = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='Eth 惩罚率' | ||
) | ||
dp_evil = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='DP 惩罚金额' | ||
) | ||
dp_evil_rate = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='DP 惩罚率' | ||
) | ||
tvl = models.CharField( | ||
default="0", | ||
max_length=500, | ||
unique=False, | ||
verbose_name='总质押量' | ||
) | ||
|
||
class Meta: | ||
verbose_name = 'Node' | ||
verbose_name_plural = verbose_name | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
def as_dict(self): | ||
tz = pytz.timezone(settings.TIME_ZONE) | ||
return { | ||
'id': self.id, | ||
'chain': self.chain.name, | ||
'strategy': self.strategy.name, | ||
'name': self.name, | ||
'eth_income': self.eth_income, | ||
'eth_income_rate': self.eth_income_rate, | ||
'dp_income': self.dp_income, | ||
'dp_income_rate': self.dp_income_rate, | ||
'eth_evil': self.eth_evil, | ||
'eth_evil_rate': self.eth_evil_rate, | ||
'dp_evil': self.eth_evil, | ||
'dp_evil_rate': self.eth_evil_rate, | ||
'tvl': self.tvl, | ||
'created_at': self.created_at.astimezone(tz).strftime("%Y-%m-%d %H:%M:%S") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Oops, something went wrong.