0.17.0 • Published 5 months ago

@lumina-dex/sdk v0.17.0

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

LuminaDex SDK

State machine-driven SDK for interacting with the Lumina DEX on the Mina blockchain

npm version License: MIT

⚠️ Disclaimer

The Lumina DEX SDK is provided "as is" without any warranties or guarantees. While we strive to ensure the SDK's reliability and security, users should be aware that:

  • Lumina is not liable for any losses, damages, or issues arising from the use of this SDK
  • Users are responsible for validating and testing the SDK's functionality in their applications
  • Smart contract interactions always carry inherent risks including potential loss of funds

By using this SDK, you acknowledge and accept these risks and limitations.

Quick Links

Features

  • XState Powered: Built on XState state machines for predictable, testable application logic with type-safe events and transitions
  • Framework Agnostic: First-class support for both React and Vue with dedicated integrations, while maintaining a framework-agnostic core
  • Complete DEX Support: Connect wallets, swap tokens, add/remove liquidity, fetch pool data, and deploy contracts with a consistent API
  • Type-Safe: Full TypeScript support with comprehensive type definitions for a better developer experience and fewer runtime errors

Installation

# Using npm
npm install @lumina-dex/sdk

# Using pnpm
pnpm add @lumina-dex/sdk

# Using yarn
yarn add @lumina-dex/sdk

# Using bun
bun add @lumina-dex/sdk

Basic Usage

import { createDex, createWallet } from "@lumina-dex/sdk"

// Create and start a wallet machine actor
const Wallet = createWallet()

// Create and start a DEX machine actor with the wallet as input
const Dex = createDex({
	input: {
		wallet: Wallet,
		frontendFee: {
			destination: "B62qmdQRb8FKaKA7cwaujmuTBbpp5NXTJFQqL1X9ya5nkvHSuWsiQ1H",
			amount: 1
		}
	}
})

// Connect the wallet
Wallet.send({ type: "Connect" })

// Subscribe to wallet state changes
Wallet.subscribe(state => {
	console.log("Wallet state:", state.value)
	console.log("Current network:", state.context.currentNetwork)
	console.log("Account address:", state.context.account)
})

Framework Integration

The SDK provides dedicated integration modules for both React and Vue.

React

import {
	createDex,
	createWallet,
	type LuminaContext as LC
} from "@lumina-dex/sdk"
import { useSelector } from "@lumina-dex/sdk/react"
import { createContext, useContext } from "react"

// Create context
const Wallet = createWallet()
const Dex = createDex({
	input: { wallet: Wallet, frontendFee: { destination: "", amount: 0 } }
})
const Context: LC = { Dex, Wallet }
export const LuminaContext = createContext(Context)

// Use in components
function WalletButton() {
	const { Wallet } = useContext(LuminaContext)
	const isReady = useSelector(Wallet, (state) => state.matches("READY"))
	const connect = () => Wallet.send({ type: "Connect" })

	return (
		<button onClick={connect} disabled={isReady}>
			{isReady ? "Connected" : "Connect Wallet"}
		</button>
	)
}

Vue

<script setup lang="ts">
import { dexMachine, walletMachine } from "@lumina-dex/sdk"
import { useActor } from "@lumina-dex/sdk/vue"
import { computed } from "vue"

// Create shared composable
const Wallet = useActor(walletMachine)
const Dex = useActor(dexMachine, {
  input: {
    wallet: Wallet.actorRef,
    frontendFee: { destination: "", amount: 0 }
  }
})

// Reactive state
const isReady = computed(() => Wallet.snapshot.value.matches("READY"))
const connect = () => Wallet.send({ type: "Connect" })
</script>

<template>
  <button @click="connect" :disabled="isReady">
    {{ isReady ? "Connected" : "Connect Wallet" }}
  </button>
</template>

Data Fetching

import { fetchPoolList, fetchTokenList } from "@lumina-dex/sdk"

// Fetch tokens for a specific network
const tokens = await fetchTokenList("mina:devnet")
const pools = await fetchPoolList("mina:devnet")
console.log("Token list:", tokens)
console.log("Pool list:", pools)

// For direct blockchain queries (slower, use server-side)
import { fetchAllFromPoolFactory } from "@lumina-dex/sdk"
const { tokens, pools } = await fetchAllFromPoolFactory({
	network: "mina:devnet"
})

Load Additional Features

By default, the SDK initializes with the Swap feature. You can specify which features you want to load during initialization:

const Dex = createDex({
	input: {
		wallet: Wallet,
		features: ["Swap", "DeployPool"], // Load specific features
		frontendFee: {
			destination: "B62qmdQRb8FKaKA7cwaujmuTBbpp5NXTJFQqL1X9ya5nkvHSuWsiQ1H",
			amount: 1
		}
	}
})

You can load additional features dynamically after initialization:

Dex.send({ type: "LoadFeatures", features: ["DeployPool", "Claim"] })

Debugging

You can set in localStorage some specific values to help with debugging and caching:

localStorage.setItem("disableCache", true) // default false
localStorage.setItem("debugLogs", true) // default false in prod

Documentation

For complete documentation, visit https://lumina-dex.github.io/sdk/

Examples

For full working examples, check out:

License

MIT

0.17.0

5 months ago

0.16.0

5 months ago

0.15.1

6 months ago

0.15.0

6 months ago

0.14.0

6 months ago

0.13.0

6 months ago

0.12.0

7 months ago

0.11.0

7 months ago

0.10.0

8 months ago

0.9.0

8 months ago

0.8.0

8 months ago

0.7.0

8 months ago

0.6.4

8 months ago

0.6.3

9 months ago

0.6.2

9 months ago

0.6.1

9 months ago

0.6.0

9 months ago

0.5.1

9 months ago

0.5.0

9 months ago

0.4.0

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.2

10 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago