hedge-web3 0.2.15 → 0.2.18
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/idl/vault.d.ts +327 -10
- package/declarations/index.d.ts +2 -0
- package/declarations/instructions/psmMintUsh.d.ts +6 -0
- package/declarations/instructions/psmRedeemUsh.d.ts +6 -0
- package/lib/idl/vault.js +327 -10
- package/lib/index.js +2 -0
- package/lib/instructions/psmMintUsh.js +65 -0
- package/lib/instructions/psmRedeemUsh.js +65 -0
- package/package.json +1 -1
- package/src/idl/vault.ts +704 -70
- 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/lib/idl/vault.js
CHANGED
@@ -1759,7 +1759,7 @@ exports.IDL = {
|
|
1759
1759
|
"args": []
|
1760
1760
|
},
|
1761
1761
|
{
|
1762
|
-
"name": "
|
1762
|
+
"name": "psmCreate",
|
1763
1763
|
"accounts": [
|
1764
1764
|
{
|
1765
1765
|
"name": "payer",
|
@@ -1772,37 +1772,245 @@ exports.IDL = {
|
|
1772
1772
|
"isSigner": false
|
1773
1773
|
},
|
1774
1774
|
{
|
1775
|
-
"name": "
|
1775
|
+
"name": "psmAccount",
|
1776
1776
|
"isMut": true,
|
1777
1777
|
"isSigner": false
|
1778
1778
|
},
|
1779
1779
|
{
|
1780
|
-
"name": "
|
1780
|
+
"name": "collateralMint",
|
1781
|
+
"isMut": false,
|
1782
|
+
"isSigner": false
|
1783
|
+
},
|
1784
|
+
{
|
1785
|
+
"name": "systemProgram",
|
1786
|
+
"isMut": false,
|
1787
|
+
"isSigner": false
|
1788
|
+
}
|
1789
|
+
],
|
1790
|
+
"args": [
|
1791
|
+
{
|
1792
|
+
"name": "mintFee",
|
1793
|
+
"type": "u64"
|
1794
|
+
},
|
1795
|
+
{
|
1796
|
+
"name": "redeemFee",
|
1797
|
+
"type": "u64"
|
1798
|
+
},
|
1799
|
+
{
|
1800
|
+
"name": "debtLimit",
|
1801
|
+
"type": "u64"
|
1802
|
+
},
|
1803
|
+
{
|
1804
|
+
"name": "minSwap",
|
1805
|
+
"type": "u64"
|
1806
|
+
},
|
1807
|
+
{
|
1808
|
+
"name": "overrideCurrentTime",
|
1809
|
+
"type": "i64"
|
1810
|
+
}
|
1811
|
+
]
|
1812
|
+
},
|
1813
|
+
{
|
1814
|
+
"name": "psmEditAccount",
|
1815
|
+
"accounts": [
|
1816
|
+
{
|
1817
|
+
"name": "payer",
|
1818
|
+
"isMut": true,
|
1819
|
+
"isSigner": true
|
1820
|
+
},
|
1821
|
+
{
|
1822
|
+
"name": "vaultSystemState",
|
1781
1823
|
"isMut": true,
|
1782
1824
|
"isSigner": false
|
1783
1825
|
},
|
1784
1826
|
{
|
1785
|
-
"name": "
|
1827
|
+
"name": "psmAccount",
|
1786
1828
|
"isMut": true,
|
1787
1829
|
"isSigner": false
|
1788
1830
|
},
|
1789
1831
|
{
|
1790
|
-
"name": "
|
1832
|
+
"name": "collateralMint",
|
1833
|
+
"isMut": false,
|
1834
|
+
"isSigner": false
|
1835
|
+
},
|
1836
|
+
{
|
1837
|
+
"name": "systemProgram",
|
1838
|
+
"isMut": false,
|
1839
|
+
"isSigner": false
|
1840
|
+
}
|
1841
|
+
],
|
1842
|
+
"args": [
|
1843
|
+
{
|
1844
|
+
"name": "mintFee",
|
1845
|
+
"type": "u64"
|
1846
|
+
},
|
1847
|
+
{
|
1848
|
+
"name": "redeemFee",
|
1849
|
+
"type": "u64"
|
1850
|
+
},
|
1851
|
+
{
|
1852
|
+
"name": "debtLimit",
|
1853
|
+
"type": "u64"
|
1854
|
+
},
|
1855
|
+
{
|
1856
|
+
"name": "minSwap",
|
1857
|
+
"type": "u64"
|
1858
|
+
},
|
1859
|
+
{
|
1860
|
+
"name": "overrideCurrentTime",
|
1861
|
+
"type": "i64"
|
1862
|
+
}
|
1863
|
+
]
|
1864
|
+
},
|
1865
|
+
{
|
1866
|
+
"name": "psmMintUsh",
|
1867
|
+
"accounts": [
|
1868
|
+
{
|
1869
|
+
"name": "payer",
|
1870
|
+
"isMut": true,
|
1871
|
+
"isSigner": true
|
1872
|
+
},
|
1873
|
+
{
|
1874
|
+
"name": "vaultSystemState",
|
1875
|
+
"isMut": true,
|
1876
|
+
"isSigner": false
|
1877
|
+
},
|
1878
|
+
{
|
1879
|
+
"name": "feePool",
|
1880
|
+
"isMut": true,
|
1881
|
+
"isSigner": false
|
1882
|
+
},
|
1883
|
+
{
|
1884
|
+
"name": "feePoolAssociatedUshTokenAccount",
|
1885
|
+
"isMut": true,
|
1886
|
+
"isSigner": false
|
1887
|
+
},
|
1888
|
+
{
|
1889
|
+
"name": "psmAccount",
|
1890
|
+
"isMut": true,
|
1891
|
+
"isSigner": false
|
1892
|
+
},
|
1893
|
+
{
|
1894
|
+
"name": "psmAccountAta",
|
1895
|
+
"isMut": true,
|
1896
|
+
"isSigner": false
|
1897
|
+
},
|
1898
|
+
{
|
1899
|
+
"name": "ownerUshAccount",
|
1900
|
+
"isMut": true,
|
1901
|
+
"isSigner": false
|
1902
|
+
},
|
1903
|
+
{
|
1904
|
+
"name": "ownerCollateralAccount",
|
1791
1905
|
"isMut": true,
|
1792
1906
|
"isSigner": false
|
1793
1907
|
},
|
1794
1908
|
{
|
1795
1909
|
"name": "collateralMint",
|
1910
|
+
"isMut": false,
|
1911
|
+
"isSigner": false
|
1912
|
+
},
|
1913
|
+
{
|
1914
|
+
"name": "ushMint",
|
1796
1915
|
"isMut": true,
|
1797
1916
|
"isSigner": false
|
1798
1917
|
},
|
1918
|
+
{
|
1919
|
+
"name": "systemProgram",
|
1920
|
+
"isMut": false,
|
1921
|
+
"isSigner": false
|
1922
|
+
},
|
1799
1923
|
{
|
1800
1924
|
"name": "tokenProgram",
|
1801
1925
|
"isMut": false,
|
1802
1926
|
"isSigner": false
|
1803
1927
|
}
|
1804
1928
|
],
|
1805
|
-
"args": [
|
1929
|
+
"args": [
|
1930
|
+
{
|
1931
|
+
"name": "collateralAmount",
|
1932
|
+
"type": "u64"
|
1933
|
+
},
|
1934
|
+
{
|
1935
|
+
"name": "overrideCurrentTime",
|
1936
|
+
"type": "i64"
|
1937
|
+
}
|
1938
|
+
]
|
1939
|
+
},
|
1940
|
+
{
|
1941
|
+
"name": "psmRedeemUsh",
|
1942
|
+
"accounts": [
|
1943
|
+
{
|
1944
|
+
"name": "payer",
|
1945
|
+
"isMut": true,
|
1946
|
+
"isSigner": true
|
1947
|
+
},
|
1948
|
+
{
|
1949
|
+
"name": "vaultSystemState",
|
1950
|
+
"isMut": true,
|
1951
|
+
"isSigner": false
|
1952
|
+
},
|
1953
|
+
{
|
1954
|
+
"name": "feePool",
|
1955
|
+
"isMut": true,
|
1956
|
+
"isSigner": false
|
1957
|
+
},
|
1958
|
+
{
|
1959
|
+
"name": "feePoolAssociatedUshTokenAccount",
|
1960
|
+
"isMut": true,
|
1961
|
+
"isSigner": false
|
1962
|
+
},
|
1963
|
+
{
|
1964
|
+
"name": "psmAccount",
|
1965
|
+
"isMut": true,
|
1966
|
+
"isSigner": false
|
1967
|
+
},
|
1968
|
+
{
|
1969
|
+
"name": "psmAccountAta",
|
1970
|
+
"isMut": true,
|
1971
|
+
"isSigner": false
|
1972
|
+
},
|
1973
|
+
{
|
1974
|
+
"name": "ownerUshAccount",
|
1975
|
+
"isMut": true,
|
1976
|
+
"isSigner": false
|
1977
|
+
},
|
1978
|
+
{
|
1979
|
+
"name": "ownerCollateralAccount",
|
1980
|
+
"isMut": true,
|
1981
|
+
"isSigner": false
|
1982
|
+
},
|
1983
|
+
{
|
1984
|
+
"name": "collateralMint",
|
1985
|
+
"isMut": false,
|
1986
|
+
"isSigner": false
|
1987
|
+
},
|
1988
|
+
{
|
1989
|
+
"name": "ushMint",
|
1990
|
+
"isMut": true,
|
1991
|
+
"isSigner": false
|
1992
|
+
},
|
1993
|
+
{
|
1994
|
+
"name": "systemProgram",
|
1995
|
+
"isMut": false,
|
1996
|
+
"isSigner": false
|
1997
|
+
},
|
1998
|
+
{
|
1999
|
+
"name": "tokenProgram",
|
2000
|
+
"isMut": false,
|
2001
|
+
"isSigner": false
|
2002
|
+
}
|
2003
|
+
],
|
2004
|
+
"args": [
|
2005
|
+
{
|
2006
|
+
"name": "ushAmount",
|
2007
|
+
"type": "u64"
|
2008
|
+
},
|
2009
|
+
{
|
2010
|
+
"name": "overrideCurrentTime",
|
2011
|
+
"type": "i64"
|
2012
|
+
}
|
2013
|
+
]
|
1806
2014
|
}
|
1807
2015
|
],
|
1808
2016
|
"accounts": [
|
@@ -2034,6 +2242,80 @@ exports.IDL = {
|
|
2034
2242
|
]
|
2035
2243
|
}
|
2036
2244
|
},
|
2245
|
+
{
|
2246
|
+
"name": "psmAccount",
|
2247
|
+
"type": {
|
2248
|
+
"kind": "struct",
|
2249
|
+
"fields": [
|
2250
|
+
{
|
2251
|
+
"name": "collateralMint",
|
2252
|
+
"type": "publicKey"
|
2253
|
+
},
|
2254
|
+
{
|
2255
|
+
"name": "minCollateralRatio",
|
2256
|
+
"type": "u128"
|
2257
|
+
},
|
2258
|
+
{
|
2259
|
+
"name": "mintFee",
|
2260
|
+
"type": "u128"
|
2261
|
+
},
|
2262
|
+
{
|
2263
|
+
"name": "redeemFee",
|
2264
|
+
"type": "u128"
|
2265
|
+
},
|
2266
|
+
{
|
2267
|
+
"name": "totalFeesAccumulatedUsh",
|
2268
|
+
"type": "u128"
|
2269
|
+
},
|
2270
|
+
{
|
2271
|
+
"name": "totalFeesAccumulatedCollateral",
|
2272
|
+
"type": "u128"
|
2273
|
+
},
|
2274
|
+
{
|
2275
|
+
"name": "recentPrice",
|
2276
|
+
"type": "u128"
|
2277
|
+
},
|
2278
|
+
{
|
2279
|
+
"name": "debtLimit",
|
2280
|
+
"type": "u64"
|
2281
|
+
},
|
2282
|
+
{
|
2283
|
+
"name": "deposited",
|
2284
|
+
"type": "u64"
|
2285
|
+
},
|
2286
|
+
{
|
2287
|
+
"name": "amountMinted",
|
2288
|
+
"type": "u64"
|
2289
|
+
},
|
2290
|
+
{
|
2291
|
+
"name": "minSwap",
|
2292
|
+
"type": "u64"
|
2293
|
+
},
|
2294
|
+
{
|
2295
|
+
"name": "timeCreated",
|
2296
|
+
"type": "u64"
|
2297
|
+
},
|
2298
|
+
{
|
2299
|
+
"name": "timeLastInteraction",
|
2300
|
+
"type": "u64"
|
2301
|
+
},
|
2302
|
+
{
|
2303
|
+
"name": "priceLastUpdatedTimestamp",
|
2304
|
+
"type": "u64"
|
2305
|
+
},
|
2306
|
+
{
|
2307
|
+
"name": "psmStatus",
|
2308
|
+
"type": {
|
2309
|
+
"defined": "PsmStatus"
|
2310
|
+
}
|
2311
|
+
},
|
2312
|
+
{
|
2313
|
+
"name": "collateralDecimals",
|
2314
|
+
"type": "u8"
|
2315
|
+
}
|
2316
|
+
]
|
2317
|
+
}
|
2318
|
+
},
|
2037
2319
|
{
|
2038
2320
|
"name": "stakingPoolPosition",
|
2039
2321
|
"type": {
|
@@ -2611,6 +2893,26 @@ exports.IDL = {
|
|
2611
2893
|
]
|
2612
2894
|
}
|
2613
2895
|
},
|
2896
|
+
{
|
2897
|
+
"name": "PsmStatus",
|
2898
|
+
"type": {
|
2899
|
+
"kind": "enum",
|
2900
|
+
"variants": [
|
2901
|
+
{
|
2902
|
+
"name": "PsmEnabled"
|
2903
|
+
},
|
2904
|
+
{
|
2905
|
+
"name": "PsmDisabled"
|
2906
|
+
},
|
2907
|
+
{
|
2908
|
+
"name": "MintOnly"
|
2909
|
+
},
|
2910
|
+
{
|
2911
|
+
"name": "RedeemOnly"
|
2912
|
+
}
|
2913
|
+
]
|
2914
|
+
}
|
2915
|
+
},
|
2614
2916
|
{
|
2615
2917
|
"name": "SystemStatus",
|
2616
2918
|
"type": {
|
@@ -2907,26 +3209,41 @@ exports.IDL = {
|
|
2907
3209
|
},
|
2908
3210
|
{
|
2909
3211
|
"code": 6027,
|
3212
|
+
"name": "PsmDisabled",
|
3213
|
+
"msg": "PSM is currently disabled."
|
3214
|
+
},
|
3215
|
+
{
|
3216
|
+
"code": 6028,
|
3217
|
+
"name": "PsmMaxDebtReached",
|
3218
|
+
"msg": "PSM - Max Debt reached"
|
3219
|
+
},
|
3220
|
+
{
|
3221
|
+
"code": 6029,
|
3222
|
+
"name": "PsmMinSwapAmount",
|
3223
|
+
"msg": "PSM - Need more to swap"
|
3224
|
+
},
|
3225
|
+
{
|
3226
|
+
"code": 6030,
|
2910
3227
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2911
3228
|
"msg": "New Max debt extended value is less than the current debt!"
|
2912
3229
|
},
|
2913
3230
|
{
|
2914
|
-
"code":
|
3231
|
+
"code": 6031,
|
2915
3232
|
"name": "UpdateVaultTypeNoEnabledOracles",
|
2916
3233
|
"msg": "No Enabled Oracles!"
|
2917
3234
|
},
|
2918
3235
|
{
|
2919
|
-
"code":
|
3236
|
+
"code": 6032,
|
2920
3237
|
"name": "UpdateVaultTypeDuplicateOraclePriorities",
|
2921
3238
|
"msg": "Duplicate Oracle Priorities"
|
2922
3239
|
},
|
2923
3240
|
{
|
2924
|
-
"code":
|
3241
|
+
"code": 6033,
|
2925
3242
|
"name": "UpdateVaultTypeInvalidOraclePriority",
|
2926
3243
|
"msg": "Invalid Oracle Priority"
|
2927
3244
|
},
|
2928
3245
|
{
|
2929
|
-
"code":
|
3246
|
+
"code": 6034,
|
2930
3247
|
"name": "OracleUpdateFailed",
|
2931
3248
|
"msg": "OracleUpdateFailed"
|
2932
3249
|
}
|
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;
|