Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token attribute information to ListAllPositions #746

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/model/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@
from .position import (
ForceUnlockRequest,
ListAllLockedPositionResponse,
ListAllLockedPositionsQuery,
ListAllLockEventsQuery,
ListAllLockEventsResponse,
ListAllLockEventsSortItem,
ListAllPositionResponse,
ListAllPositionsQuery,
LockEventCategory,
PositionResponse,
)
Expand Down
2 changes: 2 additions & 0 deletions app/model/schema/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
BasePaginationQuery,
CURRENCY_str,
EMPTY_str,
IbetShare,
IbetShareContractVersion,
IbetStraightBond,
IbetStraightBondContractVersion,
KeyManagerType,
MMDD_constr,
Expand Down
60 changes: 60 additions & 0 deletions app/model/schema/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,72 @@ class IbetStraightBondContractVersion(StrEnum):
V_24_09 = "24_09"


class IbetStraightBond(BaseModel):
"""IbetStraightBond schema"""

issuer_address: str
token_address: str
name: str
symbol: str
total_supply: int
face_value: int
face_value_currency: str
redemption_date: str
redemption_value: int
redemption_value_currency: str
return_date: str
return_amount: str
purpose: str
interest_rate: float
interest_payment_date: list[str]
interest_payment_currency: str
base_fx_rate: float
transferable: bool
is_redeemed: bool
status: bool
is_offering: bool
tradable_exchange_contract_address: str
personal_info_contract_address: str
require_personal_info_registered: bool
contact_information: str
privacy_policy: str
transfer_approval_required: bool
memo: str


class IbetShareContractVersion(StrEnum):
V_22_12 = "22_12"
V_24_06 = "24_06"
V_24_09 = "24_09"


class IbetShare(BaseModel):
"""IbetShare schema"""

issuer_address: str
token_address: str
name: str
symbol: str
issue_price: int
principal_value: int
total_supply: int
dividends: float
dividend_record_date: str
dividend_payment_date: str
cancellation_date: str
transferable: bool
transfer_approval_required: bool
status: bool
is_offering: bool
tradable_exchange_contract_address: str
personal_info_contract_address: str
require_personal_info_registered: bool
contact_information: str
privacy_policy: str
is_canceled: bool
memo: str


MMDD_constr = Annotated[
str, StringConstraints(pattern="^(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$")
]
Expand Down
32 changes: 28 additions & 4 deletions app/model/schema/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
"""

from enum import StrEnum
from typing import List, Optional
from typing import List, Optional, Union

from pydantic import BaseModel, Field, PositiveInt, RootModel

from app.model import EthereumAddress

from .base import BasePaginationQuery, ResultSet, SortOrder, TokenType
from .base import (
BasePaginationQuery,
IbetShare,
IbetStraightBond,
ResultSet,
SortOrder,
TokenType,
)


############################
Expand All @@ -37,6 +44,9 @@ class Position(BaseModel):
token_address: str = Field(description="Token address")
token_type: TokenType = Field(description="Token type")
token_name: str = Field(description="Token name")
token_attributes: Optional[Union[IbetStraightBond, IbetShare]] = Field(
description="Token attributes"
)
balance: int = Field(description="Balance")
exchange_balance: int = Field(description="Balance on the exchange contract")
exchange_commitment: int = Field(description="Commitment on the exchange contract")
Expand Down Expand Up @@ -83,6 +93,22 @@ class LockEvent(BaseModel):
############################
# REQUEST
############################
class ListAllPositionsQuery(BasePaginationQuery):
include_former_position: bool = Field(
False,
description="Whether to include positions that were held in the past but currently have a zero balance.",
)
include_token_attributes: bool = Field(
False,
description="Whether to include token attribute information in the response.",
)
token_type: Optional[TokenType] = Field(None, description="Token type")


class ListAllLockedPositionsQuery(BasePaginationQuery):
token_type: Optional[TokenType] = Field(None, description="Token type")


class ListAllLockEventsSortItem(StrEnum):
token_address = "token_address"
lock_address = "lock_address"
Expand Down Expand Up @@ -117,8 +143,6 @@ class ForceUnlockRequest(BaseModel):
############################
# RESPONSE
############################


class PositionResponse(RootModel[Position]):
"""Position schema (Response)"""

Expand Down
56 changes: 4 additions & 52 deletions app/model/schema/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
BasePaginationQuery,
CURRENCY_str,
EMPTY_str,
IbetShare,
IbetShareContractVersion,
IbetStraightBond,
IbetStraightBondContractVersion,
MMDD_constr,
ResultSet,
Expand Down Expand Up @@ -466,69 +468,19 @@ class TokenAddressResponse(BaseModel):
token_status: int


class IbetStraightBondResponse(BaseModel):
class IbetStraightBondResponse(IbetStraightBond):
"""ibet Straight Bond schema (Response)"""

issuer_address: str
token_address: str
name: str
symbol: str
total_supply: int
face_value: int
face_value_currency: str
redemption_date: str
redemption_value: int
redemption_value_currency: str
return_date: str
return_amount: str
purpose: str
interest_rate: float
interest_payment_date: list[str]
interest_payment_currency: str
base_fx_rate: float
transferable: bool
is_redeemed: bool
status: bool
is_offering: bool
tradable_exchange_contract_address: str
personal_info_contract_address: str
require_personal_info_registered: bool
contact_information: str
privacy_policy: str
issue_datetime: str
token_status: int
transfer_approval_required: bool
memo: str
contract_version: IbetStraightBondContractVersion


class IbetShareResponse(BaseModel):
class IbetShareResponse(IbetShare):
"""ibet Share schema (Response)"""

issuer_address: str
token_address: str
name: str
symbol: str
issue_price: int
principal_value: int
total_supply: int
dividends: float
dividend_record_date: str
dividend_payment_date: str
cancellation_date: str
transferable: bool
transfer_approval_required: bool
status: bool
is_offering: bool
tradable_exchange_contract_address: str
personal_info_contract_address: str
require_personal_info_registered: bool
contact_information: str
privacy_policy: str
issue_datetime: str
token_status: int
is_canceled: bool
memo: str
contract_version: IbetShareContractVersion


Expand Down
Loading
Loading