flash-sdk 2.0.66 → 2.0.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +87 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-sdk",
3
- "version": "2.0.66",
3
+ "version": "2.0.68",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/readme.md CHANGED
@@ -9,17 +9,99 @@ npm i flash-sdk / yarn add flash-sdk
9
9
  ## Using the SDK
10
10
 
11
11
  ### connect sdk locally
12
- `
12
+ ```
13
13
  import { AnchorProvider } from "@coral-xyz/anchor";
14
+ import { ComputeBudgetProgram } from '@solana/web3.js'
14
15
 
15
16
  const provider : AnchorProvider = AnchorProvider.local(clusterUrl, {
16
17
  commitment: "confirmed",
17
18
  preflightCommitment: "confirmed",
18
19
  skipPreflight: true
19
20
  });
20
- client = new PerpetualsClient(provider, programId);
21
-
22
- `
21
+ const perpClient = new PerpetualsClient(provider, programId);
22
+
23
+ const POOL_CONFIG = PoolConfig.fromIdsByName('Crypto.1','mainnet-beta')
24
+
25
+ <!-- load ALT -->
26
+ await perpClient.loadAddressLookupTable(POOL_CONFIG)
27
+
28
+ <!-- Add Liquidity -->
29
+ const payTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
30
+ const { instructions : addLiqInstructions, additionalSigners : addLiqAdditionalSigners } = await perpClient.addLiquidity(
31
+ payTokenSymbol,
32
+ tokenAmountIn,
33
+ minLpAmountOut, // new BN(0)
34
+ POOL_CONFIG
35
+ )
36
+ const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
37
+
38
+ const txid = perpClient.sendTransaction([setCULimitIx, ...addLiqInstructions ], {
39
+ addLiqAdditionalSigners,
40
+ alts: perpClient.addressLookupTables,
41
+ })
42
+
43
+
44
+
45
+ <!-- remove Liquidity -->
46
+ const recieveTokenSymbol = 'USDC'; // 'SOL' , 'BTC', 'ETH'
47
+ const { instructions : removeLiqInstructions, additionalSigners : removeLiqAdditionalSigners } = await await perpClient.removeLiquidity(
48
+ recieveTokenSymbol,
49
+ lpAmountIn,
50
+ minTokenAmountOut, // new BN(0)
51
+ POOL_CONFIG
52
+ )
53
+ const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 600_000 })
54
+ const txid = perpClient.sendTransaction([setCULimitIx, ...removeLiqInstructions ], {
55
+ removeLiqAdditionalSigners,
56
+ alts: perpClient.addressLookupTables,
57
+ })
58
+
59
+
60
+
61
+ <!-- to STAKE FLP.1 -->
62
+ const { instructions: depositStakeInstructions, additionalSigners: depositStakeAdditionalSigners } =
63
+ await perpClient.depositStake(.provider.wallet.publicKey, provider.wallet.publicKey, flpDepositAmount, POOL_CONFIG)
64
+
65
+ const txid = perpClient.sendTransaction([...depositStakeInstructions ], {
66
+ depositStakeAdditionalSigners,
67
+ alts: perpClient.addressLookupTables,
68
+ })
69
+
70
+
23
71
 
24
72
 
25
- ### To fetch all the pool data
73
+ <!-- to STAKE FLP.1 -->
74
+ const { instructions: depositStakeInstructions, additionalSigners: depositStakeAdditionalSigners } =
75
+ await perpClient.depositStake(.provider.wallet.publicKey, provider.wallet.publicKey, flpDepositAmount, POOL_CONFIG)
76
+
77
+ const txid = perpClient.sendTransaction([...depositStakeInstructions ], {
78
+ depositStakeAdditionalSigners,
79
+ alts: perpClient.addressLookupTables,
80
+ })
81
+
82
+
83
+
84
+ <!-- to UN-STAKE FLP.1 -->
85
+
86
+ const { instructions: unstakeInstantInstructions, additionalSigners : unstakeInstantAdditionalSigners } = await perpClient.unstakeInstant('USDC',flpUnstakeAmount,POOL_CONFIG)
87
+
88
+ const { instructions: withdrawStakeInstructions } = await perpClient.withdrawStake(POOL_CONFIG, false)
89
+
90
+ const txid = perpClient.sendTransaction([...unstakeInstantInstructions, ...withdrawStakeInstructions ], {
91
+ unstakeInstantAdditionalSigners,
92
+ alts: perpClient.addressLookupTables,
93
+ })
94
+
95
+
96
+
97
+ <!-- collect fees -->
98
+
99
+ const { instructions, additionalSigners } = await perpClient.collectStakeFees('USDC',POOL_CONFIG)
100
+
101
+ const txid = perpClient.sendTransaction([...instructions ], {
102
+ additionalSigners,
103
+ alts: perpClient.addressLookupTables,
104
+ })
105
+
106
+
107
+ ```