npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dittoproject/sdk-core

v0.0.2

Published

SDK that give developers ability to interact with innovative Ditto platform

Downloads

1

Readme

Ditto SDK core

Compatibility

This section describes the SDK's current transaction creation and network support capabilities

Networks

List of networks that the SDK already supports or will support after a few updates

| Network name | ID | Supported from | |-------------------|-------|-------------------| | Polygon Mainnet | 137 | v0.0.1 | | Arbitrum One | 42161 | v0.0.2 | | BNB chain | 56 | — (planned) |

Actions

List of actions currently supported by the SDK

| Action | Supported from | |--------------------------|-------------------| | Swap with uniswap | v0.0.1 | | Swap with dex aggregator | — (planned) |

Triggers

List of triggers currently supported by the SDK

| Trigger | Supported from | |-------------|-------------------| | Instant | v0.0.1 | | Schedule | v0.0.2 | | Price based | v0.0.2 | | AAVE | — (not supported) |

SDK basics

This section provides examples of how to use the SDK and various instructions

1. Install SDK core

npm add @dittoproject/sdk-core

2. Initialize SDK

You can install the package in any way you like, including using yarn, bun, pnpm, npm, etc.

import createDittoSDK from "@dittoproject/sdk-core"

const sdk = await createDittoSDK({
    signer: "Your signer here (optional, but recommended for front-ends)",
    provider: new ethers.providers.JsonRpcProvider("Your RPC provider URL")
})

3. Authentication

Authentication is primarily needed so that users can interact with their smart wallets or create new ones. Without authorization, any actions with smart wallets will be rejected

3.1. Authenticate using existing signer

await sdk.authentication.authenticateWithSigner(/*
    place signer here if not provided in sdk init object 
*/)

This will trigger user's wallet and show prompt to sign message, retrieved from Ditto backend

3.2. Get authentication data for manual authentication

// Get nonce from Ditto backend
const nonce = await sdk.authentication.getAuthenticationNonce()

// Sign nonce with your account manually
const signature = ""

// Verify signature
const result = await sdk.authentication.verifySignature(signature) // => boolean

4. Create and configure automation

Automation is an object in which user-defined parameters are stored. There can be an unlimited number of these objects. Configured automations can be deployed with the help of SDK

import { Ditto } from "@dittoproject/sdk-core"

const automation = sdk.createAutomation({
    chainId: 137,
    trigger: Ditto.Triggers.Instant,
    actions: [
      Ditto.Actions.SwapWithUniswap
    ]
})


// Use .configureTrigger for trigger 
// confgiration, we skip it here
// because instant trigger does not 
// require configuration

// In this example we will swap 
// 0.1 USDT to USDC using uniswap
// with automatic route building
automation.configureAction(Actions.SwapWithUniswap, {
    fromToken: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
    toToken: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
    fromAmount: "100000"
})

5. Build or deploy automation

const result = await sdk.buildAutomation(automation, {
    // Where to take assets from, 
    // Signer = from user, Vault = from vault balance
    
    // If signer specified, then transfers will 
    // be added to pre call data
    transferFrom: Holder.Signer,
    chainId: 137,
    // Specify vault or let SDK choose
    vault: "automatic"
})

To deploy your automation instead of just getting data, replace buildAutomation method to deployAutomation with same arguments

Working with vaults

Actions with vaults can be done only after authentication

Retrieve vaults

// Get all account vaults list
sdk.vaults.getVaults()

// Get specific vault
// First argument is vault index in array
// Second is vault chain id, optional
sdk.vaults.getVault(0, 137)

Deploy new vault

// Deploy new vault
// First argument is chain id
// Second is vault version, currently latest 
// version on polygon is 3
await sdk.vaults.deployVault(137, 2)

// After vault deployed, update account data to 
// be able to get new vault
await sdk.updateCachedAccount()

Withdraw ERC-20 tokens and native currency

In this example we will transfer 0.1 USDT from vault1 to vault2

const vault1 = sdk.vaults.getVault(0, 137)
const vault2 = sdk.vaults.getVault(1, 137)

// To withdraw native currency, pass zero address 
// into token address argument
sdk.vaults.getTokenWithdrawTransaction(
    vault1, 
    vault2.address,
    "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", 
    "100000"
) // => TransactionRequest

This method returns you a transaction request that you can execute with your signer