@typus/typus-sdk 0.2.1 → 0.2.3
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/README.md +6 -3
- package/lib/constants.d.ts +11 -9
- package/lib/constants.js +12 -10
- package/lib/scripts/coveredCall/getNewCoveredCallVaultTx.js +7 -2
- package/lib/scripts/coveredCall/getUpdatePayoffConfigTx.js +3 -2
- package/lib/{scripts/getCoveredCallVaultAsset.d.ts → test/getUsersShares.d.ts} +0 -0
- package/lib/{scripts/getCoveredCallVaultAsset.js → test/getUsersShares.js} +6 -9
- package/lib/test/{getUserDepositData.d.ts → getVaultData.d.ts} +0 -0
- package/lib/test/{getUserDepositData.js → getVaultData.js} +6 -18
- package/lib/test/testClaim.d.ts +1 -0
- package/lib/test/testClaim.js +81 -0
- package/lib/test/testDeposit.js +2 -2
- package/lib/test/testMint.js +5 -1
- package/lib/test/testNewVault.js +35 -61
- package/lib/test/testOracle.js +4 -0
- package/lib/test/testSettle.js +139 -142
- package/lib/utils/coveredCall/createTimeOracle.d.ts +1 -0
- package/lib/utils/coveredCall/createTimeOracle.js +91 -0
- package/lib/utils/coveredCall/getClaimAllTx.js +2 -2
- package/lib/utils/coveredCall/getDepositTx.js +1 -1
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.d.ts +1 -1
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.js +6 -1
- package/lib/utils/coveredCall/getUpdatePayoffConfigTx.d.ts +1 -1
- package/lib/utils/coveredCall/getUpdatePayoffConfigTx.js +2 -1
- package/lib/utils/fetchData.d.ts +19 -0
- package/lib/utils/fetchData.js +21 -12
- package/lib/utils/getTypeArgumentFromToken.js +5 -3
- package/lib/utils/getUsersShares.d.ts +8 -0
- package/lib/utils/getUsersShares.js +145 -0
- package/lib/utils/getVaultData.d.ts +2 -0
- package/lib/utils/getVaultData.js +135 -0
- package/lib/utils/getVaultIndexInRegistry.js +4 -0
- package/lib/utils/isObjAvailable.d.ts +1 -0
- package/lib/utils/{getCoveredCallVaultAsset.js → isObjAvailable.js} +17 -9
- package/package.json +3 -2
- package/lib/utils/getCoveredCallVaultAsset.d.ts +0 -1
- package/lib/utils/getSubVault.d.ts +0 -0
- package/lib/utils/getSubVault.js +0 -52
|
@@ -0,0 +1,91 @@
|
|
|
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 (_) 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
|
+
exports.createTimeOracle = void 0;
|
|
40
|
+
var getNewTimeOracleTx_1 = require("../getNewTimeOracleTx");
|
|
41
|
+
var constants_1 = require("../../constants");
|
|
42
|
+
var sui_js_1 = require("@mysten/sui.js");
|
|
43
|
+
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
44
|
+
var keypair = sui_js_1.Ed25519Keypair.deriveKeypair(constants_1.TEST_MNEMONIC);
|
|
45
|
+
var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
46
|
+
function createTimeOracle() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var _this = this;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
var newTimeOracleTx, moveCallTxn, digest, txn, timeOracle, managerCap, e_1;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
_a.trys.push([0, 4, , 5]);
|
|
56
|
+
console.log("create new time oracle...");
|
|
57
|
+
return [4 /*yield*/, (0, getNewTimeOracleTx_1.getNewTimeOracleTx)(constants_1.ORACLE_PACKAGE)];
|
|
58
|
+
case 1:
|
|
59
|
+
newTimeOracleTx = _a.sent();
|
|
60
|
+
return [4 /*yield*/, signer.executeMoveCall(newTimeOracleTx)];
|
|
61
|
+
case 2:
|
|
62
|
+
moveCallTxn = _a.sent();
|
|
63
|
+
digest = moveCallTxn.EffectsCert.certificate.transactionDigest;
|
|
64
|
+
return [4 /*yield*/, provider.getTransactionWithEffects(digest)];
|
|
65
|
+
case 3:
|
|
66
|
+
txn = _a.sent();
|
|
67
|
+
timeOracle = void 0;
|
|
68
|
+
managerCap = void 0;
|
|
69
|
+
if (txn.effects.created[0].owner["AddressOwner"] == undefined) {
|
|
70
|
+
timeOracle = txn.effects.created[0].reference.objectId;
|
|
71
|
+
managerCap = txn.effects.created[1].reference.objectId;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
timeOracle = txn.effects.created[1].reference.objectId;
|
|
75
|
+
managerCap = txn.effects.created[0].reference.objectId;
|
|
76
|
+
}
|
|
77
|
+
resolve([timeOracle, managerCap]);
|
|
78
|
+
return [3 /*break*/, 5];
|
|
79
|
+
case 4:
|
|
80
|
+
e_1 = _a.sent();
|
|
81
|
+
console.log("err in createTimeOracle");
|
|
82
|
+
reject(e_1);
|
|
83
|
+
return [3 /*break*/, 5];
|
|
84
|
+
case 5: return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); })];
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.createTimeOracle = createTimeOracle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getNewCoveredCallVaultTx(packageId: string, registry: string, typeArgument: string, managerCap: string, expiration: number, strike: number): Promise<any>;
|
|
1
|
+
export declare function getNewCoveredCallVaultTx(packageId: string, registry: string, typeArgument: string, managerCap: string, tokenDecimal: number, shareDecimal: number, timeOracle: string, period: number, start: number, expiration: number, strike: number): Promise<any>;
|
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getNewCoveredCallVaultTx = void 0;
|
|
40
|
-
function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap, expiration, strike) {
|
|
40
|
+
function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap, tokenDecimal, shareDecimal, timeOracle, period, start, expiration, strike) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -49,6 +49,11 @@ function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap,
|
|
|
49
49
|
arguments: [
|
|
50
50
|
managerCap,
|
|
51
51
|
registry,
|
|
52
|
+
tokenDecimal,
|
|
53
|
+
shareDecimal,
|
|
54
|
+
timeOracle,
|
|
55
|
+
period,
|
|
56
|
+
start,
|
|
52
57
|
expiration,
|
|
53
58
|
strike,
|
|
54
59
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getUpdatePayoffConfigTx(packageId: string, registry: string, typeArgument: string, managerCap: string, index: number, price: number, roi: number): Promise<any>;
|
|
1
|
+
export declare function getUpdatePayoffConfigTx(packageId: string, registry: string, typeArgument: string, managerCap: string, index: number, price: number, roi: number, exposureRatio: number): Promise<any>;
|
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getUpdatePayoffConfigTx = void 0;
|
|
40
|
-
function getUpdatePayoffConfigTx(packageId, registry, typeArgument, managerCap, index, price, roi) {
|
|
40
|
+
function getUpdatePayoffConfigTx(packageId, registry, typeArgument, managerCap, index, price, roi, exposureRatio) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -52,6 +52,7 @@ function getUpdatePayoffConfigTx(packageId, registry, typeArgument, managerCap,
|
|
|
52
52
|
index,
|
|
53
53
|
price,
|
|
54
54
|
roi,
|
|
55
|
+
exposureRatio,
|
|
55
56
|
],
|
|
56
57
|
gasBudget: 1000,
|
|
57
58
|
};
|
package/lib/utils/fetchData.d.ts
CHANGED
|
@@ -3,6 +3,25 @@ export interface SubVaults {
|
|
|
3
3
|
maker: string;
|
|
4
4
|
regular: string;
|
|
5
5
|
}
|
|
6
|
+
export interface Vault {
|
|
7
|
+
vaultId: string;
|
|
8
|
+
vaultIdx: number;
|
|
9
|
+
asset: string;
|
|
10
|
+
ableToDeposit: boolean;
|
|
11
|
+
ableToWithdraw: boolean;
|
|
12
|
+
expirationTsMs: number;
|
|
13
|
+
payoffConfig: PayoffConfig;
|
|
14
|
+
period: number;
|
|
15
|
+
shareDecimal: number;
|
|
16
|
+
startTsMs: number;
|
|
17
|
+
tokenDecimal: number;
|
|
18
|
+
}
|
|
19
|
+
export interface PayoffConfig {
|
|
20
|
+
exposureRatio: number;
|
|
21
|
+
premiumRoi: number;
|
|
22
|
+
strike: number;
|
|
23
|
+
strikeOtmPct: number;
|
|
24
|
+
}
|
|
6
25
|
export declare function getCoveredCallVaultsFromRegistry(registry: string): Promise<any>;
|
|
7
26
|
export declare function getTableFromCoveredCallVault(coveredCallVault: string): Promise<any>;
|
|
8
27
|
export declare function getSubVaultsFromTable(tableUnderCoveredCallVault: string): Promise<SubVaults>;
|
package/lib/utils/fetchData.js
CHANGED
|
@@ -51,6 +51,7 @@ exports.getUserDataFromLinkedListNode = exports.getLinkedListNodesFromTable = ex
|
|
|
51
51
|
var sui_js_1 = require("@mysten/sui.js");
|
|
52
52
|
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
53
53
|
var decode = function (str) { return Buffer.from(str, 'base64').toString('binary'); };
|
|
54
|
+
//new version: getVaultDataFromRegistry()
|
|
54
55
|
function getCoveredCallVaultsFromRegistry(registry) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
57
|
var coveredCallVaults;
|
|
@@ -75,11 +76,13 @@ function getTableFromCoveredCallVault(coveredCallVault) {
|
|
|
75
76
|
switch (_a.label) {
|
|
76
77
|
case 0:
|
|
77
78
|
console.log("coveredCallVault: " + coveredCallVault);
|
|
78
|
-
return [4 /*yield*/, provider.getObject(coveredCallVault)
|
|
79
|
-
//@ts-ignore
|
|
80
|
-
];
|
|
79
|
+
return [4 /*yield*/, provider.getObject(coveredCallVault)];
|
|
81
80
|
case 1:
|
|
82
81
|
tmp = _a.sent();
|
|
82
|
+
if (tmp.status != "Exists") {
|
|
83
|
+
console.log("obj not exists");
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
83
86
|
tableUnderCoveredCallVault = tmp.details.data.fields.value.fields.vault.fields.sub_vaults.fields.id.id;
|
|
84
87
|
console.log("table : " + tableUnderCoveredCallVault);
|
|
85
88
|
return [2 /*return*/, tableUnderCoveredCallVault];
|
|
@@ -107,11 +110,13 @@ function getSubVaultsFromTable(tableUnderCoveredCallVault) {
|
|
|
107
110
|
case 3:
|
|
108
111
|
if (!!subVaults_1_1.done) return [3 /*break*/, 6];
|
|
109
112
|
subVault = subVaults_1_1.value;
|
|
110
|
-
return [4 /*yield*/, provider.getObject(subVault.objectId)
|
|
111
|
-
//@ts-ignore
|
|
112
|
-
];
|
|
113
|
+
return [4 /*yield*/, provider.getObject(subVault.objectId)];
|
|
113
114
|
case 4:
|
|
114
115
|
txn = _b.sent();
|
|
116
|
+
if (txn.status != "Exists") {
|
|
117
|
+
console.log("obj not exists");
|
|
118
|
+
return [2 /*return*/, {}];
|
|
119
|
+
}
|
|
115
120
|
name_1 = decode(txn.details.data.fields.name) //rolling / regular / maker
|
|
116
121
|
;
|
|
117
122
|
//@ts-ignore
|
|
@@ -147,11 +152,13 @@ function getTableUnderSubVault(subVault) {
|
|
|
147
152
|
switch (_a.label) {
|
|
148
153
|
case 0:
|
|
149
154
|
console.log("sub vault: " + subVault);
|
|
150
|
-
return [4 /*yield*/, provider.getObject(subVault)
|
|
151
|
-
//@ts-ignore
|
|
152
|
-
];
|
|
155
|
+
return [4 /*yield*/, provider.getObject(subVault)];
|
|
153
156
|
case 1:
|
|
154
157
|
tmp = _a.sent();
|
|
158
|
+
if (tmp.status != "Exists") {
|
|
159
|
+
console.log("obj not exists");
|
|
160
|
+
return [2 /*return*/, ""];
|
|
161
|
+
}
|
|
155
162
|
table = tmp.details.data.fields.value.fields.user_shares.fields.nodes.fields.id.id;
|
|
156
163
|
console.log("table under sub vault: ", table);
|
|
157
164
|
return [2 /*return*/, table];
|
|
@@ -180,11 +187,13 @@ function getUserDataFromLinkedListNode(linkedListNode) {
|
|
|
180
187
|
var tmp, usersData;
|
|
181
188
|
return __generator(this, function (_a) {
|
|
182
189
|
switch (_a.label) {
|
|
183
|
-
case 0: return [4 /*yield*/, provider.getObject(linkedListNode)
|
|
184
|
-
//@ts-ignore
|
|
185
|
-
];
|
|
190
|
+
case 0: return [4 /*yield*/, provider.getObject(linkedListNode)];
|
|
186
191
|
case 1:
|
|
187
192
|
tmp = _a.sent();
|
|
193
|
+
if (tmp.status != "Exists") {
|
|
194
|
+
console.log("obj not exists");
|
|
195
|
+
return [2 /*return*/];
|
|
196
|
+
}
|
|
188
197
|
usersData = tmp.details.data.fields;
|
|
189
198
|
console.log("users data from linked list node:");
|
|
190
199
|
console.log(usersData);
|
|
@@ -46,11 +46,13 @@ function getTypeArgumentFromToken(token) {
|
|
|
46
46
|
switch (_a.label) {
|
|
47
47
|
case 0:
|
|
48
48
|
_a.trys.push([0, 2, , 3]);
|
|
49
|
-
return [4 /*yield*/, provider.getObject(token)
|
|
50
|
-
//@ts-ignore
|
|
51
|
-
];
|
|
49
|
+
return [4 /*yield*/, provider.getObject(token)];
|
|
52
50
|
case 1:
|
|
53
51
|
tmp = _a.sent();
|
|
52
|
+
if (tmp.status != "Exists") {
|
|
53
|
+
console.log("obj not exists");
|
|
54
|
+
return [2 /*return*/];
|
|
55
|
+
}
|
|
54
56
|
typeArgument = tmp.details.data.type;
|
|
55
57
|
typeArgument = typeArgument.split("<")[1];
|
|
56
58
|
typeArgument = typeArgument.split(">")[0];
|
|
@@ -0,0 +1,145 @@
|
|
|
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 (_) 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
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.getUsersShares = void 0;
|
|
51
|
+
var sui_js_1 = require("@mysten/sui.js");
|
|
52
|
+
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
53
|
+
function getSubVaultsData(registry) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var subVaultsData, coveredCallVaults, coveredCallVaultsId, objsInfo, objsInfo_1, objsInfo_1_1, objInfo, vaultId, vault, subVaultData;
|
|
56
|
+
var e_1, _a;
|
|
57
|
+
return __generator(this, function (_b) {
|
|
58
|
+
switch (_b.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
subVaultsData = new Map();
|
|
61
|
+
return [4 /*yield*/, provider.getObjectsOwnedByObject(registry)];
|
|
62
|
+
case 1:
|
|
63
|
+
coveredCallVaults = _b.sent();
|
|
64
|
+
coveredCallVaultsId = coveredCallVaults.map(function (e) { return e.objectId; });
|
|
65
|
+
return [4 /*yield*/, provider.getObjectBatch(coveredCallVaultsId)];
|
|
66
|
+
case 2:
|
|
67
|
+
objsInfo = _b.sent();
|
|
68
|
+
try {
|
|
69
|
+
for (objsInfo_1 = __values(objsInfo), objsInfo_1_1 = objsInfo_1.next(); !objsInfo_1_1.done; objsInfo_1_1 = objsInfo_1.next()) {
|
|
70
|
+
objInfo = objsInfo_1_1.value;
|
|
71
|
+
if (objInfo.status != "Exists") {
|
|
72
|
+
console.log("obj not exist");
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
vaultId = Number(objInfo.details.data.fields.name);
|
|
76
|
+
vault = objInfo.details.data.fields.value.fields.vault.fields;
|
|
77
|
+
subVaultData = {
|
|
78
|
+
regularTotalSupply: Number(vault.regular_sub_vault.fields.share_supply),
|
|
79
|
+
regularTotalBalance: Number(vault.regular_sub_vault.fields.balance),
|
|
80
|
+
isRollingTotalSupply: Number(vault.rolling_sub_vault.fields.share_supply),
|
|
81
|
+
isRollingTotalBalance: Number(vault.rolling_sub_vault.fields.balance),
|
|
82
|
+
};
|
|
83
|
+
subVaultsData.set(vaultId, subVaultData);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
if (objsInfo_1_1 && !objsInfo_1_1.done && (_a = objsInfo_1.return)) _a.call(objsInfo_1);
|
|
90
|
+
}
|
|
91
|
+
finally { if (e_1) throw e_1.error; }
|
|
92
|
+
}
|
|
93
|
+
return [2 /*return*/, subVaultsData];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function getUsersShares(userShareTable, registry) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var subVaultsData, userShareIds, userShares;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, getSubVaultsData(registry)]; //vault idx to subvault info
|
|
104
|
+
case 1:
|
|
105
|
+
subVaultsData = _a.sent() //vault idx to subvault info
|
|
106
|
+
;
|
|
107
|
+
return [4 /*yield*/, provider.getObjectsOwnedByObject(userShareTable)];
|
|
108
|
+
case 2:
|
|
109
|
+
userShareIds = (_a.sent()).map(function (x) { return x.objectId; });
|
|
110
|
+
return [4 /*yield*/, provider.getObjectBatch(userShareIds)];
|
|
111
|
+
case 3:
|
|
112
|
+
userShares = (_a.sent()).map(function (x) {
|
|
113
|
+
var _a, _b, _c, _d;
|
|
114
|
+
if (x.status != "Exists") {
|
|
115
|
+
console.log("obj not exist");
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
var index = Number(x.details.data.fields.name.fields.index);
|
|
120
|
+
//@ts-ignore
|
|
121
|
+
var isRolling = Boolean(x.details.data.fields.name.fields.is_rolling);
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
var share = Number(x.details.data.fields.value);
|
|
124
|
+
//user deposit amount = (user share/total share) * total balance
|
|
125
|
+
var depositAmount = isRolling ?
|
|
126
|
+
(share * ((_a = subVaultsData.get(index)) === null || _a === void 0 ? void 0 : _a.isRollingTotalSupply) / ((_b = subVaultsData.get(index)) === null || _b === void 0 ? void 0 : _b.isRollingTotalBalance)) :
|
|
127
|
+
(share * ((_c = subVaultsData.get(index)) === null || _c === void 0 ? void 0 : _c.regularTotalSupply) / ((_d = subVaultsData.get(index)) === null || _d === void 0 ? void 0 : _d.regularTotalBalance));
|
|
128
|
+
var res = {
|
|
129
|
+
coveredCallVaultIndex: index,
|
|
130
|
+
//@ts-ignore
|
|
131
|
+
isRolling: isRolling,
|
|
132
|
+
//@ts-ignore
|
|
133
|
+
share: share,
|
|
134
|
+
//@ts-ignore
|
|
135
|
+
user: x.details.data.fields.name.fields.user,
|
|
136
|
+
depositAmount: depositAmount,
|
|
137
|
+
};
|
|
138
|
+
return res;
|
|
139
|
+
});
|
|
140
|
+
return [2 /*return*/, userShares];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
exports.getUsersShares = getUsersShares;
|
|
@@ -0,0 +1,135 @@
|
|
|
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 (_) 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
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.getVaultDataFromRegistry = void 0;
|
|
51
|
+
var sui_js_1 = require("@mysten/sui.js");
|
|
52
|
+
var constants_1 = require("../constants");
|
|
53
|
+
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
54
|
+
function getVaultDataFromRegistry(registry) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var coveredCallVaults, coveredCallVaultsId, objsInfo, vaults, _loop_1, objsInfo_1, objsInfo_1_1, objInfo;
|
|
57
|
+
var e_1, _a;
|
|
58
|
+
return __generator(this, function (_b) {
|
|
59
|
+
switch (_b.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
console.log("registry: " + registry);
|
|
62
|
+
return [4 /*yield*/, provider.getObjectsOwnedByObject(registry)];
|
|
63
|
+
case 1:
|
|
64
|
+
coveredCallVaults = _b.sent();
|
|
65
|
+
coveredCallVaultsId = coveredCallVaults.map(function (e) { return e.objectId; });
|
|
66
|
+
return [4 /*yield*/, provider.getObjectBatch(coveredCallVaultsId)];
|
|
67
|
+
case 2:
|
|
68
|
+
objsInfo = _b.sent();
|
|
69
|
+
vaults = [];
|
|
70
|
+
_loop_1 = function (objInfo) {
|
|
71
|
+
if (objInfo.status != "Exists") {
|
|
72
|
+
console.log("obj not exist");
|
|
73
|
+
return "continue";
|
|
74
|
+
}
|
|
75
|
+
//vault
|
|
76
|
+
//@ts-ignore
|
|
77
|
+
var vault = objInfo.details.data.fields.value.fields.vault.fields;
|
|
78
|
+
//config
|
|
79
|
+
//@ts-ignore
|
|
80
|
+
var config = objInfo.details.data.fields.value.fields.config.fields;
|
|
81
|
+
//vaultIdx
|
|
82
|
+
//@ts-ignore
|
|
83
|
+
var vaultIdx = objInfo.details.data.fields.name;
|
|
84
|
+
//asset
|
|
85
|
+
//@ts-ignore
|
|
86
|
+
var type = objInfo.details.data.fields.value.type;
|
|
87
|
+
var asset = constants_1.TOKEN_NAME.find(function (e) { return type.includes(e); });
|
|
88
|
+
if (!asset) {
|
|
89
|
+
console.log("can't find token");
|
|
90
|
+
asset = "";
|
|
91
|
+
}
|
|
92
|
+
//vaultId
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
var vaultId = objInfo.details.data.fields.id.id;
|
|
95
|
+
//payoff config
|
|
96
|
+
var payoffConfig = {
|
|
97
|
+
exposureRatio: Number(config.payoff_config.fields.exposure_ratio),
|
|
98
|
+
premiumRoi: Number(config.payoff_config.fields.premium_roi),
|
|
99
|
+
strike: Number(config.payoff_config.fields.strike),
|
|
100
|
+
strikeOtmPct: Number(config.payoff_config.fields.strike_otm_pct)
|
|
101
|
+
};
|
|
102
|
+
var res = {
|
|
103
|
+
vaultId: vaultId,
|
|
104
|
+
vaultIdx: vaultIdx,
|
|
105
|
+
asset: asset,
|
|
106
|
+
ableToDeposit: vault.able_to_deposit,
|
|
107
|
+
ableToWithdraw: vault.able_to_withdraw,
|
|
108
|
+
expirationTsMs: config.expiration_ts_ms,
|
|
109
|
+
payoffConfig: payoffConfig,
|
|
110
|
+
period: Number(config.period),
|
|
111
|
+
shareDecimal: config.share_decimal,
|
|
112
|
+
startTsMs: config.start_ts_ms,
|
|
113
|
+
tokenDecimal: config.token_decimal,
|
|
114
|
+
};
|
|
115
|
+
vaults.push(res);
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
for (objsInfo_1 = __values(objsInfo), objsInfo_1_1 = objsInfo_1.next(); !objsInfo_1_1.done; objsInfo_1_1 = objsInfo_1.next()) {
|
|
119
|
+
objInfo = objsInfo_1_1.value;
|
|
120
|
+
_loop_1(objInfo);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
124
|
+
finally {
|
|
125
|
+
try {
|
|
126
|
+
if (objsInfo_1_1 && !objsInfo_1_1.done && (_a = objsInfo_1.return)) _a.call(objsInfo_1);
|
|
127
|
+
}
|
|
128
|
+
finally { if (e_1) throw e_1.error; }
|
|
129
|
+
}
|
|
130
|
+
return [2 /*return*/, vaults];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
exports.getVaultDataFromRegistry = getVaultDataFromRegistry;
|
|
@@ -47,6 +47,10 @@ function getVaultIndexInregistry(registry) {
|
|
|
47
47
|
case 0: return [4 /*yield*/, provider.getObject(registry)];
|
|
48
48
|
case 1:
|
|
49
49
|
txn = _a.sent();
|
|
50
|
+
if (txn.status != "Exists") {
|
|
51
|
+
console.log("obj not exists");
|
|
52
|
+
return [2 /*return*/, -1];
|
|
53
|
+
}
|
|
50
54
|
index = txn.details.data.fields.name;
|
|
51
55
|
return [2 /*return*/, index];
|
|
52
56
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isObjAvailable(obj: string): Promise<Boolean>;
|
|
@@ -36,23 +36,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.isObjAvailable = void 0;
|
|
40
40
|
var sui_js_1 = require("@mysten/sui.js");
|
|
41
|
+
var rpc = new sui_js_1.JsonRpcProvider('https://fullnode.devnet.sui.io:443');
|
|
41
42
|
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
42
|
-
function
|
|
43
|
+
function isObjAvailable(obj) {
|
|
43
44
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var tmp,
|
|
45
|
+
var tmp, e_1;
|
|
45
46
|
return __generator(this, function (_a) {
|
|
46
47
|
switch (_a.label) {
|
|
47
|
-
case 0:
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
case 0:
|
|
49
|
+
_a.trys.push([0, 2, , 3]);
|
|
50
|
+
return [4 /*yield*/, provider.getObject(obj)];
|
|
50
51
|
case 1:
|
|
51
52
|
tmp = _a.sent();
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
if (tmp.status == "Exists")
|
|
54
|
+
return [2 /*return*/, true];
|
|
55
|
+
else
|
|
56
|
+
return [2 /*return*/, false];
|
|
57
|
+
return [3 /*break*/, 3];
|
|
58
|
+
case 2:
|
|
59
|
+
e_1 = _a.sent();
|
|
60
|
+
return [2 /*return*/, false];
|
|
61
|
+
case 3: return [2 /*return*/];
|
|
54
62
|
}
|
|
55
63
|
});
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
|
-
exports.
|
|
66
|
+
exports.isObjAvailable = isObjAvailable;
|
package/package.json
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
"name": "@typus/typus-sdk",
|
|
3
3
|
"author": "Typus",
|
|
4
4
|
"description": "typus sdk",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.3",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@mysten/
|
|
7
|
+
"@mysten/bcs": "^0.5.0",
|
|
8
|
+
"@mysten/sui.js": "^0.20.0",
|
|
8
9
|
"@types/node": "^17.0.0",
|
|
9
10
|
"bs58": "^4.0.1",
|
|
10
11
|
"builtin-modules": "^1.1.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCoveredCallVaultAsset(vault: string): Promise<string>;
|