@d8x/perpetuals-sdk 0.7.14 → 0.7.15
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/dist/cjs/traderInterface.d.ts +75 -1
- package/dist/cjs/traderInterface.js +101 -0
- package/dist/cjs/traderInterface.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/traderInterface.d.ts +75 -1
- package/dist/esm/traderInterface.js +102 -1
- package/dist/esm/traderInterface.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
- package/src/traderInterface.ts +121 -2
- package/src/version.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
2
|
+
import { CallOverrides, ContractTransaction, Overrides } from "@ethersproject/contracts";
|
|
2
3
|
import MarketData from "./marketData";
|
|
3
4
|
import { ClientOrder, NodeSDKConfig, Order, SmartContractOrder } from "./nodeSDKTypes";
|
|
4
5
|
import TraderDigests from "./traderDigests";
|
|
@@ -9,6 +10,7 @@ import TraderDigests from "./traderDigests";
|
|
|
9
10
|
*/
|
|
10
11
|
export default class TraderInterface extends MarketData {
|
|
11
12
|
digestTool: TraderDigests;
|
|
13
|
+
protected gasLimit: number;
|
|
12
14
|
/**
|
|
13
15
|
* Constructor
|
|
14
16
|
* @param {NodeSDKConfig} config Configuration object, see
|
|
@@ -77,4 +79,76 @@ export default class TraderInterface extends MarketData {
|
|
|
77
79
|
*/
|
|
78
80
|
getOrderBookABI(symbol: string, method: string): string;
|
|
79
81
|
static chainOrders(orders: SmartContractOrder[], ids: string[]): ClientOrder[];
|
|
82
|
+
/**
|
|
83
|
+
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
84
|
+
* @param {Signer} signer Signer that will deposit liquidity
|
|
85
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
86
|
+
* @param {number} amountCC Amount in pool-collateral currency
|
|
87
|
+
* @example
|
|
88
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
89
|
+
* async function main() {
|
|
90
|
+
* console.log(LiquidityProviderTool);
|
|
91
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
92
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
93
|
+
* const pk: string = <string>process.env.PK;
|
|
94
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
95
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
96
|
+
* // add liquidity
|
|
97
|
+
* await lqudtProviderTool.setAllowance("MATIC");
|
|
98
|
+
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
99
|
+
* console.log(respAddLiquidity);
|
|
100
|
+
* }
|
|
101
|
+
* main();
|
|
102
|
+
*
|
|
103
|
+
* @return Transaction object
|
|
104
|
+
*/
|
|
105
|
+
addLiquidity(signer: Signer, poolSymbolName: string, amountCC: number, overrides?: Overrides): Promise<ContractTransaction>;
|
|
106
|
+
/**
|
|
107
|
+
* Initiates a liquidity withdrawal from the pool
|
|
108
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
109
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
110
|
+
* @param {Signer} signer Signer that will initiate liquidity withdrawal
|
|
111
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
112
|
+
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
113
|
+
* @example
|
|
114
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
115
|
+
* async function main() {
|
|
116
|
+
* console.log(LiquidityProviderTool);
|
|
117
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
118
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
119
|
+
* const pk: string = <string>process.env.PK;
|
|
120
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
121
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
122
|
+
* // initiate withdrawal
|
|
123
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
124
|
+
* console.log(respRemoveLiquidity);
|
|
125
|
+
* }
|
|
126
|
+
* main();
|
|
127
|
+
*
|
|
128
|
+
* @return Transaction object.
|
|
129
|
+
*/
|
|
130
|
+
initiateLiquidityWithdrawal(signer: Signer, poolSymbolName: string, amountPoolShares: number, overrides?: Overrides): Promise<ContractTransaction>;
|
|
131
|
+
/**
|
|
132
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
133
|
+
* The address loses pool shares in return.
|
|
134
|
+
* @param {Signer} signer Signer that will execute the liquidity withdrawal
|
|
135
|
+
* @param poolSymbolName
|
|
136
|
+
* @example
|
|
137
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
138
|
+
* async function main() {
|
|
139
|
+
* console.log(LiquidityProviderTool);
|
|
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 lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
144
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
145
|
+
* // remove liquidity
|
|
146
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
147
|
+
* console.log(respRemoveLiquidity);
|
|
148
|
+
* }
|
|
149
|
+
* main();
|
|
150
|
+
*
|
|
151
|
+
* @returns Transaction object.
|
|
152
|
+
*/
|
|
153
|
+
executeLiquidityWithdrawal(signer: Signer, poolSymbolName: string, overrides?: Overrides): Promise<ContractTransaction>;
|
|
80
154
|
}
|
|
@@ -23,6 +23,7 @@ class TraderInterface extends marketData_1.default {
|
|
|
23
23
|
*/
|
|
24
24
|
constructor(config) {
|
|
25
25
|
super(config);
|
|
26
|
+
this.gasLimit = 1000000;
|
|
26
27
|
this.digestTool = new traderDigests_1.default();
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
@@ -148,6 +149,106 @@ class TraderInterface extends marketData_1.default {
|
|
|
148
149
|
}
|
|
149
150
|
return obOrders;
|
|
150
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
154
|
+
* @param {Signer} signer Signer that will deposit liquidity
|
|
155
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
156
|
+
* @param {number} amountCC Amount in pool-collateral currency
|
|
157
|
+
* @example
|
|
158
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
159
|
+
* async function main() {
|
|
160
|
+
* console.log(LiquidityProviderTool);
|
|
161
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
162
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
163
|
+
* const pk: string = <string>process.env.PK;
|
|
164
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
165
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
166
|
+
* // add liquidity
|
|
167
|
+
* await lqudtProviderTool.setAllowance("MATIC");
|
|
168
|
+
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
169
|
+
* console.log(respAddLiquidity);
|
|
170
|
+
* }
|
|
171
|
+
* main();
|
|
172
|
+
*
|
|
173
|
+
* @return Transaction object
|
|
174
|
+
*/
|
|
175
|
+
async addLiquidity(signer, poolSymbolName, amountCC, overrides) {
|
|
176
|
+
if (this.proxyContract == null) {
|
|
177
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
178
|
+
}
|
|
179
|
+
let poolId = perpetualDataHandler_1.default._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
180
|
+
let decimals = this.getMarginTokenDecimalsFromSymbol(poolSymbolName);
|
|
181
|
+
let tx = await this.proxyContract
|
|
182
|
+
.connect(signer)
|
|
183
|
+
.addLiquidity(poolId, (0, d8XMath_1.floatToDecN)(amountCC, decimals), overrides || { gasLimit: this.gasLimit });
|
|
184
|
+
return tx;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Initiates a liquidity withdrawal from the pool
|
|
188
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
189
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
190
|
+
* @param {Signer} signer Signer that will initiate liquidity withdrawal
|
|
191
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
192
|
+
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
193
|
+
* @example
|
|
194
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
195
|
+
* async function main() {
|
|
196
|
+
* console.log(LiquidityProviderTool);
|
|
197
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
198
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
199
|
+
* const pk: string = <string>process.env.PK;
|
|
200
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
201
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
202
|
+
* // initiate withdrawal
|
|
203
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
204
|
+
* console.log(respRemoveLiquidity);
|
|
205
|
+
* }
|
|
206
|
+
* main();
|
|
207
|
+
*
|
|
208
|
+
* @return Transaction object.
|
|
209
|
+
*/
|
|
210
|
+
async initiateLiquidityWithdrawal(signer, poolSymbolName, amountPoolShares, overrides) {
|
|
211
|
+
if (this.proxyContract == null) {
|
|
212
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
213
|
+
}
|
|
214
|
+
let poolId = perpetualDataHandler_1.default._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
215
|
+
let tx = await this.proxyContract
|
|
216
|
+
.connect(signer)
|
|
217
|
+
.withdrawLiquidity(poolId, (0, d8XMath_1.floatToDec18)(amountPoolShares), overrides || { gasLimit: this.gasLimit });
|
|
218
|
+
return tx;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
222
|
+
* The address loses pool shares in return.
|
|
223
|
+
* @param {Signer} signer Signer that will execute the liquidity withdrawal
|
|
224
|
+
* @param poolSymbolName
|
|
225
|
+
* @example
|
|
226
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
227
|
+
* async function main() {
|
|
228
|
+
* console.log(LiquidityProviderTool);
|
|
229
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
230
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
231
|
+
* const pk: string = <string>process.env.PK;
|
|
232
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
233
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
234
|
+
* // remove liquidity
|
|
235
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
236
|
+
* console.log(respRemoveLiquidity);
|
|
237
|
+
* }
|
|
238
|
+
* main();
|
|
239
|
+
*
|
|
240
|
+
* @returns Transaction object.
|
|
241
|
+
*/
|
|
242
|
+
async executeLiquidityWithdrawal(signer, poolSymbolName, overrides) {
|
|
243
|
+
if (this.proxyContract == null) {
|
|
244
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
245
|
+
}
|
|
246
|
+
let poolId = perpetualDataHandler_1.default._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
247
|
+
let tx = await this.proxyContract
|
|
248
|
+
.connect(signer)
|
|
249
|
+
.executeLiquidityWithdrawal(poolId, await signer.getAddress(), overrides || { gasLimit: this.gasLimit });
|
|
250
|
+
return tx;
|
|
251
|
+
}
|
|
151
252
|
}
|
|
152
253
|
exports.default = TraderInterface;
|
|
153
254
|
//# sourceMappingURL=traderInterface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traderInterface.js","sourceRoot":"","sources":["../../src/traderInterface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"traderInterface.js","sourceRoot":"","sources":["../../src/traderInterface.ts"],"names":[],"mappings":";;;AAEA,uCAAuE;AACvE,sEAAsC;AACtC,iDAAsG;AACtG,0FAA0D;AAC1D,4EAA4C;AAC5C;;;;GAIG;AACH,MAAqB,eAAgB,SAAQ,oBAAU;IAIrD,wBAAwB;IACxB,+CAA+C;IAC/C,wBAAwB;IACxB,0CAA0C;IAE1C;;;;OAIG;IACH,YAAY,MAAqB;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;QAbN,aAAQ,GAAW,OAAS,CAAC;QAcrC,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAa,EAAE,CAAC;IACxC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,gBAAgB,CAC3B,cAAsB,EACtB,UAAkB,EAClB,UAAkB,EAClB,SAAyB;QAEzB,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,MAAM,KAAK,CAAC,qEAAqE,CAAC,CAAC;SACpF;QACD,IAAI,MAAM,GAAG,8BAAoB,CAAC,oBAAoB,CAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC7F,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;QACzG,OAAO,OAAO,GAAG,MAAO,CAAC;I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aAAa,IAAI,IAAI,EAAE;YAC9B,MAAM,KAAK,CAAC,qEAAqE,CAAC,CAAC;SACpF;QACD,IAAI,MAAM,GAAG,8BAAoB,CAAC,oBAAoB,CAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC7F,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa;aAC9B,OAAO,CAAC,MAAM,CAAC;aACf,0BAA0B,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3G,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAtRD,kCAsRC"}
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const D8X_SDK_VERSION = "0.7.
|
|
1
|
+
export declare const D8X_SDK_VERSION = "0.7.15";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
2
|
+
import { CallOverrides, ContractTransaction, Overrides } from "@ethersproject/contracts";
|
|
2
3
|
import MarketData from "./marketData";
|
|
3
4
|
import { ClientOrder, NodeSDKConfig, Order, SmartContractOrder } from "./nodeSDKTypes";
|
|
4
5
|
import TraderDigests from "./traderDigests";
|
|
@@ -9,6 +10,7 @@ import TraderDigests from "./traderDigests";
|
|
|
9
10
|
*/
|
|
10
11
|
export default class TraderInterface extends MarketData {
|
|
11
12
|
digestTool: TraderDigests;
|
|
13
|
+
protected gasLimit: number;
|
|
12
14
|
/**
|
|
13
15
|
* Constructor
|
|
14
16
|
* @param {NodeSDKConfig} config Configuration object, see
|
|
@@ -77,4 +79,76 @@ export default class TraderInterface extends MarketData {
|
|
|
77
79
|
*/
|
|
78
80
|
getOrderBookABI(symbol: string, method: string): string;
|
|
79
81
|
static chainOrders(orders: SmartContractOrder[], ids: string[]): ClientOrder[];
|
|
82
|
+
/**
|
|
83
|
+
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
84
|
+
* @param {Signer} signer Signer that will deposit liquidity
|
|
85
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
86
|
+
* @param {number} amountCC Amount in pool-collateral currency
|
|
87
|
+
* @example
|
|
88
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
89
|
+
* async function main() {
|
|
90
|
+
* console.log(LiquidityProviderTool);
|
|
91
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
92
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
93
|
+
* const pk: string = <string>process.env.PK;
|
|
94
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
95
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
96
|
+
* // add liquidity
|
|
97
|
+
* await lqudtProviderTool.setAllowance("MATIC");
|
|
98
|
+
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
99
|
+
* console.log(respAddLiquidity);
|
|
100
|
+
* }
|
|
101
|
+
* main();
|
|
102
|
+
*
|
|
103
|
+
* @return Transaction object
|
|
104
|
+
*/
|
|
105
|
+
addLiquidity(signer: Signer, poolSymbolName: string, amountCC: number, overrides?: Overrides): Promise<ContractTransaction>;
|
|
106
|
+
/**
|
|
107
|
+
* Initiates a liquidity withdrawal from the pool
|
|
108
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
109
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
110
|
+
* @param {Signer} signer Signer that will initiate liquidity withdrawal
|
|
111
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
112
|
+
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
113
|
+
* @example
|
|
114
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
115
|
+
* async function main() {
|
|
116
|
+
* console.log(LiquidityProviderTool);
|
|
117
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
118
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
119
|
+
* const pk: string = <string>process.env.PK;
|
|
120
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
121
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
122
|
+
* // initiate withdrawal
|
|
123
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
124
|
+
* console.log(respRemoveLiquidity);
|
|
125
|
+
* }
|
|
126
|
+
* main();
|
|
127
|
+
*
|
|
128
|
+
* @return Transaction object.
|
|
129
|
+
*/
|
|
130
|
+
initiateLiquidityWithdrawal(signer: Signer, poolSymbolName: string, amountPoolShares: number, overrides?: Overrides): Promise<ContractTransaction>;
|
|
131
|
+
/**
|
|
132
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
133
|
+
* The address loses pool shares in return.
|
|
134
|
+
* @param {Signer} signer Signer that will execute the liquidity withdrawal
|
|
135
|
+
* @param poolSymbolName
|
|
136
|
+
* @example
|
|
137
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
138
|
+
* async function main() {
|
|
139
|
+
* console.log(LiquidityProviderTool);
|
|
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 lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
144
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
145
|
+
* // remove liquidity
|
|
146
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
147
|
+
* console.log(respRemoveLiquidity);
|
|
148
|
+
* }
|
|
149
|
+
* main();
|
|
150
|
+
*
|
|
151
|
+
* @returns Transaction object.
|
|
152
|
+
*/
|
|
153
|
+
executeLiquidityWithdrawal(signer: Signer, poolSymbolName: string, overrides?: Overrides): Promise<ContractTransaction>;
|
|
80
154
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ABK64x64ToFloat } from "./d8XMath";
|
|
1
|
+
import { ABK64x64ToFloat, floatToDec18, floatToDecN } from "./d8XMath";
|
|
2
2
|
import MarketData from "./marketData";
|
|
3
3
|
import { ZERO_ORDER_ID } from "./nodeSDKTypes";
|
|
4
4
|
import PerpetualDataHandler from "./perpetualDataHandler";
|
|
@@ -20,6 +20,7 @@ export default class TraderInterface extends MarketData {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(config) {
|
|
22
22
|
super(config);
|
|
23
|
+
this.gasLimit = 1000000;
|
|
23
24
|
this.digestTool = new TraderDigests();
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -145,5 +146,105 @@ export default class TraderInterface extends MarketData {
|
|
|
145
146
|
}
|
|
146
147
|
return obOrders;
|
|
147
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
151
|
+
* @param {Signer} signer Signer that will deposit liquidity
|
|
152
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
153
|
+
* @param {number} amountCC Amount in pool-collateral currency
|
|
154
|
+
* @example
|
|
155
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
156
|
+
* async function main() {
|
|
157
|
+
* console.log(LiquidityProviderTool);
|
|
158
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
159
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
160
|
+
* const pk: string = <string>process.env.PK;
|
|
161
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
162
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
163
|
+
* // add liquidity
|
|
164
|
+
* await lqudtProviderTool.setAllowance("MATIC");
|
|
165
|
+
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
166
|
+
* console.log(respAddLiquidity);
|
|
167
|
+
* }
|
|
168
|
+
* main();
|
|
169
|
+
*
|
|
170
|
+
* @return Transaction object
|
|
171
|
+
*/
|
|
172
|
+
async addLiquidity(signer, poolSymbolName, amountCC, overrides) {
|
|
173
|
+
if (this.proxyContract == null) {
|
|
174
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
175
|
+
}
|
|
176
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
177
|
+
let decimals = this.getMarginTokenDecimalsFromSymbol(poolSymbolName);
|
|
178
|
+
let tx = await this.proxyContract
|
|
179
|
+
.connect(signer)
|
|
180
|
+
.addLiquidity(poolId, floatToDecN(amountCC, decimals), overrides || { gasLimit: this.gasLimit });
|
|
181
|
+
return tx;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Initiates a liquidity withdrawal from the pool
|
|
185
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
186
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
187
|
+
* @param {Signer} signer Signer that will initiate liquidity withdrawal
|
|
188
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
189
|
+
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
190
|
+
* @example
|
|
191
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
192
|
+
* async function main() {
|
|
193
|
+
* console.log(LiquidityProviderTool);
|
|
194
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
195
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
196
|
+
* const pk: string = <string>process.env.PK;
|
|
197
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
198
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
199
|
+
* // initiate withdrawal
|
|
200
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
201
|
+
* console.log(respRemoveLiquidity);
|
|
202
|
+
* }
|
|
203
|
+
* main();
|
|
204
|
+
*
|
|
205
|
+
* @return Transaction object.
|
|
206
|
+
*/
|
|
207
|
+
async initiateLiquidityWithdrawal(signer, poolSymbolName, amountPoolShares, overrides) {
|
|
208
|
+
if (this.proxyContract == null) {
|
|
209
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
210
|
+
}
|
|
211
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
212
|
+
let tx = await this.proxyContract
|
|
213
|
+
.connect(signer)
|
|
214
|
+
.withdrawLiquidity(poolId, floatToDec18(amountPoolShares), overrides || { gasLimit: this.gasLimit });
|
|
215
|
+
return tx;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
219
|
+
* The address loses pool shares in return.
|
|
220
|
+
* @param {Signer} signer Signer that will execute the liquidity withdrawal
|
|
221
|
+
* @param poolSymbolName
|
|
222
|
+
* @example
|
|
223
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
224
|
+
* async function main() {
|
|
225
|
+
* console.log(LiquidityProviderTool);
|
|
226
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
227
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
228
|
+
* const pk: string = <string>process.env.PK;
|
|
229
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
230
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
231
|
+
* // remove liquidity
|
|
232
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
233
|
+
* console.log(respRemoveLiquidity);
|
|
234
|
+
* }
|
|
235
|
+
* main();
|
|
236
|
+
*
|
|
237
|
+
* @returns Transaction object.
|
|
238
|
+
*/
|
|
239
|
+
async executeLiquidityWithdrawal(signer, poolSymbolName, overrides) {
|
|
240
|
+
if (this.proxyContract == null) {
|
|
241
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
242
|
+
}
|
|
243
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
244
|
+
let tx = await this.proxyContract
|
|
245
|
+
.connect(signer)
|
|
246
|
+
.executeLiquidityWithdrawal(poolId, await signer.getAddress(), overrides || { gasLimit: this.gasLimit });
|
|
247
|
+
return tx;
|
|
248
|
+
}
|
|
148
249
|
}
|
|
149
250
|
//# sourceMappingURL=traderInterface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traderInterface.js","sourceRoot":"","sources":["../../src/traderInterface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traderInterface.js","sourceRoot":"","sources":["../../src/traderInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAyD,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACtG,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IAIrD,wBAAwB;IACxB,+CAA+C;IAC/C,wBAAwB;IACxB,0CAA0C;IAE1C;;;;OAIG;IACH,YAAY,MAAqB;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;QAbN,aAAQ,GAAW,OAAS,CAAC;QAcrC,IAAI,CAAC,UAAU,GAAG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AAC;SACpF;QACD,IAAI,MAAM,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC7F,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa;aAC9B,OAAO,CAAC,MAAM,CAAC;aACf,iBAAiB,CAAC,MAAM,EAAE,YAAY,CAAC,gBAAgB,CAAC,EAAE,SAAS,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvG,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,KAAK,CAAC,0BAA0B,CACrC,MAAc,EACd,cAAsB,EACtB,SAAqB;QAErB,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,MAAM,KAAK,CAAC,qEAAqE,CAAC,CAAC;SACpF;QACD,IAAI,MAAM,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC7F,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa;aAC9B,OAAO,CAAC,MAAM,CAAC;aACf,0BAA0B,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3G,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const D8X_SDK_VERSION = "0.7.
|
|
1
|
+
export declare const D8X_SDK_VERSION = "0.7.15";
|
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const D8X_SDK_VERSION = "0.7.
|
|
1
|
+
export const D8X_SDK_VERSION = "0.7.15";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
package/src/traderInterface.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
2
|
+
import { CallOverrides, Contract, ContractTransaction, Overrides } from "@ethersproject/contracts";
|
|
3
|
+
import { ABK64x64ToFloat, floatToDec18, floatToDecN } from "./d8XMath";
|
|
3
4
|
import MarketData from "./marketData";
|
|
4
5
|
import { ClientOrder, NodeSDKConfig, Order, SmartContractOrder, ZERO_ORDER_ID } from "./nodeSDKTypes";
|
|
5
6
|
import PerpetualDataHandler from "./perpetualDataHandler";
|
|
@@ -11,6 +12,7 @@ import TraderDigests from "./traderDigests";
|
|
|
11
12
|
*/
|
|
12
13
|
export default class TraderInterface extends MarketData {
|
|
13
14
|
public digestTool: TraderDigests;
|
|
15
|
+
protected gasLimit: number = 1_000_000;
|
|
14
16
|
|
|
15
17
|
// accTrade.order(order)
|
|
16
18
|
// cancelOrder(symbol: string, orderId: string)
|
|
@@ -169,4 +171,121 @@ export default class TraderInterface extends MarketData {
|
|
|
169
171
|
}
|
|
170
172
|
return obOrders;
|
|
171
173
|
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
177
|
+
* @param {Signer} signer Signer that will deposit liquidity
|
|
178
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
179
|
+
* @param {number} amountCC Amount in pool-collateral currency
|
|
180
|
+
* @example
|
|
181
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
182
|
+
* async function main() {
|
|
183
|
+
* console.log(LiquidityProviderTool);
|
|
184
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
185
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
186
|
+
* const pk: string = <string>process.env.PK;
|
|
187
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
188
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
189
|
+
* // add liquidity
|
|
190
|
+
* await lqudtProviderTool.setAllowance("MATIC");
|
|
191
|
+
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
192
|
+
* console.log(respAddLiquidity);
|
|
193
|
+
* }
|
|
194
|
+
* main();
|
|
195
|
+
*
|
|
196
|
+
* @return Transaction object
|
|
197
|
+
*/
|
|
198
|
+
public async addLiquidity(
|
|
199
|
+
signer: Signer,
|
|
200
|
+
poolSymbolName: string,
|
|
201
|
+
amountCC: number,
|
|
202
|
+
overrides?: Overrides
|
|
203
|
+
): Promise<ContractTransaction> {
|
|
204
|
+
if (this.proxyContract == null) {
|
|
205
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
206
|
+
}
|
|
207
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
208
|
+
let decimals = this.getMarginTokenDecimalsFromSymbol(poolSymbolName);
|
|
209
|
+
let tx = await this.proxyContract
|
|
210
|
+
.connect(signer)
|
|
211
|
+
.addLiquidity(poolId, floatToDecN(amountCC, decimals!), overrides || { gasLimit: this.gasLimit });
|
|
212
|
+
return tx;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Initiates a liquidity withdrawal from the pool
|
|
217
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
218
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
219
|
+
* @param {Signer} signer Signer that will initiate liquidity withdrawal
|
|
220
|
+
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
221
|
+
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
222
|
+
* @example
|
|
223
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
224
|
+
* async function main() {
|
|
225
|
+
* console.log(LiquidityProviderTool);
|
|
226
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
227
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
228
|
+
* const pk: string = <string>process.env.PK;
|
|
229
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
230
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
231
|
+
* // initiate withdrawal
|
|
232
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
233
|
+
* console.log(respRemoveLiquidity);
|
|
234
|
+
* }
|
|
235
|
+
* main();
|
|
236
|
+
*
|
|
237
|
+
* @return Transaction object.
|
|
238
|
+
*/
|
|
239
|
+
public async initiateLiquidityWithdrawal(
|
|
240
|
+
signer: Signer,
|
|
241
|
+
poolSymbolName: string,
|
|
242
|
+
amountPoolShares: number,
|
|
243
|
+
overrides?: Overrides
|
|
244
|
+
): Promise<ContractTransaction> {
|
|
245
|
+
if (this.proxyContract == null) {
|
|
246
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
247
|
+
}
|
|
248
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
249
|
+
let tx = await this.proxyContract
|
|
250
|
+
.connect(signer)
|
|
251
|
+
.withdrawLiquidity(poolId, floatToDec18(amountPoolShares), overrides || { gasLimit: this.gasLimit });
|
|
252
|
+
return tx;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
257
|
+
* The address loses pool shares in return.
|
|
258
|
+
* @param {Signer} signer Signer that will execute the liquidity withdrawal
|
|
259
|
+
* @param poolSymbolName
|
|
260
|
+
* @example
|
|
261
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
262
|
+
* async function main() {
|
|
263
|
+
* console.log(LiquidityProviderTool);
|
|
264
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
265
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
266
|
+
* const pk: string = <string>process.env.PK;
|
|
267
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
268
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
269
|
+
* // remove liquidity
|
|
270
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
271
|
+
* console.log(respRemoveLiquidity);
|
|
272
|
+
* }
|
|
273
|
+
* main();
|
|
274
|
+
*
|
|
275
|
+
* @returns Transaction object.
|
|
276
|
+
*/
|
|
277
|
+
public async executeLiquidityWithdrawal(
|
|
278
|
+
signer: Signer,
|
|
279
|
+
poolSymbolName: string,
|
|
280
|
+
overrides?: Overrides
|
|
281
|
+
): Promise<ContractTransaction> {
|
|
282
|
+
if (this.proxyContract == null) {
|
|
283
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
284
|
+
}
|
|
285
|
+
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
286
|
+
let tx = await this.proxyContract
|
|
287
|
+
.connect(signer)
|
|
288
|
+
.executeLiquidityWithdrawal(poolId, await signer.getAddress(), overrides || { gasLimit: this.gasLimit });
|
|
289
|
+
return tx;
|
|
290
|
+
}
|
|
172
291
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const D8X_SDK_VERSION = "0.7.
|
|
1
|
+
export const D8X_SDK_VERSION = "0.7.15";
|