@t2000/sdk 0.17.17 → 0.17.18
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/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-Dl9CthNB.d.cts → index-DdtOBw42.d.cts} +1 -0
- package/dist/{index-Dl9CthNB.d.ts → index-DdtOBw42.d.ts} +1 -0
- package/dist/index.cjs +85 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +85 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1899,6 +1899,45 @@ async function addSwapToTx(params) {
|
|
|
1899
1899
|
toDecimals: toInfo.decimals
|
|
1900
1900
|
};
|
|
1901
1901
|
}
|
|
1902
|
+
async function buildRawSwapTx(params) {
|
|
1903
|
+
const { client, address, fromCoinType, toCoinType, amount, toDecimals, maxSlippageBps = 500 } = params;
|
|
1904
|
+
const aggClient = createAggregatorClient(client, address);
|
|
1905
|
+
const _origLog = console.log;
|
|
1906
|
+
console.log = () => {
|
|
1907
|
+
};
|
|
1908
|
+
let result;
|
|
1909
|
+
try {
|
|
1910
|
+
result = await aggClient.findRouters({
|
|
1911
|
+
from: fromCoinType,
|
|
1912
|
+
target: toCoinType,
|
|
1913
|
+
amount,
|
|
1914
|
+
byAmountIn: true
|
|
1915
|
+
});
|
|
1916
|
+
} finally {
|
|
1917
|
+
console.log = _origLog;
|
|
1918
|
+
}
|
|
1919
|
+
if (!result || result.insufficientLiquidity) {
|
|
1920
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `No swap route for reward token \u2192 USDC`);
|
|
1921
|
+
}
|
|
1922
|
+
const tx = new transactions.Transaction();
|
|
1923
|
+
const slippage = maxSlippageBps / 1e4;
|
|
1924
|
+
console.log = () => {
|
|
1925
|
+
};
|
|
1926
|
+
try {
|
|
1927
|
+
await aggClient.fastRouterSwap({
|
|
1928
|
+
router: result,
|
|
1929
|
+
txb: tx,
|
|
1930
|
+
slippage
|
|
1931
|
+
});
|
|
1932
|
+
} finally {
|
|
1933
|
+
console.log = _origLog;
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
tx,
|
|
1937
|
+
estimatedOut: Number(result.amountOut.toString()),
|
|
1938
|
+
toDecimals
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1902
1941
|
async function getPoolPrice(client) {
|
|
1903
1942
|
try {
|
|
1904
1943
|
const pool = await client.getObject({
|
|
@@ -3654,6 +3693,11 @@ var AutoInvestManager = class {
|
|
|
3654
3693
|
}
|
|
3655
3694
|
};
|
|
3656
3695
|
var LOW_LIQUIDITY_ASSETS = /* @__PURE__ */ new Set(["GOLD"]);
|
|
3696
|
+
var REWARD_TOKEN_DECIMALS = {
|
|
3697
|
+
"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT": 9,
|
|
3698
|
+
"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP": 6,
|
|
3699
|
+
"0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI": 9
|
|
3700
|
+
};
|
|
3657
3701
|
function defaultSlippage(asset) {
|
|
3658
3702
|
return LOW_LIQUIDITY_ASSETS.has(asset) ? 0.05 : 0.03;
|
|
3659
3703
|
}
|
|
@@ -4855,7 +4899,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4855
4899
|
this.enforcer.assertNotLocked();
|
|
4856
4900
|
const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
|
|
4857
4901
|
if (adapters.length === 0) {
|
|
4858
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
|
|
4902
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, usdcReceived: 0, gasCost: 0, gasMethod: "none" };
|
|
4859
4903
|
}
|
|
4860
4904
|
const tx = new transactions.Transaction();
|
|
4861
4905
|
tx.setSender(this._address);
|
|
@@ -4868,18 +4912,52 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4868
4912
|
}
|
|
4869
4913
|
}
|
|
4870
4914
|
if (allRewards.length === 0) {
|
|
4871
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
|
|
4915
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, usdcReceived: 0, gasCost: 0, gasMethod: "none" };
|
|
4872
4916
|
}
|
|
4873
|
-
const
|
|
4917
|
+
const claimResult = await executeWithGas(this.client, this.keypair, async () => tx);
|
|
4918
|
+
await this.client.waitForTransaction({ digest: claimResult.digest });
|
|
4919
|
+
const usdcReceived = await this.swapRewardTokensToUsdc(allRewards);
|
|
4874
4920
|
return {
|
|
4875
4921
|
success: true,
|
|
4876
|
-
tx:
|
|
4922
|
+
tx: claimResult.digest,
|
|
4877
4923
|
rewards: allRewards,
|
|
4878
|
-
totalValueUsd:
|
|
4879
|
-
|
|
4880
|
-
|
|
4924
|
+
totalValueUsd: usdcReceived,
|
|
4925
|
+
usdcReceived,
|
|
4926
|
+
gasCost: claimResult.gasCostSui,
|
|
4927
|
+
gasMethod: claimResult.gasMethod
|
|
4881
4928
|
};
|
|
4882
4929
|
}
|
|
4930
|
+
async swapRewardTokensToUsdc(rewards) {
|
|
4931
|
+
const uniqueTokens = [...new Set(rewards.map((r) => r.coinType))];
|
|
4932
|
+
const usdcType = SUPPORTED_ASSETS.USDC.type;
|
|
4933
|
+
const usdcDecimals = SUPPORTED_ASSETS.USDC.decimals;
|
|
4934
|
+
let totalUsdc = 0;
|
|
4935
|
+
for (const coinType of uniqueTokens) {
|
|
4936
|
+
try {
|
|
4937
|
+
const balResult = await this.client.getBalance({
|
|
4938
|
+
owner: this._address,
|
|
4939
|
+
coinType
|
|
4940
|
+
});
|
|
4941
|
+
const rawBalance = BigInt(balResult.totalBalance);
|
|
4942
|
+
if (rawBalance <= 0n) continue;
|
|
4943
|
+
const decimals = REWARD_TOKEN_DECIMALS[coinType] ?? 9;
|
|
4944
|
+
const swapResult = await buildRawSwapTx({
|
|
4945
|
+
client: this.client,
|
|
4946
|
+
address: this._address,
|
|
4947
|
+
fromCoinType: coinType,
|
|
4948
|
+
fromDecimals: decimals,
|
|
4949
|
+
toCoinType: usdcType,
|
|
4950
|
+
toDecimals: usdcDecimals,
|
|
4951
|
+
amount: rawBalance
|
|
4952
|
+
});
|
|
4953
|
+
const gasResult = await executeWithGas(this.client, this.keypair, async () => swapResult.tx);
|
|
4954
|
+
await this.client.waitForTransaction({ digest: gasResult.digest });
|
|
4955
|
+
totalUsdc += swapResult.estimatedOut / 10 ** usdcDecimals;
|
|
4956
|
+
} catch {
|
|
4957
|
+
}
|
|
4958
|
+
}
|
|
4959
|
+
return totalUsdc;
|
|
4960
|
+
}
|
|
4883
4961
|
// -- Strategies --
|
|
4884
4962
|
async investStrategy(params) {
|
|
4885
4963
|
this.enforcer.assertNotLocked();
|