@t2000/sdk 5.1.0 → 5.3.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/dist/browser.cjs +0 -43
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -42
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +198 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -19
- package/dist/index.d.ts +100 -19
- package/dist/index.js +187 -152
- package/dist/index.js.map +1 -1
- package/dist/{types-C01EGu76.d.cts → simulate-BTIIpnXc.d.cts} +3 -39
- package/dist/{types-C01EGu76.d.ts → simulate-BTIIpnXc.d.ts} +3 -39
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1765,170 +1765,198 @@ async function normalizeAddressInput(value, ctx = {}) {
|
|
|
1765
1765
|
|
|
1766
1766
|
// src/t2000.ts
|
|
1767
1767
|
init_errors();
|
|
1768
|
+
var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".t2000");
|
|
1769
|
+
function resolveConfigPath(configDir) {
|
|
1770
|
+
return path.join(configDir ?? DEFAULT_CONFIG_DIR, "config.json");
|
|
1771
|
+
}
|
|
1772
|
+
function todayUtc() {
|
|
1773
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1774
|
+
}
|
|
1775
|
+
function readLimitsFile(configDir) {
|
|
1776
|
+
const path = resolveConfigPath(configDir);
|
|
1777
|
+
try {
|
|
1778
|
+
return sanitize(JSON.parse(fs.readFileSync(path, "utf-8")));
|
|
1779
|
+
} catch {
|
|
1780
|
+
return {};
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
function writeLimitsFile(file, configDir) {
|
|
1784
|
+
const path$1 = resolveConfigPath(configDir);
|
|
1785
|
+
let existing = {};
|
|
1786
|
+
try {
|
|
1787
|
+
existing = JSON.parse(fs.readFileSync(path$1, "utf-8"));
|
|
1788
|
+
} catch {
|
|
1789
|
+
existing = {};
|
|
1790
|
+
}
|
|
1791
|
+
for (const dead of ["maxPerTx", "maxDailySend", "dailyUsed", "dailyResetDate", "locked"]) {
|
|
1792
|
+
delete existing[dead];
|
|
1793
|
+
}
|
|
1794
|
+
const merged = { ...existing };
|
|
1795
|
+
if (file.limits && (file.limits.perTxUsd !== void 0 || file.limits.dailyUsd !== void 0)) {
|
|
1796
|
+
merged.limits = file.limits;
|
|
1797
|
+
} else {
|
|
1798
|
+
delete merged.limits;
|
|
1799
|
+
}
|
|
1800
|
+
if (file.dailySpend) merged.dailySpend = file.dailySpend;
|
|
1801
|
+
else delete merged.dailySpend;
|
|
1802
|
+
const dir = path.dirname(path$1);
|
|
1803
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
1804
|
+
fs.writeFileSync(path$1, JSON.stringify(merged, null, 2) + "\n", { mode: 384 });
|
|
1805
|
+
return path$1;
|
|
1806
|
+
}
|
|
1807
|
+
function getLimits(configDir) {
|
|
1808
|
+
return readLimitsFile(configDir).limits;
|
|
1809
|
+
}
|
|
1810
|
+
function hasLimits(configDir) {
|
|
1811
|
+
const l = readLimitsFile(configDir).limits;
|
|
1812
|
+
return !!l && (l.perTxUsd !== void 0 || l.dailyUsd !== void 0);
|
|
1813
|
+
}
|
|
1814
|
+
function setLimits(limits, configDir) {
|
|
1815
|
+
const file = readLimitsFile(configDir);
|
|
1816
|
+
const merged = { ...file.limits };
|
|
1817
|
+
if (limits.perTxUsd !== void 0) merged.perTxUsd = limits.perTxUsd;
|
|
1818
|
+
if (limits.dailyUsd !== void 0) merged.dailyUsd = limits.dailyUsd;
|
|
1819
|
+
return writeLimitsFile({ ...file, limits: merged }, configDir);
|
|
1820
|
+
}
|
|
1821
|
+
function clearLimits(configDir) {
|
|
1822
|
+
const file = readLimitsFile(configDir);
|
|
1823
|
+
return writeLimitsFile({ ...file, limits: void 0 }, configDir);
|
|
1824
|
+
}
|
|
1825
|
+
function dailySpentToday(configDir) {
|
|
1826
|
+
const { dailySpend } = readLimitsFile(configDir);
|
|
1827
|
+
if (!dailySpend || dailySpend.date !== todayUtc()) return 0;
|
|
1828
|
+
return dailySpend.usd;
|
|
1829
|
+
}
|
|
1830
|
+
function recordDailySpend(usd, configDir) {
|
|
1831
|
+
if (!Number.isFinite(usd) || usd <= 0) return;
|
|
1832
|
+
const file = readLimitsFile(configDir);
|
|
1833
|
+
const today = todayUtc();
|
|
1834
|
+
const prior = file.dailySpend && file.dailySpend.date === today ? file.dailySpend.usd : 0;
|
|
1835
|
+
writeLimitsFile({ ...file, dailySpend: { date: today, usd: prior + usd } }, configDir);
|
|
1836
|
+
}
|
|
1837
|
+
function sanitize(raw) {
|
|
1838
|
+
if (typeof raw !== "object" || raw === null) return {};
|
|
1839
|
+
const r = raw;
|
|
1840
|
+
const out = {};
|
|
1841
|
+
if (typeof r.limits === "object" && r.limits !== null) {
|
|
1842
|
+
const l = r.limits;
|
|
1843
|
+
const limits = {};
|
|
1844
|
+
if (typeof l.perTxUsd === "number" && l.perTxUsd > 0) limits.perTxUsd = l.perTxUsd;
|
|
1845
|
+
if (typeof l.dailyUsd === "number" && l.dailyUsd > 0) limits.dailyUsd = l.dailyUsd;
|
|
1846
|
+
else if (typeof l.dailySendUsd === "number" && l.dailySendUsd > 0) limits.dailyUsd = l.dailySendUsd;
|
|
1847
|
+
if (limits.perTxUsd !== void 0 || limits.dailyUsd !== void 0) out.limits = limits;
|
|
1848
|
+
}
|
|
1849
|
+
if (typeof r.dailySpend === "object" && r.dailySpend !== null) {
|
|
1850
|
+
const d = r.dailySpend;
|
|
1851
|
+
if (typeof d.date === "string" && typeof d.usd === "number" && d.usd >= 0) {
|
|
1852
|
+
out.dailySpend = { date: d.date, usd: d.usd };
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return out;
|
|
1856
|
+
}
|
|
1768
1857
|
|
|
1769
|
-
// src/
|
|
1770
|
-
var
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
this.name = "SafeguardError";
|
|
1787
|
-
this.rule = rule;
|
|
1788
|
-
this.details = details;
|
|
1858
|
+
// src/limits/errors.ts
|
|
1859
|
+
var LimitExceededError = class extends Error {
|
|
1860
|
+
code = "LIMIT_EXCEEDED";
|
|
1861
|
+
operation;
|
|
1862
|
+
limitKind;
|
|
1863
|
+
limit;
|
|
1864
|
+
attempted;
|
|
1865
|
+
constructor(params) {
|
|
1866
|
+
const label = params.limitKind === "perTxUsd" ? "per-transaction limit" : "daily spend limit";
|
|
1867
|
+
super(
|
|
1868
|
+
`Exceeds ${label} ($${params.limit}). Attempted $${params.attempted.toFixed(2)}. Use --force / force:true to override.`
|
|
1869
|
+
);
|
|
1870
|
+
this.name = "LimitExceededError";
|
|
1871
|
+
this.operation = params.operation;
|
|
1872
|
+
this.limitKind = params.limitKind;
|
|
1873
|
+
this.limit = params.limit;
|
|
1874
|
+
this.attempted = params.attempted;
|
|
1789
1875
|
}
|
|
1790
1876
|
toJSON() {
|
|
1791
1877
|
return {
|
|
1792
|
-
error:
|
|
1878
|
+
error: this.code,
|
|
1793
1879
|
message: this.message,
|
|
1794
|
-
|
|
1795
|
-
|
|
1880
|
+
operation: this.operation,
|
|
1881
|
+
limitKind: this.limitKind,
|
|
1882
|
+
limit: this.limit,
|
|
1883
|
+
attempted: this.attempted
|
|
1796
1884
|
};
|
|
1797
1885
|
}
|
|
1798
1886
|
};
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1887
|
+
|
|
1888
|
+
// src/limits/enforce.ts
|
|
1889
|
+
function approxUsdValue(asset, amount) {
|
|
1890
|
+
const symbol = asset.toUpperCase();
|
|
1891
|
+
if (symbol === "USDC" || symbol === "USDSUI") return amount;
|
|
1892
|
+
return null;
|
|
1893
|
+
}
|
|
1894
|
+
function assertLimitConfig(input) {
|
|
1895
|
+
if (input.force) return;
|
|
1896
|
+
if (!Number.isFinite(input.amountUsd) || input.amountUsd <= 0) return;
|
|
1897
|
+
const { limits } = input;
|
|
1898
|
+
if (!limits) return;
|
|
1899
|
+
if (limits.perTxUsd !== void 0 && input.amountUsd > limits.perTxUsd) {
|
|
1900
|
+
throw new LimitExceededError({
|
|
1901
|
+
operation: input.operation,
|
|
1902
|
+
limitKind: "perTxUsd",
|
|
1903
|
+
limit: limits.perTxUsd,
|
|
1904
|
+
attempted: input.amountUsd
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
if (limits.dailyUsd !== void 0 && input.spentTodayUsd + input.amountUsd > limits.dailyUsd) {
|
|
1908
|
+
throw new LimitExceededError({
|
|
1909
|
+
operation: input.operation,
|
|
1910
|
+
limitKind: "dailyUsd",
|
|
1911
|
+
// The cap is total/day; report the cap (attempted is THIS write's USD).
|
|
1912
|
+
limit: limits.dailyUsd,
|
|
1913
|
+
attempted: input.spentTodayUsd + input.amountUsd
|
|
1914
|
+
});
|
|
1807
1915
|
}
|
|
1808
1916
|
}
|
|
1809
|
-
|
|
1810
|
-
// src/safeguards/enforcer.ts
|
|
1811
|
-
var SafeguardEnforcer = class {
|
|
1812
|
-
config;
|
|
1813
|
-
configPath;
|
|
1917
|
+
var LimitEnforcer = class {
|
|
1814
1918
|
constructor(configDir) {
|
|
1815
|
-
this.
|
|
1816
|
-
|
|
1919
|
+
this.configDir = configDir;
|
|
1920
|
+
}
|
|
1921
|
+
/** Throws `LimitExceededError` when the write exceeds an opted-in cap. */
|
|
1922
|
+
assert(input) {
|
|
1923
|
+
assertLimitConfig({
|
|
1924
|
+
limits: getLimits(this.configDir),
|
|
1925
|
+
spentTodayUsd: dailySpentToday(this.configDir),
|
|
1926
|
+
operation: input.operation,
|
|
1927
|
+
amountUsd: input.amountUsd,
|
|
1928
|
+
force: input.force
|
|
1929
|
+
});
|
|
1817
1930
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
const raw = JSON.parse(fs.readFileSync(this.configPath, "utf-8"));
|
|
1822
|
-
this.config = {
|
|
1823
|
-
...DEFAULT_SAFEGUARD_CONFIG,
|
|
1824
|
-
locked: raw.locked ?? false,
|
|
1825
|
-
maxPerTx: raw.maxPerTx ?? 0,
|
|
1826
|
-
maxDailySend: raw.maxDailySend ?? 0,
|
|
1827
|
-
dailyUsed: raw.dailyUsed ?? 0,
|
|
1828
|
-
dailyResetDate: raw.dailyResetDate ?? ""
|
|
1829
|
-
};
|
|
1830
|
-
} catch {
|
|
1831
|
-
this.config = { ...DEFAULT_SAFEGUARD_CONFIG };
|
|
1832
|
-
}
|
|
1931
|
+
/** Add a settled write's USD value to today's cumulative total. */
|
|
1932
|
+
record(amountUsd) {
|
|
1933
|
+
recordDailySpend(amountUsd, this.configDir);
|
|
1833
1934
|
}
|
|
1834
|
-
|
|
1835
|
-
this.
|
|
1836
|
-
if (this.config.locked) {
|
|
1837
|
-
throw new SafeguardError("locked", {});
|
|
1838
|
-
}
|
|
1935
|
+
getLimits() {
|
|
1936
|
+
return getLimits(this.configDir);
|
|
1839
1937
|
}
|
|
1840
|
-
|
|
1841
|
-
this.
|
|
1842
|
-
if (this.config.locked) {
|
|
1843
|
-
throw new SafeguardError("locked", {});
|
|
1844
|
-
}
|
|
1845
|
-
const amount = metadata.amount ?? 0;
|
|
1846
|
-
if (this.config.maxPerTx > 0 && amount > this.config.maxPerTx) {
|
|
1847
|
-
throw new SafeguardError("maxPerTx", {
|
|
1848
|
-
attempted: amount,
|
|
1849
|
-
limit: this.config.maxPerTx
|
|
1850
|
-
});
|
|
1851
|
-
}
|
|
1852
|
-
this.resetDailyIfNewDay();
|
|
1853
|
-
if (this.config.maxDailySend > 0 && this.config.dailyUsed + amount > this.config.maxDailySend) {
|
|
1854
|
-
throw new SafeguardError("maxDailySend", {
|
|
1855
|
-
attempted: amount,
|
|
1856
|
-
limit: this.config.maxDailySend,
|
|
1857
|
-
current: this.config.dailyUsed
|
|
1858
|
-
});
|
|
1859
|
-
}
|
|
1938
|
+
hasLimits() {
|
|
1939
|
+
return hasLimits(this.configDir);
|
|
1860
1940
|
}
|
|
1861
|
-
|
|
1862
|
-
this.
|
|
1863
|
-
this.config.dailyUsed += amount;
|
|
1864
|
-
this.save();
|
|
1865
|
-
}
|
|
1866
|
-
lock() {
|
|
1867
|
-
this.config.locked = true;
|
|
1868
|
-
this.save();
|
|
1869
|
-
}
|
|
1870
|
-
unlock() {
|
|
1871
|
-
this.config.locked = false;
|
|
1872
|
-
this.save();
|
|
1873
|
-
}
|
|
1874
|
-
set(key, value) {
|
|
1875
|
-
if (key === "locked" && typeof value === "boolean") {
|
|
1876
|
-
this.config.locked = value;
|
|
1877
|
-
} else if (key === "maxPerTx" && typeof value === "number") {
|
|
1878
|
-
this.config.maxPerTx = value;
|
|
1879
|
-
} else if (key === "maxDailySend" && typeof value === "number") {
|
|
1880
|
-
this.config.maxDailySend = value;
|
|
1881
|
-
}
|
|
1882
|
-
this.save();
|
|
1883
|
-
}
|
|
1884
|
-
getConfig() {
|
|
1885
|
-
this.load();
|
|
1886
|
-
this.resetDailyIfNewDay();
|
|
1887
|
-
return { ...this.config };
|
|
1888
|
-
}
|
|
1889
|
-
isConfigured() {
|
|
1890
|
-
return this.config.maxPerTx > 0 || this.config.maxDailySend > 0;
|
|
1891
|
-
}
|
|
1892
|
-
resetDailyIfNewDay() {
|
|
1893
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1894
|
-
if (this.config.dailyResetDate !== today) {
|
|
1895
|
-
this.config.dailyUsed = 0;
|
|
1896
|
-
this.config.dailyResetDate = today;
|
|
1897
|
-
this.save();
|
|
1898
|
-
}
|
|
1941
|
+
setLimits(limits) {
|
|
1942
|
+
setLimits(limits, this.configDir);
|
|
1899
1943
|
}
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
existing = JSON.parse(fs.readFileSync(this.configPath, "utf-8"));
|
|
1906
|
-
} catch {
|
|
1907
|
-
}
|
|
1908
|
-
const merged = {
|
|
1909
|
-
...existing,
|
|
1910
|
-
locked: this.config.locked,
|
|
1911
|
-
maxPerTx: this.config.maxPerTx,
|
|
1912
|
-
maxDailySend: this.config.maxDailySend,
|
|
1913
|
-
dailyUsed: this.config.dailyUsed,
|
|
1914
|
-
dailyResetDate: this.config.dailyResetDate
|
|
1915
|
-
};
|
|
1916
|
-
const dir = this.configPath.replace(/[/\\][^/\\]+$/, "");
|
|
1917
|
-
if (!fs.existsSync(dir)) {
|
|
1918
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
1919
|
-
}
|
|
1920
|
-
fs.writeFileSync(this.configPath, JSON.stringify(merged, null, 2) + "\n");
|
|
1921
|
-
} catch {
|
|
1922
|
-
}
|
|
1944
|
+
clearLimits() {
|
|
1945
|
+
clearLimits(this.configDir);
|
|
1946
|
+
}
|
|
1947
|
+
dailySpentToday() {
|
|
1948
|
+
return dailySpentToday(this.configDir);
|
|
1923
1949
|
}
|
|
1924
1950
|
};
|
|
1925
|
-
var
|
|
1951
|
+
var DEFAULT_CONFIG_DIR2 = path.join(os.homedir(), ".t2000");
|
|
1926
1952
|
var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
1927
1953
|
_signer;
|
|
1928
1954
|
_keypair;
|
|
1929
1955
|
client;
|
|
1930
1956
|
_address;
|
|
1931
|
-
|
|
1957
|
+
/** Unified spending-limit gate (per-tx + cumulative daily, USD). Shared by
|
|
1958
|
+
* CLI + MCP + programmatic writes — one gate, no bypass (R-0 Finding 1). */
|
|
1959
|
+
limits;
|
|
1932
1960
|
constructor(keypairOrSigner, client, configDir, isSignerMode) {
|
|
1933
1961
|
super();
|
|
1934
1962
|
if (isSignerMode) {
|
|
@@ -1942,8 +1970,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1942
1970
|
this._address = getAddress(kp);
|
|
1943
1971
|
}
|
|
1944
1972
|
this.client = client;
|
|
1945
|
-
this.
|
|
1946
|
-
this.enforcer.load();
|
|
1973
|
+
this.limits = new LimitEnforcer(configDir);
|
|
1947
1974
|
}
|
|
1948
1975
|
static async create(options = {}) {
|
|
1949
1976
|
const { keyPath, rpcUrl } = options;
|
|
@@ -1956,7 +1983,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1956
1983
|
);
|
|
1957
1984
|
}
|
|
1958
1985
|
const keypair = await loadKey(void 0, keyPath);
|
|
1959
|
-
return new _T2000(keypair, client,
|
|
1986
|
+
return new _T2000(keypair, client, DEFAULT_CONFIG_DIR2);
|
|
1960
1987
|
}
|
|
1961
1988
|
static fromPrivateKey(privateKey, options = {}) {
|
|
1962
1989
|
const keypair = keypairFromPrivateKey(privateKey);
|
|
@@ -1967,7 +1994,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1967
1994
|
const keypair = generateKeypair();
|
|
1968
1995
|
await saveKey(keypair, void 0, options.keyPath);
|
|
1969
1996
|
const client = getSuiClient();
|
|
1970
|
-
const agent = new _T2000(keypair, client,
|
|
1997
|
+
const agent = new _T2000(keypair, client, DEFAULT_CONFIG_DIR2);
|
|
1971
1998
|
const address = agent.address();
|
|
1972
1999
|
return { agent, address };
|
|
1973
2000
|
}
|
|
@@ -1989,11 +2016,10 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1989
2016
|
}
|
|
1990
2017
|
// -- MPP Payments --
|
|
1991
2018
|
async pay(options) {
|
|
1992
|
-
this.
|
|
1993
|
-
this.enforcer.check({ operation: "pay", amount: options.maxPrice ?? 1 });
|
|
2019
|
+
this.limits.assert({ operation: "pay", amountUsd: options.maxPrice ?? 0, force: options.force });
|
|
1994
2020
|
const result = await payWithMpp({ signer: this._signer, client: this.client, options });
|
|
1995
2021
|
if (result.paid) {
|
|
1996
|
-
this.
|
|
2022
|
+
this.limits.record(result.cost ?? options.maxPrice ?? 0);
|
|
1997
2023
|
}
|
|
1998
2024
|
return result;
|
|
1999
2025
|
}
|
|
@@ -2007,7 +2033,11 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2007
2033
|
// and the S.323 build-tracker entry.
|
|
2008
2034
|
// -- Swap --
|
|
2009
2035
|
async swap(params) {
|
|
2010
|
-
this.
|
|
2036
|
+
this.limits.assert({
|
|
2037
|
+
operation: "swap",
|
|
2038
|
+
amountUsd: approxUsdValue(params.from, params.amount) ?? 0,
|
|
2039
|
+
force: params.force
|
|
2040
|
+
});
|
|
2011
2041
|
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2012
2042
|
const fromType = resolveTokenType2(params.from);
|
|
2013
2043
|
const toType = resolveTokenType2(params.to);
|
|
@@ -2099,6 +2129,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2099
2129
|
const fromName = resolveSymbol(fromType);
|
|
2100
2130
|
const toName = resolveSymbol(toType);
|
|
2101
2131
|
const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
|
|
2132
|
+
this.limits.record(approxUsdValue(params.from, params.amount) ?? 0);
|
|
2102
2133
|
return {
|
|
2103
2134
|
success: true,
|
|
2104
2135
|
tx: gasResult.digest,
|
|
@@ -2155,7 +2186,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2155
2186
|
* the "build via gRPC, execute via JSON-RPC" hybrid).
|
|
2156
2187
|
*/
|
|
2157
2188
|
async send(params) {
|
|
2158
|
-
this.enforcer.assertNotLocked();
|
|
2159
2189
|
const asset = params.asset;
|
|
2160
2190
|
if (!asset) {
|
|
2161
2191
|
throw new exports.T2000Error(
|
|
@@ -2165,6 +2195,11 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2165
2195
|
}
|
|
2166
2196
|
assertAllowedAsset("send", asset);
|
|
2167
2197
|
const sendableAsset = asset;
|
|
2198
|
+
this.limits.assert({
|
|
2199
|
+
operation: "send",
|
|
2200
|
+
amountUsd: approxUsdValue(sendableAsset, params.amount) ?? 0,
|
|
2201
|
+
force: params.force
|
|
2202
|
+
});
|
|
2168
2203
|
const resolved = await this.resolveRecipient(params.to);
|
|
2169
2204
|
const sendAmount = params.amount;
|
|
2170
2205
|
const sendTo = resolved.address;
|
|
@@ -2176,7 +2211,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2176
2211
|
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset: sendableAsset }),
|
|
2177
2212
|
{ buildClient }
|
|
2178
2213
|
);
|
|
2179
|
-
this.
|
|
2214
|
+
this.limits.record(approxUsdValue(sendableAsset, sendAmount) ?? 0);
|
|
2180
2215
|
const balance = await this.balance();
|
|
2181
2216
|
this.emitBalanceChange(sendableAsset, sendAmount, "send", gasResult.digest);
|
|
2182
2217
|
return {
|
|
@@ -2734,7 +2769,6 @@ exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
|
|
|
2734
2769
|
exports.CLOCK_ID = CLOCK_ID;
|
|
2735
2770
|
exports.DEFAULT_GRPC_URL = DEFAULT_GRPC_URL;
|
|
2736
2771
|
exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
|
|
2737
|
-
exports.DEFAULT_SAFEGUARD_CONFIG = DEFAULT_SAFEGUARD_CONFIG;
|
|
2738
2772
|
exports.GASLESS_MIN_STABLE_AMOUNT = GASLESS_MIN_STABLE_AMOUNT;
|
|
2739
2773
|
exports.GASLESS_STABLE_TYPES = GASLESS_STABLE_TYPES;
|
|
2740
2774
|
exports.GAS_RESERVE_MIN = GAS_RESERVE_MIN;
|
|
@@ -2742,6 +2776,8 @@ exports.InvalidAddressError = InvalidAddressError;
|
|
|
2742
2776
|
exports.KNOWN_TARGETS = KNOWN_TARGETS;
|
|
2743
2777
|
exports.KeypairSigner = KeypairSigner;
|
|
2744
2778
|
exports.LABEL_PATTERNS = LABEL_PATTERNS;
|
|
2779
|
+
exports.LimitEnforcer = LimitEnforcer;
|
|
2780
|
+
exports.LimitExceededError = LimitExceededError;
|
|
2745
2781
|
exports.MIST_PER_SUI = MIST_PER_SUI;
|
|
2746
2782
|
exports.OPERATION_ASSETS = OPERATION_ASSETS;
|
|
2747
2783
|
exports.SENDABLE_ASSETS = SENDABLE_ASSETS;
|
|
@@ -2752,8 +2788,6 @@ exports.SUI_ADDRESS_REGEX = SUI_ADDRESS_REGEX;
|
|
|
2752
2788
|
exports.SUI_ADDRESS_STRICT_REGEX = SUI_ADDRESS_STRICT_REGEX;
|
|
2753
2789
|
exports.SUI_DECIMALS = SUI_DECIMALS;
|
|
2754
2790
|
exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
|
|
2755
|
-
exports.SafeguardEnforcer = SafeguardEnforcer;
|
|
2756
|
-
exports.SafeguardError = SafeguardError;
|
|
2757
2791
|
exports.SuinsNotRegisteredError = SuinsNotRegisteredError;
|
|
2758
2792
|
exports.SuinsRpcError = SuinsRpcError;
|
|
2759
2793
|
exports.T2000 = T2000;
|
|
@@ -2763,7 +2797,9 @@ exports.WRITE_APPENDER_REGISTRY = WRITE_APPENDER_REGISTRY;
|
|
|
2763
2797
|
exports.ZkLoginSigner = ZkLoginSigner;
|
|
2764
2798
|
exports.addSendToTx = addSendToTx;
|
|
2765
2799
|
exports.addSwapToTx = addSwapToTx;
|
|
2800
|
+
exports.approxUsdValue = approxUsdValue;
|
|
2766
2801
|
exports.assertAllowedAsset = assertAllowedAsset;
|
|
2802
|
+
exports.assertLimitConfig = assertLimitConfig;
|
|
2767
2803
|
exports.buildAddLeafTx = buildAddLeafTx;
|
|
2768
2804
|
exports.buildRevokeLeafTx = buildRevokeLeafTx;
|
|
2769
2805
|
exports.buildSendTx = buildSendTx;
|
|
@@ -2771,7 +2807,9 @@ exports.buildSwapTx = buildSwapTx;
|
|
|
2771
2807
|
exports.classifyAction = classifyAction;
|
|
2772
2808
|
exports.classifyLabel = classifyLabel;
|
|
2773
2809
|
exports.classifyTransaction = classifyTransaction;
|
|
2810
|
+
exports.clearLimits = clearLimits;
|
|
2774
2811
|
exports.composeTx = composeTx;
|
|
2812
|
+
exports.dailySpentToday = dailySpentToday;
|
|
2775
2813
|
exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
|
|
2776
2814
|
exports.deserializeCetusRoute = deserializeCetusRoute;
|
|
2777
2815
|
exports.displayHandle = displayHandle;
|
|
@@ -2793,10 +2831,12 @@ exports.getAddress = getAddress;
|
|
|
2793
2831
|
exports.getCoinMeta = getCoinMeta;
|
|
2794
2832
|
exports.getDecimals = getDecimals;
|
|
2795
2833
|
exports.getDecimalsForCoinType = getDecimalsForCoinType;
|
|
2834
|
+
exports.getLimits = getLimits;
|
|
2796
2835
|
exports.getSponsoredSwapProviders = getSponsoredSwapProviders;
|
|
2797
2836
|
exports.getSuiClient = getSuiClient;
|
|
2798
2837
|
exports.getSuiGrpcClient = getSuiGrpcClient;
|
|
2799
2838
|
exports.getSwapQuote = getSwapQuote;
|
|
2839
|
+
exports.hasLimits = hasLimits;
|
|
2800
2840
|
exports.isAllowedAsset = isAllowedAsset;
|
|
2801
2841
|
exports.isCetusRouteFresh = isCetusRouteFresh;
|
|
2802
2842
|
exports.isInRegistry = isInRegistry;
|
|
@@ -2815,6 +2855,8 @@ exports.queryHistory = queryHistory;
|
|
|
2815
2855
|
exports.queryTransaction = queryTransaction;
|
|
2816
2856
|
exports.rawToStable = rawToStable;
|
|
2817
2857
|
exports.rawToUsdc = rawToUsdc;
|
|
2858
|
+
exports.readLimitsFile = readLimitsFile;
|
|
2859
|
+
exports.recordDailySpend = recordDailySpend;
|
|
2818
2860
|
exports.refineLendingLabel = refineLendingLabel;
|
|
2819
2861
|
exports.resolveAddressToSuinsViaRpc = resolveAddressToSuinsViaRpc;
|
|
2820
2862
|
exports.resolveSuinsViaRpc = resolveSuinsViaRpc;
|
|
@@ -2825,6 +2867,7 @@ exports.saveKey = saveKey;
|
|
|
2825
2867
|
exports.selectAndSplitCoin = selectAndSplitCoin;
|
|
2826
2868
|
exports.selectSuiCoin = selectSuiCoin;
|
|
2827
2869
|
exports.serializeCetusRoute = serializeCetusRoute;
|
|
2870
|
+
exports.setLimits = setLimits;
|
|
2828
2871
|
exports.simulateTransaction = simulateTransaction;
|
|
2829
2872
|
exports.stableToRaw = stableToRaw;
|
|
2830
2873
|
exports.suiToMist = suiToMist;
|
|
@@ -2835,5 +2878,6 @@ exports.validateAddress = validateAddress;
|
|
|
2835
2878
|
exports.validateLabel = validateLabel;
|
|
2836
2879
|
exports.verifyCetusRouteCoinMatch = verifyCetusRouteCoinMatch;
|
|
2837
2880
|
exports.walletExists = walletExists;
|
|
2881
|
+
exports.writeLimitsFile = writeLimitsFile;
|
|
2838
2882
|
//# sourceMappingURL=index.cjs.map
|
|
2839
2883
|
//# sourceMappingURL=index.cjs.map
|