impermax-sdk 2.1.249 → 2.1.250
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/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.d.ts +9 -1
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.js +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.d.ts +0 -6
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +16 -28
- package/lib/onchain/onchainPermitHelper.d.ts +1 -0
- package/lib/onchain/onchainPermitHelper.js +15 -0
- package/lib/onchain/onchainTypes.d.ts +2 -1
- package/lib/onchain/onchainTypes.js +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Borrowable } from '../../../config/types';
|
|
1
|
+
import { Borrowable, Extension, Factory } from '../../../config/types';
|
|
2
2
|
import OnchainInteractionsLendingPool from './index';
|
|
3
3
|
import OnchainInteractionsPoolToken from '../onchainInteractionsPoolToken';
|
|
4
4
|
import OnchainBorrowable from '../../impermaxFactory/lendingPool/onchainBorrowable';
|
|
5
5
|
import OnchainAccountBorrowable from '../../account/lendingPool/onchainAccountBorrowable';
|
|
6
|
+
import { BigNumber } from "ethers";
|
|
7
|
+
import { Permit } from "../../onchainTypes";
|
|
6
8
|
export default abstract class OnchainInteractionsBorrowable extends OnchainInteractionsPoolToken {
|
|
7
9
|
protected readonly lendingPool: OnchainInteractionsLendingPool;
|
|
8
10
|
protected readonly poolToken: OnchainBorrowable;
|
|
@@ -14,4 +16,10 @@ export default abstract class OnchainInteractionsBorrowable extends OnchainInter
|
|
|
14
16
|
getAccountBorrowable: () => OnchainAccountBorrowable;
|
|
15
17
|
getPoolTokenRouter: () => any;
|
|
16
18
|
private getBorrowableType;
|
|
19
|
+
/**
|
|
20
|
+
* Borrow approve
|
|
21
|
+
*/
|
|
22
|
+
getBorrowAllowance(factory?: Factory, extension?: Extension): Promise<BigNumber>;
|
|
23
|
+
borrowApprove(amount: BigNumber, onTransactionHash: Function, factory?: Factory, extension?: Extension): Promise<any>;
|
|
24
|
+
permitBorrow(amount: BigNumber, factory?: Factory, extension?: Extension): Promise<Permit>;
|
|
17
25
|
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const onchainInteractionsPoolToken_1 = __importDefault(require("../onchainInteractionsPoolToken"));
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
7
8
|
class OnchainInteractionsBorrowable extends onchainInteractionsPoolToken_1.default {
|
|
8
9
|
constructor(lendingPool, borrowable) {
|
|
9
10
|
super();
|
|
@@ -20,5 +21,24 @@ class OnchainInteractionsBorrowable extends onchainInteractionsPoolToken_1.defau
|
|
|
20
21
|
getAccountPoolToken() {
|
|
21
22
|
return this.lendingPool.getAccountLendingPool().getBorrowable(this.getBorrowableType());
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Borrow approve
|
|
26
|
+
*/
|
|
27
|
+
async getBorrowAllowance(factory, extension) {
|
|
28
|
+
const poolToken = await this.poolToken.getPoolToken();
|
|
29
|
+
const { owner, spender } = this.getOwnerSpender(factory, extension);
|
|
30
|
+
const allowance = await poolToken.methods.borrowAllowance(owner, spender).call();
|
|
31
|
+
return ethers_1.BigNumber.from(allowance);
|
|
32
|
+
}
|
|
33
|
+
async borrowApprove(amount, onTransactionHash, factory, extension) {
|
|
34
|
+
const { spender } = this.getOwnerSpender(factory, extension);
|
|
35
|
+
const poolToken = await this.poolToken.getPoolToken();
|
|
36
|
+
return this.send(poolToken.methods.borrowApprove(spender, amount), onTransactionHash);
|
|
37
|
+
}
|
|
38
|
+
async permitBorrow(amount, factory, extension) {
|
|
39
|
+
const { owner, spender } = this.getOwnerSpender(factory, extension);
|
|
40
|
+
const poolToken = await this.poolToken.getPoolToken();
|
|
41
|
+
return this.getPermitHelper().getBorrowPermit(poolToken, owner, spender, amount);
|
|
42
|
+
}
|
|
23
43
|
}
|
|
24
44
|
exports.default = OnchainInteractionsBorrowable;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Permits } from '../../onchainTypes';
|
|
2
|
-
import { BigNumber } from 'ethers';
|
|
3
1
|
import OnchainInteractionsBorrowable from "./onchainInteractionsBorrowable";
|
|
4
2
|
import { OnchainBorrowableV2 } from "../../impermaxFactory/lendingPool";
|
|
5
3
|
import OnchainInteractionsLendingPoolV2 from "./onchainInteractionsLendingPoolV2";
|
|
@@ -8,8 +6,4 @@ export default class OnchainInteractionsBorrowableV2 extends OnchainInteractions
|
|
|
8
6
|
protected readonly poolToken: OnchainBorrowableV2;
|
|
9
7
|
getLendingPool: () => OnchainInteractionsLendingPoolV2;
|
|
10
8
|
getPoolToken: () => OnchainBorrowableV2;
|
|
11
|
-
getBorrowAllowance(): Promise<BigNumber>;
|
|
12
|
-
borrowApprove(amount: BigNumber, onTransactionHash: Function): Promise<any>;
|
|
13
|
-
borrow(amount: BigNumber, permits: Permits, onTransactionHash: Function): Promise<any>;
|
|
14
|
-
repay(amount: BigNumber, onTransactionHash: Function): Promise<any>;
|
|
15
9
|
}
|
|
@@ -3,44 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const general_1 = require("../../../config/general");
|
|
7
|
-
const ethers_1 = require("ethers");
|
|
8
6
|
const onchainInteractionsBorrowable_1 = __importDefault(require("./onchainInteractionsBorrowable"));
|
|
9
7
|
class OnchainInteractionsBorrowableV2 extends onchainInteractionsBorrowable_1.default {
|
|
10
8
|
constructor() {
|
|
11
9
|
super(...arguments);
|
|
12
10
|
this.getLendingPool = () => this.lendingPool;
|
|
13
11
|
this.getPoolToken = () => this.poolToken;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return ethers_1.BigNumber.from(allowance);
|
|
20
|
-
}
|
|
21
|
-
async borrowApprove(amount, onTransactionHash) {
|
|
22
|
-
const { spender } = this.getOwnerSpender();
|
|
23
|
-
const poolToken = await this.poolToken.getPoolToken();
|
|
24
|
-
return this.send(poolToken.methods.borrowApprove(spender, amount), onTransactionHash);
|
|
25
|
-
}
|
|
26
|
-
async borrow(amount, permits, onTransactionHash) {
|
|
27
|
-
const { router, ptAddress, account } = await this.getSendData(permits);
|
|
28
|
-
// TODO temporary fix
|
|
29
|
-
if (await this.isWETH()) {
|
|
12
|
+
/*
|
|
13
|
+
public async borrow(amount: BigNumber, permits: Permits, onTransactionHash: Function) {
|
|
14
|
+
const {router, ptAddress, account} = await this.getSendData(permits);
|
|
15
|
+
// TODO temporary fix
|
|
16
|
+
if (await this.isWETH()) {
|
|
30
17
|
return this.send(router.methods.borrowETH(ptAddress, amount, account, '100000000000000000', '0x'), onTransactionHash);
|
|
31
|
-
|
|
32
|
-
else {
|
|
18
|
+
} else {
|
|
33
19
|
return this.send(router.methods.borrow(ptAddress, amount, account, '100000000000000000', '0x'), onTransactionHash);
|
|
20
|
+
}
|
|
34
21
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return this.send(router.methods.repayETH(ptAddress, account,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
|
|
23
|
+
public async repay(amount: BigNumber, onTransactionHash: Function) {
|
|
24
|
+
const {router, ptAddress, account} = await this.getSendData([]);
|
|
25
|
+
if (await this.isWETH()) {
|
|
26
|
+
return this.send(router.methods.repayETH(ptAddress, account, DEADLINE), onTransactionHash, amount);
|
|
27
|
+
} else {
|
|
28
|
+
return this.send(router.methods.repay(ptAddress, amount, account, DEADLINE), onTransactionHash);
|
|
29
|
+
}
|
|
43
30
|
}
|
|
31
|
+
*/
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
exports.default = OnchainInteractionsBorrowableV2;
|
|
@@ -16,6 +16,7 @@ export default class OnchainPermitHelper {
|
|
|
16
16
|
private getPermit2SingleJSONData;
|
|
17
17
|
private getSignature;
|
|
18
18
|
getTokenPermit(token: Contract, owner: Address, spender: Address, value: BigNumber, version?: null): Promise<Permit>;
|
|
19
|
+
getBorrowPermit(token: Contract, owner: Address, spender: Address, value: BigNumber): Promise<Permit>;
|
|
19
20
|
getNftPermit(token: Contract, owner: Address, spender: Address, tokenId: BigNumber): Promise<Permit>;
|
|
20
21
|
getPermit2Single(token: Contract, owner: Address, spender: Address, value: BigNumber): Promise<Permit>;
|
|
21
22
|
}
|
|
@@ -128,6 +128,21 @@ class OnchainPermitHelper {
|
|
|
128
128
|
signature: await this.getSignature(owner, jsonData)
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
+
async getBorrowPermit(token, owner, spender, value) {
|
|
132
|
+
const nonce = await token.methods.nonces(owner).call();
|
|
133
|
+
const jsonData = await this.getBorrowPermitJSONData(token, {
|
|
134
|
+
owner,
|
|
135
|
+
spender,
|
|
136
|
+
value: value.toString(),
|
|
137
|
+
nonce: ethers_1.BigNumber.from(nonce).toString(),
|
|
138
|
+
deadline: this.deadline,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
permitType: onchainTypes_1.PermitType.PERMIT_BORROW,
|
|
142
|
+
permitData: ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'uint256'], [token._address, value.toString(), this.deadline]),
|
|
143
|
+
signature: await this.getSignature(owner, jsonData)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
131
146
|
async getNftPermit(token, owner, spender, tokenId) {
|
|
132
147
|
const nonce = await token.methods.nonces(tokenId).call();
|
|
133
148
|
const jsonData = await this.getNftPermitJSONData(token, {
|
|
@@ -13,6 +13,7 @@ var PermitType;
|
|
|
13
13
|
PermitType[PermitType["PERMIT_NFT"] = 1] = "PERMIT_NFT";
|
|
14
14
|
PermitType[PermitType["PERMIT2_SINGLE"] = 2] = "PERMIT2_SINGLE";
|
|
15
15
|
PermitType[PermitType["PERMIT2_BATCH"] = 3] = "PERMIT2_BATCH";
|
|
16
|
+
PermitType[PermitType["PERMIT_BORROW"] = 4] = "PERMIT_BORROW";
|
|
16
17
|
})(PermitType = exports.PermitType || (exports.PermitType = {}));
|
|
17
18
|
exports.NO_CHANGES = {
|
|
18
19
|
changeBorrowedA: 0,
|