@dripfi/drip-sdk 1.4.34 → 1.4.35-beta

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.
Files changed (72) hide show
  1. package/dist/PerqApi.js +8 -11
  2. package/dist/PerqSdk.d.ts +4 -4
  3. package/dist/PerqSdk.js +66 -48
  4. package/dist/abi/index.js +17 -22
  5. package/dist/constants.js +2 -5
  6. package/dist/contracts/BaseContract.js +3 -6
  7. package/dist/contracts/BridgeMainnetPerqToSonicContract.js +5 -11
  8. package/dist/contracts/BridgeSonicPerqToMainnetContract.js +5 -11
  9. package/dist/contracts/ERC20TokenContract.js +4 -10
  10. package/dist/contracts/SlotBurnTokenContract.js +5 -11
  11. package/dist/contracts/index.js +9 -22
  12. package/dist/contracts/perq/PerqSwapAndRecyclerContract.js +7 -13
  13. package/dist/contracts/perq/PerqTokenContract.js +5 -11
  14. package/dist/contracts/perq/PerqTokenRecyclerContract.js +6 -12
  15. package/dist/contracts/perq/PerqVestingContract.js +5 -11
  16. package/dist/index.js +7 -28
  17. package/dist/subpackages/BridgePerqPackage.js +26 -29
  18. package/dist/subpackages/LitePackage.js +49 -41
  19. package/dist/subpackages/LoyaltyCardsPackage.js +16 -22
  20. package/dist/subpackages/PoolsPackage.js +1 -4
  21. package/dist/subpackages/RecyclerPackage.js +17 -23
  22. package/dist/subpackages/SignHandlerPackage.js +1 -4
  23. package/dist/subpackages/SiloPackage.js +3 -6
  24. package/dist/subpackages/SiloVaultOperations.js +4 -8
  25. package/dist/subpackages/TokenUtilsPackage.js +14 -20
  26. package/dist/subpackages/UserPackage.js +1 -4
  27. package/dist/subpackages/VaultHandlerPackage.js +5 -8
  28. package/dist/subpackages/VestingPackage.js +5 -8
  29. package/dist/subpackages/YelayVaultOperations.js +3 -7
  30. package/dist/types/Asset.js +1 -2
  31. package/dist/types/BeanEntry.js +1 -2
  32. package/dist/types/BeansBalance.js +1 -2
  33. package/dist/types/BridgePerq.js +1 -2
  34. package/dist/types/ChainId.js +6 -9
  35. package/dist/types/ClaimSpecialEditionLoyaltyCardPayload.js +1 -2
  36. package/dist/types/DeployedProject.js +1 -2
  37. package/dist/types/DeployedVault.js +1 -2
  38. package/dist/types/DepositToken.js +1 -2
  39. package/dist/types/DetailedProjectData.js +1 -2
  40. package/dist/types/DistributionToken.js +1 -2
  41. package/dist/types/ELoyaltyCardTier.js +1 -3
  42. package/dist/types/Earnings.js +1 -2
  43. package/dist/types/LinkWalletPayload.js +1 -2
  44. package/dist/types/LinkedPodWallets.js +1 -2
  45. package/dist/types/LoyaltyCard.js +1 -2
  46. package/dist/types/MigrationOption.js +1 -2
  47. package/dist/types/MyPerqData.js +1 -2
  48. package/dist/types/NFTBoost.js +1 -2
  49. package/dist/types/OverallStats.js +1 -2
  50. package/dist/types/PerqConfig.js +9 -12
  51. package/dist/types/PerqToBeansSwapInfo.js +1 -2
  52. package/dist/types/ProjectHistoricalTvl.js +1 -2
  53. package/dist/types/QLFastRedeem.js +1 -2
  54. package/dist/types/ReducedProjectData.js +1 -2
  55. package/dist/types/SdkType.js +1 -2
  56. package/dist/types/SignedPayload.js +1 -2
  57. package/dist/types/SlotMachineSpinCost.js +1 -2
  58. package/dist/types/SpecialEditionLoyaltyCard.js +1 -2
  59. package/dist/types/Strategy.js +1 -2
  60. package/dist/types/StretchGoal.js +1 -2
  61. package/dist/types/SwapInfo.js +1 -2
  62. package/dist/types/UpgradeLoyaltyCardPayload.js +1 -2
  63. package/dist/types/UserRewards.js +1 -2
  64. package/dist/types/VaultData.js +1 -2
  65. package/dist/types/VaultOperationParams.js +1 -2
  66. package/dist/types/VaultReward.js +1 -4
  67. package/dist/types/VaultStats.js +1 -2
  68. package/dist/types/VaultType.js +1 -4
  69. package/dist/types/VestingInfo.js +1 -2
  70. package/dist/types/YelayVersion.js +1 -2
  71. package/dist/types/index.js +2 -8
  72. package/package.json +7 -7
