@typus/typus-sdk 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants.d.ts +16 -13
- package/lib/constants.js +17 -14
- package/lib/test/eventListener.d.ts +4 -3
- package/lib/test/eventListener.js +152 -54
- package/lib/test/getMakersShares.d.ts +1 -0
- package/lib/test/getMakersShares.js +52 -0
- package/lib/utils/getMakersShares.d.ts +7 -0
- package/lib/utils/getMakersShares.js +147 -0
- package/lib/utils/getUsersShares.js +3 -2
- package/lib/utils/getVaultData.js +3 -3
- package/package.json +1 -1
package/lib/constants.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
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
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
1
|
+
export declare const TOKEN_PACKAGE = "0x3e416d10557c532838c2d0d6996c8a3bc81371a7";
|
|
2
|
+
export declare const TOKEN_REGISTRY_BTC = "0xee26a4debb44a6c09e0f446c5c98da2217a0ca5d";
|
|
3
|
+
export declare const TOKEN_REGISTRY_ETH = "0x00c7526bc0b4b7be9fb6d23e60e325700194e018";
|
|
4
|
+
export declare const TOKEN_REGISTRY_SUI = "0x342f858a4f813a8f95ddc216ddf7bcb775a92782";
|
|
5
|
+
export declare const TOKEN_REGISTRY_APT = "0x09de00969635499a7f824688bff570efbf886a68";
|
|
6
|
+
export declare const TOKEN_REGISTRY_DOGE = "0xa33ba6e2c736a2548b8c1cef13fed947c6aae163";
|
|
7
|
+
export declare const TOKEN_REGISTRY_USDC = "0xf22cd5b80e1263e436fb4d71879ebb1b2799aa36";
|
|
8
|
+
export declare const ORACLE_PACKAGE = "0xcba43b3a1672f3c782e2167fc64710799009d5bb";
|
|
9
|
+
export declare const TIME_ORACLE = "0x55031e1edc517a4b16543c1c081ba33a59ffd084";
|
|
10
|
+
export declare const COVERED_CALL_PACKAGE = "0xb92f3c4c26151b86977b8811765fe74cb133a35f";
|
|
11
|
+
export declare const COVERED_CALL_REGISTRY = "0x0a4bd1721cb02a957d1602f5b2e53ad421408acb";
|
|
12
|
+
export declare const COVERED_CALL_MANAGER = "0x6fd90bf4bb9490e5fce51b8eb11fbf37c43f4cbc";
|
|
13
|
+
export declare const USER_SHARE_TABLE = "0xc90f9f13f9823719011a9b2de73bb4d6e05eaf28";
|
|
14
|
+
export declare const USER_REFUND_TABLE = "0x2a63900582a5177f7ff440613ba091618f373bfa";
|
|
15
|
+
export declare const MAKER_SHARE_TABLE = "0xfcfd04446aa3dd004150081df8982c1f09b20fb1";
|
|
16
|
+
export declare const DOV_PACKAGE = "0x49e71a735dc6bdf7327e6c663d04a3e7f68bafd0";
|
|
14
17
|
export declare const TEST_MINT_TOKEN = "0x672612858fcb5c6abf944638253142820c251753";
|
|
15
18
|
export declare const PRICE_DECIMAL = 8;
|
|
16
19
|
export declare const TOKEN_DECIMAL = 9;
|
package/lib/constants.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TOKEN_NAME_TO_MODULE = exports.TOKEN_NAME = exports.TEST_MNEMONIC = exports.FAKE_TOKEN_TYPE_ARGUMENT = exports.DEFAULT_TYPE_ARGUMENT = exports.TOKEN_DECIMAL = exports.PRICE_DECIMAL = exports.TEST_MINT_TOKEN = exports.DOV_PACKAGE = exports.MAKER_SHARE_TABLE = exports.USER_REFUND_TABLE = exports.USER_SHARE_TABLE = exports.COVERED_CALL_MANAGER = exports.COVERED_CALL_REGISTRY = exports.COVERED_CALL_PACKAGE = exports.TIME_ORACLE = exports.ORACLE_PACKAGE = exports.TOKEN_REGISTRY_SUI = exports.TOKEN_REGISTRY_ETH = exports.TOKEN_REGISTRY_BTC = exports.TOKEN_PACKAGE = void 0;
|
|
3
|
+
exports.TOKEN_NAME_TO_MODULE = exports.TOKEN_NAME = exports.TEST_MNEMONIC = exports.FAKE_TOKEN_TYPE_ARGUMENT = exports.DEFAULT_TYPE_ARGUMENT = exports.TOKEN_DECIMAL = exports.PRICE_DECIMAL = exports.TEST_MINT_TOKEN = exports.DOV_PACKAGE = exports.MAKER_SHARE_TABLE = exports.USER_REFUND_TABLE = exports.USER_SHARE_TABLE = exports.COVERED_CALL_MANAGER = exports.COVERED_CALL_REGISTRY = exports.COVERED_CALL_PACKAGE = exports.TIME_ORACLE = exports.ORACLE_PACKAGE = exports.TOKEN_REGISTRY_USDC = exports.TOKEN_REGISTRY_DOGE = exports.TOKEN_REGISTRY_APT = 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 = "0x3e416d10557c532838c2d0d6996c8a3bc81371a7";
|
|
6
|
+
exports.TOKEN_REGISTRY_BTC = "0xee26a4debb44a6c09e0f446c5c98da2217a0ca5d";
|
|
7
|
+
exports.TOKEN_REGISTRY_ETH = "0x00c7526bc0b4b7be9fb6d23e60e325700194e018";
|
|
8
|
+
exports.TOKEN_REGISTRY_SUI = "0x342f858a4f813a8f95ddc216ddf7bcb775a92782";
|
|
9
|
+
exports.TOKEN_REGISTRY_APT = "0x09de00969635499a7f824688bff570efbf886a68";
|
|
10
|
+
exports.TOKEN_REGISTRY_DOGE = "0xa33ba6e2c736a2548b8c1cef13fed947c6aae163";
|
|
11
|
+
exports.TOKEN_REGISTRY_USDC = "0xf22cd5b80e1263e436fb4d71879ebb1b2799aa36";
|
|
9
12
|
//publish from typus-oracle
|
|
10
|
-
exports.ORACLE_PACKAGE = "
|
|
11
|
-
exports.TIME_ORACLE = "
|
|
13
|
+
exports.ORACLE_PACKAGE = "0xcba43b3a1672f3c782e2167fc64710799009d5bb";
|
|
14
|
+
exports.TIME_ORACLE = "0x55031e1edc517a4b16543c1c081ba33a59ffd084";
|
|
12
15
|
//publish from typus-dov/cover_call
|
|
13
|
-
exports.COVERED_CALL_PACKAGE = "
|
|
14
|
-
exports.COVERED_CALL_REGISTRY = "
|
|
15
|
-
exports.COVERED_CALL_MANAGER = "
|
|
16
|
-
exports.USER_SHARE_TABLE = "
|
|
17
|
-
exports.USER_REFUND_TABLE = "
|
|
18
|
-
exports.MAKER_SHARE_TABLE = "
|
|
16
|
+
exports.COVERED_CALL_PACKAGE = "0xb92f3c4c26151b86977b8811765fe74cb133a35f";
|
|
17
|
+
exports.COVERED_CALL_REGISTRY = "0x0a4bd1721cb02a957d1602f5b2e53ad421408acb";
|
|
18
|
+
exports.COVERED_CALL_MANAGER = "0x6fd90bf4bb9490e5fce51b8eb11fbf37c43f4cbc";
|
|
19
|
+
exports.USER_SHARE_TABLE = "0xc90f9f13f9823719011a9b2de73bb4d6e05eaf28";
|
|
20
|
+
exports.USER_REFUND_TABLE = "0x2a63900582a5177f7ff440613ba091618f373bfa";
|
|
21
|
+
exports.MAKER_SHARE_TABLE = "0xfcfd04446aa3dd004150081df8982c1f09b20fb1";
|
|
19
22
|
//publish from typus-dov/typus-dov
|
|
20
|
-
exports.DOV_PACKAGE = "
|
|
23
|
+
exports.DOV_PACKAGE = "0x49e71a735dc6bdf7327e6c663d04a3e7f68bafd0";
|
|
21
24
|
exports.TEST_MINT_TOKEN = "0x672612858fcb5c6abf944638253142820c251753";
|
|
22
25
|
exports.PRICE_DECIMAL = 8;
|
|
23
26
|
exports.TOKEN_DECIMAL = 9;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
import { CoveredCallVault } from "../utils/fetchData";
|
|
2
|
+
export declare function getBidEventsCranker(type: string, renewSec: number, vault: CoveredCallVault[]): Promise<void>;
|
|
3
|
+
export declare function getNewAuctionEventsCranker(type: string, renewSec: number, vault: CoveredCallVault[]): Promise<void>;
|
|
4
|
+
export declare function getEndAuctionEventsCranker(type: string, renewSec: number, vault: CoveredCallVault[]): Promise<void>;
|
|
4
5
|
export declare function sendEventToTelegramChannel(text: any): Promise<void>;
|
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.sendEventToTelegramChannel = exports.getEndAuctionEventsCranker = exports.getNewAuctionEventsCranker = exports.getBidEventsCranker = void 0;
|
|
43
43
|
var constants_1 = require("../constants");
|
|
44
44
|
var sui_js_1 = require("@mysten/sui.js");
|
|
45
|
+
var getVaultData_1 = require("../utils/getVaultData");
|
|
45
46
|
var node_cron_1 = __importDefault(require("node-cron"));
|
|
46
47
|
var XMLHttpRequest_1 = require("XMLHttpRequest");
|
|
47
48
|
var moment_1 = __importDefault(require("moment"));
|
|
@@ -52,61 +53,127 @@ var apiToken = "5864284783:AAHwXWgt2YgLENdJ9mVBUDBVLHXrMLNgkic";
|
|
|
52
53
|
*/
|
|
53
54
|
var chatId = "-1001784476809";
|
|
54
55
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
-
var
|
|
56
|
+
var bidTypes, newAuctionType, endAuctionTypes, renewSec, vault;
|
|
56
57
|
return __generator(this, function (_a) {
|
|
57
58
|
switch (_a.label) {
|
|
58
59
|
case 0:
|
|
59
|
-
|
|
60
|
+
bidTypes = [
|
|
61
|
+
constants_1.COVERED_CALL_PACKAGE + "::covered_call::NewBid<" + constants_1.TOKEN_PACKAGE + "::eth::ETH>",
|
|
62
|
+
constants_1.COVERED_CALL_PACKAGE + "::covered_call::NewBid<" + constants_1.TOKEN_PACKAGE + "::btc::BTC>",
|
|
63
|
+
constants_1.COVERED_CALL_PACKAGE + "::covered_call::NewBid<" + constants_1.TOKEN_PACKAGE + "::sui::SUI>",
|
|
64
|
+
];
|
|
60
65
|
newAuctionType = constants_1.COVERED_CALL_PACKAGE + "::covered_call::NewAuction";
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
endAuctionTypes = [
|
|
67
|
+
constants_1.DOV_PACKAGE + "::dutch::Delivery<" + constants_1.TOKEN_PACKAGE + "::eth::ETH>",
|
|
68
|
+
constants_1.DOV_PACKAGE + "::dutch::Delivery<" + constants_1.TOKEN_PACKAGE + "::btc::BTC>",
|
|
69
|
+
constants_1.DOV_PACKAGE + "::dutch::Delivery<" + constants_1.TOKEN_PACKAGE + "::sui::SUI>",
|
|
64
70
|
];
|
|
71
|
+
renewSec = 10;
|
|
72
|
+
return [4 /*yield*/, (0, getVaultData_1.getVaultDataFromRegistry)(constants_1.COVERED_CALL_REGISTRY)];
|
|
65
73
|
case 1:
|
|
66
|
-
_a.sent();
|
|
74
|
+
vault = _a.sent();
|
|
75
|
+
bidTypes.map(function (bidType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0: return [4 /*yield*/, getBidEventsCranker(bidType, renewSec, vault)]; //new_bid
|
|
79
|
+
case 1:
|
|
80
|
+
_a.sent(); //new_bid
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); });
|
|
85
|
+
return [4 /*yield*/, getNewAuctionEventsCranker(newAuctionType, renewSec, vault)]; //evolution
|
|
86
|
+
case 2:
|
|
87
|
+
_a.sent(); //evolution
|
|
88
|
+
endAuctionTypes.map(function (endAuctionType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
switch (_a.label) {
|
|
91
|
+
case 0: return [4 /*yield*/, getEndAuctionEventsCranker(endAuctionType, renewSec, vault)];
|
|
92
|
+
case 1:
|
|
93
|
+
_a.sent();
|
|
94
|
+
return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}); });
|
|
67
98
|
return [2 /*return*/];
|
|
68
99
|
}
|
|
69
100
|
});
|
|
70
101
|
}); })();
|
|
71
|
-
function
|
|
102
|
+
function generateBidId(vault) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var liveVault, res;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
liveVault = vault === null || vault === void 0 ? void 0 : vault.filter(function (v) {
|
|
107
|
+
var start = moment_1.default.unix(Number(v.config.activationTsMs) / 1000);
|
|
108
|
+
return start.isBefore((0, moment_1.default)());
|
|
109
|
+
});
|
|
110
|
+
res = liveVault.map(function (v) {
|
|
111
|
+
var expiration = moment_1.default
|
|
112
|
+
.unix(Number(v.config.expirationTsMs) / 1000)
|
|
113
|
+
.format("DDMMMYY");
|
|
114
|
+
var bidId = "".concat(v.asset, "-").concat(expiration, "-").concat(v.config.payoffConfig.strike, "-C");
|
|
115
|
+
return bidId;
|
|
116
|
+
});
|
|
117
|
+
return [2 /*return*/, res];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function getBidEventsCranker(type, renewSec, vault) {
|
|
72
122
|
return __awaiter(this, void 0, void 0, function () {
|
|
73
123
|
var res;
|
|
74
124
|
var _this = this;
|
|
75
125
|
return __generator(this, function (_a) {
|
|
76
126
|
res = [];
|
|
77
127
|
node_cron_1.default.schedule('*/' + renewSec.toString() + ' * * * * *', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
78
|
-
var events, newRes, newBid,
|
|
128
|
+
var events, newRes, newBid, format_1, bidIds_1, telegramText;
|
|
129
|
+
var _this = this;
|
|
79
130
|
return __generator(this, function (_a) {
|
|
80
131
|
switch (_a.label) {
|
|
81
|
-
case 0:
|
|
82
|
-
console.log("listening for every " + renewSec.toString() + " s...");
|
|
83
|
-
return [4 /*yield*/, provider.getEvents(
|
|
84
|
-
/// from object id , can only get one event
|
|
85
|
-
// { Object: "0x89bc7299c684413ab81f7536603451277b8ed754" },
|
|
86
|
-
// { Transaction: "4aTaXLyCwT9geQg5PC3UAGGBMbuySFCzeJ6Cf62RrUEg"},
|
|
87
|
-
{ MoveEvent: type }, null, null)];
|
|
132
|
+
case 0: return [4 /*yield*/, provider.getEvents({ MoveEvent: type }, null, null)];
|
|
88
133
|
case 1:
|
|
89
134
|
events = _a.sent();
|
|
90
135
|
newRes = events.data;
|
|
91
|
-
if (newRes.length != res.length)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
136
|
+
if (!(newRes.length != res.length)) return [3 /*break*/, 3];
|
|
137
|
+
console.log("the total bid event number now: " + events.data.length);
|
|
138
|
+
console.log("there are " + (newRes.length - res.length).toString() + " new bids");
|
|
139
|
+
newBid = newRes.filter(function (_a) {
|
|
140
|
+
var id1 = _a.timestamp;
|
|
141
|
+
return !res.some(function (_a) {
|
|
142
|
+
var id2 = _a.timestamp;
|
|
143
|
+
return id2 === id1;
|
|
96
144
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
145
|
+
});
|
|
146
|
+
console.log("new bid amount: " + newBid.length);
|
|
147
|
+
format_1 = "";
|
|
148
|
+
return [4 /*yield*/, generateBidId(vault)];
|
|
149
|
+
case 2:
|
|
150
|
+
bidIds_1 = _a.sent();
|
|
151
|
+
// [
|
|
152
|
+
// 'ETH-18Jan23-1750-C',
|
|
153
|
+
// 'BTC-18Jan23-21800-C',
|
|
154
|
+
// 'ETH-17Jan23-1750-C',
|
|
155
|
+
// 'SUI-18Jan23-9-C'
|
|
156
|
+
// ]
|
|
157
|
+
newBid.map(function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
+
var bidId, size;
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
|
+
bidId = bidIds_1.find(function (bidId) { return e.event.moveEvent.type.includes(bidId.split("-")[0]); });
|
|
161
|
+
if (bidId) {
|
|
162
|
+
size = (Number(e.event.moveEvent.fields.size) / (Math.pow(10, constants_1.TOKEN_DECIMAL))).toString();
|
|
163
|
+
format_1 += bidId + " is bid with " + size + " " + bidId.split("-")[0] + "! \n";
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
console.log("can't get bidId in getBidEventsCranker");
|
|
167
|
+
}
|
|
168
|
+
return [2 /*return*/];
|
|
103
169
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
170
|
+
}); });
|
|
171
|
+
telegramText = format_1;
|
|
172
|
+
console.log(telegramText);
|
|
173
|
+
sendEventToTelegramChannel(telegramText);
|
|
174
|
+
res = newRes;
|
|
175
|
+
_a.label = 3;
|
|
176
|
+
case 3: return [2 /*return*/];
|
|
110
177
|
}
|
|
111
178
|
});
|
|
112
179
|
}); });
|
|
@@ -115,39 +182,38 @@ function getBidEventsCranker(type, renewSec) {
|
|
|
115
182
|
});
|
|
116
183
|
}
|
|
117
184
|
exports.getBidEventsCranker = getBidEventsCranker;
|
|
118
|
-
function getNewAuctionEventsCranker(type, renewSec) {
|
|
185
|
+
function getNewAuctionEventsCranker(type, renewSec, vault) {
|
|
119
186
|
return __awaiter(this, void 0, void 0, function () {
|
|
120
187
|
var res;
|
|
121
188
|
var _this = this;
|
|
122
189
|
return __generator(this, function (_a) {
|
|
123
190
|
res = [];
|
|
124
191
|
node_cron_1.default.schedule('*/' + renewSec.toString() + ' * * * * *', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
125
|
-
var events, newRes,
|
|
192
|
+
var events, newRes, format_2, bidIds, telegramText;
|
|
193
|
+
var _this = this;
|
|
126
194
|
return __generator(this, function (_a) {
|
|
127
195
|
switch (_a.label) {
|
|
128
|
-
case 0:
|
|
129
|
-
console.log("listening for every " + renewSec.toString() + " s...");
|
|
130
|
-
return [4 /*yield*/, provider.getEvents({ MoveEvent: type }, null, null)];
|
|
196
|
+
case 0: return [4 /*yield*/, provider.getEvents({ MoveEvent: type }, null, null)];
|
|
131
197
|
case 1:
|
|
132
198
|
events = _a.sent();
|
|
133
199
|
newRes = events.data;
|
|
134
|
-
if (newRes.length != res.length)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
console.log(time);
|
|
144
|
-
timesFormat_1 += time + " \n";
|
|
200
|
+
if (!(newRes.length != res.length)) return [3 /*break*/, 3];
|
|
201
|
+
format_2 = "";
|
|
202
|
+
return [4 /*yield*/, generateBidId(vault)];
|
|
203
|
+
case 2:
|
|
204
|
+
bidIds = _a.sent();
|
|
205
|
+
bidIds.map(function (bidId) { return __awaiter(_this, void 0, void 0, function () {
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
format_2 += bidId + " auction is live now! \n";
|
|
208
|
+
return [2 /*return*/];
|
|
145
209
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
210
|
+
}); });
|
|
211
|
+
telegramText = format_2;
|
|
212
|
+
console.log(telegramText);
|
|
213
|
+
sendEventToTelegramChannel(telegramText);
|
|
214
|
+
res = newRes;
|
|
215
|
+
_a.label = 3;
|
|
216
|
+
case 3: return [2 /*return*/];
|
|
151
217
|
}
|
|
152
218
|
});
|
|
153
219
|
}); });
|
|
@@ -156,9 +222,41 @@ function getNewAuctionEventsCranker(type, renewSec) {
|
|
|
156
222
|
});
|
|
157
223
|
}
|
|
158
224
|
exports.getNewAuctionEventsCranker = getNewAuctionEventsCranker;
|
|
159
|
-
function getEndAuctionEventsCranker(type, renewSec) {
|
|
225
|
+
function getEndAuctionEventsCranker(type, renewSec, vault) {
|
|
160
226
|
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
var res;
|
|
228
|
+
var _this = this;
|
|
161
229
|
return __generator(this, function (_a) {
|
|
230
|
+
res = [];
|
|
231
|
+
node_cron_1.default.schedule('*/' + renewSec.toString() + ' * * * * *', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
232
|
+
var events, newRes, format_3, bidIds, telegramText;
|
|
233
|
+
var _this = this;
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
switch (_a.label) {
|
|
236
|
+
case 0: return [4 /*yield*/, provider.getEvents({ MoveEvent: type }, null, null)];
|
|
237
|
+
case 1:
|
|
238
|
+
events = _a.sent();
|
|
239
|
+
newRes = events.data;
|
|
240
|
+
if (!(newRes.length != res.length)) return [3 /*break*/, 3];
|
|
241
|
+
format_3 = "";
|
|
242
|
+
return [4 /*yield*/, generateBidId(vault)];
|
|
243
|
+
case 2:
|
|
244
|
+
bidIds = _a.sent();
|
|
245
|
+
bidIds.map(function (bidId) { return __awaiter(_this, void 0, void 0, function () {
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
format_3 += bidId + " auction is closed! \n";
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
});
|
|
250
|
+
}); });
|
|
251
|
+
telegramText = format_3;
|
|
252
|
+
console.log(telegramText);
|
|
253
|
+
sendEventToTelegramChannel(telegramText);
|
|
254
|
+
res = newRes;
|
|
255
|
+
_a.label = 3;
|
|
256
|
+
case 3: return [2 /*return*/];
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}); });
|
|
162
260
|
return [2 /*return*/];
|
|
163
261
|
});
|
|
164
262
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
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 (_) 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
|
+
var constants_1 = require("../constants");
|
|
40
|
+
var getMakersShares_1 = require("../utils/getMakersShares");
|
|
41
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var makersShares;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0: return [4 /*yield*/, (0, getMakersShares_1.getMakersShares)(constants_1.MAKER_SHARE_TABLE, constants_1.COVERED_CALL_REGISTRY)];
|
|
46
|
+
case 1:
|
|
47
|
+
makersShares = _a.sent();
|
|
48
|
+
console.log(makersShares);
|
|
49
|
+
return [2 /*return*/];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}); })();
|
|
@@ -0,0 +1,147 @@
|
|
|
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 (_) 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.getMakersShares = void 0;
|
|
51
|
+
var sui_js_1 = require("@mysten/sui.js");
|
|
52
|
+
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
53
|
+
function getSubVaultsData(registry) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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
|
+
makerTotalSupply: Number(vault.maker_sub_vault.fields.balance),
|
|
79
|
+
makerTotalBalance: Number(vault.maker_sub_vault.fields.share_supply),
|
|
80
|
+
};
|
|
81
|
+
subVaultsData.set(vaultId, subVaultData);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
85
|
+
finally {
|
|
86
|
+
try {
|
|
87
|
+
if (objsInfo_1_1 && !objsInfo_1_1.done && (_a = objsInfo_1.return)) _a.call(objsInfo_1);
|
|
88
|
+
}
|
|
89
|
+
finally { if (e_1) throw e_1.error; }
|
|
90
|
+
}
|
|
91
|
+
return [2 /*return*/, subVaultsData];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function getMakersShares(makerShareTable, registry) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var subVaultsData, makerShareIds, makerShares;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0: return [4 /*yield*/, getSubVaultsData(registry)]; //vault idx to subvault info
|
|
102
|
+
case 1:
|
|
103
|
+
subVaultsData = _a.sent() //vault idx to subvault info
|
|
104
|
+
;
|
|
105
|
+
return [4 /*yield*/, provider.getObjectsOwnedByObject(makerShareTable)];
|
|
106
|
+
case 2:
|
|
107
|
+
makerShareIds = (_a.sent()).map(function (x) { return x.objectId; });
|
|
108
|
+
return [4 /*yield*/, provider.getObjectBatch(makerShareIds)];
|
|
109
|
+
case 3:
|
|
110
|
+
makerShares = (_a.sent()).map(function (x) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if (x.status != "Exists") {
|
|
113
|
+
console.log("obj not exist");
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
//@ts-ignore
|
|
117
|
+
var obj = (x.details.data.fields);
|
|
118
|
+
/*
|
|
119
|
+
{
|
|
120
|
+
id: { id: '0xae32e84281a8e08fade4f72d0c5f861061deb608' },
|
|
121
|
+
name: {
|
|
122
|
+
type: '0xb92f3c4c26151b86977b8811765fe74cb133a35f::covered_call::MakerShareKey',
|
|
123
|
+
fields: { index: '0', maker: '0x4a3b00eac21bfbe062932a5c2b9710245edb2cc2' }
|
|
124
|
+
},
|
|
125
|
+
value: '23000000000'
|
|
126
|
+
}
|
|
127
|
+
*/
|
|
128
|
+
var index = obj.name.fields.index;
|
|
129
|
+
var share = obj.value;
|
|
130
|
+
var maker = obj.name.fields.maker;
|
|
131
|
+
var depositAmount = (Number(share) / ((_a = subVaultsData.get(Number(index))) === null || _a === void 0 ? void 0 : _a.makerTotalSupply) * ((_b = subVaultsData.get(Number(index))) === null || _b === void 0 ? void 0 : _b.makerTotalBalance));
|
|
132
|
+
var res = {
|
|
133
|
+
coveredCallVaultIndex: index,
|
|
134
|
+
//@ts-ignore
|
|
135
|
+
share: share,
|
|
136
|
+
//@ts-ignore
|
|
137
|
+
maker: maker,
|
|
138
|
+
depositAmount: depositAmount.toFixed(0),
|
|
139
|
+
};
|
|
140
|
+
return res;
|
|
141
|
+
});
|
|
142
|
+
return [2 /*return*/, makerShares];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
exports.getMakersShares = getMakersShares;
|
|
@@ -123,8 +123,9 @@ function getUsersShares(userShareTable, registry) {
|
|
|
123
123
|
var share = Number(x.details.data.fields.value);
|
|
124
124
|
//user deposit amount = (user share/total share) * total balance
|
|
125
125
|
var depositAmount = isRolling ?
|
|
126
|
-
(share
|
|
127
|
-
(share
|
|
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));
|
|
128
|
+
depositAmount = Number(depositAmount.toFixed(0));
|
|
128
129
|
var res = {
|
|
129
130
|
coveredCallVaultIndex: index,
|
|
130
131
|
//@ts-ignore
|
|
@@ -88,7 +88,7 @@ function getVaultDataFromRegistry(registry) {
|
|
|
88
88
|
config = objInfo.details.data.fields.value.fields.config.fields;
|
|
89
89
|
vault = objInfo.details.data.fields.value.fields.vault.fields;
|
|
90
90
|
prev = objInfo.details.data.fields.value.fields.prev;
|
|
91
|
-
prev = (prev != null) ? prev :
|
|
91
|
+
prev = (prev != null) ? prev : null;
|
|
92
92
|
vaultConfig = config.vault_config.fields;
|
|
93
93
|
vaultConfigRes = {
|
|
94
94
|
strikeOtmPct: vaultConfig.strike_otm_pct,
|
|
@@ -172,7 +172,7 @@ function getVaultDataFromRegistry(registry) {
|
|
|
172
172
|
case 3:
|
|
173
173
|
next = objInfo.details.data.fields.value.fields.next;
|
|
174
174
|
totalBidSize = objInfo.details.data.fields.value.fields.total_bid_size;
|
|
175
|
-
deliveryInfo = objInfo.details.data.fields.value.fields.delivery_info;
|
|
175
|
+
deliveryInfo = objInfo.details.data.fields.value.fields.delivery_info ? objInfo.details.data.fields.value.fields.delivery_info.fields : null;
|
|
176
176
|
owner = objInfo.details.data.fields.value.fields.owner;
|
|
177
177
|
tvl = Number(vault.regular_sub_vault.fields.balance) + Number(vault.rolling_sub_vault.fields.balance);
|
|
178
178
|
res = {
|
|
@@ -182,7 +182,7 @@ function getVaultDataFromRegistry(registry) {
|
|
|
182
182
|
config: configRes,
|
|
183
183
|
vault: vaultRes,
|
|
184
184
|
auction: auctionRes,
|
|
185
|
-
prev: prev.toString(),
|
|
185
|
+
prev: (prev) ? prev.toString() : null,
|
|
186
186
|
next: next,
|
|
187
187
|
totalBidSize: totalBidSize,
|
|
188
188
|
deliveryInfo: deliveryInfo,
|