zo-sdk 0.0.13 → 0.0.14
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/api.cjs +469 -0
- package/dist/{api.d.ts → api.d.cts} +6 -5
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +26 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +465 -0
- package/dist/consts/{index.js → index.cjs} +8 -12
- package/dist/consts/{index.d.ts → index.d.cts} +1 -0
- package/dist/consts/index.d.cts.map +1 -0
- package/dist/consts/index.d.mts +66 -0
- package/dist/consts/index.d.mts.map +1 -0
- package/dist/consts/index.mjs +92 -0
- package/dist/{data.js → data.cjs} +246 -155
- package/dist/{data.d.ts → data.d.cts} +9 -8
- package/dist/data.d.cts.map +1 -0
- package/dist/data.d.mts +221 -0
- package/dist/data.d.mts.map +1 -0
- package/dist/data.mjs +841 -0
- package/dist/{index.js → index.cjs} +5 -6
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/{oracle.js → oracle.cjs} +51 -8
- package/dist/{oracle.d.ts → oracle.d.cts} +7 -6
- package/dist/oracle.d.cts.map +1 -0
- package/dist/oracle.d.mts +24 -0
- package/dist/oracle.d.mts.map +1 -0
- package/dist/oracle.mjs +173 -0
- package/dist/{utils.js → utils.cjs} +1 -2
- package/dist/{utils.d.ts → utils.d.cts} +5 -4
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +46 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +128 -0
- package/package.json +23 -13
- package/src/consts/index.ts +1 -1
- package/tsconfig.json +19 -9
- package/babel.config.js +0 -11
- package/dist/api.js +0 -400
- package/dist/api.js.map +0 -1
- package/dist/consts/index.js.map +0 -1
- package/dist/data.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js.map +0 -1
- package/dist/oracle.js.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { reverseKeyValue } from "../utils.mjs";
|
|
2
|
+
import mainnetJson from "./deployments-mainnet.json" with { type: "json" };
|
|
3
|
+
import testnetJson from "./deployments-testnet.json" with { type: "json" };
|
|
4
|
+
import PriceIdToObjectIdMainnet from "./price_id_to_object_id.mainnet.json" with { type: "json" };
|
|
5
|
+
import PriceIdToObjectIdTestnet from "./price_id_to_object_id.testnet.json" with { type: "json" };
|
|
6
|
+
import mainnetStakingJson from "./staking/deployments-mainnet.json" with { type: "json" };
|
|
7
|
+
import testnetStakingJson from "./staking/deployments-testnet.json" with { type: "json" };
|
|
8
|
+
function toCamelCase(str) {
|
|
9
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
10
|
+
}
|
|
11
|
+
function parse(obj) {
|
|
12
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(obj)) {
|
|
16
|
+
return obj.map(parse);
|
|
17
|
+
}
|
|
18
|
+
const newObj = {};
|
|
19
|
+
for (const key in obj) {
|
|
20
|
+
const camelCaseKey = toCamelCase(key);
|
|
21
|
+
newObj[camelCaseKey] = parse(obj[key]);
|
|
22
|
+
}
|
|
23
|
+
return newObj;
|
|
24
|
+
}
|
|
25
|
+
export var Network;
|
|
26
|
+
(function (Network) {
|
|
27
|
+
Network["MAINNET"] = "mainnet";
|
|
28
|
+
Network["TESTNET"] = "testnet";
|
|
29
|
+
Network["DEVNET"] = "devnet";
|
|
30
|
+
})(Network || (Network = {}));
|
|
31
|
+
function throwNetworkError(network) {
|
|
32
|
+
throw new Error(`Unknown network: ${network}`);
|
|
33
|
+
}
|
|
34
|
+
export function getConsts(network) {
|
|
35
|
+
switch (network) {
|
|
36
|
+
case Network.TESTNET: {
|
|
37
|
+
return { ...parse(testnetJson), ...parse(testnetStakingJson) };
|
|
38
|
+
}
|
|
39
|
+
case Network.MAINNET: {
|
|
40
|
+
return { ...parse(mainnetJson), ...parse(mainnetStakingJson) };
|
|
41
|
+
}
|
|
42
|
+
default: {
|
|
43
|
+
return throwNetworkError(network);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export const ZLP_TOKEN_DECIMALS = 6;
|
|
48
|
+
export const SECONDS_PER_EIGHT_HOUR = 8 * 60 * 60;
|
|
49
|
+
export function getPythFeederToPriceId(network) {
|
|
50
|
+
switch (network) {
|
|
51
|
+
case Network.TESTNET: {
|
|
52
|
+
return reverseKeyValue(PriceIdToObjectIdTestnet);
|
|
53
|
+
}
|
|
54
|
+
case Network.MAINNET: {
|
|
55
|
+
return reverseKeyValue(PriceIdToObjectIdMainnet);
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
return throwNetworkError(network);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function getPriceIdToPythFeeder(network) {
|
|
63
|
+
let priceIdToFeeder = {};
|
|
64
|
+
switch (network) {
|
|
65
|
+
case Network.TESTNET: {
|
|
66
|
+
priceIdToFeeder = PriceIdToObjectIdTestnet;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case Network.MAINNET: {
|
|
70
|
+
priceIdToFeeder = PriceIdToObjectIdMainnet;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
throw new Error(`Unknown network: ${network}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return priceIdToFeeder;
|
|
78
|
+
}
|
|
79
|
+
export function getPythFeederToId(network) {
|
|
80
|
+
let feederToId = {};
|
|
81
|
+
const consts = getConsts(network);
|
|
82
|
+
for (const key in consts.pythFeeder.feeder) {
|
|
83
|
+
if (Object.prototype.hasOwnProperty.call(consts.pythFeeder.feeder, key)) {
|
|
84
|
+
const contract = consts.pythFeeder.feeder[key];
|
|
85
|
+
feederToId[contract] = key;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return feederToId;
|
|
89
|
+
}
|
|
90
|
+
export const ALLOW_TRADE_NO_TRADE = 0;
|
|
91
|
+
export const ALLOW_TRADE_CAN_TRADE = 1;
|
|
92
|
+
export const ALLOW_TRADE_MUST_TRADE = 2;
|
|
@@ -9,96 +9,158 @@ var _DataAPI_instances, _DataAPI_parseMarketInfo, _DataAPI_parseVaultInfo, _Data
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.DataAPI = void 0;
|
|
11
11
|
const utils_1 = require("@mysten/sui/utils");
|
|
12
|
-
const consts_1 = require("./consts");
|
|
13
|
-
const oracle_1 = require("./oracle");
|
|
14
|
-
const utils_2 = require("./utils");
|
|
12
|
+
const consts_1 = require("./consts/index.cjs");
|
|
13
|
+
const oracle_1 = require("./oracle.cjs");
|
|
14
|
+
const utils_2 = require("./utils.cjs");
|
|
15
15
|
;
|
|
16
16
|
class DataAPI extends oracle_1.OracleAPI {
|
|
17
17
|
constructor(network, provider, apiEndpoint, connectionURL) {
|
|
18
18
|
super(network, provider, connectionURL);
|
|
19
19
|
_DataAPI_instances.add(this);
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
Object.defineProperty(this, "provider", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "apiEndpoint", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "vaultInfoCache", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: {}
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "symbolInfoCache", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: {}
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "marketInfoCache", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: null
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(this, "positionConfigCache", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: {}
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "rebaseFeeModelCache", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: null
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "lastUpdate", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "validateCache", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: () => {
|
|
73
|
+
super.validateCache();
|
|
74
|
+
if (this.lastUpdate + 1000 * 60 * 3 < Date.now()) {
|
|
75
|
+
this.lastUpdate = Date.now();
|
|
76
|
+
this.vaultInfoCache = {};
|
|
77
|
+
this.symbolInfoCache = {};
|
|
78
|
+
this.marketInfoCache = null;
|
|
79
|
+
this.positionConfigCache = {};
|
|
80
|
+
this.rebaseFeeModelCache = null;
|
|
81
|
+
}
|
|
35
82
|
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
for (const key of Object.keys(this.consts.zoCore.vaults)) {
|
|
47
|
-
const vault = this.consts.zoCore.vaults[key];
|
|
48
|
-
tx.moveCall({
|
|
49
|
-
// todo
|
|
50
|
-
target: `${this.consts.zoCore.package}::market::valuate_vault`,
|
|
51
|
-
typeArguments: [
|
|
52
|
-
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
53
|
-
this.consts.coins[key].module,
|
|
54
|
-
],
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "valuateVaults", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: (tx) => {
|
|
89
|
+
const vaultsValuation = tx.moveCall({
|
|
90
|
+
target: `${this.consts.zoCore.package}::market::create_vaults_valuation`,
|
|
91
|
+
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`],
|
|
55
92
|
arguments: [
|
|
93
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
56
94
|
tx.object(this.consts.zoCore.market),
|
|
57
|
-
tx.object(vault.reservingFeeModel),
|
|
58
|
-
tx.object(this.consts.pythFeeder.feeder[key]),
|
|
59
|
-
vaultsValuation,
|
|
60
95
|
],
|
|
61
96
|
});
|
|
97
|
+
for (const key of Object.keys(this.consts.zoCore.vaults)) {
|
|
98
|
+
const vault = this.consts.zoCore.vaults[key];
|
|
99
|
+
tx.moveCall({
|
|
100
|
+
// todo
|
|
101
|
+
target: `${this.consts.zoCore.package}::market::valuate_vault`,
|
|
102
|
+
typeArguments: [
|
|
103
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
104
|
+
this.consts.coins[key].module,
|
|
105
|
+
],
|
|
106
|
+
arguments: [
|
|
107
|
+
tx.object(this.consts.zoCore.market),
|
|
108
|
+
tx.object(vault.reservingFeeModel),
|
|
109
|
+
tx.object(this.consts.pythFeeder.feeder[key]),
|
|
110
|
+
vaultsValuation,
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return vaultsValuation;
|
|
62
115
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
],
|
|
73
|
-
});
|
|
74
|
-
for (const key of Object.keys(this.consts.zoCore.symbols)) {
|
|
75
|
-
const [direction, token] = (0, utils_2.parseSymbolKey)(key);
|
|
76
|
-
const symbol = this.consts.zoCore.symbols[key];
|
|
77
|
-
tx.moveCall({
|
|
78
|
-
target: `${this.consts.zoCore.package}::market::valuate_symbol`,
|
|
79
|
-
typeArguments: [
|
|
80
|
-
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
81
|
-
this.consts.coins[token].module,
|
|
82
|
-
`${this.consts.zoCore.package}::market::${direction.toUpperCase()}`,
|
|
83
|
-
],
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(this, "valuateSymbols", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
writable: true,
|
|
121
|
+
value: (tx) => {
|
|
122
|
+
const symbolsValuation = tx.moveCall({
|
|
123
|
+
target: `${this.consts.zoCore.package}::market::create_symbols_valuation`,
|
|
124
|
+
typeArguments: [`${this.consts.zoCore.package}::zlp::ZLP`],
|
|
84
125
|
arguments: [
|
|
126
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
85
127
|
tx.object(this.consts.zoCore.market),
|
|
86
|
-
tx.object(symbol.fundingFeeModel),
|
|
87
|
-
tx.object(this.consts.pythFeeder.feeder[token]),
|
|
88
|
-
symbolsValuation,
|
|
89
128
|
],
|
|
90
129
|
});
|
|
130
|
+
for (const key of Object.keys(this.consts.zoCore.symbols)) {
|
|
131
|
+
const [direction, token] = (0, utils_2.parseSymbolKey)(key);
|
|
132
|
+
const symbol = this.consts.zoCore.symbols[key];
|
|
133
|
+
tx.moveCall({
|
|
134
|
+
target: `${this.consts.zoCore.package}::market::valuate_symbol`,
|
|
135
|
+
typeArguments: [
|
|
136
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
137
|
+
this.consts.coins[token].module,
|
|
138
|
+
`${this.consts.zoCore.package}::market::${direction.toUpperCase()}`,
|
|
139
|
+
],
|
|
140
|
+
arguments: [
|
|
141
|
+
tx.object(this.consts.zoCore.market),
|
|
142
|
+
tx.object(symbol.fundingFeeModel),
|
|
143
|
+
tx.object(this.consts.pythFeeder.feeder[token]),
|
|
144
|
+
symbolsValuation,
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return symbolsValuation;
|
|
91
149
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
vaultsValuation
|
|
99
|
-
symbolsValuation
|
|
100
|
-
|
|
101
|
-
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(this, "valuate", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: true,
|
|
154
|
+
writable: true,
|
|
155
|
+
value: (tx) => {
|
|
156
|
+
const vaultsValuation = this.valuateVaults(tx);
|
|
157
|
+
const symbolsValuation = this.valuateSymbols(tx);
|
|
158
|
+
return {
|
|
159
|
+
vaultsValuation,
|
|
160
|
+
symbolsValuation,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
102
164
|
_DataAPI_parseVaultInfo.set(this, async (raw) => {
|
|
103
165
|
const vaultFields = raw.data.content.fields.value.fields;
|
|
104
166
|
const reservingFeeModelAddr = vaultFields.reserving_fee_model;
|
|
@@ -156,89 +218,119 @@ class DataAPI extends oracle_1.OracleAPI {
|
|
|
156
218
|
},
|
|
157
219
|
};
|
|
158
220
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
amount = -amount;
|
|
221
|
+
Object.defineProperty(this, "fundingFeeRate", {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
configurable: true,
|
|
224
|
+
writable: true,
|
|
225
|
+
value: async (indexToken, long) => {
|
|
226
|
+
const symbol = await this.getSymbolInfo(indexToken, long);
|
|
227
|
+
if (symbol.lastUpdate <= 0) {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
const price = (await this.getOraclePrice(indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked();
|
|
231
|
+
const lpSupplyAmount = (await this.getMarketInfo()).lpSupplyWithDecimals;
|
|
232
|
+
const model = symbol.fundingFeeModel;
|
|
233
|
+
const elapsed = consts_1.SECONDS_PER_EIGHT_HOUR;
|
|
234
|
+
const deltaSize = __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_calcDeltaSize).call(this, symbol, price);
|
|
235
|
+
const pnlPerLp = (symbol.realisedPnl + symbol.unrealisedFundingFeeValue + deltaSize) / lpSupplyAmount;
|
|
236
|
+
return __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_calcFundingFeeRate).call(this, model, pnlPerLp, elapsed);
|
|
176
237
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
238
|
+
});
|
|
239
|
+
Object.defineProperty(this, "rebaseFeeRate", {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
configurable: true,
|
|
242
|
+
writable: true,
|
|
243
|
+
value: async (collateralToken, increase, amount) => {
|
|
244
|
+
let vaultValue = 0;
|
|
245
|
+
if (!increase && amount > 0) {
|
|
246
|
+
amount = -amount;
|
|
184
247
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
248
|
+
const value = amount * (await this.getOraclePrice(collateralToken)).getPriceUnchecked().getPriceAsNumberUnchecked() / (10 ** this.consts.coins[collateralToken].decimals);
|
|
249
|
+
const vaultPromises = Object.keys(this.consts.zoCore.vaults).map(async (vault) => {
|
|
250
|
+
const vaultInfo = await this.getVaultInfo(vault);
|
|
251
|
+
const reservingFeeDelta = __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_calculateVaultReservingFee).call(this, vaultInfo, vaultInfo.reservingFeeModel, Date.now() / 1000);
|
|
252
|
+
const res = (reservingFeeDelta + vaultInfo.liquidity + vaultInfo.reservedAmount) * (await this.getOraclePrice(vault)).getPriceUnchecked().getPriceAsNumberUnchecked() / (10 ** this.consts.coins[vault].decimals);
|
|
253
|
+
if (collateralToken === vault) {
|
|
254
|
+
vaultValue = res;
|
|
255
|
+
}
|
|
256
|
+
return res;
|
|
257
|
+
});
|
|
258
|
+
const vaultValues = await Promise.all(vaultPromises);
|
|
259
|
+
const totalVaultValue = vaultValues.reduce((acc, curr) => acc + curr, 0);
|
|
260
|
+
const targetRatio = Number.parseInt(this.consts.zoCore.vaults[collateralToken].weight, 10) / Object.values(this.consts.zoCore.vaults)
|
|
261
|
+
.map(e => Number.parseInt(e.weight, 10))
|
|
262
|
+
.reduce((acc, curr) => acc + curr, 0);
|
|
263
|
+
return __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_calcRebaseFeeRate).call(this, await this.getRebaseFeeModel(), increase, (vaultValue + value) / (totalVaultValue + value), targetRatio);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
Object.defineProperty(this, "reservingFeeRate", {
|
|
267
|
+
enumerable: true,
|
|
268
|
+
configurable: true,
|
|
269
|
+
writable: true,
|
|
270
|
+
value: async (collateralToken, amount = 0) => {
|
|
271
|
+
const vaultInfo = await this.getVaultInfo(collateralToken);
|
|
272
|
+
const vaultSupply = vaultInfo.liquidity + vaultInfo.reservedAmount + vaultInfo.unrealisedReservingFeeAmount + amount;
|
|
273
|
+
const utilization = vaultSupply ? ((vaultInfo.reservedAmount + amount) / vaultSupply) : 0;
|
|
274
|
+
return __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_calcReservingFeeRate).call(this, vaultInfo.reservingFeeModel, utilization, consts_1.SECONDS_PER_EIGHT_HOUR);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(this, "getProxiedHistories", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
configurable: true,
|
|
280
|
+
writable: true,
|
|
281
|
+
value: async (trader) => {
|
|
282
|
+
const url = `${this.apiEndpoint}/traderEvents?trader=${trader}`;
|
|
283
|
+
const res = await fetch(url, {
|
|
284
|
+
method: 'GET',
|
|
285
|
+
headers: {
|
|
286
|
+
'Content-Type': 'application/json',
|
|
218
287
|
},
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
288
|
+
});
|
|
289
|
+
const historyInfoList = await res.json();
|
|
290
|
+
return historyInfoList;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(this, "getStaked", {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
configurable: true,
|
|
296
|
+
writable: true,
|
|
297
|
+
value: async (owner) => {
|
|
298
|
+
const rawCredentials = await this.provider.getOwnedObjects({
|
|
299
|
+
owner,
|
|
300
|
+
filter: {
|
|
301
|
+
MoveModule: {
|
|
302
|
+
package: this.consts.zoStaking.package,
|
|
303
|
+
module: 'pool',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
options: {
|
|
307
|
+
showType: true,
|
|
308
|
+
showContent: true,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
const pool = await this.getStakePool();
|
|
312
|
+
const credentials = rawCredentials.data.map((item) => __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_parseCredential).call(this, item, pool));
|
|
313
|
+
return {
|
|
314
|
+
credentials,
|
|
315
|
+
amount: credentials.reduce((acc, cur) => acc + cur.amount, BigInt(0)),
|
|
316
|
+
claimable: credentials.reduce((acc, cur) => acc + cur.claimable, BigInt(0)),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
Object.defineProperty(this, "getStakePool", {
|
|
321
|
+
enumerable: true,
|
|
322
|
+
configurable: true,
|
|
323
|
+
writable: true,
|
|
324
|
+
value: async () => {
|
|
325
|
+
const raw = await this.provider.getObject({
|
|
326
|
+
id: this.consts.zoStaking.pool,
|
|
327
|
+
options: {
|
|
328
|
+
showContent: true,
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
return __classPrivateFieldGet(this, _DataAPI_instances, "m", _DataAPI_parseStakePool).call(this, raw);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
242
334
|
this.provider = provider || (0, utils_2.createJsonRpcProvider)(network);
|
|
243
335
|
this.apiEndpoint = apiEndpoint;
|
|
244
336
|
}
|
|
@@ -751,4 +843,3 @@ _DataAPI_parseVaultInfo = new WeakMap(), _DataAPI_parseSymbolInfo = new WeakMap(
|
|
|
751
843
|
const rewardPerShare = rewardAmount * BigInt(1e18) / pool.stakedAmount;
|
|
752
844
|
pool.accRewardPerShare += rewardPerShare;
|
|
753
845
|
};
|
|
754
|
-
//# sourceMappingURL=data.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SuiClient } from
|
|
2
|
-
import type { Transaction } from
|
|
3
|
-
import type { Network } from
|
|
4
|
-
import { OracleAPI } from
|
|
1
|
+
import type { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
import type { Network } from "./consts/index.cjs";
|
|
4
|
+
import { OracleAPI } from "./oracle.cjs";
|
|
5
5
|
export interface IMarketInfo {
|
|
6
6
|
lpSupply: string;
|
|
7
7
|
positionId: string;
|
|
@@ -182,11 +182,11 @@ export declare class DataAPI extends OracleAPI {
|
|
|
182
182
|
private lastUpdate;
|
|
183
183
|
constructor(network: Network, provider: SuiClient | null, apiEndpoint: string, connectionURL: string);
|
|
184
184
|
validateCache: () => void;
|
|
185
|
-
valuateVaults: (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
186
|
-
valuateSymbols: (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
|
|
185
|
+
valuateVaults: (tx: Transaction) => import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
186
|
+
valuateSymbols: (tx: Transaction) => import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
187
187
|
valuate: (tx: Transaction) => {
|
|
188
|
-
vaultsValuation: import("@mysten/sui/transactions").TransactionResult;
|
|
189
|
-
symbolsValuation: import("@mysten/sui/transactions").TransactionResult;
|
|
188
|
+
vaultsValuation: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
189
|
+
symbolsValuation: import("@mysten/sui/dist/cjs/transactions").TransactionResult;
|
|
190
190
|
};
|
|
191
191
|
getPastFee(days?: number): Promise<number>;
|
|
192
192
|
valuateMarket(): Promise<IMarketValuationInfo>;
|
|
@@ -218,3 +218,4 @@ export declare class DataAPI extends OracleAPI {
|
|
|
218
218
|
getReferrerDetail(referrer: string): Promise<any>;
|
|
219
219
|
getReferralTxs(referrer: string): Promise<any>;
|
|
220
220
|
}
|
|
221
|
+
//# sourceMappingURL=data.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.cts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,2BAA0B;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAgC;AAG3D,OAAO,KAAK,EAAE,OAAO,EAAE,2BAAgB;AAEvC,OAAO,EAAE,SAAS,EAAE,qBAAgB;AAGpC,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,oBAAoB,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,4BAA4B,EAAE,MAAM,CAAA;IACpC,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,kBAAkB,CAAA;IACrC,W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