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

fix: backport js changes to python #213

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

class GlobalConfigJSON(typing.TypedDict):
emergency_mode: int
local_admins_blocked: int
flash_take_order_blocked: int
new_orders_blocked: int
orders_matching_blocked: int
orders_taking_blocked: int
host_fee_bps: int
is_order_taking_permissionless: int
padding0: list[int]
padding1: list[int]
pda_authority_previous_lamports_balance: int
Expand All @@ -33,11 +34,12 @@ class GlobalConfig:
discriminator: typing.ClassVar = b"\x95\x08\x9c\xca\xa0\xfc\xb0\xd9"
layout: typing.ClassVar = borsh.CStruct(
"emergency_mode" / borsh.U8,
"local_admins_blocked" / borsh.U8,
"flash_take_order_blocked" / borsh.U8,
"new_orders_blocked" / borsh.U8,
"orders_matching_blocked" / borsh.U8,
"orders_taking_blocked" / borsh.U8,
"host_fee_bps" / borsh.U16,
"padding0" / borsh.U8[2],
"is_order_taking_permissionless" / borsh.U8,
"padding0" / borsh.U8[1],
"padding1" / borsh.U64[10],
"pda_authority_previous_lamports_balance" / borsh.U64,
"total_tip_amount" / borsh.U64,
Expand All @@ -48,10 +50,11 @@ class GlobalConfig:
"padding2" / borsh.U64[247],
)
emergency_mode: int
local_admins_blocked: int
flash_take_order_blocked: int
new_orders_blocked: int
orders_matching_blocked: int
orders_taking_blocked: int
host_fee_bps: int
is_order_taking_permissionless: int
padding0: list[int]
padding1: list[int]
pda_authority_previous_lamports_balance: int
Expand Down Expand Up @@ -107,10 +110,11 @@ def decode(cls, data: bytes) -> "GlobalConfig":
dec = GlobalConfig.layout.parse(data[ACCOUNT_DISCRIMINATOR_SIZE:])
return cls(
emergency_mode=dec.emergency_mode,
local_admins_blocked=dec.local_admins_blocked,
flash_take_order_blocked=dec.flash_take_order_blocked,
new_orders_blocked=dec.new_orders_blocked,
orders_matching_blocked=dec.orders_matching_blocked,
orders_taking_blocked=dec.orders_taking_blocked,
host_fee_bps=dec.host_fee_bps,
is_order_taking_permissionless=dec.is_order_taking_permissionless,
padding0=dec.padding0,
padding1=dec.padding1,
pda_authority_previous_lamports_balance=dec.pda_authority_previous_lamports_balance,
Expand All @@ -125,10 +129,11 @@ def decode(cls, data: bytes) -> "GlobalConfig":
def to_json(self) -> GlobalConfigJSON:
return {
"emergency_mode": self.emergency_mode,
"local_admins_blocked": self.local_admins_blocked,
"flash_take_order_blocked": self.flash_take_order_blocked,
"new_orders_blocked": self.new_orders_blocked,
"orders_matching_blocked": self.orders_matching_blocked,
"orders_taking_blocked": self.orders_taking_blocked,
"host_fee_bps": self.host_fee_bps,
"is_order_taking_permissionless": self.is_order_taking_permissionless,
"padding0": self.padding0,
"padding1": self.padding1,
"pda_authority_previous_lamports_balance": self.pda_authority_previous_lamports_balance,
Expand All @@ -144,10 +149,11 @@ def to_json(self) -> GlobalConfigJSON:
def from_json(cls, obj: GlobalConfigJSON) -> "GlobalConfig":
return cls(
emergency_mode=obj["emergency_mode"],
local_admins_blocked=obj["local_admins_blocked"],
flash_take_order_blocked=obj["flash_take_order_blocked"],
new_orders_blocked=obj["new_orders_blocked"],
orders_matching_blocked=obj["orders_matching_blocked"],
orders_taking_blocked=obj["orders_taking_blocked"],
host_fee_bps=obj["host_fee_bps"],
is_order_taking_permissionless=obj["is_order_taking_permissionless"],
padding0=obj["padding0"],
padding1=obj["padding1"],
pda_authority_previous_lamports_balance=obj[
Expand Down
16 changes: 14 additions & 2 deletions sdk/python/express_relay/svm/generated/limo/accounts/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class OrderJSON(typing.TypedDict):
order_type: int
status: int
in_vault_bump: int
flash_ix_lock: int
padding0: list[int]
last_updated_timestamp: int
padding: list[int]


Expand All @@ -50,8 +52,10 @@ class Order:
"order_type" / borsh.U8,
"status" / borsh.U8,
"in_vault_bump" / borsh.U8,
"padding0" / borsh.U8[5],
"padding" / borsh.U64[21],
"flash_ix_lock" / borsh.U8,
"padding0" / borsh.U8[4],
"last_updated_timestamp" / borsh.U64,
"padding" / borsh.U64[20],
)
global_config: Pubkey
maker: Pubkey
Expand All @@ -68,7 +72,9 @@ class Order:
order_type: int
status: int
in_vault_bump: int
flash_ix_lock: int
padding0: list[int]
last_updated_timestamp: int
padding: list[int]

@classmethod
Expand Down Expand Up @@ -130,7 +136,9 @@ def decode(cls, data: bytes) -> "Order":
order_type=dec.order_type,
status=dec.status,
in_vault_bump=dec.in_vault_bump,
flash_ix_lock=dec.flash_ix_lock,
padding0=dec.padding0,
last_updated_timestamp=dec.last_updated_timestamp,
padding=dec.padding,
)

Expand All @@ -151,7 +159,9 @@ def to_json(self) -> OrderJSON:
"order_type": self.order_type,
"status": self.status,
"in_vault_bump": self.in_vault_bump,
"flash_ix_lock": self.flash_ix_lock,
"padding0": self.padding0,
"last_updated_timestamp": self.last_updated_timestamp,
"padding": self.padding,
}

Expand All @@ -173,6 +183,8 @@ def from_json(cls, obj: OrderJSON) -> "Order":
order_type=obj["order_type"],
status=obj["status"],
in_vault_bump=obj["in_vault_bump"],
flash_ix_lock=obj["flash_ix_lock"],
padding0=obj["padding0"],
last_updated_timestamp=obj["last_updated_timestamp"],
padding=obj["padding"],
)
170 changes: 168 additions & 2 deletions sdk/python/express_relay/svm/generated/limo/errors/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def __init__(self) -> None:

