LogoLogo
Website
  • πŸ‘‹Welcome to Velar
  • Overview
    • πŸ’‘Introduction
    • πŸ›£οΈRoadmap
    • ✨Architecture
  • Getting Started
    • πŸ’»How to Use Velar Products
    • 🌊Providing Liquidity
    • 🚜Yield Farming
    • πŸ”Staking $VELAR Tokens
    • 🧩Building Integrations
    • 🀹Giving Feedback
    • πŸ‘‹Joining Community Channels
  • Velar PerpDex
    • πŸŽ›οΈCore Concepts
    • 🟧Stacks
    • πŸŸ₯Mezo (Coming Soon)
  • Velar Versions
    • ☸️Velar Dharma
      • Automated Market Maker (AMM)
      • Liquidity Pools & Yield Farming
      • IDO Launchpad
      • Bridge
      • MemeStacker
    • πŸ’‘Velar Artha
      • πŸ“ŠPerpetual Swaps
      • 🚿Concentrated Liquidity
      • πŸŒ‰Cross-Chain Bridge
    • πŸ›£οΈVelar Kama
    • ✨Velar Moksha
  • Audits
    • πŸ’‘Introduction
    • πŸ›£οΈAMM Audit on Clarity
    • 🚊PerpDex Audit on Clarity
    • πŸš‰PerpDex Audit on EVM
  • Token
    • πŸ’‘Introduction
    • πŸŽ›οΈTokenomics
    • πŸ“’Vesting Contracts
    • πŸͺœEmission
  • Developers
    • πŸ”¨Contract Addresses
    • πŸ”©Velar SDK
      • Velar SDK 0.7.0-beta [Latest]
      • Velar SDK 0.6.9
    • πŸ”¬Velar API
    • πŸ”₯Velar Verified Burner Contract
    • Velar Assets
  • Velar Executive Leadership
    • ♣️CEO - Mithil Thakore
Powered by GitBook
On this page
  • Velar SDK Types:
  • VELAR SDK Interface:
  • Swap Exact Tokens For Tokens and Multihop:
  • Swap Tokens For Exact Tokens:
  • getPairs:
  • Available tokens:
  • Pairs:

Was this helpful?

  1. Developers
  2. Velar SDK

Velar SDK 0.6.9

Installation:

npm i @velarprotocol/velar-sdk

Velar SDK Types:

import { ContractPrincipalCV, PostCondition, PostConditionMode, UIntCV } from "@stacks/transactions";

export interface SwapConfig {
    account: string;
    inToken: string;
    outToken: string;
}

export interface ISwapService {
  swap(args: SwapPayload): Promise<SwapResponse>;
  getComputedAmount(args: ComputedAmountPayload): Promise<number>;
}

enum SwapType {
  ONE = 1,
  TWO = 2
}

export interface ComputedAmountPayload {
  amount: Number;
  slippage?: Number;
  type?: SwapType;
}

export interface SwapResponse {
  contractAddress: string,
  contractName: string,
  functionName: string,
  functionArgs: [
    UIntCV,                  // pool id
    ContractPrincipalCV,    // pool token0 address
    ContractPrincipalCV,    // pool token1 address
    ContractPrincipalCV,    // in token address
    ContractPrincipalCV,    // out token address
    ContractPrincipalCV,    // staking contract
    UIntCV,                 // amount in
    UIntCV                  // amount out
  ],
  postConditions: Array<PostCondition>,
  postConditionMode: PostConditionMode,
}

export declare class SwapService {
  constructor(args: SwapConfig);
  swap(args: SwapPayload): Promise<SwapResponse>;
  getComputedAmount(args: ComputedAmountPayload): Promise<number>;
}

VELAR SDK Interface:

export declare class VelarSDK {
  getPairs (symbol: string): Promise<Array<string>>;
  getSwapInstance(args: SwapConfig): SwapService;
}

Swap Exact Tokens For Tokens and Multihop:

