@7kprotocol/sdk-ts 3.6.1-beta.1 → 3.6.1-beta.2
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/README.md +13 -10
- package/dist/bluefin7k-I6ZCDWDN.js +2 -0
- package/dist/bluefin7k-I6ZCDWDN.js.map +1 -0
- package/dist/bluefin7k-TERLUCNL.mjs +2 -0
- package/dist/bluefin7k-TERLUCNL.mjs.map +1 -0
- package/dist/cetus-AU3OMWOY.mjs +2 -0
- package/dist/cetus-AU3OMWOY.mjs.map +1 -0
- package/dist/cetus-SIPX6FYL.js +2 -0
- package/dist/cetus-SIPX6FYL.js.map +1 -0
- package/dist/chunk-ETQEI4QC.mjs +2 -0
- package/dist/chunk-ETQEI4QC.mjs.map +1 -0
- package/dist/chunk-KVGSSW22.js +2 -0
- package/dist/chunk-KVGSSW22.js.map +1 -0
- package/dist/flowx-6M54WFWO.js +2 -0
- package/dist/flowx-6M54WFWO.js.map +1 -0
- package/dist/flowx-OXZZX5FD.mjs +2 -0
- package/dist/flowx-OXZZX5FD.mjs.map +1 -0
- package/dist/index.d.mts +536 -0
- package/dist/index.d.ts +536 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +12 -20
- package/lib/cjs/config/fetchClient.js +0 -12
- package/lib/cjs/constants/_7k.js +0 -20
- package/lib/cjs/constants/apiEndpoints.js +0 -9
- package/lib/cjs/constants/sui.js +0 -4
- package/lib/cjs/constants/tokens.js +0 -7
- package/lib/cjs/features/limitDca/cancelDcaOrder.js +0 -14
- package/lib/cjs/features/limitDca/cancelLimitOrder.js +0 -14
- package/lib/cjs/features/limitDca/claimExpiredLimitOrder.js +0 -14
- package/lib/cjs/features/limitDca/constants.js +0 -13
- package/lib/cjs/features/limitDca/getClosedDcaOrders.js +0 -23
- package/lib/cjs/features/limitDca/getClosedLimitOrders.js +0 -22
- package/lib/cjs/features/limitDca/getDcaOrderExecutions.js +0 -23
- package/lib/cjs/features/limitDca/getOpenDcaOrders.js +0 -22
- package/lib/cjs/features/limitDca/getOpenLimitOrders.js +0 -22
- package/lib/cjs/features/limitDca/index.js +0 -26
- package/lib/cjs/features/limitDca/placeDcaOrder.js +0 -33
- package/lib/cjs/features/limitDca/placeLimitOrder.js +0 -27
- package/lib/cjs/features/limitDca/types.js +0 -16
- package/lib/cjs/features/metaAg/common.js +0 -103
- package/lib/cjs/features/metaAg/error.js +0 -31
- package/lib/cjs/features/metaAg/index.js +0 -268
- package/lib/cjs/features/metaAg/providers/bluefin7k.js +0 -57
- package/lib/cjs/features/metaAg/providers/cetus.js +0 -59
- package/lib/cjs/features/metaAg/providers/flowx.js +0 -52
- package/lib/cjs/features/metaAg/providers/okx.js +0 -182
- package/lib/cjs/features/prices/index.js +0 -99
- package/lib/cjs/index.js +0 -55
- package/lib/cjs/libs/url.js +0 -17
- package/lib/cjs/types/config/fetchClient.d.ts +0 -2
- package/lib/cjs/types/config/fetchClient.d.ts.map +0 -1
- package/lib/cjs/types/constants/_7k.d.ts +0 -6
- package/lib/cjs/types/constants/_7k.d.ts.map +0 -1
- package/lib/cjs/types/constants/apiEndpoints.d.ts +0 -7
- package/lib/cjs/types/constants/apiEndpoints.d.ts.map +0 -1
- package/lib/cjs/types/constants/sui.d.ts +0 -2
- package/lib/cjs/types/constants/sui.d.ts.map +0 -1
- package/lib/cjs/types/constants/tokens.d.ts +0 -5
- package/lib/cjs/types/constants/tokens.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/cancelDcaOrder.d.ts +0 -9
- package/lib/cjs/types/features/limitDca/cancelDcaOrder.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/cancelLimitOrder.d.ts +0 -9
- package/lib/cjs/types/features/limitDca/cancelLimitOrder.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/claimExpiredLimitOrder.d.ts +0 -9
- package/lib/cjs/types/features/limitDca/claimExpiredLimitOrder.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/constants.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/constants.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/getClosedDcaOrders.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/getClosedDcaOrders.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/getClosedLimitOrders.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/getClosedLimitOrders.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/getDcaOrderExecutions.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/getDcaOrderExecutions.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/getOpenDcaOrders.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/getOpenDcaOrders.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/getOpenLimitOrders.d.ts +0 -10
- package/lib/cjs/types/features/limitDca/getOpenLimitOrders.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/index.d.ts +0 -11
- package/lib/cjs/types/features/limitDca/index.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/placeDcaOrder.d.ts +0 -14
- package/lib/cjs/types/features/limitDca/placeDcaOrder.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/placeLimitOrder.d.ts +0 -13
- package/lib/cjs/types/features/limitDca/placeLimitOrder.d.ts.map +0 -1
- package/lib/cjs/types/features/limitDca/types.d.ts +0 -98
- package/lib/cjs/types/features/limitDca/types.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/common.d.ts +0 -24
- package/lib/cjs/types/features/metaAg/common.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/error.d.ts +0 -54
- package/lib/cjs/types/features/metaAg/error.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/index.d.ts +0 -42
- package/lib/cjs/types/features/metaAg/index.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin7k.d.ts +0 -11
- package/lib/cjs/types/features/metaAg/providers/bluefin7k.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts +0 -11
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts +0 -13
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts +0 -21
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +0 -1
- package/lib/cjs/types/features/prices/index.d.ts +0 -18
- package/lib/cjs/types/features/prices/index.d.ts.map +0 -1
- package/lib/cjs/types/index.d.ts +0 -23
- package/lib/cjs/types/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/url.d.ts +0 -2
- package/lib/cjs/types/libs/url.d.ts.map +0 -1
- package/lib/cjs/types/metaAg.js +0 -16
- package/lib/cjs/types/okx.js +0 -6
- package/lib/cjs/types/types/metaAg.d.ts +0 -165
- package/lib/cjs/types/types/metaAg.d.ts.map +0 -1
- package/lib/cjs/types/types/okx.d.ts +0 -206
- package/lib/cjs/types/types/okx.d.ts.map +0 -1
- package/lib/cjs/types/utils/ObjectCache.d.ts +0 -87
- package/lib/cjs/types/utils/ObjectCache.d.ts.map +0 -1
- package/lib/cjs/types/utils/SuiClientUtils.d.ts +0 -15
- package/lib/cjs/types/utils/SuiClientUtils.d.ts.map +0 -1
- package/lib/cjs/types/utils/sui.d.ts +0 -27
- package/lib/cjs/types/utils/sui.d.ts.map +0 -1
- package/lib/cjs/types/utils/swap.d.ts +0 -15
- package/lib/cjs/types/utils/swap.d.ts.map +0 -1
- package/lib/cjs/types/utils/token.d.ts +0 -4
- package/lib/cjs/types/utils/token.d.ts.map +0 -1
- package/lib/cjs/utils/ObjectCache.js +0 -273
- package/lib/cjs/utils/SuiClientUtils.js +0 -50
- package/lib/cjs/utils/sui.js +0 -96
- package/lib/cjs/utils/swap.js +0 -37
- package/lib/cjs/utils/token.js +0 -15
- package/lib/esm/config/fetchClient.js +0 -9
- package/lib/esm/constants/_7k.js +0 -17
- package/lib/esm/constants/apiEndpoints.js +0 -6
- package/lib/esm/constants/sui.js +0 -1
- package/lib/esm/constants/tokens.js +0 -4
- package/lib/esm/features/limitDca/cancelDcaOrder.js +0 -11
- package/lib/esm/features/limitDca/cancelLimitOrder.js +0 -11
- package/lib/esm/features/limitDca/claimExpiredLimitOrder.js +0 -11
- package/lib/esm/features/limitDca/constants.js +0 -10
- package/lib/esm/features/limitDca/getClosedDcaOrders.js +0 -20
- package/lib/esm/features/limitDca/getClosedLimitOrders.js +0 -19
- package/lib/esm/features/limitDca/getDcaOrderExecutions.js +0 -20
- package/lib/esm/features/limitDca/getOpenDcaOrders.js +0 -19
- package/lib/esm/features/limitDca/getOpenLimitOrders.js +0 -19
- package/lib/esm/features/limitDca/index.js +0 -10
- package/lib/esm/features/limitDca/placeDcaOrder.js +0 -30
- package/lib/esm/features/limitDca/placeLimitOrder.js +0 -24
- package/lib/esm/features/limitDca/types.js +0 -13
- package/lib/esm/features/metaAg/common.js +0 -96
- package/lib/esm/features/metaAg/error.js +0 -29
- package/lib/esm/features/metaAg/index.js +0 -234
- package/lib/esm/features/metaAg/providers/bluefin7k.js +0 -55
- package/lib/esm/features/metaAg/providers/cetus.js +0 -57
- package/lib/esm/features/metaAg/providers/flowx.js +0 -51
- package/lib/esm/features/metaAg/providers/okx.js +0 -147
- package/lib/esm/features/prices/index.js +0 -94
- package/lib/esm/index.mjs +0 -31
- package/lib/esm/libs/url.js +0 -14
- package/lib/esm/types/config/fetchClient.d.ts +0 -2
- package/lib/esm/types/config/fetchClient.d.ts.map +0 -1
- package/lib/esm/types/constants/_7k.d.ts +0 -6
- package/lib/esm/types/constants/_7k.d.ts.map +0 -1
- package/lib/esm/types/constants/apiEndpoints.d.ts +0 -7
- package/lib/esm/types/constants/apiEndpoints.d.ts.map +0 -1
- package/lib/esm/types/constants/sui.d.ts +0 -2
- package/lib/esm/types/constants/sui.d.ts.map +0 -1
- package/lib/esm/types/constants/tokens.d.ts +0 -5
- package/lib/esm/types/constants/tokens.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/cancelDcaOrder.d.ts +0 -9
- package/lib/esm/types/features/limitDca/cancelDcaOrder.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/cancelLimitOrder.d.ts +0 -9
- package/lib/esm/types/features/limitDca/cancelLimitOrder.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/claimExpiredLimitOrder.d.ts +0 -9
- package/lib/esm/types/features/limitDca/claimExpiredLimitOrder.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/constants.d.ts +0 -10
- package/lib/esm/types/features/limitDca/constants.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/getClosedDcaOrders.d.ts +0 -10
- package/lib/esm/types/features/limitDca/getClosedDcaOrders.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/getClosedLimitOrders.d.ts +0 -10
- package/lib/esm/types/features/limitDca/getClosedLimitOrders.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/getDcaOrderExecutions.d.ts +0 -10
- package/lib/esm/types/features/limitDca/getDcaOrderExecutions.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/getOpenDcaOrders.d.ts +0 -10
- package/lib/esm/types/features/limitDca/getOpenDcaOrders.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/getOpenLimitOrders.d.ts +0 -10
- package/lib/esm/types/features/limitDca/getOpenLimitOrders.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/index.d.ts +0 -11
- package/lib/esm/types/features/limitDca/index.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/placeDcaOrder.d.ts +0 -14
- package/lib/esm/types/features/limitDca/placeDcaOrder.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/placeLimitOrder.d.ts +0 -13
- package/lib/esm/types/features/limitDca/placeLimitOrder.d.ts.map +0 -1
- package/lib/esm/types/features/limitDca/types.d.ts +0 -98
- package/lib/esm/types/features/limitDca/types.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/common.d.ts +0 -24
- package/lib/esm/types/features/metaAg/common.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/error.d.ts +0 -54
- package/lib/esm/types/features/metaAg/error.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/index.d.ts +0 -42
- package/lib/esm/types/features/metaAg/index.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/bluefin7k.d.ts +0 -11
- package/lib/esm/types/features/metaAg/providers/bluefin7k.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts +0 -11
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts +0 -13
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/okx.d.ts +0 -21
- package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +0 -1
- package/lib/esm/types/features/prices/index.d.ts +0 -18
- package/lib/esm/types/features/prices/index.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -23
- package/lib/esm/types/index.d.ts.map +0 -1
- package/lib/esm/types/libs/url.d.ts +0 -2
- package/lib/esm/types/libs/url.d.ts.map +0 -1
- package/lib/esm/types/metaAg.js +0 -11
- package/lib/esm/types/okx.js +0 -5
- package/lib/esm/types/types/metaAg.d.ts +0 -165
- package/lib/esm/types/types/metaAg.d.ts.map +0 -1
- package/lib/esm/types/types/okx.d.ts +0 -206
- package/lib/esm/types/types/okx.d.ts.map +0 -1
- package/lib/esm/types/utils/ObjectCache.d.ts +0 -87
- package/lib/esm/types/utils/ObjectCache.d.ts.map +0 -1
- package/lib/esm/types/utils/SuiClientUtils.d.ts +0 -15
- package/lib/esm/types/utils/SuiClientUtils.d.ts.map +0 -1
- package/lib/esm/types/utils/sui.d.ts +0 -27
- package/lib/esm/types/utils/sui.d.ts.map +0 -1
- package/lib/esm/types/utils/swap.d.ts +0 -15
- package/lib/esm/types/utils/swap.d.ts.map +0 -1
- package/lib/esm/types/utils/token.d.ts +0 -4
- package/lib/esm/types/utils/token.d.ts.map +0 -1
- package/lib/esm/utils/ObjectCache.js +0 -250
- package/lib/esm/utils/SuiClientUtils.js +0 -34
- package/lib/esm/utils/sui.js +0 -92
- package/lib/esm/utils/swap.js +0 -33
- package/lib/esm/utils/token.js +0 -10
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
2
|
-
export class AsyncCache {
|
|
3
|
-
async getObject(id) {
|
|
4
|
-
const [owned, shared] = await Promise.all([
|
|
5
|
-
this.get("OwnedObject", id),
|
|
6
|
-
this.get("SharedOrImmutableObject", id),
|
|
7
|
-
]);
|
|
8
|
-
return owned ?? shared ?? null;
|
|
9
|
-
}
|
|
10
|
-
async getObjects(ids) {
|
|
11
|
-
return Promise.all(ids.map((id) => this.getObject(id)));
|
|
12
|
-
}
|
|
13
|
-
async addObject(object) {
|
|
14
|
-
if (object.owner) {
|
|
15
|
-
await this.set("OwnedObject", object.objectId, object);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
await this.set("SharedOrImmutableObject", object.objectId, object);
|
|
19
|
-
}
|
|
20
|
-
return object;
|
|
21
|
-
}
|
|
22
|
-
async addObjects(objects) {
|
|
23
|
-
await Promise.all(objects.map(async (object) => this.addObject(object)));
|
|
24
|
-
}
|
|
25
|
-
async deleteObject(id) {
|
|
26
|
-
await Promise.all([
|
|
27
|
-
this.delete("OwnedObject", id),
|
|
28
|
-
this.delete("SharedOrImmutableObject", id),
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
async deleteObjects(ids) {
|
|
32
|
-
await Promise.all(ids.map((id) => this.deleteObject(id)));
|
|
33
|
-
}
|
|
34
|
-
async getMoveFunctionDefinition(ref) {
|
|
35
|
-
const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
|
|
36
|
-
return this.get("MoveFunction", functionName);
|
|
37
|
-
}
|
|
38
|
-
async addMoveFunctionDefinition(functionEntry) {
|
|
39
|
-
const pkg = normalizeSuiAddress(functionEntry.package);
|
|
40
|
-
const functionName = `${pkg}::${functionEntry.module}::${functionEntry.function}`;
|
|
41
|
-
const entry = {
|
|
42
|
-
...functionEntry,
|
|
43
|
-
package: pkg,
|
|
44
|
-
};
|
|
45
|
-
await this.set("MoveFunction", functionName, entry);
|
|
46
|
-
return entry;
|
|
47
|
-
}
|
|
48
|
-
async deleteMoveFunctionDefinition(ref) {
|
|
49
|
-
const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
|
|
50
|
-
await this.delete("MoveFunction", functionName);
|
|
51
|
-
}
|
|
52
|
-
async getCustom(key) {
|
|
53
|
-
return this.get("Custom", key);
|
|
54
|
-
}
|
|
55
|
-
async setCustom(key, value) {
|
|
56
|
-
return this.set("Custom", key, value);
|
|
57
|
-
}
|
|
58
|
-
async deleteCustom(key) {
|
|
59
|
-
return this.delete("Custom", key);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export class InMemoryObjectCache extends AsyncCache {
|
|
63
|
-
#caches = {
|
|
64
|
-
OwnedObject: new Map(),
|
|
65
|
-
SharedOrImmutableObject: new Map(),
|
|
66
|
-
MoveFunction: new Map(),
|
|
67
|
-
Custom: new Map(),
|
|
68
|
-
};
|
|
69
|
-
async get(type, key) {
|
|
70
|
-
return this.#caches[type].get(key) ?? null;
|
|
71
|
-
}
|
|
72
|
-
async set(type, key, value) {
|
|
73
|
-
this.#caches[type].set(key, value);
|
|
74
|
-
}
|
|
75
|
-
async delete(type, key) {
|
|
76
|
-
this.#caches[type].delete(key);
|
|
77
|
-
}
|
|
78
|
-
async clear(type) {
|
|
79
|
-
if (type) {
|
|
80
|
-
this.#caches[type].clear();
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
for (const cache of Object.values(this.#caches)) {
|
|
84
|
-
cache.clear();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export class CustomObjectCache {
|
|
90
|
-
#client;
|
|
91
|
-
#cache;
|
|
92
|
-
#onEffects;
|
|
93
|
-
constructor({ cache = new InMemoryObjectCache(), onEffects, client, }) {
|
|
94
|
-
this.#client = client;
|
|
95
|
-
this.#cache = cache;
|
|
96
|
-
this.#onEffects = onEffects;
|
|
97
|
-
}
|
|
98
|
-
async applyCache(transactionData, unresolvedObjects) {
|
|
99
|
-
const cached = (await this.#cache.getObjects(unresolvedObjects)).filter((obj) => obj !== null);
|
|
100
|
-
const byId = new Map(cached.map((obj) => [obj.objectId, obj]));
|
|
101
|
-
const unresolved = [];
|
|
102
|
-
for (const input of transactionData.inputs) {
|
|
103
|
-
if (!input.UnresolvedObject) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const cached = byId.get(input.UnresolvedObject.objectId);
|
|
107
|
-
if (!cached) {
|
|
108
|
-
unresolved.push(input.UnresolvedObject.objectId);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (cached.initialSharedVersion &&
|
|
112
|
-
!input.UnresolvedObject.initialSharedVersion) {
|
|
113
|
-
input.UnresolvedObject.initialSharedVersion =
|
|
114
|
-
cached.initialSharedVersion;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
if (cached.version && !input.UnresolvedObject.version) {
|
|
118
|
-
input.UnresolvedObject.version = cached.version;
|
|
119
|
-
}
|
|
120
|
-
if (cached.digest && !input.UnresolvedObject.digest) {
|
|
121
|
-
input.UnresolvedObject.digest = cached.digest;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return unresolved;
|
|
126
|
-
}
|
|
127
|
-
async resolveObjects(transactionData, unresolved) {
|
|
128
|
-
const unresolvedObjects = await this.applyCache(transactionData, unresolved);
|
|
129
|
-
if (unresolvedObjects.length === 0) {
|
|
130
|
-
return [];
|
|
131
|
-
}
|
|
132
|
-
const dedup = [...new Set(unresolvedObjects)];
|
|
133
|
-
const res = await this.#client.multiGetObjects({
|
|
134
|
-
ids: dedup,
|
|
135
|
-
options: {
|
|
136
|
-
showOwner: true,
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
const objects = [];
|
|
140
|
-
for (const obj of res || []) {
|
|
141
|
-
if (!obj.data) {
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
const owner = obj.data.owner;
|
|
145
|
-
const initialSharedVersion = owner && typeof owner === "object" && "Shared" in owner
|
|
146
|
-
? owner.Shared.initial_shared_version
|
|
147
|
-
: null;
|
|
148
|
-
const ownerAddress = owner && typeof owner === "object" && "AddressOwner" in owner
|
|
149
|
-
? owner.AddressOwner
|
|
150
|
-
: null;
|
|
151
|
-
const cached = {
|
|
152
|
-
objectId: obj.data.objectId,
|
|
153
|
-
version: obj.data.version,
|
|
154
|
-
digest: obj.data.digest,
|
|
155
|
-
initialSharedVersion,
|
|
156
|
-
owner: ownerAddress,
|
|
157
|
-
};
|
|
158
|
-
objects.push(cached);
|
|
159
|
-
}
|
|
160
|
-
await this.#cache.addObjects(objects);
|
|
161
|
-
return await this.applyCache(transactionData, unresolvedObjects);
|
|
162
|
-
}
|
|
163
|
-
asPlugin() {
|
|
164
|
-
return async (transactionData, _options, next) => {
|
|
165
|
-
const unresolvedObjects = transactionData.inputs
|
|
166
|
-
.filter((input) => input.UnresolvedObject)
|
|
167
|
-
.map((input) => input.UnresolvedObject.objectId);
|
|
168
|
-
// if object is not in cache yet, fetch from RPC and save to cache and resolve all objects
|
|
169
|
-
await this.resolveObjects(transactionData, unresolvedObjects);
|
|
170
|
-
await Promise.all(transactionData.commands.map(async (commands) => {
|
|
171
|
-
if (commands.MoveCall) {
|
|
172
|
-
const def = await this.getMoveFunctionDefinition({
|
|
173
|
-
package: commands.MoveCall.package,
|
|
174
|
-
module: commands.MoveCall.module,
|
|
175
|
-
function: commands.MoveCall.function,
|
|
176
|
-
});
|
|
177
|
-
if (def) {
|
|
178
|
-
commands.MoveCall._argumentTypes = def.parameters;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}));
|
|
182
|
-
await next();
|
|
183
|
-
await Promise.all(transactionData.commands.map(async (commands) => {
|
|
184
|
-
if (commands.MoveCall?._argumentTypes) {
|
|
185
|
-
await this.#cache.addMoveFunctionDefinition({
|
|
186
|
-
package: commands.MoveCall.package,
|
|
187
|
-
module: commands.MoveCall.module,
|
|
188
|
-
function: commands.MoveCall.function,
|
|
189
|
-
parameters: commands.MoveCall._argumentTypes,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}));
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
async clear() {
|
|
196
|
-
await this.#cache.clear();
|
|
197
|
-
}
|
|
198
|
-
async getMoveFunctionDefinition(ref) {
|
|
199
|
-
return this.#cache.getMoveFunctionDefinition(ref);
|
|
200
|
-
}
|
|
201
|
-
async getObjects(ids) {
|
|
202
|
-
return this.#cache.getObjects(ids);
|
|
203
|
-
}
|
|
204
|
-
async deleteObjects(ids) {
|
|
205
|
-
return this.#cache.deleteObjects(ids);
|
|
206
|
-
}
|
|
207
|
-
async clearOwnedObjects() {
|
|
208
|
-
await this.#cache.clear("OwnedObject");
|
|
209
|
-
}
|
|
210
|
-
async clearCustom() {
|
|
211
|
-
await this.#cache.clear("Custom");
|
|
212
|
-
}
|
|
213
|
-
async getCustom(key) {
|
|
214
|
-
return this.#cache.getCustom(key);
|
|
215
|
-
}
|
|
216
|
-
async setCustom(key, value) {
|
|
217
|
-
return this.#cache.setCustom(key, value);
|
|
218
|
-
}
|
|
219
|
-
async deleteCustom(key) {
|
|
220
|
-
return this.#cache.deleteCustom(key);
|
|
221
|
-
}
|
|
222
|
-
async applyEffects(effects) {
|
|
223
|
-
if (!effects.V2) {
|
|
224
|
-
throw new Error(`Unsupported transaction effects version ${effects.$kind}`);
|
|
225
|
-
}
|
|
226
|
-
const { lamportVersion, changedObjects } = effects.V2;
|
|
227
|
-
const deletedIds = [];
|
|
228
|
-
const addedObjects = [];
|
|
229
|
-
changedObjects.forEach(([id, change]) => {
|
|
230
|
-
if (change.outputState.NotExist) {
|
|
231
|
-
deletedIds.push(id);
|
|
232
|
-
}
|
|
233
|
-
else if (change.outputState.ObjectWrite) {
|
|
234
|
-
const [digest, owner] = change.outputState.ObjectWrite;
|
|
235
|
-
addedObjects.push({
|
|
236
|
-
objectId: id,
|
|
237
|
-
digest,
|
|
238
|
-
version: lamportVersion,
|
|
239
|
-
owner: owner.AddressOwner ?? owner.ObjectOwner ?? null,
|
|
240
|
-
initialSharedVersion: owner.Shared?.initialSharedVersion ?? null,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
await Promise.all([
|
|
245
|
-
this.#cache.addObjects(addedObjects),
|
|
246
|
-
this.#cache.deleteObjects(deletedIds),
|
|
247
|
-
this.#onEffects?.(effects),
|
|
248
|
-
]);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
-
import { CustomObjectCache } from "./ObjectCache";
|
|
3
|
-
/**
|
|
4
|
-
* Utility class for interacting with Sui blockchain coins
|
|
5
|
-
*/
|
|
6
|
-
export class SuiClientUtils {
|
|
7
|
-
client;
|
|
8
|
-
#devInspectCache;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new instance of SuiClientUtils
|
|
11
|
-
* @param client - The Sui client instance to use for blockchain interactions
|
|
12
|
-
*/
|
|
13
|
-
constructor(client) {
|
|
14
|
-
this.client = client;
|
|
15
|
-
this.#devInspectCache = new CustomObjectCache({ client: this.client });
|
|
16
|
-
}
|
|
17
|
-
devInspectTransactionBlock = async (params) => {
|
|
18
|
-
if (params.transactionBlock instanceof Transaction) {
|
|
19
|
-
params.transactionBlock.addBuildPlugin(this.#devInspectCache.asPlugin());
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const res = await this.client.devInspectTransactionBlock(params);
|
|
23
|
-
return res;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
// clear all cache if devInspectTransactionBlock fails
|
|
27
|
-
await this.#devInspectCache.clear();
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
finally {
|
|
31
|
-
await this.#devInspectCache.clearOwnedObjects();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
package/lib/esm/utils/sui.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { normalizeSuiAddress, parseStructTag } from "@mysten/sui/utils";
|
|
2
|
-
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_VAULT, } from "../constants/_7k";
|
|
3
|
-
export const SuiUtils = {
|
|
4
|
-
getSuiCoin(amount, txb) {
|
|
5
|
-
const [coin] = txb.splitCoins(txb.gas, [amount]);
|
|
6
|
-
return coin;
|
|
7
|
-
},
|
|
8
|
-
getCoinValue(coinType, coinObject, txb) {
|
|
9
|
-
const inputCoinObject = typeof coinObject == "string" ? txb.object(coinObject) : coinObject;
|
|
10
|
-
const [value] = txb.moveCall({
|
|
11
|
-
target: `0x2::coin::value`,
|
|
12
|
-
typeArguments: [coinType],
|
|
13
|
-
arguments: [inputCoinObject],
|
|
14
|
-
});
|
|
15
|
-
return value;
|
|
16
|
-
},
|
|
17
|
-
isValidStructTag(value) {
|
|
18
|
-
try {
|
|
19
|
-
return !!parseStructTag(value);
|
|
20
|
-
}
|
|
21
|
-
catch (_) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
zeroBalance(tx, coinType) {
|
|
26
|
-
return tx.moveCall({
|
|
27
|
-
target: `0x2::balance::zero`,
|
|
28
|
-
typeArguments: [coinType],
|
|
29
|
-
arguments: [],
|
|
30
|
-
})[0];
|
|
31
|
-
},
|
|
32
|
-
zeroCoin(tx, coinType) {
|
|
33
|
-
return tx.moveCall({
|
|
34
|
-
target: `0x2::coin::zero`,
|
|
35
|
-
typeArguments: [coinType],
|
|
36
|
-
arguments: [],
|
|
37
|
-
})[0];
|
|
38
|
-
},
|
|
39
|
-
coinIntoBalance(tx, coinType, coinObject) {
|
|
40
|
-
return tx.moveCall({
|
|
41
|
-
target: `0x2::coin::into_balance`,
|
|
42
|
-
typeArguments: [coinType],
|
|
43
|
-
arguments: [coinObject],
|
|
44
|
-
})[0];
|
|
45
|
-
},
|
|
46
|
-
coinFromBalance(tx, coinType, balance) {
|
|
47
|
-
return tx.moveCall({
|
|
48
|
-
target: `0x2::coin::from_balance`,
|
|
49
|
-
typeArguments: [coinType],
|
|
50
|
-
arguments: [balance],
|
|
51
|
-
})[0];
|
|
52
|
-
},
|
|
53
|
-
balanceDestroyZero(tx, coinType, balance) {
|
|
54
|
-
tx.moveCall({
|
|
55
|
-
target: `0x2::balance::destroy_zero`,
|
|
56
|
-
typeArguments: [coinType],
|
|
57
|
-
arguments: [balance],
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
collectDust(tx, coinType, coin) {
|
|
61
|
-
tx.moveCall({
|
|
62
|
-
target: `${_7K_META_PACKAGE_ID}::vault::collect_dust`,
|
|
63
|
-
typeArguments: [coinType],
|
|
64
|
-
arguments: [tx.object(_7K_META_VAULT), tx.object(_7K_META_CONFIG), coin],
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
transferOrDestroyZeroCoin(tx, coinType, coin, address) {
|
|
68
|
-
tx.moveCall({
|
|
69
|
-
target: `${_7K_META_PACKAGE_ID}::utils::transfer_or_destroy`,
|
|
70
|
-
typeArguments: [coinType],
|
|
71
|
-
arguments: [coin, tx.pure.address(address)],
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
export const isSystemAddress = (address) => {
|
|
76
|
-
const addr = normalizeSuiAddress(address);
|
|
77
|
-
const addresses = [
|
|
78
|
-
"0x0", // zero
|
|
79
|
-
"0x1", // std
|
|
80
|
-
"0x2", // sui framework
|
|
81
|
-
"0x3", // unkown but we reserved to be safe
|
|
82
|
-
"0x4", // unknown but we reserved to be safe
|
|
83
|
-
"0x5", // system state
|
|
84
|
-
"0x6", // time
|
|
85
|
-
"0x7", // unknown but we reserved to be safe
|
|
86
|
-
"0x8", // random
|
|
87
|
-
"0x9", // unknown but we reserved to be safe
|
|
88
|
-
"0x403", // coin deny list
|
|
89
|
-
"0xc", // coin registry
|
|
90
|
-
].map((v) => normalizeSuiAddress(v));
|
|
91
|
-
return addresses.includes(addr);
|
|
92
|
-
};
|
package/lib/esm/utils/swap.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate expected return amount after applying slippage, commission, and tip
|
|
3
|
-
* @param returnAmount - The raw return amount (with decimals)
|
|
4
|
-
* @param slippageBps - Slippage in basis points (1 bps = 0.01%)
|
|
5
|
-
* @param commissionBps - Commission in basis points
|
|
6
|
-
* @param tipBps - Tip in basis points (default: 0)
|
|
7
|
-
* @returns Object containing tipAmount, minAmount, commissionAmount, and expectedAmount
|
|
8
|
-
*/
|
|
9
|
-
export const getExpectedReturn = (returnAmount, slippageBps, commissionBps, tipBps = 0) => {
|
|
10
|
-
if (slippageBps > 10000) {
|
|
11
|
-
throw new Error("Slippage must be less than 100%");
|
|
12
|
-
}
|
|
13
|
-
if (commissionBps > 10000) {
|
|
14
|
-
throw new Error("Commission must be less than 100%");
|
|
15
|
-
}
|
|
16
|
-
if (tipBps > 10000) {
|
|
17
|
-
throw new Error("Tip must be less than 100%");
|
|
18
|
-
}
|
|
19
|
-
const returnAmountWithDecimal = BigInt(returnAmount);
|
|
20
|
-
const tipAmountWithDecimal = (returnAmountWithDecimal * BigInt(tipBps || 0)) / 10000n;
|
|
21
|
-
const commissionAmountWithDecimal = ((returnAmountWithDecimal - tipAmountWithDecimal) * BigInt(commissionBps)) /
|
|
22
|
-
10000n;
|
|
23
|
-
const expectedReturnWithDecimal = returnAmountWithDecimal -
|
|
24
|
-
tipAmountWithDecimal -
|
|
25
|
-
commissionAmountWithDecimal;
|
|
26
|
-
const minAmountWithDecimal = (expectedReturnWithDecimal * BigInt(1e4 - slippageBps)) / 10000n;
|
|
27
|
-
return {
|
|
28
|
-
tipAmount: tipAmountWithDecimal,
|
|
29
|
-
minAmount: minAmountWithDecimal,
|
|
30
|
-
commissionAmount: commissionAmountWithDecimal,
|
|
31
|
-
expectedAmount: expectedReturnWithDecimal.toString(10),
|
|
32
|
-
};
|
|
33
|
-
};
|
package/lib/esm/utils/token.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SUI_FULL_TYPE, SUI_TYPE } from "../constants/tokens";
|
|
2
|
-
export function normalizeTokenType(type) {
|
|
3
|
-
return type === SUI_TYPE ? SUI_FULL_TYPE : type;
|
|
4
|
-
}
|
|
5
|
-
export function denormalizeTokenType(type) {
|
|
6
|
-
return type === SUI_FULL_TYPE ? SUI_TYPE : type;
|
|
7
|
-
}
|
|
8
|
-
export function checkIsSui(type) {
|
|
9
|
-
return type === SUI_FULL_TYPE || type === SUI_TYPE;
|
|
10
|
-
}
|