-
Notifications
You must be signed in to change notification settings - Fork 548
/
useGovernanceAssets.ts
862 lines (820 loc) · 32.8 KB
/
useGovernanceAssets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
import { AccountType, AssetAccount } from '@utils/uiTypes/assets'
import { Instructions, PackageEnum } from '@utils/uiTypes/proposalCreationTypes'
import useGovernanceAssetsStore from 'stores/useGovernanceAssetsStore'
import { HELIUM_VSR_PLUGINS_PKS, VSR_PLUGIN_PKS } from '../constants/plugins'
import { useRealmQuery } from './queries/realm'
import { useRealmConfigQuery } from './queries/realmConfig'
import { useRealmGovernancesQuery } from './queries/governance'
import { useMemo } from 'react'
import { useRealmVoterWeights } from '@hooks/useRealmVoterWeightPlugins'
import { GovernanceConfig } from '@solana/spl-governance'
type Package = {
name: string
image?: string
isVisible?: boolean
}
type Packages = {
[packageId in PackageEnum]: Package
}
type PackageType = Package & {
id: PackageEnum
}
type Instruction = {
name: string
isVisible?: boolean
packageId: PackageEnum
assetType?: 'token' | 'mint' | 'wallet'
}
type InstructionsMap = {
[instructionId in Instructions]: Instruction
}
export type InstructionType = {
id: Instructions
name: string
packageId: PackageEnum
}
export default function useGovernanceAssets() {
const realm = useRealmQuery().data?.result
const config = useRealmConfigQuery().data?.result
const { communityWeight, councilWeight } = useRealmVoterWeights()
const ownVoterWeights = {
community: communityWeight?.value,
council: councilWeight?.value,
}
const canCreateProposal = (config: GovernanceConfig) => {
return (
ownVoterWeights.community?.gte(
config.minCommunityTokensToCreateProposal
) || ownVoterWeights.council?.gte(config.minCouncilTokensToCreateProposal)
)
}
const governedTokenAccounts: AssetAccount[] = useGovernanceAssetsStore(
(s) => s.governedTokenAccounts
)
const assetAccounts = useGovernanceAssetsStore((s) =>
s.assetAccounts.filter((x) => x.type !== AccountType.AUXILIARY_TOKEN)
)
const auxiliaryTokenAccounts = useGovernanceAssetsStore(
(s) => s.assetAccounts
).filter((x) => x.type === AccountType.AUXILIARY_TOKEN)
const currentPluginPk = config?.account.communityTokenConfig.voterWeightAddin
const governancesQuery = useRealmGovernancesQuery()
const governancesArray = useMemo(() => governancesQuery.data ?? [], [
governancesQuery.data,
])
function canUseGovernanceForInstruction(types: AccountType[]) {
return (
realm &&
assetAccounts
.filter((x) => types.find((t) => t === x.type))
.some((govAcc) => canCreateProposal(govAcc.governance.account.config))
)
}
const canMintRealmCouncilToken = () => {
return !!assetAccounts.find(
(x) =>
x.pubkey.toBase58() == realm?.account.config.councilMint?.toBase58()
)
}
const canUseTransferInstruction = governedTokenAccounts.some((acc) => {
const governance = governancesArray.find(
(x) => acc.governance.pubkey.toBase58() === x.pubkey.toBase58()
)
return governance && canCreateProposal(governance?.account?.config)
})
const canUseProgramUpgradeInstruction = canUseGovernanceForInstruction([
AccountType.PROGRAM,
])
const canUseMintInstruction = canUseGovernanceForInstruction([
AccountType.MINT,
])
const canUseAnyInstruction =
realm &&
governancesArray.some((gov) => canCreateProposal(gov.account.config))
const realmAuth =
realm &&
governancesArray.find(
(x) => x.pubkey.toBase58() === realm.account.authority?.toBase58()
)
const canUseAuthorityInstruction =
realmAuth && canCreateProposal(realmAuth?.account.config)
const governedSPLTokenAccounts = governedTokenAccounts.filter(
(x) => x.type === AccountType.TOKEN
)
const governedTokenAccountsWithoutNfts = governedTokenAccounts.filter(
(x) => x.type !== AccountType.NFT
)
const governedNativeAccounts = governedTokenAccounts.filter(
(x) => x.type === AccountType.SOL
)
const canUseTokenTransferInstruction = governedTokenAccountsWithoutNfts.some(
(acc) => {
const governance = governancesArray.find(
(x) => acc.governance.pubkey.toBase58() === x.pubkey.toBase58()
)
return governance && canCreateProposal(governance?.account?.config)
}
)
// Alphabetical order
// Images are in public/img/
//
// If an image is not set, then the name is displayed in the select
// please use png with transparent background for logos
//
// Packages are visible by default
const packages: Packages = {
[PackageEnum.Common]: {
name: 'Common',
},
[PackageEnum.Dual]: {
name: 'Dual Finance',
image: '/img/dual-logo.png',
},
[PackageEnum.Distribution]: {
name: 'Distribution Program',
},
[PackageEnum.GatewayPlugin]: {
name: 'Civic Plugin',
image: '/img/civic.svg',
},
[PackageEnum.Identity]: {
name: 'Identity',
image: '/img/identity.png',
},
[PackageEnum.NftPlugin]: {
name: 'NFT Plugin',
},
[PackageEnum.MangoMarketV4]: {
name: 'Mango Market v4',
image: '/img/mango.png',
},
[PackageEnum.MeanFinance]: {
name: 'Mean Finance',
image: '/img/meanfinance.png',
},
[PackageEnum.PsyFinance]: {
name: 'PsyFinance',
image: '/img/psyfinance.png',
},
[PackageEnum.Pyth]: {
name: 'Pyth',
image: '/img/pyth.svg',
},
[PackageEnum.Serum]: {
name: 'Serum',
image: '/img/serum.png',
// Temporary:
// Hide serum package for now, due to wallet disconnection bug
isVisible: false,
},
[PackageEnum.Solend]: {
name: 'Solend',
image: '/img/solend.png',
},
[PackageEnum.Symmetry]: {
name: 'Symmetry',
image: '/img/symmetry.png',
},
[PackageEnum.Squads]: {
name: 'Squads',
image: '/img/squads.png',
},
[PackageEnum.Switchboard]: {
name: 'Switchboard',
image: '/img/switchboard.png',
},
[PackageEnum.VsrPlugin]: {
name: 'Vsr Plugin',
isVisible:
currentPluginPk &&
[...VSR_PLUGIN_PKS, ...HELIUM_VSR_PLUGINS_PKS].includes(
currentPluginPk.toBase58()
),
},
}
// Alphabetical order, Packages then instructions
//
// To generate package name comment, use:
// https://patorjk.com/software/taag/#p=display&f=ANSI%20Regular&t=COMMON%0A
//
// If isVisible is not set, it is equal to canUseAnyInstruction
const instructionsMap: InstructionsMap = {
/*
██████ ██████ ███ ███ ███ ███ ██████ ███ ██
██ ██ ██ ████ ████ ████ ████ ██ ██ ████ ██
██ ██ ██ ██ ████ ██ ██ ████ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██████ ██ ██ ██ ██ ██████ ██ ████
*/
[Instructions.RevokeGoverningTokens]: {
name: 'Revoke Membership',
packageId: PackageEnum.Common,
},
[Instructions.Base64]: {
name: 'Execute Custom Instruction',
packageId: PackageEnum.Common,
},
[Instructions.ChangeMakeDonation]: {
name: 'Donation to Charity',
packageId: PackageEnum.Common,
},
[Instructions.Clawback]: {
name: 'Clawback',
isVisible:
canUseTokenTransferInstruction &&
currentPluginPk &&
VSR_PLUGIN_PKS.includes(currentPluginPk.toBase58()),
packageId: PackageEnum.VsrPlugin,
},
[Instructions.CloseTokenAccount]: {
name: 'Close token account',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.CloseMultipleTokenAccounts]: {
name: 'Close multiple token accounts',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.CreateAssociatedTokenAccount]: {
name: 'Create Associated Token Account',
packageId: PackageEnum.Common,
},
[Instructions.CreateTokenMetadata]: {
name: 'Create Token Metadata',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.Common,
},
[Instructions.DeactivateValidatorStake]: {
name: 'Deactivate validator stake',
packageId: PackageEnum.Common,
},
[Instructions.DelegateStake]: {
name: 'Delegate Stake Account',
packageId: PackageEnum.Common,
},
[Instructions.RemoveStakeLock]: {
name: 'Stake Account Remove Lock',
packageId: PackageEnum.Common,
},
[Instructions.DifferValidatorStake]: {
name: 'Differ validator stake',
// Not to be used for now
isVisible: false,
packageId: PackageEnum.Common,
},
[Instructions.Grant]: {
name: 'Grant',
isVisible:
canUseTokenTransferInstruction &&
currentPluginPk &&
VSR_PLUGIN_PKS.includes(currentPluginPk.toBase58()),
packageId: PackageEnum.VsrPlugin,
},
[Instructions.JoinDAO]: {
name: 'Join a DAO',
packageId: PackageEnum.Common,
},
[Instructions.Mint]: {
name: 'Mint Tokens',
isVisible: canUseMintInstruction,
packageId: PackageEnum.Common,
},
[Instructions.None]: {
name: 'None',
isVisible:
realm &&
governancesArray.some((g) => canCreateProposal(g.account.config)),
packageId: PackageEnum.Common,
},
[Instructions.ProgramUpgrade]: {
name: 'Upgrade Program',
isVisible: canUseProgramUpgradeInstruction,
packageId: PackageEnum.Common,
},
[Instructions.RealmConfig]: {
name: 'Realm config',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.Common,
},
[Instructions.StakeValidator]: {
name: 'Stake A Validator',
packageId: PackageEnum.Common,
},
[Instructions.SanctumDepositStake]: {
name: 'Sanctum Deposit Stake',
packageId: PackageEnum.Common,
},
[Instructions.SanctumWithdrawStake]: {
name: 'Sanctum Withdraw Stake',
packageId: PackageEnum.Common,
},
[Instructions.Transfer]: {
name: 'Transfer Tokens',
isVisible: canUseTokenTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.Burn]: {
name: 'Burn Tokens',
isVisible: canUseTokenTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.TransferDomainName]: {
name: 'SNS Transfer Out Domain Name',
packageId: PackageEnum.Common,
},
[Instructions.UpdateTokenMetadata]: {
name: 'Update Token Metadata',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.Common,
},
[Instructions.WithdrawValidatorStake]: {
name: 'Withdraw validator stake',
packageId: PackageEnum.Common,
},
[Instructions.SetMintAuthority]: {
name: 'Set Mint Authority',
packageId: PackageEnum.Common,
},
[Instructions.SplitStake]: {
name: 'Split Stake Validator',
packageId: PackageEnum.Common,
},
[Instructions.DaoVote]: {
name: 'Vote in another DAO',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.DualFinanceDelegateWithdraw]: {
name: 'Withdraw Vote Deposit',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Common,
},
[Instructions.DualFinanceVoteDeposit]: {
name: 'Join a VSR DAO',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Common,
},
/*
██████ ██ ██ █████ ██ ███████ ██ ███ ██ █████ ███ ██ ██████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██ ██
██ ██ ██ ██ ███████ ██ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██████ ██ ██ ███████ ██ ██ ██ ████ ██ ██ ██ ████ ██████ ███████
*/
[Instructions.DualFinanceStakingOption]: {
name: 'Staking Option',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceGso]: {
name: 'Lockup Staking Option',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceLiquidityStakingOption]: {
name: 'Liquidity Staking Option',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceInitStrike]: {
name: 'Init Staking Option Strike',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceExerciseStakingOption]: {
name: 'Exercise Staking Option',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceGsoWithdraw]: {
name: 'Lockup Staking Option Withdraw',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceStakingOptionWithdraw]: {
name: 'Withdraw',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceAirdrop]: {
name: 'Airdrop',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceDelegate]: {
name: 'Delegate',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
/*
██ ██████ ███████ ███ ██ ████████ ██ ████████ ██ ██
██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██████ ███████ ██ ████ ██ ██ ██ ██
*/
[Instructions.ConfigureGatewayPlugin]: {
name: 'Configure',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.GatewayPlugin,
},
[Instructions.CreateGatewayPluginRegistrar]: {
name: 'Create registrar',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.GatewayPlugin,
},
[Instructions.AddKeyToDID]: {
name: 'Add Key to DID',
isVisible: canUseAnyInstruction,
packageId: PackageEnum.Identity,
},
[Instructions.RemoveKeyFromDID]: {
name: 'Remove Key from DID',
isVisible: canUseAnyInstruction,
packageId: PackageEnum.Identity,
},
[Instructions.AddServiceToDID]: {
name: 'Add Service to DID',
isVisible: canUseAnyInstruction,
packageId: PackageEnum.Identity,
},
[Instructions.RemoveServiceFromDID]: {
name: 'Remove Service from DID',
isVisible: canUseAnyInstruction,
packageId: PackageEnum.Identity,
},
/*
███ ██ ███████ ████████ ██████ ██ ██ ██ ██████ ██ ███ ██
████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
██ ██ ██ █████ ██ ██████ ██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ███████ ██████ ██████ ██ ██ ████
*/
[Instructions.ConfigureNftPluginCollection]: {
name: 'Configure collection',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.NftPlugin,
},
[Instructions.CreateNftPluginMaxVoterWeight]: {
name: 'Create max voter weight',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.NftPlugin,
},
[Instructions.CreateNftPluginRegistrar]: {
name: 'Create registrar',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.NftPlugin,
},
/*
███ ███ █████ ███ ██ ██████ ██████ ██ ██ ██ ██
████ ████ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ███████ ██ ██ ██ ██ ███ ██ ██ ██ ██ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ████ ██████ ██████ ████ ██
*/
[Instructions.MangoV4PerpCreate]: {
name: 'Create Perp',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4PerpEdit]: {
name: 'Edit Perp',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4OpenBookRegisterMarket]: {
name: 'Register Openbook Market',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4TokenEdit]: {
name: 'Edit Token',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4TokenRegister]: {
name: 'Register Token',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4TokenRegisterTrustless]: {
name: 'Register Trustless Token',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4GroupEdit]: {
name: 'Edit Group',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4AdminWithdrawTokenFees]: {
name: 'Withdraw Token Fees',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4WithdrawPerpFees]: {
name: 'Withdraw Perp Fees',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4OpenBookEditMarket]: {
name: 'Edit Openbook Market',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4IxGateSet]: {
name: 'Enable/Disable individual instructions in Group',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4StubOracleCreate]: {
name: 'Create Stub Oracle',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4StubOracleSet]: {
name: 'Set Stub Oracle Value',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4AltSet]: {
name: 'Set Address Lookup Table for Group',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4AltExtend]: {
name: 'Extend Address Lookup Table',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.MangoV4TokenAddBank]: {
name: 'Add additional Bank to an existing Token',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
[Instructions.IdlSetBuffer]: {
name: 'Idl Set Buffer',
packageId: PackageEnum.MangoMarketV4,
isVisible: canUseAnyInstruction,
},
/*
███ ███ ███████ █████ ███ ██ ███████ ██ ███ ██ █████ ███ ██ ██████ ███████
████ ████ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██ ██
██ ████ ██ █████ ███████ ██ ██ ██ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ███████ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██ ██ ████ ██████ ███████
*/
[Instructions.MeanCreateAccount]: {
name: 'Payment Stream: New account',
packageId: PackageEnum.MeanFinance,
},
[Instructions.MeanFundAccount]: {
name: 'Payment Stream: Fund account',
packageId: PackageEnum.MeanFinance,
},
[Instructions.MeanWithdrawFromAccount]: {
name: 'Payment Stream: Withdraw funds',
packageId: PackageEnum.MeanFinance,
},
[Instructions.MeanCreateStream]: {
name: 'Payment Stream: New stream',
packageId: PackageEnum.MeanFinance,
},
[Instructions.MeanTransferStream]: {
name: 'Payment Stream: Transfer stream',
packageId: PackageEnum.MeanFinance,
},
/*
██████ ███████ ██ ██ ███████ ██ ███ ██ █████ ███ ██ ██████ ███████
██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██ ██
██████ ███████ ████ █████ ██ ██ ██ ██ ███████ ██ ██ ██ ██ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ███████ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██████ ███████
*/
[Instructions.PsyFinanceMintAmericanOptions]: {
name: ' Mint American Options',
packageId: PackageEnum.PsyFinance,
},
[Instructions.PsyFinanceBurnWriterForQuote]: {
name: 'Claim Quote with Writer Token',
packageId: PackageEnum.PsyFinance,
},
[Instructions.PsyFinanceClaimUnderlyingPostExpiration]: {
name: 'Claim Underlying (post expiration)',
packageId: PackageEnum.PsyFinance,
},
[Instructions.PsyFinanceExerciseOption]: {
name: 'Exercise Option',
packageId: PackageEnum.PsyFinance,
},
/*
██████ ██ ██ ████████ ██ ██
██ ██ ██ ██ ██ ██ ██
██████ ████ ██ ███████
██ ██ ██ ██ ██
██ ██ ██ ██ ██
*/
[Instructions.PythRecoverAccount]: {
name: 'Recover Account',
packageId: PackageEnum.Pyth,
},
[Instructions.PythUpdatePoolAuthority]: {
name: 'Update Pool Authority',
packageId: PackageEnum.Pyth,
},
/*
███████ ███████ ██████ ██ ██ ███ ███
██ ██ ██ ██ ██ ██ ████ ████
███████ █████ ██████ ██ ██ ██ ████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ███████ ██ ██ ██████ ██ ██
*/
[Instructions.SerumGrantLockedMSRM]: {
name: 'Grant Locked MSRM',
packageId: PackageEnum.Serum,
},
[Instructions.SerumGrantLockedSRM]: {
name: 'Grant Locked SRM',
packageId: PackageEnum.Serum,
},
[Instructions.SerumGrantVestMSRM]: {
name: 'Grant Vested MSRM',
packageId: PackageEnum.Serum,
},
[Instructions.SerumGrantVestSRM]: {
name: 'Grant Vested SRM',
packageId: PackageEnum.Serum,
},
[Instructions.SerumInitUser]: {
name: 'Init User Account',
packageId: PackageEnum.Serum,
},
[Instructions.SerumUpdateGovConfigAuthority]: {
name: 'Update Governance Config Authority',
packageId: PackageEnum.Serum,
},
[Instructions.SerumUpdateGovConfigParams]: {
name: 'Update Governance Config Params',
packageId: PackageEnum.Serum,
},
/*
███████ ██████ ██ ███████ ███ ██ ██████
██ ██ ██ ██ ██ ████ ██ ██ ██
███████ ██ ██ ██ █████ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██████ ███████ ███████ ██ ████ ██████
*/
[Instructions.CreateSolendObligationAccount]: {
name: 'Create Obligation Account',
packageId: PackageEnum.Solend,
},
[Instructions.DepositReserveLiquidityAndObligationCollateral]: {
name: 'Deposit Funds',
packageId: PackageEnum.Solend,
},
[Instructions.InitSolendObligationAccount]: {
name: 'Init Obligation Account',
packageId: PackageEnum.Solend,
},
[Instructions.RefreshSolendObligation]: {
name: 'Refresh Obligation',
packageId: PackageEnum.Solend,
},
[Instructions.RefreshSolendReserve]: {
name: 'Refresh Reserve',
packageId: PackageEnum.Solend,
},
[Instructions.WithdrawObligationCollateralAndRedeemReserveLiquidity]: {
name: 'Withdraw Funds',
packageId: PackageEnum.Solend,
},
/*
███████ ██ ██ ███ ███ ███ ███ ███████ ████████ ██████ ██ ██
██ ██ ██ ████ ████ ████ ████ ██ ██ ██ ██ ██ ██
███████ ████ ██ ████ ██ ██ ████ ██ █████ ██ ██████ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██ ██
*/
[Instructions.SymmetryCreateBasket]: {
name: 'Create Basket',
packageId: PackageEnum.Symmetry,
},
[Instructions.SymmetryEditBasket]: {
name: 'Edit Basket',
packageId: PackageEnum.Symmetry,
},
[Instructions.SymmetryDeposit]: {
name: 'Deposit into Basket',
packageId: PackageEnum.Symmetry,
},
[Instructions.SymmetryWithdraw]: {
name: 'Withdraw from Basket',
packageId: PackageEnum.Symmetry,
},
/*
███████ ██████ ██ ██ █████ ██████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██ ███████ ██ ██ ███████
██ ██ ▄▄ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██████ ██████ ██ ██ ██████ ███████
*/
[Instructions.SquadsMeshAddMember]: {
name: 'Mesh Add Member',
packageId: PackageEnum.Squads,
},
[Instructions.SquadsMeshChangeThresholdMember]: {
name: 'Mesh Change Threshold',
packageId: PackageEnum.Squads,
},
[Instructions.SquadsMeshRemoveMember]: {
name: 'Mesh Remove Member',
packageId: PackageEnum.Squads,
},
/*
███████ ██ ██ ██ ████████ ██████ ██ ██ ██████ ██████ █████ ██████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██ █ ██ ██ ██ ██ ███████ ██████ ██ ██ ███████ ██████ ██ ██
██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ███ ███ ██ ██ ██████ ██ ██ ██████ ██████ ██ ██ ██ ██ ██████
*/
[Instructions.SwitchboardFundOracle]: {
name: 'Fund Oracle',
packageId: PackageEnum.Switchboard,
},
[Instructions.WithdrawFromOracle]: {
name: 'Withdraw from Oracle',
packageId: PackageEnum.Switchboard,
},
/*
██ ██ ███████ ██████ ██████ ██ ██ ██ ██████ ██ ███ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
██ ██ ███████ ██████ ██████ ██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████ ███████ ██ ██ ██ ███████ ██████ ██████ ██ ██ ████
*/
[Instructions.CreateVsrRegistrar]: {
name: 'Vote Escrowed Tokens: Create Registrar',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.VsrPlugin,
},
[Instructions.VotingMintConfig]: {
name: 'Vote Escrowed Tokens: Configure Voting Mint',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.VsrPlugin,
},
[Instructions.DistributionCloseVaults]: {
name: 'Close vaults',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.Distribution,
},
[Instructions.DistributionFillVaults]: {
name: 'Fill vaults',
isVisible: canUseAuthorityInstruction,
packageId: PackageEnum.Distribution,
},
}
const availablePackages: PackageType[] = Object.entries(packages)
.filter(([, { isVisible }]) =>
typeof isVisible === 'undefined' ? true : isVisible
)
.map(([id, infos]) => ({
id: Number(id) as PackageEnum,
...infos,
}))
const availableInstructions = Object.entries(instructionsMap)
.filter(([, { isVisible, packageId }]) => {
// do not display if the instruction's package is not visible
if (!availablePackages.some(({ id }) => id === packageId)) {
return false
}
return typeof isVisible === 'undefined' ? canUseAnyInstruction : isVisible
})
.map(([id, { name, packageId }]) => ({
id: Number(id) as Instructions,
name,
packageId,
}))
const getPackageTypeById = (packageId: PackageEnum) => {
return availablePackages.find(
(availablePackage) => availablePackage.id === packageId
)
}
return {
assetAccounts,
auxiliaryTokenAccounts,
availableInstructions,
availablePackages,
canMintRealmCouncilToken,
canUseAuthorityInstruction,
canUseMintInstruction,
canUseProgramUpgradeInstruction,
canUseTransferInstruction,
getPackageTypeById,
governancesArray,
governedNativeAccounts,
governedSPLTokenAccounts,
governedTokenAccounts,
governedTokenAccountsWithoutNfts,
}
}