Skip to content

Commit be2ec47

Browse files
authored
Merge pull request #12 from 8ball030/feat/create_subaccount
feat: add-create-subaccount
2 parents 3e0f82a + 4b30ee0 commit be2ec47

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

.github/workflows/unit-test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Unit-test
22

3-
on: push
3+
on:
4+
push:
5+
workflow_dispatch:
46
jobs:
57
build:
68
name: Unit-test 🎯
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from dataclasses import dataclass
2+
3+
from eth_abi.abi import encode
4+
from .module_data import ModuleData
5+
from ..utils import decimal_to_big_int
6+
from web3 import Web3
7+
8+
9+
@dataclass
10+
class CreateSubAccountDetails:
11+
amount: int
12+
base_asset_address: str
13+
sub_asset_address: str
14+
15+
def to_eth_tx_params(self):
16+
return (
17+
decimal_to_big_int(self.amount),
18+
Web3.to_checksum_address(self.base_asset_address),
19+
Web3.to_checksum_address(self.sub_asset_address),
20+
)
21+
22+
23+
@dataclass
24+
class CreateSubAccountData(ModuleData):
25+
amount: int
26+
asset_name: str
27+
margin_type: str
28+
create_account_details: CreateSubAccountDetails
29+
30+
def to_abi_encoded(self):
31+
return encode(
32+
['uint256', 'address', 'address'],
33+
self.create_account_details.to_eth_tx_params(),
34+
)
35+
36+
def to_json(self):
37+
return {}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
"""
2+
Base class for all module data classes
3+
"""
4+
from abc import ABC, abstractmethod
15
from dataclasses import dataclass
26

37

48
@dataclass
5-
class ModuleData:
9+
class ModuleData(ABC):
10+
"""Abstract Base class for all module data classes"""
11+
12+
@abstractmethod
613
def to_abi_encoded(self):
7-
pass
14+
"""Return the data in ABI encoded format"""
15+
raise NotImplementedError
816

17+
@abstractmethod
918
def to_json(self):
10-
pass
19+
"""Return the data in JSON format"""
20+
raise NotImplementedError

0 commit comments

Comments
 (0)