class OrderOutputAmountInvalid(ProgramError):
def __init__(self) -> None:
super().__init__(6010, "Order input amount invalid")
super().__init__(6010, "Order output amount invalid")

code = 6010
name = "OrderOutputAmountInvalid"
msg = "Order input amount invalid"
msg = "Order output amount invalid"


class InvalidHostFee(ProgramError):
Expand Down Expand Up @@ -146,6 +146,144 @@ def __init__(self) -> None:
msg = "Host tup amount is less than accounted for"


class OrderWithinFlashOperation(ProgramError):
def __init__(self) -> None:
super().__init__(
6016, "Order within flash operation - all otehr actions are blocked"
)

code = 6016
name = "OrderWithinFlashOperation"
msg = "Order within flash operation - all otehr actions are blocked"


class CPINotAllowed(ProgramError):
def __init__(self) -> None:
super().__init__(6017, "CPI not allowed")

code = 6017
name = "CPINotAllowed"
msg = "CPI not allowed"


class FlashTakeOrderBlocked(ProgramError):
def __init__(self) -> None:
super().__init__(6018, "Flash take_order is blocked")

code = 6018
name = "FlashTakeOrderBlocked"
msg = "Flash take_order is blocked"


class FlashTxWithUnexpectedIxs(ProgramError):
def __init__(self) -> None:
super().__init__(
6019,
"Some unexpected instructions are present in the tx. Either before or after the flash ixs, or some ix target the same program between",
)

code = 6019
name = "FlashTxWithUnexpectedIxs"
msg = "Some unexpected instructions are present in the tx. Either before or after the flash ixs, or some ix target the same program between"


class FlashIxsNotEnded(ProgramError):
def __init__(self) -> None:
super().__init__(
6020, "Flash ixs initiated without the closing ix in the transaction"
)

code = 6020
name = "FlashIxsNotEnded"
msg = "Flash ixs initiated without the closing ix in the transaction"


class FlashIxsNotStarted(ProgramError):
def __init__(self) -> None:
super().__init__(
6021, "Flash ixs ended without the starting ix in the transaction"
)

code = 6021
name = "FlashIxsNotStarted"
msg = "Flash ixs ended without the starting ix in the transaction"


