Skip to content

Commit 9889abf

Browse files
LeTamanoirEllzer
authored andcommitted
simplify error messages (#186)
* cleanup example * atom example * tia example * dydx example * fet example * inj example * om example * osmo example * zeta example * ada example * improve error messages * fix lint
1 parent b8f0295 commit 9889abf

File tree

22 files changed

+1009
-557
lines changed

22 files changed

+1009
-557
lines changed

examples/.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
KILN_API_URL=""
2-
KILN_ACCOUNT_ID=""
32
KILN_API_KEY=""
4-
FIREBLOCKS_API_KEY=""
3+
KILN_ACCOUNT_ID=""
4+
FIREBLOCKS_API_KEY=""
5+
FIREBLOCKS_VAULT_ID=""

examples/ada.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Kiln, KILN_VALIDATORS } from '../src/kiln.ts';
2+
import type { FireblocksIntegration } from '../src/fireblocks.ts';
3+
import { loadEnv } from './env.ts';
4+
5+
const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } =
6+
await loadEnv();
7+
8+
const k = new Kiln({
9+
baseUrl: kilnApiUrl,
10+
apiToken: kilnApiKey,
11+
});
12+
13+
const vault: FireblocksIntegration = {
14+
config: {
15+
apiKey: fireblocksApiKey,
16+
secretKey: fireblocksApiSecret,
17+
basePath: 'https://api.fireblocks.io/v1',
18+
},
19+
vaultId: fireblocksVaultId,
20+
};
21+
22+
//
23+
// Get the pubkey from Fireblocks
24+
//
25+
const fireblocksWallet = (
26+
await k.fireblocks
27+
.getSdk(vault)
28+
.vaults.getVaultAccountAssetAddressesPaginated({ assetId: 'ADA', vaultAccountId: vault.vaultId, limit: 1 })
29+
).data.addresses?.[0].address;
30+
if (!fireblocksWallet) {
31+
console.log('Failed to get pubkey');
32+
process.exit(0);
33+
}
34+
35+
//
36+
// Craft the transaction
37+
//
38+
console.log('Crafting transaction...');
39+
const txRequest = await k.client.POST('/ada/transaction/stake', {
40+
body: {
41+
account_id: kilnAccountId,
42+
pool_id: KILN_VALIDATORS.ADA.mainnet.KILN0,
43+
wallet: fireblocksWallet,
44+
},
45+
});
46+
if (txRequest.error) {
47+
console.log('Failed to craft transaction:', txRequest);
48+
process.exit(1);
49+
} else {
50+
console.log('Crafted transaction:', txRequest.data);
51+
}
52+
console.log('\n\n\n');
53+
54+
//
55+
// Sign the transaction
56+
//
57+
console.log('Signing transaction...');
58+
const signRequest = await (async () => {
59+
try {
60+
return await k.fireblocks.signAdaTx(vault, txRequest.data.data);
61+
} catch (err) {
62+
console.log('Failed to sign transaction:', err);
63+
process.exit(1);
64+
}
65+
})();
66+
console.log('Signed transaction:', signRequest);
67+
console.log('\n\n\n');
68+
69+
//
70+
// Broadcast the transaction
71+
//
72+
console.log('Broadcasting transaction...');
73+
const broadcastedRequest = await k.client.POST('/ada/transaction/broadcast', {
74+
body: {
75+
tx_serialized: signRequest.signed_tx.data.signed_tx_serialized,
76+
},
77+
});
78+
if (broadcastedRequest.error) {
79+
console.log('Failed to broadcast transaction:', broadcastedRequest);
80+
process.exit(1);
81+
} else {
82+
console.log('Broadcasted transaction:', broadcastedRequest.data);
83+
}

examples/atom.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { atomToUatom, Kiln, KILN_VALIDATORS } from '../src/kiln.ts';
2+
import type { FireblocksIntegration } from '../src/fireblocks.ts';
3+
import { loadEnv } from './env.ts';
4+
5+
const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } =
6+
await loadEnv();
7+
8+
const k = new Kiln({
9+
baseUrl: kilnApiUrl,
10+
apiToken: kilnApiKey,
11+
});
12+
13+
const vault: FireblocksIntegration = {
14+
config: {
15+
apiKey: fireblocksApiKey,
16+
secretKey: fireblocksApiSecret,
17+
basePath: 'https://api.fireblocks.io/v1',
18+
},
19+
vaultId: fireblocksVaultId,
20+
};
21+
22+
//
23+
// Get the pubkey from Fireblocks
24+
//
25+
const fireblocksPubkey = (await k.fireblocks.getPubkey(vault, 'ATOM_COS')).publicKey;
26+
if (!fireblocksPubkey) {
27+
console.log('Failed to get pubkey');
28+
process.exit(0);
29+
}
30+
31+
//
32+
// Craft the transaction
33+
//
34+
console.log('Crafting transaction...');
35+
const txRequest = await k.client.POST('/atom/transaction/stake', {
36+
body: {
37+
account_id: kilnAccountId,
38+
pubkey: fireblocksPubkey,
39+
validator: KILN_VALIDATORS.ATOM.mainnet.KILN,
40+
amount_uatom: atomToUatom('0.01').toString(),
41+
restake_rewards: false,
42+
},
43+
});
44+
if (txRequest.error) {
45+
console.log('Failed to craft transaction:', txRequest);
46+
process.exit(1);
47+
} else {
48+
console.log('Crafted transaction:', txRequest.data);
49+
}
50+
console.log('\n\n\n');
51+
52+
//
53+
// Sign the transaction
54+
//
55+
console.log('Signing transaction...');
56+
const signRequest = await (async () => {
57+
try {
58+
return await k.fireblocks.signAtomTx(vault, txRequest.data.data);
59+
} catch (err) {
60+
console.log('Failed to sign transaction:', err);
61+
process.exit(1);
62+
}
63+
})();
64+
console.log('Signed transaction:', signRequest);
65+
console.log('\n\n\n');
66+
67+
//
68+
// Broadcast the transaction
69+
//
70+
console.log('Broadcasting transaction...');
71+
const broadcastedRequest = await k.client.POST('/atom/transaction/broadcast', {
72+
body: {
73+
tx_serialized: signRequest.signed_tx.data.signed_tx_serialized,
74+
},
75+
});
76+
if (broadcastedRequest.error) {
77+
console.log('Failed to broadcast transaction:', broadcastedRequest);
78+
process.exit(1);
79+
} else {
80+
console.log('Broadcasted transaction:', broadcastedRequest.data);
81+
}

