@typus/typus-sdk 0.4.7 → 0.4.9

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.
Files changed (151) hide show
  1. package/lib/constants.d.ts +30 -0
  2. package/lib/constants.js +38 -0
  3. package/lib/scripts/getSubVault.d.ts +0 -0
  4. package/lib/scripts/getSubVault.js +6 -0
  5. package/lib/scripts/sui.d.ts +1 -0
  6. package/lib/scripts/sui.js +187 -0
  7. package/lib/test/eventListener.d.ts +5 -0
  8. package/lib/test/eventListener.js +294 -0
  9. package/lib/test/getBidData.d.ts +1 -0
  10. package/lib/test/getBidData.js +53 -0
  11. package/lib/test/getMakersShares.d.ts +1 -0
  12. package/lib/test/getMakersShares.js +52 -0
  13. package/lib/test/getUsersShares.d.ts +1 -0
  14. package/lib/test/getUsersShares.js +52 -0
  15. package/lib/test/getVaultData.d.ts +1 -0
  16. package/lib/test/getVaultData.js +53 -0
  17. package/lib/test/testClaim.d.ts +1 -0
  18. package/lib/test/testClaim.js +81 -0
  19. package/lib/test/testCrypto.d.ts +1 -0
  20. package/lib/test/testCrypto.js +54 -0
  21. package/lib/test/testDeposit.d.ts +1 -0
  22. package/lib/test/testDeposit.js +73 -0
  23. package/lib/test/testDepositV2.d.ts +0 -0
  24. package/lib/test/testDepositV2.js +62 -0
  25. package/lib/test/testMint.d.ts +1 -0
  26. package/lib/test/testMint.js +136 -0
  27. package/lib/test/testNewAuction.d.ts +1 -0
  28. package/lib/test/testNewAuction.js +93 -0
  29. package/lib/test/testNewVault.d.ts +1 -0
  30. package/lib/test/testNewVault.js +152 -0
  31. package/lib/test/testOracle.d.ts +1 -0
  32. package/lib/test/testOracle.js +93 -0
  33. package/lib/test/testSettle.d.ts +1 -0
  34. package/lib/test/testSettle.js +589 -0
  35. package/lib/test/testSubscribeEvent.d.ts +1 -0
  36. package/lib/test/testSubscribeEvent.js +97 -0
  37. package/lib/test/testUnsubscribe.d.ts +1 -0
  38. package/lib/test/testUnsubscribe.js +87 -0
  39. package/lib/test/testWithdraw.d.ts +1 -0
  40. package/lib/test/testWithdraw.js +70 -0
  41. package/lib/utils/auction/getBid.d.ts +2 -0
  42. package/lib/utils/auction/getBid.js +79 -0
  43. package/lib/utils/auction/sealedAuction.d.ts +33 -0
  44. package/lib/utils/auction/sealedAuction.js +64 -0
  45. package/lib/utils/authorized/getAuthorizedAddAuthorizedUserTx.d.ts +1 -0
  46. package/lib/utils/authorized/getAuthorizedAddAuthorizedUserTx.js +60 -0
  47. package/lib/utils/authorized/getAuthorizedAddCoveredCallVaultAuthorizedUserTx.d.ts +1 -0
  48. package/lib/utils/authorized/getAuthorizedAddCoveredCallVaultAuthorizedUserTx.js +60 -0
  49. package/lib/utils/authorized/getAuthorizedDeliveryTx.d.ts +1 -0
  50. package/lib/utils/authorized/getAuthorizedDeliveryTx.js +60 -0
  51. package/lib/utils/authorized/getAuthorizedEvolutionTx.d.ts +1 -0
  52. package/lib/utils/authorized/getAuthorizedEvolutionTx.js +63 -0
  53. package/lib/utils/authorized/getAuthorizedLastEvolutionTx.d.ts +1 -0
  54. package/lib/utils/authorized/getAuthorizedLastEvolutionTx.js +62 -0
  55. package/lib/utils/authorized/getAuthorizedNewAuctionTx.d.ts +1 -0
  56. package/lib/utils/authorized/getAuthorizedNewAuctionTx.js +61 -0
  57. package/lib/utils/authorized/getAuthorizedNewCoveredCallVaultTx.d.ts +1 -0
  58. package/lib/utils/authorized/getAuthorizedNewCoveredCallVaultTx.js +77 -0
  59. package/lib/utils/authorized/getAuthorizedRemoveAuthorizedUserTx.d.ts +1 -0
  60. package/lib/utils/authorized/getAuthorizedRemoveAuthorizedUserTx.js +60 -0
  61. package/lib/utils/authorized/getAuthorizedRemoveCoveredCallVaultAuthorizedUserTx.d.ts +1 -0
  62. package/lib/utils/authorized/getAuthorizedRemoveCoveredCallVaultAuthorizedUserTx.js +60 -0
  63. package/lib/utils/authorized/getAuthorizedSettleTx.d.ts +1 -0
  64. package/lib/utils/authorized/getAuthorizedSettleTx.js +61 -0
  65. package/lib/utils/authorized/getAuthorizedUpdateNextVaultConfigTx.d.ts +1 -0
  66. package/lib/utils/authorized/getAuthorizedUpdateNextVaultConfigTx.js +65 -0
  67. package/lib/utils/coveredCall/createPriceOracle.d.ts +1 -0
  68. package/lib/utils/coveredCall/createPriceOracle.js +92 -0
  69. package/lib/utils/coveredCall/createTimeOracle.d.ts +1 -0
  70. package/lib/utils/coveredCall/createTimeOracle.js +91 -0
  71. package/lib/utils/coveredCall/getAddCoveredCallVaultAuthorizedUserTx.d.ts +1 -0
  72. package/lib/utils/coveredCall/getAddCoveredCallVaultAuthorizedUserTx.js +61 -0
  73. package/lib/utils/coveredCall/getClaimAllTx.d.ts +1 -0
  74. package/lib/utils/coveredCall/getClaimAllTx.js +59 -0
  75. package/lib/utils/coveredCall/getClaimTx.d.ts +1 -0
  76. package/lib/utils/coveredCall/getClaimTx.js +59 -0
  77. package/lib/utils/coveredCall/getDeliveryTx.d.ts +1 -0
  78. package/lib/utils/coveredCall/getDeliveryTx.js +61 -0
  79. package/lib/utils/coveredCall/getDepositTx.d.ts +1 -0
  80. package/lib/utils/coveredCall/getDepositTx.js +65 -0
  81. package/lib/utils/coveredCall/getEvolutionTx.d.ts +1 -0
  82. package/lib/utils/coveredCall/getEvolutionTx.js +64 -0
  83. package/lib/utils/coveredCall/getLastEvolutionTx.d.ts +1 -0
  84. package/lib/utils/coveredCall/getLastEvolutionTx.js +63 -0
  85. package/lib/utils/coveredCall/getMakerClaimAllTx.d.ts +1 -0
  86. package/lib/utils/coveredCall/getMakerClaimAllTx.js +59 -0
  87. package/lib/utils/coveredCall/getMakerClaimTx.d.ts +1 -0
  88. package/lib/utils/coveredCall/getMakerClaimTx.js +59 -0
  89. package/lib/utils/coveredCall/getNewAuctionTx.d.ts +1 -0
  90. package/lib/utils/coveredCall/getNewAuctionTx.js +66 -0
  91. package/lib/utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx.d.ts +1 -0
  92. package/lib/utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx.js +64 -0
  93. package/lib/utils/coveredCall/getNewBidTx.d.ts +1 -0
  94. package/lib/utils/coveredCall/getNewBidTx.js +62 -0
  95. package/lib/utils/coveredCall/getNewCoveredCallVaultTx.d.ts +1 -0
  96. package/lib/utils/coveredCall/getNewCoveredCallVaultTx.js +77 -0
  97. package/lib/utils/coveredCall/getNewManagerTx.d.ts +1 -0
  98. package/lib/utils/coveredCall/getNewManagerTx.js +59 -0
  99. package/lib/utils/coveredCall/getRefundTx.d.ts +1 -0
  100. package/lib/utils/coveredCall/getRefundTx.js +59 -0
  101. package/lib/utils/coveredCall/getRemoveBidTx.d.ts +1 -0
  102. package/lib/utils/coveredCall/getRemoveBidTx.js +60 -0
  103. package/lib/utils/coveredCall/getRemoveCoveredCallVaultAuthorizedUserTx.d.ts +1 -0
  104. package/lib/utils/coveredCall/getRemoveCoveredCallVaultAuthorizedUserTx.js +61 -0
  105. package/lib/utils/coveredCall/getRemoveManagerTx.d.ts +1 -0
  106. package/lib/utils/coveredCall/getRemoveManagerTx.js +58 -0
  107. package/lib/utils/coveredCall/getRollOverTx.d.ts +1 -0
  108. package/lib/utils/coveredCall/getRollOverTx.js +60 -0
  109. package/lib/utils/coveredCall/getSettleTx.d.ts +1 -0
  110. package/lib/utils/coveredCall/getSettleTx.js +62 -0
  111. package/lib/utils/coveredCall/getSettleWithRollOverTx.d.ts +1 -0
  112. package/lib/utils/coveredCall/getSettleWithRollOverTx.js +62 -0
  113. package/lib/utils/coveredCall/getSubscribeTx.d.ts +1 -0
  114. package/lib/utils/coveredCall/getSubscribeTx.js +60 -0
  115. package/lib/utils/coveredCall/getUnsubscribeTx.d.ts +1 -0
  116. package/lib/utils/coveredCall/getUnsubscribeTx.js +63 -0
  117. package/lib/utils/coveredCall/getUpdateNextVaultConfigTx.d.ts +1 -0
  118. package/lib/utils/coveredCall/getUpdateNextVaultConfigTx.js +66 -0
  119. package/lib/utils/coveredCall/getUpdatePayoffConfigTx.d.ts +1 -0
  120. package/lib/utils/coveredCall/getUpdatePayoffConfigTx.js +62 -0
  121. package/lib/utils/coveredCall/getWithdrawTx.d.ts +1 -0
  122. package/lib/utils/coveredCall/getWithdrawTx.js +60 -0
  123. package/lib/utils/fetchData.d.ts +83 -0
  124. package/lib/utils/fetchData.js +206 -0
  125. package/lib/utils/getCreateTokenRegistryTx.d.ts +1 -0
  126. package/lib/utils/getCreateTokenRegistryTx.js +59 -0
  127. package/lib/utils/getMakersShares.d.ts +7 -0
  128. package/lib/utils/getMakersShares.js +148 -0
  129. package/lib/utils/getMintTx.d.ts +1 -0
  130. package/lib/utils/getMintTx.js +62 -0
  131. package/lib/utils/getNewOracleTx.d.ts +1 -0
  132. package/lib/utils/getNewOracleTx.js +59 -0
  133. package/lib/utils/getNewTimeOracleTx.d.ts +1 -0
  134. package/lib/utils/getNewTimeOracleTx.js +56 -0
  135. package/lib/utils/getTypeArgumentFromToken.d.ts +1 -0
  136. package/lib/utils/getTypeArgumentFromToken.js +71 -0
  137. package/lib/utils/getUpdateOracleTx.d.ts +1 -0
  138. package/lib/utils/getUpdateOracleTx.js +64 -0
  139. package/lib/utils/getUpdateTimeOracleTx.d.ts +1 -0
  140. package/lib/utils/getUpdateTimeOracleTx.js +60 -0
  141. package/lib/utils/getUsersShares.d.ts +8 -0
  142. package/lib/utils/getUsersShares.js +147 -0
  143. package/lib/utils/getVaultData.d.ts +3 -0
  144. package/lib/utils/getVaultData.js +262 -0
  145. package/lib/utils/getVaultIndexInRegistry.d.ts +1 -0
  146. package/lib/utils/getVaultIndexInRegistry.js +61 -0
  147. package/lib/utils/isObjAvailable.d.ts +0 -0
  148. package/lib/utils/isObjAvailable.js +14 -0
  149. package/lib/utils/loadUsersDepositData.d.ts +8 -0
  150. package/lib/utils/loadUsersDepositData.js +160 -0
  151. package/package.json +1 -1
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ 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.getVaultBidPrice = 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(constants_1.TESTNET_RPC_ENDPOINT); //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, e_1_1;
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
+ var vaultId, vaultIdx, type, asset, config, vault, prev, vaultConfig, vaultConfigRes, nextVaultConfig, nextVaultConfigRes, payoffConfig, payoffConfigRes, configRes, maker, regular, rolling, vaultRes, auctionRes, vaultBidPrice, auction, priceConfig, priceConfigRes, next, totalBidSize, deliveryInfo, owner, tvl, res;
72
+ return __generator(this, function (_c) {
73
+ switch (_c.label) {
74
+ case 0:
75
+ if (objInfo.status != "Exists") {
76
+ console.log("obj not exist");
77
+ return [2 /*return*/, "continue"];
78
+ }
79
+ vaultId = objInfo.details.data.fields.id.id;
80
+ vaultIdx = objInfo.details.data.fields.name;
81
+ type = objInfo.details.data.fields.value.type;
82
+ asset = constants_1.TOKEN_NAME.find(function (e) { return type.includes(e); });
83
+ if (!asset) {
84
+ console.log("can't find token");
85
+ asset = "";
86
+ }
87
+ config = objInfo.details.data.fields.value.fields.config.fields;
88
+ vault = objInfo.details.data.fields.value.fields.vault.fields;
89
+ prev = objInfo.details.data.fields.value.fields.prev;
90
+ prev = (prev != null) ? prev : null;
91
+ vaultConfig = config.vault_config.fields;
92
+ vaultConfigRes = {
93
+ strikeOtmPct: vaultConfig.strike_otm_pct,
94
+ strikeIncrement: vaultConfig.strike_increment,
95
+ decaySpeed: vaultConfig.decay_speed,
96
+ initialPrice: vaultConfig.initial_price,
97
+ finalPrice: vaultConfig.final_price,
98
+ auctionDurationInMs: vaultConfig.auction_duration_in_ms,
99
+ };
100
+ nextVaultConfig = config.next_vault_config.fields;
101
+ nextVaultConfigRes = {
102
+ strikeOtmPct: nextVaultConfig.strike_otm_pct,
103
+ strikeIncrement: nextVaultConfig.strike_increment,
104
+ decaySpeed: nextVaultConfig.decay_speed,
105
+ initialPrice: nextVaultConfig.initial_price,
106
+ finalPrice: nextVaultConfig.final_price,
107
+ auctionDurationInMs: nextVaultConfig.auction_duration_in_ms,
108
+ };
109
+ payoffConfig = config.payoff_config.fields;
110
+ payoffConfigRes = {
111
+ exposureRatio: (payoffConfig.exposure_ratio),
112
+ premiumRoi: (payoffConfig.premium_roi),
113
+ strike: ((payoffConfig.strike) / (Math.pow(10, constants_1.PRICE_DECIMAL))).toString(),
114
+ };
115
+ configRes = {
116
+ period: config.period,
117
+ activationTsMs: config.activation_ts_ms,
118
+ expirationTsMs: config.expiration_ts_ms,
119
+ tokenDecimal: config.token_decimal,
120
+ shareDecimal: config.share_decimal,
121
+ capacity: (Number(config.capacity) / (Math.pow(10, constants_1.TOKEN_DECIMAL))).toString(),
122
+ vaultConfig: vaultConfigRes,
123
+ nextVaultConfig: nextVaultConfigRes,
124
+ payoffConfig: payoffConfigRes,
125
+ };
126
+ maker = {
127
+ balance: (vault.maker_sub_vault.fields.balance),
128
+ shareSupply: (vault.maker_sub_vault.fields.share_supply),
129
+ };
130
+ regular = {
131
+ balance: (vault.regular_sub_vault.fields.balance),
132
+ shareSupply: (vault.regular_sub_vault.fields.share_supply),
133
+ };
134
+ rolling = {
135
+ balance: (vault.rolling_sub_vault.fields.balance),
136
+ shareSupply: (vault.rolling_sub_vault.fields.share_supply),
137
+ };
138
+ vaultRes = {
139
+ ableToDeposit: vault.able_to_deposit,
140
+ ableToWithdraw: vault.able_to_withdraw,
141
+ makerSubVault: maker,
142
+ regularSubVault: regular,
143
+ rollingSubVault: rolling,
144
+ };
145
+ auctionRes = void 0;
146
+ vaultBidPrice = void 0;
147
+ if (!objInfo.details.data.fields.value.fields.auction) return [3 /*break*/, 2];
148
+ auction = objInfo.details.data.fields.value.fields.auction.fields;
149
+ priceConfig = auction.price_config.fields;
150
+ priceConfigRes = {
151
+ decaySpeed: (priceConfig.decay_speed),
152
+ initialPrice: (priceConfig.initial_price),
153
+ finalPrice: (priceConfig.final_price),
154
+ };
155
+ auctionRes = {
156
+ startTsMs: (auction.start_ts_ms),
157
+ endTsMs: (auction.end_ts_ms),
158
+ priceConfig: priceConfigRes,
159
+ index: (auction.index),
160
+ };
161
+ return [4 /*yield*/, getVaultBidPrice(auctionRes)];
162
+ case 1:
163
+ vaultBidPrice = _c.sent();
164
+ console.log("get auction in " + vaultId);
165
+ return [3 /*break*/, 3];
166
+ case 2:
167
+ console.log("No auction " + vaultId);
168
+ auctionRes = {};
169
+ vaultBidPrice = 0;
170
+ _c.label = 3;
171
+ case 3:
172
+ next = objInfo.details.data.fields.value.fields.next;
173
+ totalBidSize = objInfo.details.data.fields.value.fields.total_bid_size;
174
+ deliveryInfo = void 0;
175
+ //@ts-ignore
176
+ if (objInfo.details.data.fields.value.fields.delivery_info) {
177
+ deliveryInfo = {
178
+ //@ts-ignore
179
+ deliveryPrice: objInfo.details.data.fields.value.fields.delivery_info.fields.delivery_price,
180
+ //@ts-ignore
181
+ deliverySize: objInfo.details.data.fields.value.fields.delivery_info.fields.delivery_size,
182
+ };
183
+ }
184
+ else {
185
+ deliveryInfo = {};
186
+ }
187
+ owner = objInfo.details.data.fields.value.fields.owner;
188
+ tvl = Number(vault.regular_sub_vault.fields.balance) + Number(vault.rolling_sub_vault.fields.balance);
189
+ res = {
190
+ vaultId: vaultId,
191
+ vaultIdx: vaultIdx.toString(),
192
+ asset: asset,
193
+ config: configRes,
194
+ vault: vaultRes,
195
+ auction: auctionRes,
196
+ prev: (prev) ? prev.toString() : null,
197
+ next: next,
198
+ totalBidSize: totalBidSize,
199
+ deliveryInfo: deliveryInfo,
200
+ owner: owner,
201
+ tvl: tvl.toString(),
202
+ vaultBidPrice: vaultBidPrice.toString(),
203
+ };
204
+ vaults.push(res);
205
+ return [2 /*return*/];
206
+ }
207
+ });
208
+ };
209
+ _b.label = 3;
210
+ case 3:
211
+ _b.trys.push([3, 8, 9, 10]);
212
+ objsInfo_1 = __values(objsInfo), objsInfo_1_1 = objsInfo_1.next();
213
+ _b.label = 4;
214
+ case 4:
215
+ if (!!objsInfo_1_1.done) return [3 /*break*/, 7];
216
+ objInfo = objsInfo_1_1.value;
217
+ return [5 /*yield**/, _loop_1(objInfo)];
218
+ case 5:
219
+ _b.sent();
220
+ _b.label = 6;
221
+ case 6:
222
+ objsInfo_1_1 = objsInfo_1.next();
223
+ return [3 /*break*/, 4];
224
+ case 7: return [3 /*break*/, 10];
225
+ case 8:
226
+ e_1_1 = _b.sent();
227
+ e_1 = { error: e_1_1 };
228
+ return [3 /*break*/, 10];
229
+ case 9:
230
+ try {
231
+ if (objsInfo_1_1 && !objsInfo_1_1.done && (_a = objsInfo_1.return)) _a.call(objsInfo_1);
232
+ }
233
+ finally { if (e_1) throw e_1.error; }
234
+ return [7 /*endfinally*/];
235
+ case 10: return [2 /*return*/, vaults];
236
+ }
237
+ });
238
+ });
239
+ }
240
+ exports.getVaultDataFromRegistry = getVaultDataFromRegistry;
241
+ function getVaultBidPrice(auction) {
242
+ return __awaiter(this, void 0, void 0, function () {
243
+ var current, initialPrice, finalPrice, decaySpeed, start, end;
244
+ return __generator(this, function (_a) {
245
+ current = Date.now();
246
+ initialPrice = Number(auction.priceConfig.initialPrice);
247
+ finalPrice = Number(auction.priceConfig.finalPrice);
248
+ decaySpeed = Number(auction.priceConfig.decaySpeed);
249
+ start = Number(auction.startTsMs);
250
+ end = Number(auction.endTsMs);
251
+ /// decayed_price =
252
+ /// initial_price -
253
+ /// (initial_price - final_price) *
254
+ /// (1 - remaining_time / auction_duration) ^ decay_speed
255
+ // 1 - remaining_time / auction_duration => 1 - (end - current) / (end - start) => (current - start) / (end - start)
256
+ return [2 /*return*/, initialPrice -
257
+ (initialPrice - finalPrice) *
258
+ (((current - start) / (end - start)) ^ decaySpeed)];
259
+ });
260
+ });
261
+ }
262
+ exports.getVaultBidPrice = getVaultBidPrice;
@@ -0,0 +1 @@
1
+ export declare function getVaultIndexInregistry(registry: string): Promise<number>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getVaultIndexInregistry = void 0;
40
+ var sui_js_1 = require("@mysten/sui.js");
41
+ var constants_1 = require("../constants");
42
+ var provider = new sui_js_1.JsonRpcProvider(constants_1.TESTNET_RPC_ENDPOINT); //for read only operations
43
+ function getVaultIndexInregistry(registry) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var txn, index;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0: return [4 /*yield*/, provider.getObject(registry)];
49
+ case 1:
50
+ txn = _a.sent();
51
+ if (txn.status != "Exists") {
52
+ console.log("obj not exists");
53
+ return [2 /*return*/, -1];
54
+ }
55
+ index = txn.details.data.fields.name;
56
+ return [2 /*return*/, index];
57
+ }
58
+ });
59
+ });
60
+ }
61
+ exports.getVaultIndexInregistry = getVaultIndexInregistry;
File without changes
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // import { JsonRpcProvider, Network } from '@mysten/sui.js';
3
+ // const provider = new JsonRpcProvider(TESTNET_RPC_ENDPOINT);//for read only operations
4
+ // export async function isObjAvailable(obj: string): Promise<Boolean> {
5
+ // try {
6
+ // let tmp = await provider.getObject(
7
+ // obj
8
+ // )
9
+ // if (tmp.status == "Exists") return true
10
+ // else return false
11
+ // } catch (e) {
12
+ // return false
13
+ // }
14
+ // }
@@ -0,0 +1,8 @@
1
+ export interface UserDepositData {
2
+ coveredCallVault: string;
3
+ subVault: string;
4
+ subVaultType: string;
5
+ linkedListNode: string;
6
+ balance: number;
7
+ }
8
+ export declare function loadUsersDepositData(registry: string): Promise<Map<string, UserDepositData[]>>;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ 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.loadUsersDepositData = void 0;
51
+ var fetchData_1 = require("./fetchData");
52
+ function loadUsersDepositData(registry) {
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ var usersDepositData, coveredCallVaults, coveredCallVaults_1, coveredCallVaults_1_1, coveredCallVault, tableUnderCoveredCallVault, subVaults, _a, _b, _c, _i, subVaultType, tableUnderSubVault, linkedListNodes, linkedListNodes_1, linkedListNodes_1_1, linkedListNode, userData, userDepositData, userDepositDatas, e_1_1, e_2_1;
55
+ var e_2, _d, e_1, _e;
56
+ return __generator(this, function (_f) {
57
+ switch (_f.label) {
58
+ case 0:
59
+ usersDepositData = new Map();
60
+ return [4 /*yield*/, (0, fetchData_1.getCoveredCallVaultsFromRegistry)(registry)];
61
+ case 1:
62
+ coveredCallVaults = _f.sent();
63
+ _f.label = 2;
64
+ case 2:
65
+ _f.trys.push([2, 19, 20, 21]);
66
+ coveredCallVaults_1 = __values(coveredCallVaults), coveredCallVaults_1_1 = coveredCallVaults_1.next();
67
+ _f.label = 3;
68
+ case 3:
69
+ if (!!coveredCallVaults_1_1.done) return [3 /*break*/, 18];
70
+ coveredCallVault = coveredCallVaults_1_1.value;
71
+ return [4 /*yield*/, (0, fetchData_1.getTableFromCoveredCallVault)(coveredCallVault.objectId)
72
+ //from table find sub vault
73
+ ];
74
+ case 4:
75
+ tableUnderCoveredCallVault = _f.sent();
76
+ return [4 /*yield*/, (0, fetchData_1.getSubVaultsFromTable)(tableUnderCoveredCallVault)
77
+ //from sub vault find table
78
+ ];
79
+ case 5:
80
+ subVaults = _f.sent();
81
+ _a = subVaults;
82
+ _b = [];
83
+ for (_c in _a)
84
+ _b.push(_c);
85
+ _i = 0;
86
+ _f.label = 6;
87
+ case 6:
88
+ if (!(_i < _b.length)) return [3 /*break*/, 17];
89
+ _c = _b[_i];
90
+ if (!(_c in _a)) return [3 /*break*/, 16];
91
+ subVaultType = _c;
92
+ return [4 /*yield*/, (0, fetchData_1.getTableUnderSubVault)(subVaults[subVaultType])
93
+ //from table find linked list node
94
+ ];
95
+ case 7:
96
+ tableUnderSubVault = _f.sent();
97
+ return [4 /*yield*/, (0, fetchData_1.getLinkedListNodesFromTable)(tableUnderSubVault)
98
+ //from linkedListNode find user data
99
+ ];
100
+ case 8:
101
+ linkedListNodes = _f.sent();
102
+ _f.label = 9;
103
+ case 9:
104
+ _f.trys.push([9, 14, 15, 16]);
105
+ linkedListNodes_1 = (e_1 = void 0, __values(linkedListNodes)), linkedListNodes_1_1 = linkedListNodes_1.next();
106
+ _f.label = 10;
107
+ case 10:
108
+ if (!!linkedListNodes_1_1.done) return [3 /*break*/, 13];
109
+ linkedListNode = linkedListNodes_1_1.value;
110
+ return [4 /*yield*/, (0, fetchData_1.getUserDataFromLinkedListNode)(linkedListNode.objectId)];
111
+ case 11:
112
+ userData = _f.sent();
113
+ userDepositData = {
114
+ coveredCallVault: coveredCallVault.objectId,
115
+ subVault: subVaults[subVaultType],
116
+ subVaultType: subVaultType,
117
+ linkedListNode: linkedListNode.objectId,
118
+ balance: (userData.value) ? userData.value.fields.value : 0
119
+ };
120
+ userDepositDatas = (usersDepositData.get(userData.name) == undefined) ? [] : usersDepositData.get(userData.name);
121
+ userDepositDatas.push(userDepositData);
122
+ usersDepositData.set(userData.name, userDepositDatas);
123
+ _f.label = 12;
124
+ case 12:
125
+ linkedListNodes_1_1 = linkedListNodes_1.next();
126
+ return [3 /*break*/, 10];
127
+ case 13: return [3 /*break*/, 16];
128
+ case 14:
129
+ e_1_1 = _f.sent();
130
+ e_1 = { error: e_1_1 };
131
+ return [3 /*break*/, 16];
132
+ case 15:
133
+ try {
134
+ if (linkedListNodes_1_1 && !linkedListNodes_1_1.done && (_e = linkedListNodes_1.return)) _e.call(linkedListNodes_1);
135
+ }
136
+ finally { if (e_1) throw e_1.error; }
137
+ return [7 /*endfinally*/];
138
+ case 16:
139
+ _i++;
140
+ return [3 /*break*/, 6];
141
+ case 17:
142
+ coveredCallVaults_1_1 = coveredCallVaults_1.next();
143
+ return [3 /*break*/, 3];
144
+ case 18: return [3 /*break*/, 21];
145
+ case 19:
146
+ e_2_1 = _f.sent();
147
+ e_2 = { error: e_2_1 };
148
+ return [3 /*break*/, 21];
149
+ case 20:
150
+ try {
151
+ if (coveredCallVaults_1_1 && !coveredCallVaults_1_1.done && (_d = coveredCallVaults_1.return)) _d.call(coveredCallVaults_1);
152
+ }
153
+ finally { if (e_2) throw e_2.error; }
154
+ return [7 /*endfinally*/];
155
+ case 21: return [2 /*return*/, usersDepositData];
156
+ }
157
+ });
158
+ });
159
+ }
160
+ exports.loadUsersDepositData = loadUsersDepositData;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@typus/typus-sdk",
3
3
  "author": "Typus",
4
4
  "description": "typus sdk",
5
- "version": "0.4.7",
5
+ "version": "0.4.9",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "^0.5.0",
8
8
  "@mysten/sui.js": "^0.25.0",