Skip to content

Commit

Permalink
Merge pull request #209 from UnitapApp/refactor/relocate-chain-configs
Browse files Browse the repository at this point in the history
Move chain configs from faucet to core
  • Loading branch information
ShayanShiravani authored Dec 4, 2023
2 parents a1b89c9 + 9d7bf47 commit e4a95b9
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 21 deletions.
22 changes: 20 additions & 2 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
from django.contrib import admin

from .models import TokenPrice
from .models import Chain, TokenPrice, WalletAccount


class UserConstraintBaseAdmin(admin.ModelAdmin):
fields = ["name", "title", "type", "description", "explanation", "response", "icon_url"]
fields = [
"name",
"title",
"type",
"description",
"explanation",
"response",
"icon_url",
]
list_display = ["pk", "name", "description"]


class WalletAccountAdmin(admin.ModelAdmin):
list_display = ["pk", "name", "address"]


class ChainAdmin(admin.ModelAdmin):
list_display = ["pk", "chain_name", "chain_id", "symbol", "chain_type"]


class TokenPriceAdmin(admin.ModelAdmin):
list_display = ["symbol", "usd_price", "price_url", "datetime", "last_updated"]
list_filter = ["symbol"]


admin.site.register(WalletAccount, WalletAccountAdmin)
admin.site.register(Chain, ChainAdmin)
admin.site.register(TokenPrice, TokenPriceAdmin)
50 changes: 50 additions & 0 deletions core/migrations/0004_walletaccount_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 4.0.4 on 2023-12-03 08:08

from django.db import migrations, models
import django.db.models.deletion
import encrypted_model_fields.fields


class Migration(migrations.Migration):

dependencies = [
('core', '0003_alter_tokenprice_price_url'),
]

operations = [
migrations.CreateModel(
name='WalletAccount',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255, null=True)),
('private_key', encrypted_model_fields.fields.EncryptedCharField()),
('network_type', models.CharField(choices=[('EVM', 'EVM'), ('Solana', 'Solana'), ('Lightning', 'Lightning'), ('NONEVM', 'NONEVM'), ('NONEVMXDC', 'NONEVMXDC')], default='EVM', max_length=10)),
],
),
migrations.CreateModel(
name='Chain',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('chain_name', models.CharField(max_length=255)),
('chain_id', models.CharField(max_length=255, unique=True)),
('native_currency_name', models.CharField(max_length=255)),
('symbol', models.CharField(max_length=255)),
('decimals', models.IntegerField(default=18)),
('explorer_url', models.URLField(blank=True, max_length=255, null=True)),
('explorer_api_url', models.URLField(blank=True, max_length=255, null=True)),
('explorer_api_key', models.CharField(blank=True, max_length=255, null=True)),
('rpc_url', models.URLField(blank=True, max_length=255, null=True)),
('logo_url', models.URLField(blank=True, max_length=255, null=True)),
('modal_url', models.URLField(blank=True, max_length=255, null=True)),
('rpc_url_private', models.URLField(max_length=255)),
('poa', models.BooleanField(default=False)),
('max_gas_price', models.BigIntegerField(default=250000000000)),
('gas_multiplier', models.FloatField(default=1)),
('enough_fee_multiplier', models.BigIntegerField(default=200000)),
('is_testnet', models.BooleanField(default=False)),
('chain_type', models.CharField(choices=[('EVM', 'EVM'), ('Solana', 'Solana'), ('Lightning', 'Lightning'), ('NONEVM', 'NONEVM'), ('NONEVMXDC', 'NONEVMXDC')], default='EVM', max_length=10)),
('is_active', models.BooleanField(default=True)),
('wallet', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='chains', to='core.walletaccount')),
],
),
]
78 changes: 78 additions & 0 deletions core/migrations/0005_auto_20231203_0832.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 4.0.4 on 2023-12-03 08:32

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('faucet', '0066_rename_is_one_time_chain_is_one_time_claim'),
('core', '0004_walletaccount_chain'),
]

operations = [
migrations.RunSQL("""
INSERT INTO core_walletaccount (
id,
name,
private_key,
network_type
)
SELECT
id,
name,
private_key,
network_type
FROM
faucet_walletaccount;
INSERT INTO core_chain (
id,
chain_name,
symbol,
chain_id,
rpc_url,
decimals,
explorer_url,
logo_url,
native_currency_name,
poa,
rpc_url_private,
wallet_id,
modal_url,
max_gas_price,
gas_multiplier,
chain_type,
is_testnet,
is_active,
enough_fee_multiplier,
explorer_api_key,
explorer_api_url
)
SELECT
id,
chain_name,
symbol,
chain_id,
rpc_url,
decimals,
explorer_url,
logo_url,
native_currency_name,
poa,
rpc_url_private,
wallet_id,
modal_url,
max_gas_price,
gas_multiplier,
chain_type,
is_testnet,
is_active,
enough_fee_multiplier,
explorer_api_key,
explorer_api_url
FROM
faucet_chain;
SELECT setval(pg_get_serial_sequence('"core_walletaccount"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_walletaccount";
SELECT setval(pg_get_serial_sequence('"core_chain"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_chain";
""", reverse_sql="")
]
Loading

0 comments on commit e4a95b9

Please sign in to comment.