@typus/typus-sdk 1.7.3 → 1.7.4
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.
|
@@ -336,7 +336,7 @@ exports.tokenType = {
|
|
|
336
336
|
JPY: "0xf6b1411610d6416f5bff08750262169fb6447eaf45750943cb89eb86fbf6542f::jpy::JPY",
|
|
337
337
|
XAU: "0x3ec6cda6b1d7003290004674e82d56530f354b4754f63334cf988a1bcd5535a4::xau::XAU",
|
|
338
338
|
HAEDAL: "",
|
|
339
|
-
xBTC: "",
|
|
339
|
+
xBTC: "0x8ec68007c61b79244decfecc7f1e024ff60a9354dcb1ff37af94ad03f7e71d2e::xbtc::XBTC",
|
|
340
340
|
DOGE: "",
|
|
341
341
|
HYPE: "",
|
|
342
342
|
XRP: "",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
import { TypusConfig } from "../../src/utils";
|
|
3
|
+
/**
|
|
4
|
+
entry fun add_otc_config(
|
|
5
|
+
registry: &mut Registry,
|
|
6
|
+
user: address,
|
|
7
|
+
index: u64,
|
|
8
|
+
round: u64,
|
|
9
|
+
size: u64,
|
|
10
|
+
price: u64,
|
|
11
|
+
fee_bp: u64,
|
|
12
|
+
expiration_ts_ms: u64,
|
|
13
|
+
ctx: &mut TxContext,
|
|
14
|
+
) {
|
|
15
|
+
*/
|
|
16
|
+
export declare function addOtcConfig(config: TypusConfig, tx: Transaction, input: {
|
|
17
|
+
user: string;
|
|
18
|
+
index: string;
|
|
19
|
+
round: string;
|
|
20
|
+
size: string;
|
|
21
|
+
price: string;
|
|
22
|
+
fee_bp: string;
|
|
23
|
+
expiration_ts_ms: string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
entry fun remove_otc_config(
|
|
27
|
+
registry: &mut Registry,
|
|
28
|
+
user: address,
|
|
29
|
+
index: u64,
|
|
30
|
+
ctx: &TxContext,
|
|
31
|
+
) {
|
|
32
|
+
*/
|
|
33
|
+
export declare function removeOtcConfig(config: TypusConfig, tx: Transaction, input: {
|
|
34
|
+
user: string;
|
|
35
|
+
index: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
public fun otc<D_TOKEN, B_TOKEN>(
|
|
39
|
+
registry: &mut Registry,
|
|
40
|
+
index: u64,
|
|
41
|
+
mut balance: Balance<B_TOKEN>,
|
|
42
|
+
clock: &Clock,
|
|
43
|
+
ctx: &mut TxContext,
|
|
44
|
+
) {
|
|
45
|
+
*/
|
|
46
|
+
export declare function otc(config: TypusConfig, tx: Transaction, input: {
|
|
47
|
+
typeArguments: string[];
|
|
48
|
+
index: string;
|
|
49
|
+
coins: string[];
|
|
50
|
+
amount: string;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
export interface OtcConfig {
|
|
53
|
+
round: string;
|
|
54
|
+
size: string;
|
|
55
|
+
price: string;
|
|
56
|
+
fee_bp: string;
|
|
57
|
+
expiration_ts_ms: string;
|
|
58
|
+
u64Padding: string[];
|
|
59
|
+
}
|
|
60
|
+
export declare function getUserOtcConfigs(config: TypusConfig, input: {
|
|
61
|
+
user: string;
|
|
62
|
+
indexes: string[];
|
|
63
|
+
}): Promise<OtcConfig[]>;
|
|
@@ -0,0 +1,169 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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.addOtcConfig = addOtcConfig;
|
|
40
|
+
exports.removeOtcConfig = removeOtcConfig;
|
|
41
|
+
exports.otc = otc;
|
|
42
|
+
exports.getUserOtcConfigs = getUserOtcConfigs;
|
|
43
|
+
var transactions_1 = require("@mysten/sui/transactions");
|
|
44
|
+
var client_1 = require("@mysten/sui/client");
|
|
45
|
+
var constants_1 = require("../../src/constants");
|
|
46
|
+
var utils_1 = require("../../src/utils");
|
|
47
|
+
var bcs_1 = require("@mysten/bcs");
|
|
48
|
+
var constants_2 = require("../../src/constants");
|
|
49
|
+
/**
|
|
50
|
+
entry fun add_otc_config(
|
|
51
|
+
registry: &mut Registry,
|
|
52
|
+
user: address,
|
|
53
|
+
index: u64,
|
|
54
|
+
round: u64,
|
|
55
|
+
size: u64,
|
|
56
|
+
price: u64,
|
|
57
|
+
fee_bp: u64,
|
|
58
|
+
expiration_ts_ms: u64,
|
|
59
|
+
ctx: &mut TxContext,
|
|
60
|
+
) {
|
|
61
|
+
*/
|
|
62
|
+
function addOtcConfig(config, tx, input) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
tx.moveCall({
|
|
66
|
+
target: "".concat(config.package.dovSingle, "::tds_otc_entry::add_otc_config"),
|
|
67
|
+
typeArguments: [],
|
|
68
|
+
arguments: [
|
|
69
|
+
tx.object(config.registry.dov.dovSingle),
|
|
70
|
+
tx.pure.address(input.user),
|
|
71
|
+
tx.pure.u64(input.index),
|
|
72
|
+
tx.pure.u64(input.round),
|
|
73
|
+
tx.pure.u64(input.size),
|
|
74
|
+
tx.pure.u64(input.price),
|
|
75
|
+
tx.pure.u64(input.fee_bp),
|
|
76
|
+
tx.pure.u64(input.expiration_ts_ms),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
entry fun remove_otc_config(
|
|
85
|
+
registry: &mut Registry,
|
|
86
|
+
user: address,
|
|
87
|
+
index: u64,
|
|
88
|
+
ctx: &TxContext,
|
|
89
|
+
) {
|
|
90
|
+
*/
|
|
91
|
+
function removeOtcConfig(config, tx, input) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
tx.moveCall({
|
|
95
|
+
target: "".concat(config.package.dovSingle, "::tds_otc_entry::remove_otc_config"),
|
|
96
|
+
typeArguments: [],
|
|
97
|
+
arguments: [tx.object(config.registry.dov.dovSingle), tx.pure.address(input.user), tx.pure.u64(input.index)],
|
|
98
|
+
});
|
|
99
|
+
return [2 /*return*/];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
public fun otc<D_TOKEN, B_TOKEN>(
|
|
105
|
+
registry: &mut Registry,
|
|
106
|
+
index: u64,
|
|
107
|
+
mut balance: Balance<B_TOKEN>,
|
|
108
|
+
clock: &Clock,
|
|
109
|
+
ctx: &mut TxContext,
|
|
110
|
+
) {
|
|
111
|
+
*/
|
|
112
|
+
function otc(config, tx, input) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
+
var coin, balance;
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
coin = (0, utils_1.splitCoins)(tx, input.typeArguments[0], input.coins, input.amount);
|
|
117
|
+
balance = tx.moveCall({
|
|
118
|
+
target: "0x2::coin::into_balance",
|
|
119
|
+
typeArguments: [input.typeArguments[0]],
|
|
120
|
+
arguments: [tx.object(coin)],
|
|
121
|
+
});
|
|
122
|
+
tx.moveCall({
|
|
123
|
+
target: "".concat(config.package.dovSingle, "::tds_otc_entry::otc"),
|
|
124
|
+
typeArguments: [],
|
|
125
|
+
arguments: [tx.object(config.registry.dov.dovSingle), tx.pure.u64(input.index), tx.object(balance), tx.object(constants_1.CLOCK)],
|
|
126
|
+
});
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function getUserOtcConfigs(config, input) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var provider, transaction, results, bytes, reader;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
provider = new client_1.SuiClient({ url: config.rpcEndpoint });
|
|
138
|
+
transaction = new transactions_1.Transaction();
|
|
139
|
+
transaction.moveCall({
|
|
140
|
+
target: "".concat(config.package.dovSingle, "::tds_otc_entry::get_user_otc_configs"),
|
|
141
|
+
typeArguments: [],
|
|
142
|
+
arguments: [
|
|
143
|
+
transaction.object(config.registry.safu.safu),
|
|
144
|
+
transaction.pure.address(input.user),
|
|
145
|
+
transaction.pure.vector("u64", input.indexes),
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
return [4 /*yield*/, provider.devInspectTransactionBlock({ transactionBlock: transaction, sender: constants_2.SENDER })];
|
|
149
|
+
case 1:
|
|
150
|
+
results = (_a.sent()).results;
|
|
151
|
+
bytes = results[results.length - 1].returnValues[0][0];
|
|
152
|
+
reader = new bcs_1.BcsReader(new Uint8Array(bytes));
|
|
153
|
+
return [2 /*return*/, reader.readVec(function (reader) {
|
|
154
|
+
reader.readULEB();
|
|
155
|
+
return {
|
|
156
|
+
round: reader.read64(),
|
|
157
|
+
size: reader.read64(),
|
|
158
|
+
price: reader.read64(),
|
|
159
|
+
fee_bp: reader.read64(),
|
|
160
|
+
expiration_ts_ms: reader.read64(),
|
|
161
|
+
u64Padding: reader.readVec(function (reader) {
|
|
162
|
+
return reader.read64();
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
})];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|