timefi-sdk 0.1.0 → 0.1.1

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
@@ -16,14 +16,18 @@ The official JavaScript SDK for interacting with the **TimeFi Protocol** on the
16
16
 
17
17
  ```bash
18
18
  npm install timefi-sdk
19
- ```
20
19
 
20
+ ### Running Tests
21
+
22
+ ```bash
23
+ npm test
24
+ ```
21
25
  ## 🛠️ Quick Start
22
26
 
23
27
  ### Fetch Protocol Stats
24
28
 
25
29
  ```javascript
26
- import { TimeFiClient, formatSTX } from '@timefi/sdk';
30
+ import { TimeFiClient, formatSTX } from 'timefi-sdk';
27
31
 
28
32
  // Initialize for Stacks Mainnet
29
33
  const client = new TimeFiClient('mainnet');
@@ -36,7 +40,7 @@ console.log(`Current TVL: ${formatSTX(tvl)} STX`);
36
40
  ### Format a Stacks Address
37
41
 
38
42
  ```javascript
39
- import { formatAddress } from '@timefi/sdk';
43
+ import { formatAddress } from 'timefi-sdk';
40
44
 
41
45
  const shortAddress = formatAddress('SP3...XYZ123');
42
46
  console.log(shortAddress); // SP3...Z123
package/dist/index.esm.js CHANGED
@@ -1,111 +1,131 @@
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 = {
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
5
  VAULT: "timefi-vault-v-A2",
6
6
  REWARDS: "timefi-rewards-v-A2",
7
7
  GOVERNANCE: "timefi-governance-v-A2",
8
8
  EMERGENCY: "timefi-emergency-v-A2"
9
- }, g = {
9
+ }, N = {
10
10
  MONTH_1: { label: "1 Month", blocks: 4320, apy: 1 },
11
11
  MONTH_3: { label: "3 Months", blocks: 12960, apy: 3 },
12
12
  MONTH_6: { label: "6 Months", blocks: 25920, apy: 6 },
13
13
  MONTH_9: { label: "9 Months", blocks: 38880, apy: 9 },
14
14
  YEAR_1: { label: "1 Year", blocks: 52560, apy: 12 }
15
- }, M = 0.01, C = 1e6, w = (t) => {
15
+ }, M = 0.01, g = 1e6, y = (t) => {
16
16
  if (t == null) return "0.000000";
17
17
  try {
18
- const n = typeof t == "object" && t !== null && "value" in t ? t.value : t;
19
- return (Number(n) / 1e6).toLocaleString(void 0, {
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
20
  minimumFractionDigits: 0,
21
21
  maximumFractionDigits: 6
22
22
  });
23
23
  } catch (n) {
24
24
  return console.error("Error formatting STX:", n), "0.000000";
25
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) => {
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) => {
31
35
  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);
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);
34
50
  };
