hedge-web3 0.1.41 → 0.1.44
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 +154 -8
- package/declarations/index.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/updateVaultType.d.ts +15 -0
- package/declarations/state/VaultAccount.d.ts +8 -6
- package/declarations/state/VaultType.d.ts +24 -0
- package/declarations/utils/Sender.d.ts +2 -0
- package/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -0
- package/lib/Constants.js +1 -1
- package/lib/idl/vault.js +154 -8
- package/lib/index.js +1 -1
- package/lib/instructions/createStakingPool.js +1 -0
- package/lib/instructions/depositVault.js +7 -7
- package/lib/instructions/liquidateVault.js +5 -7
- package/lib/instructions/loanVault.js +7 -6
- package/lib/instructions/redeemVault.js +4 -5
- package/lib/instructions/refreshOraclePrice.js +2 -2
- package/lib/instructions/repayVault.js +4 -5
- package/lib/instructions/updateVaultType.js +47 -0
- package/lib/instructions/withdrawVault.js +4 -5
- package/lib/state/VaultAccount.js +9 -8
- package/lib/state/VaultType.js +32 -0
- package/lib/utils/Errors.js +1 -0
- package/lib/utils/Sender.js +32 -0
- package/lib/utils/getLinkedListAccounts.js +15 -15
- package/lib/utils/sendAndConfirmWithDebug.js +35 -0
- package/package.json +2 -2
- package/src/Constants.ts +1 -1
- package/src/idl/vault.ts +308 -16
- package/src/index.ts +1 -1
- package/src/instructions/createStakingPool.ts +1 -0
- package/src/instructions/depositVault.ts +8 -8
- package/src/instructions/liquidateVault.ts +5 -7
- package/src/instructions/loanVault.ts +11 -8
- package/src/instructions/redeemVault.ts +4 -5
- package/src/instructions/refreshOraclePrice.ts +2 -2
- package/src/instructions/repayVault.ts +4 -5
- package/src/instructions/{setVaultTypeStatus.ts → updateVaultType.ts} +39 -8
- package/src/instructions/withdrawVault.ts +4 -5
- package/src/state/VaultAccount.ts +14 -10
- package/src/utils/Errors.ts +1 -0
- package/src/utils/getLinkedListAccounts.ts +16 -16
package/src/idl/vault.ts
CHANGED
@@ -1560,7 +1560,7 @@ export type Vault = {
|
|
1560
1560
|
]
|
1561
1561
|
},
|
1562
1562
|
{
|
1563
|
-
"name": "
|
1563
|
+
"name": "updateVaultType",
|
1564
1564
|
"accounts": [
|
1565
1565
|
{
|
1566
1566
|
"name": "payer",
|
@@ -1576,12 +1576,77 @@ export type Vault = {
|
|
1576
1576
|
"name": "vaultType",
|
1577
1577
|
"isMut": true,
|
1578
1578
|
"isSigner": false
|
1579
|
+
},
|
1580
|
+
{
|
1581
|
+
"name": "oracleInfoAccount",
|
1582
|
+
"isMut": true,
|
1583
|
+
"isSigner": false
|
1584
|
+
}
|
1585
|
+
],
|
1586
|
+
"args": [
|
1587
|
+
{
|
1588
|
+
"name": "config",
|
1589
|
+
"type": {
|
1590
|
+
"defined": "VaultTypeConfig"
|
1591
|
+
}
|
1592
|
+
}
|
1593
|
+
]
|
1594
|
+
},
|
1595
|
+
{
|
1596
|
+
"name": "fixVaultRedeemPointer",
|
1597
|
+
"accounts": [
|
1598
|
+
{
|
1599
|
+
"name": "payer",
|
1600
|
+
"isMut": true,
|
1601
|
+
"isSigner": true
|
1602
|
+
},
|
1603
|
+
{
|
1604
|
+
"name": "vaultSystemState",
|
1605
|
+
"isMut": true,
|
1606
|
+
"isSigner": false
|
1607
|
+
},
|
1608
|
+
{
|
1609
|
+
"name": "vaultAccount",
|
1610
|
+
"isMut": true,
|
1611
|
+
"isSigner": false
|
1612
|
+
}
|
1613
|
+
],
|
1614
|
+
"args": []
|
1615
|
+
},
|
1616
|
+
{
|
1617
|
+
"name": "adminSetRedeemPointer",
|
1618
|
+
"accounts": [
|
1619
|
+
{
|
1620
|
+
"name": "payer",
|
1621
|
+
"isMut": true,
|
1622
|
+
"isSigner": true
|
1623
|
+
},
|
1624
|
+
{
|
1625
|
+
"name": "vaultSystemState",
|
1626
|
+
"isMut": true,
|
1627
|
+
"isSigner": false
|
1628
|
+
},
|
1629
|
+
{
|
1630
|
+
"name": "vaultAccount",
|
1631
|
+
"isMut": true,
|
1632
|
+
"isSigner": false
|
1633
|
+
},
|
1634
|
+
{
|
1635
|
+
"name": "vaultTypeAccount",
|
1636
|
+
"isMut": true,
|
1637
|
+
"isSigner": false
|
1579
1638
|
}
|
1580
1639
|
],
|
1581
1640
|
"args": [
|
1582
1641
|
{
|
1583
|
-
"name": "
|
1642
|
+
"name": "settingHead",
|
1584
1643
|
"type": "bool"
|
1644
|
+
},
|
1645
|
+
{
|
1646
|
+
"name": "pointerToSet",
|
1647
|
+
"type": {
|
1648
|
+
"option": "publicKey"
|
1649
|
+
}
|
1585
1650
|
}
|
1586
1651
|
]
|
1587
1652
|
}
|
@@ -1779,7 +1844,7 @@ export type Vault = {
|
|
1779
1844
|
"kind": "struct",
|
1780
1845
|
"fields": [
|
1781
1846
|
{
|
1782
|
-
"name": "
|
1847
|
+
"name": "vaultTypeName",
|
1783
1848
|
"type": "string"
|
1784
1849
|
},
|
1785
1850
|
{
|
@@ -1793,6 +1858,10 @@ export type Vault = {
|
|
1793
1858
|
{
|
1794
1859
|
"name": "oracleSwitchboard",
|
1795
1860
|
"type": "publicKey"
|
1861
|
+
},
|
1862
|
+
{
|
1863
|
+
"name": "vaultType",
|
1864
|
+
"type": "publicKey"
|
1796
1865
|
}
|
1797
1866
|
]
|
1798
1867
|
}
|
@@ -1903,7 +1972,7 @@ export type Vault = {
|
|
1903
1972
|
"type": {
|
1904
1973
|
"array": [
|
1905
1974
|
"u8",
|
1906
|
-
|
1975
|
+
16
|
1907
1976
|
]
|
1908
1977
|
}
|
1909
1978
|
},
|
@@ -2037,7 +2106,7 @@ export type Vault = {
|
|
2037
2106
|
"kind": "struct",
|
2038
2107
|
"fields": [
|
2039
2108
|
{
|
2040
|
-
"name": "
|
2109
|
+
"name": "vaultTypeName",
|
2041
2110
|
"type": "string"
|
2042
2111
|
},
|
2043
2112
|
{
|
@@ -2121,6 +2190,14 @@ export type Vault = {
|
|
2121
2190
|
{
|
2122
2191
|
"name": "deprecated",
|
2123
2192
|
"type": "bool"
|
2193
|
+
},
|
2194
|
+
{
|
2195
|
+
"name": "totalFeesAccumulatedUsh",
|
2196
|
+
"type": "u128"
|
2197
|
+
},
|
2198
|
+
{
|
2199
|
+
"name": "totalFeesAccumulatedCollateral",
|
2200
|
+
"type": "u128"
|
2124
2201
|
}
|
2125
2202
|
]
|
2126
2203
|
}
|
@@ -2147,7 +2224,7 @@ export type Vault = {
|
|
2147
2224
|
"type": "u64"
|
2148
2225
|
},
|
2149
2226
|
{
|
2150
|
-
"name": "
|
2227
|
+
"name": "vaultTypeName",
|
2151
2228
|
"type": "string"
|
2152
2229
|
},
|
2153
2230
|
{
|
@@ -2195,6 +2272,10 @@ export type Vault = {
|
|
2195
2272
|
"type": {
|
2196
2273
|
"option": "publicKey"
|
2197
2274
|
}
|
2275
|
+
},
|
2276
|
+
{
|
2277
|
+
"name": "vaultType",
|
2278
|
+
"type": "publicKey"
|
2198
2279
|
}
|
2199
2280
|
]
|
2200
2281
|
}
|
@@ -2243,6 +2324,56 @@ export type Vault = {
|
|
2243
2324
|
]
|
2244
2325
|
}
|
2245
2326
|
},
|
2327
|
+
{
|
2328
|
+
"name": "VaultTypeConfig",
|
2329
|
+
"type": {
|
2330
|
+
"kind": "struct",
|
2331
|
+
"fields": [
|
2332
|
+
{
|
2333
|
+
"name": "maxDebtExtended",
|
2334
|
+
"type": {
|
2335
|
+
"option": "u64"
|
2336
|
+
}
|
2337
|
+
},
|
2338
|
+
{
|
2339
|
+
"name": "minDebtPerVault",
|
2340
|
+
"type": {
|
2341
|
+
"option": "u64"
|
2342
|
+
}
|
2343
|
+
},
|
2344
|
+
{
|
2345
|
+
"name": "loanInitFee",
|
2346
|
+
"type": {
|
2347
|
+
"option": "u64"
|
2348
|
+
}
|
2349
|
+
},
|
2350
|
+
{
|
2351
|
+
"name": "oracleChainlink",
|
2352
|
+
"type": {
|
2353
|
+
"option": "publicKey"
|
2354
|
+
}
|
2355
|
+
},
|
2356
|
+
{
|
2357
|
+
"name": "oraclePyth",
|
2358
|
+
"type": {
|
2359
|
+
"option": "publicKey"
|
2360
|
+
}
|
2361
|
+
},
|
2362
|
+
{
|
2363
|
+
"name": "oracleSwitchboard",
|
2364
|
+
"type": {
|
2365
|
+
"option": "publicKey"
|
2366
|
+
}
|
2367
|
+
},
|
2368
|
+
{
|
2369
|
+
"name": "deprecated",
|
2370
|
+
"type": {
|
2371
|
+
"option": "bool"
|
2372
|
+
}
|
2373
|
+
}
|
2374
|
+
]
|
2375
|
+
}
|
2376
|
+
},
|
2246
2377
|
{
|
2247
2378
|
"name": "PositionState",
|
2248
2379
|
"type": {
|
@@ -2558,13 +2689,28 @@ export type Vault = {
|
|
2558
2689
|
},
|
2559
2690
|
{
|
2560
2691
|
"code": 6020,
|
2561
|
-
"name": "
|
2562
|
-
"msg": "Can only redeem
|
2692
|
+
"name": "NotRedeemingLowestCollateralRatioVault",
|
2693
|
+
"msg": "Can only redeem lowest collateral ratio vault in system."
|
2563
2694
|
},
|
2564
2695
|
{
|
2565
2696
|
"code": 6021,
|
2566
2697
|
"name": "VaultTypeDeprecated",
|
2567
2698
|
"msg": "Vaults of this collateral type are deprecated. No new vaults can be created and no new debt will be issued for this collateral type."
|
2699
|
+
},
|
2700
|
+
{
|
2701
|
+
"code": 6022,
|
2702
|
+
"name": "UpdateLinkedListFailed",
|
2703
|
+
"msg": "There was an error updating the list of vaults. Please make sure the transaction is fresh."
|
2704
|
+
},
|
2705
|
+
{
|
2706
|
+
"code": 6023,
|
2707
|
+
"name": "InvalidSaltLength",
|
2708
|
+
"msg": "Salt for new vaults must be of length 8"
|
2709
|
+
},
|
2710
|
+
{
|
2711
|
+
"code": 6024,
|
2712
|
+
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2713
|
+
"msg": "New Max debt extended value is less than the current debt!"
|
2568
2714
|
}
|
2569
2715
|
]
|
2570
2716
|
};
|
@@ -4131,7 +4277,7 @@ export const IDL: Vault = {
|
|
4131
4277
|
]
|
4132
4278
|
},
|
4133
4279
|
{
|
4134
|
-
"name": "
|
4280
|
+
"name": "updateVaultType",
|
4135
4281
|
"accounts": [
|
4136
4282
|
{
|
4137
4283
|
"name": "payer",
|
@@ -4147,12 +4293,77 @@ export const IDL: Vault = {
|
|
4147
4293
|
"name": "vaultType",
|
4148
4294
|
"isMut": true,
|
4149
4295
|
"isSigner": false
|
4296
|
+
},
|
4297
|
+
{
|
4298
|
+
"name": "oracleInfoAccount",
|
4299
|
+
"isMut": true,
|
4300
|
+
"isSigner": false
|
4301
|
+
}
|
4302
|
+
],
|
4303
|
+
"args": [
|
4304
|
+
{
|
4305
|
+
"name": "config",
|
4306
|
+
"type": {
|
4307
|
+
"defined": "VaultTypeConfig"
|
4308
|
+
}
|
4309
|
+
}
|
4310
|
+
]
|
4311
|
+
},
|
4312
|
+
{
|
4313
|
+
"name": "fixVaultRedeemPointer",
|
4314
|
+
"accounts": [
|
4315
|
+
{
|
4316
|
+
"name": "payer",
|
4317
|
+
"isMut": true,
|
4318
|
+
"isSigner": true
|
4319
|
+
},
|
4320
|
+
{
|
4321
|
+
"name": "vaultSystemState",
|
4322
|
+
"isMut": true,
|
4323
|
+
"isSigner": false
|
4324
|
+
},
|
4325
|
+
{
|
4326
|
+
"name": "vaultAccount",
|
4327
|
+
"isMut": true,
|
4328
|
+
"isSigner": false
|
4329
|
+
}
|
4330
|
+
],
|
4331
|
+
"args": []
|
4332
|
+
},
|
4333
|
+
{
|
4334
|
+
"name": "adminSetRedeemPointer",
|
4335
|
+
"accounts": [
|
4336
|
+
{
|
4337
|
+
"name": "payer",
|
4338
|
+
"isMut": true,
|
4339
|
+
"isSigner": true
|
4340
|
+
},
|
4341
|
+
{
|
4342
|
+
"name": "vaultSystemState",
|
4343
|
+
"isMut": true,
|
4344
|
+
"isSigner": false
|
4345
|
+
},
|
4346
|
+
{
|
4347
|
+
"name": "vaultAccount",
|
4348
|
+
"isMut": true,
|
4349
|
+
"isSigner": false
|
4350
|
+
},
|
4351
|
+
{
|
4352
|
+
"name": "vaultTypeAccount",
|
4353
|
+
"isMut": true,
|
4354
|
+
"isSigner": false
|
4150
4355
|
}
|
4151
4356
|
],
|
4152
4357
|
"args": [
|
4153
4358
|
{
|
4154
|
-
"name": "
|
4359
|
+
"name": "settingHead",
|
4155
4360
|
"type": "bool"
|
4361
|
+
},
|
4362
|
+
{
|
4363
|
+
"name": "pointerToSet",
|
4364
|
+
"type": {
|
4365
|
+
"option": "publicKey"
|
4366
|
+
}
|
4156
4367
|
}
|
4157
4368
|
]
|
4158
4369
|
}
|
@@ -4350,7 +4561,7 @@ export const IDL: Vault = {
|
|
4350
4561
|
"kind": "struct",
|
4351
4562
|
"fields": [
|
4352
4563
|
{
|
4353
|
-
"name": "
|
4564
|
+
"name": "vaultTypeName",
|
4354
4565
|
"type": "string"
|
4355
4566
|
},
|
4356
4567
|
{
|
@@ -4364,6 +4575,10 @@ export const IDL: Vault = {
|
|
4364
4575
|
{
|
4365
4576
|
"name": "oracleSwitchboard",
|
4366
4577
|
"type": "publicKey"
|
4578
|
+
},
|
4579
|
+
{
|
4580
|
+
"name": "vaultType",
|
4581
|
+
"type": "publicKey"
|
4367
4582
|
}
|
4368
4583
|
]
|
4369
4584
|
}
|
@@ -4474,7 +4689,7 @@ export const IDL: Vault = {
|
|
4474
4689
|
"type": {
|
4475
4690
|
"array": [
|
4476
4691
|
"u8",
|
4477
|
-
|
4692
|
+
16
|
4478
4693
|
]
|
4479
4694
|
}
|
4480
4695
|
},
|
@@ -4608,7 +4823,7 @@ export const IDL: Vault = {
|
|
4608
4823
|
"kind": "struct",
|
4609
4824
|
"fields": [
|
4610
4825
|
{
|
4611
|
-
"name": "
|
4826
|
+
"name": "vaultTypeName",
|
4612
4827
|
"type": "string"
|
4613
4828
|
},
|
4614
4829
|
{
|
@@ -4692,6 +4907,14 @@ export const IDL: Vault = {
|
|
4692
4907
|
{
|
4693
4908
|
"name": "deprecated",
|
4694
4909
|
"type": "bool"
|
4910
|
+
},
|
4911
|
+
{
|
4912
|
+
"name": "totalFeesAccumulatedUsh",
|
4913
|
+
"type": "u128"
|
4914
|
+
},
|
4915
|
+
{
|
4916
|
+
"name": "totalFeesAccumulatedCollateral",
|
4917
|
+
"type": "u128"
|
4695
4918
|
}
|
4696
4919
|
]
|
4697
4920
|
}
|
@@ -4718,7 +4941,7 @@ export const IDL: Vault = {
|
|
4718
4941
|
"type": "u64"
|
4719
4942
|
},
|
4720
4943
|
{
|
4721
|
-
"name": "
|
4944
|
+
"name": "vaultTypeName",
|
4722
4945
|
"type": "string"
|
4723
4946
|
},
|
4724
4947
|
{
|
@@ -4766,6 +4989,10 @@ export const IDL: Vault = {
|
|
4766
4989
|
"type": {
|
4767
4990
|
"option": "publicKey"
|
4768
4991
|
}
|
4992
|
+
},
|
4993
|
+
{
|
4994
|
+
"name": "vaultType",
|
4995
|
+
"type": "publicKey"
|
4769
4996
|
}
|
4770
4997
|
]
|
4771
4998
|
}
|
@@ -4814,6 +5041,56 @@ export const IDL: Vault = {
|
|
4814
5041
|
]
|
4815
5042
|
}
|
4816
5043
|
},
|
5044
|
+
{
|
5045
|
+
"name": "VaultTypeConfig",
|
5046
|
+
"type": {
|
5047
|
+
"kind": "struct",
|
5048
|
+
"fields": [
|
5049
|
+
{
|
5050
|
+
"name": "maxDebtExtended",
|
5051
|
+
"type": {
|
5052
|
+
"option": "u64"
|
5053
|
+
}
|
5054
|
+
},
|
5055
|
+
{
|
5056
|
+
"name": "minDebtPerVault",
|
5057
|
+
"type": {
|
5058
|
+
"option": "u64"
|
5059
|
+
}
|
5060
|
+
},
|
5061
|
+
{
|
5062
|
+
"name": "loanInitFee",
|
5063
|
+
"type": {
|
5064
|
+
"option": "u64"
|
5065
|
+
}
|
5066
|
+
},
|
5067
|
+
{
|
5068
|
+
"name": "oracleChainlink",
|
5069
|
+
"type": {
|
5070
|
+
"option": "publicKey"
|
5071
|
+
}
|
5072
|
+
},
|
5073
|
+
{
|
5074
|
+
"name": "oraclePyth",
|
5075
|
+
"type": {
|
5076
|
+
"option": "publicKey"
|
5077
|
+
}
|
5078
|
+
},
|
5079
|
+
{
|
5080
|
+
"name": "oracleSwitchboard",
|
5081
|
+
"type": {
|
5082
|
+
"option": "publicKey"
|
5083
|
+
}
|
5084
|
+
},
|
5085
|
+
{
|
5086
|
+
"name": "deprecated",
|
5087
|
+
"type": {
|
5088
|
+
"option": "bool"
|
5089
|
+
}
|
5090
|
+
}
|
5091
|
+
]
|
5092
|
+
}
|
5093
|
+
},
|
4817
5094
|
{
|
4818
5095
|
"name": "PositionState",
|
4819
5096
|
"type": {
|
@@ -5129,13 +5406,28 @@ export const IDL: Vault = {
|
|
5129
5406
|
},
|
5130
5407
|
{
|
5131
5408
|
"code": 6020,
|
5132
|
-
"name": "
|
5133
|
-
"msg": "Can only redeem
|
5409
|
+
"name": "NotRedeemingLowestCollateralRatioVault",
|
5410
|
+
"msg": "Can only redeem lowest collateral ratio vault in system."
|
5134
5411
|
},
|
5135
5412
|
{
|
5136
5413
|
"code": 6021,
|
5137
5414
|
"name": "VaultTypeDeprecated",
|
5138
5415
|
"msg": "Vaults of this collateral type are deprecated. No new vaults can be created and no new debt will be issued for this collateral type."
|
5416
|
+
},
|
5417
|
+
{
|
5418
|
+
"code": 6022,
|
5419
|
+
"name": "UpdateLinkedListFailed",
|
5420
|
+
"msg": "There was an error updating the list of vaults. Please make sure the transaction is fresh."
|
5421
|
+
},
|
5422
|
+
{
|
5423
|
+
"code": 6023,
|
5424
|
+
"name": "InvalidSaltLength",
|
5425
|
+
"msg": "Salt for new vaults must be of length 8"
|
5426
|
+
},
|
5427
|
+
{
|
5428
|
+
"code": 6024,
|
5429
|
+
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
5430
|
+
"msg": "New Max debt extended value is less than the current debt!"
|
5139
5431
|
}
|
5140
5432
|
]
|
5141
5433
|
};
|
package/src/index.ts
CHANGED
@@ -17,7 +17,7 @@ export * from './instructions/refreshOraclePrice'
|
|
17
17
|
export * from './instructions/initHedgeFoundation'
|
18
18
|
export * from './instructions/initHedgeFoundationTokens'
|
19
19
|
export * from './instructions/setHalted'
|
20
|
-
export * from './instructions/
|
20
|
+
export * from './instructions/updateVaultType'
|
21
21
|
|
22
22
|
export * from './HedgeDecimal'
|
23
23
|
export * from './Constants'
|
@@ -41,6 +41,7 @@ export async function createStakingPoolInstruction(
|
|
41
41
|
hedgeTokensToBeMinted: number,
|
42
42
|
overrideStartTime?: number
|
43
43
|
): Promise<TransactionInstruction> {
|
44
|
+
console.log("new createStakingPoolInstruction")
|
44
45
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
45
46
|
const ushMintPublickey = await getUshMintPublicKey()
|
46
47
|
const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
|
@@ -20,6 +20,7 @@ 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'
|
23
24
|
|
24
25
|
export async function depositVault(
|
25
26
|
program: Program<Vault>,
|
@@ -35,13 +36,12 @@ export async function depositVault(
|
|
35
36
|
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
36
37
|
|
37
38
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
38
|
-
const
|
39
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
39
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
40
40
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
41
41
|
provider.connection,
|
42
42
|
payer,
|
43
43
|
vaultTypeAccountInfo.collateralMint,
|
44
|
-
|
44
|
+
vaultAccount.vaultType,
|
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
|
+
vaultAccount.vaultType,
|
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 (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
|
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
|
+
vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount,
|
102
102
|
vaultPublicKey,
|
103
103
|
vaultAssociatedCollateralAccountPublicKey,
|
104
104
|
history.publicKey,
|
105
|
-
|
105
|
+
vaultAccount.vaultType,
|
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 (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
|
119
119
|
transaction.add(
|
120
120
|
TokenInstructions.closeAccount({
|
121
121
|
source: wrappedSolAccount.publicKey,
|
@@ -31,8 +31,7 @@ export async function liquidateVault(
|
|
31
31
|
): Promise<PublicKey> {
|
32
32
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
33
33
|
|
34
|
-
const
|
35
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
34
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
36
35
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
37
36
|
|
38
37
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
@@ -73,7 +72,7 @@ export async function liquidateVault(
|
|
73
72
|
provider.connection,
|
74
73
|
payer,
|
75
74
|
collateralMint,
|
76
|
-
|
75
|
+
vaultAccount.vaultType,
|
77
76
|
true
|
78
77
|
)
|
79
78
|
const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -87,7 +86,7 @@ export async function liquidateVault(
|
|
87
86
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
88
87
|
program,
|
89
88
|
provider,
|
90
|
-
|
89
|
+
vaultAccount.vaultType,
|
91
90
|
vaultPublicKey,
|
92
91
|
0,
|
93
92
|
0,
|
@@ -119,7 +118,7 @@ export async function liquidateVault(
|
|
119
118
|
oldSmallerPublicKey,
|
120
119
|
newSmallerPublicKey,
|
121
120
|
newLargerPublicKey,
|
122
|
-
vaultAccount.
|
121
|
+
vaultAccount.vaultType,
|
123
122
|
overrideTime
|
124
123
|
)
|
125
124
|
)
|
@@ -146,13 +145,12 @@ export async function liquidateVaultInstruction(
|
|
146
145
|
oldSmallerPublicKey: PublicKey,
|
147
146
|
newSmallerPublicKey: PublicKey,
|
148
147
|
newLargerPublicKey: PublicKey,
|
149
|
-
|
148
|
+
vaultTypeAccount: PublicKey,
|
150
149
|
overrideTime?: number
|
151
150
|
): Promise<TransactionInstruction> {
|
152
151
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
153
152
|
const ushMintPublickey = await getUshMintPublicKey()
|
154
153
|
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
|
155
|
-
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
156
154
|
|
157
155
|
return await program.methods
|
158
156
|
.liquidateVault(
|
@@ -17,8 +17,13 @@ import {
|
|
17
17
|
getVaultTypeAccountPublicKey,
|
18
18
|
getUshMintPublicKey,
|
19
19
|
getVaultSystemStatePublicKey,
|
20
|
+
HEDGE_PROGRAM_PUBLICKEY,
|
20
21
|
} from '../Constants'
|
21
22
|
import { Vault } from 'idl/vault'
|
23
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
24
|
+
import { VaultAccount } from '../state/VaultAccount'
|
25
|
+
|
26
|
+
const fs = require('fs');
|
22
27
|
|
23
28
|
export async function loanVault(
|
24
29
|
program: Program<Vault>,
|
@@ -36,15 +41,14 @@ export async function loanVault(
|
|
36
41
|
ushMintPublickey,
|
37
42
|
payer.publicKey
|
38
43
|
)
|
39
|
-
|
40
44
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
41
|
-
const
|
42
|
-
|
45
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
46
|
+
|
43
47
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
44
48
|
provider.connection,
|
45
49
|
payer,
|
46
50
|
vaultTypeAccount.collateralMint,
|
47
|
-
|
51
|
+
vaultAccount.vaultType,
|
48
52
|
true
|
49
53
|
)
|
50
54
|
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -54,11 +58,10 @@ export async function loanVault(
|
|
54
58
|
vaultPublicKey,
|
55
59
|
true
|
56
60
|
)
|
57
|
-
|
58
61
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
59
62
|
program,
|
60
63
|
provider,
|
61
|
-
|
64
|
+
vaultAccount.vaultType,
|
62
65
|
vaultPublicKey,
|
63
66
|
0,
|
64
67
|
loanAmount,
|
@@ -75,7 +78,7 @@ export async function loanVault(
|
|
75
78
|
vaultPublicKey,
|
76
79
|
vaultAssociatedTokenAccount.address,
|
77
80
|
history.publicKey,
|
78
|
-
|
81
|
+
vaultAccount.vaultType,
|
79
82
|
vaultTypeAssociatedTokenAccount.address,
|
80
83
|
oldSmallerPublicKey,
|
81
84
|
newSmallerPublicKey,
|
@@ -84,7 +87,7 @@ export async function loanVault(
|
|
84
87
|
overrideTime
|
85
88
|
)
|
86
89
|
)
|
87
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
|
90
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history]).catch(parseAnchorErrors)
|
88
91
|
return vaultPublicKey
|
89
92
|
}
|
90
93
|
|