hedge-web3 0.1.29 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) 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 +3 -2
  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 +19 -22
  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 -31
  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 +17 -17
  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 +39 -29
  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 +81 -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 +41 -32
  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
@@ -1,9 +1,5 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import {
3
- ASSOCIATED_TOKEN_PROGRAM_ID,
4
- TOKEN_PROGRAM_ID,
5
- getOrCreateAssociatedTokenAccount,
6
- } from '@solana/spl-token'
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
7
3
  import {
8
4
  Keypair,
9
5
  PublicKey,
@@ -24,9 +20,10 @@ import {
24
20
  getUshMintPublicKey,
25
21
  getVaultSystemStatePublicKey,
26
22
  } from '../Constants'
23
+ import { Vault } from 'idl/vault'
27
24
 
28
25
  export async function liquidateVault(
29
- program: Program,
26
+ program: Program<Vault>,
30
27
  provider: Provider,
31
28
  payer: Signer,
32
29
  vaultPublicKey: PublicKey,
@@ -34,23 +31,15 @@ export async function liquidateVault(
34
31
  ): Promise<PublicKey> {
35
32
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
36
33
 
37
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
38
- vaultAccount.collateralType
39
- )
40
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(
41
- vaultTypeAccountPublicKey
42
- )
34
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
35
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
43
36
  const collateralMint = vaultTypeAccountInfo.collateralMint
44
37
 
45
38
  const hedgeMintPublickey = await getHedgeMintPublicKey()
46
39
  const ushMintPublickey = await getUshMintPublicKey()
47
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
48
- hedgeMintPublickey
49
- )
40
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
50
41
  const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
51
- const poolStateInfo = await program.account.liquidationPoolState.fetch(
52
- liquidationPoolStatePublicKey
53
- )
42
+ const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
54
43
 
55
44
  const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
56
45
  provider.connection,
@@ -80,34 +69,31 @@ export async function liquidateVault(
80
69
  liquidationPoolStatePublicKey,
81
70
  true
82
71
  )
83
- const vaultTypeAssociatedTokenAccount =
84
- await getOrCreateAssociatedTokenAccount(
85
- provider.connection,
86
- payer,
87
- collateralMint,
88
- vaultTypeAccountPublicKey,
89
- true
90
- )
91
- const hedgeStakingPoolAssociatedUshTokenAccount =
92
- await getOrCreateAssociatedTokenAccount(
93
- provider.connection,
94
- payer,
95
- ushMintPublickey,
96
- hedgeStakingPoolPublicKey,
97
- true
98
- )
72
+ const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
73
+ provider.connection,
74
+ payer,
75
+ collateralMint,
76
+ vaultTypeAccountPublicKey,
77
+ true
78
+ )
79
+ const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
80
+ provider.connection,
81
+ payer,
82
+ ushMintPublickey,
83
+ hedgeStakingPoolPublicKey,
84
+ true
85
+ )
99
86
 
100
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
101
- await getLinkedListAccounts(
102
- program,
103
- provider,
104
- vaultTypeAccountPublicKey,
105
- vaultPublicKey,
106
- 0,
107
- 0,
108
- false,
109
- true
110
- )
87
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
88
+ program,
89
+ provider,
90
+ vaultTypeAccountPublicKey,
91
+ vaultPublicKey,
92
+ 0,
93
+ 0,
94
+ false,
95
+ true
96
+ )
111
97
 
112
98
  const history = Keypair.generate()
113
99
  const newEra = Keypair.generate()
@@ -137,17 +123,12 @@ export async function liquidateVault(
137
123
  overrideTime
138
124
  )
139
125
  )
140
- await sendAndConfirmTransaction(
141
- provider.connection,
142
- transaction,
143
- [payer, history, newEra],
144
- provider.opts
145
- )
126
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra])
146
127
  return vaultPublicKey
147
128
  }
148
129
 
149
130
  export async function liquidateVaultInstruction(
150
- program: Program,
131
+ program: Program<Vault>,
151
132
  payerPublicKey: PublicKey,
152
133
  payerAssociatedTokenAccount: PublicKey,
153
134
  vaultPublickey: PublicKey,
@@ -170,12 +151,14 @@ export async function liquidateVaultInstruction(
170
151
  ): Promise<TransactionInstruction> {
171
152
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
172
153
  const ushMintPublickey = await getUshMintPublicKey()
173
- const liquidationPoolUshAccountPublickey =
174
- await getLiquidationPoolUshAccountPublicKey()
154
+ const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
175
155
  const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
176
156
 
177
- const payload = {
178
- accounts: {
157
+ return program.methods
158
+ .liquidateVault(
159
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
160
+ )
161
+ .accounts({
179
162
  vaultSystemState: vaultSystemStatePublicKey,
180
163
  vaultTypeAccount: vaultTypeAccount,
181
164
  vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
@@ -191,8 +174,7 @@ export async function liquidateVaultInstruction(
191
174
  payerAssociatedTokenAccount: payerAssociatedTokenAccount,
192
175
  feePool: feePool,
193
176
  feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
194
- feePoolAssociatedUshTokenAccount:
195
- hedgeStakingPoolAssociatedUshTokenAccount,
177
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
196
178
  liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
197
179
  newEra: newEraPublicKey,
198
180
  oldSmallerVaultInfo: oldSmallerPublicKey,
@@ -202,11 +184,6 @@ export async function liquidateVaultInstruction(
202
184
  systemProgram: SystemProgram.programId,
203
185
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
204
186
  rent: SYSVAR_RENT_PUBKEY,
205
- },
206
- signers: [],
207
- }
208
- return program.instruction.liquidateVault(
209
- new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
210
- payload
211
- )
187
+ })
188
+ .instruction()
212
189
  }
@@ -1,8 +1,5 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import {
3
- getOrCreateAssociatedTokenAccount,
4
- TOKEN_PROGRAM_ID,
5
- } from '@solana/spl-token'
2
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
6
3
  import {
7
4
  Keypair,
8
5
  PublicKey,
@@ -21,9 +18,10 @@ import {
21
18
  getUshMintPublicKey,
22
19
  getVaultSystemStatePublicKey,
23
20
  } from '../Constants'
21
+ import { Vault } from 'idl/vault'
24
22
 
25
23
  export async function loanVault(
26
- program: Program,
24
+ program: Program<Vault>,
27
25
  provider: Provider,
28
26
  payer: Signer,
29
27
  vaultPublicKey: PublicKey,
@@ -40,20 +38,15 @@ export async function loanVault(
40
38
  )
41
39
 
42
40
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
43
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
44
- vaultAccount.collateralType
45
- )
46
- const vaultTypeAccount = await program.account.vaultType.fetch(
47
- vaultTypeAccountPublicKey
41
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
42
+ const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
43
+ const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
44
+ provider.connection,
45
+ payer,
46
+ vaultTypeAccount.collateralMint,
47
+ vaultTypeAccountPublicKey,
48
+ true
48
49
  )
49
- const vaultTypeAssociatedTokenAccount =
50
- await getOrCreateAssociatedTokenAccount(
51
- provider.connection,
52
- payer,
53
- vaultTypeAccount.collateralMint,
54
- vaultTypeAccountPublicKey,
55
- true
56
- )
57
50
  const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
58
51
  provider.connection,
59
52
  payer,
@@ -62,17 +55,16 @@ export async function loanVault(
62
55
  true
63
56
  )
64
57
 
65
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
66
- await getLinkedListAccounts(
67
- program,
68
- provider,
69
- vaultTypeAccountPublicKey,
70
- vaultPublicKey,
71
- 0,
72
- loanAmount,
73
- false,
74
- false
75
- )
58
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
59
+ program,
60
+ provider,
61
+ vaultTypeAccountPublicKey,
62
+ vaultPublicKey,
63
+ 0,
64
+ loanAmount,
65
+ false,
66
+ false
67
+ )
76
68
 
77
69
  const history = Keypair.generate()
78
70
  const transaction = new Transaction().add(
@@ -92,17 +84,12 @@ export async function loanVault(
92
84
  overrideTime
93
85
  )
94
86
  )
95
- await sendAndConfirmTransaction(
96
- provider.connection,
97
- transaction,
98
- [payer, history],
99
- provider.opts
100
- )
87
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
101
88
  return vaultPublicKey
102
89
  }
103
90
 
104
91
  export async function loanVaultInstruction(
105
- program: Program,
92
+ program: Program<Vault>,
106
93
  payerPublicKey: PublicKey,
107
94
  ownerUshAccount: PublicKey,
108
95
  vaultPublickey: PublicKey,
@@ -119,39 +106,34 @@ export async function loanVaultInstruction(
119
106
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
120
107
  const ushMintPublickey = await getUshMintPublicKey()
121
108
  const hedgeMintPublickey = await getHedgeMintPublicKey()
122
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
123
- hedgeMintPublickey
109
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
110
+ const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
111
+ hedgeStakingPoolPublicKey,
112
+ ushMintPublickey
124
113
  )
125
- const hedgeStakingPoolAssociatedUshTokenAccount =
126
- await findAssociatedTokenAddress(
127
- hedgeStakingPoolPublicKey,
128
- ushMintPublickey
129
- )
130
114
 
131
- return program.instruction.loanVault(
132
- new BN(loanAmount),
133
- new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
134
- {
135
- accounts: {
136
- vaultSystemState: vaultSystemStatePublicKey,
137
- vaultTypeAccount: vaultTypeAccount,
138
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
139
- vaultAccount: vaultPublickey,
140
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
141
- history: historyPublicKey,
142
- feePool: hedgeStakingPoolPublicKey,
143
- feePoolAssociatedUshTokenAccount:
144
- hedgeStakingPoolAssociatedUshTokenAccount,
145
- ushMint: ushMintPublickey,
146
- vaultOwner: payerPublicKey,
147
- ownerUshAccount: ownerUshAccount,
148
- oldSmallerVaultInfo: oldSmallerPublicKey,
149
- newSmallerVaultInfo: newSmallerPublicKey,
150
- newLargerVaultInfo: newLargerPublicKey,
151
- tokenProgram: TOKEN_PROGRAM_ID,
152
- systemProgram: SystemProgram.programId,
153
- },
154
- signers: [],
155
- }
156
- )
115
+ return program.methods
116
+ .loanVault(
117
+ new BN(loanAmount),
118
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
119
+ )
120
+ .accounts({
121
+ vaultSystemState: vaultSystemStatePublicKey,
122
+ vaultTypeAccount: vaultTypeAccount,
123
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
124
+ vaultAccount: vaultPublickey,
125
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
126
+ history: historyPublicKey,
127
+ feePool: hedgeStakingPoolPublicKey,
128
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
129
+ ushMint: ushMintPublickey,
130
+ vaultOwner: payerPublicKey,
131
+ ownerUshAccount: ownerUshAccount,
132
+ oldSmallerVaultInfo: oldSmallerPublicKey,
133
+ newSmallerVaultInfo: newSmallerPublicKey,
134
+ newLargerVaultInfo: newLargerPublicKey,
135
+ tokenProgram: TOKEN_PROGRAM_ID,
136
+ systemProgram: SystemProgram.programId,
137
+ })
138
+ .instruction()
157
139
  }
@@ -1,12 +1,28 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  // import { TokenInstructions } from '@project-serum/serum'
4
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import {
5
+ Keypair,
6
+ PublicKey,
7
+ sendAndConfirmTransaction,
8
+ Signer,
9
+ SystemProgram,
10
+ Transaction,
11
+ TransactionInstruction,
12
+ } from '@solana/web3.js'
5
13
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
6
- import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
14
+ import {
15
+ findAssociatedTokenAddress,
16
+ getHedgeMintPublicKey,
17
+ getPoolPublicKeyForMint,
18
+ getVaultTypeAccountPublicKey,
19
+ getUshMintPublicKey,
20
+ getVaultSystemStatePublicKey,
21
+ } from '../Constants'
22
+ import { Vault } from 'idl/vault'
7
23
 
8
- export async function redeemVault (
9
- program: Program,
24
+ export async function redeemVault(
25
+ program: Program<Vault>,
10
26
  provider: Provider,
11
27
  payer: Signer,
12
28
  vaultPublicKey: PublicKey,
@@ -16,29 +32,49 @@ export async function redeemVault (
16
32
  const ushMintPublickey = await getUshMintPublicKey()
17
33
 
18
34
  // Prep the user to get USH back out at some point
19
- const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
35
+ const payerUshAccount = await getOrCreateAssociatedTokenAccount(
36
+ provider.connection,
37
+ payer,
38
+ ushMintPublickey,
39
+ payer.publicKey
40
+ )
20
41
 
21
42
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
22
43
  const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
23
44
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
24
- const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true)
25
-
26
- const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true)
45
+ const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
46
+ provider.connection,
47
+ payer,
48
+ vaultTypeAccountInfo.collateralMint,
49
+ vaultTypeAccountPublicKey,
50
+ true
51
+ )
27
52
 
28
- const payerTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey)
53
+ const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
54
+ provider.connection,
55
+ payer,
56
+ vaultTypeAccountInfo.collateralMint,
57
+ vaultPublicKey,
58
+ true
59
+ )
29
60
 
