impermax-sdk 2.1.104 → 2.1.107

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.
@@ -1,13 +1,16 @@
1
1
  import OnchainInteractionsLendingPoolV3 from "../onchainInteractionsLendingPoolV3";
2
2
  import { OnchainInteractionsCollateralV3 } from "../index";
3
- import { Permits } from "../../../onchainTypes";
3
+ import { Permit, Permits } from "../../../onchainTypes";
4
4
  import { BigNumber } from "ethers";
5
+ import { Address } from "../../../../config/types";
5
6
  export default abstract class OnchainInteractionsNftlp {
6
7
  protected readonly collateral: OnchainInteractionsCollateralV3;
7
8
  protected cache: {};
8
9
  constructor(collateral: OnchainInteractionsCollateralV3);
9
10
  getLendingPool: () => OnchainInteractionsLendingPoolV3;
10
11
  getNftlp: () => import("../../../impermaxFactory/lendingPool/nftlp").OnchainNftlp;
12
+ protected getOnchain: () => import("../../..").default;
13
+ protected getPermitHelper: () => import("../../../onchainPermitHelper").default;
11
14
  getActionsGetter: () => any;
12
15
  getAccountNftlp: () => import("../../../account/lendingPool/nftlp").OnchainAccountNftlp;
13
16
  getAccountAddress: () => string;
@@ -15,7 +18,23 @@ export default abstract class OnchainInteractionsNftlp {
15
18
  protected getDust: () => number;
16
19
  protected encodePermits: (permits: Permits) => string;
17
20
  cleanCache(): void;
21
+ /**
22
+ * Utilities
23
+ */
18
24
  protected encodeActions(actions?: Array<any>): string;
25
+ /**
26
+ * Permit / Approve
27
+ */
28
+ abstract getOwnerSpender(): {
29
+ owner: Address;
30
+ spender: Address;
31
+ };
32
+ isApproved(tokenId: number): Promise<boolean>;
33
+ approve(tokenId: number, onTransactionHash: Function): Promise<any>;
34
+ permit(tokenId: number): Promise<Permit>;
35
+ /**
36
+ * Interactions
37
+ */
19
38
  abstract getModifyExistingPositionActions(tokenId: number, depositADelta: number, depositBDelta: number, borrowADelta: number, borrowBDelta: number): Promise<{
20
39
  actions: Array<any>;
21
40
  ethValue: number;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  const ethers_1 = require("ethers");
4
13
  class OnchainInteractionsNftlp {
@@ -6,6 +15,8 @@ class OnchainInteractionsNftlp {
6
15
  this.cache = {};
7
16
  this.getLendingPool = () => this.collateral.getLendingPool();
8
17
  this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
18
+ this.getOnchain = () => this.getLendingPool().getInteractions().getOnchain();
19
+ this.getPermitHelper = () => this.getOnchain().getPermitHelper();
9
20
  this.getActionsGetter = () => this.getLendingPool().getLendingPool().getImpermaxFactory().getActionsGetter();
10
21
  this.getAccountNftlp = () => this.getLendingPool().getAccountLendingPool().getNftlp();
11
22
  this.getAccountAddress = () => this.getLendingPool().getAccountAddress();
@@ -17,8 +28,34 @@ class OnchainInteractionsNftlp {
17
28
  cleanCache() {
18
29
  this.cache = {};
19
30
  }
31
+ /**
32
+ * Utilities
33
+ */
20
34
  encodeActions(actions = []) {
21
35
  return ethers_1.ethers.utils.defaultAbiCoder.encode(['tuple(uint256 actionType, bytes actionData, bytes nextAction)[]'], [actions]);
22
36
  }
37
+ isApproved(tokenId) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const nftlp = yield this.getNftlp().getNftlp();
40
+ const { owner, spender } = this.getOwnerSpender();
41
+ const approvedForAll = yield nftlp.methods.isApprovedForAll(owner, spender).call();
42
+ const approved = yield nftlp.methods.getApproved(tokenId).call();
43
+ return approvedForAll || approved == spender;
44
+ });
45
+ }
46
+ approve(tokenId, onTransactionHash) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const nftlp = yield this.getNftlp().getNftlp();
49
+ const { spender } = this.getOwnerSpender();
50
+ return this.getLendingPool().send(nftlp.methods.approve(spender, tokenId), onTransactionHash);
51
+ });
52
+ }
53
+ permit(tokenId) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const nftlp = yield this.getNftlp().getNftlp();
56
+ const { owner, spender } = this.getOwnerSpender();
57
+ return this.getPermitHelper().getNftPermit(nftlp, owner, spender, ethers_1.BigNumber.from(tokenId));
58
+ });
59
+ }
23
60
  }
24
61
  exports.default = OnchainInteractionsNftlp;
@@ -8,6 +8,10 @@ export default class OnchainInteractionsNftlpUniswapV3 extends OnchainInteractio
8
8
  getUniswapV3Router: () => any;
9
9
  getNftlp: () => any;
10
10
  getAccountNftlp: () => OnchainAccountNftlpUniswapV3;
11
+ getOwnerSpender(): {
12
+ owner: string;
13
+ spender: any;
14
+ };
11
15
  protected getMintEmptyAction(): Promise<any>;
12
16
  getCreateNewPositionActions(fee: number, tickLower: number, tickUpper: number, depositADelta: number, depositBDelta: number, borrowADelta: number, borrowBDelta: number): Promise<{
13
17
  actions: Array<any>;
@@ -24,6 +24,12 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
24
24
  this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
25
25
  this.getAccountNftlp = () => this.getLendingPool().getAccountLendingPool().getNftlp();
26
26
  }
27
+ getOwnerSpender() {
28
+ return {
29
+ owner: this.getAccountAddress(),
30
+ spender: this.getUniswapV3Router()._address,
31
+ };
32
+ }
27
33
  getMintEmptyAction() {
28
34
  return __awaiter(this, void 0, void 0, function* () {
29
35
  const actionsGetter = this.getActionsGetter();
@@ -48,7 +54,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
48
54
  }
49
55
  getModifyExistingPositionActions(tokenId, depositADelta, depositBDelta, borrowADelta, borrowBDelta) {
50
56
  return __awaiter(this, void 0, void 0, function* () {
51
- return this._getUpdatePositionActions(-1, yield this.getAccountNftlp().getPositionObject(tokenId), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
57
+ return this._getUpdatePositionActions(tokenId, yield this.getAccountNftlp().getPositionObject(tokenId), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
52
58
  });
53
59
  }
54
60
  _getUpdatePositionActions(tokenId, positionObject, depositADelta, depositBDelta, borrowADelta, borrowBDelta) {
@@ -14,6 +14,9 @@ export default abstract class OnchainInteractionsPoolToken {
14
14
  protected getOnchain: () => import("..").default;
15
15
  protected getPermitHelper: () => import("../onchainPermitHelper").default;
16
16
  protected send(method: any, onTransactionHash: Function, value?: BigNumber): Promise<any>;
17
+ /**
18
+ * Permit / Approve
19
+ */
17
20
  getOwnerSpender(factory?: Factory, extension?: Extension): {
18
21
  owner: string;
19
22
  spender: any;
@@ -28,6 +31,9 @@ export default abstract class OnchainInteractionsPoolToken {
28
31
  approvePermit2(amount: BigNumber, onTransactionHash: Function): Promise<any>;
29
32
  permitUnderlying(amount: BigNumber, factory?: Factory, extension?: Extension): Promise<Permit>;
30
33
  permit2Underlying(amount: BigNumber, factory?: Factory, extension?: Extension): Promise<Permit>;
34
+ /**
35
+ * Interactions
36
+ */
31
37
  protected getSendData(permits: Permits): Promise<{
32
38
  router: any;
33
39
  ptAddress: any;
@@ -45,6 +45,9 @@ class OnchainInteractionsPoolToken {
45
45
  return this.getInteractions().send(method, onTransactionHash, value);
46
46
  }
47
47
  //send = this.getInteractions().send;
48
+ /**
49
+ * Permit / Approve
50
+ */
48
51
  getOwnerSpender(factory, extension) {
49
52
  const owner = this.getAccountAddress();
50
53
  const network = this.getOnchain().network;
@@ -134,6 +137,9 @@ class OnchainInteractionsPoolToken {
134
137
  return this.getPermitHelper().getPermit2Single(token, owner, spender, amount);
135
138
  });
136
139
  }
140
+ /**
141
+ * Interactions
142
+ */
137
143
  getSendData(permits) {
138
144
  return __awaiter(this, void 0, void 0, function* () {
139
145
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.104",
3
+ "version": "2.1.107",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",