@dripfi/drip-sdk 1.4.26 → 1.4.28-bridge-perq

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,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const utils_1 = require("ethers/lib/utils");
5
+ // Chain IDs for LayerZero
6
+ const ENDPOINT_IDS = {
7
+ ETHEREUM_MAINNET: 30101,
8
+ SONIC_MAINNET: 30332,
9
+ };
10
+ class BridgePerqPackage {
11
+ perqSdk;
12
+ constructor(perqSdk) {
13
+ this.perqSdk = perqSdk;
14
+ }
15
+ /**
16
+ * Bridge PERQ tokens from Mainnet to Sonic
17
+ */
18
+ async bridgeMainnetToSonic(amount) {
19
+ try {
20
+ if (!this.perqSdk.signer) {
21
+ throw new Error('No signer provided');
22
+ }
23
+ // Get signer address for bridged tokens
24
+ const recipientAddress = await this.perqSdk.signer.getAddress();
25
+ // Check and handle approval first
26
+ const hasApproval = await this.checkMainnetToSonicBridgeApproval(amount);
27
+ if (!hasApproval) {
28
+ await this.approveMainnetToSonicBridge(amount);
29
+ }
30
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
31
+ const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
32
+ const sendParam = {
33
+ dstEid: ENDPOINT_IDS.SONIC_MAINNET,
34
+ to: recipientBytes32,
35
+ amountLD,
36
+ minAmountLD: amountLD, // No slippage for now
37
+ extraOptions: '0x',
38
+ composeMsg: '0x',
39
+ oftCmd: '0x',
40
+ };
41
+ // Get fee quote first
42
+ const feeQuote = await this.quoteMainnetToSonic(amount, recipientAddress, false);
43
+ const fee = {
44
+ nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
45
+ lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
46
+ };
47
+ // Send the transaction
48
+ const tx = await this.perqSdk.bridgeMainnetPerqToSonicContract.send(sendParam, fee, recipientAddress, {
49
+ value: fee.nativeFee,
50
+ });
51
+ const txReceipt = await tx.wait();
52
+ return txReceipt.transactionHash;
53
+ }
54
+ catch (error) {
55
+ if (error instanceof Error) {
56
+ throw new Error(`Failed to bridge Mainnet to Sonic: ${error.message}`);
57
+ }
58
+ throw new Error('Failed to bridge Mainnet to Sonic: Unknown error');
59
+ }
60
+ }
61
+ /**
62
+ * Bridge PERQ tokens from Sonic to Mainnet
63
+ */
64
+ async bridgeSonicToMainnet(amount) {
65
+ try {
66
+ if (!this.perqSdk.signer) {
67
+ throw new Error('No signer provided');
68
+ }
69
+ // Get signer address for bridged tokens
70
+ const recipientAddress = await this.perqSdk.signer.getAddress();
71
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
72
+ const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
73
+ const sendParam = {
74
+ dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
75
+ to: recipientBytes32,
76
+ amountLD,
77
+ minAmountLD: amountLD, // No slippage for now
78
+ extraOptions: '0x',
79
+ composeMsg: '0x',
80
+ oftCmd: '0x',
81
+ };
82
+ // Get fee quote first
83
+ const feeQuote = await this.quoteSonicToMainnet(amount, recipientAddress, false);
84
+ const fee = {
85
+ nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
86
+ lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
87
+ };
88
+ // Send the transaction
89
+ const tx = await this.perqSdk.bridgeSonicPerqToMainnetContract.send(sendParam, fee, recipientAddress, {
90
+ value: fee.nativeFee,
91
+ });
92
+ const txReceipt = await tx.wait();
93
+ return txReceipt.transactionHash;
94
+ }
95
+ catch (error) {
96
+ if (error instanceof Error) {
97
+ throw new Error(`Failed to bridge Sonic to Mainnet: ${error.message}`);
98
+ }
99
+ throw new Error('Failed to bridge Sonic to Mainnet: Unknown error');
100
+ }
101
+ }
102
+ /**
103
+ * Check if the Mainnet to Sonic bridge contract has approval to spend PERQ tokens
104
+ */
105
+ async checkMainnetToSonicBridgeApproval(amount) {
106
+ try {
107
+ if (!this.perqSdk.signer) {
108
+ throw new Error('No signer provided');
109
+ }
110
+ const bridgeAddress = this.perqSdk.bridgeMainnetPerqToSonicContract.getContractAddress();
111
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
112
+ const allowance = await this.perqSdk.perqTokenContract.getAllowance(bridgeAddress);
113
+ return allowance.gte(amountLD);
114
+ }
115
+ catch (error) {
116
+ if (error instanceof Error) {
117
+ throw new Error(`Failed to check Mainnet to Sonic bridge approval: ${error.message}`);
118
+ }
119
+ throw new Error('Failed to check Mainnet to Sonic bridge approval: Unknown error');
120
+ }
121
+ }
122
+ /**
123
+ * Approve the Mainnet to Sonic bridge contract to spend PERQ tokens
124
+ */
125
+ async approveMainnetToSonicBridge(amount) {
126
+ try {
127
+ const bridgeAddress = this.perqSdk.bridgeMainnetPerqToSonicContract.getContractAddress();
128
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
129
+ const tx = await this.perqSdk.perqTokenContract.approve(bridgeAddress, amountLD);
130
+ const txReceipt = await tx.wait();
131
+ return txReceipt.transactionHash;
132
+ }
133
+ catch (error) {
134
+ if (error instanceof Error) {
135
+ throw new Error(`Failed to approve Mainnet to Sonic bridge: ${error.message}`);
136
+ }
137
+ throw new Error('Failed to approve Mainnet to Sonic bridge: Unknown error');
138
+ }
139
+ }
140
+ /**
141
+ * Quote the fees for bridging PERQ from Mainnet to Sonic
142
+ */
143
+ async quoteMainnetToSonic(amount, recipientAddress, payInLzToken = false) {
144
+ try {
145
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
146
+ const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
147
+ const sendParam = {
148
+ dstEid: ENDPOINT_IDS.SONIC_MAINNET,
149
+ to: recipientBytes32,
150
+ amountLD,
151
+ minAmountLD: amountLD, // No slippage for now
152
+ extraOptions: '0x',
153
+ composeMsg: '0x',
154
+ oftCmd: '0x',
155
+ };
156
+ console.log('trying to quoteSend from mainnet to sonic with sendParam:', sendParam, ' and payInLzToken:', payInLzToken);
157
+ const fee = await this.perqSdk.bridgeMainnetPerqToSonicContract.quoteSend(sendParam, payInLzToken);
158
+ return {
159
+ nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
160
+ lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
161
+ };
162
+ }
163
+ catch (error) {
164
+ if (error instanceof Error) {
165
+ throw new Error(`Failed to quote Mainnet to Sonic bridge: ${error.message}`);
166
+ }
167
+ throw new Error('Failed to quote Mainnet to Sonic bridge: Unknown error');
168
+ }
169
+ }
170
+ /**
171
+ * Quote the fees for bridging PERQ from Sonic to Mainnet
172
+ */
173
+ async quoteSonicToMainnet(amount, recipientAddress, payInLzToken = false) {
174
+ try {
175
+ const amountLD = (0, utils_1.parseUnits)(amount, 18);
176
+ const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
177
+ const sendParam = {
178
+ dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
179
+ to: recipientBytes32,
180
+ amountLD,
181
+ minAmountLD: amountLD, // No slippage for now
182
+ extraOptions: '0x',
183
+ composeMsg: '0x',
184
+ oftCmd: '0x',
185
+ };
186
+ console.log('trying to quoteSend from sonic to mainnet with sendParam:', sendParam, ' and payInLzToken:', payInLzToken);
187
+ const fee = await this.perqSdk.bridgeSonicPerqToMainnetContract.quoteSend(sendParam, payInLzToken);
188
+ return {
189
+ nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
190
+ lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
191
+ };
192
+ }
193
+ catch (error) {
194
+ if (error instanceof Error) {
195
+ throw new Error(`Failed to quote Sonic to Mainnet bridge: ${error.message}`);
196
+ }
197
+ throw new Error('Failed to quote Sonic to Mainnet bridge: Unknown error');
198
+ }
199
+ }
200
+ }
201
+ exports.default = BridgePerqPackage;
@@ -1,5 +1,6 @@
1
1
  import PerqSdk from '../PerqSdk';
