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

feat: add Solana support #62

Merged
merged 89 commits into from
Feb 6, 2025
Merged

feat: add Solana support #62

merged 89 commits into from
Feb 6, 2025

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 13, 2024

  • skip Solana setup if no solana CLI is installed
  • improve output
  • revert handling

Works with zeta-chain/example-contracts#232

Refactor

Localnet Architecture

https://www.figma.com/board/OIkQtFPbsSc9FgZaf6nmoO/Localnet-Architecture?node-id=0-1&t=xvUDq8lw5PkzB5t1-1

@fadeev

This comment was marked as resolved.

@fadeev

This comment was marked as resolved.

@fadeev fadeev changed the base branch from main to localnet-authenticated-call November 18, 2024 13:56
@fadeev fadeev marked this pull request as ready for review February 3, 2025 14:56
@fadeev fadeev requested review from lumtis and skosito as code owners February 3, 2025 14:56
@fadeev fadeev marked this pull request as draft February 3, 2025 15:03
@fadeev
Copy link
Member Author

fadeev commented Feb 3, 2025

Swapping from EVM to Solana:

Screenshot 2025-02-03 at 18 16 37

@fadeev
Copy link
Member Author

fadeev commented Feb 3, 2025

Swapping from Solana to EVM:

Screenshot 2025-02-03 at 18 17 25

@fadeev fadeev marked this pull request as ready for review February 3, 2025 15:17
@fadeev
Copy link
Member Author

fadeev commented Feb 3, 2025

To test, clone zeta-chain/example-contracts#232 and run:

cd examples/swap
yarn
./scripts/localnet.sh start

It should have this version of localnet pre-installed (as 6.0.0-rc3).

Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

looks good, some minor comments

@@ -28,5 +28,8 @@ jobs:
- name: Install Dependencies
run: yarn

- name: Build
run: yarn build
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need above build workflow as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, yes, because the script uses gateway.so by resolving @zetachain/localnet, and the build step is needed so that the file is copied from src into dist, so that the script can find it. Once we have these files published on npm, this step will no longer be needed.

import { deployOpts } from "./deployOpts";
import * as TestERC20 from "@zetachain/protocol-contracts/abi/TestERC20.sol/TestERC20.json";

export const createToken = async (
Copy link
Contributor

Choose a reason for hiding this comment

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

createToken seems a bit too generic and confusing what it refers to (and also it is in generic place), especially since localnet already have multiple chains and that will increase

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose you're right, we can refactor this into something more manageable. I just needed a function that would mint ZRC-20, ERC-20 (if needed), created a pool with ZETA, etc. Adding SUI/ZRC-20 SUI was actually very easy thanks to this function, it was just one line of code.

if (exitOnError) {
throw new Error(err);
}
logErr("ZetaChain", `Error executing onCall: ${err}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, but might be useful to log even if exitOnError is true

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the error gets logged inside the if statement. The logErr just provides nicer output.

foreignCoins: any[];
tss: any;
}) => {
const zrc20 = args[3];
Copy link
Contributor

Choose a reason for hiding this comment

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

this might be subjective, but i think arrays can be deconstructed in js, so something like [_, receiver, zrc20, amount] = args might be cleaner

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree! I'll refactor the code, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

tss: any;
}) => {
const zrc20 = args[3];
const chainID = foreignCoins.find(
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 check for chainID should be here as well if it can be undefined based on ?. operator

Copy link
Member Author

Choose a reason for hiding this comment

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

`Monitoring new transactions for program: ${gatewayProgram.programId.toBase58()}`
);

let lastSignature: string | undefined = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be simplified, i dont think undefined parts are needed

Copy link
Member Author

Choose a reason for hiding this comment

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

);

if (transaction) {
// console.log(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can remove commented code if not used

Copy link
Member Author

Choose a reason for hiding this comment

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

} finally {
// Update lastSignature even if an error occurs
if (signatures && signatures.length > 0) {
lastSignature = signatures[0].signature;
Copy link
Contributor

Choose a reason for hiding this comment

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

is last signature on index 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe so, they're returned in descending order so the latest one should be at 0.

handlers.depositAndCall(args);
} else if (decodedInstruction.name === "deposit") {
handlers.deposit(args);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

up to you, but this can probably be refactored a bit, seems like a lot of things are going on, even visually based on amount of {...} brackets, but not blocker for this PR


const context = {
chainID,
origin: chainID === "901" ? sender : ethers.ZeroAddress,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this check?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, because we need to set context.sender for EVM chains and context.origin for Solana.

@fadeev
Copy link
Member Author

fadeev commented Feb 6, 2025

@skosito thanks for the review! Addressed most of the comments, some improvements will be made in follow-up PRs.

@fadeev fadeev merged commit ea20c24 into main Feb 6, 2025
4 checks passed
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.

Add Solana support
2 participants