-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
WALLET_MNEMONIC= | ||
|
||
# v4 | ||
WALLET_VERSION= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
temp | ||
build | ||
.idea | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma version =0.4.4; | ||
#include "imports/stdlib.fc"; | ||
|
||
() set_lib_code(cell code, int mode) impure asm "SETLIBCODE"; | ||
|
||
() deploy_lib() impure { | ||
set_lib_code(get_data(), 2); | ||
cell empty = begin_cell().end_cell(); | ||
set_code(empty); | ||
set_data(empty); | ||
} | ||
|
||
() recv_internal(slice in_msg) impure { | ||
deploy_lib(); | ||
} | ||
|
||
() recv_external(slice in_msg) impure { | ||
deploy_lib(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { toNano } from 'ton-core'; | ||
import { compile, NetworkProvider } from '@ton-community/blueprint'; | ||
import 'dotenv/config'; | ||
import { LibraryDeployer } from '../wrappers/library-deployer'; | ||
|
||
export async function run(provider: NetworkProvider) { | ||
/* const library: SimpleLibrary = { | ||
public: true, | ||
root: await compile('wallet_v5') | ||
}; | ||
let secretKey = process.env.LIBRARY_KEEPER_SECRET_KEY; | ||
if (!secretKey) { | ||
const keypair = keyPairFromSeed(await getSecureRandomBytes(32)); | ||
console.log('GENERATED PRIVATE_KEY', keypair.secretKey.toString('hex')); | ||
secretKey = keypair.secretKey.toString('hex'); | ||
fs.appendFileSync('.env', `LIBRARY_KEEPER_SECRET_KEY=${secretKey}`); | ||
} | ||
const keypair = keyPairFromSecretKey(Buffer.from(secretKey, 'hex')); | ||
const libraryKeeper = provider.open( | ||
LibraryKeeper.createFromConfig( | ||
{ publicKey: keypair.publicKey, seqno: 0 }, | ||
await compile('library-keeper') | ||
) | ||
); | ||
const isActive = await libraryKeeper.getIsActive(); | ||
if (!isActive) { | ||
await libraryKeeper.sendDeploy(provider.sender(), toNano('0.1')); | ||
await provider.waitForDeploy(libraryKeeper.address); | ||
} | ||
await libraryKeeper.sendAddLibrary({ | ||
libraryCode: library.root, | ||
secretKey: keypair.secretKey | ||
}); | ||
console.log('LIBRARY KEEPER ADDRESS', libraryKeeper.address);*/ | ||
|
||
const libraryDeployer = provider.open( | ||
LibraryDeployer.createFromConfig( | ||
{ libraryCode: await compile('wallet_v5') }, | ||
await compile('library-deployer') | ||
) | ||
); | ||
|
||
await libraryDeployer.sendDeploy(provider.sender(), toNano('0.1')); | ||
await provider.waitForDeploy(libraryDeployer.address); | ||
|
||
console.log('LIBRARY ADDRESS', libraryDeployer.address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Dictionary, toNano } from 'ton-core'; | ||
import { WalletId, WalletV5 } from '../wrappers/wallet-v5'; | ||
import { compile, NetworkProvider } from '@ton-community/blueprint'; | ||
import { getSecureRandomBytes, keyPairFromSeed } from 'ton-crypto'; | ||
|
||
export async function run(provider: NetworkProvider) { | ||
const keypair = keyPairFromSeed(await getSecureRandomBytes(32)); | ||
console.log('KEYPAIR PUBKEY', keypair.publicKey.toString('hex')); | ||
console.log('KEYPAIR PRIVATE_KEY', keypair.secretKey.toString('hex')); | ||
|
||
const walletV5 = provider.open( | ||
WalletV5.createFromConfig( | ||
{ | ||
seqno: 0, | ||
walletId: new WalletId({ networkGlobalId: -3 }).serialized, // testnet | ||
publicKey: keypair.publicKey, | ||
extensions: Dictionary.empty() | ||
}, | ||
await compile('wallet_v5') | ||
) | ||
); | ||
|
||
await walletV5.sendDeploy(provider.sender(), toNano('0.05')); | ||
|
||
await provider.waitForDeploy(walletV5.address); | ||
|
||
console.log('ADDRESS', walletV5.address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { compile } from '@ton-community/blueprint'; | ||
import { LibraryKeeper } from '../wrappers/library-keeper'; | ||
|
||
export async function run() { | ||
const code = LibraryKeeper.exportLibCode(await compile('wallet_v5')); | ||
|
||
console.log('WALLET CODE HEX', code.toBoc().toString('hex'), '\n'); | ||
console.log('WALLET CODE BASE64', code.toBoc().toString('base64')); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CompilerConfig } from '@ton-community/blueprint'; | ||
|
||
export const compile: CompilerConfig = { | ||
lang: 'func', | ||
targets: ['contracts/library-deployer.fc'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Address, | ||
beginCell, | ||
BitBuilder, | ||
Cell, | ||
Contract, | ||
contractAddress, | ||
ContractProvider, | ||
Sender, | ||
SendMode | ||
} from 'ton-core'; | ||
|
||
export type LibraryDeployerConfig = { | ||
libraryCode: Cell; | ||
}; | ||
|
||
export class LibraryDeployer implements Contract { | ||
static exportLibCode(code: Cell) { | ||
const bits = new BitBuilder(); | ||
bits.writeUint(2, 8); | ||
bits.writeUint(BigInt('0x' + code.hash().toString('hex')), 256); | ||
|
||
return new Cell({ exotic: true, bits: bits.build() }); | ||
} | ||
|
||
constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {} | ||
|
||
static createFromConfig(config: LibraryDeployerConfig, code: Cell, workchain = -1) { | ||
const data = config.libraryCode; | ||
const init = { code, data }; | ||
return new LibraryDeployer(contractAddress(workchain, init), init); | ||
} | ||
|
||
async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) { | ||
await provider.internal(via, { | ||
value, | ||
sendMode: SendMode.PAY_GAS_SEPARATELY, | ||
body: beginCell().endCell() | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters