timefi-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AdekunleBamz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # timefi-sdk
2
+
3
+ The official JavaScript SDK for interacting with the **TimeFi Protocol** on the Stacks blockchain.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/timefi-sdk.svg)](https://www.npmjs.com/package/timefi-sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## 🚀 Features
9
+
10
+ - **Protocol Client**: Easy-to-use `TimeFiClient` for read and write interactions.
11
+ - **On-chain Data**: Fetch TVL, vault status, and lock durations directly from smart contracts.
12
+ - **Formatting Utilities**: Standardized formatting for STX (microSTX to STX), addresses, and dates.
13
+ - **Mainnet/Testnet Support**: Unified interface for both networks.
14
+
15
+ ## 📦 Installation
16
+
17
+ ```bash
18
+ npm install timefi-sdk
19
+ ```
20
+
21
+ ## 🛠️ Quick Start
22
+
23
+ ### Fetch Protocol Stats
24
+
25
+ ```javascript
26
+ import { TimeFiClient, formatSTX } from '@timefi/sdk';
27
+
28
+ // Initialize for Stacks Mainnet
29
+ const client = new TimeFiClient('mainnet');
30
+
31
+ // Get Total Value Locked
32
+ const tvl = await client.getTVL();
33
+ console.log(`Current TVL: ${formatSTX(tvl)} STX`);
34
+ ```
35
+
36
+ ### Format a Stacks Address
37
+
38
+ ```javascript
39
+ import { formatAddress } from '@timefi/sdk';
40
+
41
+ const shortAddress = formatAddress('SP3...XYZ123');
42
+ console.log(shortAddress); // SP3...Z123
43
+ ```
44
+
45
+ ## 📖 Documentation
46
+
47
+ The SDK provides the following exports:
48
+
49
+ - `TimeFiClient`: Core class for blockchain interactions.
50
+ - `formatSTX(microStx)`: Converts microSTX to a human-readable STX string.
51
+ - `formatAddress(address)`: Truncates addresses for UI display.
52
+ - `CONTRACT_ADDRESS`: The main TimeFi Protocol contract address on Stacks.
53
+
54
+ ## 📄 License
55
+
56
+ MIT © [AdekunleBamz](https://github.com/AdekunleBamz)
@@ -0,0 +1,111 @@
1
+ import { callReadOnlyFunction as u, cvToValue as s, uintCV as o, PostConditionMode as c, AnchorMode as l } from "@stacks/transactions";
2
+ import { AnchorMode as k, PostConditionMode as D, bufferCV as E, noneCV as _, principalCV as v, responseErrorCV as S, responseOkCV as L, someCV as F, stringAsciiCV as G, stringUtf8CV as P, uintCV as H } from "@stacks/transactions";
3
+ import { StacksMainnet as d, StacksTestnet as f } from "@stacks/network";
4
+ const m = "SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N", i = {
5
+ VAULT: "timefi-vault-v-A2",
6
+ REWARDS: "timefi-rewards-v-A2",
7
+ GOVERNANCE: "timefi-governance-v-A2",
8
+ EMERGENCY: "timefi-emergency-v-A2"
9
+ }, g = {
10
+ MONTH_1: { label: "1 Month", blocks: 4320, apy: 1 },
11
+ MONTH_3: { label: "3 Months", blocks: 12960, apy: 3 },
12
+ MONTH_6: { label: "6 Months", blocks: 25920, apy: 6 },
13
+ MONTH_9: { label: "9 Months", blocks: 38880, apy: 9 },
14
+ YEAR_1: { label: "1 Year", blocks: 52560, apy: 12 }
15
+ }, M = 0.01, C = 1e6, w = (t) => {
16
+ if (t == null) return "0.000000";
17
+ try {
18
+ const n = typeof t == "object" && t !== null && "value" in t ? t.value : t;
19
+ return (Number(n) / 1e6).toLocaleString(void 0, {
20
+ minimumFractionDigits: 0,
21
+ maximumFractionDigits: 6
22
+ });
23
+ } catch (n) {
24
+ return console.error("Error formatting STX:", n), "0.000000";
25
+ }
26
+ }, N = (t, n = 4, r = 4) => t ? t.length <= n + r ? t : `${t.slice(0, n + 2)}...${t.slice(-r)}` : "", T = (t) => t == null ? "0" : Number(t).toLocaleString(), p = (t, n = 2) => t == null ? "0%" : (t * 100).toFixed(n) + "%", h = (t) => t ? new Date(t).toLocaleDateString(void 0, {
27
+ year: "numeric",
28
+ month: "short",
29
+ day: "numeric"
30
+ }) : "--", O = (t) => {
31
+ if (!t) return "--";
32
+ const n = /* @__PURE__ */ new Date(), r = new Date(t), e = Math.floor((n - r) / 1e3);
33
+ return e < 60 ? "just now" : e < 3600 ? `${Math.floor(e / 60)}m ago` : e < 86400 ? `${Math.floor(e / 3600)}h ago` : e < 604800 ? `${Math.floor(e / 86400)}d ago` : h(t);
34
+ };
35
+ class R {
36
+ constructor(n = "mainnet") {
37
+ this.network = n === "mainnet" ? new d() : new f(), this.contractAddress = m;
38
+ }
39
+ // --- Read-only Methods ---
40
+ async callReadOnly(n, r = [], e) {
41
+ const a = await u({
42
+ contractAddress: this.contractAddress,
43
+ contractName: i.VAULT,
44
+ functionName: n,
45
+ functionArgs: r,
46
+ network: this.network,
47
+ senderAddress: e || this.contractAddress
48
+ });
49
+ return a.type === 7 || a.type === 8 ? s(a.value) : s(a);
50
+ }
51
+ async getVault(n) {
52
+ return this.callReadOnly("get-vault", [o(n)]);
53
+ }
54
+ async getTimeRemaining(n) {
55
+ return this.callReadOnly("get-time-remaining", [o(n)]);
56
+ }
57
+ async canWithdraw(n) {
58
+ return this.callReadOnly("can-withdraw", [o(n)]);
59
+ }
60
+ async getTVL() {
61
+ return this.callReadOnly("get-tvl", []);
62
+ }
63
+ // --- Transaction Signing Options Helpers ---
64
+ getCreateVaultOptions(n, r) {
65
+ return {
66
+ contractAddress: this.contractAddress,
67
+ contractName: i.VAULT,
68
+ functionName: "create-vault",
69
+ functionArgs: [o(n * 1e6), o(r)],
70
+ network: this.network,
71
+ anchorMode: l.Any,
72
+ postConditionMode: c.Deny
73
+ };
74
+ }
75
+ getWithdrawOptions(n) {
76
+ return {
77
+ contractAddress: this.contractAddress,
78
+ contractName: i.VAULT,
79
+ functionName: "request-withdraw",
80
+ functionArgs: [o(n)],
81
+ network: this.network,
82
+ anchorMode: l.Any,
83
+ postConditionMode: c.Deny
84
+ };
85
+ }
86
+ }
87
+ export {
88
+ k as AnchorMode,
89
+ m as CONTRACT_ADDRESS,
90
+ i as CONTRACT_NAMES,
91
+ g as LOCK_PERIODS,
92
+ C as MAX_DEPOSIT,
93
+ M as MIN_DEPOSIT,
94
+ D as PostConditionMode,
95
+ R as TimeFiClient,
96
+ E as bufferCV,
97
+ N as formatAddress,
98
+ h as formatDate,
99
+ T as formatNumber,
100
+ p as formatPercent,
101
+ O as formatRelativeTime,
102
+ w as formatSTX,
103
+ _ as noneCV,
104
+ v as principalCV,
105
+ S as responseErrorCV,
106
+ L as responseOkCV,
107
+ F as someCV,
108
+ G as stringAsciiCV,
109
+ P as stringUtf8CV,
110
+ H as uintCV
111
+ };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@stacks/transactions"),s=require("@stacks/network"),c="SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N",a={VAULT:"timefi-vault-v-A2",REWARDS:"timefi-rewards-v-A2",GOVERNANCE:"timefi-governance-v-A2",EMERGENCY:"timefi-emergency-v-A2"},l={MONTH_1:{label:"1 Month",blocks:4320,apy:1},MONTH_3:{label:"3 Months",blocks:12960,apy:3},MONTH_6:{label:"6 Months",blocks:25920,apy:6},MONTH_9:{label:"9 Months",blocks:38880,apy:9},YEAR_1:{label:"1 Year",blocks:52560,apy:12}},d=.01,f=1e6,m=e=>{if(e==null)return"0.000000";try{const t=typeof e=="object"&&e!==null&&"value"in e?e.value:e;return(Number(t)/1e6).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:6})}catch(t){return console.error("Error formatting STX:",t),"0.000000"}},C=(e,t=4,o=4)=>e?e.length<=t+o?e:`${e.slice(0,t+2)}...${e.slice(-o)}`:"",b=e=>e==null?"0":Number(e).toLocaleString(),g=(e,t=2)=>e==null?"0%":(e*100).toFixed(t)+"%",u=e=>e?new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):"--",A=e=>{if(!e)return"--";const t=new Date,o=new Date(e),r=Math.floor((t-o)/1e3);return r<60?"just now":r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:r<604800?`${Math.floor(r/86400)}d ago`:u(e)};class y{constructor(t="mainnet"){this.network=t==="mainnet"?new s.StacksMainnet:new s.StacksTestnet,this.contractAddress=c}async callReadOnly(t,o=[],r){const i=await n.callReadOnlyFunction({contractAddress:this.contractAddress,contractName:a.VAULT,functionName:t,functionArgs:o,network:this.network,senderAddress:r||this.contractAddress});return i.type===7||i.type===8?n.cvToValue(i.value):n.cvToValue(i)}async getVault(t){return this.callReadOnly("get-vault",[n.uintCV(t)])}async getTimeRemaining(t){return this.callReadOnly("get-time-remaining",[n.uintCV(t)])}async canWithdraw(t){return this.callReadOnly("can-withdraw",[n.uintCV(t)])}async getTVL(){return this.callReadOnly("get-tvl",[])}getCreateVaultOptions(t,o){return{contractAddress:this.contractAddress,contractName:a.VAULT,functionName:"create-vault",functionArgs:[n.uintCV(t*1e6),n.uintCV(o)],network:this.network,anchorMode:n.AnchorMode.Any,postConditionMode:n.PostConditionMode.Deny}}getWithdrawOptions(t){return{contractAddress:this.contractAddress,contractName:a.VAULT,functionName:"request-withdraw",functionArgs:[n.uintCV(t)],network:this.network,anchorMode:n.AnchorMode.Any,postConditionMode:n.PostConditionMode.Deny}}}Object.defineProperty(exports,"AnchorMode",{enumerable:!0,get:()=>n.AnchorMode});Object.defineProperty(exports,"PostConditionMode",{enumerable:!0,get:()=>n.PostConditionMode});Object.defineProperty(exports,"bufferCV",{enumerable:!0,get:()=>n.bufferCV});Object.defineProperty(exports,"noneCV",{enumerable:!0,get:()=>n.noneCV});Object.defineProperty(exports,"principalCV",{enumerable:!0,get:()=>n.principalCV});Object.defineProperty(exports,"responseErrorCV",{enumerable:!0,get:()=>n.responseErrorCV});Object.defineProperty(exports,"responseOkCV",{enumerable:!0,get:()=>n.responseOkCV});Object.defineProperty(exports,"someCV",{enumerable:!0,get:()=>n.someCV});Object.defineProperty(exports,"stringAsciiCV",{enumerable:!0,get:()=>n.stringAsciiCV});Object.defineProperty(exports,"stringUtf8CV",{enumerable:!0,get:()=>n.stringUtf8CV});Object.defineProperty(exports,"uintCV",{enumerable:!0,get:()=>n.uintCV});exports.CONTRACT_ADDRESS=c;exports.CONTRACT_NAMES=a;exports.LOCK_PERIODS=l;exports.MAX_DEPOSIT=f;exports.MIN_DEPOSIT=d;exports.TimeFiClient=y;exports.formatAddress=C;exports.formatDate=u;exports.formatNumber=b;exports.formatPercent=g;exports.formatRelativeTime=A;exports.formatSTX=m;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "timefi-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Core SDK for interacting with TimeFi Protocol on Stacks",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/AdekunleBamz/TimeFi-Protocol.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/AdekunleBamz/TimeFi-Protocol/issues"
18
+ },
19
+ "homepage": "https://github.com/AdekunleBamz/TimeFi-Protocol#readme",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "vite build",
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "keywords": [
28
+ "stacks",
29
+ "bitcoin",
30
+ "clarity",
31
+ "defi",
32
+ "time-lock"
33
+ ],
34
+ "author": "AdekunleBamz",
35
+ "license": "MIT",
36
+ "dependencies": {
37
+ "@stacks/network": "^6.13.0",
38
+ "@stacks/transactions": "^6.14.0"
39
+ },
40
+ "devDependencies": {
41
+ "vite": "^5.0.0"
42
+ }
43
+ }