Skip to content

Commit

Permalink
add balance and vestingBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed Dec 5, 2023
1 parent 2306ef0 commit 681a9ac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
11 changes: 10 additions & 1 deletion lib/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ export abstract class NeokingdomDAO {
for (let i = nextStep; i < s.length; i++) {
const context = await c(this);
const step = s[i];

if (this.config.verbose) {
console.log(`${i + 1}/${s.length}: ${step.toString()}`);
console.log(
`${i + 1}/${s.length}: ${step ? step.toString() : "step is empty"}`
);
}

// If a step is null, it's skipped
if (step === null) {
continue;
}

let tx: TransactionResponse | null = null;
try {
tx = await step(context);
Expand Down
11 changes: 6 additions & 5 deletions lib/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export type ContractNames = keyof typeof FACTORIES;
export type Contributor = {
name?: string;
address: string;
status: "contributor" | "board" | "investor";
tokens: string;
status?: "contributor" | "board" | "investor";
balance?: string;
vestingBalance?: string;
};

export type Address = `0x${string}`;
Expand Down Expand Up @@ -89,19 +90,19 @@ export type ContractContext = Context & NeokingdomContracts;

export type Step<T extends Context> = (
c: T
) => Promise<TransactionResponse | null>;
) => Promise<TransactionResponse> | null;

export type StepWithExpandable<T extends Context> =
| ExpandableStep<T>
| ((c: T) => Promise<TransactionResponse | null>);
| ((c: T) => Promise<TransactionResponse> | null);

export type ExpandableStep<T extends Context> = {
expandableFunction: (c: T) => ProcessedSequence<T>;
};

export type Sequence<T extends Context> = StepWithExpandable<T>[];

export type ProcessedSequence<T extends Context> = Step<T>[];
export type ProcessedSequence<T extends Context> = (Step<T> | null)[];

// FIXME: There Must Be A Better Way™ to do this in TypeScript
export const CONTRACT_NAMES = [
Expand Down
25 changes: 20 additions & 5 deletions lib/sequence/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SETUP_SEQUENCE: Sequence<SetupContext> = [
)
),

// Set each address to contributor
// Set address status
expandable((preprocessContext: SetupContext) =>
preprocessContext.contributors.map((contributor) => async (c) => {
if (contributor.status === "contributor") {
Expand Down Expand Up @@ -42,10 +42,25 @@ export const SETUP_SEQUENCE: Sequence<SetupContext> = [
expandable((preprocessContext: SetupContext) =>
preprocessContext.contributors.map(
(contributor) => (c) =>
c.governanceToken.mint(
contributor.address,
BigNumber.from(contributor.tokens.toString())
)
contributor.balance
? c.governanceToken.mint(
contributor.address,
BigNumber.from(contributor.balance.toString())
)
: null
)
),

// Give each contributor vesting tokens
expandable((preprocessContext: SetupContext) =>
preprocessContext.contributors.map(
(contributor) => (c) =>
contributor.vestingBalance
? c.governanceToken.mintVesting(
contributor.address,
BigNumber.from(contributor.vestingBalance.toString())
)
: null
)
),
];
Expand Down

0 comments on commit 681a9ac

Please sign in to comment.