@strobelabs/perpcity-sdk 0.4.2 → 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 +21 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3631,7 +3631,17 @@ async function openTakerPosition(context, perpId, params) {
|
|
|
3631
3631
|
const notional = marginScaled * BigInt(NUMBER_1E6) / BigInt(marginRatio);
|
|
3632
3632
|
const totalFeeRate = creatorFee + insuranceFee + lpFee + protocolFeeRate;
|
|
3633
3633
|
const totalFees = BigInt(Math.ceil(Number(notional) * totalFeeRate));
|
|
3634
|
-
|
|
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
|
+
}
|
|
3635
3645
|
const unspecifiedAmountLimit = typeof params.unspecifiedAmountLimit === "bigint" ? params.unspecifiedAmountLimit : scale6Decimals(params.unspecifiedAmountLimit);
|
|
3636
3646
|
const contractParams = {
|
|
3637
3647
|
holder: context.walletClient.account.address,
|
|
@@ -3684,7 +3694,16 @@ async function openMakerPosition(context, perpId, params) {
|
|
|
3684
3694
|
const marginScaled = scale6Decimals(params.margin);
|
|
3685
3695
|
const maxAmt0InScaled = typeof params.maxAmt0In === "bigint" ? params.maxAmt0In : scale6Decimals(params.maxAmt0In);
|
|
3686
3696
|
const maxAmt1InScaled = typeof params.maxAmt1In === "bigint" ? params.maxAmt1In : scale6Decimals(params.maxAmt1In);
|
|
3687
|
-
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
|
+
}
|
|
3688
3707
|
const perpData = await context.getPerpData(perpId);
|
|
3689
3708
|
const tickLower = priceToTick(params.priceLower, true);
|
|
3690
3709
|
const tickUpper = priceToTick(params.priceUpper, false);
|