-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples_internal.py
67 lines (50 loc) · 2.5 KB
/
examples_internal.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
from eth_account import Account
import time
import math
from pprint import pprint
from limit_order_sdk import Address, OrderInfoData
# This is a well-known test private key, do not use it in production
PRIV_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
def create_limit_order(chain_id: int):
from limit_order_sdk import LimitOrder, MakerTraits
wallet = Account.from_key(PRIV_KEY)
# Expiration time setup
expires_in = 120 # 2 minutes in seconds
expiration = math.floor(time.time() / 1000) + expires_in
# Creating a LimitOrder
maker_traits = MakerTraits.default().with_expiration(expiration)
order_info_data = OrderInfoData(
maker_asset=Address("0xdac17f958d2ee523a2206206994597c13d831ec7"),
taker_asset=Address("0x111111111117dc0aa78b770fa6a738034120c302"),
making_amount=100_000000,
taking_amount=10_00000000000000000,
maker=Address(wallet.address),
# Optional fields like salt or receiver can be added here if necessary
)
order = LimitOrder(order_info_data, maker_traits)
typed_data = order.get_typed_data(chain_id)
signed_message = Account.sign_typed_data(PRIV_KEY, typed_data.domain, {"Order": typed_data.types["Order"]}, typed_data.message)
signature = signed_message.signature.hex()
pprint(f"Limit Order signature: {signature}")
def create_rfq_order(chain_id: int):
from limit_order_sdk import RfqOrder, rand_int, UINT_40_MAX
wallet = Account.from_key(PRIV_KEY)
expires_in = 120 # 2 minutes in seconds
expiration = math.floor(time.time() / 1000) + expires_in
order_info = OrderInfoData(
maker_asset=Address("0xdac17f958d2ee523a2206206994597c13d831ec7"),
taker_asset=Address("0x111111111117dc0aa78b770fa6a738034120c302"),
making_amount=100_000000, # 100 USDT
taking_amount=10_00000000000000000, # 10 1INCH
maker=Address(wallet.address),
)
options = {"allowedSender": Address("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"), "expiration": expiration, "nonce": rand_int(UINT_40_MAX)}
order = RfqOrder(order_info=order_info, options=options)
typed_data = order.get_typed_data(chain_id)
signed_message = Account.sign_typed_data(PRIV_KEY, typed_data.domain, {"Order": typed_data.types["Order"]}, typed_data.message)
signature = signed_message.signature.hex()
pprint(f"RFQ Order signature: {signature}")
if __name__ == "__main__":
chain_id = 1 # Ethereum
create_limit_order(chain_id)
create_rfq_order(chain_id)