Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@scallop-io/sui-scallop-sdk

scallop-io4.4kApache-2.02.1.7TypeScript support: included

Typescript sdk for interacting with Scallop contract on SUI

sui, scallop labs, typescript, blockchain

readme

scallop

GitHub release GitHub licence

The Typescript SDK for interacting with the Scallop lending protocol on the SUI network

Description

This SDK is used to interact with sui-lending-protocol and is written based on another sui-integrated tool, sui-kit. It consists of seven main functional models, here's a brief introduction to each of them:

  • Scallop: Provide an entry to quickly create an instance (client, address, query, builder, utils) and complete initialization at the same time.

  • ScallopClient: Helps users encapsulate basic operations for interacting with the contract. Once the instance is created, it can be called directly for use.

  • ScallopAddress: Used to manage the addresses of the lending contract. It's prepackaged into the client and provides the addresses of mainly production environment for customers to query addresses, usually used in conjunction with the builder.

  • ScallopQuery: Used to encapsulate all methods for querying on-chain data of the scallop contract. More useful information will be provided here in the future, such as lending, collateral, or borrowing portfolios.

  • ScallopBuilder: Used for more detailed organization of the lending protocol's transaction blocks. You can build your own transaction combinations according to your needs by this model.

  • ScallopUtils: Used to encapsulate some useful methods that will be used when interacting with the scallop contract.

  • ScallopIndexer: It is used to query the on-chain index data through the SDK API. It is mainly used in query instances, effectively reducing the number of RPC requests..

Pre-requisites

  • Installation:
    pnpm install @scallop-io/sui-scallop-sdk
  • Create an instance:

    Note: Currently, this SDK only supports the mainnet network. When you use the testnet network, it will give errors because there is no address package ID for the testnet.

    // Create an instance quickly through the`Scallop` class to construct other models.
    const scallopSDK = new Scallop({
        addressId: '67c44a103fe1b8c454eb9699',
        networkType: 'mainnet',
        ...
    });
    
    const scallopAddress = await scallopSDK.getScallopAddress(...);
    const scallopConstants = await scallopSDK.getScallopConstants(...);
    const scallopQuery = await scallopSDK.createScallopQuery(...);
    const scallopBuilder = await scallopSDK.createScallopBuilder(...);
    const scallopUtils = await scallopSDK.createScallopUtils(...);
    const scallopClient = await scallopSDK.createScallopClient(...);
    const scallopIndexer = await scallopSDK.createScallopIndexer();
    
    // Or, you can choose to import the class directly to create an instance.
    import {
      ScallopAddress,
      ScallopConstants,
      ScallopBuilder,
      ScallopQuery,
      ScallopUtils,
      ScallopIndexer,
      ScallopClient,
    } from '@scallop-io/sui-scallop-sdk'
    
    const scallopAddress = new ScallopAddress(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const scallopConstants = new ScallopConstants(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const ScallopQuery = new ScallopQuery(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const ScallopBuilder = new ScallopBuilder(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const ScallopUtils = new ScallopUtils(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const scallopClient = new ScallopClient(
      addressId: '67c44a103fe1b8c454eb9699',
      ...
    );
    const ScallopIndexer = new ScallopIndexer();
    // Remember to initialize the instance before using it
    await scallopAddress.read();
    await scallopConstants.init();
    await ScallopQuery.init();
    await ScallopBuilder.init();
    await ScallopUtils.init();
    await scallopClient.init();

Quick Guide for each model

Below we will give a brief introduction to these instances respectively, and introduce the functions through test codes.

For the original codes, please refer to test folder.

You need to set up the .env file before testing. (Reference .env.example)

  • Run the test

    pnpm run test:unit test/index.spec.ts
    pnpm run test:unit test/address.spec.ts
    pnpm run test:unit test/builder.spec.ts
    pnpm run test:unit test/query.spec.ts
    pnpm run test:unit test/utils.spec.ts
    pnpm run test:unit test/indexer.spec.ts

License

APACHE-2.0

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.1.6 (2025-05-23)

2.1.6 (2025-05-09)

2.1.5 (2025-05-09)

2.1.4 (2025-05-09)

  • Use now price instead of time-weighted price for Pyth price (aaed310)

2.1.3 (2025-05-09)

Bugfixes

Features

Add support for merging and splitting veSCA keys.

2.1.2 (2025-05-06)

Bugfixes

2.1.1 (2025-05-04)

Bugfixes

2.1.0 (2025-05-03)

⚠ BREAKING CHANGES

Starting from v2.1.0, Scallop Address class has been merged into Scallop Constants class as its superclass. All methods previously available in Scallop Address can now be accessed directly from Scallop Constants class.

  • Refactor classes structure (923f5ff)

  • Remove unused packages and upgrade @mysten/sui package (e150a17)

2.0.12 (2025-04-01)

Features

  • Add more strict rate limiter class in ScallopCache(c3eddb4)

2.0.11 (2025-03-31)

Bugfixes

  • Handle boolean values when parsing pool addresses values (b713bb1)

2.0.10 (2025-03-31)

Features

  • Add isIsolated to PoolAddress interface to ensure backward compatibility (e62bc06)

2.0.9 (2025-03-31)

Features

  • Add emerging to whitelist (6900254)

2.0.8 (2025-03-31)

Bugfixes

  • Add walletAddress as parameter (535e381)

2.0.7 (2025-03-26)

Bugfixes

2.0.6 (2025-03-23)

Features

  • add selectSCoinOrMarketCoin function and use it on withdrawQuick (e888676)

Bugfixes

  • fix coinNameToOldMarketCoinTypeMap logic (0384be0)
  • scallop cache init param (87b4869)

2.0.5 (2025-03-21)

Features

  • fix lending pending rewards (d084e41)

2.0.4 (2025-03-20)

Features

  • add collateral details in portfolio query (eef0a2e)

2.0.3 (2025-03-20)

Bug Fixes

  • update filter logic in getUserPortfolio to include accounts with positive totalDepositedValue (9163326)

  • make suiKit params optional (c79890c)

2.0.2 (2025-03-19)

2.0.1 (2025-03-18)

Features

  • Add getScallopConstants method (972250c)
  • Update README and add documentation for ScallopConstants (51bfaf8)

⚠ BREAKING CHANGES

Starting from v2.0.0, all constants in the Scallop SDK will be replaced by the ScallopConstants class. This class dynamically fetches necessary data from the API, allowing assets to be added or removed without requiring an SDK upgrade for each new pool.

2.0.0 (2025-03-17)

Features

  • Add ScallopConstants class
  • Adjust structure to use ScallopConstants class

1.5.3 (2025-03-03)

Features

  • Minor fix

1.5.2 (2025-03-03)

Features

  • Update address id to 675c65cd301dd817ea262e76 (767c09f)

1.5.1 (2025-03-03)

Features

  • Allow to query oracle list on-chain (a50e85c)

1.5.0 (2025-02-28)

⚠ BREAKING CHANGES

Starting from v1.5.0, Scallop SDK will use xOracle V2. Further development will continue from this version onward. Any version below this version is deprecated.

1.4.27 (2025-02-27)

Features

  • Fix available deposit / borrow calc

1.4.26 (2025-02-24)

Features

  • Add usdy pool

1.4.25 (2025-02-21)

Features

  • Add ns as isolated asset (ed4c222)

1.4.24 (2025-02-19)

Features

  • Add mUSD as isolated asset
  • Optimize build result

1.4.23 (2025-02-08)

Features

  • Fix sui bridge wormhole symbol coin format (523e523)

1.4.22 (2025-02-06)

Features

  • Add sbwBTC pool support (f5979d8)

1.4.21 (2025-01-24)

Features

  • Add $BLUB as isolated asset

1.4.20 (2025-01-19)

Features

  • Add TotalLendingSupply and TotalCollateralSupply (83c7aa0)

1.4.19 (2025-01-09)

Features

  • Add decimals to poolAddressQuery (469a631)

1.4.18 (2025-01-08)

Features

  • Update poolAddressQuery.ts (e37e3c9)

1.4.17 (2025-01-07)

Bugfix

  • Fix bad-debt risk level calculation (65136d5)

1.4.16 (2025-01-02)

Bugfix

  • Fix mergeSimilarCoins dest type (b428748)

1.4.10 (2024-12-31)

Features

  • Use deepMergeObject instead of replacing cache in ScallopCache (bbb6683)

1.4.9 (2024-12-30)

Features

  • Add support sbUSDT and ssbUSDT (5a510ec)

1.4.8 (2024-12-29)

Features

  • Adjust getUserPortfolio return structure (1ad951da)

1.4.7 (2024-12-28)

Features

  • Add getUserPortfolio into scallopQuery (ce63c7a)
  • Merge tokenBucket functionality into scallopCache (85d8ef6)

1.4.6 (2024-12-25)

Bugfixes

  • Set fallback value to undefined (36a47f4)

1.4.5 (2024-12-24)

Features

  • Add FDUSD

1.4.4 (2024-12-22)

Features

1.4.3 (2024-12-22)

Adjusments

  • Revert some features

1.4.2 (2024-12-22)

Bugfixes

  • Fix sCoin price not showing (9aef4aa)

  • Optimize and reduce overall rpc calls

1.4.14 (2024-12-17)

Bugfixes

1.4.13 (2024-12-17)

Bugfixes

  • Fix SUPPORT_BORROW_INCENTIVES constants (6904e80)

1.4.12 (2024-12-17)

Bugfixes

  • Fix $FUD and $DEEP availableRepayCoin (6f39c06)

1.4.11 (2024-12-16)

Bugfixes

  • Fix name from parseOriginBorrowIncentivePoolData method (53c219d)

  • Reduce rate limit

1.4.1 (2024-12-16)

⚠ BREAKING CHANGES

  • Breaking changes for claimBorrowIncentives and parseCoinType methods (21dfc91)

  • Remove getBorrowIncentiveRewardCoinName (21dfc91)

  • Allow dynamic reward coins for borrow incentive

1.4.0 (2024-12-16)

⚠ BREAKING CHANGES

  • All indexer parameters are moved into object parameters called args (0112d9a)

1.3.4 (2024-12-14)

⚠ BREAKING CHANGES

Features

  • Add getSupportedPoolAddresses in ScallopUtils (4aab3bd)
  • Add deep and fud as isolated assets (512125d)
  • Add borrow limit (c32bd39)

  • Change borrow incentive rewards type from [sui, sca] to [ssui, ssca] (67e4d6d)

1.3.3 (2024-11-25)

Features

  • Add new function getCoinPrice using indexer (e6fe81e)

  • Use stakeObligationWithVeScaQuick where possible in scallopClient (e4c95bd)

  • Add sCoinType to spool and lending query (e28d93f)

  • Add getCoinPriceByIndexer to scallopQuery (3259f0d)

1.3.2 (2024-11-06)

Features

  • Add optional params for queryKeys (9db4963)

  • Disable isIsolatedAsset query temporarily (d9d6284)

Bugfixes

  • Remove unnecessary queryGetObjects (0a0d4d1)
  • Fix query never invalidate if staleTime or gcTime is Infinity (61927c1)

1.3.1 (2024-11-04)

Features

1.3.0 (2024-11-01)

⚠ BREAKING CHANGES

Starting from v1.3.0, Scallop SDK will use @mysten/sui@1.3.0. Further development will continue from this version onward

0.47.7 (2024-10-28)

Features

  • Add fallback to onchain-data mechanism for methods that support indexer calls (71b3de2)
  • Add missing forceAddress parameters (3d24a39)

0.47.6 (2024-10-22)

Features

  • Add option forceAddressesInterface (c66a64b)

0.47.5 (2024-10-21)

Features

  • Add sbeth (Sui Bridged ETH) (0e2f2cf)

0.47.4 (2024-10-21)

Features

  • Allow exclude empty veSca in getVeScas method (d636ff1)

0.47.3 (2024-10-18)

Features

  • Add usePythPullModel to scallop params

0.47.2 (2024-10-12)

Bugfix

  • Fix error on veScaKey selection logic in stakeObligationWithVeScaQuick method (5f3324b)

0.47.1 (2024-10-08)

Bugfix

0.47.0 (2024-10-08)

⚠ BREAKING CHANGES

  • Refactor the entire naming for wormhole wrapped coin. For example:
    • sol -> wsol; ssol -> swsol
    • apt -> wapt; sapt -> swapt
    • btc -> wbtc; sbtc -> swbtc
    • eth -> weth; seth -> sweth
    • usdc -> wusdc; susdc -> swusdc
    • usdt -> wusdt; susdt -> swusdt
  • 'usdc' and 'susdc' naming will be reserved for native USDC

0.47.0-alpha.6 (2024-10-08)

Features

  • Update borrow incentive pools (525f90c)

0.47.0-alpha.5 (2024-10-08)

Features

  • Refactor fallback values (06f0a47)

0.47.0-alpha.4 (2024-10-07)

Features

  • Pull updates from v0.46.65

0.47.0-alpha.3 (2024-10-07)

Features

  • Add usdc native name, symbol, and type support (b276009)

0.46.65 (2024-10-07)

Features

0.46.64 (2024-10-06)

Features

0.47.0-alpha.2 (2024-10-04)

Features

0.46.63 (2024-10-03)

Features

0.47.0-alpha.1 (2024-09-30)

⚠ BREAKING CHANGES

  • Refactor the entire naming for wormhole wrapped coin. For example:
    • sol -> wsol; ssol -> swsol
    • apt -> wapt; sapt -> swapt
    • btc -> wbtc; sbtc -> swbtc
    • eth -> weth; seth -> sweth
    • usdc -> wusdc; susdc -> swusdc
    • usdt -> wusdt; susdt -> swusdt

0.46.62 (2024-09-27)

Features

0.46.61 (2024-09-26)

Features

0.46.60 (2024-09-24)

Features

  • Bump version

0.46.59 (2024-09-24)

Bugfix

  • Fix error redeem market coin too small (36f905c)

0.46.58 (2024-09-24)

Features

  • Allow excluding staked coin in migrateAllMarketCoin method (4e1725e)

0.46.58-alpha.1 (2024-09-19)

Adjustments

  • Increase staleTime to 2s (608489c)
  • Limit 10 for owned objects query (6d96fd6)
  • Increase token per interval to 50 and apply incremental delay time (d04e04d)
  • Add walletAddress params to ScallopCache (4e7f940)

0.46.57 (2024-09-13)

Bugfixes

  • Reduce query object limit from 50 to 10 (877667d)
  • Fix undefined value (9e4e653)
  • Fix selecting SUI coin type (38b2885)

0.46.56 (2024-09-11)

Features

  • Add sCoin support for BTC and SOL (b191459)

  • Add getSCoinSwapRate method into scallopQuery (f7e1ac0)

  • Add sCoinType property to marketPool return type (9a2bd5c)

  • Add claimAllUnlockedSca method into scallopClient (d4dbdc8)

0.46.55 (2024-08-18)

Bugfixes

  • Fix the issue where the loyalty program is not transferring rewards to the user’s address after claiming (82a411d)

0.46.54 (2024-08-06)

Features

  • Add token bucket algorithm for rate limit rpc requests (d4369ef)

  • Remove logic from unstakeQuick to prevent ambiguity of the method responsibility (5633a35)

0.46.53 (2024-08-01)

Bugfixes

  • stakeHelper function, handle stake spool when user has old marketCoin and new sCoin (5911caf)

  • minor fix on migrateAllMarketCoin (49da8b8) (04e777f)

0.46.52 (2024-07-31)

Bugfixes

0.46.51 (2024-07-31)

Features

0.46.50 (2024-07-30)

Bugfixes

  • Fix reward apr for borrow incentive when point is 0 (64c924f)

Features

  • Add walletAddress property to ScallopQuery instance (94d8396)
  • Optimize getPythPrices function (d75234b)

0.46.49 (2024-07-12)

Bugfixes

0.46.48 (2024-07-09)

Features

  • Add returnSCoin parameter to unstakeQuick (a3ad485)

0.46.47 (2024-07-09)

Bugfixes

  • update unstakeQuick return type (8fe0660)

0.46.46 (2024-07-09)

Bugfixes

  • Adjust unit tests that uses unstakeQuick (fcace2b)

0.46.45 (2024-07-09)

Bugfixes

0.46.44 (2024-07-09)

Features

  • Adjust staking spool methods with new sCoin (607f53f)

0.46.43 (2024-07-09)

Bugfixes

  • Minor fix on unstakedMarketAmount (faa647d)

0.46.42 (2024-07-08)

Bugfixes

  • Fix getLending parameters order (f71217b)

0.46.41 (2024-07-05)

Features

  • Add query, builder, and client method for new sCoin (291eca0)
  • Update docs (61a53b3)
  • Update API_BASE_URL (50ec3a8)
  • Add totalRewardedPools (d38f654)

0.46.40 (2024-07-02)

Features

  • Add getFlashLoanFees function in scallopQuery (1a5ee01)

0.46.39 (2024-06-20)

Bug Fixes

0.46.38 (2024-06-17)

Bug Fixes

  • Fix order of execution (5cfdc24)
  • Use concurrency on getStakeRewardPools (c59cfdb)

0.46.37 (2024-06-10)

Features

0.46.36 (2024-06-01)

Bug Fixes

0.46.35 (2024-06-01)

Bug Fixes

0.46.34 (2024-05-31)

Bug Fixes

0.46.33 (2024-05-29)

Bug Fixes

  • Fix increasedPointRate calculation (18d364a)

0.46.32 (2024-05-27)

Bug Fixes

⚠ BREAKING CHANGES

  • Refactor borrow incentive pools structure (516afb5)

0.46.31 (2024-05-27)

Bug Fixes

Features

  • Enable indexer for borrowIncentivePools(737c122)

0.46.3 (2024-05-27)

Bug Fixes

0.46.2 (2024-05-23)

Bug Fixes

  • Minor bug fix on spool

0.46.1 (2024-05-22)

Bug Fixes

  • Minor bug fix

0.46.0 (2024-05-22)

Features

  • Add Referral Program

0.45.0 (2024-05-12)

Bug Fixes

  • Avoid multiple RPC calls and Move Call on the same object of short period of time

0.44.28 (2024-05-11)

Features

  • Export getBindedObligationId and getBindedVeScaKey functions (e0a4365)
  • getVeSca return veSca with highest balance (95d928f)

0.44.27 (2024-04-26)

Features

0.44.26 (2024-04-26)

Features

  • Add deactiveBoost method to borrowIncentive builder module(f469475)

0.44.25 (2024-04-22)

Features

  • add afsui, hasui, vsui, and eth borrow incentive(0190c69)

0.44.24 (2024-04-22)

Features

  • add sca borrow incentive (8504da3)

0.44.23 (2024-04-21)

Features

0.44.22 (2024-04-01)

Bug Fixes

  • Minor fix on borrow incentive objectId (184b03d)

0.44.21 (2024-03-29)

Bug Fixes

  • Minor fix on borrow incentive builder test (39af1fa)
  • add isFinite check to boostValue calculation, add staked property to BorrowIncentivePool type (97640b5)

Features

  • Refactor unit tests for veSCA builder (3d0acf4)

0.44.20 (2024-03-26)

Bug Fixes

  • borrow incentive reward apr calculation (555671f)
  • get sca price in with pyth feed (2347b87)

0.44.19 (2024-03-25)

Features

  • add veSCA and stakeObligationWithVeSca implementation (dbd6c68)
  • add vesca bind check before using it (873826b)
  • done veScaQuickMethods (d96fe36)
  • finish borrow incentive (bd466fb)
  • update address id (0f9d6a9)
  • use test vesca (d700b3c)

Bug Fixes

  • Add OLD_BORROW_INCENTIVE_PROTOCOL_ID constant to borrowIncentiveBuilder.ts (01c0d0a)
  • add weighted staked on query (6e79d08)
  • boost calculation (270ed16)
  • minor (df4d118)
  • minor typo (c1ba7ff)
  • typo (fb57c5a)
  • use normal stake if no vesca (4dda1df)
  • use production addressses (3f14e82)

0.44.18 (2024-03-03)

Bug Fixes

0.44.17 (2024-03-03)

Features

  • add multiple pyth endpoints (216b6a3)
  • add new spools (fc08c12)
  • support specifying pyth endpoints (a526c36)

Bug Fixes

  • redundant initialization (bd74a99)

0.44.16 (2024-01-29)

Features

0.44.15 (2024-01-29)

Features

  • add LSDs to the const of empty addresses (eebc5ed)
  • add support for new spools in getStakeAccounts (aad24e0)
  • lending query adds conversionRate and marketCoinPrice fields (ebe4e33)
  • update for lsd incentive (e37ccdb)

0.44.14 (2024-01-11)

Bug Fixes

  • remove coin name for stakeObligation and unstakeObligation (186cf2e)

0.44.13 (2024-01-07)

Bug Fixes

0.44.12 (2024-01-05)

Bug Fixes

  • wrong obligation id obtaining (2e4e6e9)

0.44.11 (2024-01-05)

Bug Fixes

  • avoid loop getOwnedObjects (327e82b)

0.44.10 (2023-12-27)

Features

  • add change ratio when using indexer for getTvl (e4e9ce6)

0.44.9 (2023-12-27)

Features

  • add poolSize limit to availableDepositAmount (e42be8a)
  • update sdk api endpoint (78ea1d4)

0.44.8 (2023-12-26)

Features

0.44.7 (2023-11-30)

Features

  • add requiredRepay field and change the value of availableRepay in obligationAccount (4118a29)
  • add usdt borrow incentive support (d89d558)
  • borrow and repay with sign tx in client support incentive (ddf8298)

0.44.6 (2023-11-28)

0.44.5 (2023-11-24)

Features

  • add an object id address to dynamically update protocol objec (df8faa3)
  • add borrow fee information in core query (2a4dfa8)
  • add reward fee information in spool and borrow incentive query (0b26403)

0.44.4 (2023-11-14)

Features

  • add avaliable claim of borrow incentive pools in getObligationAccount (fcaac4c)

Bug Fixes

  • wrong availableClaim in getLending (fee4ec6)

0.44.3 (2023-11-12)

Features

  • add borrow incentive support (d6ad251)
  • rename functions and constants for spool (8d49c06)

0.44.2 (2023-11-07)

Features

0.44.1 (2023-10-25)

Features

  • add new afsui and hasui pools (c42ec5b)

0.44.0 (2023-10-22)

0.42.8 (2023-10-20)

0.42.7 (2023-10-18)

Bug Fixes

0.42.6 (2023-10-10)

Bug Fixes

  • correct the number of staked coin for getLending (466d603)

0.42.5 (2023-10-07)

0.42.4 (2023-10-07)

0.42.3 (2023-10-07)

Features

  • add getting tvl in query model (33579ca)

0.42.2 (2023-10-05)

Features

  • add depositAndStake and unstakeAndWithdraw (57e8669)
  • add get coins amount (8311bf2)
  • add get market coin (6bd48ae)
  • add get market coins (18e136c)
  • add getting coin decimal to utils (02efc60)
  • add getting coin wrap type to utils (93b7b14)
  • add getting multiple stake and reward pools in query (6be7063)
  • add getting obligation account in query (31bad4e)
  • add getting price from pyth to query and utils (ee487a0)
  • add getting spools and spool in query (ba92d7b)
  • add getting user lending info in query (21fdf6a)
  • add market pools and collaterals (fc72248)
  • add marketPool fields (7901444)
  • add parse coin name to symbol function in utils (85c96bd)
  • add portfolio query and improve pool, collateral and spool fields (c75e462)
  • add price field into marke pools and collaterals (99b3958)

Bug Fixes

  • correct getting coin prices (38bd69c)
  • correct getting coin type regex (3badcfc)

0.42.1 (2023-09-27)

⚠ BREAKING CHANGES

  • refactor the entire SDK

Features