@suilend/sdk 13.8.0-next.g33ed981 → 13.8.0-next.gbe76414
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/utils/priceGuard.d.ts +6 -1
- package/utils/priceGuard.js +23 -5
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"13.8.0-next.
|
|
1
|
+
{"name":"@suilend/sdk","version":"13.8.0-next.gbe76414","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":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"7.7.0","@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/utils/priceGuard.d.ts
CHANGED
|
@@ -6,7 +6,12 @@ export type PriceGuardState = {
|
|
|
6
6
|
anchorTimestampS: bigint;
|
|
7
7
|
};
|
|
8
8
|
export declare const clampToBand: (anchor: bigint, price: bigint, bandBps: bigint) => bigint;
|
|
9
|
-
export
|
|
9
|
+
export type StoredPrices = {
|
|
10
|
+
price: bigint;
|
|
11
|
+
smoothedPrice: bigint;
|
|
12
|
+
};
|
|
13
|
+
export declare const nextAnchor: (anchor: bigint, stored: bigint, incoming: bigint, bandBps: bigint) => bigint;
|
|
14
|
+
export declare const applyPriceGuard: (price: bigint, smoothedPrice: bigint, guard: PriceGuardState, nowS: bigint, stored: StoredPrices | null) => {
|
|
10
15
|
price: bigint;
|
|
11
16
|
smoothedPrice: bigint;
|
|
12
17
|
wasClamped: boolean;
|
package/utils/priceGuard.js
CHANGED
|
@@ -14,11 +14,29 @@ export const clampToBand = (anchor, price, bandBps) => {
|
|
|
14
14
|
const atLeastLower = price > lower ? price : lower;
|
|
15
15
|
return atLeastLower < upper ? atLeastLower : upper;
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
17
|
+
export const nextAnchor = (anchor, stored, incoming, bandBps) => {
|
|
18
|
+
if (anchor === 0n)
|
|
19
|
+
return incoming;
|
|
20
|
+
const carried = clampToBand(anchor, stored, bandBps);
|
|
21
|
+
return carried === 0n ? clampToBand(anchor, incoming, bandBps) : carried;
|
|
22
|
+
};
|
|
23
|
+
// Models one refresh at nowS. Once the guard's interval has elapsed, the chain opens the
|
|
24
|
+
// next one on the prices the reserve holds, so without `stored` this clamps against the
|
|
25
|
+
// read anchors instead and can land up to a band off. The chain also writes the anchors,
|
|
26
|
+
// which this does not, so callers must re-read the guard instead of chaining results.
|
|
27
|
+
export const applyPriceGuard = (price, smoothedPrice, guard, nowS, stored) => {
|
|
28
|
+
const band = guard.maxPriceChangeBps;
|
|
29
|
+
const opens = stored != null &&
|
|
30
|
+
band > 0n &&
|
|
31
|
+
nowS - guard.anchorTimestampS >= guard.minUpdateIntervalS;
|
|
32
|
+
const priceAnchor = opens
|
|
33
|
+
? nextAnchor(guard.priceAnchor, stored.price, price, band)
|
|
34
|
+
: guard.priceAnchor;
|
|
35
|
+
const smoothedPriceAnchor = opens
|
|
36
|
+
? nextAnchor(guard.smoothedPriceAnchor, stored.smoothedPrice, smoothedPrice, band)
|
|
37
|
+
: guard.smoothedPriceAnchor;
|
|
38
|
+
const clampedPrice = clampToBand(priceAnchor, price, band);
|
|
39
|
+
const clampedSmoothedPrice = clampToBand(smoothedPriceAnchor, smoothedPrice, band);
|
|
22
40
|
return {
|
|
23
41
|
price: clampedPrice,
|
|
24
42
|
smoothedPrice: clampedSmoothedPrice,
|