hedge-web3 0.2.16 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +377 -4
- package/declarations/index.d.ts +2 -0
- package/declarations/instructions/psmMintUsh.d.ts +6 -0
- package/declarations/instructions/psmRedeemUsh.d.ts +6 -0
- package/declarations/instructions/updateVaultType.d.ts +1 -0
- package/lib/idl/vault.js +377 -4
- package/lib/index.js +2 -0
- package/lib/instructions/psmMintUsh.js +65 -0
- package/lib/instructions/psmRedeemUsh.js +65 -0
- package/lib/instructions/updateVaultType.js +9 -8
- package/package.json +1 -1
- package/src/idl/vault.ts +769 -23
- package/src/index.ts +2 -0
- package/src/instructions/psmEditAccount.rs +124 -0
- package/src/instructions/psmMintUsh.ts +129 -0
- package/src/instructions/psmRedeemUsh.ts +129 -0
- package/src/instructions/updateVaultType.ts +2 -0
package/lib/idl/vault.js
CHANGED
@@ -79,6 +79,10 @@ exports.IDL = {
|
|
79
79
|
"name": "maxDebtExtended",
|
80
80
|
"type": "u64"
|
81
81
|
},
|
82
|
+
{
|
83
|
+
"name": "emergencyModeThreshold",
|
84
|
+
"type": "u64"
|
85
|
+
},
|
82
86
|
{
|
83
87
|
"name": "canBeRedeemed",
|
84
88
|
"type": "bool"
|
@@ -1757,6 +1761,260 @@ exports.IDL = {
|
|
1757
1761
|
}
|
1758
1762
|
],
|
1759
1763
|
"args": []
|
1764
|
+
},
|
1765
|
+
{
|
1766
|
+
"name": "psmCreate",
|
1767
|
+
"accounts": [
|
1768
|
+
{
|
1769
|
+
"name": "payer",
|
1770
|
+
"isMut": true,
|
1771
|
+
"isSigner": true
|
1772
|
+
},
|
1773
|
+
{
|
1774
|
+
"name": "vaultSystemState",
|
1775
|
+
"isMut": true,
|
1776
|
+
"isSigner": false
|
1777
|
+
},
|
1778
|
+
{
|
1779
|
+
"name": "psmAccount",
|
1780
|
+
"isMut": true,
|
1781
|
+
"isSigner": false
|
1782
|
+
},
|
1783
|
+
{
|
1784
|
+
"name": "collateralMint",
|
1785
|
+
"isMut": false,
|
1786
|
+
"isSigner": false
|
1787
|
+
},
|
1788
|
+
{
|
1789
|
+
"name": "systemProgram",
|
1790
|
+
"isMut": false,
|
1791
|
+
"isSigner": false
|
1792
|
+
}
|
1793
|
+
],
|
1794
|
+
"args": [
|
1795
|
+
{
|
1796
|
+
"name": "mintFee",
|
1797
|
+
"type": "u64"
|
1798
|
+
},
|
1799
|
+
{
|
1800
|
+
"name": "redeemFee",
|
1801
|
+
"type": "u64"
|
1802
|
+
},
|
1803
|
+
{
|
1804
|
+
"name": "debtLimit",
|
1805
|
+
"type": "u64"
|
1806
|
+
},
|
1807
|
+
{
|
1808
|
+
"name": "minSwap",
|
1809
|
+
"type": "u64"
|
1810
|
+
},
|
1811
|
+
{
|
1812
|
+
"name": "overrideCurrentTime",
|
1813
|
+
"type": "i64"
|
1814
|
+
}
|
1815
|
+
]
|
1816
|
+
},
|
1817
|
+
{
|
1818
|
+
"name": "psmEditAccount",
|
1819
|
+
"accounts": [
|
1820
|
+
{
|
1821
|
+
"name": "payer",
|
1822
|
+
"isMut": true,
|
1823
|
+
"isSigner": true
|
1824
|
+
},
|
1825
|
+
{
|
1826
|
+
"name": "vaultSystemState",
|
1827
|
+
"isMut": true,
|
1828
|
+
"isSigner": false
|
1829
|
+
},
|
1830
|
+
{
|
1831
|
+
"name": "psmAccount",
|
1832
|
+
"isMut": true,
|
1833
|
+
"isSigner": false
|
1834
|
+
},
|
1835
|
+
{
|
1836
|
+
"name": "collateralMint",
|
1837
|
+
"isMut": false,
|
1838
|
+
"isSigner": false
|
1839
|
+
},
|
1840
|
+
{
|
1841
|
+
"name": "systemProgram",
|
1842
|
+
"isMut": false,
|
1843
|
+
"isSigner": false
|
1844
|
+
}
|
1845
|
+
],
|
1846
|
+
"args": [
|
1847
|
+
{
|
1848
|
+
"name": "mintFee",
|
1849
|
+
"type": "u64"
|
1850
|
+
},
|
1851
|
+
{
|
1852
|
+
"name": "redeemFee",
|
1853
|
+
"type": "u64"
|
1854
|
+
},
|
1855
|
+
{
|
1856
|
+
"name": "debtLimit",
|
1857
|
+
"type": "u64"
|
1858
|
+
},
|
1859
|
+
{
|
1860
|
+
"name": "minSwap",
|
1861
|
+
"type": "u64"
|
1862
|
+
},
|
1863
|
+
{
|
1864
|
+
"name": "overrideCurrentTime",
|
1865
|
+
"type": "i64"
|
1866
|
+
}
|
1867
|
+
]
|
1868
|
+
},
|
1869
|
+
{
|
1870
|
+
"name": "psmMintUsh",
|
1871
|
+
"accounts": [
|
1872
|
+
{
|
1873
|
+
"name": "payer",
|
1874
|
+
"isMut": true,
|
1875
|
+
"isSigner": true
|
1876
|
+
},
|
1877
|
+
{
|
1878
|
+
"name": "vaultSystemState",
|
1879
|
+
"isMut": true,
|
1880
|
+
"isSigner": false
|
1881
|
+
},
|
1882
|
+
{
|
1883
|
+
"name": "feePool",
|
1884
|
+
"isMut": true,
|
1885
|
+
"isSigner": false
|
1886
|
+
},
|
1887
|
+
{
|
1888
|
+
"name": "feePoolAssociatedUshTokenAccount",
|
1889
|
+
"isMut": true,
|
1890
|
+
"isSigner": false
|
1891
|
+
},
|
1892
|
+
{
|
1893
|
+
"name": "psmAccount",
|
1894
|
+
"isMut": true,
|
1895
|
+
"isSigner": false
|
1896
|
+
},
|
1897
|
+
{
|
1898
|
+
"name": "psmAccountAta",
|
1899
|
+
"isMut": true,
|
1900
|
+
"isSigner": false
|
1901
|
+
},
|
1902
|
+
{
|
1903
|
+
"name": "ownerUshAccount",
|
1904
|
+
"isMut": true,
|
1905
|
+
"isSigner": false
|
1906
|
+
},
|
1907
|
+
{
|
1908
|
+
"name": "ownerCollateralAccount",
|
1909
|
+
"isMut": true,
|
1910
|
+
"isSigner": false
|
1911
|
+
},
|
1912
|
+
{
|
1913
|
+
"name": "collateralMint",
|
1914
|
+
"isMut": false,
|
1915
|
+
"isSigner": false
|
1916
|
+
},
|
1917
|
+
{
|
1918
|
+
"name": "ushMint",
|
1919
|
+
"isMut": true,
|
1920
|
+
"isSigner": false
|
1921
|
+
},
|
1922
|
+
{
|
1923
|
+
"name": "systemProgram",
|
1924
|
+
"isMut": false,
|
1925
|
+
"isSigner": false
|
1926
|
+
},
|
1927
|
+
{
|
1928
|
+
"name": "tokenProgram",
|
1929
|
+
"isMut": false,
|
1930
|
+
"isSigner": false
|
1931
|
+
}
|
1932
|
+
],
|
1933
|
+
"args": [
|
1934
|
+
{
|
1935
|
+
"name": "collateralAmount",
|
1936
|
+
"type": "u64"
|
1937
|
+
},
|
1938
|
+
{
|
1939
|
+
"name": "overrideCurrentTime",
|
1940
|
+
"type": "i64"
|
1941
|
+
}
|
1942
|
+
]
|
1943
|
+
},
|
1944
|
+
{
|
1945
|
+
"name": "psmRedeemUsh",
|
1946
|
+
"accounts": [
|
1947
|
+
{
|
1948
|
+
"name": "payer",
|
1949
|
+
"isMut": true,
|
1950
|
+
"isSigner": true
|
1951
|
+
},
|
1952
|
+
{
|
1953
|
+
"name": "vaultSystemState",
|
1954
|
+
"isMut": true,
|
1955
|
+
"isSigner": false
|
1956
|
+
},
|
1957
|
+
{
|
1958
|
+
"name": "feePool",
|
1959
|
+
"isMut": true,
|
1960
|
+
"isSigner": false
|
1961
|
+
},
|
1962
|
+
{
|
1963
|
+
"name": "feePoolAssociatedUshTokenAccount",
|
1964
|
+
"isMut": true,
|
1965
|
+
"isSigner": false
|
1966
|
+
},
|
1967
|
+
{
|
1968
|
+
"name": "psmAccount",
|
1969
|
+
"isMut": true,
|
1970
|
+
"isSigner": false
|
1971
|
+
},
|
1972
|
+
{
|
1973
|
+
"name": "psmAccountAta",
|
1974
|
+
"isMut": true,
|
1975
|
+
"isSigner": false
|
1976
|
+
},
|
1977
|
+
{
|
1978
|
+
"name": "ownerUshAccount",
|
1979
|
+
"isMut": true,
|
1980
|
+
"isSigner": false
|
1981
|
+
},
|
1982
|
+
{
|
1983
|
+
"name": "ownerCollateralAccount",
|
1984
|
+
"isMut": true,
|
1985
|
+
"isSigner": false
|
1986
|
+
},
|
1987
|
+
{
|
1988
|
+
"name": "collateralMint",
|
1989
|
+
"isMut": false,
|
1990
|
+
"isSigner": false
|
1991
|
+
},
|
1992
|
+
{
|
1993
|
+
"name": "ushMint",
|
1994
|
+
"isMut": true,
|
1995
|
+
"isSigner": false
|
1996
|
+
},
|
1997
|
+
{
|
1998
|
+
"name": "systemProgram",
|
1999
|
+
"isMut": false,
|
2000
|
+
"isSigner": false
|
2001
|
+
},
|
2002
|
+
{
|
2003
|
+
"name": "tokenProgram",
|
2004
|
+
"isMut": false,
|
2005
|
+
"isSigner": false
|
2006
|
+
}
|
2007
|
+
],
|
2008
|
+
"args": [
|
2009
|
+
{
|
2010
|
+
"name": "ushAmount",
|
2011
|
+
"type": "u64"
|
2012
|
+
},
|
2013
|
+
{
|
2014
|
+
"name": "overrideCurrentTime",
|
2015
|
+
"type": "i64"
|
2016
|
+
}
|
2017
|
+
]
|
1760
2018
|
}
|
1761
2019
|
],
|
1762
2020
|
"accounts": [
|
@@ -1988,6 +2246,80 @@ exports.IDL = {
|
|
1988
2246
|
]
|
1989
2247
|
}
|
1990
2248
|
},
|
2249
|
+
{
|
2250
|
+
"name": "psmAccount",
|
2251
|
+
"type": {
|
2252
|
+
"kind": "struct",
|
2253
|
+
"fields": [
|
2254
|
+
{
|
2255
|
+
"name": "collateralMint",
|
2256
|
+
"type": "publicKey"
|
2257
|
+
},
|
2258
|
+
{
|
2259
|
+
"name": "minCollateralRatio",
|
2260
|
+
"type": "u128"
|
2261
|
+
},
|
2262
|
+
{
|
2263
|
+
"name": "mintFee",
|
2264
|
+
"type": "u128"
|
2265
|
+
},
|
2266
|
+
{
|
2267
|
+
"name": "redeemFee",
|
2268
|
+
"type": "u128"
|
2269
|
+
},
|
2270
|
+
{
|
2271
|
+
"name": "totalFeesAccumulatedUsh",
|
2272
|
+
"type": "u128"
|
2273
|
+
},
|
2274
|
+
{
|
2275
|
+
"name": "totalFeesAccumulatedCollateral",
|
2276
|
+
"type": "u128"
|
2277
|
+
},
|
2278
|
+
{
|
2279
|
+
"name": "recentPrice",
|
2280
|
+
"type": "u128"
|
2281
|
+
},
|
2282
|
+
{
|
2283
|
+
"name": "debtLimit",
|
2284
|
+
"type": "u64"
|
2285
|
+
},
|
2286
|
+
{
|
2287
|
+
"name": "deposited",
|
2288
|
+
"type": "u64"
|
2289
|
+
},
|
2290
|
+
{
|
2291
|
+
"name": "amountMinted",
|
2292
|
+
"type": "u64"
|
2293
|
+
},
|
2294
|
+
{
|
2295
|
+
"name": "minSwap",
|
2296
|
+
"type": "u64"
|
2297
|
+
},
|
2298
|
+
{
|
2299
|
+
"name": "timeCreated",
|
2300
|
+
"type": "u64"
|
2301
|
+
},
|
2302
|
+
{
|
2303
|
+
"name": "timeLastInteraction",
|
2304
|
+
"type": "u64"
|
2305
|
+
},
|
2306
|
+
{
|
2307
|
+
"name": "priceLastUpdatedTimestamp",
|
2308
|
+
"type": "u64"
|
2309
|
+
},
|
2310
|
+
{
|
2311
|
+
"name": "psmStatus",
|
2312
|
+
"type": {
|
2313
|
+
"defined": "PsmStatus"
|
2314
|
+
}
|
2315
|
+
},
|
2316
|
+
{
|
2317
|
+
"name": "collateralDecimals",
|
2318
|
+
"type": "u8"
|
2319
|
+
}
|
2320
|
+
]
|
2321
|
+
}
|
2322
|
+
},
|
1991
2323
|
{
|
1992
2324
|
"name": "stakingPoolPosition",
|
1993
2325
|
"type": {
|
@@ -2469,6 +2801,12 @@ exports.IDL = {
|
|
2469
2801
|
"option": "u64"
|
2470
2802
|
}
|
2471
2803
|
},
|
2804
|
+
{
|
2805
|
+
"name": "emergencyModeThreshold",
|
2806
|
+
"type": {
|
2807
|
+
"option": "u64"
|
2808
|
+
}
|
2809
|
+
},
|
2472
2810
|
{
|
2473
2811
|
"name": "oracleChainlink",
|
2474
2812
|
"type": {
|
@@ -2565,6 +2903,26 @@ exports.IDL = {
|
|
2565
2903
|
]
|
2566
2904
|
}
|
2567
2905
|
},
|
2906
|
+
{
|
2907
|
+
"name": "PsmStatus",
|
2908
|
+
"type": {
|
2909
|
+
"kind": "enum",
|
2910
|
+
"variants": [
|
2911
|
+
{
|
2912
|
+
"name": "PsmEnabled"
|
2913
|
+
},
|
2914
|
+
{
|
2915
|
+
"name": "PsmDisabled"
|
2916
|
+
},
|
2917
|
+
{
|
2918
|
+
"name": "MintOnly"
|
2919
|
+
},
|
2920
|
+
{
|
2921
|
+
"name": "RedeemOnly"
|
2922
|
+
}
|
2923
|
+
]
|
2924
|
+
}
|
2925
|
+
},
|
2568
2926
|
{
|
2569
2927
|
"name": "SystemStatus",
|
2570
2928
|
"type": {
|
@@ -2861,26 +3219,41 @@ exports.IDL = {
|
|
2861
3219
|
},
|
2862
3220
|
{
|
2863
3221
|
"code": 6027,
|
3222
|
+
"name": "PsmDisabled",
|
3223
|
+
"msg": "PSM is currently disabled."
|
3224
|
+
},
|
3225
|
+
{
|
3226
|
+
"code": 6028,
|
3227
|
+
"name": "PsmMaxDebtReached",
|
3228
|
+
"msg": "PSM - Max Debt reached"
|
3229
|
+
},
|
3230
|
+
{
|
3231
|
+
"code": 6029,
|
3232
|
+
"name": "PsmMinSwapAmount",
|
3233
|
+
"msg": "PSM - Need more to swap"
|
3234
|
+
},
|
3235
|
+
{
|
3236
|
+
"code": 6030,
|
2864
3237
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2865
3238
|
"msg": "New Max debt extended value is less than the current debt!"
|
2866
3239
|
},
|
2867
3240
|
{
|
2868
|
-
"code":
|
3241
|
+
"code": 6031,
|
2869
3242
|
"name": "UpdateVaultTypeNoEnabledOracles",
|
2870
3243
|
"msg": "No Enabled Oracles!"
|
2871
3244
|
},
|
2872
3245
|
{
|
2873
|
-
"code":
|
3246
|
+
"code": 6032,
|
2874
3247
|
"name": "UpdateVaultTypeDuplicateOraclePriorities",
|
2875
3248
|
"msg": "Duplicate Oracle Priorities"
|
2876
3249
|
},
|
2877
3250
|
{
|
2878
|
-
"code":
|
3251
|
+
"code": 6033,
|
2879
3252
|
"name": "UpdateVaultTypeInvalidOraclePriority",
|
2880
3253
|
"msg": "Invalid Oracle Priority"
|
2881
3254
|
},
|
2882
3255
|
{
|
2883
|
-
"code":
|
3256
|
+
"code": 6034,
|
2884
3257
|
"name": "OracleUpdateFailed",
|
2885
3258
|
"msg": "OracleUpdateFailed"
|
2886
3259
|
}
|
package/lib/index.js
CHANGED
@@ -19,6 +19,8 @@ __exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
|
19
19
|
__exportStar(require("./instructions/claimLiquidationPoolPosition"), exports);
|
20
20
|
__exportStar(require("./instructions/closeClaimedLiquidationPoolPosition"), exports);
|
21
21
|
__exportStar(require("./instructions/createVault"), exports);
|
22
|
+
__exportStar(require("./instructions/psmMintUsh"), exports);
|
23
|
+
__exportStar(require("./instructions/psmRedeemUsh"), exports);
|
22
24
|
__exportStar(require("./instructions/depositVault"), exports);
|
23
25
|
__exportStar(require("./instructions/withdrawVault"), exports);
|
24
26
|
__exportStar(require("./instructions/loanVault"), exports);
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.psmMintUshInstruction = exports.psmMintUsh = void 0;
|
16
|
+
const anchor_1 = require("@project-serum/anchor");
|
17
|
+
const spl_token_1 = require("@solana/spl-token");
|
18
|
+
const web3_js_1 = require("@solana/web3.js");
|
19
|
+
const Constants_1 = require("../Constants");
|
20
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
21
|
+
function psmMintUsh(program, provider, payer, collateralMint, collateralAmount, overrideTime) {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
24
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
25
|
+
const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
26
|
+
const enc = new TextEncoder();
|
27
|
+
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
28
|
+
const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
|
29
|
+
const transaction = new web3_js_1.Transaction().add(yield psmMintUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(collateralAmount), overrideTime));
|
30
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
31
|
+
return payer.publicKey;
|
32
|
+
});
|
33
|
+
}
|
34
|
+
exports.psmMintUsh = psmMintUsh;
|
35
|
+
function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMint, collateralAmount, overrideTime) {
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
38
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
39
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
40
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
41
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
42
|
+
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(psmAccount, collateralMint);
|
43
|
+
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, collateralMint);
|
44
|
+
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
|
45
|
+
return yield program.methods
|
46
|
+
.psmMintUsh(collateralAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
47
|
+
)
|
48
|
+
.accounts({
|
49
|
+
payer: payerPublicKey,
|
50
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
51
|
+
feePool: hedgeStakingPoolPublicKey,
|
52
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
53
|
+
psmAccount: psmAccount,
|
54
|
+
psmAccountAta: psmAccountAta,
|
55
|
+
ownerUshAccount: ownerUshAccount,
|
56
|
+
ownerCollateralAccount: ownerCollateralAccount,
|
57
|
+
collateralMint: collateralMint,
|
58
|
+
ushMint: ushMintPublickey,
|
59
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
60
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
61
|
+
})
|
62
|
+
.instruction();
|
63
|
+
});
|
64
|
+
}
|
65
|
+
exports.psmMintUshInstruction = psmMintUshInstruction;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.psmRedeemUshInstruction = exports.psmRedeemUsh = void 0;
|
16
|
+
const anchor_1 = require("@project-serum/anchor");
|
17
|
+
const spl_token_1 = require("@solana/spl-token");
|
18
|
+
const web3_js_1 = require("@solana/web3.js");
|
19
|
+
const Constants_1 = require("../Constants");
|
20
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
21
|
+
function psmRedeemUsh(program, provider, payer, collateralMint, ushAmount, overrideTime) {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
24
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
25
|
+
const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
26
|
+
const enc = new TextEncoder();
|
27
|
+
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
28
|
+
const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
|
29
|
+
const transaction = new web3_js_1.Transaction().add(yield psmRedeemUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(ushAmount), overrideTime));
|
30
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
31
|
+
return payer.publicKey;
|
32
|
+
});
|
33
|
+
}
|
34
|
+
exports.psmRedeemUsh = psmRedeemUsh;
|
35
|
+
function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateralMint, ushAmount, overrideTime) {
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
38
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
39
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
40
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
41
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
42
|
+
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(psmAccount, collateralMint);
|
43
|
+
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, collateralMint);
|
44
|
+
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
|
45
|
+
return yield program.methods
|
46
|
+
.psmRedeemUsh(ushAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
47
|
+
)
|
48
|
+
.accounts({
|
49
|
+
payer: payerPublicKey,
|
50
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
51
|
+
feePool: hedgeStakingPoolPublicKey,
|
52
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
53
|
+
psmAccount: psmAccount,
|
54
|
+
psmAccountAta: psmAccountAta,
|
55
|
+
ownerUshAccount: ownerUshAccount,
|
56
|
+
ownerCollateralAccount: ownerCollateralAccount,
|
57
|
+
collateralMint: collateralMint,
|
58
|
+
ushMint: ushMintPublickey,
|
59
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
60
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
61
|
+
})
|
62
|
+
.instruction();
|
63
|
+
});
|
64
|
+
}
|
65
|
+
exports.psmRedeemUshInstruction = psmRedeemUshInstruction;
|
@@ -26,19 +26,20 @@ function updateVaultType(program, provider, payer, vaultTypeAccount, oracleInfoA
|
|
26
26
|
}
|
27
27
|
exports.updateVaultType = updateVaultType;
|
28
28
|
function updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, oracleInfoAccount, vaultTypeConfig) {
|
29
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
31
31
|
const config = {
|
32
32
|
maxDebtExtended: (_a = vaultTypeConfig.maxDebtExtended) !== null && _a !== void 0 ? _a : null,
|
33
33
|
minDebtPerVault: (_b = vaultTypeConfig.minDebtPerVault) !== null && _b !== void 0 ? _b : null,
|
34
34
|
loanInitFee: (_c = vaultTypeConfig.loanInitFee) !== null && _c !== void 0 ? _c : null,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
emergencyModeThreshold: (_d = vaultTypeConfig.emergencyModeThreshold) !== null && _d !== void 0 ? _d : null,
|
36
|
+
oracleChainlink: (_e = vaultTypeConfig.oracleChainlink) !== null && _e !== void 0 ? _e : null,
|
37
|
+
oraclePyth: (_f = vaultTypeConfig.oraclePyth) !== null && _f !== void 0 ? _f : null,
|
38
|
+
oracleSwitchboard: (_g = vaultTypeConfig.oracleSwitchboard) !== null && _g !== void 0 ? _g : null,
|
39
|
+
deprecated: (_h = vaultTypeConfig.deprecated) !== null && _h !== void 0 ? _h : null,
|
40
|
+
priorityPyth: (_j = vaultTypeConfig.priorityPyth) !== null && _j !== void 0 ? _j : null,
|
41
|
+
priorityChainlink: (_k = vaultTypeConfig.priorityChainlink) !== null && _k !== void 0 ? _k : null,
|
42
|
+
prioritySwitchboard: (_l = vaultTypeConfig.prioritySwitchboard) !== null && _l !== void 0 ? _l : null,
|
42
43
|
};
|
43
44
|
return yield program.methods
|
44
45
|
.updateVaultType(config)
|