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

add: ops script to initialize gateway program #20

Closed
wants to merge 2 commits into from

Conversation

brewmaster012
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 9.17%. Comparing base (08b8147) to head (3a7e0d5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main     #20   +/-   ##
=====================================
  Coverage   9.17%   9.17%           
=====================================
  Files          1       1           
  Lines        218     218           
=====================================
  Hits          20      20           
  Misses       198     198           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -16,3 +16,4 @@ wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
#test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/ops.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/ops.ts"

Comment on lines +2 to +3
// uncomment Anchor.toml [test] to run this script
// #test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/ops.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Unclear what does this mean. We should put instruction to run the script in the readme

console.log("=====================================");
console.log("BEGIN OPS ON DEVNET........");

const provider = anchor.AnchorProvider.local("https://api.devnet.solana.com");
Copy link
Member

Choose a reason for hiding this comment

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

Comment above mention it c mainnet but here the URL is devnet. I think we should use an environment variable for it

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, same as mentioned before: we could group all constants in const.ts, adding the ability to override them via env var.

Comment on lines +49 to +58
// Uncomment the following to initialize the gateway program;
// can only be initialized once
// try {
// const inst = await gatewayProgram.methods.initialize(tssAddressArray,chain_id_bn).transaction();
// console.log("initialize inst:", inst);
// const tx = await anchor.web3.sendAndConfirmTransaction(conn, inst, [wallet]);
// console.log("tx:", tx);
// } catch (err) {
// console.log("initialize err:", err);
// }
Copy link
Member

Choose a reason for hiding this comment

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

We should rather have argument or using environment variable to customize script logic

// const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount);
try {
console.log("fetching pda account data....", pdaAccount.toBase58());
// const data = await gatewayProgram.account.pda.fetch(pdaAccount);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// const data = await gatewayProgram.account.pda.fetch(pdaAccount);


const pdaAccountInfo = await conn.getAccountInfo(pdaAccount);
console.log("pdaAccountInfoData:", pdaAccountInfo.data);
// const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount);

console.log(`depositPaused: ${ainfo.depositPaused}`);
console.log(`chain_id: ${ainfo.chainId}`);

// console.log(`pda data:`, ainfo);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// console.log(`pda data:`, ainfo);

Comment on lines +78 to +81
// console.log(`pda account data: nonce ${pdaAccountData.nonce}`);
// const hexAddr = bufferToHex(Buffer.from(pdaAccountData.tssAddress));
// console.log(`pda account data: tss address ${hexAddr}`);
// console.log(`authority: ${pdaAccountData.authority.toBase58()}`);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// console.log(`pda account data: nonce ${pdaAccountData.nonce}`);
// const hexAddr = bufferToHex(Buffer.from(pdaAccountData.tssAddress));
// console.log(`pda account data: tss address ${hexAddr}`);
// console.log(`authority: ${pdaAccountData.authority.toBase58()}`);

@@ -0,0 +1,90 @@
// this is for ops on devnet/mainnet
Copy link
Member

Choose a reason for hiding this comment

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

Unclear what ops means, if this is to deploy the gateway, it should be reflected in the name of the script?

import {bufferToHex} from "ethereumjs-util";
import {getAccount} from "@solana/spl-token";

const programId = new web3.PublicKey("ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move all hardcoded values to constants in a separate file, and add the ability of overriding them via env vars?

console.log("=====================================");
console.log("BEGIN OPS ON DEVNET........");

const provider = anchor.AnchorProvider.local("https://api.devnet.solana.com");
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, same as mentioned before: we could group all constants in const.ts, adding the ability to override them via env var.

@brewmaster012
Copy link
Contributor Author

brewmaster012 commented Sep 12, 2024

thanksf or the comments, but to clarify: the ops script serves two purposes:

  1. as a log of deployment
  2. template for deployment for mainnet

This is one-off script (at most two-off). The commented code is there to prevent accidental re-deployment and can be uncommented for mainnet deployment.

As long as it works I will not further improve it.

@fbac fbac self-requested a review September 24, 2024 10:45
@lumtis
Copy link
Member

lumtis commented Oct 1, 2024

thanksf or the comments, but to clarify: the ops script serves two purposes:

  1. as a log of deployment
  2. template for deployment for mainnet

This is one-off script (at most two-off). The commented code is there to prevent accidental re-deployment and can be uncommented for mainnet deployment.

As long as it works I will not further improve it.

Not sure to understand the point. If the script is not used in practice and just as a template, the we can have a playbook instead of it.
If the script is aimed to be used in production, we should have production grade code. Having commented code for no reason is confusing, we should write code as if an entirely new team could take ownership of the codebase and know how to use the script.

@brewmaster012
Copy link
Contributor Author

closing this as it's not suitable for merging.
Will keep the branch alive as a record.

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.

4 participants