### Install the Scallop SDK Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/README.md Installs the Scallop SDK using the pnpm package manager. This is the first step to integrate the SDK into your project. ```bash pnpm install @scallop-io/sui-scallop-sdk ``` -------------------------------- ### FlashLoan on Scallop Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Provides an example of performing a flash loan on Scallop. It shows how to borrow assets, perform operations with the borrowed funds (e.g., DEX swap), and then repay the loan within the same transaction block. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); const [coin, loan] = scallopTxBlock.borrowFlashLoan(10 ** 9, 'wusdc'); /** * Do something with the borrowed coin * such as pass it to a dex to make a profit. * scallopTxBlock.moveCall('xx::dex::swap', [coin]); */ // In the end, repay the loan. scallopTxBlock.repayFlashLoan(coin, loan, 'wusdc'); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Burn sCoin and Get Market Coin Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Burns an sCoin and receives the corresponding market coin in return. The sender must be set, and the `burnSCoinQuick` method is called with the sCoin name and the amount to burn. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); const sCoinName = 'ssui'; await scallopTxBlock.burnSCoinQuick(sCoinName, 10 ** 9); ``` -------------------------------- ### Update Oracle Prices Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Demonstrates how to update asset prices in the obligation account, which is necessary before withdrawing collateral or borrowing. The example shows calling `updateAssetPricesQuick` with a list of coin names. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "updateAssetPricesQuick". tx.setSender(sender); await tx.updateAssetPricesQuick(['sui', 'wusdc']); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get Supported Borrow Incentive Rewards Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Demonstrates how to get a set of coin names that can be used as incentive rewards for the borrow incentive program via the `supportedBorrowIncentiveRewards` method. ```typescript const supportedRewardsName = scallopConstants.supportedBorrowIncentiveRewards(); // return Set ``` -------------------------------- ### Convert Market Coin to sCoin Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Mints a new sCoin by converting a market coin. This involves setting the sender and calling `mintSCoinQuick` with the market coin name and the amount to mint. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); const marketCoinName = 'ssui'; await scallopTxBlock.mintSCoinQuick(marketCoinName, 10 ** 9); ``` -------------------------------- ### Create Stake Account for Scoin Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Creates a stake account, which is a prerequisite for interacting with the Scoin pool. The transaction block is then used to transfer this newly created stake account to the sender. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); const stakeAccount = scallopTxBlock.createStakeAccount('ssui'); scallopTxBlock.transferObjects([stakeAccount], sender); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get Flashloan Fees Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves information about flashloan fees. The function returns details regarding these fees, with the specific return type documented in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const flashloanFees = await scallopQuery.getFlashLoanFees(); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Repay Asset to Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Demonstrates repaying an asset to a Scallop lending pool using `repayQuick`. The sender must be set, and the amount and asset name are required for the repayment. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "repayQuick". scallopTxBlock.setSender(sender); await scallopTxBlock.repayQuick(10 ** 9, 'wusdc'); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Write Scallop Addresses (TypeScript) Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/address.md Provides examples for writing (creating, updating, deleting) addresses using the ScallopAddress class. These operations require API authentication keys. The examples show how to initialize the class with authentication credentials and perform write operations. ```typescript const scallopAddress = new ScallopAddress({ addressId: TEST_ADDRESSES_ID, auth: process.env.API_KEY, network: NETWORK, }); // create addresses. const addresses = await scallopAddress.create({...}); // Update addresses by id. const allAddresses = await scallopAddress.update({...}); // delete addresses by id. const allAddresses = await scallopAddress.delete(id); ``` -------------------------------- ### Open Obligation Account with Scallop SDK Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Demonstrates opening an obligation account, which is required to borrow from Scallop. It shows how to create the account and handle the returned objects, including adding collateral and transferring keys. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Create an account and send obligation key to sender. scallopTxBlock.openObligationEntry(); // Simply Create an account, but the object returned by the instruction needs to be processed. const [obligation, obligationKey, hotPotato] = txBlock.openObligation(); await txBlock.addCollateralQuick(amount, coinName, obligation); scallopTxBlock.returnObligation(obligation, hotPotato); scallopTxBlock.transferObjects([obligationKey], sender); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Create Scallop Transaction Block Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Initializes the Scallop SDK with network details and a secret key, then creates a transaction block to organize subsequent operations. Requires the Scallop SDK and a valid network type and secret key environment variable. ```typescript const scallopSDK = new Scallop({ addressId: '675c65cd301dd817ea262e76', secretKey: process.env.SECRET_KEY, networkType: NETWORK, }); const scallopBuilder = await scallopSDK.createScallopBuilder(); // Create transaction block to organize your transaction. const scallopTxBlock = scallopBuilder.createTxBlock(); ``` -------------------------------- ### Supply Asset to Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Demonstrates supplying an asset to a Scallop lending pool using `depositQuick`. The sender must be set, and the amount and asset name are required. The resulting market coin is then transferred. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "depositQuick". scallopTxBlock.setSender(sender); const marketCoin = await scallopTxBlock.depositQuick(10 ** 9, 'wusdc'); scallopTxBlock.transferObjects([marketCoin], sender); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get Prices of all Supported Asset Coins Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieve the prices for all supported asset coins using the Pyth oracle. This method returns a record mapping asset names to their current prices. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const assetCoinsPrices = await scallopQuery.getPricesFromPyth(); // return Record ``` -------------------------------- ### Get Coin Prices Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/utils.md Fetches the current prices for specified coins or all available coins. This utility is essential for market data analysis and financial operations. ```typescript const scallopUtils = await scallopSDK.createScallopUtils(); const coinPrices = await scallopUtils.getCoinPrices(); const usdcCoinPrice = (await scallopUtils.getCoinPrices(['wusdc']))['wusdc']; ``` -------------------------------- ### Get Coin Decimals by Coin Name Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Illustrates how to get the decimal places for a specific coin by its name using the `coinDecimals` property of ScallopConstants. ```typescript const coinName = 'sui'; const suiDecimal = scallopConstants.coinDecimals[coinName]; ``` -------------------------------- ### Deposit Collateral to Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Shows how to deposit collateral into a Scallop lending pool using the `addCollateralQuick` method. Requires setting the sender and specifying the amount and coin name. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "addCollateralQuick". scallopTxBlock.setSender(sender); await scallopTxBlock.addCollateralQuick(10 ** 9, 'wusdc'); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Compatibility with @mysten/sui Transaction Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Illustrates how to use Scallop's `ScallopTransactionBlock` in conjunction with `@mysten/sui`'s `Transaction` object. This allows combining Scallop-specific operations with general Sui transaction building capabilities. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); /** * For example, you can do the following: * 1. split SUI from gas * 2. depoit SUI to Scallop * 3. transfer SUI Market Coin to sender */ const suiTxBlock = scallopTxBlock.txBlock; const [coin] = suiTxBlock.splitCoins(suiTxBlock.gas, [10 ** 6]); const marketCoin = scallopTxBlock.deposit(coin, 'sui'); suiTxBlock.transferObjects([marketCoin], suiTxBlock.pure.address(sender)); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Borrow Asset from Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Illustrates borrowing an asset from a Scallop lending pool with `borrowQuick`. This requires setting the sender, specifying the amount and asset, and transferring the borrowed coin to the sender. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "borrowQuick". scallopTxBlock.setSender(sender); const borrowedCoin = await scallopTxBlock.borrowQuick(10 ** 9, 'wusdc'); // Transfer borrowed coin to sender. scallopTxBlock.transferObjects([borrowedCoin], sender); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Split veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Splits a veSCA object into two, allowing a portion to be transferred. The `splitVeScaQuick` method is used with the amount to split and the veSCA key, with an option to transfer the split veSCA. ```typescript const veScaKey = ... // objectId const splitAmount = 10 ** 9; // split amount 1 SCA // set third param to true to transfer the splitted veScaKey to sender await scallopTxBlock.splitVeScaQuick({ splitAmount, veScaKey, transferVeScaKey: true }); ``` -------------------------------- ### Stake Market Coin to Scoin Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Stakes a specified amount of market coin into the Scoin pool. This operation requires setting the transaction sender and invoking the `stakeQuick` method with the amount and coin type. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); // Sender is required to invoke "stakeQuick". scallopTxBlock.setSender(sender); await scallopTxBlock.stakeQuick(10 ** 8, 'ssui'); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Claim Unlocked SCA from Expired veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Redeems unlocked SCA from an expired veSCA. This involves setting the sender and calling `redeemScaQuick` with the veSCA key. ```typescript const veScaKey = ...; const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); await scallopTxBlock.redeemScaQuick({ veScaKey }); ``` -------------------------------- ### Get User veSCA Loyalty Program Information Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetches the loyalty program information for a specific user within the veSCA system. The return type details can be found in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const loyaltyProgramInfos = await scallopQuery.getLoyaltyProgramInfos(); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Initial Lock SCA for veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Initializes a veSCA by locking a minimum amount of SCA (10 SCA) for a minimum duration (1 day). The sender must be set, and the `lockScaQuick` method is used with the specified amount and lock period. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); /* - Minimum lock amount is 10 SCA - Minimum lock period is 1 day */ const scaAmount = 10e9; // minimum lock amount is 10 SCA const lockPeriodInDays = 1; await scallopTxBlock.lockScaQuick(scaAmount, lockPeriodInDays); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Lock More SCA to Existing veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Adds more SCA to an existing, non-expired veSCA. The sender must be set, and the `extendLockAmountQuick` method is called with the additional SCA amount. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); const scaAmount = 3; await scallopTxBlock.extendLockAmountQuick({ scaAmount }); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Withdraw Asset from Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Shows how to withdraw an asset from a Scallop lending pool using `withdrawQuick`. This requires setting the sender, specifying the amount and asset, and transferring the withdrawn coin. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "withdrawQuick". scallopTxBlock.setSender(sender); const coin = await scallopTxBlock.withdrawQuick(10 ** 9, 'wusdc'); scallopTxBlock.transferObjects([coin], sender); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Merge veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Merges two veSCA objects into a single one. This operation requires specifying the target and source veSCA object IDs and calling `mergeVeScaQuick`. ```typescript const targetVeScaKey = ... // objectId const sourceVeScaKey = ... // objectId const scallopTxBlock = scallopBuilder.createBlock(); await scallopTxBlock.mergeVeScaQuick({ targetVeScaKey, sourceVeScaKey }); ``` -------------------------------- ### Withdraw Collateral from Scallop Lending Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Illustrates withdrawing collateral from a Scallop lending pool using `takeCollateralQuick`. This involves setting the sender, specifying the amount and coin, and transferring the withdrawn coin. ```typescript const scallopTxBlock = txBuilder.createTxBlock(); // Sender is required to invoke "removeCollateralQuick". scallopTxBlock.setSender(sender); const coin = await scallopTxBlock.takeCollateralQuick(10 ** 9, 'wusdc'); scallopTxBlock.transferObjects([coin], sender); await txBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Claim Reward Coin from Reward Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Claims reward coins from the reward pool. This action requires setting the sender and calling the `claimQuick` method for a specific coin type. The claimed reward coins are then transferred to the sender. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); // Sender is required to invoke "claimQuick". scallopTxBlock.setSender(sender); const rewardCoin = await scallopTxBlock.claimQuick('ssui'); scallopTxBlock.transferObjects([rewardCoin], sender); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get User Portfolio Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves a user's complete portfolio based on their wallet address. This includes all assets and their respective details. The function returns the user's portfolio, with the return type specified in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Alternative // const scallopQuery = new ScallopQuery({}) // await scallopQuery.init() const walletAddress = '0x...'; const portfolio = await scallopQuery.getUserPortfolio({ walletAddress }); // returns user portfolio ``` -------------------------------- ### Get sCoin Total Supply Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves the total supply of a specified sCoin. The function requires the name of the sCoin as input. For the exact return type, please consult the source code in the `src/types/query` directory. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const sCoinName = 'ssui'; const sCoinTotalSupply = await scallopQuery.getSCoinTotalSupply(sCoinName); ``` -------------------------------- ### Extend veSCA Lock Period Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Extends the lock period for an existing, non-expired veSCA. The sender must be set, and the `extendLockPeriodQuick` method is called with the new lock period in days. ```typescript const scallopTxBlock = scallopTxBlock(); scallopTxBlock.setSender(sender); const extendPeriodInDays = 2; await scallopTxBlock.extendLockPeriodQuick({ lockPeriodInDays: extendPeriodInDays }); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get Lending Information Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves user lending information, including spool details. Supports fetching multiple lending details by asset symbols or a single lending detail by its symbol. The return type is defined in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get multiple lending information from owner. const lendings = await scallopQuery.getLendings(['sui', 'wusdc']); // Get lending information separately. const lending = await scallopQuery.getLending('sui'); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Get Coin Type by Coin Name Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Shows how to retrieve the coin type (e.g., SUI coin type) for a given coin name using the `coinTypes` property of ScallopConstants. ```typescript const coinName = 'wusdc'; const suiCoinType = scallopConstants.coinTypes[coinName]; ... const sCoinName = 'swusdt'; const swusdtScointype = scallopConstants.coinTypes[sCoinName]; ``` -------------------------------- ### Get Obligation Coin Names Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/utils.md Retrieves a list of asset coin names associated with a specific obligation account. This function helps in understanding the assets held within an obligation. ```typescript const scallopUtils = await scallopSDK.createScallopUtils(); const obligations = await client.getObligations(); const assetCoinNames = await scallopUtils.getObligationCoinNames( obligations[0].id ); ``` -------------------------------- ### Unstake Market Coin from Scoin Pool Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Unstakes a specified amount of market coin from the Scoin pool, returning the corresponding sCoin. The sender must be set, and the `unstakeQuick` method is called. The resulting sCoin is then transferred to the sender. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); // Sender is required to invoke "unstakeQuick". scallopTxBlock.setSender(sender); const sCoin = await scallopTxBlock.unstakeQuick(10 ** 8, 'ssui'); scallopTxBlock.transferObjects([sCoin], sender); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Get sCoin Amounts in Wallet Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetches the amounts of specified sCoins held within a user's wallet. This function takes an array of sCoin names and the sender's address as parameters. The return type definition is located in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const sCoinNames = ['ssui', 'swusdc']; const sCoinAmounts = await scallopQuery.getSCoinAmounts(sCoinNames, sender); ``` -------------------------------- ### Get veSCA Treasury Information Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetches the treasury information related to veSCA. The function returns a string representing the total staked veSCA. For precise type definitions, refer to the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const totalStakeVeSca = await scallopQuery.getVeScaTreasuryInfo(); // return string ``` -------------------------------- ### Get Obligation Account Information Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetches user obligation account details, encompassing collateral and borrowing information. It allows retrieving all obligation accounts or specific ones by their ID. The exact return type is detailed in the project's `src/types/query` directory. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get all obligation accounts information. const obligationAccounts = await scallopQuery.getObligationAccounts(); // Get obligation account information separately. const obligations = await scallopQuery.getObligations(); const obligationAccount = await scallopQuery.getObligationAccount( obligations[0].id ); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Get Price Update Policies - TypeScript Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves the primary and secondary price update policy objects for the XOracle. This function requires an initialized Scallop SDK instance and a query object created via `createScallopQuery()`. The output is an object containing 'primary' and 'secondary' policy responses. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const policies = await scallopQuery.getPriceUpdatePolicies(); // return { primary: SuiObjectResponse, secondary: SuiObjectResponse } ``` ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const { primary, secondary } = await scallopQuery.getPriceUpdatePolicies(); ``` -------------------------------- ### Get Asset Oracles - TypeScript Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetches the primary and secondary oracles for all supported pool assets. This function requires an initialized Scallop SDK instance and a query object created via `createScallopQuery()`. The output is a structured object mapping asset names to their respective primary and secondary oracle configurations. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const oracles = await scallopQuery.getAssetOracles(); /** * return * { * sui: { * primary: ['pyth', ...], * secondary: ['supra', ...] * }, * usdc: { * primary: [...], * ... * } */ ``` -------------------------------- ### Get Referrer veSCA Key from Referee Address Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves the referrer's veSCA key associated with a given referee wallet address, if such a binding exists. The function returns a string representing the veSCA key or null if no referral binding is found. Type definitions are available in `src/types/query`. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const refereeAdress = '0x...'; const referrerVeScaKey = await scallopSDK.getVeScaKeyIdFromReferralBindings(refereeAddress); // return string or null ``` -------------------------------- ### Create Scallop SDK Instance (Scallop Class) Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/README.md Demonstrates how to quickly create an instance of the Scallop SDK using the `Scallop` class. This method initializes all other models and provides access to them. ```typescript const scallopSDK = new Scallop({ addressId: '67c44a103fe1b8c454eb9699', networkType: 'mainnet', secretKey: [secretKey] // ... other options }); 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(); ``` -------------------------------- ### Create Scallop SDK Instances (Direct Class Import) Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/README.md Illustrates how to import individual Scallop SDK classes and instantiate them directly. Each class requires specific initialization before use. ```typescript 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(); ``` -------------------------------- ### Initialize Scallop SDK Instance (Scallop Class with init) Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/README.md Shows an alternative way to initialize the Scallop SDK using the `Scallop` class, first calling `init()` and then accessing the models directly from the client. ```typescript // Create an instance quickly through the`Scallop` class to construct other models. await scallopSDK.init(); const scallopClient = scallopSDK.client; const { query, builder, constants, address, indexer } = scallopClient; const { indexer } = query; ``` -------------------------------- ### Scallop Indexer: Fetch Pool Data Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/indexer.md This snippet demonstrates how to initialize the Scallop Indexer and retrieve various market-related data, including pools, collaterals, spools, borrow incentive pools, and total value locked. ```typescript const scallopIndexer = await scallopSDK.createScallopIndexer(); const market = await scallopIndexer.getMarket(); const marketPools = await scallopIndexer.getMarketPools(); const marketPool = await scallopIndexer.getMarketPool('sui'); const marketCollaterals = await scallopIndexer.getMarketCollaterals(); const marketCollateral = await scallopIndexer.getMarketCollateral('sui'); const Spools = await scallopIndexer.getSpools(); const Spool = await scallopIndexer.getSpool('ssui'); const BorrowIncentivePools = await scallopIndexer.getBorrowIncentivePools(); const BorrowIncentivePool = await scallopIndexer.getBorrowIncentivePool('sui'); const tvl = await scallopIndexer.getTotalValueLocked(); ``` -------------------------------- ### Initialize ScallopConstants Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Demonstrates the basic initialization of the ScallopConstants class with a required address ID and calling the asynchronous init method. ```typescript const scallopConstants = new ScallopConstants( addressId: '67c44a103fe1b8c454eb9699' ); await scallopConstants.init(); ``` -------------------------------- ### Get Wrapped Coin Type Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/utils.md Fetches the wrapped coin type for a given asset coin name. This is useful when dealing with wrapped versions of native assets. ```typescript const scallopUtils = await scallopSDK.createScallopUtils(); const suiCoinWrapType = scallopUtils.getCoinWrappedType('sui'); const usdcCoinWrapType = scallopUtils.getCoinWrappedType('wusdc'); ``` -------------------------------- ### Access ScallopConstants Whitelist Properties Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Shows how to access different types of whitelists (lending, borrowing, collateral, packages) from the initialized ScallopConstants instance. ```typescript const lendingPoolWhitelist = scallopConstants.whitelist.lending; const borrowingPoolWhitelist = scallopConstants.whitelist.borrowing; const collateralWhitelist = scallopConstants.whitelist.collateral; const packagesWhitelist = scallopConstants.whitelist.packages; ... ``` -------------------------------- ### Query Coin Amounts and Prices Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Obtain coin amounts for a specific owner and retrieve asset prices. Methods include fetching all or specific coin amounts, market coin amounts, and prices from Pyth. The return types are detailed in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get all coin amount from owner. const coinAmounts = await scallopQuery.getCoinAmounts(); // Get specific coin amount from owner. const coinAmount = await scallopQuery.getCoinAmount('sui'); // Get all market coin amount from owner. const marketCoinAmounts = await scallopQuery.getMarketCoinAmounts(); // Get specific market coin amount from owner. const marketCoinAmount = await scallopQuery.getMarketCoinAmount('ssui'); // Get specific asset coin price. const usdcPrice = await scallopQuery.getPriceFromPyth('wusdc'); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Query Market and Collateral Pool Data Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieve asset and collateral pool data from the market. Methods like `queryMarket` fetch all data, while specific methods like `getMarketPool` retrieve data for individual assets. The return types are defined in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get both asset and collateral pools data from market. Use inspectTxn call to obtain the data provided in the scallop contract query module. const marketData = await scallopQuery.queryMarket(); // Get multiple asset pools data. To obtain all market pools at once, it is recommended to use the `queryMarket` method to reduce time consumption. const marketPools = await scallopQuery.getMarketPools(['sui', 'wusdc']); // Get asset pool data separately. const suiMarketPool = await scallopQuery.getMarketPool('sui'); // Get multiple collateral pools data. To obtain all market pools at once, it is recommended to use the `queryMarket` method to reduce time consumption. const marketCollaterals = await scallopQuery.getMarketCollaterals([ 'sui', 'wusdc', ]); // Get collateral pool data separately. const suiMarketCollateral = await scallopQuery.getMarketCollateral('sui'); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Lock More SCA and Extend veSCA Lock Period Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Locks additional SCA and extends the lock period for an existing, non-expired veSCA. This is done by calling `lockScaQuick` with an object containing the amount and desired lock period. ```typescript const scallopTxBlock = scallopBuilder.createTxBlock(); scallopTxBlock.setSender(sender); const scaAmount = 3; const extendPeriodInDays = 2; await scallopTxBlock.lockScaQuick({ amountOrCoin: scaAmount, lockPeriodInDays: extendPeriodInDays }); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Migrate All Market Coin Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Migrates all old market coins, including stakes within spools and mini wallets, to the new sCoin package. Setting the parameter to `false` returns the transaction block instead of executing it. ```typescript // Migrate all old market coin into new sCoin. Pass `false` as parameter to return the txBlock const txBlock = await client.migrateAllMarketCoin(false); ``` -------------------------------- ### Get Reward Coin Name from Stake Market Coin Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/utils.md Retrieves the reward coin name associated with a given stake market coin name. This function helps identify the reward token for staking operations. ```typescript const scallopUtils = await scallopSDK.createScallopUtils(); const rewardCoinName = scallopUtils.getRewardCoinName('swusdc'); ``` -------------------------------- ### Renew Expired veSCA Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/builder.md Renews an expired veSCA by locking a minimum amount of SCA (10 SCA) for a minimum duration (1 day). Requires setting the sender and calling `renewExpiredVeScaQuick` with the amount and new lock period. ```typescript const scallopTxBlock = scallopTxBlock(); scallopTxBlock.setSender(sender); const scaAmount = 10; // Minimum renew amount is 10 SCA const extendPeriodInDays = 7; // Minimum extend period is 1 day await scallopTxBlock.renewExpiredVeScaQuick({ scaAmount, lockPeriodInDays: extendPeriodInDays }); await scallopBuilder.signAndSendTxBlock(scallopTxBlock); ``` -------------------------------- ### Query Borrow Incentive Pools Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieve data for borrow incentive pools. This method allows fetching all available borrow incentive pools. The specific return type structure can be found in the project's `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const borrowIncentivePools = await scallopQuery.getBorrowIncentivePools(); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Open Obligation Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Opens a new obligation for the user to interact with the lending contract. This action prepares the user's account for lending operations. ```typescript const openObligationResult = await client.openObligation(); ``` -------------------------------- ### Set Default Values in ScallopConstants Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Demonstrates setting default values for pool addresses, whitelist, and general addresses during ScallopConstants initialization using the `defaultValues` option. ```typescript const scallopConstants = new ScallopConstants( addressId: '67c44a103fe1b8c454eb9699', defaultValues: { poolAddresses: [DEFAULT_POOL_ADDRESSES], whitelist: [DEFEAULT_WHITELIST], addresses: [DEFAULT_ADDRESSES] } ) await scallopConstants.init(); ``` -------------------------------- ### Create Stake Account Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Creates a new stake account for a specific spool. Each spool can support multiple stake accounts for managing staked assets. ```typescript // Create stake account for specific spool, each pool can have multiple accounts. const createStakeAccountResult = await client.createStakeAccount('ssui'); ``` -------------------------------- ### Get Scallop Total Value Locked (TVL) Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieves the total value locked (TVL) in Scallop, which includes the sum of total supply value and total borrow value. For detailed return type information, consult the source code in the `src/types/query` folder. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get tvl that including total supply value and total borrow value. const tvl = await scallopQuery.getTvl(); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Query Obligation Data Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Fetch obligation data for a given owner. `getObligations` retrieves all obligation keys and IDs, and `queryObligation` fetches detailed data using an obligation ID. Refer to `src/types/query` for return type definitions. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get all obligation key and id from owner. const obligations = await scallopQuery.getObligations(); // Use obligation id to get obligation data.. const obligationData = await scallopQuery.queryObligation(obligations[0].id); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Convert Between Coin and Market Coin Names Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/utils.md Facilitates bidirectional conversion between standard coin names and their corresponding market coin names. This is useful for managing assets across different Scallop functionalities. ```typescript const scallopUtils = await scallopSDK.createScallopUtils(); const usdcCoinName = scallopUtils.parseCoinName('swusdc'); const usdcMarketCoinName = scallopUtils.parseMarketCoinName('wusdc'); ``` -------------------------------- ### Query On-chain Data Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Methods for querying on-chain data related to spool and lending contracts. These methods have been migrated to the query instance and may be removed from the client in the future. ```typescript const marketData = await client.queryMarket(); // Get obligations data. const obligationsData = await client.getObligations(); // Get obligation data. const obligationData = await client.queryObligation(); // Get all stake accounts data. const allStakeAccountsData = await client.getAllStakeAccounts(); // Get stake accounts data. const stakeAccountsData = await client.getStakeAccounts('ssui'); // Get stake pool data. const stakePoolData = await client.getStakePool('ssui'); // Get reward pool data. const rewardPoolData = await client.getStakeRewardPool('ssui'); ``` -------------------------------- ### Access ScallopConstants Pool Addresses Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/constants.md Demonstrates how to retrieve the pool addresses, which are mapped by pool name, from the initialized ScallopConstants instance. ```typescript const poolAddresses = scallopConstants.poolAddresses; // Record ``` -------------------------------- ### Get Binded veSCA Key/Obligation ID Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md This functionality allows querying the relationship between veSCA keys and obligation IDs. It can retrieve the obligation ID bound to a given veSCA key, or the veSCA key bound to an obligation ID. The return type is either a string or null. Refer to `src/types/query` for type definitions. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // get binded veScaKey const veScaKey = '0x...'; const obligationId = await scallopQuery.getBindedVeScaKey(veScaKey); // return type string or null ``` ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // get binded veScaKey const obligationId = '0x...'; const veScaKey = await scallopQuery.getBindedVeScaKey(obligationId); // return type string or null ``` -------------------------------- ### Query Stake Account and Pool Data Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Retrieve stake account and pool information for spools. This includes fetching all stake accounts, stake accounts for specific spools, multiple stake pools, individual stake pools, and reward pools. Return types are defined in `src/types/query`. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); // Get stake account for all spools. const allStakeAccounts = await scallopQuery.getAllStakeAccounts(); // Get stake accounts for specific spool. const stakeAccounts = await scallopQuery.getStakeAccounts('ssui'); // Get multiple stake pools data. const stakePools = await scallopQuery.getStakePools(['ssui', 'swusdc']); // Get stake pool data separately. const suiStakePool = await scallopQuery.getStakePool('ssui'); // Get multiple reward pools data. const rewardPools = await scallopQuery.getStakeRewardPools([ 'ssui', 'swusdc', ]); // Get reward pool data separately. const rewardPool = await scallopQuery.getStakeRewardPool('ssui'); // For the return type, please refer to the type definition of the source code, which is located in the project `src/types/query` folder location. ``` -------------------------------- ### Repay Asset Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Repays borrowed assets to the lending protocol. Requires specifying the obligation ID and key to correctly attribute the repayment. ```typescript // Manually obtain obligation id and specify account to repay asset. const obligationsData = await client.getObligations(); const repayResult = await client.repay( 'sui', 3 * 10 ** 8, true, obligationsData[0].id ); ``` -------------------------------- ### Flash Loan Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Executes a flash loan operation. The transaction block logic is organized within a callback function, allowing for custom operations with the borrowed funds. ```typescript // Organize your transaction block in callback const flashLoanResult = await client.flashLoan( 'sui', 10 ** 8, async (_txBlock, coin) => { return coin; } ); ``` -------------------------------- ### Isolated Assets Information Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/query.md Provides functionality to manage and query isolated assets. Users can retrieve a list of all isolated assets or check if a specific asset is currently isolated. The return types are `string[]` for the list and `boolean` for the check, with detailed definitions in `src/types/query`. ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const isolatedAssets = await scallopQuery.getIsolatedAssets(); // returns string[]; ``` ```typescript const scallopQuery = await scallopSDK.createScallopQuery(); const isolatedAssetName = 'deep'; const isIsolated = await scallopQuery.isIsolatedAsset(isolatedAssetName); // returns boolean ``` -------------------------------- ### Borrow Asset Source: https://github.com/scallop-io/sui-scallop-sdk/blob/main/document/client.md Borrows assets from the lending protocol. This operation requires specifying the obligation ID and key for the transaction. ```typescript // Borrowing asset requires specifying obligation id and key. // Manually obtain obligation id and specify account to borrow asset. const obligationsData = await client.getObligations(); const borrowResult = await client.borrow( 'sui', 3 * 10 ** 8, true, obligationsData[0].id, obligationsData[0].keyId ); ```