nado-protocol 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nado_protocol/__init__.py +0 -0
- nado_protocol/client/__init__.py +200 -0
- nado_protocol/client/apis/__init__.py +26 -0
- nado_protocol/client/apis/base.py +42 -0
- nado_protocol/client/apis/market/__init__.py +23 -0
- nado_protocol/client/apis/market/execute.py +192 -0
- nado_protocol/client/apis/market/query.py +310 -0
- nado_protocol/client/apis/perp/__init__.py +18 -0
- nado_protocol/client/apis/perp/query.py +30 -0
- nado_protocol/client/apis/rewards/__init__.py +6 -0
- nado_protocol/client/apis/rewards/execute.py +131 -0
- nado_protocol/client/apis/rewards/query.py +12 -0
- nado_protocol/client/apis/spot/__init__.py +23 -0
- nado_protocol/client/apis/spot/base.py +32 -0
- nado_protocol/client/apis/spot/execute.py +117 -0
- nado_protocol/client/apis/spot/query.py +79 -0
- nado_protocol/client/apis/subaccount/__init__.py +24 -0
- nado_protocol/client/apis/subaccount/execute.py +54 -0
- nado_protocol/client/apis/subaccount/query.py +145 -0
- nado_protocol/client/context.py +90 -0
- nado_protocol/contracts/__init__.py +377 -0
- nado_protocol/contracts/abis/Endpoint.json +636 -0
- nado_protocol/contracts/abis/FQuerier.json +1909 -0
- nado_protocol/contracts/abis/IClearinghouse.json +876 -0
- nado_protocol/contracts/abis/IERC20.json +185 -0
- nado_protocol/contracts/abis/IEndpoint.json +250 -0
- nado_protocol/contracts/abis/IFoundationRewardsAirdrop.json +76 -0
- nado_protocol/contracts/abis/IOffchainBook.json +536 -0
- nado_protocol/contracts/abis/IPerpEngine.json +931 -0
- nado_protocol/contracts/abis/IProductEngine.json +352 -0
- nado_protocol/contracts/abis/ISpotEngine.json +813 -0
- nado_protocol/contracts/abis/IStaking.json +288 -0
- nado_protocol/contracts/abis/IVrtxAirdrop.json +138 -0
- nado_protocol/contracts/abis/MockERC20.json +311 -0
- nado_protocol/contracts/deployments/deployment.test.json +18 -0
- nado_protocol/contracts/eip712/__init__.py +16 -0
- nado_protocol/contracts/eip712/domain.py +36 -0
- nado_protocol/contracts/eip712/sign.py +79 -0
- nado_protocol/contracts/eip712/types.py +154 -0
- nado_protocol/contracts/loader.py +55 -0
- nado_protocol/contracts/types.py +141 -0
- nado_protocol/engine_client/__init__.py +35 -0
- nado_protocol/engine_client/execute.py +416 -0
- nado_protocol/engine_client/query.py +481 -0
- nado_protocol/engine_client/types/__init__.py +113 -0
- nado_protocol/engine_client/types/execute.py +680 -0
- nado_protocol/engine_client/types/models.py +247 -0
- nado_protocol/engine_client/types/query.py +516 -0
- nado_protocol/engine_client/types/stream.py +6 -0
- nado_protocol/indexer_client/__init__.py +28 -0
- nado_protocol/indexer_client/query.py +466 -0
- nado_protocol/indexer_client/types/__init__.py +122 -0
- nado_protocol/indexer_client/types/models.py +364 -0
- nado_protocol/indexer_client/types/query.py +819 -0
- nado_protocol/trigger_client/__init__.py +17 -0
- nado_protocol/trigger_client/execute.py +118 -0
- nado_protocol/trigger_client/query.py +61 -0
- nado_protocol/trigger_client/types/__init__.py +7 -0
- nado_protocol/trigger_client/types/execute.py +89 -0
- nado_protocol/trigger_client/types/models.py +44 -0
- nado_protocol/trigger_client/types/query.py +77 -0
- nado_protocol/utils/__init__.py +37 -0
- nado_protocol/utils/backend.py +111 -0
- nado_protocol/utils/bytes32.py +159 -0
- nado_protocol/utils/enum.py +6 -0
- nado_protocol/utils/exceptions.py +58 -0
- nado_protocol/utils/execute.py +403 -0
- nado_protocol/utils/expiration.py +45 -0
- nado_protocol/utils/interest.py +66 -0
- nado_protocol/utils/math.py +67 -0
- nado_protocol/utils/model.py +79 -0
- nado_protocol/utils/nonce.py +33 -0
- nado_protocol/utils/subaccount.py +18 -0
- nado_protocol/utils/time.py +21 -0
- nado_protocol-0.1.0.dist-info/METADATA +157 -0
- nado_protocol-0.1.0.dist-info/RECORD +78 -0
- nado_protocol-0.1.0.dist-info/WHEEL +4 -0
- nado_protocol-0.1.0.dist-info/entry_points.txt +11 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "string",
|
|
6
|
+
"name": "name_",
|
|
7
|
+
"type": "string"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"internalType": "string",
|
|
11
|
+
"name": "symbol_",
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"internalType": "uint8",
|
|
16
|
+
"name": "decimals_",
|
|
17
|
+
"type": "uint8"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"stateMutability": "nonpayable",
|
|
21
|
+
"type": "constructor"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"anonymous": false,
|
|
25
|
+
"inputs": [
|
|
26
|
+
{
|
|
27
|
+
"indexed": true,
|
|
28
|
+
"internalType": "address",
|
|
29
|
+
"name": "owner",
|
|
30
|
+
"type": "address"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"indexed": true,
|
|
34
|
+
"internalType": "address",
|
|
35
|
+
"name": "spender",
|
|
36
|
+
"type": "address"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"indexed": false,
|
|
40
|
+
"internalType": "uint256",
|
|
41
|
+
"name": "value",
|
|
42
|
+
"type": "uint256"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"name": "Approval",
|
|
46
|
+
"type": "event"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"anonymous": false,
|
|
50
|
+
"inputs": [
|
|
51
|
+
{
|
|
52
|
+
"indexed": true,
|
|
53
|
+
"internalType": "address",
|
|
54
|
+
"name": "from",
|
|
55
|
+
"type": "address"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"indexed": true,
|
|
59
|
+
"internalType": "address",
|
|
60
|
+
"name": "to",
|
|
61
|
+
"type": "address"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"indexed": false,
|
|
65
|
+
"internalType": "uint256",
|
|
66
|
+
"name": "value",
|
|
67
|
+
"type": "uint256"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"name": "Transfer",
|
|
71
|
+
"type": "event"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"inputs": [
|
|
75
|
+
{
|
|
76
|
+
"internalType": "address",
|
|
77
|
+
"name": "owner",
|
|
78
|
+
"type": "address"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"internalType": "address",
|
|
82
|
+
"name": "spender",
|
|
83
|
+
"type": "address"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"name": "allowance",
|
|
87
|
+
"outputs": [
|
|
88
|
+
{
|
|
89
|
+
"internalType": "uint256",
|
|
90
|
+
"name": "",
|
|
91
|
+
"type": "uint256"
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"stateMutability": "view",
|
|
95
|
+
"type": "function"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"inputs": [
|
|
99
|
+
{
|
|
100
|
+
"internalType": "address",
|
|
101
|
+
"name": "spender",
|
|
102
|
+
"type": "address"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"internalType": "uint256",
|
|
106
|
+
"name": "amount",
|
|
107
|
+
"type": "uint256"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"name": "approve",
|
|
111
|
+
"outputs": [
|
|
112
|
+
{
|
|
113
|
+
"internalType": "bool",
|
|
114
|
+
"name": "",
|
|
115
|
+
"type": "bool"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"stateMutability": "nonpayable",
|
|
119
|
+
"type": "function"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"inputs": [
|
|
123
|
+
{
|
|
124
|
+
"internalType": "address",
|
|
125
|
+
"name": "account",
|
|
126
|
+
"type": "address"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"name": "balanceOf",
|
|
130
|
+
"outputs": [
|
|
131
|
+
{
|
|
132
|
+
"internalType": "uint256",
|
|
133
|
+
"name": "",
|
|
134
|
+
"type": "uint256"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"stateMutability": "view",
|
|
138
|
+
"type": "function"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"inputs": [],
|
|
142
|
+
"name": "decimals",
|
|
143
|
+
"outputs": [
|
|
144
|
+
{
|
|
145
|
+
"internalType": "uint8",
|
|
146
|
+
"name": "",
|
|
147
|
+
"type": "uint8"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"stateMutability": "view",
|
|
151
|
+
"type": "function"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"inputs": [
|
|
155
|
+
{
|
|
156
|
+
"internalType": "address",
|
|
157
|
+
"name": "spender",
|
|
158
|
+
"type": "address"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"internalType": "uint256",
|
|
162
|
+
"name": "subtractedValue",
|
|
163
|
+
"type": "uint256"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"name": "decreaseAllowance",
|
|
167
|
+
"outputs": [
|
|
168
|
+
{
|
|
169
|
+
"internalType": "bool",
|
|
170
|
+
"name": "",
|
|
171
|
+
"type": "bool"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"stateMutability": "nonpayable",
|
|
175
|
+
"type": "function"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"inputs": [
|
|
179
|
+
{
|
|
180
|
+
"internalType": "address",
|
|
181
|
+
"name": "spender",
|
|
182
|
+
"type": "address"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"internalType": "uint256",
|
|
186
|
+
"name": "addedValue",
|
|
187
|
+
"type": "uint256"
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"name": "increaseAllowance",
|
|
191
|
+
"outputs": [
|
|
192
|
+
{
|
|
193
|
+
"internalType": "bool",
|
|
194
|
+
"name": "",
|
|
195
|
+
"type": "bool"
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
"stateMutability": "nonpayable",
|
|
199
|
+
"type": "function"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"inputs": [
|
|
203
|
+
{
|
|
204
|
+
"internalType": "address",
|
|
205
|
+
"name": "account",
|
|
206
|
+
"type": "address"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"internalType": "uint256",
|
|
210
|
+
"name": "amount",
|
|
211
|
+
"type": "uint256"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"name": "mint",
|
|
215
|
+
"outputs": [],
|
|
216
|
+
"stateMutability": "nonpayable",
|
|
217
|
+
"type": "function"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"inputs": [],
|
|
221
|
+
"name": "name",
|
|
222
|
+
"outputs": [
|
|
223
|
+
{
|
|
224
|
+
"internalType": "string",
|
|
225
|
+
"name": "",
|
|
226
|
+
"type": "string"
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
"stateMutability": "view",
|
|
230
|
+
"type": "function"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"inputs": [],
|
|
234
|
+
"name": "symbol",
|
|
235
|
+
"outputs": [
|
|
236
|
+
{
|
|
237
|
+
"internalType": "string",
|
|
238
|
+
"name": "",
|
|
239
|
+
"type": "string"
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
"stateMutability": "view",
|
|
243
|
+
"type": "function"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"inputs": [],
|
|
247
|
+
"name": "totalSupply",
|
|
248
|
+
"outputs": [
|
|
249
|
+
{
|
|
250
|
+
"internalType": "uint256",
|
|
251
|
+
"name": "",
|
|
252
|
+
"type": "uint256"
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
"stateMutability": "view",
|
|
256
|
+
"type": "function"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"inputs": [
|
|
260
|
+
{
|
|
261
|
+
"internalType": "address",
|
|
262
|
+
"name": "to",
|
|
263
|
+
"type": "address"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"internalType": "uint256",
|
|
267
|
+
"name": "amount",
|
|
268
|
+
"type": "uint256"
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
"name": "transfer",
|
|
272
|
+
"outputs": [
|
|
273
|
+
{
|
|
274
|
+
"internalType": "bool",
|
|
275
|
+
"name": "",
|
|
276
|
+
"type": "bool"
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
"stateMutability": "nonpayable",
|
|
280
|
+
"type": "function"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"inputs": [
|
|
284
|
+
{
|
|
285
|
+
"internalType": "address",
|
|
286
|
+
"name": "from",
|
|
287
|
+
"type": "address"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"internalType": "address",
|
|
291
|
+
"name": "to",
|
|
292
|
+
"type": "address"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"internalType": "uint256",
|
|
296
|
+
"name": "amount",
|
|
297
|
+
"type": "uint256"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"name": "transferFrom",
|
|
301
|
+
"outputs": [
|
|
302
|
+
{
|
|
303
|
+
"internalType": "bool",
|
|
304
|
+
"name": "",
|
|
305
|
+
"type": "bool"
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
"stateMutability": "nonpayable",
|
|
309
|
+
"type": "function"
|
|
310
|
+
}
|
|
311
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodeUrl": "http://0.0.0.0:8545",
|
|
3
|
+
"publicNodeUrl": "http://0.0.0.0:8545",
|
|
4
|
+
"explorerUrl": "",
|
|
5
|
+
"startBlock": 0,
|
|
6
|
+
"deployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
7
|
+
"quote": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
|
|
8
|
+
"querier": "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
|
|
9
|
+
"feeCalculator": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
10
|
+
"clearinghouse": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
11
|
+
"clearinghouseLiq": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
|
|
12
|
+
"endpoint": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
13
|
+
"spotEngine": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
14
|
+
"perpEngine": "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
15
|
+
"vrtxAirdrop": "0x0000000000000000000000000000000000000000",
|
|
16
|
+
"vrtxStaking": "0x0000000000000000000000000000000000000000",
|
|
17
|
+
"foundationRewardsAirdrop": "0x0000000000000000000000000000000000000000"
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from nado_protocol.contracts.eip712.domain import *
|
|
2
|
+
from nado_protocol.contracts.eip712.sign import *
|
|
3
|
+
from nado_protocol.contracts.eip712.types import *
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"get_nado_eip712_domain",
|
|
8
|
+
"get_eip712_domain_type",
|
|
9
|
+
"build_eip712_typed_data",
|
|
10
|
+
"get_eip712_typed_data_digest",
|
|
11
|
+
"sign_eip712_typed_data",
|
|
12
|
+
"get_nado_eip712_type",
|
|
13
|
+
"EIP712Domain",
|
|
14
|
+
"EIP712Types",
|
|
15
|
+
"EIP712TypedData",
|
|
16
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from nado_protocol.contracts.eip712.types import EIP712Domain
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_nado_eip712_domain(verifying_contract: str, chain_id: int) -> EIP712Domain:
|
|
5
|
+
"""
|
|
6
|
+
Util to create an EIP712Domain instance specific to Nado.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
verifying_contract (str): The address of the contract that will verify the EIP-712 signature.
|
|
10
|
+
|
|
11
|
+
chain_id (int): The chain ID of the originating network.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
EIP712Domain: An instance of EIP712Domain with name set to "Nado", version "0.0.1", and the provided verifying contract and chain ID.
|
|
15
|
+
"""
|
|
16
|
+
return EIP712Domain(
|
|
17
|
+
name="Nado",
|
|
18
|
+
version="0.0.1",
|
|
19
|
+
verifyingContract=verifying_contract,
|
|
20
|
+
chainId=chain_id,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_eip712_domain_type() -> list[dict[str, str]]:
|
|
25
|
+
"""
|
|
26
|
+
Util to return the structure of an EIP712Domain as per EIP-712.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
dict: A list of dictionaries each containing the name and type of a field in EIP712Domain.
|
|
30
|
+
"""
|
|
31
|
+
return [
|
|
32
|
+
{"name": "name", "type": "string"},
|
|
33
|
+
{"name": "version", "type": "string"},
|
|
34
|
+
{"name": "chainId", "type": "uint256"},
|
|
35
|
+
{"name": "verifyingContract", "type": "address"},
|
|
36
|
+
]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from eth_account.signers.local import LocalAccount
|
|
2
|
+
from nado_protocol.contracts.eip712.domain import (
|
|
3
|
+
get_eip712_domain_type,
|
|
4
|
+
get_nado_eip712_domain,
|
|
5
|
+
)
|
|
6
|
+
from nado_protocol.contracts.eip712.types import (
|
|
7
|
+
EIP712TypedData,
|
|
8
|
+
EIP712Types,
|
|
9
|
+
get_nado_eip712_type,
|
|
10
|
+
)
|
|
11
|
+
from eth_account.messages import encode_structured_data, _hash_eip191_message
|
|
12
|
+
|
|
13
|
+
from nado_protocol.contracts.types import NadoTxType
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_eip712_typed_data(
|
|
17
|
+
tx: NadoTxType, msg: dict, verifying_contract: str, chain_id: int
|
|
18
|
+
) -> EIP712TypedData:
|
|
19
|
+
"""
|
|
20
|
+
Util to build EIP712 typed data for Nado execution.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
tx (NadoTxType): The Nado tx type being signed.
|
|
24
|
+
|
|
25
|
+
msg (dict): The message being signed.
|
|
26
|
+
|
|
27
|
+
verifying_contract (str): The contract that will verify the signature.
|
|
28
|
+
|
|
29
|
+
chain_id (int): The chain ID of the originating network.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
EIP712TypedData: A structured data object that adheres to the EIP-712 standard.
|
|
33
|
+
"""
|
|
34
|
+
eip17_domain = get_nado_eip712_domain(verifying_contract, chain_id)
|
|
35
|
+
eip712_tx_type = get_nado_eip712_type(tx)
|
|
36
|
+
eip712_primary_type = list(eip712_tx_type.keys())[0]
|
|
37
|
+
eip712_types = EIP712Types(
|
|
38
|
+
**{
|
|
39
|
+
"EIP712Domain": get_eip712_domain_type(),
|
|
40
|
+
**eip712_tx_type,
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
return EIP712TypedData(
|
|
44
|
+
domain=eip17_domain,
|
|
45
|
+
primaryType=eip712_primary_type,
|
|
46
|
+
types=eip712_types,
|
|
47
|
+
message=msg,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_eip712_typed_data_digest(typed_data: EIP712TypedData) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Util to get the EIP-712 typed data hash.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
typed_data (EIP712TypedData): The EIP-712 typed data to hash.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
str: The hexadecimal representation of the hash.
|
|
60
|
+
"""
|
|
61
|
+
encoded_data = encode_structured_data(typed_data.dict())
|
|
62
|
+
return f"0x{_hash_eip191_message(encoded_data).hex()}"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def sign_eip712_typed_data(typed_data: EIP712TypedData, signer: LocalAccount) -> str:
|
|
66
|
+
"""
|
|
67
|
+
Util to sign EIP-712 typed data using a local Ethereum account.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
typed_data (EIP712TypedData): The EIP-712 typed data to sign.
|
|
71
|
+
|
|
72
|
+
signer (LocalAccount): The local Ethereum account to sign the data.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
str: The hexadecimal representation of the signature.
|
|
76
|
+
"""
|
|
77
|
+
encoded_data = encode_structured_data(typed_data.dict())
|
|
78
|
+
typed_data_hash = signer.sign_message(encoded_data)
|
|
79
|
+
return typed_data_hash.signature.hex()
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
from nado_protocol.contracts.types import NadoTxType
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class EIP712Domain(BaseModel):
|
|
6
|
+
"""
|
|
7
|
+
Model that represents the EIP-712 Domain data structure.
|
|
8
|
+
|
|
9
|
+
Attributes:
|
|
10
|
+
name (str): The user-readable name of the signing domain, i.e., the name of the DApp or the protocol.
|
|
11
|
+
version (str): The current major version of the signing domain. Signatures from different versions are not compatible.
|
|
12
|
+
chainId (int): The chain ID of the originating network.
|
|
13
|
+
verifyingContract (str): The address of the contract that will verify the signature.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
name: str
|
|
17
|
+
version: str
|
|
18
|
+
chainId: int
|
|
19
|
+
verifyingContract: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class EIP712Types(BaseModel):
|
|
23
|
+
"""
|
|
24
|
+
Util to encapsulate the EIP-712 type data structure.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
EIP712Domain (list[dict]): A list of dictionaries representing EIP-712 Domain data.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
EIP712Domain: list[dict]
|
|
31
|
+
|
|
32
|
+
class Config:
|
|
33
|
+
arbitrary_types_allowed = True
|
|
34
|
+
extra = "allow"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class EIP712TypedData(BaseModel):
|
|
38
|
+
"""
|
|
39
|
+
Util to represent the EIP-712 Typed Data structure.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
types (EIP712Types): EIP-712 type data.
|
|
43
|
+
primaryType (str): The primary type for EIP-712 message signing.
|
|
44
|
+
domain (EIP712Domain): The domain data of the EIP-712 typed message.
|
|
45
|
+
message (dict): The actual data to sign.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
types: EIP712Types
|
|
49
|
+
primaryType: str
|
|
50
|
+
domain: EIP712Domain
|
|
51
|
+
message: dict
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_nado_eip712_type(tx: NadoTxType) -> dict:
|
|
55
|
+
"""
|
|
56
|
+
Util that provides the EIP712 type information for Nado execute types.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
tx (NadoTxType): The Nado transaction type for which to retrieve EIP712 type information.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
dict: A dictionary containing the EIP712 type information for the given execute type.
|
|
63
|
+
"""
|
|
64
|
+
return {
|
|
65
|
+
NadoTxType.PLACE_ORDER: {
|
|
66
|
+
"Order": [
|
|
67
|
+
{"name": "sender", "type": "bytes32"},
|
|
68
|
+
{"name": "priceX18", "type": "int128"},
|
|
69
|
+
{"name": "amount", "type": "int128"},
|
|
70
|
+
{"name": "expiration", "type": "uint64"},
|
|
71
|
+
{"name": "nonce", "type": "uint64"},
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
NadoTxType.PLACE_ISOLATED_ORDER: {
|
|
75
|
+
"IsolatedOrder": [
|
|
76
|
+
{"name": "sender", "type": "bytes32"},
|
|
77
|
+
{"name": "priceX18", "type": "int128"},
|
|
78
|
+
{"name": "amount", "type": "int128"},
|
|
79
|
+
{"name": "expiration", "type": "uint64"},
|
|
80
|
+
{"name": "nonce", "type": "uint64"},
|
|
81
|
+
{"name": "margin", "type": "int128"},
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
NadoTxType.CANCEL_ORDERS: {
|
|
85
|
+
"Cancellation": [
|
|
86
|
+
{"name": "sender", "type": "bytes32"},
|
|
87
|
+
{"name": "productIds", "type": "uint32[]"},
|
|
88
|
+
{"name": "digests", "type": "bytes32[]"},
|
|
89
|
+
{"name": "nonce", "type": "uint64"},
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
NadoTxType.CANCEL_PRODUCT_ORDERS: {
|
|
93
|
+
"CancellationProducts": [
|
|
94
|
+
{"name": "sender", "type": "bytes32"},
|
|
95
|
+
{"name": "productIds", "type": "uint32[]"},
|
|
96
|
+
{"name": "nonce", "type": "uint64"},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
NadoTxType.WITHDRAW_COLLATERAL: {
|
|
100
|
+
"WithdrawCollateral": [
|
|
101
|
+
{"name": "sender", "type": "bytes32"},
|
|
102
|
+
{"name": "productId", "type": "uint32"},
|
|
103
|
+
{"name": "amount", "type": "uint128"},
|
|
104
|
+
{"name": "nonce", "type": "uint64"},
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
NadoTxType.LIQUIDATE_SUBACCOUNT: {
|
|
108
|
+
"LiquidateSubaccount": [
|
|
109
|
+
{"name": "sender", "type": "bytes32"},
|
|
110
|
+
{"name": "liquidatee", "type": "bytes32"},
|
|
111
|
+
{"name": "productId", "type": "uint32"},
|
|
112
|
+
{"name": "isEncodedSpread", "type": "bool"},
|
|
113
|
+
{"name": "amount", "type": "int128"},
|
|
114
|
+
{"name": "nonce", "type": "uint64"},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
NadoTxType.MINT_LP: {
|
|
118
|
+
"MintLp": [
|
|
119
|
+
{"name": "sender", "type": "bytes32"},
|
|
120
|
+
{"name": "productId", "type": "uint32"},
|
|
121
|
+
{"name": "amountBase", "type": "uint128"},
|
|
122
|
+
{"name": "quoteAmountLow", "type": "uint128"},
|
|
123
|
+
{"name": "quoteAmountHigh", "type": "uint128"},
|
|
124
|
+
{"name": "nonce", "type": "uint64"},
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
NadoTxType.BURN_LP: {
|
|
128
|
+
"BurnLp": [
|
|
129
|
+
{"name": "sender", "type": "bytes32"},
|
|
130
|
+
{"name": "productId", "type": "uint32"},
|
|
131
|
+
{"name": "amount", "type": "uint128"},
|
|
132
|
+
{"name": "nonce", "type": "uint64"},
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
NadoTxType.LINK_SIGNER: {
|
|
136
|
+
"LinkSigner": [
|
|
137
|
+
{"name": "sender", "type": "bytes32"},
|
|
138
|
+
{"name": "signer", "type": "bytes32"},
|
|
139
|
+
{"name": "nonce", "type": "uint64"},
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
NadoTxType.AUTHENTICATE_STREAM: {
|
|
143
|
+
"StreamAuthentication": [
|
|
144
|
+
{"name": "sender", "type": "bytes32"},
|
|
145
|
+
{"name": "expiration", "type": "uint64"},
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
NadoTxType.LIST_TRIGGER_ORDERS: {
|
|
149
|
+
"ListTriggerOrders": [
|
|
150
|
+
{"name": "sender", "type": "bytes32"},
|
|
151
|
+
{"name": "recvTime", "type": "uint64"},
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
}[tx]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from nado_protocol.contracts.types import (
|
|
4
|
+
NadoAbiName,
|
|
5
|
+
NadoDeployment,
|
|
6
|
+
NadoNetwork,
|
|
7
|
+
)
|
|
8
|
+
from nado_protocol.utils.model import ensure_data_type, parse_enum_value
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def load_abi(abi_name: NadoAbiName) -> list[dict]:
|
|
12
|
+
"""
|
|
13
|
+
Load the Application Binary Interface (ABI) for a given contract.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
abi_name (NadoAbiName): The name of the contract for which the ABI is loaded.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
list[dict]: A list of dictionaries representing the ABI of the contract.
|
|
20
|
+
"""
|
|
21
|
+
file_path = Path(__file__).parent / "abis" / f"{parse_enum_value(abi_name)}.json"
|
|
22
|
+
return ensure_data_type(_load_json(file_path), list)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def load_deployment(network: NadoNetwork) -> NadoDeployment:
|
|
26
|
+
"""
|
|
27
|
+
Load the deployment data for a given network.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
network (NadoNetwork): The network for which the deployment data is loaded.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
NadoDeployment: An instance of NadoDeployment containing the loaded deployment data.
|
|
34
|
+
"""
|
|
35
|
+
file_path = (
|
|
36
|
+
Path(__file__).parent
|
|
37
|
+
/ "deployments"
|
|
38
|
+
/ f"deployment.{parse_enum_value(network)}.json"
|
|
39
|
+
)
|
|
40
|
+
return NadoDeployment(**_load_json(file_path))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _load_json(file_path: Path) -> dict:
|
|
44
|
+
"""
|
|
45
|
+
Load a JSON file.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
file_path (Path): The path to the JSON file.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
dict: The content of the JSON file as a dictionary.
|
|
52
|
+
"""
|
|
53
|
+
with open(file_path, "r") as f:
|
|
54
|
+
data = json.load(f)
|
|
55
|
+
return data
|