examples/dydx.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { dydxToAdydx, Kiln, KILN_VALIDATORS } from '../src/kiln.ts';
2+
import type { FireblocksIntegration } from '../src/fireblocks.ts';
3+
import { loadEnv } from './env.ts';
4+
5+
const { kilnApiKey, kilnAccountId, kilnApiUrl, fireblocksApiKey, fireblocksApiSecret, fireblocksVaultId } =
6+
await loadEnv();
7+
8+
const k = new Kiln({
9+
baseUrl: kilnApiUrl,
10+
apiToken: kilnApiKey,
11+
});
12+
13+
const vault: FireblocksIntegration = {
14+
config: {
15+
apiKey: fireblocksApiKey,
16+
secretKey: fireblocksApiSecret,
17+
basePath: 'https://api.fireblocks.io/v1',
18+
},
19+
vaultId: fireblocksVaultId,
20+
};
21+
22+
//
23+
// Get the pubkey from Fireblocks
24+
//
25+
const fireblocksPubkey = (await k.fireblocks.getPubkey(vault, 'DYDX_DYDX')).publicKey;
26+
if (!fireblocksPubkey) {
27+
console.log('Failed to get pubkey');
28+
process.exit(0);
29+
}
30+
31+
//
32+
// Craft the transaction
33+
//
34+
console.log('Crafting transaction...');
35+
const txRequest = await k.client.POST('/dydx/transaction/stake', {
36+
body: {
37+
account_id: kilnAccountId,
38+
pubkey: fireblocksPubkey,
39+
validator: KILN_VALIDATORS.DYDX.mainnet.KILN,
40+
amount_adydx: dydxToAdydx('0.01').toString(),
41+
restake_rewards: false,
42+
},
43+
});
44+
if (txRequest.error) {
45+
console.log('Failed to craft transaction:', txRequest);
46+
process.exit(1);
47+
} else {
48+
console.log('Crafted transaction:', txRequest.data);
49+
}
50+
console.log('\n\n\n');
51+
52+
//
53+
// Sign the transaction
54+
//
55+
console.log('Signing transaction...');
56+
const signRequest = await (async () => {
57+
try {
58+
return await k.fireblocks.signDydxTx(vault, txRequest.data.data);
59+
} catch (err) {
60+
console.log('Failed to sign transaction:', err);
61+
process.exit(1);
62+
}
63+
})();
64+
console.log('Signed transaction:', signRequest);
65+
console.log('\n\n\n');
66+
67+
//
68+
// Broadcast the transaction
69+
//
70+
console.log('Broadcasting transaction...');
71+
const broadcastedRequest = await k.client.POST('/dydx/transaction/broadcast', {
72+
body: {
73+
tx_serialized: signRequest.signed_tx.data.signed_tx_serialized,
74+
},
75+
});
76+
if (broadcastedRequest.error) {
77+
console.log('Failed to broadcast transaction:', broadcastedRequest);
78+
process.exit(1);
79+
} else {
80+
console.log('Broadcasted transaction:', broadcastedRequest.data);
81+
}

examples/env.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const loadEnv = async () => {
2+
if (!Bun.env.KILN_API_URL) {
3+
console.log('KILN_API_URL is required');
4+
process.exit(1);
5+
}
6+
7+
if (!Bun.env.KILN_ACCOUNT_ID) {
8+
console.log('KILN_ACCOUNT_ID is required');
9+
process.exit(1);
10+
}
11+
12+
if (!Bun.env.KILN_API_KEY) {
13+
console.log('KILN_API_KEY is required');
14+
process.exit(1);
15+
}
16+
17+
if (!Bun.env.FIREBLOCKS_API_KEY) {
18+
console.log('FIREBLOCKS_API_KEY is required');
19+
process.exit(1);
20+
}
21+
22+
if (!Bun.env.FIREBLOCKS_VAULT_ID) {
23+
console.log('FIREBLOCKS_VAULT_ID is required');
24+
process.exit(1);
25+
}
26+
27+
const fireblocksApiSecret = await Bun.file('fireblocks_secret_prod.key').text();
28+
29+
return {
30+
kilnApiUrl: Bun.env.KILN_API_URL,
31+
kilnApiKey: Bun.env.KILN_API_KEY,
32+
kilnAccountId: Bun.env.KILN_ACCOUNT_ID,
33+
fireblocksApiKey: Bun.env.FIREBLOCKS_API_KEY,
34+
fireblocksVaultId: Bun.env.FIREBLOCKS_VAULT_ID as `${number}`,
35+
fireblocksApiSecret,
36+
};
37+
};

examples/eth.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)