File size: 5,784 Bytes
002494e
d6c64d5
 
002494e
d6c64d5
002494e
d6c64d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb71589
d6c64d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
022bff0
 
 
 
9843af0
 
0a53ad9
9843af0
022bff0
d6c64d5
 
 
 
 
e6e6f96
d6c64d5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import gradio as gr
import pandas as pd
import time

# --- 1. Compliance Simulator Logic ---

def compliance_check(investor_country, accreditation_status, investment_amount):
    """
    Simulates the Kancil L1's native Compliance Engine pre-compile check.
    Compliance rules are hardcoded for demonstration purposes.
    """
    time.sleep(1) # Simulate network latency

    # Rule 1: Must be an accredited investor for high-value RWA
    if accreditation_status != "Accredited Investor":
        return f"❌ **Transaction Rejected**\n\nReason: Investor status '{accreditation_status}' does not meet the minimum requirement of 'Accredited Investor' for this RWA token. Compliance enforced at L1 protocol level."

    # Rule 2: Geo-fencing (e.g., cannot invest from a sanctioned country)
    if investor_country in ["North Korea", "Iran", "Syria"]:
        return f"❌ **Transaction Rejected**\n\nReason: Investor country '{investor_country}' is on the network's restricted list. Compliance enforced at L1 protocol level."

    # Rule 3: Minimum investment threshold
    if investment_amount < 10000:
        return f"❌ **Transaction Rejected**\n\nReason: Investment amount (${investment_amount:,.2f}) is below the minimum required threshold of $10,000. Compliance enforced at L1 protocol level."

    # If all checks pass
    return f"✅ **Transaction Approved**\n\nCompliance Engine Pre-Compile Check Passed. Token transfer is authorized."

# --- 2. DAO Voting Mockup Logic ---

# Initial state of the DAO proposal
dao_proposal = {
    "title": "K-DAO Proposal 001: Approve Tokenization of Dubai Office Tower (Asset ID: DXB-CRE-001)",
    "description": "Proposal to onboard a $50M Commercial Real Estate asset located in the Dubai International Financial Centre (DIFC).",
    "yes_votes": 1500000,
    "no_votes": 500000,
    "quorum": 2000000,
    "status": "Active",
    "end_date": "2026-01-31"
}

# Mock function to update the vote count
def cast_vote(vote_type, voting_power):
    global dao_proposal
    if dao_proposal["status"] != "Active":
        return "Voting is closed."

    try:
        power = int(voting_power)
    except ValueError:
        return "Invalid voting power. Please enter a number."

    if vote_type == "Yes":
        dao_proposal["yes_votes"] += power
    elif vote_type == "No":
        dao_proposal["no_votes"] += power

    # Check if quorum is met
    total_votes = dao_proposal["yes_votes"] + dao_proposal["no_votes"]
    if total_votes >= dao_proposal["quorum"]:
        dao_proposal["status"] = "Passed" if dao_proposal["yes_votes"] > dao_proposal["no_votes"] else "Failed"

    return display_dao_status()

# Function to display the current DAO status
def display_dao_status():
    total_votes = dao_proposal["yes_votes"] + dao_proposal["no_votes"]
    progress = (total_votes / dao_proposal["quorum"]) * 100
    
    status_text = f"""
    **Proposal:** {dao_proposal['title']}
    **Status:** {dao_proposal['status']}
    **Quorum Required:** {dao_proposal['quorum']:,} $KANCIL
    **Total Votes Cast:** {total_votes:,} $KANCIL
    **Yes Votes:** {dao_proposal['yes_votes']:,} $KANCIL
    **No Votes:** {dao_proposal['no_votes']:,} $KANCIL
    **Voting Ends:** {dao_proposal['end_date']}
    """
    return status_text

# --- 3. Asset Dashboard Mockup (Static) ---

asset_data = {
    "Metric": ["Asset ID", "Asset Type", "Location", "Total Value Tokenized", "Tokens Issued", "Compliance Status", "Last Income Distribution"],
    "Value": ["DXB-CRE-001", "Commercial Real Estate (Office)", "Dubai, UAE", "$50,000,000", "50,000,000", "Fully Compliant (Kancil L1 Enforced)", "2025-12-01 (Automated by Smart Contract)"]
}
asset_df = pd.DataFrame(asset_data)

# --- Gradio Interface Setup ---

# Compliance Simulator Tab
compliance_tab = gr.Interface(
    fn=compliance_check,
    inputs=[
        gr.Dropdown(["USA", "UAE", "Singapore", "Germany", "UK", "Japan"], label="Investor Country (Simulated Geo-Fencing)"),
        gr.Dropdown(["Accredited Investor", "Non-Accredited Investor", "Institutional Investor"], label="Accreditation Status (Simulated Whitelist)"),
        gr.Slider(minimum=1000, maximum=100000, step=1000, value=10000, label="Investment Amount (Simulated Threshold)")
    ],
    outputs=gr.Markdown(label="Kancil L1 Compliance Engine Result"),
    title="Kancil L1 Compliance Simulator",
    description="Demonstrates the L1's native pre-compile for enforcing RWA compliance rules before a transaction is executed."
)

# DAO Voting Tab
dao_status_output = gr.Markdown(value=display_dao_status())

dao_tab = gr.Interface(
    fn=cast_vote,
    inputs=[
        gr.Radio(["Yes", "No"], label="Your Vote"),
        gr.Number(label="Your Voting Power ($KANCIL)", value=1000)
    ],
    outputs=dao_status_output,
    title="Kancil Asset Management DAO (K-DAO) Mockup",
    description="Simulates the decentralized governance process for approving new assets and network changes."
)

# Asset Dashboard Tab
with gr.Blocks() as asset_tab:
    gr.Markdown("## Tokenized Asset Dashboard (Static Mockup)")
    gr.Markdown("A static view of a tokenized asset, showing the data transparency and visual representation enabled by the Kancil L1.")
    
    # FIX: Removed type="filepath" and relied on Gradio's static file serving for the value.
    # This avoids the internal file-moving logic that caused the NotADirectoryError.
    gr.Image(label="Tokenized Asset Visual (DXB-CRE-001)", value="assets/cre_exterior.png")
    gr.Dataframe(value=asset_df, label="Asset Metadata")


# Combine all tabs
demo = gr.TabbedInterface(
    [compliance_tab, dao_tab, asset_tab],
    ["Compliance Simulator", "K-DAO Voting", "Asset Dashboard"],
    title="Kancil: Autonomous RWA L1 MVP(Demo)"
)

if __name__ == "__main__":
    demo.launch()