@d8x/perpetuals-sdk 0.1.12 → 0.2.0
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/abi/testnet/IPerpetualManager.json +5215 -0
- package/dist/cjs/abi/testnet/LimitOrderBook.json +1075 -0
- package/dist/cjs/abi/zkevmTestnet/IPerpetualManager.json +5215 -0
- package/dist/cjs/abi/zkevmTestnet/LimitOrderBook.json +1075 -0
- package/dist/cjs/abi/zkevmTestnet/LimitOrderBookFactory.json +135 -0
- package/dist/cjs/accountTrade.js +441 -0
- package/dist/cjs/accountTrade.js.map +1 -0
- package/dist/{src → cjs}/brokerTool.js +31 -84
- package/dist/cjs/brokerTool.js.map +1 -0
- package/dist/cjs/config/defaultConfig.json +47 -0
- package/dist/cjs/config/mockSwap.json +4 -0
- package/dist/cjs/config/priceFeedConfig.json +104 -0
- package/dist/cjs/config/symbolList.json +13 -0
- package/dist/cjs/d8XMath.js.map +1 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/liquidatorTool.js +287 -0
- package/dist/cjs/liquidatorTool.js.map +1 -0
- package/dist/{src → cjs}/liquidityProviderTool.js +12 -65
- package/dist/cjs/liquidityProviderTool.js.map +1 -0
- package/dist/{src → cjs}/marketData.js +52 -134
- package/dist/cjs/marketData.js.map +1 -0
- package/dist/{src → cjs}/nodeSDKTypes.d.ts +5 -5
- package/dist/cjs/nodeSDKTypes.js +64 -0
- package/dist/cjs/nodeSDKTypes.js.map +1 -0
- package/dist/{src → cjs}/orderReferrerTool.d.ts +12 -5
- package/dist/{src → cjs}/orderReferrerTool.js +114 -112
- package/dist/cjs/orderReferrerTool.js.map +1 -0
- package/dist/{src → cjs}/perpetualDataHandler.d.ts +1 -1
- package/dist/{src → cjs}/perpetualDataHandler.js +47 -109
- package/dist/cjs/perpetualDataHandler.js.map +1 -0
- package/dist/{src → cjs}/perpetualEventHandler.d.ts +3 -3
- package/dist/{src → cjs}/perpetualEventHandler.js +12 -74
- package/dist/cjs/perpetualEventHandler.js.map +1 -0
- package/dist/cjs/priceFeeds.js +466 -0
- package/dist/cjs/priceFeeds.js.map +1 -0
- package/dist/{src → cjs}/traderDigests.js +7 -43
- package/dist/cjs/traderDigests.js.map +1 -0
- package/dist/{src → cjs}/traderInterface.js +13 -66
- package/dist/cjs/traderInterface.js.map +1 -0
- package/dist/{src → cjs}/triangulator.js +2 -17
- package/dist/cjs/triangulator.js.map +1 -0
- package/dist/{src → cjs}/utils.js +3 -29
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/{src → cjs}/version.js +1 -1
- package/dist/cjs/version.js.map +1 -0
- package/dist/{src → cjs}/writeAccessHandler.js +12 -65
- package/dist/cjs/writeAccessHandler.js.map +1 -0
- package/dist/esm/abi/ERC20.json +288 -0
- package/dist/esm/abi/MockTokenSwap.json +186 -0
- package/dist/{abi/testnet → esm/abi/central-park}/IPerpetualManager.json +404 -214
- package/dist/{abi/testnet → esm/abi/central-park}/LimitOrderBook.json +197 -15
- package/dist/esm/abi/central-park/LimitOrderBookFactory.json +135 -0
- package/dist/esm/abi/testnet/IPerpetualManager.json +5215 -0
- package/dist/esm/abi/testnet/LimitOrderBook.json +1075 -0
- package/dist/esm/abi/testnet/LimitOrderBookFactory.json +135 -0
- package/dist/esm/abi/zkevmTestnet/IPerpetualManager.json +5215 -0
- package/dist/esm/abi/zkevmTestnet/LimitOrderBook.json +1075 -0
- package/dist/esm/abi/zkevmTestnet/LimitOrderBookFactory.json +135 -0
- package/dist/esm/accountTrade.d.ts +221 -0
- package/dist/{src → esm}/accountTrade.js +22 -93
- package/dist/esm/accountTrade.js.map +1 -0
- package/dist/esm/brokerTool.d.ts +318 -0
- package/dist/esm/brokerTool.js +572 -0
- package/dist/esm/brokerTool.js.map +1 -0
- package/dist/esm/config/defaultConfig.json +47 -0
- package/dist/esm/config/mockSwap.json +4 -0
- package/dist/esm/config/priceFeedConfig.json +104 -0
- package/dist/esm/config/symbolList.json +13 -0
- package/dist/esm/d8XMath.d.ts +122 -0
- package/dist/esm/d8XMath.js +247 -0
- package/dist/esm/d8XMath.js.map +1 -0
- package/{src/index.ts → dist/esm/index.d.ts} +1 -15
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/liquidatorTool.d.ts +158 -0
- package/dist/{src → esm}/liquidatorTool.js +10 -65
- package/dist/esm/liquidatorTool.js.map +1 -0
- package/dist/esm/liquidityProviderTool.d.ts +126 -0
- package/dist/esm/liquidityProviderTool.js +218 -0
- package/dist/esm/liquidityProviderTool.js.map +1 -0
- package/dist/esm/marketData.d.ts +309 -0
- package/dist/esm/marketData.js +1007 -0
- package/dist/esm/marketData.js.map +1 -0
- package/dist/esm/nodeSDKTypes.d.ts +266 -0
- package/dist/esm/nodeSDKTypes.js +60 -0
- package/dist/esm/nodeSDKTypes.js.map +1 -0
- package/dist/esm/orderReferrerTool.d.ts +196 -0
- package/dist/esm/orderReferrerTool.js +491 -0
- package/dist/esm/orderReferrerTool.js.map +1 -0
- package/dist/esm/perpetualDataHandler.d.ts +220 -0
- package/dist/esm/perpetualDataHandler.js +1060 -0
- package/dist/esm/perpetualDataHandler.js.map +1 -0
- package/dist/esm/perpetualEventHandler.d.ts +179 -0
- package/dist/esm/perpetualEventHandler.js +435 -0
- package/dist/esm/perpetualEventHandler.js.map +1 -0
- package/dist/esm/priceFeeds.d.ts +115 -0
- package/dist/{src → esm}/priceFeeds.js +16 -83
- package/dist/esm/priceFeeds.js.map +1 -0
- package/dist/esm/traderDigests.d.ts +21 -0
- package/dist/esm/traderDigests.js +80 -0
- package/dist/esm/traderDigests.js.map +1 -0
- package/dist/esm/traderInterface.d.ts +79 -0
- package/dist/esm/traderInterface.js +196 -0
- package/dist/esm/traderInterface.js.map +1 -0
- package/dist/esm/triangulator.d.ts +27 -0
- package/dist/esm/triangulator.js +110 -0
- package/dist/esm/triangulator.js.map +1 -0
- package/dist/esm/utils.d.ts +59 -0
- package/dist/esm/utils.js +138 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/writeAccessHandler.d.ts +50 -0
- package/dist/esm/writeAccessHandler.js +157 -0
- package/dist/esm/writeAccessHandler.js.map +1 -0
- package/package.json +16 -26
- package/dist/bundle.js +0 -36793
- package/dist/config/defaultConfig.json +0 -47
- package/dist/config/mockSwap.json +0 -4
- package/dist/config/priceFeedConfig.json +0 -104
- package/dist/config/symbolList.json +0 -13
- package/dist/src/index.js +0 -45
- package/dist/src/nodeSDKTypes.js +0 -115
- package/dist/src/version.d.ts +0 -1
- package/module.d.ts +0 -1
- package/src/accountTrade.ts +0 -392
- package/src/brokerTool.ts +0 -507
- package/src/d8XMath.ts +0 -319
- package/src/liquidatorTool.ts +0 -258
- package/src/liquidityProviderTool.ts +0 -186
- package/src/marketData.ts +0 -946
- package/src/nodeSDKTypes.ts +0 -293
- package/src/orderReferrerTool.ts +0 -389
- package/src/perpetualDataHandler.ts +0 -1061
- package/src/perpetualEventHandler.ts +0 -455
- package/src/priceFeeds.ts +0 -381
- package/src/traderDigests.ts +0 -91
- package/src/traderInterface.ts +0 -159
- package/src/triangulator.ts +0 -105
- package/src/utils.ts +0 -134
- package/src/version.ts +0 -1
- package/src/writeAccessHandler.ts +0 -127
- /package/dist/{abi → cjs/abi}/ERC20.json +0 -0
- /package/dist/{abi → cjs/abi}/MockTokenSwap.json +0 -0
- /package/dist/{abi → cjs/abi}/central-park/IPerpetualManager.json +0 -0
- /package/dist/{abi → cjs/abi}/central-park/LimitOrderBook.json +0 -0
- /package/dist/{abi → cjs/abi}/central-park/LimitOrderBookFactory.json +0 -0
- /package/dist/{abi → cjs/abi}/testnet/LimitOrderBookFactory.json +0 -0
- /package/dist/{src → cjs}/accountTrade.d.ts +0 -0
- /package/dist/{src → cjs}/brokerTool.d.ts +0 -0
- /package/dist/{src → cjs}/d8XMath.d.ts +0 -0
- /package/dist/{src → cjs}/d8XMath.js +0 -0
- /package/dist/{src → cjs}/index.d.ts +0 -0
- /package/dist/{src → cjs}/liquidatorTool.d.ts +0 -0
- /package/dist/{src → cjs}/liquidityProviderTool.d.ts +0 -0
- /package/dist/{src → cjs}/marketData.d.ts +0 -0
- /package/dist/{src → cjs}/priceFeeds.d.ts +0 -0
- /package/dist/{src → cjs}/traderDigests.d.ts +0 -0
- /package/dist/{src → cjs}/traderInterface.d.ts +0 -0
- /package/dist/{src → cjs}/triangulator.d.ts +0 -0
- /package/dist/{src → cjs}/utils.d.ts +0 -0
- /package/dist/{src → cjs}/writeAccessHandler.d.ts +0 -0
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
|
-
import { dec18ToFloat, floatToDec18 } from "./d8XMath";
|
|
3
|
-
import { ERC20_ABI, NodeSDKConfig } from "./nodeSDKTypes";
|
|
4
|
-
import PerpetualDataHandler from "./perpetualDataHandler";
|
|
5
|
-
import WriteAccessHandler from "./writeAccessHandler";
|
|
6
|
-
/**
|
|
7
|
-
* Functions to provide liquidity. This class requires a private key and executes
|
|
8
|
-
* smart-contract interactions that require gas-payments.
|
|
9
|
-
* @extends WriteAccessHandler
|
|
10
|
-
*/
|
|
11
|
-
export default class LiquidityProviderTool extends WriteAccessHandler {
|
|
12
|
-
/**
|
|
13
|
-
* Constructor
|
|
14
|
-
* @param {NodeSDKConfig} config Configuration object, see PerpetualDataHandler.
|
|
15
|
-
* readSDKConfig.
|
|
16
|
-
* @example
|
|
17
|
-
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
18
|
-
* async function main() {
|
|
19
|
-
* console.log(LiquidityProviderTool);
|
|
20
|
-
* // load configuration for testnet
|
|
21
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
22
|
-
* // LiquidityProviderTool (authentication required, PK is an environment variable with a private key)
|
|
23
|
-
* const pk: string = <string>process.env.PK;
|
|
24
|
-
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
25
|
-
* // Create a proxy instance to access the blockchain
|
|
26
|
-
* await lqudtProviderTool.createProxyInstance();
|
|
27
|
-
* }
|
|
28
|
-
* main();
|
|
29
|
-
*
|
|
30
|
-
* @param privateKey private key of account that trades
|
|
31
|
-
*/
|
|
32
|
-
public constructor(config: NodeSDKConfig, privateKey: string) {
|
|
33
|
-
super(config, privateKey);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Value of the pool share tokens for this liquidity provider
|
|
38
|
-
* in poolSymbol-currency (e.g. MATIC, USDC).
|
|
39
|
-
* @param {string} poolSymbolName Pool symbol name (e.g. MATIC).
|
|
40
|
-
* @example
|
|
41
|
-
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
42
|
-
* async function main() {
|
|
43
|
-
* console.log(LiquidityProviderTool);
|
|
44
|
-
* // setup (authentication required, PK is an environment variable with a private key)
|
|
45
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
46
|
-
* const pk: string = <string>process.env.PK;
|
|
47
|
-
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
48
|
-
* await lqudtProviderTool.createProxyInstance();
|
|
49
|
-
* // get value of pool share token
|
|
50
|
-
* let shareToken = await lqudtProviderTool.getParticipationValue("MATIC");
|
|
51
|
-
* console.log(shareToken);
|
|
52
|
-
* }
|
|
53
|
-
* main();
|
|
54
|
-
*
|
|
55
|
-
* @return Value in poolSymbol-currency (e.g. MATIC, USDC), balance of pool share tokens, and share token symbol.
|
|
56
|
-
*/
|
|
57
|
-
public async getParticipationValue(
|
|
58
|
-
poolSymbolName: string
|
|
59
|
-
): Promise<{ value: number; shareTokenBalance: number; poolShareToken: string }> {
|
|
60
|
-
if (
|
|
61
|
-
this.proxyContract == null ||
|
|
62
|
-
this.signer == null ||
|
|
63
|
-
this.poolStaticInfos.length == 0 ||
|
|
64
|
-
this.provider == null
|
|
65
|
-
) {
|
|
66
|
-
throw Error("no proxy contract or wallet or data initialized. Use createProxyInstance().");
|
|
67
|
-
}
|
|
68
|
-
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
69
|
-
|
|
70
|
-
let shareTokenAddr = this.poolStaticInfos[poolId - 1].shareTokenAddr;
|
|
71
|
-
let shareToken = new ethers.Contract(shareTokenAddr, ERC20_ABI, this.signer);
|
|
72
|
-
let dShareTokenBalanceOfAddr = await shareToken.balanceOf(this.traderAddr);
|
|
73
|
-
|
|
74
|
-
let valueCCDec18 = await this.proxyContract.getTokenAmountToReturn(poolId, dShareTokenBalanceOfAddr);
|
|
75
|
-
|
|
76
|
-
let shareTokenBalanceOfAddr = dec18ToFloat(dShareTokenBalanceOfAddr);
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
value: dec18ToFloat(valueCCDec18),
|
|
80
|
-
shareTokenBalance: shareTokenBalanceOfAddr,
|
|
81
|
-
poolShareToken: shareTokenAddr,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Add liquidity to the PnL participant fund. The address gets pool shares in return.
|
|
87
|
-
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC)
|
|
88
|
-
* @param {number} amountCC Amount in pool-collateral currency
|
|
89
|
-
* @example
|
|
90
|
-
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
91
|
-
* async function main() {
|
|
92
|
-
* console.log(LiquidityProviderTool);
|
|
93
|
-
* // setup (authentication required, PK is an environment variable with a private key)
|
|
94
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
95
|
-
* const pk: string = <string>process.env.PK;
|
|
96
|
-
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
97
|
-
* await lqudtProviderTool.createProxyInstance();
|
|
98
|
-
* // add liquidity
|
|
99
|
-
* await lqudtProviderTool.setAllowance("MATIC");
|
|
100
|
-
* let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
|
|
101
|
-
* console.log(respAddLiquidity);
|
|
102
|
-
* }
|
|
103
|
-
* main();
|
|
104
|
-
*
|
|
105
|
-
* @return Transaction object
|
|
106
|
-
*/
|
|
107
|
-
public async addLiquidity(poolSymbolName: string, amountCC: number): Promise<ethers.ContractTransaction> {
|
|
108
|
-
if (this.proxyContract == null || this.signer == null) {
|
|
109
|
-
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
110
|
-
}
|
|
111
|
-
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
112
|
-
let tx = await this.proxyContract.addLiquidity(poolId, floatToDec18(amountCC), {
|
|
113
|
-
gasLimit: this.gasLimit,
|
|
114
|
-
});
|
|
115
|
-
return tx;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Initiates a liquidity withdrawal from the pool
|
|
120
|
-
* It triggers a time-delayed unlocking of the given number of pool shares.
|
|
121
|
-
* The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.
|
|
122
|
-
* @param {string} poolSymbolName Name of pool symbol (e.g. MATIC).
|
|
123
|
-
* @param {string} amountPoolShares Amount in pool-shares, removes everything if > available amount.
|
|
124
|
-
* @example
|
|
125
|
-
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
126
|
-
* async function main() {
|
|
127
|
-
* console.log(LiquidityProviderTool);
|
|
128
|
-
* // setup (authentication required, PK is an environment variable with a private key)
|
|
129
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
130
|
-
* const pk: string = <string>process.env.PK;
|
|
131
|
-
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
132
|
-
* await lqudtProviderTool.createProxyInstance();
|
|
133
|
-
* // initiate withdrawal
|
|
134
|
-
* let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
|
|
135
|
-
* console.log(respRemoveLiquidity);
|
|
136
|
-
* }
|
|
137
|
-
* main();
|
|
138
|
-
*
|
|
139
|
-
* @return Transaction object.
|
|
140
|
-
*/
|
|
141
|
-
public async initiateLiquidityWithdrawal(
|
|
142
|
-
poolSymbolName: string,
|
|
143
|
-
amountPoolShares: number
|
|
144
|
-
): Promise<ethers.providers.TransactionResponse> {
|
|
145
|
-
if (this.proxyContract == null || this.signer == null) {
|
|
146
|
-
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
147
|
-
}
|
|
148
|
-
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
149
|
-
let tx = await this.proxyContract.withdrawLiquidity(poolId, floatToDec18(amountPoolShares), {
|
|
150
|
-
gasLimit: this.gasLimit,
|
|
151
|
-
});
|
|
152
|
-
return tx;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal.
|
|
157
|
-
* The address loses pool shares in return.
|
|
158
|
-
* @param poolSymbolName
|
|
159
|
-
* @example
|
|
160
|
-
* import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
|
|
161
|
-
* async function main() {
|
|
162
|
-
* console.log(LiquidityProviderTool);
|
|
163
|
-
* // setup (authentication required, PK is an environment variable with a private key)
|
|
164
|
-
* const config = PerpetualDataHandler.readSDKConfig("testnet");
|
|
165
|
-
* const pk: string = <string>process.env.PK;
|
|
166
|
-
* let lqudtProviderTool = new LiquidityProviderTool(config, pk);
|
|
167
|
-
* await lqudtProviderTool.createProxyInstance();
|
|
168
|
-
* // remove liquidity
|
|
169
|
-
* let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
|
|
170
|
-
* console.log(respRemoveLiquidity);
|
|
171
|
-
* }
|
|
172
|
-
* main();
|
|
173
|
-
*
|
|
174
|
-
* @returns Transaction object.
|
|
175
|
-
*/
|
|
176
|
-
public async executeLiquidityWithdrawal(poolSymbolName: string): Promise<ethers.providers.TransactionResponse> {
|
|
177
|
-
if (this.proxyContract == null || this.signer == null) {
|
|
178
|
-
throw Error("no proxy contract or wallet initialized. Use createProxyInstance().");
|
|
179
|
-
}
|
|
180
|
-
let poolId = PerpetualDataHandler._getPoolIdFromSymbol(poolSymbolName, this.poolStaticInfos);
|
|
181
|
-
let tx = await this.proxyContract.executeLiquidityWithdrawal(poolId, {
|
|
182
|
-
gasLimit: this.gasLimit,
|
|
183
|
-
});
|
|
184
|
-
return tx;
|
|
185
|
-
}
|
|
186
|
-
}
|