@t2000/sdk 0.15.1 → 0.15.3
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/dist/index.cjs +28 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3056,9 +3056,12 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3056
3056
|
}
|
|
3057
3057
|
async balance() {
|
|
3058
3058
|
const bal = await queryBalance(this.client, this._address);
|
|
3059
|
+
const earningAssets = new Set(
|
|
3060
|
+
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
3061
|
+
);
|
|
3059
3062
|
try {
|
|
3060
3063
|
const positions = await this.positions();
|
|
3061
|
-
const savings = positions.positions.filter((p) => p.type === "save").reduce((sum, p) => sum + p.amount, 0);
|
|
3064
|
+
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).reduce((sum, p) => sum + p.amount, 0);
|
|
3062
3065
|
const debt = positions.positions.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.amount, 0);
|
|
3063
3066
|
bal.savings = savings;
|
|
3064
3067
|
bal.debt = debt;
|
|
@@ -3086,7 +3089,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3086
3089
|
for (const pos of portfolioPositions) {
|
|
3087
3090
|
if (!(pos.asset in INVESTMENT_ASSETS)) continue;
|
|
3088
3091
|
const price = assetPrices[pos.asset] ?? 0;
|
|
3089
|
-
if (pos.
|
|
3092
|
+
if (pos.earning) {
|
|
3093
|
+
investmentValue += pos.totalAmount * price;
|
|
3094
|
+
investmentCostBasis += pos.costBasis;
|
|
3095
|
+
if (pos.asset === "SUI") {
|
|
3096
|
+
const gasSui = Math.max(0, bal.gasReserve.sui);
|
|
3097
|
+
bal.gasReserve = { sui: gasSui, usdEquiv: gasSui * price };
|
|
3098
|
+
}
|
|
3099
|
+
} else if (pos.asset === "SUI") {
|
|
3090
3100
|
const actualHeld = Math.min(pos.totalAmount, bal.gasReserve.sui);
|
|
3091
3101
|
investmentValue += actualHeld * price;
|
|
3092
3102
|
if (actualHeld < pos.totalAmount && pos.totalAmount > 0) {
|
|
@@ -3946,26 +3956,20 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
3946
3956
|
if (depositAmount <= 0) {
|
|
3947
3957
|
throw new T2000Error("INSUFFICIENT_BALANCE", `No ${params.asset} available to deposit (wallet: ${walletAmount}, gas reserve: ${gasReserve})`);
|
|
3948
3958
|
}
|
|
3949
|
-
const
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
transaction: tx,
|
|
3953
|
-
options: { showEffects: true }
|
|
3959
|
+
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
3960
|
+
const { tx } = await adapter.buildSaveTx(this._address, depositAmount, params.asset);
|
|
3961
|
+
return tx;
|
|
3954
3962
|
});
|
|
3955
|
-
await this.client.waitForTransaction({ digest: result.digest });
|
|
3956
|
-
const gasCost = result.effects?.gasUsed ? Math.abs(
|
|
3957
|
-
(Number(result.effects.gasUsed.computationCost) + Number(result.effects.gasUsed.storageCost) - Number(result.effects.gasUsed.storageRebate)) / 1e9
|
|
3958
|
-
) : 0;
|
|
3959
3963
|
this.portfolio.recordEarn(params.asset, adapter.id, rate.saveApy);
|
|
3960
3964
|
return {
|
|
3961
3965
|
success: true,
|
|
3962
|
-
tx:
|
|
3966
|
+
tx: gasResult.digest,
|
|
3963
3967
|
asset: params.asset,
|
|
3964
3968
|
amount: depositAmount,
|
|
3965
3969
|
protocol: adapter.name,
|
|
3966
3970
|
apy: rate.saveApy,
|
|
3967
|
-
gasCost,
|
|
3968
|
-
gasMethod:
|
|
3971
|
+
gasCost: gasResult.gasCostSui,
|
|
3972
|
+
gasMethod: gasResult.gasMethod
|
|
3969
3973
|
};
|
|
3970
3974
|
}
|
|
3971
3975
|
async investUnearn(params) {
|
|
@@ -3984,27 +3988,23 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
3984
3988
|
const positions = await adapter.getPositions(this._address);
|
|
3985
3989
|
const supply = positions.supplies.find((s) => s.asset === params.asset);
|
|
3986
3990
|
const withdrawAmount = supply?.amount ?? pos.totalAmount;
|
|
3987
|
-
const { tx, effectiveAmount } = await adapter.buildWithdrawTx(this._address, withdrawAmount, params.asset);
|
|
3988
|
-
const result = await this.client.signAndExecuteTransaction({
|
|
3989
|
-
signer: this.keypair,
|
|
3990
|
-
transaction: tx,
|
|
3991
|
-
options: { showEffects: true }
|
|
3992
|
-
});
|
|
3993
|
-
await this.client.waitForTransaction({ digest: result.digest });
|
|
3994
|
-
const gasCost = result.effects?.gasUsed ? Math.abs(
|
|
3995
|
-
(Number(result.effects.gasUsed.computationCost) + Number(result.effects.gasUsed.storageCost) - Number(result.effects.gasUsed.storageRebate)) / 1e9
|
|
3996
|
-
) : 0;
|
|
3997
3991
|
const protocolName = adapter.name;
|
|
3992
|
+
let effectiveAmount = withdrawAmount;
|
|
3993
|
+
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
3994
|
+
const result = await adapter.buildWithdrawTx(this._address, withdrawAmount, params.asset);
|
|
3995
|
+
effectiveAmount = result.effectiveAmount;
|
|
3996
|
+
return result.tx;
|
|
3997
|
+
});
|
|
3998
3998
|
this.portfolio.recordUnearn(params.asset);
|
|
3999
3999
|
return {
|
|
4000
4000
|
success: true,
|
|
4001
|
-
tx:
|
|
4001
|
+
tx: gasResult.digest,
|
|
4002
4002
|
asset: params.asset,
|
|
4003
4003
|
amount: effectiveAmount,
|
|
4004
4004
|
protocol: protocolName,
|
|
4005
4005
|
apy: 0,
|
|
4006
|
-
gasCost,
|
|
4007
|
-
gasMethod:
|
|
4006
|
+
gasCost: gasResult.gasCostSui,
|
|
4007
|
+
gasMethod: gasResult.gasMethod
|
|
4008
4008
|
};
|
|
4009
4009
|
}
|
|
4010
4010
|
async getPortfolio() {
|
|
@@ -4029,7 +4029,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4029
4029
|
const currentPrice = prices[pos.asset] ?? 0;
|
|
4030
4030
|
let totalAmount = pos.totalAmount;
|
|
4031
4031
|
let costBasis = pos.costBasis;
|
|
4032
|
-
if (pos.asset in INVESTMENT_ASSETS) {
|
|
4032
|
+
if (pos.asset in INVESTMENT_ASSETS && !pos.earning) {
|
|
4033
4033
|
try {
|
|
4034
4034
|
const assetInfo = SUPPORTED_ASSETS[pos.asset];
|
|
4035
4035
|
const bal = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
|