handle-sdk
Advanced tools
Comparing version 0.0.24 to 0.0.26
{ | ||
"name": "handle-sdk", | ||
"version": "0.0.24", | ||
"version": "0.0.26", | ||
"description": "handle.fi sdk", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -36,2 +36,3 @@ import { fxToken } from "./fxToken"; | ||
withdrawCollateral(amount: ethers.BigNumber, collateralToken: CollateralTokens, returnTxData?: boolean, gasLimit?: ethers.BigNumber, gasPrice?: ethers.BigNumber): Promise<any>; | ||
burn(amount: ethers.BigNumber, returnTxData?: boolean, gasLimit?: ethers.BigNumber, gasPrice?: ethers.BigNumber, deadline?: number): Promise<any>; | ||
} |
@@ -195,3 +195,2 @@ "use strict"; | ||
throw new Error("This function requires a signer"); | ||
deadline = deadline !== null && deadline !== void 0 ? deadline : Math.floor(Date.now() / 1000) + 300; | ||
func = !returnTxData | ||
@@ -201,3 +200,3 @@ ? this.sdk.contracts.comptroller | ||
collateralTokenAddress = this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
return [4 /*yield*/, func.mint(tokenAmount, this.token.address, collateralTokenAddress, collateralAmount, deadline, referral !== null && referral !== void 0 ? referral : ethers_1.ethers.constants.AddressZero, { | ||
return [4 /*yield*/, func.mint(tokenAmount, this.token.address, collateralTokenAddress, collateralAmount, getDeadline(deadline), referral !== null && referral !== void 0 ? referral : ethers_1.ethers.constants.AddressZero, { | ||
gasPrice: gasPrice, | ||
@@ -221,7 +220,6 @@ gasLimit: gasLimit | ||
throw new Error("This function requires a signer"); | ||
deadline = deadline !== null && deadline !== void 0 ? deadline : Math.floor(Date.now() / 1000) + 300; | ||
func = !returnTxData | ||
? this.sdk.contracts.comptroller | ||
: this.sdk.contracts.comptroller.populateTransaction; | ||
return [4 /*yield*/, func.mintWithoutCollateral(tokenAmount, this.token.address, deadline, referral !== null && referral !== void 0 ? referral : ethers_1.ethers.constants.AddressZero, { | ||
return [4 /*yield*/, func.mintWithoutCollateral(tokenAmount, this.token.address, getDeadline(deadline), referral !== null && referral !== void 0 ? referral : ethers_1.ethers.constants.AddressZero, { | ||
gasPrice: gasPrice, | ||
@@ -257,8 +255,9 @@ gasLimit: gasLimit | ||
allowance = _a.sent(); | ||
if (!allowance.lt(amount)) return [3 /*break*/, 5]; | ||
if (!allowance.lt(amount)) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, this.sdk.contracts[collateralToken].approve(this.sdk.contracts.treasury.address, amount)]; | ||
case 4: | ||
case 4: return [4 /*yield*/, (_a.sent()).wait(2)]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: | ||
_a.label = 6; | ||
case 6: | ||
collateralTokenAddress = this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
@@ -269,3 +268,3 @@ return [4 /*yield*/, func.depositCollateral(this.account, amount, collateralTokenAddress, this.token.address, referral !== null && referral !== void 0 ? referral : ethers_1.ethers.constants.AddressZero, { | ||
})]; | ||
case 6: return [2 /*return*/, _a.sent()]; | ||
case 7: return [2 /*return*/, _a.sent()]; | ||
} | ||
@@ -304,2 +303,23 @@ }); | ||
}; | ||
Vault.prototype.burn = function (amount, returnTxData, gasLimit, gasPrice, deadline) { | ||
if (returnTxData === void 0) { returnTxData = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var func; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.sdk.signer) | ||
throw new Error("This function requires a signer"); | ||
func = !returnTxData | ||
? this.sdk.contracts.comptroller | ||
: this.sdk.contracts.comptroller.populateTransaction; | ||
return [4 /*yield*/, func.burn(amount, this.token.address, getDeadline(deadline), { | ||
gasPrice: gasPrice, | ||
gasLimit: gasLimit | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Vault; | ||
@@ -332,1 +352,2 @@ }()); | ||
}); }; | ||
var getDeadline = function (deadline) { return deadline !== null && deadline !== void 0 ? deadline : Math.floor(Date.now() / 1000) + 300; }; |
@@ -47,3 +47,3 @@ "use strict"; | ||
var DEPOSIT_AMOUNT = ethers_1.ethers.utils.parseEther("0.0000000000000001"); | ||
var GAS_PRICE = ethers_1.ethers.BigNumber.from("2500000"); | ||
var GAS_LIMIT = ethers_1.ethers.BigNumber.from("2500000"); | ||
globals_1.xdescribe("Vault: depositCollateral, withdrawCollateral", function () { | ||
@@ -71,3 +71,3 @@ var _this = this; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, vault.depositCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.WETH, false, GAS_PRICE)]; | ||
case 0: return [4 /*yield*/, vault.depositCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.WETH, false, GAS_LIMIT)]; | ||
case 1: return [4 /*yield*/, (_a.sent()).wait(1)]; | ||
@@ -83,3 +83,3 @@ case 2: | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, vault.depositCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.DAI, false, GAS_PRICE)]; | ||
case 0: return [4 /*yield*/, vault.depositCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.DAI, false, GAS_LIMIT)]; | ||
case 1: return [4 /*yield*/, (_a.sent()).wait(1)]; | ||
@@ -95,3 +95,3 @@ case 2: | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, vault.withdrawCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.WETH, false, GAS_PRICE)]; | ||
case 0: return [4 /*yield*/, vault.withdrawCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.WETH, false, GAS_LIMIT)]; | ||
case 1: return [4 /*yield*/, (_a.sent()).wait(1)]; | ||
@@ -107,3 +107,3 @@ case 2: | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, vault.withdrawCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.DAI, false, GAS_PRICE)]; | ||
case 0: return [4 /*yield*/, vault.withdrawCollateral(DEPOSIT_AMOUNT, ProtocolTokens_1.CollateralTokens.DAI, false, GAS_LIMIT)]; | ||
case 1: return [4 /*yield*/, (_a.sent()).wait(1)]; | ||
@@ -110,0 +110,0 @@ case 2: |
{ | ||
"name": "handle-sdk", | ||
"version": "0.0.24", | ||
"version": "0.0.26", | ||
"description": "handle.fi sdk", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -148,3 +148,2 @@ import { fxToken } from "./fxToken"; | ||
if (!this.sdk.signer) throw new Error("This function requires a signer"); | ||
deadline = deadline ?? Math.floor(Date.now() / 1000) + 300; | ||
const func = !returnTxData | ||
@@ -160,3 +159,3 @@ ? this.sdk.contracts.comptroller | ||
collateralAmount, | ||
deadline, | ||
getDeadline(deadline), | ||
referral ?? ethers.constants.AddressZero, | ||
@@ -180,3 +179,2 @@ { | ||
if (!this.sdk.signer) throw new Error("This function requires a signer"); | ||
deadline = deadline ?? Math.floor(Date.now() / 1000) + 300; | ||
const func = !returnTxData | ||
@@ -188,3 +186,3 @@ ? this.sdk.contracts.comptroller | ||
this.token.address, | ||
deadline, | ||
getDeadline(deadline), | ||
referral ?? ethers.constants.AddressZero, | ||
@@ -223,30 +221,32 @@ { | ||
); | ||
} else { | ||
const allowance = await this.sdk.contracts[collateralToken].allowance( | ||
this.account, | ||
this.sdk.contracts.treasury.address | ||
); | ||
} | ||
if (allowance.lt(amount)) { | ||
const allowance = await this.sdk.contracts[collateralToken].allowance( | ||
this.account, | ||
this.sdk.contracts.treasury.address | ||
); | ||
if (allowance.lt(amount)) { | ||
await ( | ||
await this.sdk.contracts[collateralToken].approve( | ||
this.sdk.contracts.treasury.address, | ||
amount | ||
); | ||
} | ||
) | ||
).wait(2); | ||
} | ||
const collateralTokenAddress = | ||
this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
const collateralTokenAddress = | ||
this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
return await func.depositCollateral( | ||
this.account, | ||
amount, | ||
collateralTokenAddress, | ||
this.token.address, | ||
referral ?? ethers.constants.AddressZero, | ||
{ | ||
gasPrice: gasPrice, | ||
gasLimit: gasLimit | ||
} | ||
); | ||
} | ||
return await func.depositCollateral( | ||
this.account, | ||
amount, | ||
collateralTokenAddress, | ||
this.token.address, | ||
referral ?? ethers.constants.AddressZero, | ||
{ | ||
gasPrice: gasPrice, | ||
gasLimit: gasLimit | ||
} | ||
); | ||
} | ||
@@ -272,18 +272,36 @@ | ||
}); | ||
} else { | ||
const collateralTokenAddress = | ||
this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
} | ||
const collateralTokenAddress = | ||
this.sdk.protocol.getCollateralTokenBySymbol(collateralToken).address; | ||
return await func.withdrawCollateral( | ||
collateralTokenAddress, | ||
this.account, | ||
amount, | ||
this.token.address, | ||
{ | ||
gasPrice: gasPrice, | ||
gasLimit: gasLimit | ||
} | ||
); | ||
} | ||
return await func.withdrawCollateral( | ||
collateralTokenAddress, | ||
this.account, | ||
amount, | ||
this.token.address, | ||
{ | ||
gasPrice: gasPrice, | ||
gasLimit: gasLimit | ||
} | ||
); | ||
} | ||
public async burn( | ||
amount: ethers.BigNumber, | ||
returnTxData: boolean = false, | ||
gasLimit?: ethers.BigNumber, | ||
gasPrice?: ethers.BigNumber, | ||
deadline?: number | ||
) { | ||
if (!this.sdk.signer) throw new Error("This function requires a signer"); | ||
const func = !returnTxData | ||
? this.sdk.contracts.comptroller | ||
: this.sdk.contracts.comptroller.populateTransaction; | ||
return await func.burn(amount, this.token.address, getDeadline(deadline), { | ||
gasPrice, | ||
gasLimit | ||
}); | ||
} | ||
} | ||
@@ -302,1 +320,3 @@ | ||
}; | ||
const getDeadline = (deadline?: number) => deadline ?? Math.floor(Date.now() / 1000) + 300; |
@@ -12,3 +12,3 @@ import { xdescribe, it } from "@jest/globals"; | ||
const DEPOSIT_AMOUNT = ethers.utils.parseEther("0.0000000000000001"); | ||
const GAS_PRICE = ethers.BigNumber.from("2500000"); | ||
const GAS_LIMIT = ethers.BigNumber.from("2500000"); | ||
@@ -23,3 +23,3 @@ xdescribe("Vault: depositCollateral, withdrawCollateral", function () { | ||
await ( | ||
await vault.depositCollateral(DEPOSIT_AMOUNT, CollateralTokens.WETH, false, GAS_PRICE) | ||
await vault.depositCollateral(DEPOSIT_AMOUNT, CollateralTokens.WETH, false, GAS_LIMIT) | ||
).wait(1); | ||
@@ -29,3 +29,3 @@ }); | ||
await ( | ||
await vault.depositCollateral(DEPOSIT_AMOUNT, CollateralTokens.DAI, false, GAS_PRICE) | ||
await vault.depositCollateral(DEPOSIT_AMOUNT, CollateralTokens.DAI, false, GAS_LIMIT) | ||
).wait(1); | ||
@@ -35,3 +35,3 @@ }); | ||
await ( | ||
await vault.withdrawCollateral(DEPOSIT_AMOUNT, CollateralTokens.WETH, false, GAS_PRICE) | ||
await vault.withdrawCollateral(DEPOSIT_AMOUNT, CollateralTokens.WETH, false, GAS_LIMIT) | ||
).wait(1); | ||
@@ -41,5 +41,5 @@ }); | ||
await ( | ||
await vault.withdrawCollateral(DEPOSIT_AMOUNT, CollateralTokens.DAI, false, GAS_PRICE) | ||
await vault.withdrawCollateral(DEPOSIT_AMOUNT, CollateralTokens.DAI, false, GAS_LIMIT) | ||
).wait(1); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1615928
139
18350