impermax-sdk 2.1.5 → 2.1.7
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/config/subgraphs.d.ts +2 -2
- package/lib/config/subgraphs.js +205 -131
- package/lib/config/types.d.ts +10 -0
- package/lib/config/types.js +7 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/offchain/account/offchainAccount.d.ts +6 -6
- package/lib/offchain/account/offchainAccount.js +33 -24
- package/lib/offchain/account/vault/offchainAccountVault.js +10 -3
- package/lib/offchain/offchain.d.ts +13 -10
- package/lib/offchain/offchain.js +18 -11
- package/lib/offchain/offchainInitializer.d.ts +11 -11
- package/lib/offchain/offchainInitializer.js +151 -91
- package/lib/offchain/offchainMultichain.d.ts +4 -4
- package/lib/offchain/offchainMultichain.js +28 -56
- package/lib/offchain/offchainTypes.d.ts +17 -1
- package/lib/offchain/queries/apis/ponder/index.d.ts +3 -3
- package/lib/offchain/queries/apis/ponder/index.js +45 -24
- package/lib/offchain/queries/apis/thegraph/index.d.ts +3 -3
- package/lib/offchain/queries/apis/thegraph/index.js +4 -2
- package/lib/offchain/queries/interfaces/query-builder.d.ts +3 -3
- package/lib/offchain/vault/offchainHedgedVault.js +2 -25
- package/lib/offchain/vault/offchainLendingVault.d.ts +3 -3
- package/lib/offchain/vault/offchainLendingVault.js +11 -27
- package/lib/offchain/vault/offchainLeveragedVault.js +2 -25
- package/lib/offchain/vault/offchainVault.d.ts +3 -8
- package/lib/offchain/vault/offchainVault.js +3 -8
- package/lib/onchain/account/onchainAccountLendingVault.js +1 -1
- package/lib/onchain/onchainLendingVault.js +1 -1
- package/package.json +1 -1
|
@@ -24,10 +24,17 @@ class OffchainAccountVault extends offchainAccountPoolToken_1.default {
|
|
|
24
24
|
}
|
|
25
25
|
getVaultPosition() {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
27
|
+
const vaultsUserData = yield this.account.getVaultsUserData();
|
|
28
|
+
if (!vaultsUserData)
|
|
29
29
|
return undefined;
|
|
30
|
-
|
|
30
|
+
// Look through each vault type
|
|
31
|
+
for (const vaultType in vaultsUserData) {
|
|
32
|
+
const vaultsOfType = vaultsUserData[vaultType];
|
|
33
|
+
const position = vaultsOfType[this.getVaultAddress()];
|
|
34
|
+
if (position)
|
|
35
|
+
return position;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
31
38
|
});
|
|
32
39
|
}
|
|
33
40
|
getAmount() {
|
|
@@ -6,7 +6,7 @@ import OffchainSolidexHelper from "./offchainSolidexHelper";
|
|
|
6
6
|
import OffchainAccount from "./account";
|
|
7
7
|
import OffchainEndpointManager from './offchainEndpointManager';
|
|
8
8
|
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState } from '../config/types';
|
|
9
|
-
import { LendingPoolData,
|
|
9
|
+
import { LendingPoolData, VaultData, VaultPosition, TvlData, UserData, XimxData } from './offchainTypes';
|
|
10
10
|
import OffchainVault from './vault/offchainVault';
|
|
11
11
|
import OffchainConfigManager from './configManager';
|
|
12
12
|
import { LlamaTvlChart } from './offchainAPRHelper';
|
|
@@ -32,7 +32,7 @@ export default class Offchain {
|
|
|
32
32
|
protected usersData: {
|
|
33
33
|
[key in Address]?: Promise<FactoryIndex<UserData> | null>;
|
|
34
34
|
};
|
|
35
|
-
protected
|
|
35
|
+
protected vaultsData: Promise<AddressIndex<VaultData>> | null;
|
|
36
36
|
protected lendingVaultsUsersData: {
|
|
37
37
|
[key in Address]?: Promise<AddressIndex<VaultPosition> | null>;
|
|
38
38
|
};
|
|
@@ -40,10 +40,13 @@ export default class Offchain {
|
|
|
40
40
|
protected ximxData: Promise<XimxData> | null;
|
|
41
41
|
protected whitelistData: Promise<LendingPoolIndex<WhitelistState>> | null;
|
|
42
42
|
protected endpointManager: OffchainEndpointManager;
|
|
43
|
+
protected vaultsUsersData: {
|
|
44
|
+
[key in Address]?: Promise<AddressIndex<AddressIndex<VaultPosition>>>;
|
|
45
|
+
};
|
|
43
46
|
constructor(offchainMultichain: OffchainMultichain, network: Networks);
|
|
44
47
|
cleanCache(): void;
|
|
45
48
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
|
|
46
|
-
|
|
49
|
+
getVault(vaultAddress: Address): Promise<OffchainVault>;
|
|
47
50
|
getAccount(accountAddress: Address): OffchainAccount;
|
|
48
51
|
getPriceHelper: () => OffchainPriceHelper;
|
|
49
52
|
getSolidexHelper: () => OffchainSolidexHelper;
|
|
@@ -67,17 +70,17 @@ export default class Offchain {
|
|
|
67
70
|
getUserData: typeof initializer.getUserData;
|
|
68
71
|
protected initializeXimxData: typeof initializer.initializeXimxData;
|
|
69
72
|
getXimxData: typeof initializer.getXimxData;
|
|
70
|
-
|
|
71
|
-
protected initializeLendingVaultsData: typeof initializer.initializeLendingVaultsData;
|
|
72
|
-
getLendingVaultsData: typeof initializer.getLendingVaultsData;
|
|
73
|
-
getLendingVaultData: typeof initializer.getLendingVaultData;
|
|
74
|
-
protected fetchLendingVaultsUserData: typeof initializer.fetchLendingVaultsUserData;
|
|
75
|
-
protected initializeLendingVaultsUserData: typeof initializer.initializeLendingVaultsUserData;
|
|
76
|
-
getLendingVaultsUserData: typeof initializer.getLendingVaultsUserData;
|
|
73
|
+
getVaultsUserData: typeof initializer.getVaultsUserData;
|
|
77
74
|
protected fetchWhitelist: typeof initializer.fetchWhitelist;
|
|
78
75
|
protected initializeWhitelistData: typeof initializer.initializeWhitelistData;
|
|
79
76
|
getWhitelistData: typeof initializer.getWhitelistData;
|
|
80
77
|
getWhitelistState: typeof initializer.getWhitelistState;
|
|
78
|
+
protected fetchVaults: typeof initializer.fetchVaults;
|
|
79
|
+
protected initializeVaultsData: typeof initializer.initializeVaultsData;
|
|
80
|
+
getVaultsData: typeof initializer.getVaultsData;
|
|
81
|
+
getVaultData: typeof initializer.getVaultData;
|
|
82
|
+
protected fetchVaultsUserData: typeof initializer.fetchVaultsUserData;
|
|
83
|
+
protected initializeVaultsUserData: typeof initializer.initializeVaultsUserData;
|
|
81
84
|
/**
|
|
82
85
|
* DATA GETTERS
|
|
83
86
|
*/
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -71,17 +71,23 @@ class Offchain {
|
|
|
71
71
|
this.getUserData = initializer.getUserData;
|
|
72
72
|
this.initializeXimxData = initializer.initializeXimxData;
|
|
73
73
|
this.getXimxData = initializer.getXimxData;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.
|
|
74
|
+
// protected initializeLendingVaultsData = initializer.initializeLendingVaultsData;
|
|
75
|
+
// public getLendingVaultsData = initializer.getLendingVaultsData;
|
|
76
|
+
// public getLendingVaultData = initializer.getLendingVaultData;
|
|
77
|
+
// protected fetchLendingVaultsUserData = initializer.fetchLendingVaultsUserData;
|
|
78
|
+
// protected initializeLendingVaultsUserData = initializer.initializeLendingVaultsUserData;
|
|
79
|
+
// public getLendingVaultsUserData = initializer.getLendingVaultsUserData;
|
|
80
|
+
this.getVaultsUserData = initializer.getVaultsUserData;
|
|
81
81
|
this.fetchWhitelist = initializer.fetchWhitelist;
|
|
82
82
|
this.initializeWhitelistData = initializer.initializeWhitelistData;
|
|
83
83
|
this.getWhitelistData = initializer.getWhitelistData;
|
|
84
84
|
this.getWhitelistState = initializer.getWhitelistState;
|
|
85
|
+
this.fetchVaults = initializer.fetchVaults;
|
|
86
|
+
this.initializeVaultsData = initializer.initializeVaultsData;
|
|
87
|
+
this.getVaultsData = initializer.getVaultsData;
|
|
88
|
+
this.getVaultData = initializer.getVaultData;
|
|
89
|
+
this.fetchVaultsUserData = initializer.fetchVaultsUserData;
|
|
90
|
+
this.initializeVaultsUserData = initializer.initializeVaultsUserData;
|
|
85
91
|
// TODO fix conflicting lines (commented)
|
|
86
92
|
//this.network = cfg.network;
|
|
87
93
|
//this.chainId = cfg.chainId;
|
|
@@ -96,12 +102,12 @@ class Offchain {
|
|
|
96
102
|
this.endpointManager = new offchainEndpointManager_1.default();
|
|
97
103
|
this.accounts = {};
|
|
98
104
|
this.usersData = {};
|
|
99
|
-
this.
|
|
105
|
+
this.vaultsUsersData = {};
|
|
100
106
|
}
|
|
101
107
|
cleanCache() {
|
|
102
108
|
this.lendingPoolsData = null;
|
|
103
109
|
this.usersData = {};
|
|
104
|
-
this.
|
|
110
|
+
this.vaultsData = null;
|
|
105
111
|
this.lendingVaultsUsersData = {};
|
|
106
112
|
this.tvlData = null;
|
|
107
113
|
this.ximxData = null;
|
|
@@ -117,9 +123,10 @@ class Offchain {
|
|
|
117
123
|
return this.lendingPools[factory][pairAddress];
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
|
-
|
|
126
|
+
// NOTE: We need to update this to return vault based on its type..
|
|
127
|
+
getVault(vaultAddress) {
|
|
121
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
yield this.
|
|
129
|
+
yield this.getVaultsData(); // make sure that lending vaults are initialized
|
|
123
130
|
if (!this.vaults)
|
|
124
131
|
this.vaults = {};
|
|
125
132
|
if (!this.vaults[vaultAddress])
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ApolloQueryResult } from "apollo-client";
|
|
2
2
|
import { DocumentNode } from "graphql";
|
|
3
|
-
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, WhitelistState } from
|
|
4
|
-
import { Amms } from
|
|
5
|
-
import { LendingPoolData,
|
|
6
|
-
import Offchain from
|
|
3
|
+
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, WhitelistState } from "../config/types";
|
|
4
|
+
import { Amms } from "../config/amms";
|
|
5
|
+
import { LendingPoolData, VaultPosition, RawUserData, TvlData, UserData, WhitelistData, XimxData, VaultData } from "./offchainTypes";
|
|
6
|
+
import Offchain from "./offchain";
|
|
7
7
|
export declare function apolloFetcher(subgraphUrl: string, query: DocumentNode): Promise<ApolloQueryResult<any>>;
|
|
8
8
|
export declare function fetchBlockByTimestamp(this: Offchain, timestamp: number): Promise<number | null>;
|
|
9
|
+
export declare function fetchVaults(this: Offchain): Promise<AddressIndex<VaultData[]>>;
|
|
9
10
|
export declare function fetchLendingPools(this: Offchain): Promise<FactoryIndex<LendingPoolData[]>>;
|
|
10
11
|
export declare function fetchLendingPoolsPast(this: Offchain, seconds: number): Promise<FactoryIndex<any[]> | null>;
|
|
11
12
|
export declare function fetchImpermaxChefRewardRates(this: Offchain): Promise<AddressIndex<Array<{
|
|
@@ -33,10 +34,9 @@ export declare function getXimxData(this: Offchain): Promise<XimxData>;
|
|
|
33
34
|
/**
|
|
34
35
|
* Lending Vault
|
|
35
36
|
**/
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
38
|
-
export declare function
|
|
39
|
-
export declare function getLendingVaultData(this: Offchain, lendingVaultAddress: Address): Promise<LendingVaultData>;
|
|
37
|
+
export declare function initializeVaultsData(this: Offchain): Promise<AddressIndex<VaultData>>;
|
|
38
|
+
export declare function getVaultsData(this: Offchain): Promise<AddressIndex<VaultData>>;
|
|
39
|
+
export declare function getVaultData(this: Offchain, vaultAddress: Address): Promise<VaultData>;
|
|
40
40
|
/**
|
|
41
41
|
* Whitelist
|
|
42
42
|
*/
|
|
@@ -47,6 +47,6 @@ export declare function getWhitelistState(this: Offchain, factory: Factory, pair
|
|
|
47
47
|
/**
|
|
48
48
|
* User Data
|
|
49
49
|
*/
|
|
50
|
-
export declare function
|
|
51
|
-
export declare function
|
|
52
|
-
export declare function
|
|
50
|
+
export declare function fetchVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<VaultPosition[]>>;
|
|
51
|
+
export declare function initializeVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<AddressIndex<VaultPosition>>>;
|
|
52
|
+
export declare function getVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<AddressIndex<VaultPosition>>>;
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.getVaultsUserData = exports.initializeVaultsUserData = exports.fetchVaultsUserData = exports.getWhitelistState = exports.getWhitelistData = exports.initializeWhitelistData = exports.fetchWhitelist = exports.getVaultData = exports.getVaultsData = exports.initializeVaultsData = exports.getXimxData = exports.initializeXimxData = exports.getUserData = exports.initializeUserData = exports.fetchUserData = exports.getTvlData = exports.initializeTvlData = exports.getLendingPoolData = exports.getLendingPoolsData = exports.initializeLendingPoolsData = exports.fetchUniswapAPR = exports.fetchCurrentVolumeAndReserves = exports.fetchPastVolume = exports.fetchImpermaxChefRewardRates = exports.fetchLendingPoolsPast = exports.fetchLendingPools = exports.fetchVaults = exports.fetchBlockByTimestamp = exports.apolloFetcher = void 0;
|
|
16
16
|
const apollo_client_1 = __importDefault(require("apollo-client"));
|
|
17
17
|
const apollo_link_http_1 = require("apollo-link-http");
|
|
18
18
|
const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
|
|
@@ -21,7 +21,7 @@ const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
|
21
21
|
const subgraphs_1 = require("../config/subgraphs");
|
|
22
22
|
const types_1 = require("../config/types");
|
|
23
23
|
const amms_1 = require("../config/amms");
|
|
24
|
-
const
|
|
24
|
+
const vault_1 = require("./vault");
|
|
25
25
|
const impermax_factories_1 = require("../config/contracts/impermax-factories");
|
|
26
26
|
const SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
|
27
27
|
function apolloFetcher(subgraphUrl, query) {
|
|
@@ -34,7 +34,7 @@ function apolloFetcher(subgraphUrl, query) {
|
|
|
34
34
|
});
|
|
35
35
|
const result = yield client.query({
|
|
36
36
|
query: query,
|
|
37
|
-
fetchPolicy:
|
|
37
|
+
fetchPolicy: "cache-first",
|
|
38
38
|
});
|
|
39
39
|
return queries_1.QueryBuilderFactory.transformData(result);
|
|
40
40
|
});
|
|
@@ -61,6 +61,34 @@ function fetchBlockByTimestamp(timestamp) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
exports.fetchBlockByTimestamp = fetchBlockByTimestamp;
|
|
64
|
+
// Follows similar logic as `fetchLendingPools`
|
|
65
|
+
function fetchVaults() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const calls = [];
|
|
68
|
+
let vaultType;
|
|
69
|
+
for (vaultType in subgraphs_1.VAULT_SUBGRAPH_URL[this.network]) {
|
|
70
|
+
const subgraphs = subgraphs_1.VAULT_SUBGRAPH_URL[this.network][vaultType];
|
|
71
|
+
if (!subgraphs || subgraphs.length === 0)
|
|
72
|
+
continue;
|
|
73
|
+
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.vaultsQuery(vaultType, [])));
|
|
74
|
+
}
|
|
75
|
+
const results = yield Promise.all(calls);
|
|
76
|
+
const vaults = {};
|
|
77
|
+
let i = 0;
|
|
78
|
+
for (vaultType in subgraphs_1.VAULT_SUBGRAPH_URL[this.network]) {
|
|
79
|
+
const subgraphs = subgraphs_1.VAULT_SUBGRAPH_URL[this.network][vaultType];
|
|
80
|
+
if (!subgraphs || subgraphs.length === 0)
|
|
81
|
+
continue;
|
|
82
|
+
// WARN: data.lendingVaults will be wrong for different vaults! In the subgraph schema
|
|
83
|
+
// we should name it to just vaults and replace here once done.
|
|
84
|
+
const vaultsForType = results[i++].data.lendingVaults;
|
|
85
|
+
const typedVaults = vaultsForType.map((vault) => (Object.assign(Object.assign({}, vault), { vaultType })));
|
|
86
|
+
vaults[vaultType] = typedVaults;
|
|
87
|
+
}
|
|
88
|
+
return vaults;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.fetchVaults = fetchVaults;
|
|
64
92
|
// Fetch Lending Pools
|
|
65
93
|
function fetchLendingPools() {
|
|
66
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,7 +111,7 @@ function fetchLendingPools() {
|
|
|
83
111
|
exports.fetchLendingPools = fetchLendingPools;
|
|
84
112
|
function fetchLendingPoolsPast(seconds) {
|
|
85
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const timestamp = Math.floor(
|
|
114
|
+
const timestamp = Math.floor(new Date().getTime() / 1000);
|
|
87
115
|
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
88
116
|
if (!blockNumber)
|
|
89
117
|
return null;
|
|
@@ -93,7 +121,7 @@ function fetchLendingPoolsPast(seconds) {
|
|
|
93
121
|
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
94
122
|
const endpoints = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
95
123
|
// Not all endpoints might support this
|
|
96
|
-
const supportedEndpoints = endpoints.filter(endpoint => queries_1.QueryBuilderFactory.getQuery(endpoint).lendingPoolsPastQuery);
|
|
124
|
+
const supportedEndpoints = endpoints.filter((endpoint) => queries_1.QueryBuilderFactory.getQuery(endpoint).lendingPoolsPastQuery);
|
|
97
125
|
// Skip if no endpoints support past queries for this factory
|
|
98
126
|
if (supportedEndpoints.length === 0)
|
|
99
127
|
continue;
|
|
@@ -133,7 +161,7 @@ function fetchImpermaxChefRewardRates() {
|
|
|
133
161
|
rewards[pool.id] = [];
|
|
134
162
|
rewards[pool.id].push({
|
|
135
163
|
rewardToken,
|
|
136
|
-
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
164
|
+
rewardRate: (parseFloat(pool.allocPoint) / totalAllocPoint) * rewardPerSec,
|
|
137
165
|
});
|
|
138
166
|
}
|
|
139
167
|
for (const impermaxRewarder of impermaxRewarders) {
|
|
@@ -145,7 +173,7 @@ function fetchImpermaxChefRewardRates() {
|
|
|
145
173
|
rewards[pool.borrowable] = [];
|
|
146
174
|
rewards[pool.borrowable].push({
|
|
147
175
|
rewardToken,
|
|
148
|
-
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
176
|
+
rewardRate: (parseFloat(pool.allocPoint) / totalAllocPoint) * rewardPerSec,
|
|
149
177
|
});
|
|
150
178
|
}
|
|
151
179
|
}
|
|
@@ -156,7 +184,7 @@ exports.fetchImpermaxChefRewardRates = fetchImpermaxChefRewardRates;
|
|
|
156
184
|
// Uniswap APR
|
|
157
185
|
function fetchPastVolume(amm, lendingPools, seconds) {
|
|
158
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const timestamp = Math.floor(
|
|
187
|
+
const timestamp = Math.floor(new Date().getTime() / 1000);
|
|
160
188
|
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
161
189
|
if (!blockNumber)
|
|
162
190
|
return {};
|
|
@@ -168,7 +196,7 @@ function fetchPastVolume(amm, lendingPools, seconds) {
|
|
|
168
196
|
// Since it's not part of core, one endpoint should suffice
|
|
169
197
|
if (!query.pastVolumeQuery)
|
|
170
198
|
return {};
|
|
171
|
-
result = yield this.apolloFetcher(subgraph, query.pastVolumeQuery(blockNumber, lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
199
|
+
result = yield this.apolloFetcher(subgraph, query.pastVolumeQuery(blockNumber, lendingPools.map((lendingPool) => lendingPool.pair.uniswapV2PairAddress)));
|
|
172
200
|
for (const pair of result.data.pairs) {
|
|
173
201
|
pastVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
174
202
|
}
|
|
@@ -191,7 +219,7 @@ function fetchCurrentVolumeAndReserves(amm, lendingPools) {
|
|
|
191
219
|
// Since it's not part of core, one endpoint should suffice
|
|
192
220
|
if (!query.currentVolumeAndReservesQuery)
|
|
193
221
|
return { currentReserve, currentVolume };
|
|
194
|
-
result = yield this.apolloFetcher(subgraph, query.currentVolumeAndReservesQuery(lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
222
|
+
result = yield this.apolloFetcher(subgraph, query.currentVolumeAndReservesQuery(lendingPools.map((lendingPool) => lendingPool.pair.uniswapV2PairAddress)));
|
|
195
223
|
for (const pair of result.data.pairs) {
|
|
196
224
|
currentVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
197
225
|
currentReserve[pair.id] = parseInt(pair.reserveUSD);
|
|
@@ -218,12 +246,12 @@ function fetchUniswapAPR(lendingPoolsByAmm, seconds = 60 * 60 * 24 * 7) {
|
|
|
218
246
|
promises.push(Promise.all([
|
|
219
247
|
amm,
|
|
220
248
|
this.fetchPastVolume(amm, lendingPools, seconds),
|
|
221
|
-
this.fetchCurrentVolumeAndReserves(amm, lendingPools)
|
|
249
|
+
this.fetchCurrentVolumeAndReserves(amm, lendingPools),
|
|
222
250
|
]));
|
|
223
251
|
}
|
|
224
252
|
const ammsData = yield Promise.all(promises);
|
|
225
253
|
for (const data of ammsData) {
|
|
226
|
-
const [amm, pastVolume, { currentVolume, currentReserve }
|
|
254
|
+
const [amm, pastVolume, { currentVolume, currentReserve }] = data;
|
|
227
255
|
const lendingPools = lendingPoolsByAmm[amm];
|
|
228
256
|
if (lendingPools === undefined)
|
|
229
257
|
continue;
|
|
@@ -233,11 +261,13 @@ function fetchUniswapAPR(lendingPoolsByAmm, seconds = 60 * 60 * 24 * 7) {
|
|
|
233
261
|
uniswapAPR[lendingPool.id] = 0;
|
|
234
262
|
continue;
|
|
235
263
|
}
|
|
236
|
-
const cumVolumePast = pastVolume[uniswapV2PairAddress]
|
|
264
|
+
const cumVolumePast = pastVolume[uniswapV2PairAddress]
|
|
265
|
+
? pastVolume[uniswapV2PairAddress]
|
|
266
|
+
: 0;
|
|
237
267
|
const cumVolumeNow = currentVolume[uniswapV2PairAddress];
|
|
238
268
|
const reserveUSD = currentReserve[uniswapV2PairAddress];
|
|
239
269
|
const volumeUSD = cumVolumeNow - cumVolumePast;
|
|
240
|
-
const yearlyVolume = volumeUSD * SECONDS_IN_YEAR / seconds;
|
|
270
|
+
const yearlyVolume = (volumeUSD * SECONDS_IN_YEAR) / seconds;
|
|
241
271
|
const yearlyFee = yearlyVolume * amms_1.AMM_LP_FEE[this.network][amm];
|
|
242
272
|
uniswapAPR[lendingPool.id] = yearlyFee / reserveUSD;
|
|
243
273
|
}
|
|
@@ -276,11 +306,14 @@ function initializeLendingPoolsData() {
|
|
|
276
306
|
for (const lendingPool of lendingPools[factory]) {
|
|
277
307
|
lendingPool.pair.uniswapAPR = uniswapAPR[lendingPool.id] || 0;
|
|
278
308
|
if (impermaxChefRewardRates) {
|
|
279
|
-
lendingPool.borrowable0.rewards =
|
|
280
|
-
|
|
309
|
+
lendingPool.borrowable0.rewards =
|
|
310
|
+
impermaxChefRewardRates[lendingPool.borrowable0.id];
|
|
311
|
+
lendingPool.borrowable1.rewards =
|
|
312
|
+
impermaxChefRewardRates[lendingPool.borrowable1.id];
|
|
281
313
|
}
|
|
282
314
|
// If one of the price of the 2 tokens is 0, fix the collateral price by doubling it
|
|
283
|
-
if (parseFloat(lendingPool.borrowable0.underlying.derivedUSD) === 0 ||
|
|
315
|
+
if (parseFloat(lendingPool.borrowable0.underlying.derivedUSD) === 0 ||
|
|
316
|
+
parseFloat(lendingPool.borrowable1.underlying.derivedUSD) === 0) {
|
|
284
317
|
lendingPool.pair.derivedUSD = (parseFloat(lendingPool.pair.derivedUSD) * 2).toString();
|
|
285
318
|
}
|
|
286
319
|
if (!lendingPoolsData[factory])
|
|
@@ -310,17 +343,16 @@ function initializeLendingPoolsData() {
|
|
|
310
343
|
for (const factory in lendingPools) {
|
|
311
344
|
this.lendingPools[factory] = {};
|
|
312
345
|
for (const lendingPool of lendingPools[factory]) {
|
|
313
|
-
this.lendingPools[factory][lendingPool.id] =
|
|
314
|
-
new lendingPool_1.default(this, factory, lendingPool.id);
|
|
346
|
+
this.lendingPools[factory][lendingPool.id] = new lendingPool_1.default(this, factory, lendingPool.id);
|
|
315
347
|
}
|
|
316
348
|
}
|
|
317
349
|
// Quickfix for MIM and SPELL
|
|
318
350
|
if (this.network === types_1.Networks.Arbitrum) {
|
|
319
351
|
// const ETH_MIM = '0xa6e69dd0c36f3b59539e2c7afd274ef91b5c70f9';
|
|
320
352
|
// const ETH_SPELL = '0x35b44b303eacb71114aa62fe8dae6f9c5de0f680';
|
|
321
|
-
const ETH_gGOHM =
|
|
322
|
-
const ETH_MAGIC =
|
|
323
|
-
const ETH_RDNT =
|
|
353
|
+
const ETH_gGOHM = "0x6d94f7e67c6ae0b0257c35754e059fdfb249d998";
|
|
354
|
+
const ETH_MAGIC = "0x88a0b00bbe918ee00e3482f71962070dc052984b";
|
|
355
|
+
const ETH_RDNT = "0xfb468ad210d427d65c9a765a480649d5754ca325";
|
|
324
356
|
// const LIZ_LIZ_ETH = '0x699c5e23357ab1bf658bd0b38070d746e37671f3';
|
|
325
357
|
// const LIZ_ETH_USDC = '0x1229aac120ae75301ab1c3a2a04ec14183493584';
|
|
326
358
|
// const LIZ_ETH_BTC = '0xce009c44e1645bc6d19c90ba440c618a42ae581d';
|
|
@@ -331,7 +363,7 @@ function initializeLendingPoolsData() {
|
|
|
331
363
|
//lendingPoolsData[Factory.V2V1_1][ETH_SPELL].pair.rewards[0].rewardRate = '8.44';
|
|
332
364
|
//lendingPoolsData[Factory.V2V1_1][ETH_MIM].pair.rewards[0].rewardRate = '30.64';
|
|
333
365
|
//lendingPoolsData[Factory.V2V1_1][ETH_gGOHM].pair.rewards[0].rewardRate = '0.000009129';
|
|
334
|
-
lendingPoolsDataV2V1_1[ETH_MAGIC].pair.rewards[0].rewardRate =
|
|
366
|
+
lendingPoolsDataV2V1_1[ETH_MAGIC].pair.rewards[0].rewardRate = "0.135";
|
|
335
367
|
}
|
|
336
368
|
}
|
|
337
369
|
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
@@ -375,33 +407,34 @@ function initializeLendingPoolsData() {
|
|
|
375
407
|
if (this.network === types_1.Networks.Polygon) {
|
|
376
408
|
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
377
409
|
if (lendingPoolsDataV2V2) {
|
|
378
|
-
const GNS_DAI =
|
|
410
|
+
const GNS_DAI = "0xf9221c5edc736d26ffc4ddccddfa15a4b958862e";
|
|
379
411
|
if (lendingPoolsDataV2V2[GNS_DAI]) {
|
|
380
412
|
const GNS = lendingPoolsDataV2V2[GNS_DAI].borrowable1.underlying;
|
|
381
413
|
lendingPoolsDataV2V2[GNS_DAI].pair.rewards[0] = {
|
|
382
|
-
id:
|
|
414
|
+
id: "",
|
|
383
415
|
rewardsToken: GNS,
|
|
384
|
-
rewardRate:
|
|
385
|
-
periodFinish:
|
|
416
|
+
rewardRate: "0.00608",
|
|
417
|
+
periodFinish: "0",
|
|
386
418
|
};
|
|
387
|
-
lendingPoolsDataV2V2[GNS_DAI].pair.stakedTotalSupply =
|
|
419
|
+
lendingPoolsDataV2V2[GNS_DAI].pair.stakedTotalSupply = "1640000";
|
|
388
420
|
}
|
|
389
421
|
}
|
|
390
422
|
}
|
|
391
423
|
if (this.network === types_1.Networks.Avalanche) {
|
|
392
424
|
const lendingPoolsDataV2V1_2 = lendingPoolsData[types_1.Factory.V2V1_2];
|
|
393
425
|
if (lendingPoolsDataV2V1_2) {
|
|
394
|
-
const QI_AVAX =
|
|
426
|
+
const QI_AVAX = "0x3e2a4dcd46e0e339aec603080d90bd939a163062";
|
|
395
427
|
if (lendingPoolsDataV2V1_2[QI_AVAX]) {
|
|
396
428
|
const QI = lendingPoolsDataV2V1_2[QI_AVAX].borrowable0.underlying;
|
|
397
429
|
lendingPoolsDataV2V1_2[QI_AVAX].pair.rewards[0] = {
|
|
398
|
-
id:
|
|
430
|
+
id: "",
|
|
399
431
|
rewardsToken: QI,
|
|
400
|
-
rewardRate:
|
|
401
|
-
periodFinish:
|
|
432
|
+
rewardRate: "4.54",
|
|
433
|
+
periodFinish: "0",
|
|
402
434
|
};
|
|
403
435
|
// TODO -> this is wrong
|
|
404
|
-
lendingPoolsDataV2V1_2[QI_AVAX].pair.stakedTotalSupply =
|
|
436
|
+
lendingPoolsDataV2V1_2[QI_AVAX].pair.stakedTotalSupply =
|
|
437
|
+
"0.000000992210460243"; //https://snowtrace.io/token/0xe530dc2095ef5653205cf5ea79f8979a7028065c?a=0x784da19e61cf348a8c54547531795ecfee2affd1
|
|
405
438
|
}
|
|
406
439
|
}
|
|
407
440
|
/*REWARD STOPPED const sAVAX_AVAX = '0x5b588f4481035b0f765393fc9f4752615a6d0498';
|
|
@@ -472,7 +505,7 @@ function initializeTvlData() {
|
|
|
472
505
|
types_1.Networks.Base,
|
|
473
506
|
types_1.Networks.Scroll,
|
|
474
507
|
types_1.Networks.Real,
|
|
475
|
-
types_1.Networks.Blast
|
|
508
|
+
types_1.Networks.Blast,
|
|
476
509
|
]; // exclude ropsten
|
|
477
510
|
const calls = [];
|
|
478
511
|
for (const network of networks) {
|
|
@@ -605,22 +638,28 @@ function initializeUserData(account) {
|
|
|
605
638
|
const underlyingAddress = supplyPositions.borrowable.underlying.id;
|
|
606
639
|
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
607
640
|
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
608
|
-
const poolTokenType = underlyingAddress === addressA
|
|
641
|
+
const poolTokenType = underlyingAddress === addressA
|
|
642
|
+
? types_1.PoolTokenType.BorrowableA
|
|
643
|
+
: types_1.PoolTokenType.BorrowableB;
|
|
609
644
|
const resultOfFactory = result[factory];
|
|
610
645
|
if (!(uniswapV2PairAddress in resultOfFactory.supplyPositions))
|
|
611
646
|
resultOfFactory.supplyPositions[uniswapV2PairAddress] = {};
|
|
612
|
-
resultOfFactory.supplyPositions[uniswapV2PairAddress][poolTokenType] =
|
|
647
|
+
resultOfFactory.supplyPositions[uniswapV2PairAddress][poolTokenType] =
|
|
648
|
+
supplyPositions;
|
|
613
649
|
}
|
|
614
650
|
for (const borrowPositions of rawUserData.borrowPositions) {
|
|
615
651
|
const uniswapV2PairAddress = borrowPositions.borrowable.lendingPool.id;
|
|
616
652
|
const underlyingAddress = borrowPositions.borrowable.underlying.id;
|
|
617
653
|
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
618
654
|
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
619
|
-
const poolTokenType = underlyingAddress === addressA
|
|
655
|
+
const poolTokenType = underlyingAddress === addressA
|
|
656
|
+
? types_1.PoolTokenType.BorrowableA
|
|
657
|
+
: types_1.PoolTokenType.BorrowableB;
|
|
620
658
|
const resultOfFactory = result[factory];
|
|
621
659
|
if (!(uniswapV2PairAddress in resultOfFactory.borrowPositions))
|
|
622
660
|
resultOfFactory.borrowPositions[uniswapV2PairAddress] = {};
|
|
623
|
-
resultOfFactory.borrowPositions[uniswapV2PairAddress][poolTokenType] =
|
|
661
|
+
resultOfFactory.borrowPositions[uniswapV2PairAddress][poolTokenType] =
|
|
662
|
+
borrowPositions;
|
|
624
663
|
}
|
|
625
664
|
}
|
|
626
665
|
return result;
|
|
@@ -656,50 +695,51 @@ exports.getXimxData = getXimxData;
|
|
|
656
695
|
/**
|
|
657
696
|
* Lending Vault
|
|
658
697
|
**/
|
|
659
|
-
function
|
|
660
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
661
|
-
const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
|
|
662
|
-
if (subgraph.length == 0)
|
|
663
|
-
return [];
|
|
664
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
665
|
-
const result = yield this.apolloFetcher(subgraph, query.lendingVaultsQuery([]));
|
|
666
|
-
return result.data.lendingVaults;
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
exports.fetchLendingVaults = fetchLendingVaults;
|
|
670
|
-
function initializeLendingVaultsData() {
|
|
698
|
+
function initializeVaultsData() {
|
|
671
699
|
return __awaiter(this, void 0, void 0, function* () {
|
|
672
|
-
const
|
|
673
|
-
const
|
|
674
|
-
//
|
|
675
|
-
|
|
676
|
-
|
|
700
|
+
const vaultsData = {};
|
|
701
|
+
const vaults = yield this.fetchVaults();
|
|
702
|
+
// Put all vaults in one map, we can destrucutre later as we know
|
|
703
|
+
// which vault is whcih type from subgraphs
|
|
704
|
+
for (const vaultType in vaults) {
|
|
705
|
+
const vaultsOfType = vaults[vaultType];
|
|
706
|
+
for (const vault of vaultsOfType) {
|
|
707
|
+
vaultsData[vault.id] = vault;
|
|
708
|
+
}
|
|
677
709
|
}
|
|
678
|
-
// Initialize OffchainLendingVault objects
|
|
679
710
|
this.vaults = {};
|
|
680
|
-
for (const
|
|
681
|
-
|
|
682
|
-
|
|
711
|
+
for (const vault of Object.values(vaultsData)) {
|
|
712
|
+
switch (vault.vaultType) {
|
|
713
|
+
case types_1.VaultType.LENDING:
|
|
714
|
+
this.vaults[vault.id] = new vault_1.OffchainLendingVault(this, vault.id);
|
|
715
|
+
break;
|
|
716
|
+
case types_1.VaultType.HEDGED:
|
|
717
|
+
this.vaults[vault.id] = new vault_1.OffchainHedgedVault(this, vault.id);
|
|
718
|
+
break;
|
|
719
|
+
case types_1.VaultType.LEVERAGED:
|
|
720
|
+
this.vaults[vault.id] = new vault_1.OffchainLeveragedVault(this, vault.id);
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
683
723
|
}
|
|
684
|
-
return
|
|
724
|
+
return vaultsData;
|
|
685
725
|
});
|
|
686
726
|
}
|
|
687
|
-
exports.
|
|
688
|
-
function
|
|
727
|
+
exports.initializeVaultsData = initializeVaultsData;
|
|
728
|
+
function getVaultsData() {
|
|
689
729
|
return __awaiter(this, void 0, void 0, function* () {
|
|
690
|
-
if (!this.
|
|
691
|
-
this.
|
|
692
|
-
return this.
|
|
730
|
+
if (!this.vaultsData)
|
|
731
|
+
this.vaultsData = this.initializeVaultsData();
|
|
732
|
+
return this.vaultsData;
|
|
693
733
|
});
|
|
694
734
|
}
|
|
695
|
-
exports.
|
|
696
|
-
function
|
|
735
|
+
exports.getVaultsData = getVaultsData;
|
|
736
|
+
function getVaultData(vaultAddress) {
|
|
697
737
|
return __awaiter(this, void 0, void 0, function* () {
|
|
698
|
-
const
|
|
699
|
-
return
|
|
738
|
+
const vaultsData = yield this.getVaultsData();
|
|
739
|
+
return vaultsData[vaultAddress.toLowerCase()];
|
|
700
740
|
});
|
|
701
741
|
}
|
|
702
|
-
exports.
|
|
742
|
+
exports.getVaultData = getVaultData;
|
|
703
743
|
/**
|
|
704
744
|
* Whitelist
|
|
705
745
|
*/
|
|
@@ -759,36 +799,56 @@ exports.getWhitelistState = getWhitelistState;
|
|
|
759
799
|
/**
|
|
760
800
|
* User Data
|
|
761
801
|
*/
|
|
762
|
-
function
|
|
802
|
+
function fetchVaultsUserData(account) {
|
|
763
803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
804
|
+
const calls = [];
|
|
805
|
+
let vaultType;
|
|
806
|
+
// Collect all fetch promises
|
|
807
|
+
for (vaultType in subgraphs_1.VAULT_SUBGRAPH_URL[this.network]) {
|
|
808
|
+
const subgraphs = subgraphs_1.VAULT_SUBGRAPH_URL[this.network][vaultType];
|
|
809
|
+
if (!subgraphs || subgraphs.length === 0)
|
|
810
|
+
continue;
|
|
811
|
+
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.vaultsUserQuery(account)));
|
|
812
|
+
}
|
|
813
|
+
const results = yield Promise.all(calls);
|
|
814
|
+
const userVaultData = {};
|
|
815
|
+
let i = 0;
|
|
816
|
+
for (vaultType in subgraphs_1.VAULT_SUBGRAPH_URL[this.network]) {
|
|
817
|
+
const subgraphs = subgraphs_1.VAULT_SUBGRAPH_URL[this.network][vaultType];
|
|
818
|
+
if (!subgraphs || subgraphs.length === 0)
|
|
819
|
+
continue;
|
|
820
|
+
const result = results[i++];
|
|
821
|
+
const user = result.data.user;
|
|
822
|
+
if (user && user.positions) {
|
|
823
|
+
userVaultData[vaultType] = user.positions.map((position) => (Object.assign(Object.assign({}, position), { vaultType })));
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return userVaultData;
|
|
771
827
|
});
|
|
772
828
|
}
|
|
773
|
-
exports.
|
|
774
|
-
function
|
|
829
|
+
exports.fetchVaultsUserData = fetchVaultsUserData;
|
|
830
|
+
function initializeVaultsUserData(account) {
|
|
775
831
|
return __awaiter(this, void 0, void 0, function* () {
|
|
776
|
-
const
|
|
777
|
-
if (!positions)
|
|
778
|
-
return null;
|
|
832
|
+
const userVaultData = yield this.fetchVaultsUserData(account);
|
|
779
833
|
const result = {};
|
|
780
|
-
for (const
|
|
781
|
-
|
|
834
|
+
for (const vaultType in userVaultData) {
|
|
835
|
+
const positions = userVaultData[vaultType];
|
|
836
|
+
if (!positions)
|
|
837
|
+
continue;
|
|
838
|
+
result[vaultType] = {};
|
|
839
|
+
for (const position of positions) {
|
|
840
|
+
result[vaultType][position.lendingVault.id] = position;
|
|
841
|
+
}
|
|
782
842
|
}
|
|
783
843
|
return result;
|
|
784
844
|
});
|
|
785
845
|
}
|
|
786
|
-
exports.
|
|
787
|
-
function
|
|
846
|
+
exports.initializeVaultsUserData = initializeVaultsUserData;
|
|
847
|
+
function getVaultsUserData(account) {
|
|
788
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
789
|
-
if (!(account in this.
|
|
790
|
-
this.
|
|
791
|
-
return yield this.
|
|
849
|
+
if (!(account in this.vaultsUsersData))
|
|
850
|
+
this.vaultsUsersData[account] = this.initializeVaultsUserData(account);
|
|
851
|
+
return (yield this.vaultsUsersData[account]) || {};
|
|
792
852
|
});
|
|
793
853
|
}
|
|
794
|
-
exports.
|
|
854
|
+
exports.getVaultsUserData = getVaultsUserData;
|