@d8x/perpetuals-sdk 0.0.11 → 0.0.14
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.
- package/abi/LimitOrderBook.json +16 -18
- package/abi/LimitOrderBookFactory.json +0 -50
- package/config/defaultConfig.json +1 -1
- package/dist/accountTrade.d.ts +20 -5
- package/dist/accountTrade.js +20 -5
- package/dist/brokerTool.d.ts +36 -17
- package/dist/brokerTool.js +36 -16
- package/dist/marketData.js +0 -2
- package/dist/nodeSDKTypes.d.ts +1 -2
- package/dist/orderReferrerTool.d.ts +59 -3
- package/dist/orderReferrerTool.js +72 -8
- package/dist/perpetualDataHandler.d.ts +17 -0
- package/dist/perpetualDataHandler.js +26 -2
- package/dist/writeAccessHandler.d.ts +5 -0
- package/dist/writeAccessHandler.js +7 -0
- package/package.json +1 -1
- package/src/accountTrade.ts +20 -5
- package/src/brokerTool.ts +37 -17
- package/src/marketData.ts +0 -2
- package/src/nodeSDKTypes.ts +1 -2
- package/src/orderReferrerTool.ts +72 -9
- package/src/perpetualDataHandler.ts +31 -5
- package/src/writeAccessHandler.ts +8 -0
package/abi/LimitOrderBook.json
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "address",
|
|
6
|
+
"name": "_perpetualManagerAddr",
|
|
7
|
+
"type": "address"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"internalType": "uint24",
|
|
11
|
+
"name": "_perpetualId",
|
|
12
|
+
"type": "uint24"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"stateMutability": "nonpayable",
|
|
16
|
+
"type": "constructor"
|
|
17
|
+
},
|
|
2
18
|
{
|
|
3
19
|
"anonymous": false,
|
|
4
20
|
"inputs": [
|
|
@@ -486,24 +502,6 @@
|
|
|
486
502
|
"stateMutability": "view",
|
|
487
503
|
"type": "function"
|
|
488
504
|
},
|
|
489
|
-
{
|
|
490
|
-
"inputs": [
|
|
491
|
-
{
|
|
492
|
-
"internalType": "address",
|
|
493
|
-
"name": "_perpetualManagerAddr",
|
|
494
|
-
"type": "address"
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
"internalType": "uint24",
|
|
498
|
-
"name": "_perpetualId",
|
|
499
|
-
"type": "uint24"
|
|
500
|
-
}
|
|
501
|
-
],
|
|
502
|
-
"name": "initialize",
|
|
503
|
-
"outputs": [],
|
|
504
|
-
"stateMutability": "nonpayable",
|
|
505
|
-
"type": "function"
|
|
506
|
-
},
|
|
507
505
|
{
|
|
508
506
|
"inputs": [],
|
|
509
507
|
"name": "lastOrderHash",
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
[
|
|
2
|
-
{
|
|
3
|
-
"inputs": [
|
|
4
|
-
{
|
|
5
|
-
"internalType": "address",
|
|
6
|
-
"name": "_initImplementation",
|
|
7
|
-
"type": "address"
|
|
8
|
-
}
|
|
9
|
-
],
|
|
10
|
-
"stateMutability": "nonpayable",
|
|
11
|
-
"type": "constructor"
|
|
12
|
-
},
|
|
13
2
|
{
|
|
14
3
|
"anonymous": false,
|
|
15
4
|
"inputs": [
|
|
@@ -54,19 +43,6 @@
|
|
|
54
43
|
"name": "PerpetualLimitOrderBookDeployed",
|
|
55
44
|
"type": "event"
|
|
56
45
|
},
|
|
57
|
-
{
|
|
58
|
-
"inputs": [],
|
|
59
|
-
"name": "beacon",
|
|
60
|
-
"outputs": [
|
|
61
|
-
{
|
|
62
|
-
"internalType": "contract LimitOrderBookBeacon",
|
|
63
|
-
"name": "",
|
|
64
|
-
"type": "address"
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
"stateMutability": "view",
|
|
68
|
-
"type": "function"
|
|
69
|
-
},
|
|
70
46
|
{
|
|
71
47
|
"inputs": [
|
|
72
48
|
{
|
|
@@ -85,32 +61,6 @@
|
|
|
85
61
|
"stateMutability": "nonpayable",
|
|
86
62
|
"type": "function"
|
|
87
63
|
},
|
|
88
|
-
{
|
|
89
|
-
"inputs": [],
|
|
90
|
-
"name": "getBeacon",
|
|
91
|
-
"outputs": [
|
|
92
|
-
{
|
|
93
|
-
"internalType": "address",
|
|
94
|
-
"name": "",
|
|
95
|
-
"type": "address"
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
"stateMutability": "view",
|
|
99
|
-
"type": "function"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
"inputs": [],
|
|
103
|
-
"name": "getImplementation",
|
|
104
|
-
"outputs": [
|
|
105
|
-
{
|
|
106
|
-
"internalType": "address",
|
|
107
|
-
"name": "",
|
|
108
|
-
"type": "address"
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
"stateMutability": "view",
|
|
112
|
-
"type": "function"
|
|
113
|
-
},
|
|
114
64
|
{
|
|
115
65
|
"inputs": [
|
|
116
66
|
{
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"proxyAddr": "0x44Ae67695781209ace41c422dCfD29d3C678AF68",
|
|
4
4
|
"nodeURL": "https://rpc-mumbai.maticvigil.com/",
|
|
5
5
|
"proxyABILocation": "../abi/IPerpetualManager.json",
|
|
6
|
-
"limitOrderBookFactoryAddr": "
|
|
6
|
+
"limitOrderBookFactoryAddr": "0x5D9Af75B450be534d57106c817145f4E373069cb",
|
|
7
7
|
"limitOrderBookFactoryABILocation": "../abi/LimitOrderBookFactory.json",
|
|
8
8
|
"limitOrderBookABILocation": "../abi/LimitOrderBook.json"
|
|
9
9
|
}
|
package/dist/accountTrade.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
37
37
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
38
38
|
* async function main() {
|
|
39
39
|
* console.log(AccountTrade);
|
|
40
|
-
* //
|
|
40
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
41
41
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
42
42
|
* const pk: string = <string>process.env.PK;
|
|
43
43
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -59,7 +59,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
59
59
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
60
60
|
* async function main() {
|
|
61
61
|
* console.log(AccountTrade);
|
|
62
|
-
* //
|
|
62
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
63
63
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
64
64
|
* const pk: string = <string>process.env.PK;
|
|
65
65
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -84,7 +84,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
84
84
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
85
85
|
* async function main() {
|
|
86
86
|
* console.log(AccountTrade);
|
|
87
|
-
* //
|
|
87
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
88
88
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
89
89
|
* const pk: string = <string>process.env.PK;
|
|
90
90
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -121,7 +121,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
121
121
|
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
122
122
|
* async function main() {
|
|
123
123
|
* console.log(AccountTrade);
|
|
124
|
-
* //
|
|
124
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
125
125
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
126
126
|
* const pk: string = <string>process.env.PK;
|
|
127
127
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -143,7 +143,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
143
143
|
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
144
144
|
* async function main() {
|
|
145
145
|
* console.log(AccountTrade);
|
|
146
|
-
* //
|
|
146
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
147
147
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
148
148
|
* const pk: string = <string>process.env.PK;
|
|
149
149
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -160,6 +160,21 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
160
160
|
/**
|
|
161
161
|
*
|
|
162
162
|
* @param symbol Symbol of the form ETH-USD-MATIC.
|
|
163
|
+
* @example
|
|
164
|
+
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
165
|
+
* async function main() {
|
|
166
|
+
* console.log(AccountTrade);
|
|
167
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
168
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
169
|
+
* const pk: string = <string>process.env.PK;
|
|
170
|
+
* let accTrade = new AccountTrade(config, pk);
|
|
171
|
+
* await accTrade.createProxyInstance();
|
|
172
|
+
* // get order IDs
|
|
173
|
+
* let orderIds = await accTrade.getOrderIds("MATIC-USD-MATIC");
|
|
174
|
+
* console.log(orderIds);
|
|
175
|
+
* }
|
|
176
|
+
* main();
|
|
177
|
+
*
|
|
163
178
|
* @returns {string[]} Array of Ids for all the orders currently open by this trader.
|
|
164
179
|
*/
|
|
165
180
|
getOrderIds(symbol: string): Promise<string[]>;
|
package/dist/accountTrade.js
CHANGED
|
@@ -56,7 +56,7 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
56
56
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
57
57
|
* async function main() {
|
|
58
58
|
* console.log(AccountTrade);
|
|
59
|
-
* //
|
|
59
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
60
60
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
61
61
|
* const pk: string = <string>process.env.PK;
|
|
62
62
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -92,7 +92,7 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
92
92
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
93
93
|
* async function main() {
|
|
94
94
|
* console.log(AccountTrade);
|
|
95
|
-
* //
|
|
95
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
96
96
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
97
97
|
* const pk: string = <string>process.env.PK;
|
|
98
98
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -117,7 +117,7 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
117
117
|
* import { AccountTrade, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
118
118
|
* async function main() {
|
|
119
119
|
* console.log(AccountTrade);
|
|
120
|
-
* //
|
|
120
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
121
121
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
122
122
|
* const pk: string = <string>process.env.PK;
|
|
123
123
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -169,7 +169,7 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
169
169
|
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
170
170
|
* async function main() {
|
|
171
171
|
* console.log(AccountTrade);
|
|
172
|
-
* //
|
|
172
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
173
173
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
174
174
|
* const pk: string = <string>process.env.PK;
|
|
175
175
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -203,7 +203,7 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
203
203
|
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
204
204
|
* async function main() {
|
|
205
205
|
* console.log(AccountTrade);
|
|
206
|
-
* //
|
|
206
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
207
207
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
208
208
|
* const pk: string = <string>process.env.PK;
|
|
209
209
|
* let accTrade = new AccountTrade(config, pk);
|
|
@@ -229,6 +229,21 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
229
229
|
/**
|
|
230
230
|
*
|
|
231
231
|
* @param symbol Symbol of the form ETH-USD-MATIC.
|
|
232
|
+
* @example
|
|
233
|
+
* import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
234
|
+
* async function main() {
|
|
235
|
+
* console.log(AccountTrade);
|
|
236
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
237
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
238
|
+
* const pk: string = <string>process.env.PK;
|
|
239
|
+
* let accTrade = new AccountTrade(config, pk);
|
|
240
|
+
* await accTrade.createProxyInstance();
|
|
241
|
+
* // get order IDs
|
|
242
|
+
* let orderIds = await accTrade.getOrderIds("MATIC-USD-MATIC");
|
|
243
|
+
* console.log(orderIds);
|
|
244
|
+
* }
|
|
245
|
+
* main();
|
|
246
|
+
*
|
|
232
247
|
* @returns {string[]} Array of Ids for all the orders currently open by this trader.
|
|
233
248
|
*/
|
|
234
249
|
getOrderIds(symbol) {
|
package/dist/brokerTool.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WriteAccessHandler from "./writeAccessHandler";
|
|
2
|
-
import { NodeSDKConfig, Order
|
|
3
|
-
import {
|
|
2
|
+
import { NodeSDKConfig, Order } from "./nodeSDKTypes";
|
|
3
|
+
import { ethers } from "ethers";
|
|
4
4
|
/**
|
|
5
5
|
* Functions for brokers to determine fees, deposit lots, and sign-up traders.
|
|
6
6
|
* This class requires a private key and executes smart-contract interactions that
|
|
@@ -37,7 +37,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
37
37
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
38
38
|
* async function main() {
|
|
39
39
|
* console.log(BrokerTool);
|
|
40
|
-
* //
|
|
40
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
41
41
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
42
42
|
* const pk: string = <string>process.env.PK;
|
|
43
43
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -61,7 +61,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
61
61
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
62
62
|
* async function main() {
|
|
63
63
|
* console.log(BrokerTool);
|
|
64
|
-
* //
|
|
64
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
65
65
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
66
66
|
* const pk: string = <string>process.env.PK;
|
|
67
67
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -84,7 +84,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
84
84
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
85
85
|
* async function main() {
|
|
86
86
|
* console.log(BrokerTool);
|
|
87
|
-
* //
|
|
87
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
88
88
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
89
89
|
* const pk: string = <string>process.env.PK;
|
|
90
90
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -107,7 +107,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
107
107
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
108
108
|
* async function main() {
|
|
109
109
|
* console.log(BrokerTool);
|
|
110
|
-
* //
|
|
110
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
111
111
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
112
112
|
* const pk: string = <string>process.env.PK;
|
|
113
113
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -132,21 +132,22 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
132
132
|
* specify symbol, side, type and quantity.
|
|
133
133
|
* @param {string} traderAddr Address of the trader for whom to determine the fee.
|
|
134
134
|
* @example
|
|
135
|
-
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
135
|
+
* import { BrokerTool, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
136
136
|
* async function main() {
|
|
137
137
|
* console.log(BrokerTool);
|
|
138
|
-
* //
|
|
138
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
139
139
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
140
140
|
* const pk: string = <string>process.env.PK;
|
|
141
141
|
* let brokTool = new BrokerTool(config, pk);
|
|
142
142
|
* await brokTool.createProxyInstance();
|
|
143
143
|
* // get exchange fee based on an order and trader
|
|
144
|
-
* let order = {
|
|
144
|
+
* let order: Order = {
|
|
145
|
+
* symbol: "MATIC-USD-MATIC",
|
|
145
146
|
* side: "BUY",
|
|
146
147
|
* type: "MARKET",
|
|
147
|
-
* quantity:
|
|
148
|
+
* quantity: 100,
|
|
148
149
|
* timestamp: Date.now()
|
|
149
|
-
*
|
|
150
|
+
* };
|
|
150
151
|
* let exchFee = await brokTool.determineExchangeFee(order,
|
|
151
152
|
* "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
|
|
152
153
|
* console.log(exchFee);
|
|
@@ -164,7 +165,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
164
165
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
165
166
|
* async function main() {
|
|
166
167
|
* console.log(BrokerTool);
|
|
167
|
-
* //
|
|
168
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
168
169
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
169
170
|
* const pk: string = <string>process.env.PK;
|
|
170
171
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -186,7 +187,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
186
187
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
187
188
|
* async function main() {
|
|
188
189
|
* console.log(BrokerTool);
|
|
189
|
-
* //
|
|
190
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
190
191
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
191
192
|
* const pk: string = <string>process.env.PK;
|
|
192
193
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -208,7 +209,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
208
209
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
209
210
|
* async function main() {
|
|
210
211
|
* console.log(BrokerTool);
|
|
211
|
-
* //
|
|
212
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
212
213
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
213
214
|
* const pk: string = <string>process.env.PK;
|
|
214
215
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -230,7 +231,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
230
231
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
231
232
|
* async function main() {
|
|
232
233
|
* console.log(BrokerTool);
|
|
233
|
-
* //
|
|
234
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
234
235
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
235
236
|
* const pk: string = <string>process.env.PK;
|
|
236
237
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -257,7 +258,7 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
257
258
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
258
259
|
* async function main() {
|
|
259
260
|
* console.log(BrokerTool);
|
|
260
|
-
* //
|
|
261
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
261
262
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
262
263
|
* const pk: string = <string>process.env.PK;
|
|
263
264
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -272,6 +273,9 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
272
273
|
* let signedOrder = await brokTool.signOrder(order, "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
273
274
|
* 0.0001, 1669723339);
|
|
274
275
|
* console.log(signedOrder);
|
|
276
|
+
* // execute order
|
|
277
|
+
* let orderTransaction = await accTrade.order(signedOrder);
|
|
278
|
+
* console.log(orderTransaction.hash);
|
|
275
279
|
* }
|
|
276
280
|
* main();
|
|
277
281
|
*
|
|
@@ -289,13 +293,28 @@ export default class BrokerTool extends WriteAccessHandler {
|
|
|
289
293
|
* @ignore
|
|
290
294
|
*/
|
|
291
295
|
createSignatureForTrader(traderAddr: string, symbol: string, brokerFee: number, deadline: number): Promise<string>;
|
|
292
|
-
static _signOrder
|
|
296
|
+
private static _signOrder;
|
|
293
297
|
/**
|
|
294
298
|
* Transfer ownership of a broker's status to a new wallet. This function transfers the values related to
|
|
295
299
|
* (i) trading volume and (ii) deposited lots to newAddress. The broker needs in addition to manually transfer
|
|
296
300
|
* his D8X holdings to newAddress. Until this transfer is completed, the broker will not have his current designation reflected at newAddress.
|
|
297
301
|
* @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
|
|
298
302
|
* @param {string} newAddress The address this broker wants to use from now on.
|
|
303
|
+
* @example
|
|
304
|
+
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
305
|
+
* async function main() {
|
|
306
|
+
* console.log(BrokerTool);
|
|
307
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
308
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
309
|
+
* const pk: string = <string>process.env.PK;
|
|
310
|
+
* let brokTool = new BrokerTool(config, pk);
|
|
311
|
+
* await brokTool.createProxyInstance();
|
|
312
|
+
* // transfer ownership
|
|
313
|
+
* let respTransferOwnership = await brokTool.transferOwnership("MATIC", "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
|
|
314
|
+
* console.log(respTransferOwnership);
|
|
315
|
+
* }
|
|
316
|
+
* main();
|
|
317
|
+
*
|
|
299
318
|
* @returns {ethers.providers.TransactionResponse} ethers transaction object
|
|
300
319
|
*/
|
|
301
320
|
transferOwnership(poolSymbolName: string, newAddress: string): Promise<ethers.providers.TransactionResponse>;
|
package/dist/brokerTool.js
CHANGED
|
@@ -56,7 +56,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
56
56
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
57
57
|
* async function main() {
|
|
58
58
|
* console.log(BrokerTool);
|
|
59
|
-
* //
|
|
59
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
60
60
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
61
61
|
* const pk: string = <string>process.env.PK;
|
|
62
62
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -93,7 +93,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
93
93
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
94
94
|
* async function main() {
|
|
95
95
|
* console.log(BrokerTool);
|
|
96
|
-
* //
|
|
96
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
97
97
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
98
98
|
* const pk: string = <string>process.env.PK;
|
|
99
99
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -115,6 +115,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
115
115
|
let brokerDesignation;
|
|
116
116
|
if (typeof lots == "undefined") {
|
|
117
117
|
brokerDesignation = yield this.getBrokerDesignation(poolSymbolName);
|
|
118
|
+
brokerDesignation = brokerDesignation > 0 ? brokerDesignation : 0;
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
121
|
brokerDesignation = lots;
|
|
@@ -132,7 +133,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
132
133
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
133
134
|
* async function main() {
|
|
134
135
|
* console.log(BrokerTool);
|
|
135
|
-
* //
|
|
136
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
136
137
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
137
138
|
* const pk: string = <string>process.env.PK;
|
|
138
139
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -164,7 +165,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
164
165
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
165
166
|
* async function main() {
|
|
166
167
|
* console.log(BrokerTool);
|
|
167
|
-
* //
|
|
168
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
168
169
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
169
170
|
* const pk: string = <string>process.env.PK;
|
|
170
171
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -200,21 +201,22 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
200
201
|
* specify symbol, side, type and quantity.
|
|
201
202
|
* @param {string} traderAddr Address of the trader for whom to determine the fee.
|
|
202
203
|
* @example
|
|
203
|
-
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
204
|
+
* import { BrokerTool, PerpetualDataHandler, Order } from '@d8x/perpetuals-sdk';
|
|
204
205
|
* async function main() {
|
|
205
206
|
* console.log(BrokerTool);
|
|
206
|
-
* //
|
|
207
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
207
208
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
208
209
|
* const pk: string = <string>process.env.PK;
|
|
209
210
|
* let brokTool = new BrokerTool(config, pk);
|
|
210
211
|
* await brokTool.createProxyInstance();
|
|
211
212
|
* // get exchange fee based on an order and trader
|
|
212
|
-
* let order = {
|
|
213
|
+
* let order: Order = {
|
|
214
|
+
* symbol: "MATIC-USD-MATIC",
|
|
213
215
|
* side: "BUY",
|
|
214
216
|
* type: "MARKET",
|
|
215
|
-
* quantity:
|
|
217
|
+
* quantity: 100,
|
|
216
218
|
* timestamp: Date.now()
|
|
217
|
-
*
|
|
219
|
+
* };
|
|
218
220
|
* let exchFee = await brokTool.determineExchangeFee(order,
|
|
219
221
|
* "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
|
|
220
222
|
* console.log(exchFee);
|
|
@@ -242,7 +244,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
242
244
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
243
245
|
* async function main() {
|
|
244
246
|
* console.log(BrokerTool);
|
|
245
|
-
* //
|
|
247
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
246
248
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
247
249
|
* const pk: string = <string>process.env.PK;
|
|
248
250
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -274,7 +276,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
274
276
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
275
277
|
* async function main() {
|
|
276
278
|
* console.log(BrokerTool);
|
|
277
|
-
* //
|
|
279
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
278
280
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
279
281
|
* const pk: string = <string>process.env.PK;
|
|
280
282
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -306,7 +308,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
306
308
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
307
309
|
* async function main() {
|
|
308
310
|
* console.log(BrokerTool);
|
|
309
|
-
* //
|
|
311
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
310
312
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
311
313
|
* const pk: string = <string>process.env.PK;
|
|
312
314
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -337,7 +339,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
337
339
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
338
340
|
* async function main() {
|
|
339
341
|
* console.log(BrokerTool);
|
|
340
|
-
* //
|
|
342
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
341
343
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
342
344
|
* const pk: string = <string>process.env.PK;
|
|
343
345
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -374,7 +376,7 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
374
376
|
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
375
377
|
* async function main() {
|
|
376
378
|
* console.log(BrokerTool);
|
|
377
|
-
* //
|
|
379
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
378
380
|
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
379
381
|
* const pk: string = <string>process.env.PK;
|
|
380
382
|
* let brokTool = new BrokerTool(config, pk);
|
|
@@ -389,6 +391,9 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
389
391
|
* let signedOrder = await brokTool.signOrder(order, "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
|
|
390
392
|
* 0.0001, 1669723339);
|
|
391
393
|
* console.log(signedOrder);
|
|
394
|
+
* // execute order
|
|
395
|
+
* let orderTransaction = await accTrade.order(signedOrder);
|
|
396
|
+
* console.log(orderTransaction.hash);
|
|
392
397
|
* }
|
|
393
398
|
* main();
|
|
394
399
|
*
|
|
@@ -401,8 +406,8 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
401
406
|
}
|
|
402
407
|
order.brokerAddr = this.traderAddr;
|
|
403
408
|
order.brokerFeeTbps = brokerFee * 100000;
|
|
404
|
-
order.deadline = deadline;
|
|
405
|
-
order.brokerSignature = yield BrokerTool._signOrder(order.symbol, order.brokerFeeTbps, traderAddr, ethers_1.BigNumber.from(deadline), this.signer, this.chainId, this.proxyAddr, this.symbolToPerpStaticInfo);
|
|
409
|
+
order.deadline = Math.round(deadline);
|
|
410
|
+
order.brokerSignature = yield BrokerTool._signOrder(order.symbol, order.brokerFeeTbps, traderAddr, ethers_1.BigNumber.from(Math.round(deadline)), this.signer, this.chainId, this.proxyAddr, this.symbolToPerpStaticInfo);
|
|
406
411
|
return order;
|
|
407
412
|
});
|
|
408
413
|
}
|
|
@@ -448,6 +453,21 @@ class BrokerTool extends writeAccessHandler_1.default {
|
|
|
448
453
|
* his D8X holdings to newAddress. Until this transfer is completed, the broker will not have his current designation reflected at newAddress.
|
|
449
454
|
* @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
|
|
450
455
|
* @param {string} newAddress The address this broker wants to use from now on.
|
|
456
|
+
* @example
|
|
457
|
+
* import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
458
|
+
* async function main() {
|
|
459
|
+
* console.log(BrokerTool);
|
|
460
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
461
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
462
|
+
* const pk: string = <string>process.env.PK;
|
|
463
|
+
* let brokTool = new BrokerTool(config, pk);
|
|
464
|
+
* await brokTool.createProxyInstance();
|
|
465
|
+
* // transfer ownership
|
|
466
|
+
* let respTransferOwnership = await brokTool.transferOwnership("MATIC", "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
|
|
467
|
+
* console.log(respTransferOwnership);
|
|
468
|
+
* }
|
|
469
|
+
* main();
|
|
470
|
+
*
|
|
451
471
|
* @returns {ethers.providers.TransactionResponse} ethers transaction object
|
|
452
472
|
*/
|
|
453
473
|
transferOwnership(poolSymbolName, newAddress) {
|
package/dist/marketData.js
CHANGED
|
@@ -346,8 +346,6 @@ class MarketData extends perpetualDataHandler_1.default {
|
|
|
346
346
|
collToQuoteIndexPrice: indexS3,
|
|
347
347
|
markPrice: indexS2 * (1 + markPremiumRate),
|
|
348
348
|
currentFundingRateBps: currentFundingRateBps,
|
|
349
|
-
initialMarginRate: (0, d8XMath_1.ABK64x64ToFloat)(perp.fInitialMarginRate),
|
|
350
|
-
maintenanceMarginRate: (0, d8XMath_1.ABK64x64ToFloat)(perp.fMaintenanceMarginRate),
|
|
351
349
|
openInterestBC: (0, d8XMath_1.ABK64x64ToFloat)(perp.fOpenInterest),
|
|
352
350
|
maxPositionBC: (0, d8XMath_1.ABK64x64ToFloat)(perp.fMaxPositionBC),
|
|
353
351
|
};
|
package/dist/nodeSDKTypes.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ export interface PoolStaticInfo {
|
|
|
65
65
|
export interface PerpetualStaticInfo {
|
|
66
66
|
id: number;
|
|
67
67
|
limitOrderBookAddr: string;
|
|
68
|
+
initialMarginRate: number;
|
|
68
69
|
maintenanceMarginRate: number;
|
|
69
70
|
collateralCurrencyType: CollaterlCCY;
|
|
70
71
|
S2Symbol: string;
|
|
@@ -116,8 +117,6 @@ export interface PerpetualState {
|
|
|
116
117
|
collToQuoteIndexPrice: number;
|
|
117
118
|
markPrice: number;
|
|
118
119
|
currentFundingRateBps: number;
|
|
119
|
-
initialMarginRate: number;
|
|
120
|
-
maintenanceMarginRate: number;
|
|
121
120
|
openInterestBC: number;
|
|
122
121
|
maxPositionBC: number;
|
|
123
122
|
}
|