@wuwei-labs/srsly 2.0.0-beta.24 → 2.0.0-beta.25
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/README.md +123 -21
- package/dist/cjs/codama/errors/srsly.js +7 -1
- package/dist/cjs/codama/errors/srsly.js.map +1 -1
- package/dist/cjs/contract/create.js +13 -2
- package/dist/cjs/contract/create.js.map +1 -1
- package/dist/cjs/index.js +25 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/types/paymentFrequency.js +58 -0
- package/dist/cjs/types/paymentFrequency.js.map +1 -0
- package/dist/cjs/utils/constants.js +3 -20
- package/dist/cjs/utils/constants.js.map +1 -1
- package/dist/cjs/utils/duration.js +77 -0
- package/dist/cjs/utils/duration.js.map +1 -0
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/paymentFrequency.js +60 -0
- package/dist/cjs/utils/paymentFrequency.js.map +1 -0
- package/dist/esm/codama/errors/srsly.js +6 -0
- package/dist/esm/codama/errors/srsly.js.map +1 -1
- package/dist/esm/contract/create.js +13 -2
- package/dist/esm/contract/create.js.map +1 -1
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/types/paymentFrequency.js +53 -0
- package/dist/esm/types/paymentFrequency.js.map +1 -0
- package/dist/esm/utils/constants.js +2 -18
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/duration.js +68 -0
- package/dist/esm/utils/duration.js.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/paymentFrequency.js +55 -0
- package/dist/esm/utils/paymentFrequency.js.map +1 -0
- package/dist/types/codama/errors/srsly.d.ts +5 -1
- package/dist/types/codama/errors/srsly.d.ts.map +1 -1
- package/dist/types/contract/create.d.ts +7 -5
- package/dist/types/contract/create.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/paymentFrequency.d.ts +44 -0
- package/dist/types/types/paymentFrequency.d.ts.map +1 -0
- package/dist/types/utils/constants.d.ts +0 -13
- package/dist/types/utils/constants.d.ts.map +1 -1
- package/dist/types/utils/duration.d.ts +56 -0
- package/dist/types/utils/duration.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/paymentFrequency.d.ts +18 -0
- package/dist/types/utils/paymentFrequency.d.ts.map +1 -0
- package/package.json +1 -1
- package/target/idl/srsly.json +10 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ yarn add @wuwei-labs/srsly
|
|
|
34
34
|
### Option 1: Pack and Send (Server/CLI)
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
|
-
import { createContract, setConfig } from '@wuwei-labs/srsly';
|
|
37
|
+
import { createContract, setConfig, days, weeks } from '@wuwei-labs/srsly';
|
|
38
38
|
import { createKeyPairSignerFromBytes } from '@solana/kit';
|
|
39
39
|
|
|
40
40
|
// 1. Configure SDK with RPC endpoint
|
|
@@ -51,10 +51,9 @@ const signature = await createContract({
|
|
|
51
51
|
owner: signer,
|
|
52
52
|
fleet: fleetAddress,
|
|
53
53
|
ownerProfile: profileAddress,
|
|
54
|
-
rate: 1000000, // ATLAS tokens
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
paymentsFreq: 'daily'
|
|
54
|
+
rate: 1000000, // ATLAS tokens per payment period
|
|
55
|
+
durationMax: days(7), // 7 days using helper function
|
|
56
|
+
paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
|
|
58
57
|
}).pack(signer.address).send(signer); // Now chainable!
|
|
59
58
|
|
|
60
59
|
console.log('Transaction signature:', signature);
|
|
@@ -91,10 +90,9 @@ const packedTx = await createContract({
|
|
|
91
90
|
owner: walletPublicKey,
|
|
92
91
|
fleet: fleetAddress,
|
|
93
92
|
ownerProfile: profileAddress,
|
|
94
|
-
rate: 1000000, // ATLAS tokens
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
paymentsFreq: 'daily'
|
|
93
|
+
rate: 1000000, // ATLAS tokens per payment period
|
|
94
|
+
durationMax: days(7), // 7 days using helper function
|
|
95
|
+
paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
|
|
98
96
|
}).pack(walletPublicKey); // Pack with fee payer address
|
|
99
97
|
|
|
100
98
|
// 3. Sign and send with wallet adapter
|
|
@@ -159,8 +157,52 @@ const createIx = await createContract({
|
|
|
159
157
|
fleet: "123abc...", // string
|
|
160
158
|
ownerProfile: address("456def..."), // Address<string>
|
|
161
159
|
rate: 5000000,
|
|
162
|
-
durationMin: 86400,
|
|
163
160
|
durationMax: 2592000,
|
|
161
|
+
paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Duration Helper Functions
|
|
166
|
+
|
|
167
|
+
The SDK provides convenient helper functions for converting time units to seconds:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { days, weeks, months, hours, minutes, duration } from '@wuwei-labs/srsly';
|
|
171
|
+
|
|
172
|
+
// Individual helper functions
|
|
173
|
+
const sevenDays = days(7); // 604800 seconds
|
|
174
|
+
const twoWeeks = weeks(2); // 1209600 seconds
|
|
175
|
+
const oneMonth = months(1); // 2678400 seconds (31 days)
|
|
176
|
+
const sixHours = hours(6); // 21600 seconds
|
|
177
|
+
const thirtyMinutes = minutes(30); // 1800 seconds
|
|
178
|
+
|
|
179
|
+
// Using in contract creation
|
|
180
|
+
const contract = await createContract({
|
|
181
|
+
owner: wallet,
|
|
182
|
+
fleet: fleetAddress,
|
|
183
|
+
ownerProfile: profileAddress,
|
|
184
|
+
rate: 1000000,
|
|
185
|
+
durationMax: weeks(2), // 2 weeks maximum
|
|
186
|
+
paymentsFreq: 'daily' // Min automatically set to 1 day
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Alternative: use the duration object
|
|
190
|
+
const anotherContract = await createContract({
|
|
191
|
+
owner: wallet,
|
|
192
|
+
fleet: fleetAddress,
|
|
193
|
+
ownerProfile: profileAddress,
|
|
194
|
+
rate: 500000,
|
|
195
|
+
durationMax: duration.months(3), // 3 months maximum
|
|
196
|
+
paymentsFreq: 'weekly' // Min automatically set to 1 week
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// You can still use raw seconds if preferred
|
|
200
|
+
const rawContract = await createContract({
|
|
201
|
+
owner: wallet,
|
|
202
|
+
fleet: fleetAddress,
|
|
203
|
+
ownerProfile: profileAddress,
|
|
204
|
+
rate: 750000,
|
|
205
|
+
durationMax: 86400, // Raw 86400 seconds (1 day)
|
|
164
206
|
paymentsFreq: 'daily'
|
|
165
207
|
});
|
|
166
208
|
```
|
|
@@ -168,7 +210,7 @@ const createIx = await createContract({
|
|
|
168
210
|
### Contract Management
|
|
169
211
|
|
|
170
212
|
```typescript
|
|
171
|
-
import { createContract, closeContract } from '@wuwei-labs/srsly';
|
|
213
|
+
import { createContract, closeContract, days, months } from '@wuwei-labs/srsly';
|
|
172
214
|
|
|
173
215
|
// Create rental contract instruction
|
|
174
216
|
const createIx = await createContract({
|
|
@@ -176,9 +218,8 @@ const createIx = await createContract({
|
|
|
176
218
|
fleet: fleetAddress,
|
|
177
219
|
ownerProfile: profileAddress,
|
|
178
220
|
rate: 5000000,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
paymentsFreq: 'daily'
|
|
221
|
+
durationMax: months(1), // 30 days using helper function
|
|
222
|
+
paymentsFreq: 'daily' // Minimum duration automatically set to 1 day
|
|
182
223
|
});
|
|
183
224
|
|
|
184
225
|
// Close contract instruction
|
|
@@ -201,8 +242,8 @@ const acceptIx = await acceptRental({
|
|
|
201
242
|
borrowerFaction: 'mud', // or 1, 2, 3
|
|
202
243
|
fleet: fleetAddress,
|
|
203
244
|
contract: contractAddress,
|
|
204
|
-
rate: 100, // ATLAS per
|
|
205
|
-
duration: 86400 //
|
|
245
|
+
rate: 100, // ATLAS per payment period (based on contract's payment frequency)
|
|
246
|
+
duration: 86400 // Duration in seconds (must be between contract's min/max)
|
|
206
247
|
});
|
|
207
248
|
|
|
208
249
|
// Cancel active rental instruction
|
|
@@ -291,6 +332,55 @@ const ix2 = await acceptRental(params)
|
|
|
291
332
|
.set({ gameId: 'custom-game-id...', atlasMint: 'custom-mint...' });
|
|
292
333
|
```
|
|
293
334
|
|
|
335
|
+
## Duration and Payment Frequency
|
|
336
|
+
|
|
337
|
+
**Important**: All durations must be aligned with the payment frequency to ensure proper payment calculations.
|
|
338
|
+
|
|
339
|
+
### Duration Rules
|
|
340
|
+
|
|
341
|
+
1. **Duration Units**: All durations are specified in seconds
|
|
342
|
+
2. **Alignment Requirement**: Durations must be multiples of the payment frequency interval
|
|
343
|
+
3. **Validation**: The SDK automatically validates duration alignment and throws an error if invalid
|
|
344
|
+
|
|
345
|
+
### Payment Frequency Intervals
|
|
346
|
+
|
|
347
|
+
| Frequency | Interval | Example Valid Durations |
|
|
348
|
+
|-----------|----------|------------------------|
|
|
349
|
+
| `hourly` | 3,600 seconds (1 hour) | 3,600 (1h), 7,200 (2h), 86,400 (24h) |
|
|
350
|
+
| `daily` | 86,400 seconds (1 day) | 86,400 (1d), 172,800 (2d), 604,800 (7d) |
|
|
351
|
+
| `weekly` | 604,800 seconds (1 week) | 604,800 (1w), 1,209,600 (2w), 2,419,200 (4w) |
|
|
352
|
+
| `monthly` | 2,678,400 seconds (31 days) | 2,678,400 (1m), 5,356,800 (2m) |
|
|
353
|
+
|
|
354
|
+
### Examples
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
// ✅ Valid: 7 day max duration with daily payments
|
|
358
|
+
await createContract({
|
|
359
|
+
durationMax: 604800, // 7 days (604800 % 86400 = 0) ✓
|
|
360
|
+
paymentsFreq: 'daily' // Min duration automatically set to 1 day
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// ❌ Invalid: 3.5 day max duration with daily payments
|
|
364
|
+
await createContract({
|
|
365
|
+
durationMax: 302400, // 3.5 days (302400 % 86400 = 43200) ✗
|
|
366
|
+
paymentsFreq: 'daily'
|
|
367
|
+
});
|
|
368
|
+
// Error: Duration (302400 seconds) must be a multiple of daily frequency (86400 seconds)
|
|
369
|
+
|
|
370
|
+
// ✅ Valid: Hourly payments with hour-aligned max duration
|
|
371
|
+
await createContract({
|
|
372
|
+
durationMax: 172800, // 48 hours (172800 % 3600 = 0) ✓
|
|
373
|
+
paymentsFreq: 'hourly' // Min duration automatically set to 1 hour
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Rate Calculation
|
|
378
|
+
|
|
379
|
+
The `rate` parameter in contracts represents ATLAS tokens per payment period:
|
|
380
|
+
- For `daily` frequency: rate is ATLAS per day
|
|
381
|
+
- For `weekly` frequency: rate is ATLAS per week
|
|
382
|
+
- For `hourly` frequency: rate is ATLAS per hour
|
|
383
|
+
|
|
294
384
|
## Payment System
|
|
295
385
|
|
|
296
386
|
SRSLY implements an escrow-based payment system:
|
|
@@ -301,10 +391,12 @@ SRSLY implements an escrow-based payment system:
|
|
|
301
391
|
4. **Refunds**: Pro-rata refunds for early cancellation (24-hour minimum)
|
|
302
392
|
|
|
303
393
|
```typescript
|
|
304
|
-
// Payment calculation
|
|
305
|
-
const rate = 1000; // ATLAS per
|
|
306
|
-
const
|
|
307
|
-
const
|
|
394
|
+
// Payment calculation example
|
|
395
|
+
const rate = 1000; // ATLAS per payment period
|
|
396
|
+
const paymentFrequency = 'daily'; // Payment every 86400 seconds
|
|
397
|
+
const duration = days(7); // 7 days using helper function
|
|
398
|
+
const paymentPeriods = duration / days(1); // 7 periods
|
|
399
|
+
const totalAmount = rate * paymentPeriods * ATLAS_TO_STARDUST; // Total in stardust
|
|
308
400
|
```
|
|
309
401
|
|
|
310
402
|
## Program Sets Reference
|
|
@@ -338,7 +430,11 @@ import type {
|
|
|
338
430
|
import {
|
|
339
431
|
ATLAS_TO_STARDUST,
|
|
340
432
|
FACTION_MAPPING,
|
|
341
|
-
toAddress
|
|
433
|
+
toAddress,
|
|
434
|
+
days,
|
|
435
|
+
weeks,
|
|
436
|
+
months,
|
|
437
|
+
duration
|
|
342
438
|
} from '@wuwei-labs/srsly';
|
|
343
439
|
|
|
344
440
|
// Conversion rate: 1 ATLAS = 100,000,000 stardust
|
|
@@ -352,6 +448,12 @@ console.log(FACTION_MAPPING[3]); // 'ustur'
|
|
|
352
448
|
// Address conversion utility
|
|
353
449
|
const addressObj = toAddress("123abc..."); // converts string to Address<string>
|
|
354
450
|
console.log(addressObj); // Address<string>
|
|
451
|
+
|
|
452
|
+
// Duration helper functions
|
|
453
|
+
console.log(days(7)); // 604800 (7 days in seconds)
|
|
454
|
+
console.log(weeks(2)); // 1209600 (2 weeks in seconds)
|
|
455
|
+
console.log(months(1)); // 2678400 (1 month in seconds)
|
|
456
|
+
console.log(duration.hours(12)); // 43200 (12 hours in seconds)
|
|
355
457
|
```
|
|
356
458
|
|
|
357
459
|
## IDL and Program Information
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @see https://github.com/codama-idl/codama
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.SRSLY_ERROR__INVALID_OWNER_PROFILE = exports.SRSLY_ERROR__ACCOUNT_OWNED_BY_WRONG_PROGRAM = exports.SRSLY_ERROR__INVALID_ATLAS_CONVERSION_RATE = exports.SRSLY_ERROR__UNAUTHORIZED_CONFIG_UPDATE = exports.SRSLY_ERROR__INVALID_RENTAL_DURATION = exports.SRSLY_ERROR__INVALID_FEE_RATE = exports.SRSLY_ERROR__UNSUPPORTED_MIGRATION_VERSION = exports.SRSLY_ERROR__RENTAL_STATE_EXISTS = exports.SRSLY_ERROR__RENTAL_IS_ACTIVE = exports.SRSLY_ERROR__INVALID_THREAD_CONTEXT = exports.SRSLY_ERROR__EXPECTED_DAILY_FREQUENCY = exports.SRSLY_ERROR__DEV_ONLY_FREQUENCY = exports.SRSLY_ERROR__CONTRACT_CLOSED = exports.SRSLY_ERROR__INSUFFICIENT_CANCELLATION_NOTICE = exports.SRSLY_ERROR__INVALID_SUB_PROFILE_INVALIDATOR = exports.SRSLY_ERROR__INVALID_PAYMENT_FREQUENCY = exports.SRSLY_ERROR__INVALID_RATE = exports.SRSLY_ERROR__FLEET_ALREADY_RENTED = exports.SRSLY_ERROR__INVALID_RATE_CALCULATION = exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM = exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM = void 0;
|
|
10
|
+
exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM_ALIGNMENT = exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM_ALIGNMENT = exports.SRSLY_ERROR__INVALID_OWNER_PROFILE = exports.SRSLY_ERROR__ACCOUNT_OWNED_BY_WRONG_PROGRAM = exports.SRSLY_ERROR__INVALID_ATLAS_CONVERSION_RATE = exports.SRSLY_ERROR__UNAUTHORIZED_CONFIG_UPDATE = exports.SRSLY_ERROR__INVALID_RENTAL_DURATION = exports.SRSLY_ERROR__INVALID_FEE_RATE = exports.SRSLY_ERROR__UNSUPPORTED_MIGRATION_VERSION = exports.SRSLY_ERROR__RENTAL_STATE_EXISTS = exports.SRSLY_ERROR__RENTAL_IS_ACTIVE = exports.SRSLY_ERROR__INVALID_THREAD_CONTEXT = exports.SRSLY_ERROR__EXPECTED_DAILY_FREQUENCY = exports.SRSLY_ERROR__DEV_ONLY_FREQUENCY = exports.SRSLY_ERROR__CONTRACT_CLOSED = exports.SRSLY_ERROR__INSUFFICIENT_CANCELLATION_NOTICE = exports.SRSLY_ERROR__INVALID_SUB_PROFILE_INVALIDATOR = exports.SRSLY_ERROR__INVALID_PAYMENT_FREQUENCY = exports.SRSLY_ERROR__INVALID_RATE = exports.SRSLY_ERROR__FLEET_ALREADY_RENTED = exports.SRSLY_ERROR__INVALID_RATE_CALCULATION = exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM = exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM = void 0;
|
|
11
11
|
exports.getSrslyErrorMessage = getSrslyErrorMessage;
|
|
12
12
|
exports.isSrslyError = isSrslyError;
|
|
13
13
|
const kit_1 = require("@solana/kit");
|
|
@@ -54,6 +54,10 @@ exports.SRSLY_ERROR__INVALID_ATLAS_CONVERSION_RATE = 0x1782; // 6018
|
|
|
54
54
|
exports.SRSLY_ERROR__ACCOUNT_OWNED_BY_WRONG_PROGRAM = 0x1783; // 6019
|
|
55
55
|
/** InvalidOwnerProfile: Fleet owner profile does not match the provided owner profile. */
|
|
56
56
|
exports.SRSLY_ERROR__INVALID_OWNER_PROFILE = 0x1784; // 6020
|
|
57
|
+
/** InvalidDurationMinimumAlignment: Duration minimum must be a multiple of the payment frequency interval. */
|
|
58
|
+
exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM_ALIGNMENT = 0x1785; // 6021
|
|
59
|
+
/** InvalidDurationMaximumAlignment: Duration maximum must be a multiple of the payment frequency interval. */
|
|
60
|
+
exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM_ALIGNMENT = 0x1786; // 6022
|
|
57
61
|
let srslyErrorMessages;
|
|
58
62
|
if (process.env.NODE_ENV !== 'production') {
|
|
59
63
|
srslyErrorMessages = {
|
|
@@ -65,7 +69,9 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
65
69
|
[exports.SRSLY_ERROR__INSUFFICIENT_CANCELLATION_NOTICE]: `Rental time remaining is less than minimum cancellation notice required.`,
|
|
66
70
|
[exports.SRSLY_ERROR__INVALID_ATLAS_CONVERSION_RATE]: `Invalid ATLAS conversion rate. Must be greater than 0.`,
|
|
67
71
|
[exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM]: `Invalid duration maximum. Must be greater than or equal to the duration minimum.`,
|
|
72
|
+
[exports.SRSLY_ERROR__INVALID_DURATION_MAXIMUM_ALIGNMENT]: `Duration maximum must be a multiple of the payment frequency interval.`,
|
|
68
73
|
[exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM]: `Invalid duration minimum. Must be between 1 and the duration maximum.`,
|
|
74
|
+
[exports.SRSLY_ERROR__INVALID_DURATION_MINIMUM_ALIGNMENT]: `Duration minimum must be a multiple of the payment frequency interval.`,
|
|
69
75
|
[exports.SRSLY_ERROR__INVALID_FEE_RATE]: `Invalid fee rate. Service fee must be <= 50%, referral fee <= 100%, base_bps > 0.`,
|
|
70
76
|
[exports.SRSLY_ERROR__INVALID_OWNER_PROFILE]: `Fleet owner profile does not match the provided owner profile.`,
|
|
71
77
|
[exports.SRSLY_ERROR__INVALID_PAYMENT_FREQUENCY]: `Invalid payment frequency. Must be one of: @hourly, @daily, @weekly, @monthly.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"srsly.js","sourceRoot":"","sources":["../../../../src/codama/errors/srsly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;
|
|
1
|
+
{"version":3,"file":"srsly.js","sourceRoot":"","sources":["../../../../src/codama/errors/srsly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA+GH,oDAMC;AAED,oCAcC;AAnID,qCAKqB;AACrB,0CAAoD;AAEpD,oGAAoG;AACvF,QAAA,qCAAqC,GAAG,MAAM,CAAC,CAAC,OAAO;AACpE,+GAA+G;AAClG,QAAA,qCAAqC,GAAG,MAAM,CAAC,CAAC,OAAO;AACpE,mGAAmG;AACtF,QAAA,qCAAqC,GAAG,MAAM,CAAC,CAAC,OAAO;AACpE,8EAA8E;AACjE,QAAA,iCAAiC,GAAG,MAAM,CAAC,CAAC,OAAO;AAChE,4EAA4E;AAC/D,QAAA,yBAAyB,GAAG,MAAM,CAAC,CAAC,OAAO;AACxD,8GAA8G;AACjG,QAAA,sCAAsC,GAAG,MAAM,CAAC,CAAC,OAAO;AACrE,qEAAqE;AACxD,QAAA,4CAA4C,GAAG,M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B,KAAK,EACL,kBAAkB,EAClB,gCAAqB,EACrB,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -4,11 +4,22 @@ exports.createContract = createContract;
|
|
|
4
4
|
exports.getCreateContractInstructionAsync = getCreateContractInstructionAsync;
|
|
5
5
|
const config_1 = require("../utils/config");
|
|
6
6
|
const constants_1 = require("../utils/constants");
|
|
7
|
+
const paymentFrequency_1 = require("../utils/paymentFrequency");
|
|
8
|
+
const paymentFrequency_2 = require("../types/paymentFrequency");
|
|
7
9
|
/**
|
|
8
10
|
* Internal function to create a contract instruction with configuration options
|
|
9
11
|
*/
|
|
10
12
|
async function _createContract(params, config) {
|
|
11
|
-
const { owner, fleet, ownerProfile, rate,
|
|
13
|
+
const { owner, fleet, ownerProfile, rate, durationMax, paymentsFreq, ownerKeyIndex = 0, gameId, mint, } = params;
|
|
14
|
+
// Validate payment frequency using auto-generated validation
|
|
15
|
+
if (!(0, paymentFrequency_2.isValidPaymentFrequency)(paymentsFreq)) {
|
|
16
|
+
throw new Error(`Invalid payment frequency: ${paymentsFreq}. Valid values are auto-generated from Rust PaymentFrequency enum.`);
|
|
17
|
+
}
|
|
18
|
+
// Calculate durationMin from payment frequency
|
|
19
|
+
const durationMin = (0, paymentFrequency_1.paymentFrequencyStringToSeconds)(paymentsFreq);
|
|
20
|
+
// Validate that durationMax is a multiple of the payment frequency
|
|
21
|
+
// Uses the codama-generated PaymentFrequency enum and mirrors Rust implementation
|
|
22
|
+
(0, paymentFrequency_1.validateDurationAlignment)(durationMax, paymentsFreq);
|
|
12
23
|
// Get the actual game ID to use (param override, config override, or network default)
|
|
13
24
|
const actualGameId = gameId ? (0, constants_1.toAddress)(gameId) : await (0, constants_1.getSageGameId)(config);
|
|
14
25
|
// Get codama functions
|
|
@@ -28,7 +39,7 @@ async function _createContract(params, config) {
|
|
|
28
39
|
rate: BigInt(rate),
|
|
29
40
|
durationMin: BigInt(durationMin),
|
|
30
41
|
durationMax: BigInt(durationMax),
|
|
31
|
-
paymentsFeq: paymentsFreq
|
|
42
|
+
paymentsFeq: `@${paymentsFreq}`,
|
|
32
43
|
ownerKeyIndex,
|
|
33
44
|
sageProgram: (0, constants_1.toAddress)(await (0, constants_1.getSageProgramAddress)(config)),
|
|
34
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/contract/create.ts"],"names":[],"mappings":";;AAkKA,wCAIC;AAKD,8EAKC;AA3KD,4CAA2G;AAC3G,kDAAmG;AACnG,gEAAuG;AACvG,gEAA4F;AA+D5F;;GAEG;AACH,KAAK,UAAU,eAAe,CAC5B,MAA4B,EAC5B,MAAsB;IAEtB,MAAM,EACJ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,aAAa,GAAG,CAAC,EACjB,MAAM,EACN,IAAI,GACL,GAAG,MAAM,CAAC;IAEX,6DAA6D;IAC7D,IAAI,CAAC,IAAA,0CAAuB,EAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,oEAAoE,CAAC,CAAC;IAClI,CAAC;IAED,+CAA+C;IAC/C,MAAM,WAAW,GAAG,IAAA,kDAA+B,EAAC,YAAY,CAAC,CAAC;IAElE,mEAAmE;IACnE,kFAAkF;IAClF,IAAA,4CAAyB,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAErD,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,IAAA,qBAAS,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAA,yBAAa,EAAC,MAAM,CAAC,CAAC;IAE9E,uBAAuB;IACvB,MAAM,kBAAkB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,IAAA,k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C,cAAc,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,iCAAiC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,12 +14,33 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.PaymentFrequency = void 0;
|
|
17
|
+
exports.duration = exports.months = exports.weeks = exports.days = exports.hours = exports.minutes = exports.decaseconds = exports.validateDurationAlignment = exports.paymentFrequencyStringToSeconds = exports.paymentFrequencyToSeconds = exports.isValidPaymentFrequency = exports.getPaymentFrequencyFromString = exports.PAYMENT_FREQUENCY_CONSTANTS = exports.PAYMENT_FREQUENCY_MAP = exports.VALID_PAYMENT_FREQUENCIES = exports.PaymentFrequency = void 0;
|
|
18
18
|
// Export main SDK functions
|
|
19
19
|
__exportStar(require("./contract"), exports);
|
|
20
20
|
__exportStar(require("./rental"), exports);
|
|
21
21
|
__exportStar(require("./utils"), exports);
|
|
22
|
-
// Export PaymentFrequency from
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "PaymentFrequency", { enumerable: true, get: function () { return
|
|
22
|
+
// Export PaymentFrequency from codama (generated from Rust)
|
|
23
|
+
var paymentFrequency_1 = require("./codama/types/paymentFrequency");
|
|
24
|
+
Object.defineProperty(exports, "PaymentFrequency", { enumerable: true, get: function () { return paymentFrequency_1.PaymentFrequency; } });
|
|
25
|
+
// Export auto-generated payment frequency types and utilities
|
|
26
|
+
var paymentFrequency_2 = require("./types/paymentFrequency");
|
|
27
|
+
Object.defineProperty(exports, "VALID_PAYMENT_FREQUENCIES", { enumerable: true, get: function () { return paymentFrequency_2.VALID_PAYMENT_FREQUENCIES; } });
|
|
28
|
+
Object.defineProperty(exports, "PAYMENT_FREQUENCY_MAP", { enumerable: true, get: function () { return paymentFrequency_2.PAYMENT_FREQUENCY_MAP; } });
|
|
29
|
+
Object.defineProperty(exports, "PAYMENT_FREQUENCY_CONSTANTS", { enumerable: true, get: function () { return paymentFrequency_2.PAYMENT_FREQUENCY_CONSTANTS; } });
|
|
30
|
+
Object.defineProperty(exports, "getPaymentFrequencyFromString", { enumerable: true, get: function () { return paymentFrequency_2.getPaymentFrequencyFromString; } });
|
|
31
|
+
Object.defineProperty(exports, "isValidPaymentFrequency", { enumerable: true, get: function () { return paymentFrequency_2.isValidPaymentFrequency; } });
|
|
32
|
+
// Export payment frequency utilities that mirror Rust implementation
|
|
33
|
+
var paymentFrequency_3 = require("./utils/paymentFrequency");
|
|
34
|
+
Object.defineProperty(exports, "paymentFrequencyToSeconds", { enumerable: true, get: function () { return paymentFrequency_3.paymentFrequencyToSeconds; } });
|
|
35
|
+
Object.defineProperty(exports, "paymentFrequencyStringToSeconds", { enumerable: true, get: function () { return paymentFrequency_3.paymentFrequencyStringToSeconds; } });
|
|
36
|
+
Object.defineProperty(exports, "validateDurationAlignment", { enumerable: true, get: function () { return paymentFrequency_3.validateDurationAlignment; } });
|
|
37
|
+
// Export duration helper functions for convenient time unit conversion
|
|
38
|
+
var duration_1 = require("./utils/duration");
|
|
39
|
+
Object.defineProperty(exports, "decaseconds", { enumerable: true, get: function () { return duration_1.decaseconds; } });
|
|
40
|
+
Object.defineProperty(exports, "minutes", { enumerable: true, get: function () { return duration_1.minutes; } });
|
|
41
|
+
Object.defineProperty(exports, "hours", { enumerable: true, get: function () { return duration_1.hours; } });
|
|
42
|
+
Object.defineProperty(exports, "days", { enumerable: true, get: function () { return duration_1.days; } });
|
|
43
|
+
Object.defineProperty(exports, "weeks", { enumerable: true, get: function () { return duration_1.weeks; } });
|
|
44
|
+
Object.defineProperty(exports, "months", { enumerable: true, get: function () { return duration_1.months; } });
|
|
45
|
+
Object.defineProperty(exports, "duration", { enumerable: true, get: function () { return duration_1.duration; } });
|
|
25
46
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AAsBxB,8DAA8D;AAC9D,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,0CAAwB;AAsBxB,4DAA4D;AAC5D,oEAAmE;AAA1D,oHAAA,gBAAgB,OAAA;AAEzB,8DAA8D;AAC9D,6DAOkC;AALhC,6HAAA,yBAAyB,OAAA;AACzB,yHAAA,qBAAqB,OAAA;AACrB,+HAAA,2BAA2B,OAAA;AAC3B,iIAAA,6BAA6B,OAAA;AAC7B,2HAAA,uBAAuB,OAAA;AAGzB,qEAAqE;AACrE,6DAIkC;AAHhC,6HAAA,yBAAyB,OAAA;AACzB,mIAAA,+BAA+B,OAAA;AAC/B,6HAAA,yBAAyB,OAAA;AAG3B,uEAAuE;AACvE,6CAQ0B;AAPxB,uGAAA,WAAW,OAAA;AACX,mGAAA,OAAO,OAAA;AACP,iGAAA,KAAK,OAAA;AACL,gGAAA,IAAI,OAAA;AACJ,iGAAA,KAAK,OAAA;AACL,kGAAA,MAAM,OAAA;AACN,oGAAA,QAAQ,OAAA"}
|
package/dist/cjs/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This code was AUTO-GENERATED from the Rust PaymentFrequency implementation.
|
|
4
|
+
* Please DO NOT EDIT THIS FILE manually - it will be overwritten.
|
|
5
|
+
*
|
|
6
|
+
* Source: programs/srsly/src/utils.rs
|
|
7
|
+
* Generated by: generate.mjs
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PAYMENT_FREQUENCY_CONSTANTS = exports.PAYMENT_FREQUENCY_MAP = exports.VALID_PAYMENT_FREQUENCIES = void 0;
|
|
11
|
+
exports.getPaymentFrequencyFromString = getPaymentFrequencyFromString;
|
|
12
|
+
exports.isValidPaymentFrequency = isValidPaymentFrequency;
|
|
13
|
+
const paymentFrequency_1 = require("../codama/types/paymentFrequency");
|
|
14
|
+
/**
|
|
15
|
+
* Array of all valid payment frequency strings
|
|
16
|
+
* Auto-generated from Rust PaymentFrequency enum
|
|
17
|
+
*/
|
|
18
|
+
exports.VALID_PAYMENT_FREQUENCIES = [
|
|
19
|
+
'hourly',
|
|
20
|
+
'daily',
|
|
21
|
+
'weekly',
|
|
22
|
+
'monthly'
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Mapping from user-friendly strings to PaymentFrequency enum values
|
|
26
|
+
* Auto-generated from Rust PaymentFrequency enum
|
|
27
|
+
*/
|
|
28
|
+
exports.PAYMENT_FREQUENCY_MAP = {
|
|
29
|
+
'hourly': paymentFrequency_1.PaymentFrequency.Hourly,
|
|
30
|
+
'daily': paymentFrequency_1.PaymentFrequency.Daily,
|
|
31
|
+
'weekly': paymentFrequency_1.PaymentFrequency.Weekly,
|
|
32
|
+
'monthly': paymentFrequency_1.PaymentFrequency.Monthly
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Constants extracted from Rust constants.rs
|
|
36
|
+
* Auto-synced with Rust implementation
|
|
37
|
+
*/
|
|
38
|
+
exports.PAYMENT_FREQUENCY_CONSTANTS = {
|
|
39
|
+
SECONDS_PER_DECASECOND: 10,
|
|
40
|
+
SECONDS_PER_MINUTE: 60,
|
|
41
|
+
SECONDS_PER_HOUR: 3600,
|
|
42
|
+
SECONDS_PER_DAY: 86400,
|
|
43
|
+
SECONDS_PER_WEEK: 604800,
|
|
44
|
+
SECONDS_PER_MONTH: 2678400
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Get PaymentFrequency enum value from user-friendly string
|
|
48
|
+
*/
|
|
49
|
+
function getPaymentFrequencyFromString(frequencyString) {
|
|
50
|
+
return exports.PAYMENT_FREQUENCY_MAP[frequencyString];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a string is a valid payment frequency
|
|
54
|
+
*/
|
|
55
|
+
function isValidPaymentFrequency(value) {
|
|
56
|
+
return exports.VALID_PAYMENT_FREQUENCIES.includes(value);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=paymentFrequency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentFrequency.js","sourceRoot":"","sources":["../../../src/types/paymentFrequency.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAgDH,sEAEC;AAKD,0DAEC;AAvDD,uEAAoE;AAQpE;;;GAGG;AACU,QAAA,yBAAyB,GAAsC;IAC1E,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;CACD,CAAC;AAEX;;;GAGG;AACU,QAAA,qBAAqB,GAAqD;IACrF,QAAQ,EAAE,mCAAgB,CAAC,MAAM;IACjC,OAAO,EAAE,mCAAgB,CAAC,KAAK;IAC/B,QAAQ,EAAE,mCAAgB,CAAC,MAAM;IACjC,SAAS,EAAE,mCAAgB,CAAC,OAAO;CAC3B,CAAC;AAEX;;;GAGG;AACU,QAAA,2BAA2B,GAAG;IACzC,sBAAsB,EAAE,EAAE;IAC1B,kBAAkB,EAAE,EAAE;IACtB,gBAAgB,EAAE,IAAI;IACtB,eAAe,EAAE,KAAK;IACtB,gBAAgB,EAAE,MAAM;IACxB,iBAAiB,EAAE,OAAO;CAClB,CAAC;AAEX;;GAEG;AACH,SAAgB,6BAA6B,CAAC,eAAuC;IACnF,OAAO,6BAAqB,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,KAAa;IACnD,OAAO,iCAAyB,CAAC,QAAQ,CAAC,KAA+B,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FACTION_MAPPING = exports.FACTION_SPECIFIC_CSS = exports.
|
|
3
|
+
exports.FACTION_MAPPING = exports.FACTION_SPECIFIC_CSS = exports.ATLAS_TO_STARDUST = exports.PROFILE_FACTION_SEED = exports.SAGE_PLAYER_PROFILE_SEED = exports.STARBASE_PLAYER_SEED = exports.STARBASE_SEED = void 0;
|
|
4
4
|
exports.toAddress = toAddress;
|
|
5
5
|
exports.getSrslyProgramAddress = getSrslyProgramAddress;
|
|
6
6
|
exports.getProgramId = getProgramId;
|
|
@@ -8,7 +8,6 @@ exports.getSageProgramAddress = getSageProgramAddress;
|
|
|
8
8
|
exports.getProfileFactionProgramAddress = getProfileFactionProgramAddress;
|
|
9
9
|
exports.getSageGameId = getSageGameId;
|
|
10
10
|
exports.getAtlasMint = getAtlasMint;
|
|
11
|
-
exports.paymentFrequencyToString = paymentFrequencyToString;
|
|
12
11
|
const config_1 = require("./config");
|
|
13
12
|
const kit_1 = require("@solana/kit");
|
|
14
13
|
/**
|
|
@@ -25,18 +24,7 @@ exports.SAGE_PLAYER_PROFILE_SEED = 'sage_player_profile';
|
|
|
25
24
|
exports.PROFILE_FACTION_SEED = 'profile_faction';
|
|
26
25
|
// Token conversion constants
|
|
27
26
|
exports.ATLAS_TO_STARDUST = 100_000_000; // 1 ATLAS = 100,000,000 stardust
|
|
28
|
-
// PaymentFrequency enum
|
|
29
|
-
var PaymentFrequency;
|
|
30
|
-
(function (PaymentFrequency) {
|
|
31
|
-
PaymentFrequency[PaymentFrequency["Hourly"] = 0] = "Hourly";
|
|
32
|
-
PaymentFrequency[PaymentFrequency["Daily"] = 1] = "Daily";
|
|
33
|
-
PaymentFrequency[PaymentFrequency["DailyOld"] = 2] = "DailyOld";
|
|
34
|
-
PaymentFrequency[PaymentFrequency["Weekly"] = 3] = "Weekly";
|
|
35
|
-
PaymentFrequency[PaymentFrequency["Monthly"] = 4] = "Monthly";
|
|
36
|
-
// Development-only frequencies (not available on mainnet)
|
|
37
|
-
PaymentFrequency[PaymentFrequency["Decasecond"] = 5] = "Decasecond";
|
|
38
|
-
PaymentFrequency[PaymentFrequency["Minute"] = 6] = "Minute";
|
|
39
|
-
})(PaymentFrequency || (exports.PaymentFrequency = PaymentFrequency = {}));
|
|
27
|
+
// PaymentFrequency enum is now exported from codama-generated types
|
|
40
28
|
// Network constants are now managed in config.ts
|
|
41
29
|
async function getSrslyProgramAddress(config) {
|
|
42
30
|
const globalConfig = (0, config_1.getConfig)();
|
|
@@ -85,10 +73,5 @@ exports.FACTION_MAPPING = {
|
|
|
85
73
|
2: 'oni',
|
|
86
74
|
3: 'ustur'
|
|
87
75
|
};
|
|
88
|
-
|
|
89
|
-
* Convert PaymentFrequency enum to string
|
|
90
|
-
*/
|
|
91
|
-
function paymentFrequencyToString(freq) {
|
|
92
|
-
return PaymentFrequency[freq].toLowerCase();
|
|
93
|
-
}
|
|
76
|
+
// PaymentFrequency utilities are now in utils/paymentFrequency.ts
|
|
94
77
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":";;;AAOA,8BAEC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":";;;AAOA,8BAEC;AAeD,wDAMC;AAGD,oCAEC;AAGD,sDAOC;AAED,0EAMC;AAED,sCAMC;AAED,oCAMC;AArED,qCAAkF;AAClF,qCAAoD;AAEpD;;;GAGG;AACH,SAAgB,SAAS,CAAC,KAA+B;IACvD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA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
+
exports.decaseconds = decaseconds;
|
|
5
|
+
exports.minutes = minutes;
|
|
6
|
+
exports.hours = hours;
|
|
7
|
+
exports.days = days;
|
|
8
|
+
exports.weeks = weeks;
|
|
9
|
+
exports.months = months;
|
|
10
|
+
const paymentFrequency_1 = require("../types/paymentFrequency");
|
|
11
|
+
/**
|
|
12
|
+
* Duration helper functions for converting time units to seconds
|
|
13
|
+
* Uses the same constants as the payment frequency system for consistency
|
|
14
|
+
*/
|
|
15
|
+
const { SECONDS_PER_DECASECOND, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH } = paymentFrequency_1.PAYMENT_FREQUENCY_CONSTANTS;
|
|
16
|
+
/**
|
|
17
|
+
* Convert decaseconds (10 seconds) to seconds
|
|
18
|
+
* @param amount Number of decaseconds
|
|
19
|
+
* @returns Number of seconds
|
|
20
|
+
*/
|
|
21
|
+
function decaseconds(amount) {
|
|
22
|
+
return amount * SECONDS_PER_DECASECOND;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert minutes to seconds
|
|
26
|
+
* @param amount Number of minutes
|
|
27
|
+
* @returns Number of seconds
|
|
28
|
+
*/
|
|
29
|
+
function minutes(amount) {
|
|
30
|
+
return amount * SECONDS_PER_MINUTE;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert hours to seconds
|
|
34
|
+
* @param amount Number of hours
|
|
35
|
+
* @returns Number of seconds
|
|
36
|
+
*/
|
|
37
|
+
function hours(amount) {
|
|
38
|
+
return amount * SECONDS_PER_HOUR;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Convert days to seconds
|
|
42
|
+
* @param amount Number of days
|
|
43
|
+
* @returns Number of seconds
|
|
44
|
+
*/
|
|
45
|
+
function days(amount) {
|
|
46
|
+
return amount * SECONDS_PER_DAY;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert weeks to seconds
|
|
50
|
+
* @param amount Number of weeks
|
|
51
|
+
* @returns Number of seconds
|
|
52
|
+
*/
|
|
53
|
+
function weeks(amount) {
|
|
54
|
+
return amount * SECONDS_PER_WEEK;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convert months to seconds
|
|
58
|
+
* @param amount Number of months (31 days each)
|
|
59
|
+
* @returns Number of seconds
|
|
60
|
+
*/
|
|
61
|
+
function months(amount) {
|
|
62
|
+
return amount * SECONDS_PER_MONTH;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* All duration helper functions
|
|
66
|
+
*/
|
|
67
|
+
exports.duration = {
|
|
68
|
+
decaseconds,
|
|
69
|
+
minutes,
|
|
70
|
+
hours,
|
|
71
|
+
days,
|
|
72
|
+
weeks,
|
|
73
|
+
months,
|
|
74
|
+
// Also expose the raw constants for advanced users
|
|
75
|
+
constants: paymentFrequency_1.PAYMENT_FREQUENCY_CONSTANTS,
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../src/utils/duration.ts"],"names":[],"mappings":";;;AAqBA,kCAEC;AAOD,0BAEC;AAOD,sBAEC;AAOD,oBAEC;AAOD,sBAEC;AAOD,wBAEC;AApED,gEAAwE;AAExE;;;GAGG;AAEH,MAAM,EACJ,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,GAAG,8CAA2B,CAAC;AAEhC;;;;GAIG;AACH,SAAgB,WAAW,CAAC,MAAc;IACxC,OAAO,MAAM,GAAG,sBAAsB,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAAc;IACpC,OAAO,MAAM,GAAG,kBAAkB,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,MAAc;IAClC,OAAO,MAAM,GAAG,gBAAgB,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAgB,IAAI,CAAC,MAAc;IACjC,OAAO,MAAM,GAAG,eAAe,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,MAAc;IAClC,OAAO,MAAM,GAAG,gBAAgB,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,MAAc;IACnC,OAAO,MAAM,GAAG,iBAAiB,CAAC;AACpC,CAAC;AAED;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,WAAW;IACX,OAAO;IACP,KAAK;IACL,IAAI;IACJ,KAAK;IACL,MAAM;IAEN,mDAAmD;IACnD,SAAS,EAAE,8CAA2B;CAC9B,CAAC"}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./constants"), exports);
|
|
18
18
|
__exportStar(require("./profiles"), exports);
|
|
19
19
|
__exportStar(require("./config"), exports);
|
|
20
|
+
__exportStar(require("./paymentFrequency"), exports);
|
|
21
|
+
__exportStar(require("./duration"), exports);
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,qDAAmC;AACnC,6CAA2B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paymentFrequencyToSeconds = paymentFrequencyToSeconds;
|
|
4
|
+
exports.paymentFrequencyStringToSeconds = paymentFrequencyStringToSeconds;
|
|
5
|
+
exports.validateDurationAlignment = validateDurationAlignment;
|
|
6
|
+
const paymentFrequency_1 = require("../codama/types/paymentFrequency");
|
|
7
|
+
const paymentFrequency_2 = require("../types/paymentFrequency");
|
|
8
|
+
/**
|
|
9
|
+
* Payment frequency conversion utilities
|
|
10
|
+
* Mirrors the Rust implementation in programs/srsly/src/utils.rs
|
|
11
|
+
* Uses auto-generated constants and mappings from Rust source
|
|
12
|
+
*/
|
|
13
|
+
// Auto-synced constants from Rust constants.rs
|
|
14
|
+
const { SECONDS_PER_DECASECOND, SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH } = paymentFrequency_2.PAYMENT_FREQUENCY_CONSTANTS;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a PaymentFrequency enum value to seconds
|
|
17
|
+
* Mirrors the to_seconds() method from the Rust implementation
|
|
18
|
+
*/
|
|
19
|
+
function paymentFrequencyToSeconds(frequency) {
|
|
20
|
+
switch (frequency) {
|
|
21
|
+
case paymentFrequency_1.PaymentFrequency.Decasecond:
|
|
22
|
+
return SECONDS_PER_DECASECOND;
|
|
23
|
+
case paymentFrequency_1.PaymentFrequency.Minute:
|
|
24
|
+
return SECONDS_PER_MINUTE;
|
|
25
|
+
case paymentFrequency_1.PaymentFrequency.Hourly:
|
|
26
|
+
return SECONDS_PER_HOUR;
|
|
27
|
+
case paymentFrequency_1.PaymentFrequency.Daily:
|
|
28
|
+
case paymentFrequency_1.PaymentFrequency.DailyOld:
|
|
29
|
+
return SECONDS_PER_DAY;
|
|
30
|
+
case paymentFrequency_1.PaymentFrequency.Weekly:
|
|
31
|
+
return SECONDS_PER_WEEK;
|
|
32
|
+
case paymentFrequency_1.PaymentFrequency.Monthly:
|
|
33
|
+
return SECONDS_PER_MONTH;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown payment frequency: ${frequency}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a payment frequency string to seconds
|
|
40
|
+
* Uses auto-generated mapping from Rust PaymentFrequency enum
|
|
41
|
+
*/
|
|
42
|
+
function paymentFrequencyStringToSeconds(frequencyString) {
|
|
43
|
+
const frequency = paymentFrequency_2.PAYMENT_FREQUENCY_MAP[frequencyString];
|
|
44
|
+
if (frequency === undefined) {
|
|
45
|
+
throw new Error(`Invalid payment frequency string: ${frequencyString}`);
|
|
46
|
+
}
|
|
47
|
+
return paymentFrequencyToSeconds(frequency);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validates that a duration is a multiple of the payment frequency
|
|
51
|
+
* Uses auto-generated types from Rust PaymentFrequency enum
|
|
52
|
+
*/
|
|
53
|
+
function validateDurationAlignment(duration, frequencyString) {
|
|
54
|
+
const durationNumber = Number(duration);
|
|
55
|
+
const frequencySeconds = paymentFrequencyStringToSeconds(frequencyString);
|
|
56
|
+
if (durationNumber % frequencySeconds !== 0) {
|
|
57
|
+
throw new Error(`Duration (${duration} seconds) must be a multiple of ${frequencyString} frequency (${frequencySeconds} seconds)`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=paymentFrequency.js.map
|