2
2
  import { DetailedProjectData, MyPerqData, ReducedProjectData, UserRewards, VaultData, VaultStats } from '../types';
3
+ import OverallStats from '../types/OverallStats';
3
4
  export default class PoolsPackage {
4
5
  private perqSdk;
5
6
  constructor(perqSdk: PerqSdk);
@@ -9,6 +10,10 @@ export default class PoolsPackage {
9
10
  getPoolDetails(vaultAddress: string, onChainProjectId: number): Promise<VaultData>;
10
11
  getAllProjects(): Promise<ReducedProjectData[]>;
11
12
  getProjectDetails(projectName: string): Promise<DetailedProjectData>;
13
+ getOverallStats(): Promise<OverallStats>;
14
+ /**
15
+ * @deprecated Use `getOverallStats()` instead.
16
+ */
12
17
  getPoolStats(): Promise<VaultStats>;
13
18
  getRewardsPerHour(vaultAddress: string): Promise<number>;
14
19
  getUserBoostedNfts(vaultAddress: string): Promise<string[]>;
@@ -32,6 +32,12 @@ class PoolsPackage {
32
32
  async getProjectDetails(projectName) {
33
33
  return this.perqSdk.perqApi.fetchProjetctDetails(projectName);
34
34
  }
35
+ async getOverallStats() {
36
+ return this.perqSdk.perqApi.fetchOverallStats();
37
+ }
38
+ /**
39
+ * @deprecated Use `getOverallStats()` instead.
40
+ */
35
41
  async getPoolStats() {
36
42
  return this.perqSdk.perqApi.fetchPoolStats();
37
43
  }
@@ -6,6 +6,8 @@ type MyPerqBalance = {
6
6
  earnedRewardsUsd: number;
7
7
  rewardsPerHour: number;
8
8
  rewardsPerHourUsd: number;
9
+ rewardsPerDay: number;
10
+ rewardsPerDayUsd: number;
9
11
  };
10
12
  type MyPerqData = VaultData & MyPerqBalance & {
11
13
  ethPrice: number;
@@ -0,0 +1,7 @@
1
+ type OverallStats = {
2
+ activeProjects: number;
3
+ totalTvl: number;
4
+ totalYieldUsd: number;
5
+ totalUsers: number;
6
+ };
7
+ export default OverallStats;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -9,6 +9,8 @@ type PerqConfig = {
9
9
  swapAndDepositContractAddress: string;
10
10
  ethereumSwapperAddress: string;
11
11
  smartVaultManagerContractAddress: string;
12
+ bridgeMainnetPerqToSonicAddress: string;
13
+ bridgeSonicPerqToMainnetAddress: string;
12
14
  };
13
15
  export default PerqConfig;
14
16
  export declare const PRODUCTION: PerqConfig;
@@ -12,6 +12,8 @@ exports.PRODUCTION = {
12
12
  swapAndDepositContractAddress: '0xd8534197bd587f8226d12e0c864ef2cae6f82f5c',
13
13
  ethereumSwapperAddress: '0x33e52c206d584550193e642c8982f2fff6339994',
14
14
  smartVaultManagerContractAddress: '0x23daf34e2b9af02a74dc19cb52af727b19403874',
15
+ bridgeMainnetPerqToSonicAddress: '0x26c352304909CC7e59EEeD39242Eb7AFbC706Ad3',
16
+ bridgeSonicPerqToMainnetAddress: '0x26c352304909CC7e59EEeD39242Eb7AFbC706Ad3',
15
17
  };
16
18
  exports.DEVELOPMENT = {
17
19
  route: 'https://dev.perq.finance',
@@ -22,4 +24,6 @@ exports.DEVELOPMENT = {
22
24
  swapAndDepositContractAddress: '0x5fb08e00de169f041711206a0995410884080177',
23
25
  ethereumSwapperAddress: '0xe411921ee9eedfefd7b9ae15bf232bd36949fcbbc',
24
26
  smartVaultManagerContractAddress: '0x2638d6c0b4ef6dee04050fa0b07ca62500435747',
27
+ bridgeMainnetPerqToSonicAddress: '0x26c352304909CC7e59EEeD39242Eb7AFbC706Ad3',
28
+ bridgeSonicPerqToMainnetAddress: '0x26c352304909CC7e59EEeD39242Eb7AFbC706Ad3',
25
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.4.26",
3
+ "version": "1.4.28-bridge-perq",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",