@t2000/sdk 0.19.1 → 0.19.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/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/{index-D-6pQwzx.d.cts → index-CcTPxTBs.d.cts} +1 -0
- package/dist/{index-D-6pQwzx.d.ts → index-CcTPxTBs.d.ts} +1 -0
- package/dist/index.cjs +77 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +77 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-
|
|
1
|
+
export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-CcTPxTBs.cjs';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
|
4
4
|
import '@mysten/sui/keypairs/ed25519';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-
|
|
1
|
+
export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-CcTPxTBs.js';
|
|
2
2
|
import '@mysten/sui/transactions';
|
|
3
3
|
import '@mysten/sui/jsonRpc';
|
|
4
4
|
import '@mysten/sui/keypairs/ed25519';
|
package/dist/index.cjs
CHANGED
|
@@ -42716,33 +42716,88 @@ async function queryBalance(client, address) {
|
|
|
42716
42716
|
}
|
|
42717
42717
|
|
|
42718
42718
|
// src/wallet/history.ts
|
|
42719
|
+
var SUI_TYPE = "0x2::sui::SUI";
|
|
42720
|
+
var KNOWN_TARGETS = [
|
|
42721
|
+
[/::mpp_charge::/, "mpp payment"],
|
|
42722
|
+
[/::suilend|::obligation/, "lending"],
|
|
42723
|
+
[/::navi|::incentive_v2/, "lending"],
|
|
42724
|
+
[/::cetus|::pool/, "swap"],
|
|
42725
|
+
[/::deepbook/, "swap"],
|
|
42726
|
+
[/::transfer::public_transfer/, "send"],
|
|
42727
|
+
[/::coin::split/, "split"]
|
|
42728
|
+
];
|
|
42719
42729
|
async function queryHistory(client, address, limit = 20) {
|
|
42720
42730
|
const txns = await client.queryTransactionBlocks({
|
|
42721
42731
|
filter: { FromAddress: address },
|
|
42722
|
-
options: { showEffects: true, showInput: true },
|
|
42732
|
+
options: { showEffects: true, showInput: true, showBalanceChanges: true },
|
|
42723
42733
|
limit,
|
|
42724
42734
|
order: "descending"
|
|
42725
42735
|
});
|
|
42726
42736
|
return txns.data.map((tx) => {
|
|
42727
42737
|
const gasUsed = tx.effects?.gasUsed;
|
|
42728
42738
|
const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
|
|
42739
|
+
const targets = extractMoveCallTargets(tx.transaction);
|
|
42740
|
+
const action = classifyAction(targets);
|
|
42741
|
+
const { amount, asset, recipient } = extractTransferDetails(
|
|
42742
|
+
tx.balanceChanges,
|
|
42743
|
+
address
|
|
42744
|
+
);
|
|
42729
42745
|
return {
|
|
42730
42746
|
digest: tx.digest,
|
|
42731
|
-
action
|
|
42747
|
+
action,
|
|
42748
|
+
amount,
|
|
42749
|
+
asset,
|
|
42750
|
+
recipient,
|
|
42732
42751
|
timestamp: Number(tx.timestampMs ?? 0),
|
|
42733
42752
|
gasCost
|
|
42734
42753
|
};
|
|
42735
42754
|
});
|
|
42736
42755
|
}
|
|
42737
|
-
function
|
|
42738
|
-
if (!
|
|
42739
|
-
const
|
|
42740
|
-
|
|
42741
|
-
|
|
42742
|
-
|
|
42743
|
-
const
|
|
42744
|
-
|
|
42745
|
-
|
|
42756
|
+
function extractTransferDetails(changes, sender) {
|
|
42757
|
+
if (!changes || changes.length === 0) return {};
|
|
42758
|
+
const outflows = changes.filter((c) => {
|
|
42759
|
+
const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
|
|
42760
|
+
return owner === sender && BigInt(c.amount) < 0n;
|
|
42761
|
+
});
|
|
42762
|
+
const inflows = changes.filter((c) => {
|
|
42763
|
+
const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
|
|
42764
|
+
return owner !== sender && BigInt(c.amount) > 0n;
|
|
42765
|
+
});
|
|
42766
|
+
const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b2) => Number(BigInt(a.amount) - BigInt(b2.amount)))[0] ?? outflows[0];
|
|
42767
|
+
if (!primaryOutflow) return {};
|
|
42768
|
+
const coinType = primaryOutflow.coinType;
|
|
42769
|
+
const decimals = coinType.includes("::usdc::") ? 6 : 9;
|
|
42770
|
+
const amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
|
|
42771
|
+
const asset = coinType === SUI_TYPE ? "SUI" : coinType.includes("::usdc::") ? "USDC" : coinType.split("::").pop() ?? "unknown";
|
|
42772
|
+
const recipientChange = inflows.find((c) => c.coinType === coinType);
|
|
42773
|
+
const recipient = recipientChange ? typeof recipientChange.owner === "object" && recipientChange.owner.AddressOwner ? recipientChange.owner.AddressOwner : void 0 : void 0;
|
|
42774
|
+
return { amount, asset, recipient };
|
|
42775
|
+
}
|
|
42776
|
+
function extractMoveCallTargets(txBlock) {
|
|
42777
|
+
try {
|
|
42778
|
+
if (!txBlock || typeof txBlock !== "object") return [];
|
|
42779
|
+
const data = "data" in txBlock ? txBlock.data : void 0;
|
|
42780
|
+
if (!data || typeof data !== "object") return [];
|
|
42781
|
+
const inner = "transaction" in data ? data.transaction : void 0;
|
|
42782
|
+
if (!inner || typeof inner !== "object") return [];
|
|
42783
|
+
const commands = "commands" in inner ? inner.commands : void 0;
|
|
42784
|
+
if (!Array.isArray(commands)) return [];
|
|
42785
|
+
return commands.filter((c) => c.MoveCall).map((c) => {
|
|
42786
|
+
const mc = c.MoveCall;
|
|
42787
|
+
return `${mc.package}::${mc.module}::${mc.function}`;
|
|
42788
|
+
});
|
|
42789
|
+
} catch {
|
|
42790
|
+
return [];
|
|
42791
|
+
}
|
|
42792
|
+
}
|
|
42793
|
+
function classifyAction(targets) {
|
|
42794
|
+
if (targets.length === 0) return "transaction";
|
|
42795
|
+
for (const target of targets) {
|
|
42796
|
+
for (const [pattern, label] of KNOWN_TARGETS) {
|
|
42797
|
+
if (pattern.test(target)) return label;
|
|
42798
|
+
}
|
|
42799
|
+
}
|
|
42800
|
+
return "transaction";
|
|
42746
42801
|
}
|
|
42747
42802
|
|
|
42748
42803
|
// src/protocols/protocolFee.ts
|
|
@@ -57118,9 +57173,18 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
57118
57173
|
this.enforcer.check({ operation: "pay", amount: options.maxPrice ?? 1 });
|
|
57119
57174
|
const { Mppx } = await import('mppx/client');
|
|
57120
57175
|
const { sui } = await import('@t2000/mpp-sui/client');
|
|
57176
|
+
const client = this.client;
|
|
57177
|
+
const keypair = this.keypair;
|
|
57121
57178
|
const mppx = Mppx.create({
|
|
57122
57179
|
polyfill: false,
|
|
57123
|
-
methods: [sui({
|
|
57180
|
+
methods: [sui({
|
|
57181
|
+
client,
|
|
57182
|
+
signer: keypair,
|
|
57183
|
+
execute: async (tx) => {
|
|
57184
|
+
const result = await executeWithGas(client, keypair, () => tx);
|
|
57185
|
+
return { digest: result.digest, effects: result.effects };
|
|
57186
|
+
}
|
|
57187
|
+
})]
|
|
57124
57188
|
});
|
|
57125
57189
|
const method = (options.method ?? "GET").toUpperCase();
|
|
57126
57190
|
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
@@ -58188,7 +58252,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
58188
58252
|
await new Promise((r) => setTimeout(r, 1500));
|
|
58189
58253
|
}
|
|
58190
58254
|
const maxSellable = Math.max(0, walletAmount - gasReserve);
|
|
58191
|
-
const trackedAmount = pos
|
|
58255
|
+
const trackedAmount = pos ? pos.totalAmount : maxSellable;
|
|
58192
58256
|
if (trackedAmount <= 0) {
|
|
58193
58257
|
throw new T2000Error("INSUFFICIENT_INVESTMENT", `No ${params.asset} position to sell`);
|
|
58194
58258
|
}
|