@typus/typus-sdk 0.2.2 → 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/lib/constants.d.ts +11 -11
- package/lib/constants.js +11 -11
- package/lib/scripts/coveredCall/getNewCoveredCallVaultTx.js +4 -2
- package/lib/test/getUsersShares.js +1 -1
- package/lib/test/getVaultData.js +1 -1
- package/lib/test/testDeposit.js +2 -2
- package/lib/test/testMint.js +4 -0
- package/lib/test/testNewVault.js +4 -2
- package/lib/test/testOracle.js +4 -0
- package/lib/test/testSettle.js +12 -7
- package/lib/utils/coveredCall/getDepositTx.js +1 -1
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.d.ts +1 -1
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.js +3 -1
- package/lib/utils/fetchData.d.ts +14 -0
- package/lib/utils/fetchData.js +20 -12
- package/lib/utils/getTypeArgumentFromToken.js +5 -3
- package/lib/utils/getUsersShares.d.ts +2 -1
- package/lib/utils/getUsersShares.js +84 -12
- package/lib/utils/getVaultData.js +38 -12
- package/lib/utils/getVaultIndexInRegistry.js +4 -0
- package/package.json +1 -1
- package/lib/utils/getSubVault.d.ts +0 -0
- package/lib/utils/getSubVault.js +0 -52
package/lib/constants.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export declare const TOKEN_PACKAGE = "
|
|
2
|
-
export declare const TOKEN_REGISTRY_BTC = "
|
|
3
|
-
export declare const TOKEN_REGISTRY_ETH = "
|
|
4
|
-
export declare const TOKEN_REGISTRY_SUI = "
|
|
5
|
-
export declare const ORACLE_PACKAGE = "
|
|
6
|
-
export declare const COVERED_CALL_PACKAGE = "
|
|
7
|
-
export declare const COVERED_CALL_REGISTRY = "
|
|
8
|
-
export declare const COVERED_CALL_MANAGER = "
|
|
9
|
-
export declare const USER_SHARE_TABLE = "
|
|
10
|
-
export declare const MAKER_SHARE_TABLE = "
|
|
11
|
-
export declare const DOV_PACKAGE = "
|
|
1
|
+
export declare const TOKEN_PACKAGE = "0x97cfaa5d2a79c1be5da410870deb258ed5f42561";
|
|
2
|
+
export declare const TOKEN_REGISTRY_BTC = "0xb10e4bf339c2495d793647fa726fd5427ca8c328";
|
|
3
|
+
export declare const TOKEN_REGISTRY_ETH = "0x59c42da8bb8a3b98a764985af1d9cef7e6e9f87d";
|
|
4
|
+
export declare const TOKEN_REGISTRY_SUI = "0xf4a1954d812748ee08dd4c4c1e21bb136a6c089e";
|
|
5
|
+
export declare const ORACLE_PACKAGE = "0x437d2eb473bd348ad22b37ffb84bd652656026b1";
|
|
6
|
+
export declare const COVERED_CALL_PACKAGE = "0x5ece57f5f85a00ad812afd9a4a7b7781d157f7ed";
|
|
7
|
+
export declare const COVERED_CALL_REGISTRY = "0x189cf44a4a1daa77df7aab6d5894e2712843c2c9";
|
|
8
|
+
export declare const COVERED_CALL_MANAGER = "0x7e39015e03494ebcb976120a0ac2f112c1602dc2";
|
|
9
|
+
export declare const USER_SHARE_TABLE = "0x59cd2080bfc2ac8bbf917339372f1c36d44431c5";
|
|
10
|
+
export declare const MAKER_SHARE_TABLE = "0x4b3457ee86bd47048006b181738dd5a29263d4b2";
|
|
11
|
+
export declare const DOV_PACKAGE = "0x3674cf36f02160cdf3fd983629fed062f2306461";
|
|
12
12
|
export declare const DEFAULT_TYPE_ARGUMENT = "0x2::sui::SUI";
|
|
13
13
|
export declare const FAKE_TOKEN_TYPE_ARGUMENT = "0x27b3674c685046f66cad1d5496d2967894fa5329::token::USDC";
|
|
14
14
|
export declare const TEST_MNEMONIC = "plug grain matter asthma aware critic can lottery blouse uncover sauce speak";
|
package/lib/constants.js
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TOKEN_NAME_TO_MODULE = exports.TOKEN_NAME = exports.TEST_MNEMONIC = exports.FAKE_TOKEN_TYPE_ARGUMENT = exports.DEFAULT_TYPE_ARGUMENT = exports.DOV_PACKAGE = exports.MAKER_SHARE_TABLE = exports.USER_SHARE_TABLE = exports.COVERED_CALL_MANAGER = exports.COVERED_CALL_REGISTRY = exports.COVERED_CALL_PACKAGE = exports.ORACLE_PACKAGE = exports.TOKEN_REGISTRY_SUI = exports.TOKEN_REGISTRY_ETH = exports.TOKEN_REGISTRY_BTC = exports.TOKEN_PACKAGE = void 0;
|
|
4
4
|
//publish from sui-dev-token
|
|
5
|
-
exports.TOKEN_PACKAGE = "
|
|
6
|
-
exports.TOKEN_REGISTRY_BTC = "
|
|
7
|
-
exports.TOKEN_REGISTRY_ETH = "
|
|
8
|
-
exports.TOKEN_REGISTRY_SUI = "
|
|
5
|
+
exports.TOKEN_PACKAGE = "0x97cfaa5d2a79c1be5da410870deb258ed5f42561";
|
|
6
|
+
exports.TOKEN_REGISTRY_BTC = "0xb10e4bf339c2495d793647fa726fd5427ca8c328"; //fake btc registry
|
|
7
|
+
exports.TOKEN_REGISTRY_ETH = "0x59c42da8bb8a3b98a764985af1d9cef7e6e9f87d"; //fake eth registry
|
|
8
|
+
exports.TOKEN_REGISTRY_SUI = "0xf4a1954d812748ee08dd4c4c1e21bb136a6c089e"; //fake usdc registry
|
|
9
9
|
//publish from typus-oracle
|
|
10
|
-
exports.ORACLE_PACKAGE = "
|
|
10
|
+
exports.ORACLE_PACKAGE = "0x437d2eb473bd348ad22b37ffb84bd652656026b1";
|
|
11
11
|
//publish from typus-dov/cover_call
|
|
12
|
-
exports.COVERED_CALL_PACKAGE = "
|
|
13
|
-
exports.COVERED_CALL_REGISTRY = "
|
|
14
|
-
exports.COVERED_CALL_MANAGER = "
|
|
15
|
-
exports.USER_SHARE_TABLE = "
|
|
16
|
-
exports.MAKER_SHARE_TABLE = "
|
|
12
|
+
exports.COVERED_CALL_PACKAGE = "0x5ece57f5f85a00ad812afd9a4a7b7781d157f7ed";
|
|
13
|
+
exports.COVERED_CALL_REGISTRY = "0x189cf44a4a1daa77df7aab6d5894e2712843c2c9";
|
|
14
|
+
exports.COVERED_CALL_MANAGER = "0x7e39015e03494ebcb976120a0ac2f112c1602dc2";
|
|
15
|
+
exports.USER_SHARE_TABLE = "0x59cd2080bfc2ac8bbf917339372f1c36d44431c5";
|
|
16
|
+
exports.MAKER_SHARE_TABLE = "0x4b3457ee86bd47048006b181738dd5a29263d4b2";
|
|
17
17
|
//publish from typus-dov/typus-dov
|
|
18
|
-
exports.DOV_PACKAGE = "
|
|
18
|
+
exports.DOV_PACKAGE = "0x3674cf36f02160cdf3fd983629fed062f2306461";
|
|
19
19
|
exports.DEFAULT_TYPE_ARGUMENT = "0x2::sui::SUI";
|
|
20
20
|
exports.FAKE_TOKEN_TYPE_ARGUMENT = "0x27b3674c685046f66cad1d5496d2967894fa5329::token::USDC";
|
|
21
21
|
exports.TEST_MNEMONIC = "plug grain matter asthma aware critic can lottery blouse uncover sauce speak";
|
|
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var getNewCoveredCallVaultTx_1 = require("../../utils/coveredCall/getNewCoveredCallVaultTx");
|
|
40
40
|
var constants_1 = require("../../constants");
|
|
41
41
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var expiration, strike, tokenDecimal, shareDecimal, timeOracle, newCoveredCallVaultTx;
|
|
42
|
+
var expiration, strike, tokenDecimal, shareDecimal, timeOracle, period, start, newCoveredCallVaultTx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
@@ -49,7 +49,9 @@ var constants_1 = require("../../constants");
|
|
|
49
49
|
tokenDecimal = 9;
|
|
50
50
|
shareDecimal = 4;
|
|
51
51
|
timeOracle = "";
|
|
52
|
-
|
|
52
|
+
period = 0;
|
|
53
|
+
start = 0;
|
|
54
|
+
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, constants_1.COVERED_CALL_MANAGER, tokenDecimal, shareDecimal, timeOracle, period, start, expiration, strike)];
|
|
53
55
|
case 1:
|
|
54
56
|
newCoveredCallVaultTx = _a.sent();
|
|
55
57
|
console.log(newCoveredCallVaultTx);
|
|
@@ -42,7 +42,7 @@ var getUsersShares_1 = require("../utils/getUsersShares");
|
|
|
42
42
|
var usersShares;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
|
-
case 0: return [4 /*yield*/, (0, getUsersShares_1.getUsersShares)(constants_1.USER_SHARE_TABLE)];
|
|
45
|
+
case 0: return [4 /*yield*/, (0, getUsersShares_1.getUsersShares)(constants_1.USER_SHARE_TABLE, constants_1.COVERED_CALL_REGISTRY)];
|
|
46
46
|
case 1:
|
|
47
47
|
usersShares = _a.sent();
|
|
48
48
|
console.log(usersShares);
|
package/lib/test/getVaultData.js
CHANGED
|
@@ -45,7 +45,7 @@ var getVaultData_1 = require("../utils/getVaultData");
|
|
|
45
45
|
case 0: return [4 /*yield*/, (0, getVaultData_1.getVaultDataFromRegistry)(constants_1.COVERED_CALL_REGISTRY)];
|
|
46
46
|
case 1:
|
|
47
47
|
res = _a.sent();
|
|
48
|
-
console.log("vault ");
|
|
48
|
+
console.log("vault: ");
|
|
49
49
|
console.log(res);
|
|
50
50
|
return [2 /*return*/];
|
|
51
51
|
}
|
package/lib/test/testDeposit.js
CHANGED
|
@@ -53,9 +53,9 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
53
53
|
return __generator(this, function (_a) {
|
|
54
54
|
switch (_a.label) {
|
|
55
55
|
case 0:
|
|
56
|
-
depositAmount =
|
|
56
|
+
depositAmount = 100000000;
|
|
57
57
|
isRolling = true;
|
|
58
|
-
token = "
|
|
58
|
+
token = "0x07f6ef13aa444a793b11675494a8c7fb3b1acab7" // minted token
|
|
59
59
|
;
|
|
60
60
|
vaultIndex = 0;
|
|
61
61
|
return [4 /*yield*/, (0, getTypeArgumentFromToken_1.getTypeArgumentFromToken)(token)];
|
package/lib/test/testMint.js
CHANGED
|
@@ -76,6 +76,10 @@ function prepareData(tokenRegistry) {
|
|
|
76
76
|
return [4 /*yield*/, provider.getObject(tokenRegistry)];
|
|
77
77
|
case 1:
|
|
78
78
|
obj = _a.sent();
|
|
79
|
+
if (obj.status != "Exists") {
|
|
80
|
+
console.log("obj not exists");
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
79
83
|
type_1 = obj.details.data.fields.treasury_cap.fields.total_supply.type;
|
|
80
84
|
console.log("type arugment : " + type_1);
|
|
81
85
|
tokenName = constants_1.TOKEN_NAME.find(function (e) { return type_1.includes(e); });
|
package/lib/test/testNewVault.js
CHANGED
|
@@ -71,11 +71,13 @@ var getTypeArgumentFromToken_1 = require("../utils/getTypeArgumentFromToken");
|
|
|
71
71
|
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
72
72
|
var keypair = sui_js_1.Ed25519Keypair.deriveKeypair(constants_1.TEST_MNEMONIC);
|
|
73
73
|
var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
74
|
-
var token = "
|
|
74
|
+
var token = "0x07f6ef13aa444a793b11675494a8c7fb3b1acab7"; // minted token
|
|
75
75
|
var expiration = 1;
|
|
76
76
|
var strike = 105;
|
|
77
77
|
var tokenDecimal = 9;
|
|
78
78
|
var shareDecimal = 4;
|
|
79
|
+
var period = 1; //weekly
|
|
80
|
+
var start = 1671782400000; // 2022/12/23 Friday 08:00:00
|
|
79
81
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
82
|
var typeArgument, _a, timeOracle, _, newCoveredCallVaultTx, moveCallTxn;
|
|
81
83
|
return __generator(this, function (_b) {
|
|
@@ -88,7 +90,7 @@ var shareDecimal = 4;
|
|
|
88
90
|
return [4 /*yield*/, (0, createTimeOracle_1.createTimeOracle)()];
|
|
89
91
|
case 2:
|
|
90
92
|
_a = __read.apply(void 0, [_b.sent(), 2]), timeOracle = _a[0], _ = _a[1];
|
|
91
|
-
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, tokenDecimal, shareDecimal, timeOracle, expiration, strike)];
|
|
93
|
+
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, tokenDecimal, shareDecimal, timeOracle, period, start, expiration, strike)];
|
|
92
94
|
case 3:
|
|
93
95
|
newCoveredCallVaultTx = _b.sent();
|
|
94
96
|
return [4 /*yield*/, signer.executeMoveCall(newCoveredCallVaultTx)];
|
package/lib/test/testOracle.js
CHANGED
|
@@ -80,6 +80,10 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
80
80
|
return [4 /*yield*/, provider.getObject(newOracle)];
|
|
81
81
|
case 6:
|
|
82
82
|
newOracleObj = _a.sent();
|
|
83
|
+
if (newOracleObj.status != "Exists") {
|
|
84
|
+
console.log("obj not exists");
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}
|
|
83
87
|
console.log("updated oracle:");
|
|
84
88
|
//@ts-ignore
|
|
85
89
|
console.log(newOracleObj.details.data.fields);
|
package/lib/test/testSettle.js
CHANGED
|
@@ -92,7 +92,7 @@ var expirationTsMs2 = 2000000;
|
|
|
92
92
|
// let timeOracle = '0x2b06a0f8109e394258c288b1d90c8c5a9c3832db';
|
|
93
93
|
// let timeOracleManager = '0xcad2723ff9c95ce423d3614375e2fa73ce9a7c04';
|
|
94
94
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
|
-
var typeArgument, _a, priceOracle, priceOracleManager, _b, timeOracle, timeOracleManager, price, ts, tokenDecimal, shareDecimal, vaultIndex, depositAmount, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, currentTime, bidSize, sellSize, premiumRoi, exposureRatio;
|
|
95
|
+
var typeArgument, _a, priceOracle, priceOracleManager, _b, timeOracle, timeOracleManager, price, ts, tokenDecimal, shareDecimal, period, start, vaultIndex, depositAmount, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, currentTime, bidSize, sellSize, premiumRoi, exposureRatio;
|
|
96
96
|
return __generator(this, function (_c) {
|
|
97
97
|
switch (_c.label) {
|
|
98
98
|
case 0: return [4 /*yield*/, (0, getTypeArgumentFromToken_1.getTypeArgumentFromToken)(token)
|
|
@@ -121,7 +121,10 @@ var expirationTsMs2 = 2000000;
|
|
|
121
121
|
_c.sent();
|
|
122
122
|
tokenDecimal = 9;
|
|
123
123
|
shareDecimal = 4;
|
|
124
|
-
|
|
124
|
+
period = 1;
|
|
125
|
+
start = 0 //???
|
|
126
|
+
;
|
|
127
|
+
return [4 /*yield*/, createNewVault(typeArgument, expirationTsMs1, tokenDecimal, shareDecimal, timeOracle, period, start)
|
|
125
128
|
//deposit to new vault
|
|
126
129
|
];
|
|
127
130
|
case 5:
|
|
@@ -335,7 +338,7 @@ function updateTimeOracle(timeOracle, managerCap, ts) {
|
|
|
335
338
|
});
|
|
336
339
|
});
|
|
337
340
|
}
|
|
338
|
-
function createNewVault(typeArgument, expirationTsMs1, tokenDecimal, shareDecimal, timeOracle) {
|
|
341
|
+
function createNewVault(typeArgument, expirationTsMs1, tokenDecimal, shareDecimal, timeOracle, period, start) {
|
|
339
342
|
return __awaiter(this, void 0, void 0, function () {
|
|
340
343
|
var _this = this;
|
|
341
344
|
return __generator(this, function (_a) {
|
|
@@ -345,7 +348,7 @@ function createNewVault(typeArgument, expirationTsMs1, tokenDecimal, shareDecima
|
|
|
345
348
|
switch (_a.label) {
|
|
346
349
|
case 0:
|
|
347
350
|
_a.trys.push([0, 4, , 5]);
|
|
348
|
-
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, tokenDecimal, shareDecimal, timeOracle, expirationTsMs1, strike)];
|
|
351
|
+
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, tokenDecimal, shareDecimal, timeOracle, period, start, expirationTsMs1, strike)];
|
|
349
352
|
case 1:
|
|
350
353
|
newCoveredCallVaultTx = _a.sent();
|
|
351
354
|
return [4 /*yield*/, signer.executeMoveCall(newCoveredCallVaultTx)];
|
|
@@ -414,11 +417,13 @@ function getNewestVaultIndex(registry) {
|
|
|
414
417
|
var tmp, numOfVault;
|
|
415
418
|
return __generator(this, function (_a) {
|
|
416
419
|
switch (_a.label) {
|
|
417
|
-
case 0: return [4 /*yield*/, provider.getObject(registry)
|
|
418
|
-
//@ts-ignore
|
|
419
|
-
];
|
|
420
|
+
case 0: return [4 /*yield*/, provider.getObject(registry)];
|
|
420
421
|
case 1:
|
|
421
422
|
tmp = _a.sent();
|
|
423
|
+
if (tmp.status != "Exists") {
|
|
424
|
+
console.log("obj not exists");
|
|
425
|
+
return [2 /*return*/, -1];
|
|
426
|
+
}
|
|
422
427
|
numOfVault = tmp.details.data.fields.num_of_vault;
|
|
423
428
|
return [2 /*return*/, numOfVault - 1];
|
|
424
429
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getNewCoveredCallVaultTx(packageId: string, registry: string, typeArgument: string, managerCap: string, tokenDecimal: number, shareDecimal: number, timeOracle: 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, tokenDecimal, shareDecimal, timeOracle, 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) {
|
|
@@ -52,6 +52,8 @@ function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap,
|
|
|
52
52
|
tokenDecimal,
|
|
53
53
|
shareDecimal,
|
|
54
54
|
timeOracle,
|
|
55
|
+
period,
|
|
56
|
+
start,
|
|
55
57
|
expiration,
|
|
56
58
|
strike,
|
|
57
59
|
],
|
package/lib/utils/fetchData.d.ts
CHANGED
|
@@ -7,6 +7,20 @@ export interface Vault {
|
|
|
7
7
|
vaultId: string;
|
|
8
8
|
vaultIdx: number;
|
|
9
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;
|
|
10
24
|
}
|
|
11
25
|
export declare function getCoveredCallVaultsFromRegistry(registry: string): Promise<any>;
|
|
12
26
|
export declare function getTableFromCoveredCallVault(coveredCallVault: string): Promise<any>;
|
package/lib/utils/fetchData.js
CHANGED
|
@@ -76,11 +76,13 @@ function getTableFromCoveredCallVault(coveredCallVault) {
|
|
|
76
76
|
switch (_a.label) {
|
|
77
77
|
case 0:
|
|
78
78
|
console.log("coveredCallVault: " + coveredCallVault);
|
|
79
|
-
return [4 /*yield*/, provider.getObject(coveredCallVault)
|
|
80
|
-
//@ts-ignore
|
|
81
|
-
];
|
|
79
|
+
return [4 /*yield*/, provider.getObject(coveredCallVault)];
|
|
82
80
|
case 1:
|
|
83
81
|
tmp = _a.sent();
|
|
82
|
+
if (tmp.status != "Exists") {
|
|
83
|
+
console.log("obj not exists");
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
84
86
|
tableUnderCoveredCallVault = tmp.details.data.fields.value.fields.vault.fields.sub_vaults.fields.id.id;
|
|
85
87
|
console.log("table : " + tableUnderCoveredCallVault);
|
|
86
88
|
return [2 /*return*/, tableUnderCoveredCallVault];
|
|
@@ -108,11 +110,13 @@ function getSubVaultsFromTable(tableUnderCoveredCallVault) {
|
|
|
108
110
|
case 3:
|
|
109
111
|
if (!!subVaults_1_1.done) return [3 /*break*/, 6];
|
|
110
112
|
subVault = subVaults_1_1.value;
|
|
111
|
-
return [4 /*yield*/, provider.getObject(subVault.objectId)
|
|
112
|
-
//@ts-ignore
|
|
113
|
-
];
|
|
113
|
+
return [4 /*yield*/, provider.getObject(subVault.objectId)];
|
|
114
114
|
case 4:
|
|
115
115
|
txn = _b.sent();
|
|
116
|
+
if (txn.status != "Exists") {
|
|
117
|
+
console.log("obj not exists");
|
|
118
|
+
return [2 /*return*/, {}];
|
|
119
|
+
}
|
|
116
120
|
name_1 = decode(txn.details.data.fields.name) //rolling / regular / maker
|
|
117
121
|
;
|
|
118
122
|
//@ts-ignore
|
|
@@ -148,11 +152,13 @@ function getTableUnderSubVault(subVault) {
|
|
|
148
152
|
switch (_a.label) {
|
|
149
153
|
case 0:
|
|
150
154
|
console.log("sub vault: " + subVault);
|
|
151
|
-
return [4 /*yield*/, provider.getObject(subVault)
|
|
152
|
-
//@ts-ignore
|
|
153
|
-
];
|
|
155
|
+
return [4 /*yield*/, provider.getObject(subVault)];
|
|
154
156
|
case 1:
|
|
155
157
|
tmp = _a.sent();
|
|
158
|
+
if (tmp.status != "Exists") {
|
|
159
|
+
console.log("obj not exists");
|
|
160
|
+
return [2 /*return*/, ""];
|
|
161
|
+
}
|
|
156
162
|
table = tmp.details.data.fields.value.fields.user_shares.fields.nodes.fields.id.id;
|
|
157
163
|
console.log("table under sub vault: ", table);
|
|
158
164
|
return [2 /*return*/, table];
|
|
@@ -181,11 +187,13 @@ function getUserDataFromLinkedListNode(linkedListNode) {
|
|
|
181
187
|
var tmp, usersData;
|
|
182
188
|
return __generator(this, function (_a) {
|
|
183
189
|
switch (_a.label) {
|
|
184
|
-
case 0: return [4 /*yield*/, provider.getObject(linkedListNode)
|
|
185
|
-
//@ts-ignore
|
|
186
|
-
];
|
|
190
|
+
case 0: return [4 /*yield*/, provider.getObject(linkedListNode)];
|
|
187
191
|
case 1:
|
|
188
192
|
tmp = _a.sent();
|
|
193
|
+
if (tmp.status != "Exists") {
|
|
194
|
+
console.log("obj not exists");
|
|
195
|
+
return [2 /*return*/];
|
|
196
|
+
}
|
|
189
197
|
usersData = tmp.details.data.fields;
|
|
190
198
|
console.log("users data from linked list node:");
|
|
191
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];
|
|
@@ -3,5 +3,6 @@ export interface UserShare {
|
|
|
3
3
|
isRolling: boolean;
|
|
4
4
|
share: number;
|
|
5
5
|
user: string;
|
|
6
|
+
depositAmount: number;
|
|
6
7
|
}
|
|
7
|
-
export declare function getUsersShares(userShareTable: string): Promise<
|
|
8
|
+
export declare function getUsersShares(userShareTable: string, registry: string): Promise<UserShare[]>;
|
|
@@ -35,33 +35,105 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
50
|
exports.getUsersShares = void 0;
|
|
40
51
|
var sui_js_1 = require("@mysten/sui.js");
|
|
41
52
|
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
42
|
-
function
|
|
53
|
+
function getSubVaultsData(registry) {
|
|
43
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var
|
|
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;
|
|
45
101
|
return __generator(this, function (_a) {
|
|
46
102
|
switch (_a.label) {
|
|
47
|
-
case 0:
|
|
48
|
-
userShareTable = "0xee0ed2fb694508934edee1f620a99354eecdafbd";
|
|
49
|
-
return [4 /*yield*/, provider.getObjectsOwnedByObject(userShareTable)];
|
|
103
|
+
case 0: return [4 /*yield*/, getSubVaultsData(registry)]; //vault idx to subvault info
|
|
50
104
|
case 1:
|
|
105
|
+
subVaultsData = _a.sent() //vault idx to subvault info
|
|
106
|
+
;
|
|
107
|
+
return [4 /*yield*/, provider.getObjectsOwnedByObject(userShareTable)];
|
|
108
|
+
case 2:
|
|
51
109
|
userShareIds = (_a.sent()).map(function (x) { return x.objectId; });
|
|
52
|
-
console.log(userShareIds);
|
|
53
110
|
return [4 /*yield*/, provider.getObjectBatch(userShareIds)];
|
|
54
|
-
case
|
|
111
|
+
case 3:
|
|
55
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));
|
|
56
128
|
var res = {
|
|
129
|
+
coveredCallVaultIndex: index,
|
|
57
130
|
//@ts-ignore
|
|
58
|
-
|
|
59
|
-
//@ts-ignore
|
|
60
|
-
isRolling: x.details.data.fields.value.fields.is_rolling,
|
|
131
|
+
isRolling: isRolling,
|
|
61
132
|
//@ts-ignore
|
|
62
|
-
share:
|
|
133
|
+
share: share,
|
|
63
134
|
//@ts-ignore
|
|
64
|
-
user: x.details.data.fields.
|
|
135
|
+
user: x.details.data.fields.name.fields.user,
|
|
136
|
+
depositAmount: depositAmount,
|
|
65
137
|
};
|
|
66
138
|
return res;
|
|
67
139
|
});
|
|
@@ -68,25 +68,51 @@ function getVaultDataFromRegistry(registry) {
|
|
|
68
68
|
objsInfo = _b.sent();
|
|
69
69
|
vaults = [];
|
|
70
70
|
_loop_1 = function (objInfo) {
|
|
71
|
-
|
|
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
|
|
72
82
|
//@ts-ignore
|
|
73
|
-
var
|
|
83
|
+
var vaultIdx = objInfo.details.data.fields.name;
|
|
74
84
|
//asset
|
|
75
85
|
//@ts-ignore
|
|
76
86
|
var type = objInfo.details.data.fields.value.type;
|
|
77
|
-
var
|
|
78
|
-
if (!
|
|
87
|
+
var asset = constants_1.TOKEN_NAME.find(function (e) { return type.includes(e); });
|
|
88
|
+
if (!asset) {
|
|
79
89
|
console.log("can't find token");
|
|
80
|
-
|
|
90
|
+
asset = "";
|
|
81
91
|
}
|
|
82
|
-
//
|
|
92
|
+
//vaultId
|
|
83
93
|
//@ts-ignore
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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);
|
|
90
116
|
};
|
|
91
117
|
try {
|
|
92
118
|
for (objsInfo_1 = __values(objsInfo), objsInfo_1_1 = objsInfo_1.next(); !objsInfo_1_1.done; objsInfo_1_1 = objsInfo_1.next()) {
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
File without changes
|
package/lib/utils/getSubVault.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { JsonRpcProvider, Network } from '@mysten/sui.js';
|
|
3
|
-
// import { COVERED_CALL_REGISTRY } from "../constants"
|
|
4
|
-
// const provider = new JsonRpcProvider(Network.DEVNET);//for read only operations
|
|
5
|
-
// export async function subVaults(): Promise<any> {
|
|
6
|
-
// // let data = await provider.getObject("0x9f3a10e5e7cc22092825c9a4e8269b37fb935a9d")
|
|
7
|
-
// // let data = await provider.getObjectsOwnedByObject("0x0fda36c64af91d4f9c946f00c6f13194c37493ab")
|
|
8
|
-
// // let data = await provider.getObject("0x933ab335ef83ef247ae43f537f9a76317feb7358")
|
|
9
|
-
// // console.log("data: ", JSON.stringify(data))
|
|
10
|
-
// return await subVaultsV2(COVERED_CALL_REGISTRY, provider)
|
|
11
|
-
// }
|
|
12
|
-
// export async function subVaultsV2(registry: string, provider: JsonRpcProvider): Promise<any> {
|
|
13
|
-
// console.log("registry: " + registry)
|
|
14
|
-
// //vault
|
|
15
|
-
// let tmpObj1 = await provider.getObjectsOwnedByObject(registry)
|
|
16
|
-
// console.log("vault num under registry:" + tmpObj1.length)
|
|
17
|
-
// if (tmpObj1.length != 0) {
|
|
18
|
-
// let vault = tmpObj1[0].objectId
|
|
19
|
-
// // let vault = "0x701c014a20294ee7e170148353a2dfe42fb5fb88"
|
|
20
|
-
// console.log("vault: " + vault)
|
|
21
|
-
// //table
|
|
22
|
-
// let tmpObj2 = await provider.getObject(vault)
|
|
23
|
-
// //@ts-ignore
|
|
24
|
-
// let tableId = tmpObj2.details.data.fields.value.fields.vault.fields.sub_vaults.fields.id.id
|
|
25
|
-
// console.log("table: " + tableId)
|
|
26
|
-
// //sub vault (maker / rolling / no_rolling) id
|
|
27
|
-
// let tmpObj3 = await provider.getObjectsOwnedByObject(tableId)
|
|
28
|
-
// let subVaultsId: string[] = [];
|
|
29
|
-
// tmpObj3.map(e => {
|
|
30
|
-
// // console.log("data: " + JSON.stringify(e))
|
|
31
|
-
// subVaultsId.push(e.objectId as string)
|
|
32
|
-
// }
|
|
33
|
-
// )
|
|
34
|
-
// console.log("subVaults: ")
|
|
35
|
-
// //@ts-ignore
|
|
36
|
-
// console.log(subVaultsId)
|
|
37
|
-
// //sub vault data
|
|
38
|
-
// const subVaultsMap = new Map();
|
|
39
|
-
// //@ts-ignore
|
|
40
|
-
// for (let e of subVaultsId) {
|
|
41
|
-
// let tmpObj4 = await provider.getObject(e)
|
|
42
|
-
// //@ts-ignore
|
|
43
|
-
// subVaultsMap.set(tmpObj4.details.data.fields.name, tmpObj4.details.data.fields)
|
|
44
|
-
// }
|
|
45
|
-
// // console.log(subVaultsMap.get("rolling").value.fields.users_table)
|
|
46
|
-
// return subVaultsMap
|
|
47
|
-
// } else {
|
|
48
|
-
// console.log("no vault under this registry: " + registry);
|
|
49
|
-
// return null;
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
|
-
// subVaults()
|