@d8x/perpetuals-sdk 0.0.7 → 0.0.9

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v1.1",
3
- "proxyAddr": "0x51b05809eF1E84BB963D84ff95FB5E625d88152d",
3
+ "proxyAddr": "0xB90C23f690F355BBA119c1BD070B08CB4cbEAa58",
4
4
  "nodeURL": "https://rpc-mumbai.maticvigil.com/",
5
5
  "proxyABILocation": "../abi/IPerpetualManager.json",
6
6
  "limitOrderBookFactoryAddr": "0x92B6967Ea9b6A0375013649dBd3d0CD9DceeEf4d",
@@ -9,7 +9,22 @@ import WriteAccessHandler from "./writeAccessHandler";
9
9
  export default class AccountTrade extends WriteAccessHandler {
10
10
  /**
11
11
  * Constructor
12
- * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.readSDKConfig.
12
+ * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.
13
+ * readSDKConfig.
14
+ * @example
15
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
16
+ * async function main() {
17
+ * console.log(AccountTrade);
18
+ * // load configuration for testnet
19
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
20
+ * // AccountTrade (authentication required, PK is an environment variable with a private key)
21
+ * const pk: string = <string>process.env.PK;
22
+ * let accTrade = new AccountTrade(config, pk);
23
+ * // Create a proxy instance to access the blockchain
24
+ * await accTrade.createProxyInstance();
25
+ * }
26
+ * main();
27
+ *
13
28
  * @param {string} privateKey Private key of account that trades.
14
29
  */
15
30
  constructor(config: NodeSDKConfig, privateKey: string);
@@ -21,10 +36,19 @@ export default class AccountTrade extends WriteAccessHandler {
21
36
  cancelOrder(symbol: string, orderId: string): Promise<string | undefined>;
22
37
  /**
23
38
  * Submits an order to the exchange.
24
- * @param {Order} order Order struct.
25
- * @returns {string} Transaction hash.
39
+ * @param {Order} order Order structure. As a minimum the structure needs to
40
+ * specify symbol, side, type and quantity.
41
+ * @example
42
+ * let order: Order = {
43
+ * symbol: "MATIC-USD-MATIC",
44
+ * side: "BUY",
45
+ * type: "MARKET",
46
+ * quantity: 1,
47
+ * }
48
+ *
49
+ * @returns {ContractTransaction} Contract Transaction (containing events).
26
50
  */
27
- order(order: Order): Promise<string | undefined>;
51
+ order(order: Order): Promise<ethers.ContractTransaction>;
28
52
  /**
29
53
  * Fee charged by the exchange for trading any perpetual on a given pool.
30
54
  * It accounts for the current trader's fee tier (based on the trader's D8X balance and trading volume).
@@ -32,6 +56,21 @@ export default class AccountTrade extends WriteAccessHandler {
32
56
  * Note that this result only includes exchange fees, additional broker fees are not included.
33
57
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
34
58
  * @param {string=} brokerAddr Optional address of a broker this trader may use to trade under.
59
+ * @example
60
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
61
+ * async function main() {
62
+ * console.log(AccountTrade);
63
+ * // Setup (authentication required, PK is an environment variable with a private key)
64
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
65
+ * const pk: string = <string>process.env.PK;
66
+ * let accTrade = new AccountTrade(config, pk);
67
+ * await accTrade.createProxyInstance();
68
+ * // query exchange fee
69
+ * let fees = await accTrade.queryExchangeFee("MATIC");
70
+ * console.log(fees);
71
+ * }
72
+ * main();
73
+ *
35
74
  * @returns Exchange fee, in decimals (i.e. 0.1% is 0.001).
36
75
  */
37
76
  queryExchangeFee(poolSymbolName: string, brokerAddr?: string): Promise<number>;
@@ -39,9 +78,30 @@ export default class AccountTrade extends WriteAccessHandler {
39
78
  * Exponentially weighted EMA of the total trading volume of all trades performed by this trader.
40
79
  * The weights are chosen so that in average this coincides with the 30 day volume.
41
80
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
81
+ * @example
82
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
83
+ * async function main() {
84
+ * console.log(AccountTrade);
85
+ * // Setup (authentication required, PK is an environment variable with a private key)
86
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
87
+ * const pk: string = <string>process.env.PK;
88
+ * let accTrade = new AccountTrade(config, pk);
89
+ * await accTrade.createProxyInstance();
90
+ * // query 30 day volume
91
+ * let vol = await accTrade.getCurrentTraderVolume("MATIC");
92
+ * console.log(vol);
93
+ * }
94
+ * main();
95
+ *
42
96
  * @returns {number} Current trading volume for this trader, in USD.
43
97
  */
44
98
  getCurrentTraderVolume(poolSymbolName: string): Promise<number>;
99
+ /**
100
+ *
101
+ * @param symbol Symbol of the form ETH-USD-MATIC.
102
+ * @returns {string[]} Array of Ids for all the orders currently open by this trader.
103
+ */
104
+ getOrderIds(symbol: string): Promise<string[]>;
45
105
  /**
46
106
  * Static order function
47
107
  * @param order order type (not SmartContractOrder but Order)
@@ -55,7 +115,7 @@ export default class AccountTrade extends WriteAccessHandler {
55
115
  * @returns transaction hash
56
116
  * @ignore
57
117
  */
58
- _order(order: Order, traderAddr: string, symbolToPerpetualMap: Map<string, PerpetualStaticInfo>, proxyContract: ethers.Contract, orderBookContract: ethers.Contract | null, chainId: number, signer: ethers.Wallet, gasLimit: number): Promise<string | undefined>;
118
+ _order(order: Order, traderAddr: string, symbolToPerpetualMap: Map<string, PerpetualStaticInfo>, proxyContract: ethers.Contract, orderBookContract: ethers.Contract | null, chainId: number, signer: ethers.Wallet, gasLimit: number): Promise<ethers.ContractTransaction>;
59
119
  protected _cancelOrder(symbol: string, orderId: string, orderBookContract: ethers.Contract | null): Promise<string | undefined>;
60
120
  /**
61
121
  * Creates a signature
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ethers_1 = require("ethers");
16
16
  const d8XMath_1 = require("./d8XMath");
17
+ const marketData_1 = __importDefault(require("./marketData"));
17
18
  const nodeSDKTypes_1 = require("./nodeSDKTypes");
18
19
  const writeAccessHandler_1 = __importDefault(require("./writeAccessHandler"));
19
20
  /**
@@ -24,7 +25,22 @@ const writeAccessHandler_1 = __importDefault(require("./writeAccessHandler"));
24
25
  class AccountTrade extends writeAccessHandler_1.default {
25
26
  /**
26
27
  * Constructor
27
- * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.readSDKConfig.
28
+ * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.
29
+ * readSDKConfig.
30
+ * @example
31
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
32
+ * async function main() {
33
+ * console.log(AccountTrade);
34
+ * // load configuration for testnet
35
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
36
+ * // AccountTrade (authentication required, PK is an environment variable with a private key)
37
+ * const pk: string = <string>process.env.PK;
38
+ * let accTrade = new AccountTrade(config, pk);
39
+ * // Create a proxy instance to access the blockchain
40
+ * await accTrade.createProxyInstance();
41
+ * }
42
+ * main();
43
+ *
28
44
  * @param {string} privateKey Private key of account that trades.
29
45
  */
30
46
  constructor(config, privateKey) {
@@ -52,8 +68,17 @@ class AccountTrade extends writeAccessHandler_1.default {
52
68
  */
53
69
  /**
54
70
  * Submits an order to the exchange.
55
- * @param {Order} order Order struct.
56
- * @returns {string} Transaction hash.
71
+ * @param {Order} order Order structure. As a minimum the structure needs to
72
+ * specify symbol, side, type and quantity.
73
+ * @example
74
+ * let order: Order = {
75
+ * symbol: "MATIC-USD-MATIC",
76
+ * side: "BUY",
77
+ * type: "MARKET",
78
+ * quantity: 1,
79
+ * }
80
+ *
81
+ * @returns {ContractTransaction} Contract Transaction (containing events).
57
82
  */
58
83
  order(order) {
59
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -74,6 +99,21 @@ class AccountTrade extends writeAccessHandler_1.default {
74
99
  * Note that this result only includes exchange fees, additional broker fees are not included.
75
100
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
76
101
  * @param {string=} brokerAddr Optional address of a broker this trader may use to trade under.
102
+ * @example
103
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
104
+ * async function main() {
105
+ * console.log(AccountTrade);
106
+ * // Setup (authentication required, PK is an environment variable with a private key)
107
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
108
+ * const pk: string = <string>process.env.PK;
109
+ * let accTrade = new AccountTrade(config, pk);
110
+ * await accTrade.createProxyInstance();
111
+ * // query exchange fee
112
+ * let fees = await accTrade.queryExchangeFee("MATIC");
113
+ * console.log(fees);
114
+ * }
115
+ * main();
116
+ *
77
117
  * @returns Exchange fee, in decimals (i.e. 0.1% is 0.001).
78
118
  */
79
119
  queryExchangeFee(poolSymbolName, brokerAddr) {
@@ -93,6 +133,21 @@ class AccountTrade extends writeAccessHandler_1.default {
93
133
  * Exponentially weighted EMA of the total trading volume of all trades performed by this trader.
94
134
  * The weights are chosen so that in average this coincides with the 30 day volume.
95
135
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
136
+ * @example
137
+ * import { AccountTrade, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
138
+ * async function main() {
139
+ * console.log(AccountTrade);
140
+ * // Setup (authentication required, PK is an environment variable with a private key)
141
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
142
+ * const pk: string = <string>process.env.PK;
143
+ * let accTrade = new AccountTrade(config, pk);
144
+ * await accTrade.createProxyInstance();
145
+ * // query 30 day volume
146
+ * let vol = await accTrade.getCurrentTraderVolume("MATIC");
147
+ * console.log(vol);
148
+ * }
149
+ * main();
150
+ *
96
151
  * @returns {number} Current trading volume for this trader, in USD.
97
152
  */
98
153
  getCurrentTraderVolume(poolSymbolName) {
@@ -105,6 +160,20 @@ class AccountTrade extends writeAccessHandler_1.default {
105
160
  return (0, d8XMath_1.ABK64x64ToFloat)(volume);
106
161
  });
107
162
  }
163
+ /**
164
+ *
165
+ * @param symbol Symbol of the form ETH-USD-MATIC.
166
+ * @returns {string[]} Array of Ids for all the orders currently open by this trader.
167
+ */
168
+ getOrderIds(symbol) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ if (this.proxyContract == null || this.signer == null) {
171
+ throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
172
+ }
173
+ let orderBookContract = this.getOrderBookContract(symbol);
174
+ return yield marketData_1.default.orderIdsOfTrader(this.traderAddr, orderBookContract);
175
+ });
176
+ }
108
177
  /**
109
178
  * Static order function
110
179
  * @param order order type (not SmartContractOrder but Order)
@@ -136,7 +205,7 @@ class AccountTrade extends writeAccessHandler_1.default {
136
205
  let signature = yield this._createSignature(scOrder, chainId, true, signer, proxyContract.address);
137
206
  tx = yield orderBookContract.createLimitOrder(scOrder, signature, { gasLimit: gasLimit });
138
207
  }
139
- return tx.hash;
208
+ return tx;
140
209
  });
141
210
  }
142
211
  _cancelOrder(symbol, orderId, orderBookContract) {
@@ -3,43 +3,120 @@ import { NodeSDKConfig, Order, PerpetualStaticInfo } from "./nodeSDKTypes";
3
3
  import { BigNumber, ethers } from "ethers";
4
4
  /**
5
5
  * Functions for brokers to determine fees, deposit lots, and sign-up traders.
6
+ * This class requires a private key and executes smart-contract interactions that
7
+ * require gas-payments.
6
8
  */
7
9
  export default class BrokerTool extends WriteAccessHandler {
8
10
  /**
9
11
  * Constructor
10
- * @param {NodeSDKConfig} config Configuration object.
12
+ * @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.
13
+ * readSDKConfig.
14
+ * @example
15
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
16
+ * async function main() {
17
+ * console.log(BrokerTool);
18
+ * // load configuration for testnet
19
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
20
+ * // BrokerTool (authentication required, PK is an environment variable with a private key)
21
+ * const pk: string = <string>process.env.PK;
22
+ * let brokTool = new BrokerTool(config, pk);
23
+ * // Create a proxy instance to access the blockchain
24
+ * await brokTool.createProxyInstance();
25
+ * }
26
+ * main();
27
+ *
11
28
  * @param {string} privateKey Private key of a broker.
12
29
  */
13
30
  constructor(config: NodeSDKConfig, privateKey: string);
14
31
  /**
15
32
  * Determine the exchange fee based on lots, traded volume, and D8X balance of this broker.
16
- * This is the final exchange fee paid by the broker.
33
+ * This is the final exchange fee that this broker can offer to traders that trade through him.
17
34
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
35
+ * @example
36
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
37
+ * async function main() {
38
+ * console.log(BrokerTool);
39
+ * // Setup (authentication required, PK is an environment variable with a private key)
40
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
41
+ * const pk: string = <string>process.env.PK;
42
+ * let brokTool = new BrokerTool(config, pk);
43
+ * await brokTool.createProxyInstance();
44
+ * // get broker induced fee
45
+ * let brokFee = await brokTool.getBrokerInducedFee("MATIC");
46
+ * console.log(brokFee);
47
+ * }
48
+ * main();
49
+ *
18
50
  * @returns {number} Exchange fee for this broker, in decimals (i.e. 0.1% is 0.001)
19
51
  */
20
52
  getBrokerInducedFee(poolSymbolName: string): Promise<number>;
21
53
  /**
22
54
  * Determine the exchange fee based on lots purchased by this broker.
23
- * The final exchange fee paid by the broker is equal to
55
+ * The final exchange fee that this broker can offer to traders that trade through him is equal to
24
56
  * maximum(brokerTool.getFeeForBrokerDesignation(poolSymbolName), brokerTool.getFeeForBrokerVolume(poolSymbolName), brokerTool.getFeeForBrokerStake())
25
57
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
26
58
  * @param {number=} lots Optional, designation to use if different from this broker's.
59
+ * @example
60
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
61
+ * async function main() {
62
+ * console.log(BrokerTool);
63
+ * // Setup (authentication required, PK is an environment variable with a private key)
64
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
65
+ * const pk: string = <string>process.env.PK;
66
+ * let brokTool = new BrokerTool(config, pk);
67
+ * await brokTool.createProxyInstance();
68
+ * // get broker fee induced by lots
69
+ * let brokFeeLots = await brokTool.getFeeForBrokerDesignation("MATIC");
70
+ * console.log(brokFeeLots);
71
+ * }
72
+ * main();
73
+ *
27
74
  * @returns {number} Fee based solely on this broker's designation, in decimals (i.e. 0.1% is 0.001).
28
75
  */
29
76
  getFeeForBrokerDesignation(poolSymbolName: string, lots?: number): Promise<number>;
30
77
  /**
31
78
  * Determine the exchange fee based on volume traded under this broker.
32
- * The final exchange fee paid by the broker is equal to
79
+ * The final exchange fee that this broker can offer to traders that trade through him is equal to
33
80
  * maximum(brokerTool.getFeeForBrokerDesignation(poolSymbolName), brokerTool.getFeeForBrokerVolume(poolSymbolName), brokerTool.getFeeForBrokerStake())
34
81
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
82
+ * @example
83
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
84
+ * async function main() {
85
+ * console.log(BrokerTool);
86
+ * // Setup (authentication required, PK is an environment variable with a private key)
87
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
88
+ * const pk: string = <string>process.env.PK;
89
+ * let brokTool = new BrokerTool(config, pk);
90
+ * await brokTool.createProxyInstance();
91
+ * // get broker fee induced by volume
92
+ * let brokFeeVol = await brokTool.getFeeForBrokerVolume("MATIC");
93
+ * console.log(brokFeeVol);
94
+ * }
95
+ * main();
96
+ *
35
97
  * @returns {number} Fee based solely on a broker's traded volume in the corresponding pool, in decimals (i.e. 0.1% is 0.001).
36
98
  */
37
- getFeeForBrokerVolume(poolSymbolName: string): Promise<number | undefined>;
99
+ getFeeForBrokerVolume(poolSymbolName: string): Promise<number>;
38
100
  /**
39
101
  * Determine the exchange fee based on the current D8X balance in a broker's wallet.
40
- * The final exchange fee paid by the broker is equal to
102
+ * The final exchange fee that this broker can offer to traders that trade through him is equal to
41
103
  * maximum(brokerTool.getFeeForBrokerDesignation(symbol, lots), brokerTool.getFeeForBrokerVolume(symbol), brokerTool.getFeeForBrokerStake)
42
104
  * @param {string=} brokerAddr Address of the broker in question, if different from the one calling this function.
105
+ * @example
106
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
107
+ * async function main() {
108
+ * console.log(BrokerTool);
109
+ * // Setup (authentication required, PK is an environment variable with a private key)
110
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
111
+ * const pk: string = <string>process.env.PK;
112
+ * let brokTool = new BrokerTool(config, pk);
113
+ * await brokTool.createProxyInstance();
114
+ * // get broker fee induced by staked d8x
115
+ * let brokFeeStake = await brokTool.getFeeForBrokerStake("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
116
+ * console.log(brokFeeStake);
117
+ * }
118
+ * main();
119
+ *
43
120
  * @returns {number} Fee based solely on a broker's D8X balance, in decimals (i.e. 0.1% is 0.001).
44
121
  */
45
122
  getFeeForBrokerStake(brokerAddr?: string): Promise<number>;
@@ -50,7 +127,30 @@ export default class BrokerTool extends WriteAccessHandler {
50
127
  * Use this, for instance, to verify that the fee to be charged for a given order is as expected,
51
128
  * before and after signing it with brokerTool.signOrder.
52
129
  * This fee is equal or lower than the broker induced fee, provided the order is properly signed.
53
- * @param {Order} order Order for which to determine the exchange fee. Not necessarily signed by this broker.
130
+ * @param {Order} order Order structure. As a minimum the structure needs to
131
+ * specify symbol, side, type and quantity.
132
+ * @example
133
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
134
+ * async function main() {
135
+ * console.log(BrokerTool);
136
+ * // Setup (authentication required, PK is an environment variable with a private key)
137
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
138
+ * const pk: string = <string>process.env.PK;
139
+ * let brokTool = new BrokerTool(config, pk);
140
+ * await brokTool.createProxyInstance();
141
+ * // get exchange fee based on an order and trader
142
+ * let order = {symbol: "ETH-USD-MATIC",
143
+ * side: "BUY",
144
+ * type: "MARKET",
145
+ * quantity: 1,
146
+ * timestamp: Date.now()
147
+ * };
148
+ * let exchFee = await brokTool.determineExchangeFee(order,
149
+ * "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B");
150
+ * console.log(exchFee);
151
+ * }
152
+ * main();
153
+ *
54
154
  * @param {string} traderAddr Address of the trader for whom to determine the fee.
55
155
  * @returns {number} Fee in decimals (i.e. 0.1% is 0.001).
56
156
  */
@@ -59,6 +159,21 @@ export default class BrokerTool extends WriteAccessHandler {
59
159
  * Exponentially weighted EMA of the total trading volume of all trades performed under this broker.
60
160
  * The weights are chosen so that in average this coincides with the 30 day volume.
61
161
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
162
+ * @example
163
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
164
+ * async function main() {
165
+ * console.log(BrokerTool);
166
+ * // Setup (authentication required, PK is an environment variable with a private key)
167
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
168
+ * const pk: string = <string>process.env.PK;
169
+ * let brokTool = new BrokerTool(config, pk);
170
+ * await brokTool.createProxyInstance();
171
+ * // get 30 day volume for broker
172
+ * let brokVolume = await brokTool.getCurrentBrokerVolume("MATIC");
173
+ * console.log(brokVolume);
174
+ * }
175
+ * main();
176
+ *
62
177
  * @returns {number} Current trading volume for this broker, in USD.
63
178
  */
64
179
  getCurrentBrokerVolume(poolSymbolName: string): Promise<number>;
@@ -66,6 +181,21 @@ export default class BrokerTool extends WriteAccessHandler {
66
181
  * Total amount of collateral currency a broker has to deposit into the default fund to purchase one lot.
67
182
  * This is equivalent to the price of a lot expressed in a given pool's currency (e.g. MATIC, USDC, etc).
68
183
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
184
+ * @example
185
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
186
+ * async function main() {
187
+ * console.log(BrokerTool);
188
+ * // Setup (authentication required, PK is an environment variable with a private key)
189
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
190
+ * const pk: string = <string>process.env.PK;
191
+ * let brokTool = new BrokerTool(config, pk);
192
+ * await brokTool.createProxyInstance();
193
+ * // get lot price
194
+ * let brokLotSize = await brokTool.getLotSize("MATIC");
195
+ * console.log(brokLotSize);
196
+ * }
197
+ * main();
198
+ *
69
199
  * @returns {number} Broker lot size in a given pool's currency, e.g. in MATIC for poolSymbolName MATIC.
70
200
  */
71
201
  getLotSize(poolSymbolName: string): Promise<number>;
@@ -73,6 +203,21 @@ export default class BrokerTool extends WriteAccessHandler {
73
203
  * Provides information on how many lots a broker purchased for a given pool.
74
204
  * This is relevant to determine the broker's fee tier.
75
205
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
206
+ * @example
207
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
208
+ * async function main() {
209
+ * console.log(BrokerTool);
210
+ * // Setup (authentication required, PK is an environment variable with a private key)
211
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
212
+ * const pk: string = <string>process.env.PK;
213
+ * let brokTool = new BrokerTool(config, pk);
214
+ * await brokTool.createProxyInstance();
215
+ * // get broker designation
216
+ * let brokDesignation = await brokTool.getBrokerDesignation("MATIC");
217
+ * console.log(brokDesignation);
218
+ * }
219
+ * main();
220
+ *
76
221
  * @returns {number} Number of lots purchased by this broker.
77
222
  */
78
223
  getBrokerDesignation(poolSymbolName: string): Promise<number>;
@@ -80,15 +225,54 @@ export default class BrokerTool extends WriteAccessHandler {
80
225
  * Deposit lots to the default fund of a given pool.
81
226
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
82
227
  * @param {number} lots Number of lots to deposit into this pool.
83
- * @returns {ethers.providers.TransactionResponse} Transaction object.
228
+ * @example
229
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
230
+ * async function main() {
231
+ * console.log(BrokerTool);
232
+ * // Setup (authentication required, PK is an environment variable with a private key)
233
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
234
+ * const pk: string = <string>process.env.PK;
235
+ * let brokTool = new BrokerTool(config, pk);
236
+ * await brokTool.createProxyInstance();
237
+ * // deposit to default fund
238
+ * let respDeposit = await brokTool.brokerDepositToDefaultFund("MATIC",1);
239
+ * console.log(respDeposit);
240
+ * }
241
+ * main();
242
+ *
243
+ * @returns {ethers.ContractTransaction} ContractTransaction object.
84
244
  */
85
- brokerDepositToDefaultFund(poolSymbolName: string, lots: number): Promise<ethers.providers.TransactionResponse>;
245
+ brokerDepositToDefaultFund(poolSymbolName: string, lots: number): Promise<ethers.ContractTransaction>;
86
246
  /**
87
- * Adds this broker's signature to an order so that it can be submitted by an approved trader.
247
+ * Adds this broker's signature to an order. An order signed by a broker is considered
248
+ * to be routed through this broker and benefits from the broker's fee conditions.
88
249
  * @param {Order} order Order to sign.
89
250
  * @param {string} traderAddr Address of trader submitting the order.
90
- * @param {number} feeDecimals Fee that this broker is approving for the trader.
91
- * @param {number} deadline Deadline for the order to be executed.
251
+ * @param {number} feeDecimals Fee that this broker imposes on this order.
252
+ * The fee is sent to the broker's wallet. Fee should be specified in decimals, e.g., 0.0001 equals 1bps.
253
+ * @param {number} deadline Deadline for the order to be executed. Specify deadline as a unix timestamp
254
+ * @example
255
+ * import { BrokerTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
256
+ * async function main() {
257
+ * console.log(BrokerTool);
258
+ * // Setup (authentication required, PK is an environment variable with a private key)
259
+ * const config = PerpetualDataHandler.readSDKConfig("testnet");
260
+ * const pk: string = <string>process.env.PK;
261
+ * let brokTool = new BrokerTool(config, pk);
262
+ * await brokTool.createProxyInstance();
263
+ * // sign order
264
+ * let order = {symbol: "ETH-USD-MATIC",
265
+ * side: "BUY",
266
+ * type: "MARKET",
267
+ * quantity: 1,
268
+ * timestamp: Date.now()
269
+ * };
270
+ * let signedOrder = await brokTool.signOrder(order, "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
271
+ * 0.0001, 1669723339);
272
+ * console.log(signedOrder);
273
+ * }
274
+ * main();
275
+ *
92
276
  * @returns {Order} An order signed by this broker, which can be submitted directly with AccountTrade.order.
93
277
  */
94
278
  signOrder(order: Order, traderAddr: string, brokerFee: number, deadline: number): Promise<Order>;
@@ -105,7 +289,9 @@ export default class BrokerTool extends WriteAccessHandler {
105
289
  createSignatureForTrader(traderAddr: string, symbol: string, brokerFee: number, deadline: number): Promise<string>;
106
290
  static _signOrder(symbol: string, brokerFeeTbps: number, traderAddr: string, iDeadline: BigNumber, signer: ethers.Wallet, chainId: number, proxyAddress: string, symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>): Promise<string>;
107
291
  /**
108
- * Transfer ownership of a broker's status to a new wallet.
292
+ * Transfer ownership of a broker's status to a new wallet. This function transfers the values related to
293
+ * (i) trading volume and (ii) deposited lots to newAddress. The broker needs in addition to manually transfer
294
+ * his D8X holdings to newAddress. Until this transfer is completed, the broker will not have his current designation reflected at newAddress.
109
295
  * @param {string} poolSymbolName Pool symbol name (e.g. MATIC, USDC, etc).
110
296
  * @param {string} newAddress The address this broker wants to use from now on.
111
297
  * @returns {ethers.providers.TransactionResponse} ethers transaction object