hedge-web3 0.1.29 → 0.1.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/declarations/idl/vault.d.ts +99 -99
  2. package/declarations/index.d.ts +1 -0
  3. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
  4. package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
  5. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
  6. package/declarations/instructions/createStakingPool.d.ts +3 -2
  7. package/declarations/instructions/createVault.d.ts +6 -5
  8. package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
  9. package/declarations/instructions/depositStakingPool.d.ts +3 -2
  10. package/declarations/instructions/depositVault.d.ts +3 -2
  11. package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
  12. package/declarations/instructions/liquidateVault.d.ts +3 -2
  13. package/declarations/instructions/loanVault.d.ts +3 -2
  14. package/declarations/instructions/redeemVault.d.ts +3 -2
  15. package/declarations/instructions/refreshOraclePrice.d.ts +4 -4
  16. package/declarations/instructions/repayVault.d.ts +3 -2
  17. package/declarations/instructions/setHalted.d.ts +3 -2
  18. package/declarations/instructions/setVaultTypeStatus.d.ts +3 -2
  19. package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
  20. package/declarations/instructions/withdrawVault.d.ts +3 -2
  21. package/declarations/state/VaultAccount.d.ts +1 -1
  22. package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
  23. package/lib/idl/vault.js +99 -99
  24. package/lib/index.js +1 -0
  25. package/lib/instructions/claimLiquidationPoolPosition.js +22 -24
  26. package/lib/instructions/claimStakingPoolPosition.js +19 -19
  27. package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
  28. package/lib/instructions/createStakingPool.js +17 -18
  29. package/lib/instructions/createVault.js +28 -32
  30. package/lib/instructions/depositLiquidationPool.js +17 -18
  31. package/lib/instructions/depositStakingPool.js +16 -18
  32. package/lib/instructions/depositVault.js +25 -27
  33. package/lib/instructions/initHedgeFoundation.js +17 -19
  34. package/lib/instructions/initHedgeFoundationTokens.js +15 -15
  35. package/lib/instructions/liquidateVault.js +32 -33
  36. package/lib/instructions/loanVault.js +23 -23
  37. package/lib/instructions/redeemVault.js +24 -24
  38. package/lib/instructions/refreshOraclePrice.js +19 -19
  39. package/lib/instructions/repayVault.js +23 -23
  40. package/lib/instructions/setHalted.js +8 -9
  41. package/lib/instructions/setVaultTypeStatus.js +9 -10
  42. package/lib/instructions/withdrawStakingPool.js +22 -24
  43. package/lib/instructions/withdrawVault.js +23 -23
  44. package/lib/state/LiquidationPoolEra.js +3 -1
  45. package/lib/state/LiquidationPosition.js +0 -7
  46. package/lib/state/StakingPool.js +3 -4
  47. package/lib/state/VaultAccount.js +2 -5
  48. package/lib/utils/getLinkedListAccounts.js +24 -16
  49. package/package.json +2 -2
  50. package/src/idl/vault.ts +198 -198
  51. package/src/index.ts +1 -0
  52. package/src/instructions/claimLiquidationPoolPosition.ts +42 -34
  53. package/src/instructions/claimStakingPoolPosition.ts +45 -25
  54. package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
  55. package/src/instructions/createStakingPool.ts +37 -35
  56. package/src/instructions/createVault.ts +80 -125
  57. package/src/instructions/depositLiquidationPool.ts +45 -26
  58. package/src/instructions/depositStakingPool.ts +32 -24
  59. package/src/instructions/depositVault.ts +57 -86
  60. package/src/instructions/initHedgeFoundation.ts +42 -43
  61. package/src/instructions/initHedgeFoundationTokens.ts +38 -39
  62. package/src/instructions/liquidateVault.ts +42 -65
  63. package/src/instructions/loanVault.ts +51 -69
  64. package/src/instructions/redeemVault.ts +83 -47
  65. package/src/instructions/refreshOraclePrice.ts +42 -33
  66. package/src/instructions/repayVault.ts +45 -65
  67. package/src/instructions/setHalted.ts +32 -24
  68. package/src/instructions/setVaultTypeStatus.ts +32 -24
  69. package/src/instructions/withdrawStakingPool.ts +44 -30
  70. package/src/instructions/withdrawVault.ts +58 -82
  71. package/src/state/LiquidationPoolEra.ts +4 -3
  72. package/src/state/LiquidationPosition.ts +0 -27
  73. package/src/state/StakingPool.ts +4 -7
  74. package/src/state/StakingPoolPosition.ts +2 -3
  75. package/src/state/VaultAccount.ts +9 -28
  76. package/src/state/VaultHistoryEvent.ts +1 -2
  77. package/src/utils/getLinkedListAccounts.ts +31 -30
  78. package/tsconfig.json +1 -1
@@ -1,18 +1,38 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ sendAndConfirmTransaction,
7
+ Signer,
8
+ SystemProgram,
9
+ SYSVAR_RENT_PUBKEY,
10
+ Transaction,
11
+ TransactionInstruction,
12
+ } from '@solana/web3.js'
4
13
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
14
+ import {
15
+ getLiquidationPoolStatePublicKey,
16
+ getLiquidationPoolUshAccountPublicKey,
17
+ getUshMintPublicKey,
18
+ getVaultSystemStatePublicKey,
19
+ } from '../Constants'
20
+ import { Vault } from 'idl/vault'
6
21
 
7
- export async function depositLiquidationPool (
8
- program: Program,
22
+ export async function depositLiquidationPool(
23
+ program: Program<Vault>,
9
24
  provider: Provider,
10
25
  payer: Signer,
11
26
  depositAmount: number,
12
27
  overrideStartTime?: number
13
28
  ): Promise<PublicKey> {
14
29
  const ushMintPublickey = await getUshMintPublicKey()
15
- const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
30
+ const payerUshAccount = await getOrCreateAssociatedTokenAccount(
31
+ provider.connection,
32
+ payer,
33
+ ushMintPublickey,
34
+ payer.publicKey
35
+ )
16
36
 
17
37
  const poolPosition = Keypair.generate()
18
38
  const transaction = new Transaction().add(
@@ -25,12 +45,12 @@ export async function depositLiquidationPool (
25
45
  overrideStartTime
26
46
  )
27
47
  )
28
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors)
48
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
29
49
  return poolPosition.publicKey
30
50
  }
31
51
 
