0.0.86 • Published 6 months ago

@ace3/pluto-sdk v0.0.86

Weekly downloads
-
License
MIT
Repository
-
Last release
6 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

6 months ago

0.0.85

6 months ago

0.0.86

6 months ago

0.0.82

6 months ago

0.0.83

6 months ago

0.0.81

6 months ago

0.0.80

7 months ago

0.0.79

7 months ago

0.0.73

7 months ago

0.0.74

7 months ago

0.0.75

7 months ago

0.0.76

7 months ago

0.0.77

7 months ago

0.0.78

7 months ago

0.0.42

8 months ago

0.0.43

8 months ago

0.0.44

8 months ago

0.0.45

8 months ago

0.0.46

8 months ago

0.0.47

8 months ago

0.0.70

8 months ago

0.0.71

8 months ago

0.0.72

8 months ago

0.0.62

8 months ago

0.0.63

8 months ago

0.0.64

8 months ago

0.0.65

8 months ago

0.0.66

8 months ago

0.0.67

8 months ago

0.0.68

8 months ago

0.0.69

8 months ago

0.0.60

8 months ago

0.0.61

8 months ago

0.0.59

8 months ago

0.0.51

8 months ago

0.0.52

8 months ago

0.0.53

8 months ago

0.0.54

8 months ago

0.0.55

8 months ago

0.0.56

8 months ago

0.0.57

8 months ago

0.0.58

8 months ago

0.0.50

8 months ago

0.0.48

8 months ago

0.0.49

8 months ago

0.0.41

8 months ago

0.0.40

8 months ago

0.0.39

8 months ago

0.0.38

8 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

9 months ago

0.0.27

9 months ago

0.0.26

9 months ago

0.0.25

9 months ago

0.0.24

9 months ago

0.0.23

9 months ago

0.0.20

9 months ago

0.0.19

9 months ago

0.0.18

9 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago