@drift-labs/sdk 0.1.30-master.1 → 0.1.30-master.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/lib/accounts/bulkAccountLoader.js +1 -1
- package/lib/constants/markets.js +11 -8
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +31 -20
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +1 -1
- package/src/constants/markets.ts +11 -8
- package/src/tx/retryTxSender.ts +42 -26
- package/src/assert/assert.js +0 -10
- package/src/assert/assert.js.map +0 -1
- package/src/math/conversion.js +0 -16
- package/src/math/conversion.js.map +0 -1
- package/src/math/funding.js +0 -223
- package/src/math/funding.js.map +0 -1
- package/src/math/insuranceFund.js +0 -23
- package/src/math/insuranceFund.js.map +0 -1
- package/src/math/market.js +0 -30
- package/src/math/market.js.map +0 -1
- package/src/math/orders.js +0 -73
- package/src/math/orders.js.map +0 -1
- package/src/math/position.js +0 -121
- package/src/math/position.js.map +0 -1
- package/src/math/trade.js +0 -182
- package/src/math/trade.js.map +0 -1
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/oracles/switchboardClient.js +0 -60
- package/src/oracles/switchboardClient.js.map +0 -1
- package/src/oracles/types.js +0 -3
- package/src/oracles/types.js.map +0 -1
- package/src/token/index.js +0 -39
- package/src/token/index.js.map +0 -1
- package/src/tx/defaultTxSender.js +0 -13
- package/src/tx/defaultTxSender.js.map +0 -1
- package/src/tx/types.js +0 -3
- package/src/tx/types.js.map +0 -1
- package/src/tx/utils.js +0 -9
- package/src/tx/utils.js.map +0 -1
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
- package/src/util/tps.js +0 -17
- package/src/util/tps.js.map +0 -1
|
@@ -175,7 +175,7 @@ class BulkAccountLoader {
|
|
|
175
175
|
this.log('unable to update account for newest slot');
|
|
176
176
|
this.log('oldBuffer ' + oldBuffer);
|
|
177
177
|
this.log('newBuffer ' + newBuffer);
|
|
178
|
-
this.log('buffers equal ' + newBuffer.equals(oldBuffer));
|
|
178
|
+
this.log('buffers equal ' + (newBuffer === null || newBuffer === void 0 ? void 0 : newBuffer.equals(oldBuffer)));
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
});
|
package/lib/constants/markets.js
CHANGED
|
@@ -188,12 +188,15 @@ exports.Markets = [
|
|
|
188
188
|
launchTs: 1649105516000,
|
|
189
189
|
oracleSource: __1.OracleSource.PYTH,
|
|
190
190
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
{
|
|
192
|
+
fullName: 'Serum',
|
|
193
|
+
category: ['DEX'],
|
|
194
|
+
symbol: 'SRM-PERP',
|
|
195
|
+
baseAssetSymbol: 'SRM',
|
|
196
|
+
marketIndex: new __1.BN(17),
|
|
197
|
+
devnetPublicKey: '992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs',
|
|
198
|
+
mainnetPublicKey: '3NBReDRTLKMQEKiLD5tGcx4kXbTf88b7f2xLS9UuGjym',
|
|
199
|
+
launchTs: 1649877367000,
|
|
200
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
201
|
+
},
|
|
199
202
|
];
|
|
@@ -16,7 +16,7 @@ export declare class RetryTxSender implements TxSender {
|
|
|
16
16
|
confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
17
17
|
getTimestamp(): number;
|
|
18
18
|
sleep(reference: ResolveReference): Promise<void>;
|
|
19
|
-
promiseTimeout<T>(
|
|
19
|
+
promiseTimeout<T>(promises: Promise<T>[], timeoutMs: number): Promise<T | null>;
|
|
20
20
|
sendToAdditionalConnections(rawTx: Buffer, opts: ConfirmOptions): void;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -99,29 +99,40 @@ class RetryTxSender {
|
|
|
99
99
|
(0, assert_1.default)(decodedSignature.length === 64, 'signature has invalid length');
|
|
100
100
|
const start = Date.now();
|
|
101
101
|
const subscriptionCommitment = commitment || this.provider.opts.commitment;
|
|
102
|
-
|
|
102
|
+
const subscriptionIds = new Array();
|
|
103
|
+
const connections = [
|
|
104
|
+
this.provider.connection,
|
|
105
|
+
...this.additionalConnections,
|
|
106
|
+
];
|
|
103
107
|
let response = null;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
const promises = connections.map((connection, i) => {
|
|
109
|
+
let subscriptionId;
|
|
110
|
+
const confirmPromise = new Promise((resolve, reject) => {
|
|
111
|
+
try {
|
|
112
|
+
subscriptionId = connection.onSignature(signature, (result, context) => {
|
|
113
|
+
subscriptionIds[i] = undefined;
|
|
114
|
+
response = {
|
|
115
|
+
context,
|
|
116
|
+
value: result,
|
|
117
|
+
};
|
|
118
|
+
resolve(null);
|
|
119
|
+
}, subscriptionCommitment);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
reject(err);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
subscriptionIds.push(subscriptionId);
|
|
126
|
+
return confirmPromise;
|
|
118
127
|
});
|
|
119
128
|
try {
|
|
120
|
-
yield this.promiseTimeout(
|
|
129
|
+
yield this.promiseTimeout(promises, this.timeout);
|
|
121
130
|
}
|
|
122
131
|
finally {
|
|
123
|
-
|
|
124
|
-
|
|
132
|
+
for (const [i, subscriptionId] of subscriptionIds.entries()) {
|
|
133
|
+
if (subscriptionId) {
|
|
134
|
+
connections[i].removeSignatureListener(subscriptionId);
|
|
135
|
+
}
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
138
|
if (response === null) {
|
|
@@ -142,12 +153,12 @@ class RetryTxSender {
|
|
|
142
153
|
});
|
|
143
154
|
});
|
|
144
155
|
}
|
|
145
|
-
promiseTimeout(
|
|
156
|
+
promiseTimeout(promises, timeoutMs) {
|
|
146
157
|
let timeoutId;
|
|
147
158
|
const timeoutPromise = new Promise((resolve) => {
|
|
148
159
|
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
149
160
|
});
|
|
150
|
-
return Promise.race([
|
|
161
|
+
return Promise.race([...promises, timeoutPromise]).then((result) => {
|
|
151
162
|
clearTimeout(timeoutId);
|
|
152
163
|
return result;
|
|
153
164
|
});
|
package/package.json
CHANGED
|
@@ -215,7 +215,7 @@ export class BulkAccountLoader {
|
|
|
215
215
|
this.log('unable to update account for newest slot');
|
|
216
216
|
this.log('oldBuffer ' + oldBuffer);
|
|
217
217
|
this.log('newBuffer ' + newBuffer);
|
|
218
|
-
this.log('buffers equal ' + newBuffer
|
|
218
|
+
this.log('buffers equal ' + newBuffer?.equals(oldBuffer));
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
package/src/constants/markets.ts
CHANGED
|
@@ -198,12 +198,15 @@ export const Markets: MarketConfig[] = [
|
|
|
198
198
|
launchTs: 1649105516000,
|
|
199
199
|
oracleSource: OracleSource.PYTH,
|
|
200
200
|
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
201
|
+
{
|
|
202
|
+
fullName: 'Serum',
|
|
203
|
+
category: ['DEX'],
|
|
204
|
+
symbol: 'SRM-PERP',
|
|
205
|
+
baseAssetSymbol: 'SRM',
|
|
206
|
+
marketIndex: new BN(17),
|
|
207
|
+
devnetPublicKey: '992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs',
|
|
208
|
+
mainnetPublicKey: '3NBReDRTLKMQEKiLD5tGcx4kXbTf88b7f2xLS9UuGjym',
|
|
209
|
+
launchTs: 1649877367000,
|
|
210
|
+
oracleSource: OracleSource.PYTH,
|
|
211
|
+
},
|
|
209
212
|
];
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -136,32 +136,43 @@ export class RetryTxSender implements TxSender {
|
|
|
136
136
|
const start = Date.now();
|
|
137
137
|
const subscriptionCommitment = commitment || this.provider.opts.commitment;
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
const subscriptionIds = new Array<number>();
|
|
140
|
+
const connections = [
|
|
141
|
+
this.provider.connection,
|
|
142
|
+
...this.additionalConnections,
|
|
143
|
+
];
|
|
140
144
|
let response: RpcResponseAndContext<SignatureResult> | null = null;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
const promises = connections.map((connection, i) => {
|
|
146
|
+
let subscriptionId;
|
|
147
|
+
const confirmPromise = new Promise((resolve, reject) => {
|
|
148
|
+
try {
|
|
149
|
+
subscriptionId = connection.onSignature(
|
|
150
|
+
signature,
|
|
151
|
+
(result: SignatureResult, context: Context) => {
|
|
152
|
+
subscriptionIds[i] = undefined;
|
|
153
|
+
response = {
|
|
154
|
+
context,
|
|
155
|
+
value: result,
|
|
156
|
+
};
|
|
157
|
+
resolve(null);
|
|
158
|
+
},
|
|
159
|
+
subscriptionCommitment
|
|
160
|
+
);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
reject(err);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
subscriptionIds.push(subscriptionId);
|
|
166
|
+
return confirmPromise;
|
|
158
167
|
});
|
|
159
168
|
|
|
160
169
|
try {
|
|
161
|
-
await this.promiseTimeout(
|
|
170
|
+
await this.promiseTimeout(promises, this.timeout);
|
|
162
171
|
} finally {
|
|
163
|
-
|
|
164
|
-
|
|
172
|
+
for (const [i, subscriptionId] of subscriptionIds.entries()) {
|
|
173
|
+
if (subscriptionId) {
|
|
174
|
+
connections[i].removeSignatureListener(subscriptionId);
|
|
175
|
+
}
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
178
|
|
|
@@ -188,16 +199,21 @@ export class RetryTxSender implements TxSender {
|
|
|
188
199
|
});
|
|
189
200
|
}
|
|
190
201
|
|
|
191
|
-
promiseTimeout<T>(
|
|
202
|
+
promiseTimeout<T>(
|
|
203
|
+
promises: Promise<T>[],
|
|
204
|
+
timeoutMs: number
|
|
205
|
+
): Promise<T | null> {
|
|
192
206
|
let timeoutId: ReturnType<typeof setTimeout>;
|
|
193
207
|
const timeoutPromise: Promise<null> = new Promise((resolve) => {
|
|
194
208
|
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
195
209
|
});
|
|
196
210
|
|
|
197
|
-
return Promise.race([
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
return Promise.race([...promises, timeoutPromise]).then(
|
|
212
|
+
(result: T | null) => {
|
|
213
|
+
clearTimeout(timeoutId);
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
);
|
|
201
217
|
}
|
|
202
218
|
|
|
203
219
|
sendToAdditionalConnections(rawTx: Buffer, opts: ConfirmOptions): void {
|
package/src/assert/assert.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assert = void 0;
|
|
4
|
-
function assert(condition, error) {
|
|
5
|
-
if (!condition) {
|
|
6
|
-
throw new Error(error || 'Unspecified AssertionError');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.assert = assert;
|
|
10
|
-
//# sourceMappingURL=assert.js.map
|
package/src/assert/assert.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["assert.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,SAAkB,EAAE,KAAc;IACxD,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,4BAA4B,CAAC,CAAC;KACvD;AACF,CAAC;AAJD,wBAIC"}
|
package/src/math/conversion.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertBaseAssetAmountToNumber = exports.convertToNumber = void 0;
|
|
4
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
5
|
-
const convertToNumber = (bigNumber, precision = numericConstants_1.MARK_PRICE_PRECISION) => {
|
|
6
|
-
if (!bigNumber)
|
|
7
|
-
return 0;
|
|
8
|
-
return (bigNumber.div(precision).toNumber() +
|
|
9
|
-
bigNumber.mod(precision).toNumber() / precision.toNumber());
|
|
10
|
-
};
|
|
11
|
-
exports.convertToNumber = convertToNumber;
|
|
12
|
-
const convertBaseAssetAmountToNumber = (baseAssetAmount) => {
|
|
13
|
-
return (0, exports.convertToNumber)(baseAssetAmount, numericConstants_1.MARK_PRICE_PRECISION.mul(numericConstants_1.PEG_PRECISION));
|
|
14
|
-
};
|
|
15
|
-
exports.convertBaseAssetAmountToNumber = convertBaseAssetAmountToNumber;
|
|
16
|
-
//# sourceMappingURL=conversion.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["conversion.ts"],"names":[],"mappings":";;;AACA,oEAGuC;AAEhC,MAAM,eAAe,GAAG,CAC9B,SAAa,EACb,YAAgB,uCAAoB,EACnC,EAAE;IACH,IAAI,CAAC,SAAS;QAAE,OAAO,CAAC,CAAC;IACzB,OAAO,CACN,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;QACnC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAC1D,CAAC;AACH,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEK,MAAM,8BAA8B,GAAG,CAAC,eAAmB,EAAE,EAAE;IACrE,OAAO,IAAA,uBAAe,EACrB,eAAe,EACf,uCAAoB,CAAC,GAAG,CAAC,gCAAa,CAAC,CACvC,CAAC;AACH,CAAC,CAAC;AALW,QAAA,8BAA8B,kCAKzC"}
|
package/src/math/funding.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateFundingPool = exports.calculateLongShortFundingRateAndLiveTwaps = exports.calculateLongShortFundingRate = exports.calculateEstimatedFundingRate = exports.calculateAllEstimatedFundingRate = void 0;
|
|
4
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
5
|
-
const numericConstants_1 = require("../constants/numericConstants");
|
|
6
|
-
const market_1 = require("./market");
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param market
|
|
10
|
-
* @param oraclePriceData
|
|
11
|
-
* @param periodAdjustment
|
|
12
|
-
* @returns Estimated funding rate. : Precision //TODO-PRECISION
|
|
13
|
-
*/
|
|
14
|
-
async function calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustment = new anchor_1.BN(1)) {
|
|
15
|
-
// periodAdjustment
|
|
16
|
-
// 1: hourly
|
|
17
|
-
// 24: daily
|
|
18
|
-
// 24 * 365.25: annualized
|
|
19
|
-
const secondsInHour = new anchor_1.BN(3600);
|
|
20
|
-
const hoursInDay = new anchor_1.BN(24);
|
|
21
|
-
if (!market.initialized) {
|
|
22
|
-
return [numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
23
|
-
}
|
|
24
|
-
const payFreq = new anchor_1.BN(market.amm.fundingPeriod);
|
|
25
|
-
// todo: sufficiently differs from blockchain timestamp?
|
|
26
|
-
const now = new anchor_1.BN((Date.now() / 1000).toFixed(0));
|
|
27
|
-
const timeSinceLastUpdate = now.sub(market.amm.lastFundingRateTs);
|
|
28
|
-
// calculate real-time mark twap
|
|
29
|
-
const lastMarkTwapWithMantissa = market.amm.lastMarkPriceTwap;
|
|
30
|
-
const lastMarkPriceTwapTs = market.amm.lastMarkPriceTwapTs;
|
|
31
|
-
const timeSinceLastMarkChange = now.sub(lastMarkPriceTwapTs);
|
|
32
|
-
const markTwapTimeSinceLastUpdate = anchor_1.BN.max(secondsInHour, secondsInHour.sub(timeSinceLastMarkChange));
|
|
33
|
-
const baseAssetPriceWithMantissa = (0, market_1.calculateMarkPrice)(market);
|
|
34
|
-
const markTwapWithMantissa = markTwapTimeSinceLastUpdate
|
|
35
|
-
.mul(lastMarkTwapWithMantissa)
|
|
36
|
-
.add(timeSinceLastMarkChange.mul(baseAssetPriceWithMantissa))
|
|
37
|
-
.div(timeSinceLastMarkChange.add(markTwapTimeSinceLastUpdate));
|
|
38
|
-
// calculate real-time (predicted) oracle twap
|
|
39
|
-
// note: oracle twap depends on `when the chord is struck` (market is trade)
|
|
40
|
-
const lastOracleTwapWithMantissa = market.amm.lastOraclePriceTwap;
|
|
41
|
-
const lastOraclePriceTwapTs = market.amm.lastOraclePriceTwapTs;
|
|
42
|
-
const timeSinceLastOracleTwapUpdate = now.sub(lastOraclePriceTwapTs);
|
|
43
|
-
const oracleTwapTimeSinceLastUpdate = anchor_1.BN.max(secondsInHour, secondsInHour.sub(timeSinceLastOracleTwapUpdate));
|
|
44
|
-
const oraclePrice = oraclePriceData.price;
|
|
45
|
-
let oracleTwapWithMantissa = lastOracleTwapWithMantissa;
|
|
46
|
-
const oracleLiveVsTwap = oraclePrice
|
|
47
|
-
.sub(lastOracleTwapWithMantissa)
|
|
48
|
-
.abs()
|
|
49
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
50
|
-
.mul(new anchor_1.BN(100))
|
|
51
|
-
.div(lastOracleTwapWithMantissa);
|
|
52
|
-
// verify pyth live input is within 10% of last twap for live update
|
|
53
|
-
if (oracleLiveVsTwap.lte(numericConstants_1.MARK_PRICE_PRECISION.mul(new anchor_1.BN(10)))) {
|
|
54
|
-
oracleTwapWithMantissa = oracleTwapTimeSinceLastUpdate
|
|
55
|
-
.mul(lastOracleTwapWithMantissa)
|
|
56
|
-
.add(timeSinceLastMarkChange.mul(oraclePrice))
|
|
57
|
-
.div(timeSinceLastOracleTwapUpdate.add(oracleTwapTimeSinceLastUpdate));
|
|
58
|
-
}
|
|
59
|
-
const twapSpread = lastMarkTwapWithMantissa.sub(lastOracleTwapWithMantissa);
|
|
60
|
-
const twapSpreadPct = twapSpread
|
|
61
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
62
|
-
.mul(new anchor_1.BN(100))
|
|
63
|
-
.div(oracleTwapWithMantissa);
|
|
64
|
-
const lowerboundEst = twapSpreadPct
|
|
65
|
-
.mul(payFreq)
|
|
66
|
-
.mul(anchor_1.BN.min(secondsInHour, timeSinceLastUpdate))
|
|
67
|
-
.mul(periodAdjustment)
|
|
68
|
-
.div(secondsInHour)
|
|
69
|
-
.div(secondsInHour)
|
|
70
|
-
.div(hoursInDay);
|
|
71
|
-
const interpEst = twapSpreadPct.mul(periodAdjustment).div(hoursInDay);
|
|
72
|
-
const interpRateQuote = twapSpreadPct
|
|
73
|
-
.mul(periodAdjustment)
|
|
74
|
-
.div(hoursInDay)
|
|
75
|
-
.div(numericConstants_1.MARK_PRICE_PRECISION.div(numericConstants_1.QUOTE_PRECISION));
|
|
76
|
-
let feePoolSize = calculateFundingPool(market);
|
|
77
|
-
if (interpRateQuote.lt(new anchor_1.BN(0))) {
|
|
78
|
-
feePoolSize = feePoolSize.mul(new anchor_1.BN(-1));
|
|
79
|
-
}
|
|
80
|
-
let cappedAltEst;
|
|
81
|
-
let largerSide;
|
|
82
|
-
let smallerSide;
|
|
83
|
-
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort.abs())) {
|
|
84
|
-
largerSide = market.baseAssetAmountLong.abs();
|
|
85
|
-
smallerSide = market.baseAssetAmountShort.abs();
|
|
86
|
-
if (twapSpread.gt(new anchor_1.BN(0))) {
|
|
87
|
-
return [
|
|
88
|
-
markTwapWithMantissa,
|
|
89
|
-
oracleTwapWithMantissa,
|
|
90
|
-
lowerboundEst,
|
|
91
|
-
interpEst,
|
|
92
|
-
interpEst,
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort.abs())) {
|
|
97
|
-
largerSide = market.baseAssetAmountShort.abs();
|
|
98
|
-
smallerSide = market.baseAssetAmountLong.abs();
|
|
99
|
-
if (twapSpread.lt(new anchor_1.BN(0))) {
|
|
100
|
-
return [
|
|
101
|
-
markTwapWithMantissa,
|
|
102
|
-
oracleTwapWithMantissa,
|
|
103
|
-
lowerboundEst,
|
|
104
|
-
interpEst,
|
|
105
|
-
interpEst,
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return [
|
|
111
|
-
markTwapWithMantissa,
|
|
112
|
-
oracleTwapWithMantissa,
|
|
113
|
-
lowerboundEst,
|
|
114
|
-
interpEst,
|
|
115
|
-
interpEst,
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
if (largerSide.gt(numericConstants_1.ZERO)) {
|
|
119
|
-
// funding smaller flow
|
|
120
|
-
cappedAltEst = smallerSide.mul(twapSpread).div(hoursInDay);
|
|
121
|
-
const feePoolTopOff = feePoolSize
|
|
122
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION.div(numericConstants_1.QUOTE_PRECISION))
|
|
123
|
-
.mul(numericConstants_1.AMM_RESERVE_PRECISION);
|
|
124
|
-
cappedAltEst = cappedAltEst.add(feePoolTopOff).div(largerSide);
|
|
125
|
-
cappedAltEst = cappedAltEst
|
|
126
|
-
.mul(numericConstants_1.MARK_PRICE_PRECISION)
|
|
127
|
-
.mul(new anchor_1.BN(100))
|
|
128
|
-
.div(oracleTwapWithMantissa)
|
|
129
|
-
.mul(periodAdjustment);
|
|
130
|
-
if (cappedAltEst.abs().gte(interpEst.abs())) {
|
|
131
|
-
cappedAltEst = interpEst;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
cappedAltEst = interpEst;
|
|
136
|
-
}
|
|
137
|
-
return [
|
|
138
|
-
markTwapWithMantissa,
|
|
139
|
-
oracleTwapWithMantissa,
|
|
140
|
-
lowerboundEst,
|
|
141
|
-
cappedAltEst,
|
|
142
|
-
interpEst,
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
|
-
exports.calculateAllEstimatedFundingRate = calculateAllEstimatedFundingRate;
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param market
|
|
149
|
-
* @param oraclePriceData
|
|
150
|
-
* @param periodAdjustment
|
|
151
|
-
* @param estimationMethod
|
|
152
|
-
* @returns Estimated funding rate. : Precision //TODO-PRECISION
|
|
153
|
-
*/
|
|
154
|
-
async function calculateEstimatedFundingRate(market, oraclePriceData, periodAdjustment = new anchor_1.BN(1), estimationMethod) {
|
|
155
|
-
const [_1, _2, lowerboundEst, cappedAltEst, interpEst] = await calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustment);
|
|
156
|
-
if (estimationMethod == 'lowerbound') {
|
|
157
|
-
//assuming remaining funding period has no gap
|
|
158
|
-
return lowerboundEst;
|
|
159
|
-
}
|
|
160
|
-
else if (estimationMethod == 'capped') {
|
|
161
|
-
return cappedAltEst;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
return interpEst;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.calculateEstimatedFundingRate = calculateEstimatedFundingRate;
|
|
168
|
-
/**
|
|
169
|
-
*
|
|
170
|
-
* @param market
|
|
171
|
-
* @param oraclePriceData
|
|
172
|
-
* @param periodAdjustment
|
|
173
|
-
* @returns Estimated funding rate. : Precision //TODO-PRECISION
|
|
174
|
-
*/
|
|
175
|
-
async function calculateLongShortFundingRate(market, oraclePriceData, periodAdjustment = new anchor_1.BN(1)) {
|
|
176
|
-
const [_1, _2, _, cappedAltEst, interpEst] = await calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustment);
|
|
177
|
-
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort)) {
|
|
178
|
-
return [cappedAltEst, interpEst];
|
|
179
|
-
}
|
|
180
|
-
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort)) {
|
|
181
|
-
return [interpEst, cappedAltEst];
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
return [interpEst, interpEst];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
exports.calculateLongShortFundingRate = calculateLongShortFundingRate;
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* @param market
|
|
191
|
-
* @param oraclePriceData
|
|
192
|
-
* @param periodAdjustment
|
|
193
|
-
* @returns Estimated funding rate. : Precision //TODO-PRECISION
|
|
194
|
-
*/
|
|
195
|
-
async function calculateLongShortFundingRateAndLiveTwaps(market, oraclePriceData, periodAdjustment = new anchor_1.BN(1)) {
|
|
196
|
-
const [markTwapLive, oracleTwapLive, _2, cappedAltEst, interpEst] = await calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustment);
|
|
197
|
-
if (market.baseAssetAmountLong.gt(market.baseAssetAmountShort.abs())) {
|
|
198
|
-
return [markTwapLive, oracleTwapLive, cappedAltEst, interpEst];
|
|
199
|
-
}
|
|
200
|
-
else if (market.baseAssetAmountLong.lt(market.baseAssetAmountShort.abs())) {
|
|
201
|
-
return [markTwapLive, oracleTwapLive, interpEst, cappedAltEst];
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
return [markTwapLive, oracleTwapLive, interpEst, interpEst];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
exports.calculateLongShortFundingRateAndLiveTwaps = calculateLongShortFundingRateAndLiveTwaps;
|
|
208
|
-
/**
|
|
209
|
-
*
|
|
210
|
-
* @param market
|
|
211
|
-
* @returns Estimated fee pool size
|
|
212
|
-
*/
|
|
213
|
-
function calculateFundingPool(market) {
|
|
214
|
-
// todo
|
|
215
|
-
const totalFeeLB = market.amm.totalFee.div(new anchor_1.BN(2));
|
|
216
|
-
const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions
|
|
217
|
-
.sub(totalFeeLB)
|
|
218
|
-
.mul(new anchor_1.BN(2))
|
|
219
|
-
.div(new anchor_1.BN(3)));
|
|
220
|
-
return feePool;
|
|
221
|
-
}
|
|
222
|
-
exports.calculateFundingPool = calculateFundingPool;
|
|
223
|
-
//# sourceMappingURL=funding.js.map
|
package/src/math/funding.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"funding.js","sourceRoot":"","sources":["funding.ts"],"names":[],"mappings":";;;AAAA,kDAA2C;AAC3C,oEAKuC;AAEvC,qCAA8C;AAG9C;;;;;;GAMG;AACI,KAAK,UAAU,gCAAgC,CACrD,MAAc,EACd,eAAgC,EAChC,mBAAuB,IAAI,WAAE,CAAC,CAAC,CAAC;IAEhC,mBAAmB;IACnB,aAAa;IACb,aAAa;IACb,2BAA2B;IAC3B,MAAM,aAAa,GAAG,IAAI,WAAE,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,WAAE,CAAC,EAAE,CAAC,CAAC;IAE9B,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;QACxB,OAAO,CAAC,uBAAI,EAAE,uBAAI,EAAE,uBAAI,EAAE,uBAAI,EAAE,uBAAI,CAAC,CAAC;KACtC;IAED,MAAM,OAAO,GAAG,IAAI,WAAE,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAEjD,wDAAwD;IACxD,MAAM,GAAG,GAAG,IAAI,WAAE,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AAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC,EAAE;QAC5E,OAAO,CAAC,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;KAC/D;SAAM;QACN,OAAO,CAAC,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;KAC5D;AACF,CAAC;AAnBD,8FAmBC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,MAAc;IAClD,OAAO;IACP,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,WAAE,CAAC,GAAG,CACrB,uBAAI,EACJ,MAAM,CAAC,GAAG,CAAC,0BAA0B;SACnC,GAAG,CAAC,UAAU,CAAC;SACf,GAAG,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,CAAC;SACd,GAAG,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,CAAC,CAChB,CAAC;IACF,OAAO,OAAO,CAAC;AAChB,CAAC;AAXD,oDAWC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateInsuranceFundSize = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
/**
|
|
6
|
-
* In the case of a levered loss, the exchange first pays out undistributed fees and then the insurance fund.
|
|
7
|
-
* Thus the de facto size of the insurance fund is the amount in the insurance vault plus the sum of each markets
|
|
8
|
-
* undistributed fees.
|
|
9
|
-
*
|
|
10
|
-
* @param connection
|
|
11
|
-
* @param state
|
|
12
|
-
* @param marketsAccount
|
|
13
|
-
* @returns Precision : QUOTE_ASSET_PRECISION
|
|
14
|
-
*/
|
|
15
|
-
async function calculateInsuranceFundSize(connection, state, marketsAccount) {
|
|
16
|
-
const insuranceVaultPublicKey = state.insuranceVault;
|
|
17
|
-
const insuranceVaultAmount = new __1.BN((await connection.getTokenAccountBalance(insuranceVaultPublicKey)).value.amount);
|
|
18
|
-
return marketsAccount.markets.reduce((insuranceVaultAmount, market) => {
|
|
19
|
-
return insuranceVaultAmount.add(market.amm.totalFee.div(new __1.BN(2)));
|
|
20
|
-
}, insuranceVaultAmount);
|
|
21
|
-
}
|
|
22
|
-
exports.calculateInsuranceFundSize = calculateInsuranceFundSize;
|
|
23
|
-
//# sourceMappingURL=insuranceFund.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insuranceFund.js","sourceRoot":"","sources":["insuranceFund.ts"],"names":[],"mappings":";;;AACA,2BAAyB;AAGzB;;;;;;;;;GASG;AACI,KAAK,UAAU,0BAA0B,CAC/C,UAAsB,EACtB,KAAmB,EACnB,cAA8B;IAE9B,MAAM,uBAAuB,GAAG,KAAK,CAAC,cAAc,CAAC;IACrD,MAAM,oBAAoB,GAAG,IAAI,MAAE,CAClC,CACC,MAAM,UAAU,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,CAChE,CAAC,KAAK,CAAC,MAAM,CACd,CAAC;IACF,OAAO,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,MAAM,EAAE,EAAE;QACrE,OAAO,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAC1B,CAAC;AAdD,gEAcC"}
|
package/src/math/market.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateOracleMarkSpread = exports.calculateNewMarketAfterTrade = exports.calculateMarkPrice = void 0;
|
|
4
|
-
const amm_1 = require("./amm");
|
|
5
|
-
/**
|
|
6
|
-
* Calculates market mark price
|
|
7
|
-
*
|
|
8
|
-
* @param market
|
|
9
|
-
* @return markPrice : Precision MARK_PRICE_PRECISION
|
|
10
|
-
*/
|
|
11
|
-
function calculateMarkPrice(market) {
|
|
12
|
-
return (0, amm_1.calculatePrice)(market.amm.baseAssetReserve, market.amm.quoteAssetReserve, market.amm.pegMultiplier);
|
|
13
|
-
}
|
|
14
|
-
exports.calculateMarkPrice = calculateMarkPrice;
|
|
15
|
-
function calculateNewMarketAfterTrade(baseAssetAmount, direction, market) {
|
|
16
|
-
const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'base', baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', direction));
|
|
17
|
-
const newAmm = Object.assign({}, market.amm);
|
|
18
|
-
const newMarket = Object.assign({}, market);
|
|
19
|
-
newMarket.amm = newAmm;
|
|
20
|
-
newMarket.amm.quoteAssetReserve = newQuoteAssetReserve;
|
|
21
|
-
newMarket.amm.baseAssetReserve = newBaseAssetReserve;
|
|
22
|
-
return newMarket;
|
|
23
|
-
}
|
|
24
|
-
exports.calculateNewMarketAfterTrade = calculateNewMarketAfterTrade;
|
|
25
|
-
function calculateOracleMarkSpread(market, oraclePriceData) {
|
|
26
|
-
const markPrice = calculateMarkPrice(market);
|
|
27
|
-
return oraclePriceData.price.sub(markPrice);
|
|
28
|
-
}
|
|
29
|
-
exports.calculateOracleMarkSpread = calculateOracleMarkSpread;
|
|
30
|
-
//# sourceMappingURL=market.js.map
|
package/src/math/market.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["market.ts"],"names":[],"mappings":";;;AAEA,+BAIe;AAGf;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAChD,OAAO,IAAA,oBAAc,EACpB,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAC3B,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAC5B,MAAM,CAAC,GAAG,CAAC,aAAa,CACxB,CAAC;AACH,CAAC;AAND,gDAMC;AAED,SAAgB,4BAA4B,CAC3C,eAAmB,EACnB,SAA4B,EAC5B,MAAc;IAEd,MAAM,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,GAChD,IAAA,mCAA6B,EAC5B,MAAM,CAAC,GAAG,EACV,MAAM,EACN,eAAe,CAAC,GAAG,EAAE,EACrB,IAAA,sBAAgB,EAAC,MAAM,EAAE,SAAS,CAAC,CACnC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5C,SAAS,CAAC,GAAG,GAAG,MAAM,CAAC;IACvB,SAAS,CAAC,GAAG,CAAC,iBAAiB,GAAG,oBAAoB,CAAC;IACvD,SAAS,CAAC,GAAG,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;IAErD,OAAO,SAAS,CAAC;AAClB,CAAC;AApBD,oEAoBC;AAED,SAAgB,yBAAyB,CACxC,MAAc,EACd,eAAgC;IAEhC,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC;AAND,8DAMC"}
|