@ostium/builder-sdk 0.3.0 → 0.3.1

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/index.d.cts CHANGED
@@ -191,7 +191,7 @@ interface CommonParams {
191
191
  slippageBps?: number;
192
192
  /**
193
193
  * Optional builder fee sharing.
194
- * `feeBps` is in basis points max 50 (0.5%).
194
+ * `feeBps` in basis points (e.g. 10 = 10 bps / 0.1%, 2.55 = 2.55 bps). Max 50 (0.5%), step 0.01 bps.
195
195
  */
196
196
  builder?: {
197
197
  address: Address;
package/dist/index.d.ts CHANGED
@@ -191,7 +191,7 @@ interface CommonParams {
191
191
  slippageBps?: number;
192
192
  /**
193
193
  * Optional builder fee sharing.
194
- * `feeBps` is in basis points max 50 (0.5%).
194
+ * `feeBps` in basis points (e.g. 10 = 10 bps / 0.1%, 2.55 = 2.55 bps). Max 50 (0.5%), step 0.01 bps.
195
195
  */
196
196
  builder?: {
197
197
  address: Address;
package/dist/index.js CHANGED
@@ -54,6 +54,32 @@ var ERC20_ABI = [
54
54
  }
55
55
  ];
56
56
 
57
+ // src/internal/builder-fee.ts
58
+ var MAX_BUILDER_FEE_BPS = 50;
59
+ var MIN_BUILDER_FEE_BPS_STEP = 0.01;
60
+ var MAX_BUILDER_FEE_CONTRACT = 5e5;
61
+ var BPS_TO_CONTRACT = 1e4;
62
+ function bpsToContractBuilderFee(feeBps) {
63
+ if (feeBps === 0) return 0n;
64
+ return BigInt(Math.round(feeBps * BPS_TO_CONTRACT));
65
+ }
66
+ function validateBuilderFeeBps(feeBps) {
67
+ if (!Number.isFinite(feeBps)) {
68
+ return "builder.feeBps must be a finite number";
69
+ }
70
+ if (feeBps < 0 || feeBps > MAX_BUILDER_FEE_BPS) {
71
+ return `builder.feeBps must be between 0 and ${MAX_BUILDER_FEE_BPS} (0%\u20130.5%)`;
72
+ }
73
+ const centiBps = Math.round(feeBps * 100);
74
+ if (Math.abs(feeBps * 100 - centiBps) > 1e-6) {
75
+ return `builder.feeBps must be a multiple of ${MIN_BUILDER_FEE_BPS_STEP} (0.01 bps)`;
76
+ }
77
+ if (bpsToContractBuilderFee(feeBps) > MAX_BUILDER_FEE_CONTRACT) {
78
+ return "builder.feeBps exceeds on-chain maximum (0.5%)";
79
+ }
80
+ return null;
81
+ }
82
+
57
83
  // src/internal/decimal.ts
58
84
  function parseUsdc(amount) {
59
85
  const amountStr = typeof amount === "number" ? amount.toString() : amount;
@@ -212,7 +238,7 @@ function buildBuilderFee(builder) {
212
238
  }
213
239
  return {
214
240
  builder: builder.b,
215
- builderFee: BigInt(builder.f)
241
+ builderFee: bpsToContractBuilderFee(builder.f)
216
242
  };
217
243
  }
218
244
 
@@ -4348,11 +4374,11 @@ function validateConfig(config) {
4348
4374
  "INVALID_CONFIG" /* INVALID_CONFIG */
4349
4375
  );
4350
4376
  }
4351
- if (config.builder !== void 0 && (config.builder.feeBps < 0 || config.builder.feeBps > 50)) {
4352
- throw new OstiumError(
4353
- "builder.feeBps must be between 0 and 50 (max 0.5%)",
4354
- "INVALID_CONFIG" /* INVALID_CONFIG */
4355
- );
4377
+ if (config.builder !== void 0) {
4378
+ const feeError = validateBuilderFeeBps(config.builder.feeBps);
4379
+ if (feeError) {
4380
+ throw new OstiumError(feeError, "INVALID_CONFIG" /* INVALID_CONFIG */);
4381
+ }
4356
4382
  }
4357
4383
  let mode;
4358
4384
  try {