@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/cli.js +32 -6
- package/dist/index.cjs +32 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -59,6 +59,32 @@ var ERC20_ABI = [
|
|
|
59
59
|
}
|
|
60
60
|
];
|
|
61
61
|
|
|
62
|
+
// src/internal/builder-fee.ts
|
|
63
|
+
var MAX_BUILDER_FEE_BPS = 50;
|
|
64
|
+
var MIN_BUILDER_FEE_BPS_STEP = 0.01;
|
|
65
|
+
var MAX_BUILDER_FEE_CONTRACT = 5e5;
|
|
66
|
+
var BPS_TO_CONTRACT = 1e4;
|
|
67
|
+
function bpsToContractBuilderFee(feeBps) {
|
|
68
|
+
if (feeBps === 0) return 0n;
|
|
69
|
+
return BigInt(Math.round(feeBps * BPS_TO_CONTRACT));
|
|
70
|
+
}
|
|
71
|
+
function validateBuilderFeeBps(feeBps) {
|
|
72
|
+
if (!Number.isFinite(feeBps)) {
|
|
73
|
+
return "builder.feeBps must be a finite number";
|
|
74
|
+
}
|
|
75
|
+
if (feeBps < 0 || feeBps > MAX_BUILDER_FEE_BPS) {
|
|
76
|
+
return `builder.feeBps must be between 0 and ${MAX_BUILDER_FEE_BPS} (0%\u20130.5%)`;
|
|
77
|
+
}
|
|
78
|
+
const centiBps = Math.round(feeBps * 100);
|
|
79
|
+
if (Math.abs(feeBps * 100 - centiBps) > 1e-6) {
|
|
80
|
+
return `builder.feeBps must be a multiple of ${MIN_BUILDER_FEE_BPS_STEP} (0.01 bps)`;
|
|
81
|
+
}
|
|
82
|
+
if (bpsToContractBuilderFee(feeBps) > MAX_BUILDER_FEE_CONTRACT) {
|
|
83
|
+
return "builder.feeBps exceeds on-chain maximum (0.5%)";
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
// src/internal/decimal.ts
|
|
63
89
|
function parseUsdc(amount) {
|
|
64
90
|
const amountStr = typeof amount === "number" ? amount.toString() : amount;
|
|
@@ -215,7 +241,7 @@ function buildBuilderFee(builder) {
|
|
|
215
241
|
}
|
|
216
242
|
return {
|
|
217
243
|
builder: builder.b,
|
|
218
|
-
builderFee:
|
|
244
|
+
builderFee: bpsToContractBuilderFee(builder.f)
|
|
219
245
|
};
|
|
220
246
|
}
|
|
221
247
|
|
|
@@ -4327,11 +4353,11 @@ function validateConfig(config) {
|
|
|
4327
4353
|
"INVALID_CONFIG" /* INVALID_CONFIG */
|
|
4328
4354
|
);
|
|
4329
4355
|
}
|
|
4330
|
-
if (config.builder !== void 0
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
"INVALID_CONFIG" /* INVALID_CONFIG */
|
|
4334
|
-
|
|
4356
|
+
if (config.builder !== void 0) {
|
|
4357
|
+
const feeError = validateBuilderFeeBps(config.builder.feeBps);
|
|
4358
|
+
if (feeError) {
|
|
4359
|
+
throw new OstiumError(feeError, "INVALID_CONFIG" /* INVALID_CONFIG */);
|
|
4360
|
+
}
|
|
4335
4361
|
}
|
|
4336
4362
|
let mode;
|
|
4337
4363
|
try {
|
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,32 @@ var ERC20_ABI = [
|
|
|
60
60
|
}
|
|
61
61
|
];
|
|
62
62
|
|
|
63
|
+
// src/internal/builder-fee.ts
|
|
64
|
+
var MAX_BUILDER_FEE_BPS = 50;
|
|
65
|
+
var MIN_BUILDER_FEE_BPS_STEP = 0.01;
|
|
66
|
+
var MAX_BUILDER_FEE_CONTRACT = 5e5;
|
|
67
|
+
var BPS_TO_CONTRACT = 1e4;
|
|
68
|
+
function bpsToContractBuilderFee(feeBps) {
|
|
69
|
+
if (feeBps === 0) return 0n;
|
|
70
|
+
return BigInt(Math.round(feeBps * BPS_TO_CONTRACT));
|
|
71
|
+
}
|
|
72
|
+
function validateBuilderFeeBps(feeBps) {
|
|
73
|
+
if (!Number.isFinite(feeBps)) {
|
|
74
|
+
return "builder.feeBps must be a finite number";
|
|
75
|
+
}
|
|
76
|
+
if (feeBps < 0 || feeBps > MAX_BUILDER_FEE_BPS) {
|
|
77
|
+
return `builder.feeBps must be between 0 and ${MAX_BUILDER_FEE_BPS} (0%\u20130.5%)`;
|
|
78
|
+
}
|
|
79
|
+
const centiBps = Math.round(feeBps * 100);
|
|
80
|
+
if (Math.abs(feeBps * 100 - centiBps) > 1e-6) {
|
|
81
|
+
return `builder.feeBps must be a multiple of ${MIN_BUILDER_FEE_BPS_STEP} (0.01 bps)`;
|
|
82
|
+
}
|
|
83
|
+
if (bpsToContractBuilderFee(feeBps) > MAX_BUILDER_FEE_CONTRACT) {
|
|
84
|
+
return "builder.feeBps exceeds on-chain maximum (0.5%)";
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
63
89
|
// src/internal/decimal.ts
|
|
64
90
|
function parseUsdc(amount) {
|
|
65
91
|
const amountStr = typeof amount === "number" ? amount.toString() : amount;
|
|
@@ -218,7 +244,7 @@ function buildBuilderFee(builder) {
|
|
|
218
244
|
}
|
|
219
245
|
return {
|
|
220
246
|
builder: builder.b,
|
|
221
|
-
builderFee:
|
|
247
|
+
builderFee: bpsToContractBuilderFee(builder.f)
|
|
222
248
|
};
|
|
223
249
|
}
|
|
224
250
|
|
|
@@ -4354,11 +4380,11 @@ function validateConfig(config) {
|
|
|
4354
4380
|
"INVALID_CONFIG" /* INVALID_CONFIG */
|
|
4355
4381
|
);
|
|
4356
4382
|
}
|
|
4357
|
-
if (config.builder !== void 0
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
"INVALID_CONFIG" /* INVALID_CONFIG */
|
|
4361
|
-
|
|
4383
|
+
if (config.builder !== void 0) {
|
|
4384
|
+
const feeError = validateBuilderFeeBps(config.builder.feeBps);
|
|
4385
|
+
if (feeError) {
|
|
4386
|
+
throw new OstiumError(feeError, "INVALID_CONFIG" /* INVALID_CONFIG */);
|
|
4387
|
+
}
|
|
4362
4388
|
}
|
|
4363
4389
|
let mode;
|
|
4364
4390
|
try {
|