Skip to content

Commit 5b3640f

Browse files
committed
bond extra reference
bond extra reference
1 parent 64e6b2c commit 5b3640f

File tree

5 files changed

+121
-4
lines changed

5 files changed

+121
-4
lines changed

dot-staking/fireblocks/nodejs/README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ npm install
4343
```
4444
This will install all required packages, including the Fireblocks SDK and Blockdaemon's API interaction tools.
4545

46-
### Step 3. Launch example.ts to generate the Stake Intent request, sign the request with Fireblocks, and broadcast the transaction
46+
### Step 3. To perform a polkadot stake intent then run.
4747
```shell
48-
npm run example
48+
npm run stake
4949
```
50+
This will create the transaction to create a proxy on your account to Blockdaemons where we nominate on your behalf.
5051

51-
This will:
52+
### Step 4. To perform a bond extra
53+
```shell
54+
npm run bond
55+
```
56+
This will then bond extra funds to your already nominated pool.
5257

5358
Generate a Stake Intent request to initiate staking.
5459
Use Fireblocks to sign the transaction.

dot-staking/fireblocks/nodejs/api.ts

+38
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export type StakeIntentResponse = {
1313
stake_intent_id: string;
1414
};
1515

16+
export type BondExtraResponse = {
17+
network: string;
18+
polkadot: {
19+
customer_address: string;
20+
amount: string;
21+
unsigned_transaction: string;
22+
};
23+
protocol: string;
24+
}
25+
1626
export type DeriveTransactionResponse = {
1727
signing_payload: string;
1828
unsigned_tx: string;
@@ -27,6 +37,11 @@ export type StakeIntentRequest = {
2737
customer_address: string;
2838
};
2939

40+
export type BondExtraRequest = {
41+
customer_address: string;
42+
amount: string;
43+
};
44+
3045
export type PrepareTransactionRequest = {
3146
sender_address: string;
3247
unsigned_tx: string;
@@ -62,6 +77,29 @@ export async function fetchUnsignedTransaction(delegatorAddress: string): Promis
6277
return (await response.json()) as StakeIntentResponse;
6378
}
6479

80+
// Fetch Bond Extra
81+
export async function fetchBondExtraTransaction(delegatorAddress: string, amount: string): Promise<BondExtraResponse> {
82+
const requestBody: BondExtraRequest = { customer_address: delegatorAddress, amount: amount };
83+
const response = await fetch(
84+
`https://svc.blockdaemon.com/boss/v1/polkadot/${process.env.POLKADOT_NETWORK}/bond-extra`,
85+
{
86+
method: "POST",
87+
headers: {
88+
"Content-Type": "application/json",
89+
Accept: "application/json",
90+
"X-API-Key": process.env.BLOCKDAEMON_STAKE_API_KEY!,
91+
},
92+
body: JSON.stringify(requestBody),
93+
}
94+
);
95+
96+
if (response.status !== 200) {
97+
throw new Error(`Blockdaemon API Error: ${JSON.stringify(await response.json())}`);
98+
}
99+
100+
return (await response.json()) as BondExtraResponse;
101+
}
102+
65103
// Prepare Transaction
66104
export async function prepareTransaction(unsignedTx: string, address: string, compileAndSendUrl: string): Promise<DeriveTransactionResponse> {
67105
const requestBody: PrepareTransactionRequest = {

dot-staking/fireblocks/nodejs/bond.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import "dotenv/config";
2+
import {getFireblocksInformation, getFireblocksSignature} from "./fireblocks";
3+
import {
4+
BondExtraResponse,
5+
DeriveTransactionResponse,
6+
fetchBondExtraTransaction,
7+
fetchUnsignedTransaction,
8+
prepareTransaction,
9+
StakeIntentResponse
10+
} from "./api";
11+
import {compileAndSend} from "./api";
12+
import {CompileAndSendResponse} from "./api";
13+
14+
15+
function checkRequiredEnvVars() {
16+
const requiredVars = [
17+
'BLOCKDAEMON_STAKE_API_KEY', 'POLKADOT_NETWORK', 'FIREBLOCKS_BASE_PATH',
18+
'FIREBLOCKS_API_KEY', 'FIREBLOCKS_SECRET_KEY', 'FIREBLOCKS_VAULT_ACCOUNT_ID', 'BLOCKDAEMON_API_KEY'
19+
];
20+
21+
requiredVars.forEach(varName => {
22+
if (!process.env[varName]) {
23+
throw new Error(`${varName} environment variable not set`);
24+
}
25+
});
26+
}
27+
28+
// Determine the configuration for mainnet or testnet
29+
function getConfigForNetwork() {
30+
const network = process.env.POLKADOT_NETWORK?.toLowerCase();
31+
const isTestnet = network === 'westend';
32+
33+
return {
34+
assetID: isTestnet ? "WND" : "DOT",
35+
stakeApiUrl: isTestnet
36+
? 'https://svc.blockdaemon.com/boss/v1/polkadot/westend/bond-extra'
37+
: 'https://svc.blockdaemon.com/boss/v1/polkadot/mainnet/bond-extra',
38+
compileAndSendUrl: isTestnet
39+
? 'https://svc.blockdaemon.com/tx/v1/polkadot-westend/compile_and_send'
40+
: 'https://svc.blockdaemon.com/tx/v1/polkadot-mainnet/compile_and_send',
41+
deriveApiUrl: isTestnet
42+
? 'https://svc.blockdaemon.com/tx/v1/polkadot-westend/derive_signing_payload'
43+
: 'https://svc.blockdaemon.com/tx/v1/polkadot-mainnet/derive_signing_payload'
44+
};
45+
}
46+
47+
async function main() {
48+
checkRequiredEnvVars()
49+
const config = getConfigForNetwork()
50+
51+
const {address: sender, fireblocks} = await getFireblocksInformation(config.assetID);
52+
const amount = "1000000000000" //This is 1 DOT & the minimum
53+
54+
//Call the Staking API to get your unsigned transaction
55+
const apiResponse: BondExtraResponse = await fetchBondExtraTransaction(sender, amount);
56+
console.log("Blockdaemon Staking API Response::", apiResponse);
57+
58+
//Call our tx lifecycle API to derive the payload to send to fireblocks
59+
const deriveTransactionResponse: DeriveTransactionResponse = await prepareTransaction(apiResponse.polkadot.unsigned_transaction, apiResponse.polkadot.customer_address, config.deriveApiUrl)
60+
61+
//Call and sign the transaction in fireblocks
62+
const {signature, pubKey} = await getFireblocksSignature(
63+
fireblocks,
64+
process.env.FIREBLOCKS_VAULT_ACCOUNT_ID!,
65+
"WND",
66+
deriveTransactionResponse.signing_payload
67+
);
68+
69+
//Take the signature, pubkey and unsigned transaction and broadcast to the network
70+
await compileAndSend(deriveTransactionResponse.unsigned_tx, signature, pubKey, config.compileAndSendUrl);
71+
}
72+
73+
main().catch(console.error);

dot-staking/fireblocks/nodejs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"type": "module",
1111
"scripts": {
1212
"start": "node --no-warnings=ExperimentalWarning --loader ts-node/esm",
13-
"example": "node --loader ts-node/esm example.ts"
13+
"stake": "node --loader ts-node/esm stake.ts",
14+
"bond": "node --loader ts-node/esm bond.ts"
1415
},
1516
"exclude": ["node_modules"]
1617
}

0 commit comments

Comments
 (0)