@typus/typus-sdk 0.1.9 → 0.2.0

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.
@@ -2,11 +2,11 @@ export declare const TOKEN_PACKAGE = "0x04aed544785e606bbda1100b7af9aaefb1db60b3
2
2
  export declare const TOKEN_REGISTRY_BTC = "0x1d41542c9bcbb3427e80afb6cd7f05b304feb149";
3
3
  export declare const TOKEN_REGISTRY_ETH = "0x97da9ec6f9842025480b73a2249e8670491c37d6";
4
4
  export declare const TOKEN_REGISTRY_SUI = "0xa0b7b5fc89ee0fa8a1f3355f9370c9651f7611b6";
5
- export declare const ORACLE_PACKAGE = "0xe85eabdada216e470344b2e70cdc8155a4007a2a";
6
- export declare const COVERED_CALL_PACKAGE = "0x76ed224498d2be57bf77ec8c0015957dd6096a36";
7
- export declare const COVERED_CALL_REGISTRY = "0x4a3b7c389f5f7a506317774a49e39631ff160537";
8
- export declare const COVERED_CALL_MANAGER = "0x35f69cc3dff02a9e86616569a72a0c8e9d950cca";
9
- export declare const DOV_PACKAGE = "0x461c7f49f322c3b12523f51c8b8f00d6e0eda243";
5
+ export declare const ORACLE_PACKAGE = "0xe450380f9abda5ef5a7d8674f36d60caeb5a5b22";
6
+ export declare const COVERED_CALL_PACKAGE = "0xaf49c3190359bdce1ef2947ef9e10dcc9227cec2";
7
+ export declare const COVERED_CALL_REGISTRY = "0x92c1ef1b38b36541d43502954d9e6529aa9cf4d9";
8
+ export declare const COVERED_CALL_MANAGER = "0x868bf971423bf0c0b443e23dc6d21bcc4169a79b";
9
+ export declare const DOV_PACKAGE = "0x0c5b45ef284e97b8564223232cdd291649c0f0b7";
10
10
  export declare const DEFAULT_TYPE_ARGUMENT = "0x2::sui::SUI";
11
11
  export declare const FAKE_TOKEN_TYPE_ARGUMENT = "0x27b3674c685046f66cad1d5496d2967894fa5329::token::USDC";
12
12
  export declare const TEST_MNEMONIC = "plug grain matter asthma aware critic can lottery blouse uncover sauce speak";
package/lib/constants.js CHANGED
@@ -7,13 +7,13 @@ exports.TOKEN_REGISTRY_BTC = "0x1d41542c9bcbb3427e80afb6cd7f05b304feb149"; //fak
7
7
  exports.TOKEN_REGISTRY_ETH = "0x97da9ec6f9842025480b73a2249e8670491c37d6"; //fake eth registry
8
8
  exports.TOKEN_REGISTRY_SUI = "0xa0b7b5fc89ee0fa8a1f3355f9370c9651f7611b6"; //fake usdc registry
9
9
  //publish from typus-oracle
10
- exports.ORACLE_PACKAGE = "0xe85eabdada216e470344b2e70cdc8155a4007a2a";
10
+ exports.ORACLE_PACKAGE = "0xe450380f9abda5ef5a7d8674f36d60caeb5a5b22";
11
11
  //publish from typus-dov/cover_call
12
- exports.COVERED_CALL_PACKAGE = "0x76ed224498d2be57bf77ec8c0015957dd6096a36";
13
- exports.COVERED_CALL_REGISTRY = "0x4a3b7c389f5f7a506317774a49e39631ff160537";
14
- exports.COVERED_CALL_MANAGER = "0x35f69cc3dff02a9e86616569a72a0c8e9d950cca";
12
+ exports.COVERED_CALL_PACKAGE = "0xaf49c3190359bdce1ef2947ef9e10dcc9227cec2";
13
+ exports.COVERED_CALL_REGISTRY = "0x92c1ef1b38b36541d43502954d9e6529aa9cf4d9";
14
+ exports.COVERED_CALL_MANAGER = "0x868bf971423bf0c0b443e23dc6d21bcc4169a79b";
15
15
  //publish from typus-dov/typus-dov
16
- exports.DOV_PACKAGE = "0x461c7f49f322c3b12523f51c8b8f00d6e0eda243";
16
+ exports.DOV_PACKAGE = "0x0c5b45ef284e97b8564223232cdd291649c0f0b7";
17
17
  exports.DEFAULT_TYPE_ARGUMENT = "0x2::sui::SUI";
18
18
  exports.FAKE_TOKEN_TYPE_ARGUMENT = "0x27b3674c685046f66cad1d5496d2967894fa5329::token::USDC";
19
19
  exports.TEST_MNEMONIC = "plug grain matter asthma aware critic can lottery blouse uncover sauce speak";
@@ -39,13 +39,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var getDeliveryTx_1 = require("../../utils/coveredCall/getDeliveryTx");
40
40
  var constants_1 = require("../../constants");
41
41
  (function () { return __awaiter(void 0, void 0, void 0, function () {
42
- var index, deliveryTx;
42
+ var index, size, timeOracle, deliveryTx;
43
43
  return __generator(this, function (_a) {
44
44
  switch (_a.label) {
45
45
  case 0:
46
46
  console.log("test for getSubscribeTx()");
47
47
  index = 0;
48
- return [4 /*yield*/, (0, getDeliveryTx_1.getDeliveryTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index)];
48
+ size = 0;
49
+ timeOracle = "";
50
+ return [4 /*yield*/, (0, getDeliveryTx_1.getDeliveryTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, index, size, timeOracle)];
49
51
  case 1:
50
52
  deliveryTx = _a.sent();
51
53
  console.log(deliveryTx);
@@ -53,7 +53,7 @@ var constants_1 = require("../../constants");
53
53
  expiration = 2000;
54
54
  assetName = "BTC";
55
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, assetName, strikeOtmPct)];
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)];
57
57
  case 1:
58
58
  newAuctionWithNextCoveredCallVaultTx = _a.sent();
59
59
  console.log(newAuctionWithNextCoveredCallVaultTx);
@@ -62,10 +62,14 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
62
62
  return [4 /*yield*/, provider.getTransactionWithEffects(digest)];
63
63
  case 3:
64
64
  txn = _a.sent();
65
- newOracle = txn.effects.created[0].reference.objectId;
66
- console.log("newOracle: " + newOracle);
67
- managerCap = txn.effects.created[1].reference.objectId;
68
- console.log("managerCap: " + managerCap);
65
+ if (txn.effects.created[0].owner["AddressOwner"] == undefined) {
66
+ newOracle = txn.effects.created[0].reference.objectId;
67
+ managerCap = txn.effects.created[1].reference.objectId;
68
+ }
69
+ else {
70
+ newOracle = txn.effects.created[1].reference.objectId;
71
+ managerCap = txn.effects.created[0].reference.objectId;
72
+ }
69
73
  console.log("update oracle...");
70
74
  return [4 /*yield*/, (0, getUpdateOracleTx_1.getUpdateOracleTx)(constants_1.ORACLE_PACKAGE, constants_1.DEFAULT_TYPE_ARGUMENT, newOracle, managerCap, price, unix)];
71
75
  case 4:
@@ -72,6 +72,10 @@ var constants_1 = require("../constants");
72
72
  var sui_js_1 = require("@mysten/sui.js");
73
73
  var getTypeArgumentFromToken_1 = require("../utils/getTypeArgumentFromToken");
74
74
  var getUpdateTimeOracleTx_1 = require("../utils/getUpdateTimeOracleTx");
75
+ var getNewAuctionWithNextCoveredCallVaultTx_1 = require("../utils/coveredCall/getNewAuctionWithNextCoveredCallVaultTx");
76
+ var getNewBidTx_1 = require("../utils/coveredCall/getNewBidTx");
77
+ var getDeliveryTx_1 = require("../utils/coveredCall/getDeliveryTx");
78
+ var getUpdatePayoffConfigTx_1 = require("../utils/coveredCall/getUpdatePayoffConfigTx");
75
79
  var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
76
80
  var keypair = sui_js_1.Ed25519Keypair.deriveKeypair(constants_1.TEST_MNEMONIC);
77
81
  var signer = new sui_js_1.RawSigner(keypair, provider);
@@ -83,7 +87,7 @@ var isRolling = true;
83
87
  var expirationTsMs1 = 1000000;
84
88
  var expirationTsMs2 = 2000000;
85
89
  (function () { return __awaiter(void 0, void 0, void 0, function () {
86
- var typeArgument, _a, priceOracle, priceOracleManager, _b, timeOracle, timeOracleManager, price, ts, vaultIndex, startAuctionTsMs;
90
+ var typeArgument, _a, priceOracle, priceOracleManager, _b, timeOracle, timeOracleManager, price, ts, vaultIndex, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, currentTime, size, sellSize, premiumRoi;
87
91
  return __generator(this, function (_c) {
88
92
  switch (_c.label) {
89
93
  case 0: return [4 /*yield*/, (0, getTypeArgumentFromToken_1.getTypeArgumentFromToken)(token)
@@ -142,31 +146,81 @@ var expirationTsMs2 = 2000000;
142
146
  _c.sent();
143
147
  return [4 /*yield*/, updateTimeOracle(timeOracle, timeOracleManager, startAuctionTsMs)
144
148
  //new_auction_with_next_covered_call_vault
145
- //TODO
146
- // let endAuctionTsMs = startAuctionTsMs + 500
147
- // let decaySpeed = 2;
148
- // await createNewAuctionWithNextCoveredCallVault(vaultIndex, startAuctionTsMs, endAuctionTsMs,decaySpeed)
149
+ //DONE
150
+ ];
151
+ case 9:
152
+ _c.sent();
153
+ endAuctionTsMs = startAuctionTsMs + 500;
154
+ decaySpeed = 2;
155
+ initialPrice = 500000000;
156
+ finalPrice = 100000000;
157
+ return [4 /*yield*/, createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, expirationTsMs2, strike)
149
158
  //update time oracle
150
- //TODO
159
+ //DONE
160
+ ];
161
+ case 10:
162
+ _c.sent();
163
+ currentTime = startAuctionTsMs + 300;
164
+ return [4 /*yield*/, updateTimeOracle(timeOracle, timeOracleManager, currentTime)
151
165
  //new bid
166
+ //DONE
167
+ ];
168
+ case 11:
169
+ _c.sent();
170
+ size = 100;
171
+ return [4 /*yield*/, newBid(vaultIndex, size, token, timeOracle)
172
+ //check some data
152
173
  //TODO
153
174
  //update time oracle
154
- //TODO
175
+ //DONE
176
+ ];
177
+ case 12:
178
+ _c.sent();
179
+ //check some data
180
+ //TODO
181
+ //update time oracle
182
+ //DONE
183
+ return [4 /*yield*/, updateTimeOracle(timeOracle, timeOracleManager, endAuctionTsMs + 1)
155
184
  //delivery
156
- //TODO
185
+ //DONE
186
+ ];
187
+ case 13:
188
+ //check some data
189
+ //TODO
190
+ //update time oracle
191
+ //DONE
192
+ _c.sent();
193
+ sellSize = 1;
194
+ return [4 /*yield*/, delivery(vaultIndex, sellSize, timeOracle)
157
195
  //================================end auction================================
158
196
  //update price oracle and time oracle
159
- //TODO
197
+ //DONE
198
+ ];
199
+ case 14:
200
+ _c.sent();
201
+ //================================end auction================================
202
+ //update price oracle and time oracle
203
+ //DONE
204
+ return [4 /*yield*/, updatePriceOracle(priceOracle, priceOracleManager, typeArgument, price, endAuctionTsMs)];
205
+ case 15:
206
+ //================================end auction================================
207
+ //update price oracle and time oracle
208
+ //DONE
209
+ _c.sent();
210
+ return [4 /*yield*/, updateTimeOracle(timeOracle, timeOracleManager, endAuctionTsMs)
160
211
  //update payoff config
161
- //TODO
162
- //deposit to another vault
163
- //TODO
212
+ //DONE
213
+ ];
214
+ case 16:
215
+ _c.sent();
216
+ premiumRoi = 100000;
217
+ return [4 /*yield*/, updatePayoffConfig(vaultIndex, price, premiumRoi)
164
218
  //update price oracle and time oracle
165
219
  //TODO
166
220
  //settle
167
221
  //TODO
168
222
  ];
169
- case 9:
223
+ case 17:
170
224
  _c.sent();
171
225
  return [2 /*return*/];
172
226
  }
@@ -435,3 +489,67 @@ function depositToVault(typeArgument, vaultIndex, depositAmount) {
435
489
  });
436
490
  });
437
491
  }
492
+ function createNewAuctionWithNextCoveredCallVault(typeArgument, vaultIndex, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, expirationTsMs2, strike) {
493
+ return __awaiter(this, void 0, void 0, function () {
494
+ var txn;
495
+ return __generator(this, function (_a) {
496
+ switch (_a.label) {
497
+ case 0: return [4 /*yield*/, (0, getNewAuctionWithNextCoveredCallVaultTx_1.getNewAuctionWithNextCoveredCallVaultTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex, startAuctionTsMs, endAuctionTsMs, decaySpeed, initialPrice, finalPrice, expirationTsMs2, strike)];
498
+ case 1:
499
+ txn = _a.sent();
500
+ return [4 /*yield*/, signer.executeMoveCall(txn)];
501
+ case 2:
502
+ _a.sent();
503
+ return [2 /*return*/];
504
+ }
505
+ });
506
+ });
507
+ }
508
+ function newBid(vaultIndex, size, token, timeOracle) {
509
+ return __awaiter(this, void 0, void 0, function () {
510
+ var newBidTx;
511
+ return __generator(this, function (_a) {
512
+ switch (_a.label) {
513
+ case 0: return [4 /*yield*/, (0, getNewBidTx_1.getNewBidTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, vaultIndex, size, token, timeOracle)];
514
+ case 1:
515
+ newBidTx = _a.sent();
516
+ return [4 /*yield*/, signer.executeMoveCall(newBidTx)];
517
+ case 2:
518
+ _a.sent();
519
+ return [2 /*return*/];
520
+ }
521
+ });
522
+ });
523
+ }
524
+ function delivery(vaultIndex, sellSize, timeOracle) {
525
+ return __awaiter(this, void 0, void 0, function () {
526
+ var deliveryTx;
527
+ return __generator(this, function (_a) {
528
+ switch (_a.label) {
529
+ case 0: return [4 /*yield*/, (0, getDeliveryTx_1.getDeliveryTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_MANAGER, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, vaultIndex, sellSize, timeOracle)];
530
+ case 1:
531
+ deliveryTx = _a.sent();
532
+ return [4 /*yield*/, signer.executeMoveCall(deliveryTx)];
533
+ case 2:
534
+ _a.sent();
535
+ return [2 /*return*/];
536
+ }
537
+ });
538
+ });
539
+ }
540
+ function updatePayoffConfig(vaultIndex, price, premiumRoi) {
541
+ return __awaiter(this, void 0, void 0, function () {
542
+ var updatePayoffConfigTx;
543
+ return __generator(this, function (_a) {
544
+ switch (_a.label) {
545
+ case 0: return [4 /*yield*/, (0, getUpdatePayoffConfigTx_1.getUpdatePayoffConfigTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, constants_1.DEFAULT_TYPE_ARGUMENT, constants_1.COVERED_CALL_MANAGER, vaultIndex, price, premiumRoi)];
546
+ case 1:
547
+ updatePayoffConfigTx = _a.sent();
548
+ return [4 /*yield*/, signer.executeMoveCall(updatePayoffConfigTx)];
549
+ case 2:
550
+ _a.sent();
551
+ return [2 /*return*/];
552
+ }
553
+ });
554
+ });
555
+ }
@@ -1 +1 @@
1
- export declare function getDeliveryTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number): Promise<any>;
1
+ export declare function getDeliveryTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number, size: number, timeOracle: string): 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.getDeliveryTx = void 0;
40
- function getDeliveryTx(packageId, managerCap, registry, typeArgument, index) {
40
+ function getDeliveryTx(packageId, managerCap, registry, typeArgument, index, size, timeOracle) {
41
41
  return __awaiter(this, void 0, void 0, function () {
42
42
  var tx;
43
43
  return __generator(this, function (_a) {
@@ -50,6 +50,8 @@ function getDeliveryTx(packageId, managerCap, registry, typeArgument, index) {
50
50
  managerCap,
51
51
  registry,
52
52
  index,
53
+ size,
54
+ timeOracle,
53
55
  ],
54
56
  gasBudget: 10000,
55
57
  };
@@ -1 +1 @@
1
- export declare function getNewAuctionWithNextCoveredCallVaultTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number, start: number, end: number, decay: number, initialPrice: number, finalPrice: number, expiration: number, assetName: string, strikeOtmPct: number): Promise<any>;
1
+ export declare function getNewAuctionWithNextCoveredCallVaultTx(packageId: string, managerCap: string, registry: string, typeArgument: string, index: number, start: number, end: number, decay: number, initialPrice: number, finalPrice: number, expiration: number, strikeOtmPct: 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, start, end, decay, initialPrice, finalPrice, expiration, assetName, strikeOtmPct) {
40
+ function getNewAuctionWithNextCoveredCallVaultTx(packageId, managerCap, registry, typeArgument, index, start, end, decay, initialPrice, finalPrice, expiration, strikeOtmPct) {
41
41
  return __awaiter(this, void 0, void 0, function () {
42
42
  var tx;
43
43
  return __generator(this, function (_a) {
@@ -56,7 +56,6 @@ function getNewAuctionWithNextCoveredCallVaultTx(packageId, managerCap, registry
56
56
  initialPrice,
57
57
  finalPrice,
58
58
  expiration,
59
- assetName,
60
59
  strikeOtmPct,
61
60
  ],
62
61
  gasBudget: 10000,
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.1.9",
5
+ "version": "0.2.0",
6
6
  "dependencies": {
7
7
  "@mysten/sui.js": "^0.17.1",
8
8
  "@types/node": "^17.0.0",