@typus/typus-sdk 0.2.2 → 0.2.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/lib/constants.d.ts +11 -11
- package/lib/constants.js +11 -11
- package/lib/scripts/coveredCall/getClaimAllTx.js +1 -1
- package/lib/scripts/coveredCall/getClaimTx.js +2 -4
- package/lib/scripts/coveredCall/getNewAuctionTx.js +2 -7
- package/lib/scripts/coveredCall/getNewAuctionWithNextCoveredCallVaultTx.js +5 -10
- package/lib/scripts/coveredCall/getNewCoveredCallVaultTx.js +12 -4
- package/lib/test/getUsersShares.js +1 -1
- package/lib/test/getVaultData.js +1 -1
- package/lib/test/testClaim.js +2 -2
- package/lib/test/testDeposit.js +2 -2
- package/lib/test/testMint.js +4 -0
- package/lib/test/testNewVault.js +13 -4
- package/lib/test/testOracle.js +4 -0
- package/lib/test/testSettle.js +24 -14
- package/lib/utils/coveredCall/getClaimAllTx.d.ts +1 -1
- package/lib/utils/coveredCall/getClaimAllTx.js +1 -2
- package/lib/utils/coveredCall/getClaimTx.d.ts +1 -1
- package/lib/utils/coveredCall/getClaimTx.js +1 -3
- package/lib/utils/coveredCall/getDeliveryTx.js +1 -1
- package/lib/utils/coveredCall/getDepositTx.js +1 -1
- package/lib/utils/coveredCall/getNewAuctionTx.d.ts +1 -1
- package/lib/utils/coveredCall/getNewAuctionTx.js +1 -6
- package/lib/utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx.d.ts +1 -1
- package/lib/utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx.js +4 -8
- package/lib/utils/coveredCall/getNewBidTx.js +2 -2
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.d.ts +1 -1
- package/lib/utils/coveredCall/getNewCoveredCallVaultTx.js +12 -4
- 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 = "0x557125ee218ff0f09b74e67110ca11a10b7c3553";
|
|
7
|
+
export declare const COVERED_CALL_REGISTRY = "0xe713352b3e1679825c8bd209a9f2c5c355572eea";
|
|
8
|
+
export declare const COVERED_CALL_MANAGER = "0x1924683a4112a39f2eee9e07a770ed7f7f911ad5";
|
|
9
|
+
export declare const USER_SHARE_TABLE = "0x1987456681ee8ba897a6693d7355931e5d25e17a";
|
|
10
|
+
export declare const MAKER_SHARE_TABLE = "0xcb3e6ad0b3ab79e35899d134dc42bdd3b97ca485";
|
|
11
|
+
export declare const DOV_PACKAGE = "0x1ab7f453176dc6d35fe5e8b6b27a53cb73d1061d";
|
|
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 = "0x557125ee218ff0f09b74e67110ca11a10b7c3553";
|
|
13
|
+
exports.COVERED_CALL_REGISTRY = "0xe713352b3e1679825c8bd209a9f2c5c355572eea";
|
|
14
|
+
exports.COVERED_CALL_MANAGER = "0x1924683a4112a39f2eee9e07a770ed7f7f911ad5";
|
|
15
|
+
exports.USER_SHARE_TABLE = "0x1987456681ee8ba897a6693d7355931e5d25e17a";
|
|
16
|
+
exports.MAKER_SHARE_TABLE = "0xcb3e6ad0b3ab79e35899d134dc42bdd3b97ca485";
|
|
17
17
|
//publish from typus-dov/typus-dov
|
|
18
|
-
exports.DOV_PACKAGE = "
|
|
18
|
+
exports.DOV_PACKAGE = "0x1ab7f453176dc6d35fe5e8b6b27a53cb73d1061d";
|
|
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";
|
|
@@ -46,7 +46,7 @@ var constants_1 = require("../../constants");
|
|
|
46
46
|
console.log("test for getClaimAllTx()");
|
|
47
47
|
index = 0;
|
|
48
48
|
isRolling = true;
|
|
49
|
-
return [4 /*yield*/, (0, getClaimAllTx_1.getClaimAllTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index
|
|
49
|
+
return [4 /*yield*/, (0, getClaimAllTx_1.getClaimAllTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index)];
|
|
50
50
|
case 1:
|
|
51
51
|
claimAllTx = _a.sent();
|
|
52
52
|
console.log(claimAllTx);
|
|
@@ -39,15 +39,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var getClaimTx_1 = require("../../utils/coveredCall/getClaimTx");
|
|
40
40
|
var constants_1 = require("../../constants");
|
|
41
41
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var index,
|
|
42
|
+
var index, claimTx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
console.log("test for getClaimTx()");
|
|
47
47
|
index = 0;
|
|
48
|
-
|
|
49
|
-
isRolling = true;
|
|
50
|
-
return [4 /*yield*/, (0, getClaimTx_1.getClaimTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index, amount, isRolling)];
|
|
48
|
+
return [4 /*yield*/, (0, getClaimTx_1.getClaimTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index)];
|
|
51
49
|
case 1:
|
|
52
50
|
claimTx = _a.sent();
|
|
53
51
|
console.log(claimTx);
|
|
@@ -39,19 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var getNewAuctionTx_1 = require("../../utils/coveredCall/getNewAuctionTx");
|
|
40
40
|
var constants_1 = require("../../constants");
|
|
41
41
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var typeArgument, vaultIndex,
|
|
42
|
+
var typeArgument, vaultIndex, newAuctionTx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
console.log("test for getNewAuctionTx()");
|
|
47
47
|
typeArgument = "0x27b3674c685046f66cad1d5496d2967894fa5329::token::USDC";
|
|
48
48
|
vaultIndex = 1;
|
|
49
|
-
|
|
50
|
-
end = 100;
|
|
51
|
-
decay = 0;
|
|
52
|
-
initialPrice = 1;
|
|
53
|
-
finalPrice = 100;
|
|
54
|
-
return [4 /*yield*/, (0, getNewAuctionTx_1.getNewAuctionTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, vaultIndex, start, end, decay, initialPrice, finalPrice)];
|
|
49
|
+
return [4 /*yield*/, (0, getNewAuctionTx_1.getNewAuctionTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, vaultIndex)];
|
|
55
50
|
case 1:
|
|
56
51
|
newAuctionTx = _a.sent();
|
|
57
52
|
console.log(newAuctionTx);
|
|
@@ -39,21 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var getNewAuctionWithNextCoveredCallVaultTx_1 = require("../../utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx");
|
|
40
40
|
var constants_1 = require("../../constants");
|
|
41
41
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var index,
|
|
42
|
+
var index, timeOracle, activationTsMs, expirationTsMs, newAuctionWithNextCoveredCallVaultTx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
console.log("test for getNewAuctionWithNextCoveredCallVaultTx()");
|
|
47
47
|
index = 1;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
finalPrice = 1;
|
|
53
|
-
expiration = 2000;
|
|
54
|
-
assetName = "BTC";
|
|
55
|
-
strikeOtmPct = 2000;
|
|
56
|
-
return [4 /*yield*/, (0, getNewAuctionWithNextCoveredCallVaultTx_1.getNewAuctionWithNextCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index, start, end, decay, initialPrice, finalPrice, expiration, strikeOtmPct)];
|
|
48
|
+
timeOracle = "";
|
|
49
|
+
activationTsMs = 1672992000000;
|
|
50
|
+
expirationTsMs = 1672992000000 + 604800000;
|
|
51
|
+
return [4 /*yield*/, (0, getNewAuctionWithNextCoveredCallVaultTx_1.getNewAuctionWithNextCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index, timeOracle, activationTsMs, expirationTsMs)];
|
|
57
52
|
case 1:
|
|
58
53
|
newAuctionWithNextCoveredCallVaultTx = _a.sent();
|
|
59
54
|
console.log(newAuctionWithNextCoveredCallVaultTx);
|
|
@@ -39,17 +39,25 @@ 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
|
|
42
|
+
var tokenDecimal, shareDecimal, timeOracle, period, activationTsMs, expirationTsMs, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance, newCoveredCallVaultTx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
console.log("test for getNewCoveredCallVaultTx()");
|
|
47
|
-
expiration = 123;
|
|
48
|
-
strike = 456;
|
|
49
47
|
tokenDecimal = 9;
|
|
50
48
|
shareDecimal = 4;
|
|
51
49
|
timeOracle = "";
|
|
52
|
-
|
|
50
|
+
period = 1;
|
|
51
|
+
activationTsMs = 1671782400000;
|
|
52
|
+
expirationTsMs = 1671782400000 + 604800000;
|
|
53
|
+
capacity = 1000000000;
|
|
54
|
+
strikeOtmPct = 500;
|
|
55
|
+
decaySpeed = 1;
|
|
56
|
+
initialPrice = 5000;
|
|
57
|
+
finalPrice = 1000;
|
|
58
|
+
auctionDurationInMs = 3600000;
|
|
59
|
+
prevBalance = 0;
|
|
60
|
+
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, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance)];
|
|
53
61
|
case 1:
|
|
54
62
|
newCoveredCallVaultTx = _a.sent();
|
|
55
63
|
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/testClaim.js
CHANGED
|
@@ -61,14 +61,14 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
61
61
|
case 1:
|
|
62
62
|
typeArgument = _a.sent();
|
|
63
63
|
console.log("test for claim, try to claim " + token + " for " + claimAmount + " ...");
|
|
64
|
-
return [4 /*yield*/, (0, getClaimTx_1.getClaimTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex
|
|
64
|
+
return [4 /*yield*/, (0, getClaimTx_1.getClaimTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex)];
|
|
65
65
|
case 2:
|
|
66
66
|
claimTx = _a.sent();
|
|
67
67
|
return [4 /*yield*/, signer.executeMoveCall(claimTx)];
|
|
68
68
|
case 3:
|
|
69
69
|
_a.sent();
|
|
70
70
|
console.log("claim successfully");
|
|
71
|
-
return [4 /*yield*/, (0, getClaimAllTx_1.getClaimAllTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex
|
|
71
|
+
return [4 /*yield*/, (0, getClaimAllTx_1.getClaimAllTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex)];
|
|
72
72
|
case 4:
|
|
73
73
|
claimAllTx = _a.sent();
|
|
74
74
|
return [4 /*yield*/, signer.executeMoveCall(claimAllTx)];
|
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,20 @@ 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 = "
|
|
75
|
-
var expiration = 1;
|
|
76
|
-
var strike = 105;
|
|
74
|
+
var token = "0x07f6ef13aa444a793b11675494a8c7fb3b1acab7"; // minted token
|
|
77
75
|
var tokenDecimal = 9;
|
|
78
76
|
var shareDecimal = 4;
|
|
77
|
+
var timeOracle = "";
|
|
78
|
+
var period = 1;
|
|
79
|
+
var activationTsMs = 1671782400000;
|
|
80
|
+
var expirationTsMs = 1671782400000 + 604800000;
|
|
81
|
+
var capacity = 1000000000;
|
|
82
|
+
var strikeOtmPct = 500;
|
|
83
|
+
var decaySpeed = 1;
|
|
84
|
+
var initialPrice = 5000;
|
|
85
|
+
var finalPrice = 1000;
|
|
86
|
+
var auctionDurationInMs = 3600000;
|
|
87
|
+
var prevBalance = 0;
|
|
79
88
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
89
|
var typeArgument, _a, timeOracle, _, newCoveredCallVaultTx, moveCallTxn;
|
|
81
90
|
return __generator(this, function (_b) {
|
|
@@ -88,7 +97,7 @@ var shareDecimal = 4;
|
|
|
88
97
|
return [4 /*yield*/, (0, createTimeOracle_1.createTimeOracle)()];
|
|
89
98
|
case 2:
|
|
90
99
|
_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,
|
|
100
|
+
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance)];
|
|
92
101
|
case 3:
|
|
93
102
|
newCoveredCallVaultTx = _b.sent();
|
|
94
103
|
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,
|
|
95
|
+
var typeArgument, _a, priceOracle, priceOracleManager, _b, timeOracle, timeOracleManager, price, ts, tokenDecimal, shareDecimal, period, activationTsMs, expirationTsMs, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance, vaultIndex, depositAmount, startAuctionTsMs, endAuctionTsMs, 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,9 +121,17 @@ var expirationTsMs2 = 2000000;
|
|
|
121
121
|
_c.sent();
|
|
122
122
|
tokenDecimal = 9;
|
|
123
123
|
shareDecimal = 4;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
period = 1;
|
|
125
|
+
activationTsMs = 1671782400000;
|
|
126
|
+
expirationTsMs = 1671782400000 + 604800000;
|
|
127
|
+
capacity = 1000000000;
|
|
128
|
+
strikeOtmPct = 500;
|
|
129
|
+
decaySpeed = 1;
|
|
130
|
+
initialPrice = 5000;
|
|
131
|
+
finalPrice = 1000;
|
|
132
|
+
auctionDurationInMs = 3600000;
|
|
133
|
+
prevBalance = 0;
|
|
134
|
+
return [4 /*yield*/, createNewVault(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance)];
|
|
127
135
|
case 5:
|
|
128
136
|
_c.sent();
|
|
129
137
|
return [4 /*yield*/, getNewestVaultIndex(constants_1.COVERED_CALL_REGISTRY)];
|
|
@@ -149,9 +157,9 @@ var expirationTsMs2 = 2000000;
|
|
|
149
157
|
decaySpeed = 2;
|
|
150
158
|
initialPrice = 500000000;
|
|
151
159
|
finalPrice = 100000000;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
];
|
|
160
|
+
activationTsMs = 1672992000000;
|
|
161
|
+
expirationTsMs = 1672992000000 + 604800000;
|
|
162
|
+
return [4 /*yield*/, createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex, timeOracle, activationTsMs, expirationTsMs)];
|
|
155
163
|
case 10:
|
|
156
164
|
_c.sent();
|
|
157
165
|
currentTime = startAuctionTsMs + 300;
|
|
@@ -335,7 +343,7 @@ function updateTimeOracle(timeOracle, managerCap, ts) {
|
|
|
335
343
|
});
|
|
336
344
|
});
|
|
337
345
|
}
|
|
338
|
-
function createNewVault(typeArgument,
|
|
346
|
+
function createNewVault(packageId, registry, typeArgument, managerCap, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance) {
|
|
339
347
|
return __awaiter(this, void 0, void 0, function () {
|
|
340
348
|
var _this = this;
|
|
341
349
|
return __generator(this, function (_a) {
|
|
@@ -345,7 +353,7 @@ function createNewVault(typeArgument, expirationTsMs1, tokenDecimal, shareDecima
|
|
|
345
353
|
switch (_a.label) {
|
|
346
354
|
case 0:
|
|
347
355
|
_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,
|
|
356
|
+
return [4 /*yield*/, (0, getNewCoveredCallVaultTx_1.getNewCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, constants_1.COVERED_CALL_MANAGER, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance)];
|
|
349
357
|
case 1:
|
|
350
358
|
newCoveredCallVaultTx = _a.sent();
|
|
351
359
|
return [4 /*yield*/, signer.executeMoveCall(newCoveredCallVaultTx)];
|
|
@@ -414,11 +422,13 @@ function getNewestVaultIndex(registry) {
|
|
|
414
422
|
var tmp, numOfVault;
|
|
415
423
|
return __generator(this, function (_a) {
|
|
416
424
|
switch (_a.label) {
|
|
417
|
-
case 0: return [4 /*yield*/, provider.getObject(registry)
|
|
418
|
-
//@ts-ignore
|
|
419
|
-
];
|
|
425
|
+
case 0: return [4 /*yield*/, provider.getObject(registry)];
|
|
420
426
|
case 1:
|
|
421
427
|
tmp = _a.sent();
|
|
428
|
+
if (tmp.status != "Exists") {
|
|
429
|
+
console.log("obj not exists");
|
|
430
|
+
return [2 /*return*/, -1];
|
|
431
|
+
}
|
|
422
432
|
numOfVault = tmp.details.data.fields.num_of_vault;
|
|
423
433
|
return [2 /*return*/, numOfVault - 1];
|
|
424
434
|
}
|
|
@@ -458,7 +468,7 @@ function depositToVault(typeArgument, vaultIndex, depositAmount) {
|
|
|
458
468
|
});
|
|
459
469
|
});
|
|
460
470
|
}
|
|
461
|
-
function createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex,
|
|
471
|
+
function createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex, timeOracle, activationTsMs, expirationTsMs) {
|
|
462
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
463
473
|
var _this = this;
|
|
464
474
|
return __generator(this, function (_a) {
|
|
@@ -468,7 +478,7 @@ function createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex, star
|
|
|
468
478
|
switch (_a.label) {
|
|
469
479
|
case 0:
|
|
470
480
|
_a.trys.push([0, 3, , 4]);
|
|
471
|
-
return [4 /*yield*/, (0, getNewAuctionWithNextCoveredCallVaultTx_1.getNewAuctionWithNextCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex,
|
|
481
|
+
return [4 /*yield*/, (0, getNewAuctionWithNextCoveredCallVaultTx_1.getNewAuctionWithNextCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex, timeOracle, activationTsMs, expirationTsMs)];
|
|
472
482
|
case 1:
|
|
473
483
|
txn = _a.sent();
|
|
474
484
|
return [4 /*yield*/, signer.executeMoveCall(txn)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getClaimAllTx(packageId: string, registry: string, typeArgument: string, index: number
|
|
1
|
+
export declare function getClaimAllTx(packageId: string, registry: string, typeArgument: string, index: 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.getClaimAllTx = void 0;
|
|
40
|
-
function getClaimAllTx(packageId, registry, typeArgument, index
|
|
40
|
+
function getClaimAllTx(packageId, registry, typeArgument, index) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -49,7 +49,6 @@ function getClaimAllTx(packageId, registry, typeArgument, index, isRolling) {
|
|
|
49
49
|
arguments: [
|
|
50
50
|
registry,
|
|
51
51
|
[index],
|
|
52
|
-
[isRolling],
|
|
53
52
|
],
|
|
54
53
|
gasBudget: 10000,
|
|
55
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getClaimTx(packageId: string, registry: string, typeArgument: string, index: number
|
|
1
|
+
export declare function getClaimTx(packageId: string, registry: string, typeArgument: string, index: 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.getClaimTx = void 0;
|
|
40
|
-
function getClaimTx(packageId, registry, typeArgument, index
|
|
40
|
+
function getClaimTx(packageId, registry, typeArgument, index) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -49,8 +49,6 @@ function getClaimTx(packageId, registry, typeArgument, index, amount, isRolling)
|
|
|
49
49
|
arguments: [
|
|
50
50
|
registry,
|
|
51
51
|
index,
|
|
52
|
-
amount,
|
|
53
|
-
isRolling,
|
|
54
52
|
],
|
|
55
53
|
gasBudget: 10000,
|
|
56
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getNewAuctionTx(packageId: string, registry: string, typeArgument: string, managerCap: string, index: number
|
|
1
|
+
export declare function getNewAuctionTx(packageId: string, registry: string, typeArgument: string, managerCap: string, index: 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.getNewAuctionTx = void 0;
|
|
40
|
-
function getNewAuctionTx(packageId, registry, typeArgument, managerCap, index
|
|
40
|
+
function getNewAuctionTx(packageId, registry, typeArgument, managerCap, index) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -50,11 +50,6 @@ function getNewAuctionTx(packageId, registry, typeArgument, managerCap, index, s
|
|
|
50
50
|
managerCap,
|
|
51
51
|
registry,
|
|
52
52
|
index,
|
|
53
|
-
start,
|
|
54
|
-
end,
|
|
55
|
-
decay,
|
|
56
|
-
initialPrice,
|
|
57
|
-
finalPrice,
|
|
58
53
|
],
|
|
59
54
|
gasBudget: 1000,
|
|
60
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getNewAuctionWithNextCoveredCallVaultTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number,
|
|
1
|
+
export declare function getNewAuctionWithNextCoveredCallVaultTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number, timeOracle: string, activationTsMs: number, expirationTsMs: 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.getNewAuctionWithNextCoveredCallVaultTx = void 0;
|
|
40
|
-
function getNewAuctionWithNextCoveredCallVaultTx(packageId, managerCap, registry, typeArgument, index,
|
|
40
|
+
function getNewAuctionWithNextCoveredCallVaultTx(packageId, managerCap, registry, typeArgument, index, timeOracle, activationTsMs, expirationTsMs) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -50,13 +50,9 @@ function getNewAuctionWithNextCoveredCallVaultTx(packageId, managerCap, registry
|
|
|
50
50
|
managerCap,
|
|
51
51
|
registry,
|
|
52
52
|
index,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
initialPrice,
|
|
57
|
-
finalPrice,
|
|
58
|
-
expiration,
|
|
59
|
-
strikeOtmPct,
|
|
53
|
+
timeOracle,
|
|
54
|
+
activationTsMs,
|
|
55
|
+
expirationTsMs,
|
|
60
56
|
],
|
|
61
57
|
gasBudget: 10000,
|
|
62
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getNewCoveredCallVaultTx(packageId: string, registry: string, typeArgument: string, managerCap: string, tokenDecimal: number, shareDecimal: number,
|
|
1
|
+
export declare function getNewCoveredCallVaultTx(packageId: string, registry: string, typeArgument: string, managerCap: string, timeOracle: string, period: number, activationTsMs: number, expirationTsMs: number, tokenDecimal: number, shareDecimal: number, capacity: number, strikeOtmPct: number, decaySpeed: number, initialPrice: number, finalPrice: number, auctionDurationInMs: number, prevBalance: 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,
|
|
40
|
+
function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap, timeOracle, period, activationTsMs, expirationTsMs, tokenDecimal, shareDecimal, capacity, strikeOtmPct, decaySpeed, initialPrice, finalPrice, auctionDurationInMs, prevBalance) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -49,11 +49,19 @@ function getNewCoveredCallVaultTx(packageId, registry, typeArgument, managerCap,
|
|
|
49
49
|
arguments: [
|
|
50
50
|
managerCap,
|
|
51
51
|
registry,
|
|
52
|
+
timeOracle,
|
|
53
|
+
period,
|
|
54
|
+
activationTsMs,
|
|
55
|
+
expirationTsMs,
|
|
52
56
|
tokenDecimal,
|
|
53
57
|
shareDecimal,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
capacity,
|
|
59
|
+
strikeOtmPct,
|
|
60
|
+
decaySpeed,
|
|
61
|
+
initialPrice,
|
|
62
|
+
finalPrice,
|
|
63
|
+
auctionDurationInMs,
|
|
64
|
+
prevBalance,
|
|
57
65
|
],
|
|
58
66
|
gasBudget: 10000,
|
|
59
67
|
};
|
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()
|