@whetstone-research/doppler-sdk 1.0.6 → 1.0.7

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/evm/index.js CHANGED
@@ -5293,7 +5293,7 @@ var DopplerFactory = class {
5293
5293
  this.chainId = chainId;
5294
5294
  }
5295
5295
  hasCustomV2Schedules(vesting) {
5296
- return (vesting?.schedules?.length ?? 0) > 0 || (vesting?.scheduleIds?.length ?? 0) > 0;
5296
+ return (vesting?.allocations?.length ?? 0) > 0;
5297
5297
  }
5298
5298
  usesDerc20V2Vesting(vesting) {
5299
5299
  if (!vesting) {
@@ -5305,6 +5305,16 @@ var DopplerFactory = class {
5305
5305
  if (!args.vesting) {
5306
5306
  return { recipients: [], amounts: [] };
5307
5307
  }
5308
+ if (args.vesting.allocations) {
5309
+ return {
5310
+ recipients: args.vesting.allocations.map(
5311
+ (allocation) => allocation.recipient
5312
+ ),
5313
+ amounts: args.vesting.allocations.map(
5314
+ (allocation) => allocation.amount
5315
+ )
5316
+ };
5317
+ }
5308
5318
  if (args.vesting.recipients && args.vesting.amounts) {
5309
5319
  return {
5310
5320
  recipients: args.vesting.recipients,
@@ -5316,18 +5326,6 @@ var DopplerFactory = class {
5316
5326
  amounts: [args.sale.initialSupply - args.sale.numTokensToSell]
5317
5327
  };
5318
5328
  }
5319
- normalizeV2ScheduleId(scheduleId, label) {
5320
- if (!Number.isFinite(scheduleId) || !Number.isInteger(scheduleId)) {
5321
- throw new Error(`${label} must be an integer`);
5322
- }
5323
- if (!Number.isSafeInteger(scheduleId)) {
5324
- throw new Error(`${label} must be a safe integer`);
5325
- }
5326
- if (scheduleId < 0) {
5327
- throw new Error(`${label} cannot be negative`);
5328
- }
5329
- return BigInt(scheduleId);
5330
- }
5331
5329
  validateUint64LikeNumber(value, fieldPath, options = {}) {
5332
5330
  const { allowZero = true } = options;
5333
5331
  if (!Number.isFinite(value) || !Number.isInteger(value)) {
@@ -5361,37 +5359,22 @@ var DopplerFactory = class {
5361
5359
  scheduleIds: Array.from({ length: args.recipientCount }, () => 0n)
5362
5360
  };
5363
5361
  }
5364
- const schedules = args.vesting.schedules?.map((schedule) => ({
5365
- cliff: BigInt(schedule.cliffDuration ?? 0),
5366
- duration: BigInt(schedule.duration ?? 0)
5367
- })) ?? [];
5368
- const explicitScheduleIds = args.vesting.scheduleIds;
5369
- if (explicitScheduleIds && explicitScheduleIds.length > 0) {
5370
- return {
5371
- schedules,
5372
- scheduleIds: explicitScheduleIds.map(
5373
- (scheduleId, index) => this.normalizeV2ScheduleId(
5374
- scheduleId,
5375
- `Vesting scheduleIds[${index}]`
5376
- )
5377
- )
5378
- };
5379
- }
5380
- if (schedules.length === 1) {
5381
- return {
5382
- schedules,
5383
- scheduleIds: Array.from({ length: args.recipientCount }, () => 0n)
5384
- };
5385
- }
5386
- if (schedules.length === args.recipientCount) {
5387
- return {
5388
- schedules,
5389
- scheduleIds: schedules.map((_, index) => BigInt(index))
5390
- };
5362
+ const schedules = [];
5363
+ const scheduleIds = [];
5364
+ const scheduleIdsByKey = /* @__PURE__ */ new Map();
5365
+ for (const allocation of args.vesting.allocations ?? []) {
5366
+ const cliff = BigInt(allocation.schedule.cliffDuration ?? 0);
5367
+ const duration = BigInt(allocation.schedule.duration ?? 0);
5368
+ const key = `${cliff}:${duration}`;
5369
+ let scheduleId = scheduleIdsByKey.get(key);
5370
+ if (scheduleId === void 0) {
5371
+ scheduleId = BigInt(schedules.length);
5372
+ schedules.push({ cliff, duration });
5373
+ scheduleIdsByKey.set(key, scheduleId);
5374
+ }
5375
+ scheduleIds.push(scheduleId);
5391
5376
  }
5392
- throw new Error(
5393
- "Vesting schedules must either contain exactly one shared schedule or one schedule per recipient when scheduleIds are omitted"
5394
- );
5377
+ return { schedules, scheduleIds };
5395
5378
  }
5396
5379
  resolveStandardTokenFactoryMode(args) {
5397
5380
  if (this.usesDerc20V2Vesting(args.vesting)) {
@@ -8235,87 +8218,70 @@ var DopplerFactory = class {
8235
8218
  const cliffDuration = vesting.cliffDuration ?? 0;
8236
8219
  const duration = vesting.duration ?? 0;
8237
8220
  const hasCustomSchedules = this.hasCustomV2Schedules(vesting);
8238
- if (hasCustomSchedules && (cliffDuration > 0 || duration > 0)) {
8221
+ if (hasCustomSchedules && (cliffDuration > 0 || duration > 0 || vesting.recipients !== void 0 || vesting.amounts !== void 0)) {
8239
8222
  throw new Error(
8240
- "Use vesting.schedules instead of top-level duration/cliffDuration when configuring multiple vesting schedules"
8223
+ "Use vesting.allocations instead of top-level duration/cliffDuration/recipients/amounts when configuring per-beneficiary vesting"
8241
8224
  );
8242
8225
  }
8243
- if (vesting.recipients && vesting.amounts) {
8244
- if (vesting.recipients.length !== vesting.amounts.length) {
8245
- throw new Error(
8246
- "Vesting recipients and amounts arrays must have the same length"
8247
- );
8226
+ const availableForVesting = sale.initialSupply - sale.numTokensToSell;
8227
+ if (vesting.allocations) {
8228
+ if (vesting.allocations.length === 0) {
8229
+ throw new Error("Vesting allocations array cannot be empty");
8248
8230
  }
8249
- if (vesting.recipients.length === 0) {
8250
- throw new Error("Vesting recipients array cannot be empty");
8251
- }
8252
- const totalVested = vesting.amounts.reduce((sum, amt) => sum + amt, 0n);
8253
- const availableForVesting = sale.initialSupply - sale.numTokensToSell;
8231
+ const totalVested = vesting.allocations.reduce(
8232
+ (sum, allocation) => sum + allocation.amount,
8233
+ 0n
8234
+ );
8254
8235
  if (totalVested > availableForVesting) {
8255
8236
  throw new Error(
8256
8237
  `Total vesting amount (${totalVested}) exceeds available tokens (${availableForVesting})`
8257
8238
  );
8258
8239
  }
8259
- } else {
8260
- const vestedAmount = sale.initialSupply - sale.numTokensToSell;
8261
- if (vestedAmount <= 0n) {
8262
- throw new Error("No tokens available for vesting");
8263
- }
8264
- }
8265
- if (hasCustomSchedules) {
8266
- const schedules = vesting.schedules;
8267
- if (!schedules || schedules.length === 0) {
8268
- throw new Error(
8269
- "Vesting schedules are required when using scheduleIds or multiple vesting schedules"
8270
- );
8271
- }
8272
- const recipientCount = vesting.recipients && vesting.amounts ? vesting.recipients.length : 1;
8273
- if (vesting.scheduleIds) {
8274
- if (vesting.scheduleIds.length !== recipientCount) {
8275
- throw new Error(
8276
- "Vesting scheduleIds array must have the same length as vesting recipients"
8277
- );
8278
- }
8279
- for (const [index, scheduleId] of vesting.scheduleIds.entries()) {
8280
- this.validateUint64LikeNumber(
8281
- scheduleId,
8282
- `Vesting scheduleIds[${index}]`
8283
- );
8284
- if (scheduleId >= schedules.length) {
8285
- throw new Error(
8286
- `Vesting scheduleIds[${index}] references missing schedule ${scheduleId}`
8287
- );
8288
- }
8289
- }
8290
- } else if (schedules.length !== 1 && schedules.length !== recipientCount) {
8291
- throw new Error(
8292
- "Vesting schedules must either contain exactly one shared schedule or one schedule per recipient when scheduleIds are omitted"
8293
- );
8294
- }
8295
- for (const [index, schedule] of schedules.entries()) {
8296
- const scheduleCliff = schedule.cliffDuration ?? 0;
8297
- const scheduleDuration = schedule.duration ?? 0;
8240
+ for (const [index, allocation] of vesting.allocations.entries()) {
8241
+ const scheduleCliff = allocation.schedule.cliffDuration ?? 0;
8242
+ const scheduleDuration = allocation.schedule.duration ?? 0;
8298
8243
  this.validateUint64LikeNumber(
8299
8244
  scheduleCliff,
8300
- `Vesting schedules[${index}].cliffDuration`
8245
+ `Vesting allocations[${index}].schedule.cliffDuration`
8301
8246
  );
8302
8247
  this.validateUint64LikeNumber(
8303
8248
  scheduleDuration,
8304
- `Vesting schedules[${index}].duration`
8249
+ `Vesting allocations[${index}].schedule.duration`
8305
8250
  );
8306
8251
  if (scheduleCliff > scheduleDuration) {
8307
8252
  throw new Error(
8308
- `Vesting schedules[${index}].cliffDuration cannot exceed duration`
8253
+ `Vesting allocations[${index}].schedule.cliffDuration cannot exceed duration`
8309
8254
  );
8310
8255
  }
8311
8256
  if (scheduleCliff > 0 && scheduleDuration > 0 && scheduleDuration < DERC20_V2_MIN_VESTING_DURATION) {
8312
8257
  throw new Error(
8313
- `Vesting schedules[${index}].duration must be 0 or at least ${DERC20_V2_MIN_VESTING_DURATION} seconds when using cliffs`
8258
+ `Vesting allocations[${index}].schedule.duration must be 0 or at least ${DERC20_V2_MIN_VESTING_DURATION} seconds when using cliffs`
8314
8259
  );
8315
8260
  }
8316
8261
  }
8317
8262
  return;
8318
8263
  }
8264
+ if (vesting.recipients && vesting.amounts) {
8265
+ if (vesting.recipients.length !== vesting.amounts.length) {
8266
+ throw new Error(
8267
+ "Vesting recipients and amounts arrays must have the same length"
8268
+ );
8269
+ }
8270
+ if (vesting.recipients.length === 0) {
8271
+ throw new Error("Vesting recipients array cannot be empty");
8272
+ }
8273
+ const totalVested = vesting.amounts.reduce((sum, amt) => sum + amt, 0n);
8274
+ if (totalVested > availableForVesting) {
8275
+ throw new Error(
8276
+ `Total vesting amount (${totalVested}) exceeds available tokens (${availableForVesting})`
8277
+ );
8278
+ }
8279
+ } else {
8280
+ const vestedAmount = sale.initialSupply - sale.numTokensToSell;
8281
+ if (vestedAmount <= 0n) {
8282
+ throw new Error("No tokens available for vesting");
8283
+ }
8284
+ }
8319
8285
  if (cliffDuration < 0) {
8320
8286
  throw new Error("Vesting cliff duration cannot be negative");
8321
8287
  }
@@ -13574,23 +13540,14 @@ function normalizeBuilderVestingScheduleDuration(value, fieldPath) {
13574
13540
  }
13575
13541
  return Number(duration);
13576
13542
  }
13577
- function normalizeBuilderScheduleId(scheduleId, fieldPath) {
13578
- if (typeof scheduleId === "bigint") {
13579
- if (scheduleId < 0n) {
13580
- throw new RangeError(`${fieldPath} cannot be negative`);
13581
- }
13582
- if (scheduleId > MAX_SAFE_INTEGER_BIGINT) {
13583
- throw new RangeError(`${fieldPath} must be a safe integer`);
13584
- }
13585
- return Number(scheduleId);
13586
- }
13587
- if (!Number.isSafeInteger(scheduleId)) {
13588
- throw new RangeError(`${fieldPath} must be a safe integer`);
13589
- }
13590
- if (scheduleId < 0) {
13591
- throw new RangeError(`${fieldPath} cannot be negative`);
13592
- }
13593
- return scheduleId;
13543
+ function normalizeBuilderVestingSchedule(schedule, fieldPath) {
13544
+ return {
13545
+ duration: normalizeBuilderVestingScheduleDuration(
13546
+ schedule.duration,
13547
+ `${fieldPath}.duration`
13548
+ ),
13549
+ cliffDuration: schedule.cliffDuration ?? 0
13550
+ };
13594
13551
  }
13595
13552
  function computeTicks(priceRange, tickSpacing) {
13596
13553
  const startTick = Math.floor(
@@ -13887,24 +13844,24 @@ var StaticAuctionBuilder = class _StaticAuctionBuilder {
13887
13844
  this.vesting = void 0;
13888
13845
  return this;
13889
13846
  }
13890
- const hasCustomSchedules = (params.schedules?.length ?? 0) > 0 || (params.scheduleIds?.length ?? 0) > 0;
13847
+ if (params.allocations) {
13848
+ this.vesting = {
13849
+ allocations: params.allocations.map((allocation, index) => ({
13850
+ recipient: allocation.recipient,
13851
+ amount: allocation.amount,
13852
+ schedule: normalizeBuilderVestingSchedule(
13853
+ allocation.schedule,
13854
+ `Vesting allocations[${index}].schedule`
13855
+ )
13856
+ }))
13857
+ };
13858
+ return this;
13859
+ }
13891
13860
  this.vesting = {
13892
- duration: Number(
13893
- params.duration ?? (hasCustomSchedules ? 0n : DEFAULT_V3_VESTING_DURATION)
13894
- ),
13861
+ duration: Number(params.duration ?? DEFAULT_V3_VESTING_DURATION),
13895
13862
  cliffDuration: params.cliffDuration ?? 0,
13896
13863
  recipients: params.recipients,
13897
- amounts: params.amounts,
13898
- schedules: params.schedules?.map((schedule) => ({
13899
- duration: normalizeBuilderVestingScheduleDuration(
13900
- schedule.duration,
13901
- "Vesting schedule duration"
13902
- ),
13903
- cliffDuration: schedule.cliffDuration ?? 0
13904
- })),
13905
- scheduleIds: params.scheduleIds?.map(
13906
- (scheduleId, index) => normalizeBuilderScheduleId(scheduleId, `Vesting scheduleIds[${index}]`)
13907
- )
13864
+ amounts: params.amounts
13908
13865
  };
13909
13866
  return this;
13910
13867
  }
@@ -14232,21 +14189,24 @@ var DynamicAuctionBuilder = class _DynamicAuctionBuilder {
14232
14189
  this.vesting = void 0;
14233
14190
  return this;
14234
14191
  }
14192
+ if (params.allocations) {
14193
+ this.vesting = {
14194
+ allocations: params.allocations.map((allocation, index) => ({
14195
+ recipient: allocation.recipient,
14196
+ amount: allocation.amount,
14197
+ schedule: normalizeBuilderVestingSchedule(
14198
+ allocation.schedule,
14199
+ `Vesting allocations[${index}].schedule`
14200
+ )
14201
+ }))
14202
+ };
14203
+ return this;
14204
+ }
14235
14205
  this.vesting = {
14236
14206
  duration: Number(params.duration ?? 0n),
14237
14207
  cliffDuration: params.cliffDuration ?? 0,
14238
14208
  recipients: params.recipients,
14239
- amounts: params.amounts,
14240
- schedules: params.schedules?.map((schedule) => ({
14241
- duration: normalizeBuilderVestingScheduleDuration(
14242
- schedule.duration,
14243
- "Vesting schedule duration"
14244
- ),
14245
- cliffDuration: schedule.cliffDuration ?? 0
14246
- })),
14247
- scheduleIds: params.scheduleIds?.map(
14248
- (scheduleId, index) => normalizeBuilderScheduleId(scheduleId, `Vesting scheduleIds[${index}]`)
14249
- )
14209
+ amounts: params.amounts
14250
14210
  };
14251
14211
  return this;
14252
14212
  }
@@ -14848,21 +14808,24 @@ var MulticurveBuilder = class _MulticurveBuilder {
14848
14808
  this.vesting = void 0;
14849
14809
  return this;
14850
14810
  }
14811
+ if (params.allocations) {
14812
+ this.vesting = {
14813
+ allocations: params.allocations.map((allocation, index) => ({
14814
+ recipient: allocation.recipient,
14815
+ amount: allocation.amount,
14816
+ schedule: normalizeBuilderVestingSchedule(
14817
+ allocation.schedule,
14818
+ `Vesting allocations[${index}].schedule`
14819
+ )
14820
+ }))
14821
+ };
14822
+ return this;
14823
+ }
14851
14824
  this.vesting = {
14852
14825
  duration: Number(params.duration ?? 0n),
14853
14826
  cliffDuration: params.cliffDuration ?? 0,
14854
14827
  recipients: params.recipients,
14855
- amounts: params.amounts,
14856
- schedules: params.schedules?.map((schedule) => ({
14857
- duration: normalizeBuilderVestingScheduleDuration(
14858
- schedule.duration,
14859
- "Vesting schedule duration"
14860
- ),
14861
- cliffDuration: schedule.cliffDuration ?? 0
14862
- })),
14863
- scheduleIds: params.scheduleIds?.map(
14864
- (scheduleId, index) => normalizeBuilderScheduleId(scheduleId, `Vesting scheduleIds[${index}]`)
14865
- )
14828
+ amounts: params.amounts
14866
14829
  };
14867
14830
  return this;
14868
14831
  }
@@ -15247,21 +15210,24 @@ var OpeningAuctionBuilder = class _OpeningAuctionBuilder {
15247
15210
  this.vesting = void 0;
15248
15211
  return this;
15249
15212
  }
15213
+ if (params.allocations) {
15214
+ this.vesting = {
15215
+ allocations: params.allocations.map((allocation, index) => ({
15216
+ recipient: allocation.recipient,
15217
+ amount: allocation.amount,
15218
+ schedule: normalizeBuilderVestingSchedule(
15219
+ allocation.schedule,
15220
+ `Vesting allocations[${index}].schedule`
15221
+ )
15222
+ }))
15223
+ };
15224
+ return this;
15225
+ }
15250
15226
  this.vesting = {
15251
15227
  duration: Number(params.duration ?? 0n),
15252
15228
  cliffDuration: params.cliffDuration ?? 0,
15253
15229
  recipients: params.recipients,
15254
- amounts: params.amounts,
15255
- schedules: params.schedules?.map((schedule) => ({
15256
- duration: normalizeBuilderVestingScheduleDuration(
15257
- schedule.duration,
15258
- "Vesting schedule duration"
15259
- ),
15260
- cliffDuration: schedule.cliffDuration ?? 0
15261
- })),
15262
- scheduleIds: params.scheduleIds?.map(
15263
- (scheduleId, index) => normalizeBuilderScheduleId(scheduleId, `Vesting scheduleIds[${index}]`)
15264
- )
15230
+ amounts: params.amounts
15265
15231
  };
15266
15232
  return this;
15267
15233
  }