61
+ const payerTokenAccount = await getOrCreateAssociatedTokenAccount(
62
+ provider.connection,
63
+ payer,
64
+ vaultTypeAccountInfo.collateralMint,
65
+ payer.publicKey
66
+ )
30
67
 
31
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
32
- await getLinkedListAccounts(
33
- program,
34
- provider,
35
- vaultTypeAccountPublicKey,
36
- vaultPublicKey,
37
- 0,
38
- 0,
39
- true,
40
- false
41
- )
68
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
+ program,
70
+ provider,
71
+ vaultTypeAccountPublicKey,
72
+ vaultPublicKey,
73
+ 0,
74
+ 0,
75
+ true,
76
+ false
77
+ )
42
78
 
43
79
  const history = Keypair.generate()
44
80
  const transaction = new Transaction().add(
@@ -59,12 +95,12 @@ export async function redeemVault (
59
95
  transactionOverrideTime
60
96
  )
61
97
  )
62
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
98
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
63
99
  return vaultPublicKey
64
100
  }
65
101
 
66
- export async function redeemVaultInstruction (
67
- program: Program,
102
+ export async function redeemVaultInstruction(
103
+ program: Program<Vault>,
68
104
  payerPublicKey: PublicKey,
69
105
  payerUshAccount: PublicKey,
70
106
  destinationTokenAccount: PublicKey,
@@ -87,29 +123,29 @@ export async function redeemVaultInstruction (
87
123
  hedgeStakingPoolPublicKey,
88
124
  ushMintPublickey
89
125
  )
90
- return program.instruction.redeemVault(
91
- new BN(redeemAmount),
92
- new BN(transactionOverrideTime ?? (Date.now() / 1000)), // override start time
93
- {
94
- accounts: {
95
- vaultSystemState: vaultSystemStatePublicKey,
96
- vaultTypeAccount: vaultTypeAccount,
97
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
98
- vault: vaultPublickey,
99
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
100
- history: historyPublicKey,
101
- feePool: hedgeStakingPoolPublicKey,
102
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
103
- ushMint: ushMintPublickey,
104
- payer: payerPublicKey,
105
- payerUshAccount: payerUshAccount,
106
- destinationTokenAccount: destinationTokenAccount,
107
- oldSmallerVaultInfo: oldSmallerPublicKey,
108
- newSmallerVaultInfo: newSmallerPublicKey,
109
- newLargerVaultInfo: newLargerPublicKey,
110
- tokenProgram: TOKEN_PROGRAM_ID,
111
- systemProgram: SystemProgram.programId
112
- },
113
- signers: []
126
+ return await program.methods
127
+ .redeemVault(
128
+ new BN(redeemAmount),
129
+ new BN(transactionOverrideTime ?? Date.now() / 1000) // override start time
130
+ )
131
+ .accounts({
132
+ vaultSystemState: vaultSystemStatePublicKey,
133
+ vaultTypeAccount: vaultTypeAccount,
134
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
135
+ vault: vaultPublickey,
136
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
137
+ history: historyPublicKey,
138
+ feePool: hedgeStakingPoolPublicKey,
139
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
140
+ ushMint: ushMintPublickey,
141
+ payer: payerPublicKey,
142
+ payerUshAccount: payerUshAccount,
143
+ destinationTokenAccount: destinationTokenAccount,
144
+ oldSmallerVaultInfo: oldSmallerPublicKey,
145
+ newSmallerVaultInfo: newSmallerPublicKey,
146
+ newLargerVaultInfo: newLargerPublicKey,
147
+ tokenProgram: TOKEN_PROGRAM_ID,
148
+ systemProgram: SystemProgram.programId,
114
149
  })
150
+ .instruction()
115
151
  }
@@ -1,9 +1,18 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { LAMPORTS_PER_SOL, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
2
+ import {
3
+ LAMPORTS_PER_SOL,
4
+ PublicKey,
5
+ sendAndConfirmTransaction,
6
+ Signer,
7
+ SystemProgram,
8
+ Transaction,
9
+ TransactionInstruction,
10
+ } from '@solana/web3.js'
11
+ import { Vault } from 'idl/vault'
3
12
  import { HEDGE_PROGRAM_PUBLICKEY } from '../Constants'
4
13
 
5
- export async function refreshOraclePrice (
6
- program: Program,
14
+ export async function refreshOraclePrice(
15
+ program: Program<Vault>,
7
16
  provider: Provider,
8
17
  payer: Signer,
9
18
  collateralType: string,
@@ -12,63 +21,63 @@ export async function refreshOraclePrice (
12
21
  overrideTime?: number
13
22
  ): Promise<string> {
14
23
  const transaction = new Transaction().add(
15
- await refreshOraclePriceInstruction(
16
- program,
17
- collateralType,
18
- network,
19
- overridePrice,
20
- overrideTime
21
- )
24
+ await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime)
22
25
  )
23
- return await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts)
26
+ return await sendAndConfirmTransaction(provider.connection, transaction, [payer])
24
27
  }
25
28
 
26
- export async function refreshOraclePriceInstruction (
27
- program: Program,
29
+ export async function refreshOraclePriceInstruction(
30
+ program: Program<Vault>,
28
31
  collateralType: string,
29
32
  network: Cluster,
30
33
  overridePrice?: number,
31
34
  overrideTime?: number
32
35
  ): Promise<TransactionInstruction> {
33
36
  const enc = new TextEncoder()
34
- const [oracleInfoAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY)
35
- const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
37
+ const [oracleInfoAccount] = await PublicKey.findProgramAddress(
38
+ [enc.encode(collateralType), enc.encode('Oracle')],
39
+ HEDGE_PROGRAM_PUBLICKEY
40
+ )
41
+ const [vaultTypeAccount] = await PublicKey.findProgramAddress(
42
+ [enc.encode(collateralType), enc.encode('State')],
43
+ HEDGE_PROGRAM_PUBLICKEY
44
+ )
36
45
 
37
- return program.instruction.refreshOraclePrice(
38
- new BN(overridePrice ?? LAMPORTS_PER_SOL * 150), // override usd/sol price
39
- new BN(overrideTime ?? Math.floor(Date.now() / 1000)-1), // override override time
40
- {
41
- accounts: {
42
- oracleInfoAccount: oracleInfoAccount,
43
- vaultTypeAccount: vaultTypeAccount,
44
- oracleChainlink: chainlinkAccunts[network],
45
- oraclePyth: pythAccounts[network],
46
- oracleSwitchboard: switchboardAccounts[network],
47
- systemProgram: SystemProgram.programId
48
- },
49
- signers: []
46
+ return await program.methods
47
+ .refreshOraclePrice(
48
+ new BN(overridePrice ?? LAMPORTS_PER_SOL * 150), // override usd/sol price
49
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000) - 1) // override override time
50
+ )
51
+ .accounts({
52
+ oracleInfoAccount: oracleInfoAccount,
53
+ vaultTypeAccount: vaultTypeAccount,
54
+ oracleChainlink: chainlinkAccunts[network],
55
+ oraclePyth: pythAccounts[network],
56
+ oracleSwitchboard: switchboardAccounts[network],
57
+ systemProgram: SystemProgram.programId,
50
58
  })
59
+ .instruction()
51
60
  }
52
61
 
53
62
  enum Cluster {
54
63
  Testing = 'Testing',
55
64
  Devnet = 'Devnet',
56
- MainnetBeta = 'MainnetBeta'
65
+ MainnetBeta = 'MainnetBeta',
57
66
  }
58
67
 
59
68
  const pythAccounts = {
60
69
  Testing: SystemProgram.programId,
61
70
  Devnet: new PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
62
- MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
71
+ MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
63
72
  }
64
73
  const chainlinkAccunts = {
65
74
  Testing: SystemProgram.programId,
66
75
  Devnet: new PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
67
- MainnetBeta: SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
76
+ MainnetBeta: SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
68
77
  }
69
78
  const switchboardAccounts = {
70
79
  Testing: SystemProgram.programId,
71
80
  // Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
72
81
  Devnet: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
73
- MainnetBeta: SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
82
+ MainnetBeta: SystemProgram.programId, // Switchboard V2 NOT ON MAINNET YET
74
83
  }