@scallop-io/sui-scallop-sdk 2.4.4 → 2.4.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.4.4",
3
+ "version": "2.4.6",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -37,6 +37,28 @@
37
37
  "dist",
38
38
  "src"
39
39
  ],
40
+ "scripts": {
41
+ "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
42
+ "build": "pnpm run build:tsup",
43
+ "build:sourcemap": "tsup ./src/index.ts --format esm,cjs --sourcemap --dts",
44
+ "build:tsup": "tsup ./src/index.ts --format esm,cjs --splitting --minify --treeshake --dts",
45
+ "watch:tsup": "tsup ./src/index.ts --format esm,cjs --clean --splitting --watch",
46
+ "watch:types": "tsc --watch",
47
+ "watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
48
+ "test": "pnpm test:typecheck && pnpm test:unit",
49
+ "test:typecheck": "tsc -p ./test",
50
+ "test:unit": "vitest run --test-timeout=60000",
51
+ "test:watch": "vitest",
52
+ "format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
53
+ "lint:fix": "eslint . --ignore-pattern dist --ignore-pattern misc --ext .ts --fix",
54
+ "prepare": "husky install",
55
+ "commit": "commit",
56
+ "release": "standard-version -f",
57
+ "release:major": "standard-version -r major",
58
+ "release:minor": "standard-version -r minor",
59
+ "release:patch": "standard-version -r patch",
60
+ "doc": "typedoc --out docs src/index.ts"
61
+ },
40
62
  "dependencies": {
41
63
  "@mysten/sui": "1.45.2",
42
64
  "@noble/hashes": "^2.0.1",
@@ -143,26 +165,5 @@
143
165
  }
144
166
  ]
145
167
  }
146
- },
147
- "scripts": {
148
- "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
149
- "build": "pnpm run build:tsup",
150
- "build:sourcemap": "tsup ./src/index.ts --format esm,cjs --sourcemap --dts",
151
- "build:tsup": "tsup ./src/index.ts --format esm,cjs --splitting --minify --treeshake --dts",
152
- "watch:tsup": "tsup ./src/index.ts --format esm,cjs --clean --splitting --watch",
153
- "watch:types": "tsc --watch",
154
- "watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
155
- "test": "pnpm test:typecheck && pnpm test:unit",
156
- "test:typecheck": "tsc -p ./test",
157
- "test:unit": "vitest run --test-timeout=60000",
158
- "test:watch": "vitest",
159
- "format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
160
- "lint:fix": "eslint . --ignore-pattern dist --ignore-pattern misc --ext .ts --fix",
161
- "commit": "commit",
162
- "release": "standard-version -f",
163
- "release:major": "standard-version -r major",
164
- "release:minor": "standard-version -r minor",
165
- "release:patch": "standard-version -r patch",
166
- "doc": "typedoc --out docs src/index.ts"
167
168
  }
168
- }
169
+ }
@@ -1,10 +1,8 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import {
3
- SuiTxBlock as SuiKitTxBlock,
4
- SUI_CLOCK_OBJECT_ID,
5
- } from '@scallop-io/sui-kit';
1
+ import { SUI_CLOCK_OBJECT_ID } from '@scallop-io/sui-kit';
6
2
  import { getObligations, getObligationLocked } from 'src/queries';
7
- import { requireSender } from 'src/utils';
3
+ import { requireSender, resolveTxBlock } from 'src/utils';
4
+ import type { Transaction } from '@mysten/sui/transactions';
5
+ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
8
6
  import type { SuiObjectArg } from '@scallop-io/sui-kit';
9
7
  import type { ScallopBuilder } from 'src/models';
