@dripfi/drip-sdk 1.0.4 → 1.0.5
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 +47 -0
- package/dist/DripApi.js +5 -7
- package/dist/DripSdk.d.ts +8 -0
- package/dist/DripSdk.js +55 -4
- package/dist/test.d.ts +2 -0
- package/dist/test.js +24 -0
- package/package.json +5 -3
package/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Drip SDK
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
The Drip SDK is a TypeScript library designed to interact with the Drip protocol. It provides methods to retrieve information about Drip Vaults, manage user authentication, and fetch user balances.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To use the Drip SDK in your project, you can install it via npm or yarn:
|
10
|
+
|
11
|
+
```npm
|
12
|
+
npm i @dripfi/drip-sdk
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```typescript
|
18
|
+
import DripSdk from '@drip/sdk';
|
19
|
+
```
|
20
|
+
|
21
|
+
Initialize the SDK with your Drip configuration and an optional signer:
|
22
|
+
|
23
|
+
```typescript
|
24
|
+
const dripConfig = new DripConfig(/* configuration */);
|
25
|
+
const signer = /* your Signer instance */;
|
26
|
+
const dripSdk = new DripSdk(dripConfig, signer);
|
27
|
+
```
|
28
|
+
|
29
|
+
## Methods
|
30
|
+
|
31
|
+
- **getAllVaults(): Promise<Vault[]>**
|
32
|
+
Fetches details of all Drip Vaults.
|
33
|
+
|
34
|
+
- **getVaultDetails(vaultAddress: string): Promise<Vault>**
|
35
|
+
Fetches details of a specific Drip Vault identified by its address.
|
36
|
+
|
37
|
+
- **authenticate(): Promise<boolean>**
|
38
|
+
Initiates the user authentication process and returns a boolean indicating success.
|
39
|
+
|
40
|
+
- **isUserAuthenticated(): Promise<{ isAuthenticated: boolean, address?: string, token?: string, message?: string }>**
|
41
|
+
Checks if the user is authenticated and returns authentication status along with relevant information.
|
42
|
+
|
43
|
+
- **updateSigner(newSigner: Signer)**
|
44
|
+
Updates the signer for the SDK instance.
|
45
|
+
|
46
|
+
- **getUserBalance(vault: Vault): Promise<UserBalance>**
|
47
|
+
Fetches the user's balance for a specific Drip Vault.
|
package/dist/DripApi.js
CHANGED
@@ -61,7 +61,7 @@ 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
66
|
const data = yield res.json();
|
67
67
|
return data;
|
@@ -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,7 @@ 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
|
87
|
-
Authorization: token,
|
88
|
-
},
|
86
|
+
headers
|
89
87
|
});
|
90
88
|
const data = yield res.json();
|
91
89
|
return data;
|
@@ -118,7 +116,7 @@ class DripApi {
|
|
118
116
|
const headers = new Headers();
|
119
117
|
headers.append('Authorization', token);
|
120
118
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/assetBalance/${blocknumber}/${vaultAddress}`, {
|
121
|
-
headers
|
119
|
+
headers
|
122
120
|
});
|
123
121
|
const data = yield res.json();
|
124
122
|
return data;
|
@@ -129,7 +127,7 @@ class DripApi {
|
|
129
127
|
const headers = new Headers();
|
130
128
|
headers.append('Authorization', token);
|
131
129
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/fastWithdrawNft/${walletAddress}/${vaultAddress}`, {
|
132
|
-
headers
|
130
|
+
headers
|
133
131
|
});
|
134
132
|
const data = yield res.json();
|
135
133
|
return data;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -10,6 +10,14 @@ export default class DripSdk {
|
|
10
10
|
constructor(dripConfig: DripConfig, signer?: Signer);
|
11
11
|
getAllVaults(): Promise<Vault[]>;
|
12
12
|
getVaultDetails(vaultAddress: string): Promise<Vault>;
|
13
|
+
authenticate(): Promise<boolean>;
|
14
|
+
isUserAuthenticated(): Promise<{
|
15
|
+
isAuthenticated: boolean;
|
16
|
+
address?: string;
|
17
|
+
token?: string;
|
18
|
+
message?: string;
|
19
|
+
}>;
|
20
|
+
updateSigner(newSigner: Signer): void;
|
13
21
|
getUserBalance(vault: Vault): Promise<UserBalance>;
|
14
22
|
private fastWithdraw;
|
15
23
|
private deposit;
|
package/dist/DripSdk.js
CHANGED
@@ -17,6 +17,7 @@ const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
|
|
17
17
|
const ethers_1 = require("ethers");
|
18
18
|
const utils_1 = require("./utils");
|
19
19
|
const DripApi_1 = __importDefault(require("./DripApi"));
|
20
|
+
const js_cookie_1 = __importDefault(require("js-cookie"));
|
20
21
|
const KASU_USDC_VAULT_ADDRESS = "0xd8aa8099a53eddebe6a49c98ca12746ff19aa502";
|
21
22
|
class DripSdk {
|
22
23
|
constructor(dripConfig, signer) {
|
@@ -37,12 +38,62 @@ class DripSdk {
|
|
37
38
|
return this.dripApi.fetchVaultDetails(vaultAddress);
|
38
39
|
});
|
39
40
|
}
|
41
|
+
authenticate() {
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
43
|
+
try {
|
44
|
+
if (!this.signer)
|
45
|
+
throw Error('No signer provided');
|
46
|
+
const address = yield this.signer.getAddress();
|
47
|
+
const cookieName = `auth_${address.toLowerCase()}`;
|
48
|
+
const token = yield web3_token_1.default.sign((msg) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(msg); }), {
|
49
|
+
statement: 'Please sign this message to authenticate.',
|
50
|
+
expires_in: '30d',
|
51
|
+
});
|
52
|
+
js_cookie_1.default.set(cookieName, token, { expires: 30 });
|
53
|
+
return true;
|
54
|
+
}
|
55
|
+
catch (error) {
|
56
|
+
console.error('Error obtaining token:', error);
|
57
|
+
}
|
58
|
+
return false;
|
59
|
+
});
|
60
|
+
}
|
61
|
+
isUserAuthenticated() {
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
63
|
+
try {
|
64
|
+
if (!this.signer) {
|
65
|
+
return { isAuthenticated: false, message: "Signer not provided" };
|
66
|
+
}
|
67
|
+
const userAddress = yield this.signer.getAddress();
|
68
|
+
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
69
|
+
const authToken = js_cookie_1.default.get(cookieName);
|
70
|
+
if (!authToken) {
|
71
|
+
return { isAuthenticated: false, message: "Auth token not found" };
|
72
|
+
}
|
73
|
+
const { address } = web3_token_1.default.verify(authToken);
|
74
|
+
if (address.toLowerCase() !== userAddress.toLowerCase()) {
|
75
|
+
js_cookie_1.default.remove(cookieName);
|
76
|
+
return { isAuthenticated: false, message: "Invalid token" };
|
77
|
+
}
|
78
|
+
return { isAuthenticated: true, address: address.toLowerCase(), token: authToken };
|
79
|
+
}
|
80
|
+
catch (error) {
|
81
|
+
console.log(error);
|
82
|
+
}
|
83
|
+
return { isAuthenticated: false };
|
84
|
+
});
|
85
|
+
}
|
86
|
+
updateSigner(newSigner) {
|
87
|
+
this.signer = newSigner;
|
88
|
+
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.dripConfig.internalConfig, newSigner);
|
89
|
+
}
|
40
90
|
getUserBalance(vault) {
|
41
91
|
return __awaiter(this, void 0, void 0, function* () {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
const
|
92
|
+
const authData = yield this.isUserAuthenticated();
|
93
|
+
if (!authData.isAuthenticated)
|
94
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
95
|
+
const userAddress = authData.address;
|
96
|
+
const token = authData.token;
|
46
97
|
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vault.vaultAddress, userAddress, token);
|
47
98
|
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vault.vaultAddress, userAddress, token);
|
48
99
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
package/dist/test.d.ts
ADDED
package/dist/test.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.signer = void 0;
|
4
|
+
const ethers_1 = require("ethers");
|
5
|
+
const _1 = require(".");
|
6
|
+
const dripProdConfig = new _1.DripConfig('https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2/api', 'https://pricefeed.v2.spool.fi/', 'https://rewards.v2.spool.fi/', 'https://fastwithdraw.v2.spool.fi/', {
|
7
|
+
1: {
|
8
|
+
ISmartVaultManager: '0x23Daf34e2b9Af02A74dC19cB52Af727B19403874',
|
9
|
+
IDepositSwap: '0xd8534197Bd587F8226d12E0C864ef2CaE6f82f5C',
|
10
|
+
ISmartVaultFactory: '0x8049Fc710D4a1Deea6a6bCeF772C166CEd7A82F5',
|
11
|
+
IDepositManager: '0x823Ba38992825FF37E72B6c3D669a09173B8F7bf',
|
12
|
+
IRewardManager: '0xd8d2C1C3C7982272e3e12dEC5aF681433fdcf003',
|
13
|
+
IStrategyRegistry: '0x554c6bCB54656390aca0a0af38CA954dbE653F15',
|
14
|
+
ISpoolLens: '0x8aa6174333F75421903b2B5c70DdF8DA5D84f74F',
|
15
|
+
},
|
16
|
+
}, 'http://localhost:7070');
|
17
|
+
const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider('https://mainnet.infura.io/v3/fa1bf2cea12147559c9634e80be76d61', 1);
|
18
|
+
exports.signer = new ethers_1.ethers.Wallet('6ffc226f7b7769e27124317372c9dbb579a324e67e97bf07131bf2f59ec0f4fe', provider);
|
19
|
+
const dripSdk = new _1.DripSdk(dripProdConfig, exports.signer);
|
20
|
+
// dripSdk.isUserAuthenticated().then((result) => {
|
21
|
+
// console.log(result)
|
22
|
+
// }).catch((error) => {
|
23
|
+
// console.log(error)
|
24
|
+
// })
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.5",
|
4
4
|
"description": "Drip SDK",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -12,11 +12,13 @@
|
|
12
12
|
"dependencies": {
|
13
13
|
"@spool.fi/spool-v2-sdk": "1.0.14",
|
14
14
|
"ethers": "^5.7.2",
|
15
|
-
"web3-token": "^1.0.6"
|
15
|
+
"web3-token": "^1.0.6",
|
16
|
+
"js-cookie": "^3.0.5"
|
16
17
|
},
|
17
18
|
"author": "",
|
18
19
|
"license": "ISC",
|
19
20
|
"devDependencies": {
|
20
|
-
"typescript": "^5.4.5"
|
21
|
+
"typescript": "^5.4.5",
|
22
|
+
"@types/js-cookie": "^3.0.6"
|
21
23
|
}
|
22
24
|
}
|