Skip to content

Commit

Permalink
Merge pull request #87 from tinymanorg/feat/tiny-1625-governance
Browse files Browse the repository at this point in the history
Add governance functions
  • Loading branch information
gulcinuras authored Jul 29, 2024
2 parents 626835d + dac1320 commit 312c268
Show file tree
Hide file tree
Showing 48 changed files with 3,732 additions and 10 deletions.
72 changes: 72 additions & 0 deletions dist/governance/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import AlgodClient from "algosdk/dist/types/client/v2/algod/algod";
import { SuggestedParams, Transaction } from "algosdk";
import { VaultAppGlobalState } from "./vault/storage";
import { RewardsAppGlobalState } from "./rewards/storage";
import { ProposalVotingAppGlobalState } from "./proposal-voting/storage";
import { ProposalVote } from "./proposal-voting/constants";
import { GetRawBoxValueCacheProps } from "./types";
import { SupportedNetwork } from "../util/commonTypes";
declare class TinymanGovernanceClient {
private algodClient;
private userAddress;
private network;
constructor(algodClient: AlgodClient, userAddress: string, network: SupportedNetwork);
getTinyPower(timeStamp?: number, cacheProps?: GetRawBoxValueCacheProps): Promise<number>;
getTotalTinyPower(timeStamp?: number, cacheProps?: GetRawBoxValueCacheProps): Promise<number>;
getCumulativeTinyPower(cacheProps?: GetRawBoxValueCacheProps, timeStamp?: number): Promise<number>;
fetchVaultAppGlobalState(): Promise<VaultAppGlobalState | null>;
generateCreateLockTransactions({ lockedAmount, lockEndTime, userAddress }: {
lockedAmount: number;
lockEndTime: number;
userAddress?: string;
}): Promise<Transaction[]>;
generateIncreaseLockAmountTransactions({ lockedAmount, userAddress }: {
lockedAmount: number;
userAddress?: string;
}): Promise<Transaction[]>;
generateExtendLockTimeTransactions({ newLockEndTime, userAddress }: {
newLockEndTime: number;
userAddress?: string;
}): Promise<Transaction[]>;
generateIncreaseLockAmountAndExtendLockEndTimeTransactions({ lockAmount, lockEndTime, userAddress }: {
lockAmount: number;
lockEndTime: number;
userAddress?: string;
}): Promise<Transaction[]>;
generateWithdrawTransactions(userAddress?: string, shouldOptIntoTINY?: boolean): Promise<Transaction[]>;
fetchAccountState(): Promise<import("./vault/storage").AccountState | null>;
fetchStakingDistributionProposal(proposalId: string): Promise<import("./staking-voting/storage").StakingDistributionProposal | null>;
generateCastVoteForStakingDistributionProposalTransactions({ proposalId, votes, assetIds, userAddress, suggestedParams }: {
proposalId: string;
votes: number[];
assetIds: number[];
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
fetchRewardsAppGlobalState(): Promise<RewardsAppGlobalState | null>;
generateClaimRewardTransactions({ periodIndexStart, periodCount, userAddress, suggestedParams, shouldOptIntoTINY }: {
periodIndexStart: number;
periodCount: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
shouldOptIntoTINY?: boolean;
}): Promise<Transaction[]>;
fetchProposal(proposalId: string): Promise<import("./proposal-voting/storage").Proposal | null>;
uploadProposalMetadata(proposalId: string, metadata: any): Promise<Response>;
generateCreateProposalTransactions({ proposalId, userAddress, suggestedParams, executionHash, executor }: {
proposalId: string;
userAddress?: string;
suggestedParams?: SuggestedParams;
executionHash?: string;
executor?: string;
}): Promise<Transaction[]>;
generateCastVoteTransactions({ proposalId, suggestedParams, vote, userAddress }: {
proposalId: string;
vote: ProposalVote;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
fetchProposalVotingAppGlobalState(): Promise<ProposalVotingAppGlobalState>;
getRequiredTinyPowerToCreateProposal(): Promise<number>;
}
export { TinymanGovernanceClient };
16 changes: 16 additions & 0 deletions dist/governance/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SupportedNetwork } from "../util/commonTypes";
declare const HOUR_IN_S: number;
declare const DAY_IN_S: number;
declare const WEEK_IN_S: number;
declare const VAULT_APP_ID: Record<SupportedNetwork, number>;
declare const STAKING_VOTING_APP_ID: Record<SupportedNetwork, number>;
declare const REWARDS_APP_ID: Record<SupportedNetwork, number>;
declare const PROPOSAL_VOTING_APP_ID: Record<SupportedNetwork, number>;
declare const BOX_FLAT_MIN_BALANCE = 2500;
declare const BOX_BYTE_MIN_BALANCE = 400;
declare const HOUR: number;
declare const DAY: number;
declare const WEEK: number;
export { HOUR, DAY, WEEK };
declare const TWO_TO_THE_64: number;
export { VAULT_APP_ID, STAKING_VOTING_APP_ID, REWARDS_APP_ID, BOX_BYTE_MIN_BALANCE, BOX_FLAT_MIN_BALANCE, TWO_TO_THE_64, WEEK_IN_S, DAY_IN_S, HOUR_IN_S, PROPOSAL_VOTING_APP_ID };
76 changes: 76 additions & 0 deletions dist/governance/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import AlgodClient from "algosdk/dist/types/client/v2/algod/algod";
import { SuggestedParams, Transaction } from "algosdk";
import { VaultAppGlobalState } from "./vault/storage";
import { RewardsAppGlobalState } from "./rewards/storage";
import { ProposalVotingAppGlobalState } from "./proposal-voting/storage";
import { ProposalVote } from "./proposal-voting/constants";
import { GetRawBoxValueCacheProps } from "./types";
import { SupportedNetwork } from "../util/commonTypes";
declare class TinymanGovernanceClient {
private algodClient;
private userAddress;
private network;
constructor(algodClient: AlgodClient, userAddress: string, network: SupportedNetwork);
getTinyPower(timeStamp?: number, cacheProps?: GetRawBoxValueCacheProps): Promise<number>;
getTotalTinyPower(timeStamp?: number, cacheProps?: GetRawBoxValueCacheProps): Promise<number>;
getCumulativeTinyPower(cacheProps?: GetRawBoxValueCacheProps, timeStamp?: number): Promise<number>;
fetchVaultAppGlobalState(): Promise<VaultAppGlobalState | null>;
generateCreateLockTransactions({ lockedAmount, lockEndTime, userAddress, suggestedParams }: {
lockedAmount: number;
lockEndTime: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
generateIncreaseLockAmountTransactions({ lockedAmount, userAddress, suggestedParams }: {
lockedAmount: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
generateExtendLockTimeTransactions({ newLockEndTime, userAddress, suggestedParams }: {
newLockEndTime: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
generateIncreaseLockAmountAndExtendLockEndTimeTransactions({ lockAmount, lockEndTime, userAddress, suggestedParams }: {
lockAmount: number;
lockEndTime: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
generateWithdrawTransactions(userAddress?: string, shouldOptIntoTINY?: boolean, suggestedParams?: SuggestedParams): Promise<Transaction[]>;
fetchAccountState(): Promise<import("./vault/storage").AccountState | null>;
fetchStakingDistributionProposal(proposalId: string): Promise<import("./staking-voting/storage").StakingDistributionProposal | null>;
generateCastVoteForStakingDistributionProposalTransactions({ proposalId, votes, assetIds, userAddress, suggestedParams }: {
proposalId: string;
votes: number[];
assetIds: number[];
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
fetchRewardsAppGlobalState(): Promise<RewardsAppGlobalState | null>;
generateClaimRewardTransactions({ periodIndexStart, periodCount, userAddress, suggestedParams, shouldOptIntoTINY }: {
periodIndexStart: number;
periodCount: number;
userAddress?: string;
suggestedParams?: SuggestedParams;
shouldOptIntoTINY?: boolean;
}): Promise<Transaction[]>;
fetchProposal(proposalId: string): Promise<import("./proposal-voting/storage").Proposal | null>;
uploadProposalMetadata(proposalId: string, metadata: any): Promise<Response>;
generateCreateProposalTransactions({ proposalId, userAddress, suggestedParams, executionHash, executor }: {
proposalId: string;
userAddress?: string;
suggestedParams?: SuggestedParams;
executionHash?: string;
executor?: string;
}): Promise<Transaction[]>;
generateCastVoteTransactions({ proposalId, suggestedParams, vote, userAddress }: {
proposalId: string;
vote: ProposalVote;
userAddress?: string;
suggestedParams?: SuggestedParams;
}): Promise<Transaction[]>;
fetchProposalVotingAppGlobalState(): Promise<ProposalVotingAppGlobalState>;
getRequiredTinyPowerToCreateProposal(): Promise<number>;
}
export { TinymanGovernanceClient };
15 changes: 15 additions & 0 deletions dist/governance/proposal-voting/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare const PROPOSAL_BOX_PREFIX: Uint8Array;
declare const ATTENDANCE_SHEET_BOX_PREFIX: Uint8Array;
declare const ACCOUNT_ATTENDANCE_SHEET_BOX_SIZE = 24;
declare const PROPOSAL_BOX_SIZE: number;
declare const PROPOSAL_BOX_COST: number;
declare const ATTENDANCE_SHEET_BOX_COST: number;
declare enum ProposalVote {
Against = 0,
For = 1,
Abstain = 2
}
declare const EXECUTION_HASH_SIZE = 34;
declare const CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT: Uint8Array;
declare const EXECUTOR_FALLBACK_ADDRESS = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";
export { PROPOSAL_BOX_PREFIX, PROPOSAL_BOX_SIZE, PROPOSAL_BOX_COST, ProposalVote, ACCOUNT_ATTENDANCE_SHEET_BOX_SIZE, ATTENDANCE_SHEET_BOX_PREFIX, ATTENDANCE_SHEET_BOX_COST, EXECUTION_HASH_SIZE, CREATE_PROPOSAL_DEFAULT_EXECUTION_HASH_ARGUMENT, EXECUTOR_FALLBACK_ADDRESS };
38 changes: 38 additions & 0 deletions dist/governance/proposal-voting/storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import AlgodClient from "algosdk/dist/types/client/v2/algod/algod";
export declare class Proposal {
index: number;
creationTimestamp: number;
votingStartTimestamp: number;
votingEndTimestamp: number;
snapshotTotalVotingPower: number;
voteCount: number;
quorumNumerator: number;
againstVotingPower: number;
forVotingPower: number;
abstainVotingPower: number;
isApproved: boolean;
isCancelled: boolean;
isExecuted: boolean;
isQuorumReached: boolean;
proposerAddress: string;
executionHash: string;
executorAddress: string;
constructor(index: number, creationTimestamp: number, votingStartTimestamp: number, votingEndTimestamp: number, snapshotTotalVotingPower: number, voteCount: number, quorumNumerator: number, againstVotingPower: number, forVotingPower: number, abstainVotingPower: number, isApproved: boolean, isCancelled: boolean, isExecuted: boolean, isQuorumReached: boolean, proposerAddress: string, executionHash: string, executorAddress: string);
get snapshotTimestamp(): number;
}
export declare class ProposalVotingAppGlobalState {
vaultAppId: number;
proposalIndexCounter: number;
votingDelay: number;
votingDuration: number;
proposalThreshold: number;
proposalThresholdNumerator: number;
quorumThreshold: number;
approvalRequirement: number;
manager: string;
proposalManager: Uint8Array;
constructor(vaultAppId: number, proposalIndexCounter: number, votingDelay: number, votingDuration: number, proposalThreshold: number, proposalThresholdNumerator: number, quorumThreshold: number, approvalRequirement: number, manager: string, proposalManager: Uint8Array);
}
export declare function getProposalBoxName(proposalId: string): Uint8Array;
export declare function getAttendanceSheetBoxName(address: string, boxIndex: number): Uint8Array;
export declare function getProposal(client: AlgodClient, appId: number, proposalId: string): Promise<Proposal | null>;
35 changes: 35 additions & 0 deletions dist/governance/proposal-voting/transactions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import algosdk, { SuggestedParams } from "algosdk";
import { VaultAppGlobalState } from "../vault/storage";
import { ProposalVote } from "./constants";
import { Proposal } from "./storage";
import { GenerateProposalMetadataPayload } from "./types";
export declare function generateProposalMetadata({ category, description, discussionUrl, pollUrl, title }: GenerateProposalMetadataPayload): {
category: string;
description: string;
discussion_url: string;
poll_url: string;
title: string;
};
export declare function prepareCreateProposalTransactions({ proposalId, proposalVotingAppId, sender, vaultAppId, vaultAppGlobalState, executionHash, executor, suggestedParams, appCallNote }: {
proposalVotingAppId: number;
sender: string;
proposalId: string;
vaultAppId: number;
vaultAppGlobalState: VaultAppGlobalState;
executionHash?: string;
executor?: Uint8Array;
suggestedParams: SuggestedParams;
appCallNote?: string;
}): algosdk.Transaction[];
export declare function prepareCastVoteTransactions({ accountPowerIndex, createAttendanceSheetBox, proposal, proposalId, proposalVotingAppId, sender, suggestedParams, vaultAppId, vote, appCallNote }: {
proposalVotingAppId: number;
vaultAppId: number;
sender: string;
proposalId: string;
proposal: Proposal;
vote: ProposalVote;
accountPowerIndex: number;
createAttendanceSheetBox: boolean;
suggestedParams: SuggestedParams;
appCallNote?: string;
}): algosdk.Transaction[];
8 changes: 8 additions & 0 deletions dist/governance/proposal-voting/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface GenerateProposalMetadataPayload {
title: string;
description: string;
category: string;
discussionUrl: string;
pollUrl: string;
}
export type { GenerateProposalMetadataPayload };
8 changes: 8 additions & 0 deletions dist/governance/rewards/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const REWARD_PERIOD_BOX_PREFIX: Uint8Array;
declare const REWARD_CLAIM_SHEET_BOX_SIZE = 1012;
declare const REWARD_CLAIM_SHEET_BOX_PREFIX: Uint8Array;
declare const REWARD_PERIOD_SIZE = 24;
declare const REWARD_PERIOD_BOX_SIZE = 1008;
declare const REWARD_PERIOD_BOX_ARRAY_LEN = 42;
declare const REWARD_CLAIM_SHEET_BOX_COST: number;
export { REWARD_CLAIM_SHEET_BOX_PREFIX, REWARD_PERIOD_BOX_PREFIX, REWARD_CLAIM_SHEET_BOX_SIZE, REWARD_PERIOD_SIZE, REWARD_PERIOD_BOX_ARRAY_LEN, REWARD_PERIOD_BOX_SIZE, REWARD_CLAIM_SHEET_BOX_COST };
19 changes: 19 additions & 0 deletions dist/governance/rewards/storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import AlgodClient from "algosdk/dist/types/client/v2/algod/algod";
declare class RewardsAppGlobalState {
tinyAssetId: number;
vaultAppId: number;
rewardHistoryCount: number;
firstPeriodTimestamp: number;
rewardPeriodCount: number;
manager: string;
rewardsManager: string;
constructor(tinyAssetId: number, vaultAppId: number, rewardHistoryCount: number, firstPeriodTimestamp: number, rewardPeriodCount: number, manager: string, rewardsManager: string);
}
declare class RewardClaimSheet {
value: Uint8Array;
constructor(value: Uint8Array);
}
declare function getRewardPeriodBoxName(boxIndex: number): Uint8Array;
declare function getAccountRewardClaimSheetBoxName(address: string, boxIndex: number): Uint8Array;
declare function getRewardClaimSheet(algod: AlgodClient, appId: number, address: string, accountRewardClaimSheetBoxIndex: number): Promise<RewardClaimSheet | null>;
export { RewardClaimSheet, RewardsAppGlobalState, getRewardPeriodBoxName, getAccountRewardClaimSheetBoxName, getRewardClaimSheet };
14 changes: 14 additions & 0 deletions dist/governance/rewards/transactions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { SuggestedParams, Transaction } from "algosdk";
declare function prepareClaimRewardsTransactions({ rewardsAppId, vaultAppId, tinyAssetId, sender, periodIndexStart, periodCount, accountPowerIndexes, suggestedParams, createRewardClaimSheet, appCallNote }: {
rewardsAppId: number;
vaultAppId: number;
tinyAssetId: number;
sender: string;
periodIndexStart: number;
periodCount: number;
accountPowerIndexes: number[];
suggestedParams: SuggestedParams;
createRewardClaimSheet: boolean;
appCallNote?: string;
}): Transaction[];
export { prepareClaimRewardsTransactions };
7 changes: 7 additions & 0 deletions dist/governance/staking-voting/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const STAKING_VOTE_MAX_OPTION_COUNT = 8;
declare const PROPOSAL_BOX_PREFIX: Uint8Array;
declare const STAKING_ATTENDANCE_BOX_PREFIX: Uint8Array;
declare const STAKING_VOTE_BOX_PREFIX: Uint8Array;
declare const STAKING_ATTENDANCE_BOX_COST: number;
declare const STAKING_VOTE_BOX_COST: number;
export { STAKING_VOTE_MAX_OPTION_COUNT, PROPOSAL_BOX_PREFIX, STAKING_ATTENDANCE_BOX_PREFIX, STAKING_VOTE_BOX_PREFIX, STAKING_ATTENDANCE_BOX_COST, STAKING_VOTE_BOX_COST };
16 changes: 16 additions & 0 deletions dist/governance/staking-voting/storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import AlgodClient from "algosdk/dist/types/client/v2/algod/algod";
declare class StakingDistributionProposal {
index: number;
creationTimestamp: number;
votingStartTimestamp: number;
votingEndTimestamp: number;
votingPower: number;
voteCount: number;
isCancelled: boolean;
constructor(index: number, creationTimestamp: number, votingStartTimestamp: number, votingEndTimestamp: number, votingPower: number, voteCount: number, isCancelled: boolean);
}
declare function getStakingDistributionProposalBoxName(proposalId: string): Uint8Array;
declare function getStakingAttendanceSheetBoxName(sender: string, boxIndex: number): Uint8Array;
declare function getStakingVoteBoxName(proposalIndex: number, assetId: number): Uint8Array;
declare function getStakingDistributionProposal(algod: AlgodClient, appId: number, proposalId: string): Promise<StakingDistributionProposal | null>;
export { StakingDistributionProposal, getStakingDistributionProposalBoxName, getStakingAttendanceSheetBoxName, getStakingVoteBoxName, getStakingDistributionProposal };
16 changes: 16 additions & 0 deletions dist/governance/staking-voting/transactions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SuggestedParams } from "algosdk";
import { StakingDistributionProposal } from "./storage";
declare function prepareCastVoteForStakingDistributionProposalTransactions({ stakingVotingAppId, vaultAppId, sender, proposalId, proposal, votes, assetIds, accountPowerIndex, appBoxNames, suggestedParams, appCallNote }: {
stakingVotingAppId: number;
vaultAppId: number;
sender: string;
proposalId: string;
proposal: StakingDistributionProposal;
votes: number[];
assetIds: number[];
accountPowerIndex: number;
appBoxNames: Uint8Array[];
suggestedParams: SuggestedParams;
appCallNote: string | null;
}): import("algosdk").Transaction[];
export { prepareCastVoteForStakingDistributionProposalTransactions };
10 changes: 10 additions & 0 deletions dist/governance/transactions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import algosdk, { SuggestedParams } from "algosdk";
declare function prepareBudgetIncreaseTxn({ sender, index, suggestedParams, boxes, extraAppArgs, foreignApps }: {
sender: string;
index: number;
suggestedParams: SuggestedParams;
extraAppArgs?: Uint8Array[];
foreignApps?: number[];
boxes?: algosdk.BoxReference[];
}): algosdk.Transaction;
export { prepareBudgetIncreaseTxn };
7 changes: 7 additions & 0 deletions dist/governance/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface RawBoxCacheValue {
[key: string]: Uint8Array;
}
export interface GetRawBoxValueCacheProps {
onCacheUpdate: (cacheData: RawBoxCacheValue) => void;
cacheData: RawBoxCacheValue | null;
}
4 changes: 4 additions & 0 deletions dist/governance/util/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function intToBytes(num: number, length?: number): Uint8Array;
export declare function areBuffersEqual(buf1: Uint8Array, buf2: Uint8Array): boolean;
export declare function bytesToInt(buffer: Uint8Array): number;
export declare function sum(values: number[]): number;
Loading

0 comments on commit 312c268

Please sign in to comment.