Skip to content

Commit f9ca675

Browse files
committed
transfer notes and cleanup
1 parent ff1d5b5 commit f9ca675

8 files changed

Lines changed: 57 additions & 37 deletions

examples/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ Examples on how to do this can be found here:
103103
- `spot_get_account_assets_http.py`
104104
- `spot_get_account_assets_ws.py`
105105

106+
Moving money to / from subaccounts is possible for spot assets.
107+
For USDC, you can move directly from main perp balance to subaccount spot balance, for example.
108+
More details can be found in the following example:
109+
- `sub_account_create.py`
110+
- `sub_account_transfer_eth.py`
111+
- `sub_account_transfer_usdc.py`
112+
106113
## Public Pools
107114
Public pools behave just like subaccounts, except that anyone can join them.
108115
You can create / modify a public pool using the SDK. Check out the following example:
@@ -118,6 +125,33 @@ If you want to deposit / withdraw from a public pool, check the following exampl
118125
To get information about pools, check:
119126
- `public_pool_info.py`
120127

128+
## Moving funds around
129+
- `withdraw_fast.py`
130+
- send USDC directly from Lighter to Arbitrum
131+
- `withdraw_normal.py`
132+
- send USDC/ETH from Lighter to Ethereum
133+
- `transfer.py`
134+
- generic example of how to transfer funds between accounts.
135+
- same functionality as `sub_account_transfer_eth` and `sub_account_transfer_usdc`
136+
137+
## Transfer Notes
138+
The `memo` field is a user message, and it has to be exactly 32 bytes long. In case of fast withdrawals, you need to specify the recipient in the memo.
139+
This is the case since the memo is part of the signature. This way, the recipient is verified.
140+
141+
When calling `client.transfer`, you pass the amount without needing to worry about the decimals.
142+
When calling `client.sign_transfer` on the other hand, you need to specify the decimals and pass an integer.
143+
144+
The `fee` field can be obtained by calling `info_api.transfer_fee_info(...)`. The field can be passed as it is.
145+
Transfers between subaccounts are free for all assets.
146+
147+
When sending assets, you can specify the source and destination routes.
148+
A route is either `perp` or `spot`. You can send USDC directly from your perp balance to another person's spot balance.
149+
If you receive USDC in your perp account, it will be instantly used as collateral for open positions.
150+
This also allows you to move USDC from your spot balance to your perp balance.
151+
Spot assets (like ETH) need to have both the from and to route set to `spot`.
152+
You can get all `asset_id`s by following the example below:
153+
- `spot_get_order_books.py`
154+
121155
## Setup steps for mainnet
122156
- deposit money on Lighter to create an account first
123157
- change the URL to `mainnet.zklighter.elliot.ai`

examples/spot_self_transfer_perp_spot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def main():
1212
print(f"CheckClient error: {err}")
1313
return
1414

15-
memo = "a"*32 # memo is a user message, and it has to be exactly 32 bytes long
15+
# You can find more notes on transfers in the README.md file, under `Transfer Notes`
1616
transfer_tx, response, err = await client.transfer(
1717
ETH_PRIVATE_KEY,
1818
to_account_index=client.account_index,
@@ -21,7 +21,7 @@ async def main():
2121
route_from=client.ROUTE_PERP,
2222
route_to=client.ROUTE_SPOT,
2323
fee=0,
24-
memo=memo,
24+
memo="0x" + "00" * 32,
2525
)
2626
if err is not None:
2727
raise Exception(f"error transferring {err}")

examples/spot_self_transfer_spot_perp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def main():
1212
print(f"CheckClient error: {err}")
1313
return
1414

15-
memo = "a"*32 # memo is a user message, and it has to be exactly 32 bytes long
15+
# You can find more notes on transfers in the README.md file, under `Transfer Notes`
1616
transfer_tx, response, err = await client.transfer(
1717
ETH_PRIVATE_KEY,
1818
to_account_index=client.account_index,
@@ -21,7 +21,7 @@ async def main():
2121
route_from=client.ROUTE_SPOT,
2222
route_to=client.ROUTE_PERP,
2323
fee=0,
24-
memo=memo,
24+
memo="0x" + "00" * 32,
2525
)
2626
if err is not None:
2727
raise Exception(f"error transferring {err}")

examples/sub_account_create.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import lighter
32
from utils import default_example_setup
43

54

examples/sub_account_transfer_eth.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import lighter
32
from utils import default_example_setup
43

54
ETH_PRIVATE_KEY = "1234567812345678123456781234567812345678123456781234567812345678"
@@ -13,9 +12,7 @@ async def main():
1312
print(f"CheckClient error: {err}")
1413
return
1514