35
51
  class R {
36
52
  constructor(n = "mainnet") {
37
- this.network = n === "mainnet" ? new d() : new f(), this.contractAddress = m;
53
+ this.network = n === "mainnet" ? new f() : new d(), this.contractAddress = h;
38
54
  }
39
55
  // --- Read-only Methods ---
40
- async callReadOnly(n, r = [], e) {
41
- const a = await u({
56
+ async callReadOnly(n, e = [], r) {
57
+ const o = await l({
42
58
  contractAddress: this.contractAddress,
43
- contractName: i.VAULT,
59
+ contractName: s.VAULT,
44
60
  functionName: n,
45
- functionArgs: r,
61
+ functionArgs: e,
46
62
  network: this.network,
47
- senderAddress: e || this.contractAddress
63
+ senderAddress: r || this.contractAddress
48
64
  });
49
- return a.type === 7 || a.type === 8 ? s(a.value) : s(a);
65
+ return o.type === 7 || o.type === 8 ? a(o.value) : a(o);
50
66
  }
51
67
  async getVault(n) {
52
- return this.callReadOnly("get-vault", [o(n)]);
68
+ if (n == null) throw new Error("vaultId is required");
69
+ return this.callReadOnly("get-vault", [i(n)]);
53
70
  }
54
71
  async getTimeRemaining(n) {
55
- return this.callReadOnly("get-time-remaining", [o(n)]);
72
+ if (n == null) throw new Error("vaultId is required");
73
+ return this.callReadOnly("get-time-remaining", [i(n)]);
56
74
  }
57
75
  async canWithdraw(n) {
58
- return this.callReadOnly("can-withdraw", [o(n)]);
76
+ if (n == null) throw new Error("vaultId is required");
77
+ return this.callReadOnly("can-withdraw", [i(n)]);
59
78
  }
60
79
  async getTVL() {
61
80
  return this.callReadOnly("get-tvl", []);
62
81
  }
63
82
  // --- Transaction Signing Options Helpers ---
64
- getCreateVaultOptions(n, r) {
83
+ getCreateVaultOptions(n, e) {
65
84
  return {
66
85
  contractAddress: this.contractAddress,
67
- contractName: i.VAULT,
86
+ contractName: s.VAULT,
68
87
  functionName: "create-vault",
69
- functionArgs: [o(n * 1e6), o(r)],
88
+ functionArgs: [i(n * 1e6), i(e)],
70
89
  network: this.network,
71
- anchorMode: l.Any,
90
+ anchorMode: u.Any,
72
91
  postConditionMode: c.Deny
73
92
  };
74
93
  }
75
94
  getWithdrawOptions(n) {
95
+ if (n == null) throw new Error("vaultId is required");
76
96
  return {
77
97
  contractAddress: this.contractAddress,
78
- contractName: i.VAULT,
98
+ contractName: s.VAULT,
79
99
  functionName: "request-withdraw",
80
- functionArgs: [o(n)],
100
+ functionArgs: [i(n)],
81
101
  network: this.network,
82
- anchorMode: l.Any,
102
+ anchorMode: u.Any,
83
103
  postConditionMode: c.Deny
84
104
  };
85
105
  }
86
106
  }
87
107
  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,
108
+ b as AnchorMode,
109
+ h as CONTRACT_ADDRESS,
110
+ s as CONTRACT_NAMES,
111
+ N as LOCK_PERIODS,
112
+ g as MAX_DEPOSIT,
93
113
  M as MIN_DEPOSIT,
94
114
  D as PostConditionMode,
95
115
  R as TimeFiClient,
96
- E as bufferCV,
97
- N as formatAddress,
98
- h as formatDate,
116
+ k as bufferCV,
117
+ C as formatAddress,
118
+ m as formatDate,
99
119
  T as formatNumber,
100
120
  p as formatPercent,
101
121
  O as formatRelativeTime,
102
- w as formatSTX,
122
+ y as formatSTX,
103
123
  _ as noneCV,
104
- v as principalCV,
105
- S as responseErrorCV,
106
- L as responseOkCV,
124
+ S as principalCV,
125
+ L as responseErrorCV,
126
+ $ as responseOkCV,
107
127
  F as someCV,
108
- G as stringAsciiCV,
109
- P as stringUtf8CV,
110
- H as uintCV
128
+ v as stringAsciiCV,
129
+ G as stringUtf8CV,
130
+ P as uintCV
111
131
  };
package/dist/index.js CHANGED
@@ -1 +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;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "timefi-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Core SDK for interacting with TimeFi Protocol on Stacks",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -11,12 +11,12 @@
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/AdekunleBamz/TimeFi-Protocol.git"
14
+ "url": "git+https://github.com/AdekunleBamz/timefi-sdk.git"
15
15
  },
16
16
  "bugs": {
17
- "url": "https://github.com/AdekunleBamz/TimeFi-Protocol/issues"
17
+ "url": "https://github.com/AdekunleBamz/timefi-sdk/issues"
18
18
  },
19
- "homepage": "https://github.com/AdekunleBamz/TimeFi-Protocol#readme",
19
+ "homepage": "https://github.com/AdekunleBamz/timefi-sdk#readme",
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },