timefi-sdk 0.1.3 → 0.1.4

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 CHANGED
@@ -3,58 +3,75 @@
3
3
  The official JavaScript SDK for interacting with the **TimeFi Protocol** on the Stacks blockchain.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/timefi-sdk.svg)](https://www.npmjs.com/package/timefi-sdk)
6
+ [![Downloads](https://img.shields.io/npm/dm/timefi-sdk.svg)](https://www.npmjs.com/package/timefi-sdk)
6
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
8
 
8
- ## 🚀 Features
9
+ ## Features
9
10
 
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.
11
+ - Protocol Client: Easy-to-use `TimeFiClient` for read and write interactions.
12
+ - On-chain Data: Fetch TVL, vault status, and lock durations directly from smart contracts.
13
+ - Formatting Utilities: Standardized formatting for STX (microSTX to STX), addresses, and dates.
14
+ - Mainnet/Testnet Support: Unified interface for both networks.
14
15
 
15
- ## 📦 Installation
16
+ ## Installation
16
17
 
17
18
  ```bash
18
19
  npm install timefi-sdk
19
-
20
- ### Running Tests
21
-
22
- ```bash
23
- npm test
24
20
  ```
25
- ## 🛠️ Quick Start
21
+
22
+ ## Quick Start
26
23
 
27
24
  ### Fetch Protocol Stats
28
25
 
29
26
  ```javascript
30
27
  import { TimeFiClient, formatSTX } from 'timefi-sdk';
31
28
 
32
- // Initialize for Stacks Mainnet
33
29
  const client = new TimeFiClient('mainnet');
34
-
35
- // Get Total Value Locked
36
30
  const tvl = await client.getTVL();
31
+
37
32
  console.log(`Current TVL: ${formatSTX(tvl)} STX`);
38
33
  ```
39
34
 
35
+ ### Build a Create-Vault Transaction
36
+
37
+ ```javascript
38
+ import { TimeFiClient } from 'timefi-sdk';
39
+
40
+ const client = new TimeFiClient('mainnet');
41
+
42
+ const txOptions = client.getCreateVaultOptions('1.25', 4320);
43
+ ```
44
+
40
45
  ### Format a Stacks Address
41
46
 
42
47
  ```javascript
43
48
  import { formatAddress } from 'timefi-sdk';
44
49
 
45
- const shortAddress = formatAddress('SP3...XYZ123');
46
- console.log(shortAddress); // SP3...Z123
50
+ const shortAddress = formatAddress('SP3F1234567890ABCDEFG1234567890XYZ123');
51
+ console.log(shortAddress);
52
+ ```
53
+
54
+ ## Running Tests
55
+
56
+ ```bash
57
+ npm test
47
58
  ```
48
59
 
49
- ## 📖 Documentation
60
+ ## Documentation
50
61
 
51
- The SDK provides the following exports:
62
+ The SDK exports:
52
63
 
53
- - `TimeFiClient`: Core class for blockchain interactions.
54
- - `formatSTX(microStx)`: Converts microSTX to a human-readable STX string.
55
- - `formatAddress(address)`: Truncates addresses for UI display.
56
- - `CONTRACT_ADDRESS`: The main TimeFi Protocol contract address on Stacks.
64
+ - `TimeFiClient`
65
+ - `formatSTX(microStx)`
66
+ - `formatAddress(address)`
67
+ - `formatNumber(value)`
68
+ - `formatPercent(value)`
69
+ - `formatDate(value)`
70
+ - `formatRelativeTime(value)`
71
+ - `CONTRACT_ADDRESS`
72
+ - `CONTRACT_NAMES`
73
+ - `LOCK_PERIODS`
57
74
 
58
- ## 📄 License
75
+ ## License
59
76
 
60
77
  MIT © [AdekunleBamz](https://github.com/AdekunleBamz)
@@ -0,0 +1,33 @@
1
+ export class TimeFiClient {
2
+ constructor(networkType?: string);
3
+ networkType: string;
4
+ network: StacksMainnet | StacksTestnet;
5
+ contractAddress: string;
6
+ callReadOnly(functionName: any, functionArgs: any[], senderAddress: any): Promise<any>;
7
+ getVault(vaultId: any): Promise<any>;
8
+ getTimeRemaining(vaultId: any): Promise<any>;
9
+ canWithdraw(vaultId: any): Promise<any>;
10
+ getTVL(): Promise<any>;
11
+ getCreateVaultOptions(amountSTX: any, lockDurationBlocks: any): {
12
+ contractAddress: string;
13
+ contractName: string;
14
+ functionName: string;
15
+ functionArgs: import("@stacks/transactions").UIntCV[];
16
+ network: StacksMainnet | StacksTestnet;
17
+ anchorMode: AnchorMode;
18
+ postConditionMode: PostConditionMode;
19
+ };
20
+ getWithdrawOptions(vaultId: any): {
21
+ contractAddress: string;
22
+ contractName: string;
23
+ functionName: string;
24
+ functionArgs: import("@stacks/transactions").UIntCV[];
25
+ network: StacksMainnet | StacksTestnet;
26
+ anchorMode: AnchorMode;
27
+ postConditionMode: PostConditionMode;
28
+ };
29
+ }
30
+ import { StacksMainnet } from '@stacks/network';
31
+ import { StacksTestnet } from '@stacks/network';
32
+ import { AnchorMode } from '@stacks/transactions';
33
+ import { PostConditionMode } from '@stacks/transactions';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Protocol Constants
3
+ */
4
+ export const CONTRACT_ADDRESS: "SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N";
5
+ export namespace CONTRACT_NAMES {
6
+ let VAULT: string;
7
+ let REWARDS: string;
8
+ let GOVERNANCE: string;
9
+ let EMERGENCY: string;
10
+ }
11
+ export namespace LOCK_PERIODS {
12
+ namespace MONTH_1 {
13
+ let label: string;
14
+ let blocks: number;
15
+ let apy: number;
16
+ }
17
+ namespace MONTH_3 {
18
+ let label_1: string;
19
+ export { label_1 as label };
20
+ let blocks_1: number;
21
+ export { blocks_1 as blocks };
22
+ let apy_1: number;
23
+ export { apy_1 as apy };
24
+ }
25
+ namespace MONTH_6 {
26
+ let label_2: string;
27
+ export { label_2 as label };
28
+ let blocks_2: number;
29
+ export { blocks_2 as blocks };
30
+ let apy_2: number;
31
+ export { apy_2 as apy };
32
+ }
33
+ namespace MONTH_9 {
34
+ let label_3: string;
35
+ export { label_3 as label };
36
+ let blocks_3: number;
37
+ export { blocks_3 as blocks };
38
+ let apy_3: number;
39
+ export { apy_3 as apy };
40
+ }
41
+ namespace YEAR_1 {
42
+ let label_4: string;
43
+ export { label_4 as label };
44
+ let blocks_4: number;
45
+ export { blocks_4 as blocks };
46
+ let apy_4: number;
47
+ export { apy_4 as apy };
48
+ }
49
+ }
50
+ export const MIN_DEPOSIT: 0.01;
51
+ export const MAX_DEPOSIT: 1000000;
@@ -0,0 +1,6 @@
1
+ export function formatSTX(microStx: any): string;
2
+ export function formatAddress(address: any, prefix?: number, suffix?: number): any;
3
+ export function formatNumber(val: any): string;
4
+ export function formatPercent(val: any, decimals?: number): string;
5
+ export function formatDate(date: any): string;
6
+ export function formatRelativeTime(date: any): string;
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@stacks/transactions"),c=require("@stacks/network"),u="SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N",s={VAULT:"timefi-vault-v-A2",REWARDS:"timefi-rewards-v-A2",GOVERNANCE:"timefi-governance-v-A2",EMERGENCY:"timefi-emergency-v-A2"},f={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,m=1e6,g=t=>{if(t==null)return"0.000000";try{const e=typeof t=="object"&&t!==null&&"value"in t?t.value:t,r=Number(e);return isNaN(r)?"0.000000":(r/1e6).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:6})}catch(e){return console.error("Error formatting STX:",e),"0.000000"}},h=(t,e=4,r=4)=>t?t.length<=e+r?t:`${t.slice(0,e+2)}...${t.slice(-r)}`:"",b=t=>{if(t==null)return"0";const e=Number(t);return isNaN(e)?"0":e.toLocaleString()},C=(t,e=2)=>{if(t==null)return"0%";const r=Number(t);return isNaN(r)?"0%":(r*100).toFixed(e)+"%"},l=t=>{if(!t)return"--";const e=new Date(t);return isNaN(e.getTime())?"--":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})},A=t=>{if(!t)return"--";const e=new Date,r=new Date(t),o=Math.floor((e-r)/1e3);if(o<-1){const i=Math.abs(o);return i<60?"in a few seconds":i<3600?`in ${Math.floor(i/60)}m`:i<86400?`in ${Math.floor(i/3600)}h`:`in ${Math.floor(i/86400)}d`}return o<5?"just now":o<60?`${o}s ago`:o<3600?`${Math.floor(o/60)}m ago`:o<86400?`${Math.floor(o/3600)}h ago`:o<604800?`${Math.floor(o/86400)}d ago`:l(t)};function a(t,e){if(!Number.isInteger(t)||t<=0)throw new Error(`${e} must be a positive integer.`)}function w(t){if(t==null)throw new Error("amountSTX is required");const e=String(t).trim();if(!/^\d+(\.\d+)?$/.test(e))throw new Error("amountSTX must be a valid positive number.");const[r,o=""]=e.split(".");if(o.length>6)throw new Error("amountSTX supports at most 6 decimal places.");const i=BigInt(r)*1000000n+BigInt((o+"000000").slice(0,6));if(i<=0n)throw new Error("amountSTX must be greater than 0.");return i}class M{constructor(e="mainnet"){if(!["mainnet","testnet"].includes(e))throw new Error(`Invalid networkType "${e}". Use "mainnet" or "testnet".`);this.networkType=e,this.network=e==="mainnet"?new c.StacksMainnet:new c.StacksTestnet,this.contractAddress=u}async callReadOnly(e,r=[],o){const i=await n.callReadOnlyFunction({contractAddress:this.contractAddress,contractName:s.VAULT,functionName:e,functionArgs:r,network:this.network,senderAddress:o||this.contractAddress});return i.type===7||i.type===8?n.cvToValue(i.value):n.cvToValue(i)}async getVault(e){return a(e,"vaultId"),this.callReadOnly("get-vault",[n.uintCV(e)])}async getTimeRemaining(e){return a(e,"vaultId"),this.callReadOnly("get-time-remaining",[n.uintCV(e)])}async canWithdraw(e){return a(e,"vaultId"),this.callReadOnly("can-withdraw",[n.uintCV(e)])}async getTVL(){return this.callReadOnly("get-tvl",[])}getCreateVaultOptions(e,r){return a(r,"lockDurationBlocks"),{contractAddress:this.contractAddress,contractName:s.VAULT,functionName:"create-vault",functionArgs:[n.uintCV(w(e)),n.uintCV(r)],network:this.network,anchorMode:n.AnchorMode.Any,postConditionMode:n.PostConditionMode.Allow}}getWithdrawOptions(e){return a(e,"vaultId"),{contractAddress:this.contractAddress,contractName:s.VAULT,functionName:"request-withdraw",functionArgs:[n.uintCV(e)],network:this.network,anchorMode:n.AnchorMode.Any,postConditionMode:n.PostConditionMode.Allow}}}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=u;exports.CONTRACT_NAMES=s;exports.LOCK_PERIODS=f;exports.MAX_DEPOSIT=m;exports.MIN_DEPOSIT=d;exports.TimeFiClient=M;exports.formatAddress=h;exports.formatDate=l;exports.formatNumber=b;exports.formatPercent=C;exports.formatRelativeTime=A;exports.formatSTX=g;
@@ -0,0 +1,4 @@
1
+ export * from "./constants.js";
2
+ export * from "./format.js";
3
+ export * from "./client.js";
4
+ export { uintCV, principalCV, bufferCV, stringAsciiCV, stringUtf8CV, noneCV, someCV, responseOkCV, responseErrorCV, AnchorMode, PostConditionMode } from "@stacks/transactions";
package/dist/index.mjs ADDED
@@ -0,0 +1,147 @@
1
+ import { callReadOnlyFunction as f, cvToValue as c, uintCV as i, PostConditionMode as u, AnchorMode as l } from "@stacks/transactions";
2
+ import { AnchorMode as S, PostConditionMode as k, bufferCV as D, noneCV as _, principalCV as $, responseErrorCV as I, responseOkCV as L, someCV as F, stringAsciiCV as P, stringUtf8CV as G, uintCV as H } from "@stacks/transactions";
3
+ import { StacksMainnet as d, StacksTestnet as m } from "@stacks/network";
4
+ const h = "SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N", a = {
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
+ }, M = {
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
+ }, p = 0.01, T = 1e6, y = (n) => {
16
+ if (n == null) return "0.000000";
17
+ try {
18
+ const t = typeof n == "object" && n !== null && "value" in n ? n.value : n, e = Number(t);
19
+ return isNaN(e) ? "0.000000" : (e / 1e6).toLocaleString(void 0, {
20
+ minimumFractionDigits: 0,
21
+ maximumFractionDigits: 6
22
+ });
23
+ } catch (t) {
24
+ return console.error("Error formatting STX:", t), "0.000000";
25
+ }
26
+ }, C = (n, t = 4, e = 4) => n ? n.length <= t + e ? n : `${n.slice(0, t + 2)}...${n.slice(-e)}` : "", b = (n) => {
27
+ if (n == null) return "0";
28
+ const t = Number(n);
29
+ return isNaN(t) ? "0" : t.toLocaleString();
30
+ }, E = (n, t = 2) => {
31
+ if (n == null) return "0%";
32
+ const e = Number(n);
33
+ return isNaN(e) ? "0%" : (e * 100).toFixed(t) + "%";
34
+ }, w = (n) => {
35
+ if (!n) return "--";
36
+ const t = new Date(n);
37
+ return isNaN(t.getTime()) ? "--" : t.toLocaleDateString(void 0, {
38
+ year: "numeric",
39
+ month: "short",
40
+ day: "numeric"
41
+ });
42
+ }, O = (n) => {
43
+ if (!n) return "--";
44
+ const t = /* @__PURE__ */ new Date(), e = new Date(n), r = Math.floor((t - e) / 1e3);
45
+ if (r < -1) {
46
+ const o = Math.abs(r);
47
+ return o < 60 ? "in a few seconds" : o < 3600 ? `in ${Math.floor(o / 60)}m` : o < 86400 ? `in ${Math.floor(o / 3600)}h` : `in ${Math.floor(o / 86400)}d`;
48
+ }
49
+ return r < 5 ? "just now" : r < 60 ? `${r}s ago` : r < 3600 ? `${Math.floor(r / 60)}m ago` : r < 86400 ? `${Math.floor(r / 3600)}h ago` : r < 604800 ? `${Math.floor(r / 86400)}d ago` : w(n);
50
+ };
51
+ function s(n, t) {
52
+ if (!Number.isInteger(n) || n <= 0)
53
+ throw new Error(`${t} must be a positive integer.`);
54
+ }
55
+ function g(n) {
56
+ if (n == null)
57
+ throw new Error("amountSTX is required");
58
+ const t = String(n).trim();
59
+ if (!/^\d+(\.\d+)?$/.test(t))
60
+ throw new Error("amountSTX must be a valid positive number.");
61
+ const [e, r = ""] = t.split(".");
62
+ if (r.length > 6)
63
+ throw new Error("amountSTX supports at most 6 decimal places.");
64
+ const o = BigInt(e) * 1000000n + BigInt((r + "000000").slice(0, 6));
65
+ if (o <= 0n)
66
+ throw new Error("amountSTX must be greater than 0.");
67
+ return o;
68
+ }
69
+ class R {
70
+ constructor(t = "mainnet") {
71
+ if (!["mainnet", "testnet"].includes(t))
72
+ throw new Error(`Invalid networkType "${t}". Use "mainnet" or "testnet".`);
73
+ this.networkType = t, this.network = t === "mainnet" ? new d() : new m(), this.contractAddress = h;
74
+ }
75
+ // --- Read-only Methods ---
76
+ async callReadOnly(t, e = [], r) {
77
+ const o = await f({
78
+ contractAddress: this.contractAddress,
79
+ contractName: a.VAULT,
80
+ functionName: t,
81
+ functionArgs: e,
82
+ network: this.network,
83
+ senderAddress: r || this.contractAddress
84
+ });
85
+ return o.type === 7 || o.type === 8 ? c(o.value) : c(o);
86
+ }
87
+ async getVault(t) {
88
+ return s(t, "vaultId"), this.callReadOnly("get-vault", [i(t)]);
89
+ }
90
+ async getTimeRemaining(t) {
91
+ return s(t, "vaultId"), this.callReadOnly("get-time-remaining", [i(t)]);
92
+ }
93
+ async canWithdraw(t) {
94
+ return s(t, "vaultId"), this.callReadOnly("can-withdraw", [i(t)]);
95
+ }
96
+ async getTVL() {
97
+ return this.callReadOnly("get-tvl", []);
98
+ }
99
+ // --- Transaction Signing Options Helpers ---
100
+ getCreateVaultOptions(t, e) {
101
+ return s(e, "lockDurationBlocks"), {
102
+ contractAddress: this.contractAddress,
103
+ contractName: a.VAULT,
104
+ functionName: "create-vault",
105
+ functionArgs: [i(g(t)), i(e)],
106
+ network: this.network,
107
+ anchorMode: l.Any,
108
+ postConditionMode: u.Allow
109
+ };
110
+ }
111
+ getWithdrawOptions(t) {
112
+ return s(t, "vaultId"), {
113
+ contractAddress: this.contractAddress,
114
+ contractName: a.VAULT,
115
+ functionName: "request-withdraw",
116
+ functionArgs: [i(t)],
117
+ network: this.network,
118
+ anchorMode: l.Any,
119
+ postConditionMode: u.Allow
120
+ };
121
+ }
122
+ }
123
+ export {
124
+ S as AnchorMode,
125
+ h as CONTRACT_ADDRESS,
126
+ a as CONTRACT_NAMES,
127
+ M as LOCK_PERIODS,
128
+ T as MAX_DEPOSIT,
129
+ p as MIN_DEPOSIT,
130
+ k as PostConditionMode,
131
+ R as TimeFiClient,
132
+ D as bufferCV,
133
+ C as formatAddress,
134
+ w as formatDate,
135
+ b as formatNumber,
136
+ E as formatPercent,
137
+ O as formatRelativeTime,
138
+ y as formatSTX,
139
+ _ as noneCV,
140
+ $ as principalCV,
141
+ I as responseErrorCV,
142
+ L as responseOkCV,
143
+ F as someCV,
144
+ P as stringAsciiCV,
145
+ G as stringUtf8CV,
146
+ H as uintCV
147
+ };
package/package.json CHANGED
@@ -1,19 +1,28 @@
1
1
  {
2
2
  "name": "timefi-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Official JavaScript SDK for TimeFi Protocol - Time-locked vaults on Stacks blockchain",
5
- "main": "dist/index.js",
6
- "module": "dist/index.esm.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
8
15
  "files": [
9
16
  "dist",
10
17
  "README.md",
11
18
  "LICENSE"
12
19
  ],
13
20
  "scripts": {
14
- "build": "vite build",
15
- "test": "echo \"Error: no test specified\" && exit 1",
16
- "prepublishOnly": "npm run build"
21
+ "clean": "rimraf dist",
22
+ "build": "npm run clean && vite build && npm run build:types",
23
+ "build:types": "tsc -p tsconfig.types.json",
24
+ "test": "vitest run",
25
+ "prepublishOnly": "npm run build && npm run test"
17
26
  },
18
27
  "keywords": [
19
28
  "stacks",
@@ -41,12 +50,17 @@
41
50
  "publishConfig": {
42
51
  "access": "public"
43
52
  },
53
+ "engines": {
54
+ "node": ">=18"
55
+ },
44
56
  "dependencies": {
45
57
  "@stacks/transactions": "^6.0.0",
46
58
  "@stacks/network": "^6.0.0"
47
59
  },
48
60
  "devDependencies": {
49
- "vite": "^5.0.0"
61
+ "rimraf": "^6.1.0",
62
+ "typescript": "^5.9.2",
63
+ "vite": "^5.0.0",
64
+ "vitest": "^4.0.8"
50
65
  }
51
-
52
- }
66
+ }
package/dist/index.esm.js DELETED
@@ -1,131 +0,0 @@
1
- import { callReadOnlyFunction as l, cvToValue as a, uintCV as i, PostConditionMode as c, AnchorMode as u } from "@stacks/transactions";
2
- import { AnchorMode as b, PostConditionMode as D, bufferCV as k, noneCV as _, principalCV as S, responseErrorCV as L, responseOkCV as $, someCV as F, stringAsciiCV as v, stringUtf8CV as G, uintCV as P } from "@stacks/transactions";
3
- import { StacksMainnet as f, StacksTestnet as d } from "@stacks/network";
4
- const h = "SP3FKNEZ86RG5RT7SZ5FBRGH85FZNG94ZH1MCGG6N", s = {
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
- }, N = {
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, g = 1e6, y = (t) => {
16
- if (t == null) return "0.000000";
17
- try {
18
- const n = typeof t == "object" && t !== null && "value" in t ? t.value : t, e = Number(n);
19
- return isNaN(e) ? "0.000000" : (e / 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
- }, C = (t, n = 4, e = 4) => t ? t.length <= n + e ? t : `${t.slice(0, n + 2)}...${t.slice(-e)}` : "", T = (t) => {
27
- if (t == null) return "0";
28
- const n = Number(t);
29
- return isNaN(n) ? "0" : n.toLocaleString();
30
- }, p = (t, n = 2) => {
31
- if (t == null) return "0%";
32
- const e = Number(t);
33
- return isNaN(e) ? "0%" : (e * 100).toFixed(n) + "%";
34
- }, m = (t) => {
35
- if (!t) return "--";
36
- const n = new Date(t);
37
- return isNaN(n.getTime()) ? "--" : n.toLocaleDateString(void 0, {
38
- year: "numeric",
39
- month: "short",
40
- day: "numeric"
41
- });
42
- }, O = (t) => {
43
- if (!t) return "--";
44
- const n = /* @__PURE__ */ new Date(), e = new Date(t), r = Math.floor((n - e) / 1e3);
45
- if (r < -1) {
46
- const o = Math.abs(r);
47
- return o < 60 ? "in a few seconds" : o < 3600 ? `in ${Math.floor(o / 60)}m` : o < 86400 ? `in ${Math.floor(o / 3600)}h` : `in ${Math.floor(o / 86400)}d`;
48
- }
49
- return r < 5 ? "just now" : r < 60 ? `${r}s ago` : r < 3600 ? `${Math.floor(r / 60)}m ago` : r < 86400 ? `${Math.floor(r / 3600)}h ago` : r < 604800 ? `${Math.floor(r / 86400)}d ago` : m(t);
50
- };
51
- class R {
52
- constructor(n = "mainnet") {
53
- this.network = n === "mainnet" ? new f() : new d(), this.contractAddress = h;
54
- }
55
- // --- Read-only Methods ---
56
- async callReadOnly(n, e = [], r) {
57
- const o = await l({
58
- contractAddress: this.contractAddress,
59
- contractName: s.VAULT,
60
- functionName: n,
61
- functionArgs: e,
62
- network: this.network,
63
- senderAddress: r || this.contractAddress
64
- });
65
- return o.type === 7 || o.type === 8 ? a(o.value) : a(o);
66
- }
67
- async getVault(n) {
68
- if (n == null) throw new Error("vaultId is required");
69
- return this.callReadOnly("get-vault", [i(n)]);
70
- }
71
- async getTimeRemaining(n) {
72
- if (n == null) throw new Error("vaultId is required");
73
- return this.callReadOnly("get-time-remaining", [i(n)]);
74
- }
75
- async canWithdraw(n) {
76
- if (n == null) throw new Error("vaultId is required");
77
- return this.callReadOnly("can-withdraw", [i(n)]);
78
- }
79
- async getTVL() {
80
- return this.callReadOnly("get-tvl", []);
81
- }
82
- // --- Transaction Signing Options Helpers ---
83
- getCreateVaultOptions(n, e) {
84
- return {
85
- contractAddress: this.contractAddress,
86
- contractName: s.VAULT,
87
- functionName: "create-vault",
88
- functionArgs: [i(n * 1e6), i(e)],
89
- network: this.network,
90
- anchorMode: u.Any,
91
- postConditionMode: c.Deny
92
- };
93
- }
94
- getWithdrawOptions(n) {
95
- if (n == null) throw new Error("vaultId is required");
96
- return {
97
- contractAddress: this.contractAddress,
98
- contractName: s.VAULT,
99
- functionName: "request-withdraw",
100
- functionArgs: [i(n)],
101
- network: this.network,
102
- anchorMode: u.Any,
103
- postConditionMode: c.Deny
104
- };
105
- }
106
- }
107
- export {
108
- b as AnchorMode,
109
- h as CONTRACT_ADDRESS,
110
- s as CONTRACT_NAMES,
111
- N as LOCK_PERIODS,
112
- g as MAX_DEPOSIT,
113
- M as MIN_DEPOSIT,
114
- D as PostConditionMode,
115
- R as TimeFiClient,
116
- k as bufferCV,
117
- C as formatAddress,
118
- m as formatDate,
119
- T as formatNumber,
120
- p as formatPercent,
121
- O as formatRelativeTime,
122
- y as formatSTX,
123
- _ as noneCV,
124
- S as principalCV,
125
- L as responseErrorCV,
126
- $ as responseOkCV,
127
- F as someCV,
128
- v as stringAsciiCV,
129
- G as stringUtf8CV,
130
- P as uintCV
131
- };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@stacks/transactions"),s=require("@stacks/network"),u="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}},f=.01,d=1e6,m=t=>{if(t==null)return"0.000000";try{const e=typeof t=="object"&&t!==null&&"value"in t?t.value:t,r=Number(e);return isNaN(r)?"0.000000":(r/1e6).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:6})}catch(e){return console.error("Error formatting STX:",e),"0.000000"}},C=(t,e=4,r=4)=>t?t.length<=e+r?t:`${t.slice(0,e+2)}...${t.slice(-r)}`:"",h=t=>{if(t==null)return"0";const e=Number(t);return isNaN(e)?"0":e.toLocaleString()},b=(t,e=2)=>{if(t==null)return"0%";const r=Number(t);return isNaN(r)?"0%":(r*100).toFixed(e)+"%"},c=t=>{if(!t)return"--";const e=new Date(t);return isNaN(e.getTime())?"--":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})},g=t=>{if(!t)return"--";const e=new Date,r=new Date(t),o=Math.floor((e-r)/1e3);if(o<-1){const i=Math.abs(o);return i<60?"in a few seconds":i<3600?`in ${Math.floor(i/60)}m`:i<86400?`in ${Math.floor(i/3600)}h`:`in ${Math.floor(i/86400)}d`}return o<5?"just now":o<60?`${o}s ago`:o<3600?`${Math.floor(o/60)}m ago`:o<86400?`${Math.floor(o/3600)}h ago`:o<604800?`${Math.floor(o/86400)}d ago`:c(t)};class A{constructor(e="mainnet"){this.network=e==="mainnet"?new s.StacksMainnet:new s.StacksTestnet,this.contractAddress=u}async callReadOnly(e,r=[],o){const i=await n.callReadOnlyFunction({contractAddress:this.contractAddress,contractName:a.VAULT,functionName:e,functionArgs:r,network:this.network,senderAddress:o||this.contractAddress});return i.type===7||i.type===8?n.cvToValue(i.value):n.cvToValue(i)}async getVault(e){if(e==null)throw new Error("vaultId is required");return this.callReadOnly("get-vault",[n.uintCV(e)])}async getTimeRemaining(e){if(e==null)throw new Error("vaultId is required");return this.callReadOnly("get-time-remaining",[n.uintCV(e)])}async canWithdraw(e){if(e==null)throw new Error("vaultId is required");return this.callReadOnly("can-withdraw",[n.uintCV(e)])}async getTVL(){return this.callReadOnly("get-tvl",[])}getCreateVaultOptions(e,r){return{contractAddress:this.contractAddress,contractName:a.VAULT,functionName:"create-vault",functionArgs:[n.uintCV(e*1e6),n.uintCV(r)],network:this.network,anchorMode:n.AnchorMode.Any,postConditionMode:n.PostConditionMode.Deny}}getWithdrawOptions(e){if(e==null)throw new Error("vaultId is required");return{contractAddress:this.contractAddress,contractName:a.VAULT,functionName:"request-withdraw",functionArgs:[n.uintCV(e)],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=u;exports.CONTRACT_NAMES=a;exports.LOCK_PERIODS=l;exports.MAX_DEPOSIT=d;exports.MIN_DEPOSIT=f;exports.TimeFiClient=A;exports.formatAddress=C;exports.formatDate=c;exports.formatNumber=h;exports.formatPercent=b;exports.formatRelativeTime=g;exports.formatSTX=m;