1+ import { Kiln , tonToNanoton } from "../src/kiln" ;
2+ import fs from "node:fs" ;
3+ import 'dotenv/config'
4+ import type { FireblocksIntegration } from "../src/fireblocks.ts" ;
5+
6+
7+ const apiSecret = fs . readFileSync ( `${ __dirname } /fireblocks_secret_prod.key` , 'utf8' ) ;
8+
9+ const k = new Kiln ( {
10+ baseUrl : process . env . KILN_API_URL as string ,
11+ apiToken : process . env . KILN_API_KEY as string ,
12+ } ) ;
13+
14+ const vault : FireblocksIntegration = {
15+ provider : 'fireblocks' ,
16+ fireblocksApiKey : process . env . FIREBLOCKS_API_KEY as string ,
17+ fireblocksSecretKey : apiSecret ,
18+ vaultId : 17
19+ } ;
20+
21+ try {
22+ console . log ( 'crafting...' ) ;
23+ const tx = await k . client . POST (
24+ '/v1/ton/transaction/stake-ton-whales-pool' ,
25+ {
26+ body : {
27+ account_id : process . env . KILN_ACCOUNT_ID as string ,
28+ wallet : 'UQAd57R6nYTCpgo1OxSmpbFRsIO6HIIfO2SW6WcfCe5qIo08' ,
29+ pool_address : 'EQBXDSbE9s03Waq62YuGdtqe-bcjsN6K9fi64eUy9M8H_Yhf' ,
30+ vesting_contract_address : 'EQBdL-upJbGStg4MF8acfEfilqd34cfoHe_k2E-yecki3yS6' ,
31+ amount_nanoton : tonToNanoton ( '2' ) . toString ( ) ,
32+ }
33+ }
34+ ) ;
35+ // const tx = await k.client.POST(
36+ // '/v1/ton/transaction/unstake-ton-whales-pool',
37+ // {
38+ // body: {
39+ // wallet: 'UQAd57R6nYTCpgo1OxSmpbFRsIO6HIIfO2SW6WcfCe5qIo08',
40+ // pool_address: 'EQBXDSbE9s03Waq62YuGdtqe-bcjsN6K9fi64eUy9M8H_Yhf',
41+ // vesting_contract_address: 'EQBdL-upJbGStg4MF8acfEfilqd34cfoHe_k2E-yecki3yS6',
42+ // amount_nanoton: tonToNanoton('0.5').toString(),
43+ // }
44+ // }
45+ // );
46+ console . log ( 'signing...' ) ;
47+ if ( ! tx . data ?. data ) throw new Error ( 'No data in response' ) ;
48+ const signResponse = await k . fireblocks . signTonTx ( vault , tx . data . data , "TON" ) ;
49+ console . log ( 'broadcasting...' ) ;
50+ if ( ! signResponse . signed_tx ?. data ?. signed_tx_serialized ) throw new Error ( 'No signed_tx in response' ) ;
51+ const broadcastedTx = await k . client . POST ( "/v1/ton/transaction/broadcast" , {
52+ body : {
53+ tx_serialized : signResponse . signed_tx . data . signed_tx_serialized ,
54+ }
55+ } ) ;
56+ console . log ( broadcastedTx ) ;
57+
58+ } catch ( err ) {
59+ console . log ( err ) ;
60+ }
0 commit comments