|
| 1 | +import { Kiln, KILN_VALIDATORS } from '../src/kiln.ts'; |
| 2 | +import type { FireblocksIntegration } from '../src/fireblocks.ts'; |
| 3 | +import { loadEnv } from './env.ts'; |
| 4 | +import { parseUnits } from "viem"; |
| 5 | + |
| 6 | +const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } = |
| 7 | + await loadEnv(); |
| 8 | + |
| 9 | +const k = new Kiln({ |
| 10 | + baseUrl: kilnApiUrl, |
| 11 | + apiToken: kilnApiKey, |
| 12 | +}); |
| 13 | + |
| 14 | +const vault: FireblocksIntegration = { |
| 15 | + config: { |
| 16 | + apiKey: fireblocksApiKey, |
| 17 | + secretKey: fireblocksApiSecret, |
| 18 | + basePath: 'https://api.fireblocks.io/v1', |
| 19 | + }, |
| 20 | + vaultId: fireblocksVaultId, |
| 21 | +}; |
| 22 | + |
| 23 | +// |
| 24 | +// Craft the transaction |
| 25 | +// |
| 26 | +console.log('Crafting transaction...'); |
| 27 | +const txRequest = await k.client.POST('/near/transaction/stake', { |
| 28 | + body: { |
| 29 | + account_id: kilnAccountId, |
| 30 | + wallet: 'c36b1a5da2e60d1fd5d3a6b46f7399eb26571457f3272f3c978bc9527ad2335f', |
| 31 | + pool_id: KILN_VALIDATORS.NEAR.testnet.KILN, |
| 32 | + amount_yocto: parseUnits('0.1', 24).toString(), |
| 33 | + }, |
| 34 | +}); |
| 35 | +if (txRequest.error) { |
| 36 | + console.log('Failed to craft transaction:', txRequest); |
| 37 | + process.exit(1); |
| 38 | +} else { |
| 39 | + console.log('Crafted transaction:', txRequest.data); |
| 40 | +} |
| 41 | +console.log('\n\n\n'); |
| 42 | + |
| 43 | +// |
| 44 | +// Sign the transaction |
| 45 | +// |
| 46 | +console.log('Signing transaction...'); |
| 47 | +const signRequest = await (async () => { |
| 48 | + try { |
| 49 | + // @ts-ignore |
| 50 | + return await k.fireblocks.signNearTx(vault, txRequest.data.data, "NEAR_TEST"); |
| 51 | + } catch (err) { |
| 52 | + console.log('Failed to sign transaction:', err); |
| 53 | + process.exit(1); |
| 54 | + } |
| 55 | +})(); |
| 56 | +console.log('Signed transaction:', signRequest); |
| 57 | +console.log('\n\n\n'); |
| 58 | + |
| 59 | +// |
| 60 | +// Broadcast the transaction |
| 61 | +// |
| 62 | +console.log('Broadcasting transaction...'); |
| 63 | +const broadcastedRequest = await k.client.POST('/near/transaction/broadcast', { |
| 64 | + body: { |
| 65 | + signed_tx_serialized: signRequest.signed_tx.data.signed_tx_serialized, |
| 66 | + }, |
| 67 | +}); |
| 68 | +if (broadcastedRequest.error) { |
| 69 | + console.log('Failed to broadcast transaction:', broadcastedRequest); |
| 70 | + process.exit(1); |
| 71 | +} else { |
| 72 | + console.log('Broadcasted transaction:', broadcastedRequest.data); |
| 73 | +} |
0 commit comments