pyaver.user_host_lifetime

  1from .aver_client import AverClient
  2from solana.publickey import PublicKey
  3from .data_classes import UserHostLifetimeState
  4from .constants import AVER_PROGRAM_ID, AVER_HOST_ACCOUNT
  5from .utils import sign_and_send_transaction_instructions
  6from solana.system_program import SYS_PROGRAM_ID
  7from solana.rpc.commitment import Finalized
  8from anchorpy import Context
  9from solana.transaction import AccountMeta
 10from solana.keypair import Keypair
 11from solana.rpc.types import TxOpts
 12from .enums import FeeTier
 13
 14class UserHostLifetime():
 15    """
 16    User data and statistics for a particular host
 17
 18    Contains aggregated lifetime data on a user's trades for a particular host
 19    """
 20
 21    pubkey: PublicKey
 22    """
 23    UserHostLifetime public key
 24    """
 25
 26    user_host_lifetime_state: UserHostLifetimeState
 27    """
 28    UserHostLifetimeState object
 29    """
 30
 31    def __init__(self, pubkey: PublicKey, user_host_lifetime_state: UserHostLifetimeState):
 32        """
 33        Initialise an UserHostLifetime object. Do not use this function; use UserHostLifetime.load() instead
 34
 35        Args:
 36            pubkey (PublicKey): UserHostLifetime public key
 37            user_host_lifetime_state (UserHostLifetimeState): UserHostLifetimeState public key
 38        """
 39        self.pubkey = pubkey
 40        self.user_host_lifetime_state = user_host_lifetime_state
 41
 42    @staticmethod
 43    async def load(aver_client: AverClient, pubkey: PublicKey):
 44        """
 45        Initialises an UserHostLifetime Account (UHLA) object.
 46
 47        A UHLA is an account which is initialized when a wallet interacts with Aver via a particular Host for the first time. It is used to store values related to 
 48        a wallet's interactions with Aver Markets via this Host. It is required to be initialized before a wallet can interact with any Markets via a given Host.
 49
 50        Args:
 51            aver_client (AverClient): AverClient object
 52            pubkey (PublicKey): UserHostLifetime public key
 53
 54        Returns:
 55            UserHostLifetime: UserHostLifetime object
 56        """
 57        user_host_lifetime_result = await aver_client.program.account['UserHostLifetime'].fetch(pubkey)
 58        return UserHostLifetime(pubkey, user_host_lifetime_result)
 59
 60    @staticmethod
 61    async def load_multiple(aver_client: AverClient, pubkeys: list[PublicKey]):
 62        """
 63         Initialised multiple UserHostLifetime objects
 64
 65        Args:
 66            aver_client (AverClient): AverClient object
 67            pubkeys (list[PublicKey]): List of UserHostLifetime public keys
 68
 69        Returns:
 70            list[UserHostLifetime]: List of UserHostLifetime objects
 71        """
 72        res = await aver_client.program.account['UserHostLifetime'].fetch_multiple(pubkeys)
 73        uhls: list[UserHostLifetime] = []
 74        for i, pubkey in enumerate(pubkeys):
 75            uhls.append(UserHostLifetime(pubkey, res[i]))
 76        return uhls
 77
 78    @staticmethod
 79    async def get_or_create_user_host_lifetime(
 80        client: AverClient,
 81        owner: Keypair,
 82        send_options: TxOpts = None,
 83        quote_token_mint: PublicKey = None,
 84        host: PublicKey = AVER_HOST_ACCOUNT,
 85        referrer: PublicKey = SYS_PROGRAM_ID,
 86        discount_token: PublicKey = SYS_PROGRAM_ID,
 87        program_id: PublicKey = AVER_PROGRAM_ID
 88    ):
 89        """
 90        Attempts to load a UserHostLifetime account and creates one if not found
 91
 92        Args:
 93            client (AverClient): AverClient object
 94            owner (Keypair): Owner of UserHostLifetime account. Pays transaction and rent costs
 95            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
 96            quote_token_mint (PublicKey, optional): Quote token mint public key. Defaults to Defaults to USDC token according to chosen solana network in AverClient.
 97            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
 98            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
 99            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
100            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
101
102        Returns:
103            UserHostLifetime: UserHostLifetime object
104        """
105        quote_token_mint = quote_token_mint if quote_token_mint is not None else client.quote_token
106        user_host_lifetime = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)[0]
107
108        try:
109            uhl = await UserHostLifetime.load(client, user_host_lifetime)
110            return uhl
111        except:
112            user_quote_token_ata = await client.get_or_create_associated_token_account(
113                owner.public_key, 
114                owner, 
115                quote_token_mint
116            )
117
118            sig = await UserHostLifetime.create_user_host_lifetime(
119                client,
120                owner,
121                user_quote_token_ata,
122                send_options,
123                host,
124                referrer,
125                discount_token,
126                program_id,
127            )
128
129            await client.provider.connection.confirm_transaction(
130                sig['result'],
131                commitment=Finalized
132            )
133
134            return await UserHostLifetime.load(client, user_host_lifetime)
135    
136    @staticmethod
137    def make_create_user_host_lifetime_instruction(
138        aver_client: AverClient,
139        user_quote_token_ata: PublicKey,
140        owner: Keypair,
141        host: PublicKey = AVER_HOST_ACCOUNT,
142        referrer: PublicKey = SYS_PROGRAM_ID,
143        discount_token: PublicKey = SYS_PROGRAM_ID,
144        program_id = AVER_PROGRAM_ID
145    ):
146        """
147        Creates instruction for UserHostLifetime account creation
148
149        Returns TransactionInstruction object only. Does not send transaction.
150
151        Args:
152            aver_client (AverClient): AverClient object
153            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
154            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
155            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
156            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
157            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
158            program_id (_type_, optional): Program public key. Defaults to AVER_PROGRAM_ID.
159
160        Returns:
161            TransactionInstruction: TransactionInstruction object
162        """
163        user_host_lifetime, bump = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)
164
165        discount_token_account = AccountMeta(
166            is_signer=False,
167            is_writable=False,
168            pubkey=discount_token,
169        )
170        referrer_account = AccountMeta(
171            is_signer=False,
172            is_writable=True,
173            pubkey=referrer,
174        )
175        return aver_client.program.instruction['init_user_host_lifetime']( 
176            bump,
177            ctx=Context(
178                accounts={
179                "user": owner.public_key,
180                "user_host_lifetime": user_host_lifetime,
181                "user_quote_token_ata": user_quote_token_ata,
182                "host": host,
183                "system_program": SYS_PROGRAM_ID,
184                },
185                remaining_accounts=[discount_token_account, referrer_account],
186                signers=[owner]
187            )
188            )
189
190    @staticmethod
191    async def create_user_host_lifetime(
192        aver_client: AverClient,
193        owner: Keypair,
194        user_quote_token_ata: PublicKey,
195        send_options: TxOpts = None,
196        host: PublicKey = AVER_HOST_ACCOUNT,
197        referrer: PublicKey = SYS_PROGRAM_ID,
198        discount_token: PublicKey = SYS_PROGRAM_ID,
199        program_id: PublicKey = AVER_PROGRAM_ID,
200    ):
201        """
202        Creates UserHostLifetime account
203
204        Sends instructions on chain
205
206        Args:
207            aver_client (AverClient): AverClient object
208            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
209            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
210            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
211            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
212            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
213            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
214            program_id (PublicKey, optional):  Program public key. Defaults to AVER_PROGRAM_ID.
215
216        Returns:
217            RPCResponse: Response
218        """
219        ix = UserHostLifetime.make_create_user_host_lifetime_instruction(
220            aver_client,
221            user_quote_token_ata,
222            owner,
223            host,
224            referrer,
225            discount_token,
226            program_id
227        )
228
229        if(send_options is None):
230            send_options = TxOpts()
231        else:
232            send_options = TxOpts(
233                skip_confirmation=send_options.skip_confirmation,
234                skip_preflight=send_options.skip_confirmation,
235                preflight_commitment=Finalized,
236                max_retries=send_options.max_retries)
237
238
239        return await sign_and_send_transaction_instructions(
240            aver_client,
241            [],
242            owner,
243            [ix],
244            send_options
245        )
246
247    @staticmethod
248    def derive_pubkey_and_bump(owner: PublicKey, host: PublicKey, program_id: PublicKey = AVER_PROGRAM_ID):
249        """
250        Derives PDA for UserHostLifetime public key
251
252        Args:
253            owner (PublicKey): Owner of host account
254            host (PublicKey, optional): Public key of corresponding Host account. Defaults to AVER_HOST_ACCOUNT.
255            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
256
257        Returns:
258            PublicKey: Public key of UserHostLifetime account
259        """
260        return PublicKey.find_program_address(
261            [bytes('user-host-lifetime', 'utf-8'), bytes(owner), bytes(host)],
262            program_id
263        )
264
265
266    def get_fee_tier_postion(self):
267        """
268        Gets user's fee tier position
269
270        This determines the percentage fee taken by the host on winnings
271
272        Returns:
273            FeeTier: FeeTier for user
274        """
275        last_fee_tier_check = self.user_host_lifetime_state.last_fee_tier_check
276        if(last_fee_tier_check == FeeTier.BASE):
277            return 0
278        if(last_fee_tier_check == FeeTier.AVER1):
279            return 1
280        if(last_fee_tier_check == FeeTier.AVER2):
281            return 2
282        if(last_fee_tier_check == FeeTier.AVER3):
283            return 3
284        if(last_fee_tier_check == FeeTier.AVER4):
285            return 4
286        if(last_fee_tier_check == FeeTier.AVER5):
287            return 5
288        if(last_fee_tier_check == FeeTier.FREE):
289            return 6
290
291        
class UserHostLifetime:
 15class UserHostLifetime():
 16    """
 17    User data and statistics for a particular host
 18
 19    Contains aggregated lifetime data on a user's trades for a particular host
 20    """
 21
 22    pubkey: PublicKey
 23    """
 24    UserHostLifetime public key
 25    """
 26
 27    user_host_lifetime_state: UserHostLifetimeState
 28    """
 29    UserHostLifetimeState object
 30    """
 31
 32    def __init__(self, pubkey: PublicKey, user_host_lifetime_state: UserHostLifetimeState):
 33        """
 34        Initialise an UserHostLifetime object. Do not use this function; use UserHostLifetime.load() instead
 35
 36        Args:
 37            pubkey (PublicKey): UserHostLifetime public key
 38            user_host_lifetime_state (UserHostLifetimeState): UserHostLifetimeState public key
 39        """
 40        self.pubkey = pubkey
 41        self.user_host_lifetime_state = user_host_lifetime_state
 42
 43    @staticmethod
 44    async def load(aver_client: AverClient, pubkey: PublicKey):
 45        """
 46        Initialises an UserHostLifetime Account (UHLA) object.
 47
 48        A UHLA is an account which is initialized when a wallet interacts with Aver via a particular Host for the first time. It is used to store values related to 
 49        a wallet's interactions with Aver Markets via this Host. It is required to be initialized before a wallet can interact with any Markets via a given Host.
 50
 51        Args:
 52            aver_client (AverClient): AverClient object
 53            pubkey (PublicKey): UserHostLifetime public key
 54
 55        Returns:
 56            UserHostLifetime: UserHostLifetime object
 57        """
 58        user_host_lifetime_result = await aver_client.program.account['UserHostLifetime'].fetch(pubkey)
 59        return UserHostLifetime(pubkey, user_host_lifetime_result)
 60
 61    @staticmethod
 62    async def load_multiple(aver_client: AverClient, pubkeys: list[PublicKey]):
 63        """
 64         Initialised multiple UserHostLifetime objects
 65
 66        Args:
 67            aver_client (AverClient): AverClient object
 68            pubkeys (list[PublicKey]): List of UserHostLifetime public keys
 69
 70        Returns:
 71            list[UserHostLifetime]: List of UserHostLifetime objects
 72        """
 73        res = await aver_client.program.account['UserHostLifetime'].fetch_multiple(pubkeys)
 74        uhls: list[UserHostLifetime] = []
 75        for i, pubkey in enumerate(pubkeys):
 76            uhls.append(UserHostLifetime(pubkey, res[i]))
 77        return uhls
 78
 79    @staticmethod
 80    async def get_or_create_user_host_lifetime(
 81        client: AverClient,
 82        owner: Keypair,
 83        send_options: TxOpts = None,
 84        quote_token_mint: PublicKey = None,
 85        host: PublicKey = AVER_HOST_ACCOUNT,
 86        referrer: PublicKey = SYS_PROGRAM_ID,
 87        discount_token: PublicKey = SYS_PROGRAM_ID,
 88        program_id: PublicKey = AVER_PROGRAM_ID
 89    ):
 90        """
 91        Attempts to load a UserHostLifetime account and creates one if not found
 92
 93        Args:
 94            client (AverClient): AverClient object
 95            owner (Keypair): Owner of UserHostLifetime account. Pays transaction and rent costs
 96            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
 97            quote_token_mint (PublicKey, optional): Quote token mint public key. Defaults to Defaults to USDC token according to chosen solana network in AverClient.
 98            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
 99            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
100            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
101            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
102
103        Returns:
104            UserHostLifetime: UserHostLifetime object
105        """
106        quote_token_mint = quote_token_mint if quote_token_mint is not None else client.quote_token
107        user_host_lifetime = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)[0]
108
109        try:
110            uhl = await UserHostLifetime.load(client, user_host_lifetime)
111            return uhl
112        except:
113            user_quote_token_ata = await client.get_or_create_associated_token_account(
114                owner.public_key, 
115                owner, 
116                quote_token_mint
117            )
118
119            sig = await UserHostLifetime.create_user_host_lifetime(
120                client,
121                owner,
122                user_quote_token_ata,
123                send_options,
124                host,
125                referrer,
126                discount_token,
127                program_id,
128            )
129
130            await client.provider.connection.confirm_transaction(
131                sig['result'],
132                commitment=Finalized
133            )
134
135            return await UserHostLifetime.load(client, user_host_lifetime)
136    
137    @staticmethod
138    def make_create_user_host_lifetime_instruction(
139        aver_client: AverClient,
140        user_quote_token_ata: PublicKey,
141        owner: Keypair,
142        host: PublicKey = AVER_HOST_ACCOUNT,
143        referrer: PublicKey = SYS_PROGRAM_ID,
144        discount_token: PublicKey = SYS_PROGRAM_ID,
145        program_id = AVER_PROGRAM_ID
146    ):
147        """
148        Creates instruction for UserHostLifetime account creation
149
150        Returns TransactionInstruction object only. Does not send transaction.
151
152        Args:
153            aver_client (AverClient): AverClient object
154            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
155            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
156            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
157            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
158            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
159            program_id (_type_, optional): Program public key. Defaults to AVER_PROGRAM_ID.
160
161        Returns:
162            TransactionInstruction: TransactionInstruction object
163        """
164        user_host_lifetime, bump = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)
165
166        discount_token_account = AccountMeta(
167            is_signer=False,
168            is_writable=False,
169            pubkey=discount_token,
170        )
171        referrer_account = AccountMeta(
172            is_signer=False,
173            is_writable=True,
174            pubkey=referrer,
175        )
176        return aver_client.program.instruction['init_user_host_lifetime']( 
177            bump,
178            ctx=Context(
179                accounts={
180                "user": owner.public_key,
181                "user_host_lifetime": user_host_lifetime,
182                "user_quote_token_ata": user_quote_token_ata,
183                "host": host,
184                "system_program": SYS_PROGRAM_ID,
185                },
186                remaining_accounts=[discount_token_account, referrer_account],
187                signers=[owner]
188            )
189            )
190
191    @staticmethod
192    async def create_user_host_lifetime(
193        aver_client: AverClient,
194        owner: Keypair,
195        user_quote_token_ata: PublicKey,
196        send_options: TxOpts = None,
197        host: PublicKey = AVER_HOST_ACCOUNT,
198        referrer: PublicKey = SYS_PROGRAM_ID,
199        discount_token: PublicKey = SYS_PROGRAM_ID,
200        program_id: PublicKey = AVER_PROGRAM_ID,
201    ):
202        """
203        Creates UserHostLifetime account
204
205        Sends instructions on chain
206
207        Args:
208            aver_client (AverClient): AverClient object
209            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
210            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
211            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
212            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
213            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
214            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
215            program_id (PublicKey, optional):  Program public key. Defaults to AVER_PROGRAM_ID.
216
217        Returns:
218            RPCResponse: Response
219        """
220        ix = UserHostLifetime.make_create_user_host_lifetime_instruction(
221            aver_client,
222            user_quote_token_ata,
223            owner,
224            host,
225            referrer,
226            discount_token,
227            program_id
228        )
229
230        if(send_options is None):
231            send_options = TxOpts()
232        else:
233            send_options = TxOpts(
234                skip_confirmation=send_options.skip_confirmation,
235                skip_preflight=send_options.skip_confirmation,
236                preflight_commitment=Finalized,
237                max_retries=send_options.max_retries)
238
239
240        return await sign_and_send_transaction_instructions(
241            aver_client,
242            [],
243            owner,
244            [ix],
245            send_options
246        )
247
248    @staticmethod
249    def derive_pubkey_and_bump(owner: PublicKey, host: PublicKey, program_id: PublicKey = AVER_PROGRAM_ID):
250        """
251        Derives PDA for UserHostLifetime public key
252
253        Args:
254            owner (PublicKey): Owner of host account
255            host (PublicKey, optional): Public key of corresponding Host account. Defaults to AVER_HOST_ACCOUNT.
256            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
257
258        Returns:
259            PublicKey: Public key of UserHostLifetime account
260        """
261        return PublicKey.find_program_address(
262            [bytes('user-host-lifetime', 'utf-8'), bytes(owner), bytes(host)],
263            program_id
264        )
265
266
267    def get_fee_tier_postion(self):
268        """
269        Gets user's fee tier position
270
271        This determines the percentage fee taken by the host on winnings
272
273        Returns:
274            FeeTier: FeeTier for user
275        """
276        last_fee_tier_check = self.user_host_lifetime_state.last_fee_tier_check
277        if(last_fee_tier_check == FeeTier.BASE):
278            return 0
279        if(last_fee_tier_check == FeeTier.AVER1):
280            return 1
281        if(last_fee_tier_check == FeeTier.AVER2):
282            return 2
283        if(last_fee_tier_check == FeeTier.AVER3):
284            return 3
285        if(last_fee_tier_check == FeeTier.AVER4):
286            return 4
287        if(last_fee_tier_check == FeeTier.AVER5):
288            return 5
289        if(last_fee_tier_check == FeeTier.FREE):
290            return 6

