Skip to content

Commit 880b31b

Browse files
authored
Merge pull request #107 from tinymanorg/fix/governance-global-state-parser
Fix type references while reading from global state
2 parents 37c97df + af95806 commit 880b31b

File tree

8 files changed

+50
-41
lines changed

8 files changed

+50
-41
lines changed

dist/governance/proposal-voting/storage.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export declare class ProposalVotingAppGlobalState {
3131
approvalRequirement: number;
3232
manager: string;
3333
proposalManager: Uint8Array;
34-
constructor(vaultAppId: number, proposalIndexCounter: number, votingDelay: number, votingDuration: number, proposalThreshold: number, proposalThresholdNumerator: number, quorumThreshold: number, approvalRequirement: number, manager: string, proposalManager: Uint8Array);
34+
constructor(vaultAppId: bigint, proposalIndexCounter: bigint, votingDelay: bigint, votingDuration: bigint, proposalThreshold: bigint, proposalThresholdNumerator: bigint, quorumThreshold: bigint, approvalRequirement: bigint, manager: string, proposalManager: Uint8Array);
3535
}
3636
export declare function getProposalBoxName(proposalId: string): Uint8Array;
3737
export declare function getAttendanceSheetBoxName(address: string, boxIndex: number): Uint8Array;

dist/governance/vault/storage.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ declare class SlopeChange {
3030
constructor(slopeDelta?: number);
3131
}
3232
declare class VaultAppGlobalState {
33+
totalLockedAmount: bigint;
34+
totalPowerCount: bigint;
3335
tinyAssetId: number;
34-
totalLockedAmount: number;
35-
totalPowerCount: number;
3636
lastTotalPowerTimestamp: number;
37-
constructor(tinyAssetId: number, totalLockedAmount: number, totalPowerCount: number, lastTotalPowerTimestamp: number);
37+
constructor(totalLockedAmount: bigint, totalPowerCount: bigint, lastTotalPowerTimestamp: bigint, tinyAssetId: bigint);
3838
get freeTotalPowerSpaceCount(): number;
3939
get lastTotalPowerBoxIndex(): number;
4040
get lastTotalPowerArrayIndex(): number;
4141
}
4242
declare function getAccountState(algodClient: Algodv2, appId: number, address: string): Promise<AccountState | null>;
4343
declare function getAccountStateBoxName(address: string): Uint8Array;
4444
declare function getTotalPowerBoxName(boxIndex: number): Uint8Array;
45-
declare function getLastAccountPowerBoxIndexes(powerCount: number): [number, number];
45+
declare function getLastAccountPowerBoxIndexes(powerCount: bigint): [number, number];
4646
declare function getAccountPowerBoxName(address: string, boxIndex: number): Uint8Array;
4747
declare function getSlopeChange(algod: Algodv2, appId: number, timeStamp: number): Promise<SlopeChange | null>;
4848
declare function getSlopeChangeBoxName(timestamp: number): Uint8Array;
49-
declare function getAllTotalPowers(algodClient: Algodv2, appId: number, totalPowerCount: number): Promise<TotalPower[]>;
49+
declare function getAllTotalPowers(algodClient: Algodv2, appId: number, totalPowerCount: bigint): Promise<TotalPower[]>;
5050
declare function getAccountPowers({ algodClient, address, appId, powerCount }: {
5151
algodClient: Algodv2;
5252
address: string;

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tinymanorg/tinyman-js-sdk",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "Tinyman JS SDK",
55
"author": "Tinyman Core Team",
66
"license": "MIT",

src/governance/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class TinymanGovernanceClient {
375375
});
376376

377377
accountState.powerCount += 1;
378-
vaultAppGlobalState.totalPowerCount += 1;
378+
vaultAppGlobalState.totalPowerCount += 1n;
379379

380380
const slopeChangeAtNewLockEndTime = await getSlopeChange(
381381
this.algodClient,

src/governance/proposal-voting/storage.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,25 @@ export class ProposalVotingAppGlobalState {
8282

8383
// eslint-disable-next-line max-params
8484
constructor(
85-
vaultAppId: number,
86-
proposalIndexCounter: number,
87-
votingDelay: number,
88-
votingDuration: number,
89-
proposalThreshold: number,
90-
proposalThresholdNumerator: number,
91-
quorumThreshold: number,
92-
approvalRequirement: number,
85+
vaultAppId: bigint,
86+
proposalIndexCounter: bigint,
87+
votingDelay: bigint,
88+
votingDuration: bigint,
89+
proposalThreshold: bigint,
90+
proposalThresholdNumerator: bigint,
91+
quorumThreshold: bigint,
92+
approvalRequirement: bigint,
9393
manager: string,
9494
proposalManager: Uint8Array
9595
) {
96-
this.vaultAppId = vaultAppId;
97-
this.proposalIndexCounter = proposalIndexCounter;
98-
this.votingDelay = votingDelay;
99-
this.votingDuration = votingDuration;
100-
this.proposalThreshold = proposalThreshold;
101-
this.proposalThresholdNumerator = proposalThresholdNumerator;
102-
this.quorumThreshold = quorumThreshold;
103-
this.approvalRequirement = approvalRequirement;
96+
this.vaultAppId = Number(vaultAppId);
97+
this.proposalIndexCounter = Number(proposalIndexCounter);
98+
this.votingDelay = Number(votingDelay);
99+
this.votingDuration = Number(votingDuration);
100+
this.proposalThreshold = Number(proposalThreshold);
101+
this.proposalThresholdNumerator = Number(proposalThresholdNumerator);
102+
this.quorumThreshold = Number(quorumThreshold);
103+
this.approvalRequirement = Number(approvalRequirement);
104104
this.manager = manager;
105105
this.proposalManager = proposalManager;
106106
}

src/governance/vault/storage.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class AccountState {
4040
}
4141

4242
get lastAccountPowerBoxIndex() {
43-
return getLastAccountPowerBoxIndexes(this.powerCount)[0];
43+
return getLastAccountPowerBoxIndexes(BigInt(this.powerCount))[0];
4444
}
4545

4646
get lastAccountPowerArrayIndex() {
47-
return getLastAccountPowerBoxIndexes(this.powerCount)[1];
47+
return getLastAccountPowerBoxIndexes(BigInt(this.powerCount))[1];
4848
}
4949
}
5050

@@ -103,16 +103,22 @@ class SlopeChange {
103103
}
104104

105105
class VaultAppGlobalState {
106+
tinyAssetId: number;
107+
lastTotalPowerTimestamp: number;
108+
106109
// eslint-disable-next-line no-useless-constructor
107110
constructor(
108-
public tinyAssetId: number,
109-
public totalLockedAmount: number,
110-
public totalPowerCount: number,
111-
public lastTotalPowerTimestamp: number
112-
) {}
111+
public totalLockedAmount: bigint,
112+
public totalPowerCount: bigint,
113+
lastTotalPowerTimestamp: bigint,
114+
tinyAssetId: bigint
115+
) {
116+
this.lastTotalPowerTimestamp = Number(lastTotalPowerTimestamp);
117+
this.tinyAssetId = Number(tinyAssetId);
118+
}
113119

114120
get freeTotalPowerSpaceCount() {
115-
const remainder = this.totalPowerCount % ACCOUNT_POWER_BOX_ARRAY_LEN;
121+
const remainder = Number(this.totalPowerCount % BigInt(ACCOUNT_POWER_BOX_ARRAY_LEN));
116122

117123
return remainder > 0 ? ACCOUNT_POWER_BOX_ARRAY_LEN - remainder : 0;
118124
}
@@ -168,10 +174,10 @@ function getTotalPowerBoxName(boxIndex: number): Uint8Array {
168174
return combinedArray;
169175
}
170176

171-
function getLastAccountPowerBoxIndexes(powerCount: number): [number, number] {
172-
const lastIndex = powerCount - 1;
173-
const boxIndex = Math.floor(lastIndex / ACCOUNT_POWER_BOX_ARRAY_LEN);
174-
const arrayIndex = lastIndex % ACCOUNT_POWER_BOX_ARRAY_LEN;
177+
function getLastAccountPowerBoxIndexes(powerCount: bigint): [number, number] {
178+
const lastIndex = powerCount - 1n;
179+
const boxIndex = Number(lastIndex / BigInt(ACCOUNT_POWER_BOX_ARRAY_LEN));
180+
const arrayIndex = Number(lastIndex % BigInt(ACCOUNT_POWER_BOX_ARRAY_LEN));
175181

176182
return [boxIndex, arrayIndex];
177183
}
@@ -213,12 +219,15 @@ function getSlopeChangeBoxName(timestamp: number) {
213219
async function getAllTotalPowers(
214220
algodClient: Algodv2,
215221
appId: number,
216-
totalPowerCount: number
222+
totalPowerCount: bigint
217223
): Promise<TotalPower[]> {
218224
let boxCount = 0;
219225

220226
if (totalPowerCount) {
221-
boxCount = Math.ceil(totalPowerCount / ACCOUNT_POWER_BOX_ARRAY_LEN);
227+
boxCount = Number(
228+
(totalPowerCount + BigInt(ACCOUNT_POWER_BOX_ARRAY_LEN - 1)) /
229+
BigInt(ACCOUNT_POWER_BOX_ARRAY_LEN)
230+
);
222231
}
223232

224233
const totalPowers: TotalPower[] = [];

0 commit comments

Comments
 (0)