Skip to content

Commit

Permalink
Merge pull request #280 from xian-network/genesis-rc
Browse files Browse the repository at this point in the history
genesis block for rcnet
  • Loading branch information
crosschainer authored Sep 17, 2024
2 parents 84d4a99 + 70789f8 commit cee2379
Show file tree
Hide file tree
Showing 6 changed files with 581 additions and 5 deletions.
55 changes: 55 additions & 0 deletions src/xian/tools/genesis/contracts/contracts_rcnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"extension": ".s.py",
"contracts": [
{
"name": "currency",
"owner": null,
"constructor_args": {
"vk": "13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e"
}
},
{
"name": "stamp_cost",
"owner": "masternodes",
"constructor_args": {
"initial_rate": 20
}
},
{
"name": "rewards",
"owner": "masternodes",
"constructor_args": null
},
{
"name": "foundation",
"owner": null,
"constructor_args": {
"vk": "13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e"
}
},
{
"name": "dao",
"owner": "masternodes",
"constructor_args": null
},
{
"name": "members",
"submit_as": "masternodes",
"owner": null,
"constructor_args": {
"genesis_nodes": ["13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e","d37ddb28488fe1bae65279934d6800fae11b26f7c01511b76ca6e602bbc2398d", "40447f46cea1260dd7487833cff630a65b7868f19aafdfd6465b989c9a6dba0e","8e73052eed03e60d4f27e4e422c0742cd2a755ac034122bd504a87afad746f8a","ca9aeee192854dc55a6d3e211bf858cc3ecd41e8b86a55c07740ece29f349597"],
"genesis_registration_fee": 100000
}
},
{
"name": "vault",
"submit_as": "team_lock",
"owner": null,
"constructor_args": {
"initial_owners":"6ebd8090a80e5fc629f38fceefd05d66035a5a4d4ba2c223319ec8f9b83cb48a,081e233f4e122a5fd79ff3c44f9d58848c3214f7110130936661394403100a9a,503ccb3dc04eaaed7c72c3ee6d22368e48a7f7e52b8577f4a4a9989eec51a0be",
"initial_required_signatures": 2,
"stream": "team_vesting"
}
}
]
}
6 changes: 3 additions & 3 deletions src/xian/tools/genesis/contracts/currency.s.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
@construct
def seed(vk: str):
balances[vk] = 5555555.55 # 5% Team Tokens
balances["team_lock"] = 16666666.65 # 15% Team Tokens 5 Year Release, Directly minted into Lock contract
balances["team_vesting"] = 16666666.65 # 15% Team Tokens 5 Year Release, Directly minted into Lock contract
balances["dao"] = 33333333.3 # 30% DAO Tokens, Directly minted into DAO contract
balances[vk] += 49999999.95 # 45% Second batch of public tokens, to be sent out after mint
balances["team_lock"] += 49999999.95 # 45% Second batch of public tokens, to be sent out after mint
balances[vk] += 5555555.55 # 5% First batch of public tokens, to be sent out after mint

# TEAM LOCK
# 365 * 4 + 364 = 1824 (4 years + 1 leap-year)
# 1824 * 24 * 60 * 60 = 157593600 (seconds in duration)
# 16666666.65 / 157593600 (release per second)

setup_seed_stream("team_lock", "team_lock", vk, 0.10575725568804825, 1824)
setup_seed_stream("team_vesting", "team_vesting", "team_lock", 0.10575725568804825, 1824)


def setup_seed_stream(stream_id: str, sender: str, receiver: str, rate: float, duration_days: int):
Expand Down
2 changes: 1 addition & 1 deletion src/xian/tools/genesis/contracts/rewards.s.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
S = Hash()

@construct
def seed(initial_split: list = [0.88, 0.01, 0.01, 0.1]):
def seed(initial_split: list = [0.30, 0.01, 0.01, 0.68]):
S['value'] = initial_split

@export
Expand Down
117 changes: 117 additions & 0 deletions src/xian/tools/genesis/contracts/vault.s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import currency

