Skip to content

Commit db67868

Browse files
allow l2 sig revoke & approve zero fees integrator (#158)
* using l2 sig * new signers, changed example * add missing signers, organize integrator examples * update mac intel signers --------- Co-authored-by: lavrric <mlavric64@gmail.com>
1 parent c58758b commit db67868

15 files changed

Lines changed: 100 additions & 85 deletions
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import asyncio
2-
from utils import default_example_setup
2+
import time
3+
from examples.utils import default_example_setup
34

45

56
ETH_PRIVATE_KEY = ""
7+
CONFIG_FILE = "../api_key_config.json"
8+
APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms
9+
610

711
async def main():
8-
client, api_client, _ = default_example_setup()
12+
client, api_client, _ = default_example_setup(CONFIG_FILE)
913

1014
err = client.check_client()
1115
if err is not None:
@@ -19,7 +23,7 @@ async def main():
1923
max_perps_maker_fee=1000,
2024
max_spot_taker_fee=1000,
2125
max_spot_maker_fee=1000,
22-
approval_expiry=1775518466000
26+
approval_expiry=APPROVAL_EXPIRY
2327
)
2428
print(tx_info, response, err)
2529

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import asyncio
2+
import time
3+
from examples.utils import default_example_setup
4+
5+
6+
CONFIG_FILE = "../api_key_config.json"
7+
APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms
8+
9+
10+
async def main():
11+
client, api_client, _ = default_example_setup(CONFIG_FILE)
12+
13+
err = client.check_client()
14+
if err is not None:
15+
print(f"CheckClient error: {err}")
16+
return
17+
18+
# no L1 sig required for approving integrator who is tied to the same address (e.g. subaccount)
19+
tx_info, response, err = await client.approve_integrator(
20+
integrator_account_index=281474976710649,
21+
max_perps_taker_fee=1000,
22+
max_perps_maker_fee=1000,
23+
max_spot_taker_fee=1000,
24+
max_spot_maker_fee=1000,
25+
approval_expiry=APPROVAL_EXPIRY
26+
)
27+
print(tx_info, response, err)
28+
29+
await client.close()
30+
await api_client.close()
31+
32+
if __name__ == "__main__":
33+
asyncio.run(main())
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import asyncio
2+
import os
3+
import time
4+
from examples.utils import default_example_setup
5+
6+
7+
CONFIG_FILE = "../api_key_config.json"
8+
APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms
9+
10+
11+
async def main():
12+
client, api_client, _ = default_example_setup(CONFIG_FILE)
13+
14+
err = client.check_client()
15+
if err is not None:
16+
print(f"CheckClient error: {err}")
17+
return
18+
19+
# no L1 sig required if integrator takes no fees
20+
tx_info, response, err = await client.approve_integrator(
21+
integrator_account_index=6,
22+
max_perps_taker_fee=0,
23+
max_perps_maker_fee=0,
24+
max_spot_taker_fee=0,
25+
max_spot_maker_fee=0,
26+
approval_expiry=APPROVAL_EXPIRY,
27+
)
28+
print(tx_info, response, err)
29+
30+
await client.close()
31+
await api_client.close()
32+
33+
34+
if __name__ == "__main__":
35+
asyncio.run(main())

examples/integrator_create_market_order.py renamed to examples/integrator/create_market_order.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import asyncio
2-
from utils import default_example_setup
2+
from examples.utils import default_example_setup
3+
4+
5+
CONFIG_FILE = "../api_key_config.json"
36

47

58
async def main():
6-
client, api_client, _ = default_example_setup()
9+
client, api_client, _ = default_example_setup(CONFIG_FILE)
710
client.check_client()
811

912
# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
1013
market_index = 2048
1114
# integrator_account_index = 6
12-
integrator_account_index = 281474976710647
15+
integrator_account_index = 281474976710649
1316
integrator_taker_fee = 1000
1417
integrator_maker_fee = 500
1518

examples/integrator_create_modify_order.py renamed to examples/integrator/create_modify_order.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import asyncio
2-
from utils import default_example_setup
2+
from examples.utils import default_example_setup
3+
4+
5+
CONFIG_FILE = "../api_key_config.json"
36

47

58
async def main():
6-
client, api_client, _ = default_example_setup()
9+
client, api_client, _ = default_example_setup(CONFIG_FILE)
710
client.check_client()
811

912
# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
1013
market_index = 0
1114
# integrator_account_index = 6
12-
integrator_account_index = 281474976710647
15+
integrator_account_index = 281474976710649
1316
integrator_taker_fee = 1000
1417
integrator_maker_fee = 500
1518

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import asyncio
2-
from utils import default_example_setup
2+
from examples.utils import default_example_setup
33

44

5-
ETH_PRIVATE_KEY = ""
5+
CONFIG_FILE = "../api_key_config.json"
6+
67

78
async def main():
8-
client, api_client, _ = default_example_setup()
9+
client, api_client, _ = default_example_setup(CONFIG_FILE)
910

1011
err = client.check_client()
1112
if err is not None:
1213
print(f"CheckClient error: {err}")
1314
return
1415