10
8
  import type {
@@ -332,12 +330,7 @@ export const newBorrowIncentiveTxBlock = (
332
330
  builder: ScallopBuilder,
333
331
  initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
334
332
  ) => {
335
- const txBlock =
336
- initTxBlock instanceof Transaction
337
- ? new SuiKitTxBlock(initTxBlock)
338
- : initTxBlock
339
- ? initTxBlock
340
- : new SuiKitTxBlock();
333
+ const txBlock = resolveTxBlock(initTxBlock);
341
334
 
342
335
  const normalMethod = generateBorrowIncentiveNormalMethod({
343
336
  builder,
@@ -1,9 +1,9 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
1
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
3
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
4
2
  import { getObligations } from '../queries';
5
3
  import { updateOracles } from './oracles';
6
- import { requireSender } from '../utils';
4
+ import { requireSender, resolveTxBlock } from '../utils';
5
+ import type { Transaction } from '@mysten/sui/transactions';
6
+ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
7
7
  import type { SuiObjectArg } from '@scallop-io/sui-kit';
8
8
  import type { ScallopBuilder } from 'src/models';
9
9
  import type {
@@ -575,12 +575,7 @@ export const newCoreTxBlock = (
575
575
  | Transaction
576
576
  | SuiTxBlockWithSpool
577
577
  ) => {
578
- const txBlock =
579
- initTxBlock instanceof Transaction
580
- ? new SuiKitTxBlock(initTxBlock)
581
- : initTxBlock
582
- ? initTxBlock
583
- : new SuiKitTxBlock();
578
+ const txBlock = resolveTxBlock(initTxBlock);
584
579
 
585
580
  const normalMethod = generateCoreNormalMethod({
586
581
  builder,
@@ -10,6 +10,7 @@ import { newReferralTxBlock } from './referralBuilder';
10
10
  import { newObligationNamingTxBlock } from './obligationNamingBuilder';
11
11
  import { newLoyaltyProgramTxBlock } from './loyaltyProgramBuilder';
12
12
  import { newSCoinTxBlock } from './sCoinBuilder';
13
+ import { SCALLOP_TX_BLOCK_MARKER } from 'src/utils';
13
14
 
14
15
  /**
15
16
  * Create a new ScallopTxBlock instance.
@@ -39,6 +40,7 @@ export const newScallopTxBlock = (
39
40
 
40
41
  return new Proxy(coreTxBlock, {
41
42
  get: (target, prop) => {
43
+ if (prop === SCALLOP_TX_BLOCK_MARKER) return true;
42
44
  if (prop in vescaTxBlock) {
43
45
  return Reflect.get(vescaTxBlock, prop);
44
46
  } else if (prop in borrowIncentiveTxBlock) {
@@ -1,5 +1,5 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
1
+ import type { Transaction } from '@mysten/sui/transactions';
2
+ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
3
  import { ScallopBuilder } from 'src/models';
4
4
  import {
5
5
  GenerateLoyaltyProgramNormalMethod,
@@ -8,7 +8,7 @@ import {
8
8
  ScallopTxBlock,
9
9
  SuiTxBlockWithLoyaltyProgramNormalMethods,
10
10
  } from 'src/types';
11
- import { requireSender } from 'src/utils';
11
+ import { requireSender, resolveTxBlock } from 'src/utils';
12
12
 
13
13
  const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
14
14
  ({ builder, txBlock }) => {
@@ -105,12 +105,7 @@ export const newLoyaltyProgramTxBlock = (
105
105
  builder: ScallopBuilder,
106
106
  initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
107
107
  ) => {
108
- const txBlock =
109
- initTxBlock instanceof Transaction
110
- ? new SuiKitTxBlock(initTxBlock)
111
- : initTxBlock
112
- ? initTxBlock
113
- : new SuiKitTxBlock();
108
+ const txBlock = resolveTxBlock(initTxBlock);
114
109
 
115
110
  const normalMethod = generateLoyaltyProgramNormalMethod({
116
111
  builder,
@@ -1,6 +1,7 @@
1
1
  import { ScallopBuilder } from 'src/models';
2
2
  import { ScallopTxBlock } from 'src/types';
3
- import {
3
+ import { resolveTxBlock } from 'src/utils';
4
+ import type {
4
5
  SuiTxBlock as SuiKitTxBlock,
5
6
  SuiObjectArg,
6
7
  Transaction,
@@ -67,12 +68,7 @@ export const newObligationNamingTxBlock = (
67
68
  builder: ScallopBuilder,
68
69
  initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
69
70
  ) => {
70
- const txBlock =
71
- initTxBlock instanceof Transaction
72
- ? new SuiKitTxBlock(initTxBlock)
73
- : initTxBlock
74
- ? initTxBlock
75
- : new SuiKitTxBlock();
71
+ const txBlock = resolveTxBlock(initTxBlock);
76
72
 
77
73
  const normalMethod = generateObligationNamingNormalMethod({
78
74
  builder,
@@ -1,11 +1,6 @@
1
1
  import { ScallopBuilder } from 'src/models';
2
2
  import { ScallopTxBlock } from 'src/types';
3
- import {
4
- SUI_CLOCK_OBJECT_ID,
5
- SuiTxBlock as SuiKitTxBlock,
6
- SuiObjectArg,
7
- Transaction,
8
- } from '@scallop-io/sui-kit';
3
+ import { SUI_CLOCK_OBJECT_ID } from '@scallop-io/sui-kit';
9
4
  import {
10
5
  GenerateReferralNormalMethod,
11
6
  GenerateReferralQuickMethod,
@@ -13,7 +8,12 @@ import {
13
8
  ReferralTxBlock,
14
9
  SuiTxBlockWithReferralNormalMethods,
15
10
  } from 'src/types/builder/referral';
16
- import { requireSender } from 'src/utils';
11
+ import { requireSender, resolveTxBlock } from 'src/utils';
12
+ import type {
13
+ SuiTxBlock as SuiKitTxBlock,
14
+ SuiObjectArg,
15
+ Transaction,
16
+ } from '@scallop-io/sui-kit';
17
17
 
18
18
  const generateReferralNormalMethod: GenerateReferralNormalMethod = ({
19
19
  builder,
@@ -155,12 +155,7 @@ export const newReferralTxBlock = (
155
155
  builder: ScallopBuilder,
156
156
  initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
157
157
  ) => {
158
- const txBlock =
159
- initTxBlock instanceof Transaction
160
- ? new SuiKitTxBlock(initTxBlock)
161
- : initTxBlock
162
- ? initTxBlock
163
- : new SuiKitTxBlock();
158
+ const txBlock = resolveTxBlock(initTxBlock);
164
159
 
165
160
  const normalMethod = generateReferralNormalMethod({
166
161
  builder,
@@ -1,4 +1,3 @@
1
- import { Transaction, SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
1
  import { ScallopBuilder } from 'src/models';
3
2
  import {
4
3
  BaseScallopTxBlock,
@@ -9,7 +8,11 @@ import {
9
8
  SuiTxBlockWithSCoinNormalMethods,
10
9
  sCoinPkgIds,
11
10
  } from 'src/types';
12
- import { requireSender } from 'src/utils';
11
+ import { requireSender, resolveTxBlock } from 'src/utils';
12
+ import type {
13
+ Transaction,
14
+ SuiTxBlock as SuiKitTxBlock,
15
+ } from '@scallop-io/sui-kit';
13
16
 
14
17
  const generateSCoinNormalMethod: GenerateSCoinNormalMethod = ({
15
18
  builder,
@@ -86,12 +89,7 @@ export const newSCoinTxBlock = (
86
89
  | Transaction
87
90
  | BaseScallopTxBlock
88
91
  ) => {
89
- const txBlock =
90
- initTxBlock instanceof Transaction
91
- ? new SuiKitTxBlock(initTxBlock)
92
- : initTxBlock
93
- ? initTxBlock
94
- : new SuiKitTxBlock();
92
+ const txBlock = resolveTxBlock(initTxBlock);
95
93
 
96
94
  const normalMethod = generateSCoinNormalMethod({
97
95
  builder,
@@ -1,8 +1,8 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
1
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
3
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
4
2
  import { getStakeAccounts } from '../queries/spoolQuery';
5
- import { requireSender } from '../utils';
3
+ import { requireSender, resolveTxBlock } from '../utils';
4
+ import type { Transaction } from '@mysten/sui/transactions';
5
+ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
6
6
  import type { SuiAddressArg } from '@scallop-io/sui-kit';
7
7
  import type { TransactionResult } from '@mysten/sui/transactions';
8
8
  import type { ScallopBuilder } from 'src/models';
@@ -332,12 +332,7 @@ export const newSpoolTxBlock = (
332
332
  | Transaction
333
333
  | SuiTxBlockWithSCoin
334
334
  ) => {
335
- const txBlock =
336
- initTxBlock instanceof Transaction
337
- ? new SuiKitTxBlock(initTxBlock)
338
- : initTxBlock
339
- ? initTxBlock
340
- : new SuiKitTxBlock();
335
+ const txBlock = resolveTxBlock(initTxBlock);
341
336
 
342
337
  const normalMethod = generateSpoolNormalMethod({
343
338
  builder,
@@ -1,9 +1,4 @@
1
- import {
2
- SUI_CLOCK_OBJECT_ID,
3
- SuiTxBlock,
4
- Transaction,
5
- SuiTxBlock as SuiKitTxBlock,
6
- } from '@scallop-io/sui-kit';
1
+ import { SUI_CLOCK_OBJECT_ID } from '@scallop-io/sui-kit';
7
2
  import { SCA_COIN_TYPE } from 'src/constants';
8
3
  import { ScallopBuilder } from 'src/models';
9
4
  import { getVeSca, getVeScas } from 'src/queries';
@@ -14,7 +9,13 @@ import {
14
9
  checkExtendLockAmount,
15
10
  checkRenewExpiredVeSca,
16
11
  checkVesca,
12
+ resolveTxBlock,
17
13
  } from 'src/utils';
14
+ import type {
15
+ SuiTxBlock,
16
+ Transaction,
17
+ SuiTxBlock as SuiKitTxBlock,
18
+ } from '@scallop-io/sui-kit';
18
19
  import type {
19
20
  TransactionObjectArgument,
20
21
  SuiObjectArg,
@@ -535,12 +536,7 @@ export const newVeScaTxBlock = (
535
536
  builder: ScallopBuilder,
536
537
  initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
537
538
  ) => {
538
- const txBlock =
539
- initTxBlock instanceof Transaction
540
- ? new SuiKitTxBlock(initTxBlock)
541
- : initTxBlock
542
- ? initTxBlock
543
- : new SuiKitTxBlock();
539
+ const txBlock = resolveTxBlock(initTxBlock);
544
540
 
545
541
  const normalMethod = generateNormalVeScaMethod({
546
542
  builder,
@@ -136,19 +136,26 @@ export const getBorrowIncentivePools = async (
136
136
  poolCoinDecimal
137
137
  );
138
138
 
139
- if (poolPoint.points > calculatedPoolPoint.accumulatedPoints) {
140
- borrowIncentivePoolPoints[coinName as string] = {
141
- symbol,
142
- coinName: rewardCoinName,
143
- coinType: rewardCoinType,
144
- coinDecimal,
145
- coinPrice: rewardCoinPrice,
146
- points: poolPoint.points,
147
- distributedPoint: poolPoint.distributedPoint,
148
- weightedAmount: poolPoint.weightedAmount,
149
- ...calculatedPoolPoint,
150
- };
151
- }
139
+ // A campaign is exhausted once every allocated point has been
140
+ // distributed (accumulatedPoints is min-capped at points). We still emit
141
+ // the pool point — the portfolio query needs it to surface users'
142
+ // already-accrued, unclaimed rewards — but zero out the APR so callers
143
+ // don't display a stale reward rate for an ended campaign.
144
+ const isExhausted =
145
+ poolPoint.points <= calculatedPoolPoint.accumulatedPoints;
146
+
147
+ borrowIncentivePoolPoints[coinName as string] = {
148
+ symbol,
149
+ coinName: rewardCoinName,
150
+ coinType: rewardCoinType,
151
+ coinDecimal,
152
+ coinPrice: rewardCoinPrice,
153
+ points: poolPoint.points,
154
+ distributedPoint: poolPoint.distributedPoint,
155
+ weightedAmount: poolPoint.weightedAmount,
156
+ ...calculatedPoolPoint,
157
+ ...(isExhausted ? { rewardApr: 0 } : {}),
158
+ };
152
159
  }
153
160
 
154
161
  const stakedAmount = BigNumber(parsedBorrowIncentivePoolData.staked);
@@ -1,4 +1,4 @@
1
- import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
1
+ import { SuiTxBlock as SuiKitTxBlock, Transaction } from '@scallop-io/sui-kit';
2
2
  import {
3
3
  UNLOCK_ROUND_DURATION,
4
4
  MAX_LOCK_DURATION,
@@ -7,6 +7,39 @@ import {
7
7
  MIN_TOP_UP_AMOUNT,
8
8
  } from 'src/constants';
9
9
  import type { SuiObjectArg } from '@scallop-io/sui-kit';
10
+ import type { ScallopTxBlock } from 'src/types';
11
+
12
+ /**
13
+ * Marker the outer `newScallopTxBlock` Proxy returns `true` for, so we can
14
+ * runtime-detect a `ScallopTxBlock` (otherwise indistinguishable from a plain
15
+ * `SuiKitTxBlock` since `ScallopTxBlock` is a TS-only type intersection).
16
+ */
17
+ export const SCALLOP_TX_BLOCK_MARKER = Symbol.for('scallop.txBlock');
18
+
19
+ export const isScallopTxBlock = (value: unknown): value is ScallopTxBlock => {
20
+ return (
21
+ typeof value === 'object' &&
22
+ value !== null &&
23
+ (value as Record<symbol, unknown>)[SCALLOP_TX_BLOCK_MARKER] === true
24
+ );
25
+ };
26
+
27
+ /**
28
+ * Resolve the `initTxBlock` argument accepted by every `new*TxBlock` factory
29
+ * into a concrete `SuiKitTxBlock` instance.
30
+ * - `ScallopTxBlock` (detected via marker) → pass through
31
+ * - `Transaction` → wrap in a new `SuiKitTxBlock`
32
+ * - existing `SuiKitTxBlock` → pass through
33
+ * - `undefined` → fresh `SuiKitTxBlock`
34
+ */
35
+ export const resolveTxBlock = (
36
+ initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
37
+ ): SuiKitTxBlock => {
38
+ if (isScallopTxBlock(initTxBlock)) return initTxBlock;
39
+ if (initTxBlock instanceof SuiKitTxBlock) return initTxBlock;
40
+ if (initTxBlock instanceof Transaction) return new SuiKitTxBlock(initTxBlock);
41
+ return initTxBlock ?? new SuiKitTxBlock();
42
+ };
10
43
 
11
44
  /**
12
45
  * Check and get the sender from the transaction block.