@glamsystems/glam-sdk 0.1.22 → 0.1.23
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/index.cjs.js +1716 -1146
- package/index.esm.js +1709 -1149
- package/package.json +1 -1
- package/src/client/base.d.ts +39 -22
- package/src/client/drift.d.ts +36 -35
- package/src/client/investor.d.ts +10 -10
- package/src/client/jupiter.d.ts +13 -14
- package/src/client/kamino.d.ts +12 -17
- package/src/client/marinade.d.ts +10 -10
- package/src/client/meteora.d.ts +6 -6
- package/src/client/mint.d.ts +13 -21
- package/src/client/price.d.ts +8 -6
- package/src/client/staking.d.ts +20 -21
- package/src/client/state.d.ts +20 -18
- package/src/client/wsol.d.ts +5 -5
- package/src/clientConfig.d.ts +2 -0
- package/src/constants.d.ts +1 -0
- package/src/index.d.ts +1 -0
- package/src/models.d.ts +29 -6
- package/src/utils/glamPDAs.d.ts +18 -0
- package/src/utils/helpers.d.ts +1 -0
- package/target/idl/glam_protocol.json +870 -416
- package/target/types/glam_protocol.d.ts +859 -405
- package/target/types/glam_protocol.ts +869 -415
package/index.cjs.js
CHANGED
|
@@ -33,7 +33,7 @@ var borsh__namespace = /*#__PURE__*/_interopNamespaceDefault(borsh);
|
|
|
33
33
|
var address = "GLAMbTqav9N9witRjswJ8enwp9vv5G8bsSJ2kPJ4rcyc";
|
|
34
34
|
var metadata = {
|
|
35
35
|
name: "glam_protocol",
|
|
36
|
-
version: "0.4.
|
|
36
|
+
version: "0.4.20",
|
|
37
37
|
spec: "0.1.0",
|
|
38
38
|
description: "Glam Protocol"
|
|
39
39
|
};
|
|
@@ -1691,6 +1691,86 @@ var instructions = [
|
|
|
1691
1691
|
}
|
|
1692
1692
|
]
|
|
1693
1693
|
},
|
|
1694
|
+
{
|
|
1695
|
+
name: "emergency_update_mint",
|
|
1696
|
+
discriminator: [
|
|
1697
|
+
141,
|
|
1698
|
+
210,
|
|
1699
|
+
26,
|
|
1700
|
+
160,
|
|
1701
|
+
120,
|
|
1702
|
+
140,
|
|
1703
|
+
28,
|
|
1704
|
+
239
|
|
1705
|
+
],
|
|
1706
|
+
accounts: [
|
|
1707
|
+
{
|
|
1708
|
+
name: "glam_state",
|
|
1709
|
+
writable: true
|
|
1710
|
+
},
|
|
1711
|
+
{
|
|
1712
|
+
name: "glam_signer",
|
|
1713
|
+
writable: true,
|
|
1714
|
+
signer: true
|
|
1715
|
+
},
|
|
1716
|
+
{
|
|
1717
|
+
name: "glam_mint",
|
|
1718
|
+
writable: true
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
name: "token_2022_program",
|
|
1722
|
+
address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
1723
|
+
}
|
|
1724
|
+
],
|
|
1725
|
+
args: [
|
|
1726
|
+
{
|
|
1727
|
+
name: "mint_id",
|
|
1728
|
+
type: "u8"
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
name: "mint_model",
|
|
1732
|
+
type: {
|
|
1733
|
+
defined: {
|
|
1734
|
+
name: "MintModel"
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
]
|
|
1739
|
+
},
|
|
1740
|
+
{
|
|
1741
|
+
name: "emergency_update_state",
|
|
1742
|
+
discriminator: [
|
|
1743
|
+
156,
|
|
1744
|
+
211,
|
|
1745
|
+
55,
|
|
1746
|
+
70,
|
|
1747
|
+
92,
|
|
1748
|
+
37,
|
|
1749
|
+
190,
|
|
1750
|
+
66
|
|
1751
|
+
],
|
|
1752
|
+
accounts: [
|
|
1753
|
+
{
|
|
1754
|
+
name: "glam_state",
|
|
1755
|
+
writable: true
|
|
1756
|
+
},
|
|
1757
|
+
{
|
|
1758
|
+
name: "glam_signer",
|
|
1759
|
+
writable: true,
|
|
1760
|
+
signer: true
|
|
1761
|
+
}
|
|
1762
|
+
],
|
|
1763
|
+
args: [
|
|
1764
|
+
{
|
|
1765
|
+
name: "state",
|
|
1766
|
+
type: {
|
|
1767
|
+
defined: {
|
|
1768
|
+
name: "StateModel"
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
]
|
|
1773
|
+
},
|
|
1694
1774
|
{
|
|
1695
1775
|
name: "force_transfer_tokens",
|
|
1696
1776
|
discriminator: [
|
|
@@ -2377,36 +2457,6 @@ var instructions = [
|
|
|
2377
2457
|
}
|
|
2378
2458
|
]
|
|
2379
2459
|
},
|
|
2380
|
-
{
|
|
2381
|
-
name: "jupiter_set_max_swap_slippage",
|
|
2382
|
-
discriminator: [
|
|
2383
|
-
110,
|
|
2384
|
-
79,
|
|
2385
|
-
13,
|
|
2386
|
-
71,
|
|
2387
|
-
208,
|
|
2388
|
-
111,
|
|
2389
|
-
56,
|
|
2390
|
-
66
|
|
2391
|
-
],
|
|
2392
|
-
accounts: [
|
|
2393
|
-
{
|
|
2394
|
-
name: "glam_state",
|
|
2395
|
-
writable: true
|
|
2396
|
-
},
|
|
2397
|
-
{
|
|
2398
|
-
name: "glam_signer",
|
|
2399
|
-
writable: true,
|
|
2400
|
-
signer: true
|
|
2401
|
-
}
|
|
2402
|
-
],
|
|
2403
|
-
args: [
|
|
2404
|
-
{
|
|
2405
|
-
name: "slippage",
|
|
2406
|
-
type: "u64"
|
|
2407
|
-
}
|
|
2408
|
-
]
|
|
2409
|
-
},
|
|
2410
2460
|
{
|
|
2411
2461
|
name: "jupiter_swap",
|
|
2412
2462
|
discriminator: [
|
|
@@ -2827,67 +2877,6 @@ var instructions = [
|
|
|
2827
2877
|
}
|
|
2828
2878
|
]
|
|
2829
2879
|
},
|
|
2830
|
-
{
|
|
2831
|
-
name: "jupiter_vote_merge_partial_unstaking",
|
|
2832
|
-
discriminator: [
|
|
2833
|
-
93,
|
|
2834
|
-
226,
|
|
2835
|
-
122,
|
|
2836
|
-
120,
|
|
2837
|
-
130,
|
|
2838
|
-
35,
|
|
2839
|
-
189,
|
|
2840
|
-
208
|
|
2841
|
-
],
|
|
2842
|
-
accounts: [
|
|
2843
|
-
{
|
|
2844
|
-
name: "glam_state"
|
|
2845
|
-
},
|
|
2846
|
-
{
|
|
2847
|
-
name: "glam_vault",
|
|
2848
|
-
pda: {
|
|
2849
|
-
seeds: [
|
|
2850
|
-
{
|
|
2851
|
-
kind: "const",
|
|
2852
|
-
value: [
|
|
2853
|
-
118,
|
|
2854
|
-
97,
|
|
2855
|
-
117,
|
|
2856
|
-
108,
|
|
2857
|
-
116
|
|
2858
|
-
]
|
|
2859
|
-
},
|
|
2860
|
-
{
|
|
2861
|
-
kind: "account",
|
|
2862
|
-
path: "glam_state"
|
|
2863
|
-
}
|
|
2864
|
-
]
|
|
2865
|
-
}
|
|
2866
|
-
},
|
|
2867
|
-
{
|
|
2868
|
-
name: "glam_signer",
|
|
2869
|
-
writable: true,
|
|
2870
|
-
signer: true
|
|
2871
|
-
},
|
|
2872
|
-
{
|
|
2873
|
-
name: "cpi_program",
|
|
2874
|
-
address: "voTpe3tHQ7AjQHMapgSue2HJFAh2cGsdokqN3XqmVSj"
|
|
2875
|
-
},
|
|
2876
|
-
{
|
|
2877
|
-
name: "locker",
|
|
2878
|
-
writable: true
|
|
2879
|
-
},
|
|
2880
|
-
{
|
|
2881
|
-
name: "escrow",
|
|
2882
|
-
writable: true
|
|
2883
|
-
},
|
|
2884
|
-
{
|
|
2885
|
-
name: "partial_unstake",
|
|
2886
|
-
writable: true
|
|
2887
|
-
}
|
|
2888
|
-
],
|
|
2889
|
-
args: []
|
|
2890
|
-
},
|
|
2891
2880
|
{
|
|
2892
2881
|
name: "jupiter_vote_new_escrow",
|
|
2893
2882
|
discriminator: [
|
|
@@ -2954,81 +2943,6 @@ var instructions = [
|
|
|
2954
2943
|
],
|
|
2955
2944
|
args: []
|
|
2956
2945
|
},
|
|
2957
|
-
{
|
|
2958
|
-
name: "jupiter_vote_open_partial_unstaking",
|
|
2959
|
-
discriminator: [
|
|
2960
|
-
84,
|
|
2961
|
-
7,
|
|
2962
|
-
113,
|
|
2963
|
-
220,
|
|
2964
|
-
212,
|
|
2965
|
-
63,
|
|
2966
|
-
237,
|
|
2967
|
-
218
|
|
2968
|
-
],
|
|
2969
|
-
accounts: [
|
|
2970
|
-
{
|
|
2971
|
-
name: "glam_state"
|
|
2972
|
-
},
|
|
2973
|
-
{
|
|
2974
|
-
name: "glam_vault",
|
|
2975
|
-
pda: {
|
|
2976
|
-
seeds: [
|
|
2977
|
-
{
|
|
2978
|
-
kind: "const",
|
|
2979
|
-
value: [
|
|
2980
|
-
118,
|
|
2981
|
-
97,
|
|
2982
|
-
117,
|
|
2983
|
-
108,
|
|
2984
|
-
116
|
|
2985
|
-
]
|
|
2986
|
-
},
|
|
2987
|
-
{
|
|
2988
|
-
kind: "account",
|
|
2989
|
-
path: "glam_state"
|
|
2990
|
-
}
|
|
2991
|
-
]
|
|
2992
|
-
}
|
|
2993
|
-
},
|
|
2994
|
-
{
|
|
2995
|
-
name: "glam_signer",
|
|
2996
|
-
writable: true,
|
|
2997
|
-
signer: true
|
|
2998
|
-
},
|
|
2999
|
-
{
|
|
3000
|
-
name: "cpi_program",
|
|
3001
|
-
address: "voTpe3tHQ7AjQHMapgSue2HJFAh2cGsdokqN3XqmVSj"
|
|
3002
|
-
},
|
|
3003
|
-
{
|
|
3004
|
-
name: "locker",
|
|
3005
|
-
writable: true
|
|
3006
|
-
},
|
|
3007
|
-
{
|
|
3008
|
-
name: "escrow",
|
|
3009
|
-
writable: true
|
|
3010
|
-
},
|
|
3011
|
-
{
|
|
3012
|
-
name: "partial_unstake",
|
|
3013
|
-
writable: true,
|
|
3014
|
-
signer: true
|
|
3015
|
-
},
|
|
3016
|
-
{
|
|
3017
|
-
name: "system_program",
|
|
3018
|
-
address: "11111111111111111111111111111111"
|
|
3019
|
-
}
|
|
3020
|
-
],
|
|
3021
|
-
args: [
|
|
3022
|
-
{
|
|
3023
|
-
name: "amount",
|
|
3024
|
-
type: "u64"
|
|
3025
|
-
},
|
|
3026
|
-
{
|
|
3027
|
-
name: "memo",
|
|
3028
|
-
type: "string"
|
|
3029
|
-
}
|
|
3030
|
-
]
|
|
3031
|
-
},
|
|
3032
2946
|
{
|
|
3033
2947
|
name: "jupiter_vote_toggle_max_lock",
|
|
3034
2948
|
discriminator: [
|
|
@@ -3159,79 +3073,6 @@ var instructions = [
|
|
|
3159
3073
|
],
|
|
3160
3074
|
args: []
|
|
3161
3075
|
},
|
|
3162
|
-
{
|
|
3163
|
-
name: "jupiter_vote_withdraw_partial_unstaking",
|
|
3164
|
-
discriminator: [
|
|
3165
|
-
109,
|
|
3166
|
-
98,
|
|
3167
|
-
65,
|
|
3168
|
-
252,
|
|
3169
|
-
184,
|
|
3170
|
-
0,
|
|
3171
|
-
216,
|
|
3172
|
-
240
|
|
3173
|
-
],
|
|
3174
|
-
accounts: [
|
|
3175
|
-
{
|
|
3176
|
-
name: "glam_state"
|
|
3177
|
-
},
|
|
3178
|
-
{
|
|
3179
|
-
name: "glam_vault",
|
|
3180
|
-
writable: true,
|
|
3181
|
-
pda: {
|
|
3182
|
-
seeds: [
|
|
3183
|
-
{
|
|
3184
|
-
kind: "const",
|
|
3185
|
-
value: [
|
|
3186
|
-
118,
|
|
3187
|
-
97,
|
|
3188
|
-
117,
|
|
3189
|
-
108,
|
|
3190
|
-
116
|
|
3191
|
-
]
|
|
3192
|
-
},
|
|
3193
|
-
{
|
|
3194
|
-
kind: "account",
|
|
3195
|
-
path: "glam_state"
|
|
3196
|
-
}
|
|
3197
|
-
]
|
|
3198
|
-
}
|
|
3199
|
-
},
|
|
3200
|
-
{
|
|
3201
|
-
name: "glam_signer",
|
|
3202
|
-
writable: true,
|
|
3203
|
-
signer: true
|
|
3204
|
-
},
|
|
3205
|
-
{
|
|
3206
|
-
name: "cpi_program",
|
|
3207
|
-
address: "voTpe3tHQ7AjQHMapgSue2HJFAh2cGsdokqN3XqmVSj"
|
|
3208
|
-
},
|
|
3209
|
-
{
|
|
3210
|
-
name: "locker",
|
|
3211
|
-
writable: true
|
|
3212
|
-
},
|
|
3213
|
-
{
|
|
3214
|
-
name: "escrow",
|
|
3215
|
-
writable: true
|
|
3216
|
-
},
|
|
3217
|
-
{
|
|
3218
|
-
name: "partial_unstake",
|
|
3219
|
-
writable: true
|
|
3220
|
-
},
|
|
3221
|
-
{
|
|
3222
|
-
name: "escrow_tokens",
|
|
3223
|
-
writable: true
|
|
3224
|
-
},
|
|
3225
|
-
{
|
|
3226
|
-
name: "destination_tokens",
|
|
3227
|
-
writable: true
|
|
3228
|
-
},
|
|
3229
|
-
{
|
|
3230
|
-
name: "token_program"
|
|
3231
|
-
}
|
|
3232
|
-
],
|
|
3233
|
-
args: []
|
|
3234
|
-
},
|
|
3235
3076
|
{
|
|
3236
3077
|
name: "kamino_farm_harvest_reward",
|
|
3237
3078
|
discriminator: [
|
|
@@ -4097,7 +3938,8 @@ var instructions = [
|
|
|
4097
3938
|
],
|
|
4098
3939
|
accounts: [
|
|
4099
3940
|
{
|
|
4100
|
-
name: "glam_state"
|
|
3941
|
+
name: "glam_state",
|
|
3942
|
+
writable: true
|
|
4101
3943
|
},
|
|
4102
3944
|
{
|
|
4103
3945
|
name: "glam_vault",
|
|
@@ -5941,8 +5783,90 @@ var instructions = [
|
|
|
5941
5783
|
writable: true,
|
|
5942
5784
|
signer: true
|
|
5943
5785
|
},
|
|
5786
|
+
{
|
|
5787
|
+
name: "kamino_lending_program",
|
|
5788
|
+
address: "KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"
|
|
5789
|
+
},
|
|
5944
5790
|
{
|
|
5945
5791
|
name: "sol_oracle"
|
|
5792
|
+
},
|
|
5793
|
+
{
|
|
5794
|
+
name: "glam_config",
|
|
5795
|
+
pda: {
|
|
5796
|
+
seeds: [
|
|
5797
|
+
{
|
|
5798
|
+
kind: "const",
|
|
5799
|
+
value: [
|
|
5800
|
+
103,
|
|
5801
|
+
108,
|
|
5802
|
+
111,
|
|
5803
|
+
98,
|
|
5804
|
+
97,
|
|
5805
|
+
108,
|
|
5806
|
+
95,
|
|
5807
|
+
99,
|
|
5808
|
+
111,
|
|
5809
|
+
110,
|
|
5810
|
+
102,
|
|
5811
|
+
105,
|
|
5812
|
+
103
|
|
5813
|
+
]
|
|
5814
|
+
}
|
|
5815
|
+
],
|
|
5816
|
+
program: {
|
|
5817
|
+
kind: "const",
|
|
5818
|
+
value: [
|
|
5819
|
+
10,
|
|
5820
|
+
11,
|
|
5821
|
+
0,
|
|
5822
|
+
83,
|
|
5823
|
+
72,
|
|
5824
|
+
16,
|
|
5825
|
+
46,
|
|
5826
|
+
144,
|
|
5827
|
+
46,
|
|
5828
|
+
42,
|
|
5829
|
+
79,
|
|
5830
|
+
22,
|
|
5831
|
+
157,
|
|
5832
|
+
123,
|
|
5833
|
+
21,
|
|
5834
|
+
242,
|
|
5835
|
+
192,
|
|
5836
|
+
146,
|
|
5837
|
+
1,
|
|
5838
|
+
78,
|
|
5839
|
+
88,
|
|
5840
|
+
59,
|
|
5841
|
+
102,
|
|
5842
|
+
9,
|
|
5843
|
+
190,
|
|
5844
|
+
226,
|
|
5845
|
+
92,
|
|
5846
|
+
189,
|
|
5847
|
+
187,
|
|
5848
|
+
232,
|
|
5849
|
+
83,
|
|
5850
|
+
220
|
|
5851
|
+
]
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
},
|
|
5855
|
+
{
|
|
5856
|
+
name: "pyth_oracle",
|
|
5857
|
+
optional: true
|
|
5858
|
+
},
|
|
5859
|
+
{
|
|
5860
|
+
name: "switchboard_price_oracle",
|
|
5861
|
+
optional: true
|
|
5862
|
+
},
|
|
5863
|
+
{
|
|
5864
|
+
name: "switchboard_twap_oracle",
|
|
5865
|
+
optional: true
|
|
5866
|
+
},
|
|
5867
|
+
{
|
|
5868
|
+
name: "scope_prices",
|
|
5869
|
+
optional: true
|
|
5946
5870
|
}
|
|
5947
5871
|
],
|
|
5948
5872
|
args: [
|
|
@@ -6001,6 +5925,68 @@ var instructions = [
|
|
|
6001
5925
|
},
|
|
6002
5926
|
{
|
|
6003
5927
|
name: "sol_oracle"
|
|
5928
|
+
},
|
|
5929
|
+
{
|
|
5930
|
+
name: "glam_config",
|
|
5931
|
+
pda: {
|
|
5932
|
+
seeds: [
|
|
5933
|
+
{
|
|
5934
|
+
kind: "const",
|
|
5935
|
+
value: [
|
|
5936
|
+
103,
|
|
5937
|
+
108,
|
|
5938
|
+
111,
|
|
5939
|
+
98,
|
|
5940
|
+
97,
|
|
5941
|
+
108,
|
|
5942
|
+
95,
|
|
5943
|
+
99,
|
|
5944
|
+
111,
|
|
5945
|
+
110,
|
|
5946
|
+
102,
|
|
5947
|
+
105,
|
|
5948
|
+
103
|
|
5949
|
+
]
|
|
5950
|
+
}
|
|
5951
|
+
],
|
|
5952
|
+
program: {
|
|
5953
|
+
kind: "const",
|
|
5954
|
+
value: [
|
|
5955
|
+
10,
|
|
5956
|
+
11,
|
|
5957
|
+
0,
|
|
5958
|
+
83,
|
|
5959
|
+
72,
|
|
5960
|
+
16,
|
|
5961
|
+
46,
|
|
5962
|
+
144,
|
|
5963
|
+
46,
|
|
5964
|
+
42,
|
|
5965
|
+
79,
|
|
5966
|
+
22,
|
|
5967
|
+
157,
|
|
5968
|
+
123,
|
|
5969
|
+
21,
|
|
5970
|
+
242,
|
|
5971
|
+
192,
|
|
5972
|
+
146,
|
|
5973
|
+
1,
|
|
5974
|
+
78,
|
|
5975
|
+
88,
|
|
5976
|
+
59,
|
|
5977
|
+
102,
|
|
5978
|
+
9,
|
|
5979
|
+
190,
|
|
5980
|
+
226,
|
|
5981
|
+
92,
|
|
5982
|
+
189,
|
|
5983
|
+
187,
|
|
5984
|
+
232,
|
|
5985
|
+
83,
|
|
5986
|
+
220
|
|
5987
|
+
]
|
|
5988
|
+
}
|
|
5989
|
+
}
|
|
6004
5990
|
}
|
|
6005
5991
|
],
|
|
6006
5992
|
args: [
|
|
@@ -6051,14 +6037,76 @@ var instructions = [
|
|
|
6051
6037
|
}
|
|
6052
6038
|
]
|
|
6053
6039
|
}
|
|
6054
|
-
},
|
|
6055
|
-
{
|
|
6056
|
-
name: "glam_signer",
|
|
6057
|
-
writable: true,
|
|
6058
|
-
signer: true
|
|
6059
|
-
},
|
|
6060
|
-
{
|
|
6061
|
-
name: "sol_oracle"
|
|
6040
|
+
},
|
|
6041
|
+
{
|
|
6042
|
+
name: "glam_signer",
|
|
6043
|
+
writable: true,
|
|
6044
|
+
signer: true
|
|
6045
|
+
},
|
|
6046
|
+
{
|
|
6047
|
+
name: "sol_oracle"
|
|
6048
|
+
},
|
|
6049
|
+
{
|
|
6050
|
+
name: "glam_config",
|
|
6051
|
+
pda: {
|
|
6052
|
+
seeds: [
|
|
6053
|
+
{
|
|
6054
|
+
kind: "const",
|
|
6055
|
+
value: [
|
|
6056
|
+
103,
|
|
6057
|
+
108,
|
|
6058
|
+
111,
|
|
6059
|
+
98,
|
|
6060
|
+
97,
|
|
6061
|
+
108,
|
|
6062
|
+
95,
|
|
6063
|
+
99,
|
|
6064
|
+
111,
|
|
6065
|
+
110,
|
|
6066
|
+
102,
|
|
6067
|
+
105,
|
|
6068
|
+
103
|
|
6069
|
+
]
|
|
6070
|
+
}
|
|
6071
|
+
],
|
|
6072
|
+
program: {
|
|
6073
|
+
kind: "const",
|
|
6074
|
+
value: [
|
|
6075
|
+
10,
|
|
6076
|
+
11,
|
|
6077
|
+
0,
|
|
6078
|
+
83,
|
|
6079
|
+
72,
|
|
6080
|
+
16,
|
|
6081
|
+
46,
|
|
6082
|
+
144,
|
|
6083
|
+
46,
|
|
6084
|
+
42,
|
|
6085
|
+
79,
|
|
6086
|
+
22,
|
|
6087
|
+
157,
|
|
6088
|
+
123,
|
|
6089
|
+
21,
|
|
6090
|
+
242,
|
|
6091
|
+
192,
|
|
6092
|
+
146,
|
|
6093
|
+
1,
|
|
6094
|
+
78,
|
|
6095
|
+
88,
|
|
6096
|
+
59,
|
|
6097
|
+
102,
|
|
6098
|
+
9,
|
|
6099
|
+
190,
|
|
6100
|
+
226,
|
|
6101
|
+
92,
|
|
6102
|
+
189,
|
|
6103
|
+
187,
|
|
6104
|
+
232,
|
|
6105
|
+
83,
|
|
6106
|
+
220
|
|
6107
|
+
]
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6062
6110
|
}
|
|
6063
6111
|
],
|
|
6064
6112
|
args: [
|
|
@@ -6117,6 +6165,68 @@ var instructions = [
|
|
|
6117
6165
|
},
|
|
6118
6166
|
{
|
|
6119
6167
|
name: "sol_oracle"
|
|
6168
|
+
},
|
|
6169
|
+
{
|
|
6170
|
+
name: "glam_config",
|
|
6171
|
+
pda: {
|
|
6172
|
+
seeds: [
|
|
6173
|
+
{
|
|
6174
|
+
kind: "const",
|
|
6175
|
+
value: [
|
|
6176
|
+
103,
|
|
6177
|
+
108,
|
|
6178
|
+
111,
|
|
6179
|
+
98,
|
|
6180
|
+
97,
|
|
6181
|
+
108,
|
|
6182
|
+
95,
|
|
6183
|
+
99,
|
|
6184
|
+
111,
|
|
6185
|
+
110,
|
|
6186
|
+
102,
|
|
6187
|
+
105,
|
|
6188
|
+
103
|
|
6189
|
+
]
|
|
6190
|
+
}
|
|
6191
|
+
],
|
|
6192
|
+
program: {
|
|
6193
|
+
kind: "const",
|
|
6194
|
+
value: [
|
|
6195
|
+
10,
|
|
6196
|
+
11,
|
|
6197
|
+
0,
|
|
6198
|
+
83,
|
|
6199
|
+
72,
|
|
6200
|
+
16,
|
|
6201
|
+
46,
|
|
6202
|
+
144,
|
|
6203
|
+
46,
|
|
6204
|
+
42,
|
|
6205
|
+
79,
|
|
6206
|
+
22,
|
|
6207
|
+
157,
|
|
6208
|
+
123,
|
|
6209
|
+
21,
|
|
6210
|
+
242,
|
|
6211
|
+
192,
|
|
6212
|
+
146,
|
|
6213
|
+
1,
|
|
6214
|
+
78,
|
|
6215
|
+
88,
|
|
6216
|
+
59,
|
|
6217
|
+
102,
|
|
6218
|
+
9,
|
|
6219
|
+
190,
|
|
6220
|
+
226,
|
|
6221
|
+
92,
|
|
6222
|
+
189,
|
|
6223
|
+
187,
|
|
6224
|
+
232,
|
|
6225
|
+
83,
|
|
6226
|
+
220
|
|
6227
|
+
]
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
6120
6230
|
}
|
|
6121
6231
|
],
|
|
6122
6232
|
args: [
|
|
@@ -6175,6 +6285,68 @@ var instructions = [
|
|
|
6175
6285
|
},
|
|
6176
6286
|
{
|
|
6177
6287
|
name: "sol_oracle"
|
|
6288
|
+
},
|
|
6289
|
+
{
|
|
6290
|
+
name: "glam_config",
|
|
6291
|
+
pda: {
|
|
6292
|
+
seeds: [
|
|
6293
|
+
{
|
|
6294
|
+
kind: "const",
|
|
6295
|
+
value: [
|
|
6296
|
+
103,
|
|
6297
|
+
108,
|
|
6298
|
+
111,
|
|
6299
|
+
98,
|
|
6300
|
+
97,
|
|
6301
|
+
108,
|
|
6302
|
+
95,
|
|
6303
|
+
99,
|
|
6304
|
+
111,
|
|
6305
|
+
110,
|
|
6306
|
+
102,
|
|
6307
|
+
105,
|
|
6308
|
+
103
|
|
6309
|
+
]
|
|
6310
|
+
}
|
|
6311
|
+
],
|
|
6312
|
+
program: {
|
|
6313
|
+
kind: "const",
|
|
6314
|
+
value: [
|
|
6315
|
+
10,
|
|
6316
|
+
11,
|
|
6317
|
+
0,
|
|
6318
|
+
83,
|
|
6319
|
+
72,
|
|
6320
|
+
16,
|
|
6321
|
+
46,
|
|
6322
|
+
144,
|
|
6323
|
+
46,
|
|
6324
|
+
42,
|
|
6325
|
+
79,
|
|
6326
|
+
22,
|
|
6327
|
+
157,
|
|
6328
|
+
123,
|
|
6329
|
+
21,
|
|
6330
|
+
242,
|
|
6331
|
+
192,
|
|
6332
|
+
146,
|
|
6333
|
+
1,
|
|
6334
|
+
78,
|
|
6335
|
+
88,
|
|
6336
|
+
59,
|
|
6337
|
+
102,
|
|
6338
|
+
9,
|
|
6339
|
+
190,
|
|
6340
|
+
226,
|
|
6341
|
+
92,
|
|
6342
|
+
189,
|
|
6343
|
+
187,
|
|
6344
|
+
232,
|
|
6345
|
+
83,
|
|
6346
|
+
220
|
|
6347
|
+
]
|
|
6348
|
+
}
|
|
6349
|
+
}
|
|
6178
6350
|
}
|
|
6179
6351
|
],
|
|
6180
6352
|
args: [
|
|
@@ -6625,80 +6797,6 @@ var instructions = [
|
|
|
6625
6797
|
}
|
|
6626
6798
|
]
|
|
6627
6799
|
},
|
|
6628
|
-
{
|
|
6629
|
-
name: "set_redemption_paused",
|
|
6630
|
-
discriminator: [
|
|
6631
|
-
226,
|
|
6632
|
-
152,
|
|
6633
|
-
104,
|
|
6634
|
-
42,
|
|
6635
|
-
1,
|
|
6636
|
-
53,
|
|
6637
|
-
196,
|
|
6638
|
-
240
|
|
6639
|
-
],
|
|
6640
|
-
accounts: [
|
|
6641
|
-
{
|
|
6642
|
-
name: "glam_state",
|
|
6643
|
-
writable: true
|
|
6644
|
-
},
|
|
6645
|
-
{
|
|
6646
|
-
name: "glam_mint"
|
|
6647
|
-
},
|
|
6648
|
-
{
|
|
6649
|
-
name: "glam_signer",
|
|
6650
|
-
writable: true,
|
|
6651
|
-
signer: true
|
|
6652
|
-
}
|
|
6653
|
-
],
|
|
6654
|
-
args: [
|
|
6655
|
-
{
|
|
6656
|
-
name: "mint_id",
|
|
6657
|
-
type: "u8"
|
|
6658
|
-
},
|
|
6659
|
-
{
|
|
6660
|
-
name: "paused",
|
|
6661
|
-
type: "bool"
|
|
6662
|
-
}
|
|
6663
|
-
]
|
|
6664
|
-
},
|
|
6665
|
-
{
|
|
6666
|
-
name: "set_subscription_paused",
|
|
6667
|
-
discriminator: [
|
|
6668
|
-
220,
|
|
6669
|
-
144,
|
|
6670
|
-
129,
|
|
6671
|
-
4,
|
|
6672
|
-
136,
|
|
6673
|
-
251,
|
|
6674
|
-
85,
|
|
6675
|
-
234
|
|
6676
|
-
],
|
|
6677
|
-
accounts: [
|
|
6678
|
-
{
|
|
6679
|
-
name: "glam_state",
|
|
6680
|
-
writable: true
|
|
6681
|
-
},
|
|
6682
|
-
{
|
|
6683
|
-
name: "glam_mint"
|
|
6684
|
-
},
|
|
6685
|
-
{
|
|
6686
|
-
name: "glam_signer",
|
|
6687
|
-
writable: true,
|
|
6688
|
-
signer: true
|
|
6689
|
-
}
|
|
6690
|
-
],
|
|
6691
|
-
args: [
|
|
6692
|
-
{
|
|
6693
|
-
name: "mint_id",
|
|
6694
|
-
type: "u8"
|
|
6695
|
-
},
|
|
6696
|
-
{
|
|
6697
|
-
name: "paused",
|
|
6698
|
-
type: "bool"
|
|
6699
|
-
}
|
|
6700
|
-
]
|
|
6701
|
-
},
|
|
6702
6800
|
{
|
|
6703
6801
|
name: "set_token_accounts_states",
|
|
6704
6802
|
discriminator: [
|
|
@@ -8867,6 +8965,44 @@ var instructions = [
|
|
|
8867
8965
|
}
|
|
8868
8966
|
]
|
|
8869
8967
|
},
|
|
8968
|
+
{
|
|
8969
|
+
name: "update_mint_apply_timelock",
|
|
8970
|
+
discriminator: [
|
|
8971
|
+
223,
|
|
8972
|
+
241,
|
|
8973
|
+
80,
|
|
8974
|
+
24,
|
|
8975
|
+
120,
|
|
8976
|
+
25,
|
|
8977
|
+
82,
|
|
8978
|
+
134
|
|
8979
|
+
],
|
|
8980
|
+
accounts: [
|
|
8981
|
+
{
|
|
8982
|
+
name: "glam_state",
|
|
8983
|
+
writable: true
|
|
8984
|
+
},
|
|
8985
|
+
{
|
|
8986
|
+
name: "glam_signer",
|
|
8987
|
+
writable: true,
|
|
8988
|
+
signer: true
|
|
8989
|
+
},
|
|
8990
|
+
{
|
|
8991
|
+
name: "glam_mint",
|
|
8992
|
+
writable: true
|
|
8993
|
+
},
|
|
8994
|
+
{
|
|
8995
|
+
name: "token_2022_program",
|
|
8996
|
+
address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
8997
|
+
}
|
|
8998
|
+
],
|
|
8999
|
+
args: [
|
|
9000
|
+
{
|
|
9001
|
+
name: "mint_id",
|
|
9002
|
+
type: "u8"
|
|
9003
|
+
}
|
|
9004
|
+
]
|
|
9005
|
+
},
|
|
8870
9006
|
{
|
|
8871
9007
|
name: "update_state",
|
|
8872
9008
|
discriminator: [
|
|
@@ -8901,6 +9037,31 @@ var instructions = [
|
|
|
8901
9037
|
}
|
|
8902
9038
|
]
|
|
8903
9039
|
},
|
|
9040
|
+
{
|
|
9041
|
+
name: "update_state_apply_timelock",
|
|
9042
|
+
discriminator: [
|
|
9043
|
+
66,
|
|
9044
|
+
12,
|
|
9045
|
+
138,
|
|
9046
|
+
80,
|
|
9047
|
+
133,
|
|
9048
|
+
85,
|
|
9049
|
+
46,
|
|
9050
|
+
220
|
|
9051
|
+
],
|
|
9052
|
+
accounts: [
|
|
9053
|
+
{
|
|
9054
|
+
name: "glam_state",
|
|
9055
|
+
writable: true
|
|
9056
|
+
},
|
|
9057
|
+
{
|
|
9058
|
+
name: "glam_signer",
|
|
9059
|
+
writable: true,
|
|
9060
|
+
signer: true
|
|
9061
|
+
}
|
|
9062
|
+
],
|
|
9063
|
+
args: []
|
|
9064
|
+
},
|
|
8904
9065
|
{
|
|
8905
9066
|
name: "withdraw",
|
|
8906
9067
|
discriminator: [
|
|
@@ -9075,6 +9236,19 @@ var instructions = [
|
|
|
9075
9236
|
}
|
|
9076
9237
|
];
|
|
9077
9238
|
var accounts = [
|
|
9239
|
+
{
|
|
9240
|
+
name: "GlobalConfig",
|
|
9241
|
+
discriminator: [
|
|
9242
|
+
149,
|
|
9243
|
+
8,
|
|
9244
|
+
156,
|
|
9245
|
+
202,
|
|
9246
|
+
160,
|
|
9247
|
+
252,
|
|
9248
|
+
176,
|
|
9249
|
+
217
|
|
9250
|
+
]
|
|
9251
|
+
},
|
|
9078
9252
|
{
|
|
9079
9253
|
name: "OpenfundsMetadataAccount",
|
|
9080
9254
|
discriminator: [
|
|
@@ -9115,14 +9289,24 @@ var errors = [
|
|
|
9115
9289
|
},
|
|
9116
9290
|
{
|
|
9117
9291
|
code: 48002,
|
|
9118
|
-
name: "
|
|
9119
|
-
msg: "
|
|
9292
|
+
name: "GlamStateDisabled",
|
|
9293
|
+
msg: "GLAM state is disabled"
|
|
9120
9294
|
},
|
|
9121
9295
|
{
|
|
9122
9296
|
code: 48003,
|
|
9123
9297
|
name: "InvalidSignerAccount",
|
|
9124
9298
|
msg: "Invalid signer token account"
|
|
9125
9299
|
},
|
|
9300
|
+
{
|
|
9301
|
+
code: 48004,
|
|
9302
|
+
name: "EmergencyUpdateDenied",
|
|
9303
|
+
msg: "Emergency update denied"
|
|
9304
|
+
},
|
|
9305
|
+
{
|
|
9306
|
+
code: 48005,
|
|
9307
|
+
name: "TimelockStillActive",
|
|
9308
|
+
msg: "Timelock still active"
|
|
9309
|
+
},
|
|
9126
9310
|
{
|
|
9127
9311
|
code: 49000,
|
|
9128
9312
|
name: "InvalidAccountType",
|
|
@@ -9268,6 +9452,11 @@ var errors = [
|
|
|
9268
9452
|
name: "InvalidAmount",
|
|
9269
9453
|
msg: "Invalid amount for subscription or redemption"
|
|
9270
9454
|
},
|
|
9455
|
+
{
|
|
9456
|
+
code: 51007,
|
|
9457
|
+
name: "MaxCapExceeded",
|
|
9458
|
+
msg: "Max cap exceeded"
|
|
9459
|
+
},
|
|
9271
9460
|
{
|
|
9272
9461
|
code: 51100,
|
|
9273
9462
|
name: "InvalidPricingOracle",
|
|
@@ -9430,6 +9619,34 @@ var types = [
|
|
|
9430
9619
|
]
|
|
9431
9620
|
}
|
|
9432
9621
|
},
|
|
9622
|
+
{
|
|
9623
|
+
name: "AssetMeta",
|
|
9624
|
+
type: {
|
|
9625
|
+
kind: "struct",
|
|
9626
|
+
fields: [
|
|
9627
|
+
{
|
|
9628
|
+
name: "asset",
|
|
9629
|
+
type: "pubkey"
|
|
9630
|
+
},
|
|
9631
|
+
{
|
|
9632
|
+
name: "decimals",
|
|
9633
|
+
type: "u8"
|
|
9634
|
+
},
|
|
9635
|
+
{
|
|
9636
|
+
name: "oracle",
|
|
9637
|
+
type: "pubkey"
|
|
9638
|
+
},
|
|
9639
|
+
{
|
|
9640
|
+
name: "oracle_source",
|
|
9641
|
+
type: {
|
|
9642
|
+
defined: {
|
|
9643
|
+
name: "OracleSource"
|
|
9644
|
+
}
|
|
9645
|
+
}
|
|
9646
|
+
}
|
|
9647
|
+
]
|
|
9648
|
+
}
|
|
9649
|
+
},
|
|
9433
9650
|
{
|
|
9434
9651
|
name: "BinLiquidityDistribution",
|
|
9435
9652
|
type: {
|
|
@@ -9731,7 +9948,7 @@ var types = [
|
|
|
9731
9948
|
name: "ExternalVaultAccounts"
|
|
9732
9949
|
},
|
|
9733
9950
|
{
|
|
9734
|
-
name: "
|
|
9951
|
+
name: "LockUpPeriod"
|
|
9735
9952
|
},
|
|
9736
9953
|
{
|
|
9737
9954
|
name: "DriftMarketIndexesPerp"
|
|
@@ -9764,7 +9981,7 @@ var types = [
|
|
|
9764
9981
|
name: "MinRedemption"
|
|
9765
9982
|
},
|
|
9766
9983
|
{
|
|
9767
|
-
name: "
|
|
9984
|
+
name: "NotifyAndSettle"
|
|
9768
9985
|
},
|
|
9769
9986
|
{
|
|
9770
9987
|
name: "Ledger"
|
|
@@ -9785,7 +10002,49 @@ var types = [
|
|
|
9785
10002
|
name: "SubscriptionPaused"
|
|
9786
10003
|
},
|
|
9787
10004
|
{
|
|
9788
|
-
name: "RedemptionPaused"
|
|
10005
|
+
name: "RedemptionPaused"
|
|
10006
|
+
},
|
|
10007
|
+
{
|
|
10008
|
+
name: "Owner"
|
|
10009
|
+
},
|
|
10010
|
+
{
|
|
10011
|
+
name: "Enabled"
|
|
10012
|
+
},
|
|
10013
|
+
{
|
|
10014
|
+
name: "Name"
|
|
10015
|
+
},
|
|
10016
|
+
{
|
|
10017
|
+
name: "Uri"
|
|
10018
|
+
},
|
|
10019
|
+
{
|
|
10020
|
+
name: "Assets"
|
|
10021
|
+
},
|
|
10022
|
+
{
|
|
10023
|
+
name: "DelegateAcls"
|
|
10024
|
+
},
|
|
10025
|
+
{
|
|
10026
|
+
name: "Integrations"
|
|
10027
|
+
},
|
|
10028
|
+
{
|
|
10029
|
+
name: "UpdateTimelock"
|
|
10030
|
+
},
|
|
10031
|
+
{
|
|
10032
|
+
name: "TimelockExpiresAt"
|
|
10033
|
+
},
|
|
10034
|
+
{
|
|
10035
|
+
name: "DefaultAccountStateFrozen"
|
|
10036
|
+
},
|
|
10037
|
+
{
|
|
10038
|
+
name: "PermanentDelegate"
|
|
10039
|
+
},
|
|
10040
|
+
{
|
|
10041
|
+
name: "TimeUnit"
|
|
10042
|
+
},
|
|
10043
|
+
{
|
|
10044
|
+
name: "KaminoLendingMarkets"
|
|
10045
|
+
},
|
|
10046
|
+
{
|
|
10047
|
+
name: "MeteoraDlmmPools"
|
|
9789
10048
|
}
|
|
9790
10049
|
]
|
|
9791
10050
|
}
|
|
@@ -9877,7 +10136,7 @@ var types = [
|
|
|
9877
10136
|
]
|
|
9878
10137
|
},
|
|
9879
10138
|
{
|
|
9880
|
-
name: "
|
|
10139
|
+
name: "U32",
|
|
9881
10140
|
fields: [
|
|
9882
10141
|
{
|
|
9883
10142
|
name: "val",
|
|
@@ -9995,13 +10254,56 @@ var types = [
|
|
|
9995
10254
|
]
|
|
9996
10255
|
},
|
|
9997
10256
|
{
|
|
9998
|
-
name: "
|
|
10257
|
+
name: "NotifyAndSettle",
|
|
10258
|
+
fields: [
|
|
10259
|
+
{
|
|
10260
|
+
name: "val",
|
|
10261
|
+
type: {
|
|
10262
|
+
defined: {
|
|
10263
|
+
name: "NotifyAndSettle"
|
|
10264
|
+
}
|
|
10265
|
+
}
|
|
10266
|
+
}
|
|
10267
|
+
]
|
|
10268
|
+
},
|
|
10269
|
+
{
|
|
10270
|
+
name: "VecDelegateAcl",
|
|
10271
|
+
fields: [
|
|
10272
|
+
{
|
|
10273
|
+
name: "val",
|
|
10274
|
+
type: {
|
|
10275
|
+
vec: {
|
|
10276
|
+
defined: {
|
|
10277
|
+
name: "DelegateAcl"
|
|
10278
|
+
}
|
|
10279
|
+
}
|
|
10280
|
+
}
|
|
10281
|
+
}
|
|
10282
|
+
]
|
|
10283
|
+
},
|
|
10284
|
+
{
|
|
10285
|
+
name: "VecIntegration",
|
|
10286
|
+
fields: [
|
|
10287
|
+
{
|
|
10288
|
+
name: "val",
|
|
10289
|
+
type: {
|
|
10290
|
+
vec: {
|
|
10291
|
+
defined: {
|
|
10292
|
+
name: "Integration"
|
|
10293
|
+
}
|
|
10294
|
+
}
|
|
10295
|
+
}
|
|
10296
|
+
}
|
|
10297
|
+
]
|
|
10298
|
+
},
|
|
10299
|
+
{
|
|
10300
|
+
name: "TimeUnit",
|
|
9999
10301
|
fields: [
|
|
10000
10302
|
{
|
|
10001
10303
|
name: "val",
|
|
10002
10304
|
type: {
|
|
10003
10305
|
defined: {
|
|
10004
|
-
name: "
|
|
10306
|
+
name: "TimeUnit"
|
|
10005
10307
|
}
|
|
10006
10308
|
}
|
|
10007
10309
|
}
|
|
@@ -10417,6 +10719,51 @@ var types = [
|
|
|
10417
10719
|
]
|
|
10418
10720
|
}
|
|
10419
10721
|
},
|
|
10722
|
+
{
|
|
10723
|
+
name: "GlobalConfig",
|
|
10724
|
+
type: {
|
|
10725
|
+
kind: "struct",
|
|
10726
|
+
fields: [
|
|
10727
|
+
{
|
|
10728
|
+
name: "admin",
|
|
10729
|
+
docs: [
|
|
10730
|
+
"The authority that can modify the config"
|
|
10731
|
+
],
|
|
10732
|
+
type: "pubkey"
|
|
10733
|
+
},
|
|
10734
|
+
{
|
|
10735
|
+
name: "fee_authority",
|
|
10736
|
+
docs: [
|
|
10737
|
+
"The authority that can modify fee structure of individual glam state",
|
|
10738
|
+
"and claim protocol fees"
|
|
10739
|
+
],
|
|
10740
|
+
type: "pubkey"
|
|
10741
|
+
},
|
|
10742
|
+
{
|
|
10743
|
+
name: "referrer",
|
|
10744
|
+
type: "pubkey"
|
|
10745
|
+
},
|
|
10746
|
+
{
|
|
10747
|
+
name: "base_fee_bps",
|
|
10748
|
+
type: "u16"
|
|
10749
|
+
},
|
|
10750
|
+
{
|
|
10751
|
+
name: "flow_fee_bps",
|
|
10752
|
+
type: "u16"
|
|
10753
|
+
},
|
|
10754
|
+
{
|
|
10755
|
+
name: "asset_metas",
|
|
10756
|
+
type: {
|
|
10757
|
+
vec: {
|
|
10758
|
+
defined: {
|
|
10759
|
+
name: "AssetMeta"
|
|
10760
|
+
}
|
|
10761
|
+
}
|
|
10762
|
+
}
|
|
10763
|
+
}
|
|
10764
|
+
]
|
|
10765
|
+
}
|
|
10766
|
+
},
|
|
10420
10767
|
{
|
|
10421
10768
|
name: "HurdleType",
|
|
10422
10769
|
type: {
|
|
@@ -10775,9 +11122,15 @@ var types = [
|
|
|
10775
11122
|
}
|
|
10776
11123
|
},
|
|
10777
11124
|
{
|
|
10778
|
-
name: "
|
|
11125
|
+
name: "lock_up_period",
|
|
10779
11126
|
type: {
|
|
10780
|
-
option: "
|
|
11127
|
+
option: "u32"
|
|
11128
|
+
}
|
|
11129
|
+
},
|
|
11130
|
+
{
|
|
11131
|
+
name: "year_in_seconds",
|
|
11132
|
+
type: {
|
|
11133
|
+
option: "u32"
|
|
10781
11134
|
}
|
|
10782
11135
|
},
|
|
10783
11136
|
{
|
|
@@ -10803,23 +11156,19 @@ var types = [
|
|
|
10803
11156
|
}
|
|
10804
11157
|
},
|
|
10805
11158
|
{
|
|
10806
|
-
name: "
|
|
11159
|
+
name: "notify_and_settle",
|
|
10807
11160
|
type: {
|
|
10808
11161
|
option: {
|
|
10809
11162
|
defined: {
|
|
10810
|
-
name: "
|
|
11163
|
+
name: "NotifyAndSettle"
|
|
10811
11164
|
}
|
|
10812
11165
|
}
|
|
10813
11166
|
}
|
|
10814
11167
|
},
|
|
10815
11168
|
{
|
|
10816
|
-
name: "
|
|
11169
|
+
name: "max_cap",
|
|
10817
11170
|
type: {
|
|
10818
|
-
option:
|
|
10819
|
-
defined: {
|
|
10820
|
-
name: "Valuation"
|
|
10821
|
-
}
|
|
10822
|
-
}
|
|
11171
|
+
option: "u64"
|
|
10823
11172
|
}
|
|
10824
11173
|
},
|
|
10825
11174
|
{
|
|
@@ -10834,6 +11183,18 @@ var types = [
|
|
|
10834
11183
|
option: "u64"
|
|
10835
11184
|
}
|
|
10836
11185
|
},
|
|
11186
|
+
{
|
|
11187
|
+
name: "subscription_paused",
|
|
11188
|
+
type: {
|
|
11189
|
+
option: "bool"
|
|
11190
|
+
}
|
|
11191
|
+
},
|
|
11192
|
+
{
|
|
11193
|
+
name: "redemption_paused",
|
|
11194
|
+
type: {
|
|
11195
|
+
option: "bool"
|
|
11196
|
+
}
|
|
11197
|
+
},
|
|
10837
11198
|
{
|
|
10838
11199
|
name: "is_raw_openfunds",
|
|
10839
11200
|
type: {
|
|
@@ -11123,6 +11484,50 @@ var types = [
|
|
|
11123
11484
|
]
|
|
11124
11485
|
}
|
|
11125
11486
|
},
|
|
11487
|
+
{
|
|
11488
|
+
name: "NotifyAndSettle",
|
|
11489
|
+
type: {
|
|
11490
|
+
kind: "struct",
|
|
11491
|
+
fields: [
|
|
11492
|
+
{
|
|
11493
|
+
name: "model",
|
|
11494
|
+
type: {
|
|
11495
|
+
defined: {
|
|
11496
|
+
name: "ValuationModel"
|
|
11497
|
+
}
|
|
11498
|
+
}
|
|
11499
|
+
},
|
|
11500
|
+
{
|
|
11501
|
+
name: "notice_period",
|
|
11502
|
+
type: "u64"
|
|
11503
|
+
},
|
|
11504
|
+
{
|
|
11505
|
+
name: "notice_period_type",
|
|
11506
|
+
type: {
|
|
11507
|
+
defined: {
|
|
11508
|
+
name: "NoticePeriodType"
|
|
11509
|
+
}
|
|
11510
|
+
}
|
|
11511
|
+
},
|
|
11512
|
+
{
|
|
11513
|
+
name: "permissionless_fulfillment",
|
|
11514
|
+
type: "bool"
|
|
11515
|
+
},
|
|
11516
|
+
{
|
|
11517
|
+
name: "settlement_period",
|
|
11518
|
+
type: "u64"
|
|
11519
|
+
},
|
|
11520
|
+
{
|
|
11521
|
+
name: "cancellation_window",
|
|
11522
|
+
type: "u64"
|
|
11523
|
+
},
|
|
11524
|
+
{
|
|
11525
|
+
name: "_padding",
|
|
11526
|
+
type: "u8"
|
|
11527
|
+
}
|
|
11528
|
+
]
|
|
11529
|
+
}
|
|
11530
|
+
},
|
|
11126
11531
|
{
|
|
11127
11532
|
name: "OpenfundsMetadataAccount",
|
|
11128
11533
|
type: {
|
|
@@ -11179,6 +11584,68 @@ var types = [
|
|
|
11179
11584
|
]
|
|
11180
11585
|
}
|
|
11181
11586
|
},
|
|
11587
|
+
{
|
|
11588
|
+
name: "OracleSource",
|
|
11589
|
+
type: {
|
|
11590
|
+
kind: "enum",
|
|
11591
|
+
variants: [
|
|
11592
|
+
{
|
|
11593
|
+
name: "Pyth"
|
|
11594
|
+
},
|
|
11595
|
+
{
|
|
11596
|
+
name: "Switchboard"
|
|
11597
|
+
},
|
|
11598
|
+
{
|
|
11599
|
+
name: "QuoteAsset"
|
|
11600
|
+
},
|
|
11601
|
+
{
|
|
11602
|
+
name: "Pyth1K"
|
|
11603
|
+
},
|
|
11604
|
+
{
|
|
11605
|
+
name: "Pyth1M"
|
|
11606
|
+
},
|
|
11607
|
+
{
|
|
11608
|
+
name: "PythStableCoin"
|
|
11609
|
+
},
|
|
11610
|
+
{
|
|
11611
|
+
name: "Prelaunch"
|
|
11612
|
+
},
|
|
11613
|
+
{
|
|
11614
|
+
name: "PythPull"
|
|
11615
|
+
},
|
|
11616
|
+
{
|
|
11617
|
+
name: "Pyth1KPull"
|
|
11618
|
+
},
|
|
11619
|
+
{
|
|
11620
|
+
name: "Pyth1MPull"
|
|
11621
|
+
},
|
|
11622
|
+
{
|
|
11623
|
+
name: "PythStableCoinPull"
|
|
11624
|
+
},
|
|
11625
|
+
{
|
|
11626
|
+
name: "SwitchboardOnDemand"
|
|
11627
|
+
},
|
|
11628
|
+
{
|
|
11629
|
+
name: "PythLazer"
|
|
11630
|
+
},
|
|
11631
|
+
{
|
|
11632
|
+
name: "PythLazer1K"
|
|
11633
|
+
},
|
|
11634
|
+
{
|
|
11635
|
+
name: "PythLazer1M"
|
|
11636
|
+
},
|
|
11637
|
+
{
|
|
11638
|
+
name: "PythLazerStableCoin"
|
|
11639
|
+
},
|
|
11640
|
+
{
|
|
11641
|
+
name: "LstPoolState"
|
|
11642
|
+
},
|
|
11643
|
+
{
|
|
11644
|
+
name: "MarinadeState"
|
|
11645
|
+
}
|
|
11646
|
+
]
|
|
11647
|
+
}
|
|
11648
|
+
},
|
|
11182
11649
|
{
|
|
11183
11650
|
name: "OrderParams",
|
|
11184
11651
|
type: {
|
|
@@ -11472,6 +11939,9 @@ var types = [
|
|
|
11472
11939
|
},
|
|
11473
11940
|
{
|
|
11474
11941
|
name: "JupiterGovClaim"
|
|
11942
|
+
},
|
|
11943
|
+
{
|
|
11944
|
+
name: "EmergencyUpdate"
|
|
11475
11945
|
}
|
|
11476
11946
|
]
|
|
11477
11947
|
}
|
|
@@ -12118,6 +12588,28 @@ var types = [
|
|
|
12118
12588
|
}
|
|
12119
12589
|
}
|
|
12120
12590
|
},
|
|
12591
|
+
{
|
|
12592
|
+
name: "base_asset",
|
|
12593
|
+
type: {
|
|
12594
|
+
option: "pubkey"
|
|
12595
|
+
}
|
|
12596
|
+
},
|
|
12597
|
+
{
|
|
12598
|
+
name: "update_timelock",
|
|
12599
|
+
type: {
|
|
12600
|
+
option: "u32"
|
|
12601
|
+
}
|
|
12602
|
+
},
|
|
12603
|
+
{
|
|
12604
|
+
name: "time_unit",
|
|
12605
|
+
type: {
|
|
12606
|
+
option: {
|
|
12607
|
+
defined: {
|
|
12608
|
+
name: "TimeUnit"
|
|
12609
|
+
}
|
|
12610
|
+
}
|
|
12611
|
+
}
|
|
12612
|
+
},
|
|
12121
12613
|
{
|
|
12122
12614
|
name: "delegate_acls",
|
|
12123
12615
|
type: {
|
|
@@ -12167,15 +12659,25 @@ var types = [
|
|
|
12167
12659
|
}
|
|
12168
12660
|
},
|
|
12169
12661
|
{
|
|
12170
|
-
name: "
|
|
12662
|
+
name: "kamino_lending_markets",
|
|
12171
12663
|
type: {
|
|
12172
|
-
option:
|
|
12664
|
+
option: {
|
|
12665
|
+
vec: "pubkey"
|
|
12666
|
+
}
|
|
12173
12667
|
}
|
|
12174
12668
|
},
|
|
12175
12669
|
{
|
|
12176
|
-
name: "
|
|
12670
|
+
name: "meteora_dlmm_pools",
|
|
12177
12671
|
type: {
|
|
12178
|
-
option:
|
|
12672
|
+
option: {
|
|
12673
|
+
vec: "pubkey"
|
|
12674
|
+
}
|
|
12675
|
+
}
|
|
12676
|
+
},
|
|
12677
|
+
{
|
|
12678
|
+
name: "max_swap_slippage_bps",
|
|
12679
|
+
type: {
|
|
12680
|
+
option: "u32"
|
|
12179
12681
|
}
|
|
12180
12682
|
},
|
|
12181
12683
|
{
|
|
@@ -12246,87 +12748,39 @@ var types = [
|
|
|
12246
12748
|
name: "CurveOneSide"
|
|
12247
12749
|
},
|
|
12248
12750
|
{
|
|
12249
|
-
name: "BidAskOneSide"
|
|
12250
|
-
},
|
|
12251
|
-
{
|
|
12252
|
-
name: "SpotBalanced"
|
|
12253
|
-
},
|
|
12254
|
-
{
|
|
12255
|
-
name: "CurveBalanced"
|
|
12256
|
-
},
|
|
12257
|
-
{
|
|
12258
|
-
name: "BidAskBalanced"
|
|
12259
|
-
},
|
|
12260
|
-
{
|
|
12261
|
-
name: "SpotImBalanced"
|
|
12262
|
-
},
|
|
12263
|
-
{
|
|
12264
|
-
name: "CurveImBalanced"
|
|
12265
|
-
},
|
|
12266
|
-
{
|
|
12267
|
-
name: "BidAskImBalanced"
|
|
12268
|
-
}
|
|
12269
|
-
]
|
|
12270
|
-
}
|
|
12271
|
-
},
|
|
12272
|
-
{
|
|
12273
|
-
name: "TimeUnit",
|
|
12274
|
-
type: {
|
|
12275
|
-
kind: "enum",
|
|
12276
|
-
variants: [
|
|
12277
|
-
{
|
|
12278
|
-
name: "Slot"
|
|
12279
|
-
},
|
|
12280
|
-
{
|
|
12281
|
-
name: "Second"
|
|
12282
|
-
}
|
|
12283
|
-
]
|
|
12284
|
-
}
|
|
12285
|
-
},
|
|
12286
|
-
{
|
|
12287
|
-
name: "Valuation",
|
|
12288
|
-
type: {
|
|
12289
|
-
kind: "struct",
|
|
12290
|
-
fields: [
|
|
12291
|
-
{
|
|
12292
|
-
name: "model",
|
|
12293
|
-
type: {
|
|
12294
|
-
defined: {
|
|
12295
|
-
name: "ValuationModel"
|
|
12296
|
-
}
|
|
12297
|
-
}
|
|
12751
|
+
name: "BidAskOneSide"
|
|
12298
12752
|
},
|
|
12299
12753
|
{
|
|
12300
|
-
name: "
|
|
12301
|
-
type: "u64"
|
|
12754
|
+
name: "SpotBalanced"
|
|
12302
12755
|
},
|
|
12303
12756
|
{
|
|
12304
|
-
name: "
|
|
12305
|
-
type: {
|
|
12306
|
-
defined: {
|
|
12307
|
-
name: "NoticePeriodType"
|
|
12308
|
-
}
|
|
12309
|
-
}
|
|
12757
|
+
name: "CurveBalanced"
|
|
12310
12758
|
},
|
|
12311
12759
|
{
|
|
12312
|
-
name: "
|
|
12313
|
-
type: "bool"
|
|
12760
|
+
name: "BidAskBalanced"
|
|
12314
12761
|
},
|
|
12315
12762
|
{
|
|
12316
|
-
name: "
|
|
12317
|
-
type: "u64"
|
|
12763
|
+
name: "SpotImBalanced"
|
|
12318
12764
|
},
|
|
12319
12765
|
{
|
|
12320
|
-
name: "
|
|
12321
|
-
type: "u64"
|
|
12766
|
+
name: "CurveImBalanced"
|
|
12322
12767
|
},
|
|
12323
12768
|
{
|
|
12324
|
-
name: "
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12769
|
+
name: "BidAskImBalanced"
|
|
12770
|
+
}
|
|
12771
|
+
]
|
|
12772
|
+
}
|
|
12773
|
+
},
|
|
12774
|
+
{
|
|
12775
|
+
name: "TimeUnit",
|
|
12776
|
+
type: {
|
|
12777
|
+
kind: "enum",
|
|
12778
|
+
variants: [
|
|
12779
|
+
{
|
|
12780
|
+
name: "Second"
|
|
12781
|
+
},
|
|
12782
|
+
{
|
|
12783
|
+
name: "Slot"
|
|
12330
12784
|
}
|
|
12331
12785
|
]
|
|
12332
12786
|
}
|
|
@@ -12398,16 +12852,11 @@ function getGlamProgramId(cluster) {
|
|
|
12398
12852
|
}
|
|
12399
12853
|
}
|
|
12400
12854
|
function getGlamProgram(cluster, provider) {
|
|
12401
|
-
|
|
12402
|
-
|
|
12403
|
-
|
|
12404
|
-
|
|
12405
|
-
|
|
12406
|
-
...GlamProtocolIdlJson
|
|
12407
|
-
};
|
|
12408
|
-
idl.address = getGlamProgramId(cluster).toBase58();
|
|
12409
|
-
return new anchor.Program(idl, provider);
|
|
12410
|
-
}
|
|
12855
|
+
const idl = {
|
|
12856
|
+
...GlamProtocolIdlJson
|
|
12857
|
+
};
|
|
12858
|
+
idl.address = getGlamProgramId(cluster).toBase58(); // Override program address for the specified cluster
|
|
12859
|
+
return new anchor.Program(idl, provider);
|
|
12411
12860
|
}
|
|
12412
12861
|
|
|
12413
12862
|
const SEED_METADATA = (GlamProtocolIdlJson.constants.find((x)=>x.name === "SEED_METADATA")?.value || "").replace(/"/g, "");
|
|
@@ -12420,6 +12869,7 @@ const STAKE_ACCOUNT_SIZE = 200;
|
|
|
12420
12869
|
const METEORA_POSITION_SIZE = 8120;
|
|
12421
12870
|
const KAMINO_OBTRIGATION_SIZE = 3344;
|
|
12422
12871
|
const JITO_TIP_DEFAULT = new web3_js.PublicKey("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5");
|
|
12872
|
+
const KAMINO_SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
|
|
12423
12873
|
/**
|
|
12424
12874
|
* Token mints. If no devnet version is defined, assume mainnet and devnet addresses are the same.
|
|
12425
12875
|
*
|
|
@@ -12473,15 +12923,22 @@ class StateIdlModel {
|
|
|
12473
12923
|
this.company = data.company ?? null;
|
|
12474
12924
|
this.owner = data.owner ?? null;
|
|
12475
12925
|
this.created = data.created ?? null;
|
|
12926
|
+
// Configs
|
|
12927
|
+
this.baseAsset = data.baseAsset ?? null;
|
|
12928
|
+
this.updateTimelock = data.updateTimelock ?? null;
|
|
12929
|
+
this.timeUnit = data.timeUnit ?? null;
|
|
12930
|
+
// ACLs
|
|
12476
12931
|
this.delegateAcls = data.delegateAcls ?? null;
|
|
12477
12932
|
this.integrations = data.integrations ?? null;
|
|
12933
|
+
// Integration specific configs
|
|
12478
12934
|
this.driftMarketIndexesPerp = data.driftMarketIndexesPerp ?? null;
|
|
12479
12935
|
this.driftMarketIndexesSpot = data.driftMarketIndexesSpot ?? null;
|
|
12480
12936
|
this.driftOrderTypes = data.driftOrderTypes ?? null;
|
|
12937
|
+
this.kaminoLendingMarkets = data.kaminoLendingMarkets ?? null;
|
|
12938
|
+
this.meteoraDlmmPools = data.meteoraDlmmPools ?? null;
|
|
12939
|
+
this.maxSwapSlippageBps = data.maxSwapSlippageBps ?? null;
|
|
12481
12940
|
this.metadata = data.metadata ?? null;
|
|
12482
12941
|
this.rawOpenfunds = data.rawOpenfunds ?? null;
|
|
12483
|
-
this.baseAsset = data.baseAsset ?? null;
|
|
12484
|
-
this.maxCap = data.maxCap ?? null;
|
|
12485
12942
|
}
|
|
12486
12943
|
}
|
|
12487
12944
|
class StateModel extends StateIdlModel {
|
|
@@ -12531,7 +12988,7 @@ class StateModel extends StateIdlModel {
|
|
|
12531
12988
|
return this.mintAddresses[0].toBase58() || this.idStr;
|
|
12532
12989
|
}
|
|
12533
12990
|
/**
|
|
12534
|
-
* Build a StateModel from onchain
|
|
12991
|
+
* Build a StateModel from onchain data
|
|
12535
12992
|
*
|
|
12536
12993
|
* @param stateAccount provides core fund data
|
|
12537
12994
|
* @param openfundsMetadataAccount includes fund rawOpenfunds data and share class rawOpenfunds data
|
|
@@ -12592,11 +13049,7 @@ class StateModel extends StateIdlModel {
|
|
|
12592
13049
|
const name = Object.keys(param.name)[0];
|
|
12593
13050
|
// @ts-ignore
|
|
12594
13051
|
const value = Object.values(param.value)[0].val;
|
|
12595
|
-
|
|
12596
|
-
mintIdlModel["lockUpPeriodInSeconds"] = Number(value);
|
|
12597
|
-
} else {
|
|
12598
|
-
mintIdlModel[name] = value;
|
|
12599
|
-
}
|
|
13052
|
+
mintIdlModel[name] = value;
|
|
12600
13053
|
});
|
|
12601
13054
|
if (openfundsMetadataAccount) {
|
|
12602
13055
|
const mintOpenfundsFields = {};
|
|
@@ -12671,18 +13124,24 @@ class MintIdlModel {
|
|
|
12671
13124
|
this.rawOpenfunds = data.rawOpenfunds ?? null;
|
|
12672
13125
|
this.allowlist = data.allowlist ?? null;
|
|
12673
13126
|
this.blocklist = data.blocklist ?? null;
|
|
12674
|
-
this.
|
|
13127
|
+
this.lockUpPeriod = data.lockUpPeriod ?? null;
|
|
13128
|
+
this.yearInSeconds = data.yearInSeconds ?? null;
|
|
12675
13129
|
this.permanentDelegate = data.permanentDelegate ?? null;
|
|
12676
13130
|
this.defaultAccountStateFrozen = data.defaultAccountStateFrozen ?? null;
|
|
12677
13131
|
this.feeStructure = data.feeStructure ?? null;
|
|
12678
13132
|
this.feeParams = data.feeParams ?? null;
|
|
12679
|
-
this.
|
|
13133
|
+
this.notifyAndSettle = data.notifyAndSettle ?? null;
|
|
13134
|
+
this.maxCap = data.maxCap ?? null;
|
|
12680
13135
|
this.minSubscription = data.minSubscription ?? null;
|
|
12681
13136
|
this.minRedemption = data.minRedemption ?? null;
|
|
13137
|
+
this.subscriptionPaused = data.subscriptionPaused ?? null;
|
|
13138
|
+
this.redemptionPaused = data.redemptionPaused ?? null;
|
|
12682
13139
|
}
|
|
12683
13140
|
}
|
|
12684
13141
|
class MintModel extends MintIdlModel {
|
|
12685
|
-
|
|
13142
|
+
/**
|
|
13143
|
+
* @deprecated
|
|
13144
|
+
*/ static mintAddress(statePda, idx = 0, glamProgramId = GLAM_PROGRAM_ID_DEFAULT) {
|
|
12686
13145
|
const [pda, _] = web3_js.PublicKey.findProgramAddressSync([
|
|
12687
13146
|
Buffer.from(SEED_MINT),
|
|
12688
13147
|
Uint8Array.from([
|
|
@@ -12778,6 +13237,14 @@ PriceDenom.SOL = {
|
|
|
12778
13237
|
PriceDenom.USD = {
|
|
12779
13238
|
usd: {}
|
|
12780
13239
|
};
|
|
13240
|
+
class TimeUnit {
|
|
13241
|
+
}
|
|
13242
|
+
TimeUnit.Slot = {
|
|
13243
|
+
slot: {}
|
|
13244
|
+
};
|
|
13245
|
+
TimeUnit.Second = {
|
|
13246
|
+
second: {}
|
|
13247
|
+
};
|
|
12781
13248
|
|
|
12782
13249
|
var ClusterNetwork = /*#__PURE__*/ function(ClusterNetwork) {
|
|
12783
13250
|
ClusterNetwork["Mainnet"] = "mainnet-beta";
|
|
@@ -12878,6 +13345,30 @@ const parseMeteoraPosition = async (connection, position)=>{
|
|
|
12878
13345
|
binArrayUpper
|
|
12879
13346
|
};
|
|
12880
13347
|
};
|
|
13348
|
+
async function fetchLookupTables(connection, authority, firstEntry) {
|
|
13349
|
+
const ALT_PROGRAM_ID = new web3_js.PublicKey("AddressLookupTab1e1111111111111111111111111");
|
|
13350
|
+
// Fetch all accounts owned by the ALT program
|
|
13351
|
+
const accounts = await connection.getProgramAccounts(ALT_PROGRAM_ID, {
|
|
13352
|
+
filters: [
|
|
13353
|
+
{
|
|
13354
|
+
memcmp: {
|
|
13355
|
+
offset: 22,
|
|
13356
|
+
bytes: authority.toBase58()
|
|
13357
|
+
}
|
|
13358
|
+
},
|
|
13359
|
+
{
|
|
13360
|
+
memcmp: {
|
|
13361
|
+
offset: 56,
|
|
13362
|
+
bytes: firstEntry.toBase58()
|
|
13363
|
+
}
|
|
13364
|
+
}
|
|
13365
|
+
]
|
|
13366
|
+
});
|
|
13367
|
+
return accounts.map(({ pubkey, account })=>new web3_js.AddressLookupTableAccount({
|
|
13368
|
+
key: pubkey,
|
|
13369
|
+
state: web3_js.AddressLookupTableAccount.deserialize(account.data)
|
|
13370
|
+
}));
|
|
13371
|
+
}
|
|
12881
13372
|
const getSimulationComputeUnits = async (connection, instructions, payer, lookupTables)=>{
|
|
12882
13373
|
const testInstructions = [
|
|
12883
13374
|
// Set an arbitrarily high number in simulation
|
|
@@ -13120,8 +13611,81 @@ class BlockhashWithCache {
|
|
|
13120
13611
|
}
|
|
13121
13612
|
}
|
|
13122
13613
|
|
|
13614
|
+
/**
|
|
13615
|
+
* Compute state account PDA from state model
|
|
13616
|
+
*/ function getStatePda(stateModel, programId, owner) {
|
|
13617
|
+
if (!stateModel?.created?.key && !stateModel?.name) {
|
|
13618
|
+
throw new Error("State model must have created key or name");
|
|
13619
|
+
}
|
|
13620
|
+
const createdKey = stateModel?.created?.key || [
|
|
13621
|
+
...Buffer.from(anchor__namespace.utils.sha256.hash(stateModel?.name)).subarray(0, 8)
|
|
13622
|
+
];
|
|
13623
|
+
const _owner = owner || stateModel?.owner?.pubkey;
|
|
13624
|
+
if (!_owner) {
|
|
13625
|
+
throw new Error("Owner must be specified explicitly or set in state model");
|
|
13626
|
+
}
|
|
13627
|
+
const [pda, _bump] = web3_js.PublicKey.findProgramAddressSync([
|
|
13628
|
+
Buffer.from(SEED_STATE),
|
|
13629
|
+
_owner.toBuffer(),
|
|
13630
|
+
Uint8Array.from(createdKey)
|
|
13631
|
+
], programId);
|
|
13632
|
+
return pda;
|
|
13633
|
+
}
|
|
13634
|
+
/**
|
|
13635
|
+
* Compute vault PDA from state PDA
|
|
13636
|
+
*/ function getVaultPda(statePda, programId) {
|
|
13637
|
+
const [pda, _bump] = web3_js.PublicKey.findProgramAddressSync([
|
|
13638
|
+
Buffer.from(SEED_VAULT),
|
|
13639
|
+
statePda.toBuffer()
|
|
13640
|
+
], programId);
|
|
13641
|
+
return pda;
|
|
13642
|
+
}
|
|
13643
|
+
/**
|
|
13644
|
+
* Compute escrow PDA from state PDA
|
|
13645
|
+
*/ function getEscrowPda(statePda, programId) {
|
|
13646
|
+
const [pda, _bump] = web3_js.PublicKey.findProgramAddressSync([
|
|
13647
|
+
Buffer.from(SEED_ESCROW),
|
|
13648
|
+
statePda.toBuffer()
|
|
13649
|
+
], programId);
|
|
13650
|
+
return pda;
|
|
13651
|
+
}
|
|
13652
|
+
function getOpenfundsPda(statePda, programId) {
|
|
13653
|
+
const [pda, _] = web3_js.PublicKey.findProgramAddressSync([
|
|
13654
|
+
Buffer.from(SEED_METADATA),
|
|
13655
|
+
statePda.toBuffer()
|
|
13656
|
+
], programId);
|
|
13657
|
+
return pda;
|
|
13658
|
+
}
|
|
13659
|
+
function getMintPda(statePda, mintIdx, programId) {
|
|
13660
|
+
const [pda, _] = web3_js.PublicKey.findProgramAddressSync([
|
|
13661
|
+
Buffer.from(SEED_MINT),
|
|
13662
|
+
Uint8Array.from([
|
|
13663
|
+
mintIdx % 256
|
|
13664
|
+
]),
|
|
13665
|
+
statePda.toBuffer()
|
|
13666
|
+
], programId);
|
|
13667
|
+
return pda;
|
|
13668
|
+
}
|
|
13669
|
+
function getExtraMetasPda(mint) {
|
|
13670
|
+
return web3_js.PublicKey.findProgramAddressSync([
|
|
13671
|
+
Buffer.from("extra-account-metas"),
|
|
13672
|
+
mint.toBuffer()
|
|
13673
|
+
], TRANSFER_HOOK_PROGRAM)[0];
|
|
13674
|
+
}
|
|
13675
|
+
function getAccountPolicyPda(tokenAccount) {
|
|
13676
|
+
return web3_js.PublicKey.findProgramAddressSync([
|
|
13677
|
+
Buffer.from("account-policy"),
|
|
13678
|
+
tokenAccount.toBuffer()
|
|
13679
|
+
], TRANSFER_HOOK_PROGRAM)[0];
|
|
13680
|
+
}
|
|
13681
|
+
|
|
13123
13682
|
const JUPITER_API_DEFAULT = "https://lite-api.jup.ag";
|
|
13124
13683
|
const DEFAULT_PRIORITY_FEE = 10000; // microLamports
|
|
13684
|
+
const LOOKUP_TABLES = [
|
|
13685
|
+
new web3_js.PublicKey("284iwGtA9X9aLy3KsyV8uT2pXLARhYbiSi5SiM2g47M2"),
|
|
13686
|
+
new web3_js.PublicKey("D9cnvzswDikQDf53k4HpQ3KJ9y1Fv3HGGDFYMXnK5T6c"),
|
|
13687
|
+
new web3_js.PublicKey("EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb")
|
|
13688
|
+
];
|
|
13125
13689
|
const isBrowser = process.env.ANCHOR_BROWSER || typeof window !== "undefined" && !window.process?.hasOwnProperty("type");
|
|
13126
13690
|
class BaseClient {
|
|
13127
13691
|
get detectedCluster() {
|
|
@@ -13134,6 +13698,15 @@ class BaseClient {
|
|
|
13134
13698
|
}
|
|
13135
13699
|
return ClusterNetwork.Mainnet;
|
|
13136
13700
|
}
|
|
13701
|
+
get statePda() {
|
|
13702
|
+
if (!this._statePda) {
|
|
13703
|
+
throw new Error("State PDA is not specified");
|
|
13704
|
+
}
|
|
13705
|
+
return this._statePda;
|
|
13706
|
+
}
|
|
13707
|
+
set statePda(statePda) {
|
|
13708
|
+
this._statePda = statePda;
|
|
13709
|
+
}
|
|
13137
13710
|
isMainnet() {
|
|
13138
13711
|
return this.cluster === ClusterNetwork.Mainnet;
|
|
13139
13712
|
}
|
|
@@ -13192,7 +13765,7 @@ class BaseClient {
|
|
|
13192
13765
|
})
|
|
13193
13766
|
];
|
|
13194
13767
|
}
|
|
13195
|
-
async intoVersionedTransaction(tx, { lookupTables, signer, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee = false, jitoTipLamports, simulate = false }) {
|
|
13768
|
+
async intoVersionedTransaction(tx, { lookupTables = [], signer, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee = false, jitoTipLamports, simulate = false }) {
|
|
13196
13769
|
signer = signer || this.getSigner();
|
|
13197
13770
|
const instructions = tx.instructions;
|
|
13198
13771
|
// Set Jito tip if provided
|
|
@@ -13203,6 +13776,7 @@ class BaseClient {
|
|
|
13203
13776
|
lamports: jitoTipLamports
|
|
13204
13777
|
}));
|
|
13205
13778
|
}
|
|
13779
|
+
lookupTables.push(...await this.getAdressLookupTableAccounts(LOOKUP_TABLES));
|
|
13206
13780
|
const recentBlockhash = (await this.blockhashWithCache.get()).blockhash;
|
|
13207
13781
|
try {
|
|
13208
13782
|
computeUnitLimit = await getSimulationComputeUnits(this.provider.connection, instructions, signer, lookupTables);
|
|
@@ -13296,13 +13870,13 @@ class BaseClient {
|
|
|
13296
13870
|
}
|
|
13297
13871
|
const addressLookupTableAccountInfos = await this.provider.connection.getMultipleAccountsInfo(keys.map((key)=>new web3_js.PublicKey(key)));
|
|
13298
13872
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index)=>{
|
|
13299
|
-
const
|
|
13873
|
+
const tableAddress = keys[index];
|
|
13300
13874
|
if (accountInfo) {
|
|
13301
|
-
const
|
|
13302
|
-
key: new web3_js.PublicKey(
|
|
13875
|
+
const tableAccount = new web3_js.AddressLookupTableAccount({
|
|
13876
|
+
key: new web3_js.PublicKey(tableAddress),
|
|
13303
13877
|
state: web3_js.AddressLookupTableAccount.deserialize(accountInfo.data)
|
|
13304
13878
|
});
|
|
13305
|
-
acc.push(
|
|
13879
|
+
acc.push(tableAccount);
|
|
13306
13880
|
}
|
|
13307
13881
|
return acc;
|
|
13308
13882
|
}, new Array());
|
|
@@ -13313,44 +13887,33 @@ class BaseClient {
|
|
|
13313
13887
|
getSigner() {
|
|
13314
13888
|
const publicKey = this.provider?.publicKey;
|
|
13315
13889
|
if (!publicKey) {
|
|
13316
|
-
throw new Error("Signer public key cannot be retrieved from provider");
|
|
13890
|
+
throw new Error("Signer public key cannot be retrieved from anchor provider");
|
|
13317
13891
|
}
|
|
13318
13892
|
return publicKey;
|
|
13319
13893
|
}
|
|
13320
|
-
|
|
13321
|
-
return
|
|
13894
|
+
get signer() {
|
|
13895
|
+
return this.getSigner();
|
|
13322
13896
|
}
|
|
13323
|
-
|
|
13324
|
-
|
|
13325
|
-
...Buffer.from(anchor__namespace.utils.sha256.hash(this.getName(stateModel))).subarray(0, 8)
|
|
13326
|
-
];
|
|
13327
|
-
const owner = stateModel.owner?.pubkey || this.getSigner();
|
|
13328
|
-
const [pda, _bump] = web3_js.PublicKey.findProgramAddressSync([
|
|
13329
|
-
Buffer.from(SEED_STATE),
|
|
13330
|
-
owner.toBuffer(),
|
|
13331
|
-
Uint8Array.from(createdKey)
|
|
13332
|
-
], this.program.programId);
|
|
13333
|
-
return pda;
|
|
13897
|
+
get wallet() {
|
|
13898
|
+
return this.getWallet();
|
|
13334
13899
|
}
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
Buffer.from(SEED_VAULT),
|
|
13338
|
-
statePda.toBuffer()
|
|
13339
|
-
], this.program.programId);
|
|
13340
|
-
return pda;
|
|
13900
|
+
get vaultPda() {
|
|
13901
|
+
return getVaultPda(this.statePda, this.program.programId);
|
|
13341
13902
|
}
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
return pda;
|
|
13903
|
+
get escrowPda() {
|
|
13904
|
+
return getEscrowPda(this.statePda, this.program.programId);
|
|
13905
|
+
}
|
|
13906
|
+
get mintPda() {
|
|
13907
|
+
return getMintPda(this.statePda, 0, this.program.programId);
|
|
13348
13908
|
}
|
|
13349
|
-
|
|
13350
|
-
return
|
|
13909
|
+
get extraMetasPda() {
|
|
13910
|
+
return getExtraMetasPda(this.mintPda);
|
|
13911
|
+
}
|
|
13912
|
+
get openfundsPda() {
|
|
13913
|
+
return getOpenfundsPda(this.statePda, this.program.programId);
|
|
13351
13914
|
}
|
|
13352
13915
|
/**
|
|
13353
|
-
* Fetch all the token accounts (including token program and token 2022 program) owned by
|
|
13916
|
+
* Fetch all the token accounts (including token program and token 2022 program) owned by the specified account.
|
|
13354
13917
|
*
|
|
13355
13918
|
* @param owner
|
|
13356
13919
|
* @returns
|
|
@@ -13381,128 +13944,122 @@ class BaseClient {
|
|
|
13381
13944
|
programId: splToken.TOKEN_2022_PROGRAM_ID
|
|
13382
13945
|
})));
|
|
13383
13946
|
}
|
|
13384
|
-
async
|
|
13385
|
-
const
|
|
13386
|
-
const
|
|
13947
|
+
async getSolAndTokenBalances(owner) {
|
|
13948
|
+
const balanceLamports = await this.provider.connection.getBalance(owner);
|
|
13949
|
+
const tokenAccounts = await this.getTokenAccountsByOwner(owner);
|
|
13950
|
+
const uiAmount = balanceLamports / web3_js.LAMPORTS_PER_SOL;
|
|
13951
|
+
return {
|
|
13952
|
+
balanceLamports,
|
|
13953
|
+
uiAmount,
|
|
13954
|
+
tokenAccounts
|
|
13955
|
+
};
|
|
13956
|
+
}
|
|
13957
|
+
getAta(mint, owner, tokenProgram = splToken.TOKEN_PROGRAM_ID) {
|
|
13958
|
+
return splToken.getAssociatedTokenAddressSync(mint, owner, true, tokenProgram);
|
|
13959
|
+
}
|
|
13960
|
+
getVaultAta(mint, tokenProgramId) {
|
|
13961
|
+
return this.getAta(mint, this.vaultPda, tokenProgramId);
|
|
13962
|
+
}
|
|
13963
|
+
async getVaultBalance() {
|
|
13964
|
+
const lamports = await this.provider.connection.getBalance(this.vaultPda);
|
|
13387
13965
|
return lamports / web3_js.LAMPORTS_PER_SOL;
|
|
13388
13966
|
}
|
|
13389
|
-
async
|
|
13390
|
-
|
|
13391
|
-
|
|
13967
|
+
async getVaultLamports() {
|
|
13968
|
+
return await this.provider.connection.getBalance(this.vaultPda);
|
|
13969
|
+
}
|
|
13970
|
+
async getVaultTokenBalance(mintPubkey) {
|
|
13971
|
+
const { mint, tokenProgram } = await this.fetchMintAndTokenProgram(mintPubkey);
|
|
13972
|
+
const ata = this.getVaultAta(mintPubkey, tokenProgram);
|
|
13392
13973
|
try {
|
|
13393
|
-
const account = await splToken.getAccount(this.provider.connection, ata);
|
|
13394
|
-
return
|
|
13974
|
+
const account = await splToken.getAccount(this.provider.connection, ata, "confirmed", tokenProgram);
|
|
13975
|
+
return {
|
|
13976
|
+
amount: new anchor.BN(account.amount),
|
|
13977
|
+
uiAmount: Number(account.amount) / Math.pow(10, mint.decimals)
|
|
13978
|
+
};
|
|
13395
13979
|
} catch (e) {
|
|
13396
13980
|
if (e instanceof splToken.TokenAccountNotFoundError) {
|
|
13397
|
-
return
|
|
13981
|
+
return {
|
|
13982
|
+
amount: new anchor.BN(0),
|
|
13983
|
+
uiAmount: 0
|
|
13984
|
+
};
|
|
13398
13985
|
}
|
|
13399
13986
|
throw e;
|
|
13400
13987
|
}
|
|
13401
13988
|
}
|
|
13402
|
-
async
|
|
13989
|
+
async fetchMintAndTokenProgram(mintPubkey) {
|
|
13403
13990
|
const connection = this.provider.connection;
|
|
13404
|
-
const info = await connection.getAccountInfo(
|
|
13991
|
+
const info = await connection.getAccountInfo(mintPubkey, "confirmed");
|
|
13405
13992
|
if (!info) {
|
|
13406
|
-
throw new Error(`Mint ${
|
|
13993
|
+
throw new Error(`Mint ${mintPubkey} not found`);
|
|
13407
13994
|
}
|
|
13408
13995
|
const tokenProgram = info.owner;
|
|
13409
|
-
const mint = splToken.unpackMint(
|
|
13996
|
+
const mint = splToken.unpackMint(mintPubkey, info, tokenProgram);
|
|
13410
13997
|
return {
|
|
13411
13998
|
mint,
|
|
13412
13999
|
tokenProgram
|
|
13413
14000
|
};
|
|
13414
14001
|
}
|
|
13415
|
-
|
|
13416
|
-
|
|
13417
|
-
Buffer.from(SEED_METADATA),
|
|
13418
|
-
statePda.toBuffer()
|
|
13419
|
-
], this.program.programId);
|
|
13420
|
-
return pda;
|
|
13421
|
-
}
|
|
13422
|
-
getMintPda(statePda, mintIdx = 0) {
|
|
13423
|
-
const [pda, _] = web3_js.PublicKey.findProgramAddressSync([
|
|
13424
|
-
Buffer.from(SEED_MINT),
|
|
13425
|
-
Uint8Array.from([
|
|
13426
|
-
mintIdx % 256
|
|
13427
|
-
]),
|
|
13428
|
-
statePda.toBuffer()
|
|
13429
|
-
], this.program.programId);
|
|
13430
|
-
return pda;
|
|
13431
|
-
}
|
|
13432
|
-
getMintAta(user, mintPda) {
|
|
13433
|
-
return this.getAta(mintPda, user, splToken.TOKEN_2022_PROGRAM_ID);
|
|
13434
|
-
}
|
|
13435
|
-
getExtraMetasPda(glamState, mintIdx = 0) {
|
|
13436
|
-
const mintPda = this.getMintPda(glamState, mintIdx);
|
|
13437
|
-
return web3_js.PublicKey.findProgramAddressSync([
|
|
13438
|
-
Buffer.from("extra-account-metas"),
|
|
13439
|
-
mintPda.toBuffer()
|
|
13440
|
-
], TRANSFER_HOOK_PROGRAM)[0];
|
|
13441
|
-
}
|
|
13442
|
-
getAccountPolicyPda(glamState, subject, mintIdx = 0) {
|
|
13443
|
-
const ata = this.getMintAta(subject, this.getMintPda(glamState, mintIdx));
|
|
13444
|
-
return web3_js.PublicKey.findProgramAddressSync([
|
|
13445
|
-
Buffer.from("account-policy"),
|
|
13446
|
-
ata.toBuffer()
|
|
13447
|
-
], TRANSFER_HOOK_PROGRAM)[0];
|
|
14002
|
+
getMintAta(user) {
|
|
14003
|
+
return this.getAta(this.mintPda, user, splToken.TOKEN_2022_PROGRAM_ID);
|
|
13448
14004
|
}
|
|
13449
|
-
|
|
14005
|
+
/**
|
|
14006
|
+
* @deprecated
|
|
14007
|
+
*/ getName(stateModel) {
|
|
13450
14008
|
const name = stateModel.name || stateModel.mints && stateModel.mints[0]?.name || stateModel.rawOpenfunds?.legalFundNameIncludingUmbrella;
|
|
13451
14009
|
if (!name) {
|
|
13452
14010
|
throw new Error("Name not be inferred from state model");
|
|
13453
14011
|
}
|
|
13454
14012
|
return name;
|
|
13455
14013
|
}
|
|
13456
|
-
async isLockupEnabled(
|
|
13457
|
-
|
|
13458
|
-
|
|
13459
|
-
|
|
14014
|
+
async isLockupEnabled() {
|
|
14015
|
+
if (!this.statePda) {
|
|
14016
|
+
throw new Error("State PDA is not specified");
|
|
14017
|
+
}
|
|
14018
|
+
const state = await this.fetchStateAccount();
|
|
14019
|
+
if (state.params.length < 2) {
|
|
13460
14020
|
throw new Error("Invalid mint index");
|
|
13461
14021
|
}
|
|
13462
|
-
|
|
14022
|
+
// iterate over the mint params
|
|
14023
|
+
for (const param of state.params[1]){
|
|
13463
14024
|
const name = Object.keys(param.name)[0];
|
|
13464
14025
|
// @ts-ignore
|
|
13465
14026
|
const value = Object.values(param.value)[0].val;
|
|
13466
|
-
if (name === "
|
|
14027
|
+
if (name === "lockUpPeriod") {
|
|
13467
14028
|
return new anchor.BN(value).toNumber() >= 0;
|
|
13468
14029
|
}
|
|
13469
14030
|
}
|
|
13470
14031
|
return false;
|
|
13471
14032
|
}
|
|
13472
14033
|
async fetchStateAccount(statePda) {
|
|
13473
|
-
return await this.program.account.stateAccount.fetch(statePda);
|
|
14034
|
+
return await this.program.account.stateAccount.fetch(statePda || this.statePda);
|
|
13474
14035
|
}
|
|
13475
|
-
async fetchOpenfundsMetadataAccount(
|
|
13476
|
-
const
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
async fetchMintAccount(state, mintIdx) {
|
|
13480
|
-
const connection = this.provider.connection;
|
|
13481
|
-
return await splToken.getMint(connection, this.getMintPda(state, mintIdx), connection.commitment, splToken.TOKEN_2022_PROGRAM_ID);
|
|
14036
|
+
async fetchOpenfundsMetadataAccount(statePda) {
|
|
14037
|
+
const glamStatePda = statePda || this.statePda; // state pda used for computing openfunds pda
|
|
14038
|
+
const openfundsPda = glamStatePda.equals(this.statePda) ? this.openfundsPda : getOpenfundsPda(glamStatePda, this.program.programId);
|
|
14039
|
+
return await this.program.account.openfundsMetadataAccount.fetch(openfundsPda);
|
|
13482
14040
|
}
|
|
13483
14041
|
/**
|
|
13484
14042
|
* Generates instructions to wrap SOL into wSOL if the vault doesn't have enough wSOL
|
|
13485
14043
|
*
|
|
13486
14044
|
* @param lamports Desired amount of wSOL
|
|
13487
14045
|
* @returns Array of instructions, null if no instructions are needed
|
|
13488
|
-
*/ async maybeWrapSol(
|
|
14046
|
+
*/ async maybeWrapSol(lamports, signer) {
|
|
13489
14047
|
const glamSigner = signer || this.getSigner();
|
|
13490
|
-
const
|
|
13491
|
-
const vaultWsolAta = this.getAta(WSOL, glamVault);
|
|
14048
|
+
const vaultWsolAta = this.getAta(WSOL, this.vaultPda);
|
|
13492
14049
|
let wsolBalance = new anchor.BN(0);
|
|
13493
14050
|
try {
|
|
13494
14051
|
wsolBalance = new anchor.BN((await this.provider.connection.getTokenAccountBalance(vaultWsolAta)).value.amount);
|
|
13495
14052
|
} catch (err) {}
|
|
13496
|
-
const solBalance = new anchor.BN(await this.provider.connection.getBalance(
|
|
14053
|
+
const solBalance = new anchor.BN(await this.provider.connection.getBalance(this.vaultPda));
|
|
13497
14054
|
const delta = new anchor.BN(lamports).sub(wsolBalance); // wSOL amount needed
|
|
13498
14055
|
if (solBalance.lt(delta)) {
|
|
13499
14056
|
throw new Error(`Insufficient funds in vault to complete the transaction. SOL balance (lamports): ${solBalance}, lamports needed: ${lamports}`);
|
|
13500
14057
|
}
|
|
13501
14058
|
if (delta.gt(new anchor.BN(0)) && solBalance.gte(delta)) {
|
|
13502
14059
|
return [
|
|
13503
|
-
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultWsolAta,
|
|
14060
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultWsolAta, this.vaultPda, WSOL),
|
|
13504
14061
|
await this.program.methods.systemTransfer(delta).accounts({
|
|
13505
|
-
glamState,
|
|
14062
|
+
glamState: this.statePda,
|
|
13506
14063
|
glamSigner,
|
|
13507
14064
|
to: vaultWsolAta
|
|
13508
14065
|
}).instruction(),
|
|
@@ -13511,7 +14068,9 @@ class BaseClient {
|
|
|
13511
14068
|
}
|
|
13512
14069
|
return [];
|
|
13513
14070
|
}
|
|
13514
|
-
|
|
14071
|
+
/**
|
|
14072
|
+
* @deprecated
|
|
14073
|
+
*/ getAssetIdFromCurrency(currency) {
|
|
13515
14074
|
switch(currency.toUpperCase()){
|
|
13516
14075
|
case "SOL":
|
|
13517
14076
|
case "WSOL":
|
|
@@ -13548,19 +14107,21 @@ class BaseClient {
|
|
|
13548
14107
|
/**
|
|
13549
14108
|
* Fetch glam state from onchain accounts and build a StateModel
|
|
13550
14109
|
*
|
|
13551
|
-
* @param statePda
|
|
14110
|
+
* @param statePda Optional state PDA, if not specified, use the client's state PDA
|
|
13552
14111
|
* @returns
|
|
13553
|
-
*/ async
|
|
13554
|
-
const
|
|
13555
|
-
const
|
|
14112
|
+
*/ async fetchStateModel(statePda) {
|
|
14113
|
+
const glamStatePda = statePda || this.statePda;
|
|
14114
|
+
const stateAccount = await this.fetchStateAccount(glamStatePda);
|
|
14115
|
+
const openfundsMetadataAccount = await this.fetchOpenfundsMetadataAccount(glamStatePda);
|
|
13556
14116
|
if (stateAccount.mints.length > 0) {
|
|
13557
|
-
const
|
|
13558
|
-
|
|
14117
|
+
const mintPubkey = glamStatePda.equals(this.statePda) ? this.mintPda : getMintPda(glamStatePda, 0, this.program.programId);
|
|
14118
|
+
const { mint } = await this.fetchMintAndTokenProgram(mintPubkey);
|
|
14119
|
+
return StateModel.fromOnchainAccounts(statePda, stateAccount, openfundsMetadataAccount, mint, this.program.programId);
|
|
13559
14120
|
}
|
|
13560
14121
|
return StateModel.fromOnchainAccounts(statePda, stateAccount, openfundsMetadataAccount, undefined, this.program.programId);
|
|
13561
14122
|
}
|
|
13562
14123
|
/**
|
|
13563
|
-
* Fetch all glam
|
|
14124
|
+
* Fetch all glam state models if no filter options provided
|
|
13564
14125
|
*
|
|
13565
14126
|
* @param filterOptions
|
|
13566
14127
|
* @returns
|
|
@@ -13604,6 +14165,9 @@ class BaseClient {
|
|
|
13604
14165
|
}
|
|
13605
14166
|
this.cluster = config?.cluster || this.detectedCluster;
|
|
13606
14167
|
this.program = getGlamProgram(this.cluster, this.provider);
|
|
14168
|
+
if (config?.statePda) {
|
|
14169
|
+
this.statePda = config.statePda;
|
|
14170
|
+
}
|
|
13607
14171
|
this.jupiterApi = config?.jupiterApi || JUPITER_API_DEFAULT;
|
|
13608
14172
|
this.blockhashWithCache = new BlockhashWithCache(this.provider, !!isBrowser);
|
|
13609
14173
|
}
|
|
@@ -14508,56 +15072,52 @@ const DRIFT_MARGIN_PRECISION = 10000;
|
|
|
14508
15072
|
class DriftClient {
|
|
14509
15073
|
/*
|
|
14510
15074
|
* Client methods
|
|
14511
|
-
*/ async initialize(
|
|
14512
|
-
const tx = await this.initializeTx(
|
|
14513
|
-
return await this.base.sendAndConfirm(tx);
|
|
14514
|
-
}
|
|
14515
|
-
async updateUserCustomMarginRatio(statePda, maxLeverage, subAccountId = 0) {
|
|
14516
|
-
const tx = await this.updateUserCustomMarginRatioTx(statePda, maxLeverage, subAccountId);
|
|
15075
|
+
*/ async initialize(subAccountId = 0, txOptions = {}) {
|
|
15076
|
+
const tx = await this.initializeTx(subAccountId, txOptions);
|
|
14517
15077
|
return await this.base.sendAndConfirm(tx);
|
|
14518
15078
|
}
|
|
14519
|
-
async
|
|
14520
|
-
const tx = await this.
|
|
15079
|
+
async updateUserCustomMarginRatio(maxLeverage, subAccountId = 0) {
|
|
15080
|
+
const tx = await this.updateUserCustomMarginRatioTx(maxLeverage, subAccountId);
|
|
14521
15081
|
return await this.base.sendAndConfirm(tx);
|
|
14522
15082
|
}
|
|
14523
|
-
async
|
|
14524
|
-
const tx = await this.
|
|
15083
|
+
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
|
|
15084
|
+
const tx = await this.updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId, txOptions);
|
|
14525
15085
|
return await this.base.sendAndConfirm(tx);
|
|
14526
15086
|
}
|
|
14527
|
-
async
|
|
14528
|
-
const tx = await this.
|
|
15087
|
+
async updateUserDelegate(delegate, subAccountId = 0) {
|
|
15088
|
+
const tx = await this.updateUserDelegateTx(new web3_js.PublicKey(delegate), subAccountId);
|
|
14529
15089
|
return await this.base.sendAndConfirm(tx);
|
|
14530
15090
|
}
|
|
14531
|
-
async
|
|
14532
|
-
const tx = await this.
|
|
15091
|
+
async deleteUser(subAccountId = 0, txOptions = {}) {
|
|
15092
|
+
const tx = await this.deleteUserTx(subAccountId, txOptions);
|
|
14533
15093
|
return await this.base.sendAndConfirm(tx);
|
|
14534
15094
|
}
|
|
14535
|
-
async
|
|
14536
|
-
const tx = await this.
|
|
15095
|
+
async deposit(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
15096
|
+
const tx = await this.depositTx(amount, marketIndex, subAccountId, txOptions);
|
|
14537
15097
|
return await this.base.sendAndConfirm(tx);
|
|
14538
15098
|
}
|
|
14539
|
-
async
|
|
14540
|
-
const tx = await this.
|
|
15099
|
+
async withdraw(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
15100
|
+
const tx = await this.withdrawTx(amount, marketIndex, subAccountId, txOptions);
|
|
14541
15101
|
return await this.base.sendAndConfirm(tx);
|
|
14542
15102
|
}
|
|
14543
|
-
async
|
|
14544
|
-
const tx = await this.
|
|
15103
|
+
async placeOrder(orderParams, subAccountId = 0, txOptions = {}) {
|
|
15104
|
+
const tx = await this.placeOrderTx(orderParams, subAccountId, txOptions);
|
|
14545
15105
|
return await this.base.sendAndConfirm(tx);
|
|
14546
15106
|
}
|
|
14547
|
-
async
|
|
14548
|
-
const tx = await this.
|
|
15107
|
+
async modifyOrder(modifyOrderParams, subAccountId = 0, txOptions = {}) {
|
|
15108
|
+
const tx = await this.modifyOrderTx(modifyOrderParams, subAccountId, txOptions);
|
|
14549
15109
|
return await this.base.sendAndConfirm(tx);
|
|
14550
15110
|
}
|
|
14551
|
-
async
|
|
14552
|
-
const tx = await this.
|
|
15111
|
+
async cancelOrders(marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
|
|
15112
|
+
const tx = await this.cancelOrdersTx(marketType, marketIndex, direction, subAccountId, txOptions);
|
|
14553
15113
|
return await this.base.sendAndConfirm(tx);
|
|
14554
15114
|
}
|
|
14555
|
-
async
|
|
14556
|
-
const tx = await this.
|
|
15115
|
+
async cancelOrdersByIds(orderIds, subAccountId = 0, txOptions = {}) {
|
|
15116
|
+
const tx = await this.cancelOrdersByIdsTx(orderIds, subAccountId, txOptions);
|
|
14557
15117
|
return await this.base.sendAndConfirm(tx);
|
|
14558
15118
|
}
|
|
14559
|
-
async
|
|
14560
|
-
const tx = await this.
|
|
15119
|
+
async settlePnl(marketIndex, subAccountId = 0, txOptions = {}) {
|
|
15120
|
+
const tx = await this.settlePnlTx(marketIndex, subAccountId, txOptions);
|
|
14561
15121
|
return await this.base.sendAndConfirm(tx);
|
|
14562
15122
|
}
|
|
14563
15123
|
getGlamReferrerPdas() {
|
|
@@ -14623,8 +15183,8 @@ class DriftClient {
|
|
|
14623
15183
|
uiAmount
|
|
14624
15184
|
};
|
|
14625
15185
|
}
|
|
14626
|
-
getDriftUserPdas(
|
|
14627
|
-
const vault = this.base.
|
|
15186
|
+
getDriftUserPdas(subAccountId = 0) {
|
|
15187
|
+
const vault = this.base.vaultPda;
|
|
14628
15188
|
return {
|
|
14629
15189
|
user: this.getUserPda(vault, subAccountId),
|
|
14630
15190
|
userStats: this.getUserStatsPda(vault)
|
|
@@ -14747,8 +15307,8 @@ class DriftClient {
|
|
|
14747
15307
|
charsToName(chars) {
|
|
14748
15308
|
return String.fromCharCode(...chars).replace(/\0/g, "").trim();
|
|
14749
15309
|
}
|
|
14750
|
-
async fetchDriftUser(
|
|
14751
|
-
const { user } = this.getDriftUserPdas(
|
|
15310
|
+
async fetchDriftUser(subAccountId = 0) {
|
|
15311
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
14752
15312
|
const accountInfo = await this.base.provider.connection.getAccountInfo(user);
|
|
14753
15313
|
if (!accountInfo) {
|
|
14754
15314
|
return null;
|
|
@@ -14792,8 +15352,10 @@ class DriftClient {
|
|
|
14792
15352
|
// const { spotPositions, perpPositions } = driftUser;
|
|
14793
15353
|
// return { spotPositions, perpPositions };
|
|
14794
15354
|
// }
|
|
14795
|
-
|
|
14796
|
-
|
|
15355
|
+
/**
|
|
15356
|
+
* @deprecated
|
|
15357
|
+
*/ async fetchPolicyConfig(glamState) {
|
|
15358
|
+
const driftUserAccount = glamState && glamState.id && await this.fetchDriftUser();
|
|
14797
15359
|
let delegate = driftUserAccount?.delegate;
|
|
14798
15360
|
if (delegate && delegate.equals(web3_js.PublicKey.default)) {
|
|
14799
15361
|
delegate = undefined;
|
|
@@ -14808,8 +15370,8 @@ class DriftClient {
|
|
|
14808
15370
|
driftMarketIndexesSpot: glamState?.driftMarketIndexesSpot || []
|
|
14809
15371
|
};
|
|
14810
15372
|
}
|
|
14811
|
-
async composeRemainingAccounts(
|
|
14812
|
-
const driftUser = await this.fetchDriftUser(
|
|
15373
|
+
async composeRemainingAccounts(subAccountId, marketType, marketIndex) {
|
|
15374
|
+
const driftUser = await this.fetchDriftUser(subAccountId);
|
|
14813
15375
|
if (!driftUser) {
|
|
14814
15376
|
throw new Error("Drift user not found");
|
|
14815
15377
|
}
|
|
@@ -14849,19 +15411,19 @@ class DriftClient {
|
|
|
14849
15411
|
isSigner: false
|
|
14850
15412
|
})));
|
|
14851
15413
|
}
|
|
14852
|
-
async initializeUserStatsIx(
|
|
14853
|
-
const { userStats } = this.getDriftUserPdas(
|
|
15414
|
+
async initializeUserStatsIx(glamSigner) {
|
|
15415
|
+
const { userStats } = this.getDriftUserPdas();
|
|
14854
15416
|
// @ts-ignore
|
|
14855
15417
|
return await this.base.program.methods.driftInitializeUserStats().accounts({
|
|
14856
|
-
glamState,
|
|
15418
|
+
glamState: this.base.statePda,
|
|
14857
15419
|
glamSigner,
|
|
14858
15420
|
state: this.driftStatePda,
|
|
14859
15421
|
userStats
|
|
14860
15422
|
}).instruction();
|
|
14861
15423
|
}
|
|
14862
|
-
async initializeUserIx(
|
|
15424
|
+
async initializeUserIx(glamSigner, subAccountId) {
|
|
14863
15425
|
const name = `GLAM *.+ ${subAccountId}`.split("").map((char)=>char.charCodeAt(0)).concat(Array(24).fill(0));
|
|
14864
|
-
const { user, userStats } = this.getDriftUserPdas(
|
|
15426
|
+
const { user, userStats } = this.getDriftUserPdas(subAccountId);
|
|
14865
15427
|
const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
|
|
14866
15428
|
const remainingAccounts = [
|
|
14867
15429
|
{
|
|
@@ -14876,72 +15438,72 @@ class DriftClient {
|
|
|
14876
15438
|
}
|
|
14877
15439
|
];
|
|
14878
15440
|
return await this.base.program.methods.driftInitializeUser(subAccountId, name).accounts({
|
|
14879
|
-
glamState,
|
|
15441
|
+
glamState: this.base.statePda,
|
|
14880
15442
|
user,
|
|
14881
15443
|
userStats,
|
|
14882
15444
|
state: this.driftStatePda,
|
|
14883
15445
|
glamSigner
|
|
14884
15446
|
}).remainingAccounts(remainingAccounts).instruction();
|
|
14885
15447
|
}
|
|
14886
|
-
async initializeTx(
|
|
15448
|
+
async initializeTx(subAccountId = 0, txOptions = {}) {
|
|
14887
15449
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14888
15450
|
const tx = new web3_js.Transaction();
|
|
14889
15451
|
// Create userStats account if it doesn't exist
|
|
14890
|
-
const { userStats } = this.getDriftUserPdas(
|
|
15452
|
+
const { userStats } = this.getDriftUserPdas();
|
|
14891
15453
|
const userStatsInfo = await this.base.provider.connection.getAccountInfo(userStats);
|
|
14892
15454
|
if (!userStatsInfo) {
|
|
14893
|
-
tx.add(await this.initializeUserStatsIx(
|
|
15455
|
+
tx.add(await this.initializeUserStatsIx(glamSigner));
|
|
14894
15456
|
}
|
|
14895
15457
|
// Initialize user (aka sub-account)
|
|
14896
|
-
tx.add(await this.initializeUserIx(
|
|
15458
|
+
tx.add(await this.initializeUserIx(glamSigner, subAccountId));
|
|
14897
15459
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14898
15460
|
}
|
|
14899
|
-
async updateUserCustomMarginRatioIx(
|
|
15461
|
+
async updateUserCustomMarginRatioIx(maxLeverage, subAccountId = 0, txOptions = {}) {
|
|
14900
15462
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14901
|
-
const { user } = this.getDriftUserPdas(
|
|
15463
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
14902
15464
|
// https://github.com/drift-labs/protocol-v2/blob/babed162b08b1fe34e49a81c5aa3e4ec0a88ecdf/programs/drift/src/math/constants.rs#L183-L184
|
|
14903
15465
|
const marginRatio = DRIFT_MARGIN_PRECISION / maxLeverage;
|
|
14904
15466
|
return await this.base.program.methods.driftUpdateUserCustomMarginRatio(subAccountId, marginRatio).accounts({
|
|
14905
|
-
glamState,
|
|
15467
|
+
glamState: this.base.statePda,
|
|
14906
15468
|
glamSigner,
|
|
14907
15469
|
user
|
|
14908
15470
|
}).instruction();
|
|
14909
15471
|
}
|
|
14910
|
-
async updateUserCustomMarginRatioTx(
|
|
14911
|
-
const tx = new web3_js.Transaction().add(await this.updateUserCustomMarginRatioIx(
|
|
15472
|
+
async updateUserCustomMarginRatioTx(maxLeverage, subAccountId = 0, txOptions = {}) {
|
|
15473
|
+
const tx = new web3_js.Transaction().add(await this.updateUserCustomMarginRatioIx(maxLeverage, subAccountId, txOptions));
|
|
14912
15474
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14913
15475
|
}
|
|
14914
|
-
async updateUserMarginTradingEnabledIx(
|
|
15476
|
+
async updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
|
|
14915
15477
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14916
|
-
const { user } = this.getDriftUserPdas(
|
|
15478
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
14917
15479
|
return await this.base.program.methods.driftUpdateUserMarginTradingEnabled(subAccountId, marginTradingEnabled).accounts({
|
|
14918
|
-
glamState,
|
|
15480
|
+
glamState: this.base.statePda,
|
|
14919
15481
|
glamSigner,
|
|
14920
15482
|
user
|
|
14921
15483
|
}).instruction();
|
|
14922
15484
|
}
|
|
14923
|
-
async updateUserMarginTradingEnabledTx(
|
|
14924
|
-
const tx = new web3_js.Transaction().add(...txOptions.preInstructions || [], await this.updateUserMarginTradingEnabledIx(
|
|
15485
|
+
async updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
|
|
15486
|
+
const tx = new web3_js.Transaction().add(...txOptions.preInstructions || [], await this.updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId, txOptions));
|
|
14925
15487
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14926
15488
|
}
|
|
14927
|
-
async updateUserDelegateIx(
|
|
15489
|
+
async updateUserDelegateIx(delegate, subAccountId = 0, txOptions = {}) {
|
|
14928
15490
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14929
|
-
const { user } = this.getDriftUserPdas(
|
|
15491
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
14930
15492
|
return await this.base.program.methods.driftUpdateUserDelegate(subAccountId, new web3_js.PublicKey(delegate)).accounts({
|
|
14931
|
-
glamState,
|
|
15493
|
+
glamState: this.base.statePda,
|
|
14932
15494
|
glamSigner,
|
|
14933
15495
|
user
|
|
14934
15496
|
}).instruction();
|
|
14935
15497
|
}
|
|
14936
|
-
async updateUserDelegateTx(
|
|
14937
|
-
const tx = new web3_js.Transaction().add(await this.updateUserDelegateIx(
|
|
15498
|
+
async updateUserDelegateTx(delegate, subAccountId = 0, txOptions = {}) {
|
|
15499
|
+
const tx = new web3_js.Transaction().add(await this.updateUserDelegateIx(delegate, subAccountId, txOptions));
|
|
14938
15500
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14939
15501
|
}
|
|
14940
|
-
async deleteUserTx(
|
|
15502
|
+
async deleteUserTx(subAccountId = 0, txOptions = {}) {
|
|
14941
15503
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14942
|
-
const { user, userStats } = this.getDriftUserPdas(
|
|
15504
|
+
const { user, userStats } = this.getDriftUserPdas(subAccountId);
|
|
14943
15505
|
const tx = await this.base.program.methods.driftDeleteUser().accounts({
|
|
14944
|
-
glamState,
|
|
15506
|
+
glamState: this.base.statePda,
|
|
14945
15507
|
state: this.driftStatePda,
|
|
14946
15508
|
user,
|
|
14947
15509
|
userStats,
|
|
@@ -14949,25 +15511,25 @@ class DriftClient {
|
|
|
14949
15511
|
}).transaction();
|
|
14950
15512
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
14951
15513
|
}
|
|
14952
|
-
async depositTx(
|
|
15514
|
+
async depositTx(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
14953
15515
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
14954
|
-
const { user, userStats } = this.getDriftUserPdas(
|
|
15516
|
+
const { user, userStats } = this.getDriftUserPdas(subAccountId);
|
|
14955
15517
|
const { mint, oracle, tokenProgram, marketPda, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
14956
15518
|
console.log(`Spot market ${marketIndex} mint ${mint}, oracle: ${oracle}, marketPda: ${marketPda}, vault: ${driftVault}`);
|
|
14957
15519
|
const preInstructions = [];
|
|
14958
15520
|
const postInstructions = [];
|
|
14959
15521
|
// If drift user doesn't exist, prepend initializeUserStats and initializeUser instructions
|
|
14960
|
-
if (!await this.fetchDriftUser(
|
|
14961
|
-
preInstructions.push(await this.initializeUserStatsIx(
|
|
15522
|
+
if (!await this.fetchDriftUser(subAccountId)) {
|
|
15523
|
+
preInstructions.push(await this.initializeUserStatsIx(glamSigner), await this.initializeUserIx(glamSigner, subAccountId));
|
|
14962
15524
|
}
|
|
14963
15525
|
if (mint.equals(WSOL)) {
|
|
14964
|
-
const wrapSolIxs = await this.base.maybeWrapSol(
|
|
15526
|
+
const wrapSolIxs = await this.base.maybeWrapSol(amount, glamSigner);
|
|
14965
15527
|
preInstructions.push(...wrapSolIxs);
|
|
14966
15528
|
// If we need to wrap SOL, it means the wSOL balance will be drained,
|
|
14967
15529
|
// and we close the wSOL token account for convenience
|
|
14968
|
-
const tokenAccount = this.base.getVaultAta(
|
|
15530
|
+
const tokenAccount = this.base.getVaultAta(WSOL);
|
|
14969
15531
|
const closeTokenAccountIx = await this.base.program.methods.tokenCloseAccount().accounts({
|
|
14970
|
-
glamState,
|
|
15532
|
+
glamState: this.base.statePda,
|
|
14971
15533
|
glamSigner,
|
|
14972
15534
|
tokenAccount,
|
|
14973
15535
|
cpiProgram: splToken.TOKEN_PROGRAM_ID
|
|
@@ -14994,24 +15556,24 @@ class DriftClient {
|
|
|
14994
15556
|
});
|
|
14995
15557
|
}
|
|
14996
15558
|
const tx = await this.base.program.methods.driftDeposit(marketIndex, amount, false).accounts({
|
|
14997
|
-
glamState,
|
|
15559
|
+
glamState: this.base.statePda,
|
|
14998
15560
|
state: this.driftStatePda,
|
|
14999
15561
|
user,
|
|
15000
15562
|
userStats,
|
|
15001
15563
|
spotMarketVault: driftVault,
|
|
15002
|
-
userTokenAccount: this.base.getVaultAta(
|
|
15564
|
+
userTokenAccount: this.base.getVaultAta(mint, tokenProgram),
|
|
15003
15565
|
glamSigner,
|
|
15004
15566
|
tokenProgram
|
|
15005
15567
|
}).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
15006
15568
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15007
15569
|
}
|
|
15008
|
-
async withdrawTx(
|
|
15570
|
+
async withdrawTx(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
|
|
15009
15571
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15010
|
-
const { user, userStats } = this.getDriftUserPdas(
|
|
15572
|
+
const { user, userStats } = this.getDriftUserPdas(subAccountId);
|
|
15011
15573
|
const { mint, tokenProgram, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
|
|
15012
|
-
const glamVault = this.base.
|
|
15013
|
-
const glamVaultAta = this.base.getVaultAta(
|
|
15014
|
-
const remainingAccounts = await this.composeRemainingAccounts(
|
|
15574
|
+
const glamVault = this.base.vaultPda;
|
|
15575
|
+
const glamVaultAta = this.base.getVaultAta(mint, tokenProgram);
|
|
15576
|
+
const remainingAccounts = await this.composeRemainingAccounts(subAccountId, MarketType.SPOT, marketIndex);
|
|
15015
15577
|
if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
|
|
15016
15578
|
remainingAccounts.push({
|
|
15017
15579
|
pubkey: mint,
|
|
@@ -15024,7 +15586,7 @@ class DriftClient {
|
|
|
15024
15586
|
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, glamVaultAta, glamVault, mint, tokenProgram)
|
|
15025
15587
|
];
|
|
15026
15588
|
const tx = await this.base.program.methods.driftWithdraw(marketIndex, amount, false).accounts({
|
|
15027
|
-
glamState: statePda,
|
|
15589
|
+
glamState: this.base.statePda,
|
|
15028
15590
|
state: this.driftStatePda,
|
|
15029
15591
|
user,
|
|
15030
15592
|
userStats,
|
|
@@ -15036,10 +15598,10 @@ class DriftClient {
|
|
|
15036
15598
|
}).remainingAccounts(remainingAccounts).preInstructions(preInstructions).transaction();
|
|
15037
15599
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15038
15600
|
}
|
|
15039
|
-
async placeOrderTx(
|
|
15601
|
+
async placeOrderTx(orderParams, subAccountId = 0, txOptions = {}) {
|
|
15040
15602
|
const { marketIndex, marketType } = orderParams;
|
|
15041
15603
|
const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
|
|
15042
|
-
const remainingAccounts = (await this.composeRemainingAccounts(
|
|
15604
|
+
const remainingAccounts = (await this.composeRemainingAccounts(subAccountId, marketType, marketIndex)).concat([
|
|
15043
15605
|
{
|
|
15044
15606
|
pubkey: referrer,
|
|
15045
15607
|
isWritable: true,
|
|
@@ -15052,19 +15614,19 @@ class DriftClient {
|
|
|
15052
15614
|
}
|
|
15053
15615
|
]);
|
|
15054
15616
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15055
|
-
const { user } = this.getDriftUserPdas(
|
|
15617
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
15056
15618
|
// @ts-ignore
|
|
15057
15619
|
const tx = await this.base.program.methods.driftPlaceOrders([
|
|
15058
15620
|
orderParams
|
|
15059
15621
|
]).accounts({
|
|
15060
|
-
glamState,
|
|
15622
|
+
glamState: this.base.statePda,
|
|
15061
15623
|
user,
|
|
15062
15624
|
state: this.driftStatePda,
|
|
15063
15625
|
glamSigner
|
|
15064
15626
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
15065
15627
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15066
15628
|
}
|
|
15067
|
-
async modifyOrderTx(
|
|
15629
|
+
async modifyOrderTx(modifyOrderParams, subAccountId = 0, txOptions = {}) {
|
|
15068
15630
|
// const { marketIndex, marketType } = orderParams;
|
|
15069
15631
|
// const remainingAccounts = await this.composeRemainingAccounts(
|
|
15070
15632
|
// statePda,
|
|
@@ -15074,10 +15636,10 @@ class DriftClient {
|
|
|
15074
15636
|
// marketIndex,
|
|
15075
15637
|
// );
|
|
15076
15638
|
const signer = txOptions.signer || this.base.getSigner();
|
|
15077
|
-
const { user } = this.getDriftUserPdas(
|
|
15639
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
15078
15640
|
const tx = await this.base.program.methods// @ts-ignore
|
|
15079
15641
|
.driftModifyOrder(1, modifyOrderParams).accounts({
|
|
15080
|
-
glamState: statePda,
|
|
15642
|
+
glamState: this.base.statePda,
|
|
15081
15643
|
glamSigner: signer,
|
|
15082
15644
|
user,
|
|
15083
15645
|
state: this.driftStatePda
|
|
@@ -15085,59 +15647,44 @@ class DriftClient {
|
|
|
15085
15647
|
.transaction();
|
|
15086
15648
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15087
15649
|
}
|
|
15088
|
-
async cancelOrdersTx(
|
|
15650
|
+
async cancelOrdersTx(marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
|
|
15089
15651
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15090
|
-
const { user } = this.getDriftUserPdas(
|
|
15091
|
-
const remainingAccounts = await this.composeRemainingAccounts(
|
|
15652
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
15653
|
+
const remainingAccounts = await this.composeRemainingAccounts(subAccountId, marketType, marketIndex);
|
|
15092
15654
|
// @ts-ignore
|
|
15093
15655
|
const tx = await this.base.program.methods.driftCancelOrders(marketType, marketIndex, direction).accounts({
|
|
15094
|
-
glamState,
|
|
15656
|
+
glamState: this.base.statePda,
|
|
15095
15657
|
glamSigner,
|
|
15096
15658
|
user,
|
|
15097
15659
|
state: this.driftStatePda
|
|
15098
15660
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
15099
15661
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15100
15662
|
}
|
|
15101
|
-
async cancelOrdersByIdsTx(
|
|
15663
|
+
async cancelOrdersByIdsTx(orderIds, subAccountId = 0, txOptions = {}) {
|
|
15102
15664
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15103
|
-
const { user } = this.getDriftUserPdas(
|
|
15104
|
-
const remainingAccounts = await this.composeRemainingAccounts(
|
|
15665
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
15666
|
+
const remainingAccounts = await this.composeRemainingAccounts(subAccountId);
|
|
15105
15667
|
// @ts-ignore
|
|
15106
15668
|
const tx = await this.base.program.methods.driftCancelOrdersByIds(orderIds).accounts({
|
|
15107
|
-
glamState,
|
|
15669
|
+
glamState: this.base.statePda,
|
|
15108
15670
|
glamSigner,
|
|
15109
15671
|
user,
|
|
15110
15672
|
state: this.driftStatePda
|
|
15111
15673
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
15112
15674
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15113
15675
|
}
|
|
15114
|
-
async settlePnlTx(
|
|
15676
|
+
async settlePnlTx(marketIndex, subAccountId = 0, txOptions = {}) {
|
|
15115
15677
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15116
|
-
const { user } = this.getDriftUserPdas(
|
|
15117
|
-
const { vault: driftVault } = await this.fetchAndParseSpotMarket(
|
|
15678
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
15679
|
+
const { vault: driftVault } = await this.fetchAndParseSpotMarket(0);
|
|
15680
|
+
const remainingAccounts = await this.composeRemainingAccounts(subAccountId, MarketType.PERP, marketIndex);
|
|
15118
15681
|
// @ts-ignore
|
|
15119
15682
|
const tx = await this.base.program.methods.driftSettlePnl(marketIndex).accounts({
|
|
15120
|
-
glamState,
|
|
15683
|
+
glamState: this.base.statePda,
|
|
15121
15684
|
glamSigner,
|
|
15122
15685
|
user,
|
|
15123
15686
|
state: this.driftStatePda,
|
|
15124
15687
|
spotMarketVault: driftVault
|
|
15125
|
-
}).transaction();
|
|
15126
|
-
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15127
|
-
}
|
|
15128
|
-
async priceDriftTx(glamState, priceDenom, txOptions = {}) {
|
|
15129
|
-
const signer = txOptions.signer || this.base.getSigner();
|
|
15130
|
-
const glamVault = this.base.getVaultPda(glamState);
|
|
15131
|
-
const { user, userStats } = this.getDriftUserPdas(glamState);
|
|
15132
|
-
const remainingAccounts = await this.composeRemainingAccounts(glamState, 0);
|
|
15133
|
-
const tx = await this.base.program.methods.priceDrift(priceDenom).accounts({
|
|
15134
|
-
glamState,
|
|
15135
|
-
signer,
|
|
15136
|
-
glamVault,
|
|
15137
|
-
user,
|
|
15138
|
-
userStats,
|
|
15139
|
-
solOracle: SOL_ORACLE,
|
|
15140
|
-
state: this.driftStatePda
|
|
15141
15688
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
15142
15689
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15143
15690
|
}
|
|
@@ -15169,12 +15716,12 @@ const BASE = new web3_js.PublicKey("bJ1TRoFo2P6UHVwqdiipp6Qhp2HaaHpLowZ5LHet8Gm"
|
|
|
15169
15716
|
class JupiterSwapClient {
|
|
15170
15717
|
/*
|
|
15171
15718
|
* Client methods
|
|
15172
|
-
*/ async swap(
|
|
15173
|
-
const tx = await this.swapTx(
|
|
15719
|
+
*/ async swap(options, txOptions = {}) {
|
|
15720
|
+
const tx = await this.swapTx(options, txOptions);
|
|
15174
15721
|
return await this.base.sendAndConfirm(tx);
|
|
15175
15722
|
}
|
|
15176
|
-
async setMaxSwapSlippage(
|
|
15177
|
-
const tx = await this.setMaxSwapSlippageTx(
|
|
15723
|
+
async setMaxSwapSlippage(slippageBps, txOptions = {}) {
|
|
15724
|
+
const tx = await this.setMaxSwapSlippageTx(slippageBps, txOptions);
|
|
15178
15725
|
return await this.base.sendAndConfirm(tx);
|
|
15179
15726
|
}
|
|
15180
15727
|
async fetchProgramLabels() {
|
|
@@ -15189,9 +15736,9 @@ class JupiterSwapClient {
|
|
|
15189
15736
|
}
|
|
15190
15737
|
/*
|
|
15191
15738
|
* API methods
|
|
15192
|
-
*/ async swapTx(
|
|
15739
|
+
*/ async swapTx(options, txOptions = {}) {
|
|
15193
15740
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15194
|
-
const glamVault = this.base.
|
|
15741
|
+
const glamVault = this.base.vaultPda;
|
|
15195
15742
|
let swapInstruction;
|
|
15196
15743
|
let addressLookupTableAddresses;
|
|
15197
15744
|
let inputMint;
|
|
@@ -15237,10 +15784,10 @@ class JupiterSwapClient {
|
|
|
15237
15784
|
]);
|
|
15238
15785
|
const inputStakePool = ASSETS_MAINNET.get(inputMint.toBase58())?.oracle || null;
|
|
15239
15786
|
const outputStakePool = ASSETS_MAINNET.get(outputMint.toBase58())?.oracle || null;
|
|
15240
|
-
const preInstructions = await this.getPreInstructions(
|
|
15787
|
+
const preInstructions = await this.getPreInstructions(glamSigner, inputMint, outputMint, amount, inputTokenProgram, outputTokenProgram);
|
|
15241
15788
|
// @ts-ignore
|
|
15242
15789
|
const tx = await this.base.program.methods.jupiterSwap(swapIx.data).accounts({
|
|
15243
|
-
glamState,
|
|
15790
|
+
glamState: this.base.statePda,
|
|
15244
15791
|
glamSigner,
|
|
15245
15792
|
inputMint,
|
|
15246
15793
|
outputMint,
|
|
@@ -15254,22 +15801,19 @@ class JupiterSwapClient {
|
|
|
15254
15801
|
...txOptions
|
|
15255
15802
|
});
|
|
15256
15803
|
}
|
|
15257
|
-
async setMaxSwapSlippageTx(
|
|
15258
|
-
|
|
15259
|
-
|
|
15260
|
-
|
|
15261
|
-
glamSigner
|
|
15262
|
-
}).transaction();
|
|
15804
|
+
async setMaxSwapSlippageTx(slippageBps, txOptions = {}) {
|
|
15805
|
+
txOptions.signer || this.base.getSigner();
|
|
15806
|
+
// FIXME: interface has changed, fix this place holder
|
|
15807
|
+
const tx = new web3_js.Transaction();
|
|
15263
15808
|
return this.base.intoVersionedTransaction(tx, {
|
|
15264
15809
|
...txOptions
|
|
15265
15810
|
});
|
|
15266
15811
|
}
|
|
15267
|
-
async setMaxSwapSlippageIx(
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
}).instruction();
|
|
15812
|
+
async setMaxSwapSlippageIx(slippageBps, txOptions = {}) {
|
|
15813
|
+
txOptions.signer || this.base.getSigner();
|
|
15814
|
+
// FIXME: interface has changed, fix this place holder
|
|
15815
|
+
const tx = new web3_js.Transaction();
|
|
15816
|
+
return tx.instructions[0];
|
|
15273
15817
|
}
|
|
15274
15818
|
async getQuoteResponse(quoteParams) {
|
|
15275
15819
|
const res = await fetch(`${this.base.jupiterApi}/swap/v1/quote?` + new URLSearchParams(Object.entries(quoteParams).map(([key, val])=>[
|
|
@@ -15300,15 +15844,15 @@ class JupiterSwapClient {
|
|
|
15300
15844
|
this.base = base;
|
|
15301
15845
|
this./*
|
|
15302
15846
|
* Utils
|
|
15303
|
-
*/ getPreInstructions = async (
|
|
15304
|
-
const vault = this.base.
|
|
15305
|
-
const ata = this.base.
|
|
15847
|
+
*/ getPreInstructions = async (signer, inputMint, outputMint, amount, inputTokenProgram = splToken.TOKEN_PROGRAM_ID, outputTokenProgram = splToken.TOKEN_PROGRAM_ID)=>{
|
|
15848
|
+
const vault = this.base.vaultPda;
|
|
15849
|
+
const ata = this.base.getVaultAta(outputMint, outputTokenProgram);
|
|
15306
15850
|
const preInstructions = [
|
|
15307
15851
|
splToken.createAssociatedTokenAccountIdempotentInstruction(signer, ata, vault, outputMint, outputTokenProgram)
|
|
15308
15852
|
];
|
|
15309
15853
|
// Transfer SOL to wSOL ATA if needed for the vault
|
|
15310
15854
|
if (inputMint.equals(WSOL)) {
|
|
15311
|
-
const wrapSolIxs = await this.base.maybeWrapSol(
|
|
15855
|
+
const wrapSolIxs = await this.base.maybeWrapSol(amount, signer);
|
|
15312
15856
|
preInstructions.push(...wrapSolIxs);
|
|
15313
15857
|
}
|
|
15314
15858
|
return preInstructions;
|
|
@@ -15352,8 +15896,8 @@ class JupiterVoteClient {
|
|
|
15352
15896
|
* @param amount
|
|
15353
15897
|
* @param txOptions
|
|
15354
15898
|
* @returns
|
|
15355
|
-
*/ async stakeJup(
|
|
15356
|
-
const vault = this.base.
|
|
15899
|
+
*/ async stakeJup(amount, txOptions = {}) {
|
|
15900
|
+
const vault = this.base.vaultPda;
|
|
15357
15901
|
const escrow = this.getEscrowPda(vault);
|
|
15358
15902
|
const escrowJupAta = this.base.getAta(JUP, escrow);
|
|
15359
15903
|
const vaultJupAta = this.base.getAta(JUP, vault);
|
|
@@ -15363,19 +15907,19 @@ class JupiterVoteClient {
|
|
|
15363
15907
|
if (!escrowCreated) {
|
|
15364
15908
|
console.log("Will create escrow account:", escrow.toBase58());
|
|
15365
15909
|
preInstructions.push(await this.base.program.methods.jupiterVoteNewEscrow().accounts({
|
|
15366
|
-
glamState: statePda,
|
|
15910
|
+
glamState: this.base.statePda,
|
|
15367
15911
|
locker: this.stakeLocker,
|
|
15368
15912
|
escrow
|
|
15369
15913
|
}).instruction());
|
|
15370
15914
|
preInstructions.push(await this.base.program.methods.jupiterVoteToggleMaxLock(true).accounts({
|
|
15371
|
-
glamState: statePda,
|
|
15915
|
+
glamState: this.base.statePda,
|
|
15372
15916
|
locker: this.stakeLocker,
|
|
15373
15917
|
escrow
|
|
15374
15918
|
}).instruction());
|
|
15375
15919
|
}
|
|
15376
15920
|
preInstructions.push(splToken.createAssociatedTokenAccountIdempotentInstruction(this.base.getSigner(), escrowJupAta, escrow, JUP));
|
|
15377
15921
|
const tx = await this.base.program.methods.jupiterVoteIncreaseLockedAmount(amount).accounts({
|
|
15378
|
-
glamState: statePda,
|
|
15922
|
+
glamState: this.base.statePda,
|
|
15379
15923
|
locker: this.stakeLocker,
|
|
15380
15924
|
escrow,
|
|
15381
15925
|
escrowTokens: escrowJupAta,
|
|
@@ -15394,11 +15938,11 @@ class JupiterVoteClient {
|
|
|
15394
15938
|
* @param txOptions
|
|
15395
15939
|
* @returns
|
|
15396
15940
|
*/ // TODO: support partial unstake
|
|
15397
|
-
async unstakeJup(
|
|
15398
|
-
const vault = this.base.
|
|
15941
|
+
async unstakeJup(txOptions = {}) {
|
|
15942
|
+
const vault = this.base.vaultPda;
|
|
15399
15943
|
const escrow = this.getEscrowPda(vault);
|
|
15400
15944
|
const tx = await this.base.program.methods.jupiterVoteToggleMaxLock(false).accounts({
|
|
15401
|
-
glamState: statePda,
|
|
15945
|
+
glamState: this.base.statePda,
|
|
15402
15946
|
locker: this.stakeLocker,
|
|
15403
15947
|
escrow
|
|
15404
15948
|
}).transaction();
|
|
@@ -15407,13 +15951,13 @@ class JupiterVoteClient {
|
|
|
15407
15951
|
});
|
|
15408
15952
|
return await this.base.sendAndConfirm(vTx);
|
|
15409
15953
|
}
|
|
15410
|
-
async withdrawJup(
|
|
15411
|
-
const vault = this.base.
|
|
15954
|
+
async withdrawJup(txOptions = {}) {
|
|
15955
|
+
const vault = this.base.vaultPda;
|
|
15412
15956
|
const escrow = this.getEscrowPda(vault);
|
|
15413
15957
|
const escrowJupAta = this.base.getAta(JUP, escrow);
|
|
15414
15958
|
const vaultJupAta = this.base.getAta(JUP, vault);
|
|
15415
15959
|
const tx = await this.base.program.methods.jupiterVoteWithdraw().accounts({
|
|
15416
|
-
glamState: statePda,
|
|
15960
|
+
glamState: this.base.statePda,
|
|
15417
15961
|
locker: this.stakeLocker,
|
|
15418
15962
|
escrow,
|
|
15419
15963
|
escrowTokens: escrowJupAta,
|
|
@@ -15427,15 +15971,15 @@ class JupiterVoteClient {
|
|
|
15427
15971
|
});
|
|
15428
15972
|
return await this.base.sendAndConfirm(vTx);
|
|
15429
15973
|
}
|
|
15430
|
-
async claimAndStake(
|
|
15974
|
+
async claimAndStake(distributor, amountUnlocked, amountLocked, proof, txOptions = {}) {
|
|
15431
15975
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15432
|
-
const vault = this.base.
|
|
15976
|
+
const vault = this.base.vaultPda;
|
|
15433
15977
|
const escrow = this.getEscrowPda(vault);
|
|
15434
15978
|
const escrowJupAta = this.base.getAta(JUP, escrow);
|
|
15435
15979
|
const distributorJupAta = this.base.getAta(JUP, distributor);
|
|
15436
15980
|
// @ts-ignore
|
|
15437
15981
|
const tx = await this.base.program.methods.merkleDistributorNewClaimAndStake(amountUnlocked, amountLocked, proof).accounts({
|
|
15438
|
-
glamState: statePda,
|
|
15982
|
+
glamState: this.base.statePda,
|
|
15439
15983
|
glamSigner,
|
|
15440
15984
|
distributor,
|
|
15441
15985
|
from: distributorJupAta,
|
|
@@ -15451,11 +15995,11 @@ class JupiterVoteClient {
|
|
|
15451
15995
|
});
|
|
15452
15996
|
return await this.base.sendAndConfirm(vTx);
|
|
15453
15997
|
}
|
|
15454
|
-
async cancelUnstake(
|
|
15455
|
-
const vault = this.base.
|
|
15998
|
+
async cancelUnstake(txOptions = {}) {
|
|
15999
|
+
const vault = this.base.vaultPda;
|
|
15456
16000
|
const escrow = this.getEscrowPda(vault);
|
|
15457
16001
|
const tx = await this.base.program.methods.jupiterVoteToggleMaxLock(true).accounts({
|
|
15458
|
-
glamState: statePda,
|
|
16002
|
+
glamState: this.base.statePda,
|
|
15459
16003
|
locker: this.stakeLocker,
|
|
15460
16004
|
escrow
|
|
15461
16005
|
}).transaction();
|
|
@@ -15467,13 +16011,12 @@ class JupiterVoteClient {
|
|
|
15467
16011
|
/**
|
|
15468
16012
|
* Vote on a proposal. The vote account will be created if it doesn't exist.
|
|
15469
16013
|
*
|
|
15470
|
-
* @param statePda
|
|
15471
16014
|
* @param proposal
|
|
15472
16015
|
* @param side
|
|
15473
16016
|
* @param txOptions
|
|
15474
16017
|
* @returns
|
|
15475
|
-
*/ async voteOnProposal(
|
|
15476
|
-
const glamVault = this.base.
|
|
16018
|
+
*/ async voteOnProposal(proposal, side, txOptions = {}) {
|
|
16019
|
+
const glamVault = this.base.vaultPda;
|
|
15477
16020
|
const vote = this.getVotePda(proposal, glamVault);
|
|
15478
16021
|
const governor = this.getGovernorPda();
|
|
15479
16022
|
const voteAccountInfo = await this.base.provider.connection.getAccountInfo(vote);
|
|
@@ -15482,14 +16025,14 @@ class JupiterVoteClient {
|
|
|
15482
16025
|
if (!voteCreated) {
|
|
15483
16026
|
console.log("Will create vote account:", vote.toBase58());
|
|
15484
16027
|
preInstructions.push(await this.base.program.methods.jupiterGovNewVote(glamVault).accountsPartial({
|
|
15485
|
-
glamState,
|
|
16028
|
+
glamState: this.base.statePda,
|
|
15486
16029
|
proposal,
|
|
15487
16030
|
vote
|
|
15488
16031
|
}).instruction());
|
|
15489
16032
|
}
|
|
15490
16033
|
const escrow = this.getEscrowPda(glamVault);
|
|
15491
16034
|
const tx = await this.base.program.methods.jupiterVoteCastVote(side).accounts({
|
|
15492
|
-
glamState,
|
|
16035
|
+
glamState: this.base.statePda,
|
|
15493
16036
|
escrow,
|
|
15494
16037
|
proposal,
|
|
15495
16038
|
vote,
|
|
@@ -15504,8 +16047,8 @@ class JupiterVoteClient {
|
|
|
15504
16047
|
}
|
|
15505
16048
|
/*
|
|
15506
16049
|
* Utils
|
|
15507
|
-
*/ async fetchVotes(
|
|
15508
|
-
const glamVault = this.base.
|
|
16050
|
+
*/ async fetchVotes(proposals) {
|
|
16051
|
+
const glamVault = this.base.vaultPda;
|
|
15509
16052
|
const votes = proposals.map((proposal)=>this.getVotePda(new web3_js.PublicKey(proposal), glamVault));
|
|
15510
16053
|
const votesAccountInfo = await this.base.provider.connection.getMultipleAccountsInfo(votes);
|
|
15511
16054
|
return votesAccountInfo.filter((accountInfo)=>accountInfo !== null).map((accountInfo)=>({
|
|
@@ -15566,31 +16109,31 @@ class JupiterVoteClient {
|
|
|
15566
16109
|
class MarinadeClient {
|
|
15567
16110
|
/*
|
|
15568
16111
|
* Client methods
|
|
15569
|
-
*/ async deposit(
|
|
15570
|
-
const tx = await this.depositTx(
|
|
16112
|
+
*/ async deposit(amount, txOptions = {}) {
|
|
16113
|
+
const tx = await this.depositTx(amount, txOptions);
|
|
15571
16114
|
return await this.base.sendAndConfirm(tx);
|
|
15572
16115
|
}
|
|
15573
|
-
async depositStakeAccount(
|
|
15574
|
-
const tx = await this.depositStakeAccountTx(
|
|
16116
|
+
async depositStakeAccount(stakeAccount) {
|
|
16117
|
+
const tx = await this.depositStakeAccountTx(stakeAccount, {});
|
|
15575
16118
|
return await this.base.sendAndConfirm(tx);
|
|
15576
16119
|
}
|
|
15577
|
-
async orderUnstake(
|
|
15578
|
-
const tx = await this.orderUnstakeTx(
|
|
16120
|
+
async orderUnstake(amount, txOptions = {}) {
|
|
16121
|
+
const tx = await this.orderUnstakeTx(amount, txOptions);
|
|
15579
16122
|
return await this.base.sendAndConfirm(tx);
|
|
15580
16123
|
}
|
|
15581
|
-
async claim(
|
|
15582
|
-
const tx = await this.claimTx(
|
|
16124
|
+
async claim(tickets, txOptions = {}) {
|
|
16125
|
+
const tx = await this.claimTx(tickets, txOptions);
|
|
15583
16126
|
return await this.base.sendAndConfirm(tx);
|
|
15584
16127
|
}
|
|
15585
16128
|
/*
|
|
15586
16129
|
* Utils
|
|
15587
|
-
*/ async getTickets(
|
|
15588
|
-
const vault = this.base.
|
|
16130
|
+
*/ async getTickets() {
|
|
16131
|
+
const vault = this.base.vaultPda;
|
|
15589
16132
|
const accounts = await fetchMarinadeTicketAccounts(this.base.provider.connection, vault);
|
|
15590
16133
|
return accounts.map((a)=>a.pubkey);
|
|
15591
16134
|
}
|
|
15592
|
-
async getParsedTickets(
|
|
15593
|
-
const vault = this.base.
|
|
16135
|
+
async getParsedTickets() {
|
|
16136
|
+
const vault = this.base.vaultPda;
|
|
15594
16137
|
const accounts = await fetchMarinadeTicketAccounts(this.base.provider.connection, vault);
|
|
15595
16138
|
const currentEpoch = await this.base.provider.connection.getEpochInfo();
|
|
15596
16139
|
return accounts.map((a)=>{
|
|
@@ -15643,15 +16186,15 @@ class MarinadeClient {
|
|
|
15643
16186
|
}
|
|
15644
16187
|
/*
|
|
15645
16188
|
* API methods
|
|
15646
|
-
*/ async depositTx(
|
|
16189
|
+
*/ async depositTx(amount, txOptions) {
|
|
15647
16190
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15648
|
-
const vault = this.base.
|
|
16191
|
+
const vault = this.base.vaultPda;
|
|
15649
16192
|
const marinadeState = this.getMarinadeState();
|
|
15650
|
-
const vaultMsolAta = this.base.
|
|
16193
|
+
const vaultMsolAta = this.base.getVaultAta(marinadeState.msolMintAddress);
|
|
15651
16194
|
const createMsolAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultMsolAta, vault, marinadeState.msolMintAddress);
|
|
15652
16195
|
// @ts-ignore
|
|
15653
16196
|
const tx = await this.base.program.methods.marinadeDeposit(amount).accounts({
|
|
15654
|
-
glamState,
|
|
16197
|
+
glamState: this.base.statePda,
|
|
15655
16198
|
glamSigner,
|
|
15656
16199
|
reservePda: marinadeState.reserveAddress,
|
|
15657
16200
|
state: marinadeState.marinadeStateAddress,
|
|
@@ -15667,7 +16210,7 @@ class MarinadeClient {
|
|
|
15667
16210
|
]).transaction();
|
|
15668
16211
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15669
16212
|
}
|
|
15670
|
-
async depositStakeAccountTx(
|
|
16213
|
+
async depositStakeAccountTx(stakeAccount, txOptions) {
|
|
15671
16214
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15672
16215
|
const stakeAccountInfo = await this.getParsedStakeAccountInfo(stakeAccount);
|
|
15673
16216
|
console.log("Stake account info", stakeAccountInfo);
|
|
@@ -15677,7 +16220,7 @@ class MarinadeClient {
|
|
|
15677
16220
|
const validatorIndex = validatorLookupIndex === -1 ? marinadeState.state.validatorSystem.validatorList.count : validatorLookupIndex;
|
|
15678
16221
|
const duplicationFlag = await marinadeState.validatorDuplicationFlag(stakeAccountInfo.voter);
|
|
15679
16222
|
const tx = await this.base.program.methods.marinadeDepositStakeAccount(validatorIndex).accounts({
|
|
15680
|
-
glamState,
|
|
16223
|
+
glamState: this.base.statePda,
|
|
15681
16224
|
glamSigner,
|
|
15682
16225
|
state: marinadeState.marinadeStateAddress,
|
|
15683
16226
|
validatorList: marinadeState.state.validatorSystem.validatorList.account,
|
|
@@ -15686,17 +16229,17 @@ class MarinadeClient {
|
|
|
15686
16229
|
duplicationFlag,
|
|
15687
16230
|
msolMint: MSOL,
|
|
15688
16231
|
msolMintAuthority: await marinadeState.mSolMintAuthority(),
|
|
15689
|
-
mintTo: this.base.getVaultAta(
|
|
16232
|
+
mintTo: this.base.getVaultAta(MSOL),
|
|
15690
16233
|
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
15691
16234
|
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
15692
16235
|
stakeProgram: web3_js.StakeProgram.programId
|
|
15693
16236
|
}).transaction();
|
|
15694
16237
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15695
16238
|
}
|
|
15696
|
-
async orderUnstakeTx(
|
|
16239
|
+
async orderUnstakeTx(amount, txOptions) {
|
|
15697
16240
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15698
16241
|
const marinadeState = this.getMarinadeState();
|
|
15699
|
-
const vaultMsolAta = this.base.getVaultAta(
|
|
16242
|
+
const vaultMsolAta = this.base.getVaultAta(marinadeState.msolMintAddress);
|
|
15700
16243
|
const ticketSeed = Date.now().toString();
|
|
15701
16244
|
const ticket = await web3_js.PublicKey.createWithSeed(glamSigner, ticketSeed, MARINADE_PROGRAM_ID);
|
|
15702
16245
|
const lamports = await this.base.provider.connection.getMinimumBalanceForRentExemption(MARINADE_TICKET_SIZE);
|
|
@@ -15710,7 +16253,7 @@ class MarinadeClient {
|
|
|
15710
16253
|
programId: MARINADE_PROGRAM_ID
|
|
15711
16254
|
});
|
|
15712
16255
|
const tx = await this.base.program.methods.marinadeOrderUnstake(amount).accounts({
|
|
15713
|
-
glamState,
|
|
16256
|
+
glamState: this.base.statePda,
|
|
15714
16257
|
glamSigner,
|
|
15715
16258
|
newTicketAccount: ticket,
|
|
15716
16259
|
msolMint: marinadeState.msolMintAddress,
|
|
@@ -15723,14 +16266,14 @@ class MarinadeClient {
|
|
|
15723
16266
|
]).transaction();
|
|
15724
16267
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15725
16268
|
}
|
|
15726
|
-
async claimTx(
|
|
16269
|
+
async claimTx(tickets, txOptions) {
|
|
15727
16270
|
if (tickets.length < 1) {
|
|
15728
16271
|
throw new Error("At least one ticket is required");
|
|
15729
16272
|
}
|
|
15730
16273
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15731
16274
|
const marinadeState = this.getMarinadeState();
|
|
15732
16275
|
const instructions = await Promise.all(tickets.map((ticket)=>this.base.program.methods.marinadeClaim().accounts({
|
|
15733
|
-
glamState,
|
|
16276
|
+
glamState: this.base.statePda,
|
|
15734
16277
|
glamSigner,
|
|
15735
16278
|
ticketAccount: ticket,
|
|
15736
16279
|
state: marinadeState.marinadeStateAddress,
|
|
@@ -15749,37 +16292,36 @@ class MarinadeClient {
|
|
|
15749
16292
|
class WSolClient {
|
|
15750
16293
|
/*
|
|
15751
16294
|
* Client methods
|
|
15752
|
-
*/ async wrap(
|
|
15753
|
-
const tx = await this.wrapTx(
|
|
16295
|
+
*/ async wrap(amount, txOptions = {}) {
|
|
16296
|
+
const tx = await this.wrapTx(amount, txOptions);
|
|
15754
16297
|
return await this.base.sendAndConfirm(tx);
|
|
15755
16298
|
}
|
|
15756
|
-
async unwrap(
|
|
15757
|
-
const tx = await this.unwrapTx(
|
|
16299
|
+
async unwrap(txOptions = {}) {
|
|
16300
|
+
const tx = await this.unwrapTx(txOptions);
|
|
15758
16301
|
return await this.base.sendAndConfirm(tx);
|
|
15759
16302
|
}
|
|
15760
16303
|
/*
|
|
15761
16304
|
* API methods
|
|
15762
|
-
*/ async wrapTx(
|
|
16305
|
+
*/ async wrapTx(amount, txOptions) {
|
|
15763
16306
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15764
|
-
const
|
|
15765
|
-
const to = this.base.getAta(WSOL, vault);
|
|
16307
|
+
const to = this.base.getVaultAta(WSOL);
|
|
15766
16308
|
// @ts-ignore
|
|
15767
16309
|
const tx = await this.base.program.methods.systemTransfer(amount).accounts({
|
|
15768
|
-
glamState,
|
|
16310
|
+
glamState: this.base.statePda,
|
|
15769
16311
|
glamSigner,
|
|
15770
16312
|
to
|
|
15771
16313
|
}).preInstructions([
|
|
15772
|
-
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, to,
|
|
16314
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, to, this.base.vaultPda, WSOL)
|
|
15773
16315
|
]).postInstructions([
|
|
15774
16316
|
splToken.createSyncNativeInstruction(to)
|
|
15775
16317
|
]).transaction();
|
|
15776
16318
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
15777
16319
|
}
|
|
15778
|
-
async unwrapTx(
|
|
16320
|
+
async unwrapTx(txOptions) {
|
|
15779
16321
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15780
|
-
const tokenAccount = this.base.getVaultAta(
|
|
16322
|
+
const tokenAccount = this.base.getVaultAta(WSOL);
|
|
15781
16323
|
const tx = await this.base.program.methods.tokenCloseAccount().accounts({
|
|
15782
|
-
glamState,
|
|
16324
|
+
glamState: this.base.statePda,
|
|
15783
16325
|
glamSigner,
|
|
15784
16326
|
tokenAccount,
|
|
15785
16327
|
cpiProgram: splToken.TOKEN_PROGRAM_ID
|
|
@@ -15794,11 +16336,11 @@ class WSolClient {
|
|
|
15794
16336
|
class StakingClient {
|
|
15795
16337
|
/*
|
|
15796
16338
|
* Client methods
|
|
15797
|
-
*/ async unstake(
|
|
16339
|
+
*/ async unstake(asset, amount, txOptions = {}) {
|
|
15798
16340
|
const assetStr = asset.toBase58();
|
|
15799
16341
|
// mSOL
|
|
15800
16342
|
if (assetStr === MSOL.toBase58()) {
|
|
15801
|
-
const tx = await this.marinade.orderUnstakeTx(
|
|
16343
|
+
const tx = await this.marinade.orderUnstakeTx(new anchor.BN(amount), txOptions);
|
|
15802
16344
|
return await this.base.sendAndConfirm(tx);
|
|
15803
16345
|
}
|
|
15804
16346
|
// Other LSTs
|
|
@@ -15806,47 +16348,47 @@ class StakingClient {
|
|
|
15806
16348
|
if (!assetMeta || !assetMeta.oracle) {
|
|
15807
16349
|
throw new Error("Invalid LST: " + asset);
|
|
15808
16350
|
}
|
|
15809
|
-
const tx = await this.stakePoolWithdrawStakeTx(
|
|
16351
|
+
const tx = await this.stakePoolWithdrawStakeTx(assetMeta.oracle, new anchor.BN(amount), true, txOptions);
|
|
15810
16352
|
return await this.base.sendAndConfirm(tx);
|
|
15811
16353
|
}
|
|
15812
|
-
async stakePoolDepositSol(
|
|
15813
|
-
const tx = await this.stakePoolDepositSolTx(
|
|
16354
|
+
async stakePoolDepositSol(stakePool, amount, txOptions = {}) {
|
|
16355
|
+
const tx = await this.stakePoolDepositSolTx(stakePool, amount, txOptions);
|
|
15814
16356
|
return await this.base.sendAndConfirm(tx);
|
|
15815
16357
|
}
|
|
15816
|
-
async stakePoolDepositStake(
|
|
15817
|
-
const tx = await this.stakePoolDepositStakeTx(
|
|
16358
|
+
async stakePoolDepositStake(stakePool, stakeAccount, txOptions = {}) {
|
|
16359
|
+
const tx = await this.stakePoolDepositStakeTx(stakePool, stakeAccount, txOptions);
|
|
15818
16360
|
return await this.base.sendAndConfirm(tx);
|
|
15819
16361
|
}
|
|
15820
|
-
async stakePoolWithdrawStake(
|
|
15821
|
-
const tx = await this.stakePoolWithdrawStakeTx(
|
|
16362
|
+
async stakePoolWithdrawStake(stakePool, amount, txOptions = {}) {
|
|
16363
|
+
const tx = await this.stakePoolWithdrawStakeTx(stakePool, amount, false, txOptions);
|
|
15822
16364
|
return await this.base.sendAndConfirm(tx);
|
|
15823
16365
|
}
|
|
15824
|
-
async initializeAndDelegateStake(
|
|
15825
|
-
const tx = await this.initializeAndDelegateStakeTx(
|
|
16366
|
+
async initializeAndDelegateStake(vote, amount, txOptions = {}) {
|
|
16367
|
+
const tx = await this.initializeAndDelegateStakeTx(vote, amount, txOptions);
|
|
15826
16368
|
return await this.base.sendAndConfirm(tx);
|
|
15827
16369
|
}
|
|
15828
|
-
async deactivate(
|
|
15829
|
-
const tx = await this.deactivateStakeTx(
|
|
16370
|
+
async deactivate(stakeAccounts, txOptions = {}) {
|
|
16371
|
+
const tx = await this.deactivateStakeTx(stakeAccounts, txOptions);
|
|
15830
16372
|
return await this.base.sendAndConfirm(tx);
|
|
15831
16373
|
}
|
|
15832
|
-
async withdraw(
|
|
15833
|
-
const tx = await this.withdrawStakeTx(
|
|
16374
|
+
async withdraw(stakeAccounts, txOptions = {}) {
|
|
16375
|
+
const tx = await this.withdrawStakeTx(stakeAccounts, txOptions);
|
|
15834
16376
|
return await this.base.sendAndConfirm(tx);
|
|
15835
16377
|
}
|
|
15836
|
-
async merge(
|
|
15837
|
-
const tx = await this.mergeStakeTx(
|
|
16378
|
+
async merge(destinationStake, sourceStake, txOptions = {}) {
|
|
16379
|
+
const tx = await this.mergeStakeTx(destinationStake, sourceStake, txOptions);
|
|
15838
16380
|
return await this.base.sendAndConfirm(tx);
|
|
15839
16381
|
}
|
|
15840
|
-
async split(
|
|
15841
|
-
const { tx, newStake } = await this.splitStakeTx(
|
|
16382
|
+
async split(existingStake, lamports, txOptions = {}) {
|
|
16383
|
+
const { tx, newStake } = await this.splitStakeTx(existingStake, lamports, txOptions);
|
|
15842
16384
|
const txSig = await this.base.sendAndConfirm(tx);
|
|
15843
16385
|
return {
|
|
15844
16386
|
newStake,
|
|
15845
16387
|
txSig
|
|
15846
16388
|
};
|
|
15847
16389
|
}
|
|
15848
|
-
async redelegate(
|
|
15849
|
-
const { newStake, tx } = await this.redelegateStakeTx(
|
|
16390
|
+
async redelegate(existingStake, vote, txOptions = {}) {
|
|
16391
|
+
const { newStake, tx } = await this.redelegateStakeTx(existingStake, vote, txOptions);
|
|
15850
16392
|
const txSig = await this.base.sendAndConfirm(tx);
|
|
15851
16393
|
return {
|
|
15852
16394
|
newStake,
|
|
@@ -15855,13 +16397,12 @@ class StakingClient {
|
|
|
15855
16397
|
}
|
|
15856
16398
|
/*
|
|
15857
16399
|
* Utils
|
|
15858
|
-
*/ getStakeAccountPda(state, accountId) {
|
|
15859
|
-
|
|
15860
|
-
|
|
15861
|
-
|
|
15862
|
-
|
|
15863
|
-
|
|
15864
|
-
}
|
|
16400
|
+
*/ // getStakeAccountPda(state: PublicKey, accountId: string): [PublicKey, number] {
|
|
16401
|
+
// return PublicKey.findProgramAddressSync(
|
|
16402
|
+
// [Buffer.from("stake_account"), Buffer.from(accountId), state.toBuffer()],
|
|
16403
|
+
// this.base.program.programId,
|
|
16404
|
+
// );
|
|
16405
|
+
// }
|
|
15865
16406
|
getStakePoolWithdrawAuthority(programId, stakePool) {
|
|
15866
16407
|
const [publicKey] = web3_js.PublicKey.findProgramAddressSync([
|
|
15867
16408
|
stakePool.toBuffer(),
|
|
@@ -15877,6 +16418,7 @@ class StakingClient {
|
|
|
15877
16418
|
return publicKey;
|
|
15878
16419
|
}
|
|
15879
16420
|
async getStakeAccountsWithStates(withdrawAuthority) {
|
|
16421
|
+
const authority = withdrawAuthority || this.base.vaultPda;
|
|
15880
16422
|
const accounts = await this.base.provider.connection.getParsedProgramAccounts(web3_js.StakeProgram.programId, {
|
|
15881
16423
|
filters: [
|
|
15882
16424
|
{
|
|
@@ -15885,7 +16427,7 @@ class StakingClient {
|
|
|
15885
16427
|
{
|
|
15886
16428
|
memcmp: {
|
|
15887
16429
|
offset: 12,
|
|
15888
|
-
bytes:
|
|
16430
|
+
bytes: authority.toBase58()
|
|
15889
16431
|
}
|
|
15890
16432
|
}
|
|
15891
16433
|
]
|
|
@@ -15975,16 +16517,16 @@ class StakingClient {
|
|
|
15975
16517
|
}
|
|
15976
16518
|
/*
|
|
15977
16519
|
* API methods
|
|
15978
|
-
*/ async stakePoolDepositSolTx(
|
|
16520
|
+
*/ async stakePoolDepositSolTx(stakePool, lamports, txOptions = {}) {
|
|
15979
16521
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
15980
16522
|
const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, tokenProgramId: tokenProgram, reserveStake } = await this.getStakePoolAccountData(stakePool);
|
|
15981
|
-
const glamVault = this.base.
|
|
15982
|
-
const poolTokensTo = this.base.
|
|
16523
|
+
const glamVault = this.base.vaultPda;
|
|
16524
|
+
const poolTokensTo = this.base.getVaultAta(poolMint, tokenProgram);
|
|
15983
16525
|
console.log(`stakePool ${stakePool}, programId: ${stakePoolProgram}`);
|
|
15984
16526
|
// @ts-ignore
|
|
15985
16527
|
const tx = await this.base.program.methods.stakePoolDepositSol(lamports).accounts({
|
|
15986
16528
|
glamSigner,
|
|
15987
|
-
glamState,
|
|
16529
|
+
glamState: this.base.statePda,
|
|
15988
16530
|
cpiProgram: stakePoolProgram,
|
|
15989
16531
|
stakePool,
|
|
15990
16532
|
stakePoolWithdrawAuthority: withdrawAuthority,
|
|
@@ -15999,11 +16541,11 @@ class StakingClient {
|
|
|
15999
16541
|
]).transaction();
|
|
16000
16542
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16001
16543
|
}
|
|
16002
|
-
async stakePoolDepositStakeTx(
|
|
16544
|
+
async stakePoolDepositStakeTx(stakePool, stakeAccount, txOptions = {}) {
|
|
16003
16545
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16004
16546
|
const { programId: stakePoolProgram, poolMint, depositAuthority, withdrawAuthority, feeAccount, validatorList, tokenProgramId: tokenProgram, reserveStake } = await this.getStakePoolAccountData(stakePool);
|
|
16005
|
-
const glamVault = this.base.
|
|
16006
|
-
const poolTokensTo = this.base.
|
|
16547
|
+
const glamVault = this.base.vaultPda;
|
|
16548
|
+
const poolTokensTo = this.base.getVaultAta(poolMint, tokenProgram);
|
|
16007
16549
|
// All stake accounts owned by the stake pool withdraw authority
|
|
16008
16550
|
const validatorStakeCandidates = await this.getStakeAccountsWithStates(withdrawAuthority);
|
|
16009
16551
|
// Find a validator stake account to use from the list of candidates.
|
|
@@ -16018,7 +16560,7 @@ class StakingClient {
|
|
|
16018
16560
|
}
|
|
16019
16561
|
const tx = await this.base.program.methods.stakePoolDepositStake().accounts({
|
|
16020
16562
|
glamSigner,
|
|
16021
|
-
glamState,
|
|
16563
|
+
glamState: this.base.statePda,
|
|
16022
16564
|
cpiProgram: stakePoolProgram,
|
|
16023
16565
|
stakePool,
|
|
16024
16566
|
stakePoolWithdrawAuthority: withdrawAuthority,
|
|
@@ -16036,11 +16578,11 @@ class StakingClient {
|
|
|
16036
16578
|
]).transaction();
|
|
16037
16579
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16038
16580
|
}
|
|
16039
|
-
async stakePoolWithdrawStakeTx(
|
|
16581
|
+
async stakePoolWithdrawStakeTx(stakePool, amount, deactivate = false, txOptions = {}) {
|
|
16040
16582
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16041
16583
|
const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, tokenProgramId: tokenProgram, validatorList, reserveStake } = await this.getStakePoolAccountData(stakePool);
|
|
16042
|
-
|
|
16043
|
-
const poolTokensFrom = this.base.
|
|
16584
|
+
this.base.vaultPda;
|
|
16585
|
+
const poolTokensFrom = this.base.getVaultAta(poolMint, tokenProgram);
|
|
16044
16586
|
// The reserve stake account should NOT be used for withdrawals unless we have no other options.
|
|
16045
16587
|
const validatorStakeCandidates = (await this.getStakeAccountsWithStates(withdrawAuthority)).filter((s)=>!s.address.equals(reserveStake));
|
|
16046
16588
|
console.log("validatorStakeCandidates", validatorStakeCandidates);
|
|
@@ -16049,13 +16591,13 @@ class StakingClient {
|
|
|
16049
16591
|
const postInstructions = deactivate ? [
|
|
16050
16592
|
await this.base.program.methods.stakeDeactivate().accounts({
|
|
16051
16593
|
glamSigner,
|
|
16052
|
-
glamState,
|
|
16594
|
+
glamState: this.base.statePda,
|
|
16053
16595
|
stake: stakeAccount
|
|
16054
16596
|
}).instruction()
|
|
16055
16597
|
] : [];
|
|
16056
16598
|
const tx = await this.base.program.methods.stakePoolWithdrawStake(amount).accounts({
|
|
16057
16599
|
glamSigner,
|
|
16058
|
-
glamState,
|
|
16600
|
+
glamState: this.base.statePda,
|
|
16059
16601
|
cpiProgram: stakePoolProgram,
|
|
16060
16602
|
stake: stakeAccount,
|
|
16061
16603
|
stakePool,
|
|
@@ -16071,21 +16613,21 @@ class StakingClient {
|
|
|
16071
16613
|
]).postInstructions(postInstructions).transaction();
|
|
16072
16614
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16073
16615
|
}
|
|
16074
|
-
async initializeAndDelegateStakeTx(
|
|
16616
|
+
async initializeAndDelegateStakeTx(vote, amount, txOptions = {}) {
|
|
16075
16617
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16076
16618
|
const [stakeAccount, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
|
|
16077
16619
|
const initStakeIx = await this.base.program.methods.stakeInitialize().accounts({
|
|
16078
|
-
glamState,
|
|
16620
|
+
glamState: this.base.statePda,
|
|
16079
16621
|
glamSigner,
|
|
16080
16622
|
stake: stakeAccount
|
|
16081
16623
|
}).instruction();
|
|
16082
16624
|
const fundStakeIx = await this.base.program.methods.systemTransfer(amount).accounts({
|
|
16083
|
-
glamState,
|
|
16625
|
+
glamState: this.base.statePda,
|
|
16084
16626
|
glamSigner,
|
|
16085
16627
|
to: stakeAccount
|
|
16086
16628
|
}).instruction();
|
|
16087
16629
|
const tx = await this.base.program.methods.stakeDelegateStake().accounts({
|
|
16088
|
-
glamState,
|
|
16630
|
+
glamState: this.base.statePda,
|
|
16089
16631
|
glamSigner,
|
|
16090
16632
|
stake: stakeAccount,
|
|
16091
16633
|
vote,
|
|
@@ -16097,13 +16639,13 @@ class StakingClient {
|
|
|
16097
16639
|
]).transaction();
|
|
16098
16640
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16099
16641
|
}
|
|
16100
|
-
async deactivateStakeTx(
|
|
16642
|
+
async deactivateStakeTx(stakeAccounts, txOptions = {}) {
|
|
16101
16643
|
if (stakeAccounts.length < 1) {
|
|
16102
16644
|
throw new Error("At least one stake account is required");
|
|
16103
16645
|
}
|
|
16104
16646
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16105
16647
|
const tx = await this.base.program.methods.stakeDeactivate().accounts({
|
|
16106
|
-
glamState,
|
|
16648
|
+
glamState: this.base.statePda,
|
|
16107
16649
|
glamSigner,
|
|
16108
16650
|
stake: stakeAccounts[0]
|
|
16109
16651
|
}).remainingAccounts(stakeAccounts.slice(1).map((a)=>({
|
|
@@ -16113,7 +16655,7 @@ class StakingClient {
|
|
|
16113
16655
|
}))).transaction();
|
|
16114
16656
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16115
16657
|
}
|
|
16116
|
-
async withdrawStakeTx(
|
|
16658
|
+
async withdrawStakeTx(stakeAccounts, txOptions = {}) {
|
|
16117
16659
|
if (stakeAccounts.length < 1) {
|
|
16118
16660
|
throw new Error("At least one stake account is required");
|
|
16119
16661
|
}
|
|
@@ -16125,7 +16667,7 @@ class StakingClient {
|
|
|
16125
16667
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16126
16668
|
const tx = await this.base.program.methods.stakeWithdraw(lamports).accounts({
|
|
16127
16669
|
glamSigner,
|
|
16128
|
-
glamState,
|
|
16670
|
+
glamState: this.base.statePda,
|
|
16129
16671
|
stake: stakeAccounts[0]
|
|
16130
16672
|
}).remainingAccounts(stakeAccounts.slice(1).map((a)=>({
|
|
16131
16673
|
pubkey: a,
|
|
@@ -16134,22 +16676,22 @@ class StakingClient {
|
|
|
16134
16676
|
}))).transaction();
|
|
16135
16677
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16136
16678
|
}
|
|
16137
|
-
async mergeStakeTx(
|
|
16679
|
+
async mergeStakeTx(destinationStake, sourceStake, txOptions = {}) {
|
|
16138
16680
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16139
16681
|
const tx = await this.base.program.methods.stakeMerge().accounts({
|
|
16140
16682
|
glamSigner,
|
|
16141
|
-
glamState,
|
|
16683
|
+
glamState: this.base.statePda,
|
|
16142
16684
|
destinationStake,
|
|
16143
16685
|
sourceStake
|
|
16144
16686
|
}).transaction();
|
|
16145
16687
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16146
16688
|
}
|
|
16147
|
-
async splitStakeTx(
|
|
16689
|
+
async splitStakeTx(existingStake, lamports, txOptions = {}) {
|
|
16148
16690
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16149
16691
|
const [newStake, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
|
|
16150
16692
|
const tx = await this.base.program.methods.stakeSplit(lamports).accounts({
|
|
16151
16693
|
glamSigner,
|
|
16152
|
-
glamState,
|
|
16694
|
+
glamState: this.base.statePda,
|
|
16153
16695
|
stake: existingStake,
|
|
16154
16696
|
splitStake: newStake
|
|
16155
16697
|
}).preInstructions([
|
|
@@ -16161,12 +16703,12 @@ class StakingClient {
|
|
|
16161
16703
|
newStake
|
|
16162
16704
|
};
|
|
16163
16705
|
}
|
|
16164
|
-
async redelegateStakeTx(
|
|
16706
|
+
async redelegateStakeTx(existingStake, vote, txOptions = {}) {
|
|
16165
16707
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16166
16708
|
const [newStake, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
|
|
16167
16709
|
const tx = await this.base.program.methods.stakeRedelegate().accounts({
|
|
16168
16710
|
glamSigner,
|
|
16169
|
-
glamState,
|
|
16711
|
+
glamState: this.base.statePda,
|
|
16170
16712
|
vote,
|
|
16171
16713
|
stake: existingStake,
|
|
16172
16714
|
newStake,
|
|
@@ -16186,51 +16728,49 @@ class StakingClient {
|
|
|
16186
16728
|
}
|
|
16187
16729
|
}
|
|
16188
16730
|
|
|
16189
|
-
function getPublicKey(input) {
|
|
16190
|
-
return typeof input === "string" ? new web3_js.PublicKey(input) : input;
|
|
16191
|
-
}
|
|
16192
16731
|
class StateClient {
|
|
16193
|
-
async
|
|
16732
|
+
async create(partialStateModel, singleTx = false, txOptions = {}) {
|
|
16194
16733
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16195
16734
|
let stateModel = this.enrichStateModel(partialStateModel);
|
|
16196
|
-
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
const openfunds = this.base.getOpenfundsPda(glamState);
|
|
16735
|
+
const statePda = getStatePda(stateModel, this.base.program.programId);
|
|
16736
|
+
this.base.statePda = statePda;
|
|
16737
|
+
console.log(`State PDA set to GlamClient: ${statePda}`);
|
|
16200
16738
|
const mints = stateModel.mints;
|
|
16201
16739
|
stateModel.mints = [];
|
|
16202
16740
|
if (mints && mints.length > 1) {
|
|
16203
|
-
throw new Error("Multiple mints not supported");
|
|
16741
|
+
throw new Error("Multiple mints not supported. Only 1 mint is allowed.");
|
|
16204
16742
|
}
|
|
16205
|
-
// No
|
|
16743
|
+
// No mint, only need to initialize the state
|
|
16206
16744
|
if (mints && mints.length === 0) {
|
|
16207
16745
|
// @ts-ignore
|
|
16208
16746
|
const tx = await this.base.program.methods.initializeState(stateModel).accountsPartial({
|
|
16209
|
-
glamState,
|
|
16747
|
+
glamState: statePda,
|
|
16210
16748
|
glamSigner,
|
|
16211
|
-
glamVault
|
|
16749
|
+
glamVault: this.base.vaultPda
|
|
16212
16750
|
}).transaction();
|
|
16213
16751
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16214
16752
|
const txSig = await this.base.sendAndConfirm(vTx);
|
|
16215
16753
|
return [
|
|
16216
16754
|
txSig,
|
|
16217
|
-
|
|
16755
|
+
statePda
|
|
16218
16756
|
];
|
|
16219
16757
|
}
|
|
16220
|
-
let extraMetasAccount =
|
|
16758
|
+
// let extraMetasAccount =
|
|
16759
|
+
// mints && mints[0].lockUpPeriod && mints[0].lockUpPeriod > 0
|
|
16760
|
+
// ? this.base.extraMetasPda
|
|
16761
|
+
// : null;
|
|
16221
16762
|
// Initialize state and add mint in one transaction
|
|
16222
16763
|
if (mints && mints.length > 0 && singleTx) {
|
|
16223
16764
|
const initStateIx = await this.base.program.methods.initializeState(stateModel).accountsPartial({
|
|
16224
|
-
glamState,
|
|
16765
|
+
glamState: statePda,
|
|
16225
16766
|
glamSigner,
|
|
16226
|
-
glamVault
|
|
16767
|
+
glamVault: this.base.vaultPda
|
|
16227
16768
|
}).instruction();
|
|
16228
|
-
const newMint = this.base.getMintPda(glamState, 0);
|
|
16229
16769
|
const tx = await this.base.program.methods.addMint(mints[0]).accounts({
|
|
16230
|
-
glamState,
|
|
16770
|
+
glamState: statePda,
|
|
16231
16771
|
glamSigner,
|
|
16232
|
-
newMint,
|
|
16233
|
-
extraMetasAccount
|
|
16772
|
+
newMint: this.base.mintPda,
|
|
16773
|
+
extraMetasAccount: this.base.extraMetasPda
|
|
16234
16774
|
}).preInstructions([
|
|
16235
16775
|
initStateIx
|
|
16236
16776
|
]).transaction();
|
|
@@ -16238,53 +16778,73 @@ class StateClient {
|
|
|
16238
16778
|
const txSig = await this.base.sendAndConfirm(vTx);
|
|
16239
16779
|
return [
|
|
16240
16780
|
txSig,
|
|
16241
|
-
|
|
16781
|
+
statePda
|
|
16242
16782
|
];
|
|
16243
16783
|
}
|
|
16244
16784
|
// Initialize state and add mints in separate transactions
|
|
16245
16785
|
const tx = await this.base.program.methods.initializeState(stateModel).accountsPartial({
|
|
16246
|
-
glamState,
|
|
16247
|
-
glamVault,
|
|
16786
|
+
glamState: statePda,
|
|
16787
|
+
glamVault: this.base.vaultPda,
|
|
16248
16788
|
glamSigner,
|
|
16249
|
-
openfundsMetadata:
|
|
16789
|
+
openfundsMetadata: this.base.openfundsPda
|
|
16250
16790
|
}).transaction();
|
|
16251
16791
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16252
16792
|
const txSig = await this.base.sendAndConfirm(vTx);
|
|
16253
16793
|
await Promise.all((mints || []).map(async (mint, j)=>{
|
|
16254
|
-
const newMint = this.base.getMintPda(glamState, j);
|
|
16255
16794
|
const tx = await this.base.program.methods.addMint(mint).accounts({
|
|
16256
|
-
glamState,
|
|
16795
|
+
glamState: statePda,
|
|
16257
16796
|
glamSigner,
|
|
16258
|
-
newMint,
|
|
16259
|
-
extraMetasAccount
|
|
16797
|
+
newMint: this.base.mintPda,
|
|
16798
|
+
extraMetasAccount: this.base.extraMetasPda
|
|
16260
16799
|
}).transaction();
|
|
16261
16800
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16262
16801
|
return await this.base.sendAndConfirm(vTx);
|
|
16263
16802
|
}));
|
|
16264
16803
|
return [
|
|
16265
16804
|
txSig,
|
|
16266
|
-
|
|
16805
|
+
statePda
|
|
16267
16806
|
];
|
|
16268
16807
|
}
|
|
16269
|
-
async
|
|
16270
|
-
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
|
|
16808
|
+
async update(updated, txOptions = {}) {
|
|
16809
|
+
const tx = await this.updateStateTx(updated, txOptions);
|
|
16810
|
+
return await this.base.sendAndConfirm(tx);
|
|
16811
|
+
}
|
|
16812
|
+
async updateApplyTimelock(txOptions = {}) {
|
|
16813
|
+
const tx = await this.updateStateApplyTimelockTx(txOptions);
|
|
16274
16814
|
return await this.base.sendAndConfirm(tx);
|
|
16275
16815
|
}
|
|
16276
|
-
async
|
|
16816
|
+
async emergencyUpdate(updated, txOptions = {}) {
|
|
16817
|
+
const vTx = await this.emergencyUpdateStateTx(updated, txOptions);
|
|
16818
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16819
|
+
}
|
|
16820
|
+
async updateStateTx(updated, txOptions) {
|
|
16277
16821
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16278
16822
|
const tx = await this.base.program.methods.updateState(new StateIdlModel(updated)).accounts({
|
|
16279
|
-
glamState,
|
|
16823
|
+
glamState: this.base.statePda,
|
|
16824
|
+
glamSigner
|
|
16825
|
+
}).preInstructions(txOptions.preInstructions || []).transaction();
|
|
16826
|
+
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16827
|
+
}
|
|
16828
|
+
async updateStateApplyTimelockTx(txOptions) {
|
|
16829
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16830
|
+
const tx = await this.base.program.methods.updateStateApplyTimelock().accounts({
|
|
16831
|
+
glamState: this.base.statePda,
|
|
16832
|
+
glamSigner
|
|
16833
|
+
}).preInstructions(txOptions.preInstructions || []).transaction();
|
|
16834
|
+
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16835
|
+
}
|
|
16836
|
+
async emergencyUpdateStateTx(updated, txOptions) {
|
|
16837
|
+
const glamSigner = txOptions.signer || this.base.signer;
|
|
16838
|
+
const tx = await this.base.program.methods.emergencyUpdateState(new StateIdlModel(updated)).accounts({
|
|
16839
|
+
glamState: this.base.statePda,
|
|
16280
16840
|
glamSigner
|
|
16281
16841
|
}).preInstructions(txOptions.preInstructions || []).transaction();
|
|
16282
16842
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16283
16843
|
}
|
|
16284
|
-
async
|
|
16844
|
+
async close(txOptions = {}) {
|
|
16285
16845
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16286
16846
|
const tx = await this.base.program.methods.closeState().accounts({
|
|
16287
|
-
glamState,
|
|
16847
|
+
glamState: this.base.statePda,
|
|
16288
16848
|
glamSigner
|
|
16289
16849
|
}).preInstructions(txOptions.preInstructions || []).transaction();
|
|
16290
16850
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
@@ -16295,7 +16855,9 @@ class StateClient {
|
|
|
16295
16855
|
*/ enrichStateModel(partialStateModel) {
|
|
16296
16856
|
const owner = this.base.getSigner();
|
|
16297
16857
|
const defaultDate = new Date().toISOString().split("T")[0];
|
|
16298
|
-
|
|
16858
|
+
if (!partialStateModel?.name) {
|
|
16859
|
+
throw new Error("Name must be specified in partial state model");
|
|
16860
|
+
}
|
|
16299
16861
|
// createdKey = hash state name and get first 8 bytes
|
|
16300
16862
|
// useful for computing state account PDA in the future
|
|
16301
16863
|
partialStateModel.created = new CreatedModel({
|
|
@@ -16315,13 +16877,13 @@ class StateClient {
|
|
|
16315
16877
|
const mint = partialStateModel.mints[0];
|
|
16316
16878
|
partialStateModel.rawOpenfunds.fundCurrency = partialStateModel.rawOpenfunds?.fundCurrency || mint.rawOpenfunds?.shareClassCurrency || null;
|
|
16317
16879
|
} else if (partialStateModel.mints?.length && partialStateModel.mints.length > 1) {
|
|
16318
|
-
throw new Error("
|
|
16880
|
+
throw new Error("Multiple mints are not supported. Only 1 mint is allowed.");
|
|
16319
16881
|
}
|
|
16320
16882
|
if (partialStateModel.enabled) {
|
|
16321
16883
|
partialStateModel.rawOpenfunds.fundLaunchDate = partialStateModel.rawOpenfunds?.fundLaunchDate || defaultDate;
|
|
16322
16884
|
}
|
|
16323
16885
|
// fields containing fund id / pda
|
|
16324
|
-
const statePda = this.base.
|
|
16886
|
+
const statePda = getStatePda(partialStateModel, this.base.program.programId);
|
|
16325
16887
|
partialStateModel.uri = partialStateModel.uri || `https://gui.glam.systems/products/${statePda}`;
|
|
16326
16888
|
partialStateModel.metadata = new Metadata({
|
|
16327
16889
|
...partialStateModel.metadata,
|
|
@@ -16341,10 +16903,10 @@ class StateClient {
|
|
|
16341
16903
|
} else {
|
|
16342
16904
|
mint.isRawOpenfunds = false;
|
|
16343
16905
|
}
|
|
16344
|
-
const
|
|
16345
|
-
mint.uri = `https://api.glam.systems/metadata/${
|
|
16906
|
+
const mintPda = getMintPda(statePda, i, this.base.program.programId);
|
|
16907
|
+
mint.uri = `https://api.glam.systems/metadata/${mintPda}`;
|
|
16346
16908
|
mint.statePubkey = statePda;
|
|
16347
|
-
mint.imageUri = `https://api.glam.systems/v0/sparkle?key=${
|
|
16909
|
+
mint.imageUri = `https://api.glam.systems/v0/sparkle?key=${mintPda}&format=png`;
|
|
16348
16910
|
});
|
|
16349
16911
|
// convert partial share class models to full share class models
|
|
16350
16912
|
partialStateModel.mints = (partialStateModel.mints || []).map((s)=>new MintModel(s));
|
|
@@ -16356,31 +16918,30 @@ class StateClient {
|
|
|
16356
16918
|
* @param statePda
|
|
16357
16919
|
* @param delegates Public keys of delegates to be deleted
|
|
16358
16920
|
* @returns
|
|
16359
|
-
*/ async deleteDelegateAcls(
|
|
16360
|
-
|
|
16921
|
+
*/ async deleteDelegateAcls(delegates, txOptions = {}) {
|
|
16922
|
+
return await this.update({
|
|
16361
16923
|
delegateAcls: delegates.map((pubkey)=>({
|
|
16362
16924
|
pubkey,
|
|
16363
16925
|
permissions: [],
|
|
16364
16926
|
expiresAt: new anchor.BN(0)
|
|
16365
16927
|
}))
|
|
16366
|
-
});
|
|
16367
|
-
return await this.updateState(statePda, updated, txOptions);
|
|
16928
|
+
}, txOptions);
|
|
16368
16929
|
}
|
|
16369
|
-
async upsertDelegateAcls(
|
|
16370
|
-
return await this.
|
|
16930
|
+
async upsertDelegateAcls(delegateAcls, txOptions = {}) {
|
|
16931
|
+
return await this.update({
|
|
16371
16932
|
delegateAcls
|
|
16372
16933
|
}, txOptions);
|
|
16373
16934
|
}
|
|
16374
|
-
async closeTokenAccounts(
|
|
16375
|
-
const tx = await this.closeTokenAccountsTx(
|
|
16935
|
+
async closeTokenAccounts(tokenAccounts, txOptions = {}) {
|
|
16936
|
+
const tx = await this.closeTokenAccountsTx(tokenAccounts, txOptions);
|
|
16376
16937
|
return await this.base.sendAndConfirm(tx);
|
|
16377
16938
|
}
|
|
16378
16939
|
/**
|
|
16379
16940
|
* Close vault's token accounts, all token accounts must use the same token program
|
|
16380
|
-
*/ async closeTokenAccountIx(
|
|
16941
|
+
*/ async closeTokenAccountIx(tokenAccounts, tokenProgram = splToken.TOKEN_PROGRAM_ID, txOptions = {}) {
|
|
16381
16942
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16382
16943
|
return await this.base.program.methods.tokenCloseAccount().accounts({
|
|
16383
|
-
glamState,
|
|
16944
|
+
glamState: this.base.statePda,
|
|
16384
16945
|
glamSigner,
|
|
16385
16946
|
tokenAccount: tokenAccounts[0],
|
|
16386
16947
|
cpiProgram: tokenProgram
|
|
@@ -16390,7 +16951,7 @@ class StateClient {
|
|
|
16390
16951
|
isWritable: true
|
|
16391
16952
|
}))).instruction();
|
|
16392
16953
|
}
|
|
16393
|
-
async closeTokenAccountsTx(
|
|
16954
|
+
async closeTokenAccountsTx(accounts, txOptions) {
|
|
16394
16955
|
const accountsInfo = await this.base.provider.connection.getMultipleAccountsInfo(accounts);
|
|
16395
16956
|
if (accounts.length !== accountsInfo.filter((a)=>!!a).length) {
|
|
16396
16957
|
throw new Error("Some token accounts do not exist");
|
|
@@ -16418,7 +16979,7 @@ class StateClient {
|
|
|
16418
16979
|
});
|
|
16419
16980
|
const ixs = (await Promise.all(Array.from(tokenAccountsByProgram.entries()).map(async ([programId, accounts])=>{
|
|
16420
16981
|
if (accounts.length === 0) return null;
|
|
16421
|
-
return this.closeTokenAccountIx(
|
|
16982
|
+
return this.closeTokenAccountIx(accounts, new web3_js.PublicKey(programId), txOptions);
|
|
16422
16983
|
}))).filter((ix)=>ix !== null);
|
|
16423
16984
|
if (ixs.length === 0) {
|
|
16424
16985
|
throw new Error("No token accounts to close");
|
|
@@ -16427,80 +16988,78 @@ class StateClient {
|
|
|
16427
16988
|
tx.add(...ixs);
|
|
16428
16989
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16429
16990
|
}
|
|
16430
|
-
/* Deposit & Withdraw */ async deposit(
|
|
16431
|
-
const tx = await this.depositTx(new web3_js.PublicKey(
|
|
16991
|
+
/* Deposit & Withdraw */ async deposit(asset, amount, txOptions = {}) {
|
|
16992
|
+
const tx = await this.depositTx(new web3_js.PublicKey(asset), amount, txOptions);
|
|
16432
16993
|
return await this.base.sendAndConfirm(tx);
|
|
16433
16994
|
}
|
|
16434
|
-
async depositSol(
|
|
16435
|
-
const tx = await this.depositSolTx(
|
|
16995
|
+
async depositSol(lamports, wrap = true, txOptions = {}) {
|
|
16996
|
+
const tx = await this.depositSolTx(lamports, wrap, txOptions);
|
|
16436
16997
|
return await this.base.sendAndConfirm(tx);
|
|
16437
16998
|
}
|
|
16438
|
-
async depositSolTx(
|
|
16999
|
+
async depositSolTx(lamports, wrap = true, txOptions = {}) {
|
|
16439
17000
|
const signer = txOptions.signer || this.base.getSigner();
|
|
16440
|
-
const vault = this.base.getVaultPda(glamState);
|
|
16441
17001
|
const _lamports = lamports instanceof anchor.BN ? BigInt(lamports.toString()) : lamports;
|
|
16442
17002
|
if (!wrap) {
|
|
16443
17003
|
const tx = new web3_js.Transaction().add(web3_js.SystemProgram.transfer({
|
|
16444
17004
|
fromPubkey: signer,
|
|
16445
|
-
toPubkey:
|
|
17005
|
+
toPubkey: this.base.vaultPda,
|
|
16446
17006
|
lamports: _lamports
|
|
16447
17007
|
}));
|
|
16448
17008
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16449
17009
|
}
|
|
16450
|
-
const vaultAta = this.base.getAta(WSOL,
|
|
16451
|
-
const tx = new web3_js.Transaction().add(splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultAta,
|
|
17010
|
+
const vaultAta = this.base.getAta(WSOL, this.base.vaultPda);
|
|
17011
|
+
const tx = new web3_js.Transaction().add(splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultAta, this.base.vaultPda, WSOL), web3_js.SystemProgram.transfer({
|
|
16452
17012
|
fromPubkey: signer,
|
|
16453
17013
|
toPubkey: vaultAta,
|
|
16454
17014
|
lamports: _lamports
|
|
16455
17015
|
}), splToken.createSyncNativeInstruction(vaultAta));
|
|
16456
17016
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16457
17017
|
}
|
|
16458
|
-
async withdraw(
|
|
16459
|
-
const tx = await this.withdrawTx(
|
|
17018
|
+
async withdraw(asset, amount, txOptions = {}) {
|
|
17019
|
+
const tx = await this.withdrawTx(new web3_js.PublicKey(asset), amount, txOptions);
|
|
16460
17020
|
return await this.base.sendAndConfirm(tx);
|
|
16461
17021
|
}
|
|
16462
|
-
async depositTx(
|
|
17022
|
+
async depositTx(asset, amount, txOptions) {
|
|
16463
17023
|
const signer = txOptions.signer || this.base.getSigner();
|
|
16464
|
-
const
|
|
16465
|
-
const { mint, tokenProgram } = await this.base.fetchMintWithOwner(asset);
|
|
17024
|
+
const { mint, tokenProgram } = await this.base.fetchMintAndTokenProgram(asset);
|
|
16466
17025
|
const signerAta = this.base.getAta(asset, signer, tokenProgram);
|
|
16467
|
-
const vaultAta = this.base.
|
|
16468
|
-
const tx = new web3_js.Transaction().add(splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultAta,
|
|
17026
|
+
const vaultAta = this.base.getAta(asset, this.base.vaultPda, tokenProgram);
|
|
17027
|
+
const tx = new web3_js.Transaction().add(splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultAta, this.base.vaultPda, asset, tokenProgram), splToken.createTransferCheckedInstruction(signerAta, asset, vaultAta, signer, new anchor.BN(amount).toNumber(), mint.decimals, [], tokenProgram));
|
|
16469
17028
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16470
17029
|
}
|
|
16471
|
-
async withdrawIxs(
|
|
17030
|
+
async withdrawIxs(asset, amount, txOptions) {
|
|
16472
17031
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16473
|
-
const { tokenProgram } = await this.base.
|
|
17032
|
+
const { tokenProgram } = await this.base.fetchMintAndTokenProgram(asset);
|
|
16474
17033
|
const signerAta = this.base.getAta(asset, glamSigner, tokenProgram);
|
|
16475
17034
|
return [
|
|
16476
17035
|
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, signerAta, glamSigner, asset, tokenProgram),
|
|
16477
17036
|
await this.base.program.methods.withdraw(new anchor.BN(amount)).accounts({
|
|
16478
|
-
glamState,
|
|
17037
|
+
glamState: this.base.statePda,
|
|
16479
17038
|
glamSigner,
|
|
16480
17039
|
asset,
|
|
16481
17040
|
tokenProgram
|
|
16482
17041
|
}).instruction()
|
|
16483
17042
|
];
|
|
16484
17043
|
}
|
|
16485
|
-
async withdrawTx(
|
|
17044
|
+
async withdrawTx(asset, amount, txOptions) {
|
|
16486
17045
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16487
|
-
const { tokenProgram } = await this.base.
|
|
17046
|
+
const { tokenProgram } = await this.base.fetchMintAndTokenProgram(asset);
|
|
16488
17047
|
const signerAta = this.base.getAta(asset, glamSigner, tokenProgram);
|
|
16489
17048
|
const preInstructions = [
|
|
16490
17049
|
splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, signerAta, glamSigner, asset, tokenProgram)
|
|
16491
17050
|
];
|
|
16492
17051
|
const postInstructions = [];
|
|
16493
17052
|
if (asset.equals(WSOL)) {
|
|
16494
|
-
const wrapSolIxs = await this.base.maybeWrapSol(
|
|
17053
|
+
const wrapSolIxs = await this.base.maybeWrapSol(amount, glamSigner);
|
|
16495
17054
|
preInstructions.push(...wrapSolIxs);
|
|
16496
17055
|
// If we need to wrap SOL, it means the wSOL balance will be drained,
|
|
16497
17056
|
// and we close the wSOL token account for convenience
|
|
16498
|
-
postInstructions.push(await this.closeTokenAccountIx(
|
|
16499
|
-
this.base.
|
|
17057
|
+
postInstructions.push(await this.closeTokenAccountIx([
|
|
17058
|
+
this.base.getAta(WSOL, this.base.vaultPda)
|
|
16500
17059
|
]));
|
|
16501
17060
|
}
|
|
16502
17061
|
const tx = await this.base.program.methods.withdraw(new anchor.BN(amount)).accounts({
|
|
16503
|
-
glamState,
|
|
17062
|
+
glamState: this.base.statePda,
|
|
16504
17063
|
glamSigner,
|
|
16505
17064
|
asset,
|
|
16506
17065
|
tokenProgram
|
|
@@ -16515,9 +17074,12 @@ class StateClient {
|
|
|
16515
17074
|
class MintClient {
|
|
16516
17075
|
// `getTokenAccounts` is a helius only RPC endpoint, we have to hardcode the URL here
|
|
16517
17076
|
// We cannot use NEXT_PUBLIC_SOLANA_RPC because users may choose to use a non-helius RPC
|
|
16518
|
-
async fetchTokenHolders(
|
|
16519
|
-
|
|
16520
|
-
|
|
17077
|
+
async fetchTokenHolders() {
|
|
17078
|
+
if (!process.env.NEXT_PUBLIC_HELIUS_API_KEY) {
|
|
17079
|
+
return await this.getHolders();
|
|
17080
|
+
}
|
|
17081
|
+
const cluster = this.base.cluster === ClusterNetwork.Mainnet ? "mainnet" : "devnet";
|
|
17082
|
+
const response = await fetch(`https://${cluster}.helius-rpc.com/?api-key=${process.env.NEXT_PUBLIC_HELIUS_API_KEY}`, {
|
|
16521
17083
|
method: "POST",
|
|
16522
17084
|
headers: {
|
|
16523
17085
|
"Content-Type": "application/json"
|
|
@@ -16527,7 +17089,7 @@ class MintClient {
|
|
|
16527
17089
|
id: "1",
|
|
16528
17090
|
method: "getTokenAccounts",
|
|
16529
17091
|
params: {
|
|
16530
|
-
mint:
|
|
17092
|
+
mint: this.base.mintPda.toBase58(),
|
|
16531
17093
|
options: {
|
|
16532
17094
|
showZeroBalance: true
|
|
16533
17095
|
}
|
|
@@ -16540,7 +17102,7 @@ class MintClient {
|
|
|
16540
17102
|
return tokenAccounts.map((ta)=>({
|
|
16541
17103
|
owner: new web3_js.PublicKey(ta.owner),
|
|
16542
17104
|
pubkey: new web3_js.PublicKey(ta.address),
|
|
16543
|
-
mint,
|
|
17105
|
+
mint: this.base.mintPda,
|
|
16544
17106
|
programId: splToken.TOKEN_2022_PROGRAM_ID,
|
|
16545
17107
|
decimals: 9,
|
|
16546
17108
|
amount: ta.amount,
|
|
@@ -16550,16 +17112,9 @@ class MintClient {
|
|
|
16550
17112
|
}
|
|
16551
17113
|
// Much slower than fetchTokenHolders.
|
|
16552
17114
|
// Use fetchTokenHolders instead when possible.
|
|
16553
|
-
async getHolders(
|
|
16554
|
-
const mintPda = this.base.getMintPda(state, mintId);
|
|
17115
|
+
async getHolders() {
|
|
16555
17116
|
const connection = this.base.provider.connection;
|
|
16556
|
-
|
|
16557
|
-
try {
|
|
16558
|
-
mint = await splToken.getMint(connection, mintPda, connection.commitment, splToken.TOKEN_2022_PROGRAM_ID);
|
|
16559
|
-
} catch (e) {
|
|
16560
|
-
return [];
|
|
16561
|
-
}
|
|
16562
|
-
// Size of a glam mint with perment delegate extension enabled
|
|
17117
|
+
// dataSize varies due to different sets of extensions enabled
|
|
16563
17118
|
// const dataSize = 175;
|
|
16564
17119
|
const accounts = await connection.getProgramAccounts(splToken.TOKEN_2022_PROGRAM_ID, {
|
|
16565
17120
|
filters: [
|
|
@@ -16567,7 +17122,7 @@ class MintClient {
|
|
|
16567
17122
|
{
|
|
16568
17123
|
memcmp: {
|
|
16569
17124
|
offset: 0,
|
|
16570
|
-
bytes: mintPda.toBase58()
|
|
17125
|
+
bytes: this.base.mintPda.toBase58()
|
|
16571
17126
|
}
|
|
16572
17127
|
}
|
|
16573
17128
|
]
|
|
@@ -16580,62 +17135,68 @@ class MintClient {
|
|
|
16580
17135
|
pubkey: tokenAccount.address,
|
|
16581
17136
|
mint: tokenAccount.mint,
|
|
16582
17137
|
programId: splToken.TOKEN_2022_PROGRAM_ID,
|
|
16583
|
-
decimals:
|
|
17138
|
+
decimals: 9,
|
|
16584
17139
|
amount: tokenAccount.amount.toString(),
|
|
16585
|
-
uiAmount: Number(tokenAccount.amount) / 10 **
|
|
17140
|
+
uiAmount: Number(tokenAccount.amount) / 10 ** 9,
|
|
16586
17141
|
frozen: tokenAccount.isFrozen
|
|
16587
17142
|
};
|
|
16588
17143
|
});
|
|
16589
17144
|
}
|
|
16590
|
-
async update(
|
|
16591
|
-
const
|
|
16592
|
-
|
|
16593
|
-
|
|
16594
|
-
glamState,
|
|
16595
|
-
glamMint
|
|
17145
|
+
async update(mintModel, txOptions = {}) {
|
|
17146
|
+
const tx = await this.base.program.methods.updateMint(0, new MintIdlModel(mintModel)).accounts({
|
|
17147
|
+
glamState: this.base.statePda,
|
|
17148
|
+
glamMint: this.base.mintPda
|
|
16596
17149
|
}).transaction();
|
|
16597
|
-
const vTx = await this.base.intoVersionedTransaction(tx,
|
|
17150
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16598
17151
|
return await this.base.sendAndConfirm(vTx);
|
|
16599
17152
|
}
|
|
16600
|
-
async
|
|
16601
|
-
const
|
|
16602
|
-
|
|
16603
|
-
|
|
16604
|
-
|
|
16605
|
-
|
|
16606
|
-
|
|
16607
|
-
|
|
17153
|
+
async updateApplyTimelock(txOptions = {}) {
|
|
17154
|
+
const tx = await this.base.program.methods.updateMintApplyTimelock(0).accounts({
|
|
17155
|
+
glamState: this.base.statePda,
|
|
17156
|
+
glamMint: this.base.mintPda
|
|
17157
|
+
}).transaction();
|
|
17158
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17159
|
+
return await this.base.sendAndConfirm(vTx);
|
|
17160
|
+
}
|
|
17161
|
+
async emergencyUpdate(mintModel, txOptions = {}) {
|
|
17162
|
+
const tx = await this.base.program.methods.emergencyUpdateMint(0, new MintIdlModel(mintModel)).accounts({
|
|
17163
|
+
glamState: this.base.statePda,
|
|
17164
|
+
glamMint: this.base.mintPda
|
|
17165
|
+
}).transaction();
|
|
17166
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17167
|
+
return await this.base.sendAndConfirm(vTx);
|
|
17168
|
+
}
|
|
17169
|
+
async closeMintIx() {
|
|
17170
|
+
return await this.base.program.methods.closeMint(0).accounts({
|
|
17171
|
+
glamState: this.base.statePda,
|
|
17172
|
+
glamMint: this.base.mintPda,
|
|
17173
|
+
extraMetasAccount: this.base.extraMetasPda
|
|
16608
17174
|
}).instruction();
|
|
16609
17175
|
}
|
|
16610
|
-
async closeMint(
|
|
17176
|
+
async closeMint(txOptions = {}) {
|
|
16611
17177
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16612
|
-
const
|
|
16613
|
-
|
|
16614
|
-
// @ts-ignore
|
|
16615
|
-
const tx = await this.base.program.methods.closeMint(mintId).accounts({
|
|
16616
|
-
glamState,
|
|
17178
|
+
const tx = await this.base.program.methods.closeMint(0).accounts({
|
|
17179
|
+
glamState: this.base.statePda,
|
|
16617
17180
|
glamSigner,
|
|
16618
|
-
glamMint,
|
|
16619
|
-
extraMetasAccount
|
|
17181
|
+
glamMint: this.base.mintPda,
|
|
17182
|
+
extraMetasAccount: this.base.extraMetasPda
|
|
16620
17183
|
}).transaction();
|
|
16621
17184
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16622
17185
|
return await this.base.sendAndConfirm(vTx);
|
|
16623
17186
|
}
|
|
16624
17187
|
/**
|
|
16625
|
-
* Create a glam mint token account for
|
|
17188
|
+
* Create a glam mint token account for the specified user
|
|
16626
17189
|
*
|
|
16627
|
-
* @param glamState
|
|
16628
17190
|
* @param owner Owner of the token account
|
|
16629
|
-
* @param mintId ID of the mint (only 0 is supported)
|
|
16630
17191
|
* @param setFrozen If true, the token account will be frozen
|
|
16631
17192
|
* @param txOptions
|
|
16632
17193
|
* @returns Transaction signature
|
|
16633
|
-
*/ async createTokenAccount(
|
|
17194
|
+
*/ async createTokenAccount(owner, setFrozen = true, txOptions = {}) {
|
|
16634
17195
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16635
|
-
const glamMint = this.base.
|
|
16636
|
-
const ata = this.base.getMintAta(owner
|
|
17196
|
+
const glamMint = this.base.mintPda;
|
|
17197
|
+
const ata = this.base.getMintAta(owner);
|
|
16637
17198
|
const ixCreateAta = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, ata, owner, glamMint, splToken.TOKEN_2022_PROGRAM_ID);
|
|
16638
|
-
return await this.setTokenAccountsStates(
|
|
17199
|
+
return await this.setTokenAccountsStates([
|
|
16639
17200
|
ata
|
|
16640
17201
|
], setFrozen, {
|
|
16641
17202
|
preInstructions: [
|
|
@@ -16647,19 +17208,16 @@ class MintClient {
|
|
|
16647
17208
|
/**
|
|
16648
17209
|
* Freeze or unfreeze token accounts of a glam mint
|
|
16649
17210
|
*
|
|
16650
|
-
* @param glamState
|
|
16651
|
-
* @param mintId ID of the mint (only 0 is supported)
|
|
16652
17211
|
* @param tokenAccounts List of token accounts to freeze or unfreeze
|
|
16653
17212
|
* @param frozen If true, the token accounts will be frozen; otherwise, they will be unfrozen
|
|
16654
17213
|
* @param txOptions
|
|
16655
17214
|
* @returns Transaction signature
|
|
16656
|
-
*/ async setTokenAccountsStates(
|
|
17215
|
+
*/ async setTokenAccountsStates(tokenAccounts, frozen, txOptions = {}) {
|
|
16657
17216
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16658
|
-
const
|
|
16659
|
-
|
|
16660
|
-
glamState,
|
|
17217
|
+
const tx = await this.base.program.methods.setTokenAccountsStates(0, frozen).accounts({
|
|
17218
|
+
glamState: this.base.statePda,
|
|
16661
17219
|
glamSigner,
|
|
16662
|
-
glamMint
|
|
17220
|
+
glamMint: this.base.mintPda
|
|
16663
17221
|
}).remainingAccounts(tokenAccounts.map((account)=>({
|
|
16664
17222
|
pubkey: account,
|
|
16665
17223
|
isSigner: false,
|
|
@@ -16671,25 +17229,21 @@ class MintClient {
|
|
|
16671
17229
|
/**
|
|
16672
17230
|
* Mint tokens to recipient. Token account will be created if it does not exist.
|
|
16673
17231
|
*
|
|
16674
|
-
* @param glamState
|
|
16675
|
-
* @param mintId ID of the mint (only 0 is supported)
|
|
16676
17232
|
* @param recipient Recipient public key
|
|
16677
17233
|
* @param amount Amount of tokens to mint
|
|
16678
17234
|
* @param forceThaw If true, automatically unfreeze the token account before minting
|
|
16679
17235
|
* @param txOptions
|
|
16680
17236
|
* @returns Transaction signature
|
|
16681
|
-
*/ async mint(
|
|
17237
|
+
*/ async mint(recipient, amount, forceThaw = false, txOptions = {}) {
|
|
16682
17238
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16683
|
-
const
|
|
16684
|
-
const mintTo = this.base.getMintAta(recipient, glamMint);
|
|
17239
|
+
const mintTo = this.base.getMintAta(recipient);
|
|
16685
17240
|
const preInstructions = [];
|
|
16686
|
-
preInstructions.push(splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, mintTo, recipient,
|
|
17241
|
+
preInstructions.push(splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, mintTo, recipient, this.base.mintPda, splToken.TOKEN_2022_PROGRAM_ID));
|
|
16687
17242
|
if (forceThaw) {
|
|
16688
|
-
preInstructions.push(
|
|
16689
|
-
|
|
16690
|
-
glamState,
|
|
17243
|
+
preInstructions.push(await this.base.program.methods.setTokenAccountsStates(0, false).accounts({
|
|
17244
|
+
glamState: this.base.statePda,
|
|
16691
17245
|
glamSigner,
|
|
16692
|
-
glamMint
|
|
17246
|
+
glamMint: this.base.mintPda
|
|
16693
17247
|
}).remainingAccounts([
|
|
16694
17248
|
{
|
|
16695
17249
|
pubkey: mintTo,
|
|
@@ -16698,12 +17252,12 @@ class MintClient {
|
|
|
16698
17252
|
}
|
|
16699
17253
|
]).instruction());
|
|
16700
17254
|
}
|
|
16701
|
-
let policyAccount = await this.base.isLockupEnabled(
|
|
17255
|
+
let policyAccount = await this.base.isLockupEnabled() ? getAccountPolicyPda(mintTo) : null;
|
|
16702
17256
|
// @ts-ignore
|
|
16703
17257
|
const tx = await this.base.program.methods.mintTokens(0, amount).accounts({
|
|
16704
|
-
glamState,
|
|
17258
|
+
glamState: this.base.statePda,
|
|
16705
17259
|
glamSigner,
|
|
16706
|
-
glamMint,
|
|
17260
|
+
glamMint: this.base.mintPda,
|
|
16707
17261
|
recipient,
|
|
16708
17262
|
policyAccount
|
|
16709
17263
|
}).preInstructions(preInstructions).transaction();
|
|
@@ -16713,24 +17267,20 @@ class MintClient {
|
|
|
16713
17267
|
/**
|
|
16714
17268
|
* Burn tokens from a token account
|
|
16715
17269
|
*
|
|
16716
|
-
* @param glamState
|
|
16717
|
-
* @param mintId ID of the mint (only 0 is supported)
|
|
16718
17270
|
* @param amount Amount of tokens to burn
|
|
16719
17271
|
* @param from Owner of the token account
|
|
16720
17272
|
* @param forceThaw If true, automatically unfree the token account before burning
|
|
16721
17273
|
* @param txOptions
|
|
16722
17274
|
* @returns Transaction signature
|
|
16723
|
-
*/ async burn(
|
|
17275
|
+
*/ async burn(amount, from, forceThaw = false, txOptions = {}) {
|
|
16724
17276
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16725
|
-
const
|
|
16726
|
-
const ata = this.base.getMintAta(from, glamMint);
|
|
17277
|
+
const ata = this.base.getMintAta(from);
|
|
16727
17278
|
const preInstructions = [];
|
|
16728
17279
|
if (forceThaw) {
|
|
16729
|
-
preInstructions.push(
|
|
16730
|
-
|
|
16731
|
-
glamState,
|
|
17280
|
+
preInstructions.push(await this.base.program.methods.setTokenAccountsStates(0, false).accounts({
|
|
17281
|
+
glamState: this.base.statePda,
|
|
16732
17282
|
glamSigner,
|
|
16733
|
-
glamMint
|
|
17283
|
+
glamMint: this.base.mintPda
|
|
16734
17284
|
}).remainingAccounts([
|
|
16735
17285
|
{
|
|
16736
17286
|
pubkey: ata,
|
|
@@ -16739,10 +17289,10 @@ class MintClient {
|
|
|
16739
17289
|
}
|
|
16740
17290
|
]).instruction());
|
|
16741
17291
|
}
|
|
16742
|
-
const tx = await this.base.program.methods.burnTokens(
|
|
16743
|
-
glamState,
|
|
17292
|
+
const tx = await this.base.program.methods.burnTokens(0, amount).accounts({
|
|
17293
|
+
glamState: this.base.statePda,
|
|
16744
17294
|
glamSigner,
|
|
16745
|
-
glamMint,
|
|
17295
|
+
glamMint: this.base.mintPda,
|
|
16746
17296
|
from
|
|
16747
17297
|
}).preInstructions(preInstructions).transaction();
|
|
16748
17298
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
@@ -16751,27 +17301,23 @@ class MintClient {
|
|
|
16751
17301
|
/**
|
|
16752
17302
|
* Transfer tokens from one token account to another
|
|
16753
17303
|
*
|
|
16754
|
-
* @param glamState
|
|
16755
|
-
* @param mintId ID of the mint (only 0 is supported)
|
|
16756
17304
|
* @param amount Amount of tokens to transfer
|
|
16757
17305
|
* @param from Owner of the sender token account
|
|
16758
17306
|
* @param to Owner of the recipient token account
|
|
16759
17307
|
* @param forceThaw If true, automatically unfree the token accounts before transfer
|
|
16760
17308
|
* @param txOptions
|
|
16761
17309
|
* @returns
|
|
16762
|
-
*/ async forceTransfer(
|
|
17310
|
+
*/ async forceTransfer(amount, from, to, forceThaw = false, txOptions = {}) {
|
|
16763
17311
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16764
|
-
const
|
|
16765
|
-
const
|
|
16766
|
-
const toAta = this.base.getMintAta(to, glamMint);
|
|
17312
|
+
const fromAta = this.base.getMintAta(from);
|
|
17313
|
+
const toAta = this.base.getMintAta(to);
|
|
16767
17314
|
const preInstructions = [];
|
|
16768
|
-
preInstructions.push(splToken.createAssociatedTokenAccountIdempotentInstruction(this.base.getSigner(), toAta, to,
|
|
17315
|
+
preInstructions.push(splToken.createAssociatedTokenAccountIdempotentInstruction(this.base.getSigner(), toAta, to, this.base.mintPda, splToken.TOKEN_2022_PROGRAM_ID));
|
|
16769
17316
|
if (forceThaw) {
|
|
16770
|
-
preInstructions.push(
|
|
16771
|
-
|
|
16772
|
-
glamState,
|
|
17317
|
+
preInstructions.push(await this.base.program.methods.setTokenAccountsStates(0, false).accounts({
|
|
17318
|
+
glamState: this.base.statePda,
|
|
16773
17319
|
glamSigner,
|
|
16774
|
-
glamMint
|
|
17320
|
+
glamMint: this.base.mintPda
|
|
16775
17321
|
}).remainingAccounts([
|
|
16776
17322
|
// fromAta is already unfrozen, still add it to test the ix is idempotent
|
|
16777
17323
|
{
|
|
@@ -16788,10 +17334,10 @@ class MintClient {
|
|
|
16788
17334
|
}
|
|
16789
17335
|
const remainingAccounts = [];
|
|
16790
17336
|
let toPolicyAccount = null;
|
|
16791
|
-
if (await this.base.isLockupEnabled(
|
|
16792
|
-
const extraMetasAccount = this.base.
|
|
16793
|
-
const fromPolicy = this.base.
|
|
16794
|
-
const toPolicy = this.base.
|
|
17337
|
+
if (await this.base.isLockupEnabled()) {
|
|
17338
|
+
const extraMetasAccount = this.base.extraMetasPda;
|
|
17339
|
+
const fromPolicy = getAccountPolicyPda(this.base.getMintAta(from));
|
|
17340
|
+
const toPolicy = getAccountPolicyPda(this.base.getMintAta(to));
|
|
16795
17341
|
toPolicyAccount = toPolicy;
|
|
16796
17342
|
remainingAccounts.push(...[
|
|
16797
17343
|
extraMetasAccount,
|
|
@@ -16800,11 +17346,10 @@ class MintClient {
|
|
|
16800
17346
|
TRANSFER_HOOK_PROGRAM
|
|
16801
17347
|
]);
|
|
16802
17348
|
}
|
|
16803
|
-
|
|
16804
|
-
|
|
16805
|
-
glamState,
|
|
17349
|
+
const tx = await this.base.program.methods.forceTransferTokens(0, amount).accounts({
|
|
17350
|
+
glamState: this.base.statePda,
|
|
16806
17351
|
glamSigner,
|
|
16807
|
-
glamMint,
|
|
17352
|
+
glamMint: this.base.mintPda,
|
|
16808
17353
|
from,
|
|
16809
17354
|
to,
|
|
16810
17355
|
toPolicyAccount
|
|
@@ -16826,7 +17371,6 @@ const DEFAULT_OBLIGATION_ARGS = {
|
|
|
16826
17371
|
tag: 0,
|
|
16827
17372
|
id: 0
|
|
16828
17373
|
};
|
|
16829
|
-
const SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
|
|
16830
17374
|
function refreshObligation(accounts, programId = KAMINO_LENDING_PROGRAM) {
|
|
16831
17375
|
const keys = [
|
|
16832
17376
|
{
|
|
@@ -17001,65 +17545,60 @@ class KaminoLendingClient {
|
|
|
17001
17545
|
/**
|
|
17002
17546
|
* Initializes Kamino user metadata
|
|
17003
17547
|
*
|
|
17004
|
-
* @param statePda
|
|
17005
17548
|
* @param market Lending market
|
|
17006
17549
|
* @param referrer Referrer user metadata
|
|
17007
17550
|
* @param txOptions
|
|
17008
17551
|
* @returns
|
|
17009
|
-
*/ async initUserMetadata(
|
|
17010
|
-
const tx = await this.initUserMetadataTx(
|
|
17552
|
+
*/ async initUserMetadata(txOptions = {}) {
|
|
17553
|
+
const tx = await this.initUserMetadataTx(txOptions);
|
|
17011
17554
|
return await this.base.sendAndConfirm(tx);
|
|
17012
17555
|
}
|
|
17013
17556
|
/**
|
|
17014
17557
|
* Deposits asset to the lending market.
|
|
17015
17558
|
*
|
|
17016
|
-
* @param statePda
|
|
17017
17559
|
* @param market Lending market
|
|
17018
17560
|
* @param asset Asset mint
|
|
17019
17561
|
* @param amount Amount to deposit
|
|
17020
17562
|
* @param txOptions
|
|
17021
17563
|
* @returns
|
|
17022
|
-
*/ async deposit(
|
|
17023
|
-
const tx = await this.depositTx(new web3_js.PublicKey(
|
|
17564
|
+
*/ async deposit(market, asset, amount, txOptions = {}) {
|
|
17565
|
+
const tx = await this.depositTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
|
|
17024
17566
|
return await this.base.sendAndConfirm(tx);
|
|
17025
17567
|
}
|
|
17026
17568
|
/**
|
|
17027
17569
|
* Withdraws asset from the lending market.
|
|
17028
17570
|
*
|
|
17029
|
-
* @param statePda
|
|
17030
17571
|
* @param market Lending market
|
|
17031
17572
|
* @param asset Asset mint
|
|
17032
17573
|
* @param amount Amount to deposit
|
|
17033
17574
|
* @param txOptions
|
|
17034
17575
|
* @returns
|
|
17035
|
-
*/ async withdraw(
|
|
17036
|
-
const tx = await this.withdrawTx(new web3_js.PublicKey(
|
|
17576
|
+
*/ async withdraw(market, asset, amount, txOptions = {}) {
|
|
17577
|
+
const tx = await this.withdrawTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
|
|
17037
17578
|
return await this.base.sendAndConfirm(tx);
|
|
17038
17579
|
}
|
|
17039
17580
|
/**
|
|
17040
17581
|
* Borrows asset from the lending market.
|
|
17041
17582
|
*
|
|
17042
|
-
* @param statePda GLAM state
|
|
17043
17583
|
* @param market Lending market
|
|
17044
17584
|
* @param asset Asset mint
|
|
17045
17585
|
* @param amount Amount to borrow
|
|
17046
17586
|
* @param txOptions
|
|
17047
17587
|
* @returns
|
|
17048
|
-
*/ async borrow(
|
|
17049
|
-
const tx = await this.borrowTx(new web3_js.PublicKey(
|
|
17588
|
+
*/ async borrow(market, asset, amount, txOptions = {}) {
|
|
17589
|
+
const tx = await this.borrowTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
|
|
17050
17590
|
return await this.base.sendAndConfirm(tx);
|
|
17051
17591
|
}
|
|
17052
17592
|
/**
|
|
17053
17593
|
* Repays asset to the lending market.
|
|
17054
17594
|
*
|
|
17055
|
-
* @param statePda
|
|
17056
17595
|
* @param market
|
|
17057
17596
|
* @param asset
|
|
17058
17597
|
* @param amount
|
|
17059
17598
|
* @param txOptions
|
|
17060
17599
|
* @returns
|
|
17061
|
-
*/ async repay(
|
|
17062
|
-
const tx = await this.repayTx(new web3_js.PublicKey(
|
|
17600
|
+
*/ async repay(market, asset, amount, txOptions = {}) {
|
|
17601
|
+
const tx = await this.repayTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
|
|
17063
17602
|
return await this.base.sendAndConfirm(tx);
|
|
17064
17603
|
}
|
|
17065
17604
|
getUserMetadataPda(owner) {
|
|
@@ -17093,17 +17632,17 @@ class KaminoLendingClient {
|
|
|
17093
17632
|
], KAMINO_FARM_PROGRAM);
|
|
17094
17633
|
return obligationFarm;
|
|
17095
17634
|
}
|
|
17096
|
-
async initUserMetadataTx(
|
|
17635
|
+
async initUserMetadataTx(txOptions = {}) {
|
|
17097
17636
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17098
|
-
const vault = this.base.
|
|
17637
|
+
const vault = this.base.vaultPda;
|
|
17099
17638
|
const userMetadata = this.getUserMetadataPda(vault);
|
|
17100
17639
|
const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
|
|
17101
17640
|
// @ts-ignore
|
|
17102
17641
|
const tx = await this.base.program.methods.kaminoLendingInitUserMetadata(lookupTable).accounts({
|
|
17103
|
-
glamState,
|
|
17642
|
+
glamState: this.base.statePda,
|
|
17104
17643
|
glamSigner,
|
|
17105
17644
|
userMetadata,
|
|
17106
|
-
referrerUserMetadata:
|
|
17645
|
+
referrerUserMetadata: null
|
|
17107
17646
|
}).transaction();
|
|
17108
17647
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17109
17648
|
return vTx;
|
|
@@ -17115,7 +17654,7 @@ class KaminoLendingClient {
|
|
|
17115
17654
|
pythOracle: KAMINO_LENDING_PROGRAM,
|
|
17116
17655
|
switchboardPriceOracle: KAMINO_LENDING_PROGRAM,
|
|
17117
17656
|
switchboardTwapOracle: KAMINO_LENDING_PROGRAM,
|
|
17118
|
-
scopePrices:
|
|
17657
|
+
scopePrices: KAMINO_SCOPE_PRICES
|
|
17119
17658
|
}));
|
|
17120
17659
|
}
|
|
17121
17660
|
refreshObligationFarmsForReserveIxs(obligation, lendingMarket, parsedReserves) {
|
|
@@ -17321,9 +17860,9 @@ class KaminoLendingClient {
|
|
|
17321
17860
|
this.reserves.set(account.pubkey, parsedReserve);
|
|
17322
17861
|
return parsedReserve;
|
|
17323
17862
|
}
|
|
17324
|
-
async depositTx(
|
|
17863
|
+
async depositTx(market, asset, amount, txOptions) {
|
|
17325
17864
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17326
|
-
const vault = this.base.
|
|
17865
|
+
const vault = this.base.vaultPda;
|
|
17327
17866
|
const userMetadata = this.getUserMetadataPda(vault);
|
|
17328
17867
|
const preInstructions = [];
|
|
17329
17868
|
const postInstructions = [];
|
|
@@ -17333,7 +17872,7 @@ class KaminoLendingClient {
|
|
|
17333
17872
|
const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
|
|
17334
17873
|
if (!obligationAccount) {
|
|
17335
17874
|
preInstructions.push(await this.base.program.methods.kaminoLendingInitObligation(DEFAULT_OBLIGATION_ARGS).accounts({
|
|
17336
|
-
glamState,
|
|
17875
|
+
glamState: this.base.statePda,
|
|
17337
17876
|
glamSigner,
|
|
17338
17877
|
obligation,
|
|
17339
17878
|
lendingMarket: market,
|
|
@@ -17350,7 +17889,7 @@ class KaminoLendingClient {
|
|
|
17350
17889
|
if (!obligationFarmAccount) {
|
|
17351
17890
|
preInstructions.push(await this.base.program.methods.kaminoLendingInitObligationFarmsForReserve(0) // TODO: What does mode do?
|
|
17352
17891
|
.accounts({
|
|
17353
|
-
glamState,
|
|
17892
|
+
glamState: this.base.statePda,
|
|
17354
17893
|
glamSigner,
|
|
17355
17894
|
obligation,
|
|
17356
17895
|
lendingMarketAuthority: this.getMarketAuthority(market),
|
|
@@ -17386,14 +17925,14 @@ class KaminoLendingClient {
|
|
|
17386
17925
|
postInstructions.push(...ixs); // farms must be refreshed after deposit
|
|
17387
17926
|
}
|
|
17388
17927
|
// If deposit asset is WSOL, wrap SOL first in case vault doesn't have enough wSOL
|
|
17389
|
-
const userSourceLiquidity = this.base.getVaultAta(
|
|
17928
|
+
const userSourceLiquidity = this.base.getVaultAta(asset);
|
|
17390
17929
|
if (asset.equals(WSOL)) {
|
|
17391
|
-
const wrapSolIxs = await this.base.maybeWrapSol(
|
|
17930
|
+
const wrapSolIxs = await this.base.maybeWrapSol(amount);
|
|
17392
17931
|
preInstructions.unshift(...wrapSolIxs);
|
|
17393
17932
|
// Close wSOL ata automatically after deposit
|
|
17394
17933
|
if (wrapSolIxs.length > 0) {
|
|
17395
17934
|
const closeIx = await this.base.program.methods.tokenCloseAccount().accounts({
|
|
17396
|
-
glamState,
|
|
17935
|
+
glamState: this.base.statePda,
|
|
17397
17936
|
glamSigner,
|
|
17398
17937
|
tokenAccount: userSourceLiquidity,
|
|
17399
17938
|
cpiProgram: splToken.TOKEN_PROGRAM_ID
|
|
@@ -17403,7 +17942,7 @@ class KaminoLendingClient {
|
|
|
17403
17942
|
}
|
|
17404
17943
|
// @ts-ignore
|
|
17405
17944
|
const tx = await this.base.program.methods.kaminoLendingDepositReserveLiquidityAndObligationCollateralV2(amount).accounts({
|
|
17406
|
-
glamState,
|
|
17945
|
+
glamState: this.base.statePda,
|
|
17407
17946
|
glamSigner,
|
|
17408
17947
|
obligation,
|
|
17409
17948
|
lendingMarket: market,
|
|
@@ -17431,9 +17970,9 @@ class KaminoLendingClient {
|
|
|
17431
17970
|
});
|
|
17432
17971
|
return vTx;
|
|
17433
17972
|
}
|
|
17434
|
-
async withdrawTx(
|
|
17973
|
+
async withdrawTx(market, asset, amount, txOptions) {
|
|
17435
17974
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17436
|
-
const vault = this.base.
|
|
17975
|
+
const vault = this.base.vaultPda;
|
|
17437
17976
|
const preInstructions = [];
|
|
17438
17977
|
const postInstructions = [];
|
|
17439
17978
|
const withdrawReserve = await this.findAndParseReserve(market, asset);
|
|
@@ -17446,7 +17985,7 @@ class KaminoLendingClient {
|
|
|
17446
17985
|
if (!obligationFarmAccount) {
|
|
17447
17986
|
preInstructions.push(await this.base.program.methods.kaminoLendingInitObligationFarmsForReserve(0) // TODO: What does mode do?
|
|
17448
17987
|
.accounts({
|
|
17449
|
-
glamState,
|
|
17988
|
+
glamState: this.base.statePda,
|
|
17450
17989
|
glamSigner,
|
|
17451
17990
|
obligation,
|
|
17452
17991
|
lendingMarketAuthority: this.getMarketAuthority(market),
|
|
@@ -17482,11 +18021,11 @@ class KaminoLendingClient {
|
|
|
17482
18021
|
postInstructions.push(...ixs); // farms must be refreshed after withdraw
|
|
17483
18022
|
}
|
|
17484
18023
|
// Create asset ATA in case it doesn't exist. Add it to the beginning of preInstructions
|
|
17485
|
-
const userDestinationLiquidity = this.base.getVaultAta(
|
|
18024
|
+
const userDestinationLiquidity = this.base.getVaultAta(asset);
|
|
17486
18025
|
const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, userDestinationLiquidity, vault, asset);
|
|
17487
18026
|
preInstructions.unshift(createAtaIx);
|
|
17488
18027
|
const withdrawIx = await this.base.program.methods.kaminoLendingWithdrawObligationCollateralAndRedeemReserveCollateralV2(amount).accounts({
|
|
17489
|
-
glamState,
|
|
18028
|
+
glamState: this.base.statePda,
|
|
17490
18029
|
glamSigner,
|
|
17491
18030
|
obligation,
|
|
17492
18031
|
lendingMarket: market,
|
|
@@ -17496,7 +18035,7 @@ class KaminoLendingClient {
|
|
|
17496
18035
|
reserveSourceCollateral: withdrawReserve.collateralSupplyVault,
|
|
17497
18036
|
reserveCollateralMint: withdrawReserve.collateralMint,
|
|
17498
18037
|
reserveLiquiditySupply: withdrawReserve.liquiditySupplyVault,
|
|
17499
|
-
userDestinationLiquidity
|
|
18038
|
+
userDestinationLiquidity,
|
|
17500
18039
|
placeholderUserDestinationCollateral: null,
|
|
17501
18040
|
collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
17502
18041
|
liquidityTokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
@@ -17522,9 +18061,9 @@ class KaminoLendingClient {
|
|
|
17522
18061
|
});
|
|
17523
18062
|
return vTx;
|
|
17524
18063
|
}
|
|
17525
|
-
async borrowTx(
|
|
18064
|
+
async borrowTx(market, asset, amount, txOptions) {
|
|
17526
18065
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17527
|
-
const vault = this.base.
|
|
18066
|
+
const vault = this.base.vaultPda;
|
|
17528
18067
|
const preInstructions = [];
|
|
17529
18068
|
const borrowReserve = await this.findAndParseReserve(market, asset);
|
|
17530
18069
|
const obligation = this.getObligationPda(vault, market, DEFAULT_OBLIGATION_ARGS);
|
|
@@ -17536,7 +18075,7 @@ class KaminoLendingClient {
|
|
|
17536
18075
|
if (!obligationFarmAccount) {
|
|
17537
18076
|
preInstructions.push(await this.base.program.methods.kaminoLendingInitObligationFarmsForReserve(0) // TODO: What does mode do?
|
|
17538
18077
|
.accounts({
|
|
17539
|
-
glamState,
|
|
18078
|
+
glamState: this.base.statePda,
|
|
17540
18079
|
glamSigner,
|
|
17541
18080
|
obligation,
|
|
17542
18081
|
lendingMarketAuthority: this.getMarketAuthority(market),
|
|
@@ -17574,11 +18113,11 @@ class KaminoLendingClient {
|
|
|
17574
18113
|
postInstructions.push(...ixs); // farms must be refreshed after deposit
|
|
17575
18114
|
}
|
|
17576
18115
|
*/ // Create asset ATA in case it doesn't exist. Add it to the beginning of preInstructions
|
|
17577
|
-
const userDestinationLiquidity = this.base.getVaultAta(
|
|
18116
|
+
const userDestinationLiquidity = this.base.getVaultAta(asset);
|
|
17578
18117
|
const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, userDestinationLiquidity, vault, asset);
|
|
17579
18118
|
preInstructions.unshift(createAtaIx);
|
|
17580
18119
|
const borrowIx = await this.base.program.methods.kaminoLendingBorrowObligationLiquidityV2(amount).accounts({
|
|
17581
|
-
glamState,
|
|
18120
|
+
glamState: this.base.statePda,
|
|
17582
18121
|
glamSigner,
|
|
17583
18122
|
obligation,
|
|
17584
18123
|
lendingMarket: market,
|
|
@@ -17587,7 +18126,7 @@ class KaminoLendingClient {
|
|
|
17587
18126
|
borrowReserveLiquidityMint: asset,
|
|
17588
18127
|
reserveSourceLiquidity: borrowReserve.liquiditySupplyVault,
|
|
17589
18128
|
borrowReserveLiquidityFeeReceiver: borrowReserve.feeVault,
|
|
17590
|
-
userDestinationLiquidity
|
|
18129
|
+
userDestinationLiquidity,
|
|
17591
18130
|
referrerTokenState: null,
|
|
17592
18131
|
instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
17593
18132
|
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
@@ -17610,9 +18149,9 @@ class KaminoLendingClient {
|
|
|
17610
18149
|
});
|
|
17611
18150
|
return vTx;
|
|
17612
18151
|
}
|
|
17613
|
-
async repayTx(
|
|
18152
|
+
async repayTx(market, asset, amount, txOptions = {}) {
|
|
17614
18153
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17615
|
-
const vault = this.base.
|
|
18154
|
+
const vault = this.base.vaultPda;
|
|
17616
18155
|
const preInstructions = [];
|
|
17617
18156
|
const repayReserve = await this.findAndParseReserve(market, asset);
|
|
17618
18157
|
const obligation = this.getObligationPda(vault, market, DEFAULT_OBLIGATION_ARGS);
|
|
@@ -17624,7 +18163,7 @@ class KaminoLendingClient {
|
|
|
17624
18163
|
if (!obligationFarmAccount) {
|
|
17625
18164
|
preInstructions.push(await this.base.program.methods.kaminoLendingInitObligationFarmsForReserve(0) // TODO: What does mode do?
|
|
17626
18165
|
.accounts({
|
|
17627
|
-
glamState,
|
|
18166
|
+
glamState: this.base.statePda,
|
|
17628
18167
|
glamSigner,
|
|
17629
18168
|
obligation,
|
|
17630
18169
|
lendingMarketAuthority: this.getMarketAuthority(market),
|
|
@@ -17653,7 +18192,7 @@ class KaminoLendingClient {
|
|
|
17653
18192
|
reserves: reservesInUse
|
|
17654
18193
|
}));
|
|
17655
18194
|
const repayIx = await this.base.program.methods.kaminoLendingRepayObligationLiquidityV2(amount).accounts({
|
|
17656
|
-
glamState,
|
|
18195
|
+
glamState: this.base.statePda,
|
|
17657
18196
|
glamSigner,
|
|
17658
18197
|
obligation,
|
|
17659
18198
|
lendingMarket: market,
|
|
@@ -17661,7 +18200,7 @@ class KaminoLendingClient {
|
|
|
17661
18200
|
repayReserve: repayReserve.address,
|
|
17662
18201
|
reserveLiquidityMint: asset,
|
|
17663
18202
|
reserveDestinationLiquidity: repayReserve.liquiditySupplyVault,
|
|
17664
|
-
userSourceLiquidity: this.base.getVaultAta(
|
|
18203
|
+
userSourceLiquidity: this.base.getVaultAta(asset),
|
|
17665
18204
|
instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
17666
18205
|
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
17667
18206
|
obligationFarmUserState: obligationFarm,
|
|
@@ -17769,13 +18308,13 @@ class KaminoFarmClient {
|
|
|
17769
18308
|
}
|
|
17770
18309
|
return map;
|
|
17771
18310
|
}
|
|
17772
|
-
async harvest(
|
|
17773
|
-
const tx = await this.harvestTx(
|
|
18311
|
+
async harvest(txOptions = {}) {
|
|
18312
|
+
const tx = await this.harvestTx(txOptions);
|
|
17774
18313
|
return await this.base.sendAndConfirm(tx);
|
|
17775
18314
|
}
|
|
17776
|
-
async harvestTx(
|
|
18315
|
+
async harvestTx(txOptions = {}) {
|
|
17777
18316
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17778
|
-
const vault = this.base.
|
|
18317
|
+
const vault = this.base.vaultPda;
|
|
17779
18318
|
const farmStates = await this.findAndParseFarmStates(vault);
|
|
17780
18319
|
const parsedFarms = await this.fetchAndParseFarms(farmStates.map((f)=>f.farmState));
|
|
17781
18320
|
const tx = new web3_js.Transaction();
|
|
@@ -17783,10 +18322,10 @@ class KaminoFarmClient {
|
|
|
17783
18322
|
const { globalConfig, rewards } = parsedFarms.get(farmState.toBase58());
|
|
17784
18323
|
for (const { index, mint, tokenProgram, rewardsVault } of rewards){
|
|
17785
18324
|
console.log("Reward token:", mint.toBase58());
|
|
17786
|
-
const vaultAta = this.base.getVaultAta(
|
|
18325
|
+
const vaultAta = this.base.getVaultAta(mint, tokenProgram);
|
|
17787
18326
|
const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultAta, vault, mint, tokenProgram);
|
|
17788
18327
|
const harvestIx = await this.base.program.methods.kaminoFarmHarvestReward(new anchor.BN(index)).accounts({
|
|
17789
|
-
glamState,
|
|
18328
|
+
glamState: this.base.statePda,
|
|
17790
18329
|
glamSigner,
|
|
17791
18330
|
userState: userFarmState,
|
|
17792
18331
|
farmState,
|
|
@@ -17840,8 +18379,7 @@ class MeteoraDlmmClient {
|
|
|
17840
18379
|
}
|
|
17841
18380
|
return dlmmPool;
|
|
17842
18381
|
}
|
|
17843
|
-
async initializePosition(
|
|
17844
|
-
const glamState = new web3_js.PublicKey(statePda);
|
|
18382
|
+
async initializePosition(pool, txOptions = {}) {
|
|
17845
18383
|
const dlmmPool = await this.getDlmmPool(pool);
|
|
17846
18384
|
const activeBin = await dlmmPool.getActiveBin();
|
|
17847
18385
|
const minBinId = activeBin.binId - DEFAULT_RANGE_INTERVAL;
|
|
@@ -17849,7 +18387,7 @@ class MeteoraDlmmClient {
|
|
|
17849
18387
|
const position = web3_js.Keypair.generate();
|
|
17850
18388
|
// @ts-ignore
|
|
17851
18389
|
const tx = await this.base.program.methods.meteoraDlmmInitializePosition(minBinId, maxBinId - minBinId + 1).accounts({
|
|
17852
|
-
glamState,
|
|
18390
|
+
glamState: this.base.statePda,
|
|
17853
18391
|
lbPair: new web3_js.PublicKey(pool),
|
|
17854
18392
|
position: position.publicKey,
|
|
17855
18393
|
eventAuthority: EVENT_AUTHORITY,
|
|
@@ -17860,17 +18398,16 @@ class MeteoraDlmmClient {
|
|
|
17860
18398
|
position
|
|
17861
18399
|
]);
|
|
17862
18400
|
}
|
|
17863
|
-
async initializePositionPda(
|
|
17864
|
-
const glamState = new web3_js.PublicKey(statePda);
|
|
18401
|
+
async initializePositionPda(pool, txOptions = {}) {
|
|
17865
18402
|
const dlmmPool = await this.getDlmmPool(pool);
|
|
17866
18403
|
const activeBin = await dlmmPool.getActiveBin();
|
|
17867
18404
|
const minBinId = activeBin.binId - DEFAULT_RANGE_INTERVAL;
|
|
17868
18405
|
const maxBinId = activeBin.binId + DEFAULT_RANGE_INTERVAL;
|
|
17869
18406
|
const width = maxBinId - minBinId + 1;
|
|
17870
|
-
const position = this.getPositionPda(new web3_js.PublicKey(pool), this.base.
|
|
18407
|
+
const position = this.getPositionPda(new web3_js.PublicKey(pool), this.base.vaultPda, minBinId, width);
|
|
17871
18408
|
// @ts-ignore
|
|
17872
18409
|
const tx = await this.base.program.methods.meteoraDlmmInitializePositionPda(minBinId, width).accounts({
|
|
17873
|
-
glamState,
|
|
18410
|
+
glamState: this.base.statePda,
|
|
17874
18411
|
lbPair: new web3_js.PublicKey(pool),
|
|
17875
18412
|
position,
|
|
17876
18413
|
eventAuthority: EVENT_AUTHORITY,
|
|
@@ -17879,13 +18416,12 @@ class MeteoraDlmmClient {
|
|
|
17879
18416
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17880
18417
|
return await this.base.sendAndConfirm(vTx);
|
|
17881
18418
|
}
|
|
17882
|
-
async addLiquidityByStrategy(
|
|
18419
|
+
async addLiquidityByStrategy(position, amountX, amountY, strategyType, txOptions = {}) {
|
|
17883
18420
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17884
18421
|
const { lbPair, lowerBinId, upperBinId, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, new web3_js.PublicKey(position));
|
|
17885
18422
|
const dlmmPool = await this.getDlmmPool(lbPair);
|
|
17886
18423
|
const activeBinId = (await dlmmPool.getActiveBin()).binId;
|
|
17887
|
-
const
|
|
17888
|
-
const glamVault = this.base.getVaultPda(glamState);
|
|
18424
|
+
const glamVault = this.base.vaultPda;
|
|
17889
18425
|
const vaultTokenXAta = this.base.getAta(dlmmPool.tokenX.publicKey, glamVault);
|
|
17890
18426
|
const vaultTokenYAta = this.base.getAta(dlmmPool.tokenY.publicKey, glamVault);
|
|
17891
18427
|
const liquidityParameter = {
|
|
@@ -17916,7 +18452,7 @@ class MeteoraDlmmClient {
|
|
|
17916
18452
|
const tx = await this.base.program.methods.meteoraDlmmAddLiquidityByStrategy2(liquidityParameter, {
|
|
17917
18453
|
slices: []
|
|
17918
18454
|
}).accounts({
|
|
17919
|
-
glamState,
|
|
18455
|
+
glamState: this.base.statePda,
|
|
17920
18456
|
position: new web3_js.PublicKey(position),
|
|
17921
18457
|
lbPair,
|
|
17922
18458
|
binArrayBitmapExtension: dlmmPool.binArrayBitmapExtension ? dlmmPool.binArrayBitmapExtension.publicKey : METEORA_DLMM_PROGRAM,
|
|
@@ -17934,12 +18470,11 @@ class MeteoraDlmmClient {
|
|
|
17934
18470
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17935
18471
|
return this.base.sendAndConfirm(vTx);
|
|
17936
18472
|
}
|
|
17937
|
-
async removeLiquidityByRange(
|
|
18473
|
+
async removeLiquidityByRange(position, bpsToRemove, txOptions = {}) {
|
|
17938
18474
|
const { lbPair, lowerBinId, upperBinId, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, new web3_js.PublicKey(position));
|
|
17939
18475
|
const dlmmPool = await this.getDlmmPool(lbPair);
|
|
17940
|
-
const
|
|
17941
|
-
const
|
|
17942
|
-
const vaultTokenYAta = this.base.getVaultAta(glamState, dlmmPool.tokenY.publicKey);
|
|
18476
|
+
const vaultTokenXAta = this.base.getVaultAta(dlmmPool.tokenX.publicKey);
|
|
18477
|
+
const vaultTokenYAta = this.base.getVaultAta(dlmmPool.tokenY.publicKey);
|
|
17943
18478
|
const remainingAccounts = [
|
|
17944
18479
|
binArrayLower,
|
|
17945
18480
|
binArrayUpper
|
|
@@ -17952,7 +18487,7 @@ class MeteoraDlmmClient {
|
|
|
17952
18487
|
const tx = await this.base.program.methods.meteoraDlmmRemoveLiquidityByRange2(lowerBinId, upperBinId, bpsToRemove, {
|
|
17953
18488
|
slices: []
|
|
17954
18489
|
}).accounts({
|
|
17955
|
-
glamState,
|
|
18490
|
+
glamState: this.base.statePda,
|
|
17956
18491
|
position: new web3_js.PublicKey(position),
|
|
17957
18492
|
lbPair,
|
|
17958
18493
|
binArrayBitmapExtension: dlmmPool.binArrayBitmapExtension ? dlmmPool.binArrayBitmapExtension.publicKey : METEORA_DLMM_PROGRAM,
|
|
@@ -17971,12 +18506,11 @@ class MeteoraDlmmClient {
|
|
|
17971
18506
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17972
18507
|
return this.base.sendAndConfirm(vTx);
|
|
17973
18508
|
}
|
|
17974
|
-
async claimFee(
|
|
18509
|
+
async claimFee(position, txOptions = {}) {
|
|
17975
18510
|
const { lbPair, lowerBinId, upperBinId, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, new web3_js.PublicKey(position));
|
|
17976
18511
|
const dlmmPool = await this.getDlmmPool(lbPair);
|
|
17977
|
-
const
|
|
17978
|
-
const
|
|
17979
|
-
const vaultTokenYAta = this.base.getVaultAta(glamState, dlmmPool.tokenY.publicKey);
|
|
18512
|
+
const vaultTokenXAta = this.base.getVaultAta(dlmmPool.tokenX.publicKey);
|
|
18513
|
+
const vaultTokenYAta = this.base.getVaultAta(dlmmPool.tokenY.publicKey);
|
|
17980
18514
|
const remainingAccounts = [
|
|
17981
18515
|
binArrayLower,
|
|
17982
18516
|
binArrayUpper
|
|
@@ -17989,7 +18523,7 @@ class MeteoraDlmmClient {
|
|
|
17989
18523
|
const tx = await this.base.program.methods.meteoraDlmmClaimFee2(lowerBinId, upperBinId, {
|
|
17990
18524
|
slices: []
|
|
17991
18525
|
}).accounts({
|
|
17992
|
-
glamState,
|
|
18526
|
+
glamState: this.base.statePda,
|
|
17993
18527
|
position: new web3_js.PublicKey(position),
|
|
17994
18528
|
lbPair,
|
|
17995
18529
|
reserveX: dlmmPool.tokenX.reserve,
|
|
@@ -18007,13 +18541,12 @@ class MeteoraDlmmClient {
|
|
|
18007
18541
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18008
18542
|
return await this.base.sendAndConfirm(vTx);
|
|
18009
18543
|
}
|
|
18010
|
-
async closePosition(
|
|
18544
|
+
async closePosition(position, txOptions = {}) {
|
|
18011
18545
|
const { lbPair, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, new web3_js.PublicKey(position));
|
|
18012
|
-
const glamState = new web3_js.PublicKey(statePda);
|
|
18013
18546
|
console.log(`close position: ${position}, binArrayLower: ${binArrayLower}, binArrayUpper: ${binArrayUpper}`);
|
|
18014
18547
|
// @ts-ignore
|
|
18015
18548
|
const tx = await this.base.program.methods.meteoraDlmmClosePosition().accounts({
|
|
18016
|
-
glamState,
|
|
18549
|
+
glamState: this.base.statePda,
|
|
18017
18550
|
position: new web3_js.PublicKey(position),
|
|
18018
18551
|
lbPair,
|
|
18019
18552
|
binArrayLower,
|
|
@@ -18058,42 +18591,42 @@ class MeteoraDlmmClient {
|
|
|
18058
18591
|
}
|
|
18059
18592
|
|
|
18060
18593
|
class InvestorClient {
|
|
18061
|
-
async subscribe(
|
|
18062
|
-
const tx = await (queued ? this.queuedSubscribeTx(
|
|
18594
|
+
async subscribe(asset, amount, mintId = 0, queued = false, txOptions = {}) {
|
|
18595
|
+
const tx = await (queued ? this.queuedSubscribeTx(asset, amount, mintId, txOptions) : this.subscribeTx(asset, amount, mintId, txOptions));
|
|
18063
18596
|
return await this.base.sendAndConfirm(tx);
|
|
18064
18597
|
}
|
|
18065
|
-
async queuedRedeem(
|
|
18066
|
-
const tx = await this.queuedRedeemTx(
|
|
18598
|
+
async queuedRedeem(asset, amount, mintId = 0, txOptions = {}) {
|
|
18599
|
+
const tx = await this.queuedRedeemTx(asset, amount, mintId, txOptions);
|
|
18067
18600
|
return await this.base.sendAndConfirm(tx);
|
|
18068
18601
|
}
|
|
18069
|
-
async fulfill(
|
|
18070
|
-
const tx = await this.fulfillTx(
|
|
18602
|
+
async fulfill(asset, mintId = 0, txOptions = {}) {
|
|
18603
|
+
const tx = await this.fulfillTx(asset, mintId, txOptions);
|
|
18071
18604
|
return await this.base.sendAndConfirm(tx);
|
|
18072
18605
|
}
|
|
18073
|
-
async claim(
|
|
18606
|
+
async claim(asset, mintId = 0, txOptions = {}) {
|
|
18074
18607
|
// Claim WSOL from redeemed shares
|
|
18075
18608
|
if (asset.equals(WSOL)) {
|
|
18076
|
-
const tx = await this.claimAssetTx(
|
|
18609
|
+
const tx = await this.claimAssetTx(asset, mintId, txOptions);
|
|
18077
18610
|
return await this.base.sendAndConfirm(tx);
|
|
18078
18611
|
}
|
|
18079
18612
|
// Claim shares after subscription is fulfilled
|
|
18080
|
-
const glamMint = this.base.
|
|
18613
|
+
const glamMint = this.base.mintPda;
|
|
18081
18614
|
if (glamMint.equals(asset)) {
|
|
18082
|
-
const tx = await this.claimShareTx(
|
|
18615
|
+
const tx = await this.claimShareTx(asset, mintId, txOptions);
|
|
18083
18616
|
return await this.base.sendAndConfirm(tx);
|
|
18084
18617
|
}
|
|
18085
18618
|
throw new Error(`Invalid asset to claim: ${asset.toBase58()}`);
|
|
18086
18619
|
}
|
|
18087
|
-
async subscribeTx(
|
|
18620
|
+
async subscribeTx(asset, amount, mintId = 0, txOptions = {}) {
|
|
18088
18621
|
if (mintId !== 0 || !asset.equals(WSOL)) {
|
|
18089
18622
|
throw new Error("Only WSOL is supported & mintId must be 0");
|
|
18090
18623
|
}
|
|
18091
18624
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18092
18625
|
// glam mint token to receive
|
|
18093
|
-
const glamMint = this.base.
|
|
18094
|
-
const mintTo = this.base.getMintAta(signer
|
|
18626
|
+
const glamMint = this.base.mintPda;
|
|
18627
|
+
const mintTo = this.base.getMintAta(signer);
|
|
18095
18628
|
// asset token to transfer to vault
|
|
18096
|
-
const vault = this.base.
|
|
18629
|
+
const vault = this.base.vaultPda;
|
|
18097
18630
|
const vaultInput = this.base.getAta(asset, vault);
|
|
18098
18631
|
const signerInput = this.base.getAta(asset, signer);
|
|
18099
18632
|
const wrapSolIxs = asset.equals(WSOL) ? [
|
|
@@ -18116,13 +18649,13 @@ class InvestorClient {
|
|
|
18116
18649
|
] : [];
|
|
18117
18650
|
// Check if lockup is enabled on the fund, if so, add signerPolicy
|
|
18118
18651
|
let signerPolicy = null;
|
|
18119
|
-
if (await this.base.isLockupEnabled(
|
|
18120
|
-
signerPolicy = this.base.
|
|
18652
|
+
if (await this.base.isLockupEnabled()) {
|
|
18653
|
+
signerPolicy = getAccountPolicyPda(this.base.getMintAta(signer));
|
|
18121
18654
|
console.log(`signerPolicy: ${signerPolicy} for signer ${signer} and token account ${mintTo}`);
|
|
18122
18655
|
}
|
|
18123
18656
|
// @ts-ignore
|
|
18124
18657
|
const tx = await this.base.program.methods.subscribe(0, amount).accounts({
|
|
18125
|
-
glamState,
|
|
18658
|
+
glamState: this.base.statePda,
|
|
18126
18659
|
glamMint,
|
|
18127
18660
|
signer,
|
|
18128
18661
|
depositAsset: asset,
|
|
@@ -18130,13 +18663,13 @@ class InvestorClient {
|
|
|
18130
18663
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
18131
18664
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18132
18665
|
}
|
|
18133
|
-
async queuedSubscribeTx(
|
|
18666
|
+
async queuedSubscribeTx(asset, amount, mintId = 0, txOptions = {}) {
|
|
18134
18667
|
if (mintId !== 0 || !asset.equals(WSOL)) {
|
|
18135
18668
|
throw new Error("Only WSOL is supported & mintId must be 0");
|
|
18136
18669
|
}
|
|
18137
18670
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18138
18671
|
// asset token to transfer to escrow
|
|
18139
|
-
const escrow = this.base.
|
|
18672
|
+
const escrow = this.base.escrowPda;
|
|
18140
18673
|
const escrowAta = this.base.getAta(asset, escrow);
|
|
18141
18674
|
const signerAta = this.base.getAta(asset, signer);
|
|
18142
18675
|
const wrapSolIxs = asset.equals(WSOL) ? [
|
|
@@ -18158,37 +18691,36 @@ class InvestorClient {
|
|
|
18158
18691
|
] : [];
|
|
18159
18692
|
// @ts-ignore
|
|
18160
18693
|
const tx = await this.base.program.methods.queuedSubscribe(0, amount).accounts({
|
|
18161
|
-
glamState,
|
|
18694
|
+
glamState: this.base.statePda,
|
|
18162
18695
|
signer,
|
|
18163
18696
|
depositAsset: asset
|
|
18164
18697
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
18165
18698
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18166
18699
|
}
|
|
18167
|
-
async queuedRedeemTx(
|
|
18700
|
+
async queuedRedeemTx(asset, amount, mintId = 0, txOptions = {}) {
|
|
18168
18701
|
if (mintId !== 0 || !asset.equals(WSOL)) {
|
|
18169
18702
|
throw new Error("Only WSOL is supported & mintId must be 0");
|
|
18170
18703
|
}
|
|
18171
18704
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18172
|
-
const glamMint = this.base.
|
|
18705
|
+
const glamMint = this.base.mintPda;
|
|
18173
18706
|
const preInstructions = [
|
|
18174
|
-
splToken.createAssociatedTokenAccountIdempotentInstruction(signer, this.base.getMintAta(signer
|
|
18707
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(signer, this.base.getMintAta(signer), signer, glamMint, splToken.TOKEN_2022_PROGRAM_ID)
|
|
18175
18708
|
];
|
|
18176
18709
|
const remainingAccounts = [];
|
|
18177
|
-
if (await this.base.isLockupEnabled(
|
|
18178
|
-
const extraMetasAccount = this.base.
|
|
18179
|
-
const signerPolicy = this.base.
|
|
18180
|
-
const escrow = this.base.
|
|
18181
|
-
const escrowPolicy = this.base.
|
|
18710
|
+
if (await this.base.isLockupEnabled()) {
|
|
18711
|
+
const extraMetasAccount = this.base.extraMetasPda;
|
|
18712
|
+
const signerPolicy = getAccountPolicyPda(this.base.getMintAta(signer));
|
|
18713
|
+
const escrow = this.base.escrowPda;
|
|
18714
|
+
const escrowPolicy = getAccountPolicyPda(this.base.getMintAta(escrow));
|
|
18182
18715
|
remainingAccounts.push(...[
|
|
18183
18716
|
extraMetasAccount,
|
|
18184
|
-
glamState,
|
|
18185
18717
|
signerPolicy,
|
|
18186
18718
|
escrowPolicy,
|
|
18187
18719
|
TRANSFER_HOOK_PROGRAM
|
|
18188
18720
|
]);
|
|
18189
18721
|
}
|
|
18190
18722
|
const tx = await this.base.program.methods.queuedRedeem(0, amount).accounts({
|
|
18191
|
-
glamState,
|
|
18723
|
+
glamState: this.base.statePda,
|
|
18192
18724
|
glamMint,
|
|
18193
18725
|
signer
|
|
18194
18726
|
}).preInstructions(preInstructions).remainingAccounts(remainingAccounts.map((pubkey)=>({
|
|
@@ -18198,16 +18730,16 @@ class InvestorClient {
|
|
|
18198
18730
|
}))).transaction();
|
|
18199
18731
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18200
18732
|
}
|
|
18201
|
-
async fulfillTx(
|
|
18733
|
+
async fulfillTx(asset, mintId = 0, txOptions = {}) {
|
|
18202
18734
|
if (mintId !== 0 || !asset.equals(WSOL)) {
|
|
18203
18735
|
throw new Error("Only WSOL is supported & mintId must be 0");
|
|
18204
18736
|
}
|
|
18205
18737
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18206
|
-
const vault = this.base.
|
|
18738
|
+
const vault = this.base.vaultPda;
|
|
18207
18739
|
const vaultAssetAta = this.base.getAta(asset, vault);
|
|
18208
|
-
const glamMint = this.base.
|
|
18209
|
-
const escrow = this.base.
|
|
18210
|
-
const escrowMintAta = this.base.getMintAta(escrow
|
|
18740
|
+
const glamMint = this.base.mintPda;
|
|
18741
|
+
const escrow = this.base.escrowPda;
|
|
18742
|
+
const escrowMintAta = this.base.getMintAta(escrow);
|
|
18211
18743
|
const escrowAssetAta = this.base.getAta(asset, escrow);
|
|
18212
18744
|
let preInstructions = [
|
|
18213
18745
|
splToken.createAssociatedTokenAccountIdempotentInstruction(signer, escrowMintAta, escrow, glamMint, splToken.TOKEN_2022_PROGRAM_ID),
|
|
@@ -18216,22 +18748,22 @@ class InvestorClient {
|
|
|
18216
18748
|
...txOptions.preInstructions || []
|
|
18217
18749
|
];
|
|
18218
18750
|
const tx = await this.base.program.methods.fulfill(mintId).accounts({
|
|
18219
|
-
glamState,
|
|
18751
|
+
glamState: this.base.statePda,
|
|
18220
18752
|
glamMint,
|
|
18221
18753
|
signer,
|
|
18222
18754
|
asset
|
|
18223
18755
|
}).preInstructions(preInstructions).transaction();
|
|
18224
18756
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18225
18757
|
}
|
|
18226
|
-
async claimAssetTx(
|
|
18758
|
+
async claimAssetTx(asset, mintId = 0, txOptions = {}) {
|
|
18227
18759
|
if (mintId !== 0 || !asset.equals(WSOL)) {
|
|
18228
18760
|
throw new Error("Only WSOL is supported & mintId must be 0");
|
|
18229
18761
|
}
|
|
18230
18762
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18231
|
-
this.base.
|
|
18763
|
+
this.base.mintPda;
|
|
18232
18764
|
const signerAta = this.base.getAta(asset, signer);
|
|
18233
18765
|
const tx = await this.base.program.methods.claim(0).accounts({
|
|
18234
|
-
glamState,
|
|
18766
|
+
glamState: this.base.statePda,
|
|
18235
18767
|
signer,
|
|
18236
18768
|
tokenMint: asset,
|
|
18237
18769
|
tokenProgram: splToken.TOKEN_PROGRAM_ID
|
|
@@ -18242,29 +18774,28 @@ class InvestorClient {
|
|
|
18242
18774
|
]).transaction();
|
|
18243
18775
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18244
18776
|
}
|
|
18245
|
-
async claimShareTx(
|
|
18777
|
+
async claimShareTx(asset, mintId = 0, txOptions = {}) {
|
|
18246
18778
|
if (mintId !== 0) {
|
|
18247
18779
|
throw new Error("mintId must be 0");
|
|
18248
18780
|
}
|
|
18249
18781
|
const signer = txOptions.signer || this.base.getSigner();
|
|
18250
|
-
this.base.
|
|
18782
|
+
this.base.mintPda;
|
|
18251
18783
|
const signerAta = this.base.getAta(asset, signer, splToken.TOKEN_2022_PROGRAM_ID);
|
|
18252
|
-
const escrow = this.base.
|
|
18784
|
+
const escrow = this.base.escrowPda;
|
|
18253
18785
|
const remainingAccounts = [];
|
|
18254
|
-
if (await this.base.isLockupEnabled(
|
|
18255
|
-
const extraMetasAccount = this.base.
|
|
18256
|
-
const signerPolicy = this.base.
|
|
18257
|
-
const escrowPolicy = this.base.
|
|
18786
|
+
if (await this.base.isLockupEnabled()) {
|
|
18787
|
+
const extraMetasAccount = this.base.extraMetasPda;
|
|
18788
|
+
const signerPolicy = getAccountPolicyPda(this.base.getMintAta(signer));
|
|
18789
|
+
const escrowPolicy = getAccountPolicyPda(this.base.getMintAta(escrow));
|
|
18258
18790
|
remainingAccounts.push(...[
|
|
18259
18791
|
extraMetasAccount,
|
|
18260
|
-
glamState,
|
|
18261
18792
|
escrowPolicy,
|
|
18262
18793
|
signerPolicy,
|
|
18263
18794
|
TRANSFER_HOOK_PROGRAM
|
|
18264
18795
|
]);
|
|
18265
18796
|
}
|
|
18266
18797
|
const tx = await this.base.program.methods.claim(0).accounts({
|
|
18267
|
-
glamState,
|
|
18798
|
+
glamState: this.base.statePda,
|
|
18268
18799
|
signer,
|
|
18269
18800
|
tokenMint: asset,
|
|
18270
18801
|
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
@@ -18287,9 +18818,10 @@ class PriceClient {
|
|
|
18287
18818
|
* !! This is a convenience method that calculates the AUM of the vault based on priced assets.
|
|
18288
18819
|
* !! It doesn't reflect the actual AUM of the vault.
|
|
18289
18820
|
* !! If the vault has not been priced or pricing data is outdated, the number is NOT meaningful.
|
|
18290
|
-
*/ async getAum(
|
|
18821
|
+
*/ async getAum() {
|
|
18822
|
+
console.warn("getAum() should only be used for testing. It doesn't reflect the actual AUM of the vault in production.");
|
|
18291
18823
|
// @ts-ignore
|
|
18292
|
-
const glamStateAccount = await this.base.fetchStateAccount(
|
|
18824
|
+
const glamStateAccount = await this.base.fetchStateAccount();
|
|
18293
18825
|
let pricedAssets = [];
|
|
18294
18826
|
glamStateAccount.params[0].forEach((param)=>{
|
|
18295
18827
|
const name = Object.keys(param.name)[0];
|
|
@@ -18300,43 +18832,48 @@ class PriceClient {
|
|
|
18300
18832
|
});
|
|
18301
18833
|
return pricedAssets.reduce((sum, p)=>new anchor.BN(p.amount).add(sum), new anchor.BN(0));
|
|
18302
18834
|
}
|
|
18303
|
-
async
|
|
18304
|
-
const glamVault = this.base.
|
|
18835
|
+
async priceKaminoIx(priceDenom) {
|
|
18836
|
+
const glamVault = this.base.vaultPda;
|
|
18305
18837
|
const obligations = await fetchKaminoObligations(this.base.provider.connection, glamVault);
|
|
18306
|
-
const
|
|
18307
|
-
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18838
|
+
const parsedObligations = await Promise.all(obligations.map((o)=>this.klend.fetchAndParseObligation(o)));
|
|
18839
|
+
const pubkeySet = new Set([]);
|
|
18840
|
+
parsedObligations.filter((o)=>o.lendingMarket !== null).map((o)=>{
|
|
18841
|
+
pubkeySet.add(o.address.toBase58());
|
|
18842
|
+
pubkeySet.add(o.lendingMarket.toBase58());
|
|
18843
|
+
o.deposits.forEach((d)=>pubkeySet.add(d.reserve.toBase58()));
|
|
18844
|
+
o.borrows.forEach((b)=>pubkeySet.add(b.reserve.toBase58()));
|
|
18845
|
+
});
|
|
18846
|
+
const remainingAccounts = Array.from(pubkeySet).map((k)=>({
|
|
18847
|
+
pubkey: new web3_js.PublicKey(k),
|
|
18848
|
+
isSigner: false,
|
|
18849
|
+
isWritable: true
|
|
18850
|
+
}));
|
|
18311
18851
|
// @ts-ignore
|
|
18312
18852
|
const priceIx = await this.base.program.methods.priceKaminoObligations(priceDenom).accounts({
|
|
18313
|
-
glamState,
|
|
18314
|
-
solOracle: SOL_ORACLE
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
return
|
|
18321
|
-
...refreshIxs,
|
|
18322
|
-
priceIx
|
|
18323
|
-
];
|
|
18853
|
+
glamState: this.base.statePda,
|
|
18854
|
+
solOracle: SOL_ORACLE,
|
|
18855
|
+
pythOracle: null,
|
|
18856
|
+
switchboardPriceOracle: null,
|
|
18857
|
+
switchboardTwapOracle: null,
|
|
18858
|
+
scopePrices: KAMINO_SCOPE_PRICES
|
|
18859
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
18860
|
+
return priceIx;
|
|
18324
18861
|
}
|
|
18325
|
-
async priceVaultIxs(
|
|
18326
|
-
const
|
|
18327
|
-
const tickets = await fetchMarinadeTicketAccounts(this.base.provider.connection,
|
|
18862
|
+
async priceVaultIxs(priceDenom) {
|
|
18863
|
+
const glamVault = this.base.vaultPda;
|
|
18864
|
+
const tickets = await fetchMarinadeTicketAccounts(this.base.provider.connection, glamVault);
|
|
18328
18865
|
// @ts-ignore
|
|
18329
18866
|
const priceTicketsIx = await this.base.program.methods.priceTickets(priceDenom).accounts({
|
|
18330
|
-
glamState,
|
|
18867
|
+
glamState: this.base.statePda,
|
|
18331
18868
|
solOracle: SOL_ORACLE
|
|
18332
18869
|
}).remainingAccounts(tickets.map((t)=>({
|
|
18333
18870
|
pubkey: t.pubkey,
|
|
18334
18871
|
isSigner: false,
|
|
18335
18872
|
isWritable: false
|
|
18336
18873
|
}))).instruction();
|
|
18337
|
-
const stakes = await fetchStakeAccounts(this.base.provider.connection,
|
|
18874
|
+
const stakes = await fetchStakeAccounts(this.base.provider.connection, glamVault);
|
|
18338
18875
|
const priceStakesIx = await this.base.program.methods.priceStakes(priceDenom).accounts({
|
|
18339
|
-
glamState,
|
|
18876
|
+
glamState: this.base.statePda,
|
|
18340
18877
|
solOracle: SOL_ORACLE
|
|
18341
18878
|
}).remainingAccounts(stakes.map((s)=>({
|
|
18342
18879
|
pubkey: s,
|
|
@@ -18344,27 +18881,50 @@ class PriceClient {
|
|
|
18344
18881
|
isWritable: false
|
|
18345
18882
|
}))).instruction();
|
|
18346
18883
|
const priceVaultIx = await this.base.program.methods.priceVault(priceDenom).accounts({
|
|
18347
|
-
glamState,
|
|
18884
|
+
glamState: this.base.statePda,
|
|
18348
18885
|
solOracle: SOL_ORACLE
|
|
18349
|
-
}).remainingAccounts(await this.remainingAccountsForPricingVaultAssets(
|
|
18886
|
+
}).remainingAccounts(await this.remainingAccountsForPricingVaultAssets()).instruction();
|
|
18350
18887
|
const priceMeteoraIx = await this.base.program.methods.priceMeteoraPositions(priceDenom).accounts({
|
|
18351
|
-
glamState,
|
|
18888
|
+
glamState: this.base.statePda,
|
|
18352
18889
|
solOracle: SOL_ORACLE
|
|
18353
|
-
}).remainingAccounts(await this.remainingAccountsForPricingMeteora(
|
|
18354
|
-
const
|
|
18355
|
-
|
|
18356
|
-
|
|
18357
|
-
|
|
18358
|
-
|
|
18359
|
-
|
|
18360
|
-
|
|
18361
|
-
|
|
18890
|
+
}).remainingAccounts(await this.remainingAccountsForPricingMeteora()).instruction();
|
|
18891
|
+
const priceKaminoIx = await this.priceKaminoIx(priceDenom);
|
|
18892
|
+
try {
|
|
18893
|
+
const { user, userStats } = this.drift.getDriftUserPdas();
|
|
18894
|
+
const remainingAccounts = await this.drift.composeRemainingAccounts(0);
|
|
18895
|
+
const priceDriftIx = await this.base.program.methods.priceDrift(priceDenom).accounts({
|
|
18896
|
+
glamState: this.base.statePda,
|
|
18897
|
+
glamVault,
|
|
18898
|
+
solOracle: SOL_ORACLE,
|
|
18899
|
+
user,
|
|
18900
|
+
userStats,
|
|
18901
|
+
state: this.drift.driftStatePda
|
|
18902
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
18903
|
+
return [
|
|
18904
|
+
priceTicketsIx,
|
|
18905
|
+
priceStakesIx,
|
|
18906
|
+
priceVaultIx,
|
|
18907
|
+
priceMeteoraIx,
|
|
18908
|
+
priceKaminoIx,
|
|
18909
|
+
priceDriftIx
|
|
18910
|
+
];
|
|
18911
|
+
} catch (error) {
|
|
18912
|
+
// Drift user not found, skip priceDriftIx
|
|
18913
|
+
return [
|
|
18914
|
+
priceTicketsIx,
|
|
18915
|
+
priceStakesIx,
|
|
18916
|
+
priceVaultIx,
|
|
18917
|
+
priceMeteoraIx,
|
|
18918
|
+
priceKaminoIx
|
|
18919
|
+
];
|
|
18920
|
+
}
|
|
18362
18921
|
}
|
|
18363
|
-
constructor(base, klend){
|
|
18922
|
+
constructor(base, klend, drift){
|
|
18364
18923
|
this.base = base;
|
|
18365
18924
|
this.klend = klend;
|
|
18366
|
-
this.
|
|
18367
|
-
|
|
18925
|
+
this.drift = drift;
|
|
18926
|
+
this.remainingAccountsForPricingMeteora = async ()=>{
|
|
18927
|
+
const glamVault = this.base.vaultPda;
|
|
18368
18928
|
const positions = await fetchMeteoraPositions(this.base.provider.connection, glamVault);
|
|
18369
18929
|
let chunks = await Promise.all(positions.map(async (pubkey)=>{
|
|
18370
18930
|
const { lbPair, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, pubkey);
|
|
@@ -18383,10 +18943,10 @@ class PriceClient {
|
|
|
18383
18943
|
}));
|
|
18384
18944
|
return chunks.flat();
|
|
18385
18945
|
};
|
|
18386
|
-
this.remainingAccountsForPricingVaultAssets = async (
|
|
18387
|
-
const glamStateAccount = await this.base.fetchStateAccount(
|
|
18946
|
+
this.remainingAccountsForPricingVaultAssets = async ()=>{
|
|
18947
|
+
const glamStateAccount = await this.base.fetchStateAccount();
|
|
18388
18948
|
return glamStateAccount.assets.map((asset)=>[
|
|
18389
|
-
this.base.getVaultAta(
|
|
18949
|
+
this.base.getVaultAta(asset),
|
|
18390
18950
|
asset,
|
|
18391
18951
|
// FIXME: check oracle vs LST state?
|
|
18392
18952
|
ASSETS_MAINNET.get(asset.toBase58())?.oracle || new web3_js.PublicKey(0)
|
|
@@ -18448,7 +19008,7 @@ class PriceClient {
|
|
|
18448
19008
|
}
|
|
18449
19009
|
get price() {
|
|
18450
19010
|
if (!this._price) {
|
|
18451
|
-
this._price = new PriceClient(this, this.kaminoLending);
|
|
19011
|
+
this._price = new PriceClient(this, this.kaminoLending, this.drift);
|
|
18452
19012
|
}
|
|
18453
19013
|
return this._price;
|
|
18454
19014
|
}
|
|
@@ -18598,6 +19158,7 @@ exports.JupiterVoteClient = JupiterVoteClient;
|
|
|
18598
19158
|
exports.KAMINO_FARM_PROGRAM = KAMINO_FARM_PROGRAM;
|
|
18599
19159
|
exports.KAMINO_LENDING_PROGRAM = KAMINO_LENDING_PROGRAM;
|
|
18600
19160
|
exports.KAMINO_OBTRIGATION_SIZE = KAMINO_OBTRIGATION_SIZE;
|
|
19161
|
+
exports.KAMINO_SCOPE_PRICES = KAMINO_SCOPE_PRICES;
|
|
18601
19162
|
exports.LPAction = LPAction;
|
|
18602
19163
|
exports.LiquidationType = LiquidationType;
|
|
18603
19164
|
exports.MARINADE_PROGRAM_ID = MARINADE_PROGRAM_ID;
|
|
@@ -18650,6 +19211,7 @@ exports.StateModel = StateModel;
|
|
|
18650
19211
|
exports.SwapDirection = SwapDirection;
|
|
18651
19212
|
exports.SwapReduceOnly = SwapReduceOnly;
|
|
18652
19213
|
exports.TRANSFER_HOOK_PROGRAM = TRANSFER_HOOK_PROGRAM;
|
|
19214
|
+
exports.TimeUnit = TimeUnit;
|
|
18653
19215
|
exports.TradeSide = TradeSide;
|
|
18654
19216
|
exports.USDC = USDC;
|
|
18655
19217
|
exports.UserStatus = UserStatus;
|
|
@@ -18659,19 +19221,27 @@ exports.WSOL = WSOL;
|
|
|
18659
19221
|
exports.ZERO = ZERO;
|
|
18660
19222
|
exports.decodeUser = decodeUser;
|
|
18661
19223
|
exports.fetchKaminoObligations = fetchKaminoObligations;
|
|
19224
|
+
exports.fetchLookupTables = fetchLookupTables;
|
|
18662
19225
|
exports.fetchMarinadeTicketAccounts = fetchMarinadeTicketAccounts;
|
|
18663
19226
|
exports.fetchMeteoraPositions = fetchMeteoraPositions;
|
|
18664
19227
|
exports.fetchStakeAccounts = fetchStakeAccounts;
|
|
19228
|
+
exports.getAccountPolicyPda = getAccountPolicyPda;
|
|
19229
|
+
exports.getEscrowPda = getEscrowPda;
|
|
19230
|
+
exports.getExtraMetasPda = getExtraMetasPda;
|
|
18665
19231
|
exports.getGlamProgram = getGlamProgram;
|
|
18666
19232
|
exports.getGlamProgramId = getGlamProgramId;
|
|
18667
19233
|
exports.getLimitOrderParams = getLimitOrderParams;
|
|
18668
19234
|
exports.getMarketOrderParams = getMarketOrderParams;
|
|
19235
|
+
exports.getMintPda = getMintPda;
|
|
19236
|
+
exports.getOpenfundsPda = getOpenfundsPda;
|
|
18669
19237
|
exports.getOrderParams = getOrderParams;
|
|
18670
19238
|
exports.getPriorityFeeEstimate = getPriorityFeeEstimate;
|
|
18671
19239
|
exports.getSimulationComputeUnits = getSimulationComputeUnits;
|
|
19240
|
+
exports.getStatePda = getStatePda;
|
|
18672
19241
|
exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
|
|
18673
19242
|
exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
|
|
18674
19243
|
exports.getVariant = getVariant;
|
|
19244
|
+
exports.getVaultPda = getVaultPda;
|
|
18675
19245
|
exports.isBrowser = isBrowser;
|
|
18676
19246
|
exports.isOneOfVariant = isOneOfVariant;
|
|
18677
19247
|
exports.isVariant = isVariant;
|