@7kprotocol/sdk-ts 2.3.6 → 2.4.0
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 +31 -3
- package/lib/cjs/config/fetchClient.js +24 -0
- package/lib/cjs/{suiClient.js → config/index.js} +15 -2
- package/lib/cjs/constants/apiEndpoints.js +9 -0
- package/lib/cjs/features/limitDca/constants.js +2 -1
- package/lib/cjs/features/limitDca/getClosedDcaOrders.js +2 -1
- package/lib/cjs/features/limitDca/getClosedLimitOrders.js +2 -1
- package/lib/cjs/features/limitDca/getDcaOrderExecutions.js +2 -1
- package/lib/cjs/features/limitDca/getOpenDcaOrders.js +2 -1
- package/lib/cjs/features/limitDca/getOpenLimitOrders.js +2 -1
- package/lib/cjs/features/prices/index.js +4 -4
- package/lib/cjs/features/swap/config.js +3 -1
- package/lib/cjs/features/swap/estimateGasFee.js +2 -2
- package/lib/cjs/features/swap/getQuote.js +3 -1
- package/lib/cjs/features/swap/getSwapHistory.js +3 -1
- package/lib/cjs/index.js +12 -6
- package/lib/cjs/libs/getCoinOjectIdsByAmount.js +2 -2
- package/lib/cjs/types/config/fetchClient.d.ts +2 -0
- package/lib/cjs/types/config/fetchClient.d.ts.map +1 -0
- package/lib/cjs/types/config/index.d.ts +13 -0
- package/lib/cjs/types/config/index.d.ts.map +1 -0
- package/lib/cjs/types/constants/apiEndpoints.d.ts +7 -0
- package/lib/cjs/types/constants/apiEndpoints.d.ts.map +1 -0
- package/lib/cjs/types/features/limitDca/constants.d.ts +1 -1
- package/lib/cjs/types/features/limitDca/constants.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/getClosedDcaOrders.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/getClosedLimitOrders.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/getDcaOrderExecutions.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/getOpenDcaOrders.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/getOpenLimitOrders.d.ts.map +1 -1
- package/lib/cjs/types/features/prices/index.d.ts +0 -1
- package/lib/cjs/types/features/prices/index.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/config.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/getSwapHistory.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +12 -4
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/utils/token.d.ts +0 -2
- package/lib/cjs/types/utils/token.d.ts.map +1 -1
- package/lib/cjs/utils/sui.js +3 -3
- package/lib/cjs/utils/token.js +0 -21
- package/lib/esm/config/fetchClient.js +13 -0
- package/lib/esm/config/index.js +24 -0
- package/lib/esm/constants/apiEndpoints.js +6 -0
- package/lib/esm/features/limitDca/constants.js +2 -1
- package/lib/esm/features/limitDca/getClosedDcaOrders.js +2 -1
- package/lib/esm/features/limitDca/getClosedLimitOrders.js +2 -1
- package/lib/esm/features/limitDca/getDcaOrderExecutions.js +2 -1
- package/lib/esm/features/limitDca/getOpenDcaOrders.js +2 -1
- package/lib/esm/features/limitDca/getOpenLimitOrders.js +2 -1
- package/lib/esm/features/prices/index.js +4 -3
- package/lib/esm/features/swap/config.js +3 -1
- package/lib/esm/features/swap/estimateGasFee.js +2 -2
- package/lib/esm/features/swap/getQuote.js +3 -1
- package/lib/esm/features/swap/getSwapHistory.js +3 -1
- package/lib/esm/index.mjs +8 -1
- package/lib/esm/libs/getCoinOjectIdsByAmount.js +2 -2
- package/lib/esm/types/config/fetchClient.d.ts +2 -0
- package/lib/esm/types/config/fetchClient.d.ts.map +1 -0
- package/lib/esm/types/config/index.d.ts +13 -0
- package/lib/esm/types/config/index.d.ts.map +1 -0
- package/lib/esm/types/constants/apiEndpoints.d.ts +7 -0
- package/lib/esm/types/constants/apiEndpoints.d.ts.map +1 -0
- package/lib/esm/types/features/limitDca/constants.d.ts +1 -1
- package/lib/esm/types/features/limitDca/constants.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/getClosedDcaOrders.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/getClosedLimitOrders.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/getDcaOrderExecutions.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/getOpenDcaOrders.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/getOpenLimitOrders.d.ts.map +1 -1
- package/lib/esm/types/features/prices/index.d.ts +0 -1
- package/lib/esm/types/features/prices/index.d.ts.map +1 -1
- package/lib/esm/types/features/swap/config.d.ts.map +1 -1
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/types/features/swap/getSwapHistory.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +12 -4
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/utils/token.d.ts +0 -2
- package/lib/esm/types/utils/token.d.ts.map +1 -1
- package/lib/esm/utils/sui.js +3 -3
- package/lib/esm/utils/token.js +0 -9
- package/package.json +1 -1
- package/lib/cjs/constants/explorer.js +0 -6
- package/lib/cjs/types/constants/explorer.d.ts +0 -4
- package/lib/cjs/types/constants/explorer.d.ts.map +0 -1
- package/lib/cjs/types/suiClient.d.ts +0 -4
- package/lib/cjs/types/suiClient.d.ts.map +0 -1
- package/lib/cjs/types/token.js +0 -2
- package/lib/cjs/types/types/token.d.ts +0 -30
- package/lib/cjs/types/types/token.d.ts.map +0 -1
- package/lib/esm/constants/explorer.js +0 -3
- package/lib/esm/suiClient.js +0 -10
- package/lib/esm/types/constants/explorer.d.ts +0 -4
- package/lib/esm/types/constants/explorer.d.ts.map +0 -1
- package/lib/esm/types/suiClient.d.ts +0 -4
- package/lib/esm/types/suiClient.d.ts.map +0 -1
- package/lib/esm/types/token.js +0 -1
- package/lib/esm/types/types/token.d.ts +0 -30
- package/lib/esm/types/types/token.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -8,17 +8,45 @@ npm i @7kprotocol/sdk-ts
|
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
You can import the entire SDK as a module:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import SevenK from "@7kprotocol/sdk-ts";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or import specific functions as needed:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { getQuote, buildTx } from "@7kprotocol/sdk-ts";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Config
|
|
24
|
+
|
|
25
|
+
Configuration is optional, but if provided, it must be set before invoking any
|
|
26
|
+
SDK functions.
|
|
27
|
+
|
|
28
|
+
### Set API Key
|
|
29
|
+
|
|
30
|
+
If you’re calling our API from your server, contact us to request dedicated API
|
|
31
|
+
keys and minimize the risk of rate limiting.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Config } from "@7kprotocol/sdk-ts";
|
|
35
|
+
|
|
36
|
+
Config.setApiKey("YOUR_API_KEY");
|
|
37
|
+
console.log("API key", Config.getApiKey());
|
|
38
|
+
```
|
|
12
39
|
|
|
13
40
|
### Set Sui Client
|
|
14
41
|
|
|
15
42
|
```typescript
|
|
16
43
|
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
|
|
17
|
-
import {
|
|
44
|
+
import { Config } from "@7kprotocol/sdk-ts";
|
|
18
45
|
|
|
19
46
|
const network = "mainnet";
|
|
20
47
|
const suiClient = new SuiClient({ url: getFullnodeUrl(network) });
|
|
21
|
-
setSuiClient(suiClient);
|
|
48
|
+
Config.setSuiClient(suiClient);
|
|
49
|
+
console.log("Sui client", Config.getSuiClient());
|
|
22
50
|
```
|
|
23
51
|
|
|
24
52
|
Note: this package only supports **mainnet** for now.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchClient = fetchClient;
|
|
13
|
+
const index_1 = require("./index");
|
|
14
|
+
function fetchClient(input, init) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
17
|
+
const apiKey = (index_1.Config.getApiKey() || "").trim();
|
|
18
|
+
if (apiKey) {
|
|
19
|
+
headers.set("apiKey", apiKey);
|
|
20
|
+
}
|
|
21
|
+
const modifiedInit = Object.assign(Object.assign({}, init), { headers });
|
|
22
|
+
return fetch(input, modifiedInit);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.setSuiClient = setSuiClient;
|
|
3
|
+
exports.Config = void 0;
|
|
5
4
|
const client_1 = require("@mysten/sui/client");
|
|
5
|
+
let apiKey = "";
|
|
6
6
|
let suiClient = new client_1.SuiClient({
|
|
7
7
|
url: (0, client_1.getFullnodeUrl)("mainnet"),
|
|
8
8
|
});
|
|
9
|
+
function setApiKey(key) {
|
|
10
|
+
apiKey = key;
|
|
11
|
+
}
|
|
12
|
+
function getApiKey() {
|
|
13
|
+
return apiKey;
|
|
14
|
+
}
|
|
9
15
|
function getSuiClient() {
|
|
10
16
|
return suiClient;
|
|
11
17
|
}
|
|
12
18
|
function setSuiClient(client) {
|
|
13
19
|
suiClient = client;
|
|
14
20
|
}
|
|
21
|
+
const Config = {
|
|
22
|
+
setApiKey,
|
|
23
|
+
getApiKey,
|
|
24
|
+
setSuiClient,
|
|
25
|
+
getSuiClient,
|
|
26
|
+
};
|
|
27
|
+
exports.Config = Config;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_ENDPOINTS = void 0;
|
|
4
|
+
exports.API_ENDPOINTS = {
|
|
5
|
+
MAIN: "https://api.7k.ag",
|
|
6
|
+
LO_DCA: "https://lod-dca.7k.ag",
|
|
7
|
+
PRICES: "https://prices.7k.ag",
|
|
8
|
+
STATISTIC: "https://statistic.7k.ag",
|
|
9
|
+
};
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LO_DCA_API = exports.DCA_MAX_RATE = exports.CONFIG_MODULE_ID = exports.DCA_ORDER_MODULE_ID = exports.LIMIT_ORDER_MODULE_ID = exports.PACKAGE = exports.SLIPPAGE_SCALE = exports.RATE_SCALE = exports.GLOBAL_CONFIG_ID = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
8
9
|
exports.GLOBAL_CONFIG_ID = "0xffc7f420b481ed7a012b42e125fd7e5716b5673759cf4629e5fcfebce970a72d";
|
|
9
10
|
exports.RATE_SCALE = BigInt("1000000000000");
|
|
10
11
|
exports.SLIPPAGE_SCALE = BigInt("10000");
|
|
@@ -13,4 +14,4 @@ exports.LIMIT_ORDER_MODULE_ID = `${exports.PACKAGE}::limit_order`;
|
|
|
13
14
|
exports.DCA_ORDER_MODULE_ID = `${exports.PACKAGE}::dca_order`;
|
|
14
15
|
exports.CONFIG_MODULE_ID = `${exports.PACKAGE}::config`;
|
|
15
16
|
exports.DCA_MAX_RATE = new bignumber_js_1.default("18446744073709551615");
|
|
16
|
-
exports.LO_DCA_API =
|
|
17
|
+
exports.LO_DCA_API = `${apiEndpoints_1.API_ENDPOINTS.LO_DCA}/api`;
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getClosedDcaOrders = getClosedDcaOrders;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
13
14
|
const url_1 = require("../../libs/url");
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
function getClosedDcaOrders(_a) {
|
|
@@ -23,7 +24,7 @@ function getClosedDcaOrders(_a) {
|
|
|
23
24
|
tokenPair,
|
|
24
25
|
};
|
|
25
26
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
26
|
-
const response = yield
|
|
27
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${constants_1.LO_DCA_API}/order-executions?${paramsStr}`);
|
|
27
28
|
if (!response.ok) {
|
|
28
29
|
throw new Error("Failed to fetch closed dca orders");
|
|
29
30
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getClosedLimitOrders = getClosedLimitOrders;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
13
14
|
const url_1 = require("../../libs/url");
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
function getClosedLimitOrders(_a) {
|
|
@@ -22,7 +23,7 @@ function getClosedLimitOrders(_a) {
|
|
|
22
23
|
tokenPair,
|
|
23
24
|
};
|
|
24
25
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
25
|
-
const response = yield
|
|
26
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${constants_1.LO_DCA_API}/limit-orders?${paramsStr}`);
|
|
26
27
|
if (!response.ok) {
|
|
27
28
|
throw new Error("Failed to fetch closed limit orders");
|
|
28
29
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getDcaOrderExecutions = getDcaOrderExecutions;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
13
14
|
const url_1 = require("../../libs/url");
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
function getDcaOrderExecutions(_a) {
|
|
@@ -23,7 +24,7 @@ function getDcaOrderExecutions(_a) {
|
|
|
23
24
|
orderType: "DCA",
|
|
24
25
|
};
|
|
25
26
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
26
|
-
const response = yield
|
|
27
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${constants_1.LO_DCA_API}/order-executions?${paramsStr}`);
|
|
27
28
|
if (!response.ok) {
|
|
28
29
|
throw new Error("Failed to fetch dca order executions");
|
|
29
30
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getOpenDcaOrders = getOpenDcaOrders;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
13
14
|
const url_1 = require("../../libs/url");
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
function getOpenDcaOrders(_a) {
|
|
@@ -22,7 +23,7 @@ function getOpenDcaOrders(_a) {
|
|
|
22
23
|
tokenPair,
|
|
23
24
|
};
|
|
24
25
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
25
|
-
const response = yield
|
|
26
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${constants_1.LO_DCA_API}/dca-orders?${paramsStr}`);
|
|
26
27
|
if (!response.ok) {
|
|
27
28
|
throw new Error("Failed to fetch open dca orders");
|
|
28
29
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getOpenLimitOrders = getOpenLimitOrders;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
13
14
|
const url_1 = require("../../libs/url");
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
function getOpenLimitOrders(_a) {
|
|
@@ -22,7 +23,7 @@ function getOpenLimitOrders(_a) {
|
|
|
22
23
|
tokenPair,
|
|
23
24
|
};
|
|
24
25
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
25
|
-
const response = yield
|
|
26
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${constants_1.LO_DCA_API}/limit-orders?${paramsStr}`);
|
|
26
27
|
if (!response.ok) {
|
|
27
28
|
throw new Error("Failed to fetch open limit orders");
|
|
28
29
|
}
|
|
@@ -9,18 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.PRICES_API = void 0;
|
|
13
12
|
exports.getTokenPrice = getTokenPrice;
|
|
14
13
|
exports.getTokenPrices = getTokenPrices;
|
|
15
14
|
exports.getSuiPrice = getSuiPrice;
|
|
15
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
16
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
16
17
|
const tokens_1 = require("../../constants/tokens");
|
|
17
18
|
const token_1 = require("../../utils/token");
|
|
18
|
-
exports.PRICES_API = "https://prices.7k.ag";
|
|
19
19
|
function getTokenPrice(id_1) {
|
|
20
20
|
return __awaiter(this, arguments, void 0, function* (id, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
|
|
21
21
|
var _a;
|
|
22
22
|
try {
|
|
23
|
-
const response = yield
|
|
23
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price?ids=${(0, token_1.normalizeTokenType)(id)}&vsCoin=${vsCoin}`);
|
|
24
24
|
const pricesRes = (yield response.json());
|
|
25
25
|
return Number(((_a = pricesRes === null || pricesRes === void 0 ? void 0 : pricesRes[id]) === null || _a === void 0 ? void 0 : _a.price) || 0);
|
|
26
26
|
}
|
|
@@ -44,7 +44,7 @@ function getTokenPrices(ids_1) {
|
|
|
44
44
|
const limitedIds = ids.slice(0, MAX_TOTAL_IDS).map(token_1.normalizeTokenType);
|
|
45
45
|
const idChunks = chunkArray(limitedIds, MAX_IDS_PER_REQUEST);
|
|
46
46
|
const responses = yield Promise.all(idChunks.map((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const response = yield
|
|
47
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price`, {
|
|
48
48
|
method: "POST",
|
|
49
49
|
headers: {
|
|
50
50
|
"Content-Type": "application/json",
|
|
@@ -11,6 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DEFAULT_CONFIG = void 0;
|
|
13
13
|
exports.getConfig = getConfig;
|
|
14
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
15
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
14
16
|
let config = null;
|
|
15
17
|
let configTs = 0;
|
|
16
18
|
exports.DEFAULT_CONFIG = {
|
|
@@ -108,7 +110,7 @@ function getConfig() {
|
|
|
108
110
|
return config;
|
|
109
111
|
}
|
|
110
112
|
try {
|
|
111
|
-
const response = yield
|
|
113
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/config`);
|
|
112
114
|
const quoteResponse = (yield response.json());
|
|
113
115
|
config = quoteResponse;
|
|
114
116
|
configTs = Date.now();
|
|
@@ -17,8 +17,8 @@ const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
|
17
17
|
const utils_1 = require("@mysten/sui/utils");
|
|
18
18
|
const buildTx_1 = require("./buildTx");
|
|
19
19
|
const number_1 = require("../../utils/number");
|
|
20
|
-
const suiClient_1 = require("../../suiClient");
|
|
21
20
|
const prices_1 = require("../prices");
|
|
21
|
+
const config_1 = require("../../config");
|
|
22
22
|
function estimateGasFee(_a) {
|
|
23
23
|
return __awaiter(this, arguments, void 0, function* ({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
|
|
24
24
|
if (!accountAddress)
|
|
@@ -39,7 +39,7 @@ function estimateGasFee(_a) {
|
|
|
39
39
|
return 0;
|
|
40
40
|
const suiPrice = _suiPrice || (yield (0, prices_1.getSuiPrice)());
|
|
41
41
|
const suiDecimals = utils_1.SUI_DECIMALS;
|
|
42
|
-
const { effects: { gasUsed, status }, } = yield
|
|
42
|
+
const { effects: { gasUsed, status }, } = yield config_1.Config.getSuiClient().devInspectTransactionBlock({
|
|
43
43
|
sender: accountAddress,
|
|
44
44
|
transactionBlock: tx,
|
|
45
45
|
});
|
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.DEFAULT_SOURCES = void 0;
|
|
13
13
|
exports.getQuote = getQuote;
|
|
14
14
|
const utils_1 = require("@mysten/sui/utils");
|
|
15
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
16
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
15
17
|
exports.DEFAULT_SOURCES = [
|
|
16
18
|
"suiswap",
|
|
17
19
|
"turbos",
|
|
@@ -45,7 +47,7 @@ function getQuote(_a) {
|
|
|
45
47
|
if (excludedPools === null || excludedPools === void 0 ? void 0 : excludedPools.length) {
|
|
46
48
|
params.append("excluded_pools", excludedPools.map((v) => (0, utils_1.normalizeSuiObjectId)(v)).join(","));
|
|
47
49
|
}
|
|
48
|
-
const response = yield
|
|
50
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/quote?${params}`);
|
|
49
51
|
if (!response.ok) {
|
|
50
52
|
throw new Error("Failed to fetch aggregator quote");
|
|
51
53
|
}
|
|
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getSwapHistory = getSwapHistory;
|
|
13
|
+
const fetchClient_1 = require("../../config/fetchClient");
|
|
14
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
13
15
|
const url_1 = require("../../libs/url");
|
|
14
16
|
function getSwapHistory(_a) {
|
|
15
17
|
return __awaiter(this, arguments, void 0, function* ({ owner, offset = 0, limit = 10, tokenPair, }) {
|
|
@@ -20,7 +22,7 @@ function getSwapHistory(_a) {
|
|
|
20
22
|
token_pair: tokenPair,
|
|
21
23
|
};
|
|
22
24
|
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
23
|
-
const response = yield
|
|
25
|
+
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.STATISTIC}/trading-history?${paramsStr}`);
|
|
24
26
|
if (!response.ok) {
|
|
25
27
|
throw new Error("Failed to fetch open limit orders");
|
|
26
28
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getDcaOrderExecutions = exports.getClosedDcaOrders = exports.cancelDcaOrder = exports.getOpenDcaOrders = exports.placeDcaOrder = exports.getClosedLimitOrders = exports.claimExpiredLimitOrder = exports.cancelLimitOrder = exports.getOpenLimitOrders = exports.placeLimitOrder = exports.getSwapHistory = exports.buildTx = exports.estimateGasFee = exports.getQuote = exports.getSuiPrice = exports.getTokenPrices = exports.getTokenPrice = exports.setSuiClient = exports.getSuiClient = void 0;
|
|
17
|
+
exports.getDcaOrderExecutions = exports.getClosedDcaOrders = exports.cancelDcaOrder = exports.getOpenDcaOrders = exports.placeDcaOrder = exports.getClosedLimitOrders = exports.claimExpiredLimitOrder = exports.cancelLimitOrder = exports.getOpenLimitOrders = exports.placeLimitOrder = exports.getSwapHistory = exports.buildTx = exports.estimateGasFee = exports.getQuote = exports.getSuiPrice = exports.getTokenPrices = exports.getTokenPrice = exports.setSuiClient = exports.getSuiClient = exports.Config = void 0;
|
|
18
18
|
__exportStar(require("./types/aggregator"), exports);
|
|
19
|
-
const
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
Object.defineProperty(exports, "setSuiClient", { enumerable: true, get: function () { return suiClient_1.setSuiClient; } });
|
|
19
|
+
const config_1 = require("./config");
|
|
20
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
22
21
|
const prices_1 = require("./features/prices");
|
|
23
22
|
Object.defineProperty(exports, "getTokenPrice", { enumerable: true, get: function () { return prices_1.getTokenPrice; } });
|
|
24
23
|
Object.defineProperty(exports, "getTokenPrices", { enumerable: true, get: function () { return prices_1.getTokenPrices; } });
|
|
@@ -39,10 +38,17 @@ Object.defineProperty(exports, "getOpenDcaOrders", { enumerable: true, get: func
|
|
|
39
38
|
Object.defineProperty(exports, "cancelDcaOrder", { enumerable: true, get: function () { return limitDca_1.cancelDcaOrder; } });
|
|
40
39
|
Object.defineProperty(exports, "getClosedDcaOrders", { enumerable: true, get: function () { return limitDca_1.getClosedDcaOrders; } });
|
|
41
40
|
Object.defineProperty(exports, "getDcaOrderExecutions", { enumerable: true, get: function () { return limitDca_1.getDcaOrderExecutions; } });
|
|
41
|
+
// avoid breaking changes
|
|
42
|
+
const getSuiClient = config_1.Config.getSuiClient;
|
|
43
|
+
exports.getSuiClient = getSuiClient;
|
|
44
|
+
const setSuiClient = config_1.Config.setSuiClient;
|
|
45
|
+
exports.setSuiClient = setSuiClient;
|
|
42
46
|
exports.default = {
|
|
47
|
+
// config
|
|
48
|
+
Config: config_1.Config,
|
|
43
49
|
// sui client
|
|
44
|
-
getSuiClient
|
|
45
|
-
setSuiClient
|
|
50
|
+
getSuiClient,
|
|
51
|
+
setSuiClient,
|
|
46
52
|
// prices
|
|
47
53
|
getTokenPrice: prices_1.getTokenPrice,
|
|
48
54
|
getTokenPrices: prices_1.getTokenPrices,
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getCoinOjectIdsByAmount = void 0;
|
|
16
16
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
|
-
const
|
|
17
|
+
const config_1 = require("../config");
|
|
18
18
|
const orderByKey = (array, key, sortBy) => {
|
|
19
19
|
if (!(array === null || array === void 0 ? void 0 : array.length)) {
|
|
20
20
|
return;
|
|
@@ -40,7 +40,7 @@ const getCoinOjectIdsByAmount = (address, amount, coinType) => __awaiter(void 0,
|
|
|
40
40
|
let nextCursor = undefined;
|
|
41
41
|
while (hasNextPage) {
|
|
42
42
|
try {
|
|
43
|
-
const coins = yield
|
|
43
|
+
const coins = yield config_1.Config.getSuiClient().getCoins({
|
|
44
44
|
owner: address,
|
|
45
45
|
coinType,
|
|
46
46
|
cursor: nextCursor,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchClient.d.ts","sourceRoot":"","sources":["../../../../src/config/fetchClient.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,QAAQ,CAAC,CAanB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
declare function setApiKey(key: string): void;
|
|
3
|
+
declare function getApiKey(): string;
|
|
4
|
+
declare function getSuiClient(): SuiClient;
|
|
5
|
+
declare function setSuiClient(client: SuiClient): void;
|
|
6
|
+
declare const Config: {
|
|
7
|
+
setApiKey: typeof setApiKey;
|
|
8
|
+
getApiKey: typeof getApiKey;
|
|
9
|
+
setSuiClient: typeof setSuiClient;
|
|
10
|
+
getSuiClient: typeof getSuiClient;
|
|
11
|
+
};
|
|
12
|
+
export { Config };
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,oBAAoB,CAAC;AAO/D,iBAAS,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEpC;AAED,iBAAS,SAAS,IAAI,MAAM,CAE3B;AAED,iBAAS,YAAY,IAAI,SAAS,CAEjC;AAED,iBAAS,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAE7C;AAED,QAAA,MAAM,MAAM;;;;;CAKX,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiEndpoints.d.ts","sourceRoot":"","sources":["../../../../src/constants/apiEndpoints.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;CAKzB,CAAC"}
|
|
@@ -7,5 +7,5 @@ export declare const LIMIT_ORDER_MODULE_ID = "0x0ef0f805710cf53c10f29c4f73e1144a
|
|
|
7
7
|
export declare const DCA_ORDER_MODULE_ID = "0x0ef0f805710cf53c10f29c4f73e1144a662747e1839689a846e2520cae122adc::dca_order";
|
|
8
8
|
export declare const CONFIG_MODULE_ID = "0x0ef0f805710cf53c10f29c4f73e1144a662747e1839689a846e2520cae122adc::config";
|
|
9
9
|
export declare const DCA_MAX_RATE: BigNumber;
|
|
10
|
-
export declare const LO_DCA_API
|
|
10
|
+
export declare const LO_DCA_API: string;
|
|
11
11
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/constants.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/constants.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,eAAO,MAAM,gBAAgB,uEACyC,CAAC;AACvE,eAAO,MAAM,UAAU,QAA0B,CAAC;AAClD,eAAO,MAAM,cAAc,QAAkB,CAAC;AAC9C,eAAO,MAAM,OAAO,uEACkD,CAAC;AACvE,eAAO,MAAM,qBAAqB,oFAA4B,CAAC;AAC/D,eAAO,MAAM,mBAAmB,kFAA0B,CAAC;AAC3D,eAAO,MAAM,gBAAgB,+EAAuB,CAAC;AACrD,eAAO,MAAM,YAAY,WAAwC,CAAC;AAClE,eAAO,MAAM,UAAU,QAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClosedDcaOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getClosedDcaOrders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getClosedDcaOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getClosedDcaOrders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAoB,MAAM,SAAS,CAAC;AAEhE,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,MAAU,EACV,KAAU,EACV,SAAS,GACV,EAAE,MAAM,kCAqBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClosedLimitOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getClosedLimitOrders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getClosedLimitOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getClosedLimitOrders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAoB,MAAM,SAAS,CAAC;AAEvD,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,EACL,MAAU,EACV,KAAU,EACV,SAAS,GACV,EAAE,MAAM,yBAkBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDcaOrderExecutions.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getDcaOrderExecutions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDcaOrderExecutions.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getDcaOrderExecutions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAoB,MAAM,SAAS,CAAC;AAEhE,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,qBAAqB,CAAC,EAC1C,KAAK,EACL,OAAO,EACP,MAAU,EACV,KAAU,GACX,EAAE,MAAM,kCAqBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOpenDcaOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getOpenDcaOrders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOpenDcaOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getOpenDcaOrders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAoB,MAAM,SAAS,CAAC;AAErD,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,MAAU,EACV,KAAU,EACV,SAAS,GACV,EAAE,MAAM,uBAkBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOpenLimitOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getOpenLimitOrders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOpenLimitOrders.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/getOpenLimitOrders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAoB,MAAM,SAAS,CAAC;AAEvD,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,MAAU,EACV,KAAU,EACV,SAAS,GACV,EAAE,MAAM,yBAkBR"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const PRICES_API = "https://prices.7k.ag";
|
|
2
1
|
export declare function getTokenPrice(id: string, vsCoin?: string): Promise<number>;
|
|
3
2
|
export declare function getTokenPrices(ids: string[], vsCoin?: string): Promise<Record<string, number>>;
|
|
4
3
|
export declare function getSuiPrice(): Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/prices/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/prices/index.ts"],"names":[],"mappings":"AAUA,wBAAsB,aAAa,CACjC,EAAE,EAAE,MAAM,EACV,MAAM,SAAyB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAUjB;AAYD,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EAAE,EACb,MAAM,SAAyB,GAC9B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkDjC;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAEnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIhD,eAAO,MAAM,cAAc,EAAE,MAwH5B,CAAC;AAEF,wBAAsB,SAAS,oBAe9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIlE,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,EAkBtC,CAAC;AAEF,wBAAsB,QAAQ,CAAC,EAC7B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAyB,EACzB,WAAW,EACX,aAAa,GACd,EAAE,MAAM,0BA2BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwapHistory.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getSwapHistory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSwapHistory.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getSwapHistory.ts"],"names":[],"mappings":"AAIA,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AASD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,UAAU,sBAAsB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED,wBAAsB,cAAc,CAAC,EACnC,KAAK,EACL,MAAU,EACV,KAAU,EACV,SAAS,GACV,EAAE,MAAM,mCAmBR"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
export * from "./types/aggregator";
|
|
2
|
-
import {
|
|
2
|
+
import { Config } from "./config";
|
|
3
3
|
import { getTokenPrice, getTokenPrices, getSuiPrice } from "./features/prices";
|
|
4
4
|
import { buildTx, getQuote, estimateGasFee, getSwapHistory } from "./features/swap";
|
|
5
5
|
import { placeLimitOrder, getOpenLimitOrders, cancelLimitOrder, claimExpiredLimitOrder, getClosedLimitOrders, placeDcaOrder, getOpenDcaOrders, cancelDcaOrder, getClosedDcaOrders, getDcaOrderExecutions } from "./features/limitDca";
|
|
6
|
-
|
|
6
|
+
declare const getSuiClient: () => import("@mysten/sui/dist/cjs/client").SuiClient;
|
|
7
|
+
declare const setSuiClient: (client: import("@mysten/sui/dist/cjs/client").SuiClient) => void;
|
|
8
|
+
export { Config, getSuiClient, setSuiClient, getTokenPrice, getTokenPrices, getSuiPrice, getQuote, estimateGasFee, buildTx, getSwapHistory, placeLimitOrder, getOpenLimitOrders, cancelLimitOrder, claimExpiredLimitOrder, getClosedLimitOrders, placeDcaOrder, getOpenDcaOrders, cancelDcaOrder, getClosedDcaOrders, getDcaOrderExecutions, };
|
|
7
9
|
declare const _default: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
Config: {
|
|
11
|
+
setApiKey: (key: string) => void;
|
|
12
|
+
getApiKey: () => string;
|
|
13
|
+
setSuiClient: (client: import("@mysten/sui/dist/cjs/client").SuiClient) => void;
|
|
14
|
+
getSuiClient: () => import("@mysten/sui/dist/cjs/client").SuiClient;
|
|
15
|
+
};
|
|
16
|
+
getSuiClient: () => import("@mysten/sui/dist/cjs/client").SuiClient;
|
|
17
|
+
setSuiClient: (client: import("@mysten/sui/dist/cjs/client").SuiClient) => void;
|
|
10
18
|
getTokenPrice: typeof getTokenPrice;
|
|
11
19
|
getTokenPrices: typeof getTokenPrices;
|
|
12
20
|
getSuiPrice: typeof getSuiPrice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EACL,OAAO,EACP,QAAQ,EACR,cAAc,EACd,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAG7B,QAAA,MAAM,YAAY,uDAAsB,CAAC;AACzC,QAAA,MAAM,YAAY,mEAAsB,CAAC;AAEzC,OAAO,EAEL,MAAM,EAGN,YAAY,EACZ,YAAY,EAGZ,aAAa,EACb,cAAc,EACd,WAAW,EAGX,QAAQ,EACR,cAAc,EACd,OAAO,EACP,cAAc,EAGd,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EAGpB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,GACtB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,wBAgCE"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { SuiscanToken } from "../types/token";
|
|
2
1
|
export declare function normalizeTokenType(type: string): string;
|
|
3
2
|
export declare function denormalizeTokenType(type: string): string;
|
|
4
3
|
export declare function checkIsSui(type: string): type is "0x2::sui::SUI" | "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
5
|
-
export declare function getSuiscanTokenMetadata(type: string): Promise<SuiscanToken>;
|
|
6
4
|
//# sourceMappingURL=token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../src/utils/token.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../../src/utils/token.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,UAE9C;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAEhD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,4GAEtC"}
|
package/lib/cjs/utils/sui.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.SuiUtils = void 0;
|
|
|
13
13
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
14
14
|
const utils_1 = require("@mysten/sui/utils");
|
|
15
15
|
const token_1 = require("./token");
|
|
16
|
-
const
|
|
16
|
+
const config_1 = require("../config");
|
|
17
17
|
exports.SuiUtils = {
|
|
18
18
|
getSuiCoin(amount, txb) {
|
|
19
19
|
const [coin] = txb.splitCoins(txb.gas, [amount]);
|
|
@@ -107,7 +107,7 @@ exports.SuiUtils = {
|
|
|
107
107
|
let iter = 0;
|
|
108
108
|
do {
|
|
109
109
|
try {
|
|
110
|
-
const res = yield
|
|
110
|
+
const res = yield config_1.Config.getSuiClient().getCoins({
|
|
111
111
|
owner: address,
|
|
112
112
|
coinType: type,
|
|
113
113
|
cursor: cursor,
|
|
@@ -155,7 +155,7 @@ exports.SuiUtils = {
|
|
|
155
155
|
const queryAll = paginationArgs === "all";
|
|
156
156
|
let nextCursor = queryAll ? null : paginationArgs.cursor;
|
|
157
157
|
do {
|
|
158
|
-
const res = yield
|
|
158
|
+
const res = yield config_1.Config.getSuiClient().getOwnedObjects(Object.assign(Object.assign({ owner }, query), { cursor: nextCursor, limit: queryAll ? null : paginationArgs.limit }));
|
|
159
159
|
if (res.data) {
|
|
160
160
|
result = [...result, ...res.data];
|
|
161
161
|
hasNextPage = res.hasNextPage;
|
package/lib/cjs/utils/token.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.normalizeTokenType = normalizeTokenType;
|
|
13
4
|
exports.denormalizeTokenType = denormalizeTokenType;
|
|
14
5
|
exports.checkIsSui = checkIsSui;
|
|
15
|
-
exports.getSuiscanTokenMetadata = getSuiscanTokenMetadata;
|
|
16
|
-
const explorer_1 = require("../constants/explorer");
|
|
17
6
|
const tokens_1 = require("../constants/tokens");
|
|
18
7
|
function normalizeTokenType(type) {
|
|
19
8
|
return type === tokens_1.SUI_TYPE ? tokens_1.SUI_FULL_TYPE : type;
|
|
@@ -24,13 +13,3 @@ function denormalizeTokenType(type) {
|
|
|
24
13
|
function checkIsSui(type) {
|
|
25
14
|
return type === tokens_1.SUI_FULL_TYPE || type === tokens_1.SUI_TYPE;
|
|
26
15
|
}
|
|
27
|
-
function getSuiscanTokenMetadata(type) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const response = yield fetch(`${explorer_1.EXPLORER.ADDRESS}/api/sui-backend/mainnet/api/coins/${denormalizeTokenType(type)}`);
|
|
30
|
-
if (!response.ok) {
|
|
31
|
-
throw new Error("Failed to fetch token metadata");
|
|
32
|
-
}
|
|
33
|
-
const data = yield response.json();
|
|
34
|
-
return Object.assign(Object.assign({}, data), { type: normalizeTokenType(data.type || "") });
|
|
35
|
-
});
|
|
36
|
-
}
|