@townsq/mm-sdk 2.5.0 → 2.8.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/chains/evm/common/constant/tokens.js +4 -4
- package/dist/chains/evm/common/constant/tokens.js.map +1 -1
- package/dist/chains/evm/hub/constants/chain.js +16 -13
- package/dist/chains/evm/hub/constants/chain.js.map +1 -1
- package/dist/chains/evm/spoke/modules/ts-evm-loan.d.ts +1 -1
- package/dist/chains/evm/spoke/modules/ts-evm-loan.js +67 -19
- package/dist/chains/evm/spoke/modules/ts-evm-loan.js.map +1 -1
- package/dist/common/constants/chain.js +16 -10
- package/dist/common/constants/chain.js.map +1 -1
- package/dist/common/constants/pool.d.ts +0 -1
- package/dist/common/constants/pool.js +1 -1
- package/dist/common/constants/pool.js.map +1 -1
- package/dist/common/types/token.d.ts +0 -1
- package/dist/common/types/token.js +1 -1
- package/dist/common/types/token.js.map +1 -1
- package/dist/lifeline/modules/ts-loan.js +0 -1
- package/dist/lifeline/modules/ts-loan.js.map +1 -1
- package/package.json +1 -1
- package/src/chains/evm/common/constant/tokens.ts +4 -4
- package/src/chains/evm/hub/constants/chain.ts +16 -16
- package/src/chains/evm/spoke/modules/ts-evm-loan.ts +83 -21
- package/src/common/constants/chain.ts +16 -16
- package/src/common/constants/pool.ts +1 -1
- package/src/common/types/token.ts +1 -1
- package/src/lifeline/modules/ts-loan.ts +83 -84
|
@@ -100,10 +100,10 @@ export const CONTRACT_SLOT: Partial<
|
|
|
100
100
|
balanceOf: 9n,
|
|
101
101
|
allowance: 10n,
|
|
102
102
|
},
|
|
103
|
-
[MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
},
|
|
103
|
+
// [MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
104
|
+
// balanceOf: 9n,
|
|
105
|
+
// allowance: 10n,
|
|
106
|
+
// },
|
|
107
107
|
},
|
|
108
108
|
},
|
|
109
109
|
} as const;
|
|
@@ -419,22 +419,22 @@ export const HUB_CHAIN: Record<NetworkType.MAINNET, HubChain> = {
|
|
|
419
419
|
MAINNET_LOAN_TYPE_ID.DEPOSIT,
|
|
420
420
|
]),
|
|
421
421
|
},
|
|
422
|
-
[MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
},
|
|
422
|
+
// [MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
423
|
+
// token: {
|
|
424
|
+
// type: TokenType.ERC20,
|
|
425
|
+
// decimals: 10,
|
|
426
|
+
// },
|
|
427
|
+
// TsTokenId: MAINNET_TS_TOKEN_ID.eBTC,
|
|
428
|
+
// poolId: MAINNET_POOLS[MAINNET_TS_TOKEN_ID.eBTC],
|
|
429
|
+
// poolAddress: convertToGenericAddress(
|
|
430
|
+
// '0x1fcd2d883e6ef9146672e2bdb8501918dc7b3ed4' as EvmAddress,
|
|
431
|
+
// ChainType.EVM,
|
|
432
|
+
// ),
|
|
433
|
+
// supportedLoanTypes: new Set([
|
|
434
|
+
// MAINNET_LOAN_TYPE_ID.BTC_EFFICIENCY,
|
|
435
|
+
// MAINNET_LOAN_TYPE_ID.DEPOSIT,
|
|
436
|
+
// ]),
|
|
437
|
+
// },
|
|
438
438
|
} satisfies Record<MainnetTsTokenId, HubTokenData>,
|
|
439
439
|
},
|
|
440
440
|
};
|
|
@@ -48,7 +48,14 @@ import type {
|
|
|
48
48
|
PrepareWithdrawCall,
|
|
49
49
|
} from '../../common/types/module.js';
|
|
50
50
|
import type { TokenRateLimit } from '../types/pool.js';
|
|
51
|
-
import
|
|
51
|
+
import {
|
|
52
|
+
BaseError,
|
|
53
|
+
Client,
|
|
54
|
+
ContractFunctionRevertedError,
|
|
55
|
+
EstimateGasExecutionError,
|
|
56
|
+
EstimateGasParameters,
|
|
57
|
+
WalletClient,
|
|
58
|
+
} from 'viem';
|
|
52
59
|
|
|
53
60
|
export const prepare = {
|
|
54
61
|
async createLoan(
|
|
@@ -193,9 +200,9 @@ export const prepare = {
|
|
|
193
200
|
spokeTokenData.token.type === TokenType.NATIVE ? amount : BigInt(0);
|
|
194
201
|
const msgValue = adapterFees + value;
|
|
195
202
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
await spokeToken.estimateGas.initiateLoanAccountWithDeposit(
|
|
203
|
+
let gasLimit = GAS_LIMIT_ESTIMATE_INCREASE;
|
|
204
|
+
try {
|
|
205
|
+
gasLimit += await spokeToken.estimateGas.initiateLoanAccountWithDeposit(
|
|
199
206
|
[messageToSend.params, accountId, nonce, amount, loanTypeId, loanName],
|
|
200
207
|
{
|
|
201
208
|
value: msgValue,
|
|
@@ -203,10 +210,26 @@ export const prepare = {
|
|
|
203
210
|
stateOverride,
|
|
204
211
|
}
|
|
205
212
|
);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error instanceof BaseError) {
|
|
215
|
+
const revert = error.walk(
|
|
216
|
+
(e) => e instanceof ContractFunctionRevertedError
|
|
217
|
+
) as ContractFunctionRevertedError | undefined;
|
|
218
|
+
|
|
219
|
+
const reason =
|
|
220
|
+
revert?.data?.errorName ?? revert?.reason ?? error.shortMessage;
|
|
206
221
|
|
|
222
|
+
if (!reason?.toLowerCase().includes('reserve balance violation')) {
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
// else: swallow — it's the expected "reserve balance violation" case
|
|
226
|
+
} else {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
207
230
|
return {
|
|
208
231
|
msgValue,
|
|
209
|
-
gasLimit: gasLimit
|
|
232
|
+
gasLimit: gasLimit,
|
|
210
233
|
messageParams: messageToSend.params,
|
|
211
234
|
spokeTokenData: spokeTokenData,
|
|
212
235
|
};
|
|
@@ -271,18 +294,38 @@ export const prepare = {
|
|
|
271
294
|
const msgValue = adapterFees + value;
|
|
272
295
|
|
|
273
296
|
// get gas limits
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
297
|
+
let gasLimit = GAS_LIMIT_ESTIMATE_INCREASE;
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
gasLimit += await spokeToken.estimateGas.topup(
|
|
301
|
+
[messageToSend.params, accountId, loanId, amount],
|
|
302
|
+
{
|
|
303
|
+
value: msgValue,
|
|
304
|
+
...transactionOptions,
|
|
305
|
+
stateOverride,
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
if (error instanceof BaseError) {
|
|
310
|
+
const revert = error.walk(
|
|
311
|
+
(e) => e instanceof ContractFunctionRevertedError
|
|
312
|
+
) as ContractFunctionRevertedError | undefined;
|
|
313
|
+
|
|
314
|
+
const reason =
|
|
315
|
+
revert?.data?.errorName ?? revert?.reason ?? error.shortMessage;
|
|
316
|
+
|
|
317
|
+
if (!reason?.toLowerCase().includes('reserve balance violation')) {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
// else: swallow — it's the expected "reserve balance violation" case
|
|
321
|
+
} else {
|
|
322
|
+
throw error;
|
|
280
323
|
}
|
|
281
|
-
|
|
324
|
+
}
|
|
282
325
|
|
|
283
326
|
return {
|
|
284
327
|
msgValue,
|
|
285
|
-
gasLimit: gasLimit
|
|
328
|
+
gasLimit: gasLimit,
|
|
286
329
|
messageParams: messageToSend.params,
|
|
287
330
|
spokeTokenData: spokeTokenData,
|
|
288
331
|
};
|
|
@@ -456,18 +499,37 @@ export const prepare = {
|
|
|
456
499
|
const msgValue = adapterFees + value;
|
|
457
500
|
|
|
458
501
|
// get gas limits
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
502
|
+
let gasLimit = GAS_LIMIT_ESTIMATE_INCREASE;
|
|
503
|
+
try {
|
|
504
|
+
gasLimit += await spokeToken.estimateGas.repay(
|
|
505
|
+
[messageToSend.params, accountId, loanId, amount, maxOverRepayment],
|
|
506
|
+
{
|
|
507
|
+
value: msgValue,
|
|
508
|
+
...transactionOptions,
|
|
509
|
+
stateOverride,
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
} catch (error) {
|
|
513
|
+
if (error instanceof BaseError) {
|
|
514
|
+
const revert = error.walk(
|
|
515
|
+
(e) => e instanceof ContractFunctionRevertedError
|
|
516
|
+
) as ContractFunctionRevertedError | undefined;
|
|
517
|
+
|
|
518
|
+
const reason =
|
|
519
|
+
revert?.data?.errorName ?? revert?.reason ?? error.shortMessage;
|
|
520
|
+
|
|
521
|
+
if (!reason?.toLowerCase().includes('reserve balance violation')) {
|
|
522
|
+
throw error;
|
|
523
|
+
}
|
|
524
|
+
// else: swallow — it's the expected "reserve balance violation" case
|
|
525
|
+
} else {
|
|
526
|
+
throw error;
|
|
465
527
|
}
|
|
466
|
-
|
|
528
|
+
}
|
|
467
529
|
|
|
468
530
|
return {
|
|
469
531
|
msgValue,
|
|
470
|
-
gasLimit: gasLimit
|
|
532
|
+
gasLimit: gasLimit,
|
|
471
533
|
messageParams: messageToSend.params,
|
|
472
534
|
spokeTokenData: spokeTokenData,
|
|
473
535
|
};
|
|
@@ -409,22 +409,22 @@ export const SPOKE_CHAIN: Record<
|
|
|
409
409
|
ChainType.EVM,
|
|
410
410
|
),
|
|
411
411
|
},
|
|
412
|
-
[MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
},
|
|
412
|
+
// [MAINNET_TS_TOKEN_ID.eBTC]: {
|
|
413
|
+
// token: {
|
|
414
|
+
// type: TokenType.ERC20,
|
|
415
|
+
// address: convertToGenericAddress(
|
|
416
|
+
// '0xd691b0aFed67F96CEC28Ab6308Cbe5b2C103b7e9' as EvmAddress,
|
|
417
|
+
// ChainType.EVM,
|
|
418
|
+
// ),
|
|
419
|
+
// decimals: 10,
|
|
420
|
+
// },
|
|
421
|
+
// TsTokenId: MAINNET_TS_TOKEN_ID.eBTC,
|
|
422
|
+
// poolId: MAINNET_POOLS[MAINNET_TS_TOKEN_ID.eBTC],
|
|
423
|
+
// spokeAddress: convertToGenericAddress(
|
|
424
|
+
// '0xe1afcb1f8977ca04ca3a971bcb509b6d7558babd' as EvmAddress,
|
|
425
|
+
// ChainType.EVM,
|
|
426
|
+
// ),
|
|
427
|
+
// },
|
|
428
428
|
},
|
|
429
429
|
},
|
|
430
430
|
} satisfies Record<MainnetTsChainId, SpokeChain>,
|
|
@@ -27,7 +27,7 @@ export const MAINNET_POOLS = {
|
|
|
27
27
|
[MAINNET_TS_TOKEN_ID.yzUSD]: 24,
|
|
28
28
|
[MAINNET_TS_TOKEN_ID.cbBTC]: 26,
|
|
29
29
|
[MAINNET_TS_TOKEN_ID.enzoBTC]: 31,
|
|
30
|
-
[MAINNET_TS_TOKEN_ID.eBTC]: 30,
|
|
30
|
+
// [MAINNET_TS_TOKEN_ID.eBTC]: 30,
|
|
31
31
|
|
|
32
32
|
} as const satisfies Record<MainnetTsTokenId, number>;
|
|
33
33
|
|