Addresses

These functions are used to derive on-chain addresses of the accounts (publickey of the sol-market)

addresses

get_drift_client_signer_public_key(program_id)

Source code in src/driftpy/addresses.py
70
71
72
73
def get_drift_client_signer_public_key(
    program_id: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address([b"drift_signer"], program_id)[0]

get_high_leverage_mode_config_public_key(program_id)

Source code in src/driftpy/addresses.py
144
145
def get_high_leverage_mode_config_public_key(program_id: Pubkey) -> Pubkey:
    return Pubkey.find_program_address([b"high_leverage_mode_config"], program_id)[0]

get_if_rebalance_config_public_key(program_id, in_market_index, out_market_index)

Source code in src/driftpy/addresses.py
168
169
170
171
172
173
174
175
176
177
178
179
180
def get_if_rebalance_config_public_key(
    program_id: Pubkey,
    in_market_index: int,
    out_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [
            b"if_rebalance_config",
            int_to_le_bytes(in_market_index),
            int_to_le_bytes(out_market_index),
        ],
        program_id,
    )[0]

get_insurance_fund_stake_public_key(program_id, authority, spot_market_index)

Source code in src/driftpy/addresses.py
26
27
28
29
30
31
32
33
34
def get_insurance_fund_stake_public_key(
    program_id: Pubkey,
    authority: Pubkey,
    spot_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"insurance_fund_stake", bytes(authority), int_to_le_bytes(spot_market_index)],
        program_id,
    )[0]

get_insurance_fund_vault_public_key(program_id, spot_market_index)

Source code in src/driftpy/addresses.py
17
18
19
20
21
22
23
def get_insurance_fund_vault_public_key(
    program_id: Pubkey,
    spot_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"insurance_fund_vault", int_to_le_bytes(spot_market_index)], program_id
    )[0]

get_perp_market_public_key(program_id, market_index)

Source code in src/driftpy/addresses.py
 8
 9
10
11
12
13
14
def get_perp_market_public_key(
    program_id: Pubkey,
    market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"perp_market", int_to_le_bytes(market_index)], program_id
    )[0]

get_phoenix_fulfillment_config_public_key(program_id, market)

Source code in src/driftpy/addresses.py
127
128
129
130
131
132
133
def get_phoenix_fulfillment_config_public_key(
    program_id: Pubkey,
    market: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"phoenix_fulfillment_config", bytes(market)], program_id
    )[0]

get_prelaunch_oracle_public_key(program_id, market_index)

Source code in src/driftpy/addresses.py
93
94
95
96
def get_prelaunch_oracle_public_key(program_id: Pubkey, market_index: int) -> Pubkey:
    return Pubkey.find_program_address(
        [b"prelaunch_oracle", int_to_le_bytes(market_index)], program_id
    )[0]

get_protected_maker_mode_config_public_key(program_id)

Source code in src/driftpy/addresses.py
148
149
def get_protected_maker_mode_config_public_key(program_id: Pubkey) -> Pubkey:
    return Pubkey.find_program_address([b"protected_maker_mode_config"], program_id)[0]

get_rfq_user_account_public_key(program_id, user_account_public_key)

Source code in src/driftpy/addresses.py
152
153
154
155
156
157
158
def get_rfq_user_account_public_key(
    program_id: Pubkey,
    user_account_public_key: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"RFQ", bytes(user_account_public_key)], program_id
    )[0]

get_sequencer_public_key_and_bump(program_id, payer, subaccount_id)

Source code in src/driftpy/addresses.py
136
137
138
139
140
141
def get_sequencer_public_key_and_bump(
    program_id: Pubkey, payer: Pubkey, subaccount_id: int
) -> tuple[Pubkey, int]:
    return Pubkey.find_program_address(
        [(str(subaccount_id)).encode(), bytes(payer)], program_id
    )

get_serum_fulfillment_config_public_key(program_id, market)

Source code in src/driftpy/addresses.py
118
119
120
121
122
123
124
def get_serum_fulfillment_config_public_key(
    program_id: Pubkey,
    market: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"serum_fulfillment_config", bytes(market)], program_id
    )[0]

get_serum_open_orders_public_key(program_id, market)

Source code in src/driftpy/addresses.py
 99
100
101
102
103
104
105
def get_serum_open_orders_public_key(
    program_id: Pubkey,
    market: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"serum_open_orders", bytes(market)], program_id
    )[0]

get_serum_signer_public_key(program_id, market, nonce)

Source code in src/driftpy/addresses.py
108
109
110
111
112
113
114
115
def get_serum_signer_public_key(
    program_id: Pubkey,
    market: Pubkey,
    nonce: int,
) -> Pubkey:
    return Pubkey.create_program_address(
        [bytes(market), int_to_le_bytes(nonce)], program_id
    )

get_signed_msg_user_account_public_key(program_id, authority)

Source code in src/driftpy/addresses.py
161
162
163
164
165
def get_signed_msg_user_account_public_key(
    program_id: Pubkey,
    authority: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address([b"SIGNED_MSG", bytes(authority)], program_id)[0]

get_spot_market_public_key(program_id, spot_market_index)

Source code in src/driftpy/addresses.py
37
38
39
40
41
42
43
def get_spot_market_public_key(
    program_id: Pubkey,
    spot_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"spot_market", int_to_le_bytes(spot_market_index)], program_id
    )[0]

get_spot_market_vault_authority_public_key(program_id, spot_market_index)

Source code in src/driftpy/addresses.py
55
56
57
58
59
60
61
def get_spot_market_vault_authority_public_key(
    program_id: Pubkey,
    spot_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"spot_market_vault_authority", int_to_le_bytes(spot_market_index)], program_id
    )[0]

get_spot_market_vault_public_key(program_id, spot_market_index)

Source code in src/driftpy/addresses.py
46
47
48
49
50
51
52
def get_spot_market_vault_public_key(
    program_id: Pubkey,
    spot_market_index: int,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"spot_market_vault", int_to_le_bytes(spot_market_index)], program_id
    )[0]

get_state_public_key(program_id)

Source code in src/driftpy/addresses.py
64
65
66
67
def get_state_public_key(
    program_id: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address([b"drift_state"], program_id)[0]

get_user_account_public_key(program_id, authority, sub_account_id=0)

Source code in src/driftpy/addresses.py
83
84
85
86
87
88
89
90
def get_user_account_public_key(
    program_id: Pubkey,
    authority: Pubkey,
    sub_account_id=0,
) -> Pubkey:
    return Pubkey.find_program_address(
        [b"user", bytes(authority), int_to_le_bytes(sub_account_id)], program_id
    )[0]

get_user_stats_account_public_key(program_id, authority)

Source code in src/driftpy/addresses.py
76
77
78
79
80
def get_user_stats_account_public_key(
    program_id: Pubkey,
    authority: Pubkey,
) -> Pubkey:
    return Pubkey.find_program_address([b"user_stats", bytes(authority)], program_id)[0]

int_to_le_bytes(a)

Source code in src/driftpy/addresses.py
4
5
def int_to_le_bytes(a: int):
    return a.to_bytes(2, "little")