@dripfi/drip-sdk 1.4.34 → 1.4.35-beta.2

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 (150) hide show
  1. package/package.json +11 -12
  2. package/dist/PerqApi.d.ts +0 -49
  3. package/dist/PerqApi.js +0 -475
  4. package/dist/PerqSdk.d.ts +0 -40
  5. package/dist/PerqSdk.js +0 -75
  6. package/dist/abi/ERC20.json +0 -222
  7. package/dist/abi/SlotBurnTokenAbi.json +0 -130
  8. package/dist/abi/WethTokenAbi.json +0 -25
  9. package/dist/abi/index.d.ts +0 -411
  10. package/dist/abi/index.js +0 -23
  11. package/dist/abi/perq/BridgeMainnetPerqToSonicAbi.json +0 -598
  12. package/dist/abi/perq/BridgeSonicPerqToMainnetAbi.json +0 -733
  13. package/dist/abi/perq/PerqSwapAndRecyclerAbi.json +0 -95
  14. package/dist/abi/perq/PerqTokenAbi.json +0 -48
  15. package/dist/abi/perq/PerqVestingAbi.json +0 -126
  16. package/dist/abi/perq/TokenRecyclerAbi.json +0 -41
  17. package/dist/constants.d.ts +0 -2
  18. package/dist/constants.js +0 -5
  19. package/dist/contracts/BaseContract.d.ts +0 -7
  20. package/dist/contracts/BaseContract.js +0 -16
  21. package/dist/contracts/BridgeMainnetPerqToSonicContract.d.ts +0 -9
  22. package/dist/contracts/BridgeMainnetPerqToSonicContract.js +0 -48
  23. package/dist/contracts/BridgeSonicPerqToMainnetContract.d.ts +0 -9
  24. package/dist/contracts/BridgeSonicPerqToMainnetContract.js +0 -47
  25. package/dist/contracts/ERC20TokenContract.d.ts +0 -10
  26. package/dist/contracts/ERC20TokenContract.js +0 -34
  27. package/dist/contracts/SlotBurnTokenContract.d.ts +0 -8
  28. package/dist/contracts/SlotBurnTokenContract.js +0 -26
  29. package/dist/contracts/index.d.ts +0 -9
  30. package/dist/contracts/index.js +0 -22
  31. package/dist/contracts/perq/PerqSwapAndRecyclerContract.d.ts +0 -8
  32. package/dist/contracts/perq/PerqSwapAndRecyclerContract.js +0 -28
  33. package/dist/contracts/perq/PerqTokenContract.d.ts +0 -7
  34. package/dist/contracts/perq/PerqTokenContract.js +0 -26
  35. package/dist/contracts/perq/PerqTokenRecyclerContract.d.ts +0 -7
  36. package/dist/contracts/perq/PerqTokenRecyclerContract.js +0 -20
  37. package/dist/contracts/perq/PerqVestingContract.d.ts +0 -13
  38. package/dist/contracts/perq/PerqVestingContract.js +0 -56
  39. package/dist/index.d.ts +0 -5
  40. package/dist/index.js +0 -28
  41. package/dist/subpackages/BridgePerqPackage.d.ts +0 -36
  42. package/dist/subpackages/BridgePerqPackage.js +0 -205
  43. package/dist/subpackages/LitePackage.d.ts +0 -19
  44. package/dist/subpackages/LitePackage.js +0 -106
  45. package/dist/subpackages/LoyaltyCardsPackage.d.ts +0 -21
  46. package/dist/subpackages/LoyaltyCardsPackage.js +0 -123
  47. package/dist/subpackages/PoolsPackage.d.ts +0 -21
  48. package/dist/subpackages/PoolsPackage.js +0 -58
  49. package/dist/subpackages/RecyclerPackage.d.ts +0 -13
  50. package/dist/subpackages/RecyclerPackage.js +0 -87
  51. package/dist/subpackages/SignHandlerPackage.d.ts +0 -8
  52. package/dist/subpackages/SignHandlerPackage.js +0 -33
  53. package/dist/subpackages/SiloPackage.d.ts +0 -18
  54. package/dist/subpackages/SiloPackage.js +0 -112
  55. package/dist/subpackages/SiloVaultOperations.d.ts +0 -31
  56. package/dist/subpackages/SiloVaultOperations.js +0 -119
  57. package/dist/subpackages/TokenUtilsPackage.d.ts +0 -27
  58. package/dist/subpackages/TokenUtilsPackage.js +0 -93
  59. package/dist/subpackages/UserPackage.d.ts +0 -11
  60. package/dist/subpackages/UserPackage.js +0 -43
  61. package/dist/subpackages/VaultHandlerPackage.d.ts +0 -54
  62. package/dist/subpackages/VaultHandlerPackage.js +0 -107
  63. package/dist/subpackages/VestingPackage.d.ts +0 -14
  64. package/dist/subpackages/VestingPackage.js +0 -112
  65. package/dist/subpackages/YelayVaultOperations.d.ts +0 -13
  66. package/dist/subpackages/YelayVaultOperations.js +0 -107
  67. package/dist/types/Asset.d.ts +0 -5
  68. package/dist/types/Asset.js +0 -2
  69. package/dist/types/BeanEntry.d.ts +0 -12
  70. package/dist/types/BeanEntry.js +0 -2
  71. package/dist/types/BeansBalance.d.ts +0 -5
  72. package/dist/types/BeansBalance.js +0 -2
  73. package/dist/types/BridgePerq.d.ts +0 -14
  74. package/dist/types/BridgePerq.js +0 -2
  75. package/dist/types/ChainId.d.ts +0 -7
  76. package/dist/types/ChainId.js +0 -9
  77. package/dist/types/ClaimSpecialEditionLoyaltyCardPayload.d.ts +0 -4
  78. package/dist/types/ClaimSpecialEditionLoyaltyCardPayload.js +0 -2
  79. package/dist/types/DeployedProject.d.ts +0 -55
  80. package/dist/types/DeployedProject.js +0 -2
  81. package/dist/types/DeployedVault.d.ts +0 -14
  82. package/dist/types/DeployedVault.js +0 -2
  83. package/dist/types/DepositToken.d.ts +0 -8
  84. package/dist/types/DepositToken.js +0 -2
  85. package/dist/types/DetailedProjectData.d.ts +0 -34
  86. package/dist/types/DetailedProjectData.js +0 -2
  87. package/dist/types/DistributionToken.d.ts +0 -6
  88. package/dist/types/DistributionToken.js +0 -2
  89. package/dist/types/ELoyaltyCardTier.d.ts +0 -10
  90. package/dist/types/ELoyaltyCardTier.js +0 -13
  91. package/dist/types/Earnings.d.ts +0 -11
  92. package/dist/types/Earnings.js +0 -2
  93. package/dist/types/LinkWalletPayload.d.ts +0 -9
  94. package/dist/types/LinkWalletPayload.js +0 -2
  95. package/dist/types/LinkedPodWallets.d.ts +0 -6
  96. package/dist/types/LinkedPodWallets.js +0 -2
  97. package/dist/types/LoyaltyCard.d.ts +0 -11
  98. package/dist/types/LoyaltyCard.js +0 -2
  99. package/dist/types/MigrationOption.d.ts +0 -6
  100. package/dist/types/MigrationOption.js +0 -2
  101. package/dist/types/MyPerqData.d.ts +0 -19
  102. package/dist/types/MyPerqData.js +0 -2
  103. package/dist/types/NFTBoost.d.ts +0 -10
  104. package/dist/types/NFTBoost.js +0 -2
  105. package/dist/types/OverallStats.d.ts +0 -7
  106. package/dist/types/OverallStats.js +0 -2
  107. package/dist/types/PerqConfig.d.ts +0 -18
  108. package/dist/types/PerqConfig.js +0 -37
  109. package/dist/types/PerqToBeansSwapInfo.d.ts +0 -8
  110. package/dist/types/PerqToBeansSwapInfo.js +0 -2
  111. package/dist/types/ProjectHistoricalTvl.d.ts +0 -4
  112. package/dist/types/ProjectHistoricalTvl.js +0 -2
  113. package/dist/types/QLFastRedeem.d.ts +0 -16
  114. package/dist/types/QLFastRedeem.js +0 -2
  115. package/dist/types/ReducedProjectData.d.ts +0 -21
  116. package/dist/types/ReducedProjectData.js +0 -2
  117. package/dist/types/SdkType.d.ts +0 -2
  118. package/dist/types/SdkType.js +0 -2
  119. package/dist/types/SignedPayload.d.ts +0 -12
  120. package/dist/types/SignedPayload.js +0 -2
  121. package/dist/types/SlotMachineSpinCost.d.ts +0 -7
  122. package/dist/types/SlotMachineSpinCost.js +0 -2
  123. package/dist/types/SpecialEditionLoyaltyCard.d.ts +0 -9
  124. package/dist/types/SpecialEditionLoyaltyCard.js +0 -2
  125. package/dist/types/Strategy.d.ts +0 -9
  126. package/dist/types/Strategy.js +0 -2
  127. package/dist/types/StretchGoal.d.ts +0 -5
  128. package/dist/types/StretchGoal.js +0 -2
  129. package/dist/types/SwapInfo.d.ts +0 -6
  130. package/dist/types/SwapInfo.js +0 -2
  131. package/dist/types/UpgradeLoyaltyCardPayload.d.ts +0 -4
  132. package/dist/types/UpgradeLoyaltyCardPayload.js +0 -2
  133. package/dist/types/UserRewards.d.ts +0 -6
  134. package/dist/types/UserRewards.js +0 -2
  135. package/dist/types/VaultData.d.ts +0 -32
  136. package/dist/types/VaultData.js +0 -2
  137. package/dist/types/VaultOperationParams.d.ts +0 -12
  138. package/dist/types/VaultOperationParams.js +0 -2
  139. package/dist/types/VaultReward.d.ts +0 -16
  140. package/dist/types/VaultReward.js +0 -4
  141. package/dist/types/VaultStats.d.ts +0 -6
  142. package/dist/types/VaultStats.js +0 -2
  143. package/dist/types/VaultType.d.ts +0 -3
  144. package/dist/types/VaultType.js +0 -4
  145. package/dist/types/VestingInfo.d.ts +0 -8
  146. package/dist/types/VestingInfo.js +0 -2
  147. package/dist/types/YelayVersion.d.ts +0 -2
  148. package/dist/types/YelayVersion.js +0 -2
  149. package/dist/types/index.d.ts +0 -34
  150. package/dist/types/index.js +0 -8
