@fepvenancio/stela-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # stela-sdk
2
+
3
+ TypeScript SDK for the **Stela** P2P lending protocol on StarkNet.
4
+
5
+ Stela enables peer-to-peer lending through on-chain inscriptions. Borrowers post collateral and request loans; lenders sign inscriptions to fund them. The protocol manages collateral locking via token-bound locker accounts, multi-lender share accounting through ERC1155 tokens, and automated liquidation of expired positions.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add stela-sdk starknet
11
+ ```
12
+
13
+ ```bash
14
+ npm install stela-sdk starknet
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ### Read an Inscription
20
+
21
+ ```typescript
22
+ import { STELA_ADDRESS, type StoredInscription } from 'stela-sdk'
23
+ import { RpcProvider, Contract } from 'starknet'
24
+ import stelaAbi from 'stela-sdk/src/abi/stela.json'
25
+
26
+ const provider = new RpcProvider({ nodeUrl: 'https://starknet-sepolia.public.blastapi.io' })
27
+ const contract = new Contract(stelaAbi, STELA_ADDRESS.sepolia, provider)
28
+
29
+ const inscription: StoredInscription = await contract.get_inscription(inscriptionId)
30
+ ```
31
+
32
+ ### Create an Inscription
33
+
34
+ ```typescript
35
+ import { STELA_ADDRESS, type InscriptionParams, ASSET_TYPE_ENUM } from 'stela-sdk'
36
+ import { Account, Contract } from 'starknet'
37
+ import stelaAbi from 'stela-sdk/src/abi/stela.json'
38
+
39
+ const contract = new Contract(stelaAbi, STELA_ADDRESS.sepolia, account)
40
+
41
+ const params: InscriptionParams = {
42
+ is_borrow: true,
43
+ debt_assets: [{
44
+ asset_address: '0x049d36...', // ETH address
45
+ asset_type: 'ERC20',
46
+ value: 1000000000000000000n, // 1 ETH
47
+ token_id: 0n,
48
+ }],
49
+ interest_assets: [{
50
+ asset_address: '0x049d36...',
51
+ asset_type: 'ERC20',
52
+ value: 50000000000000000n, // 0.05 ETH interest
53
+ token_id: 0n,
54
+ }],
55
+ collateral_assets: [{
56
+ asset_address: '0x053c91...',
57
+ asset_type: 'ERC20',
58
+ value: 2000000000000000000n, // 2x collateral
59
+ token_id: 0n,
60
+ }],
61
+ duration: 604800n, // 7 days
62
+ deadline: BigInt(Math.floor(Date.now() / 1000) + 86400), // 24h to fill
63
+ multi_lender: false,
64
+ }
65
+
66
+ const txHash = await contract.create_inscription(params)
67
+ ```
68
+
69
+ ### Sign an Inscription (Lend)
70
+
71
+ ```typescript
72
+ const MAX_BPS = 10_000n // 100%
73
+ await contract.sign_inscription(inscriptionId, MAX_BPS)
74
+ ```
75
+
76
+ ## Locker Account
77
+
78
+ When collateral is locked, it is held in a token-bound locker account. The locker restricts asset transfers but allows governance interactions (voting, staking, etc.) through the `__execute__` interface.
79
+
80
+ ```typescript
81
+ import { type LockerState } from 'stela-sdk'
82
+ import lockerAbi from 'stela-sdk/src/abi/locker.json'
83
+
84
+ // Get locker address for an inscription
85
+ const lockerAddress = await stelaContract.get_locker(inscriptionId)
86
+
87
+ // Check if locker is unlocked
88
+ const lockerContract = new Contract(lockerAbi, lockerAddress, provider)
89
+ const isUnlocked = await lockerContract.is_unlocked()
90
+
91
+ // Execute governance calls through the locker (borrower only, non-transfer calls)
92
+ await lockerContract.__execute__([{
93
+ to: governanceTokenAddress,
94
+ selector: selectorFromName('vote'),
95
+ calldata: [proposalId, voteDirection],
96
+ }])
97
+ ```
98
+
99
+ ## API Types
100
+
101
+ The SDK exports types matching the Stela indexer API responses for use with fetch or API clients:
102
+
103
+ ```typescript
104
+ import type { InscriptionRow, ApiListResponse, AssetRow } from 'stela-sdk'
105
+
106
+ const response = await fetch('https://api.stela.xyz/api/inscriptions?status=open')
107
+ const data: ApiListResponse<InscriptionRow> = await response.json()
108
+
109
+ for (const inscription of data.data) {
110
+ console.log(inscription.id, inscription.status, inscription.assets.length)
111
+ }
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### Types
117
+
118
+ | Type | Description |
119
+ |------|-------------|
120
+ | `Asset` | Token within an inscription (address, type, value, token_id) |
121
+ | `InscriptionParams` | Parameters for `create_inscription` |
122
+ | `StoredInscription` | Raw on-chain inscription data |
123
+ | `Inscription` | Parsed inscription with computed status |
124
+ | `InscriptionRow` | API response row for inscription list |
125
+ | `AssetRow` | API response row for inscription assets |
126
+ | `ApiListResponse<T>` | Paginated list response envelope |
127
+ | `ApiDetailResponse<T>` | Single item response envelope |
128
+ | `StelaEvent` | Discriminated union of all protocol events |
129
+ | `LockerState` | Locker account state (address + unlock status) |
130
+ | `LockerCall` | Call to execute through a locker |
131
+
132
+ ### Constants
133
+
134
+ | Export | Description |
135
+ |--------|-------------|
136
+ | `STELA_ADDRESS` | Contract addresses per network |
137
+ | `resolveNetwork(raw?)` | Validate/default network string |
138
+ | `MAX_BPS` | 10,000n (100% in basis points) |
139
+ | `VIRTUAL_SHARE_OFFSET` | 1e16n (share calculation offset) |
140
+ | `ASSET_TYPE_ENUM` | AssetType to numeric enum mapping |
141
+ | `ASSET_TYPE_NAMES` | Numeric enum to AssetType mapping |
142
+ | `VALID_STATUSES` | Array of all valid inscription statuses |
143
+ | `STATUS_LABELS` | Human-readable status labels |
144
+
145
+ ### ABIs
146
+
147
+ | File | Contents |
148
+ |------|----------|
149
+ | `src/abi/stela.json` | Full Stela protocol ABI (IStelaProtocol + ERC1155 + Ownable) |
150
+ | `src/abi/erc20.json` | Minimal ERC20 ABI (approve, balanceOf, allowance) |
151
+ | `src/abi/locker.json` | Locker account ABI (__execute__, is_unlocked) |
152
+
153
+ ## License
154
+
155
+ MIT