@dripfi/drip-sdk 1.0.6 → 1.0.8

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.
@@ -0,0 +1,2 @@
1
+ dist/
2
+ node_modules/
package/.prettierrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "printWidth": 120,
3
+ "useTabs": false,
4
+ "tabWidth": 2,
5
+ "singleQuote": true,
6
+ "jsxSingleQuote": true,
7
+ "semi": false,
8
+ "trailingComma": "all",
9
+ "arrowParens": "always",
10
+ "plugins": ["prettier-plugin-tailwindcss"]
11
+ }
package/README.md CHANGED
@@ -15,51 +15,153 @@ npm i @dripfi/drip-sdk
15
15
  ## Usage
16
16
 
17
17
  ```typescript
18
- import DripSdk from '@drip/sdk';
18
+ import DripSdk from '@drip/sdk'
19
19
  ```
20
20
 
21
21
  Initialize the SDK with your Drip configuration and an optional signer:
22
22
 
23
23
  ```typescript
24
- const dripConfig = new DripConfig(/* configuration */);
25
- const signer = /* your Signer instance */;
24
+ const dripConfig = new DripConfig(
25
+ subgraphUrl: string,
26
+ priceFeedApiUrl: string,
27
+ rewardsUrl: string,
28
+ fastRedeemApi: string,
29
+ contracts: Record<number, ContractAddresses>,
30
+ dripRoute: string);
31
+ const signer: ethers.Signer = /* your Signer instance */;
26
32
  const dripSdk = new DripSdk(dripConfig, signer);
33
+
34
+ type Vault = {
35
+ vaultName: string
36
+ vaultAddress: string
37
+ apy: number
38
+ tvr: number
39
+ protocols: string[]
40
+ projectName: string
41
+ depositToken: VaultDepositToken
42
+ type: VaultType
43
+ rewards: VaultReward[]
44
+ liveUntil: string
45
+ liveUntilFormatted: string
46
+ hasPoolEnded: boolean
47
+ boosters: NFTBoost[]
48
+ stretchGoals: StretchGoal[]
49
+ strategies: Strategy[]
50
+ newWithdraw: boolean
51
+ tgePrice?: number
52
+ maxAmountOfTokens?: number
53
+ rewardsInformation: RewardsInformation
54
+ }
55
+
56
+ type VaultType = 'launch' | 'earn' | 'airdrop'
57
+
58
+ type VaultDepositToken = {
59
+ name: string
60
+ symbol: string
61
+ roundingDecimals: number
62
+ precisionDecimals: number
63
+ tokenAddress: string
64
+ }
65
+
66
+ type VaultReward = {
67
+ type: 'token' | 'points'
68
+ name: string
69
+ symbol: string
70
+ decimals: number
71
+ tokenAddress: string
72
+ monthlyEmissionRate?: number
73
+ }
74
+
75
+ type NFTBoost = {
76
+ url: string
77
+ tokenAddress: string
78
+ multiplier: number
79
+ nftAddress: string
80
+ network: string
81
+ initialBlock: number // needs to be the block when rewards was deployed
82
+ imagePath: string
83
+ }
84
+
85
+ interface StretchGoal {
86
+ threshhold: number
87
+ threshholdDescription: string
88
+ rewardTooltip: string
89
+ rewardDescription: string
90
+ amountOfTokens: number
91
+ }
92
+
93
+ type RewardsInformation = {
94
+ [tokenAddress: string]: { blockNumber: string; rewardrate: string; timestamp: string; endTime: string }
95
+ }
96
+
97
+ type Strategy = {
98
+ address: string
99
+ lastDoHardWorkTime: number | null
100
+ lastDoHardWorkBlock: number | null
101
+ }
102
+
103
+ type AuthenticationStatus = {
104
+ isAuthenticated: boolean
105
+ address?: string
106
+ token?: string
107
+ message?: string
108
+ }
109
+
110
+ interface QLFastRedeem {
111
+ assetsWithdrawn: {
112
+ asset: {
113
+ decimals: number
114
+ id: string
115
+ name: string
116
+ symbol: string
117
+ }
118
+ claimed: string
119
+ id: string
120
+ }[]
121
+ blockNumber: number
122
+ id: string
123
+ svtWithdrawn: string
124
+ }
125
+
126
+ type SwapInfo = {
127
+ swapTarget: any
128
+ token: string
129
+ swapCallData: any
130
+ }
131
+
27
132
  ```
