diff --git a/examples/integrator_approve.py b/examples/integrator/approve.py similarity index 66% rename from examples/integrator_approve.py rename to examples/integrator/approve.py index 622ca6e..270c8e8 100644 --- a/examples/integrator_approve.py +++ b/examples/integrator/approve.py @@ -1,11 +1,15 @@ import asyncio -from utils import default_example_setup +import time +from examples.utils import default_example_setup ETH_PRIVATE_KEY = "" +CONFIG_FILE = "../api_key_config.json" +APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms + async def main(): - client, api_client, _ = default_example_setup() + client, api_client, _ = default_example_setup(CONFIG_FILE) err = client.check_client() if err is not None: @@ -19,7 +23,7 @@ async def main(): max_perps_maker_fee=1000, max_spot_taker_fee=1000, max_spot_maker_fee=1000, - approval_expiry=1775518466000 + approval_expiry=APPROVAL_EXPIRY ) print(tx_info, response, err) diff --git a/examples/integrator/approve_same_master_account.py b/examples/integrator/approve_same_master_account.py new file mode 100644 index 0000000..7307a5f --- /dev/null +++ b/examples/integrator/approve_same_master_account.py @@ -0,0 +1,33 @@ +import asyncio +import time +from examples.utils import default_example_setup + + +CONFIG_FILE = "../api_key_config.json" +APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms + + +async def main(): + client, api_client, _ = default_example_setup(CONFIG_FILE) + + err = client.check_client() + if err is not None: + print(f"CheckClient error: {err}") + return + + # no L1 sig required for approving integrator who is tied to the same address (e.g. subaccount) + tx_info, response, err = await client.approve_integrator( + integrator_account_index=281474976710649, + max_perps_taker_fee=1000, + max_perps_maker_fee=1000, + max_spot_taker_fee=1000, + max_spot_maker_fee=1000, + approval_expiry=APPROVAL_EXPIRY + ) + print(tx_info, response, err) + + await client.close() + await api_client.close() + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/examples/integrator/approve_zero_fees.py b/examples/integrator/approve_zero_fees.py new file mode 100644 index 0000000..8aeddca --- /dev/null +++ b/examples/integrator/approve_zero_fees.py @@ -0,0 +1,35 @@ +import asyncio +import os +import time +from examples.utils import default_example_setup + + +CONFIG_FILE = "../api_key_config.json" +APPROVAL_EXPIRY = int(time.time() * 1000) + 90 * 24 * 60 * 60 * 1000 # now + 90 days, in ms + + +async def main(): + client, api_client, _ = default_example_setup(CONFIG_FILE) + + err = client.check_client() + if err is not None: + print(f"CheckClient error: {err}") + return + + # no L1 sig required if integrator takes no fees + tx_info, response, err = await client.approve_integrator( + integrator_account_index=6, + max_perps_taker_fee=0, + max_perps_maker_fee=0, + max_spot_taker_fee=0, + max_spot_maker_fee=0, + approval_expiry=APPROVAL_EXPIRY, + ) + print(tx_info, response, err) + + await client.close() + await api_client.close() + + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/examples/integrator_create_market_order.py b/examples/integrator/create_market_order.py similarity index 81% rename from examples/integrator_create_market_order.py rename to examples/integrator/create_market_order.py index 17e63e3..b6ec720 100644 --- a/examples/integrator_create_market_order.py +++ b/examples/integrator/create_market_order.py @@ -1,15 +1,18 @@ import asyncio -from utils import default_example_setup +from examples.utils import default_example_setup + + +CONFIG_FILE = "../api_key_config.json" async def main(): - client, api_client, _ = default_example_setup() + client, api_client, _ = default_example_setup(CONFIG_FILE) client.check_client() # Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot. market_index = 2048 # integrator_account_index = 6 - integrator_account_index = 281474976710647 + integrator_account_index = 281474976710649 integrator_taker_fee = 1000 integrator_maker_fee = 500 diff --git a/examples/integrator_create_modify_order.py b/examples/integrator/create_modify_order.py similarity index 92% rename from examples/integrator_create_modify_order.py rename to examples/integrator/create_modify_order.py index 2ef5060..042e9dd 100644 --- a/examples/integrator_create_modify_order.py +++ b/examples/integrator/create_modify_order.py @@ -1,15 +1,18 @@ import asyncio -from utils import default_example_setup +from examples.utils import default_example_setup + + +CONFIG_FILE = "../api_key_config.json" async def main(): - client, api_client, _ = default_example_setup() + client, api_client, _ = default_example_setup(CONFIG_FILE) client.check_client() # Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot. market_index = 0 # integrator_account_index = 6 - integrator_account_index = 281474976710647 + integrator_account_index = 281474976710649 integrator_taker_fee = 1000 integrator_maker_fee = 500 diff --git a/examples/integrator_revoke.py b/examples/integrator/revoke.py similarity index 67% rename from examples/integrator_revoke.py rename to examples/integrator/revoke.py index 6abe9b8..903cc59 100644 --- a/examples/integrator_revoke.py +++ b/examples/integrator/revoke.py @@ -1,20 +1,21 @@ import asyncio -from utils import default_example_setup +from examples.utils import default_example_setup -ETH_PRIVATE_KEY = "" +CONFIG_FILE = "../api_key_config.json" + async def main(): - client, api_client, _ = default_example_setup() + client, api_client, _ = default_example_setup(CONFIG_FILE) err = client.check_client() if err is not None: print(f"CheckClient error: {err}") return + # no L1 sig required for revoking tx_info, response, err = await client.approve_integrator( - eth_private_key=ETH_PRIVATE_KEY, - integrator_account_index=6, + integrator_account_index=281474976710649, max_perps_taker_fee=0, max_perps_maker_fee=0, max_spot_taker_fee=0, diff --git a/examples/integrator_approve_same_master_account.py b/examples/integrator_approve_same_master_account.py deleted file mode 100644 index 2769c44..0000000 --- a/examples/integrator_approve_same_master_account.py +++ /dev/null @@ -1,26 +0,0 @@ -import asyncio -from utils import default_example_setup - -async def main(): - client, api_client, _ = default_example_setup() - - err = client.check_client() - if err is not None: - print(f"CheckClient error: {err}") - return - - tx_info, response, err = await client.approve_integrator_same_master_account( - integrator_account_index=281474976710647, - max_perps_taker_fee=1000, - max_perps_maker_fee=1000, - max_spot_taker_fee=1000, - max_spot_maker_fee=1000, - approval_expiry=1775518466000 - ) - print(tx_info, response, err) - - await client.close() - await api_client.close() - -if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file diff --git a/lighter/signer_client.py b/lighter/signer_client.py index 3bbcc1f..de2e41d 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -568,7 +568,7 @@ def sign_modify_order( def sign_approve_integrator( self, - eth_private_key: str, + eth_private_key: Optional[str], integrator_account_index: int, max_perps_taker_fee: int, max_perps_maker_fee: int, @@ -591,6 +591,8 @@ def sign_approve_integrator( api_key_index, self.account_index ) + if eth_private_key is None: + return self.__decode_tx_info(res) return self.__decode_and_sign_tx_info(eth_private_key, res) def sign_approve_integrator_same_master_account( @@ -1200,7 +1202,6 @@ async def modify_order( @process_api_key_and_nonce async def approve_integrator( self, - eth_private_key: str, integrator_account_index: int, max_perps_taker_fee: int, max_perps_maker_fee: int, @@ -1209,7 +1210,8 @@ async def approve_integrator( approval_expiry: int, skip_nonce: int = SKIP_NONCE_OFF, nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX + api_key_index: int = DEFAULT_API_KEY_INDEX, + eth_private_key: Optional[str] = None, ): tx_type, tx_info, tx_hash, error = self.sign_approve_integrator( eth_private_key, @@ -1231,38 +1233,6 @@ async def approve_integrator( logging.debug(f"Approve Integrator Send. TxResponse: {api_response}") return tx_info, api_response, None - @process_api_key_and_nonce - async def approve_integrator_same_master_account( - self, - integrator_account_index: int, - max_perps_taker_fee: int, - max_perps_maker_fee: int, - max_spot_taker_fee: int, - max_spot_maker_fee: int, - approval_expiry: int, - skip_nonce: int = SKIP_NONCE_OFF, - nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX - ): - tx_type, tx_info, tx_hash, error = self.sign_approve_integrator_same_master_account( - integrator_account_index, - max_perps_taker_fee, - max_perps_maker_fee, - max_spot_taker_fee, - max_spot_maker_fee, - approval_expiry, - skip_nonce, - nonce, - api_key_index - ) - if error is not None: - return None, None, error - - logging.debug(f"Approve Integrator TxHash: {tx_hash} TxInfo: {tx_info}") - api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info) - logging.debug(f"Approve Integrator Send. TxResponse: {api_response}") - return tx_info, api_response, None - @process_api_key_and_nonce 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): if asset_id in self.ASSET_TO_TICKER_SCALE: diff --git a/lighter/signers/lighter-signer-darwin-amd64.dylib b/lighter/signers/lighter-signer-darwin-amd64.dylib index c7b6568..f3b47a4 100644 Binary files a/lighter/signers/lighter-signer-darwin-amd64.dylib and b/lighter/signers/lighter-signer-darwin-amd64.dylib differ diff --git a/lighter/signers/lighter-signer-darwin-amd64.h b/lighter/signers/lighter-signer-darwin-amd64.h index fcd087a..cd8e9ee 100644 --- a/lighter/signers/lighter-signer-darwin-amd64.h +++ b/lighter/signers/lighter-signer-darwin-amd64.h @@ -12,8 +12,6 @@ #ifndef GO_CGO_GOSTRING_TYPEDEF typedef struct { const char *p; ptrdiff_t n; } _GoString_; -extern size_t _GoStringLen(_GoString_ s); -extern const char *_GoStringPtr(_GoString_ s); #endif #endif @@ -83,16 +81,10 @@ typedef size_t GoUintptr; typedef float GoFloat32; typedef double GoFloat64; #ifdef _MSC_VER -#if !defined(__cplusplus) || _MSVC_LANG <= 201402L #include typedef _Fcomplex GoComplex64; typedef _Dcomplex GoComplex128; #else -#include -typedef std::complex GoComplex64; -typedef std::complex GoComplex128; -#endif -#else typedef float _Complex GoComplex64; typedef double _Complex GoComplex128; #endif @@ -119,7 +111,7 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; extern "C" { #endif -extern ApiKeyResponse GenerateAPIKey(void); +extern ApiKeyResponse GenerateAPIKey(); extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long cAccountIndex); extern char* CheckClient(int cApiKeyIndex, long long cAccountIndex); extern SignedTxResponse SignChangePubKey(char* cPubKey, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex); diff --git a/lighter/signers/lighter-signer-darwin-arm64.dylib b/lighter/signers/lighter-signer-darwin-arm64.dylib index ca2ac8b..46d671b 100644 Binary files a/lighter/signers/lighter-signer-darwin-arm64.dylib and b/lighter/signers/lighter-signer-darwin-arm64.dylib differ diff --git a/lighter/signers/lighter-signer-linux-amd64.so b/lighter/signers/lighter-signer-linux-amd64.so index 4be00ef..1fd4f89 100644 Binary files a/lighter/signers/lighter-signer-linux-amd64.so and b/lighter/signers/lighter-signer-linux-amd64.so differ diff --git a/lighter/signers/lighter-signer-linux-arm64.so b/lighter/signers/lighter-signer-linux-arm64.so index f6036c3..f4bf655 100644 Binary files a/lighter/signers/lighter-signer-linux-arm64.so and b/lighter/signers/lighter-signer-linux-arm64.so differ diff --git a/lighter/signers/lighter-signer-windows-amd64.dll b/lighter/signers/lighter-signer-windows-amd64.dll index 1469234..9c64aff 100644 Binary files a/lighter/signers/lighter-signer-windows-amd64.dll and b/lighter/signers/lighter-signer-windows-amd64.dll differ diff --git a/lighter/signers/lighter-signer-windows-amd64.h b/lighter/signers/lighter-signer-windows-amd64.h index 4fcf8a5..95d8450 100644 --- a/lighter/signers/lighter-signer-windows-amd64.h +++ b/lighter/signers/lighter-signer-windows-amd64.h @@ -1,6 +1,6 @@ /* Code generated by cmd/cgo; DO NOT EDIT. */ -/* package command-line-arguments */ +/* package github.com/elliottech/lighter-go/sharedlib */ #line 1 "cgo-builtin-export-prolog"