Skip to content

Commit

Permalink
add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lyl committed Sep 5, 2022
1 parent 3e45417 commit 5c9f580
Show file tree
Hide file tree
Showing 73 changed files with 20,215 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build/
build/
cli/dist
cli/node_modules
35 changes: 35 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

{
"name": "package.json",
"version": "0.0.1",
"scripts": {
"build": "rm -rf dist; tsc -p tsconfig.json",
"cli": "node dist/cli.js",

"test": "jest"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [ "src", "dist" ],
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.31",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.4"
},
"dependencies": {
"aptos": "^1.3.7",
"big-integer": "^1.6.51",
"commander": "^9.3.0",
"yaml": "^2.1.1",

"@manahippo/move-to-ts": "^0.1.28"
}
}
232 changes: 232 additions & 0 deletions cli/src/cetus_amm/amm_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
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 {HexString, AptosClient, AptosAccount} from "aptos";
import * as Stdlib from "../stdlib";
export const packageName = "Cetue-AMM";
export const moduleAddress = new HexString("0x23f2032cdea2fd00e53834a1e6c488b9ee7dac3e5591a4ea30646e4ff1afc219");
export const moduleName = "amm_config";

export const ENOT_HAS_PRIVILEGE : U64 = u64("1001");
export const EPOOL_PAUSE : U64 = u64("1002");


export class PoolFeeConfig
{
static moduleAddress = moduleAddress;
static moduleName = moduleName;
__app: $.AppType | null = null;
static structName: string = "PoolFeeConfig";
static typeParameters: TypeParamDeclType[] = [

];
static fields: FieldDeclType[] = [
{ name: "trade_fee_numerator", typeTag: AtomicTypeTag.U64 },
{ name: "trade_fee_denominator", typeTag: AtomicTypeTag.U64 },
{ name: "protocol_fee_numerator", typeTag: AtomicTypeTag.U64 },
{ name: "protocol_fee_denominator", typeTag: AtomicTypeTag.U64 }];

trade_fee_numerator: U64;
trade_fee_denominator: U64;
protocol_fee_numerator: U64;
protocol_fee_denominator: U64;

constructor(proto: any, public typeTag: TypeTag) {
this.trade_fee_numerator = proto['trade_fee_numerator'] as U64;
this.trade_fee_denominator = proto['trade_fee_denominator'] as U64;
this.protocol_fee_numerator = proto['protocol_fee_numerator'] as U64;
this.protocol_fee_denominator = proto['protocol_fee_denominator'] as U64;
}

static PoolFeeConfigParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : PoolFeeConfig {
const proto = $.parseStructProto(data, typeTag, repo, PoolFeeConfig);
return new PoolFeeConfig(proto, typeTag);
}

static async load(repo: AptosParserRepo, client: AptosClient, address: HexString, typeParams: TypeTag[]) {
const result = await repo.loadResource(client, address, PoolFeeConfig, typeParams);
return result as unknown as PoolFeeConfig;
}
static async loadByApp(app: $.AppType, address: HexString, typeParams: TypeTag[]) {
const result = await app.repo.loadResource(app.client, address, PoolFeeConfig, typeParams);
await result.loadFullState(app)
return result as unknown as PoolFeeConfig;
}
static getTag(): StructTag {
return new StructTag(moduleAddress, moduleName, "PoolFeeConfig", []);
}
async loadFullState(app: $.AppType) {
this.__app = app;
}

}

export class PoolPauseStatus
{
static moduleAddress = moduleAddress;
static moduleName = moduleName;
__app: $.AppType | null = null;
static structName: string = "PoolPauseStatus";
static typeParameters: TypeParamDeclType[] = [

];
static fields: FieldDeclType[] = [
{ name: "pause", typeTag: AtomicTypeTag.Bool }];

pause: boolean;

constructor(proto: any, public typeTag: TypeTag) {
this.pause = proto['pause'] as boolean;
}

static PoolPauseStatusParser(data:any, typeTag: TypeTag, repo: AptosParserRepo) : PoolPauseStatus {
const proto = $.parseStructProto(data, typeTag, repo, PoolPauseStatus);
return new PoolPauseStatus(proto, typeTag);
}

static async load(repo: AptosParserRepo, client: AptosClient, address: HexString, typeParams: TypeTag[]) {
const result = await repo.loadResource(client, address, PoolPauseStatus, typeParams);
return result as unknown as PoolPauseStatus;
}
static async loadByApp(app: $.AppType, address: HexString, typeParams: TypeTag[]) {
const result = await app.repo.loadResource(app.client, address, PoolPauseStatus, typeParams);
await result.loadFullState(app)
return result as unknown as PoolPauseStatus;
}
static getTag(): StructTag {
return new StructTag(moduleAddress, moduleName, "PoolPauseStatus", []);
}
async loadFullState(app: $.AppType) {
this.__app = app;
}

}
export function admin_address_ (
$c: AptosDataCache,
): HexString {
return new HexString("0x23f2032cdea2fd00e53834a1e6c488b9ee7dac3e5591a4ea30646e4ff1afc219");
}