@@ -1,21 +1,19 @@
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
- const contracts_1 = require("../contracts");
1
+ import { ethers } from 'ethers';
2
+ import { formatUnits, parseUnits } from 'ethers/lib/utils';
3
+ import { BridgeMainnetPerqToSonicContract, BridgeSonicPerqToMainnetContract, PerqTokenContract } from '../contracts';
6
4
  // Chain IDs for LayerZero
7
5
  const ENDPOINT_IDS = {
8
6
  ETHEREUM_MAINNET: 30101,
9
7
  SONIC_MAINNET: 30332,
10
8
  };
11
- class BridgePerqPackage {
9
+ export default class BridgePerqPackage {
12
10
  perqSdk;
13
11
  bridgeMainnetPerqToSonicContract;
14
12
  bridgeSonicPerqToMainnetContract;
15
13
  constructor(perqSdk) {
16
14
  this.perqSdk = perqSdk;
17
- this.bridgeMainnetPerqToSonicContract = new contracts_1.BridgeMainnetPerqToSonicContract(perqSdk);
18
- this.bridgeSonicPerqToMainnetContract = new contracts_1.BridgeSonicPerqToMainnetContract(perqSdk);
15
+ this.bridgeMainnetPerqToSonicContract = new BridgeMainnetPerqToSonicContract(perqSdk);
16
+ this.bridgeSonicPerqToMainnetContract = new BridgeSonicPerqToMainnetContract(perqSdk);
19
17
  }
20
18
  /**
21
19
  * Bridge PERQ tokens from Mainnet to Sonic
@@ -32,8 +30,8 @@ class BridgePerqPackage {
32
30
  if (!hasApproval) {
33
31
  await this.approveMainnetToSonicBridge(amount);
34
32
  }
35
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
36
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
33
+ const amountLD = parseUnits(amount, 18);
34
+ const recipientBytes32 = ethers.utils.hexZeroPad(recipientAddress, 32);
37
35
  const sendParam = {
38
36
  dstEid: ENDPOINT_IDS.SONIC_MAINNET,
39
37
  to: recipientBytes32,
@@ -46,8 +44,8 @@ class BridgePerqPackage {
46
44
  // Get fee quote first
47
45
  const feeQuote = await this.quoteMainnetToSonic(amount, recipientAddress, false);
48
46
  const fee = {
49
- nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
50
- lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
47
+ nativeFee: parseUnits(feeQuote.nativeFee, 18),
48
+ lzTokenFee: parseUnits(feeQuote.lzTokenFee, 18),
51
49
  };
52
50
  // Send the transaction
53
51
  const tx = await this.bridgeMainnetPerqToSonicContract.send(sendParam, fee, recipientAddress, {
@@ -73,8 +71,8 @@ class BridgePerqPackage {
73
71
  }
74
72
  // Get signer address for bridged tokens
75
73
  const recipientAddress = await this.perqSdk.signer.getAddress();
76
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
77
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
74
+ const amountLD = parseUnits(amount, 18);
75
+ const recipientBytes32 = ethers.utils.hexZeroPad(recipientAddress, 32);
78
76
  const sendParam = {
79
77
  dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
80
78
  to: recipientBytes32,
@@ -87,8 +85,8 @@ class BridgePerqPackage {
87
85
  // Get fee quote first
88
86
  const feeQuote = await this.quoteSonicToMainnet(amount, recipientAddress, false);
89
87
  const fee = {
90
- nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
91
- lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
88
+ nativeFee: parseUnits(feeQuote.nativeFee, 18),
89
+ lzTokenFee: parseUnits(feeQuote.lzTokenFee, 18),
92
90
  };
93
91
  const tx = await this.bridgeSonicPerqToMainnetContract.send(sendParam, fee, recipientAddress, {
94
92
  value: fee.nativeFee,
@@ -111,9 +109,9 @@ class BridgePerqPackage {
111
109
  if (!this.perqSdk.signer) {
112
110
  throw new Error('No signer provided');
113
111
  }
114
- const perqTokenContract = new contracts_1.PerqTokenContract(this.perqSdk.perqConfig.perqTokenAddress, this.perqSdk.signer);
112
+ const perqTokenContract = new PerqTokenContract(this.perqSdk.perqConfig.perqTokenAddress, this.perqSdk.signer);
115
113
  const bridgeAddress = this.bridgeMainnetPerqToSonicContract.getContractAddress();
116
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
114
+ const amountLD = parseUnits(amount, 18);
117
115
  const allowance = await perqTokenContract.getAllowance(bridgeAddress);
118
116
  return allowance.gte(amountLD);
119
117
  }
@@ -130,8 +128,8 @@ class BridgePerqPackage {
130
128
  async approveMainnetToSonicBridge(amount) {
131
129
  try {
132
130
  const bridgeAddress = this.bridgeMainnetPerqToSonicContract.getContractAddress();
133
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
134
- const perqTokenContract = new contracts_1.PerqTokenContract(this.perqSdk.perqConfig.perqTokenAddress, this.perqSdk.signer);
131
+ const amountLD = parseUnits(amount, 18);
132
+ const perqTokenContract = new PerqTokenContract(this.perqSdk.perqConfig.perqTokenAddress, this.perqSdk.signer);
135
133
  const tx = await perqTokenContract.approve(bridgeAddress, amountLD);
136
134
  const txReceipt = await tx.wait();
137
135
  return txReceipt.transactionHash;
@@ -148,8 +146,8 @@ class BridgePerqPackage {
148
146
  */
149
147
  async quoteMainnetToSonic(amount, recipientAddress, payInLzToken = false) {
150
148
  try {
151
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
152
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
149
+ const amountLD = parseUnits(amount, 18);
150
+ const recipientBytes32 = ethers.utils.hexZeroPad(recipientAddress, 32);
153
151
  const sendParam = {
154
152
  dstEid: ENDPOINT_IDS.SONIC_MAINNET,
155
153
  to: recipientBytes32,
@@ -161,8 +159,8 @@ class BridgePerqPackage {
161
159
  };
162
160
  const fee = await this.bridgeMainnetPerqToSonicContract.quoteSend(sendParam, payInLzToken);
163
161
  return {
164
- nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
165
- lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
162
+ nativeFee: formatUnits(fee.nativeFee, 18),
163
+ lzTokenFee: formatUnits(fee.lzTokenFee, 18),
166
164
  };
167
165
  }
168
166
  catch (error) {
@@ -177,8 +175,8 @@ class BridgePerqPackage {
177
175
  */
178
176
  async quoteSonicToMainnet(amount, recipientAddress, payInLzToken = false) {
179
177
  try {
180
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
181
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
178
+ const amountLD = parseUnits(amount, 18);
179
+ const recipientBytes32 = ethers.utils.hexZeroPad(recipientAddress, 32);
182
180
  const sendParam = {
183
181
  dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
184
182
  to: recipientBytes32,
@@ -190,8 +188,8 @@ class BridgePerqPackage {
190
188
  };
191
189
  const fee = await this.bridgeSonicPerqToMainnetContract.quoteSend(sendParam, payInLzToken);
192
190
  return {
193
- nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
194
- lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
191
+ nativeFee: formatUnits(fee.nativeFee, 18),
192
+ lzTokenFee: formatUnits(fee.lzTokenFee, 18),
195
193
  };
196
194
  }
197
195
  catch (error) {
@@ -202,4 +200,3 @@ class BridgePerqPackage {
202
200
  }
203
201
  }
204
202
  }
205
- exports.default = BridgePerqPackage;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const ethers_1 = require("ethers");
7
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
1
+ import { ethers } from 'ethers';
2
+ import ERC20TokenContract from '../contracts/ERC20TokenContract';
3
+ // import { SwapArgsStruct } from '@yelay-lite/sdk/build/smartContract/VaultWrapper';
8
4
  const WETH_DECIMAL_PRECISION = 18;
9
- class LitePackage {
5
+ export default class LitePackage {
10
6
  perqSdk;
11
7
  constructor(perqSdk) {
12
8
  this.perqSdk = perqSdk;
@@ -23,63 +19,76 @@ class LitePackage {
23
19
  throw Error('No signer provided');
24
20
  }
25
21
  this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
26
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
22
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
27
23
  const decimals = await tokenContract.getPrecission();
28
- const parsedAmountToDeposit = ethers_1.ethers.utils.parseUnits(amount, decimals);
29
- const res = await this.perqSdk.yelayLiteSdk.vaults.deposit(vaultAddress, onChainProjectId, BigInt(parsedAmountToDeposit.toString()));
30
- return res.hash;
24
+ const parsedAmountToDeposit = ethers.utils.parseUnits(amount, decimals);
25
+ const res = await this.perqSdk.yelayLiteSdk.actions.deposit(vaultAddress, onChainProjectId, BigInt(parsedAmountToDeposit.toString()));
26
+ return res;
31
27
  }
32
28
  async getSwapAndDepositAllowance(tokenAddress) {
33
- const res = await this.perqSdk.yelayLiteSdk.vaults.vaultWrapperAllowance(tokenAddress);
29
+ const res = await this.perqSdk.yelayLiteSdk.portfolio.getTokenAllowance(tokenAddress);
34
30
  return res.toString();
35
31
  }
36
32
  async approveSwapAndDeposit(tokenAddress, amount) {
37
33
  if (!this.perqSdk.signer) {
38
34
  throw Error('No signer provided');
39
35
  }
40
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
36
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
41
37
  const decimals = await tokenContract.getPrecission();
42
- const parsedAmountToApprove = ethers_1.ethers.utils.parseUnits(amount, decimals);
43
- const res = await this.perqSdk.yelayLiteSdk.vaults.approveVaultWrapper(tokenAddress, parsedAmountToApprove.toBigInt());
44
- return res.hash;
38
+ const parsedAmountToApprove = ethers.utils.parseUnits(amount, decimals);
39
+ const res = await this.perqSdk.yelayLiteSdk.actions.approveToken(tokenAddress, parsedAmountToApprove.toBigInt());
40
+ return res;
45
41
  }
46
42
  async swapAndDeposit(fromTokenAddress, toTokenAddress, amount, vaultAddress, onChainProjectId) {
47
43
  if (!this.perqSdk.signer) {
48
44
  throw Error('No signer provided');
49
45
  }
50
46
  this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
51
- const tokenContract = new ERC20TokenContract_1.default(fromTokenAddress, this.perqSdk.signer);
52
- const decimals = await tokenContract.getPrecission();
53
- const parsedAmountToSwapAndDeposit = ethers_1.ethers.utils.parseUnits(amount, decimals);
54
- const chainId = await this.perqSdk.signer.getChainId();
55
- const swapInfo = await this.perqSdk.perqApi.getSwapInfo(fromTokenAddress, toTokenAddress, parsedAmountToSwapAndDeposit, this.perqSdk.yelayLiteSdk.swapperAddress, chainId);
56
- const swapArgsStruct = {
57
- tokenIn: swapInfo[0].token,
58
- swapTarget: swapInfo[0].swapTarget,
59
- swapCallData: swapInfo[0].swapCallData,
60
- };
61
- const res = await this.perqSdk.yelayLiteSdk.vaults.swapAndDeposit(vaultAddress.toLowerCase(), onChainProjectId, parsedAmountToSwapAndDeposit.toBigInt(), swapArgsStruct);
62
- return res.hash;
47
+ throw Error('Swap and deposit is not supported until the kyc at 1inch is completed');
48
+ //TODO: After we complete the kyc process at 1inch, we can use the following code to swap and deposit
49
+ // const tokenContract = new ERC20TokenContract(fromTokenAddress, this.perqSdk.signer);
50
+ // const decimals = await tokenContract.getPrecission();
51
+ // const parsedAmountToSwapAndDeposit = ethers.utils.parseUnits(amount, decimals);
52
+ // const chainId = await this.perqSdk.signer.getChainId();
53
+ // const swapInfo = await this.perqSdk.perqApi.getSwapInfo(
54
+ // fromTokenAddress,
55
+ // toTokenAddress,
56
+ // parsedAmountToSwapAndDeposit,
57
+ // this.perqSdk.yelayLiteSdk!.swapperAddress,
58
+ // chainId,
59
+ // );
60
+ // const swapArgsStruct: SwapArgsStruct = {
61
+ // tokenIn: swapInfo[0].token,
62
+ // swapTarget: swapInfo[0].swapTarget,
63
+ // swapCallData: swapInfo[0].swapCallData,
64
+ // };
65
+ // const res = await this.perqSdk.yelayLiteSdk!.actions.swapAndDeposit(
66
+ // vaultAddress.toLowerCase(),
67
+ // onChainProjectId,
68
+ // parsedAmountToSwapAndDeposit.toBigInt(),
69
+ // swapArgsStruct,
70
+ // );
71
+ // return res;
63
72
  }
64
73
  async withdraw(tokenAddress, vaultAddress, onChainProjectId, amount) {
65
74
  if (!this.perqSdk.signer) {
66
75
  throw Error('No signer provided');
67
76
  }
68
77
  this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
69
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
78
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
70
79
  const decimals = await tokenContract.getPrecission();
71
- const parsedAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amount, decimals);
72
- const res = await this.perqSdk.yelayLiteSdk.vaults.redeem(vaultAddress, onChainProjectId, BigInt(parsedAmountToWithdraw.toString()));
73
- return res.hash;
80
+ const parsedAmountToWithdraw = ethers.utils.parseUnits(amount, decimals);
81
+ const res = await this.perqSdk.yelayLiteSdk.actions.redeem(vaultAddress, onChainProjectId, BigInt(parsedAmountToWithdraw.toString()));
82
+ return res;
74
83
  }
75
84
  async wrapAndDepositEth(vaultAddress, onChainProjectId, amount) {
76
85
  if (!this.perqSdk.signer) {
77
86
  throw Error('No signer provided');
78
87
  }
79
88
  this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
80
- const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, WETH_DECIMAL_PRECISION);
81
- const res = await this.perqSdk.yelayLiteSdk.vaults.depositEth(vaultAddress, onChainProjectId, BigInt(parsedAmount.toString()));
82
- return res.hash;
89
+ const parsedAmount = ethers.utils.parseUnits(amount, WETH_DECIMAL_PRECISION);
90
+ const res = await this.perqSdk.yelayLiteSdk.actions.depositEth(vaultAddress, onChainProjectId, BigInt(parsedAmount.toString()));
91
+ return res;
83
92
  }
84
93
  async getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chainId) {
85
94
  return this.perqSdk.perqApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chainId.toString());
@@ -92,15 +101,14 @@ class LitePackage {
92
101
  throw Error('No signer provided');
93
102
  }
94
103
  this.validateChain(this.perqSdk.signer, vaultAddress, fromProjectId);
95
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
104
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
96
105
  const decimals = await tokenContract.getPrecission();
97
- const parsedAmountToDeposit = ethers_1.ethers.utils.parseUnits(amount, decimals);
98
- const res = await this.perqSdk.yelayLiteSdk.vaults.migrate(vaultAddress, fromProjectId, toProjectId, BigInt(parsedAmountToDeposit.toString()));
99
- return res.hash;
106
+ const parsedAmountToDeposit = ethers.utils.parseUnits(amount, decimals);
107
+ const res = await this.perqSdk.yelayLiteSdk.actions.migrate(vaultAddress, fromProjectId, toProjectId, BigInt(parsedAmountToDeposit.toString()));
108
+ return res;
100
109
  }
101
110
  async getHistoricalTvl(projectName) {
102
111
  const res = await this.perqSdk.perqApi.fetchHistoricalTvl(projectName);
103
112
  return res;
104
113
  }
105
114
  }
106
- exports.default = LitePackage;
@@ -1,13 +1,8 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const types_1 = require("../types");
7
- const ethers_1 = require("ethers");
8
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
9
- const constants_1 = require("../constants");
10
- class LoyaltyPackage {
1
+ import { ELoyaltyCardTier, } from '../types';
2
+ import { ethers } from 'ethers';
3
+ import ERC20TokenContract from '../contracts/ERC20TokenContract';
4
+ import { SONIC_PERQ_TOKEN_ADDRESS, SONIC_WS_TOKEN_ADDRESS } from '../constants';
5
+ export default class LoyaltyPackage {
11
6
  perqSdk;
12
7
  constructor(perqSdk) {
13
8
  this.perqSdk = perqSdk;
@@ -59,28 +54,28 @@ class LoyaltyPackage {
59
54
  if (!this.perqSdk.signer) {
60
55
  throw Error('No signer provided');
61
56
  }
62
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
57
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
63
58
  const decimals = await tokenContract.getPrecission();
64
- const parsedAmountToApprove = ethers_1.ethers.utils.parseUnits(amount, decimals);
59
+ const parsedAmountToApprove = ethers.utils.parseUnits(amount, decimals);
65
60
  const slotBurnTokenContractAddress = this.perqSdk.slotBurnTokenContract.getContractAddress();
66
61
  return await tokenContract.approveToken(slotBurnTokenContractAddress, parsedAmountToApprove.toBigInt());
67
62
  }
68
63
  async runSlotSpin(isDepositNative, tokenAddress) {
69
64
  const signerAddress = await this.perqSdk.signer.getAddress();
70
65
  const nextLoyaltyCard = await this.perqSdk.perqApi.fetchNextLoyaltyCard(signerAddress);
71
- const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === types_1.ELoyaltyCardTier.White;
66
+ const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === ELoyaltyCardTier.White;
72
67
  const sonicPrice = await this.perqSdk.perqApi.fetchTokenPrice('ws');
73
68
  const perqPrice = await this.perqSdk.perqApi.fetchTokenPrice('perq');
74
69
  if (tokenAddress !== undefined &&
75
- tokenAddress.toLowerCase() !== constants_1.SONIC_PERQ_TOKEN_ADDRESS &&
76
- tokenAddress.toLowerCase() !== constants_1.SONIC_WS_TOKEN_ADDRESS) {
70
+ tokenAddress.toLowerCase() !== SONIC_PERQ_TOKEN_ADDRESS &&
71
+ tokenAddress.toLowerCase() !== SONIC_WS_TOKEN_ADDRESS) {
77
72
  throw Error(`Slot machine does not support deposits from token ${tokenAddress}`);
78
73
  }
79
- const tokenPrice = tokenAddress === undefined ? sonicPrice : tokenAddress === constants_1.SONIC_PERQ_TOKEN_ADDRESS ? perqPrice : sonicPrice;
74
+ const tokenPrice = tokenAddress === undefined ? sonicPrice : tokenAddress === SONIC_PERQ_TOKEN_ADDRESS ? perqPrice : sonicPrice;
80
75
  // hardcode to 0.1 for the first loyalty card
81
76
  const amountForSpin = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / tokenPrice;
82
77
  const loyaltyCardOwnedChancesToWin = nextLoyaltyCard.chanceToUpgrade;
83
- const formattedAmountForSpin = ethers_1.ethers.utils.parseUnits(amountForSpin.toString(), 18);
78
+ const formattedAmountForSpin = ethers.utils.parseUnits(amountForSpin.toString(), 18);
84
79
  const depositResult = isDepositNative
85
80
  ? await this.perqSdk.slotBurnTokenContract.depositNative(formattedAmountForSpin.toString())
86
81
  : await this.perqSdk.slotBurnTokenContract.deposit(tokenAddress, formattedAmountForSpin.toString());
@@ -97,7 +92,7 @@ class LoyaltyPackage {
97
92
  const nextLoyaltyCard = await this.perqSdk.perqApi.fetchNextLoyaltyCard(signerAddress);
98
93
  const sonicPrice = await this.perqSdk.perqApi.fetchTokenPrice('ws');
99
94
  const perqPrice = await this.perqSdk.perqApi.fetchTokenPrice('perq');
100
- const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === types_1.ELoyaltyCardTier.White;
95
+ const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === ELoyaltyCardTier.White;
101
96
  const sonicSpinCost = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / sonicPrice;
102
97
  const perqSpinCost = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / perqPrice;
103
98
  return {
@@ -108,11 +103,11 @@ class LoyaltyPackage {
108
103
  }
109
104
  seededRandom(input) {
110
105
  // Convert input string to bytes
111
- const inputBytes = ethers_1.ethers.utils.toUtf8Bytes(input);
106
+ const inputBytes = ethers.utils.toUtf8Bytes(input);
112
107
  // Hash using keccak256
113
- const hash = ethers_1.ethers.utils.keccak256(inputBytes);
108
+ const hash = ethers.utils.keccak256(inputBytes);
114
109
  // Convert to a Buffer from hex string (strip 0x)
115
- const hashBuffer = new Uint8Array(ethers_1.ethers.utils.arrayify(hash));
110
+ const hashBuffer = new Uint8Array(ethers.utils.arrayify(hash));
116
111
  const dataView = new DataView(hashBuffer.buffer);
117
112
  // Read first 8 bytes as BigUInt64
118
113
  const num = dataView.getBigUint64(0);
@@ -120,4 +115,3 @@ class LoyaltyPackage {
120
115
  return Number(num % BigInt(1e12)) / 1e12;
121
116
  }
122
117
  }
123
- exports.default = LoyaltyPackage;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class PoolsPackage {
1
+ export default class PoolsPackage {
4
2
  perqSdk;
5
3
  constructor(perqSdk) {
6
4
  this.perqSdk = perqSdk;
@@ -55,4 +53,3 @@ class PoolsPackage {
55
53
  return userRewards;
56
54
  }
57
55
  }
58
- exports.default = PoolsPackage;
@@ -1,11 +1,6 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const ethers_1 = require("ethers");
7
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
8
- class RecyclerPackage {
1
+ import { ethers } from 'ethers';
2
+ import ERC20TokenContract from '../contracts/ERC20TokenContract';
3
+ export default class RecyclerPackage {
9
4
  perqSdk;
10
5
  constructor(perqSdk) {
11
6
  this.perqSdk = perqSdk;
@@ -14,7 +9,7 @@ class RecyclerPackage {
14
9
  if (!this.perqSdk.signer) {
15
10
  throw Error('No signer provided');
16
11
  }
17
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
12
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
18
13
  const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqTokenRecyclerContract.getContractAddress());
19
14
  return allowance;
20
15
  }
@@ -22,26 +17,26 @@ class RecyclerPackage {
22
17
  if (!this.perqSdk.signer) {
23
18
  throw Error('No signer provided');
24
19
  }
25
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
20
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
26
21
  const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqSwapAndRecyclerContract.getContractAddress());
27
22
  return allowance;
28
23
  }
29
- async recycleTokens(tokenAddress = this.perqSdk.perqConfig.perqTokenAddress, amountToRecycle, beneficiary = ethers_1.ethers.constants.AddressZero, price, deadline, signature) {
30
- if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
24
+ async recycleTokens(tokenAddress = this.perqSdk.perqConfig.perqTokenAddress, amountToRecycle, beneficiary = ethers.constants.AddressZero, price, deadline, signature) {
25
+ if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers.constants.AddressZero) {
31
26
  throw Error('Recycler contract address not defined');
32
27
  }
33
28
  if (!this.perqSdk.signer) {
34
29
  throw Error('No signer provided');
35
30
  }
36
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
31
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
37
32
  const decimals = await tokenContract.getPrecission();
38
- const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amountToRecycle, decimals).toString();
33
+ const amountWithDecimals = ethers.utils.parseUnits(amountToRecycle, decimals).toString();
39
34
  const recycleTx = await this.perqSdk.perqTokenRecyclerContract.recycle(amountWithDecimals, beneficiary, price, deadline, signature);
40
35
  const receipt = await recycleTx.wait();
41
36
  return receipt.transactionHash;
42
37
  }
43
38
  async swapAndRecycleETH(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature) {
44
- if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
39
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers.constants.AddressZero) {
45
40
  throw Error('Recycler contract address not defined');
46
41
  }
47
42
  const swapAndRecycleTx = await this.perqSdk.perqSwapAndRecyclerContract.swapETHAndRecycle(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature);
@@ -49,7 +44,7 @@ class RecyclerPackage {
49
44
  return receipt.transactionHash;
50
45
  }
51
46
  async swapAndRecycleERC20(beneficiary, path, minAmountOutWithDecimals, amountInWithDecimals, price, deadline, signature) {
52
- if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
47
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers.constants.AddressZero) {
53
48
  throw Error('Recycler contract address not defined');
54
49
  }
55
50
  const swapAndRecycleTx = await this.perqSdk.perqSwapAndRecyclerContract.swapAndRecycle(beneficiary, path, amountInWithDecimals, minAmountOutWithDecimals, price, deadline, signature);
@@ -60,28 +55,27 @@ class RecyclerPackage {
60
55
  if (!this.perqSdk.signer) {
61
56
  throw Error('No signer provided');
62
57
  }
63
- if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
58
+ if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers.constants.AddressZero) {
64
59
  throw Error('Recycler contract address not defined');
65
60
  }
66
61
  if (!this.perqSdk.signer) {
67
62
  throw Error('No signer provided');
68
63
  }
69
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
64
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
70
65
  const decimals = await tokenContract.getPrecission();
71
- const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
66
+ const parsedAmount = ethers.utils.parseUnits(amount, decimals);
72
67
  return await tokenContract.approveToken(this.perqSdk.perqConfig.perqTokenRecyclerAddress, parsedAmount);
73
68
  }
74
69
  async approveTokenForSwapAndRecycler(tokenAddress, amount) {
75
70
  if (!this.perqSdk.signer) {
76
71
  throw Error('No signer provided');
77
72
  }
78
- if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
73
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers.constants.AddressZero) {
79
74
  throw Error('Recycler contract address not defined');
80
75
  }
81
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
76
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
82
77
  const decimals = await tokenContract.getPrecission();
83
- const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
78
+ const parsedAmount = ethers.utils.parseUnits(amount, decimals);
84
79
  return await tokenContract.approveToken(this.perqSdk.perqConfig.perqSwapAndRecyclerAddress, parsedAmount);
85
80
  }
86
81
  }
87
- exports.default = RecyclerPackage;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class SignHandlerPackage {
1
+ export default class SignHandlerPackage {
4
2
  perqSdk;
5
3
  constructor(perqSdk) {
6
4
  this.perqSdk = perqSdk;
@@ -30,4 +28,3 @@ class SignHandlerPackage {
30
28
  };
31
29
  }
32
30
  }
33
- exports.default = SignHandlerPackage;
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const silo_sdk_1 = require("@dripfi/silo-sdk");
4
- class SiloPackage {
1
+ import { SiloSdk } from '@dripfi/silo-sdk';
2
+ export default class SiloPackage {
5
3
  siloSdk;
6
4
  constructor(signer) {
7
- this.siloSdk = new silo_sdk_1.SiloSdk(signer);
5
+ this.siloSdk = new SiloSdk(signer);
8
6
  }
9
7
  async deposit(assetAmount, vaultAddress) {
10
8
  try {
@@ -109,4 +107,3 @@ class SiloPackage {
109
107
  }
110
108
  }
111
109
  }
112
- exports.default = SiloPackage;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SiloVaultOperations = void 0;
4
- const ethers_1 = require("ethers");
1
+ import { BigNumber } from 'ethers';
5
2
  /**
6
3
  * Silo SDK vault operations implementation
7
4
  */
8
- class SiloVaultOperations {
5
+ export class SiloVaultOperations {
9
6
  perqSdk;
10
7
  constructor(perqSdk) {
11
8
  this.perqSdk = perqSdk;
@@ -64,14 +61,14 @@ class SiloVaultOperations {
64
61
  * Handles Silo withdraw with automatic full/partial withdraw detection
65
62
  */
66
63
  async handleSiloWithdraw(tokenAddress, vaultAddress, amount) {
67
- let userBalance = ethers_1.BigNumber.from(0);
64
+ let userBalance = BigNumber.from(0);
68
65
  try {
69
66
  userBalance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
70
67
  }
71
68
  catch (error) {
72
69
  console.error('Error getting user balance for silo withdraw: ', error);
73
70
  }
74
- const withdrawAmount = ethers_1.BigNumber.from(amount);
71
+ const withdrawAmount = BigNumber.from(amount);
75
72
  try {
76
73
  if (withdrawAmount.gte(userBalance)) {
77
74
  return await this.handleSiloFullWithdraw(vaultAddress);
@@ -116,4 +113,3 @@ class SiloVaultOperations {
116
113
  throw new Error('Unable to extract transaction hash from response');
117
114
  }
118
115
  }
119
- exports.SiloVaultOperations = SiloVaultOperations;
@@ -1,12 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const ethers_1 = require("ethers");
7
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
8
- const WethTokenAbi_json_1 = __importDefault(require("../abi/WethTokenAbi.json"));
9
- class TokenUtilsPackage {
1
+ import { ethers } from 'ethers';
2
+ import ERC20TokenContract from '../contracts/ERC20TokenContract';
3
+ import wethTokenAbi from '../abi/WethTokenAbi.json';
4
+ export default class TokenUtilsPackage {
10
5
  perqSdk;
11
6
  constructor(perqSdk) {
12
7
  this.perqSdk = perqSdk;
@@ -21,9 +16,9 @@ class TokenUtilsPackage {
21
16
  if (!this.perqSdk.signer) {
22
17
  throw new Error('No signer provided');
23
18
  }
24
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
19
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
25
20
  const decimals = await tokenContract.getPrecission();
26
- return ethers_1.ethers.utils.parseUnits(amount, decimals);
21
+ return ethers.utils.parseUnits(amount, decimals);
27
22
  }
28
23
  /**
29
24
  * Helper method to format amount from token decimals to human-readable string
@@ -35,9 +30,9 @@ class TokenUtilsPackage {
35
30
  if (!this.perqSdk.signer) {
36
31
  throw new Error('No signer provided');
37
32
  }
38
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
33
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
39
34
  const decimals = await tokenContract.getPrecission();
40
- return ethers_1.ethers.utils.formatUnits(amount, decimals);
35
+ return ethers.utils.formatUnits(amount, decimals);
41
36
  }
42
37
  async getTokenPrice(tokenName) {
43
38
  return this.perqSdk.perqApi.fetchTokenPrice(tokenName);
@@ -46,7 +41,7 @@ class TokenUtilsPackage {
46
41
  if (!this.perqSdk.signer) {
47
42
  throw Error('No signer provided');
48
43
  }
49
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
44
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
50
45
  const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), spender);
51
46
  return allowance.toString();
52
47
  }
@@ -54,7 +49,7 @@ class TokenUtilsPackage {
54
49
  if (!this.perqSdk.signer) {
55
50
  throw Error('No signer provided');
56
51
  }
57
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
52
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
58
53
  const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
59
54
  return await tokenContract.approveToken(spenderAddress, parsedAmount.toString());
60
55
  }
@@ -62,7 +57,7 @@ class TokenUtilsPackage {
62
57
  if (!this.perqSdk.signer) {
63
58
  throw Error('No signer provided');
64
59
  }
65
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
60
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
66
61
  const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
67
62
  const txHash = await tokenContract.transfer(receiver, parsedAmount.toString());
68
63
  return txHash;
@@ -71,9 +66,9 @@ class TokenUtilsPackage {
71
66
  if (!this.perqSdk.signer) {
72
67
  throw Error('No signer provided');
73
68
  }
74
- const wethContract = new ethers_1.ethers.Contract(tokenAddress, WethTokenAbi_json_1.default, this.perqSdk.signer);
69
+ const wethContract = new ethers.Contract(tokenAddress, wethTokenAbi, this.perqSdk.signer);
75
70
  const decimals = await wethContract.decimals();
76
- const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amount, decimals);
71
+ const amountWithDecimals = ethers.utils.parseUnits(amount, decimals);
77
72
  const depositTx = await wethContract.deposit({ value: amountWithDecimals });
78
73
  const receipt = await depositTx.wait();
79
74
  return receipt.transactionHash;
@@ -82,7 +77,7 @@ class TokenUtilsPackage {
82
77
  if (!this.perqSdk.signer) {
83
78
  throw Error('No signer provided');
84
79
  }
85
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
80
+ const tokenContract = new ERC20TokenContract(tokenAddress, this.perqSdk.signer);
86
81
  const allowance = tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), spender);
87
82
  return allowance;
88
83
  }
@@ -90,4 +85,3 @@ class TokenUtilsPackage {
90
85
  return this.perqSdk.perqConfig.perqTokenAddress;
91
86
  }
92
87
  }
93
- exports.default = TokenUtilsPackage;