@typus/typus-sdk 1.2.77 → 1.2.79
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/config.json +2 -0
- package/lib/utils/tools.d.ts +4 -0
- package/lib/utils/tools.js +26 -1
- package/lib/utils/typus-dov-single-v2/function/bidding.d.ts +78 -0
- package/lib/utils/typus-dov-single-v2/function/bidding.js +630 -0
- package/lib/utils/typus-dov-single-v2/function/token.d.ts +21 -0
- package/lib/utils/typus-dov-single-v2/function/token.js +36 -0
- package/lib/utils/typus-dov-single-v2/function/vault.d.ts +8 -0
- package/lib/utils/typus-dov-single-v2/function/vault.js +23 -0
- package/package.json +3 -2
package/lib/config.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"TGLD_COIN_METADATA": "0x3a070c729606334a2be7c51ab28da9a1101b0de01452dd62c10cda0f7a5795d2",
|
|
6
6
|
"TGLD_TOKEN_POLICY": "0xd9461bd329f1df24be9698131b6e2c2b9eaac7c9cf6d76689112f2e57be12009",
|
|
7
7
|
"NFT_TRANSFER_POLICY": "0x55475b9e16d9a0176dcef37f83a1921b15f2cbd2711a5f30b9d952c0c8f5f957",
|
|
8
|
+
"STRATEGY_POOL": "0x2c60ddd50d76beb00faa025962d566359a6ea05b1f7f19ac6bd050f4db8c885c",
|
|
8
9
|
"PACKAGE_ORIGIN": {
|
|
9
10
|
"DOV_SINGLE": "0x321848bf1ae327a9e022ccb3701940191e02fa193ab160d9c0e49cd3c003de3a",
|
|
10
11
|
"FRAMEWORK": "0xb4f25230ba74837d8299e92951306100c4a532e8c48cc3d8828abe9b91c8b274",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"TGLD_COIN_METADATA": "0xf77f8aabe64dccef0e568f2ef58a6ca74bdfb31786507cc35b7626a4df0d0ebc",
|
|
55
56
|
"TGLD_TOKEN_POLICY": "0x17875c2f772053cd148bd2b8b8a40160db3f841825d8963192f8394d5c18974c",
|
|
56
57
|
"NFT_TRANSFER_POLICY": "0x1c62271ecc443c3d92a8fe8f5662e877856d26b971d967f66937a65f55160831",
|
|
58
|
+
"STRATEGY_POOL": "0x50b01081469d032e04bfcbd057614b1359376920f55c7bebd076e0e2af07a57f",
|
|
57
59
|
"PACKAGE_ORIGIN": {
|
|
58
60
|
"DOV_SINGLE": "0x6c9a394a43844fc09d9617bc8a8e775a4521f0e28e83de1da780d043a498671f",
|
|
59
61
|
"FRAMEWORK": "0x908a10789a1a6953e0b73a997c10e3552f7ce4e2907afd00a334ed74bd973ded",
|
package/lib/utils/tools.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
1
2
|
export declare function U64FromBytes(x: any): bigint;
|
|
2
3
|
export declare function AddressFromBytes(x: any): string;
|
|
4
|
+
export declare const insertAt: (str: string, sub: string, pos: number) => string;
|
|
5
|
+
export declare const checkNumber: (str: any) => boolean;
|
|
6
|
+
export declare const countFloating: (value: number | BigNumber) => number;
|
package/lib/utils/tools.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AddressFromBytes = exports.U64FromBytes = void 0;
|
|
6
|
+
exports.countFloating = exports.checkNumber = exports.insertAt = exports.AddressFromBytes = exports.U64FromBytes = void 0;
|
|
7
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
4
8
|
function U64FromBytes(x) {
|
|
5
9
|
var u64 = BigInt(0);
|
|
6
10
|
for (var i = 0; i < x.length; i++) {
|
|
@@ -18,3 +22,24 @@ function AddressFromBytes(x) {
|
|
|
18
22
|
return address;
|
|
19
23
|
}
|
|
20
24
|
exports.AddressFromBytes = AddressFromBytes;
|
|
25
|
+
var insertAt = function (str, sub, pos) { return "".concat(str.slice(0, pos)).concat(sub).concat(str.slice(pos)); };
|
|
26
|
+
exports.insertAt = insertAt;
|
|
27
|
+
var checkNumber = function (str) {
|
|
28
|
+
if (typeof str != "string")
|
|
29
|
+
return false; // we only process strings!
|
|
30
|
+
return (
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
!isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
|
33
|
+
!isNaN(parseFloat(str))); // ...and ensure strings of whitespace fail
|
|
34
|
+
};
|
|
35
|
+
exports.checkNumber = checkNumber;
|
|
36
|
+
var countFloating = function (value) {
|
|
37
|
+
var num = (0, bignumber_js_1.default)(value).toFixed().replace(/,/g, "");
|
|
38
|
+
if (value instanceof bignumber_js_1.default) {
|
|
39
|
+
num = value.toFixed().replace(/,/g, "");
|
|
40
|
+
}
|
|
41
|
+
if (!num.includes("."))
|
|
42
|
+
return 0;
|
|
43
|
+
return num.split(".")[1].length;
|
|
44
|
+
};
|
|
45
|
+
exports.countFloating = countFloating;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { SuiClient } from "@mysten/sui.js/dist/cjs/client";
|
|
3
|
+
import { Auction, BidShare, Vault } from "../view-function";
|
|
4
|
+
export declare const tokenOrder: {
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const optionTypeOrder: {
|
|
8
|
+
[key: string]: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const periodOrder: {
|
|
11
|
+
[key: string]: number;
|
|
12
|
+
};
|
|
13
|
+
export type Receipt = {
|
|
14
|
+
id: string;
|
|
15
|
+
index: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
vid: string;
|
|
19
|
+
};
|
|
20
|
+
export type TokenAmount = {
|
|
21
|
+
value: string;
|
|
22
|
+
token: string;
|
|
23
|
+
};
|
|
24
|
+
export type BidVaultInfo = {
|
|
25
|
+
vaultInfo: Vault;
|
|
26
|
+
receipt: Receipt;
|
|
27
|
+
};
|
|
28
|
+
export interface Bid {
|
|
29
|
+
vaultIndex: string;
|
|
30
|
+
expiry: string;
|
|
31
|
+
auctionName: string;
|
|
32
|
+
strikes: string[];
|
|
33
|
+
bidSize: TokenAmount;
|
|
34
|
+
breakEvenPrice: string;
|
|
35
|
+
estPnls: TokenAmount[];
|
|
36
|
+
receiptsId: string[];
|
|
37
|
+
receiptsVid: string[];
|
|
38
|
+
settlePrice: string;
|
|
39
|
+
isAutoBid: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface OrderBy {
|
|
42
|
+
tokenOrder: number;
|
|
43
|
+
optionTypeOrder: number;
|
|
44
|
+
periodOrder: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const IncentiveRateBp = 4;
|
|
47
|
+
export declare const calcIncentiveRate: (incentiveBp: any) => number;
|
|
48
|
+
export declare const calcDeliveryPrice: (bidShare: BidShare, vaultInfo: Vault) => BigNumber;
|
|
49
|
+
export declare const calcBreakEvenPrice: (optionType: string, period: string, strikes: string[], bToken: string, price: string, incentive: number) => number;
|
|
50
|
+
export declare const calcEstPnl: (live: boolean, incentive: number, bidSize: string, optionType: string, assets: string[], strikes: string[], bidShare: BidShare, deliveryPrice: string, oTokenPrice: string) => TokenAmount[];
|
|
51
|
+
export declare const parseStrikes: (period: string, optionType: string, metadata: string) => string[];
|
|
52
|
+
export declare const parseBidReceipt: (vaults: Vault[], bidReceipts: {
|
|
53
|
+
[key: string]: Receipt[];
|
|
54
|
+
}) => {
|
|
55
|
+
sortedBidReceipts: string[];
|
|
56
|
+
bidVaultsInfo: BidVaultInfo[];
|
|
57
|
+
};
|
|
58
|
+
export declare const parseBid: (bidVaultInfo: BidVaultInfo, bidShare: BidShare, auction: Auction | null, oTokenPrice: string, isAutoBid: boolean) => Bid & OrderBy;
|
|
59
|
+
export declare const getUserBidReceipts: (provider: SuiClient, network: string, originFramworkAddress: string, userAddress: string) => Promise<{
|
|
60
|
+
[key: string]: Receipt[];
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Fetch user's bids info
|
|
64
|
+
*
|
|
65
|
+
* @param provider - Sui Client instance.
|
|
66
|
+
* @param network - network type in lowercase.
|
|
67
|
+
* @param packageAddress - Typus main package address.
|
|
68
|
+
* @param framworkAddress - Typus framwork package address.
|
|
69
|
+
* @param originFramworkAddress - Typus intial framwork package address.
|
|
70
|
+
* @param registryAddress - Typus registry package address.
|
|
71
|
+
* @param strategyPoolAddress - strategy pool package address.
|
|
72
|
+
* @param userAddress - user's wallet address.
|
|
73
|
+
* @param prices - tokens prices (usd pair on Pyth)
|
|
74
|
+
* @return User Bids.
|
|
75
|
+
*/
|
|
76
|
+
export declare const fetchUserBids: (provider: SuiClient, network: string, packageAddress: string, framworkAddress: string, originFramworkAddress: string, registryAddress: string, strategyPoolAddress: string, userAddress: string, prices: {
|
|
77
|
+
[key: string]: string;
|
|
78
|
+
}) => Promise<any>;
|
|
@@ -0,0 +1,630 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
63
|
+
var __values = (this && this.__values) || function(o) {
|
|
64
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
|
+
if (m) return m.call(o);
|
|
66
|
+
if (o && typeof o.length === "number") return {
|
|
67
|
+
next: function () {
|
|
68
|
+
if (o && i >= o.length) o = void 0;
|
|
69
|
+
return { value: o && o[i++], done: !o };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
|
+
};
|
|
74
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
|
+
};
|
|
77
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
+
exports.fetchUserBids = exports.getUserBidReceipts = exports.parseBid = exports.parseBidReceipt = exports.parseStrikes = exports.calcEstPnl = exports.calcBreakEvenPrice = exports.calcDeliveryPrice = exports.calcIncentiveRate = exports.IncentiveRateBp = exports.periodOrder = exports.optionTypeOrder = exports.tokenOrder = void 0;
|
|
79
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
80
|
+
var lodash_1 = require("lodash");
|
|
81
|
+
var moment_1 = __importDefault(require("moment"));
|
|
82
|
+
var view_function_1 = require("../view-function");
|
|
83
|
+
var vault_1 = require("./vault");
|
|
84
|
+
var token_1 = require("./token");
|
|
85
|
+
var tools_1 = require("../../tools");
|
|
86
|
+
var view_function_2 = require("../../auto-bid/view-function");
|
|
87
|
+
var PriceDecimal = (0, bignumber_js_1.default)(10).pow(8);
|
|
88
|
+
exports.tokenOrder = {
|
|
89
|
+
// Basically it's a to z but put SUI at first
|
|
90
|
+
SUI: 0,
|
|
91
|
+
AFSUI: 1,
|
|
92
|
+
APT: 2,
|
|
93
|
+
WBTC: 3,
|
|
94
|
+
BTC: 3,
|
|
95
|
+
BUCK: 4,
|
|
96
|
+
CETUS: 5,
|
|
97
|
+
WETH: 6,
|
|
98
|
+
ETH: 6,
|
|
99
|
+
FUD: 7,
|
|
100
|
+
INJ: 8,
|
|
101
|
+
JUP: 9,
|
|
102
|
+
NAVX: 10,
|
|
103
|
+
SCA: 11,
|
|
104
|
+
SEI: 12,
|
|
105
|
+
WSOL: 13,
|
|
106
|
+
SOL: 14,
|
|
107
|
+
TURBOS: 15,
|
|
108
|
+
USDC: 16,
|
|
109
|
+
USDT: 17,
|
|
110
|
+
USDY: 18,
|
|
111
|
+
};
|
|
112
|
+
exports.optionTypeOrder = {
|
|
113
|
+
0: 0,
|
|
114
|
+
1: 2,
|
|
115
|
+
2: 3,
|
|
116
|
+
4: 4,
|
|
117
|
+
6: 5,
|
|
118
|
+
5: 6,
|
|
119
|
+
};
|
|
120
|
+
exports.periodOrder = {
|
|
121
|
+
0: 1,
|
|
122
|
+
1: 2,
|
|
123
|
+
2: 3,
|
|
124
|
+
3: 0,
|
|
125
|
+
};
|
|
126
|
+
exports.IncentiveRateBp = 4;
|
|
127
|
+
var calcIncentiveRate = function (incentiveBp) {
|
|
128
|
+
var incentiveRateBp = (0, bignumber_js_1.default)(incentiveBp).div((0, bignumber_js_1.default)(10).pow(exports.IncentiveRateBp));
|
|
129
|
+
var incentiveRate = 1;
|
|
130
|
+
if (incentiveRateBp.gt(0)) {
|
|
131
|
+
incentiveRate = 1 - Number(incentiveRateBp);
|
|
132
|
+
}
|
|
133
|
+
return incentiveRate;
|
|
134
|
+
};
|
|
135
|
+
exports.calcIncentiveRate = calcIncentiveRate;
|
|
136
|
+
var calcDeliveryPrice = function (bidShare, vaultInfo) {
|
|
137
|
+
var bTokenDecimal = vaultInfo.info.bTokenDecimal;
|
|
138
|
+
var deliveryPrice = (0, bignumber_js_1.default)("0");
|
|
139
|
+
// check if bid has settled already
|
|
140
|
+
if (bidShare.bidVault.u64Padding[1]) {
|
|
141
|
+
deliveryPrice = (0, bignumber_js_1.default)(bidShare.bidVault.u64Padding[1]);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
var deliveryInfos = vaultInfo.info.deliveryInfos.deliveryInfo;
|
|
145
|
+
var deliveryInfo = deliveryInfos[deliveryInfos.length - 1];
|
|
146
|
+
deliveryPrice = deliveryInfo ? (0, bignumber_js_1.default)(deliveryInfo.deliveryPrice) : (0, bignumber_js_1.default)("0");
|
|
147
|
+
}
|
|
148
|
+
deliveryPrice = (0, bignumber_js_1.default)(deliveryPrice).div((0, bignumber_js_1.default)(10).pow((0, bignumber_js_1.default)(bTokenDecimal)));
|
|
149
|
+
return deliveryPrice;
|
|
150
|
+
};
|
|
151
|
+
exports.calcDeliveryPrice = calcDeliveryPrice;
|
|
152
|
+
var calcBreakEvenPrice = function (optionType, period, strikes, bToken, price, incentive) {
|
|
153
|
+
var breakEvenPrice = 0;
|
|
154
|
+
switch (optionType) {
|
|
155
|
+
case "0":
|
|
156
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
157
|
+
breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case "1":
|
|
164
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
165
|
+
breakEvenPrice = Number(strikes[0]) - Number(price) * 1.1 * incentive;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case "2":
|
|
172
|
+
// Calculate with the lower one
|
|
173
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
174
|
+
breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
case "4":
|
|
181
|
+
// Calculate with the lower one
|
|
182
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
183
|
+
breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
breakEvenPrice = Number(strikes[0]) / (1 - Number(price) * 1.1 * incentive);
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
case "5":
|
|
190
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
191
|
+
breakEvenPrice = Number(strikes[1]) - Number(price) * 1.1 * incentive;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
breakEvenPrice = Number(strikes[1]) / (1 + Number(price) * 1.1 * incentive);
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case "6":
|
|
198
|
+
// Calculate with the lower one
|
|
199
|
+
if (token_1.StableCoin.includes(bToken)) {
|
|
200
|
+
breakEvenPrice = Number(strikes[0]) + Number(price) * 1.1 * incentive;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
breakEvenPrice = Number(strikes[0]) / (1 + Number(price) * 1.1 * incentive);
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
return breakEvenPrice;
|
|
208
|
+
};
|
|
209
|
+
exports.calcBreakEvenPrice = calcBreakEvenPrice;
|
|
210
|
+
var calcEstPnl = function (live, incentive, bidSize, optionType, assets, strikes, bidShare, deliveryPrice, oTokenPrice) {
|
|
211
|
+
var profit = "0";
|
|
212
|
+
var cost = "0";
|
|
213
|
+
var _a = __read(assets, 3), dToken = _a[0], bToken = _a[1], oToken = _a[2];
|
|
214
|
+
var dTokenWrappedName = (0, token_1.getTokenName)({ token: dToken, wrapped: true });
|
|
215
|
+
var bTokenWrappedName = (0, token_1.getTokenName)({ token: bToken, wrapped: true });
|
|
216
|
+
var estPnls = [];
|
|
217
|
+
var referencePrice = bidShare.bidVault.u64Padding.length > 0 ? (0, bignumber_js_1.default)(bidShare.bidVault.u64Padding[0]).div(PriceDecimal) : (0, bignumber_js_1.default)(oTokenPrice);
|
|
218
|
+
if (optionType === "0") {
|
|
219
|
+
profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[0])))
|
|
220
|
+
.div(referencePrice)
|
|
221
|
+
.multipliedBy(bidSize)).toString();
|
|
222
|
+
}
|
|
223
|
+
else if (optionType === "1") {
|
|
224
|
+
profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(strikes[0]).minus(referencePrice).multipliedBy(bidSize)).toString();
|
|
225
|
+
}
|
|
226
|
+
else if (optionType === "2" || optionType === "4") {
|
|
227
|
+
profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[0])))
|
|
228
|
+
.div(referencePrice)
|
|
229
|
+
.multipliedBy(bidSize))
|
|
230
|
+
.minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus((0, bignumber_js_1.default)(strikes[1])))
|
|
231
|
+
.div(referencePrice)
|
|
232
|
+
.multipliedBy(bidSize)))
|
|
233
|
+
.toString();
|
|
234
|
+
}
|
|
235
|
+
else if (optionType === "5") {
|
|
236
|
+
profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)((0, bignumber_js_1.default)(strikes[1]).minus(referencePrice)).multipliedBy(bidSize))
|
|
237
|
+
.minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)((0, bignumber_js_1.default)(strikes[0]).minus((0, bignumber_js_1.default)(referencePrice))).multipliedBy(bidSize)))
|
|
238
|
+
.toString();
|
|
239
|
+
}
|
|
240
|
+
else if (optionType === "6") {
|
|
241
|
+
profit = bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus(strikes[0])).multipliedBy(bidSize))
|
|
242
|
+
.minus(bignumber_js_1.default.max(0, (0, bignumber_js_1.default)(referencePrice.minus(strikes[1])).multipliedBy(bidSize)))
|
|
243
|
+
.toString();
|
|
244
|
+
}
|
|
245
|
+
cost = (0, bignumber_js_1.default)(deliveryPrice).multipliedBy(bidSize).multipliedBy(1.1).multipliedBy(incentive).toString();
|
|
246
|
+
if (dToken === bToken) {
|
|
247
|
+
profit = (0, bignumber_js_1.default)(profit).minus(cost).toString();
|
|
248
|
+
}
|
|
249
|
+
if (!live) {
|
|
250
|
+
estPnls.push({
|
|
251
|
+
value: profit,
|
|
252
|
+
token: dTokenWrappedName,
|
|
253
|
+
});
|
|
254
|
+
if (dToken !== bToken) {
|
|
255
|
+
estPnls.push({ value: "-" + cost, token: bTokenWrappedName });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return estPnls;
|
|
259
|
+
};
|
|
260
|
+
exports.calcEstPnl = calcEstPnl;
|
|
261
|
+
var parseStrikes = function (period, optionType, metadata) {
|
|
262
|
+
var strikes = [period === "3" ? metadata.split("-")[3] : metadata.split("-")[2]];
|
|
263
|
+
switch (optionType) {
|
|
264
|
+
case "0":
|
|
265
|
+
break;
|
|
266
|
+
case "1":
|
|
267
|
+
break;
|
|
268
|
+
case "2":
|
|
269
|
+
strikes = [metadata.split("-")[2], metadata.split("-")[3]];
|
|
270
|
+
break;
|
|
271
|
+
case "4":
|
|
272
|
+
strikes = [metadata.split("-")[2], metadata.split("-")[3]];
|
|
273
|
+
strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
|
|
274
|
+
break;
|
|
275
|
+
case "5":
|
|
276
|
+
strikes = [metadata.split("-")[2], metadata.split("-")[3]];
|
|
277
|
+
if (period == "3") {
|
|
278
|
+
strikes = [metadata.split("-")[3], metadata.split("-")[4]];
|
|
279
|
+
}
|
|
280
|
+
strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
|
|
281
|
+
break;
|
|
282
|
+
case "6":
|
|
283
|
+
strikes = [metadata.split("-")[2], metadata.split("-")[3]];
|
|
284
|
+
if (period == "3") {
|
|
285
|
+
strikes = [metadata.split("-")[3], metadata.split("-")[4]];
|
|
286
|
+
}
|
|
287
|
+
strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
strikes = (0, tools_1.checkNumber)(strikes[0]) ? strikes : [];
|
|
291
|
+
strikes = strikes.sort(function (a, b) { return Number(a) - Number(b); });
|
|
292
|
+
return strikes;
|
|
293
|
+
};
|
|
294
|
+
exports.parseStrikes = parseStrikes;
|
|
295
|
+
var parseBidReceipt = function (vaults, bidReceipts) {
|
|
296
|
+
var sortedBidReceipts = [];
|
|
297
|
+
var bidVaultsInfo = [];
|
|
298
|
+
var vidMap = new Map();
|
|
299
|
+
vaults.forEach(function (v) {
|
|
300
|
+
var curReceipts = bidReceipts[v.info.index];
|
|
301
|
+
if (curReceipts) {
|
|
302
|
+
curReceipts.map(function (receipt) {
|
|
303
|
+
// ###### NOTE: #####
|
|
304
|
+
// Bid receipts need to be sorted and put together
|
|
305
|
+
// BY vid for SDK getMyBids to fetch the correct data.
|
|
306
|
+
// ###########
|
|
307
|
+
// Filer out autoBidReceiptsData receipts cuz it's wrapped in strategy and
|
|
308
|
+
// SDK getMyBids can't retrieve it!
|
|
309
|
+
var data = vidMap.get(receipt.vid);
|
|
310
|
+
if (!data) {
|
|
311
|
+
vidMap.set(receipt.vid, [receipt.id]);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
data.push(receipt.id);
|
|
315
|
+
vidMap.set(receipt.vid, data);
|
|
316
|
+
}
|
|
317
|
+
bidVaultsInfo.push({ vaultInfo: v, receipt: receipt });
|
|
318
|
+
});
|
|
319
|
+
var values = Array.from(vidMap.values());
|
|
320
|
+
sortedBidReceipts = values.reduce(function (previousValue, currentValue, currentIndex, array) {
|
|
321
|
+
return previousValue.concat(currentValue);
|
|
322
|
+
}, []);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return { sortedBidReceipts: sortedBidReceipts, bidVaultsInfo: bidVaultsInfo };
|
|
326
|
+
};
|
|
327
|
+
exports.parseBidReceipt = parseBidReceipt;
|
|
328
|
+
var parseBid = function (bidVaultInfo, bidShare, auction, oTokenPrice, isAutoBid) {
|
|
329
|
+
var _a, _b;
|
|
330
|
+
var vaultInfo = bidVaultInfo.vaultInfo, _c = bidVaultInfo.vaultInfo, info = _c.info, _d = _c.info, index = _d.index, bTokenDecimal = _d.bTokenDecimal, oTokenDecimal = _d.oTokenDecimal, optionType = _d.optionType, period = _d.period, _e = _c.config, lotSize = _e.bidLotSize, bidIncentiveBp = _e.bidIncentiveBp, u64Padding = _e.u64Padding, receipt = bidVaultInfo.receipt;
|
|
331
|
+
var incentiveRate = (0, exports.calcIncentiveRate)(bidIncentiveBp);
|
|
332
|
+
var _f = __read((0, vault_1.parseAssets)(info), 3), dToken = _f[0], bToken = _f[1], oToken = _f[2];
|
|
333
|
+
var oTokenName = (0, token_1.getTokenName)({ token: oToken });
|
|
334
|
+
var dTokenWrappedName = (0, token_1.getTokenName)({ token: dToken, wrapped: true });
|
|
335
|
+
var bTokenWrappedName = (0, token_1.getTokenName)({ token: bToken, wrapped: true });
|
|
336
|
+
var metadata = bidShare.bidVault.metadata;
|
|
337
|
+
var tokenLabel = metadata.split("-")[0];
|
|
338
|
+
var periodLabel = vault_1.Period[Number(period)].charAt(0).toUpperCase() + vault_1.Period[Number(period)].slice(1);
|
|
339
|
+
var optionTypeLabel = vault_1.AbbrStrategyName[optionType];
|
|
340
|
+
var bidsSize = Number(bidShare.share) / Math.pow(10, Number(oTokenDecimal));
|
|
341
|
+
var expirationDate = (0, moment_1.default)(metadata.split("-")[1], "DDMMMYY").format("yyyy-MM-DD");
|
|
342
|
+
expirationDate = moment_1.default
|
|
343
|
+
.utc(period === "3" ? "".concat(expirationDate, " ").concat((0, tools_1.insertAt)(metadata.split("-")[2], ":", 2)) : "".concat(expirationDate, " 08:00"))
|
|
344
|
+
.local()
|
|
345
|
+
.format("DD MMM YY, HH:mm");
|
|
346
|
+
var live = !auction
|
|
347
|
+
? false
|
|
348
|
+
: moment_1.default.unix(Number(auction.endTsMs) / 1000).isAfter((0, moment_1.default)()) &&
|
|
349
|
+
moment_1.default.unix(Number(auction.startTsMs) / 1000).isBefore((0, moment_1.default)()) &&
|
|
350
|
+
(0, moment_1.default)(expirationDate, "DD MMM YY, HH:mm").isAfter(moment_1.default.unix(Number(auction.endTsMs) / 1000));
|
|
351
|
+
var deliveryPrice = (0, exports.calcDeliveryPrice)(bidShare, vaultInfo);
|
|
352
|
+
var initialPrice = (_a = auction === null || auction === void 0 ? void 0 : auction.initialPrice) !== null && _a !== void 0 ? _a : 0;
|
|
353
|
+
initialPrice = (0, bignumber_js_1.default)(initialPrice).div((0, bignumber_js_1.default)(10).pow((0, bignumber_js_1.default)(bTokenDecimal)));
|
|
354
|
+
var strikes = (0, exports.parseStrikes)(period, optionType, metadata);
|
|
355
|
+
var breakEvenPriceReference = live ? initialPrice : deliveryPrice;
|
|
356
|
+
var breakEvenPrice = (0, exports.calcBreakEvenPrice)(optionType, period, strikes, bToken, breakEvenPriceReference, incentiveRate);
|
|
357
|
+
var defaultMinBidSize = (0, bignumber_js_1.default)(lotSize).div((0, bignumber_js_1.default)(10).pow(oTokenDecimal));
|
|
358
|
+
var bidSize = bidsSize.toFixed((0, tools_1.countFloating)(defaultMinBidSize.toNumber()));
|
|
359
|
+
var settlePrice = (0, bignumber_js_1.default)((_b = bidShare.bidVault.u64Padding[0]) !== null && _b !== void 0 ? _b : "0").div(PriceDecimal);
|
|
360
|
+
var estPnls = (0, exports.calcEstPnl)(live, incentiveRate, bidSize, optionType, [dToken, bToken, oToken], strikes, bidShare, deliveryPrice.toString(), oTokenPrice);
|
|
361
|
+
return {
|
|
362
|
+
vaultIndex: index,
|
|
363
|
+
auctionName: "".concat(tokenLabel, " ").concat(periodLabel, " ").concat(optionTypeLabel),
|
|
364
|
+
expiry: expirationDate,
|
|
365
|
+
strikes: strikes.map(function (s) {
|
|
366
|
+
if (tokenLabel === "MFUD") {
|
|
367
|
+
return (0, bignumber_js_1.default)(s).div(1000000).toString();
|
|
368
|
+
}
|
|
369
|
+
return s;
|
|
370
|
+
}),
|
|
371
|
+
bidSize: {
|
|
372
|
+
value: (0, bignumber_js_1.default)(bidSize)
|
|
373
|
+
.div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
|
|
374
|
+
.toString(),
|
|
375
|
+
token: oToken,
|
|
376
|
+
},
|
|
377
|
+
breakEvenPrice: (0, bignumber_js_1.default)(breakEvenPrice)
|
|
378
|
+
.div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
|
|
379
|
+
.toString(),
|
|
380
|
+
settlePrice: (0, bignumber_js_1.default)(settlePrice)
|
|
381
|
+
.div((0, bignumber_js_1.default)(10).pow(oToken === "MFUD" ? 6 : 0))
|
|
382
|
+
.toString(),
|
|
383
|
+
estPnls: estPnls,
|
|
384
|
+
isAutoBid: isAutoBid,
|
|
385
|
+
receiptsId: [receipt.id],
|
|
386
|
+
receiptsVid: [receipt.vid],
|
|
387
|
+
optionTypeOrder: exports.optionTypeOrder[optionType],
|
|
388
|
+
periodOrder: exports.periodOrder[period],
|
|
389
|
+
tokenOrder: exports.tokenOrder[oToken.toUpperCase()],
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
exports.parseBid = parseBid;
|
|
393
|
+
var getUserBidReceipts = function (provider, network, originFramworkAddress, userAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
394
|
+
var bidReceipts, result, hasNextPage, data, nextCursor, data_1, data_1_1, object, content, typeStringComponents, subtype, typeComponents, type, typePackage, vaultIndex, receipt;
|
|
395
|
+
var e_1, _a;
|
|
396
|
+
return __generator(this, function (_b) {
|
|
397
|
+
switch (_b.label) {
|
|
398
|
+
case 0:
|
|
399
|
+
bidReceipts = {};
|
|
400
|
+
return [4 /*yield*/, provider.getOwnedObjects({ owner: userAddress, options: { showType: true, showContent: true } })];
|
|
401
|
+
case 1:
|
|
402
|
+
result = _b.sent();
|
|
403
|
+
hasNextPage = result.hasNextPage;
|
|
404
|
+
data = result.data;
|
|
405
|
+
nextCursor = result.nextCursor;
|
|
406
|
+
_b.label = 2;
|
|
407
|
+
case 2:
|
|
408
|
+
if (!hasNextPage) return [3 /*break*/, 4];
|
|
409
|
+
return [4 /*yield*/, provider.getOwnedObjects({ owner: userAddress, cursor: nextCursor, options: { showType: true, showContent: true } })];
|
|
410
|
+
case 3:
|
|
411
|
+
result = _b.sent();
|
|
412
|
+
data = __spreadArray(__spreadArray([], __read(data), false), __read(result.data), false);
|
|
413
|
+
hasNextPage = result.hasNextPage;
|
|
414
|
+
nextCursor = result.nextCursor;
|
|
415
|
+
return [3 /*break*/, 2];
|
|
416
|
+
case 4:
|
|
417
|
+
if (data.length === 0) {
|
|
418
|
+
return [2 /*return*/, bidReceipts];
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
for (data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
422
|
+
object = data_1_1.value;
|
|
423
|
+
try {
|
|
424
|
+
content = (object.data || {}).content;
|
|
425
|
+
if (!content)
|
|
426
|
+
continue;
|
|
427
|
+
typeStringComponents = (content.type || "").split("<");
|
|
428
|
+
subtype = (typeStringComponents[1] || "").replace(/>/, "");
|
|
429
|
+
typeComponents = typeStringComponents[0].split("::");
|
|
430
|
+
type = typeComponents[typeComponents.length - 1];
|
|
431
|
+
typePackage = typeComponents[0];
|
|
432
|
+
if (type === "TypusBidReceipt" && originFramworkAddress == typePackage) {
|
|
433
|
+
vaultIndex = content.fields.index;
|
|
434
|
+
receipt = {
|
|
435
|
+
// @ts-ignore
|
|
436
|
+
id: content.fields.id.id,
|
|
437
|
+
// @ts-ignore
|
|
438
|
+
index: vaultIndex,
|
|
439
|
+
// @ts-ignore
|
|
440
|
+
name: content.fields.name,
|
|
441
|
+
// @ts-ignore
|
|
442
|
+
description: content.fields.description,
|
|
443
|
+
// @ts-ignore
|
|
444
|
+
vid: content.fields.vid,
|
|
445
|
+
// @ts-ignore
|
|
446
|
+
metadata: content.fields.metadata,
|
|
447
|
+
};
|
|
448
|
+
bidReceipts[vaultIndex] || (bidReceipts[vaultIndex] = []);
|
|
449
|
+
bidReceipts[vaultIndex].push(receipt);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
catch (e) {
|
|
453
|
+
console.log("Error retrieving object", object, e);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
458
|
+
finally {
|
|
459
|
+
try {
|
|
460
|
+
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
|
|
461
|
+
}
|
|
462
|
+
finally { if (e_1) throw e_1.error; }
|
|
463
|
+
}
|
|
464
|
+
return [2 /*return*/, bidReceipts];
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}); };
|
|
468
|
+
exports.getUserBidReceipts = getUserBidReceipts;
|
|
469
|
+
/**
|
|
470
|
+
* Fetch user's bids info
|
|
471
|
+
*
|
|
472
|
+
* @param provider - Sui Client instance.
|
|
473
|
+
* @param network - network type in lowercase.
|
|
474
|
+
* @param packageAddress - Typus main package address.
|
|
475
|
+
* @param framworkAddress - Typus framwork package address.
|
|
476
|
+
* @param originFramworkAddress - Typus intial framwork package address.
|
|
477
|
+
* @param registryAddress - Typus registry package address.
|
|
478
|
+
* @param strategyPoolAddress - strategy pool package address.
|
|
479
|
+
* @param userAddress - user's wallet address.
|
|
480
|
+
* @param prices - tokens prices (usd pair on Pyth)
|
|
481
|
+
* @return User Bids.
|
|
482
|
+
*/
|
|
483
|
+
var fetchUserBids = function (provider, network, packageAddress, framworkAddress, originFramworkAddress, registryAddress, strategyPoolAddress, userAddress, prices) { return __awaiter(void 0, void 0, void 0, function () {
|
|
484
|
+
var vaultsInfo, userReceipts, userStrategies, auctions, _a, sortedBidReceipts, bidVaultsInfo, bidShares, bidsFromBidShares, _loop_1, bidVaultsInfo_1, bidVaultsInfo_1_1, bidVaultInfo, autoBidsShares, vaultAutoBidReceipts, userStrategies_1, userStrategies_1_1, strategy, receipts, receipts_1, receipts_1_1, receiptItem, vaultIndex, receipt, autoBidVaultInfos, bidsFromStrategies, _loop_2, autoBidVaultInfos_1, autoBidVaultInfos_1_1, autoBidVaultInfo, byOrdered;
|
|
485
|
+
var e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
486
|
+
return __generator(this, function (_f) {
|
|
487
|
+
switch (_f.label) {
|
|
488
|
+
case 0: return [4 /*yield*/, (0, view_function_1.getVaults)(provider, packageAddress, registryAddress, [])];
|
|
489
|
+
case 1:
|
|
490
|
+
vaultsInfo = _f.sent();
|
|
491
|
+
return [4 /*yield*/, (0, exports.getUserBidReceipts)(provider, network, originFramworkAddress, userAddress)];
|
|
492
|
+
case 2:
|
|
493
|
+
userReceipts = _f.sent();
|
|
494
|
+
return [4 /*yield*/, (0, view_function_2.getUserStrategies)(provider, packageAddress, registryAddress, strategyPoolAddress, userAddress)];
|
|
495
|
+
case 3:
|
|
496
|
+
userStrategies = _f.sent();
|
|
497
|
+
return [4 /*yield*/, (0, view_function_1.getAuctions)(provider, packageAddress, registryAddress, [])];
|
|
498
|
+
case 4:
|
|
499
|
+
auctions = _f.sent();
|
|
500
|
+
_a = (0, exports.parseBidReceipt)(Object.values(vaultsInfo), userReceipts), sortedBidReceipts = _a.sortedBidReceipts, bidVaultsInfo = _a.bidVaultsInfo;
|
|
501
|
+
return [4 /*yield*/, (0, view_function_1.getMyBids)(provider, framworkAddress, packageAddress, registryAddress, sortedBidReceipts)];
|
|
502
|
+
case 5:
|
|
503
|
+
bidShares = _f.sent();
|
|
504
|
+
bidsFromBidShares = [];
|
|
505
|
+
_loop_1 = function (bidVaultInfo) {
|
|
506
|
+
var bidShare = bidShares["".concat(bidVaultInfo.receipt.index, "-").concat(bidVaultInfo.receipt.vid)];
|
|
507
|
+
var auction = auctions ? auctions[bidVaultInfo.vaultInfo.info.index] : null;
|
|
508
|
+
var _g = __read((0, vault_1.parseAssets)(bidVaultInfo.vaultInfo.info), 3), dToken = _g[0], bToken = _g[1], oToken = _g[2];
|
|
509
|
+
if (bidShare) {
|
|
510
|
+
var data = (0, exports.parseBid)(bidVaultInfo, bidShare, auction, prices[oToken.toLowerCase()], false);
|
|
511
|
+
var checkExistVault = bidsFromBidShares.find(function (p) { return p.vaultIndex === bidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(bidVaultInfo.receipt.vid); });
|
|
512
|
+
if (checkExistVault) {
|
|
513
|
+
// Merge the bid receipts into the same vault
|
|
514
|
+
checkExistVault.receiptsId = __spreadArray(__spreadArray([], __read(checkExistVault.receiptsId), false), __read(data.receiptsId), false);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
bidsFromBidShares.push(data);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
try {
|
|
522
|
+
for (bidVaultsInfo_1 = __values(bidVaultsInfo), bidVaultsInfo_1_1 = bidVaultsInfo_1.next(); !bidVaultsInfo_1_1.done; bidVaultsInfo_1_1 = bidVaultsInfo_1.next()) {
|
|
523
|
+
bidVaultInfo = bidVaultsInfo_1_1.value;
|
|
524
|
+
_loop_1(bidVaultInfo);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
528
|
+
finally {
|
|
529
|
+
try {
|
|
530
|
+
if (bidVaultsInfo_1_1 && !bidVaultsInfo_1_1.done && (_b = bidVaultsInfo_1.return)) _b.call(bidVaultsInfo_1);
|
|
531
|
+
}
|
|
532
|
+
finally { if (e_2) throw e_2.error; }
|
|
533
|
+
}
|
|
534
|
+
autoBidsShares = {};
|
|
535
|
+
vaultAutoBidReceipts = {};
|
|
536
|
+
try {
|
|
537
|
+
for (userStrategies_1 = __values(userStrategies), userStrategies_1_1 = userStrategies_1.next(); !userStrategies_1_1.done; userStrategies_1_1 = userStrategies_1.next()) {
|
|
538
|
+
strategy = userStrategies_1_1.value;
|
|
539
|
+
receipts = strategy.receipts;
|
|
540
|
+
try {
|
|
541
|
+
for (receipts_1 = (e_4 = void 0, __values(receipts)), receipts_1_1 = receipts_1.next(); !receipts_1_1.done; receipts_1_1 = receipts_1.next()) {
|
|
542
|
+
receiptItem = receipts_1_1.value;
|
|
543
|
+
vaultIndex = receiptItem.index;
|
|
544
|
+
receipt = {
|
|
545
|
+
id: receiptItem.id,
|
|
546
|
+
index: vaultIndex,
|
|
547
|
+
name: "",
|
|
548
|
+
description: "",
|
|
549
|
+
vid: receiptItem.vid,
|
|
550
|
+
metadata: receiptItem.metadata,
|
|
551
|
+
};
|
|
552
|
+
if (vaultAutoBidReceipts[vaultIndex]) {
|
|
553
|
+
vaultAutoBidReceipts[vaultIndex] = __spreadArray(__spreadArray([], __read(vaultAutoBidReceipts[vaultIndex]), false), [receipt], false);
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
vaultAutoBidReceipts[vaultIndex] = [receipt];
|
|
557
|
+
}
|
|
558
|
+
if (autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)]) {
|
|
559
|
+
autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)].share = (Number(autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)].share) +
|
|
560
|
+
Number(strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].share)).toString();
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
autoBidsShares["".concat(vaultIndex, "-").concat(receiptItem.vid)] = {
|
|
564
|
+
bidVault: strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].bidVault,
|
|
565
|
+
share: strategy.my_bids["".concat(vaultIndex, "-").concat(receiptItem.vid)].share,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
571
|
+
finally {
|
|
572
|
+
try {
|
|
573
|
+
if (receipts_1_1 && !receipts_1_1.done && (_d = receipts_1.return)) _d.call(receipts_1);
|
|
574
|
+
}
|
|
575
|
+
finally { if (e_4) throw e_4.error; }
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
580
|
+
finally {
|
|
581
|
+
try {
|
|
582
|
+
if (userStrategies_1_1 && !userStrategies_1_1.done && (_c = userStrategies_1.return)) _c.call(userStrategies_1);
|
|
583
|
+
}
|
|
584
|
+
finally { if (e_3) throw e_3.error; }
|
|
585
|
+
}
|
|
586
|
+
autoBidVaultInfos = [];
|
|
587
|
+
Object.values(vaultsInfo).forEach(function (v) {
|
|
588
|
+
var curReceipts = vaultAutoBidReceipts[v.info.index];
|
|
589
|
+
if (curReceipts) {
|
|
590
|
+
curReceipts.map(function (item) {
|
|
591
|
+
autoBidVaultInfos.push({ vaultInfo: v, receipt: item });
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
bidsFromStrategies = [];
|
|
596
|
+
_loop_2 = function (autoBidVaultInfo) {
|
|
597
|
+
var bidShare = autoBidsShares["".concat(autoBidVaultInfo.receipt.index, "-").concat(autoBidVaultInfo.receipt.vid)];
|
|
598
|
+
var auction = auctions ? auctions[autoBidVaultInfo.vaultInfo.info.index] : null;
|
|
599
|
+
var _h = __read((0, vault_1.parseAssets)(autoBidVaultInfo.vaultInfo.info), 3), dToken = _h[0], bToken = _h[1], oToken = _h[2];
|
|
600
|
+
if (bidShare) {
|
|
601
|
+
var data = (0, exports.parseBid)(autoBidVaultInfo, bidShare, auction, prices[oToken.toLowerCase()], false);
|
|
602
|
+
var checkExistVault = bidsFromStrategies.find(function (p) { return p.vaultIndex === autoBidVaultInfo.vaultInfo.info.index && p.receiptsVid.includes(autoBidVaultInfo.receipt.vid); });
|
|
603
|
+
if (checkExistVault) {
|
|
604
|
+
// Merge the bid receipts into the same vault
|
|
605
|
+
checkExistVault.receiptsId = __spreadArray(__spreadArray([], __read(checkExistVault.receiptsId), false), __read(data.receiptsId), false);
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
bidsFromStrategies.push(data);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
try {
|
|
613
|
+
for (autoBidVaultInfos_1 = __values(autoBidVaultInfos), autoBidVaultInfos_1_1 = autoBidVaultInfos_1.next(); !autoBidVaultInfos_1_1.done; autoBidVaultInfos_1_1 = autoBidVaultInfos_1.next()) {
|
|
614
|
+
autoBidVaultInfo = autoBidVaultInfos_1_1.value;
|
|
615
|
+
_loop_2(autoBidVaultInfo);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
619
|
+
finally {
|
|
620
|
+
try {
|
|
621
|
+
if (autoBidVaultInfos_1_1 && !autoBidVaultInfos_1_1.done && (_e = autoBidVaultInfos_1.return)) _e.call(autoBidVaultInfos_1);
|
|
622
|
+
}
|
|
623
|
+
finally { if (e_5) throw e_5.error; }
|
|
624
|
+
}
|
|
625
|
+
byOrdered = (0, lodash_1.orderBy)(__spreadArray(__spreadArray([], __read(bidsFromBidShares), false), __read(bidsFromStrategies), false), ["expiry", "tokenOrder", "periodOrder", "optionTypeOrder"], ["asc", "asc", "asc", "asc"]);
|
|
626
|
+
return [2 /*return*/, byOrdered];
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}); };
|
|
630
|
+
exports.fetchUserBids = fetchUserBids;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const WrappedToken: {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const UnwrappedToken: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const MillionToken: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const RemoveMillionToken: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const LST: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const StableCoin: string[];
|
|
17
|
+
export declare const getTokenName: ({ token, wrapped, million }: {
|
|
18
|
+
token: string;
|
|
19
|
+
wrapped?: boolean | undefined;
|
|
20
|
+
million?: boolean | undefined;
|
|
21
|
+
}) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenName = exports.StableCoin = exports.LST = exports.RemoveMillionToken = exports.MillionToken = exports.UnwrappedToken = exports.WrappedToken = void 0;
|
|
4
|
+
exports.WrappedToken = {
|
|
5
|
+
ETH: "WETH",
|
|
6
|
+
BTC: "WBTC",
|
|
7
|
+
SOL: "WSOL",
|
|
8
|
+
};
|
|
9
|
+
exports.UnwrappedToken = {
|
|
10
|
+
WETH: "ETH",
|
|
11
|
+
WBTC: "BTC",
|
|
12
|
+
WSOL: "SOL",
|
|
13
|
+
};
|
|
14
|
+
exports.MillionToken = {
|
|
15
|
+
FUD: "MFUD",
|
|
16
|
+
};
|
|
17
|
+
exports.RemoveMillionToken = {
|
|
18
|
+
MFUD: "FUD",
|
|
19
|
+
};
|
|
20
|
+
exports.LST = {
|
|
21
|
+
AFSUI: "SUI",
|
|
22
|
+
};
|
|
23
|
+
exports.StableCoin = ["USDC", "USDT", "BUCK", "USDY"];
|
|
24
|
+
var getTokenName = function (_a) {
|
|
25
|
+
var _b, _c, _d, _e;
|
|
26
|
+
var token = _a.token, wrapped = _a.wrapped, million = _a.million;
|
|
27
|
+
var tokenName = token;
|
|
28
|
+
if (wrapped) {
|
|
29
|
+
tokenName = (_b = exports.WrappedToken[token]) !== null && _b !== void 0 ? _b : token;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
tokenName = (_c = exports.UnwrappedToken[token]) !== null && _c !== void 0 ? _c : token;
|
|
33
|
+
}
|
|
34
|
+
return million ? (_d = exports.MillionToken[tokenName]) !== null && _d !== void 0 ? _d : tokenName : (_e = exports.RemoveMillionToken[tokenName]) !== null && _e !== void 0 ? _e : tokenName;
|
|
35
|
+
};
|
|
36
|
+
exports.getTokenName = getTokenName;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAssets = exports.AbbrStrategyName = exports.Period = void 0;
|
|
4
|
+
var token_1 = require("../../token");
|
|
5
|
+
exports.Period = {
|
|
6
|
+
0: "daily",
|
|
7
|
+
1: "weekly",
|
|
8
|
+
2: "monthly",
|
|
9
|
+
3: "hourly",
|
|
10
|
+
};
|
|
11
|
+
exports.AbbrStrategyName = {
|
|
12
|
+
0: "Call",
|
|
13
|
+
1: "Put",
|
|
14
|
+
2: "Call Spread",
|
|
15
|
+
4: "Capped Call",
|
|
16
|
+
5: "Capped Put",
|
|
17
|
+
6: "Capped Call",
|
|
18
|
+
};
|
|
19
|
+
var parseAssets = function (info) {
|
|
20
|
+
var dToken = info.depositToken, bToken = info.bidToken, oToken = info.settlementBase;
|
|
21
|
+
return (0, token_1.typeArgsToAssets)([dToken, bToken, oToken]);
|
|
22
|
+
};
|
|
23
|
+
exports.parseAssets = parseAssets;
|
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": "1.2.
|
|
5
|
+
"version": "1.2.79",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@mysten/bcs": "^0.11.1",
|
|
8
8
|
"@mysten/kiosk": "0.7.12",
|
|
@@ -33,12 +33,13 @@
|
|
|
33
33
|
"js-tokens": "^8.0.1",
|
|
34
34
|
"js-yaml": "^4.1.0",
|
|
35
35
|
"json2csv": "^6.0.0-alpha.2",
|
|
36
|
+
"lodash": "^4.17.21",
|
|
36
37
|
"math-erf": "^1.0.0",
|
|
37
38
|
"minimatch": "^9.0.3",
|
|
38
39
|
"minimist": "^1.2.5",
|
|
39
40
|
"mkdirp": "^3.0.1",
|
|
40
41
|
"mocha": "^10.1.0",
|
|
41
|
-
"moment": "^2.
|
|
42
|
+
"moment": "^2.30.1",
|
|
42
43
|
"node-cron": "^3.0.2",
|
|
43
44
|
"once": "^1.4.0",
|
|
44
45
|
"path-is-absolute": "^2.0.0",
|