@typus/typus-sdk 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -2
- package/.env +0 -11
- package/scripts/getSubVault.ts +0 -5
- package/scripts/sui.ts +0 -219
- package/utils/utils_rust/empty.rs +0 -0
- package/utils/utils_rust/gen_strikes.rs +0 -0
- package/utils/utils_ts/getSubVault.ts +0 -43
package/package.json
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
"name": "@typus/typus-sdk",
|
|
3
3
|
"author": "Typus",
|
|
4
4
|
"description": "typus sdk",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.3",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
6
9
|
"dependencies": {
|
|
7
10
|
"@mysten/sui.js": "^0.17.1",
|
|
8
11
|
"fetch": "^1.1.0",
|
|
@@ -11,7 +14,8 @@
|
|
|
11
14
|
"main": "index.ts",
|
|
12
15
|
"devDependencies": {},
|
|
13
16
|
"scripts": {
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
+
"build": "rm -rf lib && tsc"
|
|
15
19
|
},
|
|
16
20
|
"repository": {
|
|
17
21
|
"type": "git",
|
package/.env
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
NODE_ENV=development
|
|
2
|
-
HOSTNAME=typus-db.cwtf2o8jkdpt.ap-southeast-1.rds.amazonaws.com
|
|
3
|
-
DATABASE=postgres
|
|
4
|
-
USERNAME=postgres
|
|
5
|
-
PASSWORD=3n6z8VzIX6jKd4fGrOuh
|
|
6
|
-
CLUSTER=devnet
|
|
7
|
-
RPC_ENDPOINT=https://fullnode.devnet.sui.io:443
|
|
8
|
-
PORT=5432
|
|
9
|
-
SERVER_PORT=5432
|
|
10
|
-
PACKAGE=0xfbbdd33ab4c02e7a315e2477931bae4cbdf46381
|
|
11
|
-
VAULT_REGISTRY=0x0a9d87a1b6c00415708d2f1c62784b52f797213c
|
package/scripts/getSubVault.ts
DELETED
package/scripts/sui.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { JsonRpcProvider, Ed25519Keypair, RawSigner, SuiEventEnvelope, Network, Base64DataBuffer } from '@mysten/sui.js';
|
|
2
|
-
import { fromB64 } from '@mysten/bcs';
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import fetch from 'cross-fetch';
|
|
5
|
-
|
|
6
|
-
const { execSync } = require('child_process');
|
|
7
|
-
const rpc = new JsonRpcProvider('https://fullnode.devnet.sui.io:443');
|
|
8
|
-
const provider = new JsonRpcProvider(Network.DEVNET);//for read only operations
|
|
9
|
-
const owner = "0xd28103a499003bed0b1b9ee52988ecdd2db82224";
|
|
10
|
-
const obj1 = "0x7e9e58daeb94bbd0450bb9ee9f00e219a1f2b734";//obj owned by owner
|
|
11
|
-
const obj2 = "0x74aa838eb6627c8e74b0645484abb463e6fd6669";//obj owned by owner
|
|
12
|
-
const obj1Digest = "tclmc0L6hewmfWxQAxSl9eUe14C82+hzE4OblKgY38U=";
|
|
13
|
-
const obj2Digest = "tclmc0L6hewmfWxQAxSl9eUe14C82+hzE4OblKgY38U=";
|
|
14
|
-
const receiver = "0x15ca0895f29101085cb26e00ede89420741b3140";
|
|
15
|
-
const tx1 = "GRiBgktRqgJ4MSoRhCfSm/+1R/Zh9jy4UncoQeFAu5I="
|
|
16
|
-
// export PRIVATEKEY=~/.sui/sui_config/sui.keystore
|
|
17
|
-
const secretKeysPath = process.env.PRIVATEKEY;
|
|
18
|
-
|
|
19
|
-
const subVault = "0xd3b2d3ee74afe2b5af0f810b3368955f068188e8"
|
|
20
|
-
|
|
21
|
-
const TEST_MNEMONIC = "tackle wheat jungle viable memory dwarf swift fold purpose cattle impose horn"
|
|
22
|
-
const VALID_SECRET_KEY = "Itk7iNFs91kXKdqVqmLrBKJItNIoSyWAOh+ZC2qaSihpxiAxNYwKPjwfresk9CSbKCmwNwvXfPQoeLL4rVa4OQ=="//'mdqVWeFekT7pqy5T49+tV12jO0m+ESW7ki4zSU9JiCgbL0kJbj5dvQ/PqcDAzZLZqzshVEs01d1KZdmLh4uZIg==';
|
|
23
|
-
|
|
24
|
-
// let secretKeys = (readJsonFile<any>(secretKeysPath as string))
|
|
25
|
-
// let sender = secretKeys[0]
|
|
26
|
-
|
|
27
|
-
// let keypair = Ed25519Keypair.fromSecretKey(fromB64(sender))// Error: Wrong secretKey size. Expected 64 bytes, got 65.
|
|
28
|
-
// let keypair = Ed25519Keypair.fromSecretKey(fromB64(VALID_SECRET_KEY))
|
|
29
|
-
let keypair = Ed25519Keypair.deriveKeypair(TEST_MNEMONIC);
|
|
30
|
-
const signer = new RawSigner(keypair, provider);
|
|
31
|
-
|
|
32
|
-
function readJsonFile<T>(filePath: string): T {
|
|
33
|
-
return JSON.parse(
|
|
34
|
-
fs.readFileSync(
|
|
35
|
-
filePath,
|
|
36
|
-
"utf-8"
|
|
37
|
-
)
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// //Success
|
|
42
|
-
// (async () => {
|
|
43
|
-
// console.log("test for getObjectsOwnedByAddress()")
|
|
44
|
-
|
|
45
|
-
// const objects = await provider.getObjectsOwnedByAddress(
|
|
46
|
-
// owner
|
|
47
|
-
// )
|
|
48
|
-
// console.log(objects)
|
|
49
|
-
// })();
|
|
50
|
-
|
|
51
|
-
// //Success
|
|
52
|
-
// (async () => {
|
|
53
|
-
// console.log("test for getObjectsOwnedByObject()")
|
|
54
|
-
|
|
55
|
-
// const objects = await provider.getObjectsOwnedByObject(
|
|
56
|
-
// obj1
|
|
57
|
-
// )
|
|
58
|
-
// console.log(objects)
|
|
59
|
-
|
|
60
|
-
// //filter obj by type
|
|
61
|
-
// for (let object of objects) {
|
|
62
|
-
// if (object.type.includes("dynamic_field")) console.log("it's dynamic field object")
|
|
63
|
-
// }
|
|
64
|
-
// })();
|
|
65
|
-
|
|
66
|
-
// //Success
|
|
67
|
-
// (async () => {
|
|
68
|
-
// console.log("test for getObject() and getObjectBatch()")
|
|
69
|
-
|
|
70
|
-
// const txn = await provider.getObject(
|
|
71
|
-
// obj1
|
|
72
|
-
// );
|
|
73
|
-
// console.log(txn)
|
|
74
|
-
|
|
75
|
-
// // You can also fetch multiple objects in one batch request
|
|
76
|
-
// const txns = await provider.getObjectBatch([
|
|
77
|
-
// obj1,
|
|
78
|
-
// obj2,
|
|
79
|
-
// ]);
|
|
80
|
-
// console.log(txns)
|
|
81
|
-
// })();
|
|
82
|
-
|
|
83
|
-
// // Fail
|
|
84
|
-
// (async () => {
|
|
85
|
-
// console.log("test for getTransactionWithEffects() and getTransactionWithEffectsBatch()")
|
|
86
|
-
|
|
87
|
-
// const txn = await provider.getTransactionWithEffects(
|
|
88
|
-
// obj1Digest
|
|
89
|
-
// );
|
|
90
|
-
// console.log(txn)
|
|
91
|
-
|
|
92
|
-
// You can also fetch multiple transactions in one batch request
|
|
93
|
-
// const txns = await provider.getTransactionWithEffectsBatch([
|
|
94
|
-
// obj1Digest,
|
|
95
|
-
// obj2Digest,
|
|
96
|
-
// ]);
|
|
97
|
-
// console.log(txns)
|
|
98
|
-
// })();
|
|
99
|
-
|
|
100
|
-
// //Fail (without correct signer)
|
|
101
|
-
// (async () => {
|
|
102
|
-
// console.log("test for transferObject()")
|
|
103
|
-
// const transferTxn = await signer.transferObject({
|
|
104
|
-
// objectId: obj1,
|
|
105
|
-
// gasBudget: 1000,
|
|
106
|
-
// recipient: receiver,
|
|
107
|
-
// });
|
|
108
|
-
// console.log('transferTxn', transferTxn);
|
|
109
|
-
// })();
|
|
110
|
-
|
|
111
|
-
// //Fail (without correct signer)
|
|
112
|
-
// (async () => {
|
|
113
|
-
// console.log("test for executeMoveCall()")
|
|
114
|
-
// const moveCallTxn = await signer.executeMoveCall({
|
|
115
|
-
// packageObjectId: '0x2',
|
|
116
|
-
// module: 'devnet_nft',
|
|
117
|
-
// function: 'mint',
|
|
118
|
-
// typeArguments: [],
|
|
119
|
-
// arguments: [
|
|
120
|
-
// 'Example NFT',
|
|
121
|
-
// 'An NFT created by the wallet Command Line Tool',
|
|
122
|
-
// 'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty',
|
|
123
|
-
// ],
|
|
124
|
-
// gasBudget: 10000,
|
|
125
|
-
// });
|
|
126
|
-
// console.log('moveCallTxn', moveCallTxn);
|
|
127
|
-
// })();
|
|
128
|
-
|
|
129
|
-
// //Fail( Error subscribing to event)
|
|
130
|
-
// (async () => {
|
|
131
|
-
// console.log("test for subscribeEvent()")
|
|
132
|
-
// // calls RPC method 'sui_subscribeEvent' with params:
|
|
133
|
-
// // [ { SenderAddress: '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3' } ]
|
|
134
|
-
|
|
135
|
-
// const subscriptionId = await provider.subscribeEvent(
|
|
136
|
-
// { SenderAddress: '0xbff6ccc8707aa517b4f1b95750a2a8c666012df3' },
|
|
137
|
-
// (event: SuiEventEnvelope) => {
|
|
138
|
-
// console.log(event)
|
|
139
|
-
// // handle subscription notification message here. This function is called once per subscription message.
|
|
140
|
-
// }
|
|
141
|
-
// );
|
|
142
|
-
|
|
143
|
-
// // later, to unsubscribe
|
|
144
|
-
// // calls RPC method 'sui_unsubscribeEvent' with params: [ subscriptionId ]
|
|
145
|
-
// const subFoundAndRemoved = await provider.unsubscribeEvent(subscriptionId);
|
|
146
|
-
// })();
|
|
147
|
-
|
|
148
|
-
// //Fail (without correct signer)
|
|
149
|
-
//refer: https://docs.sui.io/build/json-rpc
|
|
150
|
-
// (async () => {
|
|
151
|
-
// console.log("test for publish()")
|
|
152
|
-
// const compiledModules = JSON.parse(
|
|
153
|
-
// execSync(
|
|
154
|
-
// `${cliPath} move build --dump-bytecode-as-base64 --path ${packagePath}`,
|
|
155
|
-
// { encoding: 'utf-8' }
|
|
156
|
-
// )
|
|
157
|
-
// );
|
|
158
|
-
// const modulesInBytes = compiledModules.map((m) =>
|
|
159
|
-
// Array.from(new Base64DataBuffer(m).getData())
|
|
160
|
-
// );
|
|
161
|
-
// const publishTxn = await signer.publish({
|
|
162
|
-
// compiledModules: modulesInBytes,
|
|
163
|
-
// gasBudget: 10000,
|
|
164
|
-
// });
|
|
165
|
-
// console.log('publishTxn', publishTxn);
|
|
166
|
-
// })();
|
|
167
|
-
|
|
168
|
-
// //Success
|
|
169
|
-
// (async () => {
|
|
170
|
-
// console.log("test for getTransactions()") // return digest
|
|
171
|
-
// let txs = await provider.getTransactionsForObject(
|
|
172
|
-
// obj1
|
|
173
|
-
// )
|
|
174
|
-
// console.log(txs)
|
|
175
|
-
|
|
176
|
-
// let tx = await provider.getTransactionWithEffects(
|
|
177
|
-
// txs[0]
|
|
178
|
-
// )
|
|
179
|
-
// console.log(tx)
|
|
180
|
-
// })();
|
|
181
|
-
|
|
182
|
-
// //Success
|
|
183
|
-
// (async () => {
|
|
184
|
-
// console.log("test for getEvents()")//input type: EventQuery
|
|
185
|
-
// const senderEvents = await provider.getEvents(
|
|
186
|
-
// { "Transaction": tx1 },
|
|
187
|
-
// null,
|
|
188
|
-
// null,
|
|
189
|
-
// );
|
|
190
|
-
// for (let e of senderEvents.data) {
|
|
191
|
-
// console.log(e.event)
|
|
192
|
-
// }
|
|
193
|
-
// })();
|
|
194
|
-
|
|
195
|
-
// let packageId = "0xfbbdd33ab4c02e7a315e2477931bae4cbdf46381";
|
|
196
|
-
// let registry = "0x0a9d87a1b6c00415708d2f1c62784b52f797213c";
|
|
197
|
-
// let coin = "0x84e5c5702bfbb00a830fb43e720a3a412cc2a8db";
|
|
198
|
-
// console.log("test for deposit()")
|
|
199
|
-
// await deposit(packageId, registry, coin)
|
|
200
|
-
// async function deposit(packageId: string, registry: string, coin: string) {
|
|
201
|
-
// let txn = {
|
|
202
|
-
// packageObjectId: packageId,
|
|
203
|
-
// module: 'shark_fin',
|
|
204
|
-
// function: 'deposit',
|
|
205
|
-
// typeArguments: ["0x2::sui::SUI"],
|
|
206
|
-
// arguments: [
|
|
207
|
-
// registry,
|
|
208
|
-
// 0,
|
|
209
|
-
// true,
|
|
210
|
-
// coin
|
|
211
|
-
// ],
|
|
212
|
-
// gasBudget: 1000,
|
|
213
|
-
// }
|
|
214
|
-
// const moveCallTxn = await signer.executeMoveCall(txn);
|
|
215
|
-
// console.log('moveCallTxn', moveCallTxn);
|
|
216
|
-
// }
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
File without changes
|
|
File without changes
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { JsonRpcProvider, Network } from '@mysten/sui.js';
|
|
2
|
-
const provider = new JsonRpcProvider(Network.DEVNET);//for read only operations
|
|
3
|
-
|
|
4
|
-
export async function subVaults(): Promise<any> {
|
|
5
|
-
//packageID and registry
|
|
6
|
-
let packageID = process.env.PACKAGE!
|
|
7
|
-
let registry = process.env.VAULT_REGISTRY!
|
|
8
|
-
console.log("packageID: " + packageID)
|
|
9
|
-
console.log("registry: " + registry)
|
|
10
|
-
|
|
11
|
-
//vault
|
|
12
|
-
let tmpObj1 = await provider.getObjectsOwnedByObject(registry)
|
|
13
|
-
let vault = tmpObj1[0].objectId
|
|
14
|
-
console.log("vault: " + vault)
|
|
15
|
-
|
|
16
|
-
//table
|
|
17
|
-
let tmpObj2 = await provider.getObject(vault)
|
|
18
|
-
//@ts-ignore
|
|
19
|
-
let table = tmpObj2.details.data.fields.value.fields.sub_vaults.fields.id.id
|
|
20
|
-
console.log("table: " + table)
|
|
21
|
-
|
|
22
|
-
//sub vault (maker / rolling / no_rolling) id
|
|
23
|
-
let tmpObj3 = await provider.getObjectsOwnedByObject(table)
|
|
24
|
-
let subVaultsId: string[] = [];
|
|
25
|
-
tmpObj3.map(e => {
|
|
26
|
-
subVaultsId.push(e.objectId as string)
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
console.log("subVaults: ")
|
|
30
|
-
//@ts-ignore
|
|
31
|
-
console.log(subVaultsId)
|
|
32
|
-
|
|
33
|
-
//sub vault data
|
|
34
|
-
const subVaultsMap = new Map();
|
|
35
|
-
//@ts-ignore
|
|
36
|
-
for (let e of subVaultsId) {
|
|
37
|
-
let tmpObj4 = await provider.getObject(e)
|
|
38
|
-
//@ts-ignore
|
|
39
|
-
subVaultsMap.set(tmpObj4.details.data.fields.name, tmpObj4.details.data.fields)
|
|
40
|
-
}
|
|
41
|
-
// console.log(subVaultsMap.get("rolling").value.fields.users_table)
|
|
42
|
-
return subVaultsMap
|
|
43
|
-
}
|