shared+supplier: per-script lovelace overrides for ref-script publish

Splits the single `lovelacePerOutput` param in publishReferenceScripts.ts
into `escrowLovelace` and `advertLovelace`, exposed via env vars
ESCROW_PUBLISH_LOVELACE / ADVERT_PUBLISH_LOVELACE in the CLI. Defaults
unchanged at 30 AP3X each (60 AP3X total).

Motivation: mainnet rollout where the publishing wallet has only ~57 AP3X
(buyer wallet) — needs to publish at calculated min-utxo (~17 AP3X escrow
+ ~7 AP3X advert = 24 AP3X total) instead of the safe 60 AP3X default.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
david
2026-05-14 17:47:10 +02:00
parent 1c852f3a68
commit aecf4861bc
2 changed files with 32 additions and 10 deletions

View File

@@ -26,9 +26,12 @@ export interface LivePublishRefScriptsParams {
burnAddr: string;
escrowScript: Script;
advertScript: Script;
/** Lovelace per output. Default 30_000_000n (30 AP3X) — covers min-UTxO for
* a ~5 KB script (4310 lovelace/byte × 5_140 bytes ≈ 22.2 AP3X) with headroom. */
lovelacePerOutput?: bigint;
/** Lovelace for the escrow output. Default 30_000_000n (30 AP3X). For tight
* budgets pass ~17_000_000n — escrow script is ~3.4 KB → ledger min ~15.7 AP3X. */
escrowLovelace?: bigint;
/** Lovelace for the advert output. Default 30_000_000n (30 AP3X). For tight
* budgets pass ~7_000_000n — advert script is ~1 KB → ledger min ~5.4 AP3X. */
advertLovelace?: bigint;
}
export interface PublishRefScriptsBuildResult extends BuildResult {
@@ -46,7 +49,8 @@ export async function buildLiveTxForPublishReferenceScripts(
params: LivePublishRefScriptsParams,
): Promise<PublishRefScriptsBuildResult> {
const { chain, walletKey, burnAddr, escrowScript, advertScript } = params;
const lovelacePerOutput = params.lovelacePerOutput ?? DEFAULT_LOVELACE_PER_OUTPUT;
const escrowLovelace = params.escrowLovelace ?? DEFAULT_LOVELACE_PER_OUTPUT;
const advertLovelace = params.advertLovelace ?? DEFAULT_LOVELACE_PER_OUTPUT;
const provider = new OgmiosLucidProvider({
ogmiosUrl: chain.url,
@@ -68,14 +72,14 @@ export async function buildLiveTxForPublishReferenceScripts(
.pay.ToAddressWithData(
burnAddr,
undefined,
{ lovelace: lovelacePerOutput },
{ lovelace: escrowLovelace },
escrowScript,
)
// Output 1: advert script reference.
.pay.ToAddressWithData(
burnAddr,
undefined,
{ lovelace: lovelacePerOutput },
{ lovelace: advertLovelace },
advertScript,
)
.addSignerKey(walletKey.pubKeyHash)

View File

@@ -9,10 +9,14 @@
* ADVERT_REF_UTXO=<txhash>#1
*
* Reads env (no flags):
* SUPPLIER_PRIV_KEY_HEX 64-hex Ed25519 private key
* OGMIOS_URL https:// or wss:// endpoint (HTTPS preferred)
* NETWORK_ID "0" (testnet) or "1" (mainnet)
* VECTOR_ZERO_TIME_MS optional, mainnet override; defaults to testnet genesis
* SUPPLIER_PRIV_KEY_HEX 64-hex Ed25519 private key (also accepts buyer
* key value if you want to fund publish from buyer
* wallet — env name stays the same internally)
* OGMIOS_URL https:// or wss:// endpoint (HTTPS preferred)
* NETWORK_ID "0" (testnet) or "1" (mainnet)
* VECTOR_ZERO_TIME_MS optional, mainnet override; defaults to testnet genesis
* ESCROW_PUBLISH_LOVELACE optional, lovelace for the escrow output (default 30_000_000)
* ADVERT_PUBLISH_LOVELACE optional, lovelace for the advert output (default 30_000_000)
*
* stdout (success):
* ESCROW_REF_UTXO=<txhash>#0
@@ -95,6 +99,16 @@ export async function main(env: Record<string, string | undefined>): Promise<num
}
const networkId: 0 | 1 = networkIdStr === "1" ? 1 : 0;
let escrowLovelace: bigint | undefined;
let advertLovelace: bigint | undefined;
try {
if (env.ESCROW_PUBLISH_LOVELACE) escrowLovelace = BigInt(env.ESCROW_PUBLISH_LOVELACE);
if (env.ADVERT_PUBLISH_LOVELACE) advertLovelace = BigInt(env.ADVERT_PUBLISH_LOVELACE);
} catch (err) {
process.stderr.write(`error: *_PUBLISH_LOVELACE must be integer lovelace, got: ${err instanceof Error ? err.message : String(err)}\n`);
return 1;
}
const walletKey = deriveWalletKey(privHex, networkId);
const burnAddr = pkhToEnterpriseAddress(ZERO_PKH_HEX, networkId);
const { script: escrowScript } = loadEscrowScript();
@@ -104,6 +118,8 @@ export async function main(env: Record<string, string | undefined>): Promise<num
process.stderr.write(`burn addr: ${burnAddr}\n`);
process.stderr.write(`ogmios: ${ogmiosUrl}\n`);
process.stderr.write(`network: ${networkId === 0 ? "testnet" : "mainnet"}\n`);
process.stderr.write(`escrow lovelace: ${escrowLovelace ?? "30000000 (default)"}\n`);
process.stderr.write(`advert lovelace: ${advertLovelace ?? "30000000 (default)"}\n`);
const chain = new LiveOgmiosProvider({ ogmiosUrl });
@@ -115,6 +131,8 @@ export async function main(env: Record<string, string | undefined>): Promise<num
burnAddr,
escrowScript,
advertScript,
escrowLovelace,
advertLovelace,
});
process.stderr.write(`submitted: ${result.expectedTxHash}\n`);
process.stdout.write(`ESCROW_REF_UTXO=${result.formattedEscrowRef}\n`);