export function assert_admin_ (
account: HexString,
$c: AptosDataCache,
): void {
if (!((Stdlib.Signer.address_of_(account, $c)).hex() === (admin_address_($c)).hex())) {
throw $.abortCode(Stdlib.Error.permission_denied_($.copy(ENOT_HAS_PRIVILEGE), $c));
}
return;
}

export function assert_pause_ (
$c: AptosDataCache,
): void {
if (!!get_pool_pause_($c)) {
throw $.abortCode(Stdlib.Error.unavailable_($.copy(EPOOL_PAUSE), $c));
}
return;
}

export function get_pool_pause_ (
$c: AptosDataCache,
): boolean {
return $.copy($c.borrow_global<PoolPauseStatus>(new SimpleStructTag(PoolPauseStatus), admin_address_($c)).pause);
}

export function get_protocol_fee_ (
$c: AptosDataCache,
): [U64, U64] {
let fee_config;
fee_config = $c.borrow_global<PoolFeeConfig>(new SimpleStructTag(PoolFeeConfig), admin_address_($c));
return [$.copy(fee_config.protocol_fee_numerator), $.copy(fee_config.protocol_fee_denominator)];
}

export function get_trade_fee_ (
$c: AptosDataCache,
): [U64, U64] {
let fee_config;
fee_config = $c.borrow_global<PoolFeeConfig>(new SimpleStructTag(PoolFeeConfig), admin_address_($c));
return [$.copy(fee_config.trade_fee_numerator), $.copy(fee_config.trade_fee_denominator)];
}

export function set_pool_fee_config_ (
account: HexString,
trade_fee_numerator: U64,
trade_fee_denominator: U64,
protocol_fee_numerator: U64,
protocol_fee_denominator: U64,
$c: AptosDataCache,
): void {
let addr, fee_config;
assert_admin_(account, $c);
addr = Stdlib.Signer.address_of_(account, $c);
if (!$c.exists(new SimpleStructTag(PoolFeeConfig), $.copy(addr))) {
$c.move_to(new SimpleStructTag(PoolFeeConfig), account, new PoolFeeConfig({ trade_fee_numerator: $.copy(trade_fee_numerator), trade_fee_denominator: $.copy(trade_fee_denominator), protocol_fee_numerator: $.copy(protocol_fee_numerator), protocol_fee_denominator: $.copy(protocol_fee_denominator) }, new SimpleStructTag(PoolFeeConfig)));
}
else{
fee_config = $c.borrow_global_mut<PoolFeeConfig>(new SimpleStructTag(PoolFeeConfig), $.copy(addr));
fee_config.trade_fee_numerator = $.copy(trade_fee_numerator);
fee_config.trade_fee_denominator = $.copy(trade_fee_denominator);
fee_config.protocol_fee_numerator = $.copy(protocol_fee_numerator);
fee_config.protocol_fee_denominator = $.copy(protocol_fee_denominator);
}
return;
}

export function set_pool_pause_ (
account: HexString,
pause: boolean,
$c: AptosDataCache,
): void {
let addr, status;
assert_admin_(account, $c);
addr = Stdlib.Signer.address_of_(account, $c);
if (!$c.exists(new SimpleStructTag(PoolPauseStatus), $.copy(addr))) {
$c.move_to(new SimpleStructTag(PoolPauseStatus), account, new PoolPauseStatus({ pause: pause }, new SimpleStructTag(PoolPauseStatus)));
}
else{
status = $c.borrow_global_mut<PoolPauseStatus>(new SimpleStructTag(PoolPauseStatus), $.copy(addr));
status.pause = pause;
}
return;
}

export function loadParsers(repo: AptosParserRepo) {
repo.addParser("0x23f2032cdea2fd00e53834a1e6c488b9ee7dac3e5591a4ea30646e4ff1afc219::amm_config::PoolFeeConfig", PoolFeeConfig.PoolFeeConfigParser);
repo.addParser("0x23f2032cdea2fd00e53834a1e6c488b9ee7dac3e5591a4ea30646e4ff1afc219::amm_config::PoolPauseStatus", PoolPauseStatus.PoolPauseStatusParser);
}
export class App {
constructor(
public client: AptosClient,
public repo: AptosParserRepo,
public cache: AptosLocalCache,
) {
}
get moduleAddress() {{ return moduleAddress; }}
get moduleName() {{ return moduleName; }}
get PoolFeeConfig() { return PoolFeeConfig; }
async loadPoolFeeConfig(
owner: HexString,
loadFull=true,
) {
const val = await PoolFeeConfig.load(this.repo, this.client, owner, [] as TypeTag[]);
if (loadFull) {
await val.loadFullState(this);
}
return val;
}
get PoolPauseStatus() { return PoolPauseStatus; }
async loadPoolPauseStatus(
owner: HexString,
loadFull=true,
) {
const val = await PoolPauseStatus.load(this.repo, this.client, owner, [] as TypeTag[]);
if (loadFull) {
await val.loadFullState(this);
}
return val;
}
}

Loading

0 comments on commit 5c9f580

Please sign in to comment.