flash-sdk 2.42.9-alpha.0 → 2.42.11
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/PerpetualsClient.d.ts +2 -2
- package/dist/PerpetualsClient.js +25 -18
- package/dist/idl/perpetuals.d.ts +4 -255
- package/dist/idl/perpetuals.js +4 -255
- package/dist/test2.d.ts +0 -1
- package/dist/test2.js +0 -215
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/idl/perpetuals.js
CHANGED
@@ -4236,99 +4236,6 @@ exports.IDL = {
|
|
4236
4236
|
}
|
4237
4237
|
]
|
4238
4238
|
},
|
4239
|
-
{
|
4240
|
-
"name": "decreaseAndRemoveCollateral",
|
4241
|
-
"accounts": [
|
4242
|
-
{
|
4243
|
-
"name": "owner",
|
4244
|
-
"isMut": false,
|
4245
|
-
"isSigner": true
|
4246
|
-
},
|
4247
|
-
{
|
4248
|
-
"name": "receivingAccount",
|
4249
|
-
"isMut": true,
|
4250
|
-
"isSigner": false
|
4251
|
-
},
|
4252
|
-
{
|
4253
|
-
"name": "transferAuthority",
|
4254
|
-
"isMut": false,
|
4255
|
-
"isSigner": false
|
4256
|
-
},
|
4257
|
-
{
|
4258
|
-
"name": "perpetuals",
|
4259
|
-
"isMut": false,
|
4260
|
-
"isSigner": false
|
4261
|
-
},
|
4262
|
-
{
|
4263
|
-
"name": "pool",
|
4264
|
-
"isMut": false,
|
4265
|
-
"isSigner": false
|
4266
|
-
},
|
4267
|
-
{
|
4268
|
-
"name": "position",
|
4269
|
-
"isMut": true,
|
4270
|
-
"isSigner": false
|
4271
|
-
},
|
4272
|
-
{
|
4273
|
-
"name": "market",
|
4274
|
-
"isMut": true,
|
4275
|
-
"isSigner": false
|
4276
|
-
},
|
4277
|
-
{
|
4278
|
-
"name": "targetCustody",
|
4279
|
-
"isMut": false,
|
4280
|
-
"isSigner": false
|
4281
|
-
},
|
4282
|
-
{
|
4283
|
-
"name": "targetOracleAccount",
|
4284
|
-
"isMut": false,
|
4285
|
-
"isSigner": false
|
4286
|
-
},
|
4287
|
-
{
|
4288
|
-
"name": "collateralCustody",
|
4289
|
-
"isMut": true,
|
4290
|
-
"isSigner": false
|
4291
|
-
},
|
4292
|
-
{
|
4293
|
-
"name": "collateralOracleAccount",
|
4294
|
-
"isMut": false,
|
4295
|
-
"isSigner": false
|
4296
|
-
},
|
4297
|
-
{
|
4298
|
-
"name": "collateralCustodyTokenAccount",
|
4299
|
-
"isMut": true,
|
4300
|
-
"isSigner": false
|
4301
|
-
},
|
4302
|
-
{
|
4303
|
-
"name": "tokenProgram",
|
4304
|
-
"isMut": false,
|
4305
|
-
"isSigner": false
|
4306
|
-
},
|
4307
|
-
{
|
4308
|
-
"name": "eventAuthority",
|
4309
|
-
"isMut": false,
|
4310
|
-
"isSigner": false
|
4311
|
-
},
|
4312
|
-
{
|
4313
|
-
"name": "program",
|
4314
|
-
"isMut": false,
|
4315
|
-
"isSigner": false
|
4316
|
-
},
|
4317
|
-
{
|
4318
|
-
"name": "ixSysvar",
|
4319
|
-
"isMut": false,
|
4320
|
-
"isSigner": false
|
4321
|
-
}
|
4322
|
-
],
|
4323
|
-
"args": [
|
4324
|
-
{
|
4325
|
-
"name": "params",
|
4326
|
-
"type": {
|
4327
|
-
"defined": "DecreaseAndRemoveCollateralParams"
|
4328
|
-
}
|
4329
|
-
}
|
4330
|
-
]
|
4331
|
-
},
|
4332
4239
|
{
|
4333
4240
|
"name": "decreaseSize",
|
4334
4241
|
"accounts": [
|
@@ -5156,11 +5063,6 @@ exports.IDL = {
|
|
5156
5063
|
"isMut": false,
|
5157
5064
|
"isSigner": false
|
5158
5065
|
},
|
5159
|
-
{
|
5160
|
-
"name": "receiveCustody",
|
5161
|
-
"isMut": false,
|
5162
|
-
"isSigner": false
|
5163
|
-
},
|
5164
5066
|
{
|
5165
5067
|
"name": "eventAuthority",
|
5166
5068
|
"isMut": false,
|
@@ -8247,30 +8149,6 @@ exports.IDL = {
|
|
8247
8149
|
]
|
8248
8150
|
}
|
8249
8151
|
},
|
8250
|
-
{
|
8251
|
-
"name": "DecreaseAndRemoveCollateralParams",
|
8252
|
-
"type": {
|
8253
|
-
"kind": "struct",
|
8254
|
-
"fields": [
|
8255
|
-
{
|
8256
|
-
"name": "priceWithSlippage",
|
8257
|
-
"type": {
|
8258
|
-
"defined": "OraclePrice"
|
8259
|
-
}
|
8260
|
-
},
|
8261
|
-
{
|
8262
|
-
"name": "sizeDelta",
|
8263
|
-
"type": "u64"
|
8264
|
-
},
|
8265
|
-
{
|
8266
|
-
"name": "privilege",
|
8267
|
-
"type": {
|
8268
|
-
"defined": "Privilege"
|
8269
|
-
}
|
8270
|
-
}
|
8271
|
-
]
|
8272
|
-
}
|
8273
|
-
},
|
8274
8152
|
{
|
8275
8153
|
"name": "DecreaseSizeParams",
|
8276
8154
|
"type": {
|
@@ -8395,6 +8273,10 @@ exports.IDL = {
|
|
8395
8273
|
{
|
8396
8274
|
"name": "isStopLoss",
|
8397
8275
|
"type": "bool"
|
8276
|
+
},
|
8277
|
+
{
|
8278
|
+
"name": "receiveCustodyId",
|
8279
|
+
"type": "u8"
|
8398
8280
|
}
|
8399
8281
|
]
|
8400
8282
|
}
|
@@ -11086,9 +10968,6 @@ exports.IDL = {
|
|
11086
10968
|
},
|
11087
10969
|
{
|
11088
10970
|
"name": "CollectStakeReward"
|
11089
|
-
},
|
11090
|
-
{
|
11091
|
-
"name": "DecreaseAndRemoveCollateral"
|
11092
10971
|
}
|
11093
10972
|
]
|
11094
10973
|
}
|
@@ -12010,136 +11889,6 @@ exports.IDL = {
|
|
12010
11889
|
}
|
12011
11890
|
]
|
12012
11891
|
},
|
12013
|
-
{
|
12014
|
-
"name": "DecreaseAndRemoveCollateralLog",
|
12015
|
-
"fields": [
|
12016
|
-
{
|
12017
|
-
"name": "owner",
|
12018
|
-
"type": "publicKey",
|
12019
|
-
"index": false
|
12020
|
-
},
|
12021
|
-
{
|
12022
|
-
"name": "market",
|
12023
|
-
"type": "publicKey",
|
12024
|
-
"index": false
|
12025
|
-
},
|
12026
|
-
{
|
12027
|
-
"name": "entryPrice",
|
12028
|
-
"type": "u64",
|
12029
|
-
"index": false
|
12030
|
-
},
|
12031
|
-
{
|
12032
|
-
"name": "entryPriceExponent",
|
12033
|
-
"type": "i32",
|
12034
|
-
"index": false
|
12035
|
-
},
|
12036
|
-
{
|
12037
|
-
"name": "duration",
|
12038
|
-
"type": "i64",
|
12039
|
-
"index": false
|
12040
|
-
},
|
12041
|
-
{
|
12042
|
-
"name": "exitPrice",
|
12043
|
-
"type": "u64",
|
12044
|
-
"index": false
|
12045
|
-
},
|
12046
|
-
{
|
12047
|
-
"name": "exitPriceExponent",
|
12048
|
-
"type": "i32",
|
12049
|
-
"index": false
|
12050
|
-
},
|
12051
|
-
{
|
12052
|
-
"name": "deltaSizeAmount",
|
12053
|
-
"type": "u64",
|
12054
|
-
"index": false
|
12055
|
-
},
|
12056
|
-
{
|
12057
|
-
"name": "deltaSizeUsd",
|
12058
|
-
"type": "u64",
|
12059
|
-
"index": false
|
12060
|
-
},
|
12061
|
-
{
|
12062
|
-
"name": "collateralPrice",
|
12063
|
-
"type": "u64",
|
12064
|
-
"index": false
|
12065
|
-
},
|
12066
|
-
{
|
12067
|
-
"name": "collateralPriceExponent",
|
12068
|
-
"type": "i32",
|
12069
|
-
"index": false
|
12070
|
-
},
|
12071
|
-
{
|
12072
|
-
"name": "deltaCollateralAmount",
|
12073
|
-
"type": "u64",
|
12074
|
-
"index": false
|
12075
|
-
},
|
12076
|
-
{
|
12077
|
-
"name": "finalSizeAmount",
|
12078
|
-
"type": "u64",
|
12079
|
-
"index": false
|
12080
|
-
},
|
12081
|
-
{
|
12082
|
-
"name": "finalSizeUsd",
|
12083
|
-
"type": "u64",
|
12084
|
-
"index": false
|
12085
|
-
},
|
12086
|
-
{
|
12087
|
-
"name": "finalCollateralAmount",
|
12088
|
-
"type": "u64",
|
12089
|
-
"index": false
|
12090
|
-
},
|
12091
|
-
{
|
12092
|
-
"name": "finalCollateralUsd",
|
12093
|
-
"type": "u64",
|
12094
|
-
"index": false
|
12095
|
-
},
|
12096
|
-
{
|
12097
|
-
"name": "profitUsd",
|
12098
|
-
"type": "u64",
|
12099
|
-
"index": false
|
12100
|
-
},
|
12101
|
-
{
|
12102
|
-
"name": "lossUsd",
|
12103
|
-
"type": "u64",
|
12104
|
-
"index": false
|
12105
|
-
},
|
12106
|
-
{
|
12107
|
-
"name": "feeAmount",
|
12108
|
-
"type": "u64",
|
12109
|
-
"index": false
|
12110
|
-
},
|
12111
|
-
{
|
12112
|
-
"name": "feeRebateAmount",
|
12113
|
-
"type": "u64",
|
12114
|
-
"index": false
|
12115
|
-
},
|
12116
|
-
{
|
12117
|
-
"name": "exitFeeAmount",
|
12118
|
-
"type": "u64",
|
12119
|
-
"index": false
|
12120
|
-
},
|
12121
|
-
{
|
12122
|
-
"name": "oracleAccountTime",
|
12123
|
-
"type": "i64",
|
12124
|
-
"index": false
|
12125
|
-
},
|
12126
|
-
{
|
12127
|
-
"name": "oracleAccountType",
|
12128
|
-
"type": "u8",
|
12129
|
-
"index": false
|
12130
|
-
},
|
12131
|
-
{
|
12132
|
-
"name": "oracleAccountPrice",
|
12133
|
-
"type": "u64",
|
12134
|
-
"index": false
|
12135
|
-
},
|
12136
|
-
{
|
12137
|
-
"name": "oracleAccountPriceExponent",
|
12138
|
-
"type": "i32",
|
12139
|
-
"index": false
|
12140
|
-
}
|
12141
|
-
]
|
12142
|
-
},
|
12143
11892
|
{
|
12144
11893
|
"name": "DecreaseSizeLog",
|
12145
11894
|
"fields": [
|
package/dist/test2.d.ts
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
import 'dotenv/config';
|
package/dist/test2.js
CHANGED
@@ -1,215 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
-
function step(op) {
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
-
switch (op[0]) {
|
21
|
-
case 0: case 1: t = op; break;
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
-
default:
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
-
if (t[2]) _.ops.pop();
|
31
|
-
_.trys.pop(); continue;
|
32
|
-
}
|
33
|
-
op = body.call(thisArg, _);
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
-
}
|
37
|
-
};
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
require("dotenv/config");
|
40
|
-
var bn_js_1 = require("bn.js");
|
41
|
-
var utils_1 = require("./utils");
|
42
|
-
var PerpetualsClient_1 = require("./PerpetualsClient");
|
43
|
-
var anchor_1 = require("@coral-xyz/anchor");
|
44
|
-
var web3_js_1 = require("@solana/web3.js");
|
45
|
-
var types_1 = require("./types");
|
46
|
-
var OraclePrice_1 = require("./OraclePrice");
|
47
|
-
var CustodyAccount_1 = require("./CustodyAccount");
|
48
|
-
var client_1 = require("@pythnetwork/client");
|
49
|
-
var PositionAccount_1 = require("./PositionAccount");
|
50
|
-
var PoolAccount_1 = require("./PoolAccount");
|
51
|
-
var PoolDataClient_1 = require("./PoolDataClient");
|
52
|
-
var spl_token_1 = require("@solana/spl-token");
|
53
|
-
var PoolConfig_1 = require("./PoolConfig");
|
54
|
-
var client;
|
55
|
-
var poolClient;
|
56
|
-
var prettyPrint = function (object) {
|
57
|
-
console.log(JSON.stringify(object, null, 2));
|
58
|
-
};
|
59
|
-
function initClient(clusterUrl, adminKeyPath, programId, composabilityProgramId, fbNftRewardProgramId) {
|
60
|
-
process.env["ANCHOR_WALLET"] = adminKeyPath;
|
61
|
-
var provider = anchor_1.AnchorProvider.local(clusterUrl, {
|
62
|
-
commitment: "confirmed",
|
63
|
-
preflightCommitment: "confirmed",
|
64
|
-
skipPreflight: true
|
65
|
-
});
|
66
|
-
client = new PerpetualsClient_1.PerpetualsClient(provider, programId, composabilityProgramId, fbNftRewardProgramId, fbNftRewardProgramId, null);
|
67
|
-
client.log("Client Initialized");
|
68
|
-
}
|
69
|
-
var main2 = function () { return __awaiter(void 0, void 0, void 0, function () {
|
70
|
-
var url, adminKey, poolName, POOL_CONFIG, programId, composabilityProgramId, poolKey, poolData, poolAccount, custodyAccounts, i, custodyAccountKey, custodyAccountInfo, ca, pythClient, pythHttpClientResult, priceDataSOL, priceOracleSOL, emaPriceOracleSOL, priceDataUSDC, priceOracleUSDC, emaPriceOracleUSDC, priceDataBTC, priceOracleBTC, emaPriceOracleBTC, priceDataETH, priceOracleETH, emaPriceOracleETH, user, position, newPosition, currtime, TEST_FUNCTION, TEST_FLP_STAKE, TEST_APY;
|
71
|
-
var _a, _b;
|
72
|
-
return __generator(this, function (_c) {
|
73
|
-
switch (_c.label) {
|
74
|
-
case 0:
|
75
|
-
console.log("========== 1) SETUP ==============");
|
76
|
-
url = (_a = process.env["RPC_URL"]) !== null && _a !== void 0 ? _a : 'https://api.devnet.solana.com';
|
77
|
-
console.log("url:", url);
|
78
|
-
adminKey = (_b = process.env["KEYPAIR_PATH"]) !== null && _b !== void 0 ? _b : "/Users/aw/.config/solana/Beta-Hcik.json";
|
79
|
-
console.log("adminKey path:", adminKey);
|
80
|
-
poolName = "Crypto.1";
|
81
|
-
POOL_CONFIG = PoolConfig_1.PoolConfig.fromIdsByName(poolName, 'mainnet-beta');
|
82
|
-
programId = POOL_CONFIG.programId;
|
83
|
-
composabilityProgramId = POOL_CONFIG.perpComposibilityProgramId;
|
84
|
-
initClient(url, adminKey, programId, composabilityProgramId, POOL_CONFIG.fbNftRewardProgramId);
|
85
|
-
poolKey = POOL_CONFIG.poolAddress;
|
86
|
-
return [4, client.getPool(poolName)];
|
87
|
-
case 1:
|
88
|
-
poolData = _c.sent();
|
89
|
-
poolAccount = new PoolAccount_1.PoolAccount(poolKey, poolData);
|
90
|
-
custodyAccounts = [];
|
91
|
-
i = 0;
|
92
|
-
_c.label = 2;
|
93
|
-
case 2:
|
94
|
-
if (!(i < POOL_CONFIG.custodies.length)) return [3, 5];
|
95
|
-
custodyAccountKey = client.getCustodyKey(poolName, POOL_CONFIG.custodies[i].mintKey);
|
96
|
-
return [4, client.program.account.custody.fetch(custodyAccountKey)];
|
97
|
-
case 3:
|
98
|
-
custodyAccountInfo = _c.sent();
|
99
|
-
ca = new CustodyAccount_1.CustodyAccount(POOL_CONFIG.custodies[i].custodyAccount, custodyAccountInfo);
|
100
|
-
custodyAccounts.push(ca);
|
101
|
-
_c.label = 4;
|
102
|
-
case 4:
|
103
|
-
i++;
|
104
|
-
return [3, 2];
|
105
|
-
case 5:
|
106
|
-
console.log("========== 2) PRICES ==============");
|
107
|
-
pythClient = new client_1.PythHttpClient(client.provider.connection, (0, client_1.getPythProgramKeyForCluster)('mainnet-beta'));
|
108
|
-
return [4, pythClient.getData()];
|
109
|
-
case 6:
|
110
|
-
pythHttpClientResult = _c.sent();
|
111
|
-
priceDataSOL = pythHttpClientResult.productPrice.get('Crypto.SOL/USD');
|
112
|
-
priceOracleSOL = new OraclePrice_1.OraclePrice({
|
113
|
-
price: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.aggregate.priceComponent.toString()),
|
114
|
-
exponent: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.exponent),
|
115
|
-
confidence: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.confidence),
|
116
|
-
timestamp: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.timestamp.toString()),
|
117
|
-
});
|
118
|
-
emaPriceOracleSOL = new OraclePrice_1.OraclePrice({
|
119
|
-
price: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.emaPrice.valueComponent.toString()),
|
120
|
-
exponent: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.exponent),
|
121
|
-
confidence: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.emaConfidence.valueComponent.toString()),
|
122
|
-
timestamp: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.timestamp.toString()),
|
123
|
-
});
|
124
|
-
priceDataUSDC = pythHttpClientResult.productPrice.get('Crypto.USDC/USD');
|
125
|
-
priceOracleUSDC = new OraclePrice_1.OraclePrice({
|
126
|
-
price: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.aggregate.priceComponent.toString()),
|
127
|
-
exponent: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.exponent),
|
128
|
-
confidence: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.confidence),
|
129
|
-
timestamp: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.timestamp.toString()),
|
130
|
-
});
|
131
|
-
emaPriceOracleUSDC = new OraclePrice_1.OraclePrice({
|
132
|
-
price: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.emaPrice.valueComponent.toString()),
|
133
|
-
exponent: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.exponent),
|
134
|
-
confidence: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.emaConfidence.valueComponent.toString()),
|
135
|
-
timestamp: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.timestamp.toString()),
|
136
|
-
});
|
137
|
-
priceDataBTC = pythHttpClientResult.productPrice.get('Crypto.BTC/USD');
|
138
|
-
priceOracleBTC = new OraclePrice_1.OraclePrice({
|
139
|
-
price: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.aggregate.priceComponent.toString()),
|
140
|
-
exponent: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.exponent),
|
141
|
-
confidence: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.confidence),
|
142
|
-
timestamp: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.timestamp.toString()),
|
143
|
-
});
|
144
|
-
emaPriceOracleBTC = new OraclePrice_1.OraclePrice({
|
145
|
-
price: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.emaPrice.valueComponent.toString()),
|
146
|
-
exponent: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.exponent),
|
147
|
-
confidence: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.emaConfidence.valueComponent.toString()),
|
148
|
-
timestamp: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.timestamp.toString()),
|
149
|
-
});
|
150
|
-
priceDataETH = pythHttpClientResult.productPrice.get('Crypto.ETH/USD');
|
151
|
-
priceOracleETH = new OraclePrice_1.OraclePrice({
|
152
|
-
price: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.aggregate.priceComponent.toString()),
|
153
|
-
exponent: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.exponent),
|
154
|
-
confidence: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.confidence),
|
155
|
-
timestamp: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.timestamp.toString()),
|
156
|
-
});
|
157
|
-
emaPriceOracleETH = new OraclePrice_1.OraclePrice({
|
158
|
-
price: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.emaPrice.valueComponent.toString()),
|
159
|
-
exponent: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.exponent),
|
160
|
-
confidence: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.emaConfidence.valueComponent.toString()),
|
161
|
-
timestamp: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.timestamp.toString()),
|
162
|
-
});
|
163
|
-
console.log("========== 3) POSITION SETUP ==============");
|
164
|
-
user = new web3_js_1.PublicKey("7QE3ZRYQyWLNKh5NZzaGZ4JViW8CedDBGZyojVo8tobY");
|
165
|
-
return [4, client.getPosition(new web3_js_1.PublicKey('AQN2s8kitS3Ye8RYYh865c5y9XMLKTNZrVBxMhLTHuFR'))];
|
166
|
-
case 7:
|
167
|
-
position = _c.sent();
|
168
|
-
newPosition = PositionAccount_1.PositionAccount.from(new web3_js_1.PublicKey('AQN2s8kitS3Ye8RYYh865c5y9XMLKTNZrVBxMhLTHuFR'), position);
|
169
|
-
console.log('position :>> ', newPosition);
|
170
|
-
currtime = new bn_js_1.BN((0, utils_1.getUnixTs)());
|
171
|
-
TEST_FUNCTION = function () { return __awaiter(void 0, void 0, void 0, function () {
|
172
|
-
var marketConfig, tokenETH, custodyAccountETH, x;
|
173
|
-
return __generator(this, function (_a) {
|
174
|
-
console.log("========== 4) TEST_FUNCTION : getDecreaseSizeCollateralAndFeeSync ==============");
|
175
|
-
marketConfig = POOL_CONFIG.markets.find(function (i) { return i.marketAccount.toBase58() == '8r5MBC3oULSWdm69yn2q3gBLp6h1AL4Wo11LBzcCZGWJ'; });
|
176
|
-
tokenETH = POOL_CONFIG.tokens.find(function (i) { return i.symbol == 'ETH'; });
|
177
|
-
custodyAccountETH = custodyAccounts.find(function (i) { return i.mint.toBase58() == tokenETH.mintKey.toBase58(); });
|
178
|
-
x = client.getDecreaseSizeCollateralAndFeeSync(newPosition, true, new bn_js_1.BN(1000000000), true, priceOracleETH, emaPriceOracleETH, marketConfig, custodyAccountETH, priceOracleSOL, emaPriceOracleSOL, custodyAccountETH, currtime, types_1.Side.Long, POOL_CONFIG, new bn_js_1.BN(0), true);
|
179
|
-
prettyPrint(x);
|
180
|
-
return [2];
|
181
|
-
});
|
182
|
-
}); };
|
183
|
-
return [4, TEST_FUNCTION()];
|
184
|
-
case 8:
|
185
|
-
_c.sent();
|
186
|
-
TEST_FLP_STAKE = function () { return __awaiter(void 0, void 0, void 0, function () {
|
187
|
-
return __generator(this, function (_a) {
|
188
|
-
return [2];
|
189
|
-
});
|
190
|
-
}); };
|
191
|
-
TEST_APY = function () { return __awaiter(void 0, void 0, void 0, function () {
|
192
|
-
var lpTokenInfo, nprices, custodyData;
|
193
|
-
return __generator(this, function (_a) {
|
194
|
-
switch (_a.label) {
|
195
|
-
case 0: return [4, (0, spl_token_1.getMint)(client.provider.connection, POOL_CONFIG.stakedLpTokenMint)];
|
196
|
-
case 1:
|
197
|
-
lpTokenInfo = _a.sent();
|
198
|
-
poolClient = new PoolDataClient_1.PoolDataClient(POOL_CONFIG, poolAccount, lpTokenInfo, custodyAccounts);
|
199
|
-
nprices = new Map();
|
200
|
-
nprices.set('USDC', { price: priceOracleUSDC, emaPrice: emaPriceOracleUSDC, isStale: false });
|
201
|
-
nprices.set('SOL', { price: priceOracleSOL, emaPrice: emaPriceOracleSOL, isStale: false });
|
202
|
-
nprices.set('BTC', { price: priceOracleBTC, emaPrice: emaPriceOracleBTC, isStale: false });
|
203
|
-
nprices.set('ETH', { price: priceOracleETH, emaPrice: emaPriceOracleETH, isStale: false });
|
204
|
-
custodyData = poolClient.getCustodyStats(nprices);
|
205
|
-
console.log("custodyData[0].availableToAddUsdUi:", custodyData[0].availableToAddUsdUi);
|
206
|
-
console.log("custodyAccounts[0]:", custodyAccounts[0]);
|
207
|
-
console.log("custodyAccounts[0].feesStats.rewardPerLpStaked:", custodyAccounts[0].feesStats.rewardPerLpStaked.toString());
|
208
|
-
return [2];
|
209
|
-
}
|
210
|
-
});
|
211
|
-
}); };
|
212
|
-
return [2];
|
213
|
-
}
|
214
|
-
});
|
215
|
-
}); };
|