@suilend/sdk 13.8.0-next.gd305fde → 14.0.0-next.g4630d94
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/package.json +1 -1
- package/swap/quote.d.ts +0 -6
- package/swap/quote.js +0 -75
- package/swap/transaction.d.ts +0 -1
- package/swap/transaction.js +1 -34
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"
|
|
1
|
+
{"name":"@suilend/sdk","version":"14.0.0-next.g4630d94","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/proCompatible":"./lib/proCompatible.js","./lib/pyth":"./lib/pyth.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./margin":"./margin/index.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils/feedId":"./utils/feedId.js","./utils":"./utils/index.js","./utils/interpolate":"./utils/interpolate.js","./utils/obligation":"./utils/obligation.js","./utils/priceGuard":"./utils/priceGuard.js","./utils/simulate":"./utils/simulate.js","./_generated/_envs":"./_generated/_envs/index.js","./_generated/_envs/mainnet":"./_generated/_envs/mainnet.js","./_generated/_framework/env":"./_generated/_framework/env.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/version":"./margin/margin/version.js","./margin/utils":"./margin/utils/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/pyth-2/price-identifier/structs":"./_generated/_dependencies/pyth-2/price-identifier/structs.js","./_generated/_dependencies/std/ascii/structs":"./_generated/_dependencies/std/ascii/structs.js","./_generated/_dependencies/std/option/structs":"./_generated/_dependencies/std/option/structs.js","./_generated/_dependencies/std/type-name/structs":"./_generated/_dependencies/std/type-name/structs.js","./_generated/_dependencies/sui/bag/structs":"./_generated/_dependencies/sui/bag/structs.js","./_generated/_dependencies/sui/balance/structs":"./_generated/_dependencies/sui/balance/structs.js","./_generated/_dependencies/sui/object/structs":"./_generated/_dependencies/sui/object/structs.js","./_generated/_dependencies/sui/object-table/structs":"./_generated/_dependencies/sui/object-table/structs.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js"},"types":"./index.d.ts","scripts":{"codegen":"node ./codegen.js","codegen:install":"node ./install-codegen.js","build":"rm -rf ./dist && tsc && node ./fix-esm-imports.js","typecheck":"tsc --noEmit && tsc --noEmit -p tsconfig.test.json","test":"vitest run","lint:ci":"yarn run typecheck","prettier":"prettier --write src/ tests/","release":"yarn run build && node ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/fireflyprotocol/lending-mono.git","directory":"ts/sdks/sdk"},"dependencies":{"@cetusprotocol/aggregator-sdk":"1.7.3","@flowx-finance/sdk":"2.1.0","@pythnetwork/hermes-client":"3.1.0","@pythnetwork/pyth-sui-js":"4.0.0","@suilend/springsui-sdk":"4.1.0","bignumber.js":"11.1.5","bn.js":"5.2.5","crypto-js":"4.2.0","lodash":"4.18.1","p-limit":"7.3.3","uuid":"14.0.2"},"devDependencies":{"@mysten/bcs":"2.1.2","@mysten/sui":"2.35.0","@suilend/sui-core":"2.2.0","@tsconfig/recommended":"1.0.13","@types/bn.js":"5.2.0","@types/lodash":"4.17.26","@types/node":"26.6.5","fast-check":"4.10.2","prettier":"3.9.10","ts-node":"10.9.2","typescript":"6.0.3","vite":"8.3.4","vitest":"5.0.4"},"peerDependencies":{"@mysten/bcs":"^2.1.1","@mysten/sui":">=2.31.3 <3","@suilend/sui-core":"^2.0.1"},"type":"module"}
|
package/swap/quote.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import type { QuoteResponse as Bluefin7kQuote } from "@bluefin-exchange/bluefin7k-aggregator-sdk";
|
|
2
1
|
import type { RouterDataV3 as CetusQuote, AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
|
|
3
2
|
import type { AggregatorQuoter as FlowXAggregatorQuoter, GetRoutesResult as FlowXGetRoutesResult } from "@flowx-finance/sdk";
|
|
4
3
|
import BigNumber from "bignumber.js";
|
|
5
4
|
import { Token } from "@suilend/sui-core";
|
|
6
5
|
export declare enum QuoteProvider {
|
|
7
6
|
CETUS = "cetus",
|
|
8
|
-
BLUEFIN7K = "bluefin7k",
|
|
9
7
|
FLOWX = "flowx"
|
|
10
8
|
}
|
|
11
9
|
export declare const QUOTE_PROVIDER_NAME_MAP: {
|
|
12
10
|
cetus: string;
|
|
13
|
-
bluefin7k: string;
|
|
14
11
|
flowx: string;
|
|
15
12
|
};
|
|
16
13
|
export type StandardizedRoutePath = {
|
|
@@ -52,9 +49,6 @@ export type StandardizedQuote = {
|
|
|
52
49
|
} & ({
|
|
53
50
|
provider: QuoteProvider.CETUS;
|
|
54
51
|
quote: CetusQuote;
|
|
55
|
-
} | {
|
|
56
|
-
provider: QuoteProvider.BLUEFIN7K;
|
|
57
|
-
quote: Bluefin7kQuote;
|
|
58
52
|
} | {
|
|
59
53
|
provider: QuoteProvider.FLOWX;
|
|
60
54
|
quote: FlowXGetRoutesResult<any, any>;
|
package/swap/quote.js
CHANGED
|
@@ -5,12 +5,10 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
5
5
|
export var QuoteProvider;
|
|
6
6
|
(function (QuoteProvider) {
|
|
7
7
|
QuoteProvider["CETUS"] = "cetus";
|
|
8
|
-
QuoteProvider["BLUEFIN7K"] = "bluefin7k";
|
|
9
8
|
QuoteProvider["FLOWX"] = "flowx";
|
|
10
9
|
})(QuoteProvider || (QuoteProvider = {}));
|
|
11
10
|
export const QUOTE_PROVIDER_NAME_MAP = {
|
|
12
11
|
[QuoteProvider.CETUS]: "Cetus",
|
|
13
|
-
[QuoteProvider.BLUEFIN7K]: "Bluefin7k",
|
|
14
12
|
[QuoteProvider.FLOWX]: "FlowX",
|
|
15
13
|
};
|
|
16
14
|
const getPoolProviders = (standardizedQuote) => {
|
|
@@ -108,69 +106,6 @@ const getCetusQuote = async (sdk, tokenIn, tokenOut, amountIn) => {
|
|
|
108
106
|
};
|
|
109
107
|
return standardizedQuote;
|
|
110
108
|
};
|
|
111
|
-
const getBluefin7kQuote = async (tokenIn, tokenOut, amountIn) => {
|
|
112
|
-
// Imported here rather than at module scope so 7k is loaded only when a 7k
|
|
113
|
-
// quote is actually requested, keeping a browser-only router out of every
|
|
114
|
-
// consumer's module-init graph.
|
|
115
|
-
//
|
|
116
|
-
// 7k is NOT a CJS package — 7.3.0 is `type: module` and ships no CJS build at
|
|
117
|
-
// all — so this is not the ERR_REQUIRE_ESM_RACE_CONDITION fix that the flowx
|
|
118
|
-
// deferral in transaction.ts is. Spelled out because the reverse mistake is the
|
|
119
|
-
// easy one: noticing 7k is ESM and concluding this can go back to a static
|
|
120
|
-
// import.
|
|
121
|
-
//
|
|
122
|
-
// What it does still protect is a CONSUMER's graph. 7k peer-depends on
|
|
123
|
-
// `@pythnetwork/pyth-sui-js ^2.1.0`, and pyth v2 is CJS and `require()`s
|
|
124
|
-
// ESM-only `@mysten/sui`. `ts/sdks` pins pyth to 4.0.0 so that peer never
|
|
125
|
-
// resolves to v2 here — but that resolution does not travel with the published
|
|
126
|
-
// package, so an installer without the same override gets CJS pyth v2 under 7k.
|
|
127
|
-
// Deferred, it is never in their init graph either way. (The peer range is
|
|
128
|
-
// stale regardless: 7k 7.3.0 calls pyth v4's `SuiPythClient` API and would not
|
|
129
|
-
// work against v2.)
|
|
130
|
-
const { getQuote: getBluefin7kQuoteOriginal } = await import("@bluefin-exchange/bluefin7k-aggregator-sdk");
|
|
131
|
-
const quote = await getBluefin7kQuoteOriginal({
|
|
132
|
-
tokenIn: tokenIn.coinType,
|
|
133
|
-
tokenOut: tokenOut.coinType,
|
|
134
|
-
amountIn,
|
|
135
|
-
});
|
|
136
|
-
const standardizedQuote = {
|
|
137
|
-
id: uuidv4(),
|
|
138
|
-
provider: QuoteProvider.BLUEFIN7K,
|
|
139
|
-
in: {
|
|
140
|
-
coinType: tokenIn.coinType,
|
|
141
|
-
amount: new BigNumber(quote.swapAmountWithDecimal).div(10 ** tokenIn.decimals),
|
|
142
|
-
},
|
|
143
|
-
out: {
|
|
144
|
-
coinType: tokenOut.coinType,
|
|
145
|
-
amount: new BigNumber(quote.returnAmountWithDecimal).div(10 ** tokenOut.decimals),
|
|
146
|
-
},
|
|
147
|
-
routes: (quote.routes ?? []).map((route, routeIndex) => ({
|
|
148
|
-
percent: new BigNumber(route.tokenInAmount)
|
|
149
|
-
.div(quote.swapAmount)
|
|
150
|
-
.times(100),
|
|
151
|
-
path: route.hops.map((hop) => ({
|
|
152
|
-
id: uuidv4(),
|
|
153
|
-
poolId: hop.poolId,
|
|
154
|
-
routeIndex,
|
|
155
|
-
provider: hop.pool.type,
|
|
156
|
-
in: {
|
|
157
|
-
coinType: normalizeStructTag(hop.tokenIn),
|
|
158
|
-
amount: new BigNumber(hop.tokenInAmount).times(10 **
|
|
159
|
-
hop.pool.allTokens.find((t) => normalizeStructTag(t.address) ===
|
|
160
|
-
normalizeStructTag(hop.tokenIn)).decimal),
|
|
161
|
-
},
|
|
162
|
-
out: {
|
|
163
|
-
coinType: normalizeStructTag(hop.tokenOut),
|
|
164
|
-
amount: new BigNumber(hop.tokenOutAmount).times(10 **
|
|
165
|
-
hop.pool.allTokens.find((t) => normalizeStructTag(t.address) ===
|
|
166
|
-
normalizeStructTag(hop.tokenOut)).decimal),
|
|
167
|
-
},
|
|
168
|
-
})),
|
|
169
|
-
})),
|
|
170
|
-
quote,
|
|
171
|
-
};
|
|
172
|
-
return standardizedQuote;
|
|
173
|
-
};
|
|
174
109
|
const getFlowXQuote = async (sdk, tokenIn, tokenOut, amountIn) => {
|
|
175
110
|
const quote = await sdk.getRoutes({
|
|
176
111
|
tokenIn: tokenIn.coinType,
|
|
@@ -221,13 +156,6 @@ export const getAggQuotes = async (sdkMap, activeProviders, onGetAggQuote, token
|
|
|
221
156
|
onGetAggQuote(standardizedQuote);
|
|
222
157
|
})();
|
|
223
158
|
}
|
|
224
|
-
// Bluefin7k
|
|
225
|
-
if (activeProviders.includes(QuoteProvider.BLUEFIN7K)) {
|
|
226
|
-
(async () => {
|
|
227
|
-
const standardizedQuote = await getAggQuoteWrapper(QuoteProvider.BLUEFIN7K, () => getBluefin7kQuote(tokenIn, tokenOut, amountIn), timeoutMs);
|
|
228
|
-
onGetAggQuote(standardizedQuote);
|
|
229
|
-
})();
|
|
230
|
-
}
|
|
231
159
|
// FlowX
|
|
232
160
|
if (activeProviders.includes(QuoteProvider.FLOWX)) {
|
|
233
161
|
(async () => {
|
|
@@ -243,9 +171,6 @@ export const getAggSortedQuotesAll = async (sdkMap, activeProviders, tokenIn, to
|
|
|
243
171
|
activeProviders.includes(QuoteProvider.CETUS)
|
|
244
172
|
? getAggQuoteWrapper(QuoteProvider.CETUS, () => getCetusQuote(sdkMap[QuoteProvider.CETUS], tokenIn, tokenOut, amountIn), timeoutMs)
|
|
245
173
|
: null,
|
|
246
|
-
activeProviders.includes(QuoteProvider.BLUEFIN7K)
|
|
247
|
-
? getAggQuoteWrapper(QuoteProvider.BLUEFIN7K, () => getBluefin7kQuote(tokenIn, tokenOut, amountIn), timeoutMs)
|
|
248
|
-
: null,
|
|
249
174
|
activeProviders.includes(QuoteProvider.FLOWX)
|
|
250
175
|
? getAggQuoteWrapper(QuoteProvider.FLOWX, () => getFlowXQuote(sdkMap[QuoteProvider.FLOWX], tokenIn, tokenOut, amountIn), timeoutMs)
|
|
251
176
|
: null,
|
package/swap/transaction.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export declare const getSwapTransaction: (suiGrpcClient: SuiGrpcClient, address:
|
|
|
8
8
|
[QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
|
|
9
9
|
}, partnerIdMap: {
|
|
10
10
|
[QuoteProvider.CETUS]: string;
|
|
11
|
-
[QuoteProvider.BLUEFIN7K]: string;
|
|
12
11
|
[QuoteProvider.FLOWX]: string;
|
|
13
12
|
}, transaction: Transaction, coinIn: TransactionObjectArgument | undefined) => Promise<{
|
|
14
13
|
transaction: Transaction;
|
package/swap/transaction.js
CHANGED
|
@@ -31,42 +31,9 @@ export const getSwapTransaction = async (suiGrpcClient, address, quote, slippage
|
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
else if (quote.provider === QuoteProvider.BLUEFIN7K) {
|
|
35
|
-
return getSwapTransactionWrapper(QuoteProvider.BLUEFIN7K, async () => {
|
|
36
|
-
// Deferred for the reason spelled out at the 7k import in quote.ts: 7k is
|
|
37
|
-
// itself ESM, so this is about init cost plus a consumer's exposure to the
|
|
38
|
-
// CJS pyth v2 that 7k's stale peer range still permits — not the
|
|
39
|
-
// require(ESM) fix that the flowx branch below is. `BluefinXTx` comes from
|
|
40
|
-
// the same import because the `instanceof` below needs the real class.
|
|
41
|
-
const { BluefinXTx, buildTx: buildBluefin7kTransaction } = await import("@bluefin-exchange/bluefin7k-aggregator-sdk");
|
|
42
|
-
const { tx: transaction2, coinOut } = await buildBluefin7kTransaction({
|
|
43
|
-
quoteResponse: quote.quote,
|
|
44
|
-
accountAddress: address,
|
|
45
|
-
slippage: slippagePercent / 100,
|
|
46
|
-
commission: {
|
|
47
|
-
partner: partnerIdMap[QuoteProvider.BLUEFIN7K],
|
|
48
|
-
commissionBps: 0,
|
|
49
|
-
},
|
|
50
|
-
extendTx: {
|
|
51
|
-
tx: transaction,
|
|
52
|
-
coinIn: coinIn,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
if (transaction2 instanceof BluefinXTx) {
|
|
56
|
-
// BluefinXTx
|
|
57
|
-
throw new Error("BluefinXTx not supported");
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return {
|
|
61
|
-
transaction: transaction2,
|
|
62
|
-
coinOut: coinOut,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
34
|
else if (quote.provider === QuoteProvider.FLOWX) {
|
|
68
35
|
return getSwapTransactionWrapper(QuoteProvider.FLOWX, async () => {
|
|
69
|
-
// flowx is the genuine CJS offender of the
|
|
36
|
+
// flowx is the genuine CJS offender of the two routers: 2.1.0 publishes
|
|
70
37
|
// no `exports` map, so Node ESM resolves its `main` — `index.cjs.js` —
|
|
71
38
|
// which `require()`s ESM-only `@mysten/sui/{bcs,grpc,transactions,utils}`.
|
|
72
39
|
// At module scope that lands in every consumer's init graph and Node
|