# Asset
An asset is a representation of a token's amount, symbol and precision.
It is important to note that smart contracts view token amounts as raw values without decimals. Take for example XPR with precision 4. An asset representing 1.2345 XPR would have an amount value of 12345.
# Constructors
constructor( public amount: i64 = 0, public symbol: Symbol = new Symbol() )amount- The amount of this asset.1.0000 XPR = amount 10,000 0.0010 XPR = amount 10symbol- The symbol of this asset.Symbols store precision and symbol code of the asset.Example:
import { Asset, Symbol } from 'proton-tsc' const symbol = new Symbol(4, "XPR") const asset = new Asset(10000, symbol)
static fromString(assetStr: string): AssetExample:
const asset = Asset.fromString("1.0000 XPR")
# Instance Methods
function isAmountWithinRange(): boolChecks that the asset has not overflown or underflown
function isValid(): boolChecks the Asset's isAmountWithinRange and that the symbol is valid
function toString(): stringConverts an asset to string.
Example:
const symbol = new Symbol(6, "XUSDC") const asset = new Asset(1000000, symbol) print(asset.toString()) // 1.000000 XUSDC
# Static Methods
static function add(a: Asset, b: Asset): AssetAdds two assets with the same symbol and returns a new asset with amount a + b
Throws if:
- Asset symbols do not match
 - (a + b) underflows i64
 - (a + b) overflows i64
 
static function sub(a: Asset, b: Asset): AssetSubstracts two assets with the same symbol and returns a new asset with amount a - b
Throws if:
- Asset symbols do not match
 - (a - b) underflows i64
 - (a - b) overflows i64
 
static function mul(a: Asset, b: Asset): AssetMultiplies two positive assets with the same symbol and returns a new asset with amount a * b
Throws if:
- Asset symbols do not match
 - a or b are negative
 - (a * b) overflows i64
 - (a - b) overflows
 
static function div(a: Asset, b: Asset): AssetDivides two positive assets with the same symbol and returns a new asset with amount a / b
Throws if:
- Asset symbols do not match
 - a or b are negative
 
static function eq(a: Asset, b: Asset): boolChecks that the amounts of two assets are equal
Throws if:
- Asset symbols do not match
 
static function neq(a: Asset, b: Asset): boolChecks that the amounts of two assets are not equal
Throws if:
- Asset symbols do not match
 
static function lt(a: Asset, b: Asset): boolChecks that the amounts of a is less than b
Throws if:
- Asset symbols do not match
 
static function gt(a: Asset, b: Asset): boolChecks that the amounts of a is greater than b
Throws if:
- Asset symbols do not match
 
static function lte(a: Asset, b: Asset): boolChecks that the amounts of a is less than or equal to b
Throws if:
- Asset symbols do not match
 
static function gte(a: Asset, b: Asset): boolChecks that the amounts of a is greater than or equal to b
Throws if:
- Asset symbols do not match