From 2916f3b1ce0ae085fbdf7c8ab1fb7fbe455750d8 Mon Sep 17 00:00:00 2001 From: Elliott Denis Date: Mon, 3 Nov 2025 14:55:00 +0100 Subject: [PATCH] ksm example --- examples/ksm.ts | 86 +++++++++++++++++++++++++++++++++++++++++++++++ src/validators.ts | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 examples/ksm.ts diff --git a/examples/ksm.ts b/examples/ksm.ts new file mode 100644 index 0000000..fe1e17a --- /dev/null +++ b/examples/ksm.ts @@ -0,0 +1,86 @@ +import { ksmToPlanck, Kiln } from '../src/kiln.ts'; +import type { FireblocksIntegration } from '../src/fireblocks.ts'; +import { loadEnv } from './env.ts'; + +const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } = + await loadEnv(); + +const k = new Kiln({ + baseUrl: kilnApiUrl, + apiToken: kilnApiKey, +}); + +const vault: FireblocksIntegration = { + config: { + apiKey: fireblocksApiKey, + secretKey: fireblocksApiSecret, + basePath: 'https://api.fireblocks.io/v1', + }, + vaultId: fireblocksVaultId, +}; + +// +// Get the wallet address from Fireblocks +// +const fireblocksWallet = ( + await k.fireblocks.getSdk(vault).vaults.getVaultAccountAssetAddressesPaginated({ + vaultAccountId: vault.vaultId, + assetId: 'KSM', + limit: 1, + }) +).data.addresses?.[0].address; + +if (!fireblocksWallet) { + console.log('Failed to get fireblocks wallet'); + process.exit(0); +} + +// +// Craft the transaction +// +console.log('Crafting transaction...'); +const txRequest = await k.client.POST('/ksm/transaction/bond-extra-pool', { + body: { + account_id: kilnAccountId, + member_account: fireblocksWallet, + amount_planck: ksmToPlanck('0.1').toString(), + }, +}); +if (txRequest.error) { + console.log('Failed to craft transaction:', txRequest); + process.exit(1); +} else { + console.log('Crafted transaction:', txRequest.data); +} +console.log('\n\n\n'); + +// +// Sign the transaction +// +console.log('Signing transaction...'); +const signRequest = await (async () => { + try { + return await k.fireblocks.signKsmTx(vault, txRequest.data.data); + } catch (err) { + console.log('Failed to sign transaction:', err); + process.exit(1); + } +})(); +console.log('Signed transaction:', signRequest); +console.log('\n\n\n'); + +// +// Broadcast the transaction +// +console.log('Broadcasting transaction...'); +const broadcastedRequest = await k.client.POST('/ksm/transaction/broadcast', { + body: { + tx_serialized: signRequest.signed_tx.data.signed_tx_serialized, + }, +}); +if (broadcastedRequest.error) { + console.log('Failed to broadcast transaction:', broadcastedRequest); + process.exit(1); +} else { + console.log('Broadcasted transaction:', broadcastedRequest.data); +} diff --git a/src/validators.ts b/src/validators.ts index 8439c40..e85f692 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -102,7 +102,7 @@ export const KILN_VALIDATORS = { }, SEI: { mainnet: { - KILN: 'seivaloper1u9xeaqdjz3kky2ymdhdsn0ra5uy9tc3eqkjc8w', + KILN: 'seivaloper1uxlf7mvr8nep3gm7udf2u9remms2jyjq6ee35g', }, }, SUI: {