-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: WMAS Standard * fix: run fmt * fix param * fix compilation errors * feat: WMAS interface & add missing function in wrapper * fix missing doc * fix: remove deprecated link * Update recipient address Co-authored-by: Senji888 <44082144+Ben-Rey@users.noreply.github.com> * run fmt * refactor: inverse ligne --------- Co-authored-by: Senji888 <44082144+Ben-Rey@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Args } from '@massalabs/as-types'; | ||
import { Address, call } from '@massalabs/massa-as-sdk'; | ||
import { TokenWrapper } from './wrapper'; | ||
import { u256 } from 'as-bignum/assembly/integer/u256'; | ||
|
||
export class IWMAS extends TokenWrapper { | ||
init( | ||
name: string = 'Wrapped Massa', | ||
symbol: string = 'WMAS', | ||
decimals: u8 = 9, | ||
supply: u256 = u256.Zero, | ||
): void { | ||
super.init(name, symbol, decimals, supply); | ||
} | ||
|
||
deposit(value: u64): void { | ||
call(this._origin, 'deposit', new Args(), value); | ||
} | ||
|
||
withdraw(value: u64, to: Address): void { | ||
call(this._origin, 'withdraw', new Args().add(value).add(to), 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Args, u256ToBytes } from '@massalabs/as-types'; | ||
import { Address, Context, transferCoins } from '@massalabs/massa-as-sdk'; | ||
import { burn } from './burnable/burn'; | ||
import { u256 } from 'as-bignum/assembly/integer/u256'; | ||
import { _mint } from './mintable/mint-internal'; | ||
|
||
export * from './token'; | ||
|
||
/** | ||
* Wrap wanted value. | ||
* | ||
* @param _ - unused but mandatory. | ||
*/ | ||
export function deposit(_: StaticArray<u8>): void { | ||
const amount = Context.transferredCoins(); | ||
assert(amount > 0, 'Payment must be more than 0 MAS'); | ||
const recipient = Context.caller(); | ||
|
||
const args = new Args().add(recipient).add(u256.fromU64(amount)).serialize(); | ||
_mint(args); | ||
} | ||
|
||
/** | ||
* Unwrap wanted value. | ||
* | ||
* @param bs - serialized StaticArray<u8> containing | ||
* - the amount to withdraw (u64) | ||
* - the recipient's account (String). | ||
*/ | ||
export function withdraw(bs: StaticArray<u8>): void { | ||
const args = new Args(bs); | ||
const amount = args.nextU64().expect('amount is missing'); | ||
const recipient = new Address( | ||
args.nextString().expect('recipient is missing'), | ||
); | ||
|
||
assert(amount > 0, 'Payment must be more than 0 WMAS'); | ||
|
||
burn(u256ToBytes(u256.fromU64(amount))); | ||
transferCoins(recipient, amount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters