Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce MinaProgram #2095

Merged
merged 24 commits into from
Mar 31, 2025
Merged

Introduce MinaProgram #2095

merged 24 commits into from
Mar 31, 2025

Conversation

Trivo25
Copy link
Member

@Trivo25 Trivo25 commented Mar 25, 2025

No description provided.

@Trivo25 Trivo25 requested review from a team as code owners March 25, 2025 10:42
@Trivo25 Trivo25 requested review from Shigoto-dev19 and ymekuria and removed request for a team March 25, 2025 10:42
Base automatically changed from new-api-phase-1 to main March 26, 2025 12:43
@Trivo25 Trivo25 self-assigned this Mar 26, 2025
async method(
env: Experimental.V2.MinaProgramEnv<TestState>,
value: Field
): Promise<Experimental.V2.MinaProgramMethodReturn<TestState>> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really awful but no other way if we want to keep it in the experimental namesapce for now

return UInt64.from(amount * 1e9);
} else return UInt64.from(amount * BigInt(1e9));
},
toMINA: (amount: MinaAmount): bigint => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to optionally throw if there is a remainder in this division. Personally, I would enable that param if it were offered to me.

};

// boo typescript
function mapObject<In extends { [key: string]: any }, Out extends { [key in keyof In]: any }>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this might be preferable. It will give a return type based on the function signature.

image
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function mapObject<In extends { [key: string]: any }, Out extends { [key in keyof In]: any }>(
function mapObject<In extends { [key: string]: any }, Out>(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that change, replace instances of Out[Key] with Out. You may also consider changing the name from Out to ValueOfOut or just T since it no longer represents the return type of the mapping function, just the return type of f.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, there are a lot of type errors and improvements we can and should do. I focused on getting everything to work first, fixing these will hoefully happen in the coming PRs. sadly its too much to fix everything right now but I agree

};

class MinaProgramEnv<State extends StateLayout> {
private expectedPreconditions: Unconstrained<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#expectedPreconditions: Unconstrained<{

This is another option to make the property truly private instead of typescript's fake private keyword.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties

https://www.typescriptlang.org/docs/handbook/classes.html#public-private-and-protected-modifiers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't use the hashtag syntax anywhere, and that's fine. Just raising it as an option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use it in a few places and I agree! See #2095 (comment)
We'll have to go through everything and overhaul it to bring it up to date with the rest of the codebase and latest ts standards

Event = Field[],
Action = Field[]
> =
| Omit<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is not very human-readable. Good candidate for a @link comment and a short description of why it can be either one thing or another.

...args: ProvableTupleInstances<PrivateInputs>
) => Promise<AccountUpdateTree<AccountUpdate<State, Event, Action>, AccountUpdate>>;

interface MinaProgramDescription<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a guide to when we prefer interface or type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No guide, but we do usually prefer types if possible

>;
};

// TODO really need to fix the types here...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you enumerate the issues you want to fix in the comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly one of many leftovers from the original prototype, see #2095 (comment)

@@ -0,0 +1,127 @@
import { Bool, Experimental, Field, PrivateKey, PublicKey, UInt32 } from 'o1js';

const V2 = Experimental.V2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a nit pick, but I think MinaV2 is a better name within the experimental namespace than V2. It's more clear that we're working on a new API for interacting with Mina, not everything.

const TestProgram = V2.MinaProgram({
name: 'TestProgram',
State: TestState,
Event: V2.GenericData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk what Event and Action are here


setState: {
x: V2.Update.from(value, Field(0)) as never,
address: V2.Update.from(env.accountId.publicKey, PublicKey.empty()) as never,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the x value needs the casting as never. Do you know why the typing for setState doesn't allow an update for x?

@45930
Copy link
Contributor

45930 commented Mar 31, 2025

@Trivo25 you can force merge this if you need to. I left several questions, mostly for my own understanding.

@Trivo25 Trivo25 merged commit 03ecd38 into main Mar 31, 2025
30 checks passed
@Trivo25 Trivo25 deleted the new-api-minaprogram branch March 31, 2025 16:35
@Trivo25 Trivo25 mentioned this pull request Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants