@typus/typus-sdk 0.4.4 → 0.4.5

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.
@@ -1,3 +1,3 @@
1
1
  import { CoveredCallVault, Auction } from "../utils/fetchData";
2
2
  export declare function getVaultDataFromRegistry(registry: string): Promise<CoveredCallVault[]>;
3
- export declare function getVaultBidPrice(auction: Auction, timeOracle: string): Promise<number>;
3
+ export declare function getVaultBidPrice(auction: Auction): Promise<number>;
@@ -159,7 +159,7 @@ function getVaultDataFromRegistry(registry) {
159
159
  priceConfig: priceConfigRes,
160
160
  index: (auction.index),
161
161
  };
162
- return [4 /*yield*/, getVaultBidPrice(auctionRes, timeOracle)];
162
+ return [4 /*yield*/, getVaultBidPrice(auctionRes)];
163
163
  case 1:
164
164
  vaultBidPrice = _c.sent();
165
165
  console.log("get auction in " + vaultId);
@@ -227,30 +227,24 @@ function getVaultDataFromRegistry(registry) {
227
227
  });
228
228
  }
229
229
  exports.getVaultDataFromRegistry = getVaultDataFromRegistry;
230
- function getVaultBidPrice(auction, timeOracle) {
230
+ function getVaultBidPrice(auction) {
231
231
  return __awaiter(this, void 0, void 0, function () {
232
- var tmp, currentTsMs, initialPrice, finalPrice, decaySpeed, startTsMs, endTsMs, priceDiff, numerator, denominator;
232
+ var current, initialPrice, finalPrice, decaySpeed, start, end;
233
233
  return __generator(this, function (_a) {
234
- switch (_a.label) {
235
- case 0: return [4 /*yield*/, provider.getObject(timeOracle)];
236
- case 1:
237
- tmp = _a.sent();
238
- currentTsMs = Number(tmp.details.data.fields.ts_ms);
239
- initialPrice = Number(auction.priceConfig.initialPrice);
240
- finalPrice = Number(auction.priceConfig.finalPrice);
241
- decaySpeed = Number(auction.priceConfig.decaySpeed);
242
- startTsMs = Number(auction.startTsMs);
243
- endTsMs = Number(auction.endTsMs);
244
- priceDiff = initialPrice - finalPrice;
245
- numerator = currentTsMs - startTsMs;
246
- denominator = endTsMs - startTsMs;
247
- while (decaySpeed > 0) {
248
- priceDiff = priceDiff * numerator / denominator;
249
- decaySpeed = decaySpeed - 1;
250
- }
251
- ;
252
- return [2 /*return*/, initialPrice - priceDiff];
253
- }
234
+ current = Date.now();
235
+ initialPrice = Number(auction.priceConfig.initialPrice);
236
+ finalPrice = Number(auction.priceConfig.finalPrice);
237
+ decaySpeed = Number(auction.priceConfig.decaySpeed);
238
+ start = Number(auction.startTsMs);
239
+ end = Number(auction.endTsMs);
240
+ /// decayed_price =
241
+ /// initial_price -
242
+ /// (initial_price - final_price) *
243
+ /// (1 - remaining_time / auction_duration) ^ decay_speed
244
+ // 1 - remaining_time / auction_duration => 1 - (end - current) / (end - start) => (current - start) / (end - start)
245
+ return [2 /*return*/, initialPrice -
246
+ (initialPrice - finalPrice) *
247
+ (((current - start) / (end - start)) ^ decaySpeed)];
254
248
  });
255
249
  });
256
250
  }
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.4",
5
+ "version": "0.4.5",
6
6
  "dependencies": {
7
7
  "@mysten/bcs": "^0.5.0",
8
8
  "@mysten/sui.js": "^0.20.0",