• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 13115350420

03 Feb 2025 02:09PM UTC coverage: 72.123% (-5.4%) from 77.499%
13115350420

push

github

BifrostTitan
Updated Governance program -- Example uses legacy mango markets DAO

1118 of 1754 branches covered (63.74%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 6 files covered. (0.0%)

5130 of 6909 relevant lines covered (74.25%)

1222547.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Solnet.Programs/Governance/Models/ProposalV1.cs
1
using Solnet.Programs.Governance.Enums;
2
using Solnet.Programs.Utilities;
3
using System;
4
using System.Collections.Generic;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8

9
namespace Solnet.Programs.Governance.Models
10
{
11
    /// <summary>
12
    /// Governance Proposal v1 
13
    /// </summary>
14
    public class ProposalV1 : Proposal
15
    {
16
        /// <summary>
17
        /// Additional layout info for <see cref="ProposalV1"/>
18
        /// </summary>
19
        public static class AdditionalLayout
20
        {
21
            /// <summary>
22
            /// The offset at which the yes votes count value begins.
23
            /// </summary>
24
            public const int YesVotesCountOffset = 100;
25

26
            /// <summary>
27
            /// The offset at which the no votes count value begins.
28
            /// </summary>
29
            public const int NoVotesCountOffset = 108;
30

31
            /// <summary>
32
            /// The offset at which the instructions executed count value begins.
33
            /// </summary>
34
            public const int InstructionsExecutedCountOffset = 116;
35

36
            /// <summary>
37
            /// The offset at which the instructions count value begins.
38
            /// </summary>
39
            public const int InstructionsCountOffset = 118;
40

41
            /// <summary>
42
            /// The offset at which the instructions next index value begins.
43
            /// </summary>
44
            public const int InstructionsNextIndexOffset = 120;
45

46
            /// <summary>
47
            /// The offset at which the draft at timestamp value begins.
48
            /// </summary>
49
            public const int DraftAtOffset = 122;
50
        }
51

52
        /// <summary>
53
        /// The number of Yes votes
54
        /// </summary>
55
        public ulong YesVotesCount;
56

57
        /// <summary>
58
        /// The number of No votes
59
        /// </summary>
60
        public ulong NoVotesCount;
61

62
        /// <summary>
63
        /// The number of the instructions already executed
64
        /// </summary>
65
        public ushort InstructionsExecutedCount;
66

67
        /// <summary>
68
        /// The number of instructions included in the option
69
        /// </summary>
70
        public ushort InstructionsCount;
71

72
        /// <summary>
73
        /// The index of the the next instruction to be added
74
        /// </summary>
75
        public ushort InstructionsNextIndex;
76

77
        /// <summary>
78
        /// Deserialize the data into the <see cref="ProposalV1"/> structure.
79
        /// </summary>
80
        /// <param name="data">The data to deserialize.</param>
81
        /// <returns>The <see cref="ProposalV1"/>.</returns>
82
        public static ProposalV1 Deserialize(byte[] data)
83
        {
84
            ReadOnlySpan<byte> span = data.AsSpan();
×
85

86
            int offset = AdditionalLayout.DraftAtOffset + sizeof(ulong);
×
87
            bool signingOffAtTimestampExists = span.GetBool(offset);
×
88
            ulong signingOffAtTimestamp = 0;
×
89
            offset += sizeof(byte);
×
90
            if (signingOffAtTimestampExists)
×
91
            {
92
                signingOffAtTimestamp = span.GetU64(offset);
×
93
                offset += sizeof(ulong);
×
94
            }
95

96
            bool votingAtTimestampExists = span.GetBool(offset);
×
97
            ulong votingAtTimestamp = 0;
×
98
            offset += sizeof(byte);
×
99
            if (votingAtTimestampExists)
×
100
            {
101
                votingAtTimestamp = span.GetU64(offset);
×
102
                offset += sizeof(ulong);
×
103
            }
104

105
            bool votingAtSlotExists = span.GetBool(offset);
×
106
            ulong votingAtSlot = 0;
×
107
            offset += sizeof(byte);
×
108
            if (votingAtSlotExists)
×
109
            {
110
                votingAtSlot = span.GetU64(offset);
×
111
                offset += sizeof(ulong);
×
112
            }
113

114
            bool votingCompletedAtTimestampExists = span.GetBool(offset);
×
115
            ulong votingCompletedAtTimestamp = 0;
×
116
            offset += sizeof(byte);
×
117
            if (votingCompletedAtTimestampExists)
×
118
            {
119
                votingCompletedAtTimestamp = span.GetU64(offset);
×
120
                offset += sizeof(ulong);
×
121
            }
122

123
            bool executingAtTimestampExists = span.GetBool(offset);
×
124
            ulong executingAtTimestamp = 0;
×
125
            offset += sizeof(byte);
×
126
            if (executingAtTimestampExists)
×
127
            {
128
                executingAtTimestamp = span.GetU64(offset);
×
129
                offset += sizeof(ulong);
×
130
            }
131

132
            bool closedAtTimestampExists = span.GetBool(offset);
×
133
            ulong closedAtTimestamp = 0;
×
134
            offset += sizeof(byte);
×
135
            if (closedAtTimestampExists)
×
136
            {
137
                closedAtTimestamp = span.GetU64(offset);
×
138
                offset += sizeof(ulong);
×
139
            }
140

141
            InstructionExecutionFlags ixExecutionFlags = (InstructionExecutionFlags)Enum.Parse(typeof(InstructionExecutionFlags), span.GetU8(offset).ToString());
×
142
            offset += sizeof(byte);
×
143

144
            bool maxVoteWeightExists = span.GetBool(offset);
×
145
            ulong maxVoteWeight = 0;
×
146
            offset += sizeof(byte);
×
147
            if (maxVoteWeightExists)
×
148
            {
149
                maxVoteWeight = span.GetU64(offset);
×
150
                offset += sizeof(ulong);
×
151
            }
152

153
            bool voteThresholdPercentageTypeExists = span.GetBool(offset);
×
154
            VoteThresholdPercentage voteThresholdPercentageType = Enums.VoteThresholdPercentage.YesVote;
×
155
            byte voteThresholdPercentage = 0;
×
156
            offset += sizeof(byte);
×
157
            if (voteThresholdPercentageTypeExists)
×
158
            {
159
                voteThresholdPercentageType = (VoteThresholdPercentage)Enum.Parse(typeof(VoteThresholdPercentage), span.GetU8(offset).ToString());
×
160
                offset += sizeof(byte);
×
161
                voteThresholdPercentage = span.GetU8(offset);
×
162
                offset += sizeof(byte);
×
163
            }
164

NEW
165
            int nameLength = span.GetBorshString(offset, out string name);
×
NEW
166
            _ = span.GetBorshString(offset + nameLength, out string descriptionLink);
×
167

168
            return new ProposalV1
×
169
            {
×
170
                AccountType = (GovernanceAccountType)Enum.Parse(typeof(GovernanceAccountType), span.GetU8(Layout.AccountTypeOffset).ToString()),
×
171
                Governance = span.GetPubKey(ExtraLayout.GovernanceOffset),
×
172
                GoverningTokenMint = span.GetPubKey(ExtraLayout.GoverningTokenMintOffset),
×
173
                State = (ProposalState)Enum.Parse(typeof(ProposalState), span.GetU8(ExtraLayout.StateOffset).ToString()),
×
174
                TokenOwnerRecord = span.GetPubKey(ExtraLayout.TokenOwnerRecordOffset),
×
175
                SignatoriesCount = span.GetU8(ExtraLayout.SignatoriesOffset),
×
176
                SignatoriesSignedOffCount = span.GetU8(ExtraLayout.SignatoriesSignedOffOffset),
×
177
                YesVotesCount = span.GetU64(AdditionalLayout.YesVotesCountOffset),
×
178
                NoVotesCount = span.GetU64(AdditionalLayout.NoVotesCountOffset),
×
179
                InstructionsExecutedCount = span.GetU16(AdditionalLayout.InstructionsExecutedCountOffset),
×
180
                InstructionsCount = span.GetU16(AdditionalLayout.InstructionsCountOffset),
×
181
                InstructionsNextIndex = span.GetU16(AdditionalLayout.InstructionsNextIndexOffset),
×
182
                DraftAt = span.GetU64(AdditionalLayout.DraftAtOffset),
×
183
                SigningOffAt = signingOffAtTimestamp,
×
184
                VotingAt = votingAtTimestamp,
×
185
                VotingAtSlot = votingAtSlot,
×
186
                VotingCompletedAt = votingCompletedAtTimestamp,
×
187
                ExecutingAt = executingAtTimestamp,
×
188
                ClosedAt = closedAtTimestamp,
×
189
                InstructionExecutionFlags = ixExecutionFlags,
×
190
                MaxVoteWeight = maxVoteWeight,
×
191
                VoteThresholdPercentageType = voteThresholdPercentageType,
×
192
                VoteThresholdPercentage = voteThresholdPercentage,
×
193
                Name = name,
×
194
                DescriptionLink = descriptionLink
×
195
            };
×
196
        }
197
    }
198
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc