@typus/typus-sdk 1.4.9 → 1.4.11
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/dist/config.json +13 -9
- package/dist/src/dice/fetch.d.ts +0 -1
- package/dist/src/dice/fetch.js +3 -78
- package/dist/src/{leaderboard → typus/leaderboard}/view-function.js +2 -2
- package/dist/src/{tails-staking → typus/tails-staking}/user-entry.js +1 -1
- package/dist/src/{tails-staking → typus/tails-staking}/view-function.js +2 -2
- package/dist/src/typus-dov-single-v2/{entry/authority-entry.js → authority-entry.js} +1 -1
- package/dist/src/typus-dov-single-v2/function/bidding.d.ts +2 -2
- package/dist/src/typus-dov-single-v2/function/bidding.js +21 -23
- package/dist/src/typus-dov-single-v2/function/vault.js +2 -2
- package/dist/src/typus-dov-single-v2/history/user-history.js +43 -43
- package/dist/src/typus-dov-single-v2/history/vault-history.js +11 -11
- package/dist/src/typus-dov-single-v2/index.d.ts +3 -1
- package/dist/src/typus-dov-single-v2/index.js +3 -1
- package/dist/src/typus-dov-single-v2/{entry/mfud-user-entry.js → token-user-entry.js} +1 -1
- package/dist/src/typus-dov-single-v2/{entry/user-entry.js → user-entry.js} +1 -1
- package/dist/src/typus-dov-single-v2/view-function.js +8 -8
- package/dist/src/typus-nft/fetch.d.ts +1 -0
- package/dist/src/typus-nft/fetch.js +66 -0
- package/dist/src/typus-perp/fetch.d.ts +10 -10
- package/dist/src/typus-perp/fetch.js +20 -21
- package/dist/src/typus-perp/readVec.js +6 -6
- package/dist/src/typus-perp/user/order.d.ts +10 -10
- package/dist/src/typus-perp/user/order.js +31 -32
- package/dist/src/typus-perp/user/orderWithBidReceipt.d.ts +6 -6
- package/dist/src/typus-perp/user/orderWithBidReceipt.js +15 -17
- package/dist/src/typus-perp/user/tlp.d.ts +12 -13
- package/dist/src/typus-perp/user/tlp.js +38 -41
- package/dist/src/typus-safu/index.d.ts +3 -0
- package/dist/src/typus-safu/index.js +20 -0
- package/dist/src/typus-safu/user-entry.d.ts +84 -0
- package/dist/src/typus-safu/user-entry.js +158 -0
- package/dist/src/typus-safu/view-function.d.ts +31 -0
- package/dist/src/typus-safu/view-function.js +147 -0
- package/dist/src/utils/api/sentio/reward-generated.js +3 -3
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/pyth/constant.js +1 -1
- package/dist/src/utils/pyth/pythClient.d.ts +1 -1
- package/dist/src/utils/pyth/pythClient.js +1 -1
- package/dist/src/utils/typusConfig.d.ts +93 -0
- package/dist/src/utils/typusConfig.js +21 -0
- package/package.json +4 -1
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.js +0 -27
- package/dist/src/typus-dov-single-v2/entry/index.d.ts +0 -3
- package/dist/src/typus-dov-single-v2/entry/index.js +0 -19
- /package/dist/src/{airdrop → typus/airdrop}/authority-entry.d.ts +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/authority-entry.js +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/index.d.ts +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/index.js +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/user-entry.d.ts +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/user-entry.js +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/view-function.d.ts +0 -0
- /package/dist/src/{airdrop → typus/airdrop}/view-function.js +0 -0
- /package/dist/src/{leaderboard → typus/leaderboard}/authority-entry.d.ts +0 -0
- /package/dist/src/{leaderboard → typus/leaderboard}/authority-entry.js +0 -0
- /package/dist/src/{leaderboard → typus/leaderboard}/index.d.ts +0 -0
- /package/dist/src/{leaderboard → typus/leaderboard}/index.js +0 -0
- /package/dist/src/{leaderboard → typus/leaderboard}/view-function.d.ts +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/authority-entry.d.ts +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/authority-entry.js +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/index.d.ts +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/index.js +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/user-entry.d.ts +0 -0
- /package/dist/src/{tails-staking → typus/tails-staking}/view-function.d.ts +0 -0
- /package/dist/src/{user → typus/user}/index.d.ts +0 -0
- /package/dist/src/{user → typus/user}/index.js +0 -0
- /package/dist/src/{user → typus/user}/view-function.d.ts +0 -0
- /package/dist/src/{user → typus/user}/view-function.js +0 -0
- /package/dist/src/typus-dov-single-v2/{entry/authority-entry.d.ts → authority-entry.d.ts} +0 -0
- /package/dist/src/typus-dov-single-v2/{entry/mfud-user-entry.d.ts → token-user-entry.d.ts} +0 -0
- /package/dist/src/typus-dov-single-v2/{entry/user-entry.d.ts → user-entry.d.ts} +0 -0
|
@@ -53,7 +53,7 @@ exports.parseVaultHistory = parseVaultHistory;
|
|
|
53
53
|
exports.getVaultHistoryFromDB = getVaultHistoryFromDB;
|
|
54
54
|
exports.convertGroupEventToVaultHistory = convertGroupEventToVaultHistory;
|
|
55
55
|
exports.parseBidEvents = parseBidEvents;
|
|
56
|
-
var
|
|
56
|
+
var constants_1 = require("../../constants");
|
|
57
57
|
function getVaultHistoryEvents(provider, originPackage, startTimeMs) {
|
|
58
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
59
|
var senderFilter, result, datas, hasNextPage, cursor, result;
|
|
@@ -307,14 +307,14 @@ function convertGroupEventToVaultHistory(groupEvent) {
|
|
|
307
307
|
ActivationMs = Number((_a = groupEvent.activateEvent) === null || _a === void 0 ? void 0 : _a.timestampMs);
|
|
308
308
|
SettlementTsMs = Number((_b = groupEvent.settleEvent) === null || _b === void 0 ? void 0 : _b.timestampMs);
|
|
309
309
|
if (groupEvent.deliveryEvent) {
|
|
310
|
-
b_token = (0,
|
|
311
|
-
o_token = (0,
|
|
312
|
-
bidder_bid_value = Number(groupEvent.deliveryEvent.bidder_bid_value) / Math.pow(10, (0,
|
|
313
|
-
bidder_fee = Number(groupEvent.deliveryEvent.bidder_fee) / Math.pow(10, (0,
|
|
314
|
-
delivery_price = Number(groupEvent.deliveryEvent.delivery_price) / Math.pow(10, (0,
|
|
315
|
-
delivery_size = Number(groupEvent.deliveryEvent.delivery_size) / Math.pow(10, (0,
|
|
316
|
-
incentive_bid_value = Number(groupEvent.deliveryEvent.incentive_bid_value) / Math.pow(10, (0,
|
|
317
|
-
incentive_fee = Number(groupEvent.deliveryEvent.incentive_fee) / Math.pow(10, (0,
|
|
310
|
+
b_token = (0, constants_1.typeArgToAsset)(groupEvent.deliveryEvent.b_token.name);
|
|
311
|
+
o_token = (0, constants_1.typeArgToAsset)(groupEvent.deliveryEvent.o_token.name);
|
|
312
|
+
bidder_bid_value = Number(groupEvent.deliveryEvent.bidder_bid_value) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
|
|
313
|
+
bidder_fee = Number(groupEvent.deliveryEvent.bidder_fee) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
|
|
314
|
+
delivery_price = Number(groupEvent.deliveryEvent.delivery_price) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
|
|
315
|
+
delivery_size = Number(groupEvent.deliveryEvent.delivery_size) / Math.pow(10, (0, constants_1.assetToDecimal)(o_token));
|
|
316
|
+
incentive_bid_value = Number(groupEvent.deliveryEvent.incentive_bid_value) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
|
|
317
|
+
incentive_fee = Number(groupEvent.deliveryEvent.incentive_fee) / Math.pow(10, (0, constants_1.assetToDecimal)(b_token));
|
|
318
318
|
PaidToDepositors = bidder_bid_value + bidder_fee + incentive_bid_value + incentive_fee;
|
|
319
319
|
PaidToBidders = (Number((_c = groupEvent.settleEvent) === null || _c === void 0 ? void 0 : _c.settle_balance) - Number((_d = groupEvent.settleEvent) === null || _d === void 0 ? void 0 : _d.settled_balance)) /
|
|
320
320
|
Math.pow(10, Number((_e = groupEvent.settleEvent) === null || _e === void 0 ? void 0 : _e.d_token_decimal));
|
|
@@ -375,8 +375,8 @@ function parseBidEvents(datas, end_ts_ms) {
|
|
|
375
375
|
parsedJson.txDigest = event.id.txDigest;
|
|
376
376
|
index = parsedJson.index.toString();
|
|
377
377
|
bid_event = parsedJson;
|
|
378
|
-
o_token = (0,
|
|
379
|
-
size = Number(parsedJson.size) / Math.pow(10, (0,
|
|
378
|
+
o_token = (0, constants_1.typeArgToAsset)("0x" + parsedJson.o_token.name);
|
|
379
|
+
size = Number(parsedJson.size) / Math.pow(10, (0, constants_1.assetToDecimal)(o_token));
|
|
380
380
|
bid_event.size = size.toString();
|
|
381
381
|
if (Number(bid_event.ts_ms) > end_ts_ms) {
|
|
382
382
|
return [2 /*return*/, map];
|
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./entry"), exports);
|
|
17
|
+
__exportStar(require("./authority-entry"), exports);
|
|
18
18
|
__exportStar(require("./function"), exports);
|
|
19
19
|
__exportStar(require("./history"), exports);
|
|
20
|
+
__exportStar(require("./token-user-entry"), exports);
|
|
21
|
+
__exportStar(require("./user-entry"), exports);
|
|
20
22
|
__exportStar(require("./view-function"), exports);
|
|
@@ -28,7 +28,7 @@ exports.getMfudCloseStrategyTx = getMfudCloseStrategyTx;
|
|
|
28
28
|
exports.getMfudWithdrawProfitStrategyTx = getMfudWithdrawProfitStrategyTx;
|
|
29
29
|
exports.getMfudCompoundWithRedeemTx = getMfudCompoundWithRedeemTx;
|
|
30
30
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
31
|
-
var constants_1 = require("
|
|
31
|
+
var constants_1 = require("../constants");
|
|
32
32
|
function getMfudRaiseFundTx(input) {
|
|
33
33
|
var typusTokenBalance = input.raiseCoins.length > 0
|
|
34
34
|
? input.tx.moveCall({
|
|
@@ -27,7 +27,7 @@ exports.getMultiTransferBidReceiptTx = getMultiTransferBidReceiptTx;
|
|
|
27
27
|
exports.getRebateTx = getRebateTx;
|
|
28
28
|
exports.getCompoundWithRedeemTx = getCompoundWithRedeemTx;
|
|
29
29
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
30
|
-
var constants_1 = require("
|
|
30
|
+
var constants_1 = require("../constants");
|
|
31
31
|
/**
|
|
32
32
|
public fun public_raise_fund<D_TOKEN, B_TOKEN>(
|
|
33
33
|
typus_ecosystem_version: &TypusEcosystemVersion,
|
|
@@ -60,7 +60,7 @@ exports.getMyBids = getMyBids;
|
|
|
60
60
|
exports.getRefundShares = getRefundShares;
|
|
61
61
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
62
62
|
var bcs_1 = require("@mysten/bcs");
|
|
63
|
-
var
|
|
63
|
+
var utils_1 = require("../utils");
|
|
64
64
|
var SENDER = "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
|
65
65
|
function getVaults(provider_1, packageId_1, registry_1, indexes_1) {
|
|
66
66
|
return __awaiter(this, arguments, void 0, function (provider, packageId, registry, indexes, sender) {
|
|
@@ -85,7 +85,7 @@ function getVaults(provider_1, packageId_1, registry_1, indexes_1) {
|
|
|
85
85
|
result = {};
|
|
86
86
|
reader.readVec(function (reader) {
|
|
87
87
|
reader.read16();
|
|
88
|
-
var id = (0,
|
|
88
|
+
var id = (0, utils_1.AddressFromBytes)(reader.readBytes(32));
|
|
89
89
|
var info = {
|
|
90
90
|
index: reader.read64(),
|
|
91
91
|
optionType: reader.read64(),
|
|
@@ -101,7 +101,7 @@ function getVaults(provider_1, packageId_1, registry_1, indexes_1) {
|
|
|
101
101
|
dTokenDecimal: reader.read64(),
|
|
102
102
|
bTokenDecimal: reader.read64(),
|
|
103
103
|
oTokenDecimal: reader.read64(),
|
|
104
|
-
creator: (0,
|
|
104
|
+
creator: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
105
105
|
createTsMs: reader.read64(),
|
|
106
106
|
round: reader.read64(),
|
|
107
107
|
status: reader.read64(),
|
|
@@ -161,7 +161,7 @@ function getVaults(provider_1, packageId_1, registry_1, indexes_1) {
|
|
|
161
161
|
}),
|
|
162
162
|
};
|
|
163
163
|
var config = {
|
|
164
|
-
oracleId: (0,
|
|
164
|
+
oracleId: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
165
165
|
depositLotSize: reader.read64(),
|
|
166
166
|
bidLotSize: reader.read64(),
|
|
167
167
|
minDepositSize: reader.read64(),
|
|
@@ -250,7 +250,7 @@ function getVaults(provider_1, packageId_1, registry_1, indexes_1) {
|
|
|
250
250
|
return reader.readBytes(32);
|
|
251
251
|
}); // tail
|
|
252
252
|
var depositVault = {
|
|
253
|
-
id: (0,
|
|
253
|
+
id: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
254
254
|
depositToken: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))),
|
|
255
255
|
bidToken: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))),
|
|
256
256
|
incentiveToken: reader
|
|
@@ -316,7 +316,7 @@ function getAuctions(provider_1, packageId_1, registry_1, indexes_1) {
|
|
|
316
316
|
result = {};
|
|
317
317
|
reader.readVec(function (reader) {
|
|
318
318
|
reader.read16();
|
|
319
|
-
var id = (0,
|
|
319
|
+
var id = (0, utils_1.AddressFromBytes)(reader.readBytes(32));
|
|
320
320
|
var index = reader.read64();
|
|
321
321
|
var token = String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8())));
|
|
322
322
|
var startTsMs = reader.read64();
|
|
@@ -385,7 +385,7 @@ function getAuctionBids(provider_1, packageId_1, registry_1, index_1) {
|
|
|
385
385
|
reader.read8();
|
|
386
386
|
var bid = {
|
|
387
387
|
tsMs: reader.read64(),
|
|
388
|
-
bidder: (0,
|
|
388
|
+
bidder: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
389
389
|
price: reader.read64(),
|
|
390
390
|
size: reader.read64(),
|
|
391
391
|
bidderBalance: reader.read64(),
|
|
@@ -505,7 +505,7 @@ function getMyBids(provider_1, typusFrameworkPackageId_1, packageId_1, registry_
|
|
|
505
505
|
reader.readVec(function (reader, i) {
|
|
506
506
|
reader.read16();
|
|
507
507
|
var bidVault = {
|
|
508
|
-
id: (0,
|
|
508
|
+
id: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
509
509
|
depositToken: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))),
|
|
510
510
|
bidToken: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))),
|
|
511
511
|
incentiveToken: reader
|
|
@@ -67,3 +67,4 @@ export interface DiscountPoolData {
|
|
|
67
67
|
inventory: number;
|
|
68
68
|
}
|
|
69
69
|
export declare function getMintHistory(provider: SuiClient, NFT_PACKAGE: string, vrf_input: any): Promise<import("@mysten/sui.js/client").PaginatedEvents | undefined>;
|
|
70
|
+
export declare function calculateLevelReward(totalRewards: number, levelShares: number[], numOfHolders: number[]): number[];
|
|
@@ -73,6 +73,7 @@ exports.getLevelExp = getLevelExp;
|
|
|
73
73
|
exports.getTableTails = getTableTails;
|
|
74
74
|
exports.getDiscountPool = getDiscountPool;
|
|
75
75
|
exports.getMintHistory = getMintHistory;
|
|
76
|
+
exports.calculateLevelReward = calculateLevelReward;
|
|
76
77
|
function getPool(provider, pool) {
|
|
77
78
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
79
|
var res, fields, poolData;
|
|
@@ -320,6 +321,7 @@ function getTailsDynamicField(provider, tailsIds) {
|
|
|
320
321
|
case 2:
|
|
321
322
|
results = _e.sent();
|
|
322
323
|
try {
|
|
324
|
+
// console.log(results);
|
|
323
325
|
for (results_2 = (e_4 = void 0, __values(results)), results_2_1 = results_2.next(); !results_2_1.done; results_2_1 = results_2.next()) {
|
|
324
326
|
result = results_2_1.value;
|
|
325
327
|
owner = (_b = result.data) === null || _b === void 0 ? void 0 : _b.owner.ObjectOwner;
|
|
@@ -563,3 +565,67 @@ function getMintHistory(provider, NFT_PACKAGE, vrf_input) {
|
|
|
563
565
|
});
|
|
564
566
|
});
|
|
565
567
|
}
|
|
568
|
+
function calculateLevelReward(totalRewards, levelShares, numOfHolders) {
|
|
569
|
+
// Step 1: Calculate original level rewards (per holder)
|
|
570
|
+
var totalShares = levelShares.reduce(function (acc, share) { return acc + share; }, 0);
|
|
571
|
+
var originalRewardPerHolder = levelShares.map(function (levelShare, index) {
|
|
572
|
+
var num = numOfHolders[index];
|
|
573
|
+
var levelRewardPerHolder = num > 0 ? (totalRewards * levelShare) / totalShares / num : 0;
|
|
574
|
+
return Math.floor(levelRewardPerHolder);
|
|
575
|
+
});
|
|
576
|
+
var originalLevelRewards = originalRewardPerHolder.map(function (reward, index) { return reward * numOfHolders[index]; });
|
|
577
|
+
var distributedRewards = originalLevelRewards.reduce(function (acc, reward) { return acc + reward; }, 0);
|
|
578
|
+
var emptyLevelRewards = totalRewards - distributedRewards;
|
|
579
|
+
// Step 2: Distribute rewards from empty levels
|
|
580
|
+
var reversedOriginalRewardPerHolder = originalRewardPerHolder.slice().reverse();
|
|
581
|
+
var reversedNumOfHolders = numOfHolders.slice().reverse();
|
|
582
|
+
var reversedScaledRewardPerHolder = [];
|
|
583
|
+
if (emptyLevelRewards > 0) {
|
|
584
|
+
var undistributedRewards_1 = emptyLevelRewards;
|
|
585
|
+
var uncalculatedDistributedRewards_1 = distributedRewards;
|
|
586
|
+
reversedScaledRewardPerHolder = reversedOriginalRewardPerHolder.map(function (rewardPerHolder, index) {
|
|
587
|
+
var num = reversedNumOfHolders[index];
|
|
588
|
+
var scaledRewardPerHolder = num > 0
|
|
589
|
+
? uncalculatedDistributedRewards_1 > 0
|
|
590
|
+
? (rewardPerHolder * (uncalculatedDistributedRewards_1 + undistributedRewards_1)) / uncalculatedDistributedRewards_1
|
|
591
|
+
: rewardPerHolder
|
|
592
|
+
: 0;
|
|
593
|
+
undistributedRewards_1 -= (scaledRewardPerHolder - rewardPerHolder) * num;
|
|
594
|
+
uncalculatedDistributedRewards_1 -= rewardPerHolder * num;
|
|
595
|
+
return Math.floor(scaledRewardPerHolder);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
reversedScaledRewardPerHolder = reversedOriginalRewardPerHolder.slice();
|
|
600
|
+
}
|
|
601
|
+
// Step 3: Capped level reward
|
|
602
|
+
var reversedCappedRewardPerHolder = [reversedOriginalRewardPerHolder[0]];
|
|
603
|
+
var tempHighLevelReward = 0;
|
|
604
|
+
reversedScaledRewardPerHolder.forEach(function (highLevelReward, index) {
|
|
605
|
+
var lowLevelReward = reversedScaledRewardPerHolder[index + 1] || 0;
|
|
606
|
+
tempHighLevelReward =
|
|
607
|
+
highLevelReward > 0
|
|
608
|
+
? tempHighLevelReward > 0
|
|
609
|
+
? Math.min(highLevelReward, tempHighLevelReward)
|
|
610
|
+
: highLevelReward
|
|
611
|
+
: tempHighLevelReward;
|
|
612
|
+
reversedCappedRewardPerHolder.push(tempHighLevelReward > 0 ? Math.min(lowLevelReward, tempHighLevelReward) : lowLevelReward);
|
|
613
|
+
});
|
|
614
|
+
reversedCappedRewardPerHolder.pop();
|
|
615
|
+
var cappedRewardPerHolder = reversedCappedRewardPerHolder.slice().reverse();
|
|
616
|
+
// Step 4: Distribute capped reward from Step 3 into each level
|
|
617
|
+
var distributedRewardsStep4 = reversedCappedRewardPerHolder.reduce(function (acc, reward, index) { return acc + reward * reversedNumOfHolders[index]; }, 0);
|
|
618
|
+
var undistributedRewardsStep4 = totalRewards - distributedRewardsStep4;
|
|
619
|
+
var uncalculatedDistributedRewardsStep4 = distributedRewardsStep4;
|
|
620
|
+
var levelReward = cappedRewardPerHolder.map(function (rewardPerHolder, index) {
|
|
621
|
+
var num = reversedNumOfHolders[index];
|
|
622
|
+
var scaledRewardPerHolder = uncalculatedDistributedRewardsStep4 > 0
|
|
623
|
+
? (rewardPerHolder * (uncalculatedDistributedRewardsStep4 + undistributedRewardsStep4)) /
|
|
624
|
+
uncalculatedDistributedRewardsStep4
|
|
625
|
+
: rewardPerHolder;
|
|
626
|
+
undistributedRewardsStep4 -= (scaledRewardPerHolder - rewardPerHolder) * num;
|
|
627
|
+
uncalculatedDistributedRewardsStep4 -= rewardPerHolder * num;
|
|
628
|
+
return Math.floor(scaledRewardPerHolder);
|
|
629
|
+
});
|
|
630
|
+
return levelReward;
|
|
631
|
+
}
|
|
@@ -3,21 +3,21 @@ import { LiquidityPool } from "./lp-pool/structs";
|
|
|
3
3
|
import { Markets, SymbolMarket } from "./trading/structs";
|
|
4
4
|
import { TradingOrder, Position } from "./position/structs";
|
|
5
5
|
import { LpUserShare, StakePool } from "./stake-pool/structs";
|
|
6
|
-
import { PythClient } from "../utils
|
|
6
|
+
import { PythClient } from "../utils";
|
|
7
7
|
export declare function getLpPools(provider: SuiClient, config: {
|
|
8
8
|
REGISTRY: {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
LP_POOL: string;
|
|
10
|
+
LIQUIDITY_POOL: string;
|
|
11
11
|
};
|
|
12
12
|
}): Promise<LiquidityPool[]>;
|
|
13
13
|
export declare function getStakePools(provider: SuiClient, config: {
|
|
14
14
|
REGISTRY: {
|
|
15
|
-
|
|
15
|
+
STAKE_POOL: string;
|
|
16
16
|
};
|
|
17
17
|
}): Promise<StakePool[]>;
|
|
18
18
|
export declare function getMarkets(provider: SuiClient, config: {
|
|
19
19
|
REGISTRY: {
|
|
20
|
-
|
|
20
|
+
MARKET: string;
|
|
21
21
|
};
|
|
22
22
|
}): Promise<Markets[]>;
|
|
23
23
|
export declare function getSymbolMarkets(provider: SuiClient, market: Markets): Promise<Map<string, SymbolMarket>>;
|
|
@@ -26,7 +26,7 @@ export declare function getUserOrders(provider: SuiClient, config: {
|
|
|
26
26
|
TYPUS_PERP_VERSION: string;
|
|
27
27
|
};
|
|
28
28
|
REGISTRY: {
|
|
29
|
-
|
|
29
|
+
MARKET: string;
|
|
30
30
|
};
|
|
31
31
|
}, user: string): Promise<TradingOrder[]>;
|
|
32
32
|
export declare function getUserPositions(provider: SuiClient, config: {
|
|
@@ -34,12 +34,12 @@ export declare function getUserPositions(provider: SuiClient, config: {
|
|
|
34
34
|
TYPUS_PERP_VERSION: string;
|
|
35
35
|
};
|
|
36
36
|
REGISTRY: {
|
|
37
|
-
|
|
37
|
+
MARKET: string;
|
|
38
38
|
};
|
|
39
39
|
}, user: string): Promise<Position[]>;
|
|
40
40
|
export declare function getUserStake(provider: SuiClient, config: {
|
|
41
41
|
REGISTRY: {
|
|
42
|
-
|
|
42
|
+
STAKE_POOL: string;
|
|
43
43
|
};
|
|
44
44
|
}, user: string): Promise<LpUserShare[]>;
|
|
45
45
|
export declare function getLiquidationPrice(provider: SuiClient, config: {
|
|
@@ -47,8 +47,8 @@ export declare function getLiquidationPrice(provider: SuiClient, config: {
|
|
|
47
47
|
TYPUS_PERP_VERSION: string;
|
|
48
48
|
};
|
|
49
49
|
REGISTRY: {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
LP_POOL: string;
|
|
51
|
+
MARKET: string;
|
|
52
52
|
};
|
|
53
53
|
}, input: {
|
|
54
54
|
pythClient: PythClient;
|
|
@@ -63,10 +63,9 @@ var readVec_1 = require("./readVec");
|
|
|
63
63
|
var functions_2 = require("./stake-pool/functions");
|
|
64
64
|
var structs_3 = require("./stake-pool/structs");
|
|
65
65
|
var constants_1 = require("../constants");
|
|
66
|
-
var
|
|
67
|
-
var
|
|
66
|
+
var constants_2 = require("../constants");
|
|
67
|
+
var utils_1 = require("../utils");
|
|
68
68
|
var _1 = require(".");
|
|
69
|
-
var pythClient_1 = require("../utils/pyth/pythClient");
|
|
70
69
|
var bcs_1 = require("@mysten/bcs");
|
|
71
70
|
function getLpPools(provider, config) {
|
|
72
71
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -75,7 +74,7 @@ function getLpPools(provider, config) {
|
|
|
75
74
|
return __generator(this, function (_d) {
|
|
76
75
|
switch (_d.label) {
|
|
77
76
|
case 0: return [4 /*yield*/, provider.getDynamicFields({
|
|
78
|
-
parentId: config.REGISTRY.
|
|
77
|
+
parentId: config.REGISTRY.LIQUIDITY_POOL,
|
|
79
78
|
})];
|
|
80
79
|
case 1:
|
|
81
80
|
dynamicFields = _d.sent();
|
|
@@ -120,7 +119,7 @@ function getStakePools(provider, config) {
|
|
|
120
119
|
return __generator(this, function (_d) {
|
|
121
120
|
switch (_d.label) {
|
|
122
121
|
case 0: return [4 /*yield*/, provider.getDynamicFields({
|
|
123
|
-
parentId: config.REGISTRY.
|
|
122
|
+
parentId: config.REGISTRY.STAKE_POOL,
|
|
124
123
|
})];
|
|
125
124
|
case 1:
|
|
126
125
|
dynamicFields = _d.sent();
|
|
@@ -165,7 +164,7 @@ function getMarkets(provider, config) {
|
|
|
165
164
|
return __generator(this, function (_d) {
|
|
166
165
|
switch (_d.label) {
|
|
167
166
|
case 0: return [4 /*yield*/, provider.getDynamicFields({
|
|
168
|
-
parentId: config.REGISTRY.
|
|
167
|
+
parentId: config.REGISTRY.MARKET,
|
|
169
168
|
})];
|
|
170
169
|
case 1:
|
|
171
170
|
dynamicFields = _d.sent();
|
|
@@ -260,7 +259,7 @@ function getUserOrders(provider, config, user) {
|
|
|
260
259
|
tx = new transactions_1.TransactionBlock();
|
|
261
260
|
(0, functions_1.getUserOrders)(tx, {
|
|
262
261
|
version: config.OBJECT.TYPUS_PERP_VERSION,
|
|
263
|
-
registry: config.REGISTRY.
|
|
262
|
+
registry: config.REGISTRY.MARKET,
|
|
264
263
|
marketIndex: BigInt(0),
|
|
265
264
|
user: user,
|
|
266
265
|
});
|
|
@@ -284,7 +283,7 @@ function getUserPositions(provider, config, user) {
|
|
|
284
283
|
tx = new transactions_1.TransactionBlock();
|
|
285
284
|
(0, functions_1.getUserPositions)(tx, {
|
|
286
285
|
version: config.OBJECT.TYPUS_PERP_VERSION,
|
|
287
|
-
registry: config.REGISTRY.
|
|
286
|
+
registry: config.REGISTRY.MARKET,
|
|
288
287
|
marketIndex: BigInt(0),
|
|
289
288
|
user: user,
|
|
290
289
|
});
|
|
@@ -307,7 +306,7 @@ function getUserStake(provider, config, user) {
|
|
|
307
306
|
case 0:
|
|
308
307
|
tx = new transactions_1.TransactionBlock();
|
|
309
308
|
(0, functions_2.getUserShares)(tx, {
|
|
310
|
-
registry: config.REGISTRY.
|
|
309
|
+
registry: config.REGISTRY.STAKE_POOL,
|
|
311
310
|
index: BigInt(0),
|
|
312
311
|
user: user,
|
|
313
312
|
});
|
|
@@ -344,8 +343,8 @@ function getLiquidationPrice(provider, config, input) {
|
|
|
344
343
|
try {
|
|
345
344
|
for (_a = __values(input.positions), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
346
345
|
position = _b.value;
|
|
347
|
-
TOKEN = (0,
|
|
348
|
-
BASE_TOKEN = (0,
|
|
346
|
+
TOKEN = (0, constants_2.typeArgToToken)(position.collateralToken.name);
|
|
347
|
+
BASE_TOKEN = (0, constants_2.typeArgToToken)(position.symbol.baseToken.name);
|
|
349
348
|
pythTokens.push(TOKEN);
|
|
350
349
|
pythTokens.push(BASE_TOKEN);
|
|
351
350
|
}
|
|
@@ -357,25 +356,25 @@ function getLiquidationPrice(provider, config, input) {
|
|
|
357
356
|
}
|
|
358
357
|
finally { if (e_5) throw e_5.error; }
|
|
359
358
|
}
|
|
360
|
-
return [4 /*yield*/, (0,
|
|
359
|
+
return [4 /*yield*/, (0, utils_1.updatePyth)(input.pythClient, tx, Array.from(new Set(pythTokens)))];
|
|
361
360
|
case 1:
|
|
362
361
|
_h.sent();
|
|
363
362
|
try {
|
|
364
363
|
for (_c = __values(input.positions), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
365
364
|
position = _d.value;
|
|
366
|
-
TOKEN = (0,
|
|
367
|
-
BASE_TOKEN = (0,
|
|
368
|
-
cToken =
|
|
369
|
-
baseToken =
|
|
365
|
+
TOKEN = (0, constants_2.typeArgToToken)(position.collateralToken.name);
|
|
366
|
+
BASE_TOKEN = (0, constants_2.typeArgToToken)(position.symbol.baseToken.name);
|
|
367
|
+
cToken = constants_2.tokenType[_1.NETWORK][TOKEN];
|
|
368
|
+
baseToken = constants_2.tokenType[_1.NETWORK][BASE_TOKEN];
|
|
370
369
|
(0, functions_1.getEstimatedLiquidationPrice)(tx, [cToken, baseToken], {
|
|
371
370
|
version: config.OBJECT.TYPUS_PERP_VERSION,
|
|
372
|
-
registry: config.REGISTRY.
|
|
373
|
-
poolRegistry: config.REGISTRY.
|
|
371
|
+
registry: config.REGISTRY.MARKET,
|
|
372
|
+
poolRegistry: config.REGISTRY.LP_POOL,
|
|
374
373
|
marketIndex: BigInt(0),
|
|
375
374
|
poolIndex: BigInt(0),
|
|
376
|
-
pythState:
|
|
377
|
-
oracleCToken:
|
|
378
|
-
oracleTradingSymbol:
|
|
375
|
+
pythState: utils_1.pythStateId[_1.NETWORK],
|
|
376
|
+
oracleCToken: utils_1.priceInfoObjectIds[_1.NETWORK][TOKEN],
|
|
377
|
+
oracleTradingSymbol: utils_1.priceInfoObjectIds[_1.NETWORK][BASE_TOKEN],
|
|
379
378
|
clock: constants_1.CLOCK,
|
|
380
379
|
positionId: position.positionId,
|
|
381
380
|
});
|
|
@@ -4,19 +4,19 @@ exports.readVecPosition = readVecPosition;
|
|
|
4
4
|
exports.readVecOrder = readVecOrder;
|
|
5
5
|
exports.readVecShares = readVecShares;
|
|
6
6
|
var bcs_1 = require("@mysten/bcs");
|
|
7
|
-
var
|
|
7
|
+
var utils_1 = require("../utils");
|
|
8
8
|
// import { Position, TradingOrder } from "./position/structs";
|
|
9
9
|
function readVecPosition(bytes) {
|
|
10
10
|
var reader = new bcs_1.BcsReader(bytes);
|
|
11
11
|
return reader.readVec(function (reader) {
|
|
12
12
|
reader.read16();
|
|
13
13
|
var position = {
|
|
14
|
-
id: (0,
|
|
14
|
+
id: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
15
15
|
createTsMs: reader.read64(),
|
|
16
16
|
positionId: reader.read64(),
|
|
17
17
|
linkedOrderIds: reader.readVec(function (reader) { return reader.read64(); }),
|
|
18
18
|
linkedOrderPrices: reader.readVec(function (reader) { return reader.read64(); }),
|
|
19
|
-
user: (0,
|
|
19
|
+
user: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
20
20
|
isLong: reader.read8(),
|
|
21
21
|
size: reader.read64(),
|
|
22
22
|
sizeDecimal: reader.read64(),
|
|
@@ -55,7 +55,7 @@ function readVecOrder(bytes) {
|
|
|
55
55
|
return reader.readVec(function (reader) {
|
|
56
56
|
reader.read16();
|
|
57
57
|
var order = {
|
|
58
|
-
id: (0,
|
|
58
|
+
id: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
59
59
|
createTsMs: reader.read64(),
|
|
60
60
|
orderId: reader.read64(),
|
|
61
61
|
linkedPositionId: reader
|
|
@@ -63,7 +63,7 @@ function readVecOrder(bytes) {
|
|
|
63
63
|
return reader.read64();
|
|
64
64
|
})
|
|
65
65
|
.at(0),
|
|
66
|
-
user: (0,
|
|
66
|
+
user: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
67
67
|
collateralToken: { name: String.fromCharCode.apply(null, Array.from(reader.readBytes(reader.read8()))) },
|
|
68
68
|
collateralTokenDecimal: reader.read64(),
|
|
69
69
|
symbol: {
|
|
@@ -88,7 +88,7 @@ function readVecShares(bytes) {
|
|
|
88
88
|
return reader.readVec(function (reader) {
|
|
89
89
|
reader.read16();
|
|
90
90
|
var share = {
|
|
91
|
-
user: (0,
|
|
91
|
+
user: (0, utils_1.AddressFromBytes)(reader.readBytes(32)),
|
|
92
92
|
userShareId: reader.read64(),
|
|
93
93
|
stakeTsMs: reader.read64(),
|
|
94
94
|
totalShares: reader.read64(),
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
2
|
-
import { PythClient } from "../../utils/pyth/pythClient";
|
|
3
|
-
import { TOKEN } from "../../constants/token";
|
|
4
1
|
import { Position, TradingOrder } from "../position/structs";
|
|
2
|
+
import { PythClient } from "../../utils";
|
|
3
|
+
import { TOKEN } from "../../constants";
|
|
4
|
+
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
5
5
|
export declare function createTradingOrder(config: {
|
|
6
6
|
REGISTRY: {
|
|
7
|
-
|
|
7
|
+
MARKET: string;
|
|
8
8
|
USER: string;
|
|
9
9
|
LEADERBOARD: string;
|
|
10
|
-
|
|
10
|
+
LP_POOL: string;
|
|
11
11
|
};
|
|
12
12
|
OBJECT: {
|
|
13
13
|
TYPUS_VERSION: string;
|
|
@@ -29,7 +29,7 @@ export declare function createTradingOrder(config: {
|
|
|
29
29
|
}): Promise<TransactionBlock>;
|
|
30
30
|
export declare function cancelTradingOrder(config: {
|
|
31
31
|
REGISTRY: {
|
|
32
|
-
|
|
32
|
+
MARKET: string;
|
|
33
33
|
};
|
|
34
34
|
OBJECT: {
|
|
35
35
|
TYPUS_PERP_VERSION: string;
|
|
@@ -41,8 +41,8 @@ export declare function cancelTradingOrder(config: {
|
|
|
41
41
|
}): Promise<TransactionBlock>;
|
|
42
42
|
export declare function increaseCollateral(config: {
|
|
43
43
|
REGISTRY: {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
MARKET: string;
|
|
45
|
+
LP_POOL: string;
|
|
46
46
|
};
|
|
47
47
|
OBJECT: {
|
|
48
48
|
TYPUS_PERP_VERSION: string;
|
|
@@ -56,8 +56,8 @@ export declare function increaseCollateral(config: {
|
|
|
56
56
|
}): Promise<TransactionBlock>;
|
|
57
57
|
export declare function releaseCollateral(config: {
|
|
58
58
|
REGISTRY: {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
MARKET: string;
|
|
60
|
+
LP_POOL: string;
|
|
61
61
|
};
|
|
62
62
|
OBJECT: {
|
|
63
63
|
TYPUS_PERP_VERSION: string;
|