@d8x/perpetuals-sdk 0.1.2 → 0.1.4
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/Multicall.json +86 -0
- package/abi/central-park/IPerpetualManager.json +7 -2
- package/abi/central-park/LimitOrderBook.json +130 -2
- package/config/defaultConfig.json +2 -2
- package/dist/accountTrade.d.ts +0 -1
- package/dist/accountTrade.js +0 -21
- package/dist/liquidatorTool.d.ts +2 -1
- package/dist/liquidatorTool.js +8 -2
- package/dist/liquidityProviderTool.d.ts +28 -4
- package/dist/liquidityProviderTool.js +40 -5
- package/dist/marketData.d.ts +15 -4
- package/dist/marketData.js +219 -97
- package/dist/perpetualDataHandler.d.ts +3 -2
- package/dist/perpetualDataHandler.js +5 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/writeAccessHandler.d.ts +8 -0
- package/dist/writeAccessHandler.js +27 -0
- package/package.json +1 -1
- package/src/accountTrade.ts +0 -19
- package/src/liquidatorTool.ts +8 -2
- package/src/liquidityProviderTool.ts +39 -5
- package/src/marketData.ts +265 -166
- package/src/perpetualDataHandler.ts +6 -7
- package/src/version.ts +1 -1
- package/src/writeAccessHandler.ts +27 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"constant": true,
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "getCurrentBlockTimestamp",
|
|
6
|
+
"outputs": [{ "name": "timestamp", "type": "uint256" }],
|
|
7
|
+
"payable": false,
|
|
8
|
+
"stateMutability": "view",
|
|
9
|
+
"type": "function"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"constant": false,
|
|
13
|
+
"inputs": [
|
|
14
|
+
{
|
|
15
|
+
"components": [
|
|
16
|
+
{ "name": "target", "type": "address" },
|
|
17
|
+
{ "name": "callData", "type": "bytes" }
|
|
18
|
+
],
|
|
19
|
+
"name": "calls",
|
|
20
|
+
"type": "tuple[]"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"name": "aggregate",
|
|
24
|
+
"outputs": [
|
|
25
|
+
{ "name": "blockNumber", "type": "uint256" },
|
|
26
|
+
{ "name": "returnData", "type": "bytes[]" }
|
|
27
|
+
],
|
|
28
|
+
"payable": false,
|
|
29
|
+
"stateMutability": "nonpayable",
|
|
30
|
+
"type": "function"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"constant": true,
|
|
34
|
+
"inputs": [],
|
|
35
|
+
"name": "getLastBlockHash",
|
|
36
|
+
"outputs": [{ "name": "blockHash", "type": "bytes32" }],
|
|
37
|
+
"payable": false,
|
|
38
|
+
"stateMutability": "view",
|
|
39
|
+
"type": "function"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"constant": true,
|
|
43
|
+
"inputs": [{ "name": "addr", "type": "address" }],
|
|
44
|
+
"name": "getEthBalance",
|
|
45
|
+
"outputs": [{ "name": "balance", "type": "uint256" }],
|
|
46
|
+
"payable": false,
|
|
47
|
+
"stateMutability": "view",
|
|
48
|
+
"type": "function"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"constant": true,
|
|
52
|
+
"inputs": [],
|
|
53
|
+
"name": "getCurrentBlockDifficulty",
|
|
54
|
+
"outputs": [{ "name": "difficulty", "type": "uint256" }],
|
|
55
|
+
"payable": false,
|
|
56
|
+
"stateMutability": "view",
|
|
57
|
+
"type": "function"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"constant": true,
|
|
61
|
+
"inputs": [],
|
|
62
|
+
"name": "getCurrentBlockGasLimit",
|
|
63
|
+
"outputs": [{ "name": "gaslimit", "type": "uint256" }],
|
|
64
|
+
"payable": false,
|
|
65
|
+
"stateMutability": "view",
|
|
66
|
+
"type": "function"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"constant": true,
|
|
70
|
+
"inputs": [],
|
|
71
|
+
"name": "getCurrentBlockCoinbase",
|
|
72
|
+
"outputs": [{ "name": "coinbase", "type": "address" }],
|
|
73
|
+
"payable": false,
|
|
74
|
+
"stateMutability": "view",
|
|
75
|
+
"type": "function"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"constant": true,
|
|
79
|
+
"inputs": [{ "name": "blockNumber", "type": "uint256" }],
|
|
80
|
+
"name": "getBlockHash",
|
|
81
|
+
"outputs": [{ "name": "blockHash", "type": "bytes32" }],
|
|
82
|
+
"payable": false,
|
|
83
|
+
"stateMutability": "view",
|
|
84
|
+
"type": "function"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
@@ -3705,14 +3705,19 @@
|
|
|
3705
3705
|
"internalType": "address",
|
|
3706
3706
|
"name": "_traderAddress",
|
|
3707
3707
|
"type": "address"
|
|
3708
|
+
},
|
|
3709
|
+
{
|
|
3710
|
+
"internalType": "int128[2]",
|
|
3711
|
+
"name": "_fIndexPrice",
|
|
3712
|
+
"type": "int128[2]"
|
|
3708
3713
|
}
|
|
3709
3714
|
],
|
|
3710
3715
|
"name": "getTraderState",
|
|
3711
3716
|
"outputs": [
|
|
3712
3717
|
{
|
|
3713
|
-
"internalType": "int128[
|
|
3718
|
+
"internalType": "int128[11]",
|
|
3714
3719
|
"name": "",
|
|
3715
|
-
"type": "int128[
|
|
3720
|
+
"type": "int128[11]"
|
|
3716
3721
|
}
|
|
3717
3722
|
],
|
|
3718
3723
|
"stateMutability": "view",
|
|
@@ -225,11 +225,21 @@
|
|
|
225
225
|
"internalType": "bytes",
|
|
226
226
|
"name": "_signature",
|
|
227
227
|
"type": "bytes"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"internalType": "bytes[]",
|
|
231
|
+
"name": "_updateData",
|
|
232
|
+
"type": "bytes[]"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"internalType": "uint64[]",
|
|
236
|
+
"name": "_publishTimes",
|
|
237
|
+
"type": "uint64[]"
|
|
228
238
|
}
|
|
229
239
|
],
|
|
230
240
|
"name": "cancelOrder",
|
|
231
241
|
"outputs": [],
|
|
232
|
-
"stateMutability": "
|
|
242
|
+
"stateMutability": "payable",
|
|
233
243
|
"type": "function"
|
|
234
244
|
},
|
|
235
245
|
{
|
|
@@ -284,6 +294,34 @@
|
|
|
284
294
|
"stateMutability": "payable",
|
|
285
295
|
"type": "function"
|
|
286
296
|
},
|
|
297
|
+
{
|
|
298
|
+
"inputs": [
|
|
299
|
+
{
|
|
300
|
+
"internalType": "bytes32[]",
|
|
301
|
+
"name": "_digests",
|
|
302
|
+
"type": "bytes32[]"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"internalType": "address",
|
|
306
|
+
"name": "_referrerAddr",
|
|
307
|
+
"type": "address"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"internalType": "bytes[]",
|
|
311
|
+
"name": "_updateData",
|
|
312
|
+
"type": "bytes[]"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"internalType": "uint64[]",
|
|
316
|
+
"name": "_publishTimes",
|
|
317
|
+
"type": "uint64[]"
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
"name": "executeOrders",
|
|
321
|
+
"outputs": [],
|
|
322
|
+
"stateMutability": "payable",
|
|
323
|
+
"type": "function"
|
|
324
|
+
},
|
|
287
325
|
{
|
|
288
326
|
"inputs": [
|
|
289
327
|
{
|
|
@@ -872,7 +910,7 @@
|
|
|
872
910
|
},
|
|
873
911
|
{
|
|
874
912
|
"internalType": "bytes",
|
|
875
|
-
"name": "
|
|
913
|
+
"name": "_signature",
|
|
876
914
|
"type": "bytes"
|
|
877
915
|
}
|
|
878
916
|
],
|
|
@@ -881,6 +919,96 @@
|
|
|
881
919
|
"stateMutability": "nonpayable",
|
|
882
920
|
"type": "function"
|
|
883
921
|
},
|
|
922
|
+
{
|
|
923
|
+
"inputs": [
|
|
924
|
+
{
|
|
925
|
+
"components": [
|
|
926
|
+
{
|
|
927
|
+
"internalType": "uint32",
|
|
928
|
+
"name": "flags",
|
|
929
|
+
"type": "uint32"
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
"internalType": "uint24",
|
|
933
|
+
"name": "iPerpetualId",
|
|
934
|
+
"type": "uint24"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
"internalType": "uint16",
|
|
938
|
+
"name": "brokerFeeTbps",
|
|
939
|
+
"type": "uint16"
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
"internalType": "address",
|
|
943
|
+
"name": "traderAddr",
|
|
944
|
+
"type": "address"
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
"internalType": "address",
|
|
948
|
+
"name": "brokerAddr",
|
|
949
|
+
"type": "address"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
"internalType": "address",
|
|
953
|
+
"name": "referrerAddr",
|
|
954
|
+
"type": "address"
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
"internalType": "bytes",
|
|
958
|
+
"name": "brokerSignature",
|
|
959
|
+
"type": "bytes"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
"internalType": "int128",
|
|
963
|
+
"name": "fAmount",
|
|
964
|
+
"type": "int128"
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
"internalType": "int128",
|
|
968
|
+
"name": "fLimitPrice",
|
|
969
|
+
"type": "int128"
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
"internalType": "int128",
|
|
973
|
+
"name": "fTriggerPrice",
|
|
974
|
+
"type": "int128"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
"internalType": "int128",
|
|
978
|
+
"name": "fLeverage",
|
|
979
|
+
"type": "int128"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
"internalType": "uint64",
|
|
983
|
+
"name": "iDeadline",
|
|
984
|
+
"type": "uint64"
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
"internalType": "uint64",
|
|
988
|
+
"name": "createdTimestamp",
|
|
989
|
+
"type": "uint64"
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
"internalType": "uint64",
|
|
993
|
+
"name": "submittedBlock",
|
|
994
|
+
"type": "uint64"
|
|
995
|
+
}
|
|
996
|
+
],
|
|
997
|
+
"internalType": "struct IPerpetualOrder.Order[]",
|
|
998
|
+
"name": "_orders",
|
|
999
|
+
"type": "tuple[]"
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
"internalType": "bytes[]",
|
|
1003
|
+
"name": "_signatures",
|
|
1004
|
+
"type": "bytes[]"
|
|
1005
|
+
}
|
|
1006
|
+
],
|
|
1007
|
+
"name": "postOrders",
|
|
1008
|
+
"outputs": [],
|
|
1009
|
+
"stateMutability": "nonpayable",
|
|
1010
|
+
"type": "function"
|
|
1011
|
+
},
|
|
884
1012
|
{
|
|
885
1013
|
"inputs": [
|
|
886
1014
|
{
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"name": "central-park",
|
|
26
|
-
"version":
|
|
26
|
+
"version": 4.0,
|
|
27
27
|
"proxyAddr": "0x4F1C7EE9E881Cc735f39Ca36c649ba9E930B4E4e",
|
|
28
28
|
"nodeURL": "https://polygon-mumbai.blockpi.network/v1/rpc/public",
|
|
29
29
|
"priceFeedConfigNetwork": "testnet",
|
|
30
30
|
"proxyABILocation": "../abi/central-park/IPerpetualManager.json",
|
|
31
|
-
"limitOrderBookFactoryAddr": "
|
|
31
|
+
"limitOrderBookFactoryAddr": "0xeC71488Ca228506C93CDaEd4C00Ef65ee7E6A4F1",
|
|
32
32
|
"limitOrderBookFactoryABILocation": "../abi/central-park/LimitOrderBookFactory.json",
|
|
33
33
|
"limitOrderBookABILocation": "../abi/central-park/LimitOrderBook.json",
|
|
34
34
|
"symbolListLocation": "../config/symbolList.json"
|
package/dist/accountTrade.d.ts
CHANGED
|
@@ -218,5 +218,4 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
218
218
|
* @param {number} amount How much collateral to remove, in units of collateral currency, e.g. MATIC
|
|
219
219
|
*/
|
|
220
220
|
removeCollateral(symbol: string, amount: number): Promise<ethers.ContractTransaction>;
|
|
221
|
-
swapForMockToken(symbol: string, amountToPay: string): Promise<any>;
|
|
222
221
|
}
|
package/dist/accountTrade.js
CHANGED
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const ethers_1 = require("ethers");
|
|
16
15
|
const d8XMath_1 = require("./d8XMath");
|
|
17
16
|
const marketData_1 = __importDefault(require("./marketData"));
|
|
18
17
|
const nodeSDKTypes_1 = require("./nodeSDKTypes");
|
|
@@ -342,25 +341,5 @@ class AccountTrade extends writeAccessHandler_1.default {
|
|
|
342
341
|
});
|
|
343
342
|
});
|
|
344
343
|
}
|
|
345
|
-
swapForMockToken(symbol, amountToPay) {
|
|
346
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
-
if (this.signer == null) {
|
|
348
|
-
throw Error("no wallet initialized. Use createProxyInstance().");
|
|
349
|
-
}
|
|
350
|
-
let tokenAddress = this.getMarginTokenFromSymbol(symbol);
|
|
351
|
-
if (tokenAddress == undefined) {
|
|
352
|
-
throw Error("symbols not found");
|
|
353
|
-
}
|
|
354
|
-
let tokenToSwap = new Map(Object.entries(require("../config/mockSwap.json")));
|
|
355
|
-
let swapAddress = tokenToSwap.get(tokenAddress);
|
|
356
|
-
if (swapAddress == undefined) {
|
|
357
|
-
throw Error("No swap contract found for symbol.");
|
|
358
|
-
}
|
|
359
|
-
let contract = new ethers_1.ethers.Contract(swapAddress, nodeSDKTypes_1.MOCK_TOKEN_SWAP_ABI, this.signer.provider);
|
|
360
|
-
return yield contract.swapToMockToken({
|
|
361
|
-
value: ethers_1.ethers.utils.parseEther(amountToPay),
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
344
|
}
|
|
366
345
|
exports.default = AccountTrade;
|
package/dist/liquidatorTool.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export default class LiquidatorTool extends WriteAccessHandler {
|
|
|
59
59
|
* If not, the position can be liquidated.
|
|
60
60
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
61
61
|
* @param {string} traderAddr Address of the trader whose position you want to assess.
|
|
62
|
+
* @param {[number,number]} indexPrices optional, index price S2/S3 for which we test
|
|
62
63
|
* @example
|
|
63
64
|
* import { LiquidatorTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
64
65
|
* async function main() {
|
|
@@ -78,7 +79,7 @@ export default class LiquidatorTool extends WriteAccessHandler {
|
|
|
78
79
|
* @returns {boolean} True if the trader is maintenance margin safe in the perpetual.
|
|
79
80
|
* False means that the trader's position can be liquidated.
|
|
80
81
|
*/
|
|
81
|
-
isMaintenanceMarginSafe(symbol: string, traderAddr: string): Promise<boolean>;
|
|
82
|
+
isMaintenanceMarginSafe(symbol: string, traderAddr: string, indexPrices?: [number, number]): Promise<boolean>;
|
|
82
83
|
/**
|
|
83
84
|
*
|
|
84
85
|
* @param perpetualId Perpetual id.
|
package/dist/liquidatorTool.js
CHANGED
|
@@ -92,6 +92,7 @@ class LiquidatorTool extends writeAccessHandler_1.default {
|
|
|
92
92
|
* If not, the position can be liquidated.
|
|
93
93
|
* @param {string} symbol Symbol of the form ETH-USD-MATIC.
|
|
94
94
|
* @param {string} traderAddr Address of the trader whose position you want to assess.
|
|
95
|
+
* @param {[number,number]} indexPrices optional, index price S2/S3 for which we test
|
|
95
96
|
* @example
|
|
96
97
|
* import { LiquidatorTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
97
98
|
* async function main() {
|
|
@@ -111,14 +112,19 @@ class LiquidatorTool extends writeAccessHandler_1.default {
|
|
|
111
112
|
* @returns {boolean} True if the trader is maintenance margin safe in the perpetual.
|
|
112
113
|
* False means that the trader's position can be liquidated.
|
|
113
114
|
*/
|
|
114
|
-
isMaintenanceMarginSafe(symbol, traderAddr) {
|
|
115
|
+
isMaintenanceMarginSafe(symbol, traderAddr, indexPrices) {
|
|
115
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
117
|
if (this.proxyContract == null) {
|
|
117
118
|
throw Error("no proxy contract initialized. Use createProxyInstance().");
|
|
118
119
|
}
|
|
119
120
|
const idx_notional = 4;
|
|
120
121
|
let perpID = LiquidatorTool.symbolToPerpetualId(symbol, this.symbolToPerpStaticInfo);
|
|
121
|
-
|
|
122
|
+
if (indexPrices == undefined) {
|
|
123
|
+
// fetch from API
|
|
124
|
+
let obj = yield this.priceFeedGetter.fetchPricesForPerpetual(symbol);
|
|
125
|
+
indexPrices = [obj.idxPrices[0], obj.idxPrices[1]];
|
|
126
|
+
}
|
|
127
|
+
let traderState = yield this.proxyContract.getTraderState(perpID, traderAddr, indexPrices);
|
|
122
128
|
if (traderState[idx_notional] == 0) {
|
|
123
129
|
// trader does not have open position
|
|
124
130
|
return false;
|
|
@@ -78,7 +78,9 @@ export default class LiquidityProviderTool extends WriteAccessHandler {
|
|
|
78
78
|
*/
|
|
79
79
|
addLiquidity(poolSymbolName: string, amountCC: number): Promise<ethers.ContractTransaction>;
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Initiates a liquidity withdrawal from the pool
|
|
82
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
83
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
82
84
|
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
83
85
|
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
84
86
|
* @example
|
|
@@ -90,13 +92,35 @@ export default class LiquidityProviderTool extends WriteAccessHandler {
|
|
|
90
92
|
* const pk: string = <string>process.env.PK;
|
|
91
93
|
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
92
94
|
* await lqudtProviderTool.createProxyInstance();
|
|
93
|
-
* //
|
|
94
|
-
* let respRemoveLiquidity = await lqudtProviderTool.
|
|
95
|
+
* // initiate withdrawal
|
|
96
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
95
97
|
* console.log(respRemoveLiquidity);
|
|
96
98
|
* }
|
|
97
99
|
* main();
|
|
98
100
|
*
|
|
99
101
|
* @return Transaction object.
|
|
100
102
|
*/
|
|
101
|
-
|
|
103
|
+
initiateLiquidityWithdrawal(poolSymbolName: string, amountPoolShares: number): Promise<ethers.providers.TransactionResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
106
|
+
* The address loses pool shares in return.
|
|
107
|
+
* @param poolSymbolName
|
|
108
|
+
* @example
|
|
109
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
110
|
+
* async function main() {
|
|
111
|
+
* console.log(LiquidityProviderTool);
|
|
112
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
113
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
114
|
+
* const pk: string = <string>process.env.PK;
|
|
115
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
116
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
117
|
+
* // remove liquidity
|
|
118
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
119
|
+
* console.log(respRemoveLiquidity);
|
|
120
|
+
* }
|
|
121
|
+
* main();
|
|
122
|
+
*
|
|
123
|
+
* @returns Transaction object.
|
|
124
|
+
*/
|
|
125
|
+
executeLiquidityWithdrawal(poolSymbolName: string): Promise<ethers.providers.TransactionResponse>;
|
|
102
126
|
}
|
|
@@ -123,7 +123,9 @@ class LiquidityProviderTool extends writeAccessHandler_1.default {
|
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
126
|
+
* Initiates a liquidity withdrawal from the pool
|
|
127
|
+
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
128
|
+
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
127
129
|
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
128
130
|
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
129
131
|
* @example
|
|
@@ -135,21 +137,54 @@ class LiquidityProviderTool extends writeAccessHandler_1.default {
|
|
|
135
137
|
* const pk: string = <string>process.env.PK;
|
|
136
138
|
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
137
139
|
* await lqudtProviderTool.createProxyInstance();
|
|
138
|
-
* //
|
|
139
|
-
* let respRemoveLiquidity = await lqudtProviderTool.
|
|
140
|
+
* // initiate withdrawal
|
|
141
|
+
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
140
142
|
* console.log(respRemoveLiquidity);
|
|
141
143
|
* }
|
|
142
144
|
* main();
|
|
143
145
|
*
|
|
144
146
|
* @return Transaction object.
|
|
145
147
|
*/
|
|
146
|
-
|
|
148
|
+
initiateLiquidityWithdrawal(poolSymbolName, amountPoolShares) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
if (this.proxyContract == null || this.signer == null) {
|
|
151
|
+
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
152
|
+
}
|
|
153
|
+
let poolId = perpetualDataHandler_1.default._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
154
|
+
let tx = yield this.proxyContract.withdrawLiquidity(poolId, (0, d8XMath_1.floatToDec18)(amountPoolShares), {
|
|
155
|
+
gasLimit: this.gasLimit,
|
|
156
|
+
});
|
|
157
|
+
return tx;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
162
|
+
* The address loses pool shares in return.
|
|
163
|
+
* @param poolSymbolName
|
|
164
|
+
* @example
|
|
165
|
+
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
166
|
+
* async function main() {
|
|
167
|
+
* console.log(LiquidityProviderTool);
|
|
168
|
+
* // setup (authentication required, PK is an environment variable with a private key)
|
|
169
|
+
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
170
|
+
* const pk: string = <string>process.env.PK;
|
|
171
|
+
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
172
|
+
* await lqudtProviderTool.createProxyInstance();
|
|
173
|
+
* // remove liquidity
|
|
174
|
+
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
175
|
+
* console.log(respRemoveLiquidity);
|
|
176
|
+
* }
|
|
177
|
+
* main();
|
|
178
|
+
*
|
|
179
|
+
* @returns Transaction object.
|
|
180
|
+
*/
|
|
181
|
+
executeLiquidityWithdrawal(poolSymbolName) {
|
|
147
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
183
|
if (this.proxyContract == null || this.signer == null) {
|
|
149
184
|
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
150
185
|
}
|
|
151
186
|
let poolId = perpetualDataHandler_1.default._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
152
|
-
let tx = yield this.proxyContract.
|
|
187
|
+
let tx = yield this.proxyContract.executeLiquidityWithdrawal(poolId, {
|
|
153
188
|
gasLimit: this.gasLimit,
|
|
154
189
|
});
|
|
155
190
|
return tx;
|
package/dist/marketData.d.ts
CHANGED
|
@@ -136,10 +136,14 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
136
136
|
* Estimates what the position risk will be if a given order is executed.
|
|
137
137
|
* @param traderAddr Address of trader
|
|
138
138
|
* @param order Order to be submitted
|
|
139
|
-
* @param
|
|
139
|
+
* @param account Position risk before trade
|
|
140
|
+
* @param indexPriceInfo Index prices and market status (open/closed)
|
|
140
141
|
* @returns {MarginAccount} Position risk after trade
|
|
141
142
|
*/
|
|
142
|
-
positionRiskOnTrade(traderAddr: string, order: Order,
|
|
143
|
+
positionRiskOnTrade(traderAddr: string, order: Order, account?: MarginAccount, indexPriceInfo?: [number, number, boolean, boolean]): Promise<{
|
|
144
|
+
newPositionRisk: MarginAccount;
|
|
145
|
+
orderCost: number;
|
|
146
|
+
}>;
|
|
143
147
|
/**
|
|
144
148
|
* Estimates what the position risk will be if given amount of collateral is added/removed from the account.
|
|
145
149
|
* @param traderAddr Address of trader
|
|
@@ -147,8 +151,8 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
147
151
|
* @param currentPositionRisk Position risk before
|
|
148
152
|
* @returns {MarginAccount} Position risk after
|
|
149
153
|
*/
|
|
150
|
-
positionRiskOnCollateralAction(deltaCollateral: number,
|
|
151
|
-
protected static
|
|
154
|
+
positionRiskOnCollateralAction(deltaCollateral: number, account: MarginAccount, indexPriceInfo?: [number, number, boolean, boolean]): Promise<MarginAccount>;
|
|
155
|
+
protected static _getLiquidationParams(symbol: string, lockedInQC: number, signedPositionBC: number, marginCashCC: number, markPrice: number, collToQuoteConversion: number, symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>): [number, number | undefined, number];
|
|
152
156
|
/**
|
|
153
157
|
* Gets the wallet balance in the collateral currency corresponding to a given perpetual symbol.
|
|
154
158
|
* @param address Address to check
|
|
@@ -279,5 +283,12 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
279
283
|
*/
|
|
280
284
|
static orderIdsOfTrader(traderAddr: string, orderBookContract: ethers.Contract): Promise<string[]>;
|
|
281
285
|
getAvailableMargin(traderAddr: string, symbol: string, indexPrices?: [number, number]): Promise<number>;
|
|
286
|
+
/**
|
|
287
|
+
* Calculate a type of exchange loyality score based on trader volume
|
|
288
|
+
* @param traderAddr address of the trader
|
|
289
|
+
* @param brokerAddr address of the trader's broker or undefined
|
|
290
|
+
* @returns a loyality score (4 worst, 1 best)
|
|
291
|
+
*/
|
|
292
|
+
getTraderLoyalityScore(traderAddr: string, brokerAddr?: string): Promise<number>;
|
|
282
293
|
static _exchangeInfo(_proxyContract: ethers.Contract, _poolStaticInfos: Array<PoolStaticInfo>, _symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>, _symbolList: Map<string, string>, _priceFeedGetter: PriceFeeds): Promise<ExchangeInfo>;
|
|
283
294
|
}
|