JavaScript Client for the UXD Solana Program.

Overview

npm

JavaScript Client for the UXD Solana Program

Install

npm install --save @uxd-protocol/uxd-client

Usage

About UXD on Solana

Mainnet-Beta

  • UXD Program: UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr
  • UXD Mint: 7kbnvuGBxxj8AG9qp8Scn56muWGaRaFqxg1FsRp3PaFT

Devnet

  • UXD Program: BA67esrWE7cPzQWtAftaTbrVWtmHZJ1PbbBBpZgpjH4p
  • UXD Mint: B8fvu55oqVmPzRFjo99wvnPXkuA2AcFBou5tstpeHFaR

Instantiate the Controller Object

import { Controller } from '@uxd-protocol/uxd-client';

const controller = new Controller(
  'UXD',
  6
  'UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr'
);

Instantiate a Solana Connection

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://api.mainnet-beta.solana.com');

Create and initialize the Mango object

import { createAndInitializeMango } from '@uxd-protocol/uxd-client';

const mango = createAndInitializeMango(
  connection,
  'mainnet' // 'devnet'
);

Instantiate a MangoDepository Object for a given UXD collateral, ie WSOL

import {
  WSOL,
  SOL_DECIMALS,
  USDC,
  USDC_DECIMALS,
  MangoDepository,
} from '@uxd-protocol/uxd-client';

return new MangoDepository(
  WSOL,
  'SOL',
  SOL_DECIMALS,
  USDC, // Use mainnet mint, must be matching the program used (see USDC_DEVNET)
  'USDC',
  USDC_DECIMALS,
  'UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr' // Mainnet program
);

Instantiate the UXD Client

import { UXDClient } from '@uxd-protocol/uxd-client';

const client = new UXDClient('UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr');

Mint 1 SOL worth of UXD on the SOL Mango Depository

import { Transaction } from '@solana/web3.js';

const transaction = new Transaction();
const mintWithMangoDepositoryIx =
  client.createMintWithMangoDepositoryInstruction(
    1, // UI amount of collateral to use to mint UXD
    5, // 0.5% slippage in points
    controller,
    depository, // matching Mango Depository for the collateral
    mango,
    user // PublicKey of recipient
    {}, // ConfirmOptions, leave empty for defaults
    payer, // PublicKey of payer, optional, defaults to user
  );

transaction.add(mintWithMangoDepositoryIx);

// sign, send & confirm transaction

Redeem UXD on the SOL Mango Depository

import { Transaction } from '@solana/web3.js';

const transaction = new Transaction();
const redeemFromMangoDepositoryIx =
  client.createRedeemFromMangoDepositoryInstruction(
    10, // UI amount of UXD to redeem (returned as the provided depository Collateral, here SOL))
    5, // 0.5% slippage in points
    controller,
    depository, // matching Mango Depository for the collateral
    mango,
    user // PublicKey of recipient
    {}, // ConfirmOptions, leave empty for defaults
    payer, // PublicKey of payer, optional, defaults to user
  );

transaction.add(redeemFromMangoDepositoryIx)

// sign, send & confirm transaction

Rebalance an UXD Mango Depository

This can be used as a Swap. Depending of the polarity of the PnL of the depository, this instruction will switch Quote->Collateral or Collateral->Quote.

For instance, when the PnL is Positive (Collateral price went up since minting), user can provide USDC. By doing so, UXDProgram will offset the PnL of an equal amount, close equivalent short position, and return the backing collateral amount.

It's a 4bps + slippage + spread swap (as we use the Perp price for all operations).

You can find detailed information about the current state of depositories on the UXD Backoffice.

import { Transaction } from '@solana/web3.js';

const unrealizedPnl = await depository.getUnrealizedPnl(mango, TXN_OPTS);
const polarity = unrealizedPnl > 0 ? PnLPolarity.Positive : PnLPolarity.Negative;

const transaction = new Transaction();
const rebalanceLiteMangoDepositoryIx =
  client.createRebalanceMangoDepositoryLiteInstruction(
    10, // UI amount in Quote to rebalance (Quote on mango is USDC)
    5, // 0.5% slippage in points
    PnLPolarity.positive, // The polarity of the PnL, the expected direction of the swap (can be enforce program side but here to be explicit)
    controller,
    depository, // matching Mango Depository for the collateral
    mango,
    user // PublicKey of recipient
    {}, // ConfirmOptions, leave empty for defaults
    payer, // PublicKey of payer, optional, defaults to user
  );

