New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@scallop-io/sui-scallop-sdk

Package Overview
Dependencies
Maintainers
2
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scallop-io/sui-scallop-sdk

Tookit for interacting with Scallop on SUI

  • 0.37.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

scallop

GitHub release NPM

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

Description

This SDK is used to interact with sui-lending-protocal and is written based on another sui-integrated tool, sui-kit. It consists of three main functional modules, namely Scallop Client, Scallop Address, and Scallop txBuilder. Here's a brief introduction to each of them:

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

  • Address: 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.

  • Builder: 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.

How to use

Pre-requisites

  • Installation:

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

    
    // Create an instance quickly through the`Scallop` class to construct other models.
    const sdk = new Scallop({
        networkType: 'testnet',
        ...
    })
    
    const client = sdk.createScallopClient(...);
    const address = sdk.createAddress(...);
    const txBuilder = await sdk.createTxBuilder(...);
    
    // Or, you can choose to import the class directly to create an instance.
    import {
      ScallopClient,
      ScallopAddress,
    } from '@scallop-io/sui-scallop-sdk'
    
    const client = new ScallopClient(...);
    const address = new ScallopAddress(...);
    
    

Use Client

For the original codes, please refer to test/index.spec.ts file.

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

  • Setup the network

    const NETWORK: NetworkType = 'testnet';
    
  • Run the test

    pnpm run test:unit test/index.spec.ts
    
  • Get Market Query Data

    it('Should get market query data', async () => {
      const marketData = await client.queryMarket();
      console.info('marketData:', marketData);
      expect(!!marketData).toBe(true);
    });
    
  • Open Obligation Account

    it('Should open a obligation account', async () => {
      const openObligationResult = await client.openObligation();
      console.info('openObligationResult:', openObligationResult);
      expect(openObligationResult.effects.status.status).toEqual('success');
    });
    
  • Get Obligations and Query Data

    it('Should get obligations and its query data', async () => {
      const obligations = await client.getObligations();
      console.info('obligations', obligations);
      for (const { id } of obligations) {
        const obligationData = await client.queryObligation(id);
        console.info('id:', id);
        console.info('obligationData:');
        console.dir(obligationData, { depth: null, colors: true });
        expect(!!obligationData).toBe(true);
      }
    });
    
  • Get Test Coin

    it('Should get test coin', async () => {
      const mintTestCoinResult = await client.mintTestCoin('btc', 10 ** 11);
      console.info('mintTestCoinResult:', mintTestCoinResult);
      expect(mintTestCoinResult.effects.status.status).toEqual('success');
    });
    
  • Deposit Collateral

    it('Should depoist collateral successfully', async () => {
      const obligations = await client.getObligations();
      const depositCollateralResult = await client.depositCollateral(
        'btc',
        10 ** 11,
        true,
        obligations[0]?.id
      );
      console.info('depositCollateralResult:', depositCollateralResult);
      expect(depositCollateralResult.effects.status.status).toEqual('success');
    });
    
  • Withdraw Collateral

    it('Should withdraw collateral successfully', async () => {
      const obligations = await client.getObligations();
      if (obligations.length === 0) throw Error('Obligation is required.');
      const withdrawCollateralResult = await client.withdrawCollateral(
        'eth',
        10 ** 10,
        true,
        obligations[0].id,
        obligations[0].keyId
      );
      console.info('withdrawCollateralResult:', withdrawCollateralResult);
      expect(withdrawCollateralResult.effects.status.status).toEqual('success');
    });
    
  • Deposit Asset

    it('Should depoist asset successfully', async () => {
      const depositResult = await client.deposit('usdc', 10 ** 10, true);
      console.info('depositResult:', depositResult);
      expect(depositResult.effects.status.status).toEqual('success');
    });
    
  • Withdraw Asset

    it('Should withdraw asset successfully', async () => {
      const withdrawResult = await client.withdraw('usdc', 5 * 10 ** 8, true);
      console.info('withdrawResult:', withdrawResult);
      expect(withdrawResult.effects.status.status).toEqual('success');
    });
    
  • Borrow Asset

    it('Should borrow asset successfully', async () => {
      const obligations = await client.getObligations();
      if (obligations.length === 0) throw Error('Obligation is required.');
      const borrowResult = await client.borrow(
        'usdc',
        10 ** 9,
        true,
        obligations[0].id,
        obligations[0].keyId
      );
      console.info('borrowResult:', borrowResult);
      expect(borrowResult.effects.status.status).toEqual('success');
    });
    
  • Repay Asset

    it('Should repay asset successfully', async () => {
      const obligations = await client.getObligations();
      if (obligations.length === 0) throw Error('Obligation is required.');
      const repayResult = await client.repay(
        'usdc',
        10 ** 8,
        true,
        obligations[0].id
      );
      console.info('repayResult:', repayResult);
      expect(repayResult.effects.status.status).toEqual('success');
    });
    
  • Flash Loan

    it('Should flash loan successfully', async () => {
      const flashLoanResult = await client.flashLoan(
        'usdc',
        10 ** 9,
        (txBlock, coin) => {
          return coin;
        },
        true
      );
      console.info('flashLoanResult:', flashLoanResult);
      expect(flashLoanResult.effects.status.status).toEqual('success');
    });
    

Use Scallop Transaction Builder

Use Scallop Transaction Builder

Use address manager

General Users will basically only use the get, getAddresses or getAllAddresses methods to read addresses. Here are some simple examples:

const address = new ScallopAddress({
  id: TEST_ADDRESSES_ID,
  network: NETWORK,
});

// Fetch addresses data from scallop sui API.
await addressBuilder.read();
// Get the address in the nested address structure through the dot symbol.
const address = addressBuilder.get('core.coins.usdc.id');
// Get specific network addresses of lending protocol.
const addresses = addressBuilder.getAddresses();
// Get all network addresses of lending protocol.
const allAddresses = addressBuilder.getAllAddresses();

Scallop currently maintains this address 6462a088a7ace142bb6d7e9b for use in the production environment.

Of course, you can also directly use the sui-scallop-api project to directly request an addresses.

The rest of the features are for Scallop administrators to use, and require a set of API authentication key to use the create, update, and delete address functions.

  const address = new ScallopAddress({
    id: TEST_ADDRESSES_ID,
    auth: process.env.API_KEY,
    network: NETWORK,
  });

  // create addresses.
  const addresses = await addressBuilder.create(...);
  // Update addresses by id.
  const allAddresses = await addressBuilder.update(id, ...);
  // delete addresses by id.
  const allAddresses = await addressBuilder.delete(id, ...);

License

APACHE-2.0

Keywords

FAQs

Package last updated on 28 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc