Skip to content

Commit 04a8a44

Browse files
authored
checking for allowance before approval (#118)
1 parent 8bd4511 commit 04a8a44

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

spot-contracts/tasks/mainnet.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ yarn hardhat --network mainnet transferOwnership "0x2978B4103985A6668CE345555b0f
4747
yarn hardhat --network mainnet ops:info 0xC1f33e0cf7e40a67375007104B929E49a581bafE
4848

4949
# test ops
50+
yarn hardhat --network mainnet ops:updateState 0xC1f33e0cf7e40a67375007104B929E49a581bafE
51+
5052
yarn hardhat --network mainnet ops:trancheAndDeposit \
5153
--router-address 0x38f600e08540178719BF656e6B43FC15A529c393 \
5254
--perp-address 0xC1f33e0cf7e40a67375007104B929E49a581bafE \

spot-contracts/tasks/ops/perp.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,12 @@ task("ops:trancheAndDeposit")
204204
console.log("Signer", signerAddress);
205205

206206
console.log("Approving router to spend tokens:");
207-
const tx1 = await collateralToken.connect(signer).approve(router.address, fixedPtCollateralAmount);
208-
await tx1.wait();
209-
console.log("Tx", tx1.hash);
207+
const allowance = await collateralToken.allowance(signerAddress, router.address);
208+
if (allowance.lt(fixedPtCollateralAmount)) {
209+
const tx1 = await collateralToken.connect(signer).approve(router.address, fixedPtCollateralAmount);
210+
await tx1.wait();
211+
console.log("Tx", tx1.hash);
212+
}
210213

211214
let fee = BigNumber.from("0");
212215
if (totalMintFee.gt("0") && feeToken.address !== perp.address) {
@@ -482,9 +485,12 @@ task("ops:trancheAndRollover")
482485
console.log("Signer", signerAddress);
483486

484487
console.log("Approving collateralToken to be spent");
485-
const tx1 = await collateralToken.connect(signer).approve(router.address, fixedPtCollateralAmount);
486-
await tx1.wait();
487-
console.log("Tx", tx1.hash);
488+
const allowance = await collateralToken.allowance(signerAddress, router.address);
489+
if (allowance.lt(fixedPtCollateralAmount)) {
490+
const tx1 = await collateralToken.connect(signer).approve(router.address, fixedPtCollateralAmount);
491+
await tx1.wait();
492+
console.log("Tx", tx1.hash);
493+
}
488494

489495
let fee = BigNumber.from("0");
490496
if (totalRolloverFee.gt("0")) {

0 commit comments

Comments
 (0)