-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
f3b6334
commit da62394
Showing
22 changed files
with
1,009 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
KILN_API_URL="" | ||
KILN_ACCOUNT_ID="" | ||
KILN_API_KEY="" | ||
FIREBLOCKS_API_KEY="" | ||
KILN_ACCOUNT_ID="" | ||
FIREBLOCKS_API_KEY="" | ||
FIREBLOCKS_VAULT_ID="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Kiln, KILN_VALIDATORS } 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 pubkey from Fireblocks | ||
// | ||
const fireblocksWallet = ( | ||
await k.fireblocks | ||
.getSdk(vault) | ||
.vaults.getVaultAccountAssetAddressesPaginated({ assetId: 'ADA', vaultAccountId: vault.vaultId, limit: 1 }) | ||
).data.addresses?.[0].address; | ||
if (!fireblocksWallet) { | ||
console.log('Failed to get pubkey'); | ||
process.exit(0); | ||
} | ||
|
||
// | ||
// Craft the transaction | ||
// | ||
console.log('Crafting transaction...'); | ||
const txRequest = await k.client.POST('/ada/transaction/stake', { | ||
body: { | ||
account_id: kilnAccountId, | ||
pool_id: KILN_VALIDATORS.ADA.mainnet.KILN0, | ||
wallet: fireblocksWallet, | ||
}, | ||
}); | ||
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.signAdaTx(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('/ada/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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { atomToUatom, Kiln, KILN_VALIDATORS } 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 pubkey from Fireblocks | ||
// | ||
const fireblocksPubkey = (await k.fireblocks.getPubkey(vault, 'ATOM_COS')).publicKey; | ||
if (!fireblocksPubkey) { | ||
console.log('Failed to get pubkey'); | ||
process.exit(0); | ||
} | ||
|
||
// | ||
// Craft the transaction | ||
// | ||
console.log('Crafting transaction...'); | ||
const txRequest = await k.client.POST('/atom/transaction/stake', { | ||
body: { | ||
account_id: kilnAccountId, | ||
pubkey: fireblocksPubkey, | ||
validator: KILN_VALIDATORS.ATOM.mainnet.KILN, | ||
amount_uatom: atomToUatom('0.01').toString(), | ||
restake_rewards: false, | ||
}, | ||
}); | ||
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.signAtomTx(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('/atom/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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { dydxToAdydx, Kiln, KILN_VALIDATORS } 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 pubkey from Fireblocks | ||
// | ||
const fireblocksPubkey = (await k.fireblocks.getPubkey(vault, 'DYDX_DYDX')).publicKey; | ||
if (!fireblocksPubkey) { | ||
console.log('Failed to get pubkey'); | ||
process.exit(0); | ||
} | ||
|
||
// | ||
// Craft the transaction | ||
// | ||
console.log('Crafting transaction...'); | ||
const txRequest = await k.client.POST('/dydx/transaction/stake', { | ||
body: { | ||
account_id: kilnAccountId, | ||
pubkey: fireblocksPubkey, | ||
validator: KILN_VALIDATORS.DYDX.mainnet.KILN, | ||
amount_adydx: dydxToAdydx('0.01').toString(), | ||
restake_rewards: false, | ||
}, | ||
}); | ||
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.signDydxTx(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('/dydx/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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export const loadEnv = async () => { | ||
if (!Bun.env.KILN_API_URL) { | ||
console.log('KILN_API_URL is required'); | ||
process.exit(1); | ||
} | ||
|
||
if (!Bun.env.KILN_ACCOUNT_ID) { | ||
console.log('KILN_ACCOUNT_ID is required'); | ||
process.exit(1); | ||
} | ||
|
||
if (!Bun.env.KILN_API_KEY) { | ||
console.log('KILN_API_KEY is required'); | ||
process.exit(1); | ||
} | ||
|
||
if (!Bun.env.FIREBLOCKS_API_KEY) { | ||
console.log('FIREBLOCKS_API_KEY is required'); | ||
process.exit(1); | ||
} | ||
|
||
if (!Bun.env.FIREBLOCKS_VAULT_ID) { | ||
console.log('FIREBLOCKS_VAULT_ID is required'); | ||
process.exit(1); | ||
} | ||
|
||
const fireblocksApiSecret = await Bun.file('fireblocks_secret_prod.key').text(); | ||
|
||
return { | ||
kilnApiUrl: Bun.env.KILN_API_URL, | ||
kilnApiKey: Bun.env.KILN_API_KEY, | ||
kilnAccountId: Bun.env.KILN_ACCOUNT_ID, | ||
fireblocksApiKey: Bun.env.FIREBLOCKS_API_KEY, | ||
fireblocksVaultId: Bun.env.FIREBLOCKS_VAULT_ID as `${number}`, | ||
fireblocksApiSecret, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.