16+
# no L1 sig required for revoking
1517
tx_info, response, err = await client.approve_integrator(
16-
eth_private_key=ETH_PRIVATE_KEY,
17-
integrator_account_index=6,
18+
integrator_account_index=281474976710649,
1819
max_perps_taker_fee=0,
1920
max_perps_maker_fee=0,
2021
max_spot_taker_fee=0,

‎examples/integrator_approve_same_master_account.py‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎lighter/signer_client.py‎

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def sign_modify_order(
568568

569569
def sign_approve_integrator(
570570
self,
571-
eth_private_key: str,
571+
eth_private_key: Optional[str],
572572
integrator_account_index: int,
573573
max_perps_taker_fee: int,
574574
max_perps_maker_fee: int,
@@ -591,6 +591,8 @@ def sign_approve_integrator(
591591
api_key_index,
592592
self.account_index
593593
)
594+
if eth_private_key is None:
595+
return self.__decode_tx_info(res)
594596
return self.__decode_and_sign_tx_info(eth_private_key, res)
595597

596598
def sign_approve_integrator_same_master_account(
@@ -1200,7 +1202,6 @@ async def modify_order(
12001202
@process_api_key_and_nonce
12011203
async def approve_integrator(
12021204
self,
1203-
eth_private_key: str,
12041205
integrator_account_index: int,
12051206
max_perps_taker_fee: int,
12061207
max_perps_maker_fee: int,
@@ -1209,7 +1210,8 @@ async def approve_integrator(
12091210
approval_expiry: int,
12101211
skip_nonce: int = SKIP_NONCE_OFF,
12111212
nonce: int = DEFAULT_NONCE,
1212-
api_key_index: int = DEFAULT_API_KEY_INDEX
1213+
api_key_index: int = DEFAULT_API_KEY_INDEX,
1214+
eth_private_key: Optional[str] = None,
12131215
):
12141216
tx_type, tx_info, tx_hash, error = self.sign_approve_integrator(
12151217
eth_private_key,
@@ -1231,38 +1233,6 @@ async def approve_integrator(
12311233
logging.debug(f"Approve Integrator Send. TxResponse: {api_response}")
12321234
return tx_info, api_response, None
12331235

1234-
@process_api_key_and_nonce
1235-
async def approve_integrator_same_master_account(
1236-
self,
1237-
integrator_account_index: int,
1238-
max_perps_taker_fee: int,
1239-
max_perps_maker_fee: int,
1240-
max_spot_taker_fee: int,
1241-
max_spot_maker_fee: int,
1242-
approval_expiry: int,
1243-
skip_nonce: int = SKIP_NONCE_OFF,
1244-
nonce: int = DEFAULT_NONCE,
1245-
api_key_index: int = DEFAULT_API_KEY_INDEX
1246-
):
1247-
tx_type, tx_info, tx_hash, error = self.sign_approve_integrator_same_master_account(
1248-
integrator_account_index,
1249-
max_perps_taker_fee,
1250-
max_perps_maker_fee,
1251-
max_spot_taker_fee,
1252-
max_spot_maker_fee,
1253-
approval_expiry,
1254-
skip_nonce,
1255-
nonce,
1256-
api_key_index
1257-
)
1258-
if error is not None:
1259-
return None, None, error
1260-
1261-
logging.debug(f"Approve Integrator TxHash: {tx_hash} TxInfo: {tx_info}")
1262-
api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info)
1263-
logging.debug(f"Approve Integrator Send. TxResponse: {api_response}")
1264-
return tx_info, api_response, None
1265-
12661236
@process_api_key_and_nonce
12671237
async def transfer(self, eth_private_key: str, to_account_index: int, asset_id: int, route_from: int, route_to: int, amount: float, fee: int, memo: str, skip_nonce : int = SKIP_NONCE_OFF, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX):
12681238
if asset_id in self.ASSET_TO_TICKER_SCALE:
-44.6 KB
Binary file not shown.

‎lighter/signers/lighter-signer-darwin-amd64.h‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#ifndef GO_CGO_GOSTRING_TYPEDEF
1414
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15-
extern size_t _GoStringLen(_GoString_ s);
16-
extern const char *_GoStringPtr(_GoString_ s);
1715
#endif
1816

1917
#endif
@@ -83,16 +81,10 @@ typedef size_t GoUintptr;
8381
typedef float GoFloat32;
8482
typedef double GoFloat64;
8583
#ifdef _MSC_VER
86-
#if !defined(__cplusplus) || _MSVC_LANG <= 201402L
8784
#include <complex.h>
8885
typedef _Fcomplex GoComplex64;
8986
typedef _Dcomplex GoComplex128;
9087
#else
91-
#include <complex>
92-
typedef std::complex<float> GoComplex64;
93-
typedef std::complex<double> GoComplex128;
94-
#endif
95-
#else
9688
typedef float _Complex GoComplex64;
9789
typedef double _Complex GoComplex128;
9890
#endif
@@ -119,7 +111,7 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
119111
extern "C" {
120112
#endif
121113

122-
extern ApiKeyResponse GenerateAPIKey(void);
114+
extern ApiKeyResponse GenerateAPIKey();
123115
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long cAccountIndex);
124116
extern char* CheckClient(int cApiKeyIndex, long long cAccountIndex);
125117
extern SignedTxResponse SignChangePubKey(char* cPubKey, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex);

0 commit comments

Comments
 (0)