npm install --save @uxd-protocol/uxd-client
- UXD Program: UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr
- UXD Mint: 7kbnvuGBxxj8AG9qp8Scn56muWGaRaFqxg1FsRp3PaFT
- UXD Program: BA67esrWE7cPzQWtAftaTbrVWtmHZJ1PbbBBpZgpjH4p
- UXD Mint: B8fvu55oqVmPzRFjo99wvnPXkuA2AcFBou5tstpeHFaR
import { Controller } from '@uxd-protocol/uxd-client';
const mainnetProgramId = new PublicKey('UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr');
const controller = new Controller(
'UXD',
6,
mainnetProgramId
);
import { Connection } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com');
import { UXDClient } from '@uxd-protocol/uxd-client';
const mainnetProgramId = new PublicKey('UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr');
const client = new UXDClient(mainnetProgramId);
All public instructions are permissionless, anyone can use them at any point in time. Note that appart from mint/redeem, all other instructions do not have any parameter, and simply trigger a periodic maintainance action needed by the program.
mint
(User can deposit USDC and receive UXD in exchange)redeem
(User can return UXD and receive USDC in exchange)collect_profits_of_mercurial_vault_depository
(Buyback UXP using profits)collect_profits_of_credix_lp_depository
(Buyback UXP using profits)rebalance_create_withdraw_request_from_credix_lp_depository
(automatic credix rebalance, step1)rebalance_redeem_withdraw_request_from_credix_lp_depository
(automatic credix rebalance, step2)
Those instructions are internal instructions usable only by the UXP governance. They will be used to configure and initialize the on-chain program states. Each instruction require the DAO's authority to sign the transaction.
initialize_controller
edit_controller
freeze_program
edit_identity_depository
initialize_identity_depository
mint_with_identity_depository
redeem_from_identity_depository
register_mercurial_vault_depository
edit_mercurial_vault_depository
mint_with_mercurial_vault_depository
redeem_from_mercurial_vault_depository
register_credix_lp_depository
edit_credix_lp_depository
mint_with_credix_lp_depository
redeem_from_credix_lp_depository
Complete example for a UXD mint:
import { PublicKey, Connection, ComputeBudgetProgram } from '@solana/web3.js';
import { UXDClient } from '@uxd-protocol/uxd-client';
import { Controller } from '@uxd-protocol/uxd-client';
import { IdentityDepository } from '@uxd-protocol/uxd-client';
import { MercurialVaultDepository } from '@uxd-protocol/uxd-client';
import { CredixLpDepository } from '@uxd-protocol/uxd-client';
import { Controller } from '@uxd-protocol/uxd-client';
const uxdProgramId = new PublicKey('UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr');
const usdcMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
/**
* Initialize UXD's data sources
*/
const client = new UXDClient(uxdProgramId);
const connection = new Connection('https://api.mainnet-beta.solana.com');
const controller = new Controller('UXD', 6, uxdProgramId);
const identityDepository = new IdentityDepository(
usdcMint,
'USDC',
6,
uxdProgramId
);
const mercurialVaultDepository = await MercurialVaultDepository.initialize({
connection: connection,
collateralMint: {
mint: usdcMint,
name: 'USDC',
symbol: 'USDC',
decimals: 6,
},
uxdProgramId,
});
const credixLpDepository = await CredixLpDepository.initialize({
connection: connection,
uxdProgramId: uxdProgramId,
collateralMint: usdcMint,
collateralSymbol: 'USDC',
credixProgramId: new PublicKey(
'CRDx2YkdtYtGZXGHZ59wNv1EwKHQndnRc1gT4p8i2vPX'
),
});
/**
* Generate and process the mint instruction and transaction
*/
const user: Signer = new Keypair(); // Use your keys here
const TXN_OPTS = {
commitment: 'confirmed',
preflightCommitment: 'confirmed',
skipPreflight: true,
};
const mintInstruction = client.createMintWithCredixLpDepositoryInstruction(
controller,
identityDepository,
mercurialVaultDepository,
credixLpDepository,
user,
42, // ui amount to mint
TXN_OPTS
);
const mintTransaction = new Transaction();
mintTransaction.add(mintInstruction);
mintTransaction.add(
ComputeBudgetProgram.setComputeUnitLimit({
units: 400_000,
})
);
mintTransaction.feePayer = user.publicKey;
const mintResult = await web3.sendAndConfirmTransaction(
connection,
mintTransaction,
[user],
TXN_OPTS
);
For a rust-based CPI call, please checkout the uxd-cpi repository: