0.0.86 • Published 7 months ago

@ace3/pluto-sdk v0.0.86

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Pluto SDK

Standart Usage

Jupiter

import { createJupiterApiClient, DefaultApi } from '@jup-ag/api';
let jupiterQuoteApi: DefaultApi;
jupiterQuoteApi = createJupiterApiClient();

solana/web3.js

import { clusterApiUrl, Connection, Keypair, PublicKey } from '@solana/web3.js';
import { Wallet } from '@coral-xyz/anchor';
import {
  Environment,
} from '@ace3/pluto-sdk';

let connection: Connection;
// If you want to use the default cluster, you can use `clusterApiUrl('mainnet-beta')`
connection = new Connection(clusterApiUrl('mainnet-beta'));
// If you want to use the custom RPC
connection = new Connection('https://api.mainnet-beta.solana.com');

// To Generate Keypair & Wallet
const keypair = Keypair.generate();
const wallet = new PublicKey(keypair.publicKey);

// Generate Keypair from secretKey
const keypairFromSecretKey = Keypair.fromSecretKey(
  new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
);
// or
const keyPath: string = 'path/to/keypair.json';
const rawKeypair = JSON.parse(fs.readFileSync(keyPath, 'utf-8'));
keypair = Keypair.fromSecretKey(new Uint8Array(rawKeypair));

// Create anchor wallet
const anchorWallet = new Wallet(keypair);

// Environment
const env = 'staging' as Environment;

Earn

connection, env & wallet can refer to Standard Usage

Get Earn Products

const earnProducts: EarnProduct = await getEarnProducts(env);

Get Earn Information

const earnVaultAddress = getEarnVaultAddress(env, 'EARN_VAULT_USDC');
const earnProduct = await getEarnVaultInformation(connection, wallet, earnVaultAddress, env);

Get Earn Lender Information

const earnVaultAddress = getEarnVaultAddress(env, 'EARN_VAULT_USDC');

// You can use the wallet address or public key
const lenderInformation = await getEarnLenderInformation(connection,wallet , vaultAddress, env);
// or
const dummy = '22GTyb9NJmwFXL75LxEnFX4uxNnuz2vQJSt6QVDLeh89';
const lenderInformationDummy = await getEarnLenderInformation(connection,dummy , vaultAddress, env);

Join Earn

const amount = new anchor.BN(1e6);
const computeUnitLimit:number=500000;
const computeUnitPrice:number=0;
const simulateOnly:boolean=true;
const joinEarnTx = await joinEarn(connection, wallet, earnVaultAddress, amount, env, computeUnitLimit, computeUnitPrice, simulateOnly);

Exit Earn

const amount = new anchor.BN(1e6);
const minAmount = new anchor.BN(1);
const computeUnitLimit:number=500000;
const computeUnitPrice:number=0;
const simulateOnly:boolean=true;
const exitEarnTx = await exitEarn(connection, wallet, earnVaultAddress, amount, minAmount, env, computeUnitLimit, computeUnitPrice, simulateOnly);

Leverage

connection, env & wallet can refer to Standard Usage

Get Leverage Products

const leverageProducts = await getLeverageProducts(env);

Get Leverage Information

const leverageVaultInformation = await getLeverageVaultInformation(connection, wallet, leverageVaultAddress, env);

Get Leverage Obligation Information

// You can use the wallet address or public key
const obligationLeverageInformation = await getObligationLeverageInformation(connection, wallet, leverageVaultAddress, env);
// or
const dummy = '22GTyb9NJmwFXL75LxEnFX4uxNnuz2vQJSt6QVDLeh89';
const obligationLeverageInformationDummy = await getObligationLeverageInformation(connection, dummy, leverageVaultAddress, env);

Join Leverage

const joinAmount = 1e6;
const leverage = 2000; // 2x
const { route } = await addLeverageMainnet(connection, wallet, new PublicKey(leverageVaultAddress), env, joinAmount, leverage);
const addLeverageTx = await addLeverage(connection, wallet, leverageVaultAddress, new anchor.BN(joinAmount), route, leverage, env, false, false, 1000000, 1000, true);

Close Leverage

const position = 0;
const {
  amountToSwap,
  tokenMintA,
  tokenMintB,
} = await getLeverageCloseInformation(connection, wallet, new PublicKey(leverageVaultAddress), env, position);

const route = await getSwapRouteForCloseLeverage(connection, wallet, tokenMintA, tokenMintB, amountToSwap);

const closeLeverageTx = await closeLeverage(connection, wallet, leverageVaultAddress, position, route, env, 1000000, 1000, true);

Helpers

Get Token Balance & Solana Balance

import { Connection, clusterApiUrl } from '@solana/web3.js'
import {
  USDC_MAINNET_MINT,
  getSolanaBalance,
  getTokenBalance,
} from '@ace3/pluto-sdk'

const connection = new Connection(clusterApiUrl('mainnet-beta'))
const walletAddress: string = 'solana_wallet_address'
const usdcMintAddress: string = USDC_MAINNET_MINT.toString()
const usdcBalance = await getTokenBalance({
  connection: connection,
  mintAddress: usdcMintAddress,
  ownerAddress: walletAddress,
})

const solanaBalance = await getSolanaBalance(connection, walletAddress)

// the output is already in human readable format
console.log({ solanaBalance, usdcBalance })
0.0.84

7 months ago

0.0.85

7 months ago

0.0.86

7 months ago

0.0.82

7 months ago

0.0.83

7 months ago

0.0.81

7 months ago

0.0.80

8 months ago

0.0.79

8 months ago

0.0.73

8 months ago

0.0.74

8 months ago

0.0.75

8 months ago

0.0.76

8 months ago

0.0.77

8 months ago

0.0.78

8 months ago

0.0.42

9 months ago

0.0.43

9 months ago

0.0.44

9 months ago

0.0.45

9 months ago

0.0.46

9 months ago

0.0.47

9 months ago

0.0.70

9 months ago

0.0.71

9 months ago

0.0.72

9 months ago

0.0.62

9 months ago

0.0.63

9 months ago

0.0.64

9 months ago

0.0.65

9 months ago

0.0.66

9 months ago

0.0.67

9 months ago

0.0.68

9 months ago

0.0.69

9 months ago

0.0.60

9 months ago

0.0.61

9 months ago

0.0.59

9 months ago

0.0.51

9 months ago

0.0.52

9 months ago

0.0.53

9 months ago

0.0.54

9 months ago

0.0.55

9 months ago

0.0.56

9 months ago

0.0.57

9 months ago

0.0.58

9 months ago

0.0.50

9 months ago

0.0.48

9 months ago

0.0.49

9 months ago

0.0.41

9 months ago

0.0.40

9 months ago

0.0.39

9 months ago

0.0.38

9 months ago

0.0.37

9 months ago

0.0.36

9 months ago

0.0.35

9 months ago

0.0.34

9 months ago

0.0.33

9 months ago

0.0.32

9 months ago

0.0.31

9 months ago

0.0.30

9 months ago

0.0.29

9 months ago

0.0.28

10 months ago

0.0.27

10 months ago

0.0.26

10 months ago

0.0.25

10 months ago

0.0.24

10 months ago

0.0.23

10 months ago

0.0.20

10 months ago

0.0.19

10 months ago

0.0.18

10 months ago

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago