flash-sdk 10.0.0-alpha.2 → 10.0.0-alpha.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/dist/PoolConfig.js +1 -1
- package/dist/PoolConfig.json +4016 -92
- package/dist/test2.d.ts +1 -0
- package/dist/test2.js +160 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/test2.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|
package/dist/test2.js
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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 PerpetualsClient_1 = require("./PerpetualsClient");
|
|
42
|
+
var anchor_1 = require("@coral-xyz/anchor");
|
|
43
|
+
var OraclePrice_1 = require("./OraclePrice");
|
|
44
|
+
var CustodyAccount_1 = require("./CustodyAccount");
|
|
45
|
+
var client_1 = require("@pythnetwork/client");
|
|
46
|
+
var PoolAccount_1 = require("./PoolAccount");
|
|
47
|
+
var PoolConfig_1 = require("./PoolConfig");
|
|
48
|
+
var client;
|
|
49
|
+
var poolClient;
|
|
50
|
+
var prettyPrint = function (object) {
|
|
51
|
+
console.log(JSON.stringify(object, null, 2));
|
|
52
|
+
};
|
|
53
|
+
function initClient(clusterUrl, adminKeyPath, programId, composabilityProgramId, fbNftRewardProgramId) {
|
|
54
|
+
process.env["ANCHOR_WALLET"] = adminKeyPath;
|
|
55
|
+
var provider = anchor_1.AnchorProvider.local(clusterUrl, {
|
|
56
|
+
commitment: "confirmed",
|
|
57
|
+
preflightCommitment: "confirmed",
|
|
58
|
+
skipPreflight: true
|
|
59
|
+
});
|
|
60
|
+
client = new PerpetualsClient_1.PerpetualsClient(provider, programId, composabilityProgramId, fbNftRewardProgramId, fbNftRewardProgramId, null);
|
|
61
|
+
client.log("Client Initialized");
|
|
62
|
+
}
|
|
63
|
+
var main2 = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
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;
|
|
65
|
+
var _a, _b;
|
|
66
|
+
return __generator(this, function (_c) {
|
|
67
|
+
switch (_c.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
console.log("========== 1) SETUP ==============");
|
|
70
|
+
url = (_a = process.env["RPC_URL"]) !== null && _a !== void 0 ? _a : 'https://flashtr-flash-885f.devnet.rpcpool.com/e0f3d11e-6673-4e02-b3f8-361d596ee7fe';
|
|
71
|
+
console.log("url:", url);
|
|
72
|
+
adminKey = (_b = process.env["KEYPAIR_PATH"]) !== null && _b !== void 0 ? _b : "/Users/aw/.config/solana/Beta-Hcik.json";
|
|
73
|
+
console.log("adminKey path:", adminKey);
|
|
74
|
+
poolName = "devnet.1";
|
|
75
|
+
POOL_CONFIG = PoolConfig_1.PoolConfig.fromIdsByName('devnet.1', 'devnet');
|
|
76
|
+
programId = POOL_CONFIG.programId;
|
|
77
|
+
composabilityProgramId = POOL_CONFIG.perpComposibilityProgramId;
|
|
78
|
+
initClient(url, adminKey, programId, composabilityProgramId, POOL_CONFIG.fbNftRewardProgramId);
|
|
79
|
+
poolKey = POOL_CONFIG.poolAddress;
|
|
80
|
+
return [4, client.getPool(poolName)];
|
|
81
|
+
case 1:
|
|
82
|
+
poolData = _c.sent();
|
|
83
|
+
poolAccount = new PoolAccount_1.PoolAccount(poolKey, poolData);
|
|
84
|
+
return [2];
|
|
85
|
+
case 2:
|
|
86
|
+
if (!(i < POOL_CONFIG.custodies.length)) return [3, 5];
|
|
87
|
+
custodyAccountKey = client.getCustodyKey(poolName, POOL_CONFIG.custodies[i].mintKey);
|
|
88
|
+
return [4, client.program.account.custody.fetch(custodyAccountKey)];
|
|
89
|
+
case 3:
|
|
90
|
+
custodyAccountInfo = _c.sent();
|
|
91
|
+
ca = new CustodyAccount_1.CustodyAccount(POOL_CONFIG.custodies[i].custodyAccount, custodyAccountInfo);
|
|
92
|
+
custodyAccounts.push(ca);
|
|
93
|
+
_c.label = 4;
|
|
94
|
+
case 4:
|
|
95
|
+
i++;
|
|
96
|
+
return [3, 2];
|
|
97
|
+
case 5:
|
|
98
|
+
console.log("========== 2) PRICES ==============");
|
|
99
|
+
pythClient = new client_1.PythHttpClient(client.provider.connection, (0, client_1.getPythProgramKeyForCluster)('mainnet-beta'));
|
|
100
|
+
return [4, pythClient.getData()];
|
|
101
|
+
case 6:
|
|
102
|
+
pythHttpClientResult = _c.sent();
|
|
103
|
+
priceDataSOL = pythHttpClientResult.productPrice.get('Crypto.SOL/USD');
|
|
104
|
+
priceOracleSOL = new OraclePrice_1.OraclePrice({
|
|
105
|
+
price: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.aggregate.priceComponent.toString()),
|
|
106
|
+
exponent: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.exponent),
|
|
107
|
+
confidence: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.confidence),
|
|
108
|
+
timestamp: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.timestamp.toString()),
|
|
109
|
+
});
|
|
110
|
+
emaPriceOracleSOL = new OraclePrice_1.OraclePrice({
|
|
111
|
+
price: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.emaPrice.valueComponent.toString()),
|
|
112
|
+
exponent: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.exponent),
|
|
113
|
+
confidence: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.emaConfidence.valueComponent.toString()),
|
|
114
|
+
timestamp: new bn_js_1.BN(priceDataSOL === null || priceDataSOL === void 0 ? void 0 : priceDataSOL.timestamp.toString()),
|
|
115
|
+
});
|
|
116
|
+
priceDataUSDC = pythHttpClientResult.productPrice.get('Crypto.USDC/USD');
|
|
117
|
+
priceOracleUSDC = new OraclePrice_1.OraclePrice({
|
|
118
|
+
price: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.aggregate.priceComponent.toString()),
|
|
119
|
+
exponent: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.exponent),
|
|
120
|
+
confidence: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.confidence),
|
|
121
|
+
timestamp: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.timestamp.toString()),
|
|
122
|
+
});
|
|
123
|
+
emaPriceOracleUSDC = new OraclePrice_1.OraclePrice({
|
|
124
|
+
price: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.emaPrice.valueComponent.toString()),
|
|
125
|
+
exponent: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.exponent),
|
|
126
|
+
confidence: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.emaConfidence.valueComponent.toString()),
|
|
127
|
+
timestamp: new bn_js_1.BN(priceDataUSDC === null || priceDataUSDC === void 0 ? void 0 : priceDataUSDC.timestamp.toString()),
|
|
128
|
+
});
|
|
129
|
+
priceDataBTC = pythHttpClientResult.productPrice.get('Crypto.BTC/USD');
|
|
130
|
+
priceOracleBTC = new OraclePrice_1.OraclePrice({
|
|
131
|
+
price: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.aggregate.priceComponent.toString()),
|
|
132
|
+
exponent: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.exponent),
|
|
133
|
+
confidence: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.confidence),
|
|
134
|
+
timestamp: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.timestamp.toString()),
|
|
135
|
+
});
|
|
136
|
+
emaPriceOracleBTC = new OraclePrice_1.OraclePrice({
|
|
137
|
+
price: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.emaPrice.valueComponent.toString()),
|
|
138
|
+
exponent: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.exponent),
|
|
139
|
+
confidence: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.emaConfidence.valueComponent.toString()),
|
|
140
|
+
timestamp: new bn_js_1.BN(priceDataBTC === null || priceDataBTC === void 0 ? void 0 : priceDataBTC.timestamp.toString()),
|
|
141
|
+
});
|
|
142
|
+
priceDataETH = pythHttpClientResult.productPrice.get('Crypto.ETH/USD');
|
|
143
|
+
priceOracleETH = new OraclePrice_1.OraclePrice({
|
|
144
|
+
price: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.aggregate.priceComponent.toString()),
|
|
145
|
+
exponent: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.exponent),
|
|
146
|
+
confidence: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.confidence),
|
|
147
|
+
timestamp: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.timestamp.toString()),
|
|
148
|
+
});
|
|
149
|
+
emaPriceOracleETH = new OraclePrice_1.OraclePrice({
|
|
150
|
+
price: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.emaPrice.valueComponent.toString()),
|
|
151
|
+
exponent: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.exponent),
|
|
152
|
+
confidence: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.emaConfidence.valueComponent.toString()),
|
|
153
|
+
timestamp: new bn_js_1.BN(priceDataETH === null || priceDataETH === void 0 ? void 0 : priceDataETH.timestamp.toString()),
|
|
154
|
+
});
|
|
155
|
+
console.log("========== 3) POSITION SETUP ==============");
|
|
156
|
+
return [2];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); };
|
|
160
|
+
main2();
|