Skip to content

Commit a05bea8

Browse files
committed
feat: updated slpx testnet
1 parent bd9ea85 commit a05bea8

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/slpx-testnet.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { CONTRACT_ADDRESS_INFO, CHAIN_NAME_CHAIN_ID_MAP } from "./constants";
22
import { TESTNET_SLPX_V2_ABI } from "./abis";
3-
import { parseUnits, Address } from "viem";
4-
import { ValidTestnetChainInput } from "./types";
3+
import { parseUnits } from "viem";
4+
import { ValidTestnetChainInput, AssetName } from "./types";
5+
import { getTestnetAssetAddress } from "./utils";
56

67
//===============================================
78
// Function exports
89
//===============================================
910

1011
/**
1112
* Estimates the fee for sending and calling a cross-chain transaction
12-
* @param underlyingAssetAddress - The token contract address to send (e.g. 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native token, or token address)
13+
* @param underlyingAssetName - The name of the underlying asset
1314
* @param chain - The destination chain ID (currently supports Manta Pacific)
1415
* @param amount - The amount to send as a string (will be parsed with 18 decimals)
1516
* @param partnerCode - The partner code to use for the mint
@@ -18,7 +19,10 @@ import { ValidTestnetChainInput } from "./types";
1819
* @throws Error if amount is not a positive number
1920
* @throws Error if partner code is not a string
2021
*/
21-
export function getTestnetMintParams(underlyingAssetAddress: Address, chain: ValidTestnetChainInput, amount: string, partnerCode: string = "bifrost") {
22+
export function getTestnetMintParams(underlyingAssetName: AssetName, chain: ValidTestnetChainInput, amount: string, partnerCode: string = "bifrost") {
23+
// Check if the underlying asset address is valid
24+
const underlyingAssetAddress = getTestnetAssetAddress(underlyingAssetName, chain);
25+
2226
let chainId: number;
2327

2428
if (typeof chain === "string") {

src/utils.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
// UTILITY FUNCTIONS
22

3-
import { AssetName, ValidTestnetChainInput } from "./types";
3+
import { CONTRACT_ADDRESS_INFO, CHAIN_NAME_CHAIN_ID_MAP } from "./constants";
4+
import { AssetName, ValidTestnetChainInput, TestnetChainName } from "./types";
45

5-
export function getTestnetAssetAddress(assetName: AssetName, chain: ValidTestnetChainInput) {
6+
export function getTestnetAssetAddress(assetName: AssetName, chain: ValidTestnetChainInput): string {
7+
// Convert chain ID to chain name if needed
8+
let chainName: TestnetChainName;
69

10+
if (typeof chain === "number") {
11+
// Find chain name by chain ID
12+
const foundChainName = Object.entries(CHAIN_NAME_CHAIN_ID_MAP).find(
13+
([, chainId]) => chainId === chain
14+
)?.[0] as TestnetChainName;
15+
16+
if (!foundChainName) {
17+
throw new Error(`Unsupported chain ID: ${chain}`);
18+
}
19+
20+
chainName = foundChainName;
21+
} else {
22+
chainName = chain;
23+
}
24+
25+
// Get the network contract info for the chain
26+
const networkInfo = CONTRACT_ADDRESS_INFO[chainName];
27+
if (!networkInfo) {
28+
throw new Error(`Unsupported chain: ${chainName}`);
29+
}
30+
31+
// Get the asset info from the network
32+
const assetInfo = networkInfo[assetName];
33+
if (!assetInfo) {
34+
throw new Error(`Asset ${assetName} not found on chain ${chainName}`);
35+
}
36+
37+
return assetInfo.address;
738
}

0 commit comments

Comments
 (0)