@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.
- package/dist/cjs/client.js +198 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/constants/index.js +211 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/errors/index.js +218 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/index.js +51 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules/compliance.js +202 -0
- package/dist/cjs/modules/compliance.js.map +1 -0
- package/dist/cjs/modules/index.js +18 -0
- package/dist/cjs/modules/index.js.map +1 -0
- package/dist/cjs/modules/kyc.js +278 -0
- package/dist/cjs/modules/kyc.js.map +1 -0
- package/dist/cjs/modules/token.js +365 -0
- package/dist/cjs/modules/token.js.map +1 -0
- package/dist/cjs/modules/yield.js +406 -0
- package/dist/cjs/modules/yield.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/index.js +20 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/index.js +206 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/esm/client.js +194 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/constants/index.js +208 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/errors/index.js +209 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules/compliance.js +198 -0
- package/dist/esm/modules/compliance.js.map +1 -0
- package/dist/esm/modules/index.js +8 -0
- package/dist/esm/modules/index.js.map +1 -0
- package/dist/esm/modules/kyc.js +273 -0
- package/dist/esm/modules/kyc.js.map +1 -0
- package/dist/esm/modules/token.js +360 -0
- package/dist/esm/modules/token.js.map +1 -0
- package/dist/esm/modules/yield.js +401 -0
- package/dist/esm/modules/yield.js.map +1 -0
- package/dist/esm/types/index.js +17 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/index.js +188 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/types/client.d.ts +93 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/constants/index.d.ts +83 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +83 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/compliance.d.ts +29 -0
- package/dist/types/modules/compliance.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +8 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/modules/kyc.d.ts +131 -0
- package/dist/types/modules/kyc.d.ts.map +1 -0
- package/dist/types/modules/token.d.ts +145 -0
- package/dist/types/modules/token.d.ts.map +1 -0
- package/dist/types/modules/yield.d.ts +143 -0
- package/dist/types/modules/yield.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +254 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +80 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +52 -0
- package/src/client.ts +258 -0
- package/src/constants/index.ts +226 -0
- package/src/errors/index.ts +291 -0
- package/src/index.ts +42 -0
- package/src/modules/compliance.ts +252 -0
- package/src/modules/index.ts +8 -0
- package/src/modules/kyc.ts +446 -0
- package/src/modules/token.ts +488 -0
- package/src/modules/yield.ts +566 -0
- package/src/types/index.ts +326 -0
- package/src/utils/index.ts +240 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* YieldModule - Handles yield distribution management
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.YieldModule = exports.YieldDistributorInstance = void 0;
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
/**
|
|
12
|
+
* Instance of a connected yield distributor
|
|
13
|
+
*/
|
|
14
|
+
class YieldDistributorInstance {
|
|
15
|
+
_contract;
|
|
16
|
+
_retries;
|
|
17
|
+
_retryDelay;
|
|
18
|
+
/** Distributor contract address */
|
|
19
|
+
address;
|
|
20
|
+
constructor(address, provider, signer, retries, retryDelay) {
|
|
21
|
+
this.address = (0, utils_1.normalizeAddress)(address);
|
|
22
|
+
this._retries = retries;
|
|
23
|
+
this._retryDelay = retryDelay;
|
|
24
|
+
this._contract = new ethers_1.ethers.Contract(this.address, constants_1.YIELD_DISTRIBUTOR_ABI, signer || provider);
|
|
25
|
+
}
|
|
26
|
+
/*//////////////////////////////////////////////////////////////
|
|
27
|
+
READ FUNCTIONS
|
|
28
|
+
//////////////////////////////////////////////////////////////*/
|
|
29
|
+
/**
|
|
30
|
+
* Get the number of distributions
|
|
31
|
+
*/
|
|
32
|
+
async distributionCount() {
|
|
33
|
+
const count = await this._contract.distributionCount();
|
|
34
|
+
return Number(count);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get distribution information
|
|
38
|
+
*/
|
|
39
|
+
async getDistributionInfo(distributionId) {
|
|
40
|
+
const [paymentToken, totalAmount, snapshotId, claimDeadline, claimedAmount] = await this._contract.getDistributionInfo(distributionId);
|
|
41
|
+
return {
|
|
42
|
+
id: distributionId,
|
|
43
|
+
paymentToken,
|
|
44
|
+
totalAmount,
|
|
45
|
+
snapshotId,
|
|
46
|
+
claimDeadline: (0, utils_1.timestampToDate)(claimDeadline),
|
|
47
|
+
claimedAmount,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get claimable amount for an account
|
|
52
|
+
*/
|
|
53
|
+
async getClaimableAmount(distributionId, account) {
|
|
54
|
+
return this._contract.getClaimableAmount(distributionId, (0, utils_1.normalizeAddress)(account));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if an account has claimed from a distribution
|
|
58
|
+
*/
|
|
59
|
+
async hasClaimed(distributionId, account) {
|
|
60
|
+
return this._contract.hasClaimed(distributionId, (0, utils_1.normalizeAddress)(account));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get all distributions
|
|
64
|
+
*/
|
|
65
|
+
async getDistributionHistory() {
|
|
66
|
+
const count = await this.distributionCount();
|
|
67
|
+
const distributions = [];
|
|
68
|
+
for (let i = 0; i < count; i++) {
|
|
69
|
+
distributions.push(await this.getDistributionInfo(i));
|
|
70
|
+
}
|
|
71
|
+
return distributions;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get pending claims for an account
|
|
75
|
+
*/
|
|
76
|
+
async getPendingClaims(account) {
|
|
77
|
+
const count = await this.distributionCount();
|
|
78
|
+
const pendingClaims = [];
|
|
79
|
+
const now = new Date();
|
|
80
|
+
for (let i = 0; i < count; i++) {
|
|
81
|
+
const hasClaimed = await this.hasClaimed(i, account);
|
|
82
|
+
if (hasClaimed)
|
|
83
|
+
continue;
|
|
84
|
+
const distribution = await this.getDistributionInfo(i);
|
|
85
|
+
if (distribution.claimDeadline < now)
|
|
86
|
+
continue;
|
|
87
|
+
const amount = await this.getClaimableAmount(i, account);
|
|
88
|
+
if (amount === 0n)
|
|
89
|
+
continue;
|
|
90
|
+
pendingClaims.push({
|
|
91
|
+
distributionId: i,
|
|
92
|
+
amount,
|
|
93
|
+
paymentToken: distribution.paymentToken,
|
|
94
|
+
deadline: distribution.claimDeadline,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return pendingClaims;
|
|
98
|
+
}
|
|
99
|
+
/*//////////////////////////////////////////////////////////////
|
|
100
|
+
WRITE FUNCTIONS
|
|
101
|
+
//////////////////////////////////////////////////////////////*/
|
|
102
|
+
/**
|
|
103
|
+
* Create a new distribution
|
|
104
|
+
*/
|
|
105
|
+
async createDistribution(paymentToken, totalAmount, claimWindowDays = constants_1.DEFAULTS.YIELD_CLAIM_WINDOW_DAYS, options) {
|
|
106
|
+
const tokenAddress = (0, utils_1.normalizeAddress)(paymentToken);
|
|
107
|
+
const amountWei = (0, utils_1.parseAmount)(totalAmount);
|
|
108
|
+
try {
|
|
109
|
+
const tx = await (0, utils_1.retry)(async () => {
|
|
110
|
+
const gasLimit = options?.gasLimit || await (0, utils_1.estimateGasWithBuffer)(() => this._contract.createDistribution.estimateGas(tokenAddress, amountWei, claimWindowDays));
|
|
111
|
+
return this._contract.createDistribution(tokenAddress, amountWei, claimWindowDays, { gasLimit });
|
|
112
|
+
}, { retries: options?.retries ?? this._retries, delay: options?.retryDelay ?? this._retryDelay });
|
|
113
|
+
const receipt = await tx.wait();
|
|
114
|
+
const events = (0, utils_1.parseEvents)(receipt, this._contract.interface);
|
|
115
|
+
const result = (0, utils_1.createTransactionResult)(receipt, events);
|
|
116
|
+
// Extract distribution ID from event
|
|
117
|
+
const createdEvent = events.find((e) => e.name === 'DistributionCreated');
|
|
118
|
+
const distributionId = Number(createdEvent?.args.distributionId || 0);
|
|
119
|
+
return { result, distributionId };
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw (0, errors_1.parseContractError)(error, this.address, 'createDistribution');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Claim yield from a distribution
|
|
127
|
+
*/
|
|
128
|
+
async claim(distributionId, options) {
|
|
129
|
+
try {
|
|
130
|
+
const tx = await (0, utils_1.retry)(async () => {
|
|
131
|
+
const gasLimit = options?.gasLimit || await (0, utils_1.estimateGasWithBuffer)(() => this._contract.claim.estimateGas(distributionId));
|
|
132
|
+
return this._contract.claim(distributionId, { gasLimit });
|
|
133
|
+
}, { retries: options?.retries ?? this._retries, delay: options?.retryDelay ?? this._retryDelay });
|
|
134
|
+
const receipt = await tx.wait();
|
|
135
|
+
const events = (0, utils_1.parseEvents)(receipt, this._contract.interface);
|
|
136
|
+
return (0, utils_1.createTransactionResult)(receipt, events);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
throw (0, errors_1.parseContractError)(error, this.address, 'claim');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Claim yield from multiple distributions
|
|
144
|
+
*/
|
|
145
|
+
async claimMultiple(distributionIds, options) {
|
|
146
|
+
try {
|
|
147
|
+
const tx = await (0, utils_1.retry)(async () => {
|
|
148
|
+
const gasLimit = options?.gasLimit || await (0, utils_1.estimateGasWithBuffer)(() => this._contract.claimMultiple.estimateGas(distributionIds));
|
|
149
|
+
return this._contract.claimMultiple(distributionIds, { gasLimit });
|
|
150
|
+
}, { retries: options?.retries ?? this._retries, delay: options?.retryDelay ?? this._retryDelay });
|
|
151
|
+
const receipt = await tx.wait();
|
|
152
|
+
const events = (0, utils_1.parseEvents)(receipt, this._contract.interface);
|
|
153
|
+
return (0, utils_1.createTransactionResult)(receipt, events);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw (0, errors_1.parseContractError)(error, this.address, 'claimMultiple');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Handle unclaimed funds after claim window expires
|
|
161
|
+
*/
|
|
162
|
+
async handleUnclaimedFunds(distributionId, options) {
|
|
163
|
+
try {
|
|
164
|
+
const tx = await (0, utils_1.retry)(async () => {
|
|
165
|
+
const gasLimit = options?.gasLimit || await (0, utils_1.estimateGasWithBuffer)(() => this._contract.handleUnclaimedFunds.estimateGas(distributionId));
|
|
166
|
+
return this._contract.handleUnclaimedFunds(distributionId, { gasLimit });
|
|
167
|
+
}, { retries: options?.retries ?? this._retries, delay: options?.retryDelay ?? this._retryDelay });
|
|
168
|
+
const receipt = await tx.wait();
|
|
169
|
+
const events = (0, utils_1.parseEvents)(receipt, this._contract.interface);
|
|
170
|
+
return (0, utils_1.createTransactionResult)(receipt, events);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw (0, errors_1.parseContractError)(error, this.address, 'handleUnclaimedFunds');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Set the unclaimed funds recipient
|
|
178
|
+
*/
|
|
179
|
+
async setUnclaimedFundsRecipient(recipient, options) {
|
|
180
|
+
const recipientAddress = (0, utils_1.normalizeAddress)(recipient);
|
|
181
|
+
try {
|
|
182
|
+
const tx = await (0, utils_1.retry)(async () => {
|
|
183
|
+
const gasLimit = options?.gasLimit || await (0, utils_1.estimateGasWithBuffer)(() => this._contract.setUnclaimedFundsRecipient.estimateGas(recipientAddress));
|
|
184
|
+
return this._contract.setUnclaimedFundsRecipient(recipientAddress, { gasLimit });
|
|
185
|
+
}, { retries: options?.retries ?? this._retries, delay: options?.retryDelay ?? this._retryDelay });
|
|
186
|
+
const receipt = await tx.wait();
|
|
187
|
+
const events = (0, utils_1.parseEvents)(receipt, this._contract.interface);
|
|
188
|
+
return (0, utils_1.createTransactionResult)(receipt, events);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw (0, errors_1.parseContractError)(error, this.address, 'setUnclaimedFundsRecipient');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/*//////////////////////////////////////////////////////////////
|
|
195
|
+
EVENT LISTENERS
|
|
196
|
+
//////////////////////////////////////////////////////////////*/
|
|
197
|
+
/**
|
|
198
|
+
* Listen for DistributionCreated events
|
|
199
|
+
*/
|
|
200
|
+
onDistributionCreated(callback) {
|
|
201
|
+
const listener = (distributionId, paymentToken, totalAmount, snapshotId) => {
|
|
202
|
+
callback(distributionId, paymentToken, totalAmount, snapshotId);
|
|
203
|
+
};
|
|
204
|
+
this._contract.on('DistributionCreated', listener);
|
|
205
|
+
return () => this._contract.off('DistributionCreated', listener);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Listen for YieldClaimed events
|
|
209
|
+
*/
|
|
210
|
+
onYieldClaimed(callback) {
|
|
211
|
+
const listener = (distributionId, claimant, amount) => {
|
|
212
|
+
callback(distributionId, claimant, amount);
|
|
213
|
+
};
|
|
214
|
+
this._contract.on('YieldClaimed', listener);
|
|
215
|
+
return () => this._contract.off('YieldClaimed', listener);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.YieldDistributorInstance = YieldDistributorInstance;
|
|
219
|
+
/**
|
|
220
|
+
* Module for yield distribution operations
|
|
221
|
+
*/
|
|
222
|
+
class YieldModule {
|
|
223
|
+
_provider;
|
|
224
|
+
_signer;
|
|
225
|
+
_retries;
|
|
226
|
+
_retryDelay;
|
|
227
|
+
constructor(provider, signer, retries, retryDelay) {
|
|
228
|
+
this._provider = provider;
|
|
229
|
+
this._signer = signer;
|
|
230
|
+
this._retries = retries;
|
|
231
|
+
this._retryDelay = retryDelay;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Connect to an existing yield distributor
|
|
235
|
+
*/
|
|
236
|
+
connect(address) {
|
|
237
|
+
if (!(0, utils_1.isValidAddress)(address)) {
|
|
238
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid distributor address: ${address}`);
|
|
239
|
+
}
|
|
240
|
+
return new YieldDistributorInstance(address, this._provider, this._signer, this._retries, this._retryDelay);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a distribution
|
|
244
|
+
*
|
|
245
|
+
* @param config - Distribution configuration
|
|
246
|
+
* @returns Transaction result with distribution ID
|
|
247
|
+
*/
|
|
248
|
+
async distribute(config) {
|
|
249
|
+
if (!(0, utils_1.isValidAddress)(config.tokenAddress)) {
|
|
250
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid token address: ${config.tokenAddress}`);
|
|
251
|
+
}
|
|
252
|
+
if (!(0, utils_1.isValidAddress)(config.paymentToken)) {
|
|
253
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid payment token address: ${config.paymentToken}`);
|
|
254
|
+
}
|
|
255
|
+
const distributor = this.connect(config.tokenAddress);
|
|
256
|
+
return distributor.createDistribution(config.paymentToken, config.totalAmount, config.claimWindowDays);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Preview a distribution (calculate per-holder amounts)
|
|
260
|
+
*
|
|
261
|
+
* This method calculates what each holder would receive based on their
|
|
262
|
+
* proportional ownership at the snapshot time.
|
|
263
|
+
*
|
|
264
|
+
* @param tokenAddress - The RWA token address
|
|
265
|
+
* @param totalAmount - Total amount to distribute (in token units)
|
|
266
|
+
* @param snapshotId - Optional snapshot ID (uses current balances if not provided)
|
|
267
|
+
* @param holderAddresses - Optional array of holder addresses to calculate for
|
|
268
|
+
* @returns Preview of the distribution with per-holder breakdown
|
|
269
|
+
*/
|
|
270
|
+
async previewDistribution(tokenAddress, totalAmount, snapshotId, holderAddresses) {
|
|
271
|
+
if (!(0, utils_1.isValidAddress)(tokenAddress)) {
|
|
272
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid token address: ${tokenAddress}`);
|
|
273
|
+
}
|
|
274
|
+
const token = new ethers_1.ethers.Contract(tokenAddress, constants_1.RWA_TOKEN_ABI, this._provider);
|
|
275
|
+
const totalAmountWei = (0, utils_1.parseAmount)(totalAmount);
|
|
276
|
+
// Get total supply at snapshot
|
|
277
|
+
let totalSupply;
|
|
278
|
+
if (snapshotId !== undefined) {
|
|
279
|
+
totalSupply = await token.totalSupplyAt(snapshotId);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
totalSupply = await token.totalSupply();
|
|
283
|
+
}
|
|
284
|
+
if (totalSupply === 0n) {
|
|
285
|
+
return {
|
|
286
|
+
totalHolders: 0,
|
|
287
|
+
totalSupplyAtSnapshot: 0n,
|
|
288
|
+
distributions: [],
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
// If holder addresses are provided, calculate their distributions
|
|
292
|
+
const distributions = [];
|
|
293
|
+
if (holderAddresses && holderAddresses.length > 0) {
|
|
294
|
+
for (const address of holderAddresses) {
|
|
295
|
+
const normalizedAddress = (0, utils_1.normalizeAddress)(address);
|
|
296
|
+
let balance;
|
|
297
|
+
if (snapshotId !== undefined) {
|
|
298
|
+
balance = await token.balanceOfAt(normalizedAddress, snapshotId);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
balance = await token.balanceOf(normalizedAddress);
|
|
302
|
+
}
|
|
303
|
+
if (balance > 0n) {
|
|
304
|
+
// Calculate proportional yield amount
|
|
305
|
+
const yieldAmount = (totalAmountWei * balance) / totalSupply;
|
|
306
|
+
const percentage = Number((balance * 10000n) / totalSupply) / 100;
|
|
307
|
+
distributions.push({
|
|
308
|
+
address: normalizedAddress,
|
|
309
|
+
balance,
|
|
310
|
+
yieldAmount,
|
|
311
|
+
percentage,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
totalHolders: distributions.length,
|
|
318
|
+
totalSupplyAtSnapshot: totalSupply,
|
|
319
|
+
distributions,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Calculate yield amount for a specific holder
|
|
324
|
+
*
|
|
325
|
+
* @param tokenAddress - The RWA token address
|
|
326
|
+
* @param holderAddress - The holder's address
|
|
327
|
+
* @param totalAmount - Total distribution amount
|
|
328
|
+
* @param snapshotId - Optional snapshot ID
|
|
329
|
+
* @returns The calculated yield amount for the holder
|
|
330
|
+
*/
|
|
331
|
+
async calculateHolderYield(tokenAddress, holderAddress, totalAmount, snapshotId) {
|
|
332
|
+
if (!(0, utils_1.isValidAddress)(tokenAddress)) {
|
|
333
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid token address: ${tokenAddress}`);
|
|
334
|
+
}
|
|
335
|
+
if (!(0, utils_1.isValidAddress)(holderAddress)) {
|
|
336
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_ADDRESS, `Invalid holder address: ${holderAddress}`);
|
|
337
|
+
}
|
|
338
|
+
const token = new ethers_1.ethers.Contract(tokenAddress, constants_1.RWA_TOKEN_ABI, this._provider);
|
|
339
|
+
const totalAmountWei = (0, utils_1.parseAmount)(totalAmount);
|
|
340
|
+
const normalizedHolder = (0, utils_1.normalizeAddress)(holderAddress);
|
|
341
|
+
// Get total supply and holder balance
|
|
342
|
+
let totalSupply;
|
|
343
|
+
let balance;
|
|
344
|
+
if (snapshotId !== undefined) {
|
|
345
|
+
totalSupply = await token.totalSupplyAt(snapshotId);
|
|
346
|
+
balance = await token.balanceOfAt(normalizedHolder, snapshotId);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
totalSupply = await token.totalSupply();
|
|
350
|
+
balance = await token.balanceOf(normalizedHolder);
|
|
351
|
+
}
|
|
352
|
+
if (totalSupply === 0n || balance === 0n) {
|
|
353
|
+
return { balance: 0n, yieldAmount: 0n, percentage: 0 };
|
|
354
|
+
}
|
|
355
|
+
// Calculate proportional yield amount
|
|
356
|
+
const yieldAmount = (totalAmountWei * balance) / totalSupply;
|
|
357
|
+
const percentage = Number((balance * 10000n) / totalSupply) / 100;
|
|
358
|
+
return { balance, yieldAmount, percentage };
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Claim yield from a distribution
|
|
362
|
+
*/
|
|
363
|
+
async claim(distributorAddress, distributionId) {
|
|
364
|
+
const distributor = this.connect(distributorAddress);
|
|
365
|
+
return distributor.claim(distributionId);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Claim all pending yields
|
|
369
|
+
*/
|
|
370
|
+
async claimAll(distributorAddress) {
|
|
371
|
+
if (!this._signer) {
|
|
372
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.SIGNER_REQUIRED, 'A signer is required to claim yields');
|
|
373
|
+
}
|
|
374
|
+
const distributor = this.connect(distributorAddress);
|
|
375
|
+
const signerAddress = await this._signer.getAddress();
|
|
376
|
+
const pendingClaims = await distributor.getPendingClaims(signerAddress);
|
|
377
|
+
if (pendingClaims.length === 0) {
|
|
378
|
+
throw new errors_1.RWAError(errors_1.ErrorCode.INVALID_CONFIGURATION, 'No pending claims to process');
|
|
379
|
+
}
|
|
380
|
+
const distributionIds = pendingClaims.map((c) => c.distributionId);
|
|
381
|
+
return distributor.claimMultiple(distributionIds);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Get claimable amount for an account
|
|
385
|
+
*/
|
|
386
|
+
async getClaimableAmount(distributorAddress, distributionId, account) {
|
|
387
|
+
const distributor = this.connect(distributorAddress);
|
|
388
|
+
return distributor.getClaimableAmount(distributionId, account);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Get distribution history
|
|
392
|
+
*/
|
|
393
|
+
async getDistributionHistory(distributorAddress) {
|
|
394
|
+
const distributor = this.connect(distributorAddress);
|
|
395
|
+
return distributor.getDistributionHistory();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Get pending claims for an account
|
|
399
|
+
*/
|
|
400
|
+
async getPendingClaims(distributorAddress, account) {
|
|
401
|
+
const distributor = this.connect(distributorAddress);
|
|
402
|
+
return distributor.getPendingClaims(account);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.YieldModule = YieldModule;
|
|
406
|
+
//# sourceMappingURL=yield.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yield.js","sourceRoot":"","sources":["../../../src/modules/yield.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mCAA4D;AAU5D,4CAA8E;AAC9E,sCAAoE;AACpE,oCASkB;AAElB;;GAEG;AACH,MAAa,wBAAwB;IAChB,SAAS,CAAkB;IAC3B,QAAQ,CAAS;IACjB,WAAW,CAAS;IAErC,mCAAmC;IAC1B,OAAO,CAAS;IAEzB,YACI,OAAe,EACf,QAAkB,EAClB,MAAqB,EACrB,OAAe,EACf,UAAkB;QAElB,IAAI,CAAC,O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|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core type definitions for the Mantle RWA SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AccreditationTier = void 0;
|
|
7
|
+
/*//////////////////////////////////////////////////////////////
|
|
8
|
+
ACCREDITATION TYPES
|
|
9
|
+
//////////////////////////////////////////////////////////////*/
|
|
10
|
+
/**
|
|
11
|
+
* Accreditation tiers matching the smart contract enum
|
|
12
|
+
*/
|
|
13
|
+
var AccreditationTier;
|
|
14
|
+
(function (AccreditationTier) {
|
|
15
|
+
AccreditationTier[AccreditationTier["None"] = 0] = "None";
|
|
16
|
+
AccreditationTier[AccreditationTier["Retail"] = 1] = "Retail";
|
|
17
|
+
AccreditationTier[AccreditationTier["Accredited"] = 2] = "Accredited";
|
|
18
|
+
AccreditationTier[AccreditationTier["Institutional"] = 3] = "Institutional";
|
|
19
|
+
})(AccreditationTier || (exports.AccreditationTier = AccreditationTier = {}));
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAoCH;;gEAEgE;AAEhE;;GAEG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,yDAAQ,CAAA;IACR,6DAAU,CAAA;IACV,qEAAc,CAAA;IACd,2EAAiB,CAAA;AACnB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for the Mantle RWA SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidAddress = isValidAddress;
|
|
7
|
+
exports.normalizeAddress = normalizeAddress;
|
|
8
|
+
exports.parseAmount = parseAmount;
|
|
9
|
+
exports.formatAmount = formatAmount;
|
|
10
|
+
exports.parseEvents = parseEvents;
|
|
11
|
+
exports.createTransactionResult = createTransactionResult;
|
|
12
|
+
exports.sleep = sleep;
|
|
13
|
+
exports.retry = retry;
|
|
14
|
+
exports.estimateGasWithBuffer = estimateGasWithBuffer;
|
|
15
|
+
exports.hashIdentityData = hashIdentityData;
|
|
16
|
+
exports.timestampToDate = timestampToDate;
|
|
17
|
+
exports.dateToTimestamp = dateToTimestamp;
|
|
18
|
+
exports.isExpired = isExpired;
|
|
19
|
+
exports.calculatePercentage = calculatePercentage;
|
|
20
|
+
exports.chunk = chunk;
|
|
21
|
+
exports.waitForTransaction = waitForTransaction;
|
|
22
|
+
const ethers_1 = require("ethers");
|
|
23
|
+
const errors_1 = require("../errors");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
25
|
+
/**
|
|
26
|
+
* Validate an Ethereum address
|
|
27
|
+
*/
|
|
28
|
+
function isValidAddress(address) {
|
|
29
|
+
try {
|
|
30
|
+
return ethers_1.ethers.isAddress(address);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate and normalize an Ethereum address
|
|
38
|
+
*/
|
|
39
|
+
function normalizeAddress(address) {
|
|
40
|
+
if (!isValidAddress(address)) {
|
|
41
|
+
throw new Error(`Invalid address: ${address}`);
|
|
42
|
+
}
|
|
43
|
+
return ethers_1.ethers.getAddress(address);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse a string amount to bigint with decimals
|
|
47
|
+
*/
|
|
48
|
+
function parseAmount(amount, decimals = 18) {
|
|
49
|
+
return ethers_1.ethers.parseUnits(amount, decimals);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Format a bigint amount to string with decimals
|
|
53
|
+
*/
|
|
54
|
+
function formatAmount(amount, decimals = 18) {
|
|
55
|
+
return ethers_1.ethers.formatUnits(amount, decimals);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse events from a transaction receipt
|
|
59
|
+
*/
|
|
60
|
+
function parseEvents(receipt, contractInterface) {
|
|
61
|
+
const events = [];
|
|
62
|
+
for (const log of receipt.logs) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = contractInterface.parseLog({
|
|
65
|
+
topics: log.topics,
|
|
66
|
+
data: log.data,
|
|
67
|
+
});
|
|
68
|
+
if (parsed) {
|
|
69
|
+
const args = {};
|
|
70
|
+
for (const [key, value] of Object.entries(parsed.args)) {
|
|
71
|
+
// Skip numeric indices
|
|
72
|
+
if (!/^\d+$/.test(key)) {
|
|
73
|
+
args[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
events.push({
|
|
77
|
+
name: parsed.name,
|
|
78
|
+
args,
|
|
79
|
+
address: log.address,
|
|
80
|
+
blockNumber: log.blockNumber,
|
|
81
|
+
transactionHash: log.transactionHash,
|
|
82
|
+
logIndex: log.index,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Skip logs that don't match the interface
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return events;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a transaction result from a receipt
|
|
94
|
+
*/
|
|
95
|
+
function createTransactionResult(receipt, events) {
|
|
96
|
+
return {
|
|
97
|
+
hash: receipt.hash,
|
|
98
|
+
blockNumber: receipt.blockNumber,
|
|
99
|
+
gasUsed: receipt.gasUsed,
|
|
100
|
+
status: receipt.status === 1 ? 'success' : 'failed',
|
|
101
|
+
events,
|
|
102
|
+
receipt,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sleep for a specified duration
|
|
107
|
+
*/
|
|
108
|
+
function sleep(ms) {
|
|
109
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Retry a function with exponential backoff
|
|
113
|
+
*/
|
|
114
|
+
async function retry(fn, options = {}) {
|
|
115
|
+
const { retries = constants_1.DEFAULTS.TRANSACTION_RETRIES, delay = constants_1.DEFAULTS.RETRY_DELAY_MS, onRetry } = options;
|
|
116
|
+
let lastError;
|
|
117
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
118
|
+
try {
|
|
119
|
+
return await fn();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
lastError = error;
|
|
123
|
+
// Check if error is retryable
|
|
124
|
+
const networkError = (0, errors_1.parseNetworkError)(error);
|
|
125
|
+
if (!networkError.retryable) {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
if (attempt < retries) {
|
|
129
|
+
onRetry?.(error, attempt + 1);
|
|
130
|
+
await sleep(delay * Math.pow(2, attempt)); // Exponential backoff
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw lastError;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Estimate gas with buffer
|
|
138
|
+
*/
|
|
139
|
+
async function estimateGasWithBuffer(estimateFn, bufferPercent = constants_1.DEFAULTS.GAS_BUFFER_PERCENT) {
|
|
140
|
+
const estimate = await estimateFn();
|
|
141
|
+
const buffer = (estimate * BigInt(bufferPercent)) / 100n;
|
|
142
|
+
return estimate + buffer;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Generate a keccak256 hash of identity data
|
|
146
|
+
*/
|
|
147
|
+
function hashIdentityData(data) {
|
|
148
|
+
const normalized = JSON.stringify({
|
|
149
|
+
firstName: data.firstName?.toLowerCase().trim(),
|
|
150
|
+
lastName: data.lastName?.toLowerCase().trim(),
|
|
151
|
+
dateOfBirth: data.dateOfBirth,
|
|
152
|
+
documentNumber: data.documentNumber?.toUpperCase().trim(),
|
|
153
|
+
country: data.country?.toUpperCase().trim(),
|
|
154
|
+
});
|
|
155
|
+
return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(normalized));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Convert a timestamp to a Date object
|
|
159
|
+
*/
|
|
160
|
+
function timestampToDate(timestamp) {
|
|
161
|
+
const ts = typeof timestamp === 'bigint' ? Number(timestamp) : timestamp;
|
|
162
|
+
return new Date(ts * 1000);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Convert a Date to a Unix timestamp
|
|
166
|
+
*/
|
|
167
|
+
function dateToTimestamp(date) {
|
|
168
|
+
return Math.floor(date.getTime() / 1000);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Check if a timestamp is expired
|
|
172
|
+
*/
|
|
173
|
+
function isExpired(timestamp) {
|
|
174
|
+
const now = Math.floor(Date.now() / 1000);
|
|
175
|
+
const ts = typeof timestamp === 'bigint' ? Number(timestamp) : timestamp;
|
|
176
|
+
return ts < now;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Calculate percentage
|
|
180
|
+
*/
|
|
181
|
+
function calculatePercentage(part, total) {
|
|
182
|
+
if (total === 0n)
|
|
183
|
+
return 0;
|
|
184
|
+
return Number((part * 10000n) / total) / 100;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Chunk an array into smaller arrays
|
|
188
|
+
*/
|
|
189
|
+
function chunk(array, size) {
|
|
190
|
+
const chunks = [];
|
|
191
|
+
for (let i = 0; i < array.length; i += size) {
|
|
192
|
+
chunks.push(array.slice(i, i + size));
|
|
193
|
+
}
|
|
194
|
+
return chunks;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Wait for a transaction to be mined
|
|
198
|
+
*/
|
|
199
|
+
async function waitForTransaction(provider, hash, confirmations = 1) {
|
|
200
|
+
const receipt = await provider.waitForTransaction(hash, confirmations);
|
|
201
|
+
if (!receipt) {
|
|
202
|
+
throw new errors_1.NetworkError(errors_1.ErrorCode.TIMEOUT, `Transaction ${hash} was not mined`, true);
|
|
203
|
+
}
|
|
204
|
+
return receipt;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=index.js.map
|