@@ -1,7 +0,0 @@
1
- import { ContractTransaction } from 'ethers';
2
- import BaseContract from '../BaseContract';
3
- import PerqSdk from '../../PerqSdk';
4
- export default class PerqTokenRecyclerContract extends BaseContract {
5
- constructor(perqSdk: PerqSdk);
6
- recycle(amountToRecycle: string, beneficiary: string | undefined, price: string, deadline: string, signature: string): Promise<ContractTransaction>;
7
- }
@@ -1,20 +0,0 @@
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 TokenRecyclerAbi_json_1 = __importDefault(require("../../abi/perq/TokenRecyclerAbi.json"));
8
- const BaseContract_1 = __importDefault(require("../BaseContract"));
9
- class PerqTokenRecyclerContract extends BaseContract_1.default {
10
- constructor(perqSdk) {
11
- super(perqSdk.perqConfig.perqTokenRecyclerAddress, new ethers_1.ethers.utils.Interface(TokenRecyclerAbi_json_1.default), perqSdk.signer);
12
- }
13
- async recycle(amountToRecycle, beneficiary = ethers_1.ethers.constants.AddressZero, price, deadline, signature) {
14
- if (!this.contract.signer) {
15
- throw Error('No signer provided');
16
- }
17
- return await this.contract.recycle(amountToRecycle, beneficiary, price, deadline, signature);
18
- }
19
- }
20
- exports.default = PerqTokenRecyclerContract;
@@ -1,13 +0,0 @@
1
- import { BigNumber, ContractTransaction } from 'ethers';
2
- import BaseContract from '../BaseContract';
3
- import PerqSdk from '../../PerqSdk';
4
- export default class PerqVestingContract extends BaseContract {
5
- constructor(perqSdk: PerqSdk);
6
- start(): Promise<BigNumber>;
7
- end(): Promise<BigNumber>;
8
- vested(beneficiary: string): Promise<BigNumber>;
9
- releasable(beneficiary: string): Promise<BigNumber>;
10
- releasableTotal(beneficiary: string): Promise<BigNumber>;
11
- claim(amount: string): Promise<ContractTransaction>;
12
- burn(amount: string, price: string, deadline: string, signature: string): Promise<ContractTransaction>;
13
- }
@@ -1,56 +0,0 @@
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 PerqVestingAbi_json_1 = __importDefault(require("../../abi/perq/PerqVestingAbi.json"));
8
- const BaseContract_1 = __importDefault(require("../BaseContract"));
9
- class PerqVestingContract extends BaseContract_1.default {
10
- constructor(perqSdk) {
11
- super(perqSdk.perqConfig.perqVestingAddress, new ethers_1.ethers.utils.Interface(PerqVestingAbi_json_1.default), perqSdk.signer);
12
- }
13
- async start() {
14
- if (!this.contract.signer) {
15
- throw Error('No signer provided');
16
- }
17
- return await this.contract.start();
18
- }
19
- async end() {
20
- if (!this.contract.signer) {
21
- throw Error('No signer provided');
22
- }
23
- return await this.contract.end();
24
- }
25
- async vested(beneficiary) {
26
- if (!this.contract.signer) {
27
- throw Error('No signer provided');
28
- }
29
- return await this.contract.vested(beneficiary);
30
- }
31
- async releasable(beneficiary) {
32
- if (!this.contract.signer) {
33
- throw Error('No signer provided');
34
- }
35
- return await this.contract.releasable(beneficiary);
36
- }
37
- async releasableTotal(beneficiary) {
38
- if (!this.contract.signer) {
39
- throw Error('No signer provided');
40
- }
41
- return await this.contract.releasableTotal(beneficiary);
42
- }
43
- async claim(amount) {
44
- if (!this.contract.signer) {
45
- throw Error('No signer provided');
46
- }
47
- return await this.contract.claim(amount);
48
- }
49
- async burn(amount, price, deadline, signature) {
50
- if (!this.contract.signer) {
51
- throw Error('No signer provided');
52
- }
53
- return await this.contract.burn(amount, price, deadline, signature);
54
- }
55
- }
56
- exports.default = PerqVestingContract;
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import PerqSdk from './PerqSdk';
2
- import abi from './abi';
3
- import { DEVELOPMENT, PRODUCTION } from './types/PerqConfig';
4
- export * from './types';
5
- export { PerqSdk, DEVELOPMENT, PRODUCTION, abi, };
package/dist/index.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.abi = exports.PRODUCTION = exports.DEVELOPMENT = exports.PerqSdk = void 0;
21
- const PerqSdk_1 = __importDefault(require("./PerqSdk"));
22
- exports.PerqSdk = PerqSdk_1.default;
23
- const abi_1 = __importDefault(require("./abi"));
24
- exports.abi = abi_1.default;
25
- const PerqConfig_1 = require("./types/PerqConfig");
26
- Object.defineProperty(exports, "DEVELOPMENT", { enumerable: true, get: function () { return PerqConfig_1.DEVELOPMENT; } });
27
- Object.defineProperty(exports, "PRODUCTION", { enumerable: true, get: function () { return PerqConfig_1.PRODUCTION; } });
28
- __exportStar(require("./types"), exports);
@@ -1,36 +0,0 @@
1
- import PerqSdk from '../PerqSdk';
2
- import { BridgeMainnetPerqToSonicContract, BridgeSonicPerqToMainnetContract } from '../contracts';
3
- export interface BridgeQuote {
4
- nativeFee: string;
5
- lzTokenFee: string;
6
- }
7
- export default class BridgePerqPackage {
8
- perqSdk: PerqSdk;
9
- bridgeMainnetPerqToSonicContract: BridgeMainnetPerqToSonicContract;
10
- bridgeSonicPerqToMainnetContract: BridgeSonicPerqToMainnetContract;
11
- constructor(perqSdk: PerqSdk);
12
- /**
13
- * Bridge PERQ tokens from Mainnet to Sonic
14
- */
15
- bridgeMainnetToSonic(amount: string): Promise<string>;
16
- /**
17
- * Bridge PERQ tokens from Sonic to Mainnet
18
- */
19
- bridgeSonicToMainnet(amount: string): Promise<string>;
20
- /**
21
- * Check if the Mainnet to Sonic bridge contract has approval to spend PERQ tokens
22
- */
23
- checkMainnetToSonicBridgeApproval(amount: string): Promise<boolean>;
24
- /**
25
- * Approve the Mainnet to Sonic bridge contract to spend PERQ tokens
26
- */
27
- approveMainnetToSonicBridge(amount: string): Promise<string>;
28
- /**
29
- * Quote the fees for bridging PERQ from Mainnet to Sonic
30
- */
31
- private quoteMainnetToSonic;
32
- /**
33
- * Quote the fees for bridging PERQ from Sonic to Mainnet
34
- */
35
- private quoteSonicToMainnet;
36
- }
@@ -1,205 +0,0 @@
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");
6
- // Chain IDs for LayerZero
7
- const ENDPOINT_IDS = {
8
- ETHEREUM_MAINNET: 30101,
9
- SONIC_MAINNET: 30332,
10
- };
11
- class BridgePerqPackage {
12
- perqSdk;
13
- bridgeMainnetPerqToSonicContract;
14
- bridgeSonicPerqToMainnetContract;
15
- constructor(perqSdk) {
16
- this.perqSdk = perqSdk;
17
- this.bridgeMainnetPerqToSonicContract = new contracts_1.BridgeMainnetPerqToSonicContract(perqSdk);
18
- this.bridgeSonicPerqToMainnetContract = new contracts_1.BridgeSonicPerqToMainnetContract(perqSdk);
19
- }
20
- /**
21
- * Bridge PERQ tokens from Mainnet to Sonic
22
- */
23
- async bridgeMainnetToSonic(amount) {
24
- try {
25
- if (!this.perqSdk.signer) {
26
- throw new Error('No signer provided');
27
- }
28
- // Get signer address for bridged tokens
29
- const recipientAddress = await this.perqSdk.signer.getAddress();
30
- // Check and handle approval first
31
- const hasApproval = await this.checkMainnetToSonicBridgeApproval(amount);
32
- if (!hasApproval) {
33
- await this.approveMainnetToSonicBridge(amount);
34
- }
35
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
36
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
37
- const sendParam = {
38
- dstEid: ENDPOINT_IDS.SONIC_MAINNET,
39
- to: recipientBytes32,
40
- amountLD,
41
- minAmountLD: amountLD, // No slippage for now
42
- extraOptions: '0x',
43
- composeMsg: '0x',
44
- oftCmd: '0x',
45
- };
46
- // Get fee quote first
47
- const feeQuote = await this.quoteMainnetToSonic(amount, recipientAddress, false);
48
- const fee = {
49
- nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
50
- lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
51
- };
52
- // Send the transaction
53
- const tx = await this.bridgeMainnetPerqToSonicContract.send(sendParam, fee, recipientAddress, {
54
- value: fee.nativeFee,
55
- });
56
- const txReceipt = await tx.wait();
57
- return txReceipt.transactionHash;
58
- }
59
- catch (error) {
60
- if (error instanceof Error) {
61
- throw new Error(`Failed to bridge Mainnet to Sonic: ${error.message}`);
62
- }
63
- throw new Error('Failed to bridge Mainnet to Sonic: Unknown error');
64
- }
65
- }
66
- /**
67
- * Bridge PERQ tokens from Sonic to Mainnet
68
- */
69
- async bridgeSonicToMainnet(amount) {
70
- try {
71
- if (!this.perqSdk.signer) {
72
- throw new Error('No signer provided');
73
- }
74
- // Get signer address for bridged tokens
75
- 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);
78
- const sendParam = {
79
- dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
80
- to: recipientBytes32,
81
- amountLD,
82
- minAmountLD: amountLD, // No slippage for now
83
- extraOptions: '0x',
84
- composeMsg: '0x',
85
- oftCmd: '0x',
86
- };
87
- // Get fee quote first
88
- const feeQuote = await this.quoteSonicToMainnet(amount, recipientAddress, false);
89
- const fee = {
90
- nativeFee: (0, utils_1.parseUnits)(feeQuote.nativeFee, 18),
91
- lzTokenFee: (0, utils_1.parseUnits)(feeQuote.lzTokenFee, 18),
92
- };
93
- const tx = await this.bridgeSonicPerqToMainnetContract.send(sendParam, fee, recipientAddress, {
94
- value: fee.nativeFee,
95
- });
96
- const txReceipt = await tx.wait();
97
- return txReceipt.transactionHash;
98
- }
99
- catch (error) {
100
- if (error instanceof Error) {
101
- throw new Error(`Failed to bridge Sonic to Mainnet: ${error.message}`);
102
- }
103
- throw new Error('Failed to bridge Sonic to Mainnet: Unknown error');
104
- }
105
- }
106
- /**
107
- * Check if the Mainnet to Sonic bridge contract has approval to spend PERQ tokens
108
- */
109
- async checkMainnetToSonicBridgeApproval(amount) {
110
- try {
111
- if (!this.perqSdk.signer) {
112
- throw new Error('No signer provided');
113
- }
114
- const perqTokenContract = new contracts_1.PerqTokenContract(this.perqSdk.perqConfig.perqTokenAddress, this.perqSdk.signer);
115
- const bridgeAddress = this.bridgeMainnetPerqToSonicContract.getContractAddress();
116
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
117
- const allowance = await perqTokenContract.getAllowance(bridgeAddress);
118
- return allowance.gte(amountLD);
119
- }
120
- catch (error) {
121
- if (error instanceof Error) {
122
- throw new Error(`Failed to check Mainnet to Sonic bridge approval: ${error.message}`);
123
- }
124
- throw new Error('Failed to check Mainnet to Sonic bridge approval: Unknown error');
125
- }
126
- }
127
- /**
128
- * Approve the Mainnet to Sonic bridge contract to spend PERQ tokens
129
- */
130
- async approveMainnetToSonicBridge(amount) {
131
- try {
132
- 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);
135
- const tx = await perqTokenContract.approve(bridgeAddress, amountLD);
136
- const txReceipt = await tx.wait();
137
- return txReceipt.transactionHash;
138
- }
139
- catch (error) {
140
- if (error instanceof Error) {
141
- throw new Error(`Failed to approve Mainnet to Sonic bridge: ${error.message}`);
142
- }
143
- throw new Error('Failed to approve Mainnet to Sonic bridge: Unknown error');
144
- }
145
- }
146
- /**
147
- * Quote the fees for bridging PERQ from Mainnet to Sonic
148
- */
149
- async quoteMainnetToSonic(amount, recipientAddress, payInLzToken = false) {
150
- try {
151
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
152
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
153
- const sendParam = {
154
- dstEid: ENDPOINT_IDS.SONIC_MAINNET,
155
- to: recipientBytes32,
156
- amountLD,
157
- minAmountLD: amountLD, // No slippage for now
158
- extraOptions: '0x',
159
- composeMsg: '0x',
160
- oftCmd: '0x',
161
- };
162
- const fee = await this.bridgeMainnetPerqToSonicContract.quoteSend(sendParam, payInLzToken);
163
- return {
164
- nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
165
- lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
166
- };
167
- }
168
- catch (error) {
169
- if (error instanceof Error) {
170
- throw new Error(`Failed to quote Mainnet to Sonic bridge: ${error.message}`);
171
- }
172
- throw new Error('Failed to quote Mainnet to Sonic bridge: Unknown error');
173
- }
174
- }
175
- /**
176
- * Quote the fees for bridging PERQ from Sonic to Mainnet
177
- */
178
- async quoteSonicToMainnet(amount, recipientAddress, payInLzToken = false) {
179
- try {
180
- const amountLD = (0, utils_1.parseUnits)(amount, 18);
181
- const recipientBytes32 = ethers_1.ethers.utils.hexZeroPad(recipientAddress, 32);
182
- const sendParam = {
183
- dstEid: ENDPOINT_IDS.ETHEREUM_MAINNET,
184
- to: recipientBytes32,
185
- amountLD,
186
- minAmountLD: amountLD, // No slippage for now
187
- extraOptions: '0x',
188
- composeMsg: '0x',
189
- oftCmd: '0x',
190
- };
191
- const fee = await this.bridgeSonicPerqToMainnetContract.quoteSend(sendParam, payInLzToken);
192
- return {
193
- nativeFee: (0, utils_1.formatUnits)(fee.nativeFee, 18),
194
- lzTokenFee: (0, utils_1.formatUnits)(fee.lzTokenFee, 18),
195
- };
196
- }
197
- catch (error) {
198
- if (error instanceof Error) {
199
- throw new Error(`Failed to quote Sonic to Mainnet bridge: ${error.message}`);
200
- }
201
- throw new Error('Failed to quote Sonic to Mainnet bridge: Unknown error');
202
- }
203
- }
204
- }
205
- exports.default = BridgePerqPackage;
@@ -1,19 +0,0 @@
1
- import PerqSdk from '../PerqSdk';
2
- import MigrationOption from '../types/MigrationOption';
3
- import { PerqSupportedChainId } from '../types/PerqConfig';
4
- import ProjectHistoricalTvl from '../types/ProjectHistoricalTvl';
5
- export default class LitePackage {
6
- perqSdk: PerqSdk;
7
- constructor(perqSdk: PerqSdk);
8
- private validateChain;
9
- deposit(tokenAddress: string, vaultAddress: string, onChainProjectId: number, amount: string): Promise<string>;
10
- getSwapAndDepositAllowance(tokenAddress: string): Promise<string>;
11
- approveSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
12
- swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, amount: string, vaultAddress: string, onChainProjectId: number): Promise<string>;
13
- withdraw(tokenAddress: string, vaultAddress: string, onChainProjectId: number, amount: string): Promise<string>;
14
- wrapAndDepositEth(vaultAddress: string, onChainProjectId: number, amount: string): Promise<any>;
15
- getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number, chainId: PerqSupportedChainId): Promise<string>;
16
- getMigrationOptions(vaultAddress: string, onChainProjectId: number): Promise<MigrationOption[]>;
17
- migrateDepositToOtherProject(tokenAddress: string, vaultAddress: string, fromProjectId: number, toProjectId: number, amount: string): Promise<string>;
18
- getHistoricalTvl(projectName: string): Promise<ProjectHistoricalTvl>;
19
- }
@@ -1,106 +0,0 @@
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 WETH_DECIMAL_PRECISION = 18;
9
- class LitePackage {
10
- perqSdk;
11
- constructor(perqSdk) {
12
- this.perqSdk = perqSdk;
13
- }
14
- async validateChain(signer, vaultAddress, onChainProjectId) {
15
- const vault = await this.perqSdk.perqApi.fetchPoolLiteDetails(vaultAddress, onChainProjectId);
16
- const currentChainId = await signer.getChainId();
17
- if (vault.chainId !== currentChainId) {
18
- throw Error(`Wrong chain, current chain: ${currentChainId} does not match vault chain: ${vault.chainId}`);
19
- }
20
- }
21
- async deposit(tokenAddress, vaultAddress, onChainProjectId, amount) {
22
- if (!this.perqSdk.signer) {
23
- throw Error('No signer provided');
24
- }
25
- this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
26
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
27
- 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;
31
- }
32
- async getSwapAndDepositAllowance(tokenAddress) {
33
- const res = await this.perqSdk.yelayLiteSdk.vaults.vaultWrapperAllowance(tokenAddress);
34
- return res.toString();
35
- }
36
- async approveSwapAndDeposit(tokenAddress, amount) {
37
- if (!this.perqSdk.signer) {
38
- throw Error('No signer provided');
39
- }
40
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
41
- 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;
45
- }
46
- async swapAndDeposit(fromTokenAddress, toTokenAddress, amount, vaultAddress, onChainProjectId) {
47
- if (!this.perqSdk.signer) {
48
- throw Error('No signer provided');
49
- }
50
- 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;
63
- }
64
- async withdraw(tokenAddress, vaultAddress, onChainProjectId, amount) {
65
- if (!this.perqSdk.signer) {
66
- throw Error('No signer provided');
67
- }
68
- this.validateChain(this.perqSdk.signer, vaultAddress, onChainProjectId);
69
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
70
- 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;
74
- }
75
- async wrapAndDepositEth(vaultAddress, onChainProjectId, amount) {
76
- if (!this.perqSdk.signer) {
77
- throw Error('No signer provided');
78
- }
79
- 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;
83
- }
84
- async getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chainId) {
85
- return this.perqSdk.perqApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chainId.toString());
86
- }
87
- async getMigrationOptions(vaultAddress, onChainProjectId) {
88
- return this.perqSdk.perqApi.fetchMigrationOptions(vaultAddress, onChainProjectId);
89
- }
90
- async migrateDepositToOtherProject(tokenAddress, vaultAddress, fromProjectId, toProjectId, amount) {
91
- if (!this.perqSdk.signer) {
92
- throw Error('No signer provided');
93
- }
94
- this.validateChain(this.perqSdk.signer, vaultAddress, fromProjectId);
95
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
96
- 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;
100
- }
101
- async getHistoricalTvl(projectName) {
102
- const res = await this.perqSdk.perqApi.fetchHistoricalTvl(projectName);
103
- return res;
104
- }
105
- }
106
- exports.default = LitePackage;
@@ -1,21 +0,0 @@
1
- import { BeansBalance, BeanEntry, PerqToBeansSwapInfo, LoyaltyCard, SpecialEditionLoyaltyCard } from '../types';
2
- import PerqSdk from '../PerqSdk';
3
- import SlotMachineSpinCost from '../types/SlotMachineSpinCost';
4
- export default class LoyaltyPackage {
5
- private perqSdk;
6
- constructor(perqSdk: PerqSdk);
7
- getBeansBalance(): Promise<BeansBalance>;
8
- getBeansHistory(): Promise<BeanEntry[]>;
9
- getSwapPerqForBeansInfo(): Promise<PerqToBeansSwapInfo>;
10
- upgradeLoyaltyCard(index: number): Promise<LoyaltyCard>;
11
- getOwnedLoyaltyCard(): Promise<LoyaltyCard>;
12
- getNextLoyaltyCard(): Promise<LoyaltyCard>;
13
- getAllLoyaltyCards(): Promise<LoyaltyCard[]>;
14
- claimSpecialEditionCard(cardId: string): Promise<SpecialEditionLoyaltyCard>;
15
- getOwnedSpecialEditionCards(): Promise<SpecialEditionLoyaltyCard[]>;
16
- getAllSpecialEditionCards(): Promise<SpecialEditionLoyaltyCard[]>;
17
- approveForSlotSpin(tokenAddress: string, amount: string): Promise<string>;
18
- runSlotSpin(isDepositNative: boolean, tokenAddress?: string): Promise<LoyaltyCard | null>;
19
- getSlotMachineCost(): Promise<SlotMachineSpinCost>;
20
- private seededRandom;
21
- }
@@ -1,123 +0,0 @@
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 {
11
- perqSdk;
12
- constructor(perqSdk) {
13
- this.perqSdk = perqSdk;
14
- }
15
- async getBeansBalance() {
16
- const userAddress = await this.perqSdk.signer.getAddress();
17
- return this.perqSdk.perqApi.fetchBeansBalance(userAddress);
18
- }
19
- async getBeansHistory() {
20
- const userAddress = await this.perqSdk.signer.getAddress();
21
- return this.perqSdk.perqApi.fetchBeansHistory(userAddress);
22
- }
23
- async getSwapPerqForBeansInfo() {
24
- return this.perqSdk.perqApi.getSwapPerqForBeansInfo();
25
- }
26
- async upgradeLoyaltyCard(index) {
27
- const payload = {
28
- index,
29
- };
30
- const signedPayload = await this.perqSdk.signHandler.signPayload(payload);
31
- return this.perqSdk.perqApi.upgradeLoyaltyCard(signedPayload);
32
- }
33
- async getOwnedLoyaltyCard() {
34
- const signerAddress = await this.perqSdk.signer.getAddress();
35
- return this.perqSdk.perqApi.fetchOwnedLoyaltyCard(signerAddress);
36
- }
37
- async getNextLoyaltyCard() {
38
- const signerAddress = await this.perqSdk.signer.getAddress();
39
- return this.perqSdk.perqApi.fetchNextLoyaltyCard(signerAddress);
40
- }
41
- async getAllLoyaltyCards() {
42
- return this.perqSdk.perqApi.fetchAllLoyaltyCards();
43
- }
44
- async claimSpecialEditionCard(cardId) {
45
- const payload = {
46
- cardId,
47
- };
48
- const signedPayload = await this.perqSdk.signHandler.signPayload(payload);
49
- return this.perqSdk.perqApi.claimSpecialEditionCard(signedPayload);
50
- }
51
- async getOwnedSpecialEditionCards() {
52
- const signerAddress = await this.perqSdk.signer.getAddress();
53
- return this.perqSdk.perqApi.fetchOwnedSpecialEditionLoyaltyCards(signerAddress);
54
- }
55
- async getAllSpecialEditionCards() {
56
- return this.perqSdk.perqApi.fetchAllSpecialEditionLoyaltyCards();
57
- }
58
- async approveForSlotSpin(tokenAddress, amount) {
59
- if (!this.perqSdk.signer) {
60
- throw Error('No signer provided');
61
- }
62
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
63
- const decimals = await tokenContract.getPrecission();
64
- const parsedAmountToApprove = ethers_1.ethers.utils.parseUnits(amount, decimals);
65
- const slotBurnTokenContractAddress = this.perqSdk.slotBurnTokenContract.getContractAddress();
66
- return await tokenContract.approveToken(slotBurnTokenContractAddress, parsedAmountToApprove.toBigInt());
67
- }
68
- async runSlotSpin(isDepositNative, tokenAddress) {
69
- const signerAddress = await this.perqSdk.signer.getAddress();
70
- const nextLoyaltyCard = await this.perqSdk.perqApi.fetchNextLoyaltyCard(signerAddress);
71
- const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === types_1.ELoyaltyCardTier.White;
72
- const sonicPrice = await this.perqSdk.perqApi.fetchTokenPrice('ws');
73
- const perqPrice = await this.perqSdk.perqApi.fetchTokenPrice('perq');
74
- if (tokenAddress !== undefined &&
75
- tokenAddress.toLowerCase() !== constants_1.SONIC_PERQ_TOKEN_ADDRESS &&
76
- tokenAddress.toLowerCase() !== constants_1.SONIC_WS_TOKEN_ADDRESS) {
77
- throw Error(`Slot machine does not support deposits from token ${tokenAddress}`);
78
- }
79
- const tokenPrice = tokenAddress === undefined ? sonicPrice : tokenAddress === constants_1.SONIC_PERQ_TOKEN_ADDRESS ? perqPrice : sonicPrice;
80
- // hardcode to 0.1 for the first loyalty card
81
- const amountForSpin = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / tokenPrice;
82
- const loyaltyCardOwnedChancesToWin = nextLoyaltyCard.chanceToUpgrade;
83
- const formattedAmountForSpin = ethers_1.ethers.utils.parseUnits(amountForSpin.toString(), 18);
84
- const depositResult = isDepositNative
85
- ? await this.perqSdk.slotBurnTokenContract.depositNative(formattedAmountForSpin.toString())
86
- : await this.perqSdk.slotBurnTokenContract.deposit(tokenAddress, formattedAmountForSpin.toString());
87
- const txHash = depositResult.hash;
88
- const randomValue = this.seededRandom(txHash);
89
- const upgradeWon = randomValue * 100 <= loyaltyCardOwnedChancesToWin && loyaltyCardOwnedChancesToWin !== 0;
90
- if (upgradeWon) {
91
- await this.perqSdk.perqApi.updateSlotMachineReadNow();
92
- }
93
- return upgradeWon ? nextLoyaltyCard : null;
94
- }
95
- async getSlotMachineCost() {
96
- const signerAddress = await this.perqSdk.signer.getAddress();
97
- const nextLoyaltyCard = await this.perqSdk.perqApi.fetchNextLoyaltyCard(signerAddress);
98
- const sonicPrice = await this.perqSdk.perqApi.fetchTokenPrice('ws');
99
- const perqPrice = await this.perqSdk.perqApi.fetchTokenPrice('perq');
100
- const isFirstLoyaltyCard = nextLoyaltyCard.level === 1 && nextLoyaltyCard.tier === types_1.ELoyaltyCardTier.White;
101
- const sonicSpinCost = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / sonicPrice;
102
- const perqSpinCost = isFirstLoyaltyCard ? 0.1 : nextLoyaltyCard.minBurnPerSpinUsd / perqPrice;
103
- return {
104
- nextLoyaltyCard,
105
- sonicSpinCost,
106
- perqSpinCost,
107
- };
108
- }
109
- seededRandom(input) {
110
- // Convert input string to bytes
111
- const inputBytes = ethers_1.ethers.utils.toUtf8Bytes(input);
112
- // Hash using keccak256
113
- const hash = ethers_1.ethers.utils.keccak256(inputBytes);
114
- // Convert to a Buffer from hex string (strip 0x)
115
- const hashBuffer = new Uint8Array(ethers_1.ethers.utils.arrayify(hash));
116
- const dataView = new DataView(hashBuffer.buffer);
117
- // Read first 8 bytes as BigUInt64
118
- const num = dataView.getBigUint64(0);
119
- // Normalize to [0, 1)
120
- return Number(num % BigInt(1e12)) / 1e12;
121
- }
122
- }
123
- exports.default = LoyaltyPackage;