@dripfi/drip-sdk 1.3.1 → 1.3.3
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/dist/DripApi.d.ts +3 -2
- package/dist/DripApi.js +17 -0
- package/dist/DripSdk.d.ts +3 -2
- package/dist/DripSdk.js +64 -15
- package/dist/types/SignedPayload.d.ts +9 -2
- package/package.json +1 -1
package/dist/DripApi.d.ts
CHANGED
@@ -11,7 +11,7 @@ import { LoyaltyCard } from './types/LoyaltyCard';
|
|
11
11
|
import { BeansBalance } from './types/BeansBalance';
|
12
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
13
13
|
import BeanEntry from './types/BeanEntry';
|
14
|
-
import {
|
14
|
+
import { NonceEnrichedSignedPayload, NonceEnrichedPayload } from './types/SignedPayload';
|
15
15
|
import { UpgradeLoyaltyCardPayload } from './types/UpgradeLoyaltyCardPayload';
|
16
16
|
export default class DripApi {
|
17
17
|
route: string;
|
@@ -37,8 +37,9 @@ export default class DripApi {
|
|
37
37
|
fetchAllLoyaltyCards(): Promise<LoyaltyCard[]>;
|
38
38
|
fetchOwnedLoyaltyCard(walletAddress: string): Promise<LoyaltyCard>;
|
39
39
|
fetchBeansBalance(walletAddress: string): Promise<BeansBalance>;
|
40
|
-
upgradeLoyaltyCard(signedPayload:
|
40
|
+
upgradeLoyaltyCard(signedPayload: NonceEnrichedSignedPayload<UpgradeLoyaltyCardPayload>): Promise<LoyaltyCard>;
|
41
41
|
fetchMyPerqData(userAddress: string): Promise<MyPerqData>;
|
42
42
|
getSwapPerqForBeansInfo(): Promise<PerqToBeansSwapInfo>;
|
43
43
|
fetchBeansHistory(walletAddress: string): Promise<BeanEntry[]>;
|
44
|
+
getNonceEnrichedPayload<T>(payload: T): Promise<NonceEnrichedPayload<T>>;
|
44
45
|
}
|
package/dist/DripApi.js
CHANGED
@@ -378,5 +378,22 @@ class DripApi {
|
|
378
378
|
}
|
379
379
|
});
|
380
380
|
}
|
381
|
+
getNonceEnrichedPayload(payload) {
|
382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
383
|
+
const res = yield fetch(`${this.route}/api-be/api/nonce`, {
|
384
|
+
method: 'POST',
|
385
|
+
headers: {
|
386
|
+
'Content-Type': 'application/json',
|
387
|
+
},
|
388
|
+
body: JSON.stringify({ payload }), // Wrap in payload property for BE
|
389
|
+
});
|
390
|
+
if (!res.ok) {
|
391
|
+
throw new Error('Failed to get nonce-enriched payload');
|
392
|
+
}
|
393
|
+
const enrichedPayload = yield res.json();
|
394
|
+
// Return the enriched payload without the extra nesting
|
395
|
+
return enrichedPayload.payload;
|
396
|
+
});
|
397
|
+
}
|
381
398
|
}
|
382
399
|
exports.default = DripApi;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -12,7 +12,7 @@ import { BeansBalance } from './types/BeansBalance';
|
|
12
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
13
13
|
import BeanEntry from './types/BeanEntry';
|
14
14
|
import { VestingInfo } from './types/VestingInfo';
|
15
|
-
import {
|
15
|
+
import { NonceEnrichedSignedPayload } from './types/SignedPayload';
|
16
16
|
export default class DripSdk {
|
17
17
|
private dripApi;
|
18
18
|
private dripTokenContract;
|
@@ -72,7 +72,8 @@ export default class DripSdk {
|
|
72
72
|
getAllVestingInfo(beneficiaryAddress: string): Promise<VestingInfo>;
|
73
73
|
claimVestedPerq(amount: string): Promise<string>;
|
74
74
|
burnVestedPerq(amount: string, price: string, deadline: string, signature: string): Promise<string>;
|
75
|
-
signPayload<T
|
75
|
+
signPayload<T>(payload: T): Promise<NonceEnrichedSignedPayload<T>>;
|
76
|
+
private getEnrichedPayload;
|
76
77
|
private generateRedeemBagStruct;
|
77
78
|
private getERC20Precission;
|
78
79
|
private calculatePendingDeposits;
|
package/dist/DripSdk.js
CHANGED
@@ -167,21 +167,57 @@ class DripSdk {
|
|
167
167
|
}
|
168
168
|
getUserVaultBalance(vaultAddress) {
|
169
169
|
return __awaiter(this, void 0, void 0, function* () {
|
170
|
+
if (!this.signer) {
|
171
|
+
throw Error('No signer provided');
|
172
|
+
}
|
170
173
|
const userAddress = yield this.signer.getAddress();
|
171
|
-
|
172
|
-
const
|
173
|
-
|
174
|
+
// Parallel fetch of vault, user dnfts and user wnfts
|
175
|
+
const [vault, userDnftsForVault, userWnftsForVault] = yield Promise.all([
|
176
|
+
this.getVaultDetails(vaultAddress),
|
177
|
+
this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress),
|
178
|
+
this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress),
|
179
|
+
]);
|
174
180
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
const
|
181
|
+
// Calculate deposits
|
182
|
+
let pendingDeposits = ethers_1.BigNumber.from(0);
|
183
|
+
let currentlyDeposited = ethers_1.BigNumber.from(0);
|
184
|
+
for (const dnft of userDnftsForVault) {
|
185
|
+
if (dnft.assets && dnft.assets[0]) {
|
186
|
+
const amount = ethers_1.ethers.utils.parseUnits(dnft.assets[0].toString(), decimals);
|
187
|
+
if (!dnft.isDHWFinished) {
|
188
|
+
// Pending deposits (not yet processed)
|
189
|
+
pendingDeposits = pendingDeposits.add(amount);
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
// Processed deposits
|
193
|
+
currentlyDeposited = currentlyDeposited.add(amount);
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
// Calculate withdrawals
|
198
|
+
let pendingWithdraws = ethers_1.BigNumber.from(0);
|
199
|
+
let claimable = ethers_1.BigNumber.from(0);
|
200
|
+
for (const wnft of userWnftsForVault) {
|
201
|
+
if (!wnft.isBurned && wnft.svtWithdrawn) {
|
202
|
+
const currentBlockNumber = wnft.blockNumber - 1;
|
203
|
+
const assetsPerSvtAtBlock = yield this.dripApi.fetchAssetPerSvtAtBlock(vaultAddress, currentBlockNumber);
|
204
|
+
const estimatedValueOfNFT = ethers_1.BigNumber.from(ethers_1.ethers.utils.formatUnits(ethers_1.BigNumber.from(wnft.svtWithdrawn).mul(assetsPerSvtAtBlock), 36).split('.')[0]);
|
205
|
+
if (wnft.isDHWFinished) {
|
206
|
+
// Processed and claimable
|
207
|
+
claimable = claimable.add(estimatedValueOfNFT);
|
208
|
+
}
|
209
|
+
else {
|
210
|
+
// Not processed, pending withdrawal
|
211
|
+
pendingWithdraws = pendingWithdraws.add(estimatedValueOfNFT);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}
|
179
215
|
return {
|
180
|
-
hasWithdrawsToClaim,
|
181
|
-
userBalance: ethers_1.ethers.utils.formatUnits(
|
216
|
+
hasWithdrawsToClaim: claimable.gt(0),
|
217
|
+
userBalance: ethers_1.ethers.utils.formatUnits(currentlyDeposited, decimals),
|
182
218
|
pendingUserBalance: ethers_1.ethers.utils.formatUnits(pendingDeposits, decimals),
|
183
|
-
pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(
|
184
|
-
withdrawableBalance: ethers_1.ethers.utils.formatUnits(
|
219
|
+
pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(pendingWithdraws, decimals),
|
220
|
+
withdrawableBalance: ethers_1.ethers.utils.formatUnits(claimable, decimals),
|
185
221
|
};
|
186
222
|
});
|
187
223
|
}
|
@@ -347,7 +383,9 @@ class DripSdk {
|
|
347
383
|
}
|
348
384
|
upgradeLoyaltyCard(index) {
|
349
385
|
return __awaiter(this, void 0, void 0, function* () {
|
350
|
-
const payload = {
|
386
|
+
const payload = {
|
387
|
+
index
|
388
|
+
};
|
351
389
|
const signedPayload = yield this.signPayload(payload);
|
352
390
|
return this.dripApi.upgradeLoyaltyCard(signedPayload);
|
353
391
|
});
|
@@ -557,20 +595,31 @@ class DripSdk {
|
|
557
595
|
signPayload(payload) {
|
558
596
|
return __awaiter(this, void 0, void 0, function* () {
|
559
597
|
if (!this.signer) {
|
560
|
-
throw Error('No signer provided');
|
598
|
+
throw new Error('No signer provided');
|
561
599
|
}
|
600
|
+
// Wrap the payload in a Basepayload to enrich it later on
|
601
|
+
const basePayload = {
|
602
|
+
payload
|
603
|
+
};
|
562
604
|
const signerAddress = yield this.signer.getAddress();
|
605
|
+
// Get enriched payload with nonce before signing
|
606
|
+
const enrichedPayload = yield this.getEnrichedPayload(basePayload);
|
563
607
|
// Create message to sign
|
564
|
-
const message = JSON.stringify(
|
608
|
+
const message = JSON.stringify(enrichedPayload);
|
565
609
|
// Sign the message
|
566
610
|
const signature = yield this.signer.signMessage(message);
|
567
611
|
return {
|
568
612
|
signature,
|
569
613
|
signerAddress,
|
570
|
-
payload,
|
614
|
+
payload: enrichedPayload,
|
571
615
|
};
|
572
616
|
});
|
573
617
|
}
|
618
|
+
getEnrichedPayload(payload) {
|
619
|
+
return __awaiter(this, void 0, void 0, function* () {
|
620
|
+
return this.dripApi.getNonceEnrichedPayload(payload.payload);
|
621
|
+
});
|
622
|
+
}
|
574
623
|
generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
|
575
624
|
return __awaiter(this, void 0, void 0, function* () {
|
576
625
|
if (!this.spoolSdk) {
|
@@ -1,5 +1,12 @@
|
|
1
|
-
export type
|
1
|
+
export type BasePayload<T> = {
|
2
|
+
payload: T;
|
3
|
+
};
|
4
|
+
export type NonceEnrichedPayload<T> = T & {
|
5
|
+
deadline: number;
|
6
|
+
signature: string;
|
7
|
+
};
|
8
|
+
export type NonceEnrichedSignedPayload<T> = {
|
2
9
|
signature: string;
|
3
10
|
signerAddress: string;
|
4
|
-
payload: T
|
11
|
+
payload: NonceEnrichedPayload<T>;
|
5
12
|
};
|