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 = "swap"; export const moduleAddress = new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"); export const moduleName = "event"; export class AddedEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "AddedEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "coin_x", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "coin_y", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "x_val", typeTag: AtomicTypeTag.U64 }, { name: "y_val", typeTag: AtomicTypeTag.U64 }, { name: "lp_tokens", typeTag: AtomicTypeTag.U64 }]; coin_x: Stdlib.String.String; coin_y: Stdlib.String.String; x_val: U64; y_val: U64; lp_tokens: U64; constructor(proto: any, public typeTag: TypeTag) { this.coin_x = proto['coin_x'] as Stdlib.String.String; this.coin_y = proto['coin_y'] as Stdlib.String.String; this.x_val = proto['x_val'] as U64; this.y_val = proto['y_val'] as U64; this.lp_tokens = proto['lp_tokens'] as U64; } static AddedEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : AddedEvent { const proto = $.parseStructProto(data, typeTag, repo, AddedEvent); return new AddedEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "AddedEvent", []); } async loadFullState(app: $.AppType) { await this.coin_x.loadFullState(app); await this.coin_y.loadFullState(app); this.__app = app; } } export class CreatedEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "CreatedEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "creator", typeTag: AtomicTypeTag.Address }, { name: "coin_x", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "coin_y", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }]; creator: HexString; coin_x: Stdlib.String.String; coin_y: Stdlib.String.String; constructor(proto: any, public typeTag: TypeTag) { this.creator = proto['creator'] as HexString; this.coin_x = proto['coin_x'] as Stdlib.String.String; this.coin_y = proto['coin_y'] as Stdlib.String.String; } static CreatedEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : CreatedEvent { const proto = $.parseStructProto(data, typeTag, repo, CreatedEvent); return new CreatedEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "CreatedEvent", []); } async loadFullState(app: $.AppType) { await this.coin_x.loadFullState(app); await this.coin_y.loadFullState(app); this.__app = app; } } export class EventsStore { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "EventsStore"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "created_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "CreatedEvent", [])]) }, { name: "removed_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "RemovedEvent", [])]) }, { name: "added_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "AddedEvent", [])]) }, { name: "swapped_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "SwappedEvent", [])]) }, { name: "oracle_updated_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "OracleUpdatedEvent", [])]) }, { name: "withdrew_handle", typeTag: new StructTag(new HexString("0x1"), "event", "EventHandle", [new StructTag(new HexString("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41"), "event", "WithdrewEvent", [])]) }]; created_handle: Stdlib.Event.EventHandle; removed_handle: Stdlib.Event.EventHandle; added_handle: Stdlib.Event.EventHandle; swapped_handle: Stdlib.Event.EventHandle; oracle_updated_handle: Stdlib.Event.EventHandle; withdrew_handle: Stdlib.Event.EventHandle; constructor(proto: any, public typeTag: TypeTag) { this.created_handle = proto['created_handle'] as Stdlib.Event.EventHandle; this.removed_handle = proto['removed_handle'] as Stdlib.Event.EventHandle; this.added_handle = proto['added_handle'] as Stdlib.Event.EventHandle; this.swapped_handle = proto['swapped_handle'] as Stdlib.Event.EventHandle; this.oracle_updated_handle = proto['oracle_updated_handle'] as Stdlib.Event.EventHandle; this.withdrew_handle = proto['withdrew_handle'] as Stdlib.Event.EventHandle; } static EventsStoreParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : EventsStore { const proto = $.parseStructProto(data, typeTag, repo, EventsStore); return new EventsStore(proto, typeTag); } static async load(repo: AptosParserRepo, client: AptosClient, address: HexString, typeParams: TypeTag[]) { const result = await repo.loadResource(client, address, EventsStore, typeParams); return result as unknown as EventsStore; } static async loadByApp(app: $.AppType, address: HexString, typeParams: TypeTag[]) { const result = await app.repo.loadResource(app.client, address, EventsStore, typeParams); await result.loadFullState(app) return result as unknown as EventsStore; } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "EventsStore", []); } async loadFullState(app: $.AppType) { await this.created_handle.loadFullState(app); await this.removed_handle.loadFullState(app); await this.added_handle.loadFullState(app); await this.swapped_handle.loadFullState(app); await this.oracle_updated_handle.loadFullState(app); await this.withdrew_handle.loadFullState(app); this.__app = app; } } export class OracleUpdatedEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "OracleUpdatedEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "coin_x", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "coin_y", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "x_cumulative", typeTag: AtomicTypeTag.U128 }, { name: "y_cumulative", typeTag: AtomicTypeTag.U128 }]; coin_x: Stdlib.String.String; coin_y: Stdlib.String.String; x_cumulative: U128; y_cumulative: U128; constructor(proto: any, public typeTag: TypeTag) { this.coin_x = proto['coin_x'] as Stdlib.String.String; this.coin_y = proto['coin_y'] as Stdlib.String.String; this.x_cumulative = proto['x_cumulative'] as U128; this.y_cumulative = proto['y_cumulative'] as U128; } static OracleUpdatedEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : OracleUpdatedEvent { const proto = $.parseStructProto(data, typeTag, repo, OracleUpdatedEvent); return new OracleUpdatedEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "OracleUpdatedEvent", []); } async loadFullState(app: $.AppType) { await this.coin_x.loadFullState(app); await this.coin_y.loadFullState(app); this.__app = app; } } export class RemovedEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "RemovedEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "coin_x", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "coin_y", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "x_val", typeTag: AtomicTypeTag.U64 }, { name: "y_val", typeTag: AtomicTypeTag.U64 }, { name: "lp_tokens", typeTag: AtomicTypeTag.U64 }]; coin_x: Stdlib.String.String; coin_y: Stdlib.String.String; x_val: U64; y_val: U64; lp_tokens: U64; constructor(proto: any, public typeTag: TypeTag) { this.coin_x = proto['coin_x'] as Stdlib.String.String; this.coin_y = proto['coin_y'] as Stdlib.String.String; this.x_val = proto['x_val'] as U64; this.y_val = proto['y_val'] as U64; this.lp_tokens = proto['lp_tokens'] as U64; } static RemovedEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : RemovedEvent { const proto = $.parseStructProto(data, typeTag, repo, RemovedEvent); return new RemovedEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "RemovedEvent", []); } async loadFullState(app: $.AppType) { await this.coin_x.loadFullState(app); await this.coin_y.loadFullState(app); this.__app = app; } } export class SwappedEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "SwappedEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "coin_x", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "coin_y", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "x_in", typeTag: AtomicTypeTag.U64 }, { name: "x_out", typeTag: AtomicTypeTag.U64 }, { name: "y_in", typeTag: AtomicTypeTag.U64 }, { name: "y_out", typeTag: AtomicTypeTag.U64 }]; coin_x: Stdlib.String.String; coin_y: Stdlib.String.String; x_in: U64; x_out: U64; y_in: U64; y_out: U64; constructor(proto: any, public typeTag: TypeTag) { this.coin_x = proto['coin_x'] as Stdlib.String.String; this.coin_y = proto['coin_y'] as Stdlib.String.String; this.x_in = proto['x_in'] as U64; this.x_out = proto['x_out'] as U64; this.y_in = proto['y_in'] as U64; this.y_out = proto['y_out'] as U64; } static SwappedEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : SwappedEvent { const proto = $.parseStructProto(data, typeTag, repo, SwappedEvent); return new SwappedEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "SwappedEvent", []); } async loadFullState(app: $.AppType) { await this.coin_x.loadFullState(app); await this.coin_y.loadFullState(app); this.__app = app; } } export class WithdrewEvent { static moduleAddress = moduleAddress; static moduleName = moduleName; __app: $.AppType | null = null; static structName: string = "WithdrewEvent"; static typeParameters: TypeParamDeclType[] = [ ]; static fields: FieldDeclType[] = [ { name: "coin", typeTag: new StructTag(new HexString("0x1"), "string", "String", []) }, { name: "fee", typeTag: AtomicTypeTag.U64 }]; coin: Stdlib.String.String; fee: U64; constructor(proto: any, public typeTag: TypeTag) { this.coin = proto['coin'] as Stdlib.String.String; this.fee = proto['fee'] as U64; } static WithdrewEventParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : WithdrewEvent { const proto = $.parseStructProto(data, typeTag, repo, WithdrewEvent); return new WithdrewEvent(proto, typeTag); } static getTag(): StructTag { return new StructTag(moduleAddress, moduleName, "WithdrewEvent", []); } async loadFullState(app: $.AppType) { await this.coin.loadFullState(app); this.__app = app; } } export function added_event_ ( pool_address: HexString, x_val: U64, y_val: U64, lp_tokens: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.added_handle, new AddedEvent({ coin_x: Stdlib.Type_info.type_name_($c, [$p[0]]), coin_y: Stdlib.Type_info.type_name_($c, [$p[1]]), x_val: $.copy(x_val), y_val: $.copy(y_val), lp_tokens: $.copy(lp_tokens) }, new SimpleStructTag(AddedEvent)), $c, [new SimpleStructTag(AddedEvent)]); } export function created_event_ ( pool_address: HexString, creator: HexString, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.created_handle, new CreatedEvent({ creator: $.copy(creator), coin_x: Stdlib.Type_info.type_name_($c, [$p[0]]), coin_y: Stdlib.Type_info.type_name_($c, [$p[1]]) }, new SimpleStructTag(CreatedEvent)), $c, [new SimpleStructTag(CreatedEvent)]); } export function initialize_ ( pool_account: HexString, $c: AptosDataCache, ): void { let events_store; events_store = new EventsStore({ created_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(CreatedEvent)]), removed_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(RemovedEvent)]), added_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(AddedEvent)]), swapped_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(SwappedEvent)]), oracle_updated_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(OracleUpdatedEvent)]), withdrew_handle: Stdlib.Account.new_event_handle_(pool_account, $c, [new SimpleStructTag(WithdrewEvent)]) }, new SimpleStructTag(EventsStore)); $c.move_to(new SimpleStructTag(EventsStore), pool_account, events_store); return; } export function removed_event_ ( pool_address: HexString, x_val: U64, y_val: U64, lp_tokens: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.removed_handle, new RemovedEvent({ coin_x: Stdlib.Type_info.type_name_($c, [$p[0]]), coin_y: Stdlib.Type_info.type_name_($c, [$p[1]]), x_val: $.copy(x_val), y_val: $.copy(y_val), lp_tokens: $.copy(lp_tokens) }, new SimpleStructTag(RemovedEvent)), $c, [new SimpleStructTag(RemovedEvent)]); } export function swapped_event_ ( pool_address: HexString, x_in: U64, x_out: U64, y_in: U64, y_out: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.swapped_handle, new SwappedEvent({ coin_x: Stdlib.Type_info.type_name_($c, [$p[0]]), coin_y: Stdlib.Type_info.type_name_($c, [$p[1]]), x_in: $.copy(x_in), x_out: $.copy(x_out), y_in: $.copy(y_in), y_out: $.copy(y_out) }, new SimpleStructTag(SwappedEvent)), $c, [new SimpleStructTag(SwappedEvent)]); } export function update_oracle_event_ ( pool_address: HexString, x_cumulative: U128, y_cumulative: U128, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.oracle_updated_handle, new OracleUpdatedEvent({ coin_x: Stdlib.Type_info.type_name_($c, [$p[0]]), coin_y: Stdlib.Type_info.type_name_($c, [$p[1]]), x_cumulative: $.copy(x_cumulative), y_cumulative: $.copy(y_cumulative) }, new SimpleStructTag(OracleUpdatedEvent)), $c, [new SimpleStructTag(OracleUpdatedEvent)]); } export function withdrew_event_ ( pool_address: HexString, fee: U64, $c: AptosDataCache, $p: TypeTag[], /* */ ): void { let event_store; event_store = $c.borrow_global_mut(new SimpleStructTag(EventsStore), $.copy(pool_address)); return Stdlib.Event.emit_event_(event_store.withdrew_handle, new WithdrewEvent({ coin: Stdlib.Type_info.type_name_($c, [$p[0]]), fee: $.copy(fee) }, new SimpleStructTag(WithdrewEvent)), $c, [new SimpleStructTag(WithdrewEvent)]); } export function loadParsers(repo: AptosParserRepo) { repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::AddedEvent", AddedEvent.AddedEventParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::CreatedEvent", CreatedEvent.CreatedEventParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::EventsStore", EventsStore.EventsStoreParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::OracleUpdatedEvent", OracleUpdatedEvent.OracleUpdatedEventParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::RemovedEvent", RemovedEvent.RemovedEventParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::SwappedEvent", SwappedEvent.SwappedEventParser); repo.addParser("0x870723e9a8f6d07c350e79d63655de673fb24d0695c702f479c201ab7b055f41::event::WithdrewEvent", WithdrewEvent.WithdrewEventParser); } export class App { constructor( public client: AptosClient, public repo: AptosParserRepo, public cache: AptosLocalCache, ) { } get moduleAddress() {{ return moduleAddress; }} get moduleName() {{ return moduleName; }} get AddedEvent() { return AddedEvent; } get CreatedEvent() { return CreatedEvent; } get EventsStore() { return EventsStore; } async loadEventsStore( owner: HexString, loadFull=true, fillCache=true, ) { const val = await EventsStore.load(this.repo, this.client, owner, [] as TypeTag[]); if (loadFull) { await val.loadFullState(this); } if (fillCache) { this.cache.set(val.typeTag, owner, val); } return val; } get OracleUpdatedEvent() { return OracleUpdatedEvent; } get RemovedEvent() { return RemovedEvent; } get SwappedEvent() { return SwappedEvent; } get WithdrewEvent() { return WithdrewEvent; } }