feat: update rest of scripts with creator fee
This commit is contained in:
@@ -2,7 +2,8 @@ import base64
|
||||
import json
|
||||
import struct
|
||||
|
||||
from construct import Flag, Int64ul, Struct
|
||||
from construct import Bytes, Flag, Int64ul, Struct
|
||||
from solders.pubkey import Pubkey
|
||||
|
||||
LAMPORTS_PER_SOL = 1_000_000_000
|
||||
TOKEN_DECIMALS = 6
|
||||
@@ -10,7 +11,7 @@ EXPECTED_DISCRIMINATOR = struct.pack("<Q", 6966180631402821399)
|
||||
|
||||
|
||||
class BondingCurveState:
|
||||
_STRUCT = Struct(
|
||||
_STRUCT_1 = Struct(
|
||||
"virtual_token_reserves" / Int64ul,
|
||||
"virtual_sol_reserves" / Int64ul,
|
||||
"real_token_reserves" / Int64ul,
|
||||
@@ -19,9 +20,33 @@ class BondingCurveState:
|
||||
"complete" / Flag,
|
||||
)
|
||||
|
||||
# Struct after creator fee update has been introduced
|
||||
# https://github.com/pump-fun/pump-public-docs/blob/main/docs/PUMP_CREATOR_FEE_README.md
|
||||
_STRUCT_2 = Struct(
|
||||
"virtual_token_reserves" / Int64ul,
|
||||
"virtual_sol_reserves" / Int64ul,
|
||||
"real_token_reserves" / Int64ul,
|
||||
"real_sol_reserves" / Int64ul,
|
||||
"token_total_supply" / Int64ul,
|
||||
"complete" / Flag,
|
||||
"creator" / Bytes(32), # Added new creator field - 32 bytes for Pubkey
|
||||
)
|
||||
|
||||
def __init__(self, data: bytes) -> None:
|
||||
parsed = self._STRUCT.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
"""Parse bonding curve data."""
|
||||
if data[:8] != EXPECTED_DISCRIMINATOR:
|
||||
raise ValueError("Invalid curve state discriminator")
|
||||
|
||||
if len(data) < 150:
|
||||
parsed = self._STRUCT_1.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
|
||||
else:
|
||||
parsed = self._STRUCT_1.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
# Convert raw bytes to Pubkey for creator field
|
||||
if hasattr(self, 'creator') and isinstance(self.creator, bytes):
|
||||
self.creator = Pubkey.from_bytes(self.creator)
|
||||
|
||||
|
||||
def calculate_bonding_curve_price(curve_state: BondingCurveState) -> float:
|
||||
@@ -41,7 +66,7 @@ def decode_bonding_curve_data(raw_data: str) -> BondingCurveState:
|
||||
|
||||
|
||||
# Load the JSON data
|
||||
with open("learning-examples/raw_bondingCurve_from_getAccountInfo.json", "r") as file:
|
||||
with open("learning-examples/raw_bondingCurve_from_getAccountInfo.json") as file:
|
||||
json_data = json.load(file)
|
||||
|
||||
# Extract the base64 encoded data
|
||||
|
||||
Reference in New Issue
Block a user