Skip to content

Commit 5f49093

Browse files
committed
BA SDK
1 parent cb1aea9 commit 5f49093

File tree

9 files changed

+347
-1
lines changed

9 files changed

+347
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: BA SDK
3+
sidebar_label: BA SDK
4+
sidebar_position: 1
5+
---
6+
7+
:::warning
8+
The BA SDK is currently undergoing development and is subject to change.
9+
:::
10+
11+
12+
## Overview
13+
14+
The BA SDK is a TypeScript library that allows developers to work with the Based Applications.
15+
16+
It provides a set of functions for creating and managing based applications by interacting with the [BasedAppManager](./smart-contracts/BasedAppManager.md) smart contract.
17+
18+
## Installation
19+
20+
```bash
21+
npm i @ssv-labs/based-apps-sdk
22+
```
23+
24+
## Example Usage
25+
26+
```typescript
27+
import { BasedAppsSDK } from "@ssv-labs/based-apps-sdk";
28+
29+
const sdk = new BasedAppsSDK({
30+
chain: 17000,
31+
});
32+
33+
async function main(): Promise<void> {
34+
35+
const obligatedBalances = await sdk.api.getObligatedBalances({
36+
bAppId: "0x64714cf5db177398729e37627be0fc08f43b17a6",
37+
});
38+
39+
console.log("--------------------------------");
40+
console.log(obligatedBalances);
41+
console.log("--------------------------------");
42+
43+
}
44+
45+
main();
46+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Examples
6+
7+
In this examples section we will provide quick snippets of code to do certain actions, we will not show the imports/setup for each as this is covered previously.
8+
9+
Each example will also be available in an executable typescript file found in the SDK repo.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Module Reference
6+
7+
### Core Modules
8+
9+
The SDK consists of three main modules:
10+
11+
* [**BAM Module**](bam-module.md): Make calls to the BasedAppManager contract
12+
* [**API Module**](api-module.md): Access based applications data, query states, and retrieve operational information
13+
* [**Utils Module**](utils-module.md): Helper functions for returning strategy weights and other utilities
14+
15+
### Contract Calls
16+
17+
All of the functions within the BAM module are smart contract calls, this means that the return value of these will be the transaction receipt. As shown in the examples, this receipt can be stored to a variable and accessed to get values such as the transaction hash.
18+
19+
```bash
20+
{
21+
"blockHash": "0x9e0a0b0a5296571b4e573b1cb8b23201575e0e5c9cde9e3a10b34fa2e8b0d401",
22+
"blockNumber": 17283901,
23+
"contractAddress": null,
24+
"cumulativeGasUsed": 21000,
25+
"effectiveGasPrice": "20000000000",
26+
"from": "0xYourWalletAddress",
27+
"gasUsed": 21000,
28+
"logs": [],
29+
"logsBloom": "0x000000000000000000000...",
30+
"status": 1,
31+
"to": "0xRecipientAddressHere",
32+
"transactionHash": "0xTxHashHere",
33+
"transactionIndex": 0,
34+
"type": "0x2"
35+
}
36+
```
37+
38+
### Transaction Parameters
39+
40+
For each function that performs a contract call, we can include additional custom arguments alongside the function parameters. This allows us to modify the transaction details in the same way we would customize any Ethereum transaction before sending it.
41+
42+
An example of this can be seen here where we update the gas limit like so:
43+
44+
45+
```typescript
46+
const tx = await sdk.bam.registerBapp({
47+
args: {
48+
keyshares: available,
49+
depositAmount: parseEther('10'),
50+
},
51+
gas: 1000000n,
52+
})
53+
```
54+
55+
### Parameter List
56+
57+
Below is a list of parameters that can be included within the transaction, for more details you can check [Viem's page on transaction parameters](https://viem.sh/docs/actions/wallet/sendTransaction.html#parameters).
58+
59+
```typescript
60+
gas: number,
61+
gasPrice: bigint,
62+
maxFeePerGas: bigint,
63+
maxPriorityFeePerGas: bigint,
64+
nonce: number,
65+
value: bigint,
66+
chain: Chain,
67+
account: Account,
68+
chain: Chain,
69+
accessList: AccessList,
70+
```
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# API Module
6+
7+
This is a read only library which contains all the functions you need to obtain any data relating to Based Applications.
8+
9+
After instantiating the SDK, you can call any of the functions in the utils library like so:
10+
11+
```typescript
12+
sdk.api.getValidatorsBalance()
13+
```
14+
15+
## Function List
16+
17+
### `getValidatorsBalance()`
18+
19+
Given the address of an account, returns the balance of all the validators that the account owns.
20+
21+
Input:
22+
23+
| Input parameter | Input type | Description | Example input |
24+
| ----------------- | ---------- | ----------------------------- | -------------------------------------------- |
25+
| account | string | Address of the Based Application | '0x64714cf5db177398729e37627be0fc08f43b17a6' |
26+
27+
Example:
28+
29+
```typescript
30+
const validatorBalance = await sdk.api.getValidatorsBalance({
31+
account: '0x77fc6e8b24a623725d935bc88057098d0bca6eb3',
32+
});
33+
```
34+
35+
Example output:
36+
37+
```bash
38+
{
39+
account: '0x77fc6e8b24a623725d935bc88057098d0bca6eb3',
40+
validators: [],
41+
balance: '0'
42+
}
43+
```
44+
45+
### `getBappSlashableBalance(string bappAddress)`
46+
47+
Given the address of a Based Application, returns the slashable balance of the Bapp.
48+
49+
Input:
50+
51+
| Input parameter | Input type | Description | Example input |
52+
| ----------------- | ---------- | ----------------------------- | -------------------------------------------- |
53+
| bappId | string | Address of the Based Application | '0x64714cf5db177398729e37627be0fc08f43b17a6' |
54+
55+
Example:
56+
57+
```typescript
58+
const getBappSlashableBalance = await sdk.api.getBappSlashableBalance({
59+
bAppId: "0x64714cf5db177398729e37627be0fc08f43b17a6",
60+
});
61+
```
62+
63+
Example output:
64+
65+
```bash
66+
[
67+
{
68+
token: '0x68a8ddd7a59a900e0657e9f8bbe02b70c947f25f',
69+
balance: 97110000000000000000n
70+
}
71+
]
72+
```
73+
74+
### `getStrategyTokenWeights(string bappAddress)`
75+
76+
Used to calculate the weights of the strategies in a given Bapp.
77+
78+
Input:
79+
80+
| Input parameter | Input type | Description | Example input |
81+
| ----------------- | ---------- | ----------------------------- | -------------------------------------------- |
82+
| bappId | string | Address of the Based Application | '0x64714cf5db177398729e37627be0fc08f43b17a6' |
83+
84+
Example:
85+
86+
```typescript
87+
const weights = await sdk.api.getStrategyTokenWeights({
88+
bAppId: "0x64714cf5db177398729e37627be0fc08f43b17a6",
89+
});
90+
```
91+
92+
Example output:
93+
94+
```bash
95+
[
96+
{ id: '10', tokenWeights: [ [Object] ] },
97+
{ id: '2', tokenWeights: [ [Object] ], validatorBalanceWeight: 1 }
98+
]
99+
```
100+
101+
### `getDelegatedBalances(string bappAddress)`
102+
103+
Given the address of a Based Application, returns the delegated balances of the Bapp.
104+
105+
Input:
106+
107+
| Input parameter | Input type | Description | Example input |
108+
| ----------------- | ---------- | ----------------------------- | -------------------------------------------- |
109+
| bappId | string | Address of the Based Application | '0x64714cf5db177398729e37627be0fc08f43b17a6' |
110+
111+
Example:
112+
113+
```typescript
114+
const delegatedBalances = await sdk.api.getDelegatedBalances({
115+
bAppId: "0x64714cf5db177398729e37627be0fc08f43b17a6",
116+
});
117+
```
118+
119+
Example output:
120+
121+
```bash
122+
{
123+
bAppTotalDelegatedBalance: 3297628317780000000000n,
124+
bAppTotalDelegatedBalances: [
125+
{ strategyId: '10', delegation: 3201611238600000000000n },
126+
{ strategyId: '2', delegation: 96017079180000000000n }
127+
]
128+
}
129+
```
130+
131+
### `getObligatedBalances(string bappAddress)`
132+
133+
Given the address of a Based Application, returns the obligated balances of the Bapp.
134+
135+
Input:
136+
137+
| Input parameter | Input type | Description | Example input |
138+
| ----------------- | ---------- | ----------------------------- | -------------------------------------------- |
139+
| bappId | string | Address of the Based Application | '0x64714cf5db177398729e37627be0fc08f43b17a6' |
140+
141+
Example:
142+
143+
```typescript
144+
const obligatedBalances = await sdk.api.getObligatedBalances({
145+
bAppId: "0x64714cf5db177398729e37627be0fc08f43b17a6",
146+
});
147+
```
148+
149+
Example output:
150+
151+
```bash
152+
{
153+
bAppTokens: [
154+
{
155+
totalObligatedBalance: '971100000000000000009000',
156+
token: '0x68a8ddd7a59a900e0657e9f8bbe02b70c947f25f'
157+
},
158+
{
159+
totalObligatedBalance: '0',
160+
token: '0x9196830bb4c05504e0a8475a0ad566aceeb6bec9'
161+
}
162+
],
163+
strategies: [
164+
{
165+
id: '100x64714cf5db177398729e37627be0fc08f43b17a6',
166+
obligations: [Array]
167+
},
168+
{
169+
id: '20x64714cf5db177398729e37627be0fc08f43b17a6',
170+
obligations: [Array]
171+
}
172+
]
173+
}
174+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# BAM Module
6+
7+
:::warning
8+
🚧 BAM Module is under construction 🚧
9+
:::
10+
11+
12+
This is a library which contains all the BasedAppManager functions you need for working with Based Applications, such as registering a based application.
13+
14+
After instantiating the SDK, you can call any of the functions in the utils library like so:
15+
16+
```typescript
17+
sdk.bam.registerBapp()
18+
```
19+
20+
## Function List
21+
22+
### `registerBapp()`
23+
24+
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Utils Module
2+
3+
:::warning
4+
🚧 Utils Module is under construction 🚧
5+
:::
6+
7+
This is a library which contains all the helper functions you need for working with Based Applications, such as getting strategy weights.
8+
9+
After instantiating the SDK, you can call any of the functions in the utils library like so:
10+
11+
```typescript
12+
sdk.utils.getStrategyWeights()
13+
```
14+
15+
## Function List
16+
17+
### `getStrategyWeights()`
18+
19+
20+
21+
22+

docs/developers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A set of calls to get information about the SSV network.
4343

4444
Validators are managed within Clusters - the group of operators that were selected to operate them.
4545

46-
:::hint
46+
:::info
4747
You must have a validator key to carry out this process, they can be generated programmatically by [as shown in this example](ssv-sdk/examples/create-validator-keys).
4848

4949
**Multiple validators can be registered in a single transaction.**

0 commit comments

Comments
 (0)