Package: uniswapx-sdk
Python UniswapX SDKProject InformationCode QualityRelease NotesV0.2.0Exclusive Dutch Order EncoderReactor Execute EncoderGet Orders from UniswapX APIIntegration TestsDocumentationV0.1.0Exclusive Dutch Order DecoderOrder ResolverOverview and Points of AttentionThis library is a Python SDK that can be used to easily interact with UniswapX ecosystem: Reactors, Quoter, API.
It's partially inspired byhttps://github.com/Uniswap/uniswapx-sdk⚠ This library has not been audited, so use at your own risk !⚠ The API currently exposed is very likely to change with the following versions: consider forcing the version.⚠ This project is a work in progress so not all features have already been implemented.InstallationA good practice is to usePython virtual environments, here is atutorial.The library can be pip installed frompypi.orgas usual:# update pip to latest version if neededpipinstall-Upip# install the decoder from pypi.orgpipinstalluniswapx-sdkUsageHow to encode an Exclusive Ducth OrderFirst, you need to import the classes that will help you to structure the encoding, along with a function that will compute the order nonce:fromuniswapx_sdk.encoderimport(DecayTime,ExclusiveDutchOrderInfo,ExclusiveDutchOrderInput,ExclusiveDutchOrderOutput,ExclusiveFiller,get_nonce,)Then you instantiate them:order_info=ExclusiveDutchOrderInfo(reactor="0x6000da47483062a0d734ba3dc7576ce6a0b645c4",swapper="0x...",# your account addressnonce=get_nonce(),deadline=deadline,# Unix timestamp after which the order won't be valid any more.)decay_time=DecayTime(start_timestamp,end_timestamp)dutch_input=ExclusiveDutchOrderInput(in_token_address,start_amount_in_wei,end_amount_in_wei)dutch_outputs=(ExclusiveDutchOrderOutput(token=out_token_address,# or '0x0000000000000000000000000000000000000000' for native coinstart_amount=start_amount_in_wei,end_amount=end_amount_in_wei,recipient=recipient_address,# who is going to receive the output),)exclusive_filler=ExclusiveFiller(filler_address,bps)# the exclusive filler if any with the override bps#  or exclusive_filler = ExclusiveFiller() if no exclusive fillerAnd now you're ready to encode the order and sign it:importExclusiveDutchOrderEncoderencoder=ExclusiveDutchOrderEncoder(chain_id)encoded_order,signable_message=encoder.encode_order(order_info,decay_time,dutch_input,dutch_outputs,exclusive_filler)signed_message=your_account.sign_message(signable_message)How to resolve/validate/quote an orderLet's say you have en encodedorderalong with its signaturesig. Resolving it is as simple as:fromuniswapx_sdk.resolverimportOrderResolverresolver=awaitOrderResolver.create(rpc_endpoint="https://...")resolved_order=asyncio.run(resolver.resolve(order,sig))How to decode an orderLet's say you have en encoded order. Decoding it is as simple as:fromuniswapx_sdk.decoderimportExclusiveDutchOrderDecoderdecoder=ExclusiveDutchOrderDecoder()decoded_order=decoder.decode(encoded_order)How to get orders from UniswapX APIfromuniswapx_sdk.apiimportUniswapXAPIapi=UniswapXAPI(chain_id)orders=awaitapi.get_orders(order_status)# with order_status in open, expired, error, cancelled, filled, insufficient-fundsHow to fill an orderLet's say you want to fill (execute) a dutch order. First you encode it as follows:fromuniswapx_sdk.encoderimportExclusiveDutchOrderEncoderencoded_input=ExclusiveDutchOrderEncoder.encode_execute(order,sig)# where sig is the signature corresponding to the orderThen you include theencoded_inputin the transaction you sign and send to the Exclusive Dutch Order Reactor.