@strobelabs/perpcity-sdk 0.4.1 → 0.4.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 +32 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3619,8 +3619,29 @@ async function openTakerPosition(context, perpId, params) {
|
|
|
3619
3619
|
throw new Error("Leverage must be greater than 0");
|
|
3620
3620
|
}
|
|
3621
3621
|
const marginScaled = scale6Decimals(params.margin);
|
|
3622
|
-
await approveUsdc(context, marginScaled);
|
|
3623
3622
|
const marginRatio = Math.floor(NUMBER_1E6 / params.leverage);
|
|
3623
|
+
const perpData = await context.getPerpData(perpId);
|
|
3624
|
+
const { creatorFee, insuranceFee, lpFee } = perpData.fees;
|
|
3625
|
+
const protocolFeeRaw = await context.publicClient.readContract({
|
|
3626
|
+
address: context.deployments().perpManager,
|
|
3627
|
+
abi: PERP_MANAGER_ABI,
|
|
3628
|
+
functionName: "protocolFee"
|
|
3629
|
+
});
|
|
3630
|
+
const protocolFeeRate = Number(protocolFeeRaw) / NUMBER_1E6;
|
|
3631
|
+
const notional = marginScaled * BigInt(NUMBER_1E6) / BigInt(marginRatio);
|
|
3632
|
+
const totalFeeRate = creatorFee + insuranceFee + lpFee + protocolFeeRate;
|
|
3633
|
+
const totalFees = BigInt(Math.ceil(Number(notional) * totalFeeRate));
|
|
3634
|
+
const requiredAmount = marginScaled + totalFees;
|
|
3635
|
+
const currentAllowance = await context.publicClient.readContract({
|
|
3636
|
+
address: context.deployments().usdc,
|
|
3637
|
+
abi: import_viem5.erc20Abi,
|
|
3638
|
+
functionName: "allowance",
|
|
3639
|
+
args: [context.walletClient.account.address, context.deployments().perpManager],
|
|
3640
|
+
blockTag: "latest"
|
|
3641
|
+
});
|
|
3642
|
+
if (currentAllowance < requiredAmount) {
|
|
3643
|
+
await approveUsdc(context, requiredAmount);
|
|
3644
|
+
}
|
|
3624
3645
|
const unspecifiedAmountLimit = typeof params.unspecifiedAmountLimit === "bigint" ? params.unspecifiedAmountLimit : scale6Decimals(params.unspecifiedAmountLimit);
|
|
3625
3646
|
const contractParams = {
|
|
3626
3647
|
holder: context.walletClient.account.address,
|
|
@@ -3673,7 +3694,16 @@ async function openMakerPosition(context, perpId, params) {
|
|
|
3673
3694
|
const marginScaled = scale6Decimals(params.margin);
|
|
3674
3695
|
const maxAmt0InScaled = typeof params.maxAmt0In === "bigint" ? params.maxAmt0In : scale6Decimals(params.maxAmt0In);
|
|
3675
3696
|
const maxAmt1InScaled = typeof params.maxAmt1In === "bigint" ? params.maxAmt1In : scale6Decimals(params.maxAmt1In);
|
|
3676
|
-
await
|
|
3697
|
+
const currentAllowance = await context.publicClient.readContract({
|
|
3698
|
+
address: context.deployments().usdc,
|
|
3699
|
+
abi: import_viem5.erc20Abi,
|
|
3700
|
+
functionName: "allowance",
|
|
3701
|
+
args: [context.walletClient.account.address, context.deployments().perpManager],
|
|
3702
|
+
blockTag: "latest"
|
|
3703
|
+
});
|
|
3704
|
+
if (currentAllowance < marginScaled) {
|
|
3705
|
+
await approveUsdc(context, marginScaled);
|
|
3706
|
+
}
|
|
3677
3707
|
const perpData = await context.getPerpData(perpId);
|
|
3678
3708
|
const tickLower = priceToTick(params.priceLower, true);
|
|
3679
3709
|
const tickUpper = priceToTick(params.priceUpper, false);
|