flash-sdk 1.0.4 → 1.0.6
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/CustodyAccount.js +9 -19
- package/lib/OraclePrice.d.ts +2 -0
- package/lib/OraclePrice.js +4 -0
- package/lib/PerpetualsClient.d.ts +24 -5
- package/lib/PerpetualsClient.js +604 -24
- package/lib/PoolAccount.d.ts +2 -1
- package/lib/PoolAccount.js +16 -29
- package/lib/PoolConfig.d.ts +7 -2
- package/lib/PoolConfig.js +15 -7
- package/lib/PoolConfig.json +4 -0
- package/lib/{PoolDisplayData.d.ts → PoolDataClient.d.ts} +3 -2
- package/lib/{PoolDisplayData.js → PoolDataClient.js} +13 -13
- package/lib/PositionAccount.d.ts +1 -0
- package/lib/Token.js +1 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/idl/perpetuals.d.ts +3675 -0
- package/{src/target/types → lib/idl}/perpetuals.js +140 -3
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +5 -3
- package/lib/types/index.js +21 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +57 -1
- package/lib/utils/rpc.d.ts +13 -0
- package/lib/utils/rpc.js +217 -0
- package/package.json +1 -1
- package/src/CustodyAccount.ts +24 -23
- package/src/OraclePrice.ts +4 -4
- package/src/PerpetualsClient.ts +763 -96
- package/src/PoolAccount.ts +34 -32
- package/src/PoolConfig.json +4 -0
- package/src/PoolConfig.ts +21 -6
- package/src/{PoolDisplayData.ts → PoolDataClient.ts} +2 -2
- package/src/Token.ts +1 -0
- package/src/{target/types → idl}/perpetuals.ts +280 -6
- package/src/index.ts +3 -0
- package/src/types/index.ts +26 -3
- package/src/utils/index.ts +14 -0
- package/src/utils/rpc.ts +162 -0
- package/lib/CustodyAccount.d.ts.map +0 -1
- package/lib/CustodyAccount.js.map +0 -1
- package/lib/OraclePrice.d.ts.map +0 -1
- package/lib/OraclePrice.js.map +0 -1
- package/lib/PerpetualsClient.d.ts.map +0 -1
- package/lib/PerpetualsClient.js.map +0 -1
- package/lib/PoolAccount.d.ts.map +0 -1
- package/lib/PoolAccount.js.map +0 -1
- package/lib/PositionAccount.d.ts.map +0 -1
- package/lib/PositionAccount.js.map +0 -1
- package/lib/client/src/CustodyAccount.d.ts +0 -30
- package/lib/client/src/CustodyAccount.d.ts.map +0 -1
- package/lib/client/src/CustodyAccount.js +0 -64
- package/lib/client/src/CustodyAccount.js.map +0 -1
- package/lib/client/src/OraclePrice.d.ts +0 -19
- package/lib/client/src/OraclePrice.d.ts.map +0 -1
- package/lib/client/src/OraclePrice.js +0 -84
- package/lib/client/src/OraclePrice.js.map +0 -1
- package/lib/client/src/PerpetualsClient.d.ts +0 -1938
- package/lib/client/src/PerpetualsClient.d.ts.map +0 -1
- package/lib/client/src/PerpetualsClient.js +0 -1043
- package/lib/client/src/PerpetualsClient.js.map +0 -1
- package/lib/client/src/PoolAccount.d.ts +0 -35
- package/lib/client/src/PoolAccount.d.ts.map +0 -1
- package/lib/client/src/PoolAccount.js +0 -307
- package/lib/client/src/PoolAccount.js.map +0 -1
- package/lib/client/src/PositionAccount.d.ts +0 -27
- package/lib/client/src/PositionAccount.d.ts.map +0 -1
- package/lib/client/src/PositionAccount.js +0 -91
- package/lib/client/src/PositionAccount.js.map +0 -1
- package/lib/client/src/constants/index.d.ts +0 -12
- package/lib/client/src/constants/index.d.ts.map +0 -1
- package/lib/client/src/constants/index.js +0 -15
- package/lib/client/src/constants/index.js.map +0 -1
- package/lib/client/src/index.d.ts +0 -9
- package/lib/client/src/index.d.ts.map +0 -1
- package/lib/client/src/index.js +0 -26
- package/lib/client/src/index.js.map +0 -1
- package/lib/client/src/types/index.d.ts +0 -188
- package/lib/client/src/types/index.d.ts.map +0 -1
- package/lib/client/src/types/index.js +0 -57
- package/lib/client/src/types/index.js.map +0 -1
- package/lib/client/src/utils/helpers.d.ts +0 -8
- package/lib/client/src/utils/helpers.d.ts.map +0 -1
- package/lib/client/src/utils/helpers.js +0 -152
- package/lib/client/src/utils/helpers.js.map +0 -1
- package/lib/constants/index.d.ts.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib/utils/helpers.d.ts +0 -7
- package/lib/utils/helpers.d.ts.map +0 -1
- package/lib/utils/helpers.js +0 -151
- package/lib/utils/helpers.js.map +0 -1
- package/src/target/types/limit_order_cpi.js +0 -132
- package/src/target/types/limit_order_cpi.ts +0 -259
- /package/{src/target/idl/perpetuals.json → lib/Token.d.ts} +0 -0
- /package/src/{readme.md → type-rules.md} +0 -0
package/src/PoolAccount.ts
CHANGED
@@ -370,19 +370,19 @@ export class PoolAccount implements Pool {
|
|
370
370
|
getAssetsUnderManagementUsd(
|
371
371
|
token_prices: OraclePrice[],
|
372
372
|
token_ema_prices: OraclePrice[],
|
373
|
-
|
373
|
+
custodyAccounts : CustodyAccount[],
|
374
374
|
aum_calc_mode: AumCalcMode,
|
375
|
-
|
375
|
+
currentTime : BN
|
376
|
+
) : BN {
|
376
377
|
|
377
378
|
let pool_amount_usd: BN = BN_ZERO;
|
378
379
|
|
379
|
-
for (let index=0;index<
|
380
|
+
for (let index=0;index<custodyAccounts.length;index++) {
|
380
381
|
|
381
|
-
if( token_prices.length !=
|
382
|
+
if( token_prices.length != custodyAccounts.length || token_prices.length != token_ema_prices.length ){
|
382
383
|
throw Error("token prices length incorrect");
|
383
384
|
}
|
384
385
|
|
385
|
-
|
386
386
|
let aum_token_price : OraclePrice;
|
387
387
|
// switch unable to match enum
|
388
388
|
if(isVariant(aum_calc_mode,"last")){
|
@@ -404,36 +404,38 @@ export class PoolAccount implements Pool {
|
|
404
404
|
}
|
405
405
|
|
406
406
|
let token_amount_usd :BN =
|
407
|
-
aum_token_price.getAssetAmountUsd(
|
407
|
+
aum_token_price.getAssetAmountUsd(custodyAccounts[index].assets.owned, custodyAccounts[index].decimals);
|
408
408
|
|
409
409
|
pool_amount_usd = pool_amount_usd.add(token_amount_usd);
|
410
410
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
411
|
+
if (custodyAccounts[index].pricing.useUnrealizedPnlInAum) {
|
412
|
+
// compute aggregate unrealized pnl
|
413
|
+
// console.log("long_pos:",custodyAccounts[index].longPositions)
|
414
|
+
let { profit : long_profit , loss : long_loss } = this.getPnlUsd(
|
415
|
+
custodyAccounts[index].getCollectivePosition(Side.Long),
|
416
|
+
token_prices[index],
|
417
|
+
token_ema_prices[index],
|
418
|
+
custodyAccounts[index],
|
419
|
+
currentTime,
|
420
|
+
false,
|
421
|
+
);
|
422
|
+
// console.log("long_pos:",custodyAccounts[index].shortPositions)
|
423
|
+
|
424
|
+
let { profit : short_profit , loss : short_loss } = this.getPnlUsd(
|
425
|
+
custodyAccounts[index].getCollectivePosition(Side.Short),
|
426
|
+
token_prices[index],
|
427
|
+
token_ema_prices[index],
|
428
|
+
custodyAccounts[index],
|
429
|
+
currentTime,
|
430
|
+
false,
|
431
|
+
);
|
432
|
+
|
433
|
+
// adjust pool amount by collective profit/loss
|
434
|
+
pool_amount_usd = pool_amount_usd.add(long_profit);
|
435
|
+
pool_amount_usd = pool_amount_usd.add(short_profit);
|
436
|
+
pool_amount_usd = pool_amount_usd.sub(long_loss); // check overflow - saturating_sub
|
437
|
+
pool_amount_usd = pool_amount_usd.sub(short_loss);
|
438
|
+
}
|
437
439
|
}
|
438
440
|
|
439
441
|
return pool_amount_usd;
|
package/src/PoolConfig.json
CHANGED
@@ -221,6 +221,8 @@
|
|
221
221
|
"lpTokenMint": "Han23mxQeHeoBbj4vYtYZNaB5bhwV3n4nxKezM6H6nbr",
|
222
222
|
"lpDecimals": 6,
|
223
223
|
"perpetuals": "5CpxhcrfvH8s9QDT2nMaPWqPoMwpuiPuP8e8x4YN61A2",
|
224
|
+
"transferAuthority" : "",
|
225
|
+
"multisig" : "",
|
224
226
|
"tokens": [
|
225
227
|
{
|
226
228
|
"symbol": "USDC",
|
@@ -266,6 +268,8 @@
|
|
266
268
|
"lpTokenMint": "J1887XKSeZFRzD6ACyiWMurXZd8xtNyb1Edj2oAxKT9E",
|
267
269
|
"lpDecimals": 6,
|
268
270
|
"perpetuals": "5CpxhcrfvH8s9QDT2nMaPWqPoMwpuiPuP8e8x4YN61A2",
|
271
|
+
"transferAuthority" : "",
|
272
|
+
"multisig" : "",
|
269
273
|
"tokens": [
|
270
274
|
{
|
271
275
|
"symbol": "Test",
|
package/src/PoolConfig.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Address } from '@
|
1
|
+
import { Address } from '@coral-xyz/anchor';
|
2
2
|
import { Cluster, PublicKey } from '@solana/web3.js';
|
3
3
|
import poolConfigs from './PoolConfig.json';
|
4
4
|
|
@@ -29,11 +29,8 @@ export class PoolConfig {
|
|
29
29
|
public lpTokenMint: PublicKey,
|
30
30
|
public lpDecimals: number,
|
31
31
|
public perpetuals: PublicKey,
|
32
|
-
|
33
|
-
|
34
|
-
// public perpMarketAccountKey: string,
|
35
|
-
// public multisigAccountKey: string,
|
36
|
-
// public transferAuthorityAccountKey: string,
|
32
|
+
public transferAuthority: PublicKey,
|
33
|
+
public multisig: PublicKey,
|
37
34
|
|
38
35
|
public tokens: Token[],
|
39
36
|
|
@@ -68,6 +65,20 @@ export class PoolConfig {
|
|
68
65
|
);
|
69
66
|
}
|
70
67
|
|
68
|
+
|
69
|
+
public getTokenFromSymbol = (symbol: string) : Token => {
|
70
|
+
return this.tokens.find(f => f.symbol.toUpperCase() === symbol.toUpperCase())!;
|
71
|
+
}
|
72
|
+
|
73
|
+
public getTokenFromMintString = (mint: string) : Token => {
|
74
|
+
return this.tokens.find(f => f.mintKey.toBase58() === mint)!;
|
75
|
+
}
|
76
|
+
|
77
|
+
public getTokenFromMintPk = (mint: PublicKey) : Token => {
|
78
|
+
return this.tokens.find(f => f.mintKey.equals(mint))!;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
71
82
|
// static getAllPoolConfigs(cluster: Cluster): PoolConfig[] {
|
72
83
|
// return poolConfigs.pools.map(p => this.fromIdsByName(p.poolName, cluster))
|
73
84
|
// }
|
@@ -114,6 +125,8 @@ export class PoolConfig {
|
|
114
125
|
new PublicKey(poolConfig.lpTokenMint),
|
115
126
|
poolConfig.lpDecimals,
|
116
127
|
new PublicKey(poolConfig.perpetuals),
|
128
|
+
new PublicKey(poolConfig.transferAuthority),
|
129
|
+
new PublicKey(poolConfig.multisig),
|
117
130
|
tokens,
|
118
131
|
custodies,
|
119
132
|
);
|
@@ -150,6 +163,8 @@ export class PoolConfig {
|
|
150
163
|
new PublicKey(poolConfig.lpTokenMint),
|
151
164
|
poolConfig.lpDecimals,
|
152
165
|
new PublicKey(poolConfig.perpetuals),
|
166
|
+
new PublicKey(poolConfig.transferAuthority),
|
167
|
+
new PublicKey(poolConfig.multisig),
|
153
168
|
tokens,
|
154
169
|
custodies,
|
155
170
|
);
|
@@ -11,7 +11,7 @@ import { checkedCeilDiv, checkedDecimalCeilMul, checkedDecimalMul, scaleToExpone
|
|
11
11
|
import { PoolConfig } from "./PoolConfig";
|
12
12
|
import { PoolAccount } from "./PoolAccount";
|
13
13
|
|
14
|
-
export class
|
14
|
+
export class PoolDataClient {
|
15
15
|
|
16
16
|
public poolConfig: PoolConfig;
|
17
17
|
public pool: PoolAccount;
|
@@ -35,7 +35,7 @@ export class PoolDisplayData {
|
|
35
35
|
this.pool = pool
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
loadLpData(lpTokenInfo: Mint) {
|
39
39
|
this.lpTokenInfo = lpTokenInfo
|
40
40
|
}
|
41
41
|
|
package/src/Token.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
// later inport from UI
|
@@ -3368,7 +3368,7 @@ export type Perpetuals = {
|
|
3368
3368
|
"name": "OpenPositionLog",
|
3369
3369
|
"fields": [
|
3370
3370
|
{
|
3371
|
-
"name": "
|
3371
|
+
"name": "positionPubKey",
|
3372
3372
|
"type": "publicKey",
|
3373
3373
|
"index": false
|
3374
3374
|
},
|
@@ -3377,32 +3377,169 @@ export type Perpetuals = {
|
|
3377
3377
|
"type": "publicKey",
|
3378
3378
|
"index": false
|
3379
3379
|
},
|
3380
|
+
{
|
3381
|
+
"name": "pool",
|
3382
|
+
"type": "publicKey",
|
3383
|
+
"index": false
|
3384
|
+
},
|
3380
3385
|
{
|
3381
3386
|
"name": "custody",
|
3382
3387
|
"type": "publicKey",
|
3383
3388
|
"index": false
|
3384
3389
|
},
|
3390
|
+
{
|
3391
|
+
"name": "openTime",
|
3392
|
+
"type": "i64",
|
3393
|
+
"index": false
|
3394
|
+
},
|
3395
|
+
{
|
3396
|
+
"name": "updateTime",
|
3397
|
+
"type": "i64",
|
3398
|
+
"index": false
|
3399
|
+
},
|
3400
|
+
{
|
3401
|
+
"name": "side",
|
3402
|
+
"type": {
|
3403
|
+
"defined": "Side"
|
3404
|
+
},
|
3405
|
+
"index": false
|
3406
|
+
},
|
3385
3407
|
{
|
3386
3408
|
"name": "price",
|
3387
3409
|
"type": "u64",
|
3388
3410
|
"index": false
|
3389
3411
|
},
|
3390
3412
|
{
|
3391
|
-
"name": "
|
3413
|
+
"name": "sizeUsd",
|
3414
|
+
"type": "u64",
|
3415
|
+
"index": false
|
3416
|
+
},
|
3417
|
+
{
|
3418
|
+
"name": "collateralUsd",
|
3392
3419
|
"type": "u64",
|
3393
3420
|
"index": false
|
3394
3421
|
},
|
3395
3422
|
{
|
3396
|
-
"name": "
|
3423
|
+
"name": "unrealizedProfitUsd",
|
3397
3424
|
"type": "u64",
|
3398
3425
|
"index": false
|
3399
3426
|
},
|
3427
|
+
{
|
3428
|
+
"name": "unrealizedLossUsd",
|
3429
|
+
"type": "u64",
|
3430
|
+
"index": false
|
3431
|
+
},
|
3432
|
+
{
|
3433
|
+
"name": "cumulativeInterestSnapshot",
|
3434
|
+
"type": "u128",
|
3435
|
+
"index": false
|
3436
|
+
},
|
3437
|
+
{
|
3438
|
+
"name": "lockedAmount",
|
3439
|
+
"type": "u64",
|
3440
|
+
"index": false
|
3441
|
+
},
|
3442
|
+
{
|
3443
|
+
"name": "collateralAmount",
|
3444
|
+
"type": "u64",
|
3445
|
+
"index": false
|
3446
|
+
}
|
3447
|
+
]
|
3448
|
+
},
|
3449
|
+
{
|
3450
|
+
"name": "ClosePositionLog",
|
3451
|
+
"fields": [
|
3452
|
+
{
|
3453
|
+
"name": "positionPubKey",
|
3454
|
+
"type": "publicKey",
|
3455
|
+
"index": false
|
3456
|
+
},
|
3457
|
+
{
|
3458
|
+
"name": "owner",
|
3459
|
+
"type": "publicKey",
|
3460
|
+
"index": false
|
3461
|
+
},
|
3462
|
+
{
|
3463
|
+
"name": "pool",
|
3464
|
+
"type": "publicKey",
|
3465
|
+
"index": false
|
3466
|
+
},
|
3467
|
+
{
|
3468
|
+
"name": "custody",
|
3469
|
+
"type": "publicKey",
|
3470
|
+
"index": false
|
3471
|
+
},
|
3472
|
+
{
|
3473
|
+
"name": "openTime",
|
3474
|
+
"type": "i64",
|
3475
|
+
"index": false
|
3476
|
+
},
|
3477
|
+
{
|
3478
|
+
"name": "updateTime",
|
3479
|
+
"type": "i64",
|
3480
|
+
"index": false
|
3481
|
+
},
|
3400
3482
|
{
|
3401
3483
|
"name": "side",
|
3402
3484
|
"type": {
|
3403
3485
|
"defined": "Side"
|
3404
3486
|
},
|
3405
3487
|
"index": false
|
3488
|
+
},
|
3489
|
+
{
|
3490
|
+
"name": "price",
|
3491
|
+
"type": "u64",
|
3492
|
+
"index": false
|
3493
|
+
},
|
3494
|
+
{
|
3495
|
+
"name": "sizeUsd",
|
3496
|
+
"type": "u64",
|
3497
|
+
"index": false
|
3498
|
+
},
|
3499
|
+
{
|
3500
|
+
"name": "collateralUsd",
|
3501
|
+
"type": "u64",
|
3502
|
+
"index": false
|
3503
|
+
},
|
3504
|
+
{
|
3505
|
+
"name": "unrealizedProfitUsd",
|
3506
|
+
"type": "u64",
|
3507
|
+
"index": false
|
3508
|
+
},
|
3509
|
+
{
|
3510
|
+
"name": "unrealizedLossUsd",
|
3511
|
+
"type": "u64",
|
3512
|
+
"index": false
|
3513
|
+
},
|
3514
|
+
{
|
3515
|
+
"name": "cumulativeInterestSnapshot",
|
3516
|
+
"type": "u128",
|
3517
|
+
"index": false
|
3518
|
+
},
|
3519
|
+
{
|
3520
|
+
"name": "lockedAmount",
|
3521
|
+
"type": "u64",
|
3522
|
+
"index": false
|
3523
|
+
},
|
3524
|
+
{
|
3525
|
+
"name": "collateralAmount",
|
3526
|
+
"type": "u64",
|
3527
|
+
"index": false
|
3528
|
+
},
|
3529
|
+
{
|
3530
|
+
"name": "profitUsd",
|
3531
|
+
"type": "u64",
|
3532
|
+
"index": false
|
3533
|
+
},
|
3534
|
+
{
|
3535
|
+
"name": "lossUsd",
|
3536
|
+
"type": "u64",
|
3537
|
+
"index": false
|
3538
|
+
},
|
3539
|
+
{
|
3540
|
+
"name": "feeAmount",
|
3541
|
+
"type": "u64",
|
3542
|
+
"index": false
|
3406
3543
|
}
|
3407
3544
|
]
|
3408
3545
|
}
|
@@ -6906,7 +7043,7 @@ export const IDL: Perpetuals = {
|
|
6906
7043
|
"name": "OpenPositionLog",
|
6907
7044
|
"fields": [
|
6908
7045
|
{
|
6909
|
-
"name": "
|
7046
|
+
"name": "positionPubKey",
|
6910
7047
|
"type": "publicKey",
|
6911
7048
|
"index": false
|
6912
7049
|
},
|
@@ -6915,32 +7052,169 @@ export const IDL: Perpetuals = {
|
|
6915
7052
|
"type": "publicKey",
|
6916
7053
|
"index": false
|
6917
7054
|
},
|
7055
|
+
{
|
7056
|
+
"name": "pool",
|
7057
|
+
"type": "publicKey",
|
7058
|
+
"index": false
|
7059
|
+
},
|
6918
7060
|
{
|
6919
7061
|
"name": "custody",
|
6920
7062
|
"type": "publicKey",
|
6921
7063
|
"index": false
|
6922
7064
|
},
|
7065
|
+
{
|
7066
|
+
"name": "openTime",
|
7067
|
+
"type": "i64",
|
7068
|
+
"index": false
|
7069
|
+
},
|
7070
|
+
{
|
7071
|
+
"name": "updateTime",
|
7072
|
+
"type": "i64",
|
7073
|
+
"index": false
|
7074
|
+
},
|
7075
|
+
{
|
7076
|
+
"name": "side",
|
7077
|
+
"type": {
|
7078
|
+
"defined": "Side"
|
7079
|
+
},
|
7080
|
+
"index": false
|
7081
|
+
},
|
6923
7082
|
{
|
6924
7083
|
"name": "price",
|
6925
7084
|
"type": "u64",
|
6926
7085
|
"index": false
|
6927
7086
|
},
|
6928
7087
|
{
|
6929
|
-
"name": "
|
7088
|
+
"name": "sizeUsd",
|
7089
|
+
"type": "u64",
|
7090
|
+
"index": false
|
7091
|
+
},
|
7092
|
+
{
|
7093
|
+
"name": "collateralUsd",
|
6930
7094
|
"type": "u64",
|
6931
7095
|
"index": false
|
6932
7096
|
},
|
6933
7097
|
{
|
6934
|
-
"name": "
|
7098
|
+
"name": "unrealizedProfitUsd",
|
6935
7099
|
"type": "u64",
|
6936
7100
|
"index": false
|
6937
7101
|
},
|
7102
|
+
{
|
7103
|
+
"name": "unrealizedLossUsd",
|
7104
|
+
"type": "u64",
|
7105
|
+
"index": false
|
7106
|
+
},
|
7107
|
+
{
|
7108
|
+
"name": "cumulativeInterestSnapshot",
|
7109
|
+
"type": "u128",
|
7110
|
+
"index": false
|
7111
|
+
},
|
7112
|
+
{
|
7113
|
+
"name": "lockedAmount",
|
7114
|
+
"type": "u64",
|
7115
|
+
"index": false
|
7116
|
+
},
|
7117
|
+
{
|
7118
|
+
"name": "collateralAmount",
|
7119
|
+
"type": "u64",
|
7120
|
+
"index": false
|
7121
|
+
}
|
7122
|
+
]
|
7123
|
+
},
|
7124
|
+
{
|
7125
|
+
"name": "ClosePositionLog",
|
7126
|
+
"fields": [
|
7127
|
+
{
|
7128
|
+
"name": "positionPubKey",
|
7129
|
+
"type": "publicKey",
|
7130
|
+
"index": false
|
7131
|
+
},
|
7132
|
+
{
|
7133
|
+
"name": "owner",
|
7134
|
+
"type": "publicKey",
|
7135
|
+
"index": false
|
7136
|
+
},
|
7137
|
+
{
|
7138
|
+
"name": "pool",
|
7139
|
+
"type": "publicKey",
|
7140
|
+
"index": false
|
7141
|
+
},
|
7142
|
+
{
|
7143
|
+
"name": "custody",
|
7144
|
+
"type": "publicKey",
|
7145
|
+
"index": false
|
7146
|
+
},
|
7147
|
+
{
|
7148
|
+
"name": "openTime",
|
7149
|
+
"type": "i64",
|
7150
|
+
"index": false
|
7151
|
+
},
|
7152
|
+
{
|
7153
|
+
"name": "updateTime",
|
7154
|
+
"type": "i64",
|
7155
|
+
"index": false
|
7156
|
+
},
|
6938
7157
|
{
|
6939
7158
|
"name": "side",
|
6940
7159
|
"type": {
|
6941
7160
|
"defined": "Side"
|
6942
7161
|
},
|
6943
7162
|
"index": false
|
7163
|
+
},
|
7164
|
+
{
|
7165
|
+
"name": "price",
|
7166
|
+
"type": "u64",
|
7167
|
+
"index": false
|
7168
|
+
},
|
7169
|
+
{
|
7170
|
+
"name": "sizeUsd",
|
7171
|
+
"type": "u64",
|
7172
|
+
"index": false
|
7173
|
+
},
|
7174
|
+
{
|
7175
|
+
"name": "collateralUsd",
|
7176
|
+
"type": "u64",
|
7177
|
+
"index": false
|
7178
|
+
},
|
7179
|
+
{
|
7180
|
+
"name": "unrealizedProfitUsd",
|
7181
|
+
"type": "u64",
|
7182
|
+
"index": false
|
7183
|
+
},
|
7184
|
+
{
|
7185
|
+
"name": "unrealizedLossUsd",
|
7186
|
+
"type": "u64",
|
7187
|
+
"index": false
|
7188
|
+
},
|
7189
|
+
{
|
7190
|
+
"name": "cumulativeInterestSnapshot",
|
7191
|
+
"type": "u128",
|
7192
|
+
"index": false
|
7193
|
+
},
|
7194
|
+
{
|
7195
|
+
"name": "lockedAmount",
|
7196
|
+
"type": "u64",
|
7197
|
+
"index": false
|
7198
|
+
},
|
7199
|
+
{
|
7200
|
+
"name": "collateralAmount",
|
7201
|
+
"type": "u64",
|
7202
|
+
"index": false
|
7203
|
+
},
|
7204
|
+
{
|
7205
|
+
"name": "profitUsd",
|
7206
|
+
"type": "u64",
|
7207
|
+
"index": false
|
7208
|
+
},
|
7209
|
+
{
|
7210
|
+
"name": "lossUsd",
|
7211
|
+
"type": "u64",
|
7212
|
+
"index": false
|
7213
|
+
},
|
7214
|
+
{
|
7215
|
+
"name": "feeAmount",
|
7216
|
+
"type": "u64",
|
7217
|
+
"index": false
|
6944
7218
|
}
|
6945
7219
|
]
|
6946
7220
|
}
|
package/src/index.ts
CHANGED
@@ -7,6 +7,9 @@ export * from './types';
|
|
7
7
|
export * from './utils';
|
8
8
|
export * from './PerpetualsClient';
|
9
9
|
export * from './PoolConfig';
|
10
|
+
export * from './PoolDataClient';
|
11
|
+
export {IDL} from './idl/perpetuals';
|
12
|
+
export * from './utils/rpc';
|
10
13
|
// export { default as PoolConfigJson } from "./PoolConfig.json";
|
11
14
|
|
12
15
|
|
package/src/types/index.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { BN } from "@project-serum/anchor";
|
2
1
|
import { PublicKey } from "@solana/web3.js";
|
3
2
|
import { OraclePrice } from "../OraclePrice";
|
3
|
+
import { BN_ZERO } from "../constants";
|
4
|
+
import { BN } from "@coral-xyz/anchor";
|
4
5
|
|
5
6
|
export type PositionSide = "long" | "short";
|
6
7
|
|
@@ -61,6 +62,28 @@ export interface Position {
|
|
61
62
|
bump: number
|
62
63
|
}
|
63
64
|
|
65
|
+
export const DEFAULT_POSITION : Position = {
|
66
|
+
owner: PublicKey.default,
|
67
|
+
pool: PublicKey.default,
|
68
|
+
custody: PublicKey.default,
|
69
|
+
// lockCustody: PublicKey.default,
|
70
|
+
|
71
|
+
openTime: BN_ZERO,
|
72
|
+
updateTime: BN_ZERO,
|
73
|
+
|
74
|
+
side: Side.Long,
|
75
|
+
price: BN_ZERO,
|
76
|
+
sizeUsd: BN_ZERO,
|
77
|
+
collateralUsd: BN_ZERO,
|
78
|
+
unrealizedProfitUsd: BN_ZERO,
|
79
|
+
unrealizedLossUsd: BN_ZERO,
|
80
|
+
cumulativeInterestSnapshot: BN_ZERO,
|
81
|
+
lockedAmount: BN_ZERO,
|
82
|
+
collateralAmount: BN_ZERO,
|
83
|
+
|
84
|
+
bump: 0
|
85
|
+
}
|
86
|
+
|
64
87
|
// =======================================================
|
65
88
|
// ================== POOL ========================
|
66
89
|
// =======================================================
|
@@ -132,8 +155,8 @@ export interface PositionStats {
|
|
132
155
|
collateralUsd: BN,
|
133
156
|
sizeUsd: BN,
|
134
157
|
lockedAmount: BN,
|
135
|
-
|
136
|
-
|
158
|
+
weightedPrice: BN,
|
159
|
+
totalQuantity: BN,
|
137
160
|
cumulativeInterestUsd: BN,
|
138
161
|
cumulativeInterestSnapshot: BN,
|
139
162
|
}
|
package/src/utils/index.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import BN from "bn.js";
|
2
2
|
import { BN_ONE, BN_ZERO } from "../constants";
|
3
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
3
4
|
|
4
5
|
export const getUnixTs = () => {
|
5
6
|
return new Date().getTime() / 1000;
|
@@ -57,6 +58,19 @@ export function toUiDecimals(
|
|
57
58
|
|
58
59
|
}
|
59
60
|
|
61
|
+
export async function checkIfAccountExists(
|
62
|
+
account: PublicKey,
|
63
|
+
connection: Connection
|
64
|
+
): Promise<boolean> {
|
65
|
+
// console.log("connection print", connection);
|
66
|
+
let bal = await connection.getBalance(account);
|
67
|
+
if (bal > 0) {
|
68
|
+
return true;
|
69
|
+
} else {
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
60
74
|
// recheck ?? logic
|
61
75
|
export const scaleToExponent = (arg: BN, exponent: BN, target_exponent: BN) : BN => {
|
62
76
|
if (target_exponent.eq(exponent)) {
|