User data and statistics for a particular host

Contains aggregated lifetime data on a user's trades for a particular host

UserHostLifetime( pubkey: solana.publickey.PublicKey, user_host_lifetime_state: pyaver.data_classes.UserHostLifetimeState)
32    def __init__(self, pubkey: PublicKey, user_host_lifetime_state: UserHostLifetimeState):
33        """
34        Initialise an UserHostLifetime object. Do not use this function; use UserHostLifetime.load() instead
35
36        Args:
37            pubkey (PublicKey): UserHostLifetime public key
38            user_host_lifetime_state (UserHostLifetimeState): UserHostLifetimeState public key
39        """
40        self.pubkey = pubkey
41        self.user_host_lifetime_state = user_host_lifetime_state

Initialise an UserHostLifetime object. Do not use this function; use UserHostLifetime.load() instead

Args
  • pubkey (PublicKey): UserHostLifetime public key
  • user_host_lifetime_state (UserHostLifetimeState): UserHostLifetimeState public key
pubkey: solana.publickey.PublicKey

UserHostLifetime public key

user_host_lifetime_state: pyaver.data_classes.UserHostLifetimeState

UserHostLifetimeState object

@staticmethod
async def load( aver_client: pyaver.aver_client.AverClient, pubkey: solana.publickey.PublicKey)
43    @staticmethod
44    async def load(aver_client: AverClient, pubkey: PublicKey):
45        """
46        Initialises an UserHostLifetime Account (UHLA) object.
47
48        A UHLA is an account which is initialized when a wallet interacts with Aver via a particular Host for the first time. It is used to store values related to 
49        a wallet's interactions with Aver Markets via this Host. It is required to be initialized before a wallet can interact with any Markets via a given Host.
50
51        Args:
52            aver_client (AverClient): AverClient object
53            pubkey (PublicKey): UserHostLifetime public key
54
55        Returns:
56            UserHostLifetime: UserHostLifetime object
57        """
58        user_host_lifetime_result = await aver_client.program.account['UserHostLifetime'].fetch(pubkey)
59        return UserHostLifetime(pubkey, user_host_lifetime_result)

