From 687c1c637543b2cf7a0d3d5574905cd8855ce3d0 Mon Sep 17 00:00:00 2001 From: Arno Simon Date: Tue, 15 Oct 2024 14:29:30 +0200 Subject: [PATCH 1/2] add sol example to sdk --- examples/sol.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/fireblocks.ts | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/sol.ts diff --git a/examples/sol.ts b/examples/sol.ts new file mode 100644 index 0000000..a1611e3 --- /dev/null +++ b/examples/sol.ts @@ -0,0 +1,50 @@ +import { Kiln, solToLamports } 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.key`, 'utf8'); + +console.log(process.env.KILN_API_URL); + +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: 14 +}; + +try { + console.log('crafting...'); + const tx = await k.client.POST( + '/v1/sol/transaction/stake', + { + body: { + account_id: 'd3f1b917-72b1-4982-a4dd-93fce579a708', + wallet: 'E9qDxpwuPFeFB7vDdDibdCbWwHy867eYz3rV29bAevuC', + amount_lamports: solToLamports('0.01').toString(), + vote_account_address: 'FwR3PbjS5iyqzLiLugrBqKSa5EKZ4vK9SKs7eQXtT59f' + } + } + ); + console.log('signing...'); + if(!tx.data) throw new Error('No data in response'); + const signResponse = await k.fireblocks.signSolTx(vault, tx.data.data, "SOL_TEST"); + if(!signResponse.signed_tx?.data.signed_tx_serialized) throw new Error('No signed_tx in response'); + console.log('broadcasting...'); + const broadcastedTx = await k.client.POST("/v1/sol/transaction/broadcast", { + body: { + tx_serialized: signResponse.signed_tx.data.signed_tx_serialized + } + }); + console.log(broadcastedTx); + +} catch (err) { + console.log(err); +} \ No newline at end of file diff --git a/src/fireblocks.ts b/src/fireblocks.ts index 9d3ee15..38e930f 100644 --- a/src/fireblocks.ts +++ b/src/fireblocks.ts @@ -3,7 +3,7 @@ import type { Client } from 'openapi-fetch'; import { FireblocksSigner } from './fireblocks_signer'; import type { components, paths } from './openapi/schema'; -type FireblocksIntegration = { +export type FireblocksIntegration = { provider: 'fireblocks'; fireblocksApiKey: string; fireblocksSecretKey: string; From 9b8814da7316c367925cdf2f3240a3b0f80f9d32 Mon Sep 17 00:00:00 2001 From: Arno Simon Date: Tue, 15 Oct 2024 14:29:53 +0200 Subject: [PATCH 2/2] nit --- examples/sol.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/sol.ts b/examples/sol.ts index a1611e3..0d0dc34 100644 --- a/examples/sol.ts +++ b/examples/sol.ts @@ -6,8 +6,6 @@ import type { FireblocksIntegration } from "../src/fireblocks.ts"; const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret.key`, 'utf8'); -console.log(process.env.KILN_API_URL); - const k = new Kiln({ baseUrl: process.env.KILN_API_URL as string, apiToken: process.env.KILN_API_KEY as string,