diff --git a/python-client/dlmm/dlmm/dlmm.py b/python-client/dlmm/dlmm/dlmm.py index d9c507fa..299a8370 100644 --- a/python-client/dlmm/dlmm/dlmm.py +++ b/python-client/dlmm/dlmm/dlmm.py @@ -4,7 +4,7 @@ from solana.transaction import Transaction from solders.pubkey import Pubkey from .utils import convert_to_transaction -from .types import ActiveBin, FeeInfo, GetBins, GetPositionByUser, Position, PositionInfo, StrategyParameters, SwapQuote, LBPair, TokenReserve, DlmmHttpError as HTTPError +from .types import ActivationType, ActiveBin, FeeInfo, GetBins, GetPositionByUser, Position, PositionInfo, StrategyParameters, SwapQuote, LBPair, TokenReserve, DlmmHttpError as HTTPError API_URL = "localhost:3000" @@ -780,5 +780,65 @@ def get_all_lb_pair_positions_by_user(user: Pubkey, rpc: str) -> Dict[str, Posit return {key: PositionInfo(value) for key, value in result.items()} except requests.exceptions.HTTPError as e: raise HTTPError(f"Error getting all lb pair positions by user: {e}") + except requests.exceptions.ConnectionError as e: + raise HTTPError(f"Error connecting to DLMM: {e}") + + @staticmethod + def create_customizable_permissionless_lb_pair( + bin_step: int, + token_x: Pubkey, + token_y: Pubkey, + active_id: int, + fee_bps: int, + activation_type: int, + has_alpha_vault: bool, + creator_key: Pubkey, + activation_point: Optional[int] = None + ) -> Transaction: + + if(type(bin_step) != int): + raise TypeError("bin_step must be of type `int`") + + if(type(token_x) != Pubkey): + raise TypeError("token_x must be of type `solders.pubkey.Pubkey`") + + if(type(token_y) != Pubkey): + raise TypeError("token_y must be of type `solders.pubkey.Pubkey`") + + if(type(active_id) != int): + raise TypeError("active_id must be of type `int`") + + if(type(fee_bps) != int): + raise TypeError("fee_bps must be of type `int`") + + if(type(activation_type) != int): + raise TypeError("activation_type must be of type `int`") + + if(type(has_alpha_vault) != bool): + raise TypeError("has_alpha_vault must be of type `bool`") + + if(type(creator_key) != Pubkey): + raise TypeError("creator_key must be of type `solders.pubkey.Pubkey`") + + if(activation_point is not None and type(activation_point) != int): + raise TypeError("activation_point must be of type `int`") + + try: + data = json.dumps({ + "binStep": bin_step, + "tokenX": str(token_x), + "tokenY": str(token_y), + "activeId": active_id, + "feeBps": fee_bps, + "activationType": activation_type, + "hasAlphaVault": has_alpha_vault, + "creatorKey": str(creator_key), + "activationPoint": activation_point + }) + result = requests.post(f"{API_URL}/dlmm/create-customizable-permissionless-lb-pair", data=data).json() + return convert_to_transaction(result) + + except requests.exceptions.HTTPError as e: + raise HTTPError(f"Error creating customizable permissionless lb pair: {e}") except requests.exceptions.ConnectionError as e: raise HTTPError(f"Error connecting to DLMM: {e}") \ No newline at end of file diff --git a/python-client/dlmm/dlmm/types.py b/python-client/dlmm/dlmm/types.py index 89354d3a..03b411cc 100644 --- a/python-client/dlmm/dlmm/types.py +++ b/python-client/dlmm/dlmm/types.py @@ -24,6 +24,17 @@ def __str__(self) -> str: def __repr__(self) -> str: return self.name +class ActivationType(Enum): + Slot=0, + Timestamp=1, + + def __str__(self) -> str: + return f"{self.value[1]} + + def __repr__(self) -> str: + return self.name + + class PositionVersion(Enum): V1="V1", V2="V2" diff --git a/ts-client/src/server/index.ts b/ts-client/src/server/index.ts index 8006ecf6..3d7c825b 100644 --- a/ts-client/src/server/index.ts +++ b/ts-client/src/server/index.ts @@ -80,7 +80,38 @@ app.get('/dlmm/get-all-lb-pair-positions-by-user', async (req, res) => { console.log(error) return res.status(400).send(error) } +}) + +app.post("/dlmm/create-customizable-permissionless-lb-pair", async (req, res) => { + try { + const binStep = new BN(req.body.binStep); + const tokenX = new PublicKey(req.body.tokenX); + const tokenY = new PublicKey(req.body.tokenY); + const activeId = new BN(req.body.activeId); + const feeBps = new BN(req.body.feeBps); + const activationType = parseInt(req.body.activationType); + const hasAlphaVault = Boolean(req.body.hasAlphaVault); + const creatorKey = new PublicKey(req.body.creatorKey); + const activationPoint = req.body.activationPoint !== null ? new BN(req.body.activationPoint) : null; + const transaction = DLMM.createCustomizablePermissionlessLbPair( + req.connect, + binStep, + tokenX, + tokenY, + activeId, + feeBps, + activationType, + hasAlphaVault, + creatorKey, + activationPoint + ) + return res.status(200).send(safeStringify(transaction)); + } + catch (error) { + console.log(error) + return res.status(400).send(error) + } }) app.get("/dlmm/get-active-bin", async (req, res) => {