@silvana-one/coordination 1.0.30 → 1.0.32
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/dist/node/agent.d.ts +13 -0
- package/dist/node/agent.js +38 -0
- package/dist/node/agent.js.map +1 -1
- package/dist/node/balance.d.ts +6 -0
- package/dist/node/balance.js +25 -0
- package/dist/node/balance.js.map +1 -0
- package/dist/node/index.cjs +94 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/state.d.ts +3 -0
- package/dist/node/state.js +29 -0
- package/dist/node/state.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/agent.d.ts +13 -0
- package/dist/web/agent.js +38 -0
- package/dist/web/agent.js.map +1 -1
- package/dist/web/balance.d.ts +6 -0
- package/dist/web/balance.js +25 -0
- package/dist/web/balance.js.map +1 -0
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/state.d.ts +3 -0
- package/dist/web/state.js +29 -0
- package/dist/web/state.js.map +1 -0
- package/package.json +1 -1
- package/src/agent.ts +63 -0
- package/src/balance.ts +29 -0
- package/src/index.ts +2 -0
- package/src/state.ts +37 -0
package/dist/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fetchSuiDynamicFieldsList, fetchSuiObject, suiClient, } from "@silvana-one/coordination";
|
|
2
|
+
export async function getState(params = {}) {
|
|
3
|
+
const { appInstanceID = process.env.APP_INSTANCE_ID } = params;
|
|
4
|
+
if (!appInstanceID) {
|
|
5
|
+
throw new Error("APP_INSTANCE_ID is not set");
|
|
6
|
+
}
|
|
7
|
+
// Get the AppInstance object
|
|
8
|
+
const appInstance = await fetchSuiObject(appInstanceID);
|
|
9
|
+
if (appInstance?.data?.content?.dataType !== "moveObject")
|
|
10
|
+
throw new Error("AppInstance not found");
|
|
11
|
+
// The state is inside the AppInstance
|
|
12
|
+
const stateObjectID = (appInstance?.data?.content?.fields).state.fields
|
|
13
|
+
.state.fields.id.id;
|
|
14
|
+
const state = [];
|
|
15
|
+
const fields = await fetchSuiDynamicFieldsList(stateObjectID);
|
|
16
|
+
const names = fields.data.map((field) => field.name);
|
|
17
|
+
for (const name of names) {
|
|
18
|
+
const element = await suiClient.getDynamicFieldObject({
|
|
19
|
+
parentId: stateObjectID,
|
|
20
|
+
name,
|
|
21
|
+
});
|
|
22
|
+
if (element.data?.content?.dataType !== "moveObject")
|
|
23
|
+
throw new Error("Element not found");
|
|
24
|
+
const value = BigInt((element.data?.content.fields).state[0]);
|
|
25
|
+
state.push(value);
|
|
26
|
+
}
|
|
27
|
+
return state;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,SAAS,GACV,MAAM,2BAA2B,CAAC;AAEnC,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,SAAqC,EAAE;IAEvC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC;IAC/D,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,6BAA6B;IAC7B,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,aAAa,CAAC,CAAC;IACxD,IAAI,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,KAAK,YAAY;QACvD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAE3C,sCAAsC;IACtC,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,MAAc,CAAA,CAAC,KAAK,CAAC,MAAM;SAC3E,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;IACtB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAAC,aAAa,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAErD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,qBAAqB,CAAC;YACpD,QAAQ,EAAE,aAAa;YACvB,IAAI;SACL,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,KAAK,YAAY;YAClD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAc,CAAA,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -348,6 +348,69 @@ export class AgentRegistry {
|
|
|
348
348
|
return tx;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
addMethodToApp(params: {
|
|
352
|
+
appName: string;
|
|
353
|
+
methodName: string;
|
|
354
|
+
description?: string;
|
|
355
|
+
developerName: string;
|
|
356
|
+
agentName: string;
|
|
357
|
+
agentMethod: string;
|
|
358
|
+
}): Transaction {
|
|
359
|
+
const {
|
|
360
|
+
appName,
|
|
361
|
+
methodName,
|
|
362
|
+
description,
|
|
363
|
+
developerName,
|
|
364
|
+
agentName,
|
|
365
|
+
agentMethod,
|
|
366
|
+
} = params;
|
|
367
|
+
const tx = new Transaction();
|
|
368
|
+
|
|
369
|
+
// Create the app method using app_method::new
|
|
370
|
+
const appMethod = tx.moveCall({
|
|
371
|
+
target: `${silvanaRegistryPackage}::app_method::new`,
|
|
372
|
+
arguments: [
|
|
373
|
+
tx.pure.option("string", description ?? null),
|
|
374
|
+
tx.pure.string(developerName),
|
|
375
|
+
tx.pure.string(agentName),
|
|
376
|
+
tx.pure.string(agentMethod),
|
|
377
|
+
],
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// Add the method to the app
|
|
381
|
+
tx.moveCall({
|
|
382
|
+
target: `${silvanaRegistryPackage}::registry::add_method_to_app`,
|
|
383
|
+
arguments: [
|
|
384
|
+
tx.object(this.registry),
|
|
385
|
+
tx.pure.string(appName),
|
|
386
|
+
tx.pure.string(methodName),
|
|
387
|
+
appMethod,
|
|
388
|
+
],
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
return tx;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
addMetadata(params: {
|
|
395
|
+
appInstanceId: string;
|
|
396
|
+
key: string;
|
|
397
|
+
value: string;
|
|
398
|
+
}): Transaction {
|
|
399
|
+
const { appInstanceId, key, value } = params;
|
|
400
|
+
const tx = new Transaction();
|
|
401
|
+
|
|
402
|
+
tx.moveCall({
|
|
403
|
+
target: `${silvanaRegistryPackage}::app_instance::add_metadata`,
|
|
404
|
+
arguments: [
|
|
405
|
+
tx.object(appInstanceId),
|
|
406
|
+
tx.pure.string(key),
|
|
407
|
+
tx.pure.string(value),
|
|
408
|
+
],
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
return tx;
|
|
412
|
+
}
|
|
413
|
+
|
|
351
414
|
setDefaultMethod(params: {
|
|
352
415
|
developer: string;
|
|
353
416
|
agent: string;
|
package/src/balance.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CoinBalance } from "@mysten/sui/client";
|
|
2
|
+
import { suiClient } from "@silvana-one/coordination";
|
|
3
|
+
import { MIST_PER_SUI } from "@mysten/sui/utils";
|
|
4
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
5
|
+
|
|
6
|
+
export function suiBalance(balance: CoinBalance): number {
|
|
7
|
+
return Number.parseInt(balance.totalBalance) / Number(MIST_PER_SUI);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function getSuiBalance(address: string): Promise<number> {
|
|
11
|
+
try {
|
|
12
|
+
const balance = await suiClient.getBalance({
|
|
13
|
+
owner: address,
|
|
14
|
+
coinType: "0x2::sui::SUI",
|
|
15
|
+
});
|
|
16
|
+
return suiBalance(balance);
|
|
17
|
+
} catch (error: any) {
|
|
18
|
+
console.error("getSuiBalance error:", error?.message);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function getSuiAddress(params: {
|
|
24
|
+
secretKey: string;
|
|
25
|
+
}): Promise<string> {
|
|
26
|
+
return Ed25519Keypair.fromSecretKey(params.secretKey)
|
|
27
|
+
.getPublicKey()
|
|
28
|
+
.toSuiAddress();
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
package/src/state.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchSuiDynamicFieldsList,
|
|
3
|
+
fetchSuiObject,
|
|
4
|
+
suiClient,
|
|
5
|
+
} from "@silvana-one/coordination";
|
|
6
|
+
|
|
7
|
+
export async function getState(
|
|
8
|
+
params: { appInstanceID?: string } = {}
|
|
9
|
+
): Promise<bigint[]> {
|
|
10
|
+
const { appInstanceID = process.env.APP_INSTANCE_ID } = params;
|
|
11
|
+
if (!appInstanceID) {
|
|
12
|
+
throw new Error("APP_INSTANCE_ID is not set");
|
|
13
|
+
}
|
|
14
|
+
// Get the AppInstance object
|
|
15
|
+
const appInstance = await fetchSuiObject(appInstanceID);
|
|
16
|
+
if (appInstance?.data?.content?.dataType !== "moveObject")
|
|
17
|
+
throw new Error("AppInstance not found");
|
|
18
|
+
|
|
19
|
+
// The state is inside the AppInstance
|
|
20
|
+
const stateObjectID = (appInstance?.data?.content?.fields as any).state.fields
|
|
21
|
+
.state.fields.id.id;
|
|
22
|
+
const state: bigint[] = [];
|
|
23
|
+
const fields = await fetchSuiDynamicFieldsList(stateObjectID);
|
|
24
|
+
const names = fields.data.map((field) => field.name);
|
|
25
|
+
|
|
26
|
+
for (const name of names) {
|
|
27
|
+
const element = await suiClient.getDynamicFieldObject({
|
|
28
|
+
parentId: stateObjectID,
|
|
29
|
+
name,
|
|
30
|
+
});
|
|
31
|
+
if (element.data?.content?.dataType !== "moveObject")
|
|
32
|
+
throw new Error("Element not found");
|
|
33
|
+
const value = BigInt((element.data?.content.fields as any).state[0]);
|
|
34
|
+
state.push(value);
|
|
35
|
+
}
|
|
36
|
+
return state;
|
|
37
|
+
}
|