@7kprotocol/sdk-ts 3.4.0 → 3.4.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/lib/cjs/features/swap/buildTx.js +11 -0
- package/lib/cjs/features/swap/getQuote.js +13 -2
- package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts +4 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/features/swap/buildTx.js +11 -0
- package/lib/esm/features/swap/getQuote.js +12 -1
- package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/esm/types/features/swap/getQuote.d.ts +4 -1
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ const aggregator_1 = require("../../types/aggregator");
|
|
|
14
14
|
const sui_1 = require("../../utils/sui");
|
|
15
15
|
const token_1 = require("../../utils/token");
|
|
16
16
|
const config_2 = require("./config");
|
|
17
|
+
const getQuote_1 = require("./getQuote");
|
|
17
18
|
const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }) => {
|
|
18
19
|
const isBluefinX = (0, aggregator_1.isBluefinXRouting)(quoteResponse);
|
|
19
20
|
const _commission = {
|
|
@@ -37,6 +38,7 @@ const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __
|
|
|
37
38
|
}
|
|
38
39
|
const tx = _tx || new transactions_1.Transaction();
|
|
39
40
|
const routes = (0, groupSwapRoutes_1.groupSwapRoutes)(quoteResponse);
|
|
41
|
+
validateRoutes(routes, isSponsored);
|
|
40
42
|
const splits = routes.map((group) => group[0]?.amount ?? "0");
|
|
41
43
|
let coinData;
|
|
42
44
|
if (coinIn) {
|
|
@@ -147,3 +149,12 @@ const updatePythPriceFeedsIfAny = async (tx, quoteResponse) => {
|
|
|
147
149
|
}
|
|
148
150
|
return pythMap;
|
|
149
151
|
};
|
|
152
|
+
const validateRoutes = (routes, isSponsored) => {
|
|
153
|
+
if (!isSponsored) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const hasOracleBasedSource = routes.some((g) => g.some((s) => getQuote_1.ORACLE_BASED_SOURCES.has(s.pool.type)));
|
|
157
|
+
if (hasOracleBasedSource) {
|
|
158
|
+
throw new Error("Oracle based sources are not supported for sponsored tx");
|
|
159
|
+
}
|
|
160
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SOURCES = void 0;
|
|
3
|
+
exports.ORACLE_BASED_SOURCES = exports.DEFAULT_SOURCES = void 0;
|
|
4
4
|
exports.getQuote = getQuote;
|
|
5
5
|
const utils_1 = require("@mysten/sui/utils");
|
|
6
6
|
const fetchClient_1 = require("../../config/fetchClient");
|
|
@@ -30,7 +30,18 @@ exports.DEFAULT_SOURCES = [
|
|
|
30
30
|
"sevenk_v1",
|
|
31
31
|
"fullsail",
|
|
32
32
|
];
|
|
33
|
-
|
|
33
|
+
exports.ORACLE_BASED_SOURCES = new Set([
|
|
34
|
+
"obric",
|
|
35
|
+
"haedal_pmm",
|
|
36
|
+
"sevenk_v1",
|
|
37
|
+
"steamm_oracle_quoter",
|
|
38
|
+
"steamm_oracle_quoter_v2",
|
|
39
|
+
]);
|
|
40
|
+
async function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources = exports.DEFAULT_SOURCES, commissionBps, targetPools, excludedPools, taker, isSponsored, }) {
|
|
41
|
+
let sources = _sources;
|
|
42
|
+
if (isSponsored) {
|
|
43
|
+
sources = _sources.filter((s) => !exports.ORACLE_BASED_SOURCES.has(s));
|
|
44
|
+
}
|
|
34
45
|
const params = new URLSearchParams({
|
|
35
46
|
amount: amountIn,
|
|
36
47
|
from: (0, utils_1.normalizeStructTag)(tokenIn),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,aAAa,EAKd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM/C,eAAO,MAAM,OAAO,GAAU,2GAQ3B,aAAa,KAAG,OAAO,CAAC,aAAa,CA6IvC,CAAC"}
|
|
@@ -15,8 +15,11 @@ interface Params {
|
|
|
15
15
|
excludedPools?: string[];
|
|
16
16
|
/** The taker address, required for bluefinx */
|
|
17
17
|
taker?: string;
|
|
18
|
+
/** If true, excludes all liquidity sources that depend on pyth price feeds - pyth client use tx.gas to pay the fee*/
|
|
19
|
+
isSponsored?: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare const DEFAULT_SOURCES: SourceDex[];
|
|
20
|
-
export declare
|
|
22
|
+
export declare const ORACLE_BASED_SOURCES: Set<SourceDex>;
|
|
23
|
+
export declare function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources, commissionBps, targetPools, excludedPools, taker, isSponsored, }: Params): Promise<QuoteResponse>;
|
|
21
24
|
export {};
|
|
22
25
|
//# sourceMappingURL=getQuote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;kEAG8D;IAC9D,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;kEAG8D;IAC9D,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qHAAqH;IACrH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,EAuBtC,CAAC;AAEF,eAAO,MAAM,oBAAoB,gBAM/B,CAAC;AAEH,wBAAsB,QAAQ,CAAC,EAC7B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EAAE,QAA0B,EACnC,aAAa,EACb,WAAW,EACX,aAAa,EACb,KAAK,EACL,WAAW,GACZ,EAAE,MAAM,0BAyCR"}
|
|
@@ -11,6 +11,7 @@ import { isBluefinXRouting, } from "../../types/aggregator";
|
|
|
11
11
|
import { SuiUtils } from "../../utils/sui";
|
|
12
12
|
import { denormalizeTokenType } from "../../utils/token";
|
|
13
13
|
import { getConfig } from "./config";
|
|
14
|
+
import { ORACLE_BASED_SOURCES } from "./getQuote";
|
|
14
15
|
export const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }) => {
|
|
15
16
|
const isBluefinX = isBluefinXRouting(quoteResponse);
|
|
16
17
|
const _commission = {
|
|
@@ -34,6 +35,7 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
|
|
|
34
35
|
}
|
|
35
36
|
const tx = _tx || new Transaction();
|
|
36
37
|
const routes = groupSwapRoutes(quoteResponse);
|
|
38
|
+
validateRoutes(routes, isSponsored);
|
|
37
39
|
const splits = routes.map((group) => group[0]?.amount ?? "0");
|
|
38
40
|
let coinData;
|
|
39
41
|
if (coinIn) {
|
|
@@ -143,3 +145,12 @@ const updatePythPriceFeedsIfAny = async (tx, quoteResponse) => {
|
|
|
143
145
|
}
|
|
144
146
|
return pythMap;
|
|
145
147
|
};
|
|
148
|
+
const validateRoutes = (routes, isSponsored) => {
|
|
149
|
+
if (!isSponsored) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const hasOracleBasedSource = routes.some((g) => g.some((s) => ORACLE_BASED_SOURCES.has(s.pool.type)));
|
|
153
|
+
if (hasOracleBasedSource) {
|
|
154
|
+
throw new Error("Oracle based sources are not supported for sponsored tx");
|
|
155
|
+
}
|
|
156
|
+
};
|
|
@@ -26,7 +26,18 @@ export const DEFAULT_SOURCES = [
|
|
|
26
26
|
"sevenk_v1",
|
|
27
27
|
"fullsail",
|
|
28
28
|
];
|
|
29
|
-
export
|
|
29
|
+
export const ORACLE_BASED_SOURCES = new Set([
|
|
30
|
+
"obric",
|
|
31
|
+
"haedal_pmm",
|
|
32
|
+
"sevenk_v1",
|
|
33
|
+
"steamm_oracle_quoter",
|
|
34
|
+
"steamm_oracle_quoter_v2",
|
|
35
|
+
]);
|
|
36
|
+
export async function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources = DEFAULT_SOURCES, commissionBps, targetPools, excludedPools, taker, isSponsored, }) {
|
|
37
|
+
let sources = _sources;
|
|
38
|
+
if (isSponsored) {
|
|
39
|
+
sources = _sources.filter((s) => !ORACLE_BASED_SOURCES.has(s));
|
|
40
|
+
}
|
|
30
41
|
const params = new URLSearchParams({
|
|
31
42
|
amount: amountIn,
|
|
32
43
|
from: normalizeStructTag(tokenIn),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,aAAa,EAKd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM/C,eAAO,MAAM,OAAO,GAAU,2GAQ3B,aAAa,KAAG,OAAO,CAAC,aAAa,CA6IvC,CAAC"}
|
|
@@ -15,8 +15,11 @@ interface Params {
|
|
|
15
15
|
excludedPools?: string[];
|
|
16
16
|
/** The taker address, required for bluefinx */
|
|
17
17
|
taker?: string;
|
|
18
|
+
/** If true, excludes all liquidity sources that depend on pyth price feeds - pyth client use tx.gas to pay the fee*/
|
|
19
|
+
isSponsored?: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare const DEFAULT_SOURCES: SourceDex[];
|
|
20
|
-
export declare
|
|
22
|
+
export declare const ORACLE_BASED_SOURCES: Set<SourceDex>;
|
|
23
|
+
export declare function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources, commissionBps, targetPools, excludedPools, taker, isSponsored, }: Params): Promise<QuoteResponse>;
|
|
21
24
|
export {};
|
|
22
25
|
//# sourceMappingURL=getQuote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,SAAS,EACV,MAAM,wBAA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