@mantle-rwa/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/cjs/client.js +198 -0
  2. package/dist/cjs/client.js.map +1 -0
  3. package/dist/cjs/constants/index.js +211 -0
  4. package/dist/cjs/constants/index.js.map +1 -0
  5. package/dist/cjs/errors/index.js +218 -0
  6. package/dist/cjs/errors/index.js.map +1 -0
  7. package/dist/cjs/index.js +51 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/modules/compliance.js +202 -0
  10. package/dist/cjs/modules/compliance.js.map +1 -0
  11. package/dist/cjs/modules/index.js +18 -0
  12. package/dist/cjs/modules/index.js.map +1 -0
  13. package/dist/cjs/modules/kyc.js +278 -0
  14. package/dist/cjs/modules/kyc.js.map +1 -0
  15. package/dist/cjs/modules/token.js +365 -0
  16. package/dist/cjs/modules/token.js.map +1 -0
  17. package/dist/cjs/modules/yield.js +406 -0
  18. package/dist/cjs/modules/yield.js.map +1 -0
  19. package/dist/cjs/package.json +3 -0
  20. package/dist/cjs/types/index.js +20 -0
  21. package/dist/cjs/types/index.js.map +1 -0
  22. package/dist/cjs/utils/index.js +206 -0
  23. package/dist/cjs/utils/index.js.map +1 -0
  24. package/dist/esm/client.js +194 -0
  25. package/dist/esm/client.js.map +1 -0
  26. package/dist/esm/constants/index.js +208 -0
  27. package/dist/esm/constants/index.js.map +1 -0
  28. package/dist/esm/errors/index.js +209 -0
  29. package/dist/esm/errors/index.js.map +1 -0
  30. package/dist/esm/index.js +17 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/modules/compliance.js +198 -0
  33. package/dist/esm/modules/compliance.js.map +1 -0
  34. package/dist/esm/modules/index.js +8 -0
  35. package/dist/esm/modules/index.js.map +1 -0
  36. package/dist/esm/modules/kyc.js +273 -0
  37. package/dist/esm/modules/kyc.js.map +1 -0
  38. package/dist/esm/modules/token.js +360 -0
  39. package/dist/esm/modules/token.js.map +1 -0
  40. package/dist/esm/modules/yield.js +401 -0
  41. package/dist/esm/modules/yield.js.map +1 -0
  42. package/dist/esm/types/index.js +17 -0
  43. package/dist/esm/types/index.js.map +1 -0
  44. package/dist/esm/utils/index.js +188 -0
  45. package/dist/esm/utils/index.js.map +1 -0
  46. package/dist/types/client.d.ts +93 -0
  47. package/dist/types/client.d.ts.map +1 -0
  48. package/dist/types/constants/index.d.ts +83 -0
  49. package/dist/types/constants/index.d.ts.map +1 -0
  50. package/dist/types/errors/index.d.ts +83 -0
  51. package/dist/types/errors/index.d.ts.map +1 -0
  52. package/dist/types/index.d.ts +13 -0
  53. package/dist/types/index.d.ts.map +1 -0
  54. package/dist/types/modules/compliance.d.ts +29 -0
  55. package/dist/types/modules/compliance.d.ts.map +1 -0
  56. package/dist/types/modules/index.d.ts +8 -0
  57. package/dist/types/modules/index.d.ts.map +1 -0
  58. package/dist/types/modules/kyc.d.ts +131 -0
  59. package/dist/types/modules/kyc.d.ts.map +1 -0
  60. package/dist/types/modules/token.d.ts +145 -0
  61. package/dist/types/modules/token.d.ts.map +1 -0
  62. package/dist/types/modules/yield.d.ts +143 -0
  63. package/dist/types/modules/yield.d.ts.map +1 -0
  64. package/dist/types/types/index.d.ts +254 -0
  65. package/dist/types/types/index.d.ts.map +1 -0
  66. package/dist/types/utils/index.d.ts +80 -0
  67. package/dist/types/utils/index.d.ts.map +1 -0
  68. package/package.json +52 -0
  69. package/src/client.ts +258 -0
  70. package/src/constants/index.ts +226 -0
  71. package/src/errors/index.ts +291 -0
  72. package/src/index.ts +42 -0
  73. package/src/modules/compliance.ts +252 -0
  74. package/src/modules/index.ts +8 -0
  75. package/src/modules/kyc.ts +446 -0
  76. package/src/modules/token.ts +488 -0
  77. package/src/modules/yield.ts +566 -0
  78. package/src/types/index.ts +326 -0
  79. package/src/utils/index.ts +240 -0
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ /**
3
+ * RWAClient - Main entry point for the Mantle RWA SDK
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RWAClient = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const token_1 = require("./modules/token");
9
+ const kyc_1 = require("./modules/kyc");
10
+ const yield_1 = require("./modules/yield");
11
+ const compliance_1 = require("./modules/compliance");
12
+ const constants_1 = require("./constants");
13
+ const errors_1 = require("./errors");
14
+ const utils_1 = require("./utils");
15
+ /**
16
+ * Main client for interacting with Mantle RWA contracts
17
+ */
18
+ class RWAClient {
19
+ _provider;
20
+ _signer;
21
+ _networkConfig;
22
+ _factoryAddress;
23
+ _retries;
24
+ _retryDelay;
25
+ /** Token module for RWA token operations */
26
+ token;
27
+ /** KYC module for investor verification */
28
+ kyc;
29
+ /** Yield module for distribution management */
30
+ yield;
31
+ /** Compliance module for transfer eligibility */
32
+ compliance;
33
+ constructor(config) {
34
+ // Resolve network configuration
35
+ if (typeof config.network === 'string') {
36
+ const networkConfig = constants_1.NETWORKS[config.network];
37
+ if (!networkConfig) {
38
+ throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_CONFIGURATION, `Unknown network: ${config.network}. Use 'mantle', 'mantle-sepolia', or provide custom network config.`);
39
+ }
40
+ this._networkConfig = networkConfig;
41
+ }
42
+ else {
43
+ this._networkConfig = {
44
+ name: config.network.name || 'Custom Network',
45
+ chainId: config.network.chainId,
46
+ rpcUrl: config.network.rpcUrl,
47
+ explorerUrl: config.network.explorerUrl || '',
48
+ };
49
+ }
50
+ // Create provider
51
+ this._provider = new ethers_1.ethers.JsonRpcProvider(this._networkConfig.rpcUrl);
52
+ // Create signer if private key provided
53
+ if (config.signer) {
54
+ this._signer = config.signer;
55
+ }
56
+ else if (config.privateKey) {
57
+ this._signer = new ethers_1.ethers.Wallet(config.privateKey, this._provider);
58
+ }
59
+ else {
60
+ this._signer = null;
61
+ }
62
+ // Store configuration
63
+ this._factoryAddress = config.factoryAddress || this._networkConfig.contracts?.factory;
64
+ this._retries = config.retries ?? constants_1.DEFAULTS.TRANSACTION_RETRIES;
65
+ this._retryDelay = config.retryDelay ?? constants_1.DEFAULTS.RETRY_DELAY_MS;
66
+ // Initialize modules
67
+ this.token = new token_1.TokenModule(this._provider, this._signer, this._retries, this._retryDelay);
68
+ this.kyc = new kyc_1.KYCModule(this._provider, this._signer, this._retries, this._retryDelay);
69
+ this.yield = new yield_1.YieldModule(this._provider, this._signer, this._retries, this._retryDelay);
70
+ this.compliance = new compliance_1.ComplianceModule(this._provider, this._signer);
71
+ }
72
+ /**
73
+ * Get the provider instance
74
+ */
75
+ get provider() {
76
+ return this._provider;
77
+ }
78
+ /**
79
+ * Get the signer instance (throws if not available)
80
+ */
81
+ get signer() {
82
+ if (!this._signer) {
83
+ throw new errors_1.RWAError(errors_1.ErrorCode.SIGNER_REQUIRED, 'A signer is required for this operation. Provide a privateKey or signer in the client configuration.');
84
+ }
85
+ return this._signer;
86
+ }
87
+ /**
88
+ * Check if a signer is available
89
+ */
90
+ get hasSigner() {
91
+ return this._signer !== null;
92
+ }
93
+ /**
94
+ * Get the network configuration
95
+ */
96
+ get network() {
97
+ return this._networkConfig;
98
+ }
99
+ /**
100
+ * Deploy a complete RWA system using the factory contract
101
+ * @param config Deployment configuration
102
+ * @returns Addresses of all deployed contracts
103
+ */
104
+ async deployRWASystem(config) {
105
+ if (!this._factoryAddress) {
106
+ throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_CONFIGURATION, 'Factory address not configured. Provide factoryAddress in client config or use a network with a deployed factory.');
107
+ }
108
+ // Validate configuration
109
+ this._validateDeploymentConfig(config);
110
+ const factory = new ethers_1.ethers.Contract(this._factoryAddress, constants_1.RWA_FACTORY_ABI, this.signer);
111
+ const deployConfig = {
112
+ tokenName: config.tokenName,
113
+ tokenSymbol: config.tokenSymbol,
114
+ initialSupply: (0, utils_1.parseAmount)(config.initialSupply),
115
+ complianceModules: config.complianceModules || [],
116
+ yieldClaimWindowDays: config.yieldClaimWindowDays ?? constants_1.DEFAULTS.YIELD_CLAIM_WINDOW_DAYS,
117
+ vaultSigners: config.vaultSigners,
118
+ vaultThreshold: config.vaultThreshold,
119
+ vaultWithdrawalThreshold: (0, utils_1.parseAmount)(config.vaultWithdrawalThreshold || constants_1.DEFAULTS.VAULT_WITHDRAWAL_THRESHOLD),
120
+ };
121
+ try {
122
+ const tx = await (0, utils_1.retry)(() => factory.deploy(deployConfig), { retries: this._retries, delay: this._retryDelay });
123
+ const receipt = await tx.wait();
124
+ const iface = new ethers_1.ethers.Interface(constants_1.RWA_FACTORY_ABI);
125
+ const events = (0, utils_1.parseEvents)(receipt, iface);
126
+ const deployedEvent = events.find((e) => e.name === 'RWASystemDeployed');
127
+ if (!deployedEvent) {
128
+ throw new errors_1.RWAError(errors_1.ErrorCode.UNKNOWN, 'Deployment succeeded but RWASystemDeployed event not found');
129
+ }
130
+ return {
131
+ token: deployedEvent.args.token,
132
+ vault: deployedEvent.args.vault,
133
+ yieldDistributor: deployedEvent.args.yieldDistributor,
134
+ kycRegistry: deployedEvent.args.kycRegistry,
135
+ };
136
+ }
137
+ catch (error) {
138
+ throw (0, errors_1.parseContractError)(error, this._factoryAddress, 'deploy');
139
+ }
140
+ }
141
+ /**
142
+ * Connect to an existing RWA token
143
+ */
144
+ connectToken(address) {
145
+ return this.token.connect(address);
146
+ }
147
+ /**
148
+ * Connect to an existing KYC registry
149
+ */
150
+ connectKYCRegistry(address) {
151
+ return this.kyc.connect(address);
152
+ }
153
+ /**
154
+ * Connect to an existing yield distributor
155
+ */
156
+ connectYieldDistributor(address) {
157
+ return this.yield.connect(address);
158
+ }
159
+ /**
160
+ * Get the current block number
161
+ */
162
+ async getBlockNumber() {
163
+ return this._provider.getBlockNumber();
164
+ }
165
+ /**
166
+ * Get the balance of an address
167
+ */
168
+ async getBalance(address) {
169
+ return this._provider.getBalance(address);
170
+ }
171
+ /**
172
+ * Validate deployment configuration
173
+ */
174
+ _validateDeploymentConfig(config) {
175
+ if (!config.tokenName || config.tokenName.length === 0) {
176
+ throw new errors_1.RWAError(errors_1.ErrorCode.MISSING_PARAMETER, 'tokenName is required');
177
+ }
178
+ if (!config.tokenSymbol || config.tokenSymbol.length === 0) {
179
+ throw new errors_1.RWAError(errors_1.ErrorCode.MISSING_PARAMETER, 'tokenSymbol is required');
180
+ }
181
+ if (!config.initialSupply || parseFloat(config.initialSupply) <= 0) {
182
+ throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_AMOUNT, 'initialSupply must be greater than 0');
183
+ }
184
+ if (!config.vaultSigners || config.vaultSigners.length === 0) {
185
+ throw new errors_1.RWAError(errors_1.ErrorCode.MISSING_PARAMETER, 'vaultSigners is required');
186
+ }
187
+ for (const signer of config.vaultSigners) {
188
+ if (!(0, utils_1.isValidAddress)(signer)) {
189
+ throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid vault signer address: ${signer}`);
190
+ }
191
+ }
192
+ if (config.vaultThreshold <= 0 || config.vaultThreshold > config.vaultSigners.length) {
193
+ throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_CONFIGURATION, `vaultThreshold must be between 1 and ${config.vaultSigners.length}`);
194
+ }
195
+ }
196
+ }
197
+ exports.RWAClient = RWAClient;
198
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mCAA4D;AAC5D,2CAA8C;AAC9C,uCAA0C;AAC1C,2CAA8C;AAC9C,qDAAwD;AAExD,2CAAkE;AAClE,qCAAmE;AACnE,mCAA0E;AAoB1E;;GAEG;AACH,MAAa,SAAS;IACD,SAAS,CAAW;IACpB,OAAO,CAAgB;IACvB,cAAc,CAAgB;IAC9B,eAAe,CAAU;IACzB,QAAQ,CAAS;IACjB,WAAW,CAAS;IAErC,4CAA4C;IACnC,KAAK,CAAc;IAC5B,2CAA2C;IAClC,GAAG,CAAY;IACxB,+CAA+C;IACtC,KAAK,CAAc;IAC5B,iDAAiD;I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,wCAAwC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CACvE,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA9ND,8BA8NC"}
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ /**
3
+ * Constants for the Mantle RWA SDK
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RWA_FACTORY_ABI = exports.ASSET_VAULT_ABI = exports.YIELD_DISTRIBUTOR_ABI = exports.KYC_REGISTRY_ABI = exports.RWA_TOKEN_ABI = exports.ERC20_ABI = exports.DEFAULTS = exports.PAYMENT_TOKENS = exports.ROLES = exports.NETWORKS = exports.MANTLE_SEPOLIA = exports.MANTLE_MAINNET = void 0;
7
+ /*//////////////////////////////////////////////////////////////
8
+ NETWORK CONSTANTS
9
+ //////////////////////////////////////////////////////////////*/
10
+ /**
11
+ * Mantle Mainnet configuration
12
+ */
13
+ exports.MANTLE_MAINNET = {
14
+ name: 'Mantle',
15
+ chainId: 5000,
16
+ rpcUrl: 'https://rpc.mantle.xyz',
17
+ explorerUrl: 'https://explorer.mantle.xyz',
18
+ };
19
+ /**
20
+ * Mantle Sepolia Testnet configuration
21
+ */
22
+ exports.MANTLE_SEPOLIA = {
23
+ name: 'Mantle Sepolia',
24
+ chainId: 5003,
25
+ rpcUrl: 'https://rpc.sepolia.mantle.xyz',
26
+ explorerUrl: 'https://explorer.sepolia.mantle.xyz',
27
+ };
28
+ /**
29
+ * Network configurations by name
30
+ */
31
+ exports.NETWORKS = {
32
+ mantle: exports.MANTLE_MAINNET,
33
+ 'mantle-sepolia': exports.MANTLE_SEPOLIA,
34
+ };
35
+ /*//////////////////////////////////////////////////////////////
36
+ CONTRACT CONSTANTS
37
+ //////////////////////////////////////////////////////////////*/
38
+ /**
39
+ * Role identifiers (keccak256 hashes)
40
+ */
41
+ exports.ROLES = {
42
+ DEFAULT_ADMIN_ROLE: '0x0000000000000000000000000000000000000000000000000000000000000000',
43
+ ISSUER_ROLE: '0x114e74f6ea3bd819998f78687bfcb11b140da08e9b7d222fa9c1f1ba1f2aa122', // keccak256("ISSUER_ROLE")
44
+ COMPLIANCE_OFFICER_ROLE: '0x5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f5c5f', // keccak256("COMPLIANCE_OFFICER_ROLE")
45
+ KYC_ADMIN_ROLE: '0x6b79635f61646d696e5f726f6c650000000000000000000000000000000000', // keccak256("KYC_ADMIN_ROLE")
46
+ VAULT_SIGNER_ROLE: '0x7661756c745f7369676e65725f726f6c650000000000000000000000000000', // keccak256("VAULT_SIGNER_ROLE")
47
+ };
48
+ /*//////////////////////////////////////////////////////////////
49
+ TOKEN CONSTANTS
50
+ //////////////////////////////////////////////////////////////*/
51
+ /**
52
+ * Common payment token addresses on Mantle
53
+ */
54
+ exports.PAYMENT_TOKENS = {
55
+ mantle: {
56
+ USDC: '0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9',
57
+ USDT: '0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE',
58
+ MNT: '0x0000000000000000000000000000000000000000', // Native token
59
+ },
60
+ 'mantle-sepolia': {
61
+ USDC: '0x0000000000000000000000000000000000000000', // Testnet mock
62
+ USDT: '0x0000000000000000000000000000000000000000', // Testnet mock
63
+ MNT: '0x0000000000000000000000000000000000000000', // Native token
64
+ },
65
+ };
66
+ /*//////////////////////////////////////////////////////////////
67
+ DEFAULT VALUES
68
+ //////////////////////////////////////////////////////////////*/
69
+ /**
70
+ * Default configuration values
71
+ */
72
+ exports.DEFAULTS = {
73
+ /** Default number of days for yield claim window */
74
+ YIELD_CLAIM_WINDOW_DAYS: 30,
75
+ /** Default vault withdrawal threshold (in wei) */
76
+ VAULT_WITHDRAWAL_THRESHOLD: '1000000000000000000000', // 1000 tokens
77
+ /** Default number of transaction retries */
78
+ TRANSACTION_RETRIES: 3,
79
+ /** Default retry delay in milliseconds */
80
+ RETRY_DELAY_MS: 1000,
81
+ /** Gas estimation buffer (20%) */
82
+ GAS_BUFFER_PERCENT: 20,
83
+ /** Default KYC expiry duration in seconds (1 year) */
84
+ KYC_EXPIRY_DURATION: 365 * 24 * 60 * 60,
85
+ };
86
+ /*//////////////////////////////////////////////////////////////
87
+ ABI FRAGMENTS
88
+ //////////////////////////////////////////////////////////////*/
89
+ /**
90
+ * Common ERC20 ABI fragments
91
+ */
92
+ exports.ERC20_ABI = [
93
+ 'function name() view returns (string)',
94
+ 'function symbol() view returns (string)',
95
+ 'function decimals() view returns (uint8)',
96
+ 'function totalSupply() view returns (uint256)',
97
+ 'function balanceOf(address account) view returns (uint256)',
98
+ 'function transfer(address to, uint256 amount) returns (bool)',
99
+ 'function allowance(address owner, address spender) view returns (uint256)',
100
+ 'function approve(address spender, uint256 amount) returns (bool)',
101
+ 'function transferFrom(address from, address to, uint256 amount) returns (bool)',
102
+ 'event Transfer(address indexed from, address indexed to, uint256 value)',
103
+ 'event Approval(address indexed owner, address indexed spender, uint256 value)',
104
+ ];
105
+ /**
106
+ * RWAToken ABI fragments
107
+ */
108
+ exports.RWA_TOKEN_ABI = [
109
+ ...exports.ERC20_ABI,
110
+ // Compliance functions
111
+ 'function setKYCRegistry(address registry)',
112
+ 'function addComplianceModule(address module)',
113
+ 'function removeComplianceModule(address module)',
114
+ 'function isTransferAllowed(address from, address to, uint256 amount) view returns (bool allowed, string reason)',
115
+ // Admin functions
116
+ 'function mint(address to, uint256 amount)',
117
+ 'function burn(address from, uint256 amount)',
118
+ 'function pause()',
119
+ 'function unpause()',
120
+ 'function paused() view returns (bool)',
121
+ // Role management
122
+ 'function grantIssuerRole(address account)',
123
+ 'function grantComplianceOfficerRole(address account)',
124
+ 'function revokeIssuerRole(address account)',
125
+ 'function revokeComplianceOfficerRole(address account)',
126
+ // View functions
127
+ 'function kycRegistry() view returns (address)',
128
+ 'function isComplianceModule(address module) view returns (bool)',
129
+ 'function getComplianceModules() view returns (address[])',
130
+ // Snapshot
131
+ 'function snapshot() returns (uint256)',
132
+ 'function balanceOfAt(address account, uint256 snapshotId) view returns (uint256)',
133
+ 'function totalSupplyAt(uint256 snapshotId) view returns (uint256)',
134
+ // Events
135
+ 'event TransferRestricted(address indexed from, address indexed to, uint256 amount, string reason)',
136
+ 'event ComplianceModuleUpdated(address indexed module, bool enabled)',
137
+ 'event TokensPaused(address indexed by)',
138
+ 'event TokensUnpaused(address indexed by)',
139
+ 'event KYCRegistryUpdated(address indexed oldRegistry, address indexed newRegistry)',
140
+ ];
141
+ /**
142
+ * KYCRegistry ABI fragments
143
+ */
144
+ exports.KYC_REGISTRY_ABI = [
145
+ 'function addInvestor(address investor, uint8 tier, uint256 expiryTimestamp, bytes32 identityHash)',
146
+ 'function updateInvestor(address investor, uint8 tier, uint256 expiryTimestamp)',
147
+ 'function removeInvestor(address investor)',
148
+ 'function batchAddInvestors(address[] investors, uint8[] tiers, uint256[] expiries, bytes32[] identityHashes)',
149
+ 'function isVerified(address investor) view returns (bool)',
150
+ 'function getInvestorInfo(address investor) view returns (bool verified, uint8 tier, uint256 expiry, bytes32 identityHash)',
151
+ 'function isAccredited(address investor) view returns (bool)',
152
+ 'event InvestorVerified(address indexed investor, uint8 tier, uint256 expiry)',
153
+ 'event InvestorRemoved(address indexed investor)',
154
+ 'event InvestorUpdated(address indexed investor, uint8 newTier, uint256 newExpiry)',
155
+ ];
156
+ /**
157
+ * YieldDistributor ABI fragments
158
+ */
159
+ exports.YIELD_DISTRIBUTOR_ABI = [
160
+ 'function createDistribution(address paymentToken, uint256 totalAmount, uint256 claimWindowDays) returns (uint256 distributionId)',
161
+ 'function claim(uint256 distributionId)',
162
+ 'function claimMultiple(uint256[] distributionIds)',
163
+ 'function handleUnclaimedFunds(uint256 distributionId)',
164
+ 'function setUnclaimedFundsRecipient(address recipient)',
165
+ 'function getClaimableAmount(uint256 distributionId, address account) view returns (uint256)',
166
+ 'function getDistributionInfo(uint256 distributionId) view returns (address paymentToken, uint256 totalAmount, uint256 snapshotId, uint256 claimDeadline, uint256 claimedAmount)',
167
+ 'function hasClaimed(uint256 distributionId, address account) view returns (bool)',
168
+ 'function distributionCount() view returns (uint256)',
169
+ 'event DistributionCreated(uint256 indexed distributionId, address indexed paymentToken, uint256 totalAmount, uint256 snapshotId)',
170
+ 'event YieldClaimed(uint256 indexed distributionId, address indexed claimant, uint256 amount)',
171
+ 'event UnclaimedFundsHandled(uint256 indexed distributionId, uint256 amount, address indexed recipient)',
172
+ ];
173
+ /**
174
+ * AssetVault ABI fragments
175
+ */
176
+ exports.ASSET_VAULT_ABI = [
177
+ 'function deposit(address token, uint256 amount)',
178
+ 'function depositETH() payable',
179
+ 'function proposeWithdrawal(address token, uint256 amount, address recipient) returns (uint256 proposalId)',
180
+ 'function approveWithdrawal(uint256 proposalId)',
181
+ 'function executeWithdrawal(uint256 proposalId)',
182
+ 'function declareEmergency()',
183
+ 'function resolveEmergency()',
184
+ 'function emergencyWithdraw(address token, address recipient)',
185
+ 'function getCollateralizationRatio() view returns (uint256)',
186
+ 'function getAssetBalance(address token) view returns (uint256)',
187
+ 'function isBackingVerified() view returns (bool)',
188
+ 'function isEmergency() view returns (bool)',
189
+ 'event Deposited(address indexed token, uint256 amount, address indexed depositor)',
190
+ 'event Withdrawn(address indexed token, uint256 amount, address indexed recipient)',
191
+ 'event EmergencyWithdrawal(address indexed token, uint256 amount, address indexed recipient)',
192
+ 'event SignerAdded(address indexed signer)',
193
+ 'event SignerRemoved(address indexed signer)',
194
+ 'event ThresholdUpdated(uint256 newThreshold)',
195
+ 'event WithdrawalProposed(uint256 indexed proposalId, address indexed token, uint256 amount, address recipient)',
196
+ 'event WithdrawalApproved(uint256 indexed proposalId, address indexed approver)',
197
+ 'event EmergencyDeclared(address indexed declaredBy)',
198
+ 'event EmergencyResolved(address indexed resolvedBy)',
199
+ ];
200
+ /**
201
+ * RWAFactory ABI fragments
202
+ */
203
+ exports.RWA_FACTORY_ABI = [
204
+ 'function deploy((string tokenName, string tokenSymbol, uint256 initialSupply, address[] complianceModules, uint256 yieldClaimWindowDays, address[] vaultSigners, uint256 vaultThreshold, uint256 vaultWithdrawalThreshold) config) returns ((address token, address vault, address yieldDistributor, address kycRegistry) contracts)',
205
+ 'function upgradeToken(address proxy, address newImplementation)',
206
+ 'function upgradeVault(address proxy, address newImplementation)',
207
+ 'function upgradeYieldDistributor(address proxy, address newImplementation)',
208
+ 'function upgradeKYCRegistry(address proxy, address newImplementation)',
209
+ 'event RWASystemDeployed(address indexed deployer, address token, address vault, address yieldDistributor, address kycRegistry)',
210
+ ];
211
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;gEAEgE;AAEhE;;GAEG;AACU,QAAA,cAAc,GAAkB;IACzC,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,wBAAwB;IAChC,WAAW,EAAE,6BAA6B;CAC7C,CAAC;AAEF;;GAEG;AACU,QAAA,cAAc,GAAkB;IACzC,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,gCAAgC;IACxC,WAAW,EAAE,qCAAqC;CACrD,CAAC;AAEF;;GAEG;AACU,QAAA,QAAQ,GAAkC;IACnD,MAAM,EAAE,sBAAc;IACtB,gBAAgB,EAAE,sBAAc;CACnC,CAAC;AAEF;;gEAEgE;AAEhE;;GAEG;AACU,QAAA,KAAK,GAAG;IACjB,kBAAkB,EAAE,oEAAoE;IACxF,WAAW,EAAE,oEAAoE,EAAE,2BAA2B;IAC9G,uBAAuB,EAAE,oEAAoE,EAAE,uCAAuC;IACtI,cAAc,EAAE,kEAAkE,EAAE,8BAA8B;IAClH,iBAAiB,EAAE,kEAAkE,EAAE,iCAAiC;CAClH,CAAC;AAEX;;gEAEgE;AAEhE;;GAEG;AACU,QAAA,cAAc,GAAG;IAC1B,MAAM,EAAE;QACJ,IAAI,EAAE,4CAA4C;QACl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ACT,mGAAmG;IACnG,qEAAqE;IACrE,wCAAwC;IACxC,0CAA0C;IAC1C,oFAAoF;CAC9E,CAAC;AAEX;;GAEG;AACU,QAAA,gBAAgB,GAAG;IAC5B,mGAAmG;IACnG,gFAAgF;IAChF,2CAA2C;IAC3C,8GAA8G;IAC9G,2DAA2D;IAC3D,2HAA2H;IAC3H,6DAA6D;IAC7D,8EAA8E;IAC9E,iDAAiD;IACjD,mFAAmF;CAC7E,CAAC;AAEX;;GAEG;AACU,QAAA,qBAAqB,GAAG;IACjC,kIAAkI;IAClI,wCAAwC;IACxC,mDAAmD;IACnD,uDAAuD;IACvD,wDAAwD;IACxD,6FAA6F;IAC7F,iLAAiL;IACjL,kFAAkF;IAClF,qDAAqD;IACrD,kIAAkI;IAClI,8FAA8F;IAC9F,wGAAwG;CAClG,CAAC;AAEX;;GAEG;AACU,QAAA,eAAe,GAAG;IAC3B,iDAAiD;IACjD,+BAA+B;IAC/B,2GAA2G;IAC3G,gDAAgD;IAChD,gDAAgD;IAChD,6BAA6B;IAC7B,6BAA6B;IAC7B,8DAA8D;IAC9D,6DAA6D;IAC7D,gEAAgE;IAChE,kDAAkD;IAClD,4CAA4C;IAC5C,mFAAmF;IACnF,mFAAmF;IACnF,6FAA6F;IAC7F,2CAA2C;IAC3C,6CAA6C;IAC7C,8CAA8C;IAC9C,gHAAgH;IAChH,gFAAgF;IAChF,qDAAqD;IACrD,qDAAqD;CAC/C,CAAC;AAEX;;GAEG;AACU,QAAA,eAAe,GAAG;IAC3B,sUAAsU;IACtU,iEAAiE;IACjE,iEAAiE;IACjE,4EAA4E;IAC5E,uEAAuE;IACvE,gIAAgI;CAC1H,CAAC"}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ /**
3
+ * Error handling for the Mantle RWA SDK
4
+ * Provides descriptive error messages with suggested fixes
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ValidationError = exports.NetworkError = exports.ContractError = exports.RWAError = exports.ErrorCode = void 0;
8
+ exports.parseContractError = parseContractError;
9
+ exports.parseNetworkError = parseNetworkError;
10
+ /**
11
+ * Error codes for categorizing errors
12
+ */
13
+ var ErrorCode;
14
+ (function (ErrorCode) {
15
+ // Contract errors
16
+ ErrorCode["NOT_VERIFIED"] = "NOT_VERIFIED";
17
+ ErrorCode["KYC_EXPIRED"] = "KYC_EXPIRED";
18
+ ErrorCode["TRANSFER_RESTRICTED"] = "TRANSFER_RESTRICTED";
19
+ ErrorCode["TOKENS_PAUSED"] = "TOKENS_PAUSED";
20
+ ErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
21
+ ErrorCode["INSUFFICIENT_BALANCE"] = "INSUFFICIENT_BALANCE";
22
+ ErrorCode["INVALID_RECIPIENT"] = "INVALID_RECIPIENT";
23
+ ErrorCode["CLAIM_WINDOW_EXPIRED"] = "CLAIM_WINDOW_EXPIRED";
24
+ ErrorCode["ALREADY_CLAIMED"] = "ALREADY_CLAIMED";
25
+ ErrorCode["WITHDRAWAL_THRESHOLD_NOT_MET"] = "WITHDRAWAL_THRESHOLD_NOT_MET";
26
+ ErrorCode["EMERGENCY_NOT_DECLARED"] = "EMERGENCY_NOT_DECLARED";
27
+ ErrorCode["REENTRANCY"] = "REENTRANCY";
28
+ // Network errors
29
+ ErrorCode["RPC_ERROR"] = "RPC_ERROR";
30
+ ErrorCode["TIMEOUT"] = "TIMEOUT";
31
+ ErrorCode["NONCE_TOO_LOW"] = "NONCE_TOO_LOW";
32
+ ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
33
+ ErrorCode["GAS_ESTIMATION_FAILED"] = "GAS_ESTIMATION_FAILED";
34
+ ErrorCode["NETWORK_MISMATCH"] = "NETWORK_MISMATCH";
35
+ // Validation errors
36
+ ErrorCode["INVALID_ADDRESS"] = "INVALID_ADDRESS";
37
+ ErrorCode["INVALID_AMOUNT"] = "INVALID_AMOUNT";
38
+ ErrorCode["MISSING_PARAMETER"] = "MISSING_PARAMETER";
39
+ ErrorCode["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
40
+ // Provider errors
41
+ ErrorCode["PROVIDER_NOT_CONFIGURED"] = "PROVIDER_NOT_CONFIGURED";
42
+ ErrorCode["SIGNER_REQUIRED"] = "SIGNER_REQUIRED";
43
+ // Unknown
44
+ ErrorCode["UNKNOWN"] = "UNKNOWN";
45
+ })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
46
+ /**
47
+ * Suggested fixes for common errors
48
+ */
49
+ const ERROR_SUGGESTIONS = {
50
+ [ErrorCode.NOT_VERIFIED]: 'Ensure the address is registered in the KYC registry. Use kycModule.updateRegistry() to add the investor.',
51
+ [ErrorCode.KYC_EXPIRED]: 'The KYC verification has expired. Update the investor expiry using kycModule.updateRegistry().',
52
+ [ErrorCode.TRANSFER_RESTRICTED]: 'Check compliance requirements using complianceModule.checkTransferEligibility() before attempting transfer.',
53
+ [ErrorCode.TOKENS_PAUSED]: 'Token transfers are currently paused. Contact the token issuer or wait for tokens to be unpaused.',
54
+ [ErrorCode.UNAUTHORIZED]: 'The connected account does not have the required role. Ensure you are using the correct signer.',
55
+ [ErrorCode.INSUFFICIENT_BALANCE]: 'The account does not have enough tokens. Check balance using tokenInstance.balanceOf().',
56
+ [ErrorCode.INVALID_RECIPIENT]: 'The recipient address is invalid or the zero address. Verify the address format.',
57
+ [ErrorCode.CLAIM_WINDOW_EXPIRED]: 'The claim window for this distribution has expired. Unclaimed funds may have been handled.',
58
+ [ErrorCode.ALREADY_CLAIMED]: 'This distribution has already been claimed by this account.',
59
+ [ErrorCode.WITHDRAWAL_THRESHOLD_NOT_MET]: 'Not enough signers have approved this withdrawal. Additional approvals are required.',
60
+ [ErrorCode.EMERGENCY_NOT_DECLARED]: 'Emergency mode must be declared before emergency withdrawals can be executed.',
61
+ [ErrorCode.REENTRANCY]: 'Reentrancy detected. This is a security measure. Do not call vault functions from within callbacks.',
62
+ [ErrorCode.RPC_ERROR]: 'Failed to connect to the RPC endpoint. Check your network configuration and try again.',
63
+ [ErrorCode.TIMEOUT]: 'The request timed out. The network may be congested. Try again with higher gas price.',
64
+ [ErrorCode.NONCE_TOO_LOW]: 'Transaction nonce is too low. A pending transaction may exist. Wait for it to confirm or increase nonce.',
65
+ [ErrorCode.INSUFFICIENT_FUNDS]: 'Insufficient funds for gas. Ensure the account has enough native tokens (MNT) for transaction fees.',
66
+ [ErrorCode.GAS_ESTIMATION_FAILED]: 'Gas estimation failed. The transaction may revert. Check parameters and try again.',
67
+ [ErrorCode.NETWORK_MISMATCH]: 'Connected to wrong network. Ensure your wallet is connected to the correct chain.',
68
+ [ErrorCode.INVALID_ADDRESS]: 'The provided address is not a valid Ethereum address. Check the format (0x followed by 40 hex characters).',
69
+ [ErrorCode.INVALID_AMOUNT]: 'The amount is invalid. Ensure it is a positive number and properly formatted.',
70
+ [ErrorCode.MISSING_PARAMETER]: 'A required parameter is missing. Check the function documentation for required parameters.',
71
+ [ErrorCode.INVALID_CONFIGURATION]: 'The configuration is invalid. Review the configuration object and ensure all required fields are set.',
72
+ [ErrorCode.PROVIDER_NOT_CONFIGURED]: 'No provider is configured. Initialize RWAClient with a network configuration or provider.',
73
+ [ErrorCode.SIGNER_REQUIRED]: 'A signer is required for this operation. Provide a private key or signer in the client configuration.',
74
+ [ErrorCode.UNKNOWN]: 'An unknown error occurred. Check the error details for more information.',
75
+ };
76
+ /**
77
+ * Base error class for RWA SDK errors
78
+ */
79
+ class RWAError extends Error {
80
+ code;
81
+ suggestion;
82
+ details;
83
+ constructor(code, message, details) {
84
+ super(message);
85
+ this.name = 'RWAError';
86
+ this.code = code;
87
+ this.suggestion = ERROR_SUGGESTIONS[code] || ERROR_SUGGESTIONS[ErrorCode.UNKNOWN];
88
+ this.details = details;
89
+ // Maintains proper stack trace for where error was thrown
90
+ if (Error.captureStackTrace) {
91
+ Error.captureStackTrace(this, RWAError);
92
+ }
93
+ }
94
+ /**
95
+ * Get a formatted error message including suggestion
96
+ */
97
+ toFormattedString() {
98
+ let result = `[${this.code}] ${this.message}`;
99
+ result += `\n\nSuggested fix: ${this.suggestion}`;
100
+ if (this.details) {
101
+ result += `\n\nDetails: ${JSON.stringify(this.details, null, 2)}`;
102
+ }
103
+ return result;
104
+ }
105
+ }
106
+ exports.RWAError = RWAError;
107
+ /**
108
+ * Error class for contract-related errors
109
+ */
110
+ class ContractError extends RWAError {
111
+ contractAddress;
112
+ functionName;
113
+ revertReason;
114
+ constructor(code, message, contractAddress, functionName, revertReason, details) {
115
+ super(code, message, details);
116
+ this.name = 'ContractError';
117
+ this.contractAddress = contractAddress;
118
+ this.functionName = functionName;
119
+ this.revertReason = revertReason;
120
+ }
121
+ }
122
+ exports.ContractError = ContractError;
123
+ /**
124
+ * Error class for network-related errors
125
+ */
126
+ class NetworkError extends RWAError {
127
+ chainId;
128
+ rpcUrl;
129
+ retryable;
130
+ constructor(code, message, retryable, chainId, rpcUrl, details) {
131
+ super(code, message, details);
132
+ this.name = 'NetworkError';
133
+ this.chainId = chainId;
134
+ this.rpcUrl = rpcUrl;
135
+ this.retryable = retryable;
136
+ }
137
+ }
138
+ exports.NetworkError = NetworkError;
139
+ /**
140
+ * Error class for validation errors
141
+ */
142
+ class ValidationError extends RWAError {
143
+ field;
144
+ constraint;
145
+ value;
146
+ constructor(code, message, field, constraint, value, details) {
147
+ super(code, message, details);
148
+ this.name = 'ValidationError';
149
+ this.field = field;
150
+ this.constraint = constraint;
151
+ this.value = value;
152
+ }
153
+ }
154
+ exports.ValidationError = ValidationError;
155
+ /**
156
+ * Parse a contract revert reason and return the appropriate error
157
+ */
158
+ function parseContractError(error, contractAddress, functionName) {
159
+ const errorObj = error;
160
+ const reason = errorObj.reason || errorObj.message || 'Unknown contract error';
161
+ // Map common revert reasons to error codes
162
+ let code = ErrorCode.UNKNOWN;
163
+ if (reason.includes('NotVerified') || reason.includes('not verified')) {
164
+ code = ErrorCode.NOT_VERIFIED;
165
+ }
166
+ else if (reason.includes('KYCExpired') || reason.includes('expired')) {
167
+ code = ErrorCode.KYC_EXPIRED;
168
+ }
169
+ else if (reason.includes('TransferRestricted') || reason.includes('restricted')) {
170
+ code = ErrorCode.TRANSFER_RESTRICTED;
171
+ }
172
+ else if (reason.includes('Paused') || reason.includes('paused')) {
173
+ code = ErrorCode.TOKENS_PAUSED;
174
+ }
175
+ else if (reason.includes('AccessControl') || reason.includes('unauthorized') || reason.includes('Ownable')) {
176
+ code = ErrorCode.UNAUTHORIZED;
177
+ }
178
+ else if (reason.includes('insufficient') || reason.includes('balance')) {
179
+ code = ErrorCode.INSUFFICIENT_BALANCE;
180
+ }
181
+ else if (reason.includes('ClaimWindowExpired')) {
182
+ code = ErrorCode.CLAIM_WINDOW_EXPIRED;
183
+ }
184
+ else if (reason.includes('AlreadyClaimed')) {
185
+ code = ErrorCode.ALREADY_CLAIMED;
186
+ }
187
+ else if (reason.includes('ReentrancyGuard')) {
188
+ code = ErrorCode.REENTRANCY;
189
+ }
190
+ return new ContractError(code, `Contract call failed: ${reason}`, contractAddress, functionName, reason, { originalError: errorObj.message });
191
+ }
192
+ /**
193
+ * Parse a network error and return the appropriate error
194
+ */
195
+ function parseNetworkError(error, chainId, rpcUrl) {
196
+ const errorObj = error;
197
+ const message = errorObj.message || 'Unknown network error';
198
+ let code = ErrorCode.RPC_ERROR;
199
+ let retryable = true;
200
+ if (message.includes('nonce') && message.includes('low')) {
201
+ code = ErrorCode.NONCE_TOO_LOW;
202
+ retryable = true;
203
+ }
204
+ else if (message.includes('timeout') || message.includes('ETIMEDOUT')) {
205
+ code = ErrorCode.TIMEOUT;
206
+ retryable = true;
207
+ }
208
+ else if (message.includes('insufficient funds')) {
209
+ code = ErrorCode.INSUFFICIENT_FUNDS;
210
+ retryable = false;
211
+ }
212
+ else if (message.includes('gas')) {
213
+ code = ErrorCode.GAS_ESTIMATION_FAILED;
214
+ retryable = false;
215
+ }
216
+ return new NetworkError(code, `Network error: ${message}`, retryable, chainId, rpcUrl, { originalError: message });
217
+ }
218
+ //# sourceMappingURL=index.js.map