aftermath-ts-sdk 2.0.0-temp.2 → 2.0.1
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/index.d.ts +290 -32
- package/dist/index.js +293 -254
- package/dist/index.js.map +1 -1
- package/package.json +68 -69
package/dist/index.js
CHANGED
|
@@ -126,7 +126,6 @@ var init_dynamicFieldsApiHelpers = __esm({
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
// src/general/apiHelpers/eventsApiHelpers.ts
|
|
129
|
-
import dayjs from "dayjs";
|
|
130
129
|
var _EventsApiHelpers, EventsApiHelpers;
|
|
131
130
|
var init_eventsApiHelpers = __esm({
|
|
132
131
|
"src/general/apiHelpers/eventsApiHelpers.ts"() {
|
|
@@ -158,71 +157,56 @@ var init_eventsApiHelpers = __esm({
|
|
|
158
157
|
const { query, eventFromEventOnChain, cursor, limit } = inputs;
|
|
159
158
|
const fetchedEvents = await this.Provider.provider.queryEvents({
|
|
160
159
|
query,
|
|
161
|
-
cursor: cursor ? {
|
|
162
|
-
...cursor,
|
|
163
|
-
eventSeq: cursor?.eventSeq.toString()
|
|
164
|
-
} : void 0,
|
|
160
|
+
cursor: cursor ? { ...cursor, eventSeq: cursor.eventSeq.toString() } : void 0,
|
|
165
161
|
limit
|
|
166
|
-
// defaultlimit ?
|
|
167
162
|
});
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
(event) => eventFromEventOnChain(event)
|
|
171
|
-
);
|
|
172
|
-
const nextCursor = fetchedEvents.nextCursor ?? null;
|
|
173
|
-
return { events, nextCursor };
|
|
163
|
+
const events = fetchedEvents.data.map(eventFromEventOnChain);
|
|
164
|
+
return { events, nextCursor: fetchedEvents.nextCursor ?? null };
|
|
174
165
|
};
|
|
175
166
|
// TODO: make this function use timestamp passing as one of event filter args
|
|
176
167
|
this.fetchEventsWithinTime = async (inputs) => {
|
|
177
|
-
const { fetchEventsFunc,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let cursor
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
limit: limitStepSize ?? _EventsApiHelpers.constants.defaultLimitStepSize
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
const events = eventsWithCursor.events;
|
|
189
|
-
const now = Date.now();
|
|
190
|
-
const endIndex = events.findIndex((event) => {
|
|
191
|
-
if (event.timestamp === void 0) return false;
|
|
192
|
-
const eventDate = dayjs.unix(event.timestamp / 1e3);
|
|
193
|
-
return dayjs(now).diff(eventDate, timeUnit, true) > time;
|
|
168
|
+
const { fetchEventsFunc, timeMs, limitStepSize } = inputs;
|
|
169
|
+
const limit = limitStepSize ?? _EventsApiHelpers.constants.defaultLimitStepSize;
|
|
170
|
+
const eventsWithinTime = [];
|
|
171
|
+
let cursor;
|
|
172
|
+
for (let loopCount = 0; loopCount < _EventsApiHelpers.constants.maxLoops; loopCount++) {
|
|
173
|
+
const { events, nextCursor } = await fetchEventsFunc({
|
|
174
|
+
cursor,
|
|
175
|
+
limit
|
|
194
176
|
});
|
|
195
|
-
|
|
196
|
-
|
|
177
|
+
const now = Date.now();
|
|
178
|
+
const endIndex = events.findIndex(
|
|
179
|
+
(event) => event.timestamp !== void 0 && now - event.timestamp > timeMs
|
|
180
|
+
);
|
|
181
|
+
eventsWithinTime.push(
|
|
197
182
|
...endIndex < 0 ? events : events.slice(0, endIndex)
|
|
198
|
-
|
|
199
|
-
if (events.length === 0 ||
|
|
200
|
-
eventsWithCursor.nextCursor === null || endIndex >= 0)
|
|
201
|
-
return eventsWithinTime;
|
|
202
|
-
cursor = eventsWithCursor.nextCursor;
|
|
203
|
-
loopCount += 1;
|
|
204
|
-
if (loopCount >= _EventsApiHelpers.constants.maxLoops) {
|
|
183
|
+
);
|
|
184
|
+
if (events.length === 0 || nextCursor === null || endIndex >= 0) {
|
|
205
185
|
return eventsWithinTime;
|
|
206
186
|
}
|
|
207
|
-
|
|
187
|
+
cursor = nextCursor;
|
|
188
|
+
}
|
|
189
|
+
return eventsWithinTime;
|
|
208
190
|
};
|
|
209
191
|
this.fetchAllEvents = async (inputs) => {
|
|
210
192
|
const { fetchEventsFunc, limitStepSize } = inputs;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
193
|
+
const limit = limitStepSize ?? _EventsApiHelpers.constants.defaultLimitStepSize;
|
|
194
|
+
const allEvents = [];
|
|
195
|
+
let cursor;
|
|
196
|
+
let done = false;
|
|
197
|
+
while (!done) {
|
|
198
|
+
const { events, nextCursor } = await fetchEventsFunc({
|
|
199
|
+
cursor,
|
|
200
|
+
limit
|
|
201
|
+
});
|
|
202
|
+
allEvents.push(...events);
|
|
203
|
+
if (events.length === 0 || nextCursor === null) {
|
|
204
|
+
done = true;
|
|
205
|
+
} else {
|
|
206
|
+
cursor = nextCursor;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return allEvents;
|
|
226
210
|
};
|
|
227
211
|
}
|
|
228
212
|
};
|
|
@@ -239,34 +223,21 @@ var init_eventsApiHelpers = __esm({
|
|
|
239
223
|
// =========================================================================
|
|
240
224
|
// Helpers
|
|
241
225
|
// =========================================================================
|
|
242
|
-
_EventsApiHelpers.
|
|
243
|
-
|
|
244
|
-
event.type.includes(
|
|
245
|
-
typeof eventType === "string" ? eventType : eventType()
|
|
246
|
-
) ? event : void 0
|
|
247
|
-
);
|
|
226
|
+
_EventsApiHelpers.resolveEventType = (eventType) => typeof eventType === "string" ? eventType : eventType();
|
|
227
|
+
_EventsApiHelpers.suiEventOfTypeOrUndefined = (event, eventType) => event.type.includes(_EventsApiHelpers.resolveEventType(eventType)) ? event : void 0;
|
|
248
228
|
_EventsApiHelpers.castEventOfTypeOrUndefined = (event, eventType, castFunction, exactMatch) => {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
const castedEvent = castFunction(event);
|
|
254
|
-
return castedEvent;
|
|
229
|
+
const resolved = _EventsApiHelpers.resolveEventType(eventType);
|
|
230
|
+
const matches = exactMatch ? event.type === resolved : event.type.includes(resolved);
|
|
231
|
+
if (!matches) return void 0;
|
|
232
|
+
return castFunction(event);
|
|
255
233
|
};
|
|
256
234
|
_EventsApiHelpers.findCastEventsOrUndefined = (inputs) => {
|
|
257
235
|
const { events, eventType, castFunction } = inputs;
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
);
|
|
261
|
-
const castedEvents = foundEvents.map(
|
|
262
|
-
(event) => castFunction(event)
|
|
263
|
-
);
|
|
264
|
-
return castedEvents;
|
|
236
|
+
const resolved = _EventsApiHelpers.resolveEventType(eventType);
|
|
237
|
+
return events.filter((event) => event.type.includes(resolved)).map((event) => castFunction(event));
|
|
265
238
|
};
|
|
266
239
|
_EventsApiHelpers.findCastEventOrUndefined = (inputs) => {
|
|
267
|
-
|
|
268
|
-
if (events.length <= 0) return;
|
|
269
|
-
return events[0];
|
|
240
|
+
return _EventsApiHelpers.findCastEventsOrUndefined(inputs)[0];
|
|
270
241
|
};
|
|
271
242
|
_EventsApiHelpers.findCastEventInTransactionOrUndefined = (transaction, eventType, castFunction) => {
|
|
272
243
|
return _EventsApiHelpers.findCastEventOrUndefined({
|
|
@@ -276,15 +247,15 @@ var init_eventsApiHelpers = __esm({
|
|
|
276
247
|
});
|
|
277
248
|
};
|
|
278
249
|
_EventsApiHelpers.findCastEventInTransactionsOrUndefined = (transactions, eventType, castFunction) => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
(transaction) => _EventsApiHelpers.findCastEventInTransactionOrUndefined(
|
|
250
|
+
for (const transaction of transactions) {
|
|
251
|
+
const event = _EventsApiHelpers.findCastEventInTransactionOrUndefined(
|
|
282
252
|
transaction,
|
|
283
253
|
eventType,
|
|
284
254
|
castFunction
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
|
|
255
|
+
);
|
|
256
|
+
if (event !== void 0) return event;
|
|
257
|
+
}
|
|
258
|
+
return void 0;
|
|
288
259
|
};
|
|
289
260
|
_EventsApiHelpers.createEventType = (packageAddress, packageName, eventType, wrapperType) => {
|
|
290
261
|
const innerType = `${packageAddress}::${packageName}::${eventType}`;
|
|
@@ -2721,8 +2692,8 @@ var init_nftsApiCasting = __esm({
|
|
|
2721
2692
|
offChain: "creator"
|
|
2722
2693
|
}
|
|
2723
2694
|
];
|
|
2724
|
-
|
|
2725
|
-
|
|
2695
|
+
const suggested = {};
|
|
2696
|
+
const other = Helpers.deepCopy(fields);
|
|
2726
2697
|
for (const field of suggestedFields) {
|
|
2727
2698
|
if (!(field.onChain in other)) continue;
|
|
2728
2699
|
suggested[field.offChain] = other[field.onChain];
|
|
@@ -3574,12 +3545,12 @@ var init_transactionsApiHelpers = __esm({
|
|
|
3574
3545
|
});
|
|
3575
3546
|
|
|
3576
3547
|
// src/general/utils/helpers.ts
|
|
3577
|
-
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
3578
3548
|
import { decodeSuiPrivateKey } from "@mysten/sui/cryptography";
|
|
3579
3549
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
3580
3550
|
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
|
|
3581
3551
|
import { Secp256r1Keypair } from "@mysten/sui/keypairs/secp256r1";
|
|
3582
|
-
|
|
3552
|
+
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
3553
|
+
var NUMERIC_STRING_REGEX, BIGINT_STRING_REGEX, HEX_STRING_REGEX, _Helpers, Helpers;
|
|
3583
3554
|
var init_helpers = __esm({
|
|
3584
3555
|
"src/general/utils/helpers.ts"() {
|
|
3585
3556
|
"use strict";
|
|
@@ -3588,6 +3559,9 @@ var init_helpers = __esm({
|
|
|
3588
3559
|
init_inspectionsApiHelpers();
|
|
3589
3560
|
init_objectsApiHelpers();
|
|
3590
3561
|
init_transactionsApiHelpers();
|
|
3562
|
+
NUMERIC_STRING_REGEX = /^\d*\.?\d*$/;
|
|
3563
|
+
BIGINT_STRING_REGEX = /^-?\d+n$/;
|
|
3564
|
+
HEX_STRING_REGEX = /^(0x)?[0-9A-F]+$/i;
|
|
3591
3565
|
_Helpers = class _Helpers {
|
|
3592
3566
|
static uniqueObjectArray(arr) {
|
|
3593
3567
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3632,17 +3606,13 @@ var init_helpers = __esm({
|
|
|
3632
3606
|
seen.add(obj);
|
|
3633
3607
|
if (Array.isArray(obj)) {
|
|
3634
3608
|
return obj.map(
|
|
3635
|
-
(item) =>
|
|
3609
|
+
(item) => _Helpers.removeCircularReferences(item, seen)
|
|
3636
3610
|
);
|
|
3637
|
-
} else {
|
|
3638
|
-
const entries = Object.entries(obj).map(
|
|
3639
|
-
([key, value]) => [
|
|
3640
|
-
key,
|
|
3641
|
-
this.removeCircularReferences(value, seen)
|
|
3642
|
-
]
|
|
3643
|
-
);
|
|
3644
|
-
return Object.fromEntries(entries);
|
|
3645
3611
|
}
|
|
3612
|
+
const entries = Object.entries(obj).map(
|
|
3613
|
+
([key, value]) => [key, _Helpers.removeCircularReferences(value, seen)]
|
|
3614
|
+
);
|
|
3615
|
+
return Object.fromEntries(entries);
|
|
3646
3616
|
}
|
|
3647
3617
|
return obj;
|
|
3648
3618
|
}
|
|
@@ -3671,8 +3641,10 @@ var init_helpers = __esm({
|
|
|
3671
3641
|
*/
|
|
3672
3642
|
static getObjectType(data) {
|
|
3673
3643
|
const objectType = data.data?.type;
|
|
3674
|
-
if (objectType)
|
|
3675
|
-
|
|
3644
|
+
if (objectType) {
|
|
3645
|
+
return _Helpers.addLeadingZeroesToType(objectType);
|
|
3646
|
+
}
|
|
3647
|
+
throw new Error(`no object type found on ${data.data?.objectId}`);
|
|
3676
3648
|
}
|
|
3677
3649
|
/**
|
|
3678
3650
|
* Extracts the object ID from a `SuiObjectResponse`, normalizing it with leading zeroes.
|
|
@@ -3683,8 +3655,10 @@ var init_helpers = __esm({
|
|
|
3683
3655
|
*/
|
|
3684
3656
|
static getObjectId(data) {
|
|
3685
3657
|
const objectId = data.data?.objectId;
|
|
3686
|
-
if (objectId)
|
|
3687
|
-
|
|
3658
|
+
if (objectId) {
|
|
3659
|
+
return _Helpers.addLeadingZeroesToType(objectId);
|
|
3660
|
+
}
|
|
3661
|
+
throw new Error(`no object id found on ${data.data?.type}`);
|
|
3688
3662
|
}
|
|
3689
3663
|
/**
|
|
3690
3664
|
* Retrieves the fields of a Move object from a `SuiObjectResponse`.
|
|
@@ -3693,12 +3667,13 @@ var init_helpers = __esm({
|
|
|
3693
3667
|
* @returns A record of fields for that object.
|
|
3694
3668
|
* @throws If no fields are found.
|
|
3695
3669
|
*/
|
|
3670
|
+
// biome-ignore lint/suspicious/noExplicitAny: Move fields are dynamic — callers access nested properties directly; typing as `unknown` would cascade casts through dozens of call sites
|
|
3696
3671
|
static getObjectFields(data) {
|
|
3697
3672
|
try {
|
|
3698
3673
|
const content = data.data?.content;
|
|
3699
3674
|
return content.fields;
|
|
3700
|
-
} catch (
|
|
3701
|
-
throw new Error(
|
|
3675
|
+
} catch (_e) {
|
|
3676
|
+
throw new Error(`no object fields found on ${data.data?.objectId}`);
|
|
3702
3677
|
}
|
|
3703
3678
|
}
|
|
3704
3679
|
/**
|
|
@@ -3710,8 +3685,10 @@ var init_helpers = __esm({
|
|
|
3710
3685
|
*/
|
|
3711
3686
|
static getObjectDisplay(data) {
|
|
3712
3687
|
const display = data.data?.display;
|
|
3713
|
-
if (display)
|
|
3714
|
-
|
|
3688
|
+
if (display) {
|
|
3689
|
+
return display;
|
|
3690
|
+
}
|
|
3691
|
+
throw new Error(`no object display found on ${data.data?.objectId}`);
|
|
3715
3692
|
}
|
|
3716
3693
|
// =========================================================================
|
|
3717
3694
|
// Error Parsing
|
|
@@ -3725,54 +3702,63 @@ var init_helpers = __esm({
|
|
|
3725
3702
|
*/
|
|
3726
3703
|
static parseMoveErrorMessage(inputs) {
|
|
3727
3704
|
const { errorMessage } = inputs;
|
|
3728
|
-
if (!errorMessage.toLowerCase().includes("moveabort"))
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
const
|
|
3733
|
-
|
|
3705
|
+
if (!errorMessage.toLowerCase().includes("moveabort")) {
|
|
3706
|
+
return void 0;
|
|
3707
|
+
}
|
|
3708
|
+
const moveErrorCode = (errorMsg) => {
|
|
3709
|
+
const startIndex = errorMsg.lastIndexOf(",");
|
|
3710
|
+
const endIndex = errorMsg.lastIndexOf(")");
|
|
3711
|
+
if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex) {
|
|
3734
3712
|
return void 0;
|
|
3713
|
+
}
|
|
3735
3714
|
try {
|
|
3736
|
-
const errorCode2 = parseInt(
|
|
3737
|
-
|
|
3715
|
+
const errorCode2 = Number.parseInt(
|
|
3716
|
+
errorMsg.slice(startIndex + 1, endIndex),
|
|
3717
|
+
10
|
|
3738
3718
|
);
|
|
3739
|
-
if (Number.isNaN(errorCode2))
|
|
3719
|
+
if (Number.isNaN(errorCode2)) {
|
|
3720
|
+
return void 0;
|
|
3721
|
+
}
|
|
3740
3722
|
return errorCode2;
|
|
3741
3723
|
} catch {
|
|
3742
3724
|
return void 0;
|
|
3743
3725
|
}
|
|
3744
3726
|
};
|
|
3745
|
-
const moveErrorPackageId = (
|
|
3746
|
-
const
|
|
3747
|
-
const
|
|
3748
|
-
|
|
3749
|
-
if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex)
|
|
3727
|
+
const moveErrorPackageId = (errorMsg) => {
|
|
3728
|
+
const startIndex = errorMsg.toLowerCase().indexOf("address:");
|
|
3729
|
+
const endIndex = errorMsg.indexOf(", name:");
|
|
3730
|
+
if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex) {
|
|
3750
3731
|
return void 0;
|
|
3732
|
+
}
|
|
3751
3733
|
try {
|
|
3752
|
-
const pkgStr =
|
|
3753
|
-
const packageId2 = _Helpers.addLeadingZeroesToType(
|
|
3754
|
-
if (!
|
|
3734
|
+
const pkgStr = errorMsg.slice(startIndex + 8, endIndex).trim().replaceAll("0x", "");
|
|
3735
|
+
const packageId2 = _Helpers.addLeadingZeroesToType(`0x${pkgStr}`);
|
|
3736
|
+
if (!_Helpers.isValidHex(packageId2)) {
|
|
3737
|
+
return void 0;
|
|
3738
|
+
}
|
|
3755
3739
|
return packageId2;
|
|
3756
3740
|
} catch {
|
|
3757
3741
|
return void 0;
|
|
3758
3742
|
}
|
|
3759
3743
|
};
|
|
3760
|
-
const moveErrorModule = (
|
|
3761
|
-
const
|
|
3762
|
-
const
|
|
3763
|
-
|
|
3764
|
-
if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex)
|
|
3744
|
+
const moveErrorModule = (errorMsg) => {
|
|
3745
|
+
const startIndex = errorMsg.toLowerCase().indexOf('identifier("');
|
|
3746
|
+
const endIndex = errorMsg.indexOf('")');
|
|
3747
|
+
if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex) {
|
|
3765
3748
|
return void 0;
|
|
3749
|
+
}
|
|
3766
3750
|
try {
|
|
3767
|
-
return
|
|
3751
|
+
return errorMsg.slice(startIndex + 12, endIndex).trim();
|
|
3768
3752
|
} catch {
|
|
3769
3753
|
return void 0;
|
|
3770
3754
|
}
|
|
3771
3755
|
};
|
|
3772
|
-
const errorCode = moveErrorCode(
|
|
3773
|
-
const packageId = moveErrorPackageId(
|
|
3774
|
-
const module = moveErrorModule(
|
|
3775
|
-
if (errorCode === void 0 || !packageId || !module)
|
|
3756
|
+
const errorCode = moveErrorCode(errorMessage);
|
|
3757
|
+
const packageId = moveErrorPackageId(errorMessage);
|
|
3758
|
+
const module = moveErrorModule(errorMessage);
|
|
3759
|
+
if (errorCode === void 0 || !packageId || !module) {
|
|
3760
|
+
return void 0;
|
|
3761
|
+
}
|
|
3776
3762
|
return { errorCode, packageId, module };
|
|
3777
3763
|
}
|
|
3778
3764
|
/**
|
|
@@ -3785,14 +3771,18 @@ var init_helpers = __esm({
|
|
|
3785
3771
|
*/
|
|
3786
3772
|
static translateMoveErrorMessage(inputs) {
|
|
3787
3773
|
const { errorMessage, moveErrors } = inputs;
|
|
3788
|
-
const parsed =
|
|
3789
|
-
if (!parsed
|
|
3774
|
+
const parsed = _Helpers.parseMoveErrorMessage({ errorMessage });
|
|
3775
|
+
if (!(parsed && parsed.packageId in moveErrors)) {
|
|
3776
|
+
return void 0;
|
|
3777
|
+
}
|
|
3790
3778
|
let error;
|
|
3791
3779
|
if (parsed.module in moveErrors[parsed.packageId] && parsed.errorCode in moveErrors[parsed.packageId][parsed.module]) {
|
|
3792
3780
|
error = moveErrors[parsed.packageId][parsed.module][parsed.errorCode];
|
|
3793
|
-
} else if ("ANY" in moveErrors[parsed.packageId] && parsed.errorCode in moveErrors[parsed.packageId]
|
|
3794
|
-
error = moveErrors[parsed.packageId]
|
|
3795
|
-
} else
|
|
3781
|
+
} else if ("ANY" in moveErrors[parsed.packageId] && parsed.errorCode in moveErrors[parsed.packageId].ANY) {
|
|
3782
|
+
error = moveErrors[parsed.packageId].ANY[parsed.errorCode];
|
|
3783
|
+
} else {
|
|
3784
|
+
return void 0;
|
|
3785
|
+
}
|
|
3796
3786
|
return {
|
|
3797
3787
|
...parsed,
|
|
3798
3788
|
error
|
|
@@ -3852,15 +3842,16 @@ var init_helpers = __esm({
|
|
|
3852
3842
|
let typeSuffix = "";
|
|
3853
3843
|
if (strippedType.includes("::")) {
|
|
3854
3844
|
const splitType = strippedType.replace("0x", "").split("::");
|
|
3855
|
-
typeSuffix = splitType.slice(1).reduce((acc, str) => acc
|
|
3845
|
+
typeSuffix = splitType.slice(1).reduce((acc, str) => `${acc}::${str}`, "");
|
|
3856
3846
|
strippedType = splitType[0];
|
|
3857
3847
|
}
|
|
3858
3848
|
const typeLength = strippedType.length;
|
|
3859
|
-
if (typeLength > EXPECTED_TYPE_LENGTH)
|
|
3849
|
+
if (typeLength > EXPECTED_TYPE_LENGTH) {
|
|
3860
3850
|
throw new Error("invalid type length");
|
|
3851
|
+
}
|
|
3861
3852
|
const zerosNeeded = EXPECTED_TYPE_LENGTH - typeLength;
|
|
3862
|
-
const zeroString =
|
|
3863
|
-
const newType =
|
|
3853
|
+
const zeroString = "0".repeat(zerosNeeded);
|
|
3854
|
+
const newType = `0x${zeroString}${strippedType}`;
|
|
3864
3855
|
return newType + typeSuffix;
|
|
3865
3856
|
};
|
|
3866
3857
|
/**
|
|
@@ -3872,7 +3863,9 @@ var init_helpers = __esm({
|
|
|
3872
3863
|
*/
|
|
3873
3864
|
_Helpers.splitNonSuiCoinType = (coin) => {
|
|
3874
3865
|
const [uncastChain, coinType] = coin.split(":");
|
|
3875
|
-
if (!uncastChain
|
|
3866
|
+
if (!(uncastChain && coinType)) {
|
|
3867
|
+
return { coinType: coin, chain: "sui" };
|
|
3868
|
+
}
|
|
3876
3869
|
const chain = uncastChain;
|
|
3877
3870
|
return { chain, coinType };
|
|
3878
3871
|
};
|
|
@@ -3885,7 +3878,7 @@ var init_helpers = __esm({
|
|
|
3885
3878
|
* @param str - The string to test.
|
|
3886
3879
|
* @returns `true` if it's a valid numeric string, otherwise `false`.
|
|
3887
3880
|
*/
|
|
3888
|
-
_Helpers.isNumber = (str) =>
|
|
3881
|
+
_Helpers.isNumber = (str) => NUMERIC_STRING_REGEX.test(str);
|
|
3889
3882
|
/**
|
|
3890
3883
|
* Sums an array of floating-point numbers, returning the numeric total.
|
|
3891
3884
|
*
|
|
@@ -4005,9 +3998,11 @@ var init_helpers = __esm({
|
|
|
4005
3998
|
* @param unsafeStringNumberConversion - If `true`, all numeric strings (e.g., "123") will also become BigInts.
|
|
4006
3999
|
* @returns The parsed JSON object with BigInt conversions where applicable.
|
|
4007
4000
|
*/
|
|
4008
|
-
_Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JSON.parse(json, (
|
|
4009
|
-
if (value === null)
|
|
4010
|
-
|
|
4001
|
+
_Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JSON.parse(json, (_key, value) => {
|
|
4002
|
+
if (value === null) {
|
|
4003
|
+
return void 0;
|
|
4004
|
+
}
|
|
4005
|
+
if (typeof value === "string" && BIGINT_STRING_REGEX.test(value)) {
|
|
4011
4006
|
return BigInt(value.slice(0, -1));
|
|
4012
4007
|
}
|
|
4013
4008
|
if (unsafeStringNumberConversion && typeof value === "string" && _Helpers.isNumber(value)) {
|
|
@@ -4033,17 +4028,13 @@ var init_helpers = __esm({
|
|
|
4033
4028
|
return new Date(target.getTime());
|
|
4034
4029
|
}
|
|
4035
4030
|
if (Array.isArray(target)) {
|
|
4036
|
-
|
|
4037
|
-
target.forEach((v) => {
|
|
4038
|
-
cp.push(v);
|
|
4039
|
-
});
|
|
4040
|
-
return cp.map((n) => _Helpers.deepCopy(n));
|
|
4031
|
+
return target.map((v) => _Helpers.deepCopy(v));
|
|
4041
4032
|
}
|
|
4042
4033
|
if (typeof target === "object") {
|
|
4043
|
-
const cp = {
|
|
4044
|
-
Object.keys(
|
|
4045
|
-
cp[k] = _Helpers.deepCopy(
|
|
4046
|
-
}
|
|
4034
|
+
const cp = {};
|
|
4035
|
+
for (const k of Object.keys(target)) {
|
|
4036
|
+
cp[k] = _Helpers.deepCopy(target[k]);
|
|
4037
|
+
}
|
|
4047
4038
|
return cp;
|
|
4048
4039
|
}
|
|
4049
4040
|
return target;
|
|
@@ -4055,13 +4046,13 @@ var init_helpers = __esm({
|
|
|
4055
4046
|
* @returns The index of the maximum value, or -1 if the array is empty.
|
|
4056
4047
|
*/
|
|
4057
4048
|
_Helpers.indexOfMax = (arr) => {
|
|
4058
|
-
if (arr.length === 0)
|
|
4059
|
-
|
|
4049
|
+
if (arr.length === 0) {
|
|
4050
|
+
return -1;
|
|
4051
|
+
}
|
|
4060
4052
|
let maxIndex = 0;
|
|
4061
4053
|
for (let i = 1; i < arr.length; i++) {
|
|
4062
|
-
if (arr[i] >
|
|
4054
|
+
if (arr[i] > arr[maxIndex]) {
|
|
4063
4055
|
maxIndex = i;
|
|
4064
|
-
max = arr[i];
|
|
4065
4056
|
}
|
|
4066
4057
|
}
|
|
4067
4058
|
return maxIndex;
|
|
@@ -4073,7 +4064,15 @@ var init_helpers = __esm({
|
|
|
4073
4064
|
* @param arr - The original array.
|
|
4074
4065
|
* @returns An array of unique items.
|
|
4075
4066
|
*/
|
|
4076
|
-
_Helpers.uniqueArray = (arr) =>
|
|
4067
|
+
_Helpers.uniqueArray = (arr) => {
|
|
4068
|
+
if (arr.length === 0) {
|
|
4069
|
+
return [];
|
|
4070
|
+
}
|
|
4071
|
+
if (typeof arr[0] === "object") {
|
|
4072
|
+
return _Helpers.uniqueObjectArray(arr);
|
|
4073
|
+
}
|
|
4074
|
+
return [...new Set(arr)];
|
|
4075
|
+
};
|
|
4077
4076
|
/**
|
|
4078
4077
|
* Returns a Promise that resolves after a specified number of milliseconds.
|
|
4079
4078
|
*
|
|
@@ -4100,8 +4099,11 @@ var init_helpers = __esm({
|
|
|
4100
4099
|
const falses = [];
|
|
4101
4100
|
for (let index = 0; index < array.length; index++) {
|
|
4102
4101
|
const item = array[index];
|
|
4103
|
-
if (func(item, index, array))
|
|
4104
|
-
|
|
4102
|
+
if (func(item, index, array)) {
|
|
4103
|
+
trues[trues.length] = item;
|
|
4104
|
+
} else {
|
|
4105
|
+
falses[falses.length] = item;
|
|
4106
|
+
}
|
|
4105
4107
|
}
|
|
4106
4108
|
return [trues, falses];
|
|
4107
4109
|
};
|
|
@@ -4126,14 +4128,9 @@ var init_helpers = __esm({
|
|
|
4126
4128
|
* @param predicate - A function taking `(key, value)` and returning a boolean.
|
|
4127
4129
|
* @returns A new object with only the entries that pass the predicate.
|
|
4128
4130
|
*/
|
|
4129
|
-
_Helpers.filterObject = (obj, predicate) => Object.
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
return {
|
|
4133
|
-
...acc,
|
|
4134
|
-
[key]: val
|
|
4135
|
-
};
|
|
4136
|
-
}, {});
|
|
4131
|
+
_Helpers.filterObject = (obj, predicate) => Object.fromEntries(
|
|
4132
|
+
Object.entries(obj).filter(([key, value]) => predicate(key, value))
|
|
4133
|
+
);
|
|
4137
4134
|
/**
|
|
4138
4135
|
* Applies downward slippage to a bigint amount by subtracting `slippage * amount`.
|
|
4139
4136
|
* For instance, for 1% slippage, we reduce the amount by 1%.
|
|
@@ -4173,10 +4170,7 @@ var init_helpers = __esm({
|
|
|
4173
4170
|
* @param hexString - The string to check.
|
|
4174
4171
|
* @returns `true` if `hexString` is a valid hex, otherwise `false`.
|
|
4175
4172
|
*/
|
|
4176
|
-
_Helpers.isValidHex = (hexString) =>
|
|
4177
|
-
const hexPattern = /^(0x)?[0-9A-F]+$/i;
|
|
4178
|
-
return hexPattern.test(hexString);
|
|
4179
|
-
};
|
|
4173
|
+
_Helpers.isValidHex = (hexString) => HEX_STRING_REGEX.test(hexString);
|
|
4180
4174
|
// =========================================================================
|
|
4181
4175
|
// Tx Command Input Construction
|
|
4182
4176
|
// =========================================================================
|
|
@@ -4205,10 +4199,12 @@ var init_helpers = __esm({
|
|
|
4205
4199
|
*/
|
|
4206
4200
|
_Helpers.isValidSuiAddress = (address) => isValidSuiAddress(
|
|
4207
4201
|
(() => {
|
|
4208
|
-
if (!address.startsWith("0x") || address.length < 3)
|
|
4202
|
+
if (!address.startsWith("0x") || address.length < 3) {
|
|
4203
|
+
return "";
|
|
4204
|
+
}
|
|
4209
4205
|
try {
|
|
4210
4206
|
return _Helpers.addLeadingZeroesToType(address);
|
|
4211
|
-
} catch
|
|
4207
|
+
} catch {
|
|
4212
4208
|
return "";
|
|
4213
4209
|
}
|
|
4214
4210
|
})()
|
|
@@ -4235,9 +4231,7 @@ var init_helpers = __esm({
|
|
|
4235
4231
|
case "Secp256r1":
|
|
4236
4232
|
return Secp256r1Keypair.fromSecretKey(parsedKeypair.secretKey);
|
|
4237
4233
|
default:
|
|
4238
|
-
throw new Error(
|
|
4239
|
-
`unsupported scheme \`${parsedKeypair.scheme}\``
|
|
4240
|
-
);
|
|
4234
|
+
throw new Error(`unsupported scheme \`${parsedKeypair.scheme}\``);
|
|
4241
4235
|
}
|
|
4242
4236
|
};
|
|
4243
4237
|
Helpers = _Helpers;
|
|
@@ -4703,8 +4697,6 @@ var init_auth2 = __esm({
|
|
|
4703
4697
|
});
|
|
4704
4698
|
|
|
4705
4699
|
// src/packages/farms/farmsStakingPool.ts
|
|
4706
|
-
import dayjs2 from "dayjs";
|
|
4707
|
-
import duration from "dayjs/plugin/duration";
|
|
4708
4700
|
var FarmsStakingPool;
|
|
4709
4701
|
var init_farmsStakingPool = __esm({
|
|
4710
4702
|
"src/packages/farms/farmsStakingPool.ts"() {
|
|
@@ -4791,7 +4783,7 @@ var init_farmsStakingPool = __esm({
|
|
|
4791
4783
|
return Math.max(
|
|
4792
4784
|
Math.min(
|
|
4793
4785
|
this.stakingPool.maxLockDurationMs,
|
|
4794
|
-
this.stakingPool.emissionEndTimestamp -
|
|
4786
|
+
this.stakingPool.emissionEndTimestamp - Date.now()
|
|
4795
4787
|
),
|
|
4796
4788
|
0
|
|
4797
4789
|
);
|
|
@@ -4811,7 +4803,7 @@ var init_farmsStakingPool = __esm({
|
|
|
4811
4803
|
* ```
|
|
4812
4804
|
*/
|
|
4813
4805
|
this.emitRewards = () => {
|
|
4814
|
-
const currentTimestamp =
|
|
4806
|
+
const currentTimestamp = Date.now();
|
|
4815
4807
|
if (this.stakingPool.stakedAmount === BigInt(0)) return;
|
|
4816
4808
|
const rewardCoins = Helpers.deepCopy(this.stakingPool.rewardCoins);
|
|
4817
4809
|
for (const [rewardCoinIndex, rewardCoin] of rewardCoins.entries()) {
|
|
@@ -4839,15 +4831,14 @@ var init_farmsStakingPool = __esm({
|
|
|
4839
4831
|
const { coinType, price, decimals, tvlUsd } = inputs;
|
|
4840
4832
|
if (price <= 0 || tvlUsd <= 0) return 0;
|
|
4841
4833
|
const rewardCoin = this.rewardCoin({ coinType });
|
|
4842
|
-
const currentTimestamp =
|
|
4834
|
+
const currentTimestamp = Date.now();
|
|
4843
4835
|
if (rewardCoin.emissionRate > rewardCoin.actualRewards) return 0;
|
|
4844
4836
|
if (rewardCoin.emissionStartTimestamp > currentTimestamp || currentTimestamp > this.stakingPool.emissionEndTimestamp) {
|
|
4845
4837
|
return 0;
|
|
4846
4838
|
}
|
|
4847
4839
|
const emissionRateTokens = rewardCoin.emissionRate;
|
|
4848
4840
|
const emissionRateUsd = Coin.balanceWithDecimals(emissionRateTokens, decimals) * price;
|
|
4849
|
-
|
|
4850
|
-
const oneYearMs = dayjs2.duration(1, "year").asMilliseconds();
|
|
4841
|
+
const oneYearMs = 365 * 24 * 60 * 60 * 1e3;
|
|
4851
4842
|
const rewardsUsdOneYear = emissionRateUsd * (oneYearMs / rewardCoin.emissionSchedulesMs);
|
|
4852
4843
|
const apr = rewardsUsdOneYear / tvlUsd / Casting.bigIntToFixedNumber(this.stakingPool.maxLockMultiplier);
|
|
4853
4844
|
return apr < 0 ? 0 : isNaN(apr) ? 0 : apr;
|
|
@@ -5119,7 +5110,7 @@ var init_farmsStakingPool = __esm({
|
|
|
5119
5110
|
*/
|
|
5120
5111
|
calcRewardsToEmit(inputs) {
|
|
5121
5112
|
const { rewardCoin } = inputs;
|
|
5122
|
-
const currentTimestamp =
|
|
5113
|
+
const currentTimestamp = Date.now();
|
|
5123
5114
|
const rewardsToEmit = this.calcRewardsEmittedFromTimeTmToTn({
|
|
5124
5115
|
timestampTm: rewardCoin.lastRewardTimestamp,
|
|
5125
5116
|
timestampTn: currentTimestamp,
|
|
@@ -5145,7 +5136,6 @@ var init_farmsStakingPool = __esm({
|
|
|
5145
5136
|
});
|
|
5146
5137
|
|
|
5147
5138
|
// src/packages/farms/farmsStakedPosition.ts
|
|
5148
|
-
import dayjs3 from "dayjs";
|
|
5149
5139
|
var FarmsStakedPosition;
|
|
5150
5140
|
var init_farmsStakedPosition = __esm({
|
|
5151
5141
|
"src/packages/farms/farmsStakedPosition.ts"() {
|
|
@@ -5347,7 +5337,7 @@ var init_farmsStakedPosition = __esm({
|
|
|
5347
5337
|
];
|
|
5348
5338
|
stakingPool.stakingPool.stakedAmountWithMultiplier += this.stakedPosition.stakedAmountWithMultiplier;
|
|
5349
5339
|
}
|
|
5350
|
-
const currentTimestamp =
|
|
5340
|
+
const currentTimestamp = Date.now();
|
|
5351
5341
|
stakingPool.emitRewards();
|
|
5352
5342
|
for (const [
|
|
5353
5343
|
rewardCoinIndex,
|
|
@@ -5396,7 +5386,7 @@ var init_farmsStakedPosition = __esm({
|
|
|
5396
5386
|
*/
|
|
5397
5387
|
this.isUnlocked = (inputs) => {
|
|
5398
5388
|
const { stakingPool } = inputs;
|
|
5399
|
-
const currentTime =
|
|
5389
|
+
const currentTime = Date.now();
|
|
5400
5390
|
return this.unlockTimestamp() <= currentTime || stakingPool.stakingPool.emissionEndTimestamp <= currentTime || stakingPool.stakingPool.isUnlocked;
|
|
5401
5391
|
};
|
|
5402
5392
|
/**
|
|
@@ -8060,7 +8050,7 @@ var init_pools = __esm({
|
|
|
8060
8050
|
* This indicates the user's liquidity positions across multiple pools.
|
|
8061
8051
|
*
|
|
8062
8052
|
* @param inputs - An object containing the `walletAddress`.
|
|
8063
|
-
* @returns
|
|
8053
|
+
* @returns An array of `PoolLpInfo` objects summarizing the user's LP balances.
|
|
8064
8054
|
*
|
|
8065
8055
|
* @example
|
|
8066
8056
|
* ```typescript
|
|
@@ -11898,6 +11888,22 @@ var init_perpetuals = __esm({
|
|
|
11898
11888
|
async getOwnedVaultCaps(inputs) {
|
|
11899
11889
|
return this.fetchApi("vaults/owned-vault-caps", inputs);
|
|
11900
11890
|
}
|
|
11891
|
+
/**
|
|
11892
|
+
* Fetch all vault **assistant** caps owned by a wallet.
|
|
11893
|
+
*
|
|
11894
|
+
* Assistant caps grant a non-owner wallet the ability to operate a vault
|
|
11895
|
+
* on behalf of the owner. The returned caps are structurally identical to
|
|
11896
|
+
* regular vault caps ({@link PerpetualsVaultCap}) and can be used to
|
|
11897
|
+
* construct a {@link PerpetualsAccount} that signs vault transactions with
|
|
11898
|
+
* the assistant's wallet.
|
|
11899
|
+
*
|
|
11900
|
+
* @param inputs.walletAddress - Assistant wallet address.
|
|
11901
|
+
* @returns {@link ApiPerpetualsOwnedVaultAssistantCapsResponse} containing
|
|
11902
|
+
* assistant caps.
|
|
11903
|
+
*/
|
|
11904
|
+
async getOwnedVaultAssistantCaps(inputs) {
|
|
11905
|
+
return this.fetchApi("vaults/owned-vault-assistant-caps", inputs);
|
|
11906
|
+
}
|
|
11901
11907
|
/**
|
|
11902
11908
|
* Fetch all pending vault withdrawal requests created by a given wallet.
|
|
11903
11909
|
*
|
|
@@ -11961,6 +11967,20 @@ var init_perpetuals = __esm({
|
|
|
11961
11967
|
intervalMs
|
|
11962
11968
|
});
|
|
11963
11969
|
}
|
|
11970
|
+
/**
|
|
11971
|
+
* Fetch historical funding rate data for a single market.
|
|
11972
|
+
*
|
|
11973
|
+
* @param inputs.marketId - Market ID to query.
|
|
11974
|
+
* @param inputs.fromTimestamp - Start timestamp (inclusive).
|
|
11975
|
+
* @param inputs.toTimestamp - End timestamp (exclusive).
|
|
11976
|
+
* @param inputs.limit - Optional cap on the number of points returned.
|
|
11977
|
+
*
|
|
11978
|
+
* @returns {@link ApiPerpetualsMarketFundingHistoryResponse} containing
|
|
11979
|
+
* funding history points.
|
|
11980
|
+
*/
|
|
11981
|
+
getMarketFundingHistory(inputs) {
|
|
11982
|
+
return this.fetchApi("market/funding-history", inputs);
|
|
11983
|
+
}
|
|
11964
11984
|
/**
|
|
11965
11985
|
* Fetch 24-hour volume and price change stats for multiple markets.
|
|
11966
11986
|
*
|
|
@@ -12235,6 +12255,33 @@ var init_perpetuals = __esm({
|
|
|
12235
12255
|
async getCurrentRebateRewards(inputs) {
|
|
12236
12256
|
return this.fetchApi("rebates/rewards", inputs);
|
|
12237
12257
|
}
|
|
12258
|
+
/**
|
|
12259
|
+
* Generate a CSV-formatted rebate report for perpetuals market makers.
|
|
12260
|
+
*
|
|
12261
|
+
* Computes per-account reward allocations and fee-tier rebate adjustments,
|
|
12262
|
+
* returning the result as a CSV string. When `aggregated` is true, the CSV
|
|
12263
|
+
* groups rewards by owner address instead of per-account.
|
|
12264
|
+
*
|
|
12265
|
+
* **Note:** All data returned is for the current epoch only.
|
|
12266
|
+
*
|
|
12267
|
+
* @param inputs - {@link ApiPerpetualsCreateCsvRebatesBody}.
|
|
12268
|
+
* @returns {@link ApiPerpetualsCreateCsvRebatesResponse} containing the CSV string.
|
|
12269
|
+
*/
|
|
12270
|
+
async getCsvRebates(inputs) {
|
|
12271
|
+
return this.fetchApi("rebates/create-csv-rebates", inputs);
|
|
12272
|
+
}
|
|
12273
|
+
/**
|
|
12274
|
+
* Generate a CSV-formatted referral rebate report.
|
|
12275
|
+
*
|
|
12276
|
+
* Calculates referrer commissions and referee discounts based on trading
|
|
12277
|
+
* fees within the specified epoch, returning the result as a CSV string.
|
|
12278
|
+
*
|
|
12279
|
+
* @param inputs - {@link ApiPerpetualsCreateReferralCsvRebatesBody}.
|
|
12280
|
+
* @returns {@link ApiPerpetualsCreateReferralCsvRebatesResponse} containing the CSV string.
|
|
12281
|
+
*/
|
|
12282
|
+
async getReferralCsvRebates(inputs) {
|
|
12283
|
+
return this.fetchApi("rebates/create-referral-csv-rebates", inputs);
|
|
12284
|
+
}
|
|
12238
12285
|
// =========================================================================
|
|
12239
12286
|
// Builder Codes Transactions
|
|
12240
12287
|
// =========================================================================
|
|
@@ -13878,7 +13925,7 @@ var init_sui2 = __esm({
|
|
|
13878
13925
|
});
|
|
13879
13926
|
|
|
13880
13927
|
// src/packages/suiFrens/suiFren.ts
|
|
13881
|
-
import
|
|
13928
|
+
import { format } from "date-fns";
|
|
13882
13929
|
var SuiFren;
|
|
13883
13930
|
var init_suiFren = __esm({
|
|
13884
13931
|
"src/packages/suiFrens/suiFren.ts"() {
|
|
@@ -13918,7 +13965,7 @@ var init_suiFren = __esm({
|
|
|
13918
13965
|
"Main Color": this.suiFren.attributes.main,
|
|
13919
13966
|
"Secondary Color": this.suiFren.attributes.secondary,
|
|
13920
13967
|
"Birth Location": this.suiFren.birthLocation,
|
|
13921
|
-
Birthday:
|
|
13968
|
+
Birthday: format(this.suiFren.birthdate, "MMMM d, yyyy"),
|
|
13922
13969
|
Cohort: this.suiFren.cohort.toString(),
|
|
13923
13970
|
Generation: this.suiFren.generation.toString()
|
|
13924
13971
|
// Genes: this.suiFren.genes.toString(),
|
|
@@ -17854,10 +17901,9 @@ var init_multisigApi = __esm({
|
|
|
17854
17901
|
constructor(Provider) {
|
|
17855
17902
|
this.Provider = Provider;
|
|
17856
17903
|
const sharedCustodyAddresses = this.Provider.addresses.sharedCustody;
|
|
17857
|
-
if (!sharedCustodyAddresses)
|
|
17858
|
-
throw new Error(
|
|
17859
|
-
|
|
17860
|
-
);
|
|
17904
|
+
if (!sharedCustodyAddresses) {
|
|
17905
|
+
throw new Error("not all required addresses have been set in provider");
|
|
17906
|
+
}
|
|
17861
17907
|
this.sharedCustodyAddresses = sharedCustodyAddresses;
|
|
17862
17908
|
}
|
|
17863
17909
|
// =========================================================================
|
|
@@ -17870,7 +17916,10 @@ var init_multisigApi = __esm({
|
|
|
17870
17916
|
);
|
|
17871
17917
|
const afPublicKeyArray = new Uint8Array(afPublicKeyBuffer).subarray(1);
|
|
17872
17918
|
const afPK = new Ed25519PublicKey(afPublicKeyArray);
|
|
17873
|
-
const
|
|
17919
|
+
const userPublicKeyArray = new Uint8Array(inputs.userPublicKey);
|
|
17920
|
+
const userPK = new Ed25519PublicKey(
|
|
17921
|
+
userPublicKeyArray.length === 33 ? userPublicKeyArray.subarray(1) : userPublicKeyArray
|
|
17922
|
+
);
|
|
17874
17923
|
const newMultiSigPublicKey = MultiSigPublicKey.fromPublicKeys({
|
|
17875
17924
|
threshold: 1,
|
|
17876
17925
|
publicKeys: [
|
|
@@ -19628,20 +19677,20 @@ var init_perpetualsApi = __esm({
|
|
|
19628
19677
|
});
|
|
19629
19678
|
|
|
19630
19679
|
// src/packages/pools/api/poolsApi.ts
|
|
19680
|
+
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
19631
19681
|
import {
|
|
19632
19682
|
Transaction as Transaction11
|
|
19633
19683
|
} from "@mysten/sui/transactions";
|
|
19634
19684
|
import { fromBase64, normalizeSuiObjectId } from "@mysten/sui/utils";
|
|
19635
|
-
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
19636
19685
|
var _PoolsApi, PoolsApi;
|
|
19637
19686
|
var init_poolsApi = __esm({
|
|
19638
19687
|
"src/packages/pools/api/poolsApi.ts"() {
|
|
19639
19688
|
"use strict";
|
|
19640
|
-
|
|
19641
|
-
init_pools();
|
|
19689
|
+
init_eventsApiHelpers();
|
|
19642
19690
|
init_utils();
|
|
19691
|
+
init_casting();
|
|
19643
19692
|
init_coin2();
|
|
19644
|
-
|
|
19693
|
+
init_pools();
|
|
19645
19694
|
_PoolsApi = class _PoolsApi {
|
|
19646
19695
|
// =========================================================================
|
|
19647
19696
|
// Constructor
|
|
@@ -19652,19 +19701,17 @@ var init_poolsApi = __esm({
|
|
|
19652
19701
|
* @throws {Error} Throws an error if not all required addresses have been set in AfSdk
|
|
19653
19702
|
*/
|
|
19654
19703
|
constructor(Provider) {
|
|
19655
|
-
this.Provider = Provider;
|
|
19656
19704
|
// =========================================================================
|
|
19657
19705
|
// Public Methods
|
|
19658
19706
|
// =========================================================================
|
|
19659
19707
|
// =========================================================================
|
|
19660
19708
|
// Objects
|
|
19661
19709
|
// =========================================================================
|
|
19662
|
-
this.fetchOwnedDaoFeePoolOwnerCaps =
|
|
19710
|
+
this.fetchOwnedDaoFeePoolOwnerCaps = (inputs) => {
|
|
19663
19711
|
const { walletAddress } = inputs;
|
|
19664
|
-
if (!this.objectTypes.daoFeePoolOwnerCap)
|
|
19665
|
-
throw new Error(
|
|
19666
|
-
|
|
19667
|
-
);
|
|
19712
|
+
if (!this.objectTypes.daoFeePoolOwnerCap) {
|
|
19713
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
19714
|
+
}
|
|
19668
19715
|
return this.Provider.Objects().fetchCastObjectsOwnedByAddressOfType({
|
|
19669
19716
|
walletAddress,
|
|
19670
19717
|
objectType: this.objectTypes.daoFeePoolOwnerCap,
|
|
@@ -19784,11 +19831,7 @@ var init_poolsApi = __esm({
|
|
|
19784
19831
|
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
19785
19832
|
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
19786
19833
|
tx.pure(
|
|
19787
|
-
bcs2.vector(bcs2.u64()).serialize(
|
|
19788
|
-
expectedAmountsOut.map(
|
|
19789
|
-
(amount) => amount.toString()
|
|
19790
|
-
)
|
|
19791
|
-
)
|
|
19834
|
+
bcs2.vector(bcs2.u64()).serialize(expectedAmountsOut.map((amount) => amount.toString()))
|
|
19792
19835
|
),
|
|
19793
19836
|
tx.pure.u64(Pools.normalizeInvertSlippage(slippage))
|
|
19794
19837
|
]
|
|
@@ -19833,10 +19876,11 @@ var init_poolsApi = __esm({
|
|
|
19833
19876
|
*/
|
|
19834
19877
|
this.publishLpCoinTx = (inputs) => {
|
|
19835
19878
|
const compilations = this.addresses.pools.other?.createLpCoinPackageCompilations;
|
|
19836
|
-
if (!compilations)
|
|
19879
|
+
if (!compilations) {
|
|
19837
19880
|
throw new Error(
|
|
19838
19881
|
"not all required addresses have been set in provider for lp coin publishing (requires package compilations)"
|
|
19839
19882
|
);
|
|
19883
|
+
}
|
|
19840
19884
|
const { tx, lpCoinDecimals } = inputs;
|
|
19841
19885
|
const compiledModulesAndDeps = JSON.parse(compilations[lpCoinDecimals]);
|
|
19842
19886
|
return tx.publish({
|
|
@@ -19883,9 +19927,7 @@ var init_poolsApi = __esm({
|
|
|
19883
19927
|
),
|
|
19884
19928
|
tx.pure(
|
|
19885
19929
|
bcs2.vector(bcs2.u8()).serialize(
|
|
19886
|
-
Casting.u8VectorFromString(
|
|
19887
|
-
lpCoinMetadata.name.toString()
|
|
19888
|
-
)
|
|
19930
|
+
Casting.u8VectorFromString(lpCoinMetadata.name.toString())
|
|
19889
19931
|
)
|
|
19890
19932
|
),
|
|
19891
19933
|
tx.pure(
|
|
@@ -19896,9 +19938,7 @@ var init_poolsApi = __esm({
|
|
|
19896
19938
|
)
|
|
19897
19939
|
),
|
|
19898
19940
|
tx.pure(
|
|
19899
|
-
bcs2.vector(bcs2.u8()).serialize(
|
|
19900
|
-
Casting.u8VectorFromString(lpCoinDescription)
|
|
19901
|
-
)
|
|
19941
|
+
bcs2.vector(bcs2.u8()).serialize(Casting.u8VectorFromString(lpCoinDescription))
|
|
19902
19942
|
),
|
|
19903
19943
|
tx.pure(
|
|
19904
19944
|
bcs2.vector(bcs2.u8()).serialize(Casting.u8VectorFromString(lpCoinIconUrl))
|
|
@@ -19955,10 +19995,9 @@ var init_poolsApi = __esm({
|
|
|
19955
19995
|
};
|
|
19956
19996
|
this.daoFeePoolNewTx = (inputs) => {
|
|
19957
19997
|
const { tx, poolId } = inputs;
|
|
19958
|
-
if (!this.addresses.daoFeePools)
|
|
19959
|
-
throw new Error(
|
|
19960
|
-
|
|
19961
|
-
);
|
|
19998
|
+
if (!this.addresses.daoFeePools) {
|
|
19999
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20000
|
+
}
|
|
19962
20001
|
return tx.moveCall({
|
|
19963
20002
|
target: Helpers.transactions.createTxTarget(
|
|
19964
20003
|
this.addresses.daoFeePools.packages.amm,
|
|
@@ -19977,10 +20016,9 @@ var init_poolsApi = __esm({
|
|
|
19977
20016
|
};
|
|
19978
20017
|
this.daoFeePoolUpdateFeeBpsTx = (inputs) => {
|
|
19979
20018
|
const { tx } = inputs;
|
|
19980
|
-
if (!this.addresses.daoFeePools)
|
|
19981
|
-
throw new Error(
|
|
19982
|
-
|
|
19983
|
-
);
|
|
20019
|
+
if (!this.addresses.daoFeePools) {
|
|
20020
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20021
|
+
}
|
|
19984
20022
|
return tx.moveCall({
|
|
19985
20023
|
target: Helpers.transactions.createTxTarget(
|
|
19986
20024
|
this.addresses.daoFeePools.packages.amm,
|
|
@@ -20000,10 +20038,9 @@ var init_poolsApi = __esm({
|
|
|
20000
20038
|
};
|
|
20001
20039
|
this.daoFeePoolUpdateFeeRecipientTx = (inputs) => {
|
|
20002
20040
|
const { tx } = inputs;
|
|
20003
|
-
if (!this.addresses.daoFeePools)
|
|
20004
|
-
throw new Error(
|
|
20005
|
-
|
|
20006
|
-
);
|
|
20041
|
+
if (!this.addresses.daoFeePools) {
|
|
20042
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20043
|
+
}
|
|
20007
20044
|
return tx.moveCall({
|
|
20008
20045
|
target: Helpers.transactions.createTxTarget(
|
|
20009
20046
|
this.addresses.daoFeePools.packages.amm,
|
|
@@ -20037,10 +20074,9 @@ var init_poolsApi = __esm({
|
|
|
20037
20074
|
lpCoinType,
|
|
20038
20075
|
slippage
|
|
20039
20076
|
} = inputs;
|
|
20040
|
-
if (!this.addresses.daoFeePools)
|
|
20041
|
-
throw new Error(
|
|
20042
|
-
|
|
20043
|
-
);
|
|
20077
|
+
if (!this.addresses.daoFeePools) {
|
|
20078
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20079
|
+
}
|
|
20044
20080
|
return tx.moveCall({
|
|
20045
20081
|
target: Helpers.transactions.createTxTarget(
|
|
20046
20082
|
this.addresses.daoFeePools.packages.amm,
|
|
@@ -20078,10 +20114,9 @@ var init_poolsApi = __esm({
|
|
|
20078
20114
|
lpCoinType,
|
|
20079
20115
|
slippage
|
|
20080
20116
|
} = inputs;
|
|
20081
|
-
if (!this.addresses.daoFeePools)
|
|
20082
|
-
throw new Error(
|
|
20083
|
-
|
|
20084
|
-
);
|
|
20117
|
+
if (!this.addresses.daoFeePools) {
|
|
20118
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20119
|
+
}
|
|
20085
20120
|
const poolSize = coinTypes.length;
|
|
20086
20121
|
return tx.moveCall({
|
|
20087
20122
|
target: Helpers.transactions.createTxTarget(
|
|
@@ -20118,10 +20153,9 @@ var init_poolsApi = __esm({
|
|
|
20118
20153
|
*/
|
|
20119
20154
|
this.daoFeePoolAllCoinWithdrawTx = (inputs) => {
|
|
20120
20155
|
const { tx, daoFeePoolId, lpCoinId, coinTypes, lpCoinType } = inputs;
|
|
20121
|
-
if (!this.addresses.daoFeePools)
|
|
20122
|
-
throw new Error(
|
|
20123
|
-
|
|
20124
|
-
);
|
|
20156
|
+
if (!this.addresses.daoFeePools) {
|
|
20157
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
20158
|
+
}
|
|
20125
20159
|
const poolSize = coinTypes.length;
|
|
20126
20160
|
return tx.moveCall({
|
|
20127
20161
|
target: Helpers.transactions.createTxTarget(
|
|
@@ -20171,11 +20205,12 @@ var init_poolsApi = __esm({
|
|
|
20171
20205
|
} = inputs;
|
|
20172
20206
|
const tx = new Transaction11();
|
|
20173
20207
|
tx.setSender(walletAddress);
|
|
20174
|
-
if (referrer)
|
|
20208
|
+
if (referrer) {
|
|
20175
20209
|
this.Provider.ReferralVault().updateReferrerTx({
|
|
20176
20210
|
tx,
|
|
20177
20211
|
referrer
|
|
20178
20212
|
});
|
|
20213
|
+
}
|
|
20179
20214
|
const amountOut = pool.getTradeAmountOut({
|
|
20180
20215
|
coinInAmount,
|
|
20181
20216
|
coinInType,
|
|
@@ -20216,7 +20251,7 @@ var init_poolsApi = __esm({
|
|
|
20216
20251
|
}
|
|
20217
20252
|
return tx;
|
|
20218
20253
|
};
|
|
20219
|
-
this.fetchAddTradeTx =
|
|
20254
|
+
this.fetchAddTradeTx = (inputs) => {
|
|
20220
20255
|
const {
|
|
20221
20256
|
tx,
|
|
20222
20257
|
coinInId,
|
|
@@ -20266,11 +20301,12 @@ var init_poolsApi = __esm({
|
|
|
20266
20301
|
} = inputs;
|
|
20267
20302
|
const tx = new Transaction11();
|
|
20268
20303
|
tx.setSender(walletAddress);
|
|
20269
|
-
if (referrer)
|
|
20304
|
+
if (referrer) {
|
|
20270
20305
|
this.Provider.ReferralVault().updateReferrerTx({
|
|
20271
20306
|
tx,
|
|
20272
20307
|
referrer
|
|
20273
20308
|
});
|
|
20309
|
+
}
|
|
20274
20310
|
const { coins: coinTypes, balances: coinAmounts } = Coin.coinsAndBalancesOverZero(amountsIn);
|
|
20275
20311
|
const { lpRatio } = pool.getDepositLpAmountOut({
|
|
20276
20312
|
amountsIn,
|
|
@@ -20331,11 +20367,12 @@ var init_poolsApi = __esm({
|
|
|
20331
20367
|
} = inputs;
|
|
20332
20368
|
const tx = new Transaction11();
|
|
20333
20369
|
tx.setSender(walletAddress);
|
|
20334
|
-
if (referrer)
|
|
20370
|
+
if (referrer) {
|
|
20335
20371
|
this.Provider.ReferralVault().updateReferrerTx({
|
|
20336
20372
|
tx,
|
|
20337
20373
|
referrer
|
|
20338
20374
|
});
|
|
20375
|
+
}
|
|
20339
20376
|
const lpRatio = pool.getMultiCoinWithdrawLpRatio({
|
|
20340
20377
|
lpCoinAmountIn: lpCoinAmount
|
|
20341
20378
|
});
|
|
@@ -20375,11 +20412,12 @@ var init_poolsApi = __esm({
|
|
|
20375
20412
|
const { walletAddress, pool, lpCoinAmount, referrer } = inputs;
|
|
20376
20413
|
const tx = new Transaction11();
|
|
20377
20414
|
tx.setSender(walletAddress);
|
|
20378
|
-
if (referrer)
|
|
20415
|
+
if (referrer) {
|
|
20379
20416
|
this.Provider.ReferralVault().updateReferrerTx({
|
|
20380
20417
|
tx,
|
|
20381
20418
|
referrer
|
|
20382
20419
|
});
|
|
20420
|
+
}
|
|
20383
20421
|
const lpCoinId = await this.Provider.Coin().fetchCoinWithAmountTx({
|
|
20384
20422
|
tx,
|
|
20385
20423
|
walletAddress,
|
|
@@ -20424,7 +20462,9 @@ var init_poolsApi = __esm({
|
|
|
20424
20462
|
tx.transferObjects([upgradeCap], inputs.walletAddress);
|
|
20425
20463
|
return tx;
|
|
20426
20464
|
};
|
|
20427
|
-
this.buildDaoFeePoolUpdateFeeBpsTx = Helpers.transactions.createBuildTxFunc(
|
|
20465
|
+
this.buildDaoFeePoolUpdateFeeBpsTx = Helpers.transactions.createBuildTxFunc(
|
|
20466
|
+
this.daoFeePoolUpdateFeeBpsTx
|
|
20467
|
+
);
|
|
20428
20468
|
this.buildDaoFeePoolUpdateFeeRecipientTx = Helpers.transactions.createBuildTxFunc(
|
|
20429
20469
|
this.daoFeePoolUpdateFeeRecipientTx
|
|
20430
20470
|
);
|
|
@@ -20461,13 +20501,13 @@ var init_poolsApi = __esm({
|
|
|
20461
20501
|
_PoolsApi.constants.moduleNames.events,
|
|
20462
20502
|
_PoolsApi.constants.eventNames.withdrawV2
|
|
20463
20503
|
);
|
|
20504
|
+
this.Provider = Provider;
|
|
20464
20505
|
const pools = Provider.addresses.pools;
|
|
20465
20506
|
const referralVault = Provider.addresses.referralVault;
|
|
20466
20507
|
const daoFeePools = Provider.addresses.daoFeePools;
|
|
20467
|
-
if (!pools
|
|
20468
|
-
throw new Error(
|
|
20469
|
-
|
|
20470
|
-
);
|
|
20508
|
+
if (!(pools && referralVault)) {
|
|
20509
|
+
throw new Error("not all required addresses have been set in provider");
|
|
20510
|
+
}
|
|
20471
20511
|
this.addresses = {
|
|
20472
20512
|
pools,
|
|
20473
20513
|
referralVault,
|
|
@@ -22294,8 +22334,7 @@ var init_suiFrensApi = __esm({
|
|
|
22294
22334
|
this.fetchSuiFrenVaultStateV1Object(),
|
|
22295
22335
|
this.Provider.Events().fetchEventsWithinTime({
|
|
22296
22336
|
fetchEventsFunc: this.fetchMixSuiFrensEvents,
|
|
22297
|
-
|
|
22298
|
-
time: 24
|
|
22337
|
+
timeMs: 24 * 60 * 60 * 1e3
|
|
22299
22338
|
})
|
|
22300
22339
|
]);
|
|
22301
22340
|
const mixingFees24hr = Helpers.sumBigInt(
|