Coin
The Coin class provides functionality for managing coin types, metadata, prices and balances in the Aftermath Finance protocol.
Initialization
const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider
const coin = afSdk.Coin();
Constants
Coin.constants = {
suiCoinType: "0x2::sui::SUI",
suiCoinDecimals: 9,
coinObjectType: "0x2::coin::Coin",
};
Methods
Coin Information
// Get coin decimals
const decimals = await coin.getCoinsToDecimals({
coins: ["0x2::sui::SUI"],
});
// Get coin metadata
const metadata = await coin.getCoinMetadata("0x2::sui::SUI");
// Get metadata for multiple coins
const metadatas = await coin.getCoinMetadatas({
coins: ["0x2::sui::SUI", "0x..."],
});
// Get coin price
const priceInfo = await coin.getPrice("0x2::sui::SUI");
// Get verified coins
const verifiedCoins = await coin.getVerifiedCoins();
Utility Functions
// Get coin type components
const packageName = Coin.getCoinTypePackageName("0x2::sui::SUI");
const symbol = Coin.getCoinTypeSymbol("0x2::sui::SUI");
const innerType = Coin.getInnerCoinType("0x2::sui::SUI");
// Check if coin is SUI
const isSui = Coin.isSuiCoin("0x2::sui::SUI");
// Filter coins
const filtered = Coin.filterCoinsByType({
filter: "sui",
coinTypes: ["0x2::sui::SUI", "0x..."],
});
// Balance conversions
const normalized = Coin.normalizeBalance(1.5, 9); // Convert to on-chain units
const withDecimals = Coin.balanceWithDecimals(1500000000n, 9); // Convert to display units
const withUsd = Coin.balanceWithDecimalsUsd(1500000000n, 9, 1.5); // Convert to USD
Types
Basic Types
type CoinType = string; // Coin address/identifier
type CoinDecimal = number; // Number of decimal places
type CoinSymbol = string; // Trading symbol
interface CoinPriceInfo {
price: number;
priceChange24HoursPercentage: number;
}
interface CoinWithAmount {
coin: CoinType;
amount: number;
}
Record Types
type CoinsToBalance = Record<CoinType, bigint>;
type CoinsToPrice = Record<CoinType, number>;
type CoinsToDecimals = Record<CoinType, number>;
type CoinsToPriceInfo = Record<CoinType, CoinPriceInfo>;
type CoinSymbolsToPriceInfo = Record<CoinSymbol, CoinPriceInfo>;
type CoinSymbolToCoinTypes = Record<CoinSymbol, CoinType[]>;
Example Usage
const afSdk = new Aftermath("MAINNET");
await afSdk.init();
const coin = afSdk.Coin();
// Get coin information
const metadata = await coin.getCoinMetadata("0x2::sui::SUI");
const priceInfo = await coin.getPrice("0x2::sui::SUI");
const decimals = await coin.getCoinsToDecimals({
coins: ["0x2::sui::SUI"],
});
// Convert amounts
const onChainAmount = Coin.normalizeBalance(1.5, 9);
const displayAmount = Coin.balanceWithDecimals(1500000000n, 9);
const usdValue = Coin.balanceWithDecimalsUsd(1500000000n, 9, priceInfo.price);
console.log(`Price: $${priceInfo.price}`);
console.log(`24h Change: ${priceInfo.priceChange24HoursPercentage}%`);
console.log(`Amount: ${displayAmount} SUI ($${usdValue})`);
Last updated