class FlashIxsAccountMismatch(ProgramError):
def __init__(self) -> None:
super().__init__(6022, "Some accounts differ between the two flash ixs")

code = 6022
name = "FlashIxsAccountMismatch"
msg = "Some accounts differ between the two flash ixs"


class FlashIxsArgsMismatch(ProgramError):
def __init__(self) -> None:
super().__init__(6023, "Some args differ between the two flash ixs")

code = 6023
name = "FlashIxsArgsMismatch"
msg = "Some args differ between the two flash ixs"


class OrderNotWithinFlashOperation(ProgramError):
def __init__(self) -> None:
super().__init__(6024, "Order is not within flash operation")

code = 6024
name = "OrderNotWithinFlashOperation"
msg = "Order is not within flash operation"


class EmergencyModeEnabled(ProgramError):
def __init__(self) -> None:
super().__init__(6025, "Emergency mode is enabled")

code = 6025
name = "EmergencyModeEnabled"
msg = "Emergency mode is enabled"


class CreatingNewOrdersBlocked(ProgramError):
def __init__(self) -> None:
super().__init__(6026, "Creating new ordersis blocked")

code = 6026
name = "CreatingNewOrdersBlocked"
msg = "Creating new ordersis blocked"


class OrderTakingBlocked(ProgramError):
def __init__(self) -> None:
super().__init__(6027, "Orders taking is blocked")

code = 6027
name = "OrderTakingBlocked"
msg = "Orders taking is blocked"


class OrderInputAmountTooLarge(ProgramError):
def __init__(self) -> None:
super().__init__(6028, "Order input amount larger than the remaining")

code = 6028
name = "OrderInputAmountTooLarge"
msg = "Order input amount larger than the remaining"


class PermissionRequiredPermissionlessNotEnabled(ProgramError):
def __init__(self) -> None:
super().__init__(
6029,
"Permissionless order taking not enabled, please provide permission account",
)

code = 6029
name = "PermissionRequiredPermissionlessNotEnabled"
msg = "Permissionless order taking not enabled, please provide permission account"


CustomError = typing.Union[
OrderCanNotBeCanceled,
OrderNotActive,
Expand All @@ -163,6 +301,20 @@ def __init__(self) -> None:
InvalidTipBalance,
InvalidTipTransferAmount,
InvalidHostTipBalance,
OrderWithinFlashOperation,
CPINotAllowed,
FlashTakeOrderBlocked,
FlashTxWithUnexpectedIxs,
FlashIxsNotEnded,
FlashIxsNotStarted,
FlashIxsAccountMismatch,
FlashIxsArgsMismatch,
OrderNotWithinFlashOperation,
EmergencyModeEnabled,
CreatingNewOrdersBlocked,
OrderTakingBlocked,
OrderInputAmountTooLarge,
PermissionRequiredPermissionlessNotEnabled,
]
CUSTOM_ERROR_MAP: dict[int, CustomError] = {
6000: OrderCanNotBeCanceled(),
Expand All @@ -181,6 +333,20 @@ def __init__(self) -> None:
6013: InvalidTipBalance(),
6014: InvalidTipTransferAmount(),
6015: InvalidHostTipBalance(),
6016: OrderWithinFlashOperation(),
6017: CPINotAllowed(),
6018: FlashTakeOrderBlocked(),
6019: FlashTxWithUnexpectedIxs(),
6020: FlashIxsNotEnded(),
6021: FlashIxsNotStarted(),
6022: FlashIxsAccountMismatch(),
6023: FlashIxsArgsMismatch(),
6024: OrderNotWithinFlashOperation(),
6025: EmergencyModeEnabled(),
6026: CreatingNewOrdersBlocked(),
6027: OrderTakingBlocked(),
6028: OrderInputAmountTooLarge(),
6029: PermissionRequiredPermissionlessNotEnabled(),
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
CloseOrderAndClaimTipAccounts,
)
from .take_order import take_order, TakeOrderArgs, TakeOrderAccounts
from .flash_take_order_start import (
flash_take_order_start,
FlashTakeOrderStartArgs,
FlashTakeOrderStartAccounts,
)
from .flash_take_order_end import (
flash_take_order_end,
FlashTakeOrderEndArgs,
FlashTakeOrderEndAccounts,
)
from .update_global_config import (
update_global_config,
UpdateGlobalConfigArgs,
Expand Down
Loading
Loading