Skip to content

Feat: Added customizable permissionless lb pair to python sdk #121

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

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 60 additions & 0 deletions python-client/dlmm/dlmm/dlmm.py
Original file line number Diff line number Diff line change
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: str,
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) != str):
raise TypeError("activation_type must be of type `str`")

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}")
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 = 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
Loading