28
133
 
29
134
  ## Methods
30
135
 
31
- - **getAllVaults(): Promise<Vault[]>**
136
+ - `getAllVaults(): Promise<Vault[]>`
32
137
  Fetches details of all Drip Vaults.
33
138
 
34
- - **getVaultDetails(vaultAddress: string): Promise<Vault>**
139
+ - `getVaultDetails(vaultAddress: string): Promise<Vault> `
35
140
  Fetches details of a specific Drip Vault identified by its address.
36
141
 
37
- - **authenticate(): Promise<boolean>**
142
+ - `authenticate(): Promise<boolean>`
38
143
  Initiates the user authentication process and returns a boolean indicating success.
39
144
 
40
- - **isUserAuthenticated(): Promise<{ isAuthenticated: boolean, address?: string, token?: string, message?: string }>**
145
+ - `isUserAuthenticated(): Promise<AuthenticationStatus>`
41
146
  Checks if the user is authenticated and returns authentication status along with relevant information.
42
147
 
43
- - **updateSigner(newSigner: Signer)**
148
+ - `updateSigner(newSigner: Signer): Promise<void>`
44
149
  Updates the signer for the SDK instance.
45
150
 
46
- - **getUserBalance(vault: Vault): Promise<UserBalance>**
151
+ - `getUserBalance(vault: Vault): Promise<UserBalance>`
47
152
  Fetches the user's balance for a specific Drip Vault.
48
153
 
49
- - **deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise**
154
+ - `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<void>`
50
155
  The deposit function allows you to deposit tokens into a specific vault.
51
156
 
52
- - **swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise**
157
+ - `swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<void>`
53
158
  The swapAndDeposit function allows you to deposit a different token or ether and it will take care of swapping to the correct token before making the deposit
54
159
 
55
- - **withdraw(vault: Vault, amountToWithdraw?: string): Promise**
160
+ - `withdraw(vault: Vault, amountToWithdraw?: string): Promise<void>`
56
161
  Withdraws tokens from a vault. After withdrawing, you must wait for the withdrawal to be processed by the 'DoHardWork' function, and then you can claim those tokens using claimWithdraws()
57
162
 
58
- - **claimWithdraws(vaultAddress: string): Promise**
163
+ - `claimWithdraws(vaultAddress: string): Promise<void>`
59
164
  After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account.
60
165
 
61
- - **fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise**
166
+ - `fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<void>`
62
167
  For users who prefer not to wait for withdrawals to be processed, there is a Fast Withdrawal method. While this approach is more gas-intensive, as users bear the cost of executing the withdrawal process themselves, it allows for instant access to the withdrawn tokens. When utilizing Fast Withdrawal, users immediately receive the tokens, eliminating the need to initiate the 'claimWithdrawal' process separately.
63
-
64
-
65
-
package/dist/DripApi.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { BigNumber } from "ethers";
2
- import { Vault } from "./types/Vault";
3
- import { SwapInfo } from "./types/SwapInfo";
4
- import { QLFastRedeem } from "./types/QLFastRedeem";
1
+ import { BigNumber } from 'ethers';
2
+ import { Vault } from './types/Vault';
3
+ import { SwapInfo } from './types/SwapInfo';
4
+ import { QLFastRedeem } from './types/QLFastRedeem';
5
5
  export default class DripApi {
6
6
  route: string;
7
7
  constructor(route: string);
package/dist/DripApi.js CHANGED
@@ -17,14 +17,14 @@ class DripApi {
17
17
  fetchAllVaults() {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  const res = yield fetch(`${this.route}/api-be/api/vault`);
20
- const data = yield res.json();
20
+ const data = (yield res.json());
21
21
  return data;
22
22
  });
23
23
  }