transaction.add(redeemFromMangoDepositoryIx)

// sign, send & confirm transaction
Comments
  • Program v3.1.0 (May Audit)

    Program v3.1.0 (May Audit)

    Fixed

    • Depository.getDeltaNeutralPositionNotionalSizeUI(mango: Mango) now retrieves Mango account, PERP market & price concurrently.
    • Depository.getUnrealizedPnl(mango: Mango, options: ConfirmOptions) now retrieves depository account & delta-neutral position size concurrently.
    • Depository.getFundingRate(mango: Mango) now retrieves Mango Perp market & cache + bids & asks concurrently.
    • Depository.settleMangoDepositoryMangoAccountPnl(payer: Payer, mango: Mango) now retrieves Mango account, cache, PERP market & quote root bank concurrently.

    Added

    • Add Client.createQuoteMintWithMangoDepositoryInstruction method.
    • Add Client.createQuoteRedeemWithMangoDepositoryInstruction method.
    • Add Client.createSetMangoDepositoryQuoteMintAndRedeemFeeInstruction method.
    • Add Client.createSetMangoDepositoryQuoteMintAndRedeemSoftCapInstruction method.
    • Add Client.createDisableDepositoryMintingInstruction method.
    • Add Depository.getOffsetUnrealizedPnl(mango: Mango, options: ConfirmOptions) method.
    • Add Depository.getCollateralPerpPriceNativeQuotePerNativeBase(mango: Mango): Promise<I80F48> method.
    • Add Depository.getLimitPrice(slippage: I80F48, perpOrderTakerSide: 'short' | 'long', mango: Mango): Promise<I80F48> method.
    • Export new findMultipleATAAddSync(wallet: PublicKey, mintAddresses: PublicKey[]): [PublicKey, number][] utility function.

    Changed

    • Update IDL to match UXD Program version 3.1.0 (audited).
    • Client.createRebalanceMangoDepositoryLiteInstruction now returns Promise<TransactionInstruction> asynchronously to retrieve, compute & enforce the slippage limit price.
    • Client.createMintWithMangoDepositoryInstruction now returns Promise<TransactionInstruction> asynchronously to retrive, compute & enforce the slippage limit price.
    • Client.createRedeemFromMangoDepositoryInstruction now returns Promise<TransactionInstruction> asynchronously to retrieve, compute & enforce the slippage limit price.
    • Depository.getMinTradingSizeCollateralUI(mango: Mango) now returns a number synchronously.
    • getBalance utility function now throws an Error instead of a string when unable to retrieve token account balance.
    • Upgrade @project-serum/anchor to 0.24.2 (from 0.22.0).
    • Upgrade @solana/web3.js to 1.42.0 (from 1.35.1).
    • Add mangoDepositoriesQuoteRedeemableSoftCap!: BN; // u64 property to the Controller account.
    • Add the following properties to the Depository account:
      netQuoteMinted!: BN; // i128  // The signed amount of quote-minted redeemable-tokens, negative means redeemed
      quoteMintAndRedeemFee!: number; // u8 // The fee applied to quote-mint/redeem
      totalQuoteMintAndRedeemFees!: BN; // u128 // The total amount of fee collected
      mintingDisabled!: boolean; // If the depository has disabled both collateral and quote minting
    
    • All token account required by program instructions now need to be created by the caller. The program does not initialise accounts on behalf of the user anymore

    Removed

    • Remove findAddrSync utility function export, use PublicKey.findProgramAddressSync instead.
    opened by acamill 12
  • Add methods to get price impact and estimated yield

    Add methods to get price impact and estimated yield

    Derived from https://github.com/blockworks-foundation/mango-ui-v3/blob/eba6d0e1cacd1befc302b1d2cb714075a5d49353/components/trade_form/AdvancedTradeForm.tsx

    This is for Mercurial in order to add our rebalancing routes, but that should be used by the front end too for the UI values.

    enhancement 
    opened by acamill 7
  • [Protocol] Adding generic edit instructions

    [Protocol] Adding generic edit instructions

    This PR require a multi-repository change set:

    • uxd-client for javascript public API: https://github.com/UXDProtocol/uxd-client/pull/21
    • uxd-program for smart contract update: https://github.com/UXDProtocol/uxd-program/pull/182

    In this PR I update the IDL based on recent change on the uxd-program, and also ensure backward compatibility for all client endpoints

    Changelog:

    Introduce new permissioned instructions:
      - "editController", edit arbitrary fields on the UXD controller
      - "editMangoDepository", edit arbitrary fields on the UXD mango single-colateral repository
    In order to deprecate the permissioned instructions:
      - "setMangoDepositoryQuoteMintAndRedeemFee"
      - "setMangoDepositoriesRedeemableSoftCap"
      - "setRedeemableGlobalSupplyCap"
      - "setMangoDepositoryQuoteMintAndRedeemSoftCap"
    
    enhancement 
    opened by uxd-vincent 6
  • updated

    updated "disable minting" naming and idl

    • disable depository minting -> disable depository regular minting
    • updated idl
    • shd be merged after https://github.com/UXDProtocol/uxd-client/pull/11
    opened by cnek 2
  • Program v5.1.0: identity depository

    Program v5.1.0: identity depository

    Associated Program PR here

    Fixed

    • removed mango related code from src/client.ts, src/interfaces.ts, src/mango/*
    • removed contents about mango on README.md

    Added

    • unit conversion function on src/utils.ts
    • TransactionInstruction creation functions for initializeIdentityDepository, mintWithIdentityDepository, redeemFromIdentityDepository
    • updated IDL to v5.1.0
    opened by acamill 1
  • Program v3.2.0

    Program v3.2.0

    Fixed

    • Removed unused accounts on createQuoteMintWithMangoDepositoryInstruction, createQuoteRedeemWithMangoDepositoryInstruction

    Added

    • Missing events for all instructions, including SetMangoDepositoryQuoteMintAndRedeemSoftCapEvent, SetMangoDepositoryQuoteMintAndRedeemFeeEvent, QuoteRedeemFromMangoDepositoryEvent, QuoteMintWithMangoDepositoryEvent, DisableDepositoryRegularMintingEvent
    opened by cnek 1
  • [Credix] Minting/Redeeming/CollectProfit IXs

    [Credix] Minting/Redeeming/CollectProfit IXs

    Abstract

    This PR adds integration with the onchain credix smart contract by minting UXD when depositing collateral in credix and burning UXD when withdrawing collateral from credix

    New instructions set:

    • register_credix_lp_depository

      • init all necessary accounts
      • store important accounts address
      • init accounting storage
    • mint_with_credix_lp_depository

      • take user's USDC and put it in the credix LP
      • mint UXD and give it to user in exchange
    • redeem_from_credix_lp_depository

      • take user's UXD and burn it
      • withdraw USDC from credix LP and give it to user in exchange
    • collect_profit_of_credix_lp_depository

      • see if the credix LP owned assets surpass outstanding UXD liabilities
      • if yes, withdraw profits into UXD's authority collateral account
    • edit_credix_lp_depository

      • set and change configuration flags and accounting caps

    PR Combo:

    • uxd-client: https://github.com/UXDProtocol/uxd-client/pull/34
    • uxd-program: https://github.com/UXDProtocol/uxd-program/pull/213
    opened by uxd-vincent 0
  • reinject mango collateral to identity depo IX

    reinject mango collateral to identity depo IX

    program change: https://github.com/UXDProtocol/uxd-program/pull/207

    • ix support
    • minor fix on naming/formatting
    • added back some mango model temporary

    post deploy

    • remove reinject and all mango related code
    opened by cnek 0
  • Add freeze program ix support

    Add freeze program ix support

    related program change:

    • https://github.com/UXDProtocol/uxd-program/pull/198

    Added

    • TransactionInstruction creation function for freezeProgram
    • isFrozen for controller onchain account interface
    • idl update
    opened by cnek 0
  • Program v4.0.0

    Program v4.0.0

    Fixed

    • Removed unused accounts on createQuoteMintWithMangoDepositoryInstruction, createQuoteRedeemWithMangoDepositoryInstruction

    Added

    • Missing events for all instructions, including SetMangoDepositoryQuoteMintAndRedeemSoftCapEvent, SetMangoDepositoryQuoteMintAndRedeemFeeEvent, QuoteRedeemFromMangoDepositoryEvent, QuoteMintWithMangoDepositoryEvent, DisableDepositoryRegularMintingEvent

    (Initially v3.2.0 but grew too big)

    opened by acamill 0
  • Dependencies cleanup

    Dependencies cleanup

    New dependencies:

    "dependencies": { "@blockworks-foundation/mango-client": "3.4.7", "camelcase": "5.3.1" }, "peerDependencies": { "@project-serum/anchor": "0.24.2", "@solana/spl-token": "0.2.0", "@solana/web3.js": "1.48.0" },

    opened by GregoryNEUT 0
  • [Credix] Exposing more on-chain credix informations

    [Credix] Exposing more on-chain credix informations

    The goal of this PR is to expose in the client depository:

    • the time remaining of locked withdrawal period
    • the amount of outstanding credix in the pool (which is required to know the price value of a LP unit)
    opened by uxd-vincent 0
  • Maple Integration (Minting)

    Maple Integration (Minting)

    This PR adds support for maple depository new instructions : register, mint and edit

    PR Combo:

    • uxd-client: https://github.com/UXDProtocol/uxd-client/pull/29
    • uxd-program: https://github.com/UXDProtocol/uxd-program/pull/205
    opened by uxd-vincent 0
Releases(v2.0.2)
  • v2.0.2(Jul 19, 2022)

    What's Changed

    • replace mintingDisabled with regularMintingDisabled

    Full Changelog: https://github.com/UXDProtocol/uxd-client/compare/v2.0.1...v2.0.2

    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Jul 18, 2022)

    What's Changed

    • Update IDL to fit program v3.1.0
      • Name of the instruction disableDepositoryMinting changed to disableDepositoryRegularMinting

    Full Changelog: https://github.com/UXDProtocol/uxd-client/compare/v2.0.0...v2.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Jun 29, 2022)

    Fixed

    • Depository.getDeltaNeutralPositionNotionalSizeUI(mango: Mango) now retrieves Mango account, PERP market & price concurrently.
    • Depository.getUnrealizedPnl(mango: Mango, options: ConfirmOptions) now retrieves depository account & delta-neutral position size concurrently.
    • Depository.getFundingRate(mango: Mango) now retrieves Mango Perp market & cache + bids & asks concurrently.
    • Depository.settleMangoDepositoryMangoAccountPnl(payer: Payer, mango: Mango) now retrieves Mango account, cache, PERP market & quote root bank concurrently.

    Added

    • Add Client.createQuoteMintWithMangoDepositoryInstruction method.
    • Add Client.createQuoteRedeemWithMangoDepositoryInstruction method.
    • Add Client.createSetMangoDepositoryQuoteMintAndRedeemFeeInstruction method.
    • Add Client.createSetMangoDepositoryQuoteMintAndRedeemSoftCapInstruction method.
    • Add Client.createDisableDepositoryMintingInstruction method.
    • Add Depository.getOffsetUnrealizedPnl(mango: Mango, options: ConfirmOptions) method.
    • Add Depository.getCollateralPerpPriceNativeQuotePerNativeBase(mango: Mango): Promise<I80F48> method.
    • Add Depository.getLimitPrice(slippage: I80F48, perpOrderTakerSide: 'short' | 'long', mango: Mango): Promise<I80F48> method.
    • Export new findMultipleATAAddSync(wallet: PublicKey, mintAddresses: PublicKey[]): [PublicKey, number][] utility function.

    Changed

    • Update IDL to match UXD Program version 3.1.0 (audited).
    • Client.createRebalanceMangoDepositoryLiteInstruction now returns Promise<TransactionInstruction> asynchronously to retrieve, compute & enforce the slippage limit price.
    • Client.createMintWithMangoDepositoryInstruction now returns Promise<TransactionInstruction> asynchronously to retrive, compute & enforce the slippage limit price.
    • Client.createRedeemFromMangoDepositoryInstruction now returns Promise<TransactionInstruction> asynchronously to retrieve, compute & enforce the slippage limit price.
    • Depository.getMinTradingSizeCollateralUI(mango: Mango) now returns a number synchronously.
    • getBalance utility function now throws an Error instead of a string when unable to retrieve token account balance.
    • Upgrade @project-serum/anchor to 0.24.2 (from 0.22.0).
    • Upgrade @solana/web3.js to 1.42.0 (from 1.35.1).
    • Add mangoDepositoriesQuoteRedeemableSoftCap!: BN; // u64 property to the Controller account.
    • Add the following properties to the Depository account:
      netQuoteMinted!: BN; // i128  // The signed amount of quote-minted redeemable-tokens, negative means redeemed
      quoteMintAndRedeemFee!: number; // u8 // The fee applied to quote-mint/redeem
      totalQuoteMintAndRedeemFees!: BN; // u128 // The total amount of fee collected
      mintingDisabled!: boolean; // If the depository has disabled both collateral and quote minting
    
    • All token account required by program instructions now need to be created by the caller. The program does not initialise accounts on behalf of the user anymore

    Removed

    • Remove findAddrSync utility function export, use PublicKey.findProgramAddressSync instead.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(May 6, 2022)

Owner
UXDProtocol
Algorithmic stablecoin backed 100% by a delta neutral position using derivatives.
UXDProtocol
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
The best Solana Program Template (No Anchor!)

The Best Solana Program Template Includes Shank/Solita SDK generation, Amman support, scripts, .github configuration, and more! Environment Setup Inst

Sammy 50 Dec 24, 2022
🛠 Solana Web3 Tools - A set of tools to improve the user experience on Web3 Solana Frontends.

?? Solana Web3 Tools - A set of tools to improve the user experience on Web3 Solana Frontends.

Holaplex 30 May 21, 2022
solana-base-app is a base level, including most of the common features and wallet connectivity, try using `npx solana-base-app react my-app`

solana-base-app solana-base-app is for Solana beginners to get them up and running fast. To start run : run npx solana-base-app react my-app change th

UjjwalGupta49 33 Dec 27, 2022
TikTokLive-Widget: A socket client/server program that exposes a widget with alerts (such as gifts, followers ...) for a specific user streaming on Tik Tok Live platform

TikTokLive-Widget: A socket client/server program that exposes a widget with alerts (such as gifts, followers ...) for a specific user streaming on Tik Tok Live platform

null 3 Dec 3, 2022
NFT stacking frontend completion using web3 on solana for client Nelson project.

NFT stacking frontend completion using web3 on solana for client Nelson project.

Kapollo 12 Dec 16, 2022
A full-featured Solana Metaplex Candymachine client-side library in Typescript

Candymachine Client SDK A full-featured Solana Metaplex Candymachine client-side library in Typescript Disclaimer: The SDK is currently a pre-alpha ve

Boxfish Studio 36 Nov 10, 2022
This web application was build the microverse program, it's about implementing functionalities using JavaScript

This web application was build the microverse program, it's about implementing functionalities using JavaScript

Mehdi Abdelaziz Rahal 11 Aug 18, 2022
A javascript written program that can be used to automatically join BloxFlip Rains.

Toxic Rainer Auto-BloxFlip Rain Joiner Toxic Rainer is a web-socket based background running program used to automatically join BloxFlip Rains to get

null 4 Jul 10, 2022
Candy Shop is a JavaScript library that allows DAOs, NFT projects and anyone to create an NFT marketplace on Solana in minutes!

Candy Shop (IN BETA) Intro Candy Shop is a JavaScript library that allows DAOs, NFT projects and anyone to create an NFT marketplace on Solana in minu

LIQNFT 111 Dec 15, 2022
This is a simple word counter program based on Web.

Web Word Counter: This is a simple word counter program based on Web which made with HTML, CSS and JavaScript. It's able count the number of character

Md. Rakibul Islam 2 Jan 2, 2022
Dead simple program to upload NFT data to IPFS via nft.storage

NFTP The simplest way to publish files and folders to IPFS, with one command. 100% FREE to upload as much files as you want, powered by nft.storage. N

factoria 35 Dec 11, 2022
Gofiber with NextJS Static HTML is a small Go program to showcase for bundling a static HTML export of a Next.js app

Gofiber and NextJS Static HTML Gofiber with NextJS Static HTML is a small Go program to showcase for bundling a static HTML export of a Next.js app. R

Mai 1 Jan 22, 2022
Solo programming project for week one of module 2 of the Microverse Program

To-do List Solo programming project for week one of module 2 of the Microverse Program. "To-do List" is a simple website that displays a list of books

Ivan Silva 9 May 6, 2022
A js program generate random 12 words metamask mnemonic and check the balance in the account.

Metamask-Mnemonic-Brute-Force A js program random generate 12 words metamask mnemonic and check the balance in the account. Requirement ethers web3 bi

Xeift 30 Dec 25, 2022
A tiny JVM (Java Virtual Machine) program written in TypeScript.

jvm-on-typescript A tiny JVM (Java Virtual Machine) program written in TypeScript. This virtual machine specification compliants Java Virtual Machine

Itsu 27 Nov 24, 2022
Made this group project as a part of DESIS Ascend Educare Mentorship Program.

Buy-It-Right An intersection of Finance & Technology . About The Project: Buy It Right is a board game based on the economic idea of a monopoly. Four

Sejal Maheshwari 2 Dec 5, 2022
A User Interface for calling a program's instructions

Anchor Test UI Testing Anchor programs can be lenghty and overwelming So we thought of a Cool Way of Testing Anchor program without writing an Testing

Pratik Saria 25 Sep 3, 2022