Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

695 add wmas token address wrapper #697

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions src/contracts-wrappers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,58 @@ import { CallSCOptions, ReadSCOptions, SmartContract } from '../smartContracts'
*/

export class MRC20 extends SmartContract {
// eslint-disable-next-line @typescript-eslint/naming-convention
private _version: string
// eslint-disable-next-line @typescript-eslint/naming-convention
private _name: string
// eslint-disable-next-line @typescript-eslint/naming-convention
private _symbol: string
// eslint-disable-next-line @typescript-eslint/naming-convention
private _decimals: number

async version(options?: ReadSCOptions): Promise<string> {
if (this._version) {
return this._version
}
const res = await this.read('version', undefined, options)
return bytesToStr(res.value)
return (this._version = bytesToStr(res.value))
}

async name(options?: ReadSCOptions): Promise<string> {
const res = await this.read('name', undefined, options)
return bytesToStr(res.value)
async name(): Promise<string> {
if (this._name) {
return this._name
}
const res = await this.provider.readStorage(this.address, ['NAME'], true)
return (this._name = bytesToStr(res[0]))
}

async symbol(options?: ReadSCOptions): Promise<string> {
const res = await this.read('symbol', undefined, options)
return bytesToStr(res.value)
async symbol(): Promise<string> {
if (this._symbol) {
return this._symbol
}
const res = await this.provider.readStorage(this.address, ['SYMBOL'], true)
return (this._symbol = bytesToStr(res[0]))
}

async decimals(options?: ReadSCOptions): Promise<number> {
const res = await this.read('decimals', undefined, options)
return Number(U8.fromBytes(res.value))
async decimals(): Promise<number> {
if (this._decimals) {
return this._decimals
}
const res = await this.provider.readStorage(
this.address,
['DECIMALS'],
true
)
return (this._decimals = Number(U8.fromBytes(res[0])))
}

async totalSupply(options?: ReadSCOptions): Promise<bigint> {
const res = await this.read('totalSupply', undefined, options)
return U256.fromBytes(res.value)
async totalSupply(final = true): Promise<bigint> {
const res = await this.provider.readStorage(
this.address,
['TOTAL_SUPPLY'],
final
)
return U256.fromBytes(res[0])
}

async balanceOf(address: string, options?: ReadSCOptions): Promise<bigint> {
Expand Down
16 changes: 16 additions & 0 deletions src/contracts-wrappers/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const MAINNET_TOKENS = {
WETHe: 'AS124vf3YfAJCSCQVYKczzuWWpXrximFpbTmX4rheLs5uNSftiiRY',
WETHb: 'AS125oPLYRTtfVjpWisPZVTLjBhCFfQ1jDsi75XNtRm1NZux54eCj',
PUR: 'AS133eqPPaPttJ6hJnk3sfoG5cjFFqBDi1VGxdo2wzWkq8AfZnan',
WMAS: 'AS12U4TZfNK7qoLyEERBBRDMu8nm5MKoRzPXDXans4v9wdATZedz9',
}

export const BUILDNET_TOKENS = {
Expand All @@ -18,6 +19,7 @@ export const BUILDNET_TOKENS = {
USDCs: 'AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL',
USDTbt: 'AS12ix1Qfpue7BB8q6mWVtjNdNE9UV3x4MaUo7WhdUubov8sJ3CuP',
WETHbt: 'AS12RmCXTA9NZaTBUBnRJuH66AGNmtEfEoqXKxLdmrTybS6GFJPFs',
WMAS: 'AS12FW5Rs5YN2zdpEnqwj4iHUUPt9R4Eqjq2qtpJFNKW3mn33RuLU',
}

export function checkNetwork(provider: Provider, isMainnet: boolean): void {
Expand Down Expand Up @@ -74,6 +76,13 @@ export class PUR extends MRC20 {
}
}

export class WMAS extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.WMAS)
}
}

///////////////// BUILDNET TOKENS //////////////////////

export class DAIs extends MRC20 {
Expand Down Expand Up @@ -110,3 +119,10 @@ export class WETHbt extends MRC20 {
super(provider, BUILDNET_TOKENS.WETHbt)
}
}

export class WMASBuildnet extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.WMAS)
}
}
Loading