@kasufinance/kasu-sdk 1.0.4 → 2.2.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/CLAUDE.md +410 -0
- package/README.md +179 -12
- package/dist/bundle.cjs.js +658 -90
- package/dist/bundle.esm.js +654 -92
- package/dist/facade/chain-configs.d.ts +11 -0
- package/dist/facade/chain-configs.js +84 -0
- package/dist/facade/chain-configs.js.map +1 -0
- package/dist/facade/deposits.d.ts +56 -0
- package/dist/facade/deposits.js +87 -0
- package/dist/facade/deposits.js.map +1 -0
- package/dist/facade/index.d.ts +6 -0
- package/dist/facade/index.js +9 -0
- package/dist/facade/index.js.map +1 -0
- package/dist/facade/kasu.d.ts +71 -0
- package/dist/facade/kasu.js +101 -0
- package/dist/facade/kasu.js.map +1 -0
- package/dist/facade/strategies.d.ts +37 -0
- package/dist/facade/strategies.js +112 -0
- package/dist/facade/strategies.js.map +1 -0
- package/dist/facade/types.d.ts +127 -0
- package/dist/facade/types.js +2 -0
- package/dist/facade/types.js.map +1 -0
- package/dist/facade/user-portfolio.d.ts +35 -0
- package/dist/facade/user-portfolio.js +53 -0
- package/dist/facade/user-portfolio.js.map +1 -0
- package/dist/index.d.ts +9 -17
- package/dist/index.js +9 -16
- package/dist/index.js.map +1 -1
- package/dist/kasu-sdk.d.ts +17 -0
- package/dist/kasu-sdk.js +17 -0
- package/dist/kasu-sdk.js.map +1 -0
- package/dist/sdk-config.d.ts +34 -4
- package/dist/sdk-config.js +9 -6
- package/dist/sdk-config.js.map +1 -1
- package/dist/services/DataService/data-service.d.ts +9 -2
- package/dist/services/DataService/data-service.js +91 -53
- package/dist/services/DataService/data-service.js.map +1 -1
- package/dist/services/DataService/queries.d.ts +0 -1
- package/dist/services/DataService/queries.js +0 -8
- package/dist/services/DataService/queries.js.map +1 -1
- package/dist/services/DataService/subgraph-types.d.ts +0 -6
- package/dist/services/DataService/types.d.ts +0 -1
- package/dist/services/Locking/locking.d.ts +9 -3
- package/dist/services/Locking/locking.js +114 -20
- package/dist/services/Locking/locking.js.map +1 -1
- package/dist/services/Locking/types.d.ts +1 -1
- package/dist/services/Portfolio/portfolio.d.ts +3 -2
- package/dist/services/Portfolio/portfolio.js +15 -7
- package/dist/services/Portfolio/portfolio.js.map +1 -1
- package/dist/services/Portfolio/types.d.ts +2 -2
- package/dist/services/UserLending/user-lending.d.ts +3 -1
- package/dist/services/UserLending/user-lending.js +9 -3
- package/dist/services/UserLending/user-lending.js.map +1 -1
- package/dist/tests/facade.test.d.ts +1 -0
- package/dist/tests/facade.test.js +196 -0
- package/dist/tests/facade.test.js.map +1 -0
- package/dist/tests/sample.test.js +19 -14
- package/dist/tests/sample.test.js.map +1 -1
- package/dist/utils/deployment-mode.d.ts +6 -0
- package/dist/utils/deployment-mode.js +8 -0
- package/dist/utils/deployment-mode.js.map +1 -0
- package/package.json +2 -2
- package/src/facade/chain-configs.ts +93 -0
- package/src/facade/deposits.ts +102 -0
- package/src/facade/index.ts +26 -0
- package/src/facade/kasu.ts +144 -0
- package/src/facade/strategies.ts +119 -0
- package/src/facade/types.ts +168 -0
- package/src/facade/user-portfolio.ts +73 -0
- package/src/index.ts +59 -25
- package/src/kasu-sdk.ts +27 -0
- package/src/sdk-config.ts +43 -15
- package/src/services/DataService/data-service.ts +106 -66
- package/src/services/DataService/queries.ts +0 -9
- package/src/services/DataService/subgraph-types.ts +0 -7
- package/src/services/DataService/types.ts +0 -1
- package/src/services/Locking/locking.ts +141 -25
- package/src/services/Locking/types.ts +1 -1
- package/src/services/Portfolio/portfolio.ts +21 -11
- package/src/services/Portfolio/types.ts +2 -2
- package/src/services/UserLending/user-lending.ts +13 -4
- package/src/tests/facade.test.ts +245 -0
- package/src/tests/sample.test.ts +7 -9
- package/src/utils/deployment-mode.ts +9 -0
package/dist/bundle.cjs.js
CHANGED
|
@@ -15616,14 +15616,6 @@ function filterArray(array, id_in) {
|
|
|
15616
15616
|
}
|
|
15617
15617
|
}
|
|
15618
15618
|
|
|
15619
|
-
const getPlumeTvl = gql `
|
|
15620
|
-
{
|
|
15621
|
-
lendingPools {
|
|
15622
|
-
id
|
|
15623
|
-
balance
|
|
15624
|
-
}
|
|
15625
|
-
}
|
|
15626
|
-
`;
|
|
15627
15619
|
const getPoolOverviewQuery = (ids) => gql `
|
|
15628
15620
|
query getAllPoolOverview($epochId: String!, $unusedPools: [String]!) {
|
|
15629
15621
|
lendingPools(
|
|
@@ -15777,17 +15769,36 @@ const getLendingPoolWithdrawalAndDepositsQuery = gql `
|
|
|
15777
15769
|
class DataService {
|
|
15778
15770
|
constructor(_kasuConfig, signerOrProvider) {
|
|
15779
15771
|
this._kasuConfig = _kasuConfig;
|
|
15780
|
-
this._plumeTvl = new Map();
|
|
15781
15772
|
this._externalTvlAbi = KasuPoolExternalTVLAbi__factory.connect(_kasuConfig.contracts.ExternalTVL, signerOrProvider);
|
|
15782
15773
|
this._graph = new GraphQLClient(_kasuConfig.subgraphUrl);
|
|
15783
|
-
|
|
15784
|
-
|
|
15785
|
-
|
|
15786
|
-
|
|
15774
|
+
if (_kasuConfig.directusUrl) {
|
|
15775
|
+
this._directus = le(_kasuConfig.directusUrl)
|
|
15776
|
+
.with(ne())
|
|
15777
|
+
.with(Zp());
|
|
15778
|
+
}
|
|
15779
|
+
else {
|
|
15780
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
15781
|
+
this._directus = null;
|
|
15782
|
+
}
|
|
15787
15783
|
}
|
|
15788
15784
|
getUrlFromFile(fileName) {
|
|
15789
15785
|
return `${this._kasuConfig.directusUrl}assets/${fileName}`;
|
|
15790
15786
|
}
|
|
15787
|
+
/**
|
|
15788
|
+
* Maps a pool ID to its metadata source pool ID.
|
|
15789
|
+
* Used for chains (XDC, Plume) that share Directus metadata with Base pools.
|
|
15790
|
+
*/
|
|
15791
|
+
getMetadataPoolId(poolId) {
|
|
15792
|
+
var _a;
|
|
15793
|
+
const normalizedId = poolId.toLowerCase();
|
|
15794
|
+
return (_a = this._kasuConfig.poolMetadataMapping[normalizedId]) !== null && _a !== void 0 ? _a : normalizedId;
|
|
15795
|
+
}
|
|
15796
|
+
/**
|
|
15797
|
+
* Maps an array of pool IDs to their metadata source pool IDs.
|
|
15798
|
+
*/
|
|
15799
|
+
getMetadataPoolIds(poolIds) {
|
|
15800
|
+
return poolIds.map((id) => this.getMetadataPoolId(id));
|
|
15801
|
+
}
|
|
15791
15802
|
calculatePoolCapacity(poolCapacities, poolCapacityPercentages, index, spillOver, lendingPoolSubgraph, lendingPoolConfig) {
|
|
15792
15803
|
const desiredDrawAmount = lendingPoolConfig.desiredDrawAmount; // subgraph
|
|
15793
15804
|
const desiredTrancheRatio = lendingPoolConfig.tranchesConfig[index].desiredRatio;
|
|
@@ -15834,7 +15845,7 @@ class DataService {
|
|
|
15834
15845
|
];
|
|
15835
15846
|
})));
|
|
15836
15847
|
for (const [id, tvl] of results) {
|
|
15837
|
-
tvlMap.set(id, utils$2.formatUnits(tvl,
|
|
15848
|
+
tvlMap.set(id, utils$2.formatUnits(tvl, this._kasuConfig.stableAssetDecimals));
|
|
15838
15849
|
}
|
|
15839
15850
|
}
|
|
15840
15851
|
catch (error) {
|
|
@@ -15845,7 +15856,7 @@ class DataService {
|
|
|
15845
15856
|
}
|
|
15846
15857
|
getPoolOverview(epochId, id_in) {
|
|
15847
15858
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15848
|
-
var _a, _b, _c;
|
|
15859
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
15849
15860
|
const trancheNames = [
|
|
15850
15861
|
['Senior'],
|
|
15851
15862
|
['Junior', 'Senior'],
|
|
@@ -15855,29 +15866,39 @@ class DataService {
|
|
|
15855
15866
|
unusedPools: this._kasuConfig.UNUSED_LENDING_POOL_IDS,
|
|
15856
15867
|
epochId,
|
|
15857
15868
|
});
|
|
15858
|
-
if (!this._plumeTvl.size) {
|
|
15859
|
-
const plumeResults = yield this._plumeGraph.request(getPlumeTvl);
|
|
15860
|
-
for (const pool of plumeResults.lendingPools) {
|
|
15861
|
-
this._plumeTvl.set(pool.id, pool.balance);
|
|
15862
|
-
}
|
|
15863
|
-
}
|
|
15864
15869
|
if (!this._directusPoolOverview) {
|
|
15865
|
-
|
|
15866
|
-
|
|
15867
|
-
|
|
15868
|
-
|
|
15869
|
-
|
|
15870
|
-
|
|
15871
|
-
|
|
15870
|
+
if (this._kasuConfig.directusUrl) {
|
|
15871
|
+
try {
|
|
15872
|
+
this._directusPoolOverview = yield this._directus.request(bs('PoolOverview', {
|
|
15873
|
+
filter: {
|
|
15874
|
+
enabled: {
|
|
15875
|
+
_eq: true,
|
|
15876
|
+
},
|
|
15877
|
+
},
|
|
15878
|
+
}));
|
|
15879
|
+
}
|
|
15880
|
+
catch (error) {
|
|
15881
|
+
console.warn('Directus fetch failed, falling back to on-chain data only:', error);
|
|
15882
|
+
this._directusPoolOverview = [];
|
|
15883
|
+
}
|
|
15884
|
+
}
|
|
15885
|
+
else {
|
|
15886
|
+
this._directusPoolOverview = [];
|
|
15887
|
+
}
|
|
15872
15888
|
}
|
|
15873
15889
|
const offchainTvlMap = yield this.getOffChainTvl(poolOverviewResults.lendingPools.map(({ id }) => id));
|
|
15874
15890
|
const retn = [];
|
|
15875
15891
|
for (const lendingPoolSubgraph of poolOverviewResults.lendingPools) {
|
|
15876
|
-
|
|
15892
|
+
// Use metadata mapping if available (for XDC/Plume pools that share metadata with Base)
|
|
15893
|
+
const metadataPoolId = (_a = this._kasuConfig.poolMetadataMapping[lendingPoolSubgraph.id]) !== null && _a !== void 0 ? _a : lendingPoolSubgraph.id;
|
|
15894
|
+
const lendingPoolDirectus = this._directusPoolOverview.find((r) => r.id.toLowerCase() === metadataPoolId);
|
|
15877
15895
|
const lendingPoolConfig = lendingPoolSubgraph.configuration;
|
|
15878
15896
|
if (!lendingPoolDirectus) {
|
|
15879
|
-
console.warn("Couldn't find directus pool for id: ", lendingPoolSubgraph.id
|
|
15880
|
-
|
|
15897
|
+
console.warn("Couldn't find directus pool for id: ", lendingPoolSubgraph.id, metadataPoolId !== lendingPoolSubgraph.id
|
|
15898
|
+
? `(mapped from ${metadataPoolId})`
|
|
15899
|
+
: '');
|
|
15900
|
+
// When Directus is unavailable or pool has no CMS entry,
|
|
15901
|
+
// use a fallback so the pool is still returned with on-chain data.
|
|
15881
15902
|
}
|
|
15882
15903
|
const poolCapacities = this.calculatePoolCapacity([], [], 0, 0, lendingPoolSubgraph, lendingPoolConfig);
|
|
15883
15904
|
const tranches = lendingPoolSubgraph.tranches
|
|
@@ -15944,49 +15965,50 @@ class DataService {
|
|
|
15944
15965
|
: parseFloat(tranche.balance) / trancheBalanceSum;
|
|
15945
15966
|
averageApy += parseFloat(trancheData.averageApy) * weight;
|
|
15946
15967
|
}
|
|
15947
|
-
const plumeTvl = lendingPoolDirectus.plumeStrategy &&
|
|
15948
|
-
this._plumeTvl.has(lendingPoolDirectus.plumeStrategy)
|
|
15949
|
-
? (_a = this._plumeTvl.get(lendingPoolDirectus.plumeStrategy)) !== null && _a !== void 0 ? _a : '0'
|
|
15950
|
-
: '0';
|
|
15951
15968
|
const offChainTvl = (_b = offchainTvlMap.get(lendingPoolSubgraph.id)) !== null && _b !== void 0 ? _b : '0';
|
|
15952
15969
|
const poolOverview = {
|
|
15953
15970
|
id: lendingPoolSubgraph.id,
|
|
15954
|
-
security: lendingPoolDirectus.security,
|
|
15955
|
-
enabled: lendingPoolDirectus.enabled,
|
|
15956
|
-
isOversubscribed: lendingPoolDirectus.oversubscribed,
|
|
15971
|
+
security: (_c = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.security) !== null && _c !== void 0 ? _c : [],
|
|
15972
|
+
enabled: (_d = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.enabled) !== null && _d !== void 0 ? _d : true,
|
|
15973
|
+
isOversubscribed: (_e = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.oversubscribed) !== null && _e !== void 0 ? _e : false,
|
|
15957
15974
|
apy: averageApy,
|
|
15958
|
-
description: lendingPoolDirectus.description,
|
|
15959
|
-
liteDescription: lendingPoolDirectus.liteDescription,
|
|
15960
|
-
thumbnailImageUrl:
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
|
|
15969
|
-
|
|
15970
|
-
|
|
15975
|
+
description: (_f = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.description) !== null && _f !== void 0 ? _f : '',
|
|
15976
|
+
liteDescription: (_g = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.liteDescription) !== null && _g !== void 0 ? _g : '',
|
|
15977
|
+
thumbnailImageUrl: (lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.thumbnailImage)
|
|
15978
|
+
? this.getUrlFromFile(lendingPoolDirectus.thumbnailImage)
|
|
15979
|
+
: '',
|
|
15980
|
+
bannerImageUrl: (lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.bannerImage)
|
|
15981
|
+
? this.getUrlFromFile(lendingPoolDirectus.bannerImage)
|
|
15982
|
+
: '',
|
|
15983
|
+
strategyDeckUrl: (lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.strategyDeck)
|
|
15984
|
+
? this.getUrlFromFile(lendingPoolDirectus.strategyDeck)
|
|
15985
|
+
: '',
|
|
15986
|
+
assetClass: (_h = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.assetClass) !== null && _h !== void 0 ? _h : '',
|
|
15987
|
+
industryExposure: (_j = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.industryExposure) !== null && _j !== void 0 ? _j : '',
|
|
15988
|
+
poolApyStructure: (_k = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.poolApyStructure) !== null && _k !== void 0 ? _k : 'Variable',
|
|
15989
|
+
apyExpiryDate: (_l = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.apyExpiryDate) !== null && _l !== void 0 ? _l : null,
|
|
15990
|
+
poolInvestmentTerm: (_m = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.poolInvestmentTerm) !== null && _m !== void 0 ? _m : '',
|
|
15991
|
+
loanStructure: (_o = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.loanStructure) !== null && _o !== void 0 ? _o : '',
|
|
15992
|
+
poolName: (_p = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.poolName) !== null && _p !== void 0 ? _p : lendingPoolSubgraph.name,
|
|
15993
|
+
subheading: lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.subheading,
|
|
15971
15994
|
totalValueLocked: {
|
|
15972
15995
|
total: (parseFloat(lendingPoolSubgraph.balance) +
|
|
15973
|
-
parseFloat(plumeTvl) +
|
|
15974
15996
|
parseFloat(offChainTvl)).toString(),
|
|
15975
15997
|
offchain: offChainTvl,
|
|
15976
|
-
plume: plumeTvl,
|
|
15977
15998
|
},
|
|
15978
|
-
loansUnderManagement: lendingPoolDirectus.loansUnderManagement,
|
|
15999
|
+
loansUnderManagement: (_q = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.loansUnderManagement) !== null && _q !== void 0 ? _q : '0',
|
|
15979
16000
|
yieldEarned: lendingPoolSubgraph.totalUserInterestAmount,
|
|
15980
16001
|
poolCapacity: poolCapacitySum.toString(),
|
|
15981
16002
|
poolCapacityPercentage: poolCapacityPercentageSum.toString(),
|
|
15982
|
-
activeLoans: lendingPoolDirectus.activeLoans,
|
|
15983
|
-
loanFundsOriginated: lendingPoolDirectus.loanFundsOriginated,
|
|
16003
|
+
activeLoans: (_r = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.activeLoans) !== null && _r !== void 0 ? _r : '0',
|
|
16004
|
+
loanFundsOriginated: (_s = lendingPoolDirectus === null || lendingPoolDirectus === void 0 ? void 0 : lendingPoolDirectus.loanFundsOriginated) !== null && _s !== void 0 ? _s : '0',
|
|
15984
16005
|
tranches: tranches,
|
|
15985
16006
|
isActive: !lendingPoolSubgraph.isStopped,
|
|
15986
16007
|
requestEpochsInAdvance: lendingPoolSubgraph.configuration
|
|
15987
16008
|
.lendingPoolWithdrawalConfig.requestEpochsInAdvance,
|
|
15988
16009
|
};
|
|
15989
|
-
// show only enabled pools
|
|
16010
|
+
// When Directus is available, show only enabled pools.
|
|
16011
|
+
// When Directus is unavailable, include all pools.
|
|
15990
16012
|
if (poolOverview.enabled) {
|
|
15991
16013
|
retn.push(poolOverview);
|
|
15992
16014
|
}
|
|
@@ -16206,7 +16228,11 @@ class DataService {
|
|
|
16206
16228
|
const lendingPoolsWithdrawalsAndDepositsSubgraph = yield this._graph.request(getLendingPoolWithdrawalAndDepositsQuery, { unusedPools: this._kasuConfig.UNUSED_LENDING_POOL_IDS });
|
|
16207
16229
|
const retn = [];
|
|
16208
16230
|
for (const data of poolRepaymentDirectus) {
|
|
16209
|
-
|
|
16231
|
+
// Find subgraph pool that maps to this Directus pool
|
|
16232
|
+
// On non-Base chains, subgraph pool IDs are different from Directus poolIdFK
|
|
16233
|
+
// Use getMetadataPoolId to map subgraph pool ID -> Directus/Base pool ID
|
|
16234
|
+
const lendingPoolSubgraph = lendingPoolsWithdrawalsAndDepositsSubgraph.lendingPools.find((pool) => this.getMetadataPoolId(pool.id) ===
|
|
16235
|
+
data.poolIdFK.toLowerCase());
|
|
16210
16236
|
if (lendingPoolSubgraph === undefined) {
|
|
16211
16237
|
continue;
|
|
16212
16238
|
}
|
|
@@ -16295,9 +16321,13 @@ class DataService {
|
|
|
16295
16321
|
retn.totalYieldEarned += parseFloat(poolOverview.yieldEarned);
|
|
16296
16322
|
}
|
|
16297
16323
|
for (const poolOverview of poolOverviews) {
|
|
16298
|
-
|
|
16324
|
+
// Map to metadata pool ID for Directus lookup (XDC pools → Base pools)
|
|
16325
|
+
const metadataPoolId = this.getMetadataPoolId(poolOverview.id);
|
|
16326
|
+
const riskManagement = riskManagements.find((rm) => rm.poolIdFK.toLowerCase() === metadataPoolId.toLowerCase());
|
|
16299
16327
|
if (!riskManagement) {
|
|
16300
|
-
console.warn("Couldn't find risk management for id: ", poolOverview.id
|
|
16328
|
+
console.warn("Couldn't find risk management for id: ", poolOverview.id, metadataPoolId !== poolOverview.id
|
|
16329
|
+
? `(mapped to ${metadataPoolId})`
|
|
16330
|
+
: '');
|
|
16301
16331
|
continue;
|
|
16302
16332
|
}
|
|
16303
16333
|
const weight = retn.totalLoanFundsOriginated === 0
|
|
@@ -16335,14 +16365,18 @@ class DataService {
|
|
|
16335
16365
|
}
|
|
16336
16366
|
|
|
16337
16367
|
class KSULocking {
|
|
16338
|
-
/**
|
|
16339
|
-
*
|
|
16340
|
-
*/
|
|
16341
16368
|
constructor(_kasuConfig, signerOrProvider) {
|
|
16342
16369
|
this._kasuConfig = _kasuConfig;
|
|
16343
16370
|
this.apyBonuses = [0, 0.001, 0.002];
|
|
16371
|
+
this._isLiteDeployment = _kasuConfig.isLiteDeployment;
|
|
16344
16372
|
this._contractAbi = IKSULockingAbi__factory.connect(_kasuConfig.contracts.IKSULocking, signerOrProvider);
|
|
16345
|
-
|
|
16373
|
+
// Only initialize KSU token contract if not a Lite deployment and address is provided
|
|
16374
|
+
if (!this._isLiteDeployment && _kasuConfig.contracts.KSUToken) {
|
|
16375
|
+
this._kasuToken = IERC20MetadataAbi__factory.connect(_kasuConfig.contracts.KSUToken, signerOrProvider);
|
|
16376
|
+
}
|
|
16377
|
+
else {
|
|
16378
|
+
this._kasuToken = null;
|
|
16379
|
+
}
|
|
16346
16380
|
this._userManagerAbi = IUserManagerAbi__factory.connect(_kasuConfig.contracts.UserManager, signerOrProvider);
|
|
16347
16381
|
this._systemVariablesAbi = ISystemVariablesAbi__factory.connect(_kasuConfig.contracts.SystemVariables, signerOrProvider);
|
|
16348
16382
|
this._ksuPriceAbi = IKsuPriceAbi__factory.connect(_kasuConfig.contracts.KsuPrice, signerOrProvider);
|
|
@@ -16350,13 +16384,25 @@ class KSULocking {
|
|
|
16350
16384
|
this._graph = new GraphQLClient(_kasuConfig.subgraphUrl);
|
|
16351
16385
|
this._userLoyaltyRewardsAbi = IUserLoyaltyRewardsAbi__factory.connect(_kasuConfig.contracts.UserLoyaltyRewards, signerOrProvider);
|
|
16352
16386
|
}
|
|
16387
|
+
/**
|
|
16388
|
+
* Check if this is a Lite deployment (no KSU token functionality)
|
|
16389
|
+
*/
|
|
16390
|
+
get isLiteDeployment() {
|
|
16391
|
+
return this._isLiteDeployment;
|
|
16392
|
+
}
|
|
16353
16393
|
lockKSUTokens(amount, lockPeriod) {
|
|
16354
16394
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16395
|
+
if (this._isLiteDeployment) {
|
|
16396
|
+
throw new Error('Locking is not available on Lite deployments');
|
|
16397
|
+
}
|
|
16355
16398
|
return this._contractAbi.lock(amount, lockPeriod);
|
|
16356
16399
|
});
|
|
16357
16400
|
}
|
|
16358
16401
|
lockKSUWithPermit(amount, lockPeriod, permit) {
|
|
16359
16402
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16403
|
+
if (this._isLiteDeployment) {
|
|
16404
|
+
throw new Error('Locking is not available on Lite deployments');
|
|
16405
|
+
}
|
|
16360
16406
|
const amountBN = ethers.BigNumber.from(amount);
|
|
16361
16407
|
const lockPeriodBN = ethers.BigNumber.from(lockPeriod);
|
|
16362
16408
|
const ksuPermit = {
|
|
@@ -16371,16 +16417,29 @@ class KSULocking {
|
|
|
16371
16417
|
}
|
|
16372
16418
|
unlockKSU(amount, userLockId) {
|
|
16373
16419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16420
|
+
if (this._isLiteDeployment) {
|
|
16421
|
+
throw new Error('Locking is not available on Lite deployments');
|
|
16422
|
+
}
|
|
16374
16423
|
return this._contractAbi.unlock(amount, userLockId);
|
|
16375
16424
|
});
|
|
16376
16425
|
}
|
|
16377
16426
|
claimFees() {
|
|
16378
16427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16428
|
+
if (this._isLiteDeployment) {
|
|
16429
|
+
throw new Error('Fee claiming is not available on Lite deployments');
|
|
16430
|
+
}
|
|
16379
16431
|
return yield this._contractAbi.claimFees();
|
|
16380
16432
|
});
|
|
16381
16433
|
}
|
|
16382
16434
|
lockDetails(lockPeriod) {
|
|
16383
16435
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16436
|
+
if (this._isLiteDeployment) {
|
|
16437
|
+
return {
|
|
16438
|
+
rKsuMultiplier: 0,
|
|
16439
|
+
ksuBonusMultiplier: 0,
|
|
16440
|
+
isActive: false,
|
|
16441
|
+
};
|
|
16442
|
+
}
|
|
16384
16443
|
const result = yield this._contractAbi.lockDetails(lockPeriod);
|
|
16385
16444
|
return {
|
|
16386
16445
|
rKsuMultiplier: result[0].toNumber(),
|
|
@@ -16391,12 +16450,15 @@ class KSULocking {
|
|
|
16391
16450
|
}
|
|
16392
16451
|
userTotalDeposits(userAddress) {
|
|
16393
16452
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16453
|
+
if (this._isLiteDeployment) {
|
|
16454
|
+
return ethers.BigNumber.from(0);
|
|
16455
|
+
}
|
|
16394
16456
|
return yield this._contractAbi.userTotalDeposits(userAddress);
|
|
16395
16457
|
});
|
|
16396
16458
|
}
|
|
16397
16459
|
calculateUserLockProjectedProtocolFeeRewards(epochId, KSULocked, lockPeriod) {
|
|
16398
16460
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16399
|
-
if (KSULocked === 0) {
|
|
16461
|
+
if (this._isLiteDeployment || KSULocked === 0) {
|
|
16400
16462
|
return 0;
|
|
16401
16463
|
}
|
|
16402
16464
|
const lockingSummarySubgraph = yield this._graph.request(lockingSummariesQuery);
|
|
@@ -16442,18 +16504,21 @@ class KSULocking {
|
|
|
16442
16504
|
}
|
|
16443
16505
|
getUserLocks(userAddress) {
|
|
16444
16506
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16507
|
+
if (this._isLiteDeployment) {
|
|
16508
|
+
return [];
|
|
16509
|
+
}
|
|
16445
16510
|
const result = yield this._graph.request(userLocksQuery, {
|
|
16446
16511
|
userAddress: userAddress.toLowerCase(),
|
|
16447
16512
|
});
|
|
16448
16513
|
const resultPromises = result.userLocks.map((userLock) => __awaiter(this, void 0, void 0, function* () {
|
|
16449
16514
|
const [, id] = userLock.id.split('-');
|
|
16450
|
-
const
|
|
16451
|
-
const loyaltyStatus = this.getLoyaltyLevelAndApyBonusFromRatio(
|
|
16515
|
+
const rKSUtoStableRatio = yield this.getRKSUvsStableRatio(userLock.rKSUAmount, userAddress);
|
|
16516
|
+
const loyaltyStatus = this.getLoyaltyLevelAndApyBonusFromRatio(rKSUtoStableRatio);
|
|
16452
16517
|
return {
|
|
16453
16518
|
id: ethers.BigNumber.from(id),
|
|
16454
16519
|
lockedAmount: userLock.ksuAmount,
|
|
16455
16520
|
rKSUAmount: userLock.rKSUAmount,
|
|
16456
|
-
|
|
16521
|
+
rKSUtoStableRatio: rKSUtoStableRatio,
|
|
16457
16522
|
apyBonus: loyaltyStatus.apyBonus,
|
|
16458
16523
|
loyaltyLevel: loyaltyStatus.loyaltyLevel,
|
|
16459
16524
|
startTime: parseFloat(userLock.startTimestamp),
|
|
@@ -16467,8 +16532,14 @@ class KSULocking {
|
|
|
16467
16532
|
}
|
|
16468
16533
|
getUserBonusData(userAddress) {
|
|
16469
16534
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16470
|
-
|
|
16471
|
-
|
|
16535
|
+
if (this._isLiteDeployment) {
|
|
16536
|
+
return {
|
|
16537
|
+
ksuBonusAndRewards: '0',
|
|
16538
|
+
ksuBonusAndRewardsLifetime: '0',
|
|
16539
|
+
protocolFeesEarned: '0',
|
|
16540
|
+
totalLockedAmount: '0',
|
|
16541
|
+
};
|
|
16542
|
+
}
|
|
16472
16543
|
const DECIMALS = 18;
|
|
16473
16544
|
// Normalized user address
|
|
16474
16545
|
const normalizedAddress = userAddress.toLowerCase();
|
|
@@ -16500,30 +16571,48 @@ class KSULocking {
|
|
|
16500
16571
|
};
|
|
16501
16572
|
});
|
|
16502
16573
|
}
|
|
16503
|
-
getLoyaltyLevelAndApyBonusFromRatio(
|
|
16504
|
-
|
|
16574
|
+
getLoyaltyLevelAndApyBonusFromRatio(rKSUtoStableRatio) {
|
|
16575
|
+
// On Lite deployments, always return level 0 with no bonus
|
|
16576
|
+
if (this._isLiteDeployment) {
|
|
16577
|
+
return { loyaltyLevel: 0, apyBonus: 0 };
|
|
16578
|
+
}
|
|
16579
|
+
if (rKSUtoStableRatio < 0.01) {
|
|
16505
16580
|
return { loyaltyLevel: 0, apyBonus: this.apyBonuses[0] };
|
|
16506
16581
|
}
|
|
16507
|
-
else if (
|
|
16582
|
+
else if (rKSUtoStableRatio < 0.05) {
|
|
16508
16583
|
return { loyaltyLevel: 1, apyBonus: this.apyBonuses[1] };
|
|
16509
16584
|
}
|
|
16510
16585
|
return { loyaltyLevel: 2, apyBonus: this.apyBonuses[2] };
|
|
16511
16586
|
}
|
|
16512
|
-
|
|
16587
|
+
getRKSUvsStableRatio(rKSUAmount, userAddress) {
|
|
16513
16588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16589
|
+
if (this._isLiteDeployment) {
|
|
16590
|
+
return 0;
|
|
16591
|
+
}
|
|
16514
16592
|
const [depositedAmount, pendingAmount] = yield this._userManagerAbi.userTotalPendingAndActiveDepositedAmountForCurrentEpoch(userAddress);
|
|
16515
16593
|
const ksuPrice = yield this._systemVariablesAbi.ksuEpochTokenPrice();
|
|
16516
16594
|
const rKSUAmountBignumber = ethers.ethers.utils.parseUnits(rKSUAmount, 18);
|
|
16517
|
-
const
|
|
16518
|
-
|
|
16595
|
+
const totalUserStableAmount = depositedAmount.toNumber() + pendingAmount.toNumber();
|
|
16596
|
+
// Convert rKSU value to stable asset units: rKSU * ksuPrice / 1e18 / 1e(18 - stableDecimals)
|
|
16597
|
+
const decimalDiff = 18 - this._kasuConfig.stableAssetDecimals;
|
|
16598
|
+
const rKSUInStable = rKSUAmountBignumber
|
|
16519
16599
|
.mul(ksuPrice)
|
|
16520
16600
|
.div(ethers.ethers.utils.parseUnits('1', 18))
|
|
16521
|
-
.div(ethers.ethers.utils.parseUnits('1',
|
|
16522
|
-
return
|
|
16601
|
+
.div(ethers.ethers.utils.parseUnits('1', decimalDiff));
|
|
16602
|
+
return rKSUInStable.toNumber() / totalUserStableAmount;
|
|
16603
|
+
});
|
|
16604
|
+
}
|
|
16605
|
+
/** @deprecated Use `getRKSUvsStableRatio` instead. */
|
|
16606
|
+
getRKSUvsUSDCRatio(rKSUAmount, userAddress) {
|
|
16607
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16608
|
+
return this.getRKSUvsStableRatio(rKSUAmount, userAddress);
|
|
16523
16609
|
});
|
|
16524
16610
|
}
|
|
16525
16611
|
getClaimableRewards(userAddress) {
|
|
16526
16612
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16613
|
+
if (this._isLiteDeployment) {
|
|
16614
|
+
return ethers.BigNumber.from(0);
|
|
16615
|
+
}
|
|
16527
16616
|
const result = yield this._contractAbi.rewards(userAddress);
|
|
16528
16617
|
return result;
|
|
16529
16618
|
});
|
|
@@ -16531,6 +16620,7 @@ class KSULocking {
|
|
|
16531
16620
|
getKasuTokenPrice() {
|
|
16532
16621
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16533
16622
|
const decimals = 18;
|
|
16623
|
+
// Price can still be queried on Lite deployments (set to 0 or configured value)
|
|
16534
16624
|
return Promise.resolve({
|
|
16535
16625
|
price: yield this._ksuPriceAbi.ksuTokenPrice(),
|
|
16536
16626
|
decimals,
|
|
@@ -16549,6 +16639,9 @@ class KSULocking {
|
|
|
16549
16639
|
getLifetimeRewards(userAddress, rewardDecimals, claimableRewards) {
|
|
16550
16640
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16551
16641
|
var _a, _b;
|
|
16642
|
+
if (this._isLiteDeployment) {
|
|
16643
|
+
return ethers.BigNumber.from(0);
|
|
16644
|
+
}
|
|
16552
16645
|
const result = yield this._graph.request(claimedFeesQuery, {
|
|
16553
16646
|
userAddress: userAddress.toLowerCase(),
|
|
16554
16647
|
});
|
|
@@ -16560,6 +16653,9 @@ class KSULocking {
|
|
|
16560
16653
|
});
|
|
16561
16654
|
}
|
|
16562
16655
|
getLaunchBonusAmount(lockAmount, bonusMultiplier, bonusTokensLeft) {
|
|
16656
|
+
if (this._isLiteDeployment) {
|
|
16657
|
+
return ethers.BigNumber.from(0);
|
|
16658
|
+
}
|
|
16563
16659
|
const bonusMultiplierBN = ethers.ethers.utils.parseUnits(bonusMultiplier.toFixed(2), 2);
|
|
16564
16660
|
const projectedBonus = lockAmount.mul(bonusMultiplierBN).div(100);
|
|
16565
16661
|
if (bonusTokensLeft.gt(projectedBonus)) {
|
|
@@ -16571,6 +16667,9 @@ class KSULocking {
|
|
|
16571
16667
|
}
|
|
16572
16668
|
getUserStakedKsu(userAddress) {
|
|
16573
16669
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16670
|
+
if (this._isLiteDeployment) {
|
|
16671
|
+
return '0';
|
|
16672
|
+
}
|
|
16574
16673
|
const result = yield this._graph.request(userStakedKsuQuery, {
|
|
16575
16674
|
userAddress: userAddress.toLowerCase(),
|
|
16576
16675
|
});
|
|
@@ -16582,6 +16681,9 @@ class KSULocking {
|
|
|
16582
16681
|
}
|
|
16583
16682
|
getUserEarnedrKsu(userAddress) {
|
|
16584
16683
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16684
|
+
if (this._isLiteDeployment) {
|
|
16685
|
+
return '0';
|
|
16686
|
+
}
|
|
16585
16687
|
const result = yield this._graph.request(userEarnedrKsuQuery, {
|
|
16586
16688
|
userAddress: userAddress.toLowerCase(),
|
|
16587
16689
|
});
|
|
@@ -16593,6 +16695,9 @@ class KSULocking {
|
|
|
16593
16695
|
}
|
|
16594
16696
|
getUserTotalBonusAmount(userAddress) {
|
|
16595
16697
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16698
|
+
if (this._isLiteDeployment) {
|
|
16699
|
+
return '0';
|
|
16700
|
+
}
|
|
16596
16701
|
const result = yield this._graph.request(userTotalBonusAmountQuery, {
|
|
16597
16702
|
userAddress: userAddress.toLowerCase(),
|
|
16598
16703
|
});
|
|
@@ -16604,7 +16709,13 @@ class KSULocking {
|
|
|
16604
16709
|
}
|
|
16605
16710
|
getLockingRewards(userAddress) {
|
|
16606
16711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16607
|
-
|
|
16712
|
+
if (this._isLiteDeployment) {
|
|
16713
|
+
return {
|
|
16714
|
+
claimableRewards: '0',
|
|
16715
|
+
lifeTimeRewards: '0',
|
|
16716
|
+
};
|
|
16717
|
+
}
|
|
16718
|
+
const rewardDecimals = this._kasuConfig.stableAssetDecimals;
|
|
16608
16719
|
const claimableRewards = yield this.getClaimableRewards(userAddress);
|
|
16609
16720
|
const lifeTimeRewards = yield this.getLifetimeRewards(userAddress, rewardDecimals, claimableRewards);
|
|
16610
16721
|
return {
|
|
@@ -16620,12 +16731,18 @@ class KSULocking {
|
|
|
16620
16731
|
}
|
|
16621
16732
|
getAvailableKsuBonus() {
|
|
16622
16733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16734
|
+
if (this._isLiteDeployment || !this._kasuToken) {
|
|
16735
|
+
return '0';
|
|
16736
|
+
}
|
|
16623
16737
|
const amount = yield this._kasuToken.balanceOf(this._kasuBonusAddress);
|
|
16624
16738
|
return utils$2.formatEther(amount);
|
|
16625
16739
|
});
|
|
16626
16740
|
}
|
|
16627
16741
|
getUserKsuBalance(userAddress) {
|
|
16628
16742
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16743
|
+
if (this._isLiteDeployment || !this._kasuToken) {
|
|
16744
|
+
return '0';
|
|
16745
|
+
}
|
|
16629
16746
|
const balance = yield this._kasuToken.balanceOf(userAddress.toLowerCase());
|
|
16630
16747
|
return utils$2.formatEther(balance);
|
|
16631
16748
|
});
|
|
@@ -16652,6 +16769,9 @@ class KSULocking {
|
|
|
16652
16769
|
}
|
|
16653
16770
|
getActiveLockPeriods() {
|
|
16654
16771
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16772
|
+
if (this._isLiteDeployment) {
|
|
16773
|
+
return [];
|
|
16774
|
+
}
|
|
16655
16775
|
const data = yield this._graph.request(lockingPeriodsQuery);
|
|
16656
16776
|
return data.lockPeriods;
|
|
16657
16777
|
});
|
|
@@ -16659,9 +16779,21 @@ class KSULocking {
|
|
|
16659
16779
|
getProjectedApy() {
|
|
16660
16780
|
return '10.00';
|
|
16661
16781
|
}
|
|
16662
|
-
|
|
16782
|
+
getProjectedStableAmount() {
|
|
16663
16783
|
return '20.00';
|
|
16664
16784
|
}
|
|
16785
|
+
/** @deprecated Use `getProjectedStableAmount` instead. */
|
|
16786
|
+
getProjectedUSDC() {
|
|
16787
|
+
return this.getProjectedStableAmount();
|
|
16788
|
+
}
|
|
16789
|
+
}
|
|
16790
|
+
|
|
16791
|
+
/**
|
|
16792
|
+
* Check if the SDK is configured for a Lite deployment.
|
|
16793
|
+
* Lite deployments don't have KSU token, locking, or loyalty features.
|
|
16794
|
+
*/
|
|
16795
|
+
function isLiteDeployment(config) {
|
|
16796
|
+
return config.isLiteDeployment;
|
|
16665
16797
|
}
|
|
16666
16798
|
|
|
16667
16799
|
const USER_REQUEST_EVENT_MAP = {
|
|
@@ -16956,13 +17088,19 @@ class UserLending {
|
|
|
16956
17088
|
return yield this._lendingPoolManagerAbi.requestWithdrawal(lendingPool, tranche, amount);
|
|
16957
17089
|
});
|
|
16958
17090
|
}
|
|
16959
|
-
|
|
17091
|
+
requestWithdrawalInAsset(lendingPool, tranche, assetAmount) {
|
|
16960
17092
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16961
17093
|
const trancheContract = ILendingPoolTrancheAbi__factory.connect(tranche, this._signerOrProvider);
|
|
16962
|
-
const shareAmount = yield trancheContract.convertToShares(
|
|
17094
|
+
const shareAmount = yield trancheContract.convertToShares(assetAmount);
|
|
16963
17095
|
return yield this._lendingPoolManagerAbi.requestWithdrawal(lendingPool, tranche, shareAmount);
|
|
16964
17096
|
});
|
|
16965
17097
|
}
|
|
17098
|
+
/** @deprecated Use `requestWithdrawalInAsset` instead. */
|
|
17099
|
+
requestWithdrawalInUSDC(lendingPool, tranche, amount) {
|
|
17100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17101
|
+
return this.requestWithdrawalInAsset(lendingPool, tranche, amount);
|
|
17102
|
+
});
|
|
17103
|
+
}
|
|
16966
17104
|
requestWithdrawalMax(lendingPool, tranche, user) {
|
|
16967
17105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16968
17106
|
const trancheContract = ILendingPoolTrancheAbi__factory.connect(tranche, this._signerOrProvider);
|
|
@@ -17244,7 +17382,7 @@ class UserLending {
|
|
|
17244
17382
|
lendingPool.id.toLowerCase())) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : ethers.BigNumber.from(0);
|
|
17245
17383
|
return {
|
|
17246
17384
|
poolId: lendingPool.id,
|
|
17247
|
-
yieldEarned: parseFloat(ethers.ethers.utils.formatUnits(balance,
|
|
17385
|
+
yieldEarned: parseFloat(ethers.ethers.utils.formatUnits(balance, this._kasuConfig.stableAssetDecimals)) -
|
|
17248
17386
|
parseFloat(totalAcceptedDeposits) -
|
|
17249
17387
|
-parseFloat(totalAcceptedWithdrawnAmount),
|
|
17250
17388
|
balance,
|
|
@@ -17516,7 +17654,10 @@ class Portfolio {
|
|
|
17516
17654
|
this._systemVariablesAbi = ISystemVariablesAbi__factory.connect(_kasuConfig.contracts.SystemVariables, signerOrProvider);
|
|
17517
17655
|
this._userLoyaltyRewardsAbi = IUserLoyaltyRewardsAbi__factory.connect(_kasuConfig.contracts.UserLoyaltyRewards, signerOrProvider);
|
|
17518
17656
|
this._userLendingService = new UserLending(_kasuConfig, signerOrProvider);
|
|
17519
|
-
this.
|
|
17657
|
+
this._isLiteDeployment = isLiteDeployment(_kasuConfig);
|
|
17658
|
+
this._kasuNftContract = _kasuConfig.contracts.KasuNFTs
|
|
17659
|
+
? IKasuNFTsAbi__factory.connect(_kasuConfig.contracts.KasuNFTs, signerOrProvider)
|
|
17660
|
+
: null;
|
|
17520
17661
|
this._graph = new GraphQLClient(_kasuConfig.subgraphUrl);
|
|
17521
17662
|
}
|
|
17522
17663
|
computeYieldMetrics(portfolioLendingPools) {
|
|
@@ -17562,8 +17703,8 @@ class Portfolio {
|
|
|
17562
17703
|
return this.computeYieldMetrics(portfolioLendingPools);
|
|
17563
17704
|
}
|
|
17564
17705
|
/**
|
|
17565
|
-
* Calculate the user's weekly protocol fee share (
|
|
17566
|
-
* system variables and locking summary. All inputs are expected to be pre-fetched.
|
|
17706
|
+
* Calculate the user's weekly protocol fee share (in stable asset units) given tranche
|
|
17707
|
+
* balances/configs, system variables and locking summary. All inputs are expected to be pre-fetched.
|
|
17567
17708
|
*/
|
|
17568
17709
|
calculateWeeklyProtocolFees(params) {
|
|
17569
17710
|
var _a, _b;
|
|
@@ -17605,8 +17746,8 @@ class Portfolio {
|
|
|
17605
17746
|
const totalUserDeposits = userDepositAmounts[0].add(userDepositAmounts[1]);
|
|
17606
17747
|
if (totalUserDeposits.isZero())
|
|
17607
17748
|
return 0;
|
|
17608
|
-
const
|
|
17609
|
-
const { loyaltyLevel } = this._lockingService.getLoyaltyLevelAndApyBonusFromRatio(
|
|
17749
|
+
const rKSUtoStableRatio = yield this._lockingService.getRKSUvsStableRatio(userRksuAmount, userAddress);
|
|
17750
|
+
const { loyaltyLevel } = this._lockingService.getLoyaltyLevelAndApyBonusFromRatio(rKSUtoStableRatio);
|
|
17610
17751
|
const loyaltyRewardRate = yield this._userLoyaltyRewardsAbi.loyaltyEpochRewardRates(loyaltyLevel);
|
|
17611
17752
|
if (loyaltyRewardRate.isZero() || ksuEpochPrice.price.isZero()) {
|
|
17612
17753
|
return 0;
|
|
@@ -17634,9 +17775,9 @@ class Portfolio {
|
|
|
17634
17775
|
},
|
|
17635
17776
|
protocolFees: {
|
|
17636
17777
|
claimableBalance: {
|
|
17637
|
-
|
|
17778
|
+
stableAmount: lockingRewards.claimableRewards,
|
|
17638
17779
|
},
|
|
17639
|
-
lifeTime: {
|
|
17780
|
+
lifeTime: { stableAmount: lockingRewards.lifeTimeRewards },
|
|
17640
17781
|
},
|
|
17641
17782
|
ksuLaunchBonus: { lifeTime: { ksuAmount: ksuLaunchBonus } },
|
|
17642
17783
|
};
|
|
@@ -17644,6 +17785,10 @@ class Portfolio {
|
|
|
17644
17785
|
}
|
|
17645
17786
|
getUserNfts(userAddress) {
|
|
17646
17787
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17788
|
+
// NFTs are not available on Lite deployments
|
|
17789
|
+
if (this._isLiteDeployment || !this._kasuNftContract) {
|
|
17790
|
+
return [];
|
|
17791
|
+
}
|
|
17647
17792
|
const usernfts = yield this._kasuNftContract.tokensOfOwner(userAddress);
|
|
17648
17793
|
return usernfts.map((nft) => nft.toNumber());
|
|
17649
17794
|
});
|
|
@@ -21744,4 +21889,427 @@ class KasuSdk {
|
|
|
21744
21889
|
}
|
|
21745
21890
|
}
|
|
21746
21891
|
|
|
21892
|
+
class SdkConfig {
|
|
21893
|
+
constructor(options) {
|
|
21894
|
+
var _a, _b, _c, _d;
|
|
21895
|
+
this.subgraphUrl = options.subgraphUrl;
|
|
21896
|
+
this.contracts = options.contracts;
|
|
21897
|
+
this.directusUrl = (_a = options.directusUrl) !== null && _a !== void 0 ? _a : '';
|
|
21898
|
+
this.UNUSED_LENDING_POOL_IDS = options.UNUSED_LENDING_POOL_IDS;
|
|
21899
|
+
this.isLiteDeployment = (_b = options.isLiteDeployment) !== null && _b !== void 0 ? _b : false;
|
|
21900
|
+
this.poolMetadataMapping = (_c = options.poolMetadataMapping) !== null && _c !== void 0 ? _c : {};
|
|
21901
|
+
this.stableAssetDecimals = (_d = options.stableAssetDecimals) !== null && _d !== void 0 ? _d : 6;
|
|
21902
|
+
}
|
|
21903
|
+
}
|
|
21904
|
+
|
|
21905
|
+
/**
|
|
21906
|
+
* Built-in chain configurations for Kasu-supported networks.
|
|
21907
|
+
*
|
|
21908
|
+
* Usage:
|
|
21909
|
+
* ```ts
|
|
21910
|
+
* import { CHAIN_CONFIGS } from '@kasufinance/kasu-sdk';
|
|
21911
|
+
* const base = CHAIN_CONFIGS.base;
|
|
21912
|
+
* ```
|
|
21913
|
+
*/
|
|
21914
|
+
const CHAIN_CONFIGS = {
|
|
21915
|
+
base: {
|
|
21916
|
+
chainId: 8453,
|
|
21917
|
+
name: 'Base Mainnet',
|
|
21918
|
+
isLiteDeployment: false,
|
|
21919
|
+
contracts: {
|
|
21920
|
+
KSUToken: '0x5D9b878744dbe721a3f33A60a6b102E289CeADBA',
|
|
21921
|
+
IKSULocking: '0xB145C061684C701c2C018A3f322aa14F5A553CE1',
|
|
21922
|
+
IKSULockBonus: '0xEEDE30AcF16caFf49c1a48F75185C67Be2e20B40',
|
|
21923
|
+
LendingPoolManager: '0xE1Be322323a412579b4A09fB08ff4bfcA12096B5',
|
|
21924
|
+
UserManager: '0x5Dc8D315a80fd99AbEF0f327B9a52a3FBC3C93f3',
|
|
21925
|
+
KasuAllowList: '0x807A7e119EBf0282420b5Ca0e0056c0525cBf8BB',
|
|
21926
|
+
SystemVariables: '0x193Bb02A24F5562b58fEB86550e6f09Bb6c41f69',
|
|
21927
|
+
KsuPrice: '0x221a54CbbD5f490Bd8e77CF36acBA4B1304E5c1b',
|
|
21928
|
+
UserLoyaltyRewards: '0xB4784f69Bb1F1076F50907cB0a815908a719D635',
|
|
21929
|
+
ClearingCoordinator: '0x2cF12A6d91fa4bEB5a4C17589a03e78F88f57DE2',
|
|
21930
|
+
KasuNFTs: '0x4946fF5f1a6550524C425479022D50446AA2968E',
|
|
21931
|
+
ExternalTVL: '0x662379FEBb3e4F91400B5f7d4f7F7ce4699F3c9F',
|
|
21932
|
+
},
|
|
21933
|
+
subgraphUrl: 'https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-base/v1.0.13/gn',
|
|
21934
|
+
directusUrl: 'https://kasu-finance.directus.app/',
|
|
21935
|
+
unusedPoolIds: [],
|
|
21936
|
+
poolMetadataMapping: undefined,
|
|
21937
|
+
},
|
|
21938
|
+
xdc: {
|
|
21939
|
+
chainId: 50,
|
|
21940
|
+
name: 'XDC Mainnet',
|
|
21941
|
+
isLiteDeployment: true,
|
|
21942
|
+
contracts: {
|
|
21943
|
+
// No KSUToken on Lite deployments
|
|
21944
|
+
IKSULocking: '0x7fF469f8c5fba92A9051B8D28794CBb891760e81',
|
|
21945
|
+
IKSULockBonus: '0x7cc1434EfA50301Fdd56B7c5c6fF7e30Dc20C55c',
|
|
21946
|
+
LendingPoolManager: '0xa46143db92aBe5bB1f61d13d8C1cCd50fc40Ca10',
|
|
21947
|
+
UserManager: '0x9b57dF89e59235f0481A5Fae942302c8831e1B81',
|
|
21948
|
+
KasuAllowList: '0x32c1Ff5FbBe6D28503ddc46E5001C0D13d6E9B2A',
|
|
21949
|
+
SystemVariables: '0x34d17c9DD1f31Fb34757DE923EC083601d0eDFFe',
|
|
21950
|
+
KsuPrice: '0x666b589933965bF8B378eD973f0404b6cae0eb52',
|
|
21951
|
+
UserLoyaltyRewards: '0xb95834C5610A178be9065Dd1EF78258D29879CDb',
|
|
21952
|
+
ClearingCoordinator: '0xAF0a66953Eba1c5353eB7425b398B213Bb2c6121',
|
|
21953
|
+
// No KasuNFTs on Lite deployments
|
|
21954
|
+
ExternalTVL: '0xCCB4156964377CF36441f3775A2A800dbeCB8094',
|
|
21955
|
+
},
|
|
21956
|
+
subgraphUrl: 'https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-xdc/v1.0.0/gn',
|
|
21957
|
+
directusUrl: 'https://kasu-finance.directus.app/',
|
|
21958
|
+
unusedPoolIds: [],
|
|
21959
|
+
poolMetadataMapping: {
|
|
21960
|
+
'0x20f42fb45f91657acf9528b99a5a16d0229c7800': '0xc987350716fe4a7d674c3591c391d29eba26b8ce',
|
|
21961
|
+
'0x3b7cb493aa22f731db2ab424d918e7375e00f6a9': '0x03f93c8caa9a82e000d35673ba34a4c0e6e117a2',
|
|
21962
|
+
'0xeda50c91a8c4ca8a83652b8542c0b3bd00a71fad': '0xc347a9e4aec8c8d11a149d2907deb2bf23b81c6f',
|
|
21963
|
+
},
|
|
21964
|
+
},
|
|
21965
|
+
plume: {
|
|
21966
|
+
chainId: 98866,
|
|
21967
|
+
name: 'Plume Mainnet',
|
|
21968
|
+
isLiteDeployment: true,
|
|
21969
|
+
contracts: {
|
|
21970
|
+
// Placeholder — update when Plume contracts are deployed
|
|
21971
|
+
IKSULocking: '',
|
|
21972
|
+
IKSULockBonus: '',
|
|
21973
|
+
LendingPoolManager: '',
|
|
21974
|
+
UserManager: '',
|
|
21975
|
+
KasuAllowList: '',
|
|
21976
|
+
SystemVariables: '',
|
|
21977
|
+
KsuPrice: '',
|
|
21978
|
+
UserLoyaltyRewards: '',
|
|
21979
|
+
ClearingCoordinator: '',
|
|
21980
|
+
ExternalTVL: '',
|
|
21981
|
+
},
|
|
21982
|
+
subgraphUrl: 'https://api.goldsky.com/api/public/project_cmgzlpxm300765np2a19421om/subgraphs/kasu-plume/prod',
|
|
21983
|
+
directusUrl: 'https://kasu-finance.directus.app/',
|
|
21984
|
+
unusedPoolIds: [],
|
|
21985
|
+
poolMetadataMapping: undefined,
|
|
21986
|
+
},
|
|
21987
|
+
};
|
|
21988
|
+
|
|
21989
|
+
/**
|
|
21990
|
+
* High-level facade for deposit and withdrawal operations.
|
|
21991
|
+
*
|
|
21992
|
+
* Integrators use this to submit on-chain transactions without
|
|
21993
|
+
* worrying about internal encoding details.
|
|
21994
|
+
*/
|
|
21995
|
+
class DepositsFacade {
|
|
21996
|
+
constructor(_userLending, _chainId) {
|
|
21997
|
+
this._userLending = _userLending;
|
|
21998
|
+
this._chainId = _chainId;
|
|
21999
|
+
}
|
|
22000
|
+
/**
|
|
22001
|
+
* Submit a deposit request.
|
|
22002
|
+
*
|
|
22003
|
+
* The integrator must first obtain a KYC signature via the Nexera flow
|
|
22004
|
+
* using the params from `buildKycParams()`.
|
|
22005
|
+
*
|
|
22006
|
+
* ```ts
|
|
22007
|
+
* const kycParams = kasu.deposits.buildKycParams('0xUser...');
|
|
22008
|
+
* // ... obtain kycSignature from your backend via Nexera ...
|
|
22009
|
+
* const tx = await kasu.deposits.deposit({
|
|
22010
|
+
* poolId: '0x...',
|
|
22011
|
+
* trancheId: '0x...',
|
|
22012
|
+
* amount: parseUnits('1000', 6), // 6 decimals for USDC/AUDD; use token's actual decimals
|
|
22013
|
+
* kycSignature: { blockExpiration, signature },
|
|
22014
|
+
* });
|
|
22015
|
+
* ```
|
|
22016
|
+
*/
|
|
22017
|
+
deposit(params) {
|
|
22018
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22019
|
+
var _a, _b, _c, _d;
|
|
22020
|
+
return yield this._userLending.requestDepositWithKyc(params.poolId, params.trancheId, params.amount, (_a = params.swapData) !== null && _a !== void 0 ? _a : '0x', (_b = params.fixedTermConfigId) !== null && _b !== void 0 ? _b : 0, (_c = params.depositData) !== null && _c !== void 0 ? _c : '0x', params.kycSignature, (_d = params.ethValue) !== null && _d !== void 0 ? _d : '0');
|
|
22021
|
+
});
|
|
22022
|
+
}
|
|
22023
|
+
/**
|
|
22024
|
+
* Submit a withdrawal request for a specific stable asset amount.
|
|
22025
|
+
*/
|
|
22026
|
+
withdraw(params) {
|
|
22027
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22028
|
+
return yield this._userLending.requestWithdrawalInAsset(params.poolId, params.trancheId, params.amount);
|
|
22029
|
+
});
|
|
22030
|
+
}
|
|
22031
|
+
/**
|
|
22032
|
+
* Withdraw the entire balance from a tranche.
|
|
22033
|
+
*/
|
|
22034
|
+
withdrawMax(poolId, trancheId, userAddress) {
|
|
22035
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22036
|
+
return yield this._userLending.requestWithdrawalMax(poolId, trancheId, userAddress);
|
|
22037
|
+
});
|
|
22038
|
+
}
|
|
22039
|
+
/**
|
|
22040
|
+
* Build KYC signature parameters for the Nexera verification flow.
|
|
22041
|
+
*
|
|
22042
|
+
* The integrator is responsible for sending these to their backend,
|
|
22043
|
+
* which obtains the signature from Nexera's signing service.
|
|
22044
|
+
*/
|
|
22045
|
+
buildKycParams(userAddress) {
|
|
22046
|
+
return this._userLending.buildKycSignatureParams(userAddress, this._chainId);
|
|
22047
|
+
}
|
|
22048
|
+
/**
|
|
22049
|
+
* Check whether the pool is currently in a clearing period
|
|
22050
|
+
* (deposits/withdrawals are temporarily paused).
|
|
22051
|
+
*/
|
|
22052
|
+
isClearingPending(poolId) {
|
|
22053
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22054
|
+
return yield this._userLending.isClearingPending(poolId);
|
|
22055
|
+
});
|
|
22056
|
+
}
|
|
22057
|
+
/**
|
|
22058
|
+
* Get the current epoch number.
|
|
22059
|
+
*/
|
|
22060
|
+
getCurrentEpoch() {
|
|
22061
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22062
|
+
return yield this._userLending.getCurrentEpoch();
|
|
22063
|
+
});
|
|
22064
|
+
}
|
|
22065
|
+
}
|
|
22066
|
+
|
|
22067
|
+
/**
|
|
22068
|
+
* High-level facade for browsing Kasu lending strategies (pools).
|
|
22069
|
+
*
|
|
22070
|
+
* Handles epoch fetching internally so callers never need to know about epochs.
|
|
22071
|
+
*/
|
|
22072
|
+
class StrategiesFacade {
|
|
22073
|
+
constructor(_dataService, _userLending) {
|
|
22074
|
+
this._dataService = _dataService;
|
|
22075
|
+
this._userLending = _userLending;
|
|
22076
|
+
}
|
|
22077
|
+
/**
|
|
22078
|
+
* Fetch all active lending strategies.
|
|
22079
|
+
*
|
|
22080
|
+
* ```ts
|
|
22081
|
+
* const strategies = await kasu.strategies.getAll();
|
|
22082
|
+
* ```
|
|
22083
|
+
*/
|
|
22084
|
+
getAll(poolIds) {
|
|
22085
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22086
|
+
const epochId = yield this._userLending.getCurrentEpoch();
|
|
22087
|
+
const pools = yield this._dataService.getPoolOverview(epochId, poolIds);
|
|
22088
|
+
return pools.map((pool) => this.mapPoolToStrategy(pool));
|
|
22089
|
+
});
|
|
22090
|
+
}
|
|
22091
|
+
/**
|
|
22092
|
+
* Fetch a single strategy by pool ID. Returns `null` if not found.
|
|
22093
|
+
*/
|
|
22094
|
+
getById(poolId) {
|
|
22095
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22096
|
+
var _a;
|
|
22097
|
+
const results = yield this.getAll([poolId]);
|
|
22098
|
+
return (_a = results[0]) !== null && _a !== void 0 ? _a : null;
|
|
22099
|
+
});
|
|
22100
|
+
}
|
|
22101
|
+
/**
|
|
22102
|
+
* Aggregate platform statistics (TVL, loans, yield, loss rate).
|
|
22103
|
+
*/
|
|
22104
|
+
getPlatformStats() {
|
|
22105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22106
|
+
const epochId = yield this._userLending.getCurrentEpoch();
|
|
22107
|
+
const pools = yield this._dataService.getPoolOverview(epochId);
|
|
22108
|
+
return yield this._dataService.getLendingTotals(pools);
|
|
22109
|
+
});
|
|
22110
|
+
}
|
|
22111
|
+
/**
|
|
22112
|
+
* Calculate deposit limits for a specific tranche.
|
|
22113
|
+
*
|
|
22114
|
+
* @param tranche - A `StrategyTranche` from `getAll()` or `getById()`.
|
|
22115
|
+
* @returns min/max/capacity in ether-formatted USDC strings.
|
|
22116
|
+
*/
|
|
22117
|
+
calculateDepositLimits(tranche) {
|
|
22118
|
+
const raw = tranche._raw;
|
|
22119
|
+
const min = parseFloat(raw.minimumDeposit) < 1
|
|
22120
|
+
? '1'
|
|
22121
|
+
: raw.minimumDeposit;
|
|
22122
|
+
const max = parseFloat(raw.maximumDeposit) > parseFloat(raw.poolCapacity)
|
|
22123
|
+
? raw.poolCapacity
|
|
22124
|
+
: raw.maximumDeposit;
|
|
22125
|
+
return {
|
|
22126
|
+
min,
|
|
22127
|
+
max,
|
|
22128
|
+
availableCapacity: raw.poolCapacity,
|
|
22129
|
+
};
|
|
22130
|
+
}
|
|
22131
|
+
// ------------------------------------------------------------------
|
|
22132
|
+
// Private helpers
|
|
22133
|
+
// ------------------------------------------------------------------
|
|
22134
|
+
mapPoolToStrategy(pool) {
|
|
22135
|
+
const tranches = pool.tranches.map((t) => ({
|
|
22136
|
+
id: t.id,
|
|
22137
|
+
name: t.name,
|
|
22138
|
+
apy: parseFloat(t.apy),
|
|
22139
|
+
minApy: parseFloat(t.minApy),
|
|
22140
|
+
maxApy: parseFloat(t.maxApy),
|
|
22141
|
+
minimumDeposit: t.minimumDeposit,
|
|
22142
|
+
maximumDeposit: t.maximumDeposit,
|
|
22143
|
+
availableCapacity: t.poolCapacity,
|
|
22144
|
+
fixedTermOptions: t.fixedTermConfig.map((ftd) => ({
|
|
22145
|
+
configId: ftd.configId,
|
|
22146
|
+
apy: parseFloat(ftd.apy),
|
|
22147
|
+
epochLockDuration: ftd.epochLockDuration,
|
|
22148
|
+
})),
|
|
22149
|
+
_raw: t,
|
|
22150
|
+
}));
|
|
22151
|
+
return {
|
|
22152
|
+
id: pool.id,
|
|
22153
|
+
name: pool.poolName,
|
|
22154
|
+
description: pool.description,
|
|
22155
|
+
isActive: pool.isActive,
|
|
22156
|
+
apy: pool.apy,
|
|
22157
|
+
tvl: pool.totalValueLocked,
|
|
22158
|
+
availableCapacity: pool.poolCapacity,
|
|
22159
|
+
capacityUtilisation: pool.poolCapacityPercentage,
|
|
22160
|
+
tranches,
|
|
22161
|
+
assetClass: pool.assetClass,
|
|
22162
|
+
apyStructure: pool.poolApyStructure,
|
|
22163
|
+
thumbnailUrl: pool.thumbnailImageUrl,
|
|
22164
|
+
bannerUrl: pool.bannerImageUrl,
|
|
22165
|
+
_raw: pool,
|
|
22166
|
+
};
|
|
22167
|
+
}
|
|
22168
|
+
}
|
|
22169
|
+
|
|
22170
|
+
/**
|
|
22171
|
+
* High-level facade for querying a user's portfolio, positions, and history.
|
|
22172
|
+
*
|
|
22173
|
+
* Orchestrates DataService, UserLending, and Portfolio services so the caller
|
|
22174
|
+
* only needs to provide a wallet address.
|
|
22175
|
+
*/
|
|
22176
|
+
class PortfolioFacade {
|
|
22177
|
+
constructor(_dataService, _userLending, _portfolio) {
|
|
22178
|
+
this._dataService = _dataService;
|
|
22179
|
+
this._userLending = _userLending;
|
|
22180
|
+
this._portfolio = _portfolio;
|
|
22181
|
+
}
|
|
22182
|
+
/**
|
|
22183
|
+
* Fetch a user's complete portfolio: per-pool positions and aggregate summary.
|
|
22184
|
+
*
|
|
22185
|
+
* ```ts
|
|
22186
|
+
* const positions = await kasu.portfolio.getPositions('0xUser...');
|
|
22187
|
+
* console.log(positions.summary.current.totalLendingPoolInvestments);
|
|
22188
|
+
* ```
|
|
22189
|
+
*
|
|
22190
|
+
* @param userAddress - Wallet address.
|
|
22191
|
+
* @param provider - Optional separate provider for balance queries (useful when the
|
|
22192
|
+
* SDK was initialised with a Signer but you need a read-only provider).
|
|
22193
|
+
*/
|
|
22194
|
+
getPositions(userAddress, provider) {
|
|
22195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22196
|
+
const currentEpoch = yield this._userLending.getCurrentEpoch();
|
|
22197
|
+
const poolOverviews = yield this._dataService.getPoolOverview(currentEpoch);
|
|
22198
|
+
const pools = yield this._portfolio.getPortfolioLendingData(userAddress, poolOverviews, currentEpoch, provider);
|
|
22199
|
+
const summary = yield this._portfolio.getPortfolioSummary(userAddress, pools, currentEpoch);
|
|
22200
|
+
return { pools, summary };
|
|
22201
|
+
});
|
|
22202
|
+
}
|
|
22203
|
+
/**
|
|
22204
|
+
* Fetch a user's full transaction history (deposits, withdrawals, cancellations).
|
|
22205
|
+
*/
|
|
22206
|
+
getTransactionHistory(userAddress) {
|
|
22207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22208
|
+
const currentEpoch = yield this._userLending.getCurrentEpoch();
|
|
22209
|
+
return yield this._userLending.getUserRequests(userAddress, currentEpoch);
|
|
22210
|
+
});
|
|
22211
|
+
}
|
|
22212
|
+
}
|
|
22213
|
+
|
|
22214
|
+
/**
|
|
22215
|
+
* High-level entry point for external integrators.
|
|
22216
|
+
*
|
|
22217
|
+
* Provides three domain facades — `strategies`, `deposits`, `portfolio` — and
|
|
22218
|
+
* exposes the underlying `KasuSdk` services via `.services` for power-users.
|
|
22219
|
+
*
|
|
22220
|
+
* ```ts
|
|
22221
|
+
* import { Kasu } from '@kasufinance/kasu-sdk';
|
|
22222
|
+
*
|
|
22223
|
+
* const kasu = Kasu.create({ chain: 'base', signerOrProvider: provider });
|
|
22224
|
+
*
|
|
22225
|
+
* // Browse strategies
|
|
22226
|
+
* const strategies = await kasu.strategies.getAll();
|
|
22227
|
+
*
|
|
22228
|
+
* // Deposit
|
|
22229
|
+
* const tx = await kasu.deposits.deposit({ poolId, trancheId, amount, kycSignature });
|
|
22230
|
+
*
|
|
22231
|
+
* // User positions
|
|
22232
|
+
* const positions = await kasu.portfolio.getPositions(userAddress);
|
|
22233
|
+
* ```
|
|
22234
|
+
*/
|
|
22235
|
+
class Kasu {
|
|
22236
|
+
constructor(sdk, chainConfig) {
|
|
22237
|
+
this._sdk = sdk;
|
|
22238
|
+
this._chainConfig = chainConfig;
|
|
22239
|
+
this.strategies = new StrategiesFacade(sdk.DataService, sdk.UserLending);
|
|
22240
|
+
this.deposits = new DepositsFacade(sdk.UserLending, chainConfig.chainId.toString());
|
|
22241
|
+
this.portfolio = new PortfolioFacade(sdk.DataService, sdk.UserLending, sdk.Portfolio);
|
|
22242
|
+
}
|
|
22243
|
+
/**
|
|
22244
|
+
* Create a Kasu instance with built-in chain config.
|
|
22245
|
+
*
|
|
22246
|
+
* ```ts
|
|
22247
|
+
* // Minimal setup — uses built-in Base mainnet config
|
|
22248
|
+
* const kasu = Kasu.create({ chain: 'base', signerOrProvider: provider });
|
|
22249
|
+
*
|
|
22250
|
+
* // Custom config override
|
|
22251
|
+
* const kasu = Kasu.create({
|
|
22252
|
+
* chain: 'base',
|
|
22253
|
+
* signerOrProvider: signer,
|
|
22254
|
+
* configOverrides: { UNUSED_LENDING_POOL_IDS: ['0x...'] },
|
|
22255
|
+
* });
|
|
22256
|
+
*
|
|
22257
|
+
* // Fully custom chain
|
|
22258
|
+
* const kasu = Kasu.create({
|
|
22259
|
+
* chain: { chainId: 123, name: 'MyChain', ... },
|
|
22260
|
+
* signerOrProvider: provider,
|
|
22261
|
+
* });
|
|
22262
|
+
* ```
|
|
22263
|
+
*/
|
|
22264
|
+
static create(options) {
|
|
22265
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
22266
|
+
const chainConfig = resolveChainConfig(options.chain);
|
|
22267
|
+
const overrides = (_a = options.configOverrides) !== null && _a !== void 0 ? _a : {};
|
|
22268
|
+
const sdkConfig = new SdkConfig({
|
|
22269
|
+
subgraphUrl: (_b = overrides.subgraphUrl) !== null && _b !== void 0 ? _b : chainConfig.subgraphUrl,
|
|
22270
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
22271
|
+
contracts: (_c = overrides.contracts) !== null && _c !== void 0 ? _c : chainConfig.contracts,
|
|
22272
|
+
directusUrl: (_d = overrides.directusUrl) !== null && _d !== void 0 ? _d : chainConfig.directusUrl,
|
|
22273
|
+
UNUSED_LENDING_POOL_IDS: (_e = overrides.UNUSED_LENDING_POOL_IDS) !== null && _e !== void 0 ? _e : chainConfig.unusedPoolIds,
|
|
22274
|
+
isLiteDeployment: (_f = overrides.isLiteDeployment) !== null && _f !== void 0 ? _f : chainConfig.isLiteDeployment,
|
|
22275
|
+
poolMetadataMapping: (_g = overrides.poolMetadataMapping) !== null && _g !== void 0 ? _g : chainConfig.poolMetadataMapping,
|
|
22276
|
+
});
|
|
22277
|
+
const sdk = new KasuSdk(sdkConfig, options.signerOrProvider);
|
|
22278
|
+
return new Kasu(sdk, chainConfig);
|
|
22279
|
+
}
|
|
22280
|
+
/**
|
|
22281
|
+
* Access the underlying `KasuSdk` services for advanced use cases.
|
|
22282
|
+
*
|
|
22283
|
+
* ```ts
|
|
22284
|
+
* const locks = await kasu.services.Locking.getUserLocks(address);
|
|
22285
|
+
* ```
|
|
22286
|
+
*/
|
|
22287
|
+
get services() {
|
|
22288
|
+
return this._sdk;
|
|
22289
|
+
}
|
|
22290
|
+
/** The resolved chain configuration. */
|
|
22291
|
+
get chainConfig() {
|
|
22292
|
+
return this._chainConfig;
|
|
22293
|
+
}
|
|
22294
|
+
/** Whether this deployment has KSU token / locking features. */
|
|
22295
|
+
get isLiteDeployment() {
|
|
22296
|
+
return this._chainConfig.isLiteDeployment;
|
|
22297
|
+
}
|
|
22298
|
+
}
|
|
22299
|
+
// ---------------------------------------------------------------------------
|
|
22300
|
+
// Helpers
|
|
22301
|
+
// ---------------------------------------------------------------------------
|
|
22302
|
+
function resolveChainConfig(chain) {
|
|
22303
|
+
if (typeof chain === 'string') {
|
|
22304
|
+
return CHAIN_CONFIGS[chain];
|
|
22305
|
+
}
|
|
22306
|
+
return chain;
|
|
22307
|
+
}
|
|
22308
|
+
|
|
22309
|
+
exports.CHAIN_CONFIGS = CHAIN_CONFIGS;
|
|
22310
|
+
exports.DepositsFacade = DepositsFacade;
|
|
22311
|
+
exports.Kasu = Kasu;
|
|
21747
22312
|
exports.KasuSdk = KasuSdk;
|
|
22313
|
+
exports.PortfolioFacade = PortfolioFacade;
|
|
22314
|
+
exports.SdkConfig = SdkConfig;
|
|
22315
|
+
exports.StrategiesFacade = StrategiesFacade;
|