hedge-web3 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/idl/vault.d.ts +99 -99
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/createStakingPool.d.ts +3 -2
- package/declarations/instructions/createVault.d.ts +6 -5
- package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
- package/declarations/instructions/depositStakingPool.d.ts +3 -2
- package/declarations/instructions/depositVault.d.ts +3 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
- package/declarations/instructions/liquidateVault.d.ts +3 -2
- package/declarations/instructions/loanVault.d.ts +3 -2
- package/declarations/instructions/redeemVault.d.ts +3 -2
- package/declarations/instructions/refreshOraclePrice.d.ts +3 -2
- package/declarations/instructions/repayVault.d.ts +3 -2
- package/declarations/instructions/setHalted.d.ts +3 -2
- package/declarations/instructions/setVaultTypeStatus.d.ts +3 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
- package/lib/idl/vault.js +99 -99
- package/lib/index.js +1 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +19 -22
- package/lib/instructions/claimStakingPoolPosition.js +19 -19
- package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
- package/lib/instructions/createStakingPool.js +17 -18
- package/lib/instructions/createVault.js +28 -31
- package/lib/instructions/depositLiquidationPool.js +17 -18
- package/lib/instructions/depositStakingPool.js +16 -18
- package/lib/instructions/depositVault.js +25 -27
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +32 -33
- package/lib/instructions/loanVault.js +23 -23
- package/lib/instructions/redeemVault.js +24 -24
- package/lib/instructions/refreshOraclePrice.js +17 -17
- package/lib/instructions/repayVault.js +23 -23
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +9 -10
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +23 -23
- package/lib/state/LiquidationPoolEra.js +3 -1
- package/lib/state/LiquidationPosition.js +0 -7
- package/lib/state/StakingPool.js +3 -4
- package/lib/state/VaultAccount.js +2 -5
- package/lib/utils/getLinkedListAccounts.js +24 -16
- package/package.json +2 -2
- package/src/idl/vault.ts +198 -198
- package/src/index.ts +1 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +39 -29
- package/src/instructions/claimStakingPoolPosition.ts +45 -25
- package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
- package/src/instructions/createStakingPool.ts +37 -35
- package/src/instructions/createVault.ts +81 -125
- package/src/instructions/depositLiquidationPool.ts +45 -26
- package/src/instructions/depositStakingPool.ts +32 -24
- package/src/instructions/depositVault.ts +57 -86
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +42 -65
- package/src/instructions/loanVault.ts +51 -69
- package/src/instructions/redeemVault.ts +83 -47
- package/src/instructions/refreshOraclePrice.ts +41 -32
- package/src/instructions/repayVault.ts +45 -65
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +32 -24
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +58 -82
- package/src/state/LiquidationPoolEra.ts +4 -3
- package/src/state/LiquidationPosition.ts +0 -27
- package/src/state/StakingPool.ts +4 -7
- package/src/state/StakingPoolPosition.ts +2 -3
- package/src/state/VaultAccount.ts +9 -28
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +31 -30
package/lib/idl/vault.js
CHANGED
@@ -1800,68 +1800,6 @@ exports.IDL = {
|
|
1800
1800
|
]
|
1801
1801
|
}
|
1802
1802
|
},
|
1803
|
-
{
|
1804
|
-
"name": "stakingPool",
|
1805
|
-
"type": {
|
1806
|
-
"kind": "struct",
|
1807
|
-
"fields": [
|
1808
|
-
{
|
1809
|
-
"name": "halfLifeInDays",
|
1810
|
-
"type": "u64"
|
1811
|
-
},
|
1812
|
-
{
|
1813
|
-
"name": "deposits",
|
1814
|
-
"type": "u64"
|
1815
|
-
},
|
1816
|
-
{
|
1817
|
-
"name": "startTime",
|
1818
|
-
"type": "u64"
|
1819
|
-
},
|
1820
|
-
{
|
1821
|
-
"name": "lastTransactionTime",
|
1822
|
-
"type": "u64"
|
1823
|
-
},
|
1824
|
-
{
|
1825
|
-
"name": "hedgeRewardAccumulator",
|
1826
|
-
"type": "u128"
|
1827
|
-
},
|
1828
|
-
{
|
1829
|
-
"name": "ushFeeAccumulator",
|
1830
|
-
"type": "u128"
|
1831
|
-
},
|
1832
|
-
{
|
1833
|
-
"name": "totalHedgeReward",
|
1834
|
-
"type": "u64"
|
1835
|
-
},
|
1836
|
-
{
|
1837
|
-
"name": "stakedTokenMint",
|
1838
|
-
"type": "publicKey"
|
1839
|
-
},
|
1840
|
-
{
|
1841
|
-
"name": "seedPhrase",
|
1842
|
-
"type": {
|
1843
|
-
"array": [
|
1844
|
-
"u8",
|
1845
|
-
12
|
1846
|
-
]
|
1847
|
-
}
|
1848
|
-
},
|
1849
|
-
{
|
1850
|
-
"name": "collateralFeeAccumulator",
|
1851
|
-
"type": {
|
1852
|
-
"array": [
|
1853
|
-
"u128",
|
1854
|
-
32
|
1855
|
-
]
|
1856
|
-
}
|
1857
|
-
},
|
1858
|
-
{
|
1859
|
-
"name": "bump",
|
1860
|
-
"type": "u8"
|
1861
|
-
}
|
1862
|
-
]
|
1863
|
-
}
|
1864
|
-
},
|
1865
1803
|
{
|
1866
1804
|
"name": "stakingPoolPosition",
|
1867
1805
|
"type": {
|
@@ -1927,75 +1865,63 @@ exports.IDL = {
|
|
1927
1865
|
}
|
1928
1866
|
},
|
1929
1867
|
{
|
1930
|
-
"name": "
|
1868
|
+
"name": "stakingPool",
|
1931
1869
|
"type": {
|
1932
1870
|
"kind": "struct",
|
1933
1871
|
"fields": [
|
1934
1872
|
{
|
1935
|
-
"name": "
|
1936
|
-
"type": "publicKey"
|
1937
|
-
},
|
1938
|
-
{
|
1939
|
-
"name": "vaultNumber",
|
1873
|
+
"name": "halfLifeInDays",
|
1940
1874
|
"type": "u64"
|
1941
1875
|
},
|
1942
1876
|
{
|
1943
|
-
"name": "
|
1877
|
+
"name": "deposits",
|
1944
1878
|
"type": "u64"
|
1945
1879
|
},
|
1946
1880
|
{
|
1947
|
-
"name": "
|
1881
|
+
"name": "startTime",
|
1948
1882
|
"type": "u64"
|
1949
1883
|
},
|
1950
1884
|
{
|
1951
|
-
"name": "
|
1952
|
-
"type": "
|
1885
|
+
"name": "lastTransactionTime",
|
1886
|
+
"type": "u64"
|
1953
1887
|
},
|
1954
1888
|
{
|
1955
|
-
"name": "
|
1956
|
-
"type": "
|
1889
|
+
"name": "hedgeRewardAccumulator",
|
1890
|
+
"type": "u128"
|
1957
1891
|
},
|
1958
1892
|
{
|
1959
|
-
"name": "
|
1960
|
-
"type": "
|
1893
|
+
"name": "ushFeeAccumulator",
|
1894
|
+
"type": "u128"
|
1961
1895
|
},
|
1962
1896
|
{
|
1963
|
-
"name": "
|
1897
|
+
"name": "totalHedgeReward",
|
1964
1898
|
"type": "u64"
|
1965
1899
|
},
|
1966
1900
|
{
|
1967
|
-
"name": "
|
1968
|
-
"type": "
|
1969
|
-
},
|
1970
|
-
{
|
1971
|
-
"name": "collateralAccumulatorSnapshotBytes",
|
1972
|
-
"type": "u128"
|
1901
|
+
"name": "stakedTokenMint",
|
1902
|
+
"type": "publicKey"
|
1973
1903
|
},
|
1974
1904
|
{
|
1975
|
-
"name": "
|
1905
|
+
"name": "seedPhrase",
|
1976
1906
|
"type": {
|
1977
|
-
"
|
1907
|
+
"array": [
|
1908
|
+
"u8",
|
1909
|
+
12
|
1910
|
+
]
|
1978
1911
|
}
|
1979
1912
|
},
|
1980
1913
|
{
|
1981
|
-
"name": "
|
1914
|
+
"name": "collateralFeeAccumulator",
|
1982
1915
|
"type": {
|
1983
|
-
"
|
1916
|
+
"array": [
|
1917
|
+
"u128",
|
1918
|
+
32
|
1919
|
+
]
|
1984
1920
|
}
|
1985
1921
|
},
|
1986
1922
|
{
|
1987
|
-
"name": "
|
1988
|
-
"type": "
|
1989
|
-
},
|
1990
|
-
{
|
1991
|
-
"name": "timeLastInteraction",
|
1992
|
-
"type": "u64"
|
1993
|
-
},
|
1994
|
-
{
|
1995
|
-
"name": "nextVaultToRedeem",
|
1996
|
-
"type": {
|
1997
|
-
"option": "publicKey"
|
1998
|
-
}
|
1923
|
+
"name": "bump",
|
1924
|
+
"type": "u8"
|
1999
1925
|
}
|
2000
1926
|
]
|
2001
1927
|
}
|
@@ -2201,6 +2127,80 @@ exports.IDL = {
|
|
2201
2127
|
}
|
2202
2128
|
]
|
2203
2129
|
}
|
2130
|
+
},
|
2131
|
+
{
|
2132
|
+
"name": "vault",
|
2133
|
+
"type": {
|
2134
|
+
"kind": "struct",
|
2135
|
+
"fields": [
|
2136
|
+
{
|
2137
|
+
"name": "vaultOwner",
|
2138
|
+
"type": "publicKey"
|
2139
|
+
},
|
2140
|
+
{
|
2141
|
+
"name": "vaultNumber",
|
2142
|
+
"type": "u64"
|
2143
|
+
},
|
2144
|
+
{
|
2145
|
+
"name": "deposited",
|
2146
|
+
"type": "u64"
|
2147
|
+
},
|
2148
|
+
{
|
2149
|
+
"name": "denormalizedDebt",
|
2150
|
+
"type": "u64"
|
2151
|
+
},
|
2152
|
+
{
|
2153
|
+
"name": "collateralType",
|
2154
|
+
"type": "string"
|
2155
|
+
},
|
2156
|
+
{
|
2157
|
+
"name": "pdaSalt",
|
2158
|
+
"type": "string"
|
2159
|
+
},
|
2160
|
+
{
|
2161
|
+
"name": "bump",
|
2162
|
+
"type": "u8"
|
2163
|
+
},
|
2164
|
+
{
|
2165
|
+
"name": "vaultVersion",
|
2166
|
+
"type": "u64"
|
2167
|
+
},
|
2168
|
+
{
|
2169
|
+
"name": "debtProductSnapshotBytes",
|
2170
|
+
"type": "u128"
|
2171
|
+
},
|
2172
|
+
{
|
2173
|
+
"name": "collateralAccumulatorSnapshotBytes",
|
2174
|
+
"type": "u128"
|
2175
|
+
},
|
2176
|
+
{
|
2177
|
+
"name": "debtType",
|
2178
|
+
"type": {
|
2179
|
+
"defined": "CurrencyType"
|
2180
|
+
}
|
2181
|
+
},
|
2182
|
+
{
|
2183
|
+
"name": "vaultStatus",
|
2184
|
+
"type": {
|
2185
|
+
"defined": "VaultStatus"
|
2186
|
+
}
|
2187
|
+
},
|
2188
|
+
{
|
2189
|
+
"name": "timeCreated",
|
2190
|
+
"type": "u64"
|
2191
|
+
},
|
2192
|
+
{
|
2193
|
+
"name": "timeLastInteraction",
|
2194
|
+
"type": "u64"
|
2195
|
+
},
|
2196
|
+
{
|
2197
|
+
"name": "nextVaultToRedeem",
|
2198
|
+
"type": {
|
2199
|
+
"option": "publicKey"
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
]
|
2203
|
+
}
|
2204
2204
|
}
|
2205
2205
|
],
|
2206
2206
|
"types": [
|
package/lib/index.js
CHANGED
@@ -39,3 +39,4 @@ __exportStar(require("./state/LiquidationPoolEra"), exports);
|
|
39
39
|
__exportStar(require("./state/LiquidationPoolState"), exports);
|
40
40
|
__exportStar(require("./state/LiquidationPosition"), exports);
|
41
41
|
__exportStar(require("./utils/getLinkedListAccounts"), exports);
|
42
|
+
__exportStar(require("./idl/vault"), exports);
|
@@ -18,12 +18,12 @@ function claimLiquidationPoolPosition(program, provider, poolPosition, payer, co
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
19
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
20
20
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
21
|
-
const
|
21
|
+
const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint;
|
22
22
|
const poolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
23
|
-
const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolStatePublicKey,
|
24
|
-
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer,
|
25
|
-
const transaction = new web3_js_1.Transaction().add(yield claimLiquidationPoolPositionInstruction(program, poolStatePublicKey, poolAssociatedTokenAccount, vaultTypeAccountPublicKey,
|
26
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
23
|
+
const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolStatePublicKey, collateralMintPublicKey);
|
24
|
+
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMintPublicKey, payer.publicKey);
|
25
|
+
const transaction = new web3_js_1.Transaction().add(yield claimLiquidationPoolPositionInstruction(program, poolStatePublicKey, poolAssociatedTokenAccount, vaultTypeAccountPublicKey, collateralMintPublicKey, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address, overrideStartTime));
|
26
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
27
27
|
return payerAssociatedTokenAccount.address;
|
28
28
|
});
|
29
29
|
}
|
@@ -31,23 +31,20 @@ exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
|
|
31
31
|
function claimLiquidationPoolPositionInstruction(program, poolState, poolAssociatedTokenAccount, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
33
33
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
34
|
-
return program.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
},
|
49
|
-
signers: []
|
50
|
-
});
|
34
|
+
return yield program.methods.claimLiquidationPoolPosition().accounts({
|
35
|
+
vaultSystemState: vaultSystemState,
|
36
|
+
poolState: poolState,
|
37
|
+
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
38
|
+
vaultTypeAccount: vaultTypeAccount,
|
39
|
+
collateralMint: collateralMint,
|
40
|
+
poolPosition: poolPosition,
|
41
|
+
payer: payer,
|
42
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
43
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
44
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
45
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
46
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
47
|
+
}).instruction();
|
51
48
|
});
|
52
49
|
}
|
53
50
|
exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
|
@@ -24,7 +24,7 @@ function claimStakingPoolPosition(program, provider, poolPosition, payer, collat
|
|
24
24
|
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, feePool, true);
|
25
25
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
26
26
|
const transaction = new web3_js_1.Transaction().add(yield claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount.address, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address));
|
27
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
27
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
28
28
|
return payerAssociatedTokenAccount.address;
|
29
29
|
});
|
30
30
|
}
|
@@ -32,24 +32,24 @@ exports.claimStakingPoolPosition = claimStakingPoolPosition;
|
|
32
32
|
function claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount) {
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
34
34
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
35
|
-
return program.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
35
|
+
return yield program.methods
|
36
|
+
.claimStakingPoolPosition()
|
37
|
+
.accounts({
|
38
|
+
vaultSystemState: vaultSystemState,
|
39
|
+
feePool: feePool,
|
40
|
+
stakedTokenMint: stakedTokenMint,
|
41
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
42
|
+
vaultTypeAccount: vaultTypeAccount,
|
43
|
+
collateralMint: collateralMint,
|
44
|
+
poolPosition: poolPosition,
|
45
|
+
payer: payer,
|
46
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
47
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
48
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
49
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
50
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
51
|
+
})
|
52
|
+
.instruction();
|
53
53
|
});
|
54
54
|
}
|
55
55
|
exports.claimStakingPoolPositionInstruction = claimStakingPoolPositionInstruction;
|
@@ -26,7 +26,7 @@ function closeLiquidationPoolPosition(program, provider, poolPosition, payer, ov
|
|
26
26
|
const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
|
27
27
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
|
28
28
|
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
|
29
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
29
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
30
30
|
return poolPosition;
|
31
31
|
});
|
32
32
|
}
|
@@ -38,27 +38,27 @@ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition,
|
|
38
38
|
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
39
|
const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
40
40
|
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
41
|
-
return program.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
41
|
+
return yield program.methods
|
42
|
+
.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
43
|
+
)
|
44
|
+
.accounts({
|
45
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
46
|
+
poolState: poolState,
|
47
|
+
poolEra: poolEra,
|
48
|
+
poolPosition: poolPosition,
|
49
|
+
poolUshAccount: poolUshAccount,
|
50
|
+
payer: payerPublicKey,
|
51
|
+
ownerUshAccount: payerUshAccount,
|
52
|
+
hedgeMint: hedgeMint,
|
53
|
+
ushMint: ushMint,
|
54
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
55
|
+
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
56
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
57
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
58
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
59
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
60
|
+
})
|
61
|
+
.instruction();
|
62
62
|
});
|
63
63
|
}
|
64
64
|
exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
|
@@ -18,7 +18,7 @@ const Constants_1 = require("../Constants");
|
|
18
18
|
function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
20
|
const transaction = new web3_js_1.Transaction().add(yield createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
21
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
21
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
22
22
|
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
23
23
|
return poolPublickey;
|
24
24
|
});
|
@@ -26,28 +26,27 @@ function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensT
|
|
26
26
|
exports.createStakingPool = createStakingPool;
|
27
27
|
function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
|
-
console.log("createStakingPoolInstruction program ID", program.programId.toString());
|
30
29
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
31
30
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
32
31
|
const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
33
32
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
|
34
33
|
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
35
|
-
return program.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
return yield program.methods
|
35
|
+
.createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)))
|
36
|
+
.accounts({
|
37
|
+
signer: payerPublicKey,
|
38
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
39
|
+
pool: poolPublickey,
|
40
|
+
stakedTokenMintInfo: mintPublicKey,
|
41
|
+
ushMint: ushMintPublickey,
|
42
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
43
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
44
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
45
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
46
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
47
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
48
|
+
})
|
49
|
+
.instruction();
|
51
50
|
});
|
52
51
|
}
|
53
52
|
exports.createStakingPoolInstruction = createStakingPoolInstruction;
|
@@ -32,8 +32,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
32
32
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
33
33
|
const transaction = new web3_js_1.Transaction();
|
34
34
|
const signers = [payer, history];
|
35
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
36
|
-
serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
35
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
37
36
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
38
37
|
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
39
38
|
if (isWrappedSol) {
|
@@ -58,16 +57,15 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
58
57
|
owner: payer.publicKey,
|
59
58
|
}));
|
60
59
|
}
|
61
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers
|
60
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
62
61
|
return newVaultPublicKey;
|
63
62
|
});
|
64
63
|
}
|
65
64
|
exports.createVault = createVault;
|
66
|
-
function buildCreateVaultTransaction(program, collateralType, depositAmount, overrideTime) {
|
65
|
+
function buildCreateVaultTransaction(program, payerPublicKey, collateralType, depositAmount, overrideTime) {
|
67
66
|
return __awaiter(this, void 0, void 0, function* () {
|
68
|
-
console.log(
|
67
|
+
console.log('HEDGE SDK: buildCreateVaultTransaction');
|
69
68
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
70
|
-
const payerPublicKey = program.provider.wallet.publicKey;
|
71
69
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
72
70
|
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
73
71
|
const history = web3_js_1.Keypair.generate();
|
@@ -84,8 +82,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
84
82
|
console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString());
|
85
83
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
86
84
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo);
|
87
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
88
|
-
serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
85
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
89
86
|
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
90
87
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
91
88
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
@@ -106,7 +103,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
106
103
|
}));
|
107
104
|
signers.push(wrappedSolAccount);
|
108
105
|
}
|
109
|
-
console.log(
|
106
|
+
console.log('hedgeStakingPoolPublicKey', hedgeStakingPoolPublicKey.toString());
|
110
107
|
transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
|
111
108
|
if (isWrappedSol) {
|
112
109
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
@@ -117,7 +114,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
117
114
|
transaction.partialSign(wrappedSolAccount);
|
118
115
|
}
|
119
116
|
transaction.partialSign(history);
|
120
|
-
console.log(
|
117
|
+
console.log('transaction', transaction);
|
121
118
|
return [transaction, signers, newVaultPublicKey];
|
122
119
|
});
|
123
120
|
}
|
@@ -125,27 +122,27 @@ exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
|
125
122
|
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
|
126
123
|
return __awaiter(this, void 0, void 0, function* () {
|
127
124
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
128
|
-
const ix = program.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
125
|
+
const ix = program.methods
|
126
|
+
.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
127
|
+
)
|
128
|
+
.accounts({
|
129
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
130
|
+
vaultTypeAccount: vaultTypeAccount,
|
131
|
+
vault: vaultPublicKey,
|
132
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
133
|
+
feePool: feePool,
|
134
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
135
|
+
history: historyPublicKey,
|
136
|
+
payer: payerPublicKey,
|
137
|
+
payerTokenAccount: payerTokenAccountPublicKey,
|
138
|
+
collateralMint: collateralMint,
|
139
|
+
ushMint: ushMintPublickey,
|
140
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
141
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
142
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
143
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
144
|
+
})
|
145
|
+
.instruction();
|
149
146
|
return ix;
|
150
147
|
});
|
151
148
|
}
|
@@ -21,7 +21,7 @@ function depositLiquidationPool(program, provider, payer, depositAmount, overrid
|
|
21
21
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
22
22
|
const poolPosition = web3_js_1.Keypair.generate();
|
23
23
|
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
|
24
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]
|
24
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
|
25
25
|
return poolPosition.publicKey;
|
26
26
|
});
|
27
27
|
}
|
@@ -33,23 +33,22 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAcco
|
|
33
33
|
const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
34
34
|
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
35
35
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
|
-
return program.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
});
|
36
|
+
return yield program.methods
|
37
|
+
.depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
38
|
+
)
|
39
|
+
.accounts({
|
40
|
+
vaultSystemState: vaultSystemState,
|
41
|
+
poolState: liquidationPoolStatePublicKey,
|
42
|
+
poolUshAccount: poolUSHAccount,
|
43
|
+
poolEra: liquidationPoolState.currentEra,
|
44
|
+
poolPosition: poolPositionPublicKey,
|
45
|
+
ushMint: ushMint,
|
46
|
+
payer: payerPublicKey,
|
47
|
+
ownerUshAccount: payerUshAccount,
|
48
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
49
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
50
|
+
})
|
51
|
+
.instruction();
|
53
52
|
});
|
54
53
|
}
|
55
54
|
exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
|