|
| 1 | +import { omToUom, Kiln } from '../src/kiln.ts'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import 'dotenv/config'; |
| 4 | +import type { FireblocksIntegration } from '../src/fireblocks.ts'; |
| 5 | + |
| 6 | +const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret_prod.key`, 'utf8'); |
| 7 | + |
| 8 | +const k = new Kiln({ |
| 9 | + baseUrl: process.env.KILN_API_URL as string, |
| 10 | + apiToken: process.env.KILN_API_KEY as string, |
| 11 | +}); |
| 12 | + |
| 13 | +const vault: FireblocksIntegration = { |
| 14 | + provider: 'fireblocks', |
| 15 | + fireblocksApiKey: process.env.FIREBLOCKS_API_KEY as string, |
| 16 | + fireblocksSecretKey: apiSecret, |
| 17 | + vaultId: 17, |
| 18 | +}; |
| 19 | + |
| 20 | +try { |
| 21 | + console.log('crafting...'); |
| 22 | + const tx = await k.client.POST('/mantra/transaction/stake', { |
| 23 | + body: { |
| 24 | + account_id: process.env.KILN_ACCOUNT_ID as string, |
| 25 | + pubkey: '028dfa6f41c655e38a0f8f2e3f3aa3e1246907a9bb299933f11996e2a345a21e10', |
| 26 | + validator: 'mantravaloper146mj09yzu3mvz7pmy4dvs4z9wr2mst7ram37xw', |
| 27 | + amount_uom: omToUom('0.01').toString(), |
| 28 | + }, |
| 29 | + }); |
| 30 | + |
| 31 | + console.log(tx); |
| 32 | + console.log('signing...'); |
| 33 | + if (!tx.data?.data) throw new Error('No data in response'); |
| 34 | + const signResponse = await k.fireblocks.signMantraTx(vault, tx.data.data); |
| 35 | + console.log('broadcasting...'); |
| 36 | + if (!signResponse.signed_tx?.data?.signed_tx_serialized) throw new Error('No signed_tx in response'); |
| 37 | + const broadcastedTx = await k.client.POST('/mantra/transaction/broadcast', { |
| 38 | + body: { |
| 39 | + tx_serialized: signResponse.signed_tx.data.signed_tx_serialized, |
| 40 | + }, |
| 41 | + }); |
| 42 | + console.log(broadcastedTx); |
| 43 | +} catch (err) { |
| 44 | + console.log(err); |
| 45 | +} |
0 commit comments