@dripfi/drip-sdk 1.1.27 → 1.2.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/README.md +8 -8
- package/dist/DripConfig.d.ts +6 -2
- package/dist/DripConfig.js +29 -6
- package/dist/DripSdk.d.ts +2 -3
- package/dist/DripSdk.js +34 -65
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/test.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
@@ -23,20 +23,20 @@ npm i @dripfi/drip-sdk
|
|
23
23
|
|
24
24
|
```typescript
|
25
25
|
import DripSdk from '@drip/sdk'
|
26
|
+
import { DripConfig, Chain } from '@dripfi/drip-sdk'
|
26
27
|
```
|
27
28
|
|
28
29
|
Initialize the SDK with your Drip configuration and an optional signer:
|
29
30
|
|
30
31
|
```typescript
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
contracts: Record<number, ContractAddresses>,
|
37
|
-
dripRoute: string);
|
32
|
+
|
33
|
+
const chain: Chain = Chain.MAINNET // if targeting ethereum mainnet
|
34
|
+
|
35
|
+
const chain: Chain = Chain.SEPOLIA // if targeting sepolia testnet
|
36
|
+
|
38
37
|
const signer: ethers.Signer = /* your Signer instance */;
|
39
|
-
|
38
|
+
|
39
|
+
const dripSdk = new DripSdk(chain, signer);
|
40
40
|
```
|
41
41
|
|
42
42
|
# Methods
|
package/dist/DripConfig.d.ts
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { SDKConfig } from '@spool.fi/spool-v2-sdk';
|
2
2
|
import { Signer } from 'ethers';
|
3
3
|
export declare const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
4
4
|
export declare const DRIP_TOKEN_DECIMALS = 18;
|
5
|
+
export declare enum Chain {
|
6
|
+
MAINNET = "mainnet",
|
7
|
+
SEPOLIA = "sepolia"
|
8
|
+
}
|
5
9
|
export declare class DripConfig {
|
6
10
|
internalConfig: SDKConfig;
|
7
11
|
dripRoute: string;
|
@@ -9,7 +13,7 @@ export declare class DripConfig {
|
|
9
13
|
smartVaultManagerAddress: string | undefined;
|
10
14
|
dripTokenAddress: string;
|
11
15
|
dripTokenRecyclerAddress: string;
|
12
|
-
constructor(
|
16
|
+
constructor(chain: Chain, dripRoute?: string);
|
13
17
|
getSwapAndDepositContractAddress(signer: Signer): Promise<string>;
|
14
18
|
getSmartVaultManagerAddress(signer: Signer): Promise<string>;
|
15
19
|
}
|
package/dist/DripConfig.js
CHANGED
@@ -9,16 +9,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.DripConfig = exports.DRIP_TOKEN_DECIMALS = exports.NULL_ADDRESS = void 0;
|
12
|
+
exports.DripConfig = exports.Chain = exports.DRIP_TOKEN_DECIMALS = exports.NULL_ADDRESS = void 0;
|
13
13
|
const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
|
14
14
|
exports.NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
15
15
|
exports.DRIP_TOKEN_DECIMALS = 18;
|
16
|
+
var Chain;
|
17
|
+
(function (Chain) {
|
18
|
+
Chain["MAINNET"] = "mainnet";
|
19
|
+
Chain["SEPOLIA"] = "sepolia";
|
20
|
+
})(Chain || (exports.Chain = Chain = {}));
|
21
|
+
const SUBGRAPH_URL_SEPOLIA = 'https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2-sepolia/api';
|
22
|
+
const RECYCLER_ADDRESS_SEPOLIA = '0x463aea273644AfF560da07c7c09f3142b87E12f1';
|
23
|
+
const DRIP_TOKEN_ADDRESS_SEPOLIA = '0xc9C66052327523d6A7a2ee5D50CF07e4415e27c7';
|
24
|
+
const SUBGRAPH_URL_MAINNET = 'https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2/api';
|
25
|
+
// const RECYCLER_ADDRESS_MAINNET = '';
|
26
|
+
// const DRIP_TOKEN_ADDRESS_MAINNET = '';
|
27
|
+
const DEV_BACKEND_ROUTE = 'https://dev.drip.fi.io';
|
28
|
+
const PROD_BACKEND_ROUTE = 'https://perq.finance';
|
16
29
|
class DripConfig {
|
17
|
-
constructor(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
30
|
+
constructor(chain, dripRoute) {
|
31
|
+
switch (chain) {
|
32
|
+
case Chain.MAINNET:
|
33
|
+
this.internalConfig = (0, spool_v2_sdk_1.getMainnetConfig)(SUBGRAPH_URL_MAINNET);
|
34
|
+
this.dripRoute = dripRoute ? dripRoute : PROD_BACKEND_ROUTE;
|
35
|
+
this.dripTokenAddress = exports.NULL_ADDRESS;
|
36
|
+
this.dripTokenRecyclerAddress = exports.NULL_ADDRESS;
|
37
|
+
break;
|
38
|
+
case Chain.SEPOLIA:
|
39
|
+
this.internalConfig = (0, spool_v2_sdk_1.getSepoliaConfig)(SUBGRAPH_URL_SEPOLIA);
|
40
|
+
this.dripRoute = dripRoute ? dripRoute : DEV_BACKEND_ROUTE;
|
41
|
+
this.dripTokenAddress = DRIP_TOKEN_ADDRESS_SEPOLIA;
|
42
|
+
this.dripTokenRecyclerAddress = RECYCLER_ADDRESS_SEPOLIA;
|
43
|
+
break;
|
44
|
+
}
|
22
45
|
}
|
23
46
|
getSwapAndDepositContractAddress(signer) {
|
24
47
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/DripSdk.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { Signer } from 'ethers';
|
2
|
-
import { DripConfig } from './DripConfig';
|
3
2
|
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
4
3
|
import { UserRewards } from './types/UserRewards';
|
5
4
|
import { VaultStats } from './types/VaultStats';
|
@@ -9,6 +8,7 @@ import { VaultClaimData } from './types/VaultClaimData';
|
|
9
8
|
import { Vault } from './types/Vault';
|
10
9
|
import { LoyaltyCard } from './types/LoyaltyCard';
|
11
10
|
import MyPerqData from './types/MyPerqData';
|
11
|
+
import { Chain } from './DripConfig';
|
12
12
|
export default class DripSdk {
|
13
13
|
private dripApi;
|
14
14
|
private dripTokenContract;
|
@@ -16,7 +16,7 @@ export default class DripSdk {
|
|
16
16
|
private spoolSdk?;
|
17
17
|
private signer?;
|
18
18
|
private dripConfig;
|
19
|
-
constructor(
|
19
|
+
constructor(chain: Chain, signer?: Signer, dripRoute?: string);
|
20
20
|
getAllVaults(): Promise<Vault[]>;
|
21
21
|
getVaultDetails(vaultAddress: string): Promise<Vault>;
|
22
22
|
getVaultStats(): Promise<VaultStats>;
|
@@ -54,7 +54,6 @@ export default class DripSdk {
|
|
54
54
|
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
|
55
55
|
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<string>;
|
56
56
|
private generateRedeemBagStruct;
|
57
|
-
private getAllSvts;
|
58
57
|
private getERC20Precission;
|
59
58
|
private calculatePendingDeposits;
|
60
59
|
private calculateAllDeposits;
|
package/dist/DripSdk.js
CHANGED
@@ -21,15 +21,15 @@ const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
21
21
|
const DripTokenContract_1 = __importDefault(require("./contracts/DripTokenContract"));
|
22
22
|
const DripTokenRecyclerContract_1 = __importDefault(require("./contracts/DripTokenRecyclerContract"));
|
23
23
|
class DripSdk {
|
24
|
-
constructor(
|
24
|
+
constructor(chain, signer, dripRoute) {
|
25
25
|
this.signer = signer;
|
26
|
-
this.dripConfig =
|
26
|
+
this.dripConfig = new DripConfig_1.DripConfig(chain, dripRoute);
|
27
27
|
if (signer) {
|
28
|
-
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(dripConfig.internalConfig, signer);
|
28
|
+
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.dripConfig.internalConfig, signer);
|
29
29
|
}
|
30
|
-
this.dripApi = new DripApi_1.default(dripConfig.dripRoute);
|
31
|
-
this.dripTokenContract = new DripTokenContract_1.default(dripConfig.dripTokenAddress, signer);
|
32
|
-
this.dripTokenRecyclerContract = new DripTokenRecyclerContract_1.default(dripConfig.dripTokenRecyclerAddress, signer);
|
30
|
+
this.dripApi = new DripApi_1.default(this.dripConfig.dripRoute);
|
31
|
+
this.dripTokenContract = new DripTokenContract_1.default(this.dripConfig.dripTokenAddress, signer);
|
32
|
+
this.dripTokenRecyclerContract = new DripTokenRecyclerContract_1.default(this.dripConfig.dripTokenRecyclerAddress, signer);
|
33
33
|
}
|
34
34
|
getAllVaults() {
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -229,14 +229,17 @@ class DripSdk {
|
|
229
229
|
fastWithdraw(vaultAddress, amountToWithdraw) {
|
230
230
|
return __awaiter(this, void 0, void 0, function* () {
|
231
231
|
var _a, _b;
|
232
|
+
if (!this.signer) {
|
233
|
+
throw Error('No signer provided');
|
234
|
+
}
|
232
235
|
const userAddress = yield this.signer.getAddress();
|
233
|
-
const authData =
|
236
|
+
// const authData = await this.isUserAuthenticated();
|
234
237
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
235
238
|
if (!this.signer) {
|
236
239
|
throw Error('No signer provided');
|
237
240
|
}
|
238
241
|
const vault = yield this.getVaultDetails(vaultAddress);
|
239
|
-
const redeemBagStruct = yield this.generateRedeemBagStruct(
|
242
|
+
const redeemBagStruct = yield this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
|
240
243
|
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
241
244
|
if (!currentBlockNumber) {
|
242
245
|
throw Error('Error fetching block number');
|
@@ -292,14 +295,17 @@ class DripSdk {
|
|
292
295
|
}
|
293
296
|
withdraw(vaultAddress, amountToWithdraw) {
|
294
297
|
return __awaiter(this, void 0, void 0, function* () {
|
298
|
+
if (!this.signer) {
|
299
|
+
throw Error('No signer provided');
|
300
|
+
}
|
295
301
|
const userAddress = yield this.signer.getAddress();
|
296
|
-
const authData =
|
302
|
+
// const authData = await this.isUserAuthenticated();
|
297
303
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
298
304
|
if (!this.signer) {
|
299
305
|
throw Error('No signer provided');
|
300
306
|
}
|
301
307
|
const vault = yield this.getVaultDetails(vaultAddress);
|
302
|
-
const redeemBagStruct = yield this.generateRedeemBagStruct(
|
308
|
+
const redeemBagStruct = yield this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
|
303
309
|
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, userAddress, false);
|
304
310
|
const redeemTxReceipt = yield redeemTx.wait();
|
305
311
|
return redeemTxReceipt.transactionHash;
|
@@ -428,62 +434,25 @@ class DripSdk {
|
|
428
434
|
return yield this.approveToken(tokenAddress, amount, smartVaultManagerAddress);
|
429
435
|
});
|
430
436
|
}
|
431
|
-
generateRedeemBagStruct(
|
432
|
-
return __awaiter(this, void 0, void 0, function* () {
|
433
|
-
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
|
434
|
-
const withdrawAll = !amountToWithdraw;
|
435
|
-
const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
|
436
|
-
let totalAmountToWithdraw = initialAmountToWithdraw;
|
437
|
-
let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
|
438
|
-
if (dnfts.length === 0) {
|
439
|
-
throw Error('User has no deposits');
|
440
|
-
}
|
441
|
-
dnfts = yield this.getAllSvts(vault.vaultAddress.toLowerCase(), signerAddress, dnfts, token);
|
442
|
-
let shares = ethers_1.BigNumber.from(0);
|
443
|
-
const nftIds = [];
|
444
|
-
const nftAmounts = [];
|
445
|
-
let index = 0;
|
446
|
-
while (dnfts[index] && (totalAmountToWithdraw.gt(0) || withdrawAll)) {
|
447
|
-
const dnft = dnfts[index];
|
448
|
-
const userBalance = this.calculateBalanceForDNFT(dnft, decimals);
|
449
|
-
if (userBalance.gt(0)) {
|
450
|
-
const amountToWithdraw = totalAmountToWithdraw;
|
451
|
-
const userSvts = dnft.svts;
|
452
|
-
let svtsToWithdraw = ethers_1.BigNumber.from(0);
|
453
|
-
let nftAmount = ethers_1.BigNumber.from(0);
|
454
|
-
if (amountToWithdraw.gte(userBalance) || withdrawAll) {
|
455
|
-
nftAmount = dnft.shares;
|
456
|
-
svtsToWithdraw = userSvts;
|
457
|
-
if (!withdrawAll) {
|
458
|
-
totalAmountToWithdraw = totalAmountToWithdraw.sub(userBalance);
|
459
|
-
}
|
460
|
-
}
|
461
|
-
else {
|
462
|
-
nftAmount = amountToWithdraw.mul(dnft.shares).div(userBalance);
|
463
|
-
svtsToWithdraw = nftAmount.mul(userSvts).div(dnft.shares);
|
464
|
-
totalAmountToWithdraw = totalAmountToWithdraw.sub(amountToWithdraw);
|
465
|
-
}
|
466
|
-
shares = shares.add(svtsToWithdraw);
|
467
|
-
nftIds.push(dnft.nftId);
|
468
|
-
nftAmounts.push(nftAmount);
|
469
|
-
}
|
470
|
-
index++;
|
471
|
-
}
|
472
|
-
return {
|
473
|
-
smartVault: vault.vaultAddress.toLowerCase(),
|
474
|
-
shares: shares,
|
475
|
-
nftIds,
|
476
|
-
nftAmounts,
|
477
|
-
};
|
478
|
-
});
|
479
|
-
}
|
480
|
-
getAllSvts(vaultAddress, userAddress, dnfts, token) {
|
437
|
+
generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
|
481
438
|
return __awaiter(this, void 0, void 0, function* () {
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
439
|
+
if (!this.spoolSdk) {
|
440
|
+
throw Error('No spool sdk provided');
|
441
|
+
}
|
442
|
+
const isFullWithdraw = !amountToWithdraw;
|
443
|
+
if (isFullWithdraw) {
|
444
|
+
return this.spoolSdk.views.userInfo.getMaxRedeemBag({
|
445
|
+
userAddress: signerAddress.toLowerCase(),
|
446
|
+
vaultAddress: vault.vaultAddress,
|
447
|
+
});
|
448
|
+
}
|
449
|
+
else {
|
450
|
+
return this.spoolSdk.views.userInfo.getMinimumBurnRedeemBag({
|
451
|
+
userAddress: signerAddress.toLowerCase(),
|
452
|
+
vaultAddress: vault.vaultAddress,
|
453
|
+
assetsToWithdraw: [Number(amountToWithdraw)]
|
454
|
+
});
|
455
|
+
}
|
487
456
|
});
|
488
457
|
}
|
489
458
|
getERC20Precission(tokenAddress) {
|
package/dist/index.d.ts
CHANGED
@@ -11,6 +11,6 @@ import { VaultType } from './types/VaultType';
|
|
11
11
|
import { UserVaultBalance } from './types/UserVaultBalance';
|
12
12
|
import { UserBalance } from './types/UserBalance';
|
13
13
|
import { VaultStats } from './types/VaultStats';
|
14
|
-
import {
|
14
|
+
import { Chain } from './DripConfig';
|
15
15
|
import MyPerqData from './types/MyPerqData';
|
16
|
-
export { Vault, VaultReward, DripSdk,
|
16
|
+
export { Vault, VaultReward, DripSdk, UserVaultBalance, UserBalance, VaultStats, AuthenticationStatus, NFTBoost, Strategy, StretchGoal, SwapInfo, VaultDepositToken, VaultType, MyPerqData, Chain };
|
package/dist/index.js
CHANGED
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.Chain = exports.DripSdk = void 0;
|
7
7
|
const DripSdk_1 = __importDefault(require("./DripSdk"));
|
8
8
|
exports.DripSdk = DripSdk_1.default;
|
9
9
|
const DripConfig_1 = require("./DripConfig");
|
10
|
-
Object.defineProperty(exports, "
|
10
|
+
Object.defineProperty(exports, "Chain", { enumerable: true, get: function () { return DripConfig_1.Chain; } });
|
package/dist/test.js
CHANGED
@@ -70,7 +70,7 @@ const daiVaultPerq = '0x1977efe478ba17da8be6e93fdfadbd3055d30111'; // DAI PERQ S
|
|
70
70
|
const usdcVaultPerq = '0xf9795bfbf7c40981c372d0fb25a87e0b694c4fcd'; // USDC PERQ SEPOLIA
|
71
71
|
const daiTokenAddress = '0x2a3a3872c242c35093a8fc48dac838c4b2d24a03'; // DAI TOKEN
|
72
72
|
const usdcTokenAddress = '0xa6b92fcd4ee124353c8a6acf1edb574f46f3f8df'; // USDC TOKEN
|
73
|
-
const dripSdk = new DripSdk_1.default(
|
73
|
+
const dripSdk = new DripSdk_1.default(DripConfig_1.Chain.SEPOLIA, exports.signer, 'https://localhost:3000');
|
74
74
|
// 0x689Baa4821865Cb328F5E847fB6133DEB315A832
|
75
75
|
// 0x9E9B6899Ea314dD553A99f4F49440d2CeD2b2848
|
76
76
|
function main() {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.0",
|
4
4
|
"description": "Drip SDK",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
12
12
|
},
|
13
13
|
"dependencies": {
|
14
|
-
"@spool.fi/spool-v2-sdk": "
|
14
|
+
"@spool.fi/spool-v2-sdk": "2.0.31",
|
15
15
|
"ethers": "^5.7.2",
|
16
16
|
"js-cookie": "^3.0.5",
|
17
17
|
"web3-token": "^1.0.6"
|