Skip to content

Commit

Permalink
ton example (#151)
Browse files Browse the repository at this point in the history
* add ton example

* TON stake/unstake ton-whales

* ton example

* remove ts ignore
  • Loading branch information
nooxx authored Nov 6, 2024
1 parent 66a50c7 commit 3d1cc69
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
60 changes: 60 additions & 0 deletions examples/ton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Kiln, tonToNanoton } from "../src/kiln";
import fs from "node:fs";
import 'dotenv/config'
import type { FireblocksIntegration } from "../src/fireblocks.ts";


const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret_prod.key`, 'utf8');

const k = new Kiln({
baseUrl: process.env.KILN_API_URL as string,
apiToken: process.env.KILN_API_KEY as string,
});

const vault: FireblocksIntegration = {
provider: 'fireblocks',
fireblocksApiKey: process.env.FIREBLOCKS_API_KEY as string,
fireblocksSecretKey: apiSecret,
vaultId: 17
};

try {
console.log('crafting...');
const tx = await k.client.POST(
'/v1/ton/transaction/stake-ton-whales-pool',
{
body: {
account_id: process.env.KILN_ACCOUNT_ID as string,
wallet: 'UQAd57R6nYTCpgo1OxSmpbFRsIO6HIIfO2SW6WcfCe5qIo08',
pool_address: 'EQBXDSbE9s03Waq62YuGdtqe-bcjsN6K9fi64eUy9M8H_Yhf',
vesting_contract_address: 'EQBdL-upJbGStg4MF8acfEfilqd34cfoHe_k2E-yecki3yS6',
amount_nanoton: tonToNanoton('2').toString(),
}
}
);
// const tx = await k.client.POST(
// '/v1/ton/transaction/unstake-ton-whales-pool',
// {
// body: {
// wallet: 'UQAd57R6nYTCpgo1OxSmpbFRsIO6HIIfO2SW6WcfCe5qIo08',
// pool_address: 'EQBXDSbE9s03Waq62YuGdtqe-bcjsN6K9fi64eUy9M8H_Yhf',
// vesting_contract_address: 'EQBdL-upJbGStg4MF8acfEfilqd34cfoHe_k2E-yecki3yS6',
// amount_nanoton: tonToNanoton('0.5').toString(),
// }
// }
// );
console.log('signing...');
if(!tx.data?.data) throw new Error('No data in response');
const signResponse = await k.fireblocks.signTonTx(vault, tx.data.data, "TON");
console.log('broadcasting...');
if(!signResponse.signed_tx?.data?.signed_tx_serialized) throw new Error('No signed_tx in response');
const broadcastedTx = await k.client.POST("/v1/ton/transaction/broadcast", {
body: {
tx_serialized: signResponse.signed_tx.data.signed_tx_serialized,
}
});
console.log(broadcastedTx);

} catch (err) {
console.log(err);
}
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export const nanotonToTon = (nanoton: bigint): string => {
return formatUnits(nanoton, 9);
};

/**
* Convert TON to nanoTON
*/
export const tonToNanoton = (ton: string): bigint => {
return parseUnits(ton, 9);
};

/**
* Convert uZETA to ZETA
*/
Expand Down

0 comments on commit 3d1cc69

Please sign in to comment.