Skip to content

Commit

Permalink
Feat: Added customizable permissionless lb pair to python sdk (#121)
Browse files Browse the repository at this point in the history
* added permissionless lb pair

* fixed activation type to int
  • Loading branch information
RevTpark authored Dec 17, 2024
1 parent cdabc02 commit 1d4c4b9
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
62 changes: 61 additions & 1 deletion python-client/dlmm/dlmm/dlmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}")
11 changes: 11 additions & 0 deletions python-client/dlmm/dlmm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions ts-client/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 1d4c4b9

Please sign in to comment.