Initialises an UserHostLifetime Account (UHLA) object.

A UHLA is an account which is initialized when a wallet interacts with Aver via a particular Host for the first time. It is used to store values related to a wallet's interactions with Aver Markets via this Host. It is required to be initialized before a wallet can interact with any Markets via a given Host.

Args
  • aver_client (AverClient): AverClient object
  • pubkey (PublicKey): UserHostLifetime public key
Returns

UserHostLifetime: UserHostLifetime object

@staticmethod
async def load_multiple( aver_client: pyaver.aver_client.AverClient, pubkeys: list[solana.publickey.PublicKey])
61    @staticmethod
62    async def load_multiple(aver_client: AverClient, pubkeys: list[PublicKey]):
63        """
64         Initialised multiple UserHostLifetime objects
65
66        Args:
67            aver_client (AverClient): AverClient object
68            pubkeys (list[PublicKey]): List of UserHostLifetime public keys
69
70        Returns:
71            list[UserHostLifetime]: List of UserHostLifetime objects
72        """
73        res = await aver_client.program.account['UserHostLifetime'].fetch_multiple(pubkeys)
74        uhls: list[UserHostLifetime] = []
75        for i, pubkey in enumerate(pubkeys):
76            uhls.append(UserHostLifetime(pubkey, res[i]))
77        return uhls

