Skip to content

Commit be5519d

Browse files
committed
feat: updated slpx functions for manta
1 parent f21e225 commit be5519d

1 file changed

Lines changed: 72 additions & 1 deletion

File tree

src/slpx.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,76 @@
11
import { CONTRACT_ADDRESS_INFO } from "./constants";
2-
import { SLPX_V2_ABI } from "./abis";
2+
import { SLPX_V2_ABI, MANTA_SLPX_V1_ABI } from "./abis";
3+
import { parseUnits, encodePacked } from "viem";
4+
import { manta } from "viem/chains"
5+
6+
//===============================================
7+
// Function exports
8+
//===============================================
9+
10+
/**
11+
* Estimates the fee for sending and calling a cross-chain transaction
12+
* @param asset - The token contract address to send (e.g. 0xeeeEEEeEEeeeEeEeEEEeEeeeeEEEEeEEeEeeeeeE for native token, or token address)
13+
* @param chainId - The destination chain ID (currently supports Manta Pacific)
14+
* @param amount - The amount to send as a string (will be parsed with 18 decimals)
15+
* @returns Contract call params for estimateSendAndCallFee function
16+
* @throws Error if asset is not supported for the given chain
17+
*/
18+
export function getEstimateSendAndCallFeeParams(asset: string, chainId: number, amount: string) {
19+
switch (chainId) {
20+
// Handle Manta Pacific (SLPX v1)
21+
case manta.id:
22+
// throw error if not MANTA token
23+
if (asset !== CONTRACT_ADDRESS_INFO.mantaPacific.manta?.address) {
24+
throw new Error("Asset is not MANTA token");
25+
}
26+
// Otherwise return params
27+
return {
28+
address: CONTRACT_ADDRESS_INFO.mantaPacific.slpx?.address,
29+
abi: MANTA_SLPX_V1_ABI,
30+
functionName: "estimateSendAndCallFee",
31+
args: [
32+
asset, // MANTA token
33+
parseUnits(amount, 18), // amount
34+
0, // channel_id
35+
4000000, // dstGasForCall
36+
encodePacked(["uint16", "uint256"], [1, BigInt(4200000)]), // adapterParams
37+
],
38+
}
39+
default:
40+
throw new Error("Chain ID is not valid or unsupported");
41+
}
42+
}
43+
44+
/**
45+
* Returns the contract address info
46+
* @param consoleLog - Whether to console log the contract address info
47+
* @returns
48+
*/
49+
export function getContractAddressInfo(consoleLog = false) {
50+
if (consoleLog) {
51+
console.log(CONTRACT_ADDRESS_INFO, 2, 2);
52+
}
53+
return CONTRACT_ADDRESS_INFO;
54+
}
55+
56+
/**
57+
* Returns the SLPX v2 ABI
58+
* @param consoleLog - Whether to console log the SLPX v2 ABI
59+
* @returns SLPX v2 ABI
60+
*/
61+
export function getSlpxAbi(consoleLog = false) {
62+
if (consoleLog) {
63+
console.log(SLPX_V2_ABI, 2, 2);
64+
}
65+
return SLPX_V2_ABI;
66+
}
67+
68+
69+
70+
71+
//===============================================
72+
// Class export
73+
//===============================================
374

475
export class Slpx {
576
private rspId: string;

0 commit comments

Comments
 (0)