owners = Hash()
required_signatures = Variable()
owner_count = Variable()
transaction_count = Variable()
stream_id = Variable()
transactions = Hash()

@construct
def seed(initial_owners: str, initial_required_signatures: int, stream: str):
"""
Initializes the multisig contract.
- initial_owners: Comma-separated string of owner addresses.
- initial_required_signatures: Number of required signatures to execute a transaction.
"""
owner_list = initial_owners.split(',')
for owner in owner_list:
owners[owner.strip()] = True

required_signatures.set(initial_required_signatures)
owner_count.set(len(owner_list))
transaction_count.set(0)
stream_id.set(stream)

@export
def submit_transaction(to: str = None, amount: float = None, tx_type: str = 'transfer'):
"""
Submits a new transaction to the multisig wallet.
- to: Recipient address.
- amount: Amount of tokens to transfer.
- tx_type: Type of transaction ('transfer', 'addOwner', 'removeOwner', 'changeRequirement').
"""
assert owners[ctx.caller], 'Only owners can submit transactions.'

tx_id = transaction_count.get() + 1
transaction_count.set(tx_id)

transactions[tx_id, 'type'] = tx_type
transactions[tx_id, 'to'] = to
transactions[tx_id, 'amount'] = amount
transactions[tx_id, 'executed'] = False
transactions[tx_id, 'approvals'] = 0

# The submitter approves the transaction by default
approve_transaction(tx_id)

return f"Transaction {tx_id} submitted."

@export
def approve_transaction(tx_id: int):
"""
Approves a pending transaction.
- tx_id: The ID of the transaction to approve.
"""
assert owners[ctx.caller], 'Only owners can approve transactions.'
assert not transactions[tx_id, 'executed'], 'Transaction already executed.'
assert transactions[tx_id, 'type'] is not None, 'Transaction does not exist.'
assert not transactions[tx_id, 'approvers', ctx.caller], 'Already approved.'

transactions[tx_id, 'approvers', ctx.caller] = True
transactions[tx_id, 'approvals'] += 1

return f"Transaction {tx_id} approved by {ctx.caller}."

@export
def execute_transaction(tx_id: int):
"""
Executes a transaction if enough approvals are collected.
- tx_id: The ID of the transaction to execute.
"""
assert owners[ctx.caller], 'Only owners can execute transactions.'
assert not transactions[tx_id, 'executed'], 'Transaction already executed.'
assert transactions[tx_id, 'type'] is not None, 'Transaction does not exist.'
approvals = transactions[tx_id, 'approvals']
required = required_signatures.get()
assert approvals >= required, 'Not enough approvals.'

tx_type = transactions[tx_id, 'type']
to = transactions[tx_id, 'to']
amount = transactions[tx_id, 'amount']

if tx_type == 'transfer':
currency.transfer(amount=amount, to=to)
elif tx_type == 'addOwner':
assert to is not None, 'No owner specified to add.'
assert not owners[to], 'Address is already an owner.'
owners[to] = True
owner_count.set(owner_count.get() + 1)
elif tx_type == 'removeOwner':
assert to is not None, 'No owner specified to remove.'
assert owners[to], 'Address is not an owner.'
owners[to] = False
owner_count.set(owner_count.get() - 1)
if required_signatures.get() > owner_count.get():
required_signatures.set(owner_count.get())
elif tx_type == 'changeRequirement':
assert amount is not None, 'No new requirement specified.'
new_requirement = int(amount)
assert new_requirement > 0, 'Requirement must be greater than zero.'
total_owners = owner_count.get()
assert new_requirement <= total_owners, 'Requirement cannot be greater than number of owners.'
required_signatures.set(new_requirement)
else:
return 'Invalid transaction type.'

transactions[tx_id, 'executed'] = True

return f"Transaction {tx_id} executed."

@export
def balance_stream():
"""
Executes balance_stream function from currency
contract which sends tokens to this contract
"""
currency.balance_stream(stream_id.get())
Loading

0 comments on commit cee2379

Please sign in to comment.