Initialised multiple UserHostLifetime objects

Args
  • aver_client (AverClient): AverClient object
  • pubkeys (list[PublicKey]): List of UserHostLifetime public keys
Returns

list[UserHostLifetime]: List of UserHostLifetime objects

@staticmethod
async def get_or_create_user_host_lifetime( client: pyaver.aver_client.AverClient, owner: solana.keypair.Keypair, send_options: solana.rpc.types.TxOpts = None, quote_token_mint: solana.publickey.PublicKey = None, host: solana.publickey.PublicKey = 5xhmqK1Dh48TiqvHxoZi6WWWKL6THtsUjh3GoiVEbbR8, referrer: solana.publickey.PublicKey = 11111111111111111111111111111111, discount_token: solana.publickey.PublicKey = 11111111111111111111111111111111, program_id: solana.publickey.PublicKey = 6q5ZGhEj6kkmEjuyCXuH4x8493bpi9fNzvy9L8hX83HQ)
 79    @staticmethod
 80    async def get_or_create_user_host_lifetime(
 81        client: AverClient,
 82        owner: Keypair,
 83        send_options: TxOpts = None,
 84        quote_token_mint: PublicKey = None,
 85        host: PublicKey = AVER_HOST_ACCOUNT,
 86        referrer: PublicKey = SYS_PROGRAM_ID,
 87        discount_token: PublicKey = SYS_PROGRAM_ID,
 88        program_id: PublicKey = AVER_PROGRAM_ID
 89    ):
 90        """
 91        Attempts to load a UserHostLifetime account and creates one if not found
 92
 93        Args:
 94            client (AverClient): AverClient object
 95            owner (Keypair): Owner of UserHostLifetime account. Pays transaction and rent costs
 96            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
 97            quote_token_mint (PublicKey, optional): Quote token mint public key. Defaults to Defaults to USDC token according to chosen solana network in AverClient.
 98            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
 99            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
100            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
101            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
102
103        Returns:
104            UserHostLifetime: UserHostLifetime object
105        """
106        quote_token_mint = quote_token_mint if quote_token_mint is not None else client.quote_token
107        user_host_lifetime = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)[0]
108
109        try:
110            uhl = await UserHostLifetime.load(client, user_host_lifetime)
111            return uhl
112        except:
113            user_quote_token_ata = await client.get_or_create_associated_token_account(
114                owner.public_key, 
115                owner, 
116                quote_token_mint
117            )
118
119            sig = await UserHostLifetime.create_user_host_lifetime(
120                client,
121                owner,
122                user_quote_token_ata,
123                send_options,
124                host,
125                referrer,
126                discount_token,
127                program_id,
128            )
129
130            await client.provider.connection.confirm_transaction(
131                sig['result'],
132                commitment=Finalized
133            )
134
135            return await UserHostLifetime.load(client, user_host_lifetime)

Attempts to load a UserHostLifetime account and creates one if not found

Args
  • client (AverClient): AverClient object
  • owner (Keypair): Owner of UserHostLifetime account. Pays transaction and rent costs
  • send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
  • quote_token_mint (PublicKey, optional): Quote token mint public key. Defaults to Defaults to USDC token according to chosen solana network in AverClient.
  • host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
  • referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
  • discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
  • program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
Returns

UserHostLifetime: UserHostLifetime object

@staticmethod
def make_create_user_host_lifetime_instruction( aver_client: pyaver.aver_client.AverClient, user_quote_token_ata: solana.publickey.PublicKey, owner: solana.keypair.Keypair, host: solana.publickey.PublicKey = 5xhmqK1Dh48TiqvHxoZi6WWWKL6THtsUjh3GoiVEbbR8, referrer: solana.publickey.PublicKey = 11111111111111111111111111111111, discount_token: solana.publickey.PublicKey = 11111111111111111111111111111111, program_id=6q5ZGhEj6kkmEjuyCXuH4x8493bpi9fNzvy9L8hX83HQ)
137    @staticmethod
138    def make_create_user_host_lifetime_instruction(
139        aver_client: AverClient,
140        user_quote_token_ata: PublicKey,
141        owner: Keypair,
142        host: PublicKey = AVER_HOST_ACCOUNT,
143        referrer: PublicKey = SYS_PROGRAM_ID,
144        discount_token: PublicKey = SYS_PROGRAM_ID,
145        program_id = AVER_PROGRAM_ID
146    ):
147        """
148        Creates instruction for UserHostLifetime account creation
149
150        Returns TransactionInstruction object only. Does not send transaction.
151
152        Args:
153            aver_client (AverClient): AverClient object
154            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
155            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
156            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
157            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
158            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
159            program_id (_type_, optional): Program public key. Defaults to AVER_PROGRAM_ID.
160
161        Returns:
162            TransactionInstruction: TransactionInstruction object
163        """
164        user_host_lifetime, bump = UserHostLifetime.derive_pubkey_and_bump(owner.public_key, host, program_id)
165
166        discount_token_account = AccountMeta(
167            is_signer=False,
168            is_writable=False,
169            pubkey=discount_token,
170        )
171        referrer_account = AccountMeta(
172            is_signer=False,
173            is_writable=True,
174            pubkey=referrer,
175        )
176        return aver_client.program.instruction['init_user_host_lifetime']( 
177            bump,
178            ctx=Context(
179                accounts={
180                "user": owner.public_key,
181                "user_host_lifetime": user_host_lifetime,
182                "user_quote_token_ata": user_quote_token_ata,
183                "host": host,
184                "system_program": SYS_PROGRAM_ID,
185                },
186                remaining_accounts=[discount_token_account, referrer_account],
187                signers=[owner]
188            )
189            )

