@parallel-protocol/cli 0.2.2 → 0.2.3
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.js +60 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8068,6 +8068,15 @@ var PREVIEW_WITHDRAW_ABI = [
|
|
|
8068
8068
|
outputs: [{ type: "uint256" }]
|
|
8069
8069
|
}
|
|
8070
8070
|
];
|
|
8071
|
+
var PREVIEW_MINT_ABI = [
|
|
8072
|
+
{
|
|
8073
|
+
name: "previewMint",
|
|
8074
|
+
type: "function",
|
|
8075
|
+
stateMutability: "view",
|
|
8076
|
+
inputs: [{ type: "uint256", name: "shares" }],
|
|
8077
|
+
outputs: [{ type: "uint256" }]
|
|
8078
|
+
}
|
|
8079
|
+
];
|
|
8071
8080
|
function buildTiming() {
|
|
8072
8081
|
const now = BigInt(Math.floor(Date.now() / 1e3));
|
|
8073
8082
|
return { validAfter: now - 60n, validBefore: now + 300n };
|
|
@@ -8075,8 +8084,21 @@ function buildTiming() {
|
|
|
8075
8084
|
function slippageUp(amount) {
|
|
8076
8085
|
return amount + amount * SLIPPAGE_BPS / 10000n;
|
|
8077
8086
|
}
|
|
8078
|
-
function
|
|
8079
|
-
return
|
|
8087
|
+
async function previewMintAssets(chain, susdp, shares) {
|
|
8088
|
+
return await getClient(chain).readContract({
|
|
8089
|
+
address: susdp,
|
|
8090
|
+
abi: PREVIEW_MINT_ABI,
|
|
8091
|
+
functionName: "previewMint",
|
|
8092
|
+
args: [shares]
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
async function previewWithdrawShares(chain, susdp, assets) {
|
|
8096
|
+
return await getClient(chain).readContract({
|
|
8097
|
+
address: susdp,
|
|
8098
|
+
abi: PREVIEW_WITHDRAW_ABI,
|
|
8099
|
+
functionName: "previewWithdraw",
|
|
8100
|
+
args: [assets]
|
|
8101
|
+
});
|
|
8080
8102
|
}
|
|
8081
8103
|
async function readTokenDomain(chain, token) {
|
|
8082
8104
|
return readTokenDomainFull(chain, token);
|
|
@@ -8216,15 +8238,6 @@ async function quoteSwapOut(chain, amountOut, tokenIn, tokenOut) {
|
|
|
8216
8238
|
args: [amountOut, tokenIn, tokenOut]
|
|
8217
8239
|
});
|
|
8218
8240
|
}
|
|
8219
|
-
async function quoteSwapIn(chain, amountIn, tokenIn, tokenOut) {
|
|
8220
|
-
const parallelizer = getParallelizerAddress(chain);
|
|
8221
|
-
return await getClient(chain).readContract({
|
|
8222
|
-
address: parallelizer,
|
|
8223
|
-
abi: PARALLELIZER_ABI,
|
|
8224
|
-
functionName: "quoteIn",
|
|
8225
|
-
args: [amountIn, tokenIn, tokenOut]
|
|
8226
|
-
});
|
|
8227
|
-
}
|
|
8228
8241
|
async function prepareRouteA(chain, senderAddress, amount, recipient) {
|
|
8229
8242
|
const usdpAddress = getUSDpAddress(chain);
|
|
8230
8243
|
if (!usdpAddress) throw new Error(`USDp not deployed on ${chain}`);
|
|
@@ -8375,13 +8388,15 @@ async function prepareRouteC(chain, senderAddress, amount, recipient) {
|
|
|
8375
8388
|
const susdpAddress = getSUSDpAddress(chain);
|
|
8376
8389
|
if (!usdpAddress) throw new Error(`USDp not deployed on ${chain}`);
|
|
8377
8390
|
if (!susdpAddress) throw new Error(`sUSDp not deployed on ${chain}`);
|
|
8378
|
-
const
|
|
8391
|
+
const sharesWei = parseUnits(amount, 18);
|
|
8379
8392
|
const { validAfter, validBefore } = buildTiming();
|
|
8380
8393
|
const sharedNonce = generateNonce();
|
|
8381
|
-
const [susdpDomain, usdpDomain] = await Promise.all([
|
|
8394
|
+
const [assetsNeeded, susdpDomain, usdpDomain] = await Promise.all([
|
|
8395
|
+
previewMintAssets(chain, susdpAddress, sharesWei),
|
|
8382
8396
|
readTokenDomain(chain, susdpAddress),
|
|
8383
8397
|
readTokenDomain(chain, usdpAddress)
|
|
8384
8398
|
]);
|
|
8399
|
+
const amountWei = slippageUp(assetsNeeded);
|
|
8385
8400
|
const depositTd = buildDepositTypedData(susdpDomain, {
|
|
8386
8401
|
vault: susdpAddress,
|
|
8387
8402
|
owner: senderAddress,
|
|
@@ -8410,7 +8425,9 @@ async function prepareRouteC(chain, senderAddress, amount, recipient) {
|
|
|
8410
8425
|
route: "C",
|
|
8411
8426
|
steps: [
|
|
8412
8427
|
{
|
|
8413
|
-
label: "
|
|
8428
|
+
// Steps are keyed by label: "signature" is the payload's required
|
|
8429
|
+
// signature ("depositSignature" is Route G's extra deposit sig).
|
|
8430
|
+
label: "signature",
|
|
8414
8431
|
description: "DepositWithAuthorization on sUSDp domain",
|
|
8415
8432
|
messageHash: sig1MessageHash,
|
|
8416
8433
|
typedData: depositTd
|
|
@@ -8589,14 +8606,19 @@ async function prepareRouteG(chain, senderAddress, amount, recipient) {
|
|
|
8589
8606
|
if (!usdcAddress) throw new Error(`USDC not configured on ${chain}`);
|
|
8590
8607
|
if (!susdpAddress) throw new Error(`sUSDp not deployed on ${chain}`);
|
|
8591
8608
|
const parallelizer = getParallelizerAddress(chain);
|
|
8592
|
-
const
|
|
8593
|
-
const
|
|
8594
|
-
chain,
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8609
|
+
const sharesWei = parseUnits(amount, 18);
|
|
8610
|
+
const domainsPromise = Promise.all([
|
|
8611
|
+
readTokenDomain(chain, usdcAddress),
|
|
8612
|
+
readTokenDomain(chain, susdpAddress),
|
|
8613
|
+
readTokenDomain(chain, usdpAddress)
|
|
8614
|
+
]);
|
|
8615
|
+
domainsPromise.catch(() => {
|
|
8616
|
+
});
|
|
8617
|
+
const usdpNeeded = await previewMintAssets(chain, susdpAddress, sharesWei);
|
|
8618
|
+
const amountOutMin = slippageUp(usdpNeeded);
|
|
8619
|
+
const amountInWei = slippageUp(
|
|
8620
|
+
await quoteSwapOut(chain, amountOutMin, usdcAddress, usdpAddress)
|
|
8598
8621
|
);
|
|
8599
|
-
const amountOutMin = slippageDown(expectedUSDpOut);
|
|
8600
8622
|
const { validAfter, validBefore } = buildTiming();
|
|
8601
8623
|
const swapUserSalt = generateNonce();
|
|
8602
8624
|
const depositNonce = generateNonce();
|
|
@@ -8611,11 +8633,7 @@ async function prepareRouteG(chain, senderAddress, amount, recipient) {
|
|
|
8611
8633
|
// swap recipient = payer, not merchant
|
|
8612
8634
|
validBefore
|
|
8613
8635
|
);
|
|
8614
|
-
const [usdcDomain, susdpDomain, usdpDomain] = await
|
|
8615
|
-
readTokenDomain(chain, usdcAddress),
|
|
8616
|
-
readTokenDomain(chain, susdpAddress),
|
|
8617
|
-
readTokenDomain(chain, usdpAddress)
|
|
8618
|
-
]);
|
|
8636
|
+
const [usdcDomain, susdpDomain, usdpDomain] = await domainsPromise;
|
|
8619
8637
|
const swapTd = buildReceiveAuthorizationTypedData(usdcDomain, {
|
|
8620
8638
|
from: senderAddress,
|
|
8621
8639
|
to: parallelizer,
|
|
@@ -8704,8 +8722,8 @@ async function prepareRouteG(chain, senderAddress, amount, recipient) {
|
|
|
8704
8722
|
}
|
|
8705
8723
|
},
|
|
8706
8724
|
quote: {
|
|
8707
|
-
amountIn:
|
|
8708
|
-
amountOut:
|
|
8725
|
+
amountIn: formatUnits(amountInWei, 6),
|
|
8726
|
+
amountOut: amount,
|
|
8709
8727
|
slippageBps: Number(SLIPPAGE_BPS)
|
|
8710
8728
|
},
|
|
8711
8729
|
gasEstimate: 2e5
|
|
@@ -8714,10 +8732,13 @@ async function prepareRouteG(chain, senderAddress, amount, recipient) {
|
|
|
8714
8732
|
async function prepareRouteH(chain, senderAddress, amount, recipient) {
|
|
8715
8733
|
const susdpAddress = getSUSDpAddress(chain);
|
|
8716
8734
|
if (!susdpAddress) throw new Error(`sUSDp not deployed on ${chain}`);
|
|
8717
|
-
const
|
|
8735
|
+
const assetsWei = parseUnits(amount, 18);
|
|
8718
8736
|
const { validAfter, validBefore } = buildTiming();
|
|
8719
8737
|
const nonce = generateNonce();
|
|
8720
|
-
const susdpDomain = await
|
|
8738
|
+
const [sharesWei, susdpDomain] = await Promise.all([
|
|
8739
|
+
previewWithdrawShares(chain, susdpAddress, assetsWei),
|
|
8740
|
+
readTokenDomain(chain, susdpAddress)
|
|
8741
|
+
]);
|
|
8721
8742
|
const redeemTd = buildRedeemTypedData(susdpDomain, {
|
|
8722
8743
|
vault: susdpAddress,
|
|
8723
8744
|
owner: senderAddress,
|
|
@@ -9182,10 +9203,12 @@ async function preparePayment(params) {
|
|
|
9182
9203
|
const { chain, amount } = params;
|
|
9183
9204
|
const sender = params.senderAddress;
|
|
9184
9205
|
const recv = params.recipient;
|
|
9185
|
-
const target = params.targetToken;
|
|
9186
9206
|
const tokenIn = params.tokenIn ?? "usdp";
|
|
9207
|
+
const usdpAddress = getUSDpAddress(chain);
|
|
9208
|
+
const target = params.targetToken ?? usdpAddress;
|
|
9209
|
+
const wantsUSDp = !target || !!usdpAddress && target.toLowerCase() === usdpAddress.toLowerCase();
|
|
9187
9210
|
if (tokenIn === "usdp") {
|
|
9188
|
-
if (!target) return prepareRouteA(chain, sender, amount, recv);
|
|
9211
|
+
if (!target || wantsUSDp) return prepareRouteA(chain, sender, amount, recv);
|
|
9189
9212
|
const susdpAddress = getSUSDpAddress(chain);
|
|
9190
9213
|
if (susdpAddress && target.toLowerCase() === susdpAddress.toLowerCase()) {
|
|
9191
9214
|
return prepareRouteC(chain, sender, amount, recv);
|
|
@@ -9199,13 +9222,10 @@ async function preparePayment(params) {
|
|
|
9199
9222
|
if (tokenIn === "usdc") {
|
|
9200
9223
|
const usdcAddress = getUSDCAddress(chain);
|
|
9201
9224
|
if (!usdcAddress) throw new Error(`USDC not configured on ${chain}`);
|
|
9202
|
-
if (!target ||
|
|
9225
|
+
if (!target || wantsUSDp) return prepareRouteE(chain, sender, amount, recv);
|
|
9226
|
+
if (target.toLowerCase() === usdcAddress.toLowerCase()) {
|
|
9203
9227
|
return prepareRouteF(chain, sender, amount, recv);
|
|
9204
9228
|
}
|
|
9205
|
-
const usdpAddress = getUSDpAddress(chain);
|
|
9206
|
-
if (usdpAddress && target.toLowerCase() === usdpAddress.toLowerCase()) {
|
|
9207
|
-
return prepareRouteE(chain, sender, amount, recv);
|
|
9208
|
-
}
|
|
9209
9229
|
const susdpAddress = getSUSDpAddress(chain);
|
|
9210
9230
|
if (susdpAddress && target.toLowerCase() === susdpAddress.toLowerCase()) {
|
|
9211
9231
|
return prepareRouteG(chain, sender, amount, recv);
|
|
@@ -9217,13 +9237,10 @@ async function preparePayment(params) {
|
|
|
9217
9237
|
if (tokenIn === "susdp") {
|
|
9218
9238
|
const susdpAddress = getSUSDpAddress(chain);
|
|
9219
9239
|
if (!susdpAddress) throw new Error(`sUSDp not deployed on ${chain}`);
|
|
9220
|
-
if (!target ||
|
|
9240
|
+
if (!target || wantsUSDp) return prepareRouteH(chain, sender, amount, recv);
|
|
9241
|
+
if (target.toLowerCase() === susdpAddress.toLowerCase()) {
|
|
9221
9242
|
return prepareRouteJ(chain, sender, amount, recv);
|
|
9222
9243
|
}
|
|
9223
|
-
const usdpAddress = getUSDpAddress(chain);
|
|
9224
|
-
if (usdpAddress && target.toLowerCase() === usdpAddress.toLowerCase()) {
|
|
9225
|
-
return prepareRouteH(chain, sender, amount, recv);
|
|
9226
|
-
}
|
|
9227
9244
|
const usdcAddressForI = getUSDCAddress(chain);
|
|
9228
9245
|
if (usdcAddressForI && target.toLowerCase() === usdcAddressForI.toLowerCase()) {
|
|
9229
9246
|
return prepareRouteI(chain, sender, amount, recv, target);
|
|
@@ -14561,7 +14578,7 @@ var package_default = {
|
|
|
14561
14578
|
|
|
14562
14579
|
// package.json
|
|
14563
14580
|
var package_default2 = {
|
|
14564
|
-
version: "0.2.
|
|
14581
|
+
version: "0.2.3"};
|
|
14565
14582
|
|
|
14566
14583
|
// src/commands/version.ts
|
|
14567
14584
|
function versionCommand() {
|