24
24
  fetchVaultDetails(vaultAddress) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  const res = yield fetch(`${this.route}/api-be/api/vault/${vaultAddress}`);
27
- const data = yield res.json();
27
+ const data = (yield res.json());
28
28
  return data;
29
29
  });
30
30
  }
@@ -35,13 +35,13 @@ class DripApi {
35
35
  }
36
36
  const url = `${this.route}/oneinch?getRequest=/swap/v5.2/1/swap?fromTokenAddress=${fromTokenAddress}%26toTokenAddress=${toTokenAddress}%26amount=${amount.toString()}%26fromAddress=${fromAddress}%26slippage=0.1%26disableEstimate=true%26allowPartialFill=false%26includeTokensInfo=true`;
37
37
  const res = yield fetch(url);
38
- const data = yield res.json();
38
+ const data = (yield res.json());
39
39
  return [
40
40
  {
41
41
  swapTarget: data.tx.to,
42
42
  token: data.fromToken.address,
43
43
  swapCallData: data.tx.data,
44
- }
44
+ },
45
45
  ];
46
46
  });
47
47
  }
@@ -52,7 +52,7 @@ class DripApi {
52
52
  const res = yield fetch(`${this.route}/api-be/api/spool/user/svtBalance/${walletAddress}/${vaultAddress}`, {
53
53
  headers,
54
54
  });
55
- const data = yield res.json();
55
+ const data = (yield res.json());
56
56
  return data;
57
57
  });
58
58
  }
@@ -61,9 +61,9 @@ class DripApi {
61
61
  const headers = new Headers();
62
62
  headers.append('Authorization', token);
63
63
  const res = yield fetch(`${this.route}/api-be/api/spool/userBalance/${walletAddress}/${vaultAddress}`, {
64
- headers
64
+ headers,
65
65
  });
66
- const data = yield res.json();
66
+ const data = (yield res.json());
67
67
  return data;
68
68
  });
69
69
  }
@@ -72,7 +72,7 @@ class DripApi {
72
72
  const headers = new Headers();
73
73
  headers.append('Authorization', token);
74
74
  const res = yield fetch(`${this.route}/api-be/api/spool/user/dNft/${walletAddress}/${vaultAddress}`, {
75
- headers
75
+ headers,
76
76
  });
77
77
  const data = yield res.json();
78
78
  return data;
@@ -83,9 +83,9 @@ class DripApi {
83
83
  const headers = new Headers();
84
84
  headers.append('Authorization', token);
85
85
  const res = yield fetch(`${this.route}/api-be/api/spool/user/svtFromNft/${userAddress}/${vaultAddress}?dnfts=${dnfts.join(',')}`, {
86
- headers
86
+ headers,
87
87
  });
88
- const data = yield res.json();
88
+ const data = (yield res.json());
89
89
  return data;
90
90
  });
91
91
  }
@@ -94,9 +94,9 @@ class DripApi {
94
94
  const headers = new Headers();
95
95
  headers.append('Authorization', token);
96
96
  const res = yield fetch(`${this.route}/api-be/api/spool/user/allWnft/${walletAddress}/${vaultAddress}`, {
97
- headers
97
+ headers,
98
98
  });
99
- const data = yield res.json();
99
+ const data = (yield res.json());
100
100
  return data;
101
101
  });
102
102
  }
@@ -105,9 +105,9 @@ class DripApi {
105
105
  const headers = new Headers();
106
106
  headers.append('Authorization', token);
107
107
  const res = yield fetch(`${this.route}/api-be/api/spool/user/allDnft/${walletAddress}/${vaultAddress}`, {
108
- headers
108
+ headers,
109
109
  });
110
- const data = yield res.json();
110
+ const data = (yield res.json());
111
111
  return data;
112
112
  });