Creates instruction for UserHostLifetime account creation

Returns TransactionInstruction object only. Does not send transaction.

Args
  • aver_client (AverClient): AverClient object
  • user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
  • owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
  • host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
  • referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
  • discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
  • program_id (_type_, optional): Program public key. Defaults to AVER_PROGRAM_ID.
Returns

TransactionInstruction: TransactionInstruction object

@staticmethod
async def create_user_host_lifetime( aver_client: pyaver.aver_client.AverClient, owner: solana.keypair.Keypair, user_quote_token_ata: solana.publickey.PublicKey, send_options: solana.rpc.types.TxOpts = None, host: solana.publickey.PublicKey = 5xhmqK1Dh48TiqvHxoZi6WWWKL6THtsUjh3GoiVEbbR8, referrer: solana.publickey.PublicKey = 11111111111111111111111111111111, discount_token: solana.publickey.PublicKey = 11111111111111111111111111111111, program_id: solana.publickey.PublicKey = 6q5ZGhEj6kkmEjuyCXuH4x8493bpi9fNzvy9L8hX83HQ)
191    @staticmethod
192    async def create_user_host_lifetime(
193        aver_client: AverClient,
194        owner: Keypair,
195        user_quote_token_ata: PublicKey,
196        send_options: TxOpts = None,
197        host: PublicKey = AVER_HOST_ACCOUNT,
198        referrer: PublicKey = SYS_PROGRAM_ID,
199        discount_token: PublicKey = SYS_PROGRAM_ID,
200        program_id: PublicKey = AVER_PROGRAM_ID,
201    ):
202        """
203        Creates UserHostLifetime account
204
205        Sends instructions on chain
206
207        Args:
208            aver_client (AverClient): AverClient object
209            owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
210            user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
211            send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
212            host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
213            referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
214            discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
215            program_id (PublicKey, optional):  Program public key. Defaults to AVER_PROGRAM_ID.
216
217        Returns:
218            RPCResponse: Response
219        """
220        ix = UserHostLifetime.make_create_user_host_lifetime_instruction(
221            aver_client,
222            user_quote_token_ata,
223            owner,
224            host,
225            referrer,
226            discount_token,
227            program_id
228        )
229
230        if(send_options is None):
231            send_options = TxOpts()
232        else:
233            send_options = TxOpts(
234                skip_confirmation=send_options.skip_confirmation,
235                skip_preflight=send_options.skip_confirmation,
236                preflight_commitment=Finalized,
237                max_retries=send_options.max_retries)
238
239
240        return await sign_and_send_transaction_instructions(
241            aver_client,
242            [],
243            owner,
244            [ix],
245            send_options
246        )

