hedge-web3 0.1.44 → 0.1.50
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.
- package/declarations/Constants.d.ts +1 -1
- package/declarations/idl/vault.d.ts +5 -26
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +5 -7
- package/lib/Constants.js +1 -1
- package/lib/idl/vault.js +5 -26
- package/lib/instructions/createStakingPool.js +0 -1
- package/lib/instructions/depositVault.js +7 -7
- package/lib/instructions/liquidateVault.js +7 -5
- package/lib/instructions/loanVault.js +6 -7
- package/lib/instructions/redeemVault.js +5 -4
- package/lib/instructions/refreshOraclePrice.js +2 -2
- package/lib/instructions/repayVault.js +5 -4
- package/lib/instructions/withdrawVault.js +5 -4
- package/lib/state/VaultAccount.js +26 -20
- package/lib/utils/getLinkedListAccounts.js +22 -19
- package/package.json +1 -1
- package/src/Constants.ts +1 -1
- package/src/idl/vault.ts +10 -52
- package/src/instructions/createStakingPool.ts +0 -1
- package/src/instructions/depositVault.ts +8 -8
- package/src/instructions/liquidateVault.ts +7 -5
- package/src/instructions/loanVault.ts +8 -11
- package/src/instructions/redeemVault.ts +5 -4
- package/src/instructions/refreshOraclePrice.ts +2 -2
- package/src/instructions/repayVault.ts +5 -4
- package/src/instructions/withdrawVault.ts +5 -4
- package/src/state/VaultAccount.ts +25 -25
- package/src/utils/getLinkedListAccounts.ts +24 -20
@@ -21,14 +21,13 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
21
21
|
const bs58_1 = __importDefault(require("bs58"));
|
22
22
|
function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, loanAmount, redeem, liquidate, cachedVaults) {
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
|
24
|
+
console.log('Getting getLinkedListAccounts');
|
25
25
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
26
26
|
// Default for null is the vault itself, so set them all to this vault
|
27
27
|
let oldSmallerPublicKey = vaultPublicKey;
|
28
28
|
let newSmallerPublicKey = vaultPublicKey;
|
29
29
|
let newLargerPublicKey = vaultPublicKey;
|
30
30
|
const thisVaultData = yield program.account.vault.fetch(vaultPublicKey);
|
31
|
-
const accountInfo = yield program.provider.connection.getAccountInfo(vaultPublicKey);
|
32
31
|
const thisVault = new VaultAccount_1.VaultAccount(thisVaultData, vaultPublicKey);
|
33
32
|
// Load all the vaults
|
34
33
|
let vaults;
|
@@ -51,10 +50,10 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
51
50
|
// vaults = allVaults.map((vault) => {
|
52
51
|
// return new VaultAccount(vault.account, vault.publicKey)
|
53
52
|
// })
|
54
|
-
vaults = yield getMiniVaults(program, vaultTypeAccount.
|
53
|
+
vaults = yield getMiniVaults(program, vaultTypeAccount.collateralType);
|
55
54
|
}
|
56
|
-
|
57
|
-
|
55
|
+
console.log('Vault count found:', vaults.length);
|
56
|
+
console.log('First Vault', vaults[0]);
|
58
57
|
// Filter out the accounts that are not open
|
59
58
|
// TODO filter on vault status. Or we enable people to "close out" empty vaults
|
60
59
|
// vaults = _.filter(vaults, (vault) => {
|
@@ -62,7 +61,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
62
61
|
// })
|
63
62
|
// Remove any vaults with no debt or collateral
|
64
63
|
vaults = underscore_1.default.filter(vaults, (vault) => {
|
65
|
-
return vault.denormalizedDebt
|
64
|
+
return vault.denormalizedDebt.greaterThan(0) && vault.deposited.greaterThan(0);
|
66
65
|
});
|
67
66
|
// Sort them
|
68
67
|
vaults.sort(sortVaults);
|
@@ -77,11 +76,6 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
77
76
|
if (indexBefore > 0) {
|
78
77
|
oldSmallerPublicKey = vaults[indexBefore - 1].publicKey;
|
79
78
|
}
|
80
|
-
// Pretty print the list again
|
81
|
-
// console.log('Sorted open vaults. Index Before: ', indexBefore)
|
82
|
-
// console.log(vaults.map((vault) => {
|
83
|
-
// return vault.toString(vaultPublicKey)
|
84
|
-
// }))
|
85
79
|
// Pretty print all the vaults before the operation
|
86
80
|
// console.log('Sorted open vaults BEFORE at index:', indexBefore)
|
87
81
|
// let correctOrderBefore = true
|
@@ -122,11 +116,16 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
122
116
|
if (redeem) {
|
123
117
|
vaults[indexBefore].redeem();
|
124
118
|
}
|
125
|
-
if (vaults[indexBefore].denormalizedDebt
|
119
|
+
if (vaults[indexBefore].denormalizedDebt.isZero()) {
|
126
120
|
vaults.splice(indexBefore, 1);
|
127
121
|
}
|
128
122
|
// Sort it again since we've changed one vault
|
129
123
|
vaults = vaults.sort(sortVaults);
|
124
|
+
// Pretty print the list again
|
125
|
+
// console.log('Sorted open vaults with new debt added at index: ', indexAfter)
|
126
|
+
// console.log(vaults.map((vault) => {
|
127
|
+
// return vault.toString(vaultPublicKey)
|
128
|
+
// }))
|
130
129
|
// Search for the vaults new position
|
131
130
|
let indexAfter = -1;
|
132
131
|
vaults.forEach((vault, index) => {
|
@@ -142,7 +141,8 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
142
141
|
// })
|
143
142
|
// )
|
144
143
|
// Print where it moved from / to
|
145
|
-
|
144
|
+
console.log('Index Before', indexBefore);
|
145
|
+
console.log('Index After', indexAfter);
|
146
146
|
// Save references to the new left and right
|
147
147
|
if (indexAfter > 0) {
|
148
148
|
newSmallerPublicKey = vaults[indexAfter - 1].publicKey;
|
@@ -161,14 +161,17 @@ exports.getLinkedListAccounts = getLinkedListAccounts;
|
|
161
161
|
// Sort function we can use to sort the vaults
|
162
162
|
// Sorted by collateral ratio. If two are the same, newer vault first
|
163
163
|
function sortVaults(a, b) {
|
164
|
-
const aRatio = a.deposited
|
165
|
-
const bRatio = b.deposited
|
166
|
-
if (aRatio
|
164
|
+
const aRatio = a.deposited.floor().div(a.denormalizedDebt.floor());
|
165
|
+
const bRatio = b.deposited.floor().div(b.denormalizedDebt.floor());
|
166
|
+
if (aRatio.equals(bRatio)) {
|
167
167
|
return b.vaultNumber - a.vaultNumber;
|
168
168
|
}
|
169
|
-
|
169
|
+
if (aRatio.greaterThan(bRatio)) {
|
170
|
+
return 1;
|
171
|
+
}
|
172
|
+
return -1;
|
170
173
|
}
|
171
|
-
function getMiniVaults(program,
|
174
|
+
function getMiniVaults(program, collateralType) {
|
172
175
|
return __awaiter(this, void 0, void 0, function* () {
|
173
176
|
const filters = [
|
174
177
|
// Filter for Vault Accounts
|
@@ -179,7 +182,7 @@ function getMiniVaults(program, vaultTypeName) {
|
|
179
182
|
// Filter for Vaults with this collateral type
|
180
183
|
{
|
181
184
|
memcmp: {
|
182
|
-
bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(
|
185
|
+
bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(collateralType)),
|
183
186
|
offset: 8 + 32 + 24,
|
184
187
|
},
|
185
188
|
},
|
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
} from '@solana/spl-token'
|
5
5
|
import { PublicKey } from '@solana/web3.js'
|
6
6
|
|
7
|
-
export const HEDGE_PROGRAM_ID = '
|
7
|
+
export const HEDGE_PROGRAM_ID = 'HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ'
|
8
8
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
9
9
|
|
10
10
|
export const CHAINLINK_SOL_USD_ID =
|
package/src/idl/vault.ts
CHANGED
@@ -1844,7 +1844,7 @@ export type Vault = {
|
|
1844
1844
|
"kind": "struct",
|
1845
1845
|
"fields": [
|
1846
1846
|
{
|
1847
|
-
"name": "
|
1847
|
+
"name": "collateralType",
|
1848
1848
|
"type": "string"
|
1849
1849
|
},
|
1850
1850
|
{
|
@@ -1858,10 +1858,6 @@ export type Vault = {
|
|
1858
1858
|
{
|
1859
1859
|
"name": "oracleSwitchboard",
|
1860
1860
|
"type": "publicKey"
|
1861
|
-
},
|
1862
|
-
{
|
1863
|
-
"name": "vaultType",
|
1864
|
-
"type": "publicKey"
|
1865
1861
|
}
|
1866
1862
|
]
|
1867
1863
|
}
|
@@ -2106,7 +2102,7 @@ export type Vault = {
|
|
2106
2102
|
"kind": "struct",
|
2107
2103
|
"fields": [
|
2108
2104
|
{
|
2109
|
-
"name": "
|
2105
|
+
"name": "collateralType",
|
2110
2106
|
"type": "string"
|
2111
2107
|
},
|
2112
2108
|
{
|
@@ -2190,14 +2186,6 @@ export type Vault = {
|
|
2190
2186
|
{
|
2191
2187
|
"name": "deprecated",
|
2192
2188
|
"type": "bool"
|
2193
|
-
},
|
2194
|
-
{
|
2195
|
-
"name": "totalFeesAccumulatedUsh",
|
2196
|
-
"type": "u128"
|
2197
|
-
},
|
2198
|
-
{
|
2199
|
-
"name": "totalFeesAccumulatedCollateral",
|
2200
|
-
"type": "u128"
|
2201
2189
|
}
|
2202
2190
|
]
|
2203
2191
|
}
|
@@ -2224,7 +2212,7 @@ export type Vault = {
|
|
2224
2212
|
"type": "u64"
|
2225
2213
|
},
|
2226
2214
|
{
|
2227
|
-
"name": "
|
2215
|
+
"name": "collateralType",
|
2228
2216
|
"type": "string"
|
2229
2217
|
},
|
2230
2218
|
{
|
@@ -2272,10 +2260,6 @@ export type Vault = {
|
|
2272
2260
|
"type": {
|
2273
2261
|
"option": "publicKey"
|
2274
2262
|
}
|
2275
|
-
},
|
2276
|
-
{
|
2277
|
-
"name": "vaultType",
|
2278
|
-
"type": "publicKey"
|
2279
2263
|
}
|
2280
2264
|
]
|
2281
2265
|
}
|
@@ -2689,8 +2673,8 @@ export type Vault = {
|
|
2689
2673
|
},
|
2690
2674
|
{
|
2691
2675
|
"code": 6020,
|
2692
|
-
"name": "
|
2693
|
-
"msg": "Can only redeem
|
2676
|
+
"name": "RedeemingNonHighestCollateralRatioVault",
|
2677
|
+
"msg": "Can only redeem highest collateral ratio vault in system."
|
2694
2678
|
},
|
2695
2679
|
{
|
2696
2680
|
"code": 6021,
|
@@ -2704,11 +2688,6 @@ export type Vault = {
|
|
2704
2688
|
},
|
2705
2689
|
{
|
2706
2690
|
"code": 6023,
|
2707
|
-
"name": "InvalidSaltLength",
|
2708
|
-
"msg": "Salt for new vaults must be of length 8"
|
2709
|
-
},
|
2710
|
-
{
|
2711
|
-
"code": 6024,
|
2712
2691
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2713
2692
|
"msg": "New Max debt extended value is less than the current debt!"
|
2714
2693
|
}
|
@@ -4561,7 +4540,7 @@ export const IDL: Vault = {
|
|
4561
4540
|
"kind": "struct",
|
4562
4541
|
"fields": [
|
4563
4542
|
{
|
4564
|
-
"name": "
|
4543
|
+
"name": "collateralType",
|
4565
4544
|
"type": "string"
|
4566
4545
|
},
|
4567
4546
|
{
|
@@ -4575,10 +4554,6 @@ export const IDL: Vault = {
|
|
4575
4554
|
{
|
4576
4555
|
"name": "oracleSwitchboard",
|
4577
4556
|
"type": "publicKey"
|
4578
|
-
},
|
4579
|
-
{
|
4580
|
-
"name": "vaultType",
|
4581
|
-
"type": "publicKey"
|
4582
4557
|
}
|
4583
4558
|
]
|
4584
4559
|
}
|
@@ -4823,7 +4798,7 @@ export const IDL: Vault = {
|
|
4823
4798
|
"kind": "struct",
|
4824
4799
|
"fields": [
|
4825
4800
|
{
|
4826
|
-
"name": "
|
4801
|
+
"name": "collateralType",
|
4827
4802
|
"type": "string"
|
4828
4803
|
},
|
4829
4804
|
{
|
@@ -4907,14 +4882,6 @@ export const IDL: Vault = {
|
|
4907
4882
|
{
|
4908
4883
|
"name": "deprecated",
|
4909
4884
|
"type": "bool"
|
4910
|
-
},
|
4911
|
-
{
|
4912
|
-
"name": "totalFeesAccumulatedUsh",
|
4913
|
-
"type": "u128"
|
4914
|
-
},
|
4915
|
-
{
|
4916
|
-
"name": "totalFeesAccumulatedCollateral",
|
4917
|
-
"type": "u128"
|
4918
4885
|
}
|
4919
4886
|
]
|
4920
4887
|
}
|
@@ -4941,7 +4908,7 @@ export const IDL: Vault = {
|
|
4941
4908
|
"type": "u64"
|
4942
4909
|
},
|
4943
4910
|
{
|
4944
|
-
"name": "
|
4911
|
+
"name": "collateralType",
|
4945
4912
|
"type": "string"
|
4946
4913
|
},
|
4947
4914
|
{
|
@@ -4989,10 +4956,6 @@ export const IDL: Vault = {
|
|
4989
4956
|
"type": {
|
4990
4957
|
"option": "publicKey"
|
4991
4958
|
}
|
4992
|
-
},
|
4993
|
-
{
|
4994
|
-
"name": "vaultType",
|
4995
|
-
"type": "publicKey"
|
4996
4959
|
}
|
4997
4960
|
]
|
4998
4961
|
}
|
@@ -5406,8 +5369,8 @@ export const IDL: Vault = {
|
|
5406
5369
|
},
|
5407
5370
|
{
|
5408
5371
|
"code": 6020,
|
5409
|
-
"name": "
|
5410
|
-
"msg": "Can only redeem
|
5372
|
+
"name": "RedeemingNonHighestCollateralRatioVault",
|
5373
|
+
"msg": "Can only redeem highest collateral ratio vault in system."
|
5411
5374
|
},
|
5412
5375
|
{
|
5413
5376
|
"code": 6021,
|
@@ -5421,11 +5384,6 @@ export const IDL: Vault = {
|
|
5421
5384
|
},
|
5422
5385
|
{
|
5423
5386
|
"code": 6023,
|
5424
|
-
"name": "InvalidSaltLength",
|
5425
|
-
"msg": "Salt for new vaults must be of length 8"
|
5426
|
-
},
|
5427
|
-
{
|
5428
|
-
"code": 6024,
|
5429
5387
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
5430
5388
|
"msg": "New Max debt extended value is less than the current debt!"
|
5431
5389
|
}
|
@@ -41,7 +41,6 @@ export async function createStakingPoolInstruction(
|
|
41
41
|
hedgeTokensToBeMinted: number,
|
42
42
|
overrideStartTime?: number
|
43
43
|
): Promise<TransactionInstruction> {
|
44
|
-
console.log("new createStakingPoolInstruction")
|
45
44
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
46
45
|
const ushMintPublickey = await getUshMintPublicKey()
|
47
46
|
const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
|
@@ -20,7 +20,6 @@ import {
|
|
20
20
|
getHedgeMintPublicKey,
|
21
21
|
} from '../Constants'
|
22
22
|
import { Vault } from 'idl/vault'
|
23
|
-
import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
|
24
23
|
|
25
24
|
export async function depositVault(
|
26
25
|
program: Program<Vault>,
|
@@ -36,12 +35,13 @@ export async function depositVault(
|
|
36
35
|
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
37
36
|
|
38
37
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
39
|
-
const
|
38
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
39
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
40
40
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
41
41
|
provider.connection,
|
42
42
|
payer,
|
43
43
|
vaultTypeAccountInfo.collateralMint,
|
44
|
-
|
44
|
+
vaultTypeAccountPublicKey,
|
45
45
|
true
|
46
46
|
)
|
47
47
|
|
@@ -68,7 +68,7 @@ export async function depositVault(
|
|
68
68
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
69
69
|
program,
|
70
70
|
provider,
|
71
|
-
|
71
|
+
vaultTypeAccountPublicKey,
|
72
72
|
vaultPublicKey,
|
73
73
|
depositAmount,
|
74
74
|
0,
|
@@ -76,7 +76,7 @@ export async function depositVault(
|
|
76
76
|
false
|
77
77
|
)
|
78
78
|
|
79
|
-
if (
|
79
|
+
if (vaultAccount.collateralType === 'SOL') {
|
80
80
|
transaction.add(
|
81
81
|
SystemProgram.createAccount({
|
82
82
|
fromPubkey: payer.publicKey,
|
@@ -98,11 +98,11 @@ export async function depositVault(
|
|
98
98
|
program,
|
99
99
|
vaultSystemStatePublicKey,
|
100
100
|
payer.publicKey,
|
101
|
-
|
101
|
+
vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
|
102
102
|
vaultPublicKey,
|
103
103
|
vaultAssociatedCollateralAccountPublicKey,
|
104
104
|
history.publicKey,
|
105
|
-
|
105
|
+
vaultTypeAccountPublicKey,
|
106
106
|
vaultTypeAssociatedTokenAccount.address,
|
107
107
|
hedgeStakingPoolPublicKey,
|
108
108
|
hedgeStakingPoolAssociatedUshTokenAccount,
|
@@ -115,7 +115,7 @@ export async function depositVault(
|
|
115
115
|
overrideTime
|
116
116
|
)
|
117
117
|
)
|
118
|
-
if (
|
118
|
+
if (vaultAccount.collateralType === 'SOL') {
|
119
119
|
transaction.add(
|
120
120
|
TokenInstructions.closeAccount({
|
121
121
|
source: wrappedSolAccount.publicKey,
|
@@ -31,7 +31,8 @@ export async function liquidateVault(
|
|
31
31
|
): Promise<PublicKey> {
|
32
32
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
33
33
|
|
34
|
-
const
|
34
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
35
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
35
36
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
36
37
|
|
37
38
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
@@ -72,7 +73,7 @@ export async function liquidateVault(
|
|
72
73
|
provider.connection,
|
73
74
|
payer,
|
74
75
|
collateralMint,
|
75
|
-
|
76
|
+
vaultTypeAccountPublicKey,
|
76
77
|
true
|
77
78
|
)
|
78
79
|
const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -86,7 +87,7 @@ export async function liquidateVault(
|
|
86
87
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
87
88
|
program,
|
88
89
|
provider,
|
89
|
-
|
90
|
+
vaultTypeAccountPublicKey,
|
90
91
|
vaultPublicKey,
|
91
92
|
0,
|
92
93
|
0,
|
@@ -118,7 +119,7 @@ export async function liquidateVault(
|
|
118
119
|
oldSmallerPublicKey,
|
119
120
|
newSmallerPublicKey,
|
120
121
|
newLargerPublicKey,
|
121
|
-
vaultAccount.
|
122
|
+
vaultAccount.collateralType,
|
122
123
|
overrideTime
|
123
124
|
)
|
124
125
|
)
|
@@ -145,12 +146,13 @@ export async function liquidateVaultInstruction(
|
|
145
146
|
oldSmallerPublicKey: PublicKey,
|
146
147
|
newSmallerPublicKey: PublicKey,
|
147
148
|
newLargerPublicKey: PublicKey,
|
148
|
-
|
149
|
+
collateralType: string,
|
149
150
|
overrideTime?: number
|
150
151
|
): Promise<TransactionInstruction> {
|
151
152
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
152
153
|
const ushMintPublickey = await getUshMintPublicKey()
|
153
154
|
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
|
155
|
+
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
154
156
|
|
155
157
|
return await program.methods
|
156
158
|
.liquidateVault(
|
@@ -17,13 +17,8 @@ import {
|
|
17
17
|
getVaultTypeAccountPublicKey,
|
18
18
|
getUshMintPublicKey,
|
19
19
|
getVaultSystemStatePublicKey,
|
20
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
21
20
|
} from '../Constants'
|
22
21
|
import { Vault } from 'idl/vault'
|
23
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
24
|
-
import { VaultAccount } from '../state/VaultAccount'
|
25
|
-
|
26
|
-
const fs = require('fs');
|
27
22
|
|
28
23
|
export async function loanVault(
|
29
24
|
program: Program<Vault>,
|
@@ -41,14 +36,15 @@ export async function loanVault(
|
|
41
36
|
ushMintPublickey,
|
42
37
|
payer.publicKey
|
43
38
|
)
|
44
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
45
|
-
const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
46
39
|
|
40
|
+
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
41
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
42
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
47
43
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
48
44
|
provider.connection,
|
49
45
|
payer,
|
50
46
|
vaultTypeAccount.collateralMint,
|
51
|
-
|
47
|
+
vaultTypeAccountPublicKey,
|
52
48
|
true
|
53
49
|
)
|
54
50
|
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -58,10 +54,11 @@ export async function loanVault(
|
|
58
54
|
vaultPublicKey,
|
59
55
|
true
|
60
56
|
)
|
57
|
+
|
61
58
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
62
59
|
program,
|
63
60
|
provider,
|
64
|
-
|
61
|
+
vaultTypeAccountPublicKey,
|
65
62
|
vaultPublicKey,
|
66
63
|
0,
|
67
64
|
loanAmount,
|
@@ -78,7 +75,7 @@ export async function loanVault(
|
|
78
75
|
vaultPublicKey,
|
79
76
|
vaultAssociatedTokenAccount.address,
|
80
77
|
history.publicKey,
|
81
|
-
|
78
|
+
vaultTypeAccountPublicKey,
|
82
79
|
vaultTypeAssociatedTokenAccount.address,
|
83
80
|
oldSmallerPublicKey,
|
84
81
|
newSmallerPublicKey,
|
@@ -87,7 +84,7 @@ export async function loanVault(
|
|
87
84
|
overrideTime
|
88
85
|
)
|
89
86
|
)
|
90
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
|
87
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
|
91
88
|
return vaultPublicKey
|
92
89
|
}
|
93
90
|
|
@@ -40,12 +40,13 @@ export async function redeemVault(
|
|
40
40
|
)
|
41
41
|
|
42
42
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
43
|
-
const
|
43
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
44
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
44
45
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
45
46
|
provider.connection,
|
46
47
|
payer,
|
47
48
|
vaultTypeAccountInfo.collateralMint,
|
48
|
-
|
49
|
+
vaultTypeAccountPublicKey,
|
49
50
|
true
|
50
51
|
)
|
51
52
|
|
@@ -67,7 +68,7 @@ export async function redeemVault(
|
|
67
68
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
68
69
|
program,
|
69
70
|
provider,
|
70
|
-
|
71
|
+
vaultTypeAccountPublicKey,
|
71
72
|
vaultPublicKey,
|
72
73
|
0,
|
73
74
|
0,
|
@@ -85,7 +86,7 @@ export async function redeemVault(
|
|
85
86
|
vaultPublicKey,
|
86
87
|
vaultAssociatedTokenAccount.address,
|
87
88
|
history.publicKey,
|
88
|
-
|
89
|
+
vaultTypeAccountPublicKey,
|
89
90
|
vaultTypeAssociatedTokenAccount.address,
|
90
91
|
oldSmallerPublicKey,
|
91
92
|
newSmallerPublicKey,
|
@@ -51,7 +51,7 @@ export async function refreshOraclePriceInstruction(
|
|
51
51
|
.accounts({
|
52
52
|
oracleInfoAccount: oracleInfoAccount,
|
53
53
|
vaultTypeAccount: vaultTypeAccount,
|
54
|
-
oracleChainlink:
|
54
|
+
oracleChainlink: chainlinkAccunts[network],
|
55
55
|
oraclePyth: pythAccounts[network],
|
56
56
|
oracleSwitchboard: switchboardAccounts[network],
|
57
57
|
systemProgram: SystemProgram.programId,
|
@@ -70,7 +70,7 @@ const pythAccounts = {
|
|
70
70
|
Devnet: new PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
71
71
|
MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
|
72
72
|
}
|
73
|
-
const
|
73
|
+
const chainlinkAccunts = {
|
74
74
|
Testing: SystemProgram.programId,
|
75
75
|
Devnet: new PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
|
76
76
|
MainnetBeta: SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
|
@@ -39,9 +39,10 @@ export async function repayVault(
|
|
39
39
|
)
|
40
40
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
41
41
|
|
42
|
-
const
|
42
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
43
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
43
44
|
const vaultTypeAssociatedTokenAccount = await findAssociatedTokenAddress(
|
44
|
-
|
45
|
+
vaultTypeAccountPublicKey,
|
45
46
|
vaultTypeAccount.collateralMint
|
46
47
|
)
|
47
48
|
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, vaultTypeAccount.collateralMint)
|
@@ -49,7 +50,7 @@ export async function repayVault(
|
|
49
50
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
50
51
|
program,
|
51
52
|
provider,
|
52
|
-
|
53
|
+
vaultTypeAccountPublicKey,
|
53
54
|
vaultPublicKey,
|
54
55
|
0,
|
55
56
|
repayAmount * -1,
|
@@ -66,7 +67,7 @@ export async function repayVault(
|
|
66
67
|
vaultPublicKey,
|
67
68
|
vaultAssociatedTokenAccount,
|
68
69
|
history.publicKey,
|
69
|
-
|
70
|
+
vaultTypeAccountPublicKey,
|
70
71
|
vaultTypeAssociatedTokenAccount,
|
71
72
|
oldSmallerPublicKey,
|
72
73
|
newSmallerPublicKey,
|
@@ -37,6 +37,7 @@ export async function withdrawVault(
|
|
37
37
|
const history = Keypair.generate()
|
38
38
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
39
39
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
40
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
40
41
|
const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
|
41
42
|
provider.connection,
|
42
43
|
payer,
|
@@ -45,12 +46,12 @@ export async function withdrawVault(
|
|
45
46
|
true
|
46
47
|
)
|
47
48
|
|
48
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(
|
49
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
49
50
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
50
51
|
provider.connection,
|
51
52
|
payer,
|
52
53
|
vaultTypeAccountInfo.collateralMint,
|
53
|
-
|
54
|
+
vaultTypeAccountPublicKey,
|
54
55
|
true
|
55
56
|
)
|
56
57
|
|
@@ -69,7 +70,7 @@ export async function withdrawVault(
|
|
69
70
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
70
71
|
program,
|
71
72
|
provider,
|
72
|
-
|
73
|
+
vaultTypeAccountPublicKey,
|
73
74
|
vaultPublicKey,
|
74
75
|
withdrawAmount * -1,
|
75
76
|
0,
|
@@ -85,7 +86,7 @@ export async function withdrawVault(
|
|
85
86
|
destinationTokenAccount.address,
|
86
87
|
vaultPublicKey,
|
87
88
|
vaultAssociatedCollateralAccount.address,
|
88
|
-
|
89
|
+
vaultTypeAccountPublicKey,
|
89
90
|
vaultTypeAssociatedTokenAccount.address,
|
90
91
|
hedgeStakingPoolPublicKey,
|
91
92
|
hedgeStakingPoolAssociatedUshTokenAccount,
|