16-
memo = "a"*32 # memo is a user message, and it has to be exactly 32 bytes long
17-
18-
# Note: For ETH transfers, the only acceptable route is SPOT -> SPOT
15+
# You can find more notes on transfers in the README.md file, under `Transfer Notes`
1916
transfer_tx, response, err = await client.transfer(
2017
ETH_PRIVATE_KEY,
2118
to_account_index=TO_ACCOUNT_INDEX,
@@ -24,7 +21,7 @@ async def main():
2421
route_from=client.ROUTE_SPOT,
2522
route_to=client.ROUTE_SPOT,
2623
fee=0,
27-
memo=memo,
24+
memo="0x" + "00" * 32,
2825
)
2926
if err is not None:
3027
raise Exception(f"error transferring {err}")

examples/sub_account_transfer_usdc.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import lighter
32
from utils import default_example_setup
43

54
ETH_PRIVATE_KEY = "1234567812345678123456781234567812345678123456781234567812345678"
@@ -13,10 +12,7 @@ async def main():
1312
print(f"CheckClient error: {err}")
1413
return
1514

16-
memo = "a"*32 # memo is a user message, and it has to be exactly 32 bytes long
17-
18-
# Note: You can transfer USDC from the main account to the subaccount, both from the spot and from the perp balance.
19-
# For the subaccount, you can receive it either in the spot or the perp balance (will be instantly used as collateral for open positions).
15+
# You can find more notes on transfers in the README.md file, under `Transfer Notes`
2016
transfer_tx, response, err = await client.transfer(
2117
ETH_PRIVATE_KEY,
2218
to_account_index=TO_ACCOUNT_INDEX,
@@ -25,7 +21,7 @@ async def main():
2521
route_from=client.ROUTE_PERP,
2622
route_to=client.ROUTE_SPOT,
2723
fee=0,
28-
memo=memo,
24+
memo="0x" + "00" * 32,
2925
)
3026
if err is not None:
3127
raise Exception(f"error transferring {err}")

examples/transfer.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,36 @@
22
import lighter
33
from utils import default_example_setup
44

5+
ETH_PRIVATE_KEY = "1234567812345678123456781234567812345678123456781234567812345678"
56
TO_ACCOUNT_INDEX = 9
6-
ETH_PRIVATE_KEY = "0x..."
77

88

99
async def main():
1010
client, api_client, _ = default_example_setup()
1111
info_api = lighter.InfoApi(api_client)
1212

13-
auth_token, _ = client.create_auth_token_with_expiry()
14-
fee_info = await info_api.transfer_fee_info(client.account_index, authorization=auth_token, auth=auth_token, to_account_index=TO_ACCOUNT_INDEX)
15-
print(fee_info)
13+
auth_token, err = client.create_auth_token_with_expiry()
14+
if err:
15+
raise Exception(f"Auth token failed: {err}")
1616

17-
err = client.check_client()
18-
if err is not None:
19-
print(f"CheckClient error: {err}")
20-
return
17+
fee_info = await info_api.transfer_fee_info(client.account_index, authorization=auth_token, auth=auth_token, to_account_index=TO_ACCOUNT_INDEX)
2118

22-
memo = "a"*32 # memo is a user message, and it has to be exactly 32 bytes long
19+
# You can find more notes on transfers in the README.md file, under `Transfer Notes`
2320
transfer_tx, response, err = await client.transfer(
24-
ETH_PRIVATE_KEY,
25-
usdc_amount=100, # decimals are added by sdk
21+
eth_private_key=ETH_PRIVATE_KEY,
2622
to_account_index=TO_ACCOUNT_INDEX,
23+
asset_id=client.ASSET_ID_USDC,
24+
route_from=client.ROUTE_PERP,
25+
route_to=client.ROUTE_PERP,
26+
amount=5, # decimals are added by sdk
2727
fee=fee_info.transfer_fee_usdc,
28-
memo=memo,
28+
memo="0x" + "00" * 32,
2929
)
3030
if err is not None:
31-
raise Exception(f"error transferring {err}")
31+
raise Exception(f"error transferring {err}")
32+
3233
print(transfer_tx, response)
3334

34-
lev_tx, response, err = await client.update_leverage(4, client.CROSS_MARGIN_MODE, 3)
35-
print(lev_tx, response, err)
3635

3736
if __name__ == "__main__":
38-
asyncio.run(main())
37+
asyncio.run(main())

examples/withdraw_fast.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#!/usr/bin/env python3
2-
"""
3-
Fast Withdraw - Instant withdrawal from Lighter L2 to Arbitrum
4-
"""
5-
61
import asyncio
72
import json
83
import lighter

0 commit comments

Comments
 (0)