Creates UserHostLifetime account

Sends instructions on chain

Args
  • aver_client (AverClient): AverClient object
  • owner (Keypair): Keypair of owner of UserHostLifetime account. Pays transaction and rent costs
  • user_quote_token_ata (PublicKey): Quote token ATA public key (holds funds for this user)
  • send_options (TxOpts, optional): Options to specify when broadcasting a transaction. Defaults to None.
  • host (PublicKey, optional): Host account public key. Defaults to AVER_HOST_ACCOUNT.
  • referrer (PublicKey, optional): Referrer account public key. Defaults to SYS_PROGRAM_ID.
  • discount_token (PublicKey, optional): _description_. Defaults to SYS_PROGRAM_ID.
  • program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
Returns

RPCResponse: Response

@staticmethod
def derive_pubkey_and_bump( owner: solana.publickey.PublicKey, host: solana.publickey.PublicKey, program_id: solana.publickey.PublicKey = 6q5ZGhEj6kkmEjuyCXuH4x8493bpi9fNzvy9L8hX83HQ)
248    @staticmethod
249    def derive_pubkey_and_bump(owner: PublicKey, host: PublicKey, program_id: PublicKey = AVER_PROGRAM_ID):
250        """
251        Derives PDA for UserHostLifetime public key
252
253        Args:
254            owner (PublicKey): Owner of host account
255            host (PublicKey, optional): Public key of corresponding Host account. Defaults to AVER_HOST_ACCOUNT.
256            program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
257
258        Returns:
259            PublicKey: Public key of UserHostLifetime account
260        """
261        return PublicKey.find_program_address(
262            [bytes('user-host-lifetime', 'utf-8'), bytes(owner), bytes(host)],
263            program_id
264        )

