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
use super::{AccountId, Balance, Balances, Runtime, RuntimeEvent, SlashTreasury};
use frame_support::{parameter_types, traits::NeverEnsureOrigin, PalletId};
use frame_system::EnsureRoot;
use sp_runtime::{traits::AccountIdConversion, Permill};

use circuit_runtime_types::UNIT as TRN;
use t3rn_primitives::{TreasuryAccount, TreasuryAccountProvider};

pub type DefaultTreasuryInstance = ();
pub type EscrowTreasuryInstance = pallet_treasury::pallet::Instance1;
pub type FeeTreasuryInstance = pallet_treasury::pallet::Instance2;
pub type ParachainTreasuryInstance = pallet_treasury::pallet::Instance3;
pub type SlashTreasuryInstance = pallet_treasury::pallet::Instance4;

// Treasury#1 - default Treasury
parameter_types! {
    pub const TreasuryId: PalletId = PalletId(*b"pottrsry");
    pub const MaxApprovals: u32 = 10;
    pub const ProposalBond: Permill = Permill::from_percent(5);
    pub const SpendPeriod: u32 = 7 * 24 * 60 * 60;
    pub const ProposalBondMinimum: Balance = 100 * (TRN as Balance);
}

impl pallet_treasury::Config<DefaultTreasuryInstance> for Runtime {
    type ApproveOrigin = EnsureRoot<AccountId>;
    type Burn = ();
    type BurnDestination = ();
    type Currency = Balances;
    type MaxApprovals = MaxApprovals;
    type OnSlash = SlashTreasury;
    type PalletId = TreasuryId;
    type ProposalBond = ProposalBond;
    type ProposalBondMaximum = ();
    type ProposalBondMinimum = ProposalBondMinimum;
    type RejectOrigin = EnsureRoot<AccountId>;
    type RuntimeEvent = RuntimeEvent;
    type SpendFunds = ();
    type SpendOrigin = NeverEnsureOrigin<Balance>;
    type SpendPeriod = SpendPeriod;
    type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

// Treasury#2 - EscrowTreasury
parameter_types! {
    pub const EscrowTreasuryId: PalletId = PalletId(*b"escrowry");
}

impl pallet_treasury::Config<EscrowTreasuryInstance> for Runtime {
    type ApproveOrigin = EnsureRoot<AccountId>;
    type Burn = ();
    type BurnDestination = ();
    type Currency = Balances;
    type MaxApprovals = MaxApprovals;
    type OnSlash = SlashTreasury;
    type PalletId = EscrowTreasuryId;
    type ProposalBond = ProposalBond;
    type ProposalBondMaximum = ();
    type ProposalBondMinimum = ProposalBondMinimum;
    type RejectOrigin = EnsureRoot<AccountId>;
    type RuntimeEvent = RuntimeEvent;
    type SpendFunds = ();
    type SpendOrigin = NeverEnsureOrigin<Balance>;
    type SpendPeriod = SpendPeriod;
    type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

// Treasury#3 - FeeTreasury
parameter_types! {
    pub const FeeTreasuryId: PalletId = PalletId(*b"feetrsry");
}

impl pallet_treasury::Config<FeeTreasuryInstance> for Runtime {
    type ApproveOrigin = EnsureRoot<AccountId>;
    type Burn = ();
    type BurnDestination = ();
    type Currency = Balances;
    type MaxApprovals = MaxApprovals;
    type OnSlash = SlashTreasury;
    type PalletId = FeeTreasuryId;
    type ProposalBond = ProposalBond;
    type ProposalBondMaximum = ();
    type ProposalBondMinimum = ProposalBondMinimum;
    type RejectOrigin = EnsureRoot<AccountId>;
    type RuntimeEvent = RuntimeEvent;
    type SpendFunds = ();
    type SpendOrigin = NeverEnsureOrigin<Balance>;
    type SpendPeriod = SpendPeriod;
    type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

// Treasury#4 - ParachainTreasury
parameter_types! {
    pub const ParachainTreasuryId: PalletId = PalletId(*b"partrsry");
}

impl pallet_treasury::Config<ParachainTreasuryInstance> for Runtime {
    type ApproveOrigin = EnsureRoot<AccountId>;
    type Burn = ();
    type BurnDestination = ();
    type Currency = Balances;
    type MaxApprovals = MaxApprovals;
    type OnSlash = SlashTreasury;
    type PalletId = ParachainTreasuryId;
    type ProposalBond = ProposalBond;
    type ProposalBondMaximum = ();
    type ProposalBondMinimum = ProposalBondMinimum;
    type RejectOrigin = EnsureRoot<AccountId>;
    type RuntimeEvent = RuntimeEvent;
    type SpendFunds = ();
    type SpendOrigin = NeverEnsureOrigin<Balance>;
    type SpendPeriod = SpendPeriod;
    type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

// Treasury#5 - SlashTreasury
parameter_types! {
    pub const SlashTreasuryId: PalletId = PalletId(*b"slhtrsry");
}

impl pallet_treasury::Config<SlashTreasuryInstance> for Runtime {
    type ApproveOrigin = EnsureRoot<AccountId>;
    type Burn = ();
    type BurnDestination = ();
    type Currency = Balances;
    type MaxApprovals = MaxApprovals;
    type OnSlash = SlashTreasury;
    type PalletId = SlashTreasuryId;
    type ProposalBond = ProposalBond;
    type ProposalBondMaximum = ();
    type ProposalBondMinimum = ProposalBondMinimum;
    type RejectOrigin = EnsureRoot<AccountId>;
    type RuntimeEvent = RuntimeEvent;
    type SpendFunds = ();
    type SpendOrigin = NeverEnsureOrigin<Balance>;
    type SpendPeriod = SpendPeriod;
    type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

impl TreasuryAccountProvider<AccountId> for Runtime {
    fn get_treasury_account(treasury_account: TreasuryAccount) -> AccountId {
        match treasury_account {
            TreasuryAccount::Treasury => TreasuryId::get().into_account_truncating(),
            TreasuryAccount::Escrow => EscrowTreasuryId::get().into_account_truncating(),
            TreasuryAccount::Fee => FeeTreasuryId::get().into_account_truncating(),
            TreasuryAccount::Parachain => ParachainTreasuryId::get().into_account_truncating(),
            TreasuryAccount::Slash => SlashTreasuryId::get().into_account_truncating(),
        }
    }
}