Skip to content

Commit 66e5f18

Browse files
authored
Initial version of contract manager sdk (#943)
* Initial version of governance sdk * Add more functionality to Sui contract manager and migrate variable naming to camelCase * Refactor sui functions * Add prettier * Add SuiAuthorizeUpgradeContractInstruction for governance * Update cosmwasm deploy tools entry point and expose some classes * Remove console.logs from CosmWasm * Refactor storage logic and add sui docs * Use relative path for default path of store * More documentation and minor fixes * Rename package * Add EVM classes * Implement getters for data sources * Use Google naming convention for abbreviations More info here: https://google.github.io/styleguide/tsguide.html#identifiers-abbreviations * Change package license * More comments and documentation * Store code proxy function in CosmWasm
1 parent a77ee78 commit 66e5f18

39 files changed

+1645
-17
lines changed

contract_manager/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@pythnetwork/pyth-contract-manager",
3+
"version": "1.0.0",
4+
"description": "Set of tools to manage pyth contracts",
5+
"private": true,
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"shell": "ts-node ./src/shell.ts"
10+
},
11+
"author": "",
12+
"license": "Apache-2.0",
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/pyth-network/pyth-crosschain.git"
16+
},
17+
"dependencies": {
18+
"@pythnetwork/cosmwasm-deploy-tools": "*",
19+
"@pythnetwork/price-service-client": "*",
20+
"@pythnetwork/xc-governance-sdk": "*",
21+
"@certusone/wormhole-sdk": "^0.9.8",
22+
"ts-node": "^10.9.1",
23+
"typescript": "^4.9.3"
24+
},
25+
"devDependencies": {
26+
"prettier": "^2.6.2"
27+
}
28+
}

contract_manager/src/base.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { DataSource, HexString32Bytes } from "@pythnetwork/xc-governance-sdk";
2+
3+
export abstract class Storable {
4+
/**
5+
* Returns the unique identifier for this object
6+
*/
7+
abstract getId(): string;
8+
9+
/**
10+
* Returns the type of this object. This is used to reconstruct the object and should match
11+
* the static field type in the class responsible for constructing this object.
12+
*/
13+
abstract getType(): string;
14+
15+
/**
16+
* Returns a JSON representation of this object. It should be possible to
17+
* reconstruct the object from the JSON using the fromJson method.
18+
*/
19+
abstract toJson(): any;
20+
}
21+
22+
export abstract class Contract extends Storable {
23+
/**
24+
* Returns the time period in seconds that stale data is considered valid for.
25+
*/
26+
abstract getValidTimePeriod(): Promise<number>;
27+
28+
/**
29+
* Returns an array of data sources that this contract accepts price feed messages from
30+
*/
31+
abstract getDataSources(): Promise<DataSource[]>;
32+
33+
/**
34+
* Returns the single data source that this contract accepts governance messages from
35+
*/
36+
abstract getGovernanceDataSource(): Promise<DataSource>;
37+
}

contract_manager/src/chains.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { readdirSync, readFileSync, writeFileSync } from "fs";
2+
import { Storable } from "./base";
3+
4+
export abstract class Chain extends Storable {
5+
protected constructor(public id: string) {
6+
super();
7+
}
8+
9+
getId(): string {
10+
return this.id;
11+
}
12+
}
13+
14+
export class CosmWasmChain extends Chain {
15+
static type: string = "CosmWasmChain";
16+
17+
constructor(
18+
id: string,
19+
public querierEndpoint: string,
20+
public executorEndpoint: string,
21+
public gasPrice: string,
22+
public prefix: string,
23+
public feeDenom: string
24+
) {
25+
super(id);
26+
}
27+
28+
static fromJson(parsed: any): CosmWasmChain {
29+
if (parsed.type !== CosmWasmChain.type) throw new Error("Invalid type");
30+
return new CosmWasmChain(
31+
parsed.id,
32+
parsed.querierEndpoint,
33+
parsed.executorEndpoint,
34+
parsed.gasPrice,
35+
parsed.prefix,
36+
parsed.feeDenom
37+
);
38+
}
39+
40+
toJson(): any {
41+
return {
42+
querierEndpoint: this.querierEndpoint,
43+
executorEndpoint: this.executorEndpoint,
44+
id: this.id,
45+
gasPrice: this.gasPrice,
46+
prefix: this.prefix,
47+
feeDenom: this.feeDenom,
48+
type: CosmWasmChain.type,
49+
};
50+
}
51+
52+
getType(): string {
53+
return CosmWasmChain.type;
54+
}
55+
}
56+
57+
export class SuiChain extends Chain {
58+
static type: string = "SuiChain";
59+
60+
constructor(id: string, public rpcUrl: string) {
61+
super(id);
62+
}
63+
64+
static fromJson(parsed: any): SuiChain {
65+
if (parsed.type !== SuiChain.type) throw new Error("Invalid type");
66+
return new SuiChain(parsed.id, parsed.rpcUrl);
67+
}
68+
69+
toJson(): any {
70+
return {
71+
id: this.id,
72+
rpcUrl: this.rpcUrl,
73+
type: SuiChain.type,
74+
};
75+
}
76+
77+
getType(): string {
78+
return SuiChain.type;
79+
}
80+
}
81+
82+
export class EVMChain extends Chain {
83+
static type: string = "EVMChain";
84+
85+
constructor(id: string, public rpcUrl: string) {
86+
super(id);
87+
}
88+
89+
static fromJson(parsed: any): SuiChain {
90+
if (parsed.type !== EVMChain.type) throw new Error("Invalid type");
91+
return new EVMChain(parsed.id, parsed.rpcUrl);
92+
}
93+
94+
toJson(): any {
95+
return {
96+
id: this.id,
97+
rpcUrl: this.rpcUrl,
98+
type: EVMChain.type,
99+
};
100+
}
101+
102+
getType(): string {
103+
return EVMChain.type;
104+
}
105+
}
106+
107+
export const Chains: Record<string, Chain> = {};

0 commit comments

Comments
 (0)