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

ton example #151

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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