0.0.102 • Published 5 months ago

@ace3/pluto-sdk v0.0.102

Weekly downloads
-
License
MIT
Repository
-
Last release
5 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.87

12 months ago

0.0.88

12 months ago

0.0.89

11 months ago

0.0.102

5 months ago

0.0.101

5 months ago

0.0.95

9 months ago

0.0.96

8 months ago

0.0.97

8 months ago

0.0.98

8 months ago

0.0.90

11 months ago

0.0.91

9 months ago

0.0.92

9 months ago

0.0.93

9 months ago

0.0.94

9 months ago

0.0.84

1 year ago

0.0.85

1 year ago

0.0.86

1 year ago

0.0.82

1 year ago

0.0.83

1 year ago

0.0.81

1 year ago

0.0.80

1 year ago

0.0.79

1 year ago

0.0.73

1 year ago

0.0.74

1 year ago

0.0.75

1 year ago

0.0.76

1 year ago

0.0.77

1 year ago

0.0.78

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.65

1 year ago

0.0.66

1 year ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.41

1 year ago

0.0.40

1 year ago

0.0.39

1 year ago

0.0.38

1 year ago

0.0.37

1 year ago

0.0.36

1 year ago

0.0.35

1 year ago

0.0.34

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago