impermax-sdk 1.0.46 → 1.1.0
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/impermax-router/Account.d.ts +5 -1
- package/lib/impermax-router/Account.js +18 -0
- package/lib/impermax-router/AccountLendingVault.d.ts +14 -0
- package/lib/impermax-router/AccountLendingVault.js +49 -0
- package/lib/impermax-router/Interactions.d.ts +5 -1
- package/lib/impermax-router/Interactions.js +15 -0
- package/lib/impermax-router/InteractionsLendingVault.d.ts +22 -0
- package/lib/impermax-router/InteractionsLendingVault.js +55 -0
- package/lib/impermax-router/LendingVault.d.ts +12 -0
- package/lib/impermax-router/LendingVault.js +40 -0
- package/lib/impermax-router/index.d.ts +4 -1
- package/lib/impermax-router/index.js +10 -1
- package/lib/impermax-router/types.d.ts +1 -1
- package/lib/subgraph/Account.d.ts +7 -1
- package/lib/subgraph/Account.js +25 -0
- package/lib/subgraph/AccountLendingVault.d.ts +11 -0
- package/lib/subgraph/AccountLendingVault.js +38 -0
- package/lib/subgraph/LendingVault.d.ts +23 -0
- package/lib/subgraph/LendingVault.js +126 -0
- package/lib/subgraph/index.d.ts +4 -1
- package/lib/subgraph/index.js +9 -0
- package/package.json +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AirdropData, PendingRewardUI } from "./types";
|
|
2
2
|
import ImpermaxRouter from "./index";
|
|
3
3
|
import AccountLendingPool from "./AccountLendingPool";
|
|
4
|
-
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
4
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
5
|
+
import AccountLendingVault from './AccountLendingVault';
|
|
5
6
|
export default class Account {
|
|
6
7
|
router: ImpermaxRouter;
|
|
7
8
|
account: Address;
|
|
8
9
|
accountLLPs: LendingPoolIndex<Promise<AccountLendingPool>>;
|
|
10
|
+
accountLVs: AddressIndex<Promise<AccountLendingVault>>;
|
|
9
11
|
cache: {
|
|
10
12
|
airdropData: {
|
|
11
13
|
[key in string]?: Promise<AirdropData>;
|
|
@@ -18,6 +20,8 @@ export default class Account {
|
|
|
18
20
|
cleanCache(): Promise<void>;
|
|
19
21
|
private initializeAccountLendingPool;
|
|
20
22
|
getAccountLendingPool(factory: Factory, pair: Address): Promise<AccountLendingPool>;
|
|
23
|
+
private initializeAccountLendingVault;
|
|
24
|
+
getAccountLendingVault(vaultAddress: Address): Promise<AccountLendingVault>;
|
|
21
25
|
getMassAvailableReward(pairs: FactoryIndex<Address[]>): Promise<LendingPoolIndex<PendingRewardUI[]>>;
|
|
22
26
|
private initializeAirdropData;
|
|
23
27
|
private getAirdropData;
|
|
@@ -15,12 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const AccountLendingPool_1 = __importDefault(require("./AccountLendingPool"));
|
|
16
16
|
const ethers_1 = require("ethers");
|
|
17
17
|
const merkle_distributors_1 = require("../config/endpoints/merkle-distributors");
|
|
18
|
+
const AccountLendingVault_1 = __importDefault(require("./AccountLendingVault"));
|
|
18
19
|
class Account {
|
|
19
20
|
constructor(router, account) {
|
|
20
21
|
this.cache = { airdropData: {} };
|
|
21
22
|
this.router = router;
|
|
22
23
|
this.account = account;
|
|
23
24
|
this.accountLLPs = {};
|
|
25
|
+
this.accountLVs = {};
|
|
24
26
|
this.cache.claimableIBEX = {};
|
|
25
27
|
}
|
|
26
28
|
cleanCache() {
|
|
@@ -32,6 +34,9 @@ class Account {
|
|
|
32
34
|
(yield this.accountLLPs[factory][pairAddress]).cleanCache();
|
|
33
35
|
}
|
|
34
36
|
}
|
|
37
|
+
for (const vaultAddress of Object.keys(this.accountLVs)) {
|
|
38
|
+
(yield this.accountLVs[vaultAddress]).cleanCache();
|
|
39
|
+
}
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
initializeAccountLendingPool(factory, pair) {
|
|
@@ -49,6 +54,19 @@ class Account {
|
|
|
49
54
|
return this.accountLLPs[factory][pair];
|
|
50
55
|
});
|
|
51
56
|
}
|
|
57
|
+
initializeAccountLendingVault(vaultAddress) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const lendingPool = yield this.router.getLendingVault(vaultAddress);
|
|
60
|
+
return new AccountLendingVault_1.default(this, lendingPool);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getAccountLendingVault(vaultAddress) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (!this.accountLVs[vaultAddress])
|
|
66
|
+
this.accountLVs[vaultAddress] = this.initializeAccountLendingVault(vaultAddress);
|
|
67
|
+
return this.accountLVs[vaultAddress];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
52
70
|
// Mass Available Reward (only supports ImpermaxChef)
|
|
53
71
|
getMassAvailableReward(pairs) {
|
|
54
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Account from "./Account";
|
|
2
|
+
import LendingVault from './LendingVault';
|
|
3
|
+
export default class AccountLendingVault {
|
|
4
|
+
account: Account;
|
|
5
|
+
lendingVault: LendingVault;
|
|
6
|
+
cache: {};
|
|
7
|
+
constructor(account: Account, lendingVault: LendingVault);
|
|
8
|
+
cleanCache(): void;
|
|
9
|
+
getAvailableBalance(): Promise<number>;
|
|
10
|
+
getSuppliedTokens(): Promise<number>;
|
|
11
|
+
getSuppliedAmount(): Promise<number>;
|
|
12
|
+
getSuppliedUSD(): Promise<number>;
|
|
13
|
+
getMaxWithdrawable(): Promise<number>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class AccountLendingVault {
|
|
13
|
+
constructor(account, lendingVault) {
|
|
14
|
+
this.cache = {};
|
|
15
|
+
this.account = account;
|
|
16
|
+
this.lendingVault = lendingVault;
|
|
17
|
+
}
|
|
18
|
+
cleanCache() {
|
|
19
|
+
this.cache = {};
|
|
20
|
+
}
|
|
21
|
+
// User balance
|
|
22
|
+
getAvailableBalance() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return 0;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getSuppliedTokens() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return 0;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getSuppliedAmount() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return 0;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getSuppliedUSD() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return 0;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// Interactions
|
|
43
|
+
getMaxWithdrawable() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return 0;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = AccountLendingVault;
|
|
@@ -2,13 +2,17 @@ import { BigNumber } from "ethers";
|
|
|
2
2
|
import Account from "./Account";
|
|
3
3
|
import InteractionsLendingPool from "./InteractionsLendingPool";
|
|
4
4
|
import { AirdropData, Contract } from "./types";
|
|
5
|
-
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
5
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
6
|
+
import InteractionsLendingVault from './InteractionsLendingVault';
|
|
6
7
|
export default class Interactions {
|
|
7
8
|
account: Account;
|
|
8
9
|
interactionsLLPs: LendingPoolIndex<Promise<InteractionsLendingPool>>;
|
|
10
|
+
interactionsLVs: AddressIndex<Promise<InteractionsLendingVault>>;
|
|
9
11
|
constructor(account: Account);
|
|
10
12
|
private initializeInteractionsLendingPool;
|
|
11
13
|
getInteractionsLendingPool(factory: Factory, pair: Address): Promise<InteractionsLendingPool>;
|
|
14
|
+
private initializeInteractionsLendingVault;
|
|
15
|
+
getInteractionsLendingVault(vaultAddress: Address): Promise<InteractionsLendingVault>;
|
|
12
16
|
send(method: any, onTransactionHash: Function, value?: BigNumber): Promise<any>;
|
|
13
17
|
claimAirdrop(airdropData: AirdropData, merkleDistributor: Contract, onTransactionHash: Function): Promise<any>;
|
|
14
18
|
claims(pairAddresses: FactoryIndex<Address[]>, onTransactionHash: Function): Promise<any>;
|
|
@@ -15,11 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const ethers_1 = require("ethers");
|
|
16
16
|
const InteractionsLendingPool_1 = __importDefault(require("./InteractionsLendingPool"));
|
|
17
17
|
const types_1 = require("../config/types");
|
|
18
|
+
const InteractionsLendingVault_1 = __importDefault(require("./InteractionsLendingVault"));
|
|
18
19
|
const ZERO = ethers_1.BigNumber.from(0);
|
|
19
20
|
class Interactions {
|
|
20
21
|
constructor(account) {
|
|
21
22
|
this.account = account;
|
|
22
23
|
this.interactionsLLPs = {};
|
|
24
|
+
this.interactionsLVs = {};
|
|
23
25
|
}
|
|
24
26
|
initializeInteractionsLendingPool(factory, pair) {
|
|
25
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -36,6 +38,19 @@ class Interactions {
|
|
|
36
38
|
return this.interactionsLLPs[factory][pair];
|
|
37
39
|
});
|
|
38
40
|
}
|
|
41
|
+
initializeInteractionsLendingVault(vaultAddress) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const lendingVault = yield this.account.getAccountLendingVault(vaultAddress);
|
|
44
|
+
return new InteractionsLendingVault_1.default(this, lendingVault);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getInteractionsLendingVault(vaultAddress) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!this.interactionsLVs[vaultAddress])
|
|
50
|
+
this.interactionsLVs[vaultAddress] = this.initializeInteractionsLendingVault(vaultAddress);
|
|
51
|
+
return this.interactionsLVs[vaultAddress];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
39
54
|
send(method, onTransactionHash, value = ZERO) {
|
|
40
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
56
|
try {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Interactions from "./Interactions";
|
|
2
|
+
import { BigNumber } from "ethers";
|
|
3
|
+
import { ApprovalType, PermitData } from './types';
|
|
4
|
+
import AccountLendingVault from './AccountLendingVault';
|
|
5
|
+
export default class InteractionsLendingVault {
|
|
6
|
+
interactions: Interactions;
|
|
7
|
+
accountLendingVault: AccountLendingVault;
|
|
8
|
+
constructor(interactions: Interactions, accountLendingVault: AccountLendingVault);
|
|
9
|
+
getImpermaxRouter: () => import(".").default;
|
|
10
|
+
getLendingVault: () => import("./LendingVault").default;
|
|
11
|
+
send: (method: any, onTransactionHash: Function) => Promise<any>;
|
|
12
|
+
getOwnerSpender(): {
|
|
13
|
+
owner: string;
|
|
14
|
+
spender: string;
|
|
15
|
+
};
|
|
16
|
+
isWETH(): Promise<boolean>;
|
|
17
|
+
getAllowance(approvalType: ApprovalType): Promise<BigNumber>;
|
|
18
|
+
approve(approvalType: ApprovalType, amount: BigNumber, onTransactionHash: Function): Promise<void>;
|
|
19
|
+
getPermitData(approvalType: ApprovalType, amount: BigNumber, deadlineArg: BigNumber | null, callBack: (permitData: PermitData) => void): Promise<void>;
|
|
20
|
+
deposit(amount: BigNumber, onTransactionHash: Function): Promise<void>;
|
|
21
|
+
withdraw(tokens: BigNumber, permitData: PermitData, onTransactionHash: Function): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const ethers_1 = require("ethers");
|
|
13
|
+
class InteractionsLendingVault {
|
|
14
|
+
constructor(interactions, accountLendingVault) {
|
|
15
|
+
// Shortcuts
|
|
16
|
+
this.getImpermaxRouter = () => this.interactions.account.router;
|
|
17
|
+
this.getLendingVault = () => this.accountLendingVault.lendingVault;
|
|
18
|
+
this.send = (method, onTransactionHash) => this.interactions.send(method, onTransactionHash);
|
|
19
|
+
this.interactions = interactions;
|
|
20
|
+
this.accountLendingVault = accountLendingVault;
|
|
21
|
+
}
|
|
22
|
+
getOwnerSpender() {
|
|
23
|
+
return {
|
|
24
|
+
owner: this.accountLendingVault.account.account,
|
|
25
|
+
spender: "TODO",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
isWETH() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return false;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getAllowance(approvalType) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return ethers_1.BigNumber.from("0");
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
approve(approvalType, amount, onTransactionHash) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getPermitData(approvalType, amount, deadlineArg, callBack) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
deposit(amount, onTransactionHash) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
withdraw(tokens, permitData, onTransactionHash) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = InteractionsLendingVault;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from '../config/types';
|
|
2
|
+
import ImpermaxRouter from './index';
|
|
3
|
+
export default class LendingVault {
|
|
4
|
+
router: ImpermaxRouter;
|
|
5
|
+
vaultAddress: Address;
|
|
6
|
+
cache: {};
|
|
7
|
+
constructor(router: ImpermaxRouter, vaultAddress: Address);
|
|
8
|
+
cleanCache(): void;
|
|
9
|
+
getExchangeRate(): Promise<number>;
|
|
10
|
+
getAccrualTimestamp(): Promise<number>;
|
|
11
|
+
getAvailableLiquidity(): Promise<number>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class LendingVault {
|
|
13
|
+
constructor(router, vaultAddress) {
|
|
14
|
+
this.cache = {};
|
|
15
|
+
this.router = router;
|
|
16
|
+
this.vaultAddress = vaultAddress;
|
|
17
|
+
}
|
|
18
|
+
cleanCache() {
|
|
19
|
+
this.cache = {};
|
|
20
|
+
}
|
|
21
|
+
// ExchangeRate
|
|
22
|
+
getExchangeRate() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return 0;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// Accrue Timestamp
|
|
28
|
+
getAccrualTimestamp() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return 0;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Available Liquidity
|
|
34
|
+
getAvailableLiquidity() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return 0;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = LendingVault;
|
|
@@ -2,7 +2,8 @@ import { ImpermaxRouterCfg } from "./types";
|
|
|
2
2
|
import Subgraph from "../subgraph";
|
|
3
3
|
import ContractsHelper from "./ContractsHelper";
|
|
4
4
|
import ImpermaxFactory from "./ImpermaxFactory";
|
|
5
|
-
import { Factory, FactoryIndex, Networks } from '../config/types';
|
|
5
|
+
import { Address, AddressIndex, Factory, FactoryIndex, Networks } from '../config/types';
|
|
6
|
+
import LendingVault from './LendingVault';
|
|
6
7
|
export default class ImpermaxRouter {
|
|
7
8
|
network: Networks;
|
|
8
9
|
subgraph: Subgraph;
|
|
@@ -10,6 +11,7 @@ export default class ImpermaxRouter {
|
|
|
10
11
|
chainId: number;
|
|
11
12
|
contractsHelper: ContractsHelper;
|
|
12
13
|
factories: FactoryIndex<ImpermaxFactory>;
|
|
14
|
+
lendingVaults: AddressIndex<LendingVault>;
|
|
13
15
|
uiMargin: number;
|
|
14
16
|
dust: number;
|
|
15
17
|
priceInverted: boolean;
|
|
@@ -17,4 +19,5 @@ export default class ImpermaxRouter {
|
|
|
17
19
|
cleanCache(): void;
|
|
18
20
|
setPriceInverted(priceInverted: boolean): void;
|
|
19
21
|
getFactory(factory: Factory): ImpermaxFactory;
|
|
22
|
+
getLendingVault(vaultAddress: Address): LendingVault;
|
|
20
23
|
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const ContractsHelper_1 = __importDefault(require("./ContractsHelper"));
|
|
7
7
|
const ImpermaxFactory_1 = __importDefault(require("./ImpermaxFactory"));
|
|
8
|
+
const LendingVault_1 = __importDefault(require("./LendingVault"));
|
|
8
9
|
class ImpermaxRouter {
|
|
9
10
|
constructor(cfg) {
|
|
10
11
|
this.network = cfg.network;
|
|
@@ -13,7 +14,7 @@ class ImpermaxRouter {
|
|
|
13
14
|
this.chainId = cfg.chainId;
|
|
14
15
|
this.uiMargin = 1.1;
|
|
15
16
|
this.dust = 1.000001;
|
|
16
|
-
this.priceInverted = cfg.priceInverted;
|
|
17
|
+
this.priceInverted = cfg.priceInverted ? cfg.priceInverted : false;
|
|
17
18
|
this.contractsHelper = new ContractsHelper_1.default(this);
|
|
18
19
|
this.factories = {};
|
|
19
20
|
}
|
|
@@ -21,6 +22,9 @@ class ImpermaxRouter {
|
|
|
21
22
|
for (const factory of Object.keys(this.factories)) {
|
|
22
23
|
this.factories[factory].cleanCache();
|
|
23
24
|
}
|
|
25
|
+
for (const vaultAddress of Object.keys(this.lendingVaults)) {
|
|
26
|
+
this.lendingVaults[vaultAddress].cleanCache();
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
setPriceInverted(priceInverted) {
|
|
26
30
|
this.priceInverted = priceInverted;
|
|
@@ -30,5 +34,10 @@ class ImpermaxRouter {
|
|
|
30
34
|
this.factories[factory] = new ImpermaxFactory_1.default(this, factory);
|
|
31
35
|
return this.factories[factory];
|
|
32
36
|
}
|
|
37
|
+
getLendingVault(vaultAddress) {
|
|
38
|
+
if (!this.lendingVaults[vaultAddress])
|
|
39
|
+
this.lendingVaults[vaultAddress] = new LendingVault_1.default(this, vaultAddress);
|
|
40
|
+
return this.lendingVaults[vaultAddress];
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
exports.default = ImpermaxRouter;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import Subgraph from "./index";
|
|
2
2
|
import AccountLendingPool from "./AccountLendingPool";
|
|
3
|
-
import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
3
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
4
4
|
import { UserData } from './types';
|
|
5
|
+
import AccountLendingVault from './AccountLendingVault';
|
|
5
6
|
export default class Account {
|
|
6
7
|
subgraph: Subgraph;
|
|
7
8
|
account: Address;
|
|
8
9
|
accountLLPs: LendingPoolIndex<Promise<AccountLendingPool>>;
|
|
10
|
+
accountLVs: AddressIndex<Promise<AccountLendingVault>>;
|
|
9
11
|
constructor(subgraph: Subgraph, account: Address);
|
|
10
12
|
private initializeAccountLendingPool;
|
|
11
13
|
getAccountLendingPool(factory: Factory, pair: Address): Promise<AccountLendingPool>;
|
|
14
|
+
private initializeAccountLendingVault;
|
|
15
|
+
getAccountLendingVault(vaultAddress: Address): Promise<AccountLendingVault>;
|
|
12
16
|
getUserData(): Promise<FactoryIndex<UserData>>;
|
|
13
17
|
getBorrowPositions(): Promise<FactoryIndex<Address[]>>;
|
|
14
18
|
getSupplyPositions(): Promise<FactoryIndex<Address[]>>;
|
|
19
|
+
getLendingVaultsSuppliedUSD(): Promise<number>;
|
|
20
|
+
getLendingVaultsEarningsUSD(): Promise<number>;
|
|
15
21
|
}
|
package/lib/subgraph/Account.js
CHANGED
|
@@ -13,11 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const AccountLendingPool_1 = __importDefault(require("./AccountLendingPool"));
|
|
16
|
+
const AccountLendingVault_1 = __importDefault(require("./AccountLendingVault"));
|
|
16
17
|
class Account {
|
|
17
18
|
constructor(subgraph, account) {
|
|
18
19
|
this.subgraph = subgraph;
|
|
19
20
|
this.account = account;
|
|
20
21
|
this.accountLLPs = {};
|
|
22
|
+
this.accountLVs = {};
|
|
21
23
|
}
|
|
22
24
|
initializeAccountLendingPool(factory, pair) {
|
|
23
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -34,6 +36,19 @@ class Account {
|
|
|
34
36
|
return this.accountLLPs[factory][pair];
|
|
35
37
|
});
|
|
36
38
|
}
|
|
39
|
+
initializeAccountLendingVault(vaultAddress) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const lendingVault = yield this.subgraph.getLendingVault(vaultAddress);
|
|
42
|
+
return new AccountLendingVault_1.default(this, lendingVault);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getAccountLendingVault(vaultAddress) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (!this.accountLVs[vaultAddress])
|
|
48
|
+
this.accountLVs[vaultAddress] = this.initializeAccountLendingVault(vaultAddress);
|
|
49
|
+
return this.accountLVs[vaultAddress];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
37
52
|
getUserData() {
|
|
38
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
54
|
return this.subgraph.getUserData(this.account);
|
|
@@ -59,5 +74,15 @@ class Account {
|
|
|
59
74
|
return result;
|
|
60
75
|
});
|
|
61
76
|
}
|
|
77
|
+
getLendingVaultsSuppliedUSD() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return 0;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getLendingVaultsEarningsUSD() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return 0;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
62
87
|
}
|
|
63
88
|
exports.default = Account;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Account from './Account';
|
|
2
|
+
import LendingVault from './LendingVault';
|
|
3
|
+
export default class AccountLendingVault {
|
|
4
|
+
account: Account;
|
|
5
|
+
lendingVault: LendingVault;
|
|
6
|
+
constructor(account: Account, lendingVault: LendingVault);
|
|
7
|
+
getSuppliedAmount(): Promise<number>;
|
|
8
|
+
getSuppliedUSD(): Promise<number>;
|
|
9
|
+
getEarnings(): Promise<number>;
|
|
10
|
+
getEarningsUSD(): Promise<number>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class AccountLendingVault {
|
|
13
|
+
constructor(account, lendingVault) {
|
|
14
|
+
this.account = account;
|
|
15
|
+
this.lendingVault = lendingVault;
|
|
16
|
+
}
|
|
17
|
+
getSuppliedAmount() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return 0;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getSuppliedUSD() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return 0;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getEarnings() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return 0;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getEarningsUSD() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return 0;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = AccountLendingVault;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Subgraph from "./index";
|
|
2
|
+
import { Address } from '../config/types';
|
|
3
|
+
export default class LendingVault {
|
|
4
|
+
subgraph: Subgraph;
|
|
5
|
+
vaultAddress: Address;
|
|
6
|
+
constructor(subgraph: Subgraph, vaultAddress: Address);
|
|
7
|
+
getName(): Promise<string>;
|
|
8
|
+
getSymbol(): Promise<string>;
|
|
9
|
+
getDecimals(): Promise<number>;
|
|
10
|
+
getExchangeRate(): Promise<number>;
|
|
11
|
+
getUnderlyingAddress(): Promise<Address>;
|
|
12
|
+
getAccrualTimestamp(): Promise<number>;
|
|
13
|
+
getVaultSupply(): Promise<number>;
|
|
14
|
+
getCurrentVaultSupply(): Promise<number>;
|
|
15
|
+
getVaultSupplyUSD(): Promise<number>;
|
|
16
|
+
getAvailableLiquidity(): Promise<number>;
|
|
17
|
+
getCurrentAvailableLiquidity(): Promise<number>;
|
|
18
|
+
getAvailableLiquidityUSD(): Promise<number>;
|
|
19
|
+
getSupplyRate(): Promise<number>;
|
|
20
|
+
getSupplyAPR(): Promise<number>;
|
|
21
|
+
getTokenPriceFast(fallback?: boolean): Promise<number>;
|
|
22
|
+
getTokenPriceAccurate(): Promise<number>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class LendingVault {
|
|
13
|
+
constructor(subgraph, vaultAddress) {
|
|
14
|
+
this.subgraph = subgraph;
|
|
15
|
+
this.vaultAddress = vaultAddress;
|
|
16
|
+
}
|
|
17
|
+
// Name
|
|
18
|
+
getName() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return "TODO";
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Symbol
|
|
24
|
+
getSymbol() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return "TODO";
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Decimals
|
|
30
|
+
getDecimals() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return 0;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// ExchangeRate
|
|
36
|
+
getExchangeRate() {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return 0;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Underlying Address
|
|
42
|
+
getUnderlyingAddress() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return "TODO";
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Accrue Timestamp
|
|
48
|
+
getAccrualTimestamp() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return 0;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Vault Supply
|
|
54
|
+
getVaultSupply() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return 0;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getCurrentVaultSupply() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return 0;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getVaultSupplyUSD() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return 0;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/*// Total Supply
|
|
70
|
+
async getTotalSupply() : Promise<number> {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
async getCurrentTotalSupply() : Promise<number> {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Total Borrows
|
|
78
|
+
async getTotalBorrows() : Promise<number> {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
async getCurrentTotalBorrows() : Promise<number> {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
async getTotalBorrowsUSD() : Promise<number> {
|
|
85
|
+
return 0;
|
|
86
|
+
}*/
|
|
87
|
+
// Available Liquidity
|
|
88
|
+
getAvailableLiquidity() {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
return 0;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getCurrentAvailableLiquidity() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
return 0;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getAvailableLiquidityUSD() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return 0;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Supply Rate
|
|
104
|
+
getSupplyRate() {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
return 0;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getSupplyAPR() {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return 0;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Token price getters
|
|
115
|
+
getTokenPriceFast(fallback = true) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return 0;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
getTokenPriceAccurate() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
return 0;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.default = LendingVault;
|
package/lib/subgraph/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import LendingPool from "./LendingPool";
|
|
|
3
3
|
import PriceHelper from "./PriceHelper";
|
|
4
4
|
import SolidexHelper from "./SolidexHelper";
|
|
5
5
|
import Account from "./Account";
|
|
6
|
-
import { Address, Factory, FactoryIndex, LendingPoolIndex, Networks } from '../config/types';
|
|
6
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks } from '../config/types';
|
|
7
7
|
import { LendingPoolData, TvlData, UserData, XimxData } from './types';
|
|
8
|
+
import LendingVault from './LendingVault';
|
|
8
9
|
export interface SubgraphCfg {
|
|
9
10
|
network: Networks;
|
|
10
11
|
chainId: number;
|
|
@@ -15,6 +16,7 @@ export default class Subgraph {
|
|
|
15
16
|
chainId: number;
|
|
16
17
|
whitelistedPairs?: FactoryIndex<Address[]>;
|
|
17
18
|
lendingPools: LendingPoolIndex<LendingPool>;
|
|
19
|
+
lendingVaults: AddressIndex<LendingVault>;
|
|
18
20
|
accounts: {
|
|
19
21
|
[key in Address]?: Account;
|
|
20
22
|
};
|
|
@@ -29,6 +31,7 @@ export default class Subgraph {
|
|
|
29
31
|
constructor(cfg: SubgraphCfg);
|
|
30
32
|
cleanCache(): void;
|
|
31
33
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<LendingPool>;
|
|
34
|
+
getLendingVault(vaultAddress: Address): Promise<LendingVault>;
|
|
32
35
|
getAccount(account: Address): Account;
|
|
33
36
|
/**
|
|
34
37
|
* TODO
|
package/lib/subgraph/index.js
CHANGED
|
@@ -39,6 +39,7 @@ const initializer = __importStar(require("./initializer"));
|
|
|
39
39
|
const PriceHelper_1 = __importDefault(require("./PriceHelper"));
|
|
40
40
|
const SolidexHelper_1 = __importDefault(require("./SolidexHelper"));
|
|
41
41
|
const Account_1 = __importDefault(require("./Account"));
|
|
42
|
+
const LendingVault_1 = __importDefault(require("./LendingVault"));
|
|
42
43
|
class Subgraph {
|
|
43
44
|
constructor(cfg) {
|
|
44
45
|
/**
|
|
@@ -90,6 +91,14 @@ class Subgraph {
|
|
|
90
91
|
return this.lendingPools[factory][pairAddress];
|
|
91
92
|
});
|
|
92
93
|
}
|
|
94
|
+
getLendingVault(vaultAddress) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
//await this.getLendingVaultsData(); // TODO make sure that lending vaults are initialized
|
|
97
|
+
if (!this.lendingVaults[vaultAddress])
|
|
98
|
+
this.lendingVaults[vaultAddress] = new LendingVault_1.default(this, vaultAddress);
|
|
99
|
+
return this.lendingVaults[vaultAddress];
|
|
100
|
+
});
|
|
101
|
+
}
|
|
93
102
|
getAccount(account) {
|
|
94
103
|
if (!this.accounts[account])
|
|
95
104
|
this.accounts[account] = new Account_1.default(this, account);
|