@blazephoenix/sdk 1.2.1 → 1.3.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/README.md +17 -6
- package/dist/index.cjs +21 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +21 -6
- package/dist/index.js.map +1 -1
- package/llms.txt +3 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -201,6 +201,13 @@ interface SwapRequest extends QuoteRequest {
|
|
|
201
201
|
recipient: Address;
|
|
202
202
|
/** The account that will send the swap — enables the allowance check and simulation. */
|
|
203
203
|
from?: Address;
|
|
204
|
+
/** With `from`: eth_call the built swap from that account before returning it, and fail closed
|
|
205
|
+
* (`not_executable`, no plan) on a revert. The Quoter's `canExecute` is swap math; whether these
|
|
206
|
+
* bytes settle for the payer is answered only by that call.
|
|
207
|
+
* Exception: while the Router still needs its approval, no eth_call is made. The plan comes back
|
|
208
|
+
* with `simulation: { ok: false, error.name: 'allowance' }`; send the approval, then `simulate()`
|
|
209
|
+
* again from the payer before sending the swap (`execute()` does this). */
|
|
210
|
+
simulate?: boolean;
|
|
204
211
|
/** Default 50 (0.5%). minOut = netOut − slippage, never below the on-chain floor. */
|
|
205
212
|
slippageBps?: number;
|
|
206
213
|
/** Seconds from now (default 120, 10–3600) — or pass an absolute `deadline`. */
|
|
@@ -234,6 +241,11 @@ interface ApprovalStep {
|
|
|
234
241
|
}
|
|
235
242
|
interface SwapPlan {
|
|
236
243
|
quote: Quote;
|
|
244
|
+
/** Present when built with `simulate: true`. Either the Router's eth_call from `from` settled
|
|
245
|
+
* (`ok: true`, `amountOut`), or no eth_call was made because the approval is still missing
|
|
246
|
+
* (`ok: false`, `error.name: 'allowance'`): approve, then `simulate()` again. A revert never
|
|
247
|
+
* reaches here; it is thrown as `not_executable`. */
|
|
248
|
+
simulation?: SimulationResult;
|
|
237
249
|
entry: 'swapExactIn' | 'swapExactInNative' | 'swapBestExactIn';
|
|
238
250
|
/** 'quoter': the bytes are the Quoter's own previewAndEncode output (2.x),
|
|
239
251
|
* verified field-by-field against what you asked; 'sdk': encoded locally. */
|
|
@@ -249,7 +261,7 @@ interface SwapPlan {
|
|
|
249
261
|
unwrapAfter: boolean;
|
|
250
262
|
/** Ordered transactions to send: [approval?, swap]. */
|
|
251
263
|
steps: TxRequest[];
|
|
252
|
-
/** With `exact: true`: the previewPlanExact output
|
|
264
|
+
/** With `exact: true`: the NET previewPlanExact output used to derive `minOut`. */
|
|
253
265
|
exactOut?: bigint;
|
|
254
266
|
}
|
|
255
267
|
interface SimulationResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -201,6 +201,13 @@ interface SwapRequest extends QuoteRequest {
|
|
|
201
201
|
recipient: Address;
|
|
202
202
|
/** The account that will send the swap — enables the allowance check and simulation. */
|
|
203
203
|
from?: Address;
|
|
204
|
+
/** With `from`: eth_call the built swap from that account before returning it, and fail closed
|
|
205
|
+
* (`not_executable`, no plan) on a revert. The Quoter's `canExecute` is swap math; whether these
|
|
206
|
+
* bytes settle for the payer is answered only by that call.
|
|
207
|
+
* Exception: while the Router still needs its approval, no eth_call is made. The plan comes back
|
|
208
|
+
* with `simulation: { ok: false, error.name: 'allowance' }`; send the approval, then `simulate()`
|
|
209
|
+
* again from the payer before sending the swap (`execute()` does this). */
|
|
210
|
+
simulate?: boolean;
|
|
204
211
|
/** Default 50 (0.5%). minOut = netOut − slippage, never below the on-chain floor. */
|
|
205
212
|
slippageBps?: number;
|
|
206
213
|
/** Seconds from now (default 120, 10–3600) — or pass an absolute `deadline`. */
|
|
@@ -234,6 +241,11 @@ interface ApprovalStep {
|
|
|
234
241
|
}
|
|
235
242
|
interface SwapPlan {
|
|
236
243
|
quote: Quote;
|
|
244
|
+
/** Present when built with `simulate: true`. Either the Router's eth_call from `from` settled
|
|
245
|
+
* (`ok: true`, `amountOut`), or no eth_call was made because the approval is still missing
|
|
246
|
+
* (`ok: false`, `error.name: 'allowance'`): approve, then `simulate()` again. A revert never
|
|
247
|
+
* reaches here; it is thrown as `not_executable`. */
|
|
248
|
+
simulation?: SimulationResult;
|
|
237
249
|
entry: 'swapExactIn' | 'swapExactInNative' | 'swapBestExactIn';
|
|
238
250
|
/** 'quoter': the bytes are the Quoter's own previewAndEncode output (2.x),
|
|
239
251
|
* verified field-by-field against what you asked; 'sdk': encoded locally. */
|
|
@@ -249,7 +261,7 @@ interface SwapPlan {
|
|
|
249
261
|
unwrapAfter: boolean;
|
|
250
262
|
/** Ordered transactions to send: [approval?, swap]. */
|
|
251
263
|
steps: TxRequest[];
|
|
252
|
-
/** With `exact: true`: the previewPlanExact output
|
|
264
|
+
/** With `exact: true`: the NET previewPlanExact output used to derive `minOut`. */
|
|
253
265
|
exactOut?: bigint;
|
|
254
266
|
}
|
|
255
267
|
interface SimulationResult {
|
package/dist/index.js
CHANGED
|
@@ -5161,9 +5161,9 @@ var EMBEDDED_DEPLOYMENTS = {
|
|
|
5161
5161
|
{
|
|
5162
5162
|
version: "2.0.0",
|
|
5163
5163
|
status: "pending",
|
|
5164
|
-
source: "blazephoenixxyz-crypto/Blaze-Phoenix-Dex@
|
|
5164
|
+
source: "blazephoenixxyz-crypto/Blaze-Phoenix-Dex@f746a48",
|
|
5165
5165
|
notes: "Final generation (Core/Hub/Solver/Quoter/Router). Addresses arrive through the registry the day they are deployed.",
|
|
5166
|
-
chains: { 8453: pending(),
|
|
5166
|
+
chains: { 8453: pending(), 10: pending(), 42161: pending(), 4663: pending() }
|
|
5167
5167
|
},
|
|
5168
5168
|
{
|
|
5169
5169
|
version: "1.0.0",
|
|
@@ -5656,6 +5656,9 @@ function fromBaseUnits(v, decimals, maxDp) {
|
|
|
5656
5656
|
var HEX_ADDR2 = /^0x[0-9a-fA-F]{40}$/;
|
|
5657
5657
|
var INT = /^\d{1,78}$/;
|
|
5658
5658
|
var UINT128_MAX = (1n << 128n) - 1n;
|
|
5659
|
+
function netExactOutput(version, exactOut) {
|
|
5660
|
+
return featuresOf(version).previewAndEncode ? exactOut : exactOut - (exactOut * BigInt(FEE_BPS) + 9999n) / 10000n;
|
|
5661
|
+
}
|
|
5659
5662
|
var BlazePhoenix = class {
|
|
5660
5663
|
registry;
|
|
5661
5664
|
rpc;
|
|
@@ -5935,7 +5938,7 @@ var BlazePhoenix = class {
|
|
|
5935
5938
|
args: [tIn.address, tOut.address, amountIn],
|
|
5936
5939
|
...req.blockNumber !== void 0 ? { blockNumber: req.blockNumber } : {}
|
|
5937
5940
|
});
|
|
5938
|
-
const net =
|
|
5941
|
+
const net = netExactOutput(ctx.dep.version, exactOut);
|
|
5939
5942
|
return {
|
|
5940
5943
|
chainId: ctx.chainId,
|
|
5941
5944
|
version: ctx.dep.version,
|
|
@@ -6078,8 +6081,8 @@ var BlazePhoenix = class {
|
|
|
6078
6081
|
if (!samePath(ex[0], route)) {
|
|
6079
6082
|
throw new BlazeError("calldata_mismatch", "previewPlanExact priced a different route than the one to execute");
|
|
6080
6083
|
}
|
|
6081
|
-
exactOut = ex[1];
|
|
6082
|
-
return
|
|
6084
|
+
exactOut = netExactOutput(ctx.dep.version, ex[1]);
|
|
6085
|
+
return exactOut;
|
|
6083
6086
|
};
|
|
6084
6087
|
const settleMin = async (p) => {
|
|
6085
6088
|
let floor = minOutFor(p.netOut, slippageBps, p.ironFloor);
|
|
@@ -6179,7 +6182,7 @@ var BlazePhoenix = class {
|
|
|
6179
6182
|
}
|
|
6180
6183
|
}
|
|
6181
6184
|
const quote = this.buildQuote(ctx, tIn, tOut, amountIn, pv, fb);
|
|
6182
|
-
|
|
6185
|
+
const plan = {
|
|
6183
6186
|
quote,
|
|
6184
6187
|
entry,
|
|
6185
6188
|
encodedBy,
|
|
@@ -6193,6 +6196,18 @@ var BlazePhoenix = class {
|
|
|
6193
6196
|
steps: approval ? [approval.tx, tx] : [tx],
|
|
6194
6197
|
...exactOut !== void 0 ? { exactOut } : {}
|
|
6195
6198
|
};
|
|
6199
|
+
if (!req.simulate) return plan;
|
|
6200
|
+
if (!from) throw new BlazeError("bad_request", "simulate: true needs `from` (the account that will send the swap)");
|
|
6201
|
+
const simulation = await this.simulate(plan, from);
|
|
6202
|
+
if (!simulation.ok && simulation.error?.name !== "allowance") {
|
|
6203
|
+
const err = simulation.error;
|
|
6204
|
+
throw new BlazeError(
|
|
6205
|
+
"not_executable",
|
|
6206
|
+
`the Router refuses these bytes from ${from}: ${err?.name ?? "revert"}${err?.code !== void 0 ? `(${err.code})` : ""} \u2014 ${err?.reason ?? "execution reverted"}`,
|
|
6207
|
+
{ details: { from, error: err } }
|
|
6208
|
+
);
|
|
6209
|
+
}
|
|
6210
|
+
return { ...plan, simulation };
|
|
6196
6211
|
}
|
|
6197
6212
|
/** eth_call the swap from `from` on your RPC: the realised amountOut if it
|
|
6198
6213
|
* would settle now, or the decoded reason it would revert. */
|