@panal/sdk 0.18.1 → 0.18.2
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/client.d.ts +12 -1
- package/dist/client.js +29 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -436,7 +436,18 @@ export declare class PanalClient {
|
|
|
436
436
|
* ya están desplegados sin obligarles a actualizarse.
|
|
437
437
|
*/
|
|
438
438
|
private x402Endpoint;
|
|
439
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* Retira lo acreditado en una moneda (patrón pull payment).
|
|
441
|
+
*
|
|
442
|
+
* EL GAS VA FIJADO A MANO, y no es un detalle. viem no estima: le pide al nodo
|
|
443
|
+
* que rellene la transacción (`eth_fillTransaction`), y el de Monad devuelve
|
|
444
|
+
* un gas disparatado para retirar MON —1,05 M para una wallet, 10,7 M para
|
|
445
|
+
* otra— cuando lo necesario son 55.157. Monad cobra el LÍMITE entero, no lo
|
|
446
|
+
* usado: una retirada de 1,092 MON pagó 1,096 MON de gas (2026-09-14, tx
|
|
447
|
+
* 0xa960cb7e…). El gas sale de `eth_estimateGas`, que da el número bueno, con
|
|
448
|
+
* un 10 % de margen; y si la estimación vuelve por encima de `TOPE_GAS_RETIRADA`
|
|
449
|
+
* no se firma nada.
|
|
450
|
+
*/
|
|
440
451
|
withdraw(currency?: Address): Promise<Hex>;
|
|
441
452
|
/** Comprueba el saldo antes de firmar, para fallar con un mensaje legible. */
|
|
442
453
|
private assertFunds;
|
package/dist/client.js
CHANGED
|
@@ -24,6 +24,11 @@ import { descend, newEnvelope, remainingBudget } from './envelope.js';
|
|
|
24
24
|
import { NATIVE_CURRENCY, addressesFor, chainFor } from './chains.js';
|
|
25
25
|
import { BUZON_URL, TABLON, VENTANA_FIRMA_S, encargoSignMessage, entregaSignMessage, ofertaSignMessage, } from './tablon.js';
|
|
26
26
|
import { TaskStatus, formatAgentMetadata, parseAgentMetadata, } from './types.js';
|
|
27
|
+
/**
|
|
28
|
+
* Por encima de esto una retirada no se firma: retirar MON son 55.157 de gas y
|
|
29
|
+
* $PANAL 103.511. Ver `withdraw()` para lo que pasó sin este tope.
|
|
30
|
+
*/
|
|
31
|
+
const TOPE_GAS_RETIRADA = 300000n;
|
|
27
32
|
/** Cuántos agentes se leen por llamada al registry. */
|
|
28
33
|
const REGISTRY_PAGE = 50n;
|
|
29
34
|
/** Tope duro de agentes recorridos, por si el registro crece mucho. */
|
|
@@ -1045,18 +1050,39 @@ export class PanalClient {
|
|
|
1045
1050
|
}
|
|
1046
1051
|
return rutaDeAgente(base, 'x402/ask');
|
|
1047
1052
|
}
|
|
1048
|
-
/**
|
|
1053
|
+
/**
|
|
1054
|
+
* Retira lo acreditado en una moneda (patrón pull payment).
|
|
1055
|
+
*
|
|
1056
|
+
* EL GAS VA FIJADO A MANO, y no es un detalle. viem no estima: le pide al nodo
|
|
1057
|
+
* que rellene la transacción (`eth_fillTransaction`), y el de Monad devuelve
|
|
1058
|
+
* un gas disparatado para retirar MON —1,05 M para una wallet, 10,7 M para
|
|
1059
|
+
* otra— cuando lo necesario son 55.157. Monad cobra el LÍMITE entero, no lo
|
|
1060
|
+
* usado: una retirada de 1,092 MON pagó 1,096 MON de gas (2026-09-14, tx
|
|
1061
|
+
* 0xa960cb7e…). El gas sale de `eth_estimateGas`, que da el número bueno, con
|
|
1062
|
+
* un 10 % de margen; y si la estimación vuelve por encima de `TOPE_GAS_RETIRADA`
|
|
1063
|
+
* no se firma nada.
|
|
1064
|
+
*/
|
|
1049
1065
|
async withdraw(currency = NATIVE_CURRENCY) {
|
|
1050
1066
|
const wallet = this.wallet();
|
|
1051
|
-
const
|
|
1067
|
+
const llamada = {
|
|
1052
1068
|
address: this.addresses.escrow,
|
|
1053
1069
|
abi: escrowAbi,
|
|
1054
1070
|
functionName: 'withdraw',
|
|
1055
1071
|
args: [currency],
|
|
1072
|
+
};
|
|
1073
|
+
const estimado = await this.publicClient.estimateContractGas({ ...llamada, account: this.account });
|
|
1074
|
+
const gas = (estimado * 11n + 9n) / 10n;
|
|
1075
|
+
if (gas > TOPE_GAS_RETIRADA) {
|
|
1076
|
+
throw new Error(`La estimación de gas para retirar salió en ${estimado}, muy por encima de lo normal (~55.000 en MON, ` +
|
|
1077
|
+
`~104.000 en $PANAL). Monad cobra el límite entero: no se ha enviado nada.`);
|
|
1078
|
+
}
|
|
1079
|
+
const hash = await wallet.writeContract({
|
|
1080
|
+
...llamada,
|
|
1081
|
+
gas,
|
|
1056
1082
|
chain: chainFor(this.network),
|
|
1057
1083
|
account: this.account,
|
|
1058
1084
|
});
|
|
1059
|
-
await this.
|
|
1085
|
+
await this.esperarExito(hash, 'La retirada');
|
|
1060
1086
|
return hash;
|
|
1061
1087
|
}
|
|
1062
1088
|
/** Comprueba el saldo antes de firmar, para fallar con un mensaje legible. */
|