@t2000/sdk 0.2.7 → 0.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/LICENSE +21 -0
- package/dist/index.cjs +72 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +72 -44
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 t2000
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -40,9 +40,9 @@ var SUPPORTED_ASSETS = {
|
|
|
40
40
|
symbol: "SUI"
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
process.env.T2000_PACKAGE_ID ?? "
|
|
44
|
-
process.env.T2000_CONFIG_ID ?? "
|
|
45
|
-
process.env.T2000_TREASURY_ID ?? "
|
|
43
|
+
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xab92e9f1fe549ad3d6a52924a73181b45791e76120b975138fac9ec9b75db9f3";
|
|
44
|
+
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x408add9aa9322f93cfd87523d8f603006eb8713894f4c460283c58a6888dae8a";
|
|
45
|
+
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0x3bb501b8300125dca59019247941a42af6b292a150ce3cfcce9449456be2ec91";
|
|
46
46
|
var DEFAULT_NETWORK = "mainnet";
|
|
47
47
|
var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
48
48
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
@@ -102,7 +102,8 @@ function mapMoveAbortCode(code) {
|
|
|
102
102
|
6: "Not authorized",
|
|
103
103
|
7: "Package version mismatch \u2014 upgrade required",
|
|
104
104
|
8: "Timelock is active \u2014 wait for expiry",
|
|
105
|
-
9: "No pending change to execute"
|
|
105
|
+
9: "No pending change to execute",
|
|
106
|
+
10: "Already at current version"
|
|
106
107
|
};
|
|
107
108
|
return abortMessages[code] ?? `Move abort code: ${code}`;
|
|
108
109
|
}
|
|
@@ -373,6 +374,61 @@ function inferAction(txBlock) {
|
|
|
373
374
|
if (kind === "ProgrammableTransaction") return "transaction";
|
|
374
375
|
return kind ?? "unknown";
|
|
375
376
|
}
|
|
377
|
+
|
|
378
|
+
// src/protocols/protocolFee.ts
|
|
379
|
+
var FEE_RATES = {
|
|
380
|
+
save: SAVE_FEE_BPS,
|
|
381
|
+
swap: SWAP_FEE_BPS,
|
|
382
|
+
borrow: BORROW_FEE_BPS
|
|
383
|
+
};
|
|
384
|
+
var OP_CODES = {
|
|
385
|
+
save: 0,
|
|
386
|
+
swap: 1,
|
|
387
|
+
borrow: 2
|
|
388
|
+
};
|
|
389
|
+
function calculateFee(operation, amount) {
|
|
390
|
+
const bps = FEE_RATES[operation];
|
|
391
|
+
const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
|
|
392
|
+
const rawAmount = usdcToRaw(feeAmount);
|
|
393
|
+
return {
|
|
394
|
+
amount: feeAmount,
|
|
395
|
+
asset: "USDC",
|
|
396
|
+
rate: Number(bps) / Number(BPS_DENOMINATOR),
|
|
397
|
+
rawAmount
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function addCollectFeeToTx(tx, paymentCoin, operation) {
|
|
401
|
+
const bps = FEE_RATES[operation];
|
|
402
|
+
if (bps <= 0n) return;
|
|
403
|
+
tx.moveCall({
|
|
404
|
+
target: `${T2000_PACKAGE_ID}::treasury::collect_fee`,
|
|
405
|
+
typeArguments: [SUPPORTED_ASSETS.USDC.type],
|
|
406
|
+
arguments: [
|
|
407
|
+
tx.object(T2000_TREASURY_ID),
|
|
408
|
+
tx.object(T2000_CONFIG_ID),
|
|
409
|
+
paymentCoin,
|
|
410
|
+
tx.pure.u8(OP_CODES[operation])
|
|
411
|
+
]
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest) {
|
|
415
|
+
try {
|
|
416
|
+
await fetch(`${API_BASE_URL}/api/fees`, {
|
|
417
|
+
method: "POST",
|
|
418
|
+
headers: { "Content-Type": "application/json" },
|
|
419
|
+
body: JSON.stringify({
|
|
420
|
+
agentAddress,
|
|
421
|
+
operation,
|
|
422
|
+
feeAmount: feeAmount.toString(),
|
|
423
|
+
feeRate: feeRate.toString(),
|
|
424
|
+
txDigest
|
|
425
|
+
})
|
|
426
|
+
});
|
|
427
|
+
} catch {
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/protocols/navi.ts
|
|
376
432
|
var ENV = { env: "prod" };
|
|
377
433
|
var USDC_TYPE = SUPPORTED_ASSETS.USDC.type;
|
|
378
434
|
var RATE_DECIMALS = 27;
|
|
@@ -415,7 +471,7 @@ async function updateOracle(tx, client, address) {
|
|
|
415
471
|
} catch {
|
|
416
472
|
}
|
|
417
473
|
}
|
|
418
|
-
async function buildSaveTx(client, address, amount) {
|
|
474
|
+
async function buildSaveTx(client, address, amount, options = {}) {
|
|
419
475
|
const rawAmount = Number(usdcToRaw(amount));
|
|
420
476
|
const coins = await lending.getCoins(address, { coinType: USDC_TYPE, client });
|
|
421
477
|
if (!coins || coins.length === 0) {
|
|
@@ -424,6 +480,9 @@ async function buildSaveTx(client, address, amount) {
|
|
|
424
480
|
const tx = new transactions.Transaction();
|
|
425
481
|
tx.setSender(address);
|
|
426
482
|
const coinObj = lending.mergeCoinsPTB(tx, coins, { balance: rawAmount });
|
|
483
|
+
if (options.collectFee) {
|
|
484
|
+
addCollectFeeToTx(tx, coinObj, "save");
|
|
485
|
+
}
|
|
427
486
|
await lending.depositCoinPTB(tx, USDC_TYPE, coinObj, ENV);
|
|
428
487
|
return tx;
|
|
429
488
|
}
|
|
@@ -441,12 +500,15 @@ async function buildWithdrawTx(client, address, amount) {
|
|
|
441
500
|
tx.transferObjects([withdrawnCoin], address);
|
|
442
501
|
return { tx, effectiveAmount };
|
|
443
502
|
}
|
|
444
|
-
async function buildBorrowTx(client, address, amount) {
|
|
503
|
+
async function buildBorrowTx(client, address, amount, options = {}) {
|
|
445
504
|
const rawAmount = Number(usdcToRaw(amount));
|
|
446
505
|
const tx = new transactions.Transaction();
|
|
447
506
|
tx.setSender(address);
|
|
448
507
|
await updateOracle(tx, client, address);
|
|
449
508
|
const borrowedCoin = await lending.borrowCoinPTB(tx, USDC_TYPE, rawAmount, ENV);
|
|
509
|
+
if (options.collectFee) {
|
|
510
|
+
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
511
|
+
}
|
|
450
512
|
tx.transferObjects([borrowedCoin], address);
|
|
451
513
|
return tx;
|
|
452
514
|
}
|
|
@@ -654,40 +716,6 @@ async function getSwapQuote(client, fromAsset, toAsset, amount) {
|
|
|
654
716
|
}
|
|
655
717
|
}
|
|
656
718
|
|
|
657
|
-
// src/protocols/protocolFee.ts
|
|
658
|
-
var FEE_RATES = {
|
|
659
|
-
save: SAVE_FEE_BPS,
|
|
660
|
-
swap: SWAP_FEE_BPS,
|
|
661
|
-
borrow: BORROW_FEE_BPS
|
|
662
|
-
};
|
|
663
|
-
function calculateFee(operation, amount) {
|
|
664
|
-
const bps = FEE_RATES[operation];
|
|
665
|
-
const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
|
|
666
|
-
const rawAmount = usdcToRaw(feeAmount);
|
|
667
|
-
return {
|
|
668
|
-
amount: feeAmount,
|
|
669
|
-
asset: "USDC",
|
|
670
|
-
rate: Number(bps) / Number(BPS_DENOMINATOR),
|
|
671
|
-
rawAmount
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest) {
|
|
675
|
-
try {
|
|
676
|
-
await fetch(`${API_BASE_URL}/api/fees`, {
|
|
677
|
-
method: "POST",
|
|
678
|
-
headers: { "Content-Type": "application/json" },
|
|
679
|
-
body: JSON.stringify({
|
|
680
|
-
agentAddress,
|
|
681
|
-
operation,
|
|
682
|
-
feeAmount: feeAmount.toString(),
|
|
683
|
-
feeRate: feeRate.toString(),
|
|
684
|
-
txDigest
|
|
685
|
-
})
|
|
686
|
-
});
|
|
687
|
-
} catch {
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
719
|
// src/protocols/yieldTracker.ts
|
|
692
720
|
async function getEarnings(client, keypair) {
|
|
693
721
|
const hf = await getHealthFactor(client, keypair);
|
|
@@ -1280,12 +1308,12 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1280
1308
|
const gasResult = await executeWithGas(
|
|
1281
1309
|
this.client,
|
|
1282
1310
|
this.keypair,
|
|
1283
|
-
() => buildSaveTx(this.client, this._address, saveAmount)
|
|
1311
|
+
() => buildSaveTx(this.client, this._address, saveAmount, { collectFee: true })
|
|
1284
1312
|
);
|
|
1285
1313
|
const rates = await getRates(this.client);
|
|
1286
1314
|
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
1287
1315
|
this.emitBalanceChange("USDC", saveAmount, "save", gasResult.digest);
|
|
1288
|
-
let savingsBalance = saveAmount
|
|
1316
|
+
let savingsBalance = saveAmount;
|
|
1289
1317
|
try {
|
|
1290
1318
|
const positions = await this.positions();
|
|
1291
1319
|
savingsBalance = positions.positions.filter((p) => p.type === "save").reduce((sum, p) => sum + p.amount, 0);
|
|
@@ -1369,7 +1397,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
1369
1397
|
const gasResult = await executeWithGas(
|
|
1370
1398
|
this.client,
|
|
1371
1399
|
this.keypair,
|
|
1372
|
-
() => buildBorrowTx(this.client, this._address, borrowAmount)
|
|
1400
|
+
() => buildBorrowTx(this.client, this._address, borrowAmount, { collectFee: true })
|
|
1373
1401
|
);
|
|
1374
1402
|
const hf = await getHealthFactor(this.client, this.keypair);
|
|
1375
1403
|
reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
|
|
@@ -1634,6 +1662,7 @@ exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
|
|
|
1634
1662
|
exports.T2000 = T2000;
|
|
1635
1663
|
exports.T2000Error = T2000Error;
|
|
1636
1664
|
exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
1665
|
+
exports.addCollectFeeToTx = addCollectFeeToTx;
|
|
1637
1666
|
exports.calculateFee = calculateFee;
|
|
1638
1667
|
exports.executeAutoTopUp = executeAutoTopUp;
|
|
1639
1668
|
exports.executeWithGas = executeWithGas;
|