Skip to content

Commit

Permalink
Merge pull request #697 from massalabs/695-add-wmas-token-address--wr…
Browse files Browse the repository at this point in the history
…apper

695 add wmas token address  wrapper
  • Loading branch information
peterjah authored Nov 4, 2024
2 parents 4e45a4a + 3a9ea8e commit ffc98a8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
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)
}
}

1 comment on commit ffc98a8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for experimental massa-web3

St.
Category Percentage Covered / Total
🟡 Statements 64.13% 1171/1826
🔴 Branches 45.77% 195/426
🔴 Functions 47.33% 213/450
🟡 Lines 64.42% 1164/1807

Test suite run success

132 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from ffc98a8

Please sign in to comment.