import {
  SwapType,
  VelarSDK,
  getTokens,
  ISwapService,
  SwapResponse,
} from '@velarprotocol/velar-sdk';
import { openContractCall } from '@stacks/connect';

const sdk = new VelarSDK();

async () => {
  // getTokens will return you all of the tokens symbols which currently Velar supporting
  const { VELAR, STX } = await getTokens();
  const account = '';

  // setup swap instance
  const swapInstance: ISwapService = await sdk.getSwapInstance({
    account: account,
    inToken: VELAR,
    outToken: STX,
  });

  // to display amount out
  const amount: AmountOutResponse = await swapInstance.getComputedAmount({
    type: SwapType.ONE,
    amount: 10,
  });

  // get swap calculated arguments for contract call
  const swapOptions: SwapResponse = await swapInstance.swap({
    amount: 10,
    type: SwapType.ONE,
  });

  // build options for contract call
  const options = {
    ...swapOptions,
    network: AppService.getNetwork(),
    appDetails: AppService.getAppDetails(),
    anchorMode: AnchorMode.Any,
    onFinish: data => {},
    onCancel: ex => {},
  };

  // open contract call
  await openContractCall(options);
};

Swap Tokens For Exact Tokens:

import {
  SwapType,
  VelarSDK,
  getTokens,
  ISwapService,
  SwapResponse,
} from '@velarprotocol/velar-sdk';
import { openContractCall } from '@stacks/connect';

const sdk = new VelarSDK();

async () => {
  // getTokens will return you all of the tokens symbols which currently Velar supporting
  const { VELAR, STX } = await getTokens();
  const account = '';

  // setup swap instance
  const swapInstance: ISwapService = await sdk.getSwapInstance({
    account: account,
    inToken: VELAR,
    outToken: STX,
  });

  // to display amount in
  const amount: number = await swapInstance.getComputedAmount({
    type: SwapType.TWO,
    amount: 10,
  });

  // get swap calculated arguments for contract call
  const swapOptions: SwapResponse = await swapInstance.swap({
    amount: 10,
    type: SwapType.TWO,
  });

  // build options for contract call
  const options = {
    ...swapOptions,
    network: AppService.getNetwork(),
    appDetails: AppService.getAppDetails(),
    anchorMode: AnchorMode.Any,
    onFinish: data => {},
    onCancel: ex => {},
  };

  // open contract call
  await openContractCall(options);
};

getPairs:

const pairs = await sdk.getPairs('VELAR'); // ['STX', 'aeUSDC']

Available tokens:

const Tokens = {
  SOME: 'SOME',
  ROCK: 'ROCK',
  VELAR: 'VELAR',
  MICK: 'MICK',
  LONG: 'LONG',
  PEPE: 'PEPE',
  $ROO: '$ROO',
  WELSH: 'WELSH',
  LEO: 'LEO',
  stSTX: 'stSTX',
  aeUSDC: 'aeUSDC',
  aBTC: 'aBTC',
  STX: 'STX',
  ODIN: 'ODIN',
  sODIN: 'sODIN',
  sROO: 'sROO',
  sWELSH: 'sWELSH',
  Hat: 'Hat',
  HASHIKO: 'HASHIKO',
  POMBOO: 'POMBOO',
  $MOONCH: '$MOONCH',
  NOT: 'NOT',
  ALUX: 'ALUX',
  GOATSTX: 'GOATSTX',
  MWM: 'MWM',
};

Pairs:

const Pairs = [
  {
    "symbol": "SOME",
    "pairs": [
      "STX"
    ]
  },
  {
    "symbol": "ROCK",
    "pairs": [
      "STX"
    ]
  },
  {
    "symbol": "VELAR",
    "pairs": [
      "STX",
      "aeUSDC"
    ]
  },
  // ... (other pairs omitted for brevity)
];

For more detailed information and additional functions, please refer to the npm library here.

PreviousVelar SDK 0.7.0-beta [Latest]NextVelar API

Last updated 4 months ago

Was this helpful?

πŸ”©