@typus/typus-sdk 0.3.6 → 0.3.8
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 +5 -5
- package/lib/constants.js +5 -5
- package/lib/test/eventListener.d.ts +3 -1
- package/lib/test/eventListener.js +73 -22
- package/lib/test/testDeposit.js +1 -1
- package/lib/test/testSettle.js +1 -1
- package/lib/test/testUnsubscribe.js +1 -1
- package/lib/test/testWithdraw.js +1 -1
- package/lib/utils/coveredCall/getDepositTx.d.ts +1 -1
- package/lib/utils/coveredCall/getDepositTx.js +1 -2
- package/lib/utils/coveredCall/getWithdrawTx.d.ts +1 -1
- package/lib/utils/coveredCall/getWithdrawTx.js +2 -3
- package/lib/utils/fetchData.d.ts +7 -3
- package/lib/utils/getVaultData.js +8 -7
- package/package.json +3 -2
package/lib/constants.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ export declare const TOKEN_REGISTRY_BTC = "0xe0dc19dfc9023f2e86462aa37dc8fae290b
|
|
|
3
3
|
export declare const TOKEN_REGISTRY_ETH = "0x9ad1db50850079e98d5972e3d9a8fdc90b9d1f19";
|
|
4
4
|
export declare const TOKEN_REGISTRY_SUI = "0xc6128d63d24cbdb66e50cef4577e5cf36bb889e1";
|
|
5
5
|
export declare const ORACLE_PACKAGE = "0x0d4b13cc0467c0620ce54abf703faa3b419d967b";
|
|
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 = "
|
|
6
|
+
export declare const COVERED_CALL_PACKAGE = "0x9e02627cbd517b378cb2119862f618078246c813";
|
|
7
|
+
export declare const COVERED_CALL_REGISTRY = "0x3b94b2ead34d0f617c6302ceb2f4e4cb8ff69ae6";
|
|
8
|
+
export declare const COVERED_CALL_MANAGER = "0x10f71ab8bac2a9be4d4972e07a1ea67bef94c263";
|
|
9
|
+
export declare const USER_SHARE_TABLE = "0xa885de38c4e3a28c136ea6aa6cc49a934261042a";
|
|
10
|
+
export declare const MAKER_SHARE_TABLE = "0x70241eccfc271f3c54efc56392f5a6c77950501e";
|
|
11
11
|
export declare const DOV_PACKAGE = "0x1bf2cad8d9d4d11a8e2c981b0f6a9c9744887776";
|
|
12
12
|
export declare const TEST_MINT_TOKEN = "0x672612858fcb5c6abf944638253142820c251753";
|
|
13
13
|
export declare const PRICE_DECIMAL = 8;
|
package/lib/constants.js
CHANGED
|
@@ -9,11 +9,11 @@ exports.TOKEN_REGISTRY_SUI = "0xc6128d63d24cbdb66e50cef4577e5cf36bb889e1"; //fak
|
|
|
9
9
|
//publish from typus-oracle
|
|
10
10
|
exports.ORACLE_PACKAGE = "0x0d4b13cc0467c0620ce54abf703faa3b419d967b";
|
|
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 = "0x9e02627cbd517b378cb2119862f618078246c813";
|
|
13
|
+
exports.COVERED_CALL_REGISTRY = "0x3b94b2ead34d0f617c6302ceb2f4e4cb8ff69ae6";
|
|
14
|
+
exports.COVERED_CALL_MANAGER = "0x10f71ab8bac2a9be4d4972e07a1ea67bef94c263";
|
|
15
|
+
exports.USER_SHARE_TABLE = "0xa885de38c4e3a28c136ea6aa6cc49a934261042a";
|
|
16
|
+
exports.MAKER_SHARE_TABLE = "0x70241eccfc271f3c54efc56392f5a6c77950501e";
|
|
17
17
|
//publish from typus-dov/typus-dov
|
|
18
18
|
exports.DOV_PACKAGE = "0x1bf2cad8d9d4d11a8e2c981b0f6a9c9744887776";
|
|
19
19
|
exports.TEST_MINT_TOKEN = "0x672612858fcb5c6abf944638253142820c251753";
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function getBidEventsCranker(type: string, renewSec: number): Promise<void>;
|
|
2
|
+
export declare function getNewAuctionEventsCranker(type: string, renewSec: number): Promise<void>;
|
|
3
|
+
export declare function sendEventToTelegramChannel(text: any): Promise<void>;
|
|
@@ -39,34 +39,85 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.sendEventToTelegramChannel = exports.getNewAuctionEventsCranker = exports.getBidEventsCranker = void 0;
|
|
42
43
|
var constants_1 = require("../constants");
|
|
43
44
|
var sui_js_1 = require("@mysten/sui.js");
|
|
44
45
|
var node_cron_1 = __importDefault(require("node-cron"));
|
|
46
|
+
var XMLHttpRequest_1 = require("XMLHttpRequest");
|
|
45
47
|
var provider = new sui_js_1.JsonRpcProvider(sui_js_1.Network.DEVNET); //for read only operations
|
|
46
|
-
var
|
|
48
|
+
var apiToken = "5864284783:AAHwXWgt2YgLENdJ9mVBUDBVLHXrMLNgkic";
|
|
49
|
+
/*
|
|
50
|
+
「https://api.telegram.org/botTOKEN/getUpdates」,change TOKEN to token from botFather
|
|
51
|
+
*/
|
|
52
|
+
var chatId = "-1001784476809";
|
|
47
53
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
var bidType, newAuctionType, renewSec;
|
|
48
55
|
return __generator(this, function (_a) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
switch (_a.label) {
|
|
53
|
-
case 0: return [4 /*yield*/, provider.getEvents(
|
|
54
|
-
// { MoveEvent: `${PACKAGE_ID}::amm::PoolCreationEvent` },
|
|
55
|
-
{ Object: "0x89bc7299c684413ab81f7536603451277b8ed754" }, null, null, 'descending')];
|
|
56
|
-
case 1:
|
|
57
|
-
events = _a.sent();
|
|
58
|
-
console.log(events.data.length);
|
|
59
|
-
events.data.forEach(function (envelope) {
|
|
60
|
-
var event = envelope.event;
|
|
61
|
-
// if (!('moveEvent' in event)) {
|
|
62
|
-
// throw new Error('Not a MoveEvent')
|
|
63
|
-
// }
|
|
64
|
-
console.log(event);
|
|
65
|
-
});
|
|
66
|
-
return [2 /*return*/];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}); });
|
|
56
|
+
bidType = constants_1.DOV_PACKAGE + "::dutch::NewBid<" + constants_1.TOKEN_PACKAGE + "::eth::ETH>";
|
|
57
|
+
newAuctionType = constants_1.COVERED_CALL_PACKAGE + "::covered_call::NewAuction";
|
|
58
|
+
renewSec = 10;
|
|
70
59
|
return [2 /*return*/];
|
|
71
60
|
});
|
|
72
61
|
}); })();
|
|
62
|
+
function getBidEventsCranker(type, renewSec) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var res;
|
|
65
|
+
var _this = this;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
res = [];
|
|
68
|
+
node_cron_1.default.schedule('*/' + renewSec.toString() + ' * * * * *', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
69
|
+
var events, newRes, newBid;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
console.log("listening for every " + renewSec.toString() + " s...");
|
|
74
|
+
return [4 /*yield*/, provider.getEvents(
|
|
75
|
+
/// from object id , can only get one event
|
|
76
|
+
// { Object: "0x89bc7299c684413ab81f7536603451277b8ed754" },
|
|
77
|
+
// { Transaction: "4aTaXLyCwT9geQg5PC3UAGGBMbuySFCzeJ6Cf62RrUEg"},
|
|
78
|
+
{ MoveEvent: type }, null, null)];
|
|
79
|
+
case 1:
|
|
80
|
+
events = _a.sent();
|
|
81
|
+
newRes = events.data;
|
|
82
|
+
if (newRes.length != res.length) {
|
|
83
|
+
console.log("the total bid event number now:" + events.data.length);
|
|
84
|
+
console.log("there are " + (newRes.length - res.length).toString() + " new bids");
|
|
85
|
+
newBid = newRes.filter(function (e) {
|
|
86
|
+
return res.indexOf(e) === -1;
|
|
87
|
+
});
|
|
88
|
+
newBid.map(function (e) { console.log(e.event.moveEvent.fields); });
|
|
89
|
+
res = newRes;
|
|
90
|
+
}
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}); });
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.getBidEventsCranker = getBidEventsCranker;
|
|
100
|
+
function getNewAuctionEventsCranker(type, renewSec) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.getNewAuctionEventsCranker = getNewAuctionEventsCranker;
|
|
108
|
+
function sendEventToTelegramChannel(text) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var urlString, request;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
urlString = "https://api.telegram.org/bot".concat(apiToken, "/sendMessage?chat_id=").concat(chatId, "&text=").concat(text);
|
|
113
|
+
request = new XMLHttpRequest_1.XMLHttpRequest();
|
|
114
|
+
request.open("GET", urlString);
|
|
115
|
+
request.send();
|
|
116
|
+
request.onload = function () {
|
|
117
|
+
console.log(JSON.parse(request.responseText));
|
|
118
|
+
};
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.sendEventToTelegramChannel = sendEventToTelegramChannel;
|
package/lib/test/testDeposit.js
CHANGED
|
@@ -60,7 +60,7 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
60
60
|
case 1:
|
|
61
61
|
typeArgument = _a.sent();
|
|
62
62
|
console.log("test for deposit, try to deposit " + token + " for " + depositAmount + " ...");
|
|
63
|
-
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex,
|
|
63
|
+
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex, token, depositAmount)];
|
|
64
64
|
case 2:
|
|
65
65
|
depositTx = _a.sent();
|
|
66
66
|
return [4 /*yield*/, signer.executeMoveCall(depositTx)];
|
package/lib/test/testSettle.js
CHANGED
|
@@ -401,7 +401,7 @@ function depositToVault(typeArgument, vaultIndex, depositAmount) {
|
|
|
401
401
|
switch (_a.label) {
|
|
402
402
|
case 0:
|
|
403
403
|
_a.trys.push([0, 3, , 4]);
|
|
404
|
-
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex.toString(),
|
|
404
|
+
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex.toString(), token, depositAmount.toString())];
|
|
405
405
|
case 1:
|
|
406
406
|
depositTx = _a.sent();
|
|
407
407
|
return [4 /*yield*/, signer.executeMoveCall(depositTx)];
|
|
@@ -67,7 +67,7 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
67
67
|
return [4 /*yield*/, (0, getTypeArgumentFromToken_1.getTypeArgumentFromToken)(token)];
|
|
68
68
|
case 1:
|
|
69
69
|
typeArgument = _a.sent();
|
|
70
|
-
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex,
|
|
70
|
+
return [4 /*yield*/, (0, getDepositTx_1.getDepositTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex, token, depositAmount)];
|
|
71
71
|
case 2:
|
|
72
72
|
depositTx = _a.sent();
|
|
73
73
|
return [4 /*yield*/, signer.executeMoveCall(depositTx)];
|
package/lib/test/testWithdraw.js
CHANGED
|
@@ -57,7 +57,7 @@ var signer = new sui_js_1.RawSigner(keypair, provider);
|
|
|
57
57
|
case 1:
|
|
58
58
|
typeArgument = _a.sent();
|
|
59
59
|
console.log("test for withdraw, try to withdraw " + token + " for " + withdrawAmount + " ...");
|
|
60
|
-
return [4 /*yield*/, (0, getWithdrawTx_1.getWithdrawTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex.toString(),
|
|
60
|
+
return [4 /*yield*/, (0, getWithdrawTx_1.getWithdrawTx)(constants_1.COVERED_CALL_PACKAGE, constants_1.COVERED_CALL_REGISTRY, typeArgument, vaultIndex.toString(), withdrawAmount.toString())];
|
|
61
61
|
case 2:
|
|
62
62
|
withdrawTx = _a.sent();
|
|
63
63
|
return [4 /*yield*/, signer.executeMoveCall(withdrawTx)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getDepositTx(packageId: string, registry: string, typeArgument: string, vaultIndex: string,
|
|
1
|
+
export declare function getDepositTx(packageId: string, registry: string, typeArgument: string, vaultIndex: string, coin: string, amount: 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.getDepositTx = void 0;
|
|
40
|
-
function getDepositTx(packageId, registry, typeArgument, vaultIndex,
|
|
40
|
+
function getDepositTx(packageId, registry, typeArgument, vaultIndex, coin, amount) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -51,7 +51,6 @@ function getDepositTx(packageId, registry, typeArgument, vaultIndex, isRolling,
|
|
|
51
51
|
vaultIndex,
|
|
52
52
|
coin,
|
|
53
53
|
amount,
|
|
54
|
-
isRolling,
|
|
55
54
|
],
|
|
56
55
|
gasBudget: 10000,
|
|
57
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getWithdrawTx(packageId: string, registry: string, typeArgument: string, vaultIndex: string,
|
|
1
|
+
export declare function getWithdrawTx(packageId: string, registry: string, typeArgument: string, vaultIndex: string, share: 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.getWithdrawTx = void 0;
|
|
40
|
-
function getWithdrawTx(packageId, registry, typeArgument, vaultIndex,
|
|
40
|
+
function getWithdrawTx(packageId, registry, typeArgument, vaultIndex, share) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
42
|
var tx;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
@@ -49,8 +49,7 @@ function getWithdrawTx(packageId, registry, typeArgument, vaultIndex, isRolling,
|
|
|
49
49
|
arguments: [
|
|
50
50
|
registry,
|
|
51
51
|
vaultIndex,
|
|
52
|
-
|
|
53
|
-
isRolling,
|
|
52
|
+
share,
|
|
54
53
|
],
|
|
55
54
|
gasBudget: 1000,
|
|
56
55
|
};
|
package/lib/utils/fetchData.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export interface Auction {
|
|
|
51
51
|
priceConfig: PriceConfig;
|
|
52
52
|
index: string;
|
|
53
53
|
}
|
|
54
|
+
export interface DeliveryInfo {
|
|
55
|
+
deliveryPrice: string;
|
|
56
|
+
deliverySize: string;
|
|
57
|
+
}
|
|
54
58
|
export interface CoveredCallVault {
|
|
55
59
|
vaultId: string;
|
|
56
60
|
vaultIdx: string;
|
|
@@ -58,10 +62,10 @@ export interface CoveredCallVault {
|
|
|
58
62
|
config: Config;
|
|
59
63
|
vault: Vault;
|
|
60
64
|
auction: Auction;
|
|
61
|
-
|
|
65
|
+
prev: string;
|
|
62
66
|
next: string;
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
totalBidSize: string;
|
|
68
|
+
deliveryInfo: DeliveryInfo;
|
|
65
69
|
owner: string;
|
|
66
70
|
tvl: string;
|
|
67
71
|
vaultBidPrice: string;
|
|
@@ -88,7 +88,7 @@ function getVaultDataFromRegistry(registry) {
|
|
|
88
88
|
case 3:
|
|
89
89
|
_a = __read.apply(void 0, [_c.sent(), 2]), timeOracle = _a[0], _ = _a[1];
|
|
90
90
|
_loop_1 = function (objInfo) {
|
|
91
|
-
var vaultId, vaultIdx, type, asset, config, vault,
|
|
91
|
+
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;
|
|
92
92
|
return __generator(this, function (_d) {
|
|
93
93
|
switch (_d.label) {
|
|
94
94
|
case 0:
|
|
@@ -106,7 +106,8 @@ function getVaultDataFromRegistry(registry) {
|
|
|
106
106
|
}
|
|
107
107
|
config = objInfo.details.data.fields.value.fields.config.fields;
|
|
108
108
|
vault = objInfo.details.data.fields.value.fields.vault.fields;
|
|
109
|
-
|
|
109
|
+
prev = objInfo.details.data.fields.value.fields.prev;
|
|
110
|
+
prev = (prev != null) ? prev : 0;
|
|
110
111
|
vaultConfig = config.vault_config.fields;
|
|
111
112
|
vaultConfigRes = {
|
|
112
113
|
strikeOtmPct: vaultConfig.strike_otm_pct,
|
|
@@ -189,8 +190,8 @@ function getVaultDataFromRegistry(registry) {
|
|
|
189
190
|
_d.label = 3;
|
|
190
191
|
case 3:
|
|
191
192
|
next = objInfo.details.data.fields.value.fields.next;
|
|
192
|
-
|
|
193
|
-
|
|
193
|
+
totalBidSize = objInfo.details.data.fields.value.fields.total_bid_size;
|
|
194
|
+
deliveryInfo = objInfo.details.data.fields.value.fields.delivery_info;
|
|
194
195
|
owner = objInfo.details.data.fields.value.fields.owner;
|
|
195
196
|
tvl = Number(vault.regular_sub_vault.fields.balance) + Number(vault.rolling_sub_vault.fields.balance);
|
|
196
197
|
res = {
|
|
@@ -200,10 +201,10 @@ function getVaultDataFromRegistry(registry) {
|
|
|
200
201
|
config: configRes,
|
|
201
202
|
vault: vaultRes,
|
|
202
203
|
auction: auctionRes,
|
|
203
|
-
|
|
204
|
+
prev: prev.toString(),
|
|
204
205
|
next: next,
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
totalBidSize: totalBidSize,
|
|
207
|
+
deliveryInfo: deliveryInfo,
|
|
207
208
|
owner: owner,
|
|
208
209
|
tvl: tvl.toString(),
|
|
209
210
|
vaultBidPrice: vaultBidPrice.toString(),
|
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.3.
|
|
5
|
+
"version": "0.3.8",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@mysten/bcs": "^0.5.0",
|
|
8
8
|
"@mysten/sui.js": "^0.20.0",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
"tslib": "^1.14.1",
|
|
50
50
|
"tsutils": "^2.29.0",
|
|
51
51
|
"wrappy": "^1.0.2",
|
|
52
|
-
"ws": "^8.11.0"
|
|
52
|
+
"ws": "^8.11.0",
|
|
53
|
+
"xmlhttprequest": "^1.8.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/bs58": "^4.0.1",
|