import * as $ from "@manahippo/move-to-ts"; import {AptosDataCache, AptosParserRepo, DummyCache, AptosLocalCache} from "@manahippo/move-to-ts"; import {U8, U64, U128} from "@manahippo/move-to-ts"; import {u8, u64, u128} from "@manahippo/move-to-ts"; import {TypeParamDeclType, FieldDeclType} from "@manahippo/move-to-ts"; import {AtomicTypeTag, StructTag, TypeTag, VectorTag, SimpleStructTag} from "@manahippo/move-to-ts"; import {OptionTransaction} from "@manahippo/move-to-ts"; import {HexString, AptosClient, AptosAccount, TxnBuilderTypes, Types} from "aptos"; import * as Stdlib from "../stdlib"; export const packageName = "omni-aptos-coins"; export const moduleAddress = new HexString("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344"); export const moduleName = "testnet_coins"; export class CoinCaps { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "CoinCaps"; static typeParameters: TypeParamDeclType[] = [ { name: "T", isPhantom: true } ]; static fields: FieldDeclType[] = [ { name: "mint", typeTag: new StructTag(new HexString("0x1"), "coin", "MintCapability", [new $.TypeParamIdx(0)]) }, { name: "freeze", typeTag: new StructTag(new HexString("0x1"), "coin", "FreezeCapability", [new $.TypeParamIdx(0)]) }, { name: "burn", typeTag: new StructTag(new HexString("0x1"), "coin", "BurnCapability", [new $.TypeParamIdx(0)]) }]; mint: Stdlib.Coin.MintCapability; freeze: Stdlib.Coin.FreezeCapability; burn: Stdlib.Coin.BurnCapability; constructor(proto: any, public typeTag: TypeTag) { this.mint = proto['mint'] as Stdlib.Coin.MintCapability; this.freeze = proto['freeze'] as Stdlib.Coin.FreezeCapability; this.burn = proto['burn'] as Stdlib.Coin.BurnCapability; } static CoinCapsParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : CoinCaps { const proto = $.parseStructProto(data, typeTag, repo, CoinCaps); return new CoinCaps(proto, typeTag); } static async load(repo: AptosParserRepo, client: AptosClient, address: HexString, typeParams: TypeTag[]) { const result = await repo.loadResource(client, address, CoinCaps, typeParams); return result as unknown as CoinCaps; } static async loadByApp(app: $.AppType, address: HexString, typeParams: TypeTag[]) { const result = await app.repo.loadResource(app.client, address, CoinCaps, typeParams); await result.loadFullState(app) return result as unknown as CoinCaps; } static makeTag($p: TypeTag[]): StructTag { return new StructTag(moduleAddress, moduleName, "CoinCaps", $p); } async loadFullState(app: $.AppType) { await this.mint.loadFullState(app); await this.freeze.loadFullState(app); await this.burn.loadFullState(app); this.__app = app; } } export class TestBNB { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestBNB"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestBNBParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestBNB { const proto = $.parseStructProto(data, typeTag, repo, TestBNB); return new TestBNB(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestBNB", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestBTC { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestBTC"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestBTCParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestBTC { const proto = $.parseStructProto(data, typeTag, repo, TestBTC); return new TestBTC(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestBTC", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestDAI { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestDAI"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestDAIParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestDAI { const proto = $.parseStructProto(data, typeTag, repo, TestDAI); return new TestDAI(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestDAI", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestETH { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestETH"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestETHParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestETH { const proto = $.parseStructProto(data, typeTag, repo, TestETH); return new TestETH(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestETH", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestSOL { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestSOL"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestSOLParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestSOL { const proto = $.parseStructProto(data, typeTag, repo, TestSOL); return new TestSOL(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestSOL", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestUSDC { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestUSDC"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestUSDCParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestUSDC { const proto = $.parseStructProto(data, typeTag, repo, TestUSDC); return new TestUSDC(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestUSDC", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export class TestUSDT { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "TestUSDT"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ ]; constructor(proto: any, public typeTag: TypeTag) { } static TestUSDTParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : TestUSDT { const proto = $.parseStructProto(data, typeTag, repo, TestUSDT); return new TestUSDT(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "TestUSDT", []); } async loadFullState(app: $.AppType) { this.__app = app; } } export function burn_ ( tokens: Stdlib.Coin.Coin, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let temp$1, addr, amt, cap; temp$1 = Stdlib.Type_info.type_of_($c, [$p[0]]); addr = Stdlib.Type_info.account_address_(temp$1, $c); cap = $c.borrow_global(new SimpleStructTag(CoinCaps, [$p[0]]), $.copy(addr)); amt = Stdlib.Coin.value_(tokens, $c, [$p[0]]); if (($.copy(amt)).eq((u64("0")))) { Stdlib.Coin.destroy_zero_(tokens, $c, [$p[0]]); } else{ Stdlib.Coin.burn_(tokens, cap.burn, $c, [$p[0]]); } return; } export function deploy_ ( admin: HexString, $c: AptosDataCache, ): void { init_coin_and_register_(admin, Stdlib.String.utf8_([u8("66"), u8("105"), u8("116"), u8("99"), u8("111"), u8("105"), u8("110")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("66"), u8("84"), u8("67")], $c), u8("8"), $c, [new SimpleStructTag(TestBTC)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("66"), u8("78"), u8("66")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("66"), u8("78"), u8("66")], $c), u8("8"), $c, [new SimpleStructTag(TestBNB)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("69"), u8("116"), u8("104"), u8("101"), u8("114"), u8("101"), u8("117"), u8("109")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("69"), u8("84"), u8("72")], $c), u8("8"), $c, [new SimpleStructTag(TestETH)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("83"), u8("111"), u8("108"), u8("97"), u8("110"), u8("97")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("83"), u8("79"), u8("76")], $c), u8("8"), $c, [new SimpleStructTag(TestSOL)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("85"), u8("83"), u8("68"), u8("32"), u8("67"), u8("111"), u8("105"), u8("110")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("85"), u8("83"), u8("68"), u8("67")], $c), u8("8"), $c, [new SimpleStructTag(TestUSDC)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("84"), u8("101"), u8("116"), u8("104"), u8("101"), u8("114")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("85"), u8("83"), u8("68"), u8("84")], $c), u8("8"), $c, [new SimpleStructTag(TestUSDT)]); init_coin_and_register_(admin, Stdlib.String.utf8_([u8("68"), u8("65"), u8("73")], $c), Stdlib.String.utf8_([u8("116"), u8("101"), u8("115"), u8("116"), u8("68"), u8("65"), u8("73")], $c), u8("8"), $c, [new SimpleStructTag(TestDAI)]); return; } export function buildPayload_deploy ( isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { const typeParamStrings = [] as string[]; return $.buildPayload( new HexString("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344"), "testnet_coins", "deploy", typeParamStrings, [], isJSON, ); } export function deposit_ ( user: HexString, coin: Stdlib.Coin.Coin, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { if (!Stdlib.Coin.is_account_registered_(Stdlib.Signer.address_of_(user, $c), $c, [$p[0]])) { Stdlib.Coin.register_(user, $c, [$p[0]]); } else{ } Stdlib.Coin.deposit_(Stdlib.Signer.address_of_(user, $c), coin, $c, [$p[0]]); return; } export function init_coin_ ( admin: HexString, name: U8[], symbol: U8[], decimals: U8, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let burn, freeze, mint; if (!Stdlib.Coin.is_coin_initialized_($c, [$p[0]])) { [burn, freeze, mint] = Stdlib.Coin.initialize_(admin, Stdlib.String.utf8_($.copy(name), $c), Stdlib.String.utf8_($.copy(symbol), $c), $.copy(decimals), false, $c, [$p[0]]); $c.move_to(new SimpleStructTag(CoinCaps, [$p[0]]), admin, new CoinCaps({ mint: $.copy(mint), freeze: $.copy(freeze), burn: $.copy(burn) }, new SimpleStructTag(CoinCaps, [$p[0]]))); } else{ } return; } export function buildPayload_init_coin ( name: U8[], symbol: U8[], decimals: U8, $p: TypeTag[], /* */ isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { const typeParamStrings = $p.map(t=>$.getTypeTagFullname(t)); return $.buildPayload( new HexString("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344"), "testnet_coins", "init_coin", typeParamStrings, [ name, symbol, decimals, ], isJSON, ); } export function init_coin_and_register_ ( admin: HexString, name: Stdlib.String.String, symbol: Stdlib.String.String, decimals: U8, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { init_coin_(admin, $.copy(Stdlib.String.bytes_(name, $c)), $.copy(Stdlib.String.bytes_(symbol, $c)), $.copy(decimals), $c, [$p[0]]); return; } export function initialize_ ( admin: HexString, decimals: U8, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let temp$1, name; temp$1 = Stdlib.Type_info.type_of_($c, [$p[0]]); name = Stdlib.Type_info.struct_name_(temp$1, $c); return init_coin_(admin, $.copy(name), $.copy(name), $.copy(decimals), $c, [$p[0]]); } export function mint_ ( amount: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): Stdlib.Coin.Coin { let caps; caps = $c.borrow_global(new SimpleStructTag(CoinCaps, [$p[0]]), new HexString("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344")); return Stdlib.Coin.mint_($.copy(amount), caps.mint, $c, [$p[0]]); } export function mint_to_wallet_ ( user: HexString, amount: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let coin; coin = mint_($.copy(amount), $c, [$p[0]]); if (!Stdlib.Coin.is_account_registered_(Stdlib.Signer.address_of_(user, $c), $c, [$p[0]])) { Stdlib.Coin.register_(user, $c, [$p[0]]); } else{ } Stdlib.Coin.deposit_(Stdlib.Signer.address_of_(user, $c), coin, $c, [$p[0]]); return; } export function buildPayload_mint_to_wallet ( amount: U64, $p: TypeTag[], /* */ isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { const typeParamStrings = $p.map(t=>$.getTypeTagFullname(t)); return $.buildPayload( new HexString("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344"), "testnet_coins", "mint_to_wallet", typeParamStrings, [ amount, ], isJSON, ); } export function loadParsers(repo: AptosParserRepo) { repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::CoinCaps", CoinCaps.CoinCapsParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestBNB", TestBNB.TestBNBParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestBTC", TestBTC.TestBTCParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestDAI", TestDAI.TestDAIParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestETH", TestETH.TestETHParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestSOL", TestSOL.TestSOLParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestUSDC", TestUSDC.TestUSDCParser); repo.addParser("0xcb0b45f3b49a6ab957facd2029ee0cd6720bb12907877d2f499946a7fd8f8344::testnet_coins::TestUSDT", TestUSDT.TestUSDTParser); } export class App { constructor( public client: AptosClient, public repo: AptosParserRepo, public cache: AptosLocalCache, ) { } get moduleAddress() {{ return moduleAddress; }} get moduleName() {{ return moduleName; }} get CoinCaps() { return CoinCaps; } async loadCoinCaps( owner: HexString, $p: TypeTag[], /* */ loadFull=true, fillCache=true, ) { const val = await CoinCaps.load(this.repo, this.client, owner, $p); if (loadFull) { await val.loadFullState(this); } if (fillCache) { this.cache.set(val.typeTag, owner, val); } return val; } get TestBNB() { return TestBNB; } get TestBTC() { return TestBTC; } get TestDAI() { return TestDAI; } get TestETH() { return TestETH; } get TestSOL() { return TestSOL; } get TestUSDC() { return TestUSDC; } get TestUSDT() { return TestUSDT; } payload_deploy( isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { return buildPayload_deploy(isJSON); } async deploy( _account: AptosAccount, option?: OptionTransaction, _isJSON = false ) { const payload__ = buildPayload_deploy(_isJSON); return $.sendPayloadTx(this.client, _account, payload__, option); } payload_init_coin( name: U8[], symbol: U8[], decimals: U8, $p: TypeTag[], /* */ isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { return buildPayload_init_coin(name, symbol, decimals, $p, isJSON); } async init_coin( _account: AptosAccount, name: U8[], symbol: U8[], decimals: U8, $p: TypeTag[], /* */ option?: OptionTransaction, _isJSON = false ) { const payload__ = buildPayload_init_coin(name, symbol, decimals, $p, _isJSON); return $.sendPayloadTx(this.client, _account, payload__, option); } payload_mint_to_wallet( amount: U64, $p: TypeTag[], /* */ isJSON = false, ): TxnBuilderTypes.TransactionPayloadEntryFunction | Types.TransactionPayload_EntryFunctionPayload { return buildPayload_mint_to_wallet(amount, $p, isJSON); } async mint_to_wallet( _account: AptosAccount, amount: U64, $p: TypeTag[], /* */ option?: OptionTransaction, _isJSON = false ) { const payload__ = buildPayload_mint_to_wallet(amount, $p, _isJSON); return $.sendPayloadTx(this.client, _account, payload__, option); } }