forked from drift-labs/driftpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmp.py
87 lines (73 loc) · 1.75 KB
/
tmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#%%
# %load_ext autoreload
# %autoreload 2
import sys
sys.path.append('src/')
import driftpy
print(driftpy.__path__)
from driftpy.constants.config import configs
from anchorpy import Provider
import json
from anchorpy import Wallet
from solana.rpc.async_api import AsyncClient
from driftpy.drift_client import DriftClient
from driftpy.accounts import get_user_account
from dataclasses import asdict
from solana.keypair import Keypair
import asyncio
async def main():
global summary_data
with open('tmp.json', 'r') as f: secret = json.load(f)
kp = Keypair.from_secret_key(bytes(secret))
print('pk:', kp.public_key)
config = configs['devnet']
url = 'https://api.devnet.solana.com'
wallet = Wallet(kp)
connection = AsyncClient(url)
provider = Provider(connection, wallet)
dc = DriftClient.from_config(config, provider)
while True:
print('settling...')
await dc.settle_lp(
dc.authority,
0
)
user = await get_user_account(
dc.program,
kp.public_key,
)
position = user.positions[0]
print('position:', position)
summary_data.append(
asdict(position)
)
await asyncio.sleep(10)
print()
summary_data = []
try:
asyncio.run(main())
finally:
import pandas as pd
df = pd.DataFrame(summary_data)
df.to_csv("lp_summary_bot.csv", index=False)
#%%
#%%
#%%
# from driftpy.constants.numeric_constants import AMM_RESERVE_PRECISION
# n_tokens = 1_000 * AMM_RESERVE_PRECISION
# sig = await dc.add_liquidity(
# n_tokens, 0
# )
# sig
# #%%
# import time
#%%
#%%
# # %%
# pk = PublicKey("2zJhfetddV3J89zRrQ6o9W4KW2JbD6QYHjB7uT2VsgnG")
# drift_user = User(
# dc,
# pk
# )
# %%
# %%