Derives PDA for UserHostLifetime public key

Args
  • owner (PublicKey): Owner of host account
  • host (PublicKey, optional): Public key of corresponding Host account. Defaults to AVER_HOST_ACCOUNT.
  • program_id (PublicKey, optional): Program public key. Defaults to AVER_PROGRAM_ID.
Returns

PublicKey: Public key of UserHostLifetime account

def get_fee_tier_postion(self)
267    def get_fee_tier_postion(self):
268        """
269        Gets user's fee tier position
270
271        This determines the percentage fee taken by the host on winnings
272
273        Returns:
274            FeeTier: FeeTier for user
275        """
276        last_fee_tier_check = self.user_host_lifetime_state.last_fee_tier_check
277        if(last_fee_tier_check == FeeTier.BASE):
278            return 0
279        if(last_fee_tier_check == FeeTier.AVER1):
280            return 1
281        if(last_fee_tier_check == FeeTier.AVER2):
282            return 2
283        if(last_fee_tier_check == FeeTier.AVER3):
284            return 3
285        if(last_fee_tier_check == FeeTier.AVER4):
286            return 4
287        if(last_fee_tier_check == FeeTier.AVER5):
288            return 5
289        if(last_fee_tier_check == FeeTier.FREE):
290            return 6

Gets user's fee tier position

This determines the percentage fee taken by the host on winnings

Returns

FeeTier: FeeTier for user