113
113
  }
@@ -116,9 +116,9 @@ class DripApi {
116
116
  const headers = new Headers();
117
117
  headers.append('Authorization', token);
118
118
  const res = yield fetch(`${this.route}/api-be/api/spool/user/assetBalance/${blocknumber}/${vaultAddress}`, {
119
- headers
119
+ headers,
120
120
  });
121
- const data = yield res.json();
121
+ const data = (yield res.json());
122
122
  return data;
123
123
  });
124
124
  }
@@ -127,9 +127,9 @@ class DripApi {
127
127
  const headers = new Headers();
128
128
  headers.append('Authorization', token);
129
129
  const res = yield fetch(`${this.route}/api-be/api/spool/user/fastWithdrawNft/${walletAddress}/${vaultAddress}`, {
130
- headers
130
+ headers,
131
131
  });
132
- const data = yield res.json();
132
+ const data = (yield res.json());
133
133
  return data;
134
134
  });
135
135
  }
@@ -1,5 +1,5 @@
1
- import { ContractAddresses, SDKConfig } from "@spool.fi/spool-v2-sdk";
2
- import { Signer } from "ethers";
1
+ import { ContractAddresses, SDKConfig } from '@spool.fi/spool-v2-sdk';
2
+ import { Signer } from 'ethers';
3
3
  export declare class DripConfig {
4
4
  internalConfig: SDKConfig;
5
5
  dripRoute: string;
package/dist/DripSdk.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Vault } from "./types/Vault";
2
- import { Signer } from "ethers";
3
- import { DripConfig } from "./DripConfig";
4
- import { UserBalance } from "./types/UserBalance";
1
+ import { Vault } from './types/Vault';
2
+ import { Signer } from 'ethers';
3
+ import { DripConfig } from './DripConfig';
4
+ import { UserBalance } from './types/UserBalance';
5
+ import { AuthenticationStatus } from './types/AuthenticationStatus';
5
6
  export default class DripSdk {
6
7
  private dripApi;
7
8
  private spoolSdk?;
@@ -11,12 +12,7 @@ export default class DripSdk {
11
12
  getAllVaults(): Promise<Vault[]>;
12
13
  getVaultDetails(vaultAddress: string): Promise<Vault>;
13
14
  authenticate(): Promise<boolean>;
14
- isUserAuthenticated(): Promise<{
15
- isAuthenticated: boolean;
16
- address?: string;
17
- token?: string;
18
- message?: string;
19
- }>;
15
+ isUserAuthenticated(): Promise<AuthenticationStatus>;
20
16
  updateSigner(newSigner: Signer): void;
21
17
  getUserBalance(vault: Vault): Promise<UserBalance>;
22
18
  fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<void>;
package/dist/DripSdk.js CHANGED
@@ -18,7 +18,7 @@ const ethers_1 = require("ethers");
18
18
  const utils_1 = require("./utils");
19
19
  const DripApi_1 = __importDefault(require("./DripApi"));
20
20
  const js_cookie_1 = __importDefault(require("js-cookie"));
21
- const KASU_USDC_VAULT_ADDRESS = "0xd8aa8099a53eddebe6a49c98ca12746ff19aa502";
21
+ const KASU_USDC_VAULT_ADDRESS = '0xd8aa8099a53eddebe6a49c98ca12746ff19aa502';
22
22
  class DripSdk {
23
23
  constructor(dripConfig, signer) {
24
24
  this.signer = signer;
@@ -62,18 +62,18 @@ class DripSdk {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
63
  try {
64
64
  if (!this.signer) {
65
- return { isAuthenticated: false, message: "Signer not provided" };
65
+ return { isAuthenticated: false, message: 'Signer not provided' };
66
66
  }
67
67
  const userAddress = yield this.signer.getAddress();
68
68
  const cookieName = `auth_${userAddress.toLowerCase()}`;
69
69
  const authToken = js_cookie_1.default.get(cookieName);
70
70
  if (!authToken) {
71
- return { isAuthenticated: false, message: "Auth token not found" };
71
+ return { isAuthenticated: false, message: 'Auth token not found' };
72
72
  }
73
73
  const { address } = web3_token_1.default.verify(authToken);
74
74
  if (address.toLowerCase() !== userAddress.toLowerCase()) {
75
75
  js_cookie_1.default.remove(cookieName);
76
- return { isAuthenticated: false, message: "Invalid token" };
76
+ return { isAuthenticated: false, message: 'Invalid token' };
77
77
  }
78
78
  return { isAuthenticated: true, address: address.toLowerCase(), token: authToken };
79
79
  }
@@ -271,7 +271,7 @@ class DripSdk {
271
271
  return __awaiter(this, void 0, void 0, function* () {
272
272
  const token = yield this.generateToken();
273
273
  const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
274
- const withdrawAll = (!amountToWithdraw);
274
+ const withdrawAll = !amountToWithdraw;
275
275
  const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
276
276
  let totalAmountToWithdraw = initialAmountToWithdraw;
277
277
  let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
@@ -309,7 +309,7 @@ class DripSdk {
309
309
  smartVault: vault.vaultAddress.toLowerCase(),
310
310
  shares: shares,
311
311
  nftIds,
312
- nftAmounts
312
+ nftAmounts,
313
313
  };
314
314
  });
315
315
  }
@@ -317,7 +317,9 @@ class DripSdk {
317
317
  return __awaiter(this, void 0, void 0, function* () {
318
318
  const token = yield this.generateToken();
319
319
  const svts = yield this.dripApi.fetchUserSVTFromNfts(vaultAddress, userAddress, dnfts.map((element) => parseInt(element.nftId)), token);
320
- const result = dnfts.map((element, index) => { return { nftId: element.nftId, assets: element.assets, shares: element.shares, svts: svts[index] }; });
320
+ const result = dnfts.map((element, index) => {
321
+ return { nftId: element.nftId, assets: element.assets, shares: element.shares, svts: svts[index] };
322
+ });
321
323
  return result;
322
324
  });
323
325
  }
@@ -404,9 +406,10 @@ class DripSdk {
404
406
  shouldUseNewWithdrawLogic(userAddress, vault) {
405
407
  // Users that already withdrew using the old approach should keep using the same
406
408
  const usersWhoAlreadyWithdraw = {
407
- '0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS
409
+ '0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS,
408
410
  };
409
- if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] && usersWhoAlreadyWithdraw[userAddress.toLowerCase()] === vault.vaultAddress.toLowerCase()) {
411
+ if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] &&
412
+ usersWhoAlreadyWithdraw[userAddress.toLowerCase()] === vault.vaultAddress.toLowerCase()) {
410
413
  return false;
411
414
  }
412
415
  return vault.newWithdraw;
package/dist/test.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { ethers } from "ethers";
1
+ import { ethers } from 'ethers';
2
2
  export declare const signer: ethers.Wallet;
@@ -0,0 +1,6 @@
1
+ export type AuthenticationStatus = {
2
+ isAuthenticated: boolean;
3
+ address?: string;
4
+ token?: string;
5
+ message?: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "prepublish": "npm run build",
9
9
  "build": "tsc",
10
+ "format": "prettier --write .",
10
11
  "test": "echo \"Error: no test specified\" && exit 1"
11
12
  },
12
13
  "dependencies": {
@@ -19,6 +20,8 @@
19
20
  "license": "ISC",
20
21
  "devDependencies": {
21
22
  "typescript": "^5.4.5",
22
- "@types/js-cookie": "^3.0.6"
23
+ "@types/js-cookie": "^3.0.6",
24
+ "prettier": "3.2.5",
25
+ "prettier-plugin-tailwindcss": "^0.5.12"
23
26
  }
24
27
  }