-
Notifications
You must be signed in to change notification settings - Fork 0
Add deploy script for HighloadWalletV3 contract #20
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,146 @@ | ||||||||||||||||
| /** | ||||||||||||||||
| * Template deploy script for HighloadWalletV3 (keypair-based sender) | ||||||||||||||||
| * | ||||||||||||||||
| * Behavior: | ||||||||||||||||
| * - Loads compiled code cell from wrappers/compiled.ts | ||||||||||||||||
| * - Builds data cell using highloadWalletV3ConfigToCell | ||||||||||||||||
| * - Computes the contract address and prints it | ||||||||||||||||
| * - Determines deploy amount: | ||||||||||||||||
| * - If DEPLOY_VALUE env var is set, use it | ||||||||||||||||
| * - Otherwise try to call a TonClient estimate function (if available at runtime) | ||||||||||||||||
| * - If estimation fails, fallback to DEPLOY_FALLBACK (default 0.1 TON) | ||||||||||||||||
| * - Apply DEPLOY_SAFE_MARGIN (default 1.5) | ||||||||||||||||
| * - Prints the chosen amount and exits unless CONFIRM_DEPLOY=true | ||||||||||||||||
| * - The actual SEND DEPLOY block is marked with TODO: implement using your wallet/provider | ||||||||||||||||
| * | ||||||||||||||||
| * Safety: | ||||||||||||||||
| * - Does not send funds unless CONFIRM_DEPLOY=true to avoid accidental deploys from CI | ||||||||||||||||
| * - Does not contain any secret key; expects SECRET_KEY_BASE64 or a secret manager to be used | ||||||||||||||||
| */ | ||||||||||||||||
|
|
||||||||||||||||
| import 'dotenv/config'; | ||||||||||||||||
| import { toNano, contractAddress } from '@ton/core'; | ||||||||||||||||
| import { HighloadWalletV3Code } from '../wrappers/compiled'; | ||||||||||||||||
| import { highloadWalletV3ConfigToCell } from '../wrappers/HighloadWalletV3'; | ||||||||||||||||
|
|
||||||||||||||||
| const RPC_URL = process.env.RPC_URL || 'https://net.ton.dev'; | ||||||||||||||||
| const SECRET_KEY_BASE64 = process.env.SECRET_KEY_BASE64 || ''; | ||||||||||||||||
| const WORKCHAIN = Number(process.env.WORKCHAIN || 0); | ||||||||||||||||
|
|
||||||||||||||||
| // Default subwallet id for HighloadWalletV3 as per the HighloadWalletV3 specification. | ||||||||||||||||
| // Can be overridden via the SUBWALLET_ID environment variable if needed. | ||||||||||||||||
| const HIGHLOAD_WALLET_V3_DEFAULT_SUBWALLET_ID = 0x10ad; | ||||||||||||||||
|
||||||||||||||||
|
|
||||||||||||||||
| const SUBWALLET_ID = Number(process.env.SUBWALLET_ID || HIGHLOAD_WALLET_V3_DEFAULT_SUBWALLET_ID); | ||||||||||||||||
| const TIMEOUT = Number(process.env.TIMEOUT || 3600); | ||||||||||||||||
| const DEPLOY_VALUE_ENV = process.env.DEPLOY_VALUE || ''; | ||||||||||||||||
|
||||||||||||||||
| const DEPLOY_SAFE_MARGIN = Number(process.env.DEPLOY_SAFE_MARGIN || '1.5'); | ||||||||||||||||
| const DEPLOY_FALLBACK = process.env.DEPLOY_FALLBACK || '0.1'; | ||||||||||||||||
| const CONFIRM_DEPLOY = process.env.CONFIRM_DEPLOY === 'true'; // must be explicitly set to "true" to send | ||||||||||||||||
|
|
||||||||||||||||
| async function estimateDeployAmount(init: any): Promise<bigint> { | ||||||||||||||||
|
||||||||||||||||
| // If user provided explicit value, use it | ||||||||||||||||
| if (DEPLOY_VALUE_ENV) { | ||||||||||||||||
| console.log('Using DEPLOY_VALUE from env:', DEPLOY_VALUE_ENV); | ||||||||||||||||
| return toNano(DEPLOY_VALUE_ENV); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Try to use TonClient dynamically (if installed and available at runtime) | ||||||||||||||||
| try { | ||||||||||||||||
| // dynamic require to avoid TypeScript type errors if library evolves | ||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||||||||||||||||
| const { TonClient } = require('ton'); | ||||||||||||||||
| const client = new TonClient({ endpoint: RPC_URL }); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+50
to
+54
|
||||||||||||||||
| // dynamic require to avoid TypeScript type errors if library evolves | |
| // eslint-disable-next-line @typescript-eslint/no-var-requires | |
| const { TonClient } = require('ton'); | |
| const client = new TonClient({ endpoint: RPC_URL }); | |
| // dynamic import to avoid TypeScript type errors if library evolves | |
| const { TonClient } = await import('ton'); | |
| const client = new TonClient({ endpoint: RPC_URL }); |
This conversation was marked as resolved.
Show resolved
Hide resolved
This conversation was marked as resolved.
Show resolved
Hide resolved
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precision loss when converting BigInt to Number. When converting fallback (a BigInt) to Number for multiplication, very large values could lose precision. The safer approach is to perform the multiplication in BigInt arithmetic directly:
const withMargin = (fallback * BigInt(Math.floor(DEPLOY_SAFE_MARGIN * 100))) / 100n;This preserves BigInt precision throughout the calculation.
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting bigint to number for multiplication can cause precision loss for large values. Since fallback is already a bigint from toNano(), consider using BigInt arithmetic throughout: const withMargin = (fallback * BigInt(Math.floor(DEPLOY_SAFE_MARGIN * 1000))) / 1000n to maintain precision.
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a zeroed placeholder public key will result in computing an incorrect contract address. The address depends on the actual public key that will be used for deployment. This means the computed address will not match the actual deployed contract address if a different public key is used later, which could lead to funds being sent to the wrong address or deployment failures.
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precision loss when converting BigInt to Number for display. For very large values (near the Number.MAX_SAFE_INTEGER limit), this conversion could lose precision. Consider using a string-based division or a dedicated BigInt formatting function for accurate display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No validation for TIMEOUT value. The Number() conversion could result in NaN if the environment variable is not a valid number, which would cause issues when creating the config cell. Consider adding validation: