@typus/typus-sdk 1.2.27 → 1.2.29
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/utils/auto-bid/user-entry.d.ts +2 -0
- package/lib/utils/auto-bid/user-entry.js +14 -1
- package/lib/utils/auto-bid/view-function.js +1 -1
- package/lib/utils/leader-board.d.ts +1 -1
- package/lib/utils/leader-board.js +14 -5
- package/lib/utils/nft-staking/user-entry.js +1 -0
- package/lib/utils/price.js +4 -1
- package/lib/utils/typus-dice/api.d.ts +1 -0
- package/lib/utils/typus-dice/api.js +77 -0
- package/lib/utils/typus-dice/fetch.d.ts +71 -0
- package/lib/utils/typus-dice/fetch.js +346 -0
- package/lib/utils/typus-dice/user-entry.d.ts +28 -0
- package/lib/utils/typus-dice/user-entry.js +164 -0
- package/lib/utils/typus-dice/view-function.d.ts +8 -0
- package/lib/utils/typus-dice/view-function.js +135 -0
- package/lib/utils/typus-dov-single-v2/mfud-user-entry.d.ts +2 -0
- package/lib/utils/typus-dov-single-v2/mfud-user-entry.js +23 -1
- package/lib/utils/typus-dov-single-v2/vault-history.d.ts +1 -0
- package/lib/utils/typus-dov-single-v2/vault-history.js +94 -1
- package/package.json +1 -1
|
@@ -25,6 +25,8 @@ registry: string, strategy_pool: string, vault_index: string, signal_index: stri
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function getCloseStrategyTx(gasBudget: number, packageId: string, typeArguments: string[], // D_TOKEN, B_TOKEN
|
|
27
27
|
registry: string, strategy_pool: string, vault_index: string, signal_index: string, strategy_index: string, sender: string): TransactionBlock;
|
|
28
|
+
export declare function getWithdrawProfitStrategyTx(gasBudget: number, packageId: string, typeArguments: string[], // D_TOKEN, B_TOKEN
|
|
29
|
+
registry: string, strategy_pool: string, vault_index: string, signal_index: string, strategy_index: string, sender: string): TransactionBlock;
|
|
28
30
|
/**
|
|
29
31
|
entry fun update_strategy<D_TOKEN, B_TOKEN>(
|
|
30
32
|
strategy_pool: &mut StrategyPoolV2,
|
|
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
16
16
|
return ar;
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getUpdateStrategyTx = exports.getCloseStrategyTx = exports.getNewStrategyTx = void 0;
|
|
19
|
+
exports.getUpdateStrategyTx = exports.getWithdrawProfitStrategyTx = exports.getCloseStrategyTx = exports.getNewStrategyTx = void 0;
|
|
20
20
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
21
21
|
/**
|
|
22
22
|
entry fun new_strategy<B_TOKEN>(
|
|
@@ -103,6 +103,19 @@ registry, strategy_pool, vault_index, signal_index, strategy_index, sender) {
|
|
|
103
103
|
return tx;
|
|
104
104
|
}
|
|
105
105
|
exports.getCloseStrategyTx = getCloseStrategyTx;
|
|
106
|
+
function getWithdrawProfitStrategyTx(gasBudget, packageId, typeArguments, // D_TOKEN, B_TOKEN
|
|
107
|
+
registry, strategy_pool, vault_index, signal_index, strategy_index, sender) {
|
|
108
|
+
var tx = new transactions_1.TransactionBlock();
|
|
109
|
+
var d_token = tx.moveCall({
|
|
110
|
+
target: "".concat(packageId, "::auto_bid::withdraw_profit"),
|
|
111
|
+
typeArguments: typeArguments,
|
|
112
|
+
arguments: [tx.object(registry), tx.object(strategy_pool), tx.pure(vault_index), tx.pure(signal_index), tx.pure(strategy_index)],
|
|
113
|
+
});
|
|
114
|
+
tx.transferObjects([d_token], sender);
|
|
115
|
+
tx.setGasBudget(gasBudget);
|
|
116
|
+
return tx;
|
|
117
|
+
}
|
|
118
|
+
exports.getWithdrawProfitStrategyTx = getWithdrawProfitStrategyTx;
|
|
106
119
|
/**
|
|
107
120
|
entry fun update_strategy<D_TOKEN, B_TOKEN>(
|
|
108
121
|
strategy_pool: &mut StrategyPoolV2,
|
|
@@ -209,7 +209,7 @@ function getUserStrategies(provider, packageId, registry, strategyPool, user
|
|
|
209
209
|
strategy.my_bids = my_bids;
|
|
210
210
|
strategy.remaining_balance = strategy.u64_padding.at(0);
|
|
211
211
|
strategy.gain_to_harvest = strategy.u64_padding.at(1);
|
|
212
|
-
if (strategy.bid_times
|
|
212
|
+
if (Number(strategy.bid_times) >= Number(strategy.max_times)) {
|
|
213
213
|
strategy.status = "finished";
|
|
214
214
|
}
|
|
215
215
|
else if (!strategy.active) {
|
|
@@ -8,5 +8,5 @@ interface ExpEarn {
|
|
|
8
8
|
address: string;
|
|
9
9
|
total_exp_earn: number;
|
|
10
10
|
}
|
|
11
|
-
export declare function getExpLeaderBoard(startTimestamp: string): Promise<ExpEarn[]>;
|
|
11
|
+
export declare function getExpLeaderBoard(startTimestamp: string, endTimestamp?: string): Promise<ExpEarn[]>;
|
|
12
12
|
export {};
|
|
@@ -267,9 +267,9 @@ function getBidderLeaderBoard(startTimestamp, end) {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
exports.getBidderLeaderBoard = getBidderLeaderBoard;
|
|
270
|
-
function getExpLeaderBoard(startTimestamp) {
|
|
270
|
+
function getExpLeaderBoard(startTimestamp, endTimestamp) {
|
|
271
271
|
return __awaiter(this, void 0, void 0, function () {
|
|
272
|
-
var apiUrl, headers, requestData, jsonData, response, data;
|
|
272
|
+
var apiUrl, headers, _endTimestamp, requestData, jsonData, response, data;
|
|
273
273
|
return __generator(this, function (_a) {
|
|
274
274
|
switch (_a.label) {
|
|
275
275
|
case 0:
|
|
@@ -278,9 +278,10 @@ function getExpLeaderBoard(startTimestamp) {
|
|
|
278
278
|
"api-key": "tz3JJ6stG7Fux6ueRSRA5mdpC9U0lozI3",
|
|
279
279
|
"Content-Type": "application/json",
|
|
280
280
|
};
|
|
281
|
+
_endTimestamp = endTimestamp ? endTimestamp : "99999999999";
|
|
281
282
|
requestData = {
|
|
282
283
|
sqlQuery: {
|
|
283
|
-
sql: "SELECT S.distinct_id as address, SUM(E.exp_earn) as total_exp_earn\nFROM ExpUp E\nJOIN StakeNft S ON E.number = S.number\nWHERE timestamp >= ".concat(startTimestamp, "\nGROUP BY address\nORDER BY total_exp_earn DESC;"),
|
|
284
|
+
sql: "SELECT S.distinct_id as address, SUM(E.exp_earn) as total_exp_earn\nFROM ExpUp E\nJOIN StakeNft S ON E.number = S.number\nWHERE timestamp < ".concat(_endTimestamp, " && timestamp >= ").concat(startTimestamp, "\nGROUP BY address\nORDER BY total_exp_earn DESC;"),
|
|
284
285
|
size: 1000,
|
|
285
286
|
},
|
|
286
287
|
};
|
|
@@ -302,7 +303,15 @@ function getExpLeaderBoard(startTimestamp) {
|
|
|
302
303
|
}
|
|
303
304
|
exports.getExpLeaderBoard = getExpLeaderBoard;
|
|
304
305
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
var _a, _b;
|
|
307
|
+
return __generator(this, function (_c) {
|
|
308
|
+
switch (_c.label) {
|
|
309
|
+
case 0:
|
|
310
|
+
_b = (_a = console).log;
|
|
311
|
+
return [4 /*yield*/, getExpLeaderBoard("1707721200", "1708326000")];
|
|
312
|
+
case 1:
|
|
313
|
+
_b.apply(_a, [_c.sent()]);
|
|
314
|
+
return [2 /*return*/];
|
|
315
|
+
}
|
|
307
316
|
});
|
|
308
317
|
}); })();
|
|
@@ -165,6 +165,7 @@ function getCreateKioskAndLockNftTx(kioskClient, gasBudget, nftPackageId, policy
|
|
|
165
165
|
tx = new transactions_1.TransactionBlock();
|
|
166
166
|
kioskTx = new kiosk_1.KioskTransaction({ transactionBlock: tx, kioskClient: kioskClient });
|
|
167
167
|
kioskTx.create();
|
|
168
|
+
// @ts-ignore
|
|
168
169
|
kioskTx.lock({ itemType: "".concat(nftPackageId, "::typus_nft::Tails"), itemId: nft_id, policy: policy, item: nft_id });
|
|
169
170
|
kiosk = kioskTx.kiosk, kioskCap = kioskTx.kioskCap;
|
|
170
171
|
if (kiosk && kioskCap) {
|
package/lib/utils/price.js
CHANGED
|
@@ -89,7 +89,10 @@ function getLatestPrice(pair) {
|
|
|
89
89
|
return [4 /*yield*/, getPairPrices(pair, minuteAgo.toString(), currentTimestampInSeconds.toString())];
|
|
90
90
|
case 1:
|
|
91
91
|
res = _a.sent();
|
|
92
|
-
|
|
92
|
+
if (res.at(-1)) {
|
|
93
|
+
return [2 /*return*/, res.at(-1).price];
|
|
94
|
+
}
|
|
95
|
+
return [2 /*return*/, "0"];
|
|
93
96
|
}
|
|
94
97
|
});
|
|
95
98
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDrawResult(network: "mainnet" | "testnet", packageId: string, registry: string, index: string, amount: string, guess_1: string, larger_than_1: boolean, guess_2: string, larger_than_2: boolean, vrf_input_1: number[], vrf_input_2: number[]): Promise<any>;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getDrawResult = void 0;
|
|
40
|
+
var apiUrl = "https://us-central1-aqueous-freedom-378103.cloudfunctions.net/draw-result-1";
|
|
41
|
+
function getDrawResult(network, packageId, registry, index, amount, guess_1, larger_than_1, guess_2, larger_than_2, vrf_input_1, vrf_input_2) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var queryParams, vrf_input_1_string, vrf_input_2_string, apiUrlWithParams, response, data;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
queryParams = new URLSearchParams({
|
|
48
|
+
network: network,
|
|
49
|
+
packageId: packageId,
|
|
50
|
+
registry: registry,
|
|
51
|
+
index: index,
|
|
52
|
+
amount: amount,
|
|
53
|
+
guess_1: guess_1,
|
|
54
|
+
larger_than_1: "".concat(larger_than_1),
|
|
55
|
+
guess_2: guess_2,
|
|
56
|
+
larger_than_2: "".concat(larger_than_2),
|
|
57
|
+
});
|
|
58
|
+
vrf_input_1_string = JSON.stringify(vrf_input_1);
|
|
59
|
+
vrf_input_2_string = JSON.stringify(vrf_input_2);
|
|
60
|
+
apiUrlWithParams = "".concat(apiUrl, "?").concat(queryParams.toString(), "&vrf_input_1=").concat(vrf_input_1_string, "&vrf_input_2=").concat(vrf_input_2_string);
|
|
61
|
+
return [4 /*yield*/, fetch(apiUrlWithParams, {
|
|
62
|
+
method: "GET",
|
|
63
|
+
headers: { "Content-Type": "application/json" },
|
|
64
|
+
})];
|
|
65
|
+
case 1:
|
|
66
|
+
response = _a.sent();
|
|
67
|
+
if (!response.ok) return [3 /*break*/, 3];
|
|
68
|
+
return [4 /*yield*/, response.json()];
|
|
69
|
+
case 2:
|
|
70
|
+
data = _a.sent();
|
|
71
|
+
return [2 /*return*/, data];
|
|
72
|
+
case 3: return [2 /*return*/];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.getDrawResult = getDrawResult;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SuiClient } from "@mysten/sui.js/client";
|
|
2
|
+
export declare function getPlaygrounds(provider: SuiClient, diceRegistry: string): Promise<Playground[]>;
|
|
3
|
+
export interface Playground {
|
|
4
|
+
id: string;
|
|
5
|
+
house_whitelist: string[];
|
|
6
|
+
public_key: string;
|
|
7
|
+
num_of_games: string;
|
|
8
|
+
stake_token: string;
|
|
9
|
+
opened_games: Game[];
|
|
10
|
+
game_config: GameConfig;
|
|
11
|
+
exp_config: ExpConfig;
|
|
12
|
+
is_active: boolean;
|
|
13
|
+
u64_padding: string[];
|
|
14
|
+
bcs_padding: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface GameConfig {
|
|
17
|
+
max_stake: string;
|
|
18
|
+
min_stake: string;
|
|
19
|
+
stake_lot_size: string;
|
|
20
|
+
base_exp_divisor: string;
|
|
21
|
+
losses_multiplier_bp: string;
|
|
22
|
+
critical_hits_multiplier_bp: string;
|
|
23
|
+
u64_padding: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface ExpConfig {
|
|
26
|
+
base_exp_divisor: string;
|
|
27
|
+
u64_padding: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface Game {
|
|
30
|
+
game_id: string;
|
|
31
|
+
player: string;
|
|
32
|
+
stake_amount: string;
|
|
33
|
+
guess_1: string | null;
|
|
34
|
+
larger_than_1: boolean | null;
|
|
35
|
+
vrf_input_1: number[] | null;
|
|
36
|
+
guess_2: string | null;
|
|
37
|
+
larger_than_2: boolean | null;
|
|
38
|
+
vrf_input_2: number[] | null;
|
|
39
|
+
u64_padding: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare function getHistory(provider: SuiClient, dicePackage: string, playgrounds: Playground[]): Promise<DrawDisplay[]>;
|
|
42
|
+
export declare function waitHistory(provider: SuiClient, dicePackage: string, onMessage: any): Promise<import("@mysten/sui.js/client").Unsubscribe>;
|
|
43
|
+
export declare function parseHistory(datas: any, playgrounds: Playground[]): Promise<DrawDisplay[]>;
|
|
44
|
+
interface DrawDisplay {
|
|
45
|
+
game_id: string;
|
|
46
|
+
player: string;
|
|
47
|
+
guess_1: string;
|
|
48
|
+
guess_2: string;
|
|
49
|
+
result_1: string;
|
|
50
|
+
result_2: string;
|
|
51
|
+
bet_amount: string;
|
|
52
|
+
reward: string;
|
|
53
|
+
exp: string;
|
|
54
|
+
}
|
|
55
|
+
export interface LeaderBoard {
|
|
56
|
+
player: string;
|
|
57
|
+
total_bet_amount: number;
|
|
58
|
+
total_earn_exp: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function getLeaderBoard(drawDisplays: DrawDisplay[]): Promise<LeaderBoard[]>;
|
|
61
|
+
export interface ProfitSharing {
|
|
62
|
+
level_profits: string[];
|
|
63
|
+
level_users: string[];
|
|
64
|
+
pool: string;
|
|
65
|
+
remaining: string;
|
|
66
|
+
total: string;
|
|
67
|
+
tokenType: string;
|
|
68
|
+
}
|
|
69
|
+
export declare function getProfitSharing(provider: SuiClient, diceProfitSharing: string): Promise<ProfitSharing>;
|
|
70
|
+
export declare function calculateLevelReward(totalRewards: number, levelShares: number[], numOfHolders: number[]): number[];
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,346 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.calculateLevelReward = exports.getProfitSharing = exports.getLeaderBoard = exports.parseHistory = exports.waitHistory = exports.getHistory = exports.getPlaygrounds = void 0;
|
|
51
|
+
var token_1 = require("../token");
|
|
52
|
+
function getPlaygrounds(provider, diceRegistry) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var playgroundIds, objects, result;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, provider.getDynamicFields({ parentId: diceRegistry })];
|
|
58
|
+
case 1:
|
|
59
|
+
playgroundIds = (_a.sent()).data
|
|
60
|
+
.sort(function (a, b) { return Number(a.name.value) - Number(b.name.value); })
|
|
61
|
+
.map(function (x) { return x.objectId; });
|
|
62
|
+
return [4 /*yield*/, provider.multiGetObjects({
|
|
63
|
+
ids: playgroundIds,
|
|
64
|
+
options: { showContent: true },
|
|
65
|
+
})];
|
|
66
|
+
case 2:
|
|
67
|
+
objects = _a.sent();
|
|
68
|
+
result = objects
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
.filter(function (object) { var _a, _b; return (_b = (_a = object.data) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type.endsWith("Playground"); })
|
|
71
|
+
.map(function (object) {
|
|
72
|
+
var _a;
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
var fields = (_a = object.data) === null || _a === void 0 ? void 0 : _a.content.fields;
|
|
75
|
+
var opened_games = fields.opened_games.map(function (item) { return item.fields; });
|
|
76
|
+
var game_config = fields.game_config.fields;
|
|
77
|
+
var exp_config = fields.exp_config.fields;
|
|
78
|
+
// console.log(opened_games);
|
|
79
|
+
// console.log(game_config);
|
|
80
|
+
var playground = {
|
|
81
|
+
id: fields.id.id,
|
|
82
|
+
house_whitelist: fields.house_whitelist,
|
|
83
|
+
public_key: fields.public_key,
|
|
84
|
+
num_of_games: fields.num_of_games,
|
|
85
|
+
stake_token: fields.stake_token.fields.name,
|
|
86
|
+
opened_games: opened_games,
|
|
87
|
+
game_config: game_config,
|
|
88
|
+
exp_config: exp_config,
|
|
89
|
+
is_active: fields.is_active,
|
|
90
|
+
u64_padding: fields.u64_padding,
|
|
91
|
+
bcs_padding: fields.bcs_padding,
|
|
92
|
+
};
|
|
93
|
+
// console.log(playground);
|
|
94
|
+
return playground;
|
|
95
|
+
});
|
|
96
|
+
return [2 /*return*/, result];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.getPlaygrounds = getPlaygrounds;
|
|
102
|
+
function getHistory(provider, dicePackage, playgrounds) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var eventFilter, result, history, nextPage;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
eventFilter = {
|
|
109
|
+
MoveEventType: "".concat(dicePackage, "::combo_dice::Draw"),
|
|
110
|
+
};
|
|
111
|
+
return [4 /*yield*/, provider.queryEvents({ query: eventFilter, order: "descending" })];
|
|
112
|
+
case 1:
|
|
113
|
+
result = _a.sent();
|
|
114
|
+
return [4 /*yield*/, parseHistory(result.data, playgrounds)];
|
|
115
|
+
case 2:
|
|
116
|
+
history = _a.sent();
|
|
117
|
+
_a.label = 3;
|
|
118
|
+
case 3:
|
|
119
|
+
if (!result.hasNextPage) return [3 /*break*/, 6];
|
|
120
|
+
return [4 /*yield*/, provider.queryEvents({ query: eventFilter, order: "descending", cursor: result.nextCursor })];
|
|
121
|
+
case 4:
|
|
122
|
+
result = _a.sent();
|
|
123
|
+
return [4 /*yield*/, parseHistory(result.data, playgrounds)];
|
|
124
|
+
case 5:
|
|
125
|
+
nextPage = _a.sent();
|
|
126
|
+
history = history.concat(nextPage);
|
|
127
|
+
return [3 /*break*/, 3];
|
|
128
|
+
case 6: return [2 /*return*/, history];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
exports.getHistory = getHistory;
|
|
134
|
+
function waitHistory(provider, dicePackage, onMessage) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var eventFilter, unsubscribe;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
eventFilter = {
|
|
141
|
+
MoveEventType: "".concat(dicePackage, "::combo_dice::Draw"),
|
|
142
|
+
};
|
|
143
|
+
return [4 /*yield*/, provider.subscribeEvent({
|
|
144
|
+
filter: eventFilter,
|
|
145
|
+
onMessage: onMessage,
|
|
146
|
+
})];
|
|
147
|
+
case 1:
|
|
148
|
+
unsubscribe = _a.sent();
|
|
149
|
+
return [2 /*return*/, unsubscribe];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
exports.waitHistory = waitHistory;
|
|
155
|
+
function parseHistory(datas, playgrounds) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var result;
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
result = datas.map(function (event) {
|
|
160
|
+
var drawEvent = event.parsedJson;
|
|
161
|
+
var playground = playgrounds[Number(drawEvent.index)];
|
|
162
|
+
var coinType = "0x" + playground.stake_token;
|
|
163
|
+
var asset = (0, token_1.typeArgToAsset)(coinType);
|
|
164
|
+
var decimal = (0, token_1.assetToDecimal)(asset);
|
|
165
|
+
var guess_1 = (drawEvent.larger_than_1 ? "> " : "< ") + "".concat(Number(drawEvent.guess_1) / 100);
|
|
166
|
+
var guess_2 = (drawEvent.larger_than_2 ? "> " : "< ") + "".concat(Number(drawEvent.guess_2) / 100);
|
|
167
|
+
var result_1 = "".concat(Number(drawEvent.answer_1) / 100);
|
|
168
|
+
switch (drawEvent.result_1) {
|
|
169
|
+
case "0":
|
|
170
|
+
result_1 += " W";
|
|
171
|
+
break;
|
|
172
|
+
case "1":
|
|
173
|
+
result_1 += " L";
|
|
174
|
+
break;
|
|
175
|
+
case "2":
|
|
176
|
+
result_1 += " C";
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
var result_2 = "".concat(Number(drawEvent.answer_2) / 100);
|
|
180
|
+
switch (drawEvent.result_2) {
|
|
181
|
+
case "0":
|
|
182
|
+
result_2 += " W";
|
|
183
|
+
break;
|
|
184
|
+
case "1":
|
|
185
|
+
result_2 += " L";
|
|
186
|
+
break;
|
|
187
|
+
case "2":
|
|
188
|
+
result_2 += " C";
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
var stake_amount = Number(drawEvent.stake_amount) / Math.pow(10, decimal);
|
|
192
|
+
var amount = stake_amount > 1000000 ? "".concat(stake_amount / 1000000, "m") : stake_amount;
|
|
193
|
+
var reward = Number(drawEvent.reward) / Math.pow(10, decimal);
|
|
194
|
+
var display = {
|
|
195
|
+
game_id: drawEvent.game_id,
|
|
196
|
+
player: drawEvent.player,
|
|
197
|
+
guess_1: guess_1,
|
|
198
|
+
guess_2: guess_2,
|
|
199
|
+
result_1: result_1,
|
|
200
|
+
result_2: result_2,
|
|
201
|
+
bet_amount: "".concat(amount, " ").concat(asset),
|
|
202
|
+
reward: "".concat(reward, " ").concat(asset),
|
|
203
|
+
exp: "".concat(Number(drawEvent.exp_amount), " EXP"),
|
|
204
|
+
};
|
|
205
|
+
return display;
|
|
206
|
+
});
|
|
207
|
+
return [2 /*return*/, result];
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.parseHistory = parseHistory;
|
|
212
|
+
function getLeaderBoard(drawDisplays) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
var leaderBoard, _loop_1, drawDisplays_1, drawDisplays_1_1, drawDisplay;
|
|
215
|
+
var e_1, _a;
|
|
216
|
+
return __generator(this, function (_b) {
|
|
217
|
+
leaderBoard = [];
|
|
218
|
+
_loop_1 = function (drawDisplay) {
|
|
219
|
+
var i = leaderBoard.findIndex(function (x) { return x.player == drawDisplay.player; });
|
|
220
|
+
if (i == -1) {
|
|
221
|
+
leaderBoard.push({
|
|
222
|
+
player: drawDisplay.player,
|
|
223
|
+
total_bet_amount: Number(drawDisplay.bet_amount.split(" ")[0]),
|
|
224
|
+
total_earn_exp: Number(drawDisplay.exp.split(" ")[0]),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
leaderBoard[i].total_bet_amount += Number(drawDisplay.bet_amount.split(" ")[0]);
|
|
229
|
+
leaderBoard[i].total_earn_exp += Number(drawDisplay.exp.split(" ")[0]);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
for (drawDisplays_1 = __values(drawDisplays), drawDisplays_1_1 = drawDisplays_1.next(); !drawDisplays_1_1.done; drawDisplays_1_1 = drawDisplays_1.next()) {
|
|
234
|
+
drawDisplay = drawDisplays_1_1.value;
|
|
235
|
+
_loop_1(drawDisplay);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
239
|
+
finally {
|
|
240
|
+
try {
|
|
241
|
+
if (drawDisplays_1_1 && !drawDisplays_1_1.done && (_a = drawDisplays_1.return)) _a.call(drawDisplays_1);
|
|
242
|
+
}
|
|
243
|
+
finally { if (e_1) throw e_1.error; }
|
|
244
|
+
}
|
|
245
|
+
return [2 /*return*/, leaderBoard];
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
exports.getLeaderBoard = getLeaderBoard;
|
|
250
|
+
function getProfitSharing(provider, diceProfitSharing) {
|
|
251
|
+
var _a, _b, _c, _d;
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var object, type, tokenType, result;
|
|
254
|
+
return __generator(this, function (_e) {
|
|
255
|
+
switch (_e.label) {
|
|
256
|
+
case 0: return [4 /*yield*/, provider.getObject({
|
|
257
|
+
id: diceProfitSharing,
|
|
258
|
+
options: { showContent: true },
|
|
259
|
+
})];
|
|
260
|
+
case 1:
|
|
261
|
+
object = _e.sent();
|
|
262
|
+
type = (_a = object.data) === null || _a === void 0 ? void 0 : _a.content.type;
|
|
263
|
+
tokenType = (_b = type.split("<").at(-1)) === null || _b === void 0 ? void 0 : _b.replace(">>", "");
|
|
264
|
+
result = (_d = (_c = object.data) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.fields.value.fields;
|
|
265
|
+
result.tokenType = tokenType;
|
|
266
|
+
return [2 /*return*/, result];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
exports.getProfitSharing = getProfitSharing;
|
|
272
|
+
function calculateLevelReward(totalRewards, levelShares, numOfHolders) {
|
|
273
|
+
// Step 1: Calculate original level rewards (per holder)
|
|
274
|
+
var totalShares = levelShares.reduce(function (acc, share) { return acc + share; }, 0);
|
|
275
|
+
var originalRewardPerHolder = levelShares.map(function (levelShare, index) {
|
|
276
|
+
var num = numOfHolders[index];
|
|
277
|
+
var levelRewardPerHolder = num > 0 ? (totalRewards * levelShare) / totalShares / num : 0;
|
|
278
|
+
return Math.floor(levelRewardPerHolder);
|
|
279
|
+
});
|
|
280
|
+
var originalLevelRewards = originalRewardPerHolder.map(function (reward, index) { return reward * numOfHolders[index]; });
|
|
281
|
+
var distributedRewards = originalLevelRewards.reduce(function (acc, reward) { return acc + reward; }, 0);
|
|
282
|
+
var emptyLevelRewards = totalRewards - distributedRewards;
|
|
283
|
+
// console.log("Step 1 - ", originalRewardPerHolder);
|
|
284
|
+
// Step 2: Distribute rewards from empty levels
|
|
285
|
+
var reversedOriginalRewardPerHolder = originalRewardPerHolder.slice().reverse();
|
|
286
|
+
var reversedNumOfHolders = numOfHolders.slice().reverse();
|
|
287
|
+
var reversedScaledRewardPerHolder = [];
|
|
288
|
+
if (emptyLevelRewards > 0) {
|
|
289
|
+
var undistributedRewards_1 = emptyLevelRewards;
|
|
290
|
+
var uncalculatedDistributedRewards_1 = distributedRewards;
|
|
291
|
+
reversedScaledRewardPerHolder = reversedOriginalRewardPerHolder.map(function (rewardPerHolder, index) {
|
|
292
|
+
var num = reversedNumOfHolders[index];
|
|
293
|
+
var scaledRewardPerHolder = num > 0
|
|
294
|
+
? uncalculatedDistributedRewards_1 > 0
|
|
295
|
+
? (rewardPerHolder * (uncalculatedDistributedRewards_1 + undistributedRewards_1)) / uncalculatedDistributedRewards_1
|
|
296
|
+
: rewardPerHolder
|
|
297
|
+
: 0;
|
|
298
|
+
undistributedRewards_1 -= (scaledRewardPerHolder - rewardPerHolder) * num;
|
|
299
|
+
uncalculatedDistributedRewards_1 -= rewardPerHolder * num;
|
|
300
|
+
return Math.floor(scaledRewardPerHolder);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
reversedScaledRewardPerHolder = reversedOriginalRewardPerHolder.slice();
|
|
305
|
+
}
|
|
306
|
+
// let scaledRewardPerHolder: number[] = reversedScaledRewardPerHolder.slice().reverse();
|
|
307
|
+
// console.log("Step 2 - ", scaledRewardPerHolder);
|
|
308
|
+
// Step 3: Capped level reward
|
|
309
|
+
var reversedCappedRewardPerHolder = [reversedOriginalRewardPerHolder[0]];
|
|
310
|
+
var tempHighLevelReward = 0;
|
|
311
|
+
reversedScaledRewardPerHolder.forEach(function (highLevelReward, index) {
|
|
312
|
+
var lowLevelReward = reversedScaledRewardPerHolder[index + 1] || 0;
|
|
313
|
+
tempHighLevelReward =
|
|
314
|
+
highLevelReward > 0
|
|
315
|
+
? tempHighLevelReward > 0
|
|
316
|
+
? Math.min(highLevelReward, tempHighLevelReward)
|
|
317
|
+
: highLevelReward
|
|
318
|
+
: tempHighLevelReward;
|
|
319
|
+
reversedCappedRewardPerHolder.push(tempHighLevelReward > 0 ? Math.min(lowLevelReward, tempHighLevelReward) : lowLevelReward);
|
|
320
|
+
});
|
|
321
|
+
reversedCappedRewardPerHolder.pop();
|
|
322
|
+
var cappedRewardPerHolder = reversedCappedRewardPerHolder.slice().reverse();
|
|
323
|
+
// console.log("Step 3 - ", cappedRewardPerHolder);
|
|
324
|
+
// Step 4: Distribute capped reward from Step 3 into each level
|
|
325
|
+
var distributedRewardsStep4 = reversedCappedRewardPerHolder.reduce(function (acc, reward, index) { return acc + reward * reversedNumOfHolders[index]; }, 0);
|
|
326
|
+
var undistributedRewardsStep4 = totalRewards - distributedRewardsStep4;
|
|
327
|
+
var uncalculatedDistributedRewardsStep4 = distributedRewardsStep4;
|
|
328
|
+
// console.log(distributedRewardsStep4);
|
|
329
|
+
// console.log(totalRewards);
|
|
330
|
+
// console.log(undistributedRewardsStep4);
|
|
331
|
+
// console.log(uncalculatedDistributedRewardsStep4);
|
|
332
|
+
var levelReward = cappedRewardPerHolder.map(function (rewardPerHolder, index) {
|
|
333
|
+
var num = reversedNumOfHolders[index];
|
|
334
|
+
var scaledRewardPerHolder = uncalculatedDistributedRewardsStep4 > 0
|
|
335
|
+
? (rewardPerHolder * (uncalculatedDistributedRewardsStep4 + undistributedRewardsStep4)) /
|
|
336
|
+
uncalculatedDistributedRewardsStep4
|
|
337
|
+
: rewardPerHolder;
|
|
338
|
+
undistributedRewardsStep4 -= (scaledRewardPerHolder - rewardPerHolder) * num;
|
|
339
|
+
uncalculatedDistributedRewardsStep4 -= rewardPerHolder * num;
|
|
340
|
+
// console.log(undistributedRewardsStep4);
|
|
341
|
+
return Math.floor(scaledRewardPerHolder);
|
|
342
|
+
});
|
|
343
|
+
// console.log("Step 4 - ", levelReward);
|
|
344
|
+
return levelReward;
|
|
345
|
+
}
|
|
346
|
+
exports.calculateLevelReward = calculateLevelReward;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
2
|
+
/**
|
|
3
|
+
public(friend) entry fun new_game<TOKEN>(
|
|
4
|
+
registry: &mut Registry,
|
|
5
|
+
exp_registry: &mut ExpRegistry,
|
|
6
|
+
index: u64,
|
|
7
|
+
coins: vector<Coin<TOKEN>>,
|
|
8
|
+
stake_amount: u64,
|
|
9
|
+
ctx: &mut TxContext
|
|
10
|
+
)
|
|
11
|
+
*/
|
|
12
|
+
export declare function newGameTx(gasBudget: number, packageId: string, typeArguments: string[], // [TOKEN]
|
|
13
|
+
registry: string, exp_registry: string, index: string, coins: string[], amount: string): Promise<TransactionBlock>;
|
|
14
|
+
/**
|
|
15
|
+
public(friend) entry fun play_guess(
|
|
16
|
+
registry: &mut Registry,
|
|
17
|
+
index: u64,
|
|
18
|
+
game_id: u64,
|
|
19
|
+
guess_1: u64,
|
|
20
|
+
larger_than_1: bool,
|
|
21
|
+
guess_2: u64,
|
|
22
|
+
larger_than_2: bool,
|
|
23
|
+
ctx: &mut TxContext
|
|
24
|
+
)
|
|
25
|
+
*/
|
|
26
|
+
export declare function playGuessTx(gasBudget: number, packageId: string, registry: string, index: string, guess_1: string, larger_than_1: boolean, guess_2: string, larger_than_2: boolean): Promise<TransactionBlock>;
|
|
27
|
+
export declare function newGamePlayGuessTx(gasBudget: number, packageId: string, typeArguments: string[], // [TOKEN]
|
|
28
|
+
registry: string, exp_registry: string, index: string, coins: string[], amount: string, guess_1: string, larger_than_1: boolean, guess_2: string, larger_than_2: boolean): Promise<TransactionBlock>;
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.newGamePlayGuessTx = exports.playGuessTx = exports.newGameTx = void 0;
|
|
56
|
+
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
57
|
+
/**
|
|
58
|
+
public(friend) entry fun new_game<TOKEN>(
|
|
59
|
+
registry: &mut Registry,
|
|
60
|
+
exp_registry: &mut ExpRegistry,
|
|
61
|
+
index: u64,
|
|
62
|
+
coins: vector<Coin<TOKEN>>,
|
|
63
|
+
stake_amount: u64,
|
|
64
|
+
ctx: &mut TxContext
|
|
65
|
+
)
|
|
66
|
+
*/
|
|
67
|
+
function newGameTx(gasBudget, packageId, typeArguments, // [TOKEN]
|
|
68
|
+
registry, exp_registry, index, coins, amount) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var tx;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
tx = new transactions_1.TransactionBlock();
|
|
73
|
+
tx.moveCall({
|
|
74
|
+
target: "".concat(packageId, "::combo_dice::new_game"),
|
|
75
|
+
typeArguments: typeArguments,
|
|
76
|
+
arguments: [tx.object(registry), tx.object(exp_registry), tx.pure(index), tx.makeMoveVec({ objects: coins.map(function (id) { return tx.object(id); }) }), tx.pure(amount)],
|
|
77
|
+
});
|
|
78
|
+
tx.setGasBudget(gasBudget);
|
|
79
|
+
return [2 /*return*/, tx];
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.newGameTx = newGameTx;
|
|
84
|
+
/**
|
|
85
|
+
public(friend) entry fun play_guess(
|
|
86
|
+
registry: &mut Registry,
|
|
87
|
+
index: u64,
|
|
88
|
+
game_id: u64,
|
|
89
|
+
guess_1: u64,
|
|
90
|
+
larger_than_1: bool,
|
|
91
|
+
guess_2: u64,
|
|
92
|
+
larger_than_2: bool,
|
|
93
|
+
ctx: &mut TxContext
|
|
94
|
+
)
|
|
95
|
+
*/
|
|
96
|
+
function playGuessTx(gasBudget, packageId, registry, index, guess_1, larger_than_1, guess_2, larger_than_2) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var tx;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
tx = new transactions_1.TransactionBlock();
|
|
101
|
+
tx.moveCall({
|
|
102
|
+
target: "".concat(packageId, "::combo_dice::play_guess"),
|
|
103
|
+
typeArguments: [],
|
|
104
|
+
arguments: [
|
|
105
|
+
tx.object(registry),
|
|
106
|
+
tx.pure(index),
|
|
107
|
+
tx.pure(guess_1),
|
|
108
|
+
tx.pure(larger_than_1),
|
|
109
|
+
tx.pure(guess_2),
|
|
110
|
+
tx.pure(larger_than_2),
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
tx.setGasBudget(gasBudget);
|
|
114
|
+
return [2 /*return*/, tx];
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.playGuessTx = playGuessTx;
|
|
119
|
+
function newGamePlayGuessTx(gasBudget, packageId, typeArguments, // [TOKEN]
|
|
120
|
+
registry, exp_registry, index, coins, amount, guess_1, larger_than_1, guess_2, larger_than_2) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var tx, _a, coin;
|
|
123
|
+
return __generator(this, function (_b) {
|
|
124
|
+
tx = new transactions_1.TransactionBlock();
|
|
125
|
+
if (typeArguments[0] == "0x2::sui::SUI" ||
|
|
126
|
+
typeArguments[0] == "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI") {
|
|
127
|
+
_a = __read(tx.splitCoins(tx.gas, [tx.pure(amount)]), 1), coin = _a[0];
|
|
128
|
+
tx.moveCall({
|
|
129
|
+
target: "".concat(packageId, "::combo_dice::new_game"),
|
|
130
|
+
typeArguments: typeArguments,
|
|
131
|
+
arguments: [tx.object(registry), tx.object(exp_registry), tx.pure(index), tx.makeMoveVec({ objects: [coin] }), tx.pure(amount)],
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
tx.moveCall({
|
|
136
|
+
target: "".concat(packageId, "::combo_dice::new_game"),
|
|
137
|
+
typeArguments: typeArguments,
|
|
138
|
+
arguments: [
|
|
139
|
+
tx.object(registry),
|
|
140
|
+
tx.object(exp_registry),
|
|
141
|
+
tx.pure(index),
|
|
142
|
+
tx.makeMoveVec({ objects: coins.map(function (id) { return tx.object(id); }) }),
|
|
143
|
+
tx.pure(amount),
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
tx.moveCall({
|
|
148
|
+
target: "".concat(packageId, "::combo_dice::play_guess"),
|
|
149
|
+
typeArguments: [],
|
|
150
|
+
arguments: [
|
|
151
|
+
tx.object(registry),
|
|
152
|
+
tx.pure(index),
|
|
153
|
+
tx.pure(guess_1),
|
|
154
|
+
tx.pure(larger_than_1),
|
|
155
|
+
tx.pure(guess_2),
|
|
156
|
+
tx.pure(larger_than_2),
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
tx.setGasBudget(gasBudget);
|
|
160
|
+
return [2 /*return*/, tx];
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
exports.newGamePlayGuessTx = newGamePlayGuessTx;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface DrawResult {
|
|
2
|
+
answer_1: string;
|
|
3
|
+
result_1: string;
|
|
4
|
+
answer_2: string;
|
|
5
|
+
result_2: string;
|
|
6
|
+
exp: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function simulateGame(network: "mainnet" | "testnet", packageId: string, registry: string, index: string, amount: string, guess_1: string, larger_than_1: boolean, guess_2: string, larger_than_2: boolean, vrf_input_1: number[], vrf_input_2: number[], drawKeys: any, sender?: string): Promise<DrawResult>;
|
|
@@ -0,0 +1,135 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.simulateGame = void 0;
|
|
43
|
+
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
44
|
+
var client_1 = require("@mysten/sui.js/client");
|
|
45
|
+
var bcs_1 = require("@mysten/bcs");
|
|
46
|
+
var bls_signatures_1 = __importDefault(require("bls-signatures"));
|
|
47
|
+
function simulateGame(network, packageId, registry, index, amount, guess_1, larger_than_1, guess_2, larger_than_2, vrf_input_1, vrf_input_2, drawKeys, sender) {
|
|
48
|
+
if (sender === void 0) { sender = "0xb6c7e3b1c61ee81516a8317f221daa035f1503e0ac3ae7a50b61834bc7a3ead9"; }
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var provider, transactionBlock, target, BLS, PRIVATE_KEY, draw_private_key, bls_signature_1, bls_signature_2, transactionBlockArguments, results, bytes, reader, answer_1, result_1, answer_2, result_2, reward, exp, result;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
provider = new client_1.SuiClient({ url: (0, client_1.getFullnodeUrl)(network) });
|
|
55
|
+
transactionBlock = new transactions_1.TransactionBlock();
|
|
56
|
+
target = "".concat(packageId, "::combo_dice::simulate_game");
|
|
57
|
+
console.log(target);
|
|
58
|
+
return [4 /*yield*/, (0, bls_signatures_1.default)()];
|
|
59
|
+
case 1:
|
|
60
|
+
BLS = _a.sent();
|
|
61
|
+
PRIVATE_KEY = Uint8Array.from(drawKeys[network][index]);
|
|
62
|
+
draw_private_key = BLS.PrivateKey.from_bytes(PRIVATE_KEY, true);
|
|
63
|
+
bls_signature_1 = BLS.BasicSchemeMPL.sign(draw_private_key, Uint8Array.from(vrf_input_1)).serialize();
|
|
64
|
+
bls_signature_2 = BLS.BasicSchemeMPL.sign(draw_private_key, Uint8Array.from(vrf_input_2)).serialize();
|
|
65
|
+
transactionBlockArguments = [
|
|
66
|
+
transactionBlock.object(registry),
|
|
67
|
+
transactionBlock.pure(index),
|
|
68
|
+
transactionBlock.pure(amount),
|
|
69
|
+
transactionBlock.pure(guess_1),
|
|
70
|
+
transactionBlock.pure(larger_than_1),
|
|
71
|
+
transactionBlock.pure(guess_2),
|
|
72
|
+
transactionBlock.pure(larger_than_2),
|
|
73
|
+
transactionBlock.pure(uint8ArrayToBCSStringArray(Uint8Array.from(vrf_input_1))),
|
|
74
|
+
transactionBlock.pure(uint8ArrayToBCSStringArray(Uint8Array.from(vrf_input_2))),
|
|
75
|
+
transactionBlock.pure(uint8ArrayToBCSStringArray(bls_signature_1)),
|
|
76
|
+
transactionBlock.pure(uint8ArrayToBCSStringArray(bls_signature_2)),
|
|
77
|
+
];
|
|
78
|
+
transactionBlock.moveCall({
|
|
79
|
+
target: target,
|
|
80
|
+
typeArguments: [],
|
|
81
|
+
arguments: transactionBlockArguments,
|
|
82
|
+
});
|
|
83
|
+
return [4 /*yield*/, provider.devInspectTransactionBlock({ transactionBlock: transactionBlock, sender: sender })];
|
|
84
|
+
case 2:
|
|
85
|
+
results = (_a.sent()).results;
|
|
86
|
+
bytes = results[results.length - 1].returnValues[0][0];
|
|
87
|
+
reader = new bcs_1.BcsReader(new Uint8Array(bytes));
|
|
88
|
+
// vector[
|
|
89
|
+
// answer_1,
|
|
90
|
+
// result_1,
|
|
91
|
+
// answer_2,
|
|
92
|
+
// result_2,
|
|
93
|
+
// reward,
|
|
94
|
+
// exp
|
|
95
|
+
// ]
|
|
96
|
+
// skip vector length byte first
|
|
97
|
+
reader.read8();
|
|
98
|
+
answer_1 = reader.read64();
|
|
99
|
+
result_1 = reader.read64();
|
|
100
|
+
answer_2 = reader.read64();
|
|
101
|
+
result_2 = reader.read64();
|
|
102
|
+
reward = reader.read64();
|
|
103
|
+
exp = reader.read64();
|
|
104
|
+
result = {
|
|
105
|
+
answer_1: answer_1,
|
|
106
|
+
result_1: result_1,
|
|
107
|
+
answer_2: answer_2,
|
|
108
|
+
result_2: result_2,
|
|
109
|
+
reward: reward,
|
|
110
|
+
exp: exp,
|
|
111
|
+
};
|
|
112
|
+
return [2 /*return*/, result];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.simulateGame = simulateGame;
|
|
118
|
+
function uint8ArrayToBCSStringArray(uint8Array) {
|
|
119
|
+
var result = [];
|
|
120
|
+
for (var i = 0; i < uint8Array.length; i++) {
|
|
121
|
+
// Assume each byte is a UTF-8 character
|
|
122
|
+
var character = String.fromCharCode(uint8Array[i]);
|
|
123
|
+
// Convert character to its BCS representation (you need to implement this part)
|
|
124
|
+
var bcsRepresentation = encodeToBCS(character);
|
|
125
|
+
// Add BCS representation to the result array
|
|
126
|
+
result.push(bcsRepresentation);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
// Function to encode a character to its BCS representation
|
|
131
|
+
function encodeToBCS(character) {
|
|
132
|
+
// You need to implement this part based on BCS encoding rules
|
|
133
|
+
// This is a placeholder; the actual implementation depends on BCS specifications
|
|
134
|
+
return character.charCodeAt(0).toString();
|
|
135
|
+
}
|
|
@@ -134,3 +134,5 @@ export declare function getUpdateStrategyTx(gasBudget: number, packageId: string
|
|
|
134
134
|
registry: string, strategy_pool: string, vault_index: string, signal_index: string, strategy_index: string, coins: string[], mfudPackageId: string, mfudRegistry: string, mfudAmount: string, size: string | null, price_percentage: string | null, max_times: string | null, target_rounds: string[]): TransactionBlock;
|
|
135
135
|
export declare function getCloseStrategyTx(gasBudget: number, packageId: string, typeArguments: string[], // D_TOKEN, B_TOKEN
|
|
136
136
|
registry: string, strategy_pool: string, vault_index: string, signal_index: string, strategy_index: string, mfudPackageId: string, mfudRegistry: string, sender: string): TransactionBlock;
|
|
137
|
+
export declare function getWithdrawProfitStrategyTx(gasBudget: number, packageId: string, typeArguments: string[], // D_TOKEN, B_TOKEN
|
|
138
|
+
registry: string, strategy_pool: string, vault_index: string, signal_index: string, strategy_index: string, mfudPackageId: string, mfudRegistry: string, sender: string): TransactionBlock;
|
|
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
16
16
|
return ar;
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getCloseStrategyTx = exports.getUpdateStrategyTx = exports.getNewStrategyTx = exports.getRebateTx = exports.getExerciseTx = exports.getNewBidTx = exports.getRedeemTx = exports.getHarvestTx = exports.getClaimTx = exports.getCompoundTx = exports.getUnsubscribeTx = exports.getWithdrawTx = exports.getDepositTx = void 0;
|
|
19
|
+
exports.getWithdrawProfitStrategyTx = exports.getCloseStrategyTx = exports.getUpdateStrategyTx = exports.getNewStrategyTx = exports.getRebateTx = exports.getExerciseTx = exports.getNewBidTx = exports.getRedeemTx = exports.getHarvestTx = exports.getClaimTx = exports.getCompoundTx = exports.getUnsubscribeTx = exports.getWithdrawTx = exports.getDepositTx = void 0;
|
|
20
20
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
21
21
|
var constants_1 = require("../../constants");
|
|
22
22
|
var user_entry_1 = require("./user-entry");
|
|
@@ -457,3 +457,25 @@ registry, strategy_pool, vault_index, signal_index, strategy_index, mfudPackageI
|
|
|
457
457
|
return tx;
|
|
458
458
|
}
|
|
459
459
|
exports.getCloseStrategyTx = getCloseStrategyTx;
|
|
460
|
+
function getWithdrawProfitStrategyTx(gasBudget, packageId, typeArguments, // D_TOKEN, B_TOKEN
|
|
461
|
+
registry, strategy_pool, vault_index, signal_index, strategy_index, mfudPackageId, mfudRegistry, sender) {
|
|
462
|
+
var tx = new transactions_1.TransactionBlock();
|
|
463
|
+
var d_token = tx.moveCall({
|
|
464
|
+
target: "".concat(packageId, "::auto_bid::withdraw_profit"),
|
|
465
|
+
typeArguments: typeArguments,
|
|
466
|
+
arguments: [tx.object(registry), tx.object(strategy_pool), tx.pure(vault_index), tx.pure(signal_index), tx.pure(strategy_index)],
|
|
467
|
+
});
|
|
468
|
+
if (typeArguments[0].endsWith("MFUD")) {
|
|
469
|
+
var fud_coin = tx.moveCall({
|
|
470
|
+
target: "".concat(mfudPackageId, "::mfud::burn"),
|
|
471
|
+
arguments: [tx.object(mfudRegistry), d_token],
|
|
472
|
+
});
|
|
473
|
+
tx.transferObjects([tx.object(fud_coin)], sender);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
tx.transferObjects([d_token], sender);
|
|
477
|
+
}
|
|
478
|
+
tx.setGasBudget(gasBudget);
|
|
479
|
+
return tx;
|
|
480
|
+
}
|
|
481
|
+
exports.getWithdrawProfitStrategyTx = getWithdrawProfitStrategyTx;
|
|
@@ -3,6 +3,7 @@ import { OracleInfo, VaultConfig } from "./view-function";
|
|
|
3
3
|
export declare function getVaultHistoryEvents(provider: SuiClient, originPackage: string, startTimeMs: number): Promise<SuiEvent[]>;
|
|
4
4
|
export declare function parseGroupEvents(datas: SuiEvent[]): Promise<Map<string, Map<string, GroupEvent>>>;
|
|
5
5
|
export declare function parseVaultHistory(inputMap: Map<string, Map<string, GroupEvent>>): Promise<Map<string, Map<string, VaultHistory | undefined>>>;
|
|
6
|
+
export declare function getVaultHistoryFromDB(index?: string, startTs?: string, endTs?: string): Promise<Map<string, Map<string, VaultHistory | undefined>> | undefined>;
|
|
6
7
|
export declare function convertGroupEventToVaultHistory(groupEvent: GroupEvent): Promise<VaultHistory | undefined>;
|
|
7
8
|
export interface VaultHistory {
|
|
8
9
|
vaultIndex: string;
|
|
@@ -35,8 +35,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.parseBidEvents = exports.convertGroupEventToVaultHistory = exports.parseVaultHistory = exports.parseGroupEvents = exports.getVaultHistoryEvents = void 0;
|
|
50
|
+
exports.parseBidEvents = exports.convertGroupEventToVaultHistory = exports.getVaultHistoryFromDB = exports.parseVaultHistory = exports.parseGroupEvents = exports.getVaultHistoryEvents = void 0;
|
|
40
51
|
var token_1 = require("../token");
|
|
41
52
|
function getVaultHistoryEvents(provider, originPackage, startTimeMs) {
|
|
42
53
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -200,6 +211,88 @@ function parseVaultHistory(inputMap) {
|
|
|
200
211
|
});
|
|
201
212
|
}
|
|
202
213
|
exports.parseVaultHistory = parseVaultHistory;
|
|
214
|
+
function getVaultHistoryFromDB(index, startTs, endTs) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
var apiUrl, queryParams, apiUrlWithParams, response, map, datas, datas_1, datas_1_1, data, index_1, round, vaultHistory, round_events, round_events;
|
|
217
|
+
var e_1, _a;
|
|
218
|
+
return __generator(this, function (_b) {
|
|
219
|
+
switch (_b.label) {
|
|
220
|
+
case 0:
|
|
221
|
+
apiUrl = "https://us-central1-aqueous-freedom-378103.cloudfunctions.net/vault-history";
|
|
222
|
+
queryParams = new URLSearchParams();
|
|
223
|
+
if (index) {
|
|
224
|
+
queryParams.append("index", index);
|
|
225
|
+
}
|
|
226
|
+
if (startTs) {
|
|
227
|
+
queryParams.append("startTs", startTs);
|
|
228
|
+
}
|
|
229
|
+
if (endTs) {
|
|
230
|
+
queryParams.append("endTs", endTs);
|
|
231
|
+
}
|
|
232
|
+
apiUrlWithParams = "".concat(apiUrl, "?").concat(queryParams.toString());
|
|
233
|
+
return [4 /*yield*/, fetch(apiUrlWithParams, {
|
|
234
|
+
method: "GET",
|
|
235
|
+
headers: { "Content-Type": "application/json" },
|
|
236
|
+
})];
|
|
237
|
+
case 1:
|
|
238
|
+
response = _b.sent();
|
|
239
|
+
map = new Map();
|
|
240
|
+
if (!response.ok) return [3 /*break*/, 3];
|
|
241
|
+
return [4 /*yield*/, response.json()];
|
|
242
|
+
case 2:
|
|
243
|
+
datas = _b.sent();
|
|
244
|
+
try {
|
|
245
|
+
for (datas_1 = __values(datas), datas_1_1 = datas_1.next(); !datas_1_1.done; datas_1_1 = datas_1.next()) {
|
|
246
|
+
data = datas_1_1.value;
|
|
247
|
+
index_1 = data.index;
|
|
248
|
+
round = data.round;
|
|
249
|
+
vaultHistory = {
|
|
250
|
+
vaultIndex: index_1,
|
|
251
|
+
round: round,
|
|
252
|
+
ActivationDate: new Date(Number(data.activation_date) / 1000),
|
|
253
|
+
MaxSize: data.max_size,
|
|
254
|
+
SettlementTime: new Date(Number(data.settle_date) / 1000),
|
|
255
|
+
StrikePrice: data.strikes || undefined,
|
|
256
|
+
SettlePrice: data.settle_price,
|
|
257
|
+
Return: data.return,
|
|
258
|
+
Filled: Number(data.delivery_size) == 0 ? 0 : Number(data.delivery_size) / Number(data.max_size),
|
|
259
|
+
DeliverySize: data.delivery_size,
|
|
260
|
+
DeliveryPrice: data.delivery_price,
|
|
261
|
+
PaidToDepositors: data.paid_to_depositors,
|
|
262
|
+
PaidToBidders: data.paid_to_bidders,
|
|
263
|
+
EarnedByDepositors: data.paid_to_depositors - data.paid_to_bidders,
|
|
264
|
+
ActivateTx: data.activation_tx,
|
|
265
|
+
NewAuctionTx: data.new_auction_tx,
|
|
266
|
+
DeliveryTx: data.delivery_tx,
|
|
267
|
+
RecoupTx: data.recoup_tx,
|
|
268
|
+
SettleTx: data.settle_tx,
|
|
269
|
+
};
|
|
270
|
+
if (map.has(index_1)) {
|
|
271
|
+
round_events = map.get(index_1);
|
|
272
|
+
round_events.set(round, vaultHistory);
|
|
273
|
+
map.set(index_1, round_events);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
round_events = new Map();
|
|
277
|
+
round_events.set(round, vaultHistory);
|
|
278
|
+
map.set(index_1, round_events);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
283
|
+
finally {
|
|
284
|
+
try {
|
|
285
|
+
if (datas_1_1 && !datas_1_1.done && (_a = datas_1.return)) _a.call(datas_1);
|
|
286
|
+
}
|
|
287
|
+
finally { if (e_1) throw e_1.error; }
|
|
288
|
+
}
|
|
289
|
+
return [2 /*return*/, map];
|
|
290
|
+
case 3: return [2 /*return*/];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
exports.getVaultHistoryFromDB = getVaultHistoryFromDB;
|
|
203
296
|
function convertGroupEventToVaultHistory(groupEvent) {
|
|
204
297
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
205
298
|
return __awaiter(this, void 0, void 0, function () {
|