32
- export async function depositLiquidationPoolInstruction (
33
- program: Program,
52
+ export async function depositLiquidationPoolInstruction(
53
+ program: Program<Vault>,
34
54
  payerPublicKey: PublicKey,
35
55
  payerUshAccount: PublicKey,
36
56
  poolPositionPublicKey: PublicKey,
@@ -45,23 +65,22 @@ export async function depositLiquidationPoolInstruction (
45
65
 
46
66
  const vaultSystemState = await getVaultSystemStatePublicKey()
47
67
 
48
- return program.instruction.depositLiquidationPool(
49
- new BN(depositAmount),
50
- new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
51
- {
52
- accounts: {
53
- vaultSystemState: vaultSystemState,
54
- poolState: liquidationPoolStatePublicKey,
55
- poolEra: liquidationPoolState.currentEra,
56
- poolPosition: poolPositionPublicKey,
57
- poolUshAccount: poolUSHAccount,
58
- ushMint: ushMint,
59
- payer: payerPublicKey,
60
- ownerUshAccount: payerUshAccount,
61
- tokenProgram: TOKEN_PROGRAM_ID,
62
- systemProgram: SystemProgram.programId,
63
- rent: SYSVAR_RENT_PUBKEY
64
- },
65
- signers: []
68
+ return await program.methods
69
+ .depositLiquidationPool(
70
+ new BN(depositAmount),
71
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
72
+ )
73
+ .accounts({
74
+ vaultSystemState: vaultSystemState,
75
+ poolState: liquidationPoolStatePublicKey,
76
+ poolUshAccount: poolUSHAccount,
77
+ poolEra: liquidationPoolState.currentEra,
78
+ poolPosition: poolPositionPublicKey,
79
+ ushMint: ushMint,
80
+ payer: payerPublicKey,
81
+ ownerUshAccount: payerUshAccount,
82
+ tokenProgram: TOKEN_PROGRAM_ID,
83
+ systemProgram: SystemProgram.programId,
66
84
  })
85
+ .instruction()
67
86
  }
@@ -1,11 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ sendAndConfirmTransaction,
7
+ Signer,
8
+ SystemProgram,
9
+ SYSVAR_RENT_PUBKEY,
10
+ Transaction,
11
+ TransactionInstruction,
12
+ } from '@solana/web3.js'
4
13
  import { parseAnchorErrors } from '../utils/Errors'
5
14
  import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
15
+ import { Vault } from 'idl/vault'
6
16
 
7
- export async function depositStakingPool (
8
- program: Program,
17
+ export async function depositStakingPool(
18
+ program: Program<Vault>,
9
19
  provider: Provider,
10
20
  payer: Signer,
11
21
  mintPublicKey: PublicKey,
@@ -23,12 +33,12 @@ export async function depositStakingPool (
23
33
  overrideStartTime
24
34
  )
25
35
  )
26
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors)
36
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
27
37
  return poolPosition.publicKey
28
38
  }
29
39
 
30
- export async function depositStakingPoolInstruction (
31
- program: Program,
40
+ export async function depositStakingPoolInstruction(
41
+ program: Program<Vault>,
32
42
  payerPublicKey: PublicKey,
33
43
  poolPositionPublicKey: PublicKey,
34
44
  stakedTokenMintPublicKey: PublicKey,
@@ -40,23 +50,21 @@ export async function depositStakingPoolInstruction (
40
50
  const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
41
51
  const vaultSystemState = await getVaultSystemStatePublicKey()
42
52
 
43
- return program.instruction.depositStakingPool(
44
- new BN(depositAmount),
45
- new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
46
- {
47
- accounts: {
48
- payer: payerPublicKey,
49
- vaultSystemState: vaultSystemState,
50
- pool: poolPublickey,
51
- poolPosition: poolPositionPublicKey,
52
- stakedTokenMintInfo: stakedTokenMintPublicKey,
53
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
54
- payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
55
- rent: SYSVAR_RENT_PUBKEY,
56
- tokenProgram: TOKEN_PROGRAM_ID,
57
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
58
- systemProgram: SystemProgram.programId
59
- },
60
- signers: []
53
+ return await program.methods
54
+ .depositStakingPool(
55
+ new BN(depositAmount),
56
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
57
+ )
58
+ .accounts({
59
+ payer: payerPublicKey,
60
+ vaultSystemState: vaultSystemState,
61
+ pool: poolPublickey,
62
+ poolPosition: poolPositionPublicKey,
63
+ stakedTokenMintInfo: stakedTokenMintPublicKey,
64
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
65
+ payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
66
+ tokenProgram: TOKEN_PROGRAM_ID,
67
+ systemProgram: SystemProgram.programId,
61
68
  })
69
+ .instruction()
62
70
  }
@@ -1,9 +1,6 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { TokenInstructions } from '@project-serum/serum'
3
- import {
4
- getOrCreateAssociatedTokenAccount,
5
- TOKEN_PROGRAM_ID,
6
- } from '@solana/spl-token'
3
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
7
4
  import {
8
5
  Keypair,
9
6
  PublicKey,
@@ -22,9 +19,10 @@ import {
22
19
  getPoolPublicKeyForMint,
23
20
  getHedgeMintPublicKey,
24
21
  } from '../Constants'
22
+ import { Vault } from 'idl/vault'
25
23
 
26
24
  export async function depositVault(
27
- program: Program,
25
+ program: Program<Vault>,
28
26
  provider: Provider,
29
27
  payer: Signer,
30
28
  vaultPublicKey: PublicKey,
@@ -34,67 +32,49 @@ export async function depositVault(
34
32
  const ushMintPublickey = await getUshMintPublicKey()
35
33
 
36
34
  // Prep the user to get USH back out at some point
37
- await getOrCreateAssociatedTokenAccount(
38
- provider.connection,
39
- payer,
40
- ushMintPublickey,
41
- payer.publicKey
42
- )
35
+ await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
43
36
 
44
37
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
45
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
46
- vaultAccount.collateralType
47
- )
48
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(
49
- vaultTypeAccountPublicKey
38
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
39
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
40
+ const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
41
+ provider.connection,
42
+ payer,
43
+ vaultTypeAccountInfo.collateralMint,
44
+ vaultTypeAccountPublicKey,
45
+ true
50
46
  )
51
- const vaultTypeAssociatedTokenAccount =
52
- await getOrCreateAssociatedTokenAccount(
53
- provider.connection,
54
- payer,
55
- vaultTypeAccountInfo.collateralMint,
56
- vaultTypeAccountPublicKey,
57
- true
58
- )
59
47
 
60
- const payerTokenAccount = await findAssociatedTokenAddress(
61
- payer.publicKey,
48
+ const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
49
+ const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(
50
+ vaultPublicKey,
62
51
  vaultTypeAccountInfo.collateralMint
63
52
  )
64
- const vaultAssociatedCollateralAccountPublicKey =
65
- await findAssociatedTokenAddress(
66
- vaultPublicKey,
67
- vaultTypeAccountInfo.collateralMint
68
- )
69
53
 
70
54
  const history = Keypair.generate()
71
55
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
72
56
 
73
57
  const wrappedSolAccount = Keypair.generate()
74
58
 
75
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
76
- await getHedgeMintPublicKey()
59
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
60
+ const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
61
+ hedgeStakingPoolPublicKey,
62
+ ushMintPublickey
77
63
  )
78
- const hedgeStakingPoolAssociatedUshTokenAccount =
79
- await findAssociatedTokenAddress(
80
- hedgeStakingPoolPublicKey,
81
- ushMintPublickey
82
- )
83
64
 
84
65
  const transaction = new Transaction()
85
66
  const signers = [payer, history]
86
67
 
87
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
88
- await getLinkedListAccounts(
89
- program,
90
- provider,
91
- vaultTypeAccountPublicKey,
92
- vaultPublicKey,
93
- depositAmount,
94
- 0,
95
- false,
96
- false
97
- )
68
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
+ program,
70
+ provider,
71
+ vaultTypeAccountPublicKey,
72
+ vaultPublicKey,
73
+ depositAmount,
74
+ 0,
75
+ false,
76
+ false
77
+ )
98
78
 
99
79
  if (vaultAccount.collateralType === 'SOL') {
100
80
  transaction.add(
@@ -118,9 +98,7 @@ export async function depositVault(
118
98
  program,
119
99
  vaultSystemStatePublicKey,
120
100
  payer.publicKey,
121
- vaultAccount.collateralType === 'SOL'
122
- ? wrappedSolAccount.publicKey
123
- : payerTokenAccount,
101
+ vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
124
102
  vaultPublicKey,
125
103
  vaultAssociatedCollateralAccountPublicKey,
126
104
  history.publicKey,
@@ -147,17 +125,12 @@ export async function depositVault(
147
125
  )
148
126
  }
149
127
 
150
- await sendAndConfirmTransaction(
151
- provider.connection,
152
- transaction,
153
- signers,
154
- provider.opts
155
- )
128
+ await sendAndConfirmTransaction(provider.connection, transaction, signers)
156
129
  return vaultPublicKey
157
130
  }
158
131
 
159
132
  export async function depositVaultInstruction(
160
- program: Program,
133
+ program: Program<Vault>,
161
134
  vaultSystemStatePublicKey: PublicKey,
162
135
  vaultOwner: PublicKey,
163
136
  vaultOwnerTokenAccount: PublicKey,
@@ -176,31 +149,29 @@ export async function depositVaultInstruction(
176
149
  depositAmount: number,
177
150
  overrideTime?: number
178
151
  ): Promise<TransactionInstruction> {
179
- return program.instruction.depositVault(
180
- new BN(depositAmount),
181
- new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
182
- {
183
- accounts: {
184
- vaultSystemState: vaultSystemStatePublicKey,
185
- vaultTypeAccount: vaultTypeAccountPublicKey,
186
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
187
- collateralTokenMint: collateralMint,
188
- vault: vaultPublicKey,
189
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
190
- feePool: hedgeStakingPoolPublicKey,
191
- feePoolAssociatedUshTokenAccount:
192
- hedgeStakingPoolAssociatedUshTokenAccount,
193
- history: historyPublicKey,
194
- vaultOwner: vaultOwner,
195
- vaultOwnerTokenAccount: vaultOwnerTokenAccount,
196
- ushMint: ushMintPublickey,
197
- oldSmallerVaultInfo: oldSmallerPublicKey,
198
- newSmallerVaultInfo: newSmallerPublicKey,
199
- newLargerVaultInfo: newLargerPublicKey,
200
- systemProgram: SystemProgram.programId,
201
- tokenProgram: TOKEN_PROGRAM_ID,
202
- },
203
- signers: [],
204
- }
205
- )
152
+ return await program.methods
153
+ .depositVault(
154
+ new BN(depositAmount),
155
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
156
+ )
157
+ .accounts({
158
+ vaultSystemState: vaultSystemStatePublicKey,
159
+ vaultTypeAccount: vaultTypeAccountPublicKey,
160
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
161
+ collateralTokenMint: collateralMint,
162
+ vault: vaultPublicKey,
163
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
164
+ feePool: hedgeStakingPoolPublicKey,
165
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
166
+ history: historyPublicKey,
167
+ vaultOwner: vaultOwner,
168
+ vaultOwnerTokenAccount: vaultOwnerTokenAccount,
169
+ ushMint: ushMintPublickey,
170
+ oldSmallerVaultInfo: oldSmallerPublicKey,
171
+ newSmallerVaultInfo: newSmallerPublicKey,
172
+ newLargerVaultInfo: newLargerPublicKey,
173
+ systemProgram: SystemProgram.programId,
174
+ tokenProgram: TOKEN_PROGRAM_ID,
175
+ })
176
+ .instruction()
206
177
  }
@@ -1,64 +1,63 @@
1
1
  import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ sendAndConfirmTransaction,
7
+ Signer,
8
+ SystemProgram,
9
+ SYSVAR_RENT_PUBKEY,
10
+ Transaction,
11
+ TransactionInstruction,
12
+ } from '@solana/web3.js'
4
13
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
-
7
- export async function initHedgeFoundation(
8
- program: Program,
9
- provider: Provider,
10
- payer: Signer
11
- ): Promise<PublicKey> {
14
+ import {
15
+ findAssociatedTokenAddress,
16
+ getHedgeMintPublicKey,
17
+ getLiquidationPoolStatePublicKey,
18
+ getLiquidationPoolUshAccountPublicKey,
19
+ getUshMintPublicKey,
20
+ getVaultSystemStatePublicKey,
21
+ } from '../Constants'
22
+ import { Vault } from 'idl/vault'
12
23
 
24
+ export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
13
25
  const poolEra = Keypair.generate()
14
26
  const transaction = new Transaction().add(
15
- await initHedgeFoundationInstruction(
16
- program,
17
- poolEra.publicKey,
18
- payer.publicKey,
19
- )
27
+ await initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey)
20
28
  )
21
29
 
22
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra], provider.opts).catch(parseAnchorErrors)
30
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra]).catch(parseAnchorErrors)
23
31
  return payer.publicKey
24
32
  }
25
33
 
26
- export async function initHedgeFoundationInstruction (
27
- program: Program,
34
+ export async function initHedgeFoundationInstruction(
35
+ program: Program<Vault>,
28
36
  poolEraPublicKey: PublicKey,
29
- payerPublicKey: PublicKey,
37
+ payerPublicKey: PublicKey
30
38
  ): Promise<TransactionInstruction> {
31
39
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
32
40
  const poolStatePublickey = await getLiquidationPoolStatePublicKey()
33
41
  const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
34
42
  const ushMintPublickey = await getUshMintPublicKey()
35
43
  const hedgeMintPublickey = await getHedgeMintPublicKey()
36
- const founderHedgeTokenAccount = await findAssociatedTokenAddress(
37
- payerPublicKey,
38
- hedgeMintPublickey
39
- )
40
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(
41
- vaultSystemStatePublicKey,
42
- hedgeMintPublickey
43
- )
44
+ const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
45
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
44
46
 
45
- return program.instruction.initHedgeFoundation(
46
- {
47
- accounts: {
48
- vaultSystemState: vaultSystemStatePublicKey,
49
- poolState: poolStatePublickey,
50
- poolEra: poolEraPublicKey,
51
- poolUshAccount: poolUshTokenAccount,
52
- founder: payerPublicKey,
53
- ushMint: ushMintPublickey,
54
- hedgeMint: hedgeMintPublickey,
55
- founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
56
- communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
57
- rent: SYSVAR_RENT_PUBKEY,
58
- tokenProgram: TOKEN_PROGRAM_ID,
59
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
60
- systemProgram: SystemProgram.programId
61
- },
62
- signers: []
47
+ return await program.methods
48
+ .initHedgeFoundation()
49
+ .accounts({
50
+ vaultSystemState: vaultSystemStatePublicKey,
51
+ poolState: poolStatePublickey,
52
+ poolEra: poolEraPublicKey,
53
+ poolUshAccount: poolUshTokenAccount,
54
+ founder: payerPublicKey,
55
+ ushMint: ushMintPublickey,
56
+ hedgeMint: hedgeMintPublickey,
57
+ rent: SYSVAR_RENT_PUBKEY,
58
+ tokenProgram: TOKEN_PROGRAM_ID,
59
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
60
+ systemProgram: SystemProgram.programId,
63
61
  })
62
+ .instruction()
64
63
  }
@@ -1,55 +1,54 @@
1
1
  import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ sendAndConfirmTransaction,
7
+ Signer,
8
+ SystemProgram,
9
+ SYSVAR_RENT_PUBKEY,
10
+ Transaction,
11
+ TransactionInstruction,
12
+ } from '@solana/web3.js'
4
13
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
-
7
- export async function initHedgeFoundationTokens(
8
- program: Program,
9
- provider: Provider,
10
- payer: Signer
11
- ): Promise<PublicKey> {
14
+ import {
15
+ findAssociatedTokenAddress,
16
+ getHedgeMintPublicKey,
17
+ getLiquidationPoolStatePublicKey,
18
+ getLiquidationPoolUshAccountPublicKey,
19
+ getUshMintPublicKey,
20
+ getVaultSystemStatePublicKey,
21
+ } from '../Constants'
12
22
 
23
+ export async function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey> {
13
24
  const poolEra = Keypair.generate()
14
- const transaction = new Transaction().add(
15
- await initHedgeFoundationTokensInstruction(
16
- program,
17
- payer.publicKey,
18
- )
19
- )
25
+ const transaction = new Transaction().add(await initHedgeFoundationTokensInstruction(program, payer.publicKey))
20
26
 
21
- await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors)
27
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
22
28
  return payer.publicKey
23
29
  }
24
30
 
25
- export async function initHedgeFoundationTokensInstruction (
31
+ export async function initHedgeFoundationTokensInstruction(
26
32
  program: Program,
27
- payerPublicKey: PublicKey,
33
+ payerPublicKey: PublicKey
28
34
  ): Promise<TransactionInstruction> {
29
35
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
30
36
  const hedgeMintPublickey = await getHedgeMintPublicKey()
31
- const founderHedgeTokenAccount = await findAssociatedTokenAddress(
32
- payerPublicKey,
33
- hedgeMintPublickey
34
- )
35
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(
36
- vaultSystemStatePublicKey,
37
- hedgeMintPublickey
38
- )
37
+ const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
38
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
39
39
 
40
- return program.instruction.initHedgeFoundationTokens(
41
- {
42
- accounts: {
43
- vaultSystemState: vaultSystemStatePublicKey,
44
- founder: payerPublicKey,
45
- hedgeMint: hedgeMintPublickey,
46
- founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
47
- communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
48
- rent: SYSVAR_RENT_PUBKEY,
49
- tokenProgram: TOKEN_PROGRAM_ID,
50
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
51
- systemProgram: SystemProgram.programId
52
- },
53
- signers: []
40
+ return await program.methods
41
+ .initHedgeFoundationTokens()
42
+ .accounts({
43
+ vaultSystemState: vaultSystemStatePublicKey,
44
+ founder: payerPublicKey,
45
+ hedgeMint: hedgeMintPublickey,
46
+ founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
47
+ communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
48
+ rent: SYSVAR_RENT_PUBKEY,
49
+ tokenProgram: TOKEN_PROGRAM_ID,
50
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
51
+ systemProgram: SystemProgram.programId,
54
52
  })
53
+ .instruction()
55
54
  }