From 66c4efa68bc5426c27dbabfedc4016197a858054 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 2 May 2024 19:48:11 -0400 Subject: [PATCH 01/84] Add permissionLevel and fix env vars names --- test/src/utils.ts | 103 ++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/test/src/utils.ts b/test/src/utils.ts index d06f42dc..e1006609 100644 --- a/test/src/utils.ts +++ b/test/src/utils.ts @@ -1,8 +1,8 @@ import { - PrivateKey, - type PrivateKeyType, - Session, - PermissionLevel, + PrivateKey, + type PrivateKeyType, + Session, + PermissionLevel, } from "@wharfkit/session"; import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; import { jungle4, eos } from "../../src/exports"; @@ -11,71 +11,58 @@ import type { Client } from "../../src/client"; import type { Network } from "../../src/types/network"; declare module "bun" { - interface Env { - TESTNET_PERMISSION: string; - TESTNET_NETWORK_NAME: string; - TESTNET_ACTOR: string; - TESTNET_PRIVATE_KEY: string; - MAINNET_PERMISSION: string; - MAINNET_NETWORK_NAME: string; - MAINNET_ACTOR: string; - MAINNET_PRIVATE_KEY: string; - } + interface Env { + TESTNET_PERMISSION: string; + TESTNET_NETWORK_NAME: string; + TESTNET_ACTOR: string; + TESTNET_PRIVATE_KEY: string; + MAINNET_PERMISSION: string; + MAINNET_NETWORK_NAME: string; + MAINNET_ACTOR: string; + MAINNET_PRIVATE_KEY: string; + } } export interface testEnv { - network: Network; - networkName: string; - permission: string; - actor: string; - privateKey: PrivateKeyType; + network: Network; + networkName: string; + permission: string; + actor: string; + privateKey: PrivateKeyType; } -export const destructureEnv = (networkEnv: Network) => { - return { - network: jungle4, - networkName: process.env.NETWORK_NAME, - permission: process.env.PERMISSION!, - actor: process.env.ACTOR!, - privateKey: PrivateKey.from(process.env.PRIVATE_KEY!), - }; +export const destructureEnv = (network: Network) => { + return { + network: jungle4, + networkName: process.env.TESTNET_NETWORK_NAME, + permission: process.env.TESTNET_PERMISSION!, + actor: process.env.TESTNET_ACTOR!, + privateKey: PrivateKey.from(process.env.TESTNET_PRIVATE_KEY!), + }; }; -export const testClientSession = async ({ - testEnvNetwork, -}: { testEnvNetwork: Network }): Promise => { - // Retrieve parameters for session. - const { network, permission, actor, privateKey } = - destructureEnv(testEnvNetwork); +export const testClientSession = async ({ network }: { network: Network }): Promise => { + // Retrieve parameters for session. + const { permission, actor, privateKey } = destructureEnv(network); + const chain = network; - if (!privateKey) { - throw new Error("Private key not found"); - } + if (!privateKey) { + throw new Error("Private key not found"); + } - const { url, id } = network; + // Create client + const client = createClient({ network }); - // Create client - const client = createClient({ network }); + // Setup wallet plugin with private key + const walletPlugin = new WalletPluginPrivateKey(privateKey); - // Set up wallet with privatekey - const pk: PrivateKeyType = PrivateKey.fromString( - privateKey.toString(), - false, - ); + /** Create new permission level from representing types. Can be expressed as a string in the format `@`. */ + const permissionLevel = PermissionLevel.from(`${actor}@${permission}`); + // Set up session with wallet and chain + const session = new Session({ actor, permission, walletPlugin, chain, permissionLevel }); - const walletPlugin = new WalletPluginPrivateKey(pk); + // Connect session to client + await client.setSession(session); - // Set up session with wallet and chain - const session = new Session({ - actor, - permission, - walletPlugin, - chain: { id, url }, - permissionLevel: PermissionLevel.from(`${actor}@${permission}`), - }); - - // Connect session to client - await client.setSession(session); - - return client; + return client; }; From 9e9e826905dedcf1a1a2a45e3a80b2b7da770283 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 2 May 2024 19:53:37 -0400 Subject: [PATCH 02/84] Fix name for network property in testClientSession --- .../tasks/campaigns/createCampaign.test.ts | 98 +++++++++---------- .../tasks/campaigns/getCampaigns.test.ts | 14 +-- src/actions/token/swap.test.ts | 40 ++++---- src/actions/token/token.test.ts | 78 +++++++-------- src/actions/vaccount/createAccount.test.ts | 30 +++--- src/actions/vaccount/deposit.test.ts | 26 ++--- src/actions/vaccount/getAccounts.test.ts | 62 ++++++------ src/client.test.ts | 43 ++++---- 8 files changed, 193 insertions(+), 198 deletions(-) diff --git a/src/actions/tasks/campaigns/createCampaign.test.ts b/src/actions/tasks/campaigns/createCampaign.test.ts index b3b3532b..a1640179 100644 --- a/src/actions/tasks/campaigns/createCampaign.test.ts +++ b/src/actions/tasks/campaigns/createCampaign.test.ts @@ -5,57 +5,57 @@ import { testClientSession } from "../../../../test/src/utils"; import { jungle4 } from "../../../exports"; const myNewCampaign: CreateCampaignArgs["campaign"] = { - version: 1.0, - maxTaskTime: 100, - reward: 3.5, - title: "Labelstudio OCR (LAION)", - description: - "You are contributing to a dataset for conversational style chatbots.", - instructions: "Some instructions here", - template: "

Template here

", - input_schema: null, - output_schema: null, - image: "", - category: "", - example_task: "", - estimated_time: 10, + version: 1.0, + maxTaskTime: 100, + reward: 3.5, + title: "Labelstudio OCR (LAION)", + description: + "You are contributing to a dataset for conversational style chatbots.", + instructions: "Some instructions here", + template: "

Template here

", + input_schema: null, + output_schema: null, + image: "", + category: "", + example_task: "", + estimated_time: 10, }; describe("createCampaign", async () => { - test("createCampaign() should throw an error", async () => { - const client = createClient({ network: jungle4 }); - expect(async () => { - await createCampaign({ - client, - campaign: myNewCampaign, - }); - }).toThrowError(); - }); + test("createCampaign() should throw an error", async () => { + const client = createClient({ network: jungle4 }); + expect(async () => { + await createCampaign({ + client, + campaign: myNewCampaign, + }); + }).toThrowError(); + }); - test.skip("createCampaign() should create a new campaign", async () => { - const client = await testClientSession({ testEnvNetwork: jungle4 }); - const result = await createCampaign({ client, campaign: myNewCampaign }); - expect(result).toBeDefined(); - /** - * response: { - * transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", - * processed: { - * id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", - * block_num: 137520447, - * block_time: "2024-05-01T03:55:31.500", - * producer_block_id: null, - * receipt: [Object ...], - * elapsed: 4854, - * net_usage: 176, - * scheduled: false, - * action_traces: [ - * [Object ...] - * ], - * account_ram_delta: null, - * except: null, - * error_code: null, - * }, - * } - */ - }); + test.skip("createCampaign() should create a new campaign", async () => { + const client = await testClientSession({ network: jungle4 }); + const result = await createCampaign({ client, campaign: myNewCampaign }); + expect(result).toBeDefined(); + /** + * response: { + * transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + * processed: { + * id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + * block_num: 137520447, + * block_time: "2024-05-01T03:55:31.500", + * producer_block_id: null, + * receipt: [Object ...], + * elapsed: 4854, + * net_usage: 176, + * scheduled: false, + * action_traces: [ + * [Object ...] + * ], + * account_ram_delta: null, + * except: null, + * error_code: null, + * }, + * } + */ + }); }); diff --git a/src/actions/tasks/campaigns/getCampaigns.test.ts b/src/actions/tasks/campaigns/getCampaigns.test.ts index 7a4a9b38..df992b2c 100644 --- a/src/actions/tasks/campaigns/getCampaigns.test.ts +++ b/src/actions/tasks/campaigns/getCampaigns.test.ts @@ -4,11 +4,11 @@ import { getCampaigns } from "./getCampaigns"; import { jungle4 } from "../../../exports"; describe("getCampaigns", async () => { - test("getCampaigns() should return 3 campaigns", async () => { - const client = await testClientSession({ testEnvNetwork: jungle4 }); - const campaigns = await getCampaigns({ client, limit: 3 }); - expect(campaigns).toBeDefined(); - expect(campaigns.rows).toBeArray(); - expect(campaigns.rows.length).toBe(3); - }); + test("getCampaigns() should return 3 campaigns", async () => { + const client = await testClientSession({ network: jungle4 }); + const campaigns = await getCampaigns({ client, limit: 3 }); + expect(campaigns).toBeDefined(); + expect(campaigns.rows).toBeArray(); + expect(campaigns.rows.length).toBe(3); + }); }); diff --git a/src/actions/token/swap.test.ts b/src/actions/token/swap.test.ts index 1e00ed8b..b63281ed 100644 --- a/src/actions/token/swap.test.ts +++ b/src/actions/token/swap.test.ts @@ -5,31 +5,31 @@ import type { SwapArgs } from "./swap"; import { testClientSession } from "../../../test/src/utils"; describe("buildSwapAction", async () => { - test.todo("buildSwapAction() should return a swap action object."); + test.todo("buildSwapAction() should return a swap action object."); }); describe("Swap", async () => { - // Use Mainnet + // Use Mainnet - test("swap() should throw an error when Session is not set on Client.", async () => { - const swapArgs: SwapArgs = { - client: createClient({ network: jungle4 }), - amount: 1, - direction: "UsdtToEfx", - }; + test("swap() should throw an error when Session is not set on Client.", async () => { + const swapArgs: SwapArgs = { + client: createClient({ network: jungle4 }), + amount: 1, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow( - new Error("Error swapping: Error: Session is required for this method."), - ); - }); + expect(async () => await swap(swapArgs)).toThrow( + new Error("Error swapping: Error: Session is required for this method."), + ); + }); - test("swap() should fail when amount is 0", async () => { - const swapArgs: SwapArgs = { - client: await testClientSession({ testEnvNetwork: jungle4 }), - amount: 0, - direction: "UsdtToEfx", - }; + test("swap() should fail when amount is 0", async () => { + const swapArgs: SwapArgs = { + client: await testClientSession({ network: jungle4 }), + amount: 0, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow(); - }); + expect(async () => await swap(swapArgs)).toThrow(); + }); }); diff --git a/src/actions/token/token.test.ts b/src/actions/token/token.test.ts index 7ae96c84..004fcc69 100644 --- a/src/actions/token/token.test.ts +++ b/src/actions/token/token.test.ts @@ -8,57 +8,57 @@ import { Name } from "@wharfkit/antelope"; import { testClientSession } from "../../../test/src/utils"; describe("getPrice", async () => { - test("getPrice() should retrieve price on mainnet", async () => { - const client = createClient({ network: eos }); - const price = await getPrice(); - expect(price).toBeDefined(); - expect(price).toBeNumber(); - }); + test("getPrice() should retrieve price on mainnet", async () => { + const client = createClient({ network: eos }); + const price = await getPrice(); + expect(price).toBeDefined(); + expect(price).toBeNumber(); + }); }); describe("getBalance", async () => { - test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = createClient({ network: jungle4 }); - const actor = Name.from("forcedev1234"); - const balance = await getBalance({ client, actor }); - expect(balance).toBeDefined(); - expect(balance.toString()).toBeDefined(); - expect(balance.toString()).toContain("EFX"); - }); + test("getBalance() should retrieve balance from user on mainnet", async () => { + const client = createClient({ network: jungle4 }); + const actor = Name.from("forcedev1234"); + const balance = await getBalance({ client, actor }); + expect(balance).toBeDefined(); + expect(balance.toString()).toBeDefined(); + expect(balance.toString()).toContain("EFX"); + }); - test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = createClient({ network: eos }); - const actor = Name.from("cryptonode99"); - expect(async () => await getBalance({ client, actor })).toThrowError(); - }); + test("getBalance() should throw Error retrieving balance from unknown user.", async () => { + const client = createClient({ network: eos }); + const actor = Name.from("cryptonode99"); + expect(async () => await getBalance({ client, actor })).toThrowError(); + }); }); describe("buildSwapAction", async () => { - test.todo("buildSwapAction() should return a swap action object."); + test.todo("buildSwapAction() should return a swap action object."); }); describe("Swap", async () => { - // Use Mainnet + // Use Mainnet - test("swap() should throw an error when Session is not set on Client.", async () => { - const swapArgs: SwapArgs = { - client: createClient({ network: jungle4 }), - amount: 1, - direction: "UsdtToEfx", - }; + test("swap() should throw an error when Session is not set on Client.", async () => { + const swapArgs: SwapArgs = { + client: createClient({ network: jungle4 }), + amount: 1, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow( - new Error("Error swapping: Error: Session is required for this method."), - ); - }); + expect(async () => await swap(swapArgs)).toThrow( + new Error("Error swapping: Error: Session is required for this method."), + ); + }); - test("swap() should fail when amount is 0", async () => { - const swapArgs: SwapArgs = { - client: await testClientSession({ testEnvNetwork: jungle4 }), - amount: 0, - direction: "UsdtToEfx", - }; + test("swap() should fail when amount is 0", async () => { + const swapArgs: SwapArgs = { + client: await testClientSession({ network: jungle4 }), + amount: 0, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow(); - }); + expect(async () => await swap(swapArgs)).toThrow(); + }); }); diff --git a/src/actions/vaccount/createAccount.test.ts b/src/actions/vaccount/createAccount.test.ts index 3ef79d4b..a4cc8508 100644 --- a/src/actions/vaccount/createAccount.test.ts +++ b/src/actions/vaccount/createAccount.test.ts @@ -6,23 +6,23 @@ import { createClient } from "../../client"; import { createVAccount } from "./createAccount"; import { jungle4 } from "../../exports"; -import { destructureEnv, testClientSession } from "../../../test/src/utils.js"; +import { testClientSession } from "../../../test/src/utils.js"; describe("Create Virtual account", () => { - const testEnvNetwork = jungle4; + const network = jungle4; - test.skip("createVAccount() should return a TransactResult", async () => { - const client = await testClientSession({ testEnvNetwork }); - const account = Name.from("efxforce1112"); - const result = await createVAccount({ client, account }); - expect(result).toBeDefined(); - }); + test.skip("createVAccount() should return a TransactResult", async () => { + const client = await testClientSession({ network }); + const account = Name.from("efxforce1112"); + const result = await createVAccount({ client, account }); + expect(result).toBeDefined(); + }); - test("createVAccount() should throw Error when no Session is found", async () => { - expect(async () => { - const client = createClient({ network: testEnvNetwork }); - const account = Name.from("efxforce1112"); - await createVAccount({ client, account }); - }).toThrowError(); - }); + test("createVAccount() should throw Error when no Session is found", async () => { + expect(async () => { + const client = createClient({ network: network }); + const account = Name.from("efxforce1112"); + await createVAccount({ client, account }); + }).toThrowError(); + }); }); diff --git a/src/actions/vaccount/deposit.test.ts b/src/actions/vaccount/deposit.test.ts index 6dbc9ae5..ec83b1b6 100644 --- a/src/actions/vaccount/deposit.test.ts +++ b/src/actions/vaccount/deposit.test.ts @@ -6,18 +6,18 @@ import { Name } from "@wharfkit/antelope"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; describe("deposit", async () => { - test.todo("Should throw an error when Session is not set on Client.", () => { - // TODO: implement test - }); + test.todo("Should throw an error when Session is not set on Client.", () => { + // TODO: implement test + }); - test.skip("Check that deposit is functioning correctly", async () => { - const { network, actor } = destructureEnv(jungle4); - const client = await testClientSession({ testEnvNetwork: network }); - console.debug(client.network); - const acc = Name.from(actor); - const vAccount = await getOrCreateVAccount({ client, actor: acc }); - const vAccId = Number(vAccount.id); - const result = await deposit({ client, vAccountId: vAccId, amount: 0.1 }); - console.debug(result); - }); + test.skip("Check that deposit is functioning correctly", async () => { + const { network, actor } = destructureEnv(jungle4); + const client = await testClientSession({ network }); + console.debug(client.network); + const acc = Name.from(actor); + const vAccount = await getOrCreateVAccount({ client, actor: acc }); + const vAccId = Number(vAccount.id); + const result = await deposit({ client, vAccountId: vAccId, amount: 0.1 }); + console.debug(result); + }); }); diff --git a/src/actions/vaccount/getAccounts.test.ts b/src/actions/vaccount/getAccounts.test.ts index 75fa2eef..b6f8c9de 100644 --- a/src/actions/vaccount/getAccounts.test.ts +++ b/src/actions/vaccount/getAccounts.test.ts @@ -8,39 +8,39 @@ import { Name } from "@wharfkit/antelope"; import { jungle4 } from "../../exports"; describe("Get Virtual Accounts", () => { - const vaccExample: VAccount = { - id: 0, - nonce: 53, - address: ["name", "efxforceacc1"], - balance: { - quantity: "3525.0000 EFX", - contract: "effecttokens", - }, - }; + const vaccExample: VAccount = { + id: 0, + nonce: 53, + address: ["name", "efxforceacc1"], + balance: { + quantity: "3525.0000 EFX", + contract: "effecttokens", + }, + }; - let client: Client; - beforeAll(async () => { - client = await testClientSession({ testEnvNetwork: jungle4 }); - }); + let client: Client; + beforeAll(async () => { + client = await testClientSession({ network: jungle4 }); + }); - test("getVAccounts() on testnet", async () => { - const actor = Name.from("efxforce1112"); - const vaccs = await getVAccounts({ client, actor }); - expect(vaccs).toBeDefined(); - expect(vaccs).toBeArray(); - expect(vaccs[0]).toContainKeys(Object.keys(vaccExample)); - }); + test("getVAccounts() on testnet", async () => { + const actor = Name.from("efxforce1112"); + const vaccs = await getVAccounts({ client, actor }); + expect(vaccs).toBeDefined(); + expect(vaccs).toBeArray(); + expect(vaccs[0]).toContainKeys(Object.keys(vaccExample)); + }); - test("getAccountById()", async () => { - const vacc = await getAccountById({ client, accountId: 0 }); - expect(vacc).toBeDefined(); - expect(vacc).toContainKeys(Object.keys(vaccExample)); - }); + test("getAccountById()", async () => { + const vacc = await getAccountById({ client, accountId: 0 }); + expect(vacc).toBeDefined(); + expect(vacc).toContainKeys(Object.keys(vaccExample)); + }); - test("getAccountByID() should throw Error", async () => { - const accountId = 9999999; // Should be imposible to find - expect(async () => { - await getAccountById({ client, accountId }); - }).toThrowError(); - }); + test("getAccountByID() should throw Error", async () => { + const accountId = 9999999; // Should be imposible to find + expect(async () => { + await getAccountById({ client, accountId }); + }).toThrowError(); + }); }); diff --git a/src/client.test.ts b/src/client.test.ts index d07e649f..596452d9 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -1,37 +1,32 @@ import { expect, test, describe, beforeAll } from "bun:test"; import { jungle4, eos } from "../src/exports"; import { createClient, Client as ClientConstructor } from "./client"; -import { Name } from "@wharfkit/antelope"; import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; import { Session } from "@wharfkit/session"; -import { EffectSession } from "./session"; import { destructureEnv, testClientSession } from "../test/src/utils"; describe("Client", async () => { - test("Create client with Session", async () => { - const { network, permission, actor, privateKey } = destructureEnv(eos); + test("Create client with Session", async () => { + const { + network: chain, + permission, + actor, + privateKey, + } = destructureEnv(eos); - // Create wallet with privatekey - const walletPlugin = new WalletPluginPrivateKey(privateKey); + // Create wallet with privatekey + const walletPlugin = new WalletPluginPrivateKey(privateKey); - // Set up session with wallet - const session = new Session({ - actor, - permission, - walletPlugin, - chain: { - id: network.id, - url: network.url, - }, - }); + // Set up session with wallet + const session = new Session({ actor, permission, walletPlugin, chain }); - const client = createClient({ session }); - expect(client.session).toBeDefined(); - }); + const client = createClient({ session }); + expect(client.session).toBeDefined(); + }); - test("Create client with Network", async () => { - const { network, permission, actor, privateKey } = destructureEnv(eos); - const client = createClient({ network }); - expect(client.session).toBeDefined(); - }); + test("Create client with Network", async () => { + const { network } = destructureEnv(eos); + const client = createClient({ network }); + expect(client.session).toBeDefined(); + }); }); From 0fd401f2d3ad0dc315e74f34efb8ad58281a8277 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 2 May 2024 19:54:16 -0400 Subject: [PATCH 03/84] Add transact function return type --- src/actions/vaccount/transfer.ts | 101 ++++++++++++++++--------------- src/session.ts | 85 +++++++++++++------------- 2 files changed, 94 insertions(+), 92 deletions(-) diff --git a/src/actions/vaccount/transfer.ts b/src/actions/vaccount/transfer.ts index e27d7866..a31cb289 100644 --- a/src/actions/vaccount/transfer.ts +++ b/src/actions/vaccount/transfer.ts @@ -2,70 +2,71 @@ import type { AnyAction } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { SessionNotFoundError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; +import type { TransactResult } from "@wharfkit/session"; export type vTransferActionArgs = { - client: Client; - from_id: number; - to_id: number; - quantity: number; + client: Client; + from_id: number; + to_id: number; + quantity: number; }; export const vTransferAction = ({ - client, - to_id, - from_id, - quantity, + client, + to_id, + from_id, + quantity, }: vTransferActionArgs): AnyAction => { - if (!client.session) { - throw new SessionNotFoundError("Session is required for this method."); - } + if (!client.session) { + throw new SessionNotFoundError("Session is required for this method."); + } - const { actor, authorization } = client.session; - const { vaccount, token } = useEFXContracts(client); + const { actor, authorization } = client.session; + const { vaccount, token } = useEFXContracts(client); - return { - account: vaccount, - name: "vtransfer", - authorization, - data: { - from_id, - to_id, - quantity: { - quantity: quantity, - contract: token, - }, - memo: "", - payer: actor, - sig: null, - fee: null, - }, - }; + return { + account: vaccount, + name: "vtransfer", + authorization, + data: { + from_id, + to_id, + quantity: { + quantity: quantity, + contract: token, + }, + memo: "", + payer: actor, + sig: null, + fee: null, + }, + }; }; export type vTransferArgs = { - client: Client; - from_id: number; - to_id: number; - quantity: number; + client: Client; + from_id: number; + to_id: number; + quantity: number; }; export const vTransfer = async ({ - client, - from_id, - to_id, - quantity, -}: vTransferArgs) => { - if (!client.session) { - throw new SessionNotFoundError("Session is required for this method."); - } - const { transact } = client.session; + client, + from_id, + to_id, + quantity, +}: vTransferArgs): Promise => { + if (!client.session) { + throw new SessionNotFoundError("Session is required for this method."); + } + const { transact } = client.session; - const transferAction = vTransferAction({ - client, - to_id, - from_id, - quantity, - }); + const transferAction = vTransferAction({ + client, + to_id, + from_id, + quantity, + }); - return await transact({ action: transferAction }); + return await transact({ action: transferAction }); }; diff --git a/src/session.ts b/src/session.ts index 342c1775..483ca25c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1,50 +1,51 @@ import type { - Name, - PermissionLevelType, - Session, - TransactArgs, - TransactOptions, + Name, + PermissionLevelType, + Session, + TransactArgs, + TransactOptions, + TransactResult, } from "@wharfkit/session"; import { TransactionError } from "./errors"; import type { VAccount } from "./exports"; import { TxState, waitForTransaction } from "./utils/transaction"; export class EffectSession { - public readonly wharfKitSession: Session; - - public readonly actor: Name; - public readonly permission: Name; - public readonly permissionLevel: PermissionLevelType; - public readonly authorization: { actor: Name; permission: Name }[]; - - private _vAccount: VAccount | null; - - get vAccount(): VAccount | null { - return this._vAccount; - } - - constructor(session: Session, vAccount: VAccount) { - this.actor = session.actor; - this.permission = session.permission; - this.permissionLevel = session.permissionLevel; - this.wharfKitSession = session; - this.authorization = [{ actor: this.actor, permission: this.permission }]; - this._vAccount = vAccount; - } - - public transact = async (args: TransactArgs) => { - // Start the transaction - const transaction = await this.wharfKitSession.transact({ - ...args, - }); - - //wait for TX to be IN BLOCK - await waitForTransaction( - transaction.response?.transaction_id, - this.wharfKitSession.client.v1.chain, - TxState.IN_BLOCK, - ); - - return transaction; - }; + public readonly wharfKitSession: Session; + + public readonly actor: Name; + public readonly permission: Name; + public readonly permissionLevel: PermissionLevelType; + public readonly authorization: { actor: Name; permission: Name }[]; + + private _vAccount: VAccount | null; + + get vAccount(): VAccount | null { + return this._vAccount; + } + + constructor(session: Session, vAccount: VAccount) { + this.actor = session.actor; + this.permission = session.permission; + this.permissionLevel = session.permissionLevel; + this.wharfKitSession = session; + this.authorization = [{ actor: this.actor, permission: this.permission }]; + this._vAccount = vAccount; + } + + public transact = async (args: TransactArgs): Promise => { + // Start the transaction + const transaction = await this.wharfKitSession.transact({ + ...args, + }); + + //wait for TX to be IN BLOCK + await waitForTransaction( + transaction.response?.transaction_id, + this.wharfKitSession.client.v1.chain, + TxState.IN_BLOCK, + ); + + return transaction; + }; } From b63f1650727d7e5a6e9b860a83ddcf91ad72506f Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 2 May 2024 19:54:31 -0400 Subject: [PATCH 04/84] Add transfer.test.ts --- src/actions/vaccount/transfer.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/actions/vaccount/transfer.test.ts diff --git a/src/actions/vaccount/transfer.test.ts b/src/actions/vaccount/transfer.test.ts new file mode 100644 index 00000000..7721d85a --- /dev/null +++ b/src/actions/vaccount/transfer.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, test } from "bun:test"; +import { testClientSession, destructureEnv } from "../../../test/src/utils"; +import { vTransfer } from "./transfer"; +import { jungle4 } from "../../exports"; + +describe("vTransfer", () => { + test("throws an error if session is not set", async () => { + const { network } = destructureEnv(jungle4); + const client = await testClientSession({ network }); + const from_id = 1; + const to_id = 2; + const quantity = 0.0001; + expect(async () => { + await vTransfer({ client, from_id, to_id, quantity }); + }).toThrow(); + }); +}); From cd28d057bc60fc89ea4d5639cd4da9e4917a76e2 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 3 May 2024 00:19:24 -0400 Subject: [PATCH 05/84] Fix quantity type for transfer method --- src/actions/vaccount/transfer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/vaccount/transfer.ts b/src/actions/vaccount/transfer.ts index a31cb289..96493479 100644 --- a/src/actions/vaccount/transfer.ts +++ b/src/actions/vaccount/transfer.ts @@ -1,4 +1,4 @@ -import type { AnyAction } from "@wharfkit/antelope"; +import { Asset, type AnyAction } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { SessionNotFoundError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; @@ -32,7 +32,7 @@ export const vTransferAction = ({ from_id, to_id, quantity: { - quantity: quantity, + quantity: Asset.from(quantity, "4,EFX"), contract: token, }, memo: "", From 16ebdec05f1b5c81ac0e760557b10f832f782da0 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 3 May 2024 00:19:40 -0400 Subject: [PATCH 06/84] Add transfer.test.ts --- src/actions/vaccount/transfer.test.ts | 60 +++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/actions/vaccount/transfer.test.ts b/src/actions/vaccount/transfer.test.ts index 7721d85a..f6fc809b 100644 --- a/src/actions/vaccount/transfer.test.ts +++ b/src/actions/vaccount/transfer.test.ts @@ -1,17 +1,63 @@ -import { describe, expect, test } from "bun:test"; +import { describe, expect, test, beforeAll } from "bun:test"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; import { vTransfer } from "./transfer"; -import { jungle4 } from "../../exports"; +import { type Client, jungle4 } from "../../exports"; +import { getOrCreateVAccount } from "./getOrCreate"; +import { Asset, Name } from "@wharfkit/antelope"; describe("vTransfer", () => { + const { network, actor } = destructureEnv(jungle4); + const receiver = Name.from("vibrantcacti"); + let client: Client; + const from_id = 1; + const to_id = 2; + const quantity = 0.0001; + + beforeAll(async () => { + client = await testClientSession({ network }); + }); + test("throws an error if session is not set", async () => { - const { network } = destructureEnv(jungle4); - const client = await testClientSession({ network }); - const from_id = 1; - const to_id = 2; - const quantity = 0.0001; expect(async () => { await vTransfer({ client, from_id, to_id, quantity }); }).toThrow(); }); + + test.skip("Should return txResult, when sending 0.0001 EFX", async () => { + const accountName = Name.from(actor); + const vAccount = await getOrCreateVAccount({ client, actor: accountName }); + const preBalanceVAccount = Number(vAccount.balance.quantity); + + const vAccountReceiver = await getOrCreateVAccount({ + client, + actor: receiver, + }); + const preBalanceReceiver = Number(vAccountReceiver.balance.quantity); + + const result = await vTransfer({ + client, + from_id: vAccount.id, + to_id: vAccountReceiver.id, + quantity, + }); + + expect(result).toBeDefined(); + + const postVAccount = await getOrCreateVAccount({ + client, + actor: accountName, + }); + + const postVAccountReceiver = await getOrCreateVAccount({ + client, + actor: receiver, + }); + + const postbalanceReceiver = Number(postVAccountReceiver.balance.quantity); + const postbalance = Number(postVAccount.balance.quantity); + + // Make sure the balance is updated + expect(postbalance).toBe(preBalanceVAccount - quantity); + expect(postbalanceReceiver).toBe(preBalanceReceiver + quantity); + }); }); From 8b37f7e05f4f5650dc17851dd31ae3cbea6a8ebb Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 3 May 2024 15:08:38 -0400 Subject: [PATCH 07/84] Add getPendingPayments.test.ts --- .../vaccount/getPendingPayments.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/actions/vaccount/getPendingPayments.test.ts diff --git a/src/actions/vaccount/getPendingPayments.test.ts b/src/actions/vaccount/getPendingPayments.test.ts new file mode 100644 index 00000000..ab69692e --- /dev/null +++ b/src/actions/vaccount/getPendingPayments.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, test, beforeAll } from "bun:test"; +import { testClientSession, destructureEnv } from "../../../test/src/utils"; +import { getPendingPayments } from "./getPendingPayments"; +import { jungle4 } from "../../exports"; +import { getOrCreateVAccount } from "./getOrCreate"; +import { Name } from "@wharfkit/antelope"; + +describe("getPendingPayments", () => { + const pendingPaymentsExample = { + pendingPayments: [], + claimablePayments: [], + totalEfxPending: 0, + totalEfxClaimable: 0, + }; + test("getPendingPayments() returns pendingPayments", async () => { + const { network, actor: accountName } = destructureEnv(jungle4); + const actor = Name.from(accountName); + const client = await testClientSession({ network }); + const vaccount = await getOrCreateVAccount({ client, actor }); + const vAccountId = Number(vaccount.id); + const pendingPayments = await getPendingPayments({ client, vAccountId }); + expect(pendingPayments).toBeDefined(); + expect(pendingPayments).toMatchObject(pendingPaymentsExample); + }); +}); From e241a622e31a238f80d883769cdf10e0a01a7167 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 3 May 2024 22:43:37 -0400 Subject: [PATCH 08/84] Recreate src/ structure as docs --- .../docs/tasks/campaigns/createCampaign.mdx | 36 ++++ .../docs/tasks/campaigns/getAllCampaigns.mdx | 0 .../docs/tasks/campaigns/getCampaignById.mdx | 0 .../docs/tasks/campaigns/getCampaigns.mdx | 99 ++++++++--- docs/pages/docs/tasks/getAccTaskIdx.mdx | 0 docs/pages/docs/tasks/getRepetions.mdx | 0 docs/pages/docs/tasks/getSubmissions.mdx | 0 docs/pages/docs/tasks/getTask.mdx | 0 .../docs/tasks/reservations/reserveTask.mdx | 0 docs/pages/docs/tasks/submitTask.mdx | 0 docs/pages/docs/token/getBalance.mdx | 0 docs/pages/docs/token/swap.ts | 0 docs/pages/docs/token/transfer.mdx | 166 ++++++++++++++++++ docs/pages/docs/vaccount/claim.mdx | 0 docs/pages/docs/vaccount/createAccount.mdx | 0 docs/pages/docs/vaccount/getAccounts.mdx | 0 docs/pages/docs/vaccount/getAvatar.mdx | 0 docs/pages/docs/vaccount/getOrCreate.mdx | 0 .../docs/vaccount/getPendingPayments.mdx | 0 docs/pages/docs/vaccount/payout.mdx | 0 docs/pages/docs/vaccount/transfer.mdx | 0 docs/pages/docs/vaccount/withdraw.mdx | 0 22 files changed, 280 insertions(+), 21 deletions(-) create mode 100644 docs/pages/docs/tasks/campaigns/createCampaign.mdx create mode 100644 docs/pages/docs/tasks/campaigns/getAllCampaigns.mdx create mode 100644 docs/pages/docs/tasks/campaigns/getCampaignById.mdx create mode 100644 docs/pages/docs/tasks/getAccTaskIdx.mdx create mode 100644 docs/pages/docs/tasks/getRepetions.mdx create mode 100644 docs/pages/docs/tasks/getSubmissions.mdx create mode 100644 docs/pages/docs/tasks/getTask.mdx create mode 100644 docs/pages/docs/tasks/reservations/reserveTask.mdx create mode 100644 docs/pages/docs/tasks/submitTask.mdx create mode 100644 docs/pages/docs/token/getBalance.mdx create mode 100644 docs/pages/docs/token/swap.ts create mode 100644 docs/pages/docs/token/transfer.mdx create mode 100644 docs/pages/docs/vaccount/claim.mdx create mode 100644 docs/pages/docs/vaccount/createAccount.mdx create mode 100644 docs/pages/docs/vaccount/getAccounts.mdx create mode 100644 docs/pages/docs/vaccount/getAvatar.mdx create mode 100644 docs/pages/docs/vaccount/getOrCreate.mdx create mode 100644 docs/pages/docs/vaccount/getPendingPayments.mdx create mode 100644 docs/pages/docs/vaccount/payout.mdx create mode 100644 docs/pages/docs/vaccount/transfer.mdx create mode 100644 docs/pages/docs/vaccount/withdraw.mdx diff --git a/docs/pages/docs/tasks/campaigns/createCampaign.mdx b/docs/pages/docs/tasks/campaigns/createCampaign.mdx new file mode 100644 index 00000000..9b00f9a5 --- /dev/null +++ b/docs/pages/docs/tasks/campaigns/createCampaign.mdx @@ -0,0 +1,36 @@ +# Get Campaigns [Queries the Effect SDK API for a list of campaigns.] + +## Usage + +```ts [example.ts] +import { getCampaigns } from '@effectai/effect-js' + +const campaigns = await getCampaigns({ // [!code focus] + client, + limit: 10, + page: 1 +}); +``` + +## Returns + +- **Type:** [`Promise>`](/docs/glossary/types#campaign) +- **Description:** A list of campaigns. +- **Properties:** + - **rows:** An array of campaigns. + - **more:** A boolean indicating if there are more campaigns to fetch. + - **next_key:** A string that can be used to fetch the next page of campaigns. + +## Parameters + +### client +- **Type:** `Client` + +### limit (optional) +- **Type:** `number` +- **Default:** `10` + +### page (optional) +- **Type:** `number` +- **Default:** `1` + diff --git a/docs/pages/docs/tasks/campaigns/getAllCampaigns.mdx b/docs/pages/docs/tasks/campaigns/getAllCampaigns.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/campaigns/getCampaignById.mdx b/docs/pages/docs/tasks/campaigns/getCampaignById.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx index 9b00f9a5..7e646fe1 100644 --- a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx +++ b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx @@ -1,36 +1,93 @@ -# Get Campaigns [Queries the Effect SDK API for a list of campaigns.] + +```ts +# Function Template + +## Description + +This function retrieves campaigns from a specified client with optional parameters for pagination, sorting, and IPFS fetching. ## Usage -```ts [example.ts] -import { getCampaigns } from '@effectai/effect-js' +```ts +import { createClient, getCampaigns, jungle4 } from "@effectai/sdk" -const campaigns = await getCampaigns({ // [!code focus] - client, - limit: 10, - page: 1 -}); -``` +const client = createCllient({ network: jungle4 }); +const campaigns = await getCampaigns({ client }); +console.log(campaigns); -## Returns +/** + * Output: + *{ + * rows: [ + * { + * id: 0, + * reservations_done: 2, + * total_submissions: 2, + * total_tasks: 6, + * active_batch: 0, + * num_batches: 2, + * owner: [ "name", "efxefxefxefx" ], + * paused: 0, + * content: [Object ...], + * max_task_time: 3600, + * reward: [Object ...], + * qualis: [], + * info: [Object ...], + * }, { */ ... /* }, { */ ... /* } + * ], + * next_key: UInt128 { + * ... + * }, + * more: true, + *} + */ + + +``` -- **Type:** [`Promise>`](/docs/glossary/types#campaign) -- **Description:** A list of campaigns. -- **Properties:** - - **rows:** An array of campaigns. - - **more:** A boolean indicating if there are more campaigns to fetch. - - **next_key:** A string that can be used to fetch the next page of campaigns. ## Parameters ### client -- **Type:** `Client` +- **Type:** `SomeClient` +- **Description:** The client used to retrieve campaigns. -### limit (optional) +### page - **Type:** `number` -- **Default:** `10` +- **Description:** The page number of the campaigns to retrieve. Default is 1. -### page (optional) +### limit - **Type:** `number` -- **Default:** `1` +- **Description:** The maximum number of campaigns to retrieve per page. Default is 20. + +### reverse +- **Type:** `boolean` +- **Description:** Whether to reverse the order of the retrieved campaigns. Default is false. + +### ipfsFetch +- **Type:** `boolean` +- **Description:** Whether to fetch additional information from IPFS for each campaign. Default is true. +``` + + +## Returns +- **Type:** [`Promise>`](/docs/glossary/types#campaign) +- **Description:** A list of campaigns. +- **Properties:** + - **rows:** An array of campaigns with the following structure: + - **id:** Campaign ID. + - **reservations_done:** Number of reservations done for the campaign. + - **total_submissions:** Total number of submissions for the campaign. + - **total_tasks:** Total number of tasks in the campaign. + - **active_batch:** Active batch number. + - **num_batches:** Total number of batches. + - **owner:** Owner of the campaign. + - **paused:** Indicator if the campaign is paused. + - **content:** Campaign content. + - **max_task_time:** Maximum task time in seconds. + - **reward:** Reward information. + - **qualis:** Qualification information. + - **info:** Additional information retrieved from IPFS if enabled. + - **next_key:** A string that can be used to fetch the next page of campaigns. + - **more:** A boolean indicating if there are more campaigns to fetch. diff --git a/docs/pages/docs/tasks/getAccTaskIdx.mdx b/docs/pages/docs/tasks/getAccTaskIdx.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/getRepetions.mdx b/docs/pages/docs/tasks/getRepetions.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/getSubmissions.mdx b/docs/pages/docs/tasks/getSubmissions.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/getTask.mdx b/docs/pages/docs/tasks/getTask.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/reservations/reserveTask.mdx b/docs/pages/docs/tasks/reservations/reserveTask.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/tasks/submitTask.mdx b/docs/pages/docs/tasks/submitTask.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/token/getBalance.mdx b/docs/pages/docs/token/getBalance.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/token/swap.ts b/docs/pages/docs/token/swap.ts new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/token/transfer.mdx b/docs/pages/docs/token/transfer.mdx new file mode 100644 index 00000000..74aa7bd4 --- /dev/null +++ b/docs/pages/docs/token/transfer.mdx @@ -0,0 +1,166 @@ + +# VTransfer + +## Description + +Transfer EFX tokens from one vAccount to another. + +## Usage + +```ts [example.ts] +import { getCampaigns } from '@effectai/effect-js' + +const campaigns = await getCampaigns({ // [!code focus] + client, + limit: 10, + page: 1 +}); +``` + +## Returns + +- **Type:** [`Promise>`](/docs/glossary/types#campaign) +- **Description:** A list of campaigns. +- **Properties:** + - **rows:** An array of campaigns. + - **more:** A boolean indicating if there are more campaigns to fetch. + - **next_key:** A string that can be used to fetch the next page of campaigns. + +## Parameters + +### client +- **Type:** `Client` + +### limit (optional) +- **Type:** `number` +- **Default:** `10` + +### page (optional) +- **Type:** `number` +- **Default:** `1` + +```json + // Response + response: { + transaction_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + processed: { + id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + receipt: { + status: "executed", + cpu_usage_us: 207, + net_usage_words: 16, + }, + elapsed: 207, + net_usage: 128, + scheduled: false, + action_traces: [ + { + action_ordinal: 1, + creator_action_ordinal: 0, + closest_unnotified_ancestor_action_ordinal: 0, + receipt: { + receiver: "efxaccount11", + act_digest: "d6f9be5af2565060d572a08f6e5f75498ea4c6a3d2cf77e26f3e3ffff4b6e244", + global_sequence: 196109234, + recv_sequence: 387, + auth_sequence: [ + [ "forcedev1234", 32 ] + ], + code_sequence: 8, + abi_sequence: 15, + }, + receiver: "efxaccount11", + act: { + account: "efxaccount11", + name: "vtransfer", + authorization: [ + { + actor: "forcedev1234", + permission: "active", + } + ], + data: { + from_id: 24, + to_id: 3, + quantity: { + quantity: "0.0001 EFX", + contract: "efxtoken1112", + }, + memo: "", + sig: null, + fee: null, + }, + hex_data: "180000000000000003000000000000000100000000000000044546580000000020420853419afb52000000", + }, + context_free: false, + elapsed: 76, + console: "", + trx_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + account_ram_deltas: [], + except: null, + error_code: null, + return_value_hex_data: "", + }, { + action_ordinal: 2, + creator_action_ordinal: 1, + closest_unnotified_ancestor_action_ordinal: 1, + receipt: { + receiver: "vibrantcacti", + act_digest: "d6f9be5af2565060d572a08f6e5f75498ea4c6a3d2cf77e26f3e3ffff4b6e244", + global_sequence: 196109235, + recv_sequence: 69, + auth_sequence: [ + [ "forcedev1234", 33 ] + ], + code_sequence: 8, + abi_sequence: 15, + }, + receiver: "vibrantcacti", + act: { + account: "efxaccount11", + name: "vtransfer", + authorization: [ + { + actor: "forcedev1234", + permission: "active", + } + ], + data: { + from_id: 24, + to_id: 3, + quantity: { + quantity: "0.0001 EFX", + contract: "efxtoken1112", + }, + memo: "", + sig: null, + fee: null, + }, + hex_data: "180000000000000003000000000000000100000000000000044546580000000020420853419afb52000000", + }, + context_free: false, + elapsed: 5, + console: "", + trx_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + account_ram_deltas: [], + except: null, + error_code: null, + return_value_hex_data: "", + } + ], + account_ram_delta: null, + except: null, + error_code: null, + }, + }, +} +``` diff --git a/docs/pages/docs/vaccount/claim.mdx b/docs/pages/docs/vaccount/claim.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/createAccount.mdx b/docs/pages/docs/vaccount/createAccount.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/getAccounts.mdx b/docs/pages/docs/vaccount/getAccounts.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/getAvatar.mdx b/docs/pages/docs/vaccount/getAvatar.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/getOrCreate.mdx b/docs/pages/docs/vaccount/getOrCreate.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/getPendingPayments.mdx b/docs/pages/docs/vaccount/getPendingPayments.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/payout.mdx b/docs/pages/docs/vaccount/payout.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/transfer.mdx b/docs/pages/docs/vaccount/transfer.mdx new file mode 100644 index 00000000..e69de29b diff --git a/docs/pages/docs/vaccount/withdraw.mdx b/docs/pages/docs/vaccount/withdraw.mdx new file mode 100644 index 00000000..e69de29b From 329a1eac010d69b5417478157bba5fca58896a6f Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 3 May 2024 22:45:14 -0400 Subject: [PATCH 09/84] Rename env vars --- src/client.test.ts | 27 +++++++++++++-------------- test/src/utils.ts | 24 +++++++++++------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/client.test.ts b/src/client.test.ts index c86f7081..0f7820fb 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -1,13 +1,12 @@ -import { expect, test, describe, beforeAll } from "bun:test"; -import { jungle4, eos } from "../src/exports"; -import { createClient, Client as ClientConstructor } from "./client"; +import { expect, test, describe } from "bun:test"; +import { createClient } from "./client"; import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; import { destructureEnv } from "../test/src/utils"; import { Session } from "@wharfkit/session"; describe("Client", async () => { - test("Create client with Session", async () => { - const { network, permission, actor, privateKey } = destructureEnv(); + test("Create client with Session", async () => { + const { network: chain, permission, actor, privateKey } = destructureEnv(); // Create wallet with privatekey const walletPlugin = new WalletPluginPrivateKey(privateKey); @@ -15,14 +14,14 @@ describe("Client", async () => { // Set up session with wallet const session = new Session({ actor, permission, walletPlugin, chain }); - const client = createClient({ session }); - expect(client.session).toBeDefined(); - expect(client.network.id).toBe(network.id); - }); + const client = createClient({ session }); + expect(client.session).toBeDefined(); + expect(client.network.id).toBe(chain.id); + }); - test("Create client with Network", async () => { - const { network } = destructureEnv(); - const client = createClient({ network }); - expect(client.session).toBeDefined(); - }); + test("Create client with Network", async () => { + const { network } = destructureEnv(); + const client = createClient({ network }); + expect(client.session).toBeDefined(); + }); }); diff --git a/test/src/utils.ts b/test/src/utils.ts index 82be6d93..44af7fe3 100644 --- a/test/src/utils.ts +++ b/test/src/utils.ts @@ -5,7 +5,7 @@ import { PermissionLevel, } from "@wharfkit/session"; import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; -import { jungle4, eos } from "../../src/exports"; +import { jungle4, } from "../../src/exports"; import { createClient } from "../../src/client"; import type { Client } from "../../src/client"; import type { Network } from "../../src/types/network"; @@ -32,20 +32,18 @@ export interface testEnv { } export const destructureEnv = () => { - return { - network: jungle4, - networkName: process.env.NETWORK_NAME, - permission: process.env.PERMISSION!, - actor: process.env.ACTOR!, - privateKey: PrivateKey.from(process.env.PRIVATE_KEY!), - }; + return { + network: jungle4, + networkName: process.env.TESTNET_NETWORK_NAME, + permission: process.env.TESTNET_PERMISSION!, + actor: process.env.TESTNET_ACTOR!, + privateKey: PrivateKey.from(process.env.TESTNET_PRIVATE_KEY!), + }; }; -export const testClientSession = async ({ - testEnvNetwork, -}: { testEnvNetwork: Network }): Promise => { - // Retrieve parameters for session. - const { network, permission, actor, privateKey } = destructureEnv(); +export const testClientSession = async ({ network }: { network: Network }): Promise => { + // Retrieve parameters for session. + const { network: chain, permission, actor, privateKey } = destructureEnv(); if (!privateKey) { throw new Error("Private key not found"); From af367253433a358ab0316618722fa55b489e2368 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sat, 4 May 2024 20:52:04 -0400 Subject: [PATCH 10/84] clean up camapigns docs --- docs/pages/docs/tasks/campaigns/getCampaigns.mdx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx index 7e646fe1..e412804e 100644 --- a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx +++ b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx @@ -33,11 +33,9 @@ console.log(campaigns); * reward: [Object ...], * qualis: [], * info: [Object ...], - * }, { */ ... /* }, { */ ... /* } + * }, { */ ... /* }, { */ ... /* } * ], - * next_key: UInt128 { - * ... - * }, + * next_key: UInt128 { */ ... /* }, * more: true, *} */ From 631a7035e6938293e054e73096e07c2a1528f5eb Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 6 May 2024 01:08:01 -0400 Subject: [PATCH 11/84] Add createCampaign, getCampaignById and getCamapigns docs --- .../docs/tasks/campaigns/createCampaign.mdx | 115 ++++++++++++++---- .../docs/tasks/campaigns/getCampaignById.mdx | 85 +++++++++++++ .../docs/tasks/campaigns/getCampaigns.mdx | 56 ++++----- 3 files changed, 203 insertions(+), 53 deletions(-) diff --git a/docs/pages/docs/tasks/campaigns/createCampaign.mdx b/docs/pages/docs/tasks/campaigns/createCampaign.mdx index 9b00f9a5..c6e3fd5f 100644 --- a/docs/pages/docs/tasks/campaigns/createCampaign.mdx +++ b/docs/pages/docs/tasks/campaigns/createCampaign.mdx @@ -1,36 +1,105 @@ -# Get Campaigns [Queries the Effect SDK API for a list of campaigns.] +# createCampaign + +## Description + +This function creates a campaign from a specified client with the given campaign parameters. +You can view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data, +you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide. ## Usage -```ts [example.ts] -import { getCampaigns } from '@effectai/effect-js' +```ts +import { + createCampaign, + CreateCampaignArgs, + createClient +} from '@effectai/sdk' -const campaigns = await getCampaigns({ // [!code focus] - client, - limit: 10, - page: 1 -}); -``` +const myNewCampaign: CreateCampaignArgs["campaign"] = { + version: 1.0, + maxTaskTime: 100, + reward: 3.5, + title: "Labelstudio OCR (LAION)", + description: "You are contributing to a dataset for conversational style chatbots.", + instructions: "Some instructions here", + template: "

Template here

", + input_schema: null, + output_schema: null, + image: "", + category: "", + example_task: "", + estimated_time: 10, +}; -## Returns +const client = await createClient({ network: jungle4 }); +const result = await createCampaign({ client, campaign: myNewCampaign }); +``` -- **Type:** [`Promise>`](/docs/glossary/types#campaign) -- **Description:** A list of campaigns. -- **Properties:** - - **rows:** An array of campaigns. - - **more:** A boolean indicating if there are more campaigns to fetch. - - **next_key:** A string that can be used to fetch the next page of campaigns. +## Output +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` ## Parameters + ### client -- **Type:** `Client` +- **Type:** `SomeClient` +- **Description:** The client used to retrieve campaigns. + +### CreateCampaignArgs["campaign"] +- **version**: Version number of the campaign +- **maxTaskTime**: Time maximum time in seconds for the task +- **reward**: Reward for each task in EFX +- **title**: Title of the campaign +- **description**: Description of the campaign +- **instructions**: Instructions for the campaign +- **template**: Template for the campaign, which is a string of HTML +- **input_schema**: JSON schema for each input task +- **output_schema**: JSON schema for each output task +- **image**: Image URL for the campaign +- **category**: Category of the campaign +- **example_task**: An example_task for the campaign, this should be data that will be input into the campaign +- **estimated_time**: Estimated time in seconds for the task + +## Returns + +**Type:** [`Promise`](/docs/glossary/types#transaction_result) -### limit (optional) -- **Type:** `number` -- **Default:** `10` +**Description:** Transaction result object that contains the transaction id and the processed transaction. -### page (optional) -- **Type:** `number` -- **Default:** `1` +**Properties:** +- **response**: Object +- **transaction_id**: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + - **processed**: + - **id**: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + - **block_num**: 137520447, + - **block_time**: "2024-05-01T03:55:31.500", + - **producer_block_id**: null, + - **receipt**: [Object ...], + - **elapsed**: 4854, + - **net_usage**: 176, + - **scheduled**: false, + - **action_traces**: [ [Object ...] ], + - **account_ram_delta**: null, + - **except**: null, + - **error_code**: null, diff --git a/docs/pages/docs/tasks/campaigns/getCampaignById.mdx b/docs/pages/docs/tasks/campaigns/getCampaignById.mdx index e69de29b..f04f4413 100644 --- a/docs/pages/docs/tasks/campaigns/getCampaignById.mdx +++ b/docs/pages/docs/tasks/campaigns/getCampaignById.mdx @@ -0,0 +1,85 @@ + +# getCampaignById + +## Description + +This function retrieves a campaign from a specified client with the given ID. + +## Usage + +```ts +import { createClient, getCampaignById, jungle4 } from "@effectai/sdk" + +const client = createClient({ network: jungle4 }); +const id = 1; +const campaign = await getCampaignById({ client, id }); +``` + +## Output + +```json +{ + id: 1, + reservations_done: 1, + total_submissions: 2, + total_tasks: 1, + active_batch: 1, + num_batches: 1, + owner: [ "name", "efxefxefxefx" ], + paused: 0, + content: { + field_0: 0, + field_1: "QmVKwq3bYM6cPW6kstpiq4WYckWRtdfJnzAmms2iMyGqQg", + }, + max_task_time: 3600, + reward: { + quantity: "0.0100 EFX", + contract: "efxtoken1112", + }, + qualis: [], + info: { + version: 1.1, + title: "Labelstudio OCR (LAION)", + description: "You are contributing to a dataset for conversational style chatbots.", + instructions: "Instructions here...", + template: "

Template here...

", + input_schema: null, + output_schema: null, + image: null, + category: null, + example_task: null, + estimated_time: null, + }, +} +``` +## Parameters + +### client +- **Type:** `SomeClient` +- **Description:** The client used to retrieve campaigns. + +### id +- **Type:** `number` +- **Description:** The campaign id number of the campaign to retrieve. + +## Returns + +**Type:** [`Promise`](/docs/glossary/types#campaign) + +**Description:** A list of campaigns. + +**Properties:** + +- **id:** Campaign ID. +- **reservations_done:** Number of reservations done for the campaign. +- **total_submissions:** Total number of submissions for the campaign. +- **total_tasks:** Total number of tasks in the campaign. +- **active_batch:** Active batch number. +- **num_batches:** Total number of batches. +- **owner:** Owner of the campaign. +- **paused:** Indicator if the campaign is paused. +- **content:** Campaign content. +- **max_task_time:** Maximum task time in seconds. +- **reward:** Reward information. +- **qualis:** Qualification information. +- **info:** Additional information retrieved from IPFS. diff --git a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx index e412804e..6bab9762 100644 --- a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx +++ b/docs/pages/docs/tasks/campaigns/getCampaigns.mdx @@ -1,6 +1,4 @@ - -```ts -# Function Template +# getCampaigns ## Description @@ -14,33 +12,32 @@ import { createClient, getCampaigns, jungle4 } from "@effectai/sdk" const client = createCllient({ network: jungle4 }); const campaigns = await getCampaigns({ client }); console.log(campaigns); +``` -/** - * Output: - *{ - * rows: [ - * { - * id: 0, - * reservations_done: 2, - * total_submissions: 2, - * total_tasks: 6, - * active_batch: 0, - * num_batches: 2, - * owner: [ "name", "efxefxefxefx" ], - * paused: 0, - * content: [Object ...], - * max_task_time: 3600, - * reward: [Object ...], - * qualis: [], - * info: [Object ...], - * }, { */ ... /* }, { */ ... /* } - * ], - * next_key: UInt128 { */ ... /* }, - * more: true, - *} - */ - - +## Output + +```json +{ + rows: [ + { + id: 0, + reservations_done: 2, + total_submissions: 2, + total_tasks: 6, + active_batch: 0, + num_batches: 2, + owner: [ "name", "efxefxefxefx" ], + paused: 0, + content: [Object ...], + max_task_time: 3600, + reward: [Object ...], + qualis: [], + info: [Object ...], + }, { */ ... /* }, { */ ... /* } + ], + next_key: UInt128 { */ ... /* }, + more: true, +} ``` @@ -65,7 +62,6 @@ console.log(campaigns); ### ipfsFetch - **Type:** `boolean` - **Description:** Whether to fetch additional information from IPFS for each campaign. Default is true. -``` ## Returns From 4288a667797e8ed6530056e273310318c7561c64 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 11:05:11 -0400 Subject: [PATCH 12/84] Update biome json to include docs/ --- biome.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/biome.json b/biome.json index be2e07dd..a2258812 100644 --- a/biome.json +++ b/biome.json @@ -5,10 +5,17 @@ }, "formatter": { "enabled": true, - "ignore": ["dist", "test", "docs"] + "ignore": [ + "dist", + "test" + ] }, "linter": { - "ignore": ["dist", "test", "scripts", "docs"], + "ignore": [ + "dist", + "test", + "scripts" + ], "enabled": true, "rules": { "recommended": true From 0a4411a96245717b2038662b76d26821741e89d1 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 11:05:43 -0400 Subject: [PATCH 13/84] Update sidebar with sdk api items --- docs/sidebar.ts | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 6f1859d3..cf123999 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -13,10 +13,7 @@ export const sidebar = { { text: "Collecting Data", items: [ - { - text: "Introduction", - link: "/docs/collecting-data/introduction", - }, + { text: "Introduction", link: "/docs/collecting-data/introduction" }, { text: "Creating a Template", link: "/docs/collecting-data/create-a-template", @@ -38,17 +35,56 @@ export const sidebar = { { text: "SDK API", items: [ + { + text: "vAccount", + items: [ + { text: "TODO: claim", link: "/docs/tasks/vaccount/claim" }, + { + text: "TODO: createAccount", + link: "/docs/tasks/vaccount/createAccount", + }, + { text: "TODO: deposit", link: "/docs/tasks/vaccount/deposit" }, + { + text: "TODO: getAccounts", + link: "/docs/tasks/vaccount/getAccounts", + }, + { text: "TODO: getAvatar", link: "/docs/tasks/vaccount/getAvatar" }, + { + text: "TODO: getOrCreate", + link: "/docs/tasks/vaccount/getOrCreate", + }, + { + text: "TODO: getPendingPayments", + link: "/docs/tasks/vaccount/getPendingPayments", + }, + { text: "TODO: payout", link: "/docs/tasks/vaccount/payout" }, + { text: "TODO: transfer", link: "/docs/tasks/vaccount/transfer" }, + { text: "TODO: withdraw", link: "/docs/tasks/vaccount/withdraw" }, + ], + }, { text: "Token", - items: [{ link: "/docs/token/getPrice", text: "getPrice" }], + items: [ + { text: "TODO: getPrice", link: "/docs/tasks/token/getPrice" }, + { text: "TODO: getBalance", link: "/docs/tasks/token/getBalance" }, + { text: "TODO: swap", link: "/docs/tasks/token/swap" }, + ], }, { text: "Tasks", items: [ + { + text: "TODO: createCampaign", + link: "/docs/tasks/campaigns/createCampaign", + }, { text: "getCampaigns", link: "/docs/tasks/campaigns/getCampaigns", }, + { + text: "getCampaignById", + link: "/docs/tasks/campaigns/getCampaignById", + }, ], }, ], From 80d1a0d0f267985e4e8f134c1078998144a98041 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 11:33:33 -0400 Subject: [PATCH 14/84] Use kebab case for files in pages/ --- .../pages/docs/glossary/{clientOptions.mdx => client-options.mdx} | 0 .../docs/tasks/batches/{createBatch.mdx => create-batch.mdx} | 0 docs/pages/docs/tasks/batches/{getBatch.mdx => get-batch.mdx} | 0 .../tasks/campaigns/{createCampaign.mdx => create-campaign.mdx} | 0 .../campaigns/{getAllCampaigns.mdx => get-all-campaigns.mdx} | 0 .../campaigns/{getCampaignById.mdx => get-campaign-by-id.mdx} | 0 .../docs/tasks/campaigns/{getCampaigns.mdx => get-campaigns.mdx} | 0 docs/pages/docs/tasks/{getAccTaskIdx.mdx => get-acc-task-idx.mdx} | 0 docs/pages/docs/tasks/{getRepetions.mdx => get-repetions.mdx} | 0 docs/pages/docs/tasks/{getSubmissions.mdx => get-submissions.mdx} | 0 docs/pages/docs/tasks/{getTask.mdx => get-task.mdx} | 0 .../reservations/{getReservations.mdx => get-reservations.mdx} | 0 .../docs/tasks/reservations/{reserveTask.mdx => reserve-task.mdx} | 0 docs/pages/docs/tasks/{submitTask.mdx => submit-task.mdx} | 0 docs/pages/docs/token/{getBalance.mdx => get-balance.mdx} | 0 docs/pages/docs/token/{getPrice.mdx => get-price.mdx} | 0 .../pages/docs/vaccount/{createAccount.mdx => create-account.mdx} | 0 docs/pages/docs/vaccount/{getAccounts.mdx => get-accounts.mdx} | 0 docs/pages/docs/vaccount/{getAvatar.mdx => get-avatar.mdx} | 0 docs/pages/docs/vaccount/{getOrCreate.mdx => get-or-create.mdx} | 0 .../vaccount/{getPendingPayments.mdx => get-pending-payments.mdx} | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename docs/pages/docs/glossary/{clientOptions.mdx => client-options.mdx} (100%) rename docs/pages/docs/tasks/batches/{createBatch.mdx => create-batch.mdx} (100%) rename docs/pages/docs/tasks/batches/{getBatch.mdx => get-batch.mdx} (100%) rename docs/pages/docs/tasks/campaigns/{createCampaign.mdx => create-campaign.mdx} (100%) rename docs/pages/docs/tasks/campaigns/{getAllCampaigns.mdx => get-all-campaigns.mdx} (100%) rename docs/pages/docs/tasks/campaigns/{getCampaignById.mdx => get-campaign-by-id.mdx} (100%) rename docs/pages/docs/tasks/campaigns/{getCampaigns.mdx => get-campaigns.mdx} (100%) rename docs/pages/docs/tasks/{getAccTaskIdx.mdx => get-acc-task-idx.mdx} (100%) rename docs/pages/docs/tasks/{getRepetions.mdx => get-repetions.mdx} (100%) rename docs/pages/docs/tasks/{getSubmissions.mdx => get-submissions.mdx} (100%) rename docs/pages/docs/tasks/{getTask.mdx => get-task.mdx} (100%) rename docs/pages/docs/tasks/reservations/{getReservations.mdx => get-reservations.mdx} (100%) rename docs/pages/docs/tasks/reservations/{reserveTask.mdx => reserve-task.mdx} (100%) rename docs/pages/docs/tasks/{submitTask.mdx => submit-task.mdx} (100%) rename docs/pages/docs/token/{getBalance.mdx => get-balance.mdx} (100%) rename docs/pages/docs/token/{getPrice.mdx => get-price.mdx} (100%) rename docs/pages/docs/vaccount/{createAccount.mdx => create-account.mdx} (100%) rename docs/pages/docs/vaccount/{getAccounts.mdx => get-accounts.mdx} (100%) rename docs/pages/docs/vaccount/{getAvatar.mdx => get-avatar.mdx} (100%) rename docs/pages/docs/vaccount/{getOrCreate.mdx => get-or-create.mdx} (100%) rename docs/pages/docs/vaccount/{getPendingPayments.mdx => get-pending-payments.mdx} (100%) diff --git a/docs/pages/docs/glossary/clientOptions.mdx b/docs/pages/docs/glossary/client-options.mdx similarity index 100% rename from docs/pages/docs/glossary/clientOptions.mdx rename to docs/pages/docs/glossary/client-options.mdx diff --git a/docs/pages/docs/tasks/batches/createBatch.mdx b/docs/pages/docs/tasks/batches/create-batch.mdx similarity index 100% rename from docs/pages/docs/tasks/batches/createBatch.mdx rename to docs/pages/docs/tasks/batches/create-batch.mdx diff --git a/docs/pages/docs/tasks/batches/getBatch.mdx b/docs/pages/docs/tasks/batches/get-batch.mdx similarity index 100% rename from docs/pages/docs/tasks/batches/getBatch.mdx rename to docs/pages/docs/tasks/batches/get-batch.mdx diff --git a/docs/pages/docs/tasks/campaigns/createCampaign.mdx b/docs/pages/docs/tasks/campaigns/create-campaign.mdx similarity index 100% rename from docs/pages/docs/tasks/campaigns/createCampaign.mdx rename to docs/pages/docs/tasks/campaigns/create-campaign.mdx diff --git a/docs/pages/docs/tasks/campaigns/getAllCampaigns.mdx b/docs/pages/docs/tasks/campaigns/get-all-campaigns.mdx similarity index 100% rename from docs/pages/docs/tasks/campaigns/getAllCampaigns.mdx rename to docs/pages/docs/tasks/campaigns/get-all-campaigns.mdx diff --git a/docs/pages/docs/tasks/campaigns/getCampaignById.mdx b/docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx similarity index 100% rename from docs/pages/docs/tasks/campaigns/getCampaignById.mdx rename to docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx diff --git a/docs/pages/docs/tasks/campaigns/getCampaigns.mdx b/docs/pages/docs/tasks/campaigns/get-campaigns.mdx similarity index 100% rename from docs/pages/docs/tasks/campaigns/getCampaigns.mdx rename to docs/pages/docs/tasks/campaigns/get-campaigns.mdx diff --git a/docs/pages/docs/tasks/getAccTaskIdx.mdx b/docs/pages/docs/tasks/get-acc-task-idx.mdx similarity index 100% rename from docs/pages/docs/tasks/getAccTaskIdx.mdx rename to docs/pages/docs/tasks/get-acc-task-idx.mdx diff --git a/docs/pages/docs/tasks/getRepetions.mdx b/docs/pages/docs/tasks/get-repetions.mdx similarity index 100% rename from docs/pages/docs/tasks/getRepetions.mdx rename to docs/pages/docs/tasks/get-repetions.mdx diff --git a/docs/pages/docs/tasks/getSubmissions.mdx b/docs/pages/docs/tasks/get-submissions.mdx similarity index 100% rename from docs/pages/docs/tasks/getSubmissions.mdx rename to docs/pages/docs/tasks/get-submissions.mdx diff --git a/docs/pages/docs/tasks/getTask.mdx b/docs/pages/docs/tasks/get-task.mdx similarity index 100% rename from docs/pages/docs/tasks/getTask.mdx rename to docs/pages/docs/tasks/get-task.mdx diff --git a/docs/pages/docs/tasks/reservations/getReservations.mdx b/docs/pages/docs/tasks/reservations/get-reservations.mdx similarity index 100% rename from docs/pages/docs/tasks/reservations/getReservations.mdx rename to docs/pages/docs/tasks/reservations/get-reservations.mdx diff --git a/docs/pages/docs/tasks/reservations/reserveTask.mdx b/docs/pages/docs/tasks/reservations/reserve-task.mdx similarity index 100% rename from docs/pages/docs/tasks/reservations/reserveTask.mdx rename to docs/pages/docs/tasks/reservations/reserve-task.mdx diff --git a/docs/pages/docs/tasks/submitTask.mdx b/docs/pages/docs/tasks/submit-task.mdx similarity index 100% rename from docs/pages/docs/tasks/submitTask.mdx rename to docs/pages/docs/tasks/submit-task.mdx diff --git a/docs/pages/docs/token/getBalance.mdx b/docs/pages/docs/token/get-balance.mdx similarity index 100% rename from docs/pages/docs/token/getBalance.mdx rename to docs/pages/docs/token/get-balance.mdx diff --git a/docs/pages/docs/token/getPrice.mdx b/docs/pages/docs/token/get-price.mdx similarity index 100% rename from docs/pages/docs/token/getPrice.mdx rename to docs/pages/docs/token/get-price.mdx diff --git a/docs/pages/docs/vaccount/createAccount.mdx b/docs/pages/docs/vaccount/create-account.mdx similarity index 100% rename from docs/pages/docs/vaccount/createAccount.mdx rename to docs/pages/docs/vaccount/create-account.mdx diff --git a/docs/pages/docs/vaccount/getAccounts.mdx b/docs/pages/docs/vaccount/get-accounts.mdx similarity index 100% rename from docs/pages/docs/vaccount/getAccounts.mdx rename to docs/pages/docs/vaccount/get-accounts.mdx diff --git a/docs/pages/docs/vaccount/getAvatar.mdx b/docs/pages/docs/vaccount/get-avatar.mdx similarity index 100% rename from docs/pages/docs/vaccount/getAvatar.mdx rename to docs/pages/docs/vaccount/get-avatar.mdx diff --git a/docs/pages/docs/vaccount/getOrCreate.mdx b/docs/pages/docs/vaccount/get-or-create.mdx similarity index 100% rename from docs/pages/docs/vaccount/getOrCreate.mdx rename to docs/pages/docs/vaccount/get-or-create.mdx diff --git a/docs/pages/docs/vaccount/getPendingPayments.mdx b/docs/pages/docs/vaccount/get-pending-payments.mdx similarity index 100% rename from docs/pages/docs/vaccount/getPendingPayments.mdx rename to docs/pages/docs/vaccount/get-pending-payments.mdx From 4ee23ea4564fb374d23181ab84c2c860226d2ec6 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 12:29:58 -0400 Subject: [PATCH 15/84] Use kebab case for sidebar items --- docs/sidebar.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/sidebar.ts b/docs/sidebar.ts index cf123999..397784e1 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -48,14 +48,17 @@ export const sidebar = { text: "TODO: getAccounts", link: "/docs/tasks/vaccount/getAccounts", }, - { text: "TODO: getAvatar", link: "/docs/tasks/vaccount/getAvatar" }, + { + text: "TODO: getAvatar", + link: "/docs/tasks/vaccount/get-avatar", + }, { text: "TODO: getOrCreate", - link: "/docs/tasks/vaccount/getOrCreate", + link: "/docs/tasks/vaccount/get-or-create", }, { text: "TODO: getPendingPayments", - link: "/docs/tasks/vaccount/getPendingPayments", + link: "/docs/tasks/vaccount/get-pending-payments", }, { text: "TODO: payout", link: "/docs/tasks/vaccount/payout" }, { text: "TODO: transfer", link: "/docs/tasks/vaccount/transfer" }, @@ -65,8 +68,8 @@ export const sidebar = { { text: "Token", items: [ - { text: "TODO: getPrice", link: "/docs/tasks/token/getPrice" }, - { text: "TODO: getBalance", link: "/docs/tasks/token/getBalance" }, + { text: "TODO: getPrice", link: "/docs/tasks/token/get-price" }, + { text: "TODO: getBalance", link: "/docs/tasks/token/get-balance" }, { text: "TODO: swap", link: "/docs/tasks/token/swap" }, ], }, @@ -75,15 +78,24 @@ export const sidebar = { items: [ { text: "TODO: createCampaign", - link: "/docs/tasks/campaigns/createCampaign", + link: "/docs/tasks/campaigns/create-campaign", }, { text: "getCampaigns", - link: "/docs/tasks/campaigns/getCampaigns", + link: "/docs/tasks/campaigns/get-campaigns", }, { text: "getCampaignById", - link: "/docs/tasks/campaigns/getCampaignById", + link: "/docs/tasks/campaigns/get-campaign-by-id", + }, + ], + }, + { + text: "DAO", + items: [ + { + text: "TODO: getAccountAssets", + link: "/docs/tasks/dao/get-account-assets", }, ], }, @@ -91,7 +103,9 @@ export const sidebar = { }, { text: "Glossary", - items: [{ text: "Client Options", link: "/docs/glossary/clientOptions" }], + items: [ + { text: "Client Options", link: "/docs/glossary/client-options" }, + ], }, { text: "FAQ", From bb0e4ee2566093479faacdb65899f398e15a6322 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 14:13:02 -0400 Subject: [PATCH 16/84] Update create-campaign docs --- .../docs/tasks/campaigns/create-campaign.mdx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/pages/docs/tasks/campaigns/create-campaign.mdx b/docs/pages/docs/tasks/campaigns/create-campaign.mdx index c6e3fd5f..5930e1e3 100644 --- a/docs/pages/docs/tasks/campaigns/create-campaign.mdx +++ b/docs/pages/docs/tasks/campaigns/create-campaign.mdx @@ -89,17 +89,17 @@ response: { **Properties:** - **response**: Object -- **transaction_id**: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", +- **transaction_id**: Transaction ID of the transaction - **processed**: - - **id**: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", - - **block_num**: 137520447, - - **block_time**: "2024-05-01T03:55:31.500", + - **id**: Id of the transaction + - **block_num**: Number of the block that the transaction was processed in + - **block_time**: Time the block was processed - **producer_block_id**: null, - **receipt**: [Object ...], - - **elapsed**: 4854, - - **net_usage**: 176, - - **scheduled**: false, + - **elapsed**: Time elapsed in milliseconds + - **net_usage**: Net usage of the transaction + - **scheduled**: If the transaction was scheduled - **action_traces**: [ [Object ...] ], - - **account_ram_delta**: null, - - **except**: null, - - **error_code**: null, + - **account_ram_delta**: Amount of RAM used + - **except**: exception message + - **error_code**: Error code if there was an error From b292640f3a6651c70f4939ce62c9a435a5094eff Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 14:39:02 -0400 Subject: [PATCH 17/84] Update getPrice doc --- docs/pages/docs/token/get-price.mdx | 33 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/pages/docs/token/get-price.mdx b/docs/pages/docs/token/get-price.mdx index 0b119e12..1f109b70 100644 --- a/docs/pages/docs/token/get-price.mdx +++ b/docs/pages/docs/token/get-price.mdx @@ -1,10 +1,33 @@ -# Get Price +# getPrice -Get the current price of the EFX token according to DefiBox. +## Description -```typescript -import { getPrice } from '@effectai/effect-js'; +By calling this function, you will get the current price of the EFX token according to DefiBox. +The price is in USDT. The contract can be viewed at the following link: https://www.bloks.io/account/tethertether +It is not needed for this function to connect a client or a session. + +## Usage + +```ts +import { getPrice } from '@effectai/sdk'; const price = await getPrice(); +console.log(price); +``` + +## Output + +``` +0.023399935809187228 +``` +## Parameters + +### N.A. +- **Description:** No parameters required for this function + +## Returns + +**Type:** Number + +**Description:** The current price of the EFX token according to DefiBox in USDT. -``` \ No newline at end of file From 480b62b150b7f1efe85205c80700b81062473463 Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 16:17:38 -0400 Subject: [PATCH 18/84] Add getBalance docs --- docs/pages/docs/token/get-balance.mdx | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index e69de29b..3c609116 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -0,0 +1,45 @@ +# getBalance + +## Description + +This function is used to get the balance of EFX of an Effect Network account. + +## Usage + +```ts +import { createClient, Name, getBalance } from '@effectai/sdk'; + +const client = createClient({ network: jungle4 }); +const actor = Name.from("forcedev1234"); +const balance = await getBalance({ client, actor }); +console.log(balance.toString()); +``` + +## Output + +``` +"100.0000 EFX" +``` +## Parameters + +### Client +- **Type:** `Client` +- **Description:** Client object that is used to interact with the blockchain. + +### Actor + +- **Type:** `Name` +- **Description:** +The account name of the user for which the balance is to be fetched. +Note that the account name is a Name object that is created using the `Name.from` method. + +## Returns + +**Type:** Asset + +**Description:** +Returns the balance of the account in the form of an Asset object. +The asset object has properties that represent the amount and symbol of the balance of the user. +Note that the Asset object has a `toString` method that can be used to convert the balance to a string. + + From 3378384e45718e305f8377ef92f380d2e7bf1ede Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 16:17:38 -0400 Subject: [PATCH 19/84] Add getBalance docs --- docs/pages/docs/token/get-balance.mdx | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index e69de29b..0df9248a 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -0,0 +1,45 @@ +# getBalance + +## Description + +This function is used to get the balance of EFX of an Effect Network account. + +## Usage + +```ts +import { createClient, Name, getBalance, jungle4 } from '@effectai/sdk'; + +const client = createClient({ network: jungle4 }); +const actor = Name.from("forcedev1234"); +const balance = await getBalance({ client, actor }); +console.log(balance.toString()); +``` + +## Output + +``` +"100.0000 EFX" +``` +## Parameters + +### Client +- **Type:** `Client` +- **Description:** Client object that is used to interact with the blockchain. + +### Actor + +- **Type:** `Name` +- **Description:** +The account name of the user for which the balance is to be fetched. +Note that the account name is a Name object that is created using the `Name.from` method. + +## Returns + +**Type:** Asset + +**Description:** +Returns the balance of the account in the form of an Asset object. +The asset object has properties that represent the amount and symbol of the balance of the user. +Note that the Asset object has a `toString` method that can be used to convert the balance to a string. + + From a5ec36bde05f47291b58178ab1cdf7c3ddbf5afa Mon Sep 17 00:00:00 2001 From: David Britt Date: Tue, 7 May 2024 17:40:00 -0400 Subject: [PATCH 20/84] Add swap documentation --- docs/pages/docs/token/swap.mdx | 190 +++++++++++++++++++++++++++++++++ docs/pages/docs/token/swap.ts | 0 2 files changed, 190 insertions(+) create mode 100644 docs/pages/docs/token/swap.mdx delete mode 100644 docs/pages/docs/token/swap.ts diff --git a/docs/pages/docs/token/swap.mdx b/docs/pages/docs/token/swap.mdx new file mode 100644 index 00000000..228037a0 --- /dev/null +++ b/docs/pages/docs/token/swap.mdx @@ -0,0 +1,190 @@ +# swap + +## Description + +This function is used to swap tokens from EFX to USDT or vice versa. +Note that the function requires a client object that is used to interact with the blockchain. +The client object also needs a Session object that is used to sign the transactions. + +Note that the `walletPlugin` object is used to sign the transactions. +The `walletPlugin` object is an instance of the WalletPluginPrivateKey class that is used to sign the transactions using the private key of the user. +Other wallet plugins can be used to sign transactions and can be found at: https://wharfkit.com/plugins + +## Usage + +```ts +import { createClient, Session, swap, eos as chain } from '@effectai/sdk'; +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; + +const walletPlugin = new WalletPluginPrivateKey("your_private_key"); +const actor = "forcedev1234"; +const permission = "active"; + +// Create a session +const session = new Session({ actor, permission, walletPlugin, chain }); + +// Create client and connect session +const client = createClient({ session }); + +// Define the swap arguments +const swapArgs: SwapArgs = { + client, + amount: 4, + direction: "UsdtToEfx", // or "EfxToUsdt" +}; + +// Call the swap function +const response = await swap(swapArgs); +console.log(response); +``` + +## Output + +``` + response: { + transaction_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + processed: { + id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + receipt: { + status: "executed", + cpu_usage_us: 207, + net_usage_words: 16, + }, + elapsed: 207, + net_usage: 128, + scheduled: false, + action_traces: [ + { + action_ordinal: 1, + creator_action_ordinal: 0, + closest_unnotified_ancestor_action_ordinal: 0, + receipt: { + receiver: "efxaccount11", + act_digest: "d6f9be5af2565060d572a08f6e5f75498ea4c6a3d2cf77e26f3e3ffff4b6e244", + global_sequence: 196109234, + recv_sequence: 387, + auth_sequence: [ + [ "forcedev1234", 32 ] + ], + code_sequence: 8, + abi_sequence: 15, + }, + receiver: "efxaccount11", + act: { + account: "efxaccount11", + name: "vtransfer", + authorization: [ + { + actor: "forcedev1234", + permission: "active", + } + ], + data: { + from_id: 24, + to_id: 3, + quantity: { + quantity: "0.0001 EFX", + contract: "efxtoken1112", + }, + memo: "", + sig: null, + fee: null, + }, + hex_data: "180000000000000003000000000000000100000000000000044546580000000020420853419afb52000000", + }, + context_free: false, + elapsed: 76, + console: "", + trx_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + account_ram_deltas: [], + except: null, + error_code: null, + return_value_hex_data: "", + }, { + action_ordinal: 2, + creator_action_ordinal: 1, + closest_unnotified_ancestor_action_ordinal: 1, + receipt: { + receiver: "vibrantcacti", + act_digest: "d6f9be5af2565060d572a08f6e5f75498ea4c6a3d2cf77e26f3e3ffff4b6e244", + global_sequence: 196109235, + recv_sequence: 69, + auth_sequence: [ + [ "forcedev1234", 33 ] + ], + code_sequence: 8, + abi_sequence: 15, + }, + receiver: "vibrantcacti", + act: { + account: "efxaccount11", + name: "vtransfer", + authorization: [ + { + actor: "forcedev1234", + permission: "active", + } + ], + data: { + from_id: 24, + to_id: 3, + quantity: { + quantity: "0.0001 EFX", + contract: "efxtoken1112", + }, + memo: "", + sig: null, + fee: null, + }, + hex_data: "180000000000000003000000000000000100000000000000044546580000000020420853419afb52000000", + }, + context_free: false, + elapsed: 5, + console: "", + trx_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", + block_num: 137868012, + block_time: "2024-05-03T04:12:07.500", + producer_block_id: null, + account_ram_deltas: [], + except: null, + error_code: null, + return_value_hex_data: "", + } + ], + account_ram_delta: null, + except: null, + error_code: null, + }, + }, +} +``` +## Parameters + +### Client + +- **Type:** `Client` +- **Description:** Client object that is used to interact with the blockchain. Make sure that the client is connected with a Session. + +### Ammount + +- **Type:** `number` +- **Description:** +The amount of tokens to be swapped. + +### Direction + +- **Type:** `string` +- **Description:** +The direction of the swap. It can be either "UsdtToEfx" or "EfxToUsdt". + +## Returns + +**Type:** TransactionResponse +**Description:** +Retruns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. diff --git a/docs/pages/docs/token/swap.ts b/docs/pages/docs/token/swap.ts deleted file mode 100644 index e69de29b..00000000 From 5e40649e94f3fa25a184d307fbccf145ecfd25f0 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 8 May 2024 00:55:26 -0400 Subject: [PATCH 21/84] Add transact result page to glossary --- .../docs/glossary/transaction-result.mdx | 26 +++++++++++++++++++ .../docs/tasks/campaigns/create-campaign.mdx | 24 +++-------------- docs/pages/docs/token/swap.mdx | 5 +++- docs/sidebar.ts | 1 + 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 docs/pages/docs/glossary/transaction-result.mdx diff --git a/docs/pages/docs/glossary/transaction-result.mdx b/docs/pages/docs/glossary/transaction-result.mdx new file mode 100644 index 00000000..c88e86d6 --- /dev/null +++ b/docs/pages/docs/glossary/transaction-result.mdx @@ -0,0 +1,26 @@ +# Transaction Result + +## Description + +Some functions with the `@effectai/sdk` package will return a `TransactionResult` object. +This object contains the transaction hash and the transaction receipt. + +The interface for the `TransactionResult` object is as follows: + + +```ts +interface TransactResult { + chain: ChainDefinition + request: SigningRequest + resolved: ResolvedSigningRequest | undefined + response?: { [key: string]: any } + revisions: TransactRevisions + signatures: Signature[] + signer: PermissionLevel + transaction: ResolvedTransaction | undefined +} +``` + +Read more about the `TransactionResult` object here: + +https://wharfkit.com/docs/session-kit/transact-result diff --git a/docs/pages/docs/tasks/campaigns/create-campaign.mdx b/docs/pages/docs/tasks/campaigns/create-campaign.mdx index 5930e1e3..cc0a0bef 100644 --- a/docs/pages/docs/tasks/campaigns/create-campaign.mdx +++ b/docs/pages/docs/tasks/campaigns/create-campaign.mdx @@ -82,24 +82,8 @@ response: { ## Returns -**Type:** [`Promise`](/docs/glossary/types#transaction_result) +**Type:** TransactionResult -**Description:** Transaction result object that contains the transaction id and the processed transaction. - -**Properties:** - -- **response**: Object -- **transaction_id**: Transaction ID of the transaction - - **processed**: - - **id**: Id of the transaction - - **block_num**: Number of the block that the transaction was processed in - - **block_time**: Time the block was processed - - **producer_block_id**: null, - - **receipt**: [Object ...], - - **elapsed**: Time elapsed in milliseconds - - **net_usage**: Net usage of the transaction - - **scheduled**: If the transaction was scheduled - - **action_traces**: [ [Object ...] ], - - **account_ram_delta**: Amount of RAM used - - **except**: exception message - - **error_code**: Error code if there was an error +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [[../glossary/transaction-result.mdx]] diff --git a/docs/pages/docs/token/swap.mdx b/docs/pages/docs/token/swap.mdx index 228037a0..59a66763 100644 --- a/docs/pages/docs/token/swap.mdx +++ b/docs/pages/docs/token/swap.mdx @@ -186,5 +186,8 @@ The direction of the swap. It can be either "UsdtToEfx" or "EfxToUsdt". ## Returns **Type:** TransactionResponse + **Description:** -Retruns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [[../glossary/transaction-result.mdx]] + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 397784e1..ca51024a 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -105,6 +105,7 @@ export const sidebar = { text: "Glossary", items: [ { text: "Client Options", link: "/docs/glossary/client-options" }, + { text: "TransactResult", link: "/docs/glossary/transaction-result" }, ], }, { From 1ebbc29749c395e73955b0af571be650bc7dd379 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 8 May 2024 13:17:19 -0400 Subject: [PATCH 22/84] Add asset docs --- docs/pages/docs/glossary/asset.mdx | 21 +++++++++++++++++++++ docs/sidebar.ts | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 docs/pages/docs/glossary/asset.mdx diff --git a/docs/pages/docs/glossary/asset.mdx b/docs/pages/docs/glossary/asset.mdx new file mode 100644 index 00000000..b8636b02 --- /dev/null +++ b/docs/pages/docs/glossary/asset.mdx @@ -0,0 +1,21 @@ +# Asset + +## Description + +Some functions with the `@effectai/sdk` package will return a `Asset` object. +This object contains information about tokens on the blockchain and contain information such as the symbol, precision, and amount. + +An example for the `Asset` object is as follows: + + +```json +{ + "precision": 4, + "symbol": "EFX", + "units": 10000, + "value": 1 +} +``` + +Read more about the `Asset` object here: +https://wharfkit.com/docs/antelope/asset diff --git a/docs/sidebar.ts b/docs/sidebar.ts index ca51024a..de806027 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -68,7 +68,7 @@ export const sidebar = { { text: "Token", items: [ - { text: "TODO: getPrice", link: "/docs/tasks/token/get-price" }, + { text: "getPrice", link: "/docs/tasks/token/get-price" }, { text: "TODO: getBalance", link: "/docs/tasks/token/get-balance" }, { text: "TODO: swap", link: "/docs/tasks/token/swap" }, ], @@ -77,7 +77,7 @@ export const sidebar = { text: "Tasks", items: [ { - text: "TODO: createCampaign", + text: "createCampaign", link: "/docs/tasks/campaigns/create-campaign", }, { @@ -106,6 +106,7 @@ export const sidebar = { items: [ { text: "Client Options", link: "/docs/glossary/client-options" }, { text: "TransactResult", link: "/docs/glossary/transaction-result" }, + { text: "Asset", link: "/docs/glossary/asset" }, ], }, { From edc26dbec1f39465dfaf3fceb69a59210f9c171d Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 8 May 2024 14:30:53 -0400 Subject: [PATCH 23/84] clean up get-balance and swap --- docs/pages/docs/token/get-balance.mdx | 3 ++- docs/pages/docs/token/swap.mdx | 6 +++++- docs/sidebar.ts | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index 0df9248a..8f1978a0 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -3,6 +3,7 @@ ## Description This function is used to get the balance of EFX of an Effect Network account. +Note the use of `balance.toString()` to convert the balance to a string. ## Usage @@ -42,4 +43,4 @@ Returns the balance of the account in the form of an Asset object. The asset object has properties that represent the amount and symbol of the balance of the user. Note that the Asset object has a `toString` method that can be used to convert the balance to a string. - +You can read more about the: [`Asset` object](/docs/glossary/asset) diff --git a/docs/pages/docs/token/swap.mdx b/docs/pages/docs/token/swap.mdx index 59a66763..0e527dc4 100644 --- a/docs/pages/docs/token/swap.mdx +++ b/docs/pages/docs/token/swap.mdx @@ -6,6 +6,8 @@ This function is used to swap tokens from EFX to USDT or vice versa. Note that the function requires a client object that is used to interact with the blockchain. The client object also needs a Session object that is used to sign the transactions. +### WalletPlugin + Note that the `walletPlugin` object is used to sign the transactions. The `walletPlugin` object is an instance of the WalletPluginPrivateKey class that is used to sign the transactions using the private key of the user. Other wallet plugins can be used to sign transactions and can be found at: https://wharfkit.com/plugins @@ -40,6 +42,8 @@ console.log(response); ## Output +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + ``` response: { transaction_id: "18c35c04fce3dbbfee0dea46707003c4897bb3c02766a69936c3ceb0bb836c99", @@ -189,5 +193,5 @@ The direction of the swap. It can be either "UsdtToEfx" or "EfxToUsdt". **Description:** Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. -Read more about the transaction response here: [[../glossary/transaction-result.mdx]] +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) diff --git a/docs/sidebar.ts b/docs/sidebar.ts index de806027..8b1acac0 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -68,9 +68,9 @@ export const sidebar = { { text: "Token", items: [ - { text: "getPrice", link: "/docs/tasks/token/get-price" }, - { text: "TODO: getBalance", link: "/docs/tasks/token/get-balance" }, - { text: "TODO: swap", link: "/docs/tasks/token/swap" }, + { text: "getPrice", link: "/docs/token/get-price" }, + { text: "getBalance", link: "/docs/token/get-balance" }, + { text: "swap", link: "/docs/token/swap" }, ], }, { From 81d267e2acd02dfb0bcad6217761943e1ec7e501 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:24:12 -0400 Subject: [PATCH 24/84] Use NameType instead of Name --- src/actions/atomic/getAccountAssets.ts | 4 ++-- src/actions/token/getBalance.test.ts | 5 ++--- src/actions/token/getBalance.ts | 4 ++-- src/actions/vaccount/createAccount.ts | 8 ++++---- src/actions/vaccount/deposit.test.ts | 5 +---- src/actions/vaccount/getAccounts.ts | 11 +++-------- src/actions/vaccount/getOrCreate.ts | 4 ++-- src/actions/vaccount/payout.ts | 4 ++-- src/actions/vaccount/withdraw.ts | 6 +++--- src/exports/index.ts | 2 +- src/session.ts | 12 ++++++------ src/utils/keys.ts | 5 +++-- 12 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/actions/atomic/getAccountAssets.ts b/src/actions/atomic/getAccountAssets.ts index 6f0fab18..b16ab5d7 100644 --- a/src/actions/atomic/getAccountAssets.ts +++ b/src/actions/atomic/getAccountAssets.ts @@ -1,10 +1,10 @@ -import type { Name, UInt32 } from "@wharfkit/antelope"; +import type { NameType, UInt32 } from "@wharfkit/antelope"; import type { Client } from "../../client"; import type { GetTableRowsResponse } from "../../exports"; export type getAccountAssetsArgs = { client: Client; - account: Name; + account: NameType; }; // TODO: What does this comment mean? diff --git a/src/actions/token/getBalance.test.ts b/src/actions/token/getBalance.test.ts index be30dd39..96c32fb1 100644 --- a/src/actions/token/getBalance.test.ts +++ b/src/actions/token/getBalance.test.ts @@ -2,12 +2,11 @@ import { describe, test, expect } from "bun:test"; import { getBalance } from "./getBalance"; import { createClient } from "../../client"; import { eos, jungle4 } from "../../exports"; -import { Name } from "@wharfkit/antelope"; describe("getBalance", async () => { test("getBalance() should retrieve balance from user on mainnet", async () => { const client = createClient({ network: jungle4 }); - const actor = Name.from("forcedev1234"); + const actor = "forcedev1234"; const balance = await getBalance({ client, actor }); expect(balance).toBeDefined(); expect(balance.toString()).toBeDefined(); @@ -16,7 +15,7 @@ describe("getBalance", async () => { test("getBalance() should throw Error retrieving balance from unknown user.", async () => { const client = createClient({ network: eos }); - const actor = Name.from("cryptonode99"); + const actor = "cryptonode99"; expect(async () => await getBalance({ client, actor })).toThrowError(); }); }); diff --git a/src/actions/token/getBalance.ts b/src/actions/token/getBalance.ts index 38dafafe..7859f9a8 100644 --- a/src/actions/token/getBalance.ts +++ b/src/actions/token/getBalance.ts @@ -1,9 +1,9 @@ -import type { Asset, Name } from "@wharfkit/session"; +import type { Asset, NameType } from "@wharfkit/session"; import type { Client } from "../../exports"; export type GetBalanceArgs = { client: Client; - actor: Name; + actor: NameType; }; /** diff --git a/src/actions/vaccount/createAccount.ts b/src/actions/vaccount/createAccount.ts index d9a172d2..ca331747 100644 --- a/src/actions/vaccount/createAccount.ts +++ b/src/actions/vaccount/createAccount.ts @@ -1,4 +1,4 @@ -import type { Name, TransactResult, Session } from "@wharfkit/session"; +import type { TransactResult, Session, NameType } from "@wharfkit/session"; import type { Client } from "../../client"; import { ExtendedSymbol } from "../../utils/structs"; import { VAddress } from "../../utils/variants"; @@ -6,7 +6,7 @@ import { VAddress } from "../../utils/variants"; export type CreateVAccountArgs = { client: Client; session?: Session; - account?: Name; + account?: NameType; }; /** @@ -44,8 +44,8 @@ export const createVAccount = async ({ throw new Error("No session provided"); } - // If no account is provided, use the current session actor - const acc: Name = account ?? sessionToUse.actor; + // TODO: If no account is provided, use the current session actor. Not implemented yet + const acc: NameType = account ?? sessionToUse.actor; const { actor } = sessionToUse; const { contracts, token } = client.network.config.efx; diff --git a/src/actions/vaccount/deposit.test.ts b/src/actions/vaccount/deposit.test.ts index 547afff1..45a42d34 100644 --- a/src/actions/vaccount/deposit.test.ts +++ b/src/actions/vaccount/deposit.test.ts @@ -2,7 +2,6 @@ import { describe, test, expect } from "bun:test"; import { deposit } from "./deposit"; import { eos, jungle4 } from "../../exports"; import { getOrCreateVAccount } from "./getOrCreate"; -import { Name } from "@wharfkit/antelope"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; describe("deposit", async () => { @@ -11,13 +10,11 @@ describe("deposit", async () => { }); test.skip("Check that deposit is functioning correctly", async () => { - const { network, actor } = destructureEnv(); const client = await testClientSession({ testEnvNetwork: network }); - console.debug(client.network); - const acc = Name.from(actor); const vAccount = await getOrCreateVAccount({ client, actor: acc }); const vAccId = Number(vAccount.id); const result = await deposit({ client, vAccountId: vAccId, amount: 0.1 }); console.debug(result); + const { actor } = destructureEnv(); }); }); diff --git a/src/actions/vaccount/getAccounts.ts b/src/actions/vaccount/getAccounts.ts index 3b2db2d0..b2172876 100644 --- a/src/actions/vaccount/getAccounts.ts +++ b/src/actions/vaccount/getAccounts.ts @@ -1,4 +1,4 @@ -import type { Name, UInt64Type } from "@wharfkit/antelope"; +import { Name, type NameType, type UInt64Type } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { NotFoundError } from "../../errors"; import { generateCheckSumForVAccount } from "../../utils/keys"; @@ -6,14 +6,9 @@ import type { Account } from "../../@generated/types/efxaccount11"; export type GetVAccountsArgs = { client: Client; - actor: Name; + actor: NameType; }; -/** - * Get all virtual accounts for a given account - * @param {GetVAccountsArgs} getVAccountargs - Object with sdk client and account name - * @returns {Promise} VAccount[] - Array of Effect Virtual Accounts - */ export const getVAccounts = async ({ client, actor, @@ -21,7 +16,7 @@ export const getVAccounts = async ({ const { provider, network } = client; const { contracts } = network.config.efx; - const keycs = generateCheckSumForVAccount(actor, contracts.token); + const keycs = generateCheckSumForVAccount(Name.from(actor), contracts.token); const response = await provider.v1.chain.get_table_rows({ code: contracts.vaccount, diff --git a/src/actions/vaccount/getOrCreate.ts b/src/actions/vaccount/getOrCreate.ts index 1075c89a..1661a74e 100644 --- a/src/actions/vaccount/getOrCreate.ts +++ b/src/actions/vaccount/getOrCreate.ts @@ -1,4 +1,4 @@ -import type { Name } from "@wharfkit/antelope"; +import type { NameType } from "@wharfkit/antelope"; import type { Session } from "@wharfkit/session"; import { type Client, createVAccount, getVAccounts } from "../../exports"; @@ -8,7 +8,7 @@ export const getOrCreateVAccount = async ({ session, }: { client: Client; - actor: Name; + actor: NameType; session?: Session; }) => { try { diff --git a/src/actions/vaccount/payout.ts b/src/actions/vaccount/payout.ts index 432b6d87..4670e4c0 100644 --- a/src/actions/vaccount/payout.ts +++ b/src/actions/vaccount/payout.ts @@ -1,4 +1,4 @@ -import { type AnyAction, ExtendedAsset, type Name } from "@wharfkit/antelope"; +import { type AnyAction, ExtendedAsset, NameType } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { VAccountError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; @@ -9,7 +9,7 @@ import { withdrawAction } from "./withdraw"; /* claim & withdraw EFX to VAccount */ export type PayoutArgs = { client: Client; - actor: Name; + actor: NameType; }; export const payout = async ({ client, actor }: PayoutArgs) => { diff --git a/src/actions/vaccount/withdraw.ts b/src/actions/vaccount/withdraw.ts index ae445334..00806aca 100644 --- a/src/actions/vaccount/withdraw.ts +++ b/src/actions/vaccount/withdraw.ts @@ -1,4 +1,4 @@ -import type { AnyAction, ExtendedAsset, Name } from "@wharfkit/antelope"; +import type { AnyAction, ExtendedAsset, NameType } from "@wharfkit/antelope"; import type { Client } from "../../exports"; export type WithdrawArgs = { @@ -28,10 +28,10 @@ export const withdraw = async ({ client, quantity }: WithdrawArgs) => { export type WithdrawActionArgs = { from_id: number; - to_account: Name; + to_account: NameType; quantity: ExtendedAsset; account: string; - authorization: { actor: Name; permission: Name }[]; + authorization: { actor: NameType; permission: NameType }[]; memo: string; }; diff --git a/src/exports/index.ts b/src/exports/index.ts index 33020246..28e4d6ce 100644 --- a/src/exports/index.ts +++ b/src/exports/index.ts @@ -179,6 +179,6 @@ export type { GetTableRowsResponse } from "./types"; export { Template } from "./template"; -export { Session, Name } from "@wharfkit/session"; +export { Session, Name, type NameType } from "@wharfkit/session"; export { version } from "./version"; diff --git a/src/session.ts b/src/session.ts index 6a6dd4eb..f5912169 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1,5 +1,5 @@ import type { - Name, + NameType, PermissionLevelType, Session, TransactArgs, @@ -8,12 +8,12 @@ import { TxState, waitForTransaction } from "./utils/transaction"; import type { Account } from "./@generated/types/efxaccount11"; export class EffectSession { - public readonly wharfKitSession: Session; + public readonly wharfKitSession: Session; - public readonly actor: Name; - public readonly permission: Name; - public readonly permissionLevel: PermissionLevelType; - public readonly authorization: { actor: Name; permission: Name }[]; + public readonly actor: NameType; + public readonly permission: NameType; + public readonly permissionLevel: PermissionLevelType; + public readonly authorization: { actor: NameType; permission: NameType }[]; private _vAccount: Account | null; diff --git a/src/utils/keys.ts b/src/utils/keys.ts index ffbdc572..f0644900 100644 --- a/src/utils/keys.ts +++ b/src/utils/keys.ts @@ -2,6 +2,7 @@ import { ABIEncoder, Checksum256, Name, + NameType, UInt32, UInt64, } from "@wharfkit/antelope"; @@ -21,12 +22,12 @@ export function createCompositeU64Key(lowerId: number, upperId: number) { } export const generateCheckSumForVAccount = ( - actor: Name, + actor: NameType, tokenContract: string, ): Checksum256 => { const enc = new ABIEncoder(32); Name.from(tokenContract).toABI(enc); - const vaddr = VAddress.from(Name.from(actor.toString())); + const vaddr = VAddress.from(actor); enc.writeByte(vaddr.variantIdx); vaddr.value.toABI(enc); From 631fcac05f221568379d627afb42b365ea81b6a9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:24:47 -0400 Subject: [PATCH 25/84] Fix link to transfer docs --- docs/sidebar.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 8b1acac0..4e3bfa9d 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -61,7 +61,6 @@ export const sidebar = { link: "/docs/tasks/vaccount/get-pending-payments", }, { text: "TODO: payout", link: "/docs/tasks/vaccount/payout" }, - { text: "TODO: transfer", link: "/docs/tasks/vaccount/transfer" }, { text: "TODO: withdraw", link: "/docs/tasks/vaccount/withdraw" }, ], }, @@ -70,6 +69,7 @@ export const sidebar = { items: [ { text: "getPrice", link: "/docs/token/get-price" }, { text: "getBalance", link: "/docs/token/get-balance" }, + { text: "TODO: transfer", link: "/docs/token/transfer" }, { text: "swap", link: "/docs/token/swap" }, ], }, From c639cf301366c39a7077b504c0dd2793e02393f9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:26:12 -0400 Subject: [PATCH 26/84] Clean up client.test.ts --- .../tasks/campaigns/createCampaign.test.ts | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/actions/tasks/campaigns/createCampaign.test.ts b/src/actions/tasks/campaigns/createCampaign.test.ts index a1640179..9a36fef6 100644 --- a/src/actions/tasks/campaigns/createCampaign.test.ts +++ b/src/actions/tasks/campaigns/createCampaign.test.ts @@ -5,20 +5,20 @@ import { testClientSession } from "../../../../test/src/utils"; import { jungle4 } from "../../../exports"; const myNewCampaign: CreateCampaignArgs["campaign"] = { - version: 1.0, - maxTaskTime: 100, - reward: 3.5, - title: "Labelstudio OCR (LAION)", - description: - "You are contributing to a dataset for conversational style chatbots.", - instructions: "Some instructions here", - template: "

Template here

", - input_schema: null, - output_schema: null, - image: "", - category: "", - example_task: "", - estimated_time: 10, + version: 1.0, + maxTaskTime: 100, + reward: 3.5, + title: "Labelstudio OCR (LAION)", + description: + "You are contributing to a dataset for conversational style chatbots.", + instructions: "Some instructions here", + template: "

Template here

", + input_schema: null, + output_schema: null, + image: "", + category: "", + example_task: "", + estimated_time: 10, }; describe("createCampaign", async () => { @@ -36,26 +36,5 @@ describe("createCampaign", async () => { const client = await testClientSession({ network: jungle4 }); const result = await createCampaign({ client, campaign: myNewCampaign }); expect(result).toBeDefined(); - /** - * response: { - * transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", - * processed: { - * id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", - * block_num: 137520447, - * block_time: "2024-05-01T03:55:31.500", - * producer_block_id: null, - * receipt: [Object ...], - * elapsed: 4854, - * net_usage: 176, - * scheduled: false, - * action_traces: [ - * [Object ...] - * ], - * account_ram_delta: null, - * except: null, - * error_code: null, - * }, - * } - */ }); }); From c062c9816132e414578d291bf3ca591ec6bbcc7e Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:27:13 -0400 Subject: [PATCH 27/84] Update test script --- package.json | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 34930c9c..5000faac 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,11 @@ "module": "./dist/exports/index.js", "browser": "dist/exports/index.js", "types": "./dist/exports/index.d.ts", - "files": ["dist"], + "files": [ + "dist" + ], "scripts": { - "test": "bun --env-file=.env test --preload ./test/global-setup.ts", + "test": "bun --env-file=.env test", "test:watch": "bun --env-file=.env test --watch", "test:coverage": "bun --env-file=.env test --coverage", "dev": "tsc -w", @@ -27,7 +29,12 @@ "type": "git", "url": "git+https://github.com/effectai/effect-js.git" }, - "keywords": ["efx", "AI", "blockchain", "microtasks"], + "keywords": [ + "efx", + "AI", + "blockchain", + "microtasks" + ], "author": { "name": "Effect-AI", "url": "https://effect.network", @@ -59,5 +66,7 @@ "idb-keyval": "^6.2.1", "node-localstorage": "^3.0.5" }, - "trustedDependencies": ["@biomejs/biome"] + "trustedDependencies": [ + "@biomejs/biome" + ] } From a091600271d8207acef50a75a87ec19e3ff2d678 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:27:50 -0400 Subject: [PATCH 28/84] clean up session.ts --- src/session.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/session.ts b/src/session.ts index f5912169..ec42497f 100644 --- a/src/session.ts +++ b/src/session.ts @@ -30,19 +30,19 @@ export class EffectSession { this._vAccount = vAccount; } - public transact = async (args: TransactArgs): Promise => { - // Start the transaction - const transaction = await this.wharfKitSession.transact({ - ...args, - }); - - //wait for TX to be IN BLOCK - await waitForTransaction( - transaction.response?.transaction_id, - this.wharfKitSession.client.v1.chain, - TxState.IN_BLOCK, - ); - - return transaction; - }; + public transact = async (args: TransactArgs) => { + // Start the transaction + const transaction = await this.wharfKitSession.transact({ + ...args, + }); + + //wait for TX to be IN BLOCK + await waitForTransaction( + transaction.response?.transaction_id, + this.wharfKitSession.client.v1.chain, + TxState.IN_BLOCK, + ); + + return transaction; + }; } From dd0a27be78b86da3ae9f99dcecf59425c2ca8803 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:29:21 -0400 Subject: [PATCH 29/84] Await on `createClient()` and clean up --- src/client.test.ts | 30 +++++++++++++++--------------- src/client.ts | 5 +++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/client.test.ts b/src/client.test.ts index 0f7820fb..d6b196ea 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -5,23 +5,23 @@ import { destructureEnv } from "../test/src/utils"; import { Session } from "@wharfkit/session"; describe("Client", async () => { - test("Create client with Session", async () => { - const { network: chain, permission, actor, privateKey } = destructureEnv(); + test("Create client with Session", async () => { + const { network: chain, permission, actor, privateKey } = destructureEnv(); - // Create wallet with privatekey - const walletPlugin = new WalletPluginPrivateKey(privateKey); + // Create wallet with privatekey + const walletPlugin = new WalletPluginPrivateKey(privateKey); - // Set up session with wallet - const session = new Session({ actor, permission, walletPlugin, chain }); + // Set up session with wallet + const session = new Session({ actor, permission, walletPlugin, chain }); - const client = createClient({ session }); - expect(client.session).toBeDefined(); - expect(client.network.id).toBe(chain.id); - }); + const client = await createClient({ session }); + expect(client.session).toBeDefined(); + expect(client.network.id).toBe(chain.id); + }); - test("Create client with Network", async () => { - const { network } = destructureEnv(); - const client = createClient({ network }); - expect(client.session).toBeDefined(); - }); + test("Create client with Network", async () => { + const { network } = destructureEnv(); + const client = await createClient({ network }); + expect(client.session).toBeDefined(); + }); }); diff --git a/src/client.ts b/src/client.ts index 6796cca3..fdb98e0e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -88,7 +88,7 @@ export type CreateClientArgs = { options?: ClientOpts; } & ({ network: Network } | { session: Session }); -export const createClient = ({ +export const createClient = async ({ network, session, options = {}, @@ -99,6 +99,7 @@ export const createClient = ({ ); } + // TODO: We should also check that network and session.network are the same if (session) { // if session is given here, retrieve the network from session @@ -114,7 +115,7 @@ export const createClient = ({ const client = new Client(chain, options); // automatically set the session whenever the session is provided - client.setSession(session); + await client.setSession(session); return client; } From 9ed33dc7346e8e6a34e2cc26e373478a2aa08b97 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:31:36 -0400 Subject: [PATCH 30/84] use `await createClient()` and clean up --- .../tasks/campaigns/createCampaign.test.ts | 28 ++--- .../tasks/campaigns/getAllCampaigns.test.ts | 2 +- .../tasks/campaigns/getCampaignById.test.ts | 4 +- .../tasks/campaigns/getCampaigns.test.ts | 15 ++- src/actions/token/getBalance.test.ts | 4 +- src/actions/token/getBalance.ts | 13 -- src/actions/token/swap.test.ts | 40 +++---- src/actions/token/swap.ts | 4 +- src/actions/token/token.test.ts | 88 +++++++------- src/actions/vaccount/claim.ts | 4 +- src/actions/vaccount/createAccount.test.ts | 30 ++--- src/actions/vaccount/createAccount.ts | 24 ---- src/actions/vaccount/deposit.test.ts | 20 ++-- src/actions/vaccount/getAccounts.test.ts | 67 +++++------ .../vaccount/getPendingPayments.test.ts | 38 +++--- src/actions/vaccount/transfer.test.ts | 111 +++++++++--------- src/actions/vaccount/transfer.ts | 101 ++++++++-------- test/src/utils.ts | 15 +-- 18 files changed, 278 insertions(+), 330 deletions(-) diff --git a/src/actions/tasks/campaigns/createCampaign.test.ts b/src/actions/tasks/campaigns/createCampaign.test.ts index 9a36fef6..d3a12984 100644 --- a/src/actions/tasks/campaigns/createCampaign.test.ts +++ b/src/actions/tasks/campaigns/createCampaign.test.ts @@ -22,19 +22,19 @@ const myNewCampaign: CreateCampaignArgs["campaign"] = { }; describe("createCampaign", async () => { - test("createCampaign() should throw an error", async () => { - const client = createClient({ network: jungle4 }); - expect(async () => { - await createCampaign({ - client, - campaign: myNewCampaign, - }); - }).toThrowError(); - }); + test("createCampaign() should throw an error", async () => { + const client = await createClient({ network: jungle4 }); + expect(async () => { + await createCampaign({ + client, + campaign: myNewCampaign, + }); + }).toThrowError(); + }); - test.skip("createCampaign() should create a new campaign", async () => { - const client = await testClientSession({ network: jungle4 }); - const result = await createCampaign({ client, campaign: myNewCampaign }); - expect(result).toBeDefined(); - }); + test.skip("createCampaign() should create a new campaign", async () => { + const client = await testClientSession(); + const result = await createCampaign({ client, campaign: myNewCampaign }); + expect(result).toBeDefined(); + }); }); diff --git a/src/actions/tasks/campaigns/getAllCampaigns.test.ts b/src/actions/tasks/campaigns/getAllCampaigns.test.ts index f8b27cdd..6f1de316 100644 --- a/src/actions/tasks/campaigns/getAllCampaigns.test.ts +++ b/src/actions/tasks/campaigns/getAllCampaigns.test.ts @@ -6,7 +6,7 @@ import { jungle4 } from "../../../exports"; describe("getAllCampaigns", async () => { test("getAllCampaigns() should retrieve all campaign", async () => { - const client = createClient({ network: jungle4 }); + const client = await createClient({ network: jungle4 }); const campaigns = await getAllCampaigns({ client }); expect(campaigns).toBeDefined(); expect(campaigns).toBeArray(); diff --git a/src/actions/tasks/campaigns/getCampaignById.test.ts b/src/actions/tasks/campaigns/getCampaignById.test.ts index d4eaaefb..518d23e3 100644 --- a/src/actions/tasks/campaigns/getCampaignById.test.ts +++ b/src/actions/tasks/campaigns/getCampaignById.test.ts @@ -6,7 +6,7 @@ import { campaign as exampleCampaign } from "../../../../test/src/constants"; describe("getCampaignById", async () => { test("getCampaignById() should throw an error when accessing unretrievable id", async () => { - const client = createClient({ network: jungle4 }); + const client = await createClient({ network: jungle4 }); const id = 11111; expect(async () => { await getCampaignById({ client, id }); @@ -14,7 +14,7 @@ describe("getCampaignById", async () => { }); test("getCampaignById() should retrieve campaign on testnet", async () => { - const client = createClient({ network: jungle4 }); + const client = await createClient({ network: jungle4 }); const id = 1; const campaign = await getCampaignById({ client, id }); expect(campaign).toBeDefined(); diff --git a/src/actions/tasks/campaigns/getCampaigns.test.ts b/src/actions/tasks/campaigns/getCampaigns.test.ts index df992b2c..a6f9b8f5 100644 --- a/src/actions/tasks/campaigns/getCampaigns.test.ts +++ b/src/actions/tasks/campaigns/getCampaigns.test.ts @@ -1,14 +1,13 @@ import { describe, test, expect } from "bun:test"; import { testClientSession } from "../../../../test/src/utils"; import { getCampaigns } from "./getCampaigns"; -import { jungle4 } from "../../../exports"; describe("getCampaigns", async () => { - test("getCampaigns() should return 3 campaigns", async () => { - const client = await testClientSession({ network: jungle4 }); - const campaigns = await getCampaigns({ client, limit: 3 }); - expect(campaigns).toBeDefined(); - expect(campaigns.rows).toBeArray(); - expect(campaigns.rows.length).toBe(3); - }); + test("getCampaigns() should return 3 campaigns", async () => { + const client = await testClientSession(); + const campaigns = await getCampaigns({ client, limit: 3 }); + expect(campaigns).toBeDefined(); + expect(campaigns.rows).toBeArray(); + expect(campaigns.rows.length).toBe(3); + }); }); diff --git a/src/actions/token/getBalance.test.ts b/src/actions/token/getBalance.test.ts index 96c32fb1..207d1645 100644 --- a/src/actions/token/getBalance.test.ts +++ b/src/actions/token/getBalance.test.ts @@ -5,7 +5,7 @@ import { eos, jungle4 } from "../../exports"; describe("getBalance", async () => { test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = createClient({ network: jungle4 }); + const client = await createClient({ network: jungle4 }); const actor = "forcedev1234"; const balance = await getBalance({ client, actor }); expect(balance).toBeDefined(); @@ -14,7 +14,7 @@ describe("getBalance", async () => { }); test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = createClient({ network: eos }); + const client = await createClient({ network: eos }); const actor = "cryptonode99"; expect(async () => await getBalance({ client, actor })).toThrowError(); }); diff --git a/src/actions/token/getBalance.ts b/src/actions/token/getBalance.ts index 7859f9a8..8ee90fab 100644 --- a/src/actions/token/getBalance.ts +++ b/src/actions/token/getBalance.ts @@ -6,19 +6,6 @@ export type GetBalanceArgs = { actor: NameType; }; -/** - * Get the balance of a user - * @param {{ client: Client, actor: Name}} Effect SDK client and the actor to get the balance for. - * @returns {Promise} The balance of the user - * @throws {Error} if no balance is found - * - * @example - * const client = createClient({ network: eos }); - * const actor = Name.from("cryptonode42"); - * const balance = await getBalance({ client, actor }); - * console.log(balance.toString()); - * // => "100.0000 EFX" - */ export const getBalance = async ({ client, actor, diff --git a/src/actions/token/swap.test.ts b/src/actions/token/swap.test.ts index b63281ed..1f9dc919 100644 --- a/src/actions/token/swap.test.ts +++ b/src/actions/token/swap.test.ts @@ -5,31 +5,31 @@ import type { SwapArgs } from "./swap"; import { testClientSession } from "../../../test/src/utils"; describe("buildSwapAction", async () => { - test.todo("buildSwapAction() should return a swap action object."); + test.todo("buildSwapAction() should return a swap action object."); }); describe("Swap", async () => { - // Use Mainnet + // Use Mainnet - test("swap() should throw an error when Session is not set on Client.", async () => { - const swapArgs: SwapArgs = { - client: createClient({ network: jungle4 }), - amount: 1, - direction: "UsdtToEfx", - }; + test("swap() should throw an error when Session is not set on Client.", async () => { + const swapArgs: SwapArgs = { + client: await createClient({ network: jungle4 }), + amount: 1, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow( - new Error("Error swapping: Error: Session is required for this method."), - ); - }); + expect(async () => await swap(swapArgs)).toThrow( + new Error("Error swapping: Error: Session is required for this method."), + ); + }); - test("swap() should fail when amount is 0", async () => { - const swapArgs: SwapArgs = { - client: await testClientSession({ network: jungle4 }), - amount: 0, - direction: "UsdtToEfx", - }; + test("swap() should fail when amount is 0", async () => { + const swapArgs: SwapArgs = { + client: await testClientSession(), + amount: 0, + direction: "UsdtToEfx", + }; - expect(async () => await swap(swapArgs)).toThrow(); - }); + expect(async () => await swap(swapArgs)).toThrow(); + }); }); diff --git a/src/actions/token/swap.ts b/src/actions/token/swap.ts index c45ecc53..b32c64fd 100644 --- a/src/actions/token/swap.ts +++ b/src/actions/token/swap.ts @@ -1,8 +1,8 @@ import { type AnyAction, Asset, - type Name, type PermissionLevelType, + type NameType, } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { DefiBoxPairEnum } from "./getDefiBoxPair"; @@ -16,7 +16,7 @@ export const swapDirection = { export const buildSwapAction = ( direction: string, - actor: Name, + actor: NameType, authorization: PermissionLevelType[], amount: number, tokenContract: string, diff --git a/src/actions/token/token.test.ts b/src/actions/token/token.test.ts index 004fcc69..d0db7e59 100644 --- a/src/actions/token/token.test.ts +++ b/src/actions/token/token.test.ts @@ -4,61 +4,59 @@ import { getBalance } from "./getBalance"; import { swap, type SwapArgs } from "./swap"; import { createClient } from "../../client"; import { eos, jungle4 } from "../../exports"; -import { Name } from "@wharfkit/antelope"; import { testClientSession } from "../../../test/src/utils"; describe("getPrice", async () => { - test("getPrice() should retrieve price on mainnet", async () => { - const client = createClient({ network: eos }); - const price = await getPrice(); - expect(price).toBeDefined(); - expect(price).toBeNumber(); - }); + test("getPrice() should retrieve price on mainnet", async () => { + const price = await getPrice(); + expect(price).toBeDefined(); + expect(price).toBeNumber(); + }); }); describe("getBalance", async () => { - test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = createClient({ network: jungle4 }); - const actor = Name.from("forcedev1234"); - const balance = await getBalance({ client, actor }); - expect(balance).toBeDefined(); - expect(balance.toString()).toBeDefined(); - expect(balance.toString()).toContain("EFX"); - }); - - test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = createClient({ network: eos }); - const actor = Name.from("cryptonode99"); - expect(async () => await getBalance({ client, actor })).toThrowError(); - }); + test("getBalance() should retrieve balance from user on mainnet", async () => { + const client = await createClient({ network: jungle4 }); + const actor = "forcedev1234"; + const balance = await getBalance({ client, actor }); + expect(balance).toBeDefined(); + expect(balance.toString()).toBeDefined(); + expect(balance.toString()).toContain("EFX"); + }); + + test("getBalance() should throw Error retrieving balance from unknown user.", async () => { + const client = await createClient({ network: eos }); + const actor = "cryptonode99"; + expect(async () => await getBalance({ client, actor })).toThrowError(); + }); }); describe("buildSwapAction", async () => { - test.todo("buildSwapAction() should return a swap action object."); + test.todo("buildSwapAction() should return a swap action object."); }); describe("Swap", async () => { - // Use Mainnet - - test("swap() should throw an error when Session is not set on Client.", async () => { - const swapArgs: SwapArgs = { - client: createClient({ network: jungle4 }), - amount: 1, - direction: "UsdtToEfx", - }; - - expect(async () => await swap(swapArgs)).toThrow( - new Error("Error swapping: Error: Session is required for this method."), - ); - }); - - test("swap() should fail when amount is 0", async () => { - const swapArgs: SwapArgs = { - client: await testClientSession({ network: jungle4 }), - amount: 0, - direction: "UsdtToEfx", - }; - - expect(async () => await swap(swapArgs)).toThrow(); - }); + // Use Mainnet + + test("swap() should throw an error when Session is not set on Client.", async () => { + const swapArgs: SwapArgs = { + client: await createClient({ network: jungle4 }), + amount: 1, + direction: "UsdtToEfx", + }; + + expect(async () => await swap(swapArgs)).toThrow( + new Error("Error swapping: Error: Session is required for this method."), + ); + }); + + test("swap() should fail when amount is 0", async () => { + const swapArgs: SwapArgs = { + client: await testClientSession(), + amount: 0, + direction: "UsdtToEfx", + }; + + expect(async () => await swap(swapArgs)).toThrow(); + }); }); diff --git a/src/actions/vaccount/claim.ts b/src/actions/vaccount/claim.ts index 2ae99049..60677c28 100644 --- a/src/actions/vaccount/claim.ts +++ b/src/actions/vaccount/claim.ts @@ -1,4 +1,4 @@ -import type { AnyAction, Name } from "@wharfkit/antelope"; +import type { AnyAction, NameType } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { VAccountError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; @@ -43,7 +43,7 @@ export const claim = async ({ client }: ClaimArgs) => { export type ClaimActionsArgs = { payments: Payment[]; tasks: string; - authorization: { actor: Name; permission: Name }[]; + authorization: { actor: NameType; permission: NameType }[]; }; export const claimActions = ({ diff --git a/src/actions/vaccount/createAccount.test.ts b/src/actions/vaccount/createAccount.test.ts index a4cc8508..c74bc29e 100644 --- a/src/actions/vaccount/createAccount.test.ts +++ b/src/actions/vaccount/createAccount.test.ts @@ -1,6 +1,6 @@ import { Name } from "@wharfkit/antelope"; -import { expect, test, describe, mock } from "bun:test"; +import { expect, test, describe } from "bun:test"; import { createClient } from "../../client"; import { createVAccount } from "./createAccount"; @@ -9,20 +9,20 @@ import { jungle4 } from "../../exports"; import { testClientSession } from "../../../test/src/utils.js"; describe("Create Virtual account", () => { - const network = jungle4; + const network = jungle4; - test.skip("createVAccount() should return a TransactResult", async () => { - const client = await testClientSession({ network }); - const account = Name.from("efxforce1112"); - const result = await createVAccount({ client, account }); - expect(result).toBeDefined(); - }); + test.skip("createVAccount() should return a TransactResult", async () => { + const client = await testClientSession(); + const account = Name.from("efxforce1112"); + const result = await createVAccount({ client, account }); + expect(result).toBeDefined(); + }); - test("createVAccount() should throw Error when no Session is found", async () => { - expect(async () => { - const client = createClient({ network: network }); - const account = Name.from("efxforce1112"); - await createVAccount({ client, account }); - }).toThrowError(); - }); + test("createVAccount() should throw Error when no Session is found", async () => { + expect(async () => { + const client = await createClient({ network: network }); + const account = Name.from("efxforce1112"); + await createVAccount({ client, account }); + }).toThrowError(); + }); }); diff --git a/src/actions/vaccount/createAccount.ts b/src/actions/vaccount/createAccount.ts index ca331747..1d2f2889 100644 --- a/src/actions/vaccount/createAccount.ts +++ b/src/actions/vaccount/createAccount.ts @@ -9,30 +9,6 @@ export type CreateVAccountArgs = { account?: NameType; }; -/** - * Creates a virtual Effect account - * Client must be initialized - * Session is optional if the client has a session already - * Account is optional, can be initialized with: - * - * ```ts - * import { Name } from "@wharfkit/session"; - * const account: Name = Name.from("accountname"); - * ``` - * The account name must be a valid EOS account name. - * If no account is provided, the current session actor will be used. - * - * @param {CreateVAccountArgs} { client, session, account } - Provide the client, session, and account name. - * @returns {TransactResult = The result of the the transaction.} - * - * @example - * ```ts - * import { createVAccount } from "@effectai/effect-js"; - * import { Name } from "@wharfkit/session"; - * const account: Name = Name.from("accountname"); - * const result = await createVAccount({ client, account }); - * ``` - */ export const createVAccount = async ({ client, session, diff --git a/src/actions/vaccount/deposit.test.ts b/src/actions/vaccount/deposit.test.ts index 45a42d34..688d77b3 100644 --- a/src/actions/vaccount/deposit.test.ts +++ b/src/actions/vaccount/deposit.test.ts @@ -1,20 +1,20 @@ import { describe, test, expect } from "bun:test"; import { deposit } from "./deposit"; -import { eos, jungle4 } from "../../exports"; -import { getOrCreateVAccount } from "./getOrCreate"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; +import { getVAccounts } from "./getAccounts"; describe("deposit", async () => { - test.todo("Should throw an error when Session is not set on Client.", () => { - // TODO: implement test - }); + test.todo( + "Should throw an error when Session is not set on Client.", + () => {}, + ); test.skip("Check that deposit is functioning correctly", async () => { - const client = await testClientSession({ testEnvNetwork: network }); - const vAccount = await getOrCreateVAccount({ client, actor: acc }); - const vAccId = Number(vAccount.id); - const result = await deposit({ client, vAccountId: vAccId, amount: 0.1 }); - console.debug(result); const { actor } = destructureEnv(); + const client = await testClientSession(); + const [vAccount] = await getVAccounts({ client, actor }); + const vAccountId = vAccount.id; + const result = await deposit({ client, vAccountId, amount: 0.1 }); + expect(result).toBeDefined(); }); }); diff --git a/src/actions/vaccount/getAccounts.test.ts b/src/actions/vaccount/getAccounts.test.ts index b6f8c9de..9a2010e8 100644 --- a/src/actions/vaccount/getAccounts.test.ts +++ b/src/actions/vaccount/getAccounts.test.ts @@ -1,46 +1,43 @@ import { expect, test, describe, beforeAll } from "bun:test"; -import type { VAccount } from "../../types/user"; import type { Client } from "../../client"; import { testClientSession } from "../../../test/src/utils"; - import { getVAccounts, getAccountById } from "./getAccounts"; -import { Name } from "@wharfkit/antelope"; -import { jungle4 } from "../../exports"; +import type { Account } from "../../exports"; describe("Get Virtual Accounts", () => { - const vaccExample: VAccount = { - id: 0, - nonce: 53, - address: ["name", "efxforceacc1"], - balance: { - quantity: "3525.0000 EFX", - contract: "effecttokens", - }, - }; + const vaccExample: Account = { + id: 0, + nonce: 53, + address: ["name", "efxforceacc1"], + balance: { + quantity: "3525.0000 EFX", + contract: "effecttokens", + }, + }; - let client: Client; - beforeAll(async () => { - client = await testClientSession({ network: jungle4 }); - }); + let client: Client; + beforeAll(async () => { + client = await testClientSession(); + }); - test("getVAccounts() on testnet", async () => { - const actor = Name.from("efxforce1112"); - const vaccs = await getVAccounts({ client, actor }); - expect(vaccs).toBeDefined(); - expect(vaccs).toBeArray(); - expect(vaccs[0]).toContainKeys(Object.keys(vaccExample)); - }); + test("getVAccounts() on testnet", async () => { + const actor = "efxforce1112"; + const vaccs = await getVAccounts({ client, actor }); + expect(vaccs).toBeDefined(); + expect(vaccs).toBeArray(); + expect(vaccs[0]).toContainKeys(Object.keys(vaccExample)); + }); - test("getAccountById()", async () => { - const vacc = await getAccountById({ client, accountId: 0 }); - expect(vacc).toBeDefined(); - expect(vacc).toContainKeys(Object.keys(vaccExample)); - }); + test("getAccountById()", async () => { + const vacc = await getAccountById({ client, accountId: 0 }); + expect(vacc).toBeDefined(); + expect(vacc).toContainKeys(Object.keys(vaccExample)); + }); - test("getAccountByID() should throw Error", async () => { - const accountId = 9999999; // Should be imposible to find - expect(async () => { - await getAccountById({ client, accountId }); - }).toThrowError(); - }); + test("getAccountByID() should throw Error", async () => { + const accountId = 9999999; // Should be imposible to find + expect(async () => { + await getAccountById({ client, accountId }); + }).toThrowError(); + }); }); diff --git a/src/actions/vaccount/getPendingPayments.test.ts b/src/actions/vaccount/getPendingPayments.test.ts index ab69692e..2d04a7ed 100644 --- a/src/actions/vaccount/getPendingPayments.test.ts +++ b/src/actions/vaccount/getPendingPayments.test.ts @@ -1,25 +1,23 @@ -import { describe, expect, test, beforeAll } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; import { getPendingPayments } from "./getPendingPayments"; -import { jungle4 } from "../../exports"; -import { getOrCreateVAccount } from "./getOrCreate"; -import { Name } from "@wharfkit/antelope"; +import { getVAccounts } from "./getAccounts"; describe("getPendingPayments", () => { - const pendingPaymentsExample = { - pendingPayments: [], - claimablePayments: [], - totalEfxPending: 0, - totalEfxClaimable: 0, - }; - test("getPendingPayments() returns pendingPayments", async () => { - const { network, actor: accountName } = destructureEnv(jungle4); - const actor = Name.from(accountName); - const client = await testClientSession({ network }); - const vaccount = await getOrCreateVAccount({ client, actor }); - const vAccountId = Number(vaccount.id); - const pendingPayments = await getPendingPayments({ client, vAccountId }); - expect(pendingPayments).toBeDefined(); - expect(pendingPayments).toMatchObject(pendingPaymentsExample); - }); + const pendingPaymentsExample = { + pendingPayments: [], + claimablePayments: [], + totalEfxPending: 0, + totalEfxClaimable: 0, + }; + + test("getPendingPayments() returns pendingPayments", async () => { + const { actor } = destructureEnv(); + const client = await testClientSession(); + const [vaccount] = await getVAccounts({ client, actor }); + const vAccountId = vaccount.id; + const pendingPayments = await getPendingPayments({ client, vAccountId }); + expect(pendingPayments).toBeDefined(); + expect(pendingPayments).toMatchObject(pendingPaymentsExample); + }); }); diff --git a/src/actions/vaccount/transfer.test.ts b/src/actions/vaccount/transfer.test.ts index f6fc809b..45691a74 100644 --- a/src/actions/vaccount/transfer.test.ts +++ b/src/actions/vaccount/transfer.test.ts @@ -1,63 +1,60 @@ import { describe, expect, test, beforeAll } from "bun:test"; import { testClientSession, destructureEnv } from "../../../test/src/utils"; import { vTransfer } from "./transfer"; -import { type Client, jungle4 } from "../../exports"; -import { getOrCreateVAccount } from "./getOrCreate"; -import { Asset, Name } from "@wharfkit/antelope"; +import { getVAccounts, type Client } from "../../exports"; describe("vTransfer", () => { - const { network, actor } = destructureEnv(jungle4); - const receiver = Name.from("vibrantcacti"); - let client: Client; - const from_id = 1; - const to_id = 2; - const quantity = 0.0001; - - beforeAll(async () => { - client = await testClientSession({ network }); - }); - - test("throws an error if session is not set", async () => { - expect(async () => { - await vTransfer({ client, from_id, to_id, quantity }); - }).toThrow(); - }); - - test.skip("Should return txResult, when sending 0.0001 EFX", async () => { - const accountName = Name.from(actor); - const vAccount = await getOrCreateVAccount({ client, actor: accountName }); - const preBalanceVAccount = Number(vAccount.balance.quantity); - - const vAccountReceiver = await getOrCreateVAccount({ - client, - actor: receiver, - }); - const preBalanceReceiver = Number(vAccountReceiver.balance.quantity); - - const result = await vTransfer({ - client, - from_id: vAccount.id, - to_id: vAccountReceiver.id, - quantity, - }); - - expect(result).toBeDefined(); - - const postVAccount = await getOrCreateVAccount({ - client, - actor: accountName, - }); - - const postVAccountReceiver = await getOrCreateVAccount({ - client, - actor: receiver, - }); - - const postbalanceReceiver = Number(postVAccountReceiver.balance.quantity); - const postbalance = Number(postVAccount.balance.quantity); - - // Make sure the balance is updated - expect(postbalance).toBe(preBalanceVAccount - quantity); - expect(postbalanceReceiver).toBe(preBalanceReceiver + quantity); - }); + const { actor } = destructureEnv(); + const receiver = "vibrantcacti"; + let client: Client; + const from_id = 1; + const to_id = 2; + const quantity = 0.0001; + + beforeAll(async () => { + client = await testClientSession(); + }); + + test("throws an error if session is not set", async () => { + expect(async () => { + await vTransfer({ client, from_id, to_id, quantity }); + }).toThrow(); + }); + + test.skip("Should return txResult, when sending 0.0001 EFX", async () => { + const [vAccount] = await getVAccounts({ client, actor }); + const preBalanceVAccount = Number(vAccount.balance.quantity); + + const [vAccountReceiver] = await getVAccounts({ + client, + actor: receiver, + }); + const preBalanceReceiver = Number(vAccountReceiver.balance.quantity); + + const result = await vTransfer({ + client, + from_id: vAccount.id, + to_id: vAccountReceiver.id, + quantity, + }); + + expect(result).toBeDefined(); + + const [postVAccount] = await getVAccounts({ + client, + actor, + }); + + const [postVAccountReceiver] = await getVAccounts({ + client, + actor: receiver, + }); + + const postbalanceReceiver = Number(postVAccountReceiver.balance.quantity); + const postbalance = Number(postVAccount.balance.quantity); + + // Make sure the balance is updated + expect(postbalance).toBe(preBalanceVAccount - quantity); + expect(postbalanceReceiver).toBe(preBalanceReceiver + quantity); + }); }); diff --git a/src/actions/vaccount/transfer.ts b/src/actions/vaccount/transfer.ts index 96493479..f03c720e 100644 --- a/src/actions/vaccount/transfer.ts +++ b/src/actions/vaccount/transfer.ts @@ -3,70 +3,73 @@ import type { Client } from "../../client"; import { SessionNotFoundError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; import type { TransactResult } from "@wharfkit/session"; +import { getVAccounts } from "./getAccounts"; export type vTransferActionArgs = { - client: Client; - from_id: number; - to_id: number; - quantity: number; + client: Client; + from_id: number; + to_id: number; + quantity: number; }; export const vTransferAction = ({ - client, - to_id, - from_id, - quantity, + client, + to_id, + from_id, + quantity, }: vTransferActionArgs): AnyAction => { - if (!client.session) { - throw new SessionNotFoundError("Session is required for this method."); - } + if (!client.session) { + throw new SessionNotFoundError("Session is required for this method."); + } - const { actor, authorization } = client.session; - const { vaccount, token } = useEFXContracts(client); + const { actor, authorization } = client.session; + const { vaccount, token } = useEFXContracts(client); - return { - account: vaccount, - name: "vtransfer", - authorization, - data: { - from_id, - to_id, - quantity: { - quantity: Asset.from(quantity, "4,EFX"), - contract: token, - }, - memo: "", - payer: actor, - sig: null, - fee: null, - }, - }; + return { + account: vaccount, + name: "vtransfer", + authorization, + data: { + from_id, + to_id, + quantity: { + quantity: Asset.from(quantity, "4,EFX"), + contract: token, + }, + memo: "", + payer: actor, + sig: null, + fee: null, + }, + }; }; export type vTransferArgs = { - client: Client; - from_id: number; - to_id: number; - quantity: number; + client: Client; + from_id?: number; // from_id is optional, if sesion is connected, sending from actor is possible. + to_id: number; + quantity: number; }; export const vTransfer = async ({ - client, - from_id, - to_id, - quantity, + client, + from_id, + to_id, + quantity, }: vTransferArgs): Promise => { - if (!client.session) { - throw new SessionNotFoundError("Session is required for this method."); - } - const { transact } = client.session; + if (!client.session) { + throw new SessionNotFoundError("Session is required for this method."); + } + const { transact, actor } = client.session; - const transferAction = vTransferAction({ - client, - to_id, - from_id, - quantity, - }); + const [vaccount] = await getVAccounts({ client, actor }); - return await transact({ action: transferAction }); + const transferAction = vTransferAction({ + client, + to_id, + from_id: from_id ?? vaccount.id, + quantity, + }); + + return await transact({ action: transferAction }); }; diff --git a/test/src/utils.ts b/test/src/utils.ts index 44af7fe3..95e48303 100644 --- a/test/src/utils.ts +++ b/test/src/utils.ts @@ -2,7 +2,6 @@ import { PrivateKey, type PrivateKeyType, Session, - PermissionLevel, } from "@wharfkit/session"; import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; import { jungle4, } from "../../src/exports"; @@ -41,7 +40,7 @@ export const destructureEnv = () => { }; }; -export const testClientSession = async ({ network }: { network: Network }): Promise => { +export const testClientSession = async (): Promise => { // Retrieve parameters for session. const { network: chain, permission, actor, privateKey } = destructureEnv(); @@ -49,19 +48,13 @@ export const testClientSession = async ({ network }: { network: Network }): Prom throw new Error("Private key not found"); } - // Create client - const client = createClient({ network }); - // Setup wallet plugin with private key const walletPlugin = new WalletPluginPrivateKey(privateKey); - /** Create new permission level from representing types. Can be expressed as a string in the format `@`. */ - const permissionLevel = PermissionLevel.from(`${actor}@${permission}`); - // Set up session with wallet and chain - const session = new Session({ actor, permission, walletPlugin, chain, permissionLevel }); + const session = new Session({ actor, permission, walletPlugin, chain }); - // Connect session to client - await client.setSession(session); + // Create client + const client = await createClient({ session }); return client; }; From b4a66a1c2795729f39fe6395c72df1a05a605701 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:31:45 -0400 Subject: [PATCH 31/84] Update generated types --- src/@generated/types/efxaccount11.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/@generated/types/efxaccount11.ts b/src/@generated/types/efxaccount11.ts index ee744172..bede5231 100644 --- a/src/@generated/types/efxaccount11.ts +++ b/src/@generated/types/efxaccount11.ts @@ -1,8 +1,5 @@ import type { - BytesType, Checksum160, - Checksum160Type, - UInt64, ExtendedSymbol, Signature, } from "@wharfkit/antelope"; From 7fdc26d17434f49d6a6c7be38d48a1c47dead667 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 21:32:13 -0400 Subject: [PATCH 32/84] Update get-balance docs and init transfer docs --- docs/pages/docs/token/get-balance.mdx | 5 +++- docs/pages/docs/token/transfer.mdx | 33 +++++++++++++++++++++------ docs/snippets/client.ts | 4 ++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index 8f1978a0..a2921ba6 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -2,9 +2,12 @@ ## Description -This function is used to get the balance of EFX of an Effect Network account. +This function is used to get the balance of EFX of an Effect Network account on the EOS blockchain. +There is a difference between the balance of EFX of an account on the blockchain and the balance of EFX deposited in an Effect Account. +This function returns the balance of EFX on the blockchain. Note the use of `balance.toString()` to convert the balance to a string. + ## Usage ```ts diff --git a/docs/pages/docs/token/transfer.mdx b/docs/pages/docs/token/transfer.mdx index 74aa7bd4..f3e67e6e 100644 --- a/docs/pages/docs/token/transfer.mdx +++ b/docs/pages/docs/token/transfer.mdx @@ -1,19 +1,38 @@ - # VTransfer ## Description Transfer EFX tokens from one vAccount to another. +Effect accounts are created so that users can interact with the Effect Network platform. +These accounts can be loaded with EFX tokens and used to pay for services on the platform. +This action allows users to transfer EFX tokens from one Effect account to another Effect account. ## Usage -```ts [example.ts] -import { getCampaigns } from '@effectai/effect-js' +```ts +import { + getCampaigns, + createClient, + jungle4 as network + vTransfer +} from '@effectai/sdk' + +const client = createClient({ network }) +const accountName = Name.from(actor); + +const vAccount = await getOrCreateVAccount({ client, actor: accountName }); +const preBalanceVAccount = Number(vAccount.balance.quantity); + +const vAccountReceiver = await getOrCreateVAccount({ + client, + actor: receiver, +}); +const preBalanceReceiver = Number(vAccountReceiver.balance.quantity); -const campaigns = await getCampaigns({ // [!code focus] - client, - limit: 10, - page: 1 +const result = await vTransfer({ + client, + to_id: vAccountReceiver.id, + quantity, }); ``` diff --git a/docs/snippets/client.ts b/docs/snippets/client.ts index 31df0f2b..fcd6b084 100644 --- a/docs/snippets/client.ts +++ b/docs/snippets/client.ts @@ -1,5 +1,5 @@ -import { createClient } from "@effectai/effect-js"; +import { createClient, eos } from "@effectai/sdk"; export const client = createClient({ - chain: mainnet, + chain: eos, }); From 30106a20274b0a5daa6032d877a32d003b7b62a9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Thu, 9 May 2024 22:28:46 -0400 Subject: [PATCH 33/84] Add test files --- src/actions/tasks/batch/createBatch.test.ts | 0 src/actions/tasks/batch/getBatch.test.ts | 0 src/actions/tasks/getAccTaskIdx.test.ts | 0 src/actions/tasks/getForceSettings.test.ts | 0 src/actions/tasks/getRepetitions.test.ts | 0 src/actions/tasks/getSubmissions.test.ts | 0 src/actions/tasks/getTask.test.ts | 0 src/actions/tasks/reservations/getReservations.test.ts | 0 src/actions/tasks/reservations/reserveTask.test.ts | 0 src/actions/tasks/submitTask.test.ts | 0 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/actions/tasks/batch/createBatch.test.ts create mode 100644 src/actions/tasks/batch/getBatch.test.ts create mode 100644 src/actions/tasks/getAccTaskIdx.test.ts create mode 100644 src/actions/tasks/getForceSettings.test.ts create mode 100644 src/actions/tasks/getRepetitions.test.ts create mode 100644 src/actions/tasks/getSubmissions.test.ts create mode 100644 src/actions/tasks/getTask.test.ts create mode 100644 src/actions/tasks/reservations/getReservations.test.ts create mode 100644 src/actions/tasks/reservations/reserveTask.test.ts create mode 100644 src/actions/tasks/submitTask.test.ts diff --git a/src/actions/tasks/batch/createBatch.test.ts b/src/actions/tasks/batch/createBatch.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/batch/getBatch.test.ts b/src/actions/tasks/batch/getBatch.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/getAccTaskIdx.test.ts b/src/actions/tasks/getAccTaskIdx.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/getForceSettings.test.ts b/src/actions/tasks/getForceSettings.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/getRepetitions.test.ts b/src/actions/tasks/getRepetitions.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/getSubmissions.test.ts b/src/actions/tasks/getSubmissions.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/getTask.test.ts b/src/actions/tasks/getTask.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/reservations/getReservations.test.ts b/src/actions/tasks/reservations/getReservations.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/reservations/reserveTask.test.ts b/src/actions/tasks/reservations/reserveTask.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/actions/tasks/submitTask.test.ts b/src/actions/tasks/submitTask.test.ts new file mode 100644 index 00000000..e69de29b From bd60500fdf12fb404a703c370ad54b3cee51b1e9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 12:29:37 -0400 Subject: [PATCH 34/84] Add claim.test.ts --- src/actions/vaccount/claim.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/actions/vaccount/claim.test.ts diff --git a/src/actions/vaccount/claim.test.ts b/src/actions/vaccount/claim.test.ts new file mode 100644 index 00000000..7a0e912c --- /dev/null +++ b/src/actions/vaccount/claim.test.ts @@ -0,0 +1,19 @@ +import { expect, test, describe } from "bun:test"; +import { createClient } from "../../client"; +import { testClientSession } from "../../../test/src/utils"; +import { claim, jungle4 as network } from "../../exports"; + +describe("Claim", async () => { + test.todo("Should throw when no payment is pending", async () => { + // const client = await createClient({ network }); + const client = await testClientSession(); + const response = await claim({ client }); + console.error(response); + // expect(async () => await claim({ client })).toThrow(); + }); + + test.todo("Should claim pending payments", async () => { + // TODO: Should claim pending payments + // Figure out flow to test this + }); +}); From 951be62103259835dddd04df4a9321e27bcc05df Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 12:38:50 -0400 Subject: [PATCH 35/84] Fix getAvatar function signature with getAvatarArgs --- src/actions/vaccount/getAvatar.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/actions/vaccount/getAvatar.ts b/src/actions/vaccount/getAvatar.ts index c7cda088..ec8276ad 100644 --- a/src/actions/vaccount/getAvatar.ts +++ b/src/actions/vaccount/getAvatar.ts @@ -1,8 +1,10 @@ -import type { Client } from "../../client"; import { getAsset } from "../atomic/getAsset"; -import { getAvatar as getDaoAvatar } from "../dao/getAvatar"; +import { + getAvatar as getDaoAvatar, + type GetAvatarArgs, +} from "../dao/getAvatar"; -export const getAvatar = async (client: Client, account: string) => { +export const getAvatar = async ({ client, account }: GetAvatarArgs) => { const defaultImg = "QmZQiEWsaTNpANMv9orwDvuGyMRkY5nQNazSB1KkW4pM6t"; const defaultVid = "QmZQiEWsaTNpANMv9orwDvuGyMRkY5nQNazSB1KkW4pM6t"; const daoAvatar = await getDaoAvatar({ client, account }); From 7da3801bfaf96785187b73753f63a43497268fd6 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 12:39:10 -0400 Subject: [PATCH 36/84] fix: export proper getAvatar function --- src/exports/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/exports/index.ts b/src/exports/index.ts index 28e4d6ce..d2276b59 100644 --- a/src/exports/index.ts +++ b/src/exports/index.ts @@ -11,7 +11,7 @@ export { export { getSchema, type getSchemaArgs } from "./../actions/atomic/getSchema"; -export { getAvatar, type GetAvatarArgs } from "./../actions/dao/getAvatar"; +export { type GetAvatarArgs } from "./../actions/dao/getAvatar"; export { getDaoSettings, type GetDaoSettingsArgs, @@ -109,6 +109,8 @@ export { getPrice } from "./../actions/token/getPrice"; export { getBalance, type GetBalanceArgs } from "./../actions/token/getBalance"; export { swap, swapDirection } from "./../actions/token/swap"; +export { getAvatar } from "./../actions/vaccount/getAvatar"; + export { getVAccounts, type GetVAccountsArgs, From 731bd6c4622d01c45fd5caab33b2ecc4868a75f8 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:27:57 -0400 Subject: [PATCH 37/84] todo: getAvatar, getAsset are not working as expected --- src/actions/dao/getAvatar.ts | 1 + src/actions/vaccount/getAvatar.test.ts | 18 ++++++++++++++++++ src/actions/vaccount/getAvatar.ts | 8 ++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/actions/vaccount/getAvatar.test.ts diff --git a/src/actions/dao/getAvatar.ts b/src/actions/dao/getAvatar.ts index c5e9fc0f..1d305334 100644 --- a/src/actions/dao/getAvatar.ts +++ b/src/actions/dao/getAvatar.ts @@ -6,6 +6,7 @@ export type GetAvatarArgs = { account: string; }; +// TODO: This does not seem to be working as expected export const getAvatar = async ({ client, account }: GetAvatarArgs) => { const { dao } = useEFXContracts(client); const { provider } = client; diff --git a/src/actions/vaccount/getAvatar.test.ts b/src/actions/vaccount/getAvatar.test.ts new file mode 100644 index 00000000..7af694fc --- /dev/null +++ b/src/actions/vaccount/getAvatar.test.ts @@ -0,0 +1,18 @@ +import { expect, test, describe } from "bun:test"; +import { createClient } from "../../client"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { getAvatar, jungle4 as network } from "../../exports"; + +describe("getAvatar", async () => { + test.todo("Should retrieve avatar for user", async () => { + const client = await createClient({ network }); + const account = "cryptonode42"; + const response = await getAvatar({ client, account }); + expect(response).toBeDefined(); + }); + + test.todo("Should claim pending payments", async () => { + // TODO: Should claim pending payments + // Figure out flow to test this + }); +}); diff --git a/src/actions/vaccount/getAvatar.ts b/src/actions/vaccount/getAvatar.ts index ec8276ad..5f7715a0 100644 --- a/src/actions/vaccount/getAvatar.ts +++ b/src/actions/vaccount/getAvatar.ts @@ -4,14 +4,18 @@ import { type GetAvatarArgs, } from "../dao/getAvatar"; +// TODO: This function is failing, but it is not mission critical for the app to work. export const getAvatar = async ({ client, account }: GetAvatarArgs) => { const defaultImg = "QmZQiEWsaTNpANMv9orwDvuGyMRkY5nQNazSB1KkW4pM6t"; const defaultVid = "QmZQiEWsaTNpANMv9orwDvuGyMRkY5nQNazSB1KkW4pM6t"; - const daoAvatar = await getDaoAvatar({ client, account }); + + // This function is failing, let's comment it out for now. + // const daoAvatar = await getDaoAvatar({ client, account }); const asset = await getAsset({ client, account, - assetId: daoAvatar.asset_id, + assetId: "2199025109172", + // assetId: daoAvatar.asset_id, }); return { ...asset, From 4edc84f3e4620044f2a1aa01d49cb920bc7f85cb Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:32:21 -0400 Subject: [PATCH 38/84] implement payout.test.ts --- src/actions/vaccount/payout.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/actions/vaccount/payout.test.ts diff --git a/src/actions/vaccount/payout.test.ts b/src/actions/vaccount/payout.test.ts new file mode 100644 index 00000000..c93369b3 --- /dev/null +++ b/src/actions/vaccount/payout.test.ts @@ -0,0 +1,18 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { payout } from "../../exports"; + +describe("PayOut", async () => { + test("Should fail payout when there is no pending payout", async () => { + const { actor } = destructureEnv(); + const client = await testClientSession(); + expect(async () => await payout({ client, actor })).toThrowError( + "No payouts currently claimable.", + ); + }); + + test.todo("Should payout pending payments", async () => { + // TODO: Should payout pending payments + // Figure out flow to test this + }); +}); From 20955e39749949079d1fc83e372d7bf62b07c0d5 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:39:35 -0400 Subject: [PATCH 39/84] Fix: use ExtendedAssetType instead of ExtendedAsset --- src/actions/vaccount/withdraw.ts | 10 +++++++--- src/exports/index.ts | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/actions/vaccount/withdraw.ts b/src/actions/vaccount/withdraw.ts index 00806aca..5a03c4e6 100644 --- a/src/actions/vaccount/withdraw.ts +++ b/src/actions/vaccount/withdraw.ts @@ -1,9 +1,13 @@ -import type { AnyAction, ExtendedAsset, NameType } from "@wharfkit/antelope"; +import type { + AnyAction, + ExtendedAssetType, + NameType, +} from "@wharfkit/antelope"; import type { Client } from "../../exports"; export type WithdrawArgs = { client: Client; - quantity: ExtendedAsset; + quantity: ExtendedAssetType; }; export const withdraw = async ({ client, quantity }: WithdrawArgs) => { @@ -29,7 +33,7 @@ export const withdraw = async ({ client, quantity }: WithdrawArgs) => { export type WithdrawActionArgs = { from_id: number; to_account: NameType; - quantity: ExtendedAsset; + quantity: ExtendedAssetType; account: string; authorization: { actor: NameType; permission: NameType }[]; memo: string; diff --git a/src/exports/index.ts b/src/exports/index.ts index d2276b59..4955db1b 100644 --- a/src/exports/index.ts +++ b/src/exports/index.ts @@ -181,6 +181,11 @@ export type { GetTableRowsResponse } from "./types"; export { Template } from "./template"; -export { Session, Name, type NameType } from "@wharfkit/session"; +export { + Session, + Name, + type NameType, + type ExtendedAssetType, +} from "@wharfkit/session"; export { version } from "./version"; From 734badbf32d61800e4f120b31516c18e2817d241 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:48:14 -0400 Subject: [PATCH 40/84] Add test to withdraw.test.ts --- src/actions/vaccount/withdraw.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/actions/vaccount/withdraw.test.ts diff --git a/src/actions/vaccount/withdraw.test.ts b/src/actions/vaccount/withdraw.test.ts new file mode 100644 index 00000000..feecd5b6 --- /dev/null +++ b/src/actions/vaccount/withdraw.test.ts @@ -0,0 +1,22 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { withdraw, jungle4 as network, createClient } from "../../exports"; +import type { ExtendedAssetType } from "@wharfkit/antelope"; + +describe("withdraw", async () => { + test.skip("Should withdraw vaccount EFX to wallet.", async () => { + const client = await testClientSession(); + const quantity: ExtendedAssetType = { + quantity: "0.0001 EFX", + contract: client.network.config.efx.contracts.token, + }; + const result = await withdraw({ client, quantity }); + console.log(result); + expect(result).toBeDefined(); + }); + + test.todo("Should fail when no EFX is in vAccount", async () => { + // TODO: Should fail when no EFX is in the vAccount + // Figure out flow to test this + }); +}); From e566b82abf532cb6b613e89a4d4e56471097d184 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:55:05 -0400 Subject: [PATCH 41/84] Add return type to `getOrCreate()` function signature --- src/actions/vaccount/getOrCreate.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/actions/vaccount/getOrCreate.ts b/src/actions/vaccount/getOrCreate.ts index 1661a74e..31033a02 100644 --- a/src/actions/vaccount/getOrCreate.ts +++ b/src/actions/vaccount/getOrCreate.ts @@ -1,6 +1,11 @@ import type { NameType } from "@wharfkit/antelope"; import type { Session } from "@wharfkit/session"; -import { type Client, createVAccount, getVAccounts } from "../../exports"; +import { + type Client, + createVAccount, + getVAccounts, + type Account, +} from "../../exports"; export const getOrCreateVAccount = async ({ client, @@ -10,7 +15,7 @@ export const getOrCreateVAccount = async ({ client: Client; actor: NameType; session?: Session; -}) => { +}): Promise => { try { let [account] = await getVAccounts({ client, actor }); From d63b5a47b750c6617035e827f6c679bb40bfa142 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 13:55:16 -0400 Subject: [PATCH 42/84] Add getOrCreate.test.ts --- src/actions/vaccount/getOrCreate.test.ts | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/actions/vaccount/getOrCreate.test.ts diff --git a/src/actions/vaccount/getOrCreate.test.ts b/src/actions/vaccount/getOrCreate.test.ts new file mode 100644 index 00000000..7e2d36ff --- /dev/null +++ b/src/actions/vaccount/getOrCreate.test.ts @@ -0,0 +1,29 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { jungle4 as network, type Account } from "../../exports"; +import { getOrCreateVAccount } from "./getOrCreate"; + +describe("GetOrCreate", async () => { + const vaccExample: Account = { + id: 0, + nonce: 53, + address: ["name", "efxforceacc1"], + balance: { + quantity: "3525.0000 EFX", + contract: "effecttokens", + }, + }; + + test("Should get account", async () => { + const client = await testClientSession(); + const { actor } = destructureEnv(); + const result = await getOrCreateVAccount({ client, actor }); + expect(result).toBeDefined(); + expect(result).toContainKeys(Object.keys(vaccExample)); + }); + + test.todo("Should create new account", async () => { + // TODO: Should create new account + // Figure out flow to test this + }); +}); From ca4f195aa675fbde363467fe84d0a7b8e5207b55 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 14:54:00 -0400 Subject: [PATCH 43/84] Fix efx symbol for createBatch function --- src/actions/tasks/batch/createBatch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/tasks/batch/createBatch.ts b/src/actions/tasks/batch/createBatch.ts index 3bc39712..4de4b695 100644 --- a/src/actions/tasks/batch/createBatch.ts +++ b/src/actions/tasks/batch/createBatch.ts @@ -107,7 +107,7 @@ export const createBatch = async ({ } const campaign = await getCampaignById({ client, id: campaignId }); - const assetQuantity = Asset.from(reward, " EFX"); + const assetQuantity = Asset.from(reward, "4,EFX"); const batchPrice = assetQuantity.value * repetitions; // Check if the user has enough funds to pay for the batch From fbf5502115f8b55afcdef995fb4c7be636dcceb9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 14:59:03 -0400 Subject: [PATCH 44/84] Add createBatch.test.ts --- src/actions/tasks/batch/createBatch.test.ts | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/actions/tasks/batch/createBatch.test.ts b/src/actions/tasks/batch/createBatch.test.ts index e69de29b..8130fccc 100644 --- a/src/actions/tasks/batch/createBatch.test.ts +++ b/src/actions/tasks/batch/createBatch.test.ts @@ -0,0 +1,51 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { + createBatch, + getBatchById, + getCampaignById, + getIpfsResource, + jungle4 as network, +} from "../../../exports"; + +describe("getAvatar", async () => { + test.todo("Should create a new batch for given campaign", async () => { + const campaignId = 1; + const client = await testClientSession(); + const preCampaign = await getCampaignById({ client, id: campaignId }); + + const batch = await getBatchById({ client, id: preCampaign.active_batch }); + console.debug("batch", batch); + + const batchData = await getIpfsResource({ + client, + hash: batch.content.field_1, + }); + console.debug("batchData", batchData); + + const taskData: Record = { + "e20bb19f-ca14-4575-8c14-1916896cb2f3": "Random question here", + "35921e43-f058-4214-88e8-062a7eebe878": "Random answer here", + "ba1865eb-6a52-4e06-9a64-ed351cf3f2e2": "Other question here", + "b9d1a1f7-3b4f-4c7b-9b5d-3f0b3b7d4b9e": "Other answer here", + }; + + const response = await createBatch({ + client, + campaignId, + reward: 1, + repetitions: 1, + taskData, + }); + + expect(response).toBeDefined(); + + const postCampaign = await getCampaignById({ client, id: campaignId }); + expect(postCampaign.num_batches).toBeGreaterThan(preCampaign.num_batches); + }); + + test.todo("Should fail when ...", async () => { + // TODO: Should fail when there isn't enough funds, or session connected. + // Figure out flow to test this + }); +}); From 4c8f1cd7ad660db19f742faab68d6e09b3b436a5 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:05:59 -0400 Subject: [PATCH 45/84] Add getBatch.test.ts --- src/actions/tasks/batch/getBatch.test.ts | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/actions/tasks/batch/getBatch.test.ts b/src/actions/tasks/batch/getBatch.test.ts index e69de29b..107a0ab9 100644 --- a/src/actions/tasks/batch/getBatch.test.ts +++ b/src/actions/tasks/batch/getBatch.test.ts @@ -0,0 +1,32 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { + createBatch, + getBatchById, + getCampaignById, + getIpfsResource, + jungle4 as network, +} from "../../../exports"; + +describe("getAvatar", async () => { + test("Should create a new batch for given campaign", async () => { + const campaignId = 1; + const client = await testClientSession(); + const campaign = await getCampaignById({ client, id: campaignId }); + const batchById = await getBatchById({ + client, + id: campaign.active_batch, + }); + + const batch = await getBatchById({ client, id: batchById.id }); + expect(batch).toBeDefined(); + expect(batch.id).toBe(batchById.id); + }); + + test("Should return undefined if batch does not exist.", async () => { + const nonExistentBatchId = 999999999; + const client = await testClientSession(); + const batch = await getBatchById({ client, id: nonExistentBatchId }); + expect(batch).toBeUndefined(); + }); +}); From b23eb025151905a2ef2b70f29fffefaaeaab8ab1 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:18:13 -0400 Subject: [PATCH 46/84] Add getTaskIdx.test.ts --- src/actions/tasks/getAccTaskIdx.test.ts | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/actions/tasks/getAccTaskIdx.test.ts b/src/actions/tasks/getAccTaskIdx.test.ts index e69de29b..b86b8c49 100644 --- a/src/actions/tasks/getAccTaskIdx.test.ts +++ b/src/actions/tasks/getAccTaskIdx.test.ts @@ -0,0 +1,34 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { + createBatch, + getAccTaskIdx, + getBatchById, + getCampaignById, + getIpfsResource, + getVAccounts, + jungle4 as network, +} from "../../exports"; + +describe("getAccountTaskIndex", async () => { + test("Should return an array", async () => { + const client = await testClientSession(); + const { actor } = destructureEnv(); + const [vacc] = await getVAccounts({ client, actor }); + + const accTaskIdx = await getAccTaskIdx({ client, accountId: vacc.id }); + expect(accTaskIdx).toBeDefined(); + expect(accTaskIdx).toBeArray(); + }); + + test.todo( + "Should return a value within the array when reserving task", + async () => { + // TODO: Implement this test + // Figure out flow of reserving a task, + // retrieving the task index, + // verifying the task index and + // submitting the task to complete the cycle. + }, + ); +}); From 2eedec96b884bac742acd97bfe4df66544424c32 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:24:00 -0400 Subject: [PATCH 47/84] Add getForceSettings.test.ts --- src/actions/tasks/getForceSettings.test.ts | 22 ++++++++++++++++++++++ src/actions/tasks/getForceSettings.ts | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/actions/tasks/getForceSettings.test.ts b/src/actions/tasks/getForceSettings.test.ts index e69de29b..f22fab23 100644 --- a/src/actions/tasks/getForceSettings.test.ts +++ b/src/actions/tasks/getForceSettings.test.ts @@ -0,0 +1,22 @@ +import { expect, test, describe } from "bun:test"; +import { testClientSession } from "../../../test/src/utils"; +import { getForceSettings } from "../../exports"; + +describe("getForceSettings", async () => { + const settingsExample = { + vaccount_contract: "efxaccount11", + force_vaccount_id: 11, + payout_delay_sec: 1800, + release_task_delay_sec: 1800, + fee_contract: "efxfeepool11", + fee_percentage: "0.10000000149011612", + }; + + test("Should match config settings", async () => { + const client = await testClientSession(); + const settings = await getForceSettings({ client }); + console.debug(settings); + expect(settings).toBeDefined(); + expect(Object.keys(settings)).toEqual(Object.keys(settingsExample)); + }); +}); diff --git a/src/actions/tasks/getForceSettings.ts b/src/actions/tasks/getForceSettings.ts index 5e713930..e7fb2dec 100644 --- a/src/actions/tasks/getForceSettings.ts +++ b/src/actions/tasks/getForceSettings.ts @@ -8,12 +8,12 @@ export type GetForceSettingsArgs = { export const getForceSettings = async ({ client }: GetForceSettingsArgs) => { const { provider, network } = client; - const { contracts } = network.config.efx; + const { tasks } = network.config.efx.contracts; try { const response = (await provider.v1.chain.get_table_rows({ - code: contracts.tasks, - scope: contracts.tasks, + code: tasks, + scope: tasks, table: "settings", })) as GetTableRowsResponse; From 4b92a6720030c237c746527d470c104f9d0227cf Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:27:29 -0400 Subject: [PATCH 48/84] Add getRepititions.test.ts --- src/actions/tasks/getRepetitions.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/actions/tasks/getRepetitions.test.ts b/src/actions/tasks/getRepetitions.test.ts index e69de29b..b0e0f3ab 100644 --- a/src/actions/tasks/getRepetitions.test.ts +++ b/src/actions/tasks/getRepetitions.test.ts @@ -0,0 +1,13 @@ +import { expect, test, describe } from "bun:test"; +import { testClientSession } from "../../../test/src/utils"; +import { getRepetitions } from "../../exports"; + +describe("getRepetitions", async () => { + test("Should retrieve the repitions as array", async () => { + const client = await testClientSession(); + const repitions = await getRepetitions({ client }); + console.debug(repitions); + expect(repitions).toBeDefined(); + expect(repitions).toBeArray(); + }); +}); From 67af03ae431a4e5f8908585d2cd4a10d35320774 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:27:47 -0400 Subject: [PATCH 49/84] Add getRepitionsArgs to getRepitions function --- src/actions/tasks/getRepetitions.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/actions/tasks/getRepetitions.ts b/src/actions/tasks/getRepetitions.ts index 6fde6571..0ffd96f7 100644 --- a/src/actions/tasks/getRepetitions.ts +++ b/src/actions/tasks/getRepetitions.ts @@ -1,7 +1,11 @@ import type { Client } from "../../client"; import { useEFXContracts } from "../../utils/state"; -export const getRepetitions = async (client: Client) => { +export type GetRepetitionsArgs = { + client: Client; +}; + +export const getRepetitions = async ({ client }: GetRepetitionsArgs) => { try { const { tasks } = useEFXContracts(client); const { provider } = client; From cc7e1cd468b3fde5330eea61f6f20fda0bf83cc2 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:32:34 -0400 Subject: [PATCH 50/84] Update getSubmissions return value --- src/actions/tasks/getSubmissions.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/actions/tasks/getSubmissions.ts b/src/actions/tasks/getSubmissions.ts index 1d419fea..4851a37f 100644 --- a/src/actions/tasks/getSubmissions.ts +++ b/src/actions/tasks/getSubmissions.ts @@ -12,7 +12,7 @@ export type GetSubmissionsArgs = { export const getSubmissions = async ({ client, reverse = false, -}: GetSubmissionsArgs) => { +}: GetSubmissionsArgs): Promise => { try { const { provider } = client; const { tasks } = useEFXContracts(client); @@ -24,7 +24,9 @@ export const getSubmissions = async ({ reverse, })) as GetTableRowsResponse; - return data; + const { rows } = data; + + return rows; } catch (e) { console.error("Error while fetching tasks:", e); throw new Error("Failed to fetch tasks"); From 46128da11a0ee3a369f343b9a9c26a3f5775ec3c Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:34:34 -0400 Subject: [PATCH 51/84] Add getSubmission.test.ts --- src/actions/tasks/getSubmissions.test.ts | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/actions/tasks/getSubmissions.test.ts b/src/actions/tasks/getSubmissions.test.ts index e69de29b..c0d61d89 100644 --- a/src/actions/tasks/getSubmissions.test.ts +++ b/src/actions/tasks/getSubmissions.test.ts @@ -0,0 +1,32 @@ +import { expect, test, describe } from "bun:test"; +import { testClientSession } from "../../../test/src/utils"; +import { getSubmissions } from "../../exports"; + +describe("getSubmissions", async () => { + const submissionExample = { + id: 37, + campaign_id: 6, + task_idx: 0, + account_id: 12, + content: null, + batch_id: "25769803776", + data: { + first: 1, + second: + "426624b24a7703d02c5797020c46dc10d573171c77b6eca915311ecb1820700c126f", + }, + paid: 0, + submitted_on: "2024-05-04T20:39:30", + }; + + test("Should get submissions", async () => { + const client = await testClientSession(); + const submissions = await getSubmissions({ client, reverse: false }); + + expect(submissions).toBeDefined(); + expect(submissions).toBeArray(); + + const [submission] = submissions; + expect(Object.keys(submission)).toEqual(Object.keys(submissionExample)); + }); +}); From 1704f63f689fa94182d729ad1afc83372e443d0c Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 15:51:54 -0400 Subject: [PATCH 52/84] Add getTask.test.ts --- src/actions/tasks/getTask.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/actions/tasks/getTask.test.ts b/src/actions/tasks/getTask.test.ts index e69de29b..5ab1bcf5 100644 --- a/src/actions/tasks/getTask.test.ts +++ b/src/actions/tasks/getTask.test.ts @@ -0,0 +1,27 @@ +import { expect, test, describe } from "bun:test"; +import { testClientSession } from "../../../test/src/utils"; +import { + getAccTaskIdx, + getBatchById, + getCampaignById, + getTaskData, +} from "../../exports"; + +describe("getTask", async () => { + test("Should get task", async () => { + const client = await testClientSession(); + const campaignById = await getCampaignById({ client, id: 1 }); + const batchById = await getBatchById({ + client, + id: campaignById.active_batch, + }); + const taskIndex = batchById.start_task_idx; + + const taskData = await getTaskData({ + client, + taskIndex, + batchId: batchById.id, + }); + expect(taskData).toBeDefined(); + }); +}); From 8bd5326c68a14f3fa239e90075941458096e930d Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:13:28 -0400 Subject: [PATCH 53/84] Clean up getReservations.ts, add return types, return object instead of array when needed --- .../tasks/reservations/getReservations.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/actions/tasks/reservations/getReservations.ts b/src/actions/tasks/reservations/getReservations.ts index ba4f1cb1..4adaba1b 100644 --- a/src/actions/tasks/reservations/getReservations.ts +++ b/src/actions/tasks/reservations/getReservations.ts @@ -17,10 +17,10 @@ export const getReservations = async ({ lowerBound, upperBound, indexPosition = "secondary", -}: GetReservationsArgs) => { +}: GetReservationsArgs): Promise => { const { tasks } = useEFXContracts(client); - return (await client.provider.v1.chain.get_table_rows({ + const response = (await client.provider.v1.chain.get_table_rows({ scope: tasks, code: tasks, table: "reservation", @@ -28,6 +28,9 @@ export const getReservations = async ({ upper_bound: upperBound, lower_bound: lowerBound, })) as GetTableRowsResponse; + + const { rows } = response; + return rows; }; export type GetReservationsForCampaignArgs = { @@ -38,12 +41,11 @@ export type GetReservationsForCampaignArgs = { export const getReservationsForCampaign = async ({ client, campaignId, -}: GetReservationsForCampaignArgs) => { +}: GetReservationsForCampaignArgs): Promise => { try { const lowerBound = createCompositeU64Key(campaignId, 0); const upperBound = createCompositeU64Key(campaignId, Number(UInt32.max)); - const { rows } = await getReservations({ client, lowerBound, upperBound }); - return rows; + return await getReservations({ client, lowerBound, upperBound }); } catch (e) { console.error(e); throw e; @@ -58,18 +60,16 @@ export type GetReservationForVAccountArgs = { export const getReservationsForVAccount = async ({ client, vAccountId, -}: GetReservationForVAccountArgs) => { +}: GetReservationForVAccountArgs): Promise => { try { if (!vAccountId) throw new Error("vAccountId is required"); - const data = await getReservations({ + return await getReservations({ client, lowerBound: UInt64.from(vAccountId), upperBound: UInt64.from(vAccountId), indexPosition: "fourth", }); - - return data.rows; } catch (e) { console.error(e); throw e; @@ -82,11 +82,12 @@ export type GetReservationForCampaignArgs = { vAccountId: number; }; +// TODO: This function name is unclear, we should rename it to: getVAccountReservationForCampaign export const getReservationForCampaign = async ({ client, campaignId, vAccountId, -}: GetReservationForCampaignArgs) => { +}: GetReservationForCampaignArgs): Promise => { try { const bound = createCompositeU64Key(campaignId, vAccountId); const data = await getReservations({ @@ -95,7 +96,8 @@ export const getReservationForCampaign = async ({ upperBound: bound, }); - return data.rows[0]; + const [reservation] = data; + return reservation; } catch (e) { console.error(e); throw e; From ff9204bb237171d33ec41497bd2d93c0ddca5649 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:13:41 -0400 Subject: [PATCH 54/84] add getReservations.test.ts --- .../reservations/getReservations.test.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/actions/tasks/reservations/getReservations.test.ts b/src/actions/tasks/reservations/getReservations.test.ts index e69de29b..1ac10987 100644 --- a/src/actions/tasks/reservations/getReservations.test.ts +++ b/src/actions/tasks/reservations/getReservations.test.ts @@ -0,0 +1,63 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { + getReservations, + getReservationForCampaign, + getReservationsForVAccount, + getReservationsForCampaign, +} from "./getReservations"; +import { getVAccounts } from "../../vaccount/getAccounts"; + +describe("getReservation", async () => { + test("Should return an array, with getReservations()", async () => { + const client = await testClientSession(); + const reservation = await getReservations({ client }); + + expect(reservation).toBeDefined(); + expect(reservation).toBeArray(); + }); + + test("Should get reservation for vAccount", async () => { + const client = await testClientSession(); + const { actor } = destructureEnv(); + const [vacc] = await getVAccounts({ client, actor }); + + const reservation = await getReservationsForVAccount({ + client, + vAccountId: vacc.id, + }); + + expect(reservation).toBeDefined(); + expect(reservation).toBeArray(); + }); + + test("Should get reservation for Campaigns", async () => { + const client = await testClientSession(); + const reservation = await getReservationsForCampaign({ + client, + campaignId: 1, + }); + + expect(reservation).toBeDefined(); + expect(reservation).toBeArray(); + }); + + // TODO: Sometimes the user will not have a reservation, so we need to make sure that + // a reservation is created before running this test. + test.todo("Should get reservation for Campaign by vAccountId", async () => { + const client = await testClientSession(); + const { actor } = destructureEnv(); + const [vacc] = await getVAccounts({ client, actor }); + + const reservation = await getReservationForCampaign({ + client, + vAccountId: vacc.id, + campaignId: 1, + }); + + console.debug(reservation); + + expect(reservation).toBeDefined(); + expect(reservation).toBeArray(); + }); +}); From d297b42b40df02e3930cf1b9bcde07605dcaccf8 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:18:15 -0400 Subject: [PATCH 55/84] Add reserveTAsk.test.ts --- .../tasks/reservations/reserveTask.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/actions/tasks/reservations/reserveTask.test.ts b/src/actions/tasks/reservations/reserveTask.test.ts index e69de29b..6db764e1 100644 --- a/src/actions/tasks/reservations/reserveTask.test.ts +++ b/src/actions/tasks/reservations/reserveTask.test.ts @@ -0,0 +1,15 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { reserveTask } from "./reserveTask"; + +describe("reserveTask", async () => { + // TODO: Figure out flow for how to test this function + test.todo("Should reserve task", async () => { + const client = await testClientSession(); + + const reservation = await reserveTask({ client, campaignId: 1 }); + console.debug(reservation); + + expect(reservation).toBeDefined(); + }); +}); From 43498ab912ed27f3a49fe3488e99faef2c0d0af2 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:22:05 -0400 Subject: [PATCH 56/84] Add submitTask.test.ts --- src/actions/tasks/submitTask.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/actions/tasks/submitTask.test.ts b/src/actions/tasks/submitTask.test.ts index e69de29b..891ff491 100644 --- a/src/actions/tasks/submitTask.test.ts +++ b/src/actions/tasks/submitTask.test.ts @@ -0,0 +1,25 @@ +import { expect, test, describe } from "bun:test"; +import { destructureEnv, testClientSession } from "../../../test/src/utils"; +import { submitTask } from "./submitTask"; +import { getReservationForCampaign } from "./reservations/getReservations"; +import { getVAccounts } from "../vaccount/getAccounts"; + +describe("submitTask", async () => { + // TODO: Figure out flow for how to test this function + test.todo("Should submitTask", async () => { + const client = await testClientSession(); + const { actor } = destructureEnv(); + const [vAccount] = await getVAccounts({ client, actor }); + + const reservation = getReservationForCampaign({ + client, + campaignId: 1, + vAccountId: vAccount.id, + }); + + const response = await submitTask({ client, reservation, data: {} }); + + console.debug(response); + expect(response).toBeDefined(); + }); +}); From 47d3324225ba5d0365a363111435d4bd8cd2d62a Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:22:28 -0400 Subject: [PATCH 57/84] Add test:only to package.json scripts --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7b9fa8d7..6ab0909e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "scripts": { "test": "bun --env-file=.env test", "test:watch": "bun --env-file=.env test --watch", + "test:only": "bun --env-file=.env test --watch --only", "test:coverage": "bun --env-file=.env test --coverage", "dev": "tsc -w", "build": "tsc --module es2020", From 5024bab20ff265fa1f9dc1084d51f2dc3536dd98 Mon Sep 17 00:00:00 2001 From: David Britt Date: Fri, 10 May 2024 16:26:31 -0400 Subject: [PATCH 58/84] Clean up --- src/actions/tasks/batch/createBatch.test.ts | 5 +---- src/actions/tasks/batch/getBatch.test.ts | 10 ++-------- src/actions/tasks/getAccTaskIdx.test.ts | 10 +--------- src/actions/tasks/getForceSettings.test.ts | 1 - src/actions/tasks/getRepetitions.test.ts | 1 - src/actions/tasks/reservations/getReservations.test.ts | 2 -- src/actions/tasks/reservations/reserveTask.test.ts | 3 +-- src/actions/tasks/submitTask.test.ts | 3 +-- src/actions/vaccount/claim.test.ts | 6 ++---- src/actions/vaccount/getAvatar.test.ts | 1 - src/actions/vaccount/getOrCreate.test.ts | 2 +- src/actions/vaccount/withdraw.test.ts | 4 ++-- src/constants/config.ts | 7 +------ 13 files changed, 12 insertions(+), 43 deletions(-) diff --git a/src/actions/tasks/batch/createBatch.test.ts b/src/actions/tasks/batch/createBatch.test.ts index 8130fccc..c1500931 100644 --- a/src/actions/tasks/batch/createBatch.test.ts +++ b/src/actions/tasks/batch/createBatch.test.ts @@ -1,11 +1,10 @@ import { expect, test, describe } from "bun:test"; -import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { testClientSession } from "../../../../test/src/utils"; import { createBatch, getBatchById, getCampaignById, getIpfsResource, - jungle4 as network, } from "../../../exports"; describe("getAvatar", async () => { @@ -15,13 +14,11 @@ describe("getAvatar", async () => { const preCampaign = await getCampaignById({ client, id: campaignId }); const batch = await getBatchById({ client, id: preCampaign.active_batch }); - console.debug("batch", batch); const batchData = await getIpfsResource({ client, hash: batch.content.field_1, }); - console.debug("batchData", batchData); const taskData: Record = { "e20bb19f-ca14-4575-8c14-1916896cb2f3": "Random question here", diff --git a/src/actions/tasks/batch/getBatch.test.ts b/src/actions/tasks/batch/getBatch.test.ts index 107a0ab9..6873d8dd 100644 --- a/src/actions/tasks/batch/getBatch.test.ts +++ b/src/actions/tasks/batch/getBatch.test.ts @@ -1,12 +1,6 @@ import { expect, test, describe } from "bun:test"; -import { destructureEnv, testClientSession } from "../../../../test/src/utils"; -import { - createBatch, - getBatchById, - getCampaignById, - getIpfsResource, - jungle4 as network, -} from "../../../exports"; +import { testClientSession } from "../../../../test/src/utils"; +import { getBatchById, getCampaignById } from "../../../exports"; describe("getAvatar", async () => { test("Should create a new batch for given campaign", async () => { diff --git a/src/actions/tasks/getAccTaskIdx.test.ts b/src/actions/tasks/getAccTaskIdx.test.ts index b86b8c49..7fca2c0d 100644 --- a/src/actions/tasks/getAccTaskIdx.test.ts +++ b/src/actions/tasks/getAccTaskIdx.test.ts @@ -1,14 +1,6 @@ import { expect, test, describe } from "bun:test"; import { destructureEnv, testClientSession } from "../../../test/src/utils"; -import { - createBatch, - getAccTaskIdx, - getBatchById, - getCampaignById, - getIpfsResource, - getVAccounts, - jungle4 as network, -} from "../../exports"; +import { getAccTaskIdx, getVAccounts } from "../../exports"; describe("getAccountTaskIndex", async () => { test("Should return an array", async () => { diff --git a/src/actions/tasks/getForceSettings.test.ts b/src/actions/tasks/getForceSettings.test.ts index f22fab23..f883ba96 100644 --- a/src/actions/tasks/getForceSettings.test.ts +++ b/src/actions/tasks/getForceSettings.test.ts @@ -15,7 +15,6 @@ describe("getForceSettings", async () => { test("Should match config settings", async () => { const client = await testClientSession(); const settings = await getForceSettings({ client }); - console.debug(settings); expect(settings).toBeDefined(); expect(Object.keys(settings)).toEqual(Object.keys(settingsExample)); }); diff --git a/src/actions/tasks/getRepetitions.test.ts b/src/actions/tasks/getRepetitions.test.ts index b0e0f3ab..53addfa5 100644 --- a/src/actions/tasks/getRepetitions.test.ts +++ b/src/actions/tasks/getRepetitions.test.ts @@ -6,7 +6,6 @@ describe("getRepetitions", async () => { test("Should retrieve the repitions as array", async () => { const client = await testClientSession(); const repitions = await getRepetitions({ client }); - console.debug(repitions); expect(repitions).toBeDefined(); expect(repitions).toBeArray(); }); diff --git a/src/actions/tasks/reservations/getReservations.test.ts b/src/actions/tasks/reservations/getReservations.test.ts index 1ac10987..2ea36e40 100644 --- a/src/actions/tasks/reservations/getReservations.test.ts +++ b/src/actions/tasks/reservations/getReservations.test.ts @@ -55,8 +55,6 @@ describe("getReservation", async () => { campaignId: 1, }); - console.debug(reservation); - expect(reservation).toBeDefined(); expect(reservation).toBeArray(); }); diff --git a/src/actions/tasks/reservations/reserveTask.test.ts b/src/actions/tasks/reservations/reserveTask.test.ts index 6db764e1..193dd87f 100644 --- a/src/actions/tasks/reservations/reserveTask.test.ts +++ b/src/actions/tasks/reservations/reserveTask.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe } from "bun:test"; -import { destructureEnv, testClientSession } from "../../../../test/src/utils"; +import { testClientSession } from "../../../../test/src/utils"; import { reserveTask } from "./reserveTask"; describe("reserveTask", async () => { @@ -8,7 +8,6 @@ describe("reserveTask", async () => { const client = await testClientSession(); const reservation = await reserveTask({ client, campaignId: 1 }); - console.debug(reservation); expect(reservation).toBeDefined(); }); diff --git a/src/actions/tasks/submitTask.test.ts b/src/actions/tasks/submitTask.test.ts index 891ff491..76fa372e 100644 --- a/src/actions/tasks/submitTask.test.ts +++ b/src/actions/tasks/submitTask.test.ts @@ -11,7 +11,7 @@ describe("submitTask", async () => { const { actor } = destructureEnv(); const [vAccount] = await getVAccounts({ client, actor }); - const reservation = getReservationForCampaign({ + const reservation = await getReservationForCampaign({ client, campaignId: 1, vAccountId: vAccount.id, @@ -19,7 +19,6 @@ describe("submitTask", async () => { const response = await submitTask({ client, reservation, data: {} }); - console.debug(response); expect(response).toBeDefined(); }); }); diff --git a/src/actions/vaccount/claim.test.ts b/src/actions/vaccount/claim.test.ts index 7a0e912c..e9b970d8 100644 --- a/src/actions/vaccount/claim.test.ts +++ b/src/actions/vaccount/claim.test.ts @@ -1,15 +1,13 @@ import { expect, test, describe } from "bun:test"; -import { createClient } from "../../client"; import { testClientSession } from "../../../test/src/utils"; -import { claim, jungle4 as network } from "../../exports"; +import { claim } from "../../exports"; describe("Claim", async () => { test.todo("Should throw when no payment is pending", async () => { - // const client = await createClient({ network }); const client = await testClientSession(); const response = await claim({ client }); - console.error(response); // expect(async () => await claim({ client })).toThrow(); + expect(response).toBeDefined(); }); test.todo("Should claim pending payments", async () => { diff --git a/src/actions/vaccount/getAvatar.test.ts b/src/actions/vaccount/getAvatar.test.ts index 7af694fc..a70d02bf 100644 --- a/src/actions/vaccount/getAvatar.test.ts +++ b/src/actions/vaccount/getAvatar.test.ts @@ -1,6 +1,5 @@ import { expect, test, describe } from "bun:test"; import { createClient } from "../../client"; -import { destructureEnv, testClientSession } from "../../../test/src/utils"; import { getAvatar, jungle4 as network } from "../../exports"; describe("getAvatar", async () => { diff --git a/src/actions/vaccount/getOrCreate.test.ts b/src/actions/vaccount/getOrCreate.test.ts index 7e2d36ff..547a0710 100644 --- a/src/actions/vaccount/getOrCreate.test.ts +++ b/src/actions/vaccount/getOrCreate.test.ts @@ -1,6 +1,6 @@ import { expect, test, describe } from "bun:test"; import { destructureEnv, testClientSession } from "../../../test/src/utils"; -import { jungle4 as network, type Account } from "../../exports"; +import { type Account } from "../../exports"; import { getOrCreateVAccount } from "./getOrCreate"; describe("GetOrCreate", async () => { diff --git a/src/actions/vaccount/withdraw.test.ts b/src/actions/vaccount/withdraw.test.ts index feecd5b6..cd1160e7 100644 --- a/src/actions/vaccount/withdraw.test.ts +++ b/src/actions/vaccount/withdraw.test.ts @@ -1,6 +1,6 @@ import { expect, test, describe } from "bun:test"; -import { destructureEnv, testClientSession } from "../../../test/src/utils"; -import { withdraw, jungle4 as network, createClient } from "../../exports"; +import { testClientSession } from "../../../test/src/utils"; +import { withdraw } from "../../exports"; import type { ExtendedAssetType } from "@wharfkit/antelope"; describe("withdraw", async () => { diff --git a/src/constants/config.ts b/src/constants/config.ts index 9bc87997..6f1836ef 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -1,9 +1,4 @@ -import type { - AtomicConfig, - EfxConfig, - IpfsConfig, - RelayerConfig, -} from "../types/network"; +import type { AtomicConfig, IpfsConfig, RelayerConfig } from "../types/network"; export const ipfsConfig: IpfsConfig = { ipfsEndpoint: "https://ipfs.effect.ai", From e8680d2679e3518d7477362cd463342b0b27ceb9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sat, 11 May 2024 12:54:09 -0400 Subject: [PATCH 59/84] Update return type for getAccount --- src/actions/vaccount/getAccounts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/vaccount/getAccounts.ts b/src/actions/vaccount/getAccounts.ts index b2172876..5faa2823 100644 --- a/src/actions/vaccount/getAccounts.ts +++ b/src/actions/vaccount/getAccounts.ts @@ -39,7 +39,7 @@ export type GetAccountByIdArgs = { export const getAccountById = async ({ client, accountId, -}: GetAccountByIdArgs) => { +}: GetAccountByIdArgs): Promise => { const { provider, network } = client; const { contracts } = network.config.efx; From 7a3051d21679e8901fa95af36e1d343b5367731a Mon Sep 17 00:00:00 2001 From: David Britt Date: Sat, 11 May 2024 12:54:39 -0400 Subject: [PATCH 60/84] Update getting-started page and use snippets --- docs/pages/docs/getting-started.mdx | 169 +++++++---------------- docs/snippets/client.ts | 5 - docs/snippets/getting-started-auth.ts | 24 ++++ docs/snippets/getting-started-init.ts | 8 ++ docs/snippets/getting-started-nonauth.ts | 13 ++ 5 files changed, 93 insertions(+), 126 deletions(-) delete mode 100644 docs/snippets/client.ts create mode 100644 docs/snippets/getting-started-auth.ts create mode 100644 docs/snippets/getting-started-init.ts create mode 100644 docs/snippets/getting-started-nonauth.ts diff --git a/docs/pages/docs/getting-started.mdx b/docs/pages/docs/getting-started.mdx index 71093f34..07e6f3a1 100644 --- a/docs/pages/docs/getting-started.mdx +++ b/docs/pages/docs/getting-started.mdx @@ -3,152 +3,79 @@ ## Installation Use your favorite package manager to install the SDK. +The sdk is available on [npm](https://www.npmjs.com/package/@effectai/sdk) - :::code-group +:::code-group - ```bash [npm] +```bash [npm] +npm i @effectai/sdk +``` - npm i @effectai/effect-js - ``` +```bash [bun] +bun i @effectai/sdk +``` - ```bash [bun] - bun i @effectai/effect-js - ``` +```bash [pnpm] +pnpm i @effectai/sdk +``` +::: - ```bash [pnpm] - pnpm i @effectai/effect-js - ``` - ::: ## Quick Start -### 1. Import the SDK +### 1. Import and Instantiate the EffectAI Client -```ts -import { createClient } from '@effectai/effect-js' -``` +Here the handy dandy `createClient` function is used to create a client instance. +It can three arguments, the first one is the network configuration, +the second one is the a session object, and the third one is the options object. -### 2. Instantiate the EffectAI Client +In this quick start guide we will be focusing on the first two, +how to get started with a non authenticated client using the network configuration and +an authenticated client using the session object. -Here the handy dandy `createClient` function is used to create a client instance. -It takes two optional arguments, the first one is the network configuration, the second one is the options object. You can read more about the options object in the [ClientOptions](#client-options) section. -```ts -// This would be ideal, the big question is if using mainnet should be explicitly passed or not. -const client = createClient() +Here is an example of how to create a client with a network configuration. -// But currently it is like this: -import { jungle4 } from '@effectai/effect-js' -// Atleast the opts ({}) object is now optional -const client = createClient(jungle4) +```ts twoslash +// [!include ~/snippets/getting-started-init.ts] ``` -### 3. Interact with the Client - -The sdk is built using a stateless model, meaning that all the functions are pure and do not mutate the client object. -This means, that you need to creat one client, and you can pass that client as an argument to functions to make transactions. - -Here is an example of how to get the balance of an account, assuming that the client is already set up as described above. - -```ts -import { getVAccounts, getAccountById } from "@effectai/effect-js"; -import { Name } from "@wharfkit/antelope"; - -const actor = Name.from("forcedev1234"); -// Notice we are passing the clinet as an argument to the function. -const [vacc] = await getVAccounts({ client, actor }); - -console.log(vacc) -/** -{ - id: 24, - nonce: 0, - address: [ "name", "forcedev1234" ], - balance: { - quantity: "0.0000 EFX", - contract: "efxtoken1112", - }, -} -*/ + +### 2. Interact with the Client + +The sdk is built using a stateless model, meaning that all the functions are pure +and (almost) does not mutate the client object. +In practice this means that you wiil need to create a client object, +and pass it as an argument to the functions you want to use. + +Here is an example of how to retrieve an Effect account by using its ID. + +```ts twoslash +// [!include ~/snippets/getting-started-nonauth.ts] ``` -### 4. Set up wallet and session +### 3. Set up wallet and session + +If you want to make transactions, such as creating a new account, creating a new tasks, +or transfering tokens, you need to set up a wallet and a session. +The wallet plugin is an interface that allows you to sign transactions and interact with the blockchain. -If you want to make transactions, such as creating a new account, creating a new tasks, or transfering tokens, you need to set up a wallet and a session. -The wallet plguin is an interface that allows you to sign transactions and interact with the blockchain. -The SDK comes with a few wallet plugins out of the box, but you can also create your own. +Currently the SDK does not come with any wallet plugins, +and you will need to use one provided by [wharfkit.com](https://wharfkit.com/). +A list of plugins can be found at [wharfkit.com/plugins](https://wharfkit.com/plugins?sort=popular) -In this example we will use the `WalletPluginPrivateKey` plugin, which requres a private key to be passed in. +In this example we will use the [`@wharfkit/wallet-plugin-privatekey`](https://wharfkit.com/plugins/wallet-plugin-privatekey) plugin, which requres a private key to be passed in. -Afterwards we can set up the Session object, which allows us to specify other parameters like the actor, permission, and the blockchain netork. +Afterwards we can set up the Session object, which allows us to specify other parameters like +the actor, permission, and the blockchain netork. Last but not least we connect the session to the client, and the client will be ready to use. -```ts -import { createBatch, createVAccount } from "@effectai/effect-js"; -import { Session } from "@wharfkit/session"; -import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey" - -const walletPlugin = new WalletPluginPrivateKey("your_private_key_here") - -const session = new Session({ - actor: "forcedev1234", - permission: "active", - walletPlugin, - chain: { - id: jungle4.eosChainId, - url: jungle4.eosRpcUrl, - }, -}) - -// Connect the session to the client. -await session.setSession(session) - -// Now you can use the client to make authenticated transactions. -const account = Name.from("efxforce1112"); -await createVAccount({ client, account }); +```ts twoslash +// [!include ~/snippets/getting-started-auth.ts] ``` -## Full example - -```ts -import { Session, Name } from "@wharfkit/session"; -import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; -import { - createClient, - jungle4, - eos, // Use `eos` to use mainnet - getVAccounts, - createVAccount, -} from "@effectai/effect-js"; - -const client = createClient({ network: jungle4 }); - -// Make unauthenticated requests -const actor = Name.from("forcedev1234"); -const [vacc] = await getVAccounts({ client, actor }); - -// Set up wallet with privatekey -const walletPlugin = new WalletPluginPrivateKey("your_private_key_here"); - -// Set up session with wallet and chain -const session = new Session({ - actor: "forcedev1234", - permission: "active", - walletPlugin, - chain: { - id: jungle4.eosChainId, - url: jungle4.eosRpcUrl, - }, -}); - -// Connect session to client -await client.setSession(session); - -// Now you can use the client to make authenticated transactions. -const account = Name.from("efxforce1112"); -await createVAccount({ client, account }); -``` +## Conclusion Now that we have a basic understaning of how to set up the client, we can move on to more advanced topics. Read more on the following pages. diff --git a/docs/snippets/client.ts b/docs/snippets/client.ts deleted file mode 100644 index fcd6b084..00000000 --- a/docs/snippets/client.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { createClient, eos } from "@effectai/sdk"; - -export const client = createClient({ - chain: eos, -}); diff --git a/docs/snippets/getting-started-auth.ts b/docs/snippets/getting-started-auth.ts new file mode 100644 index 00000000..da0b77fa --- /dev/null +++ b/docs/snippets/getting-started-auth.ts @@ -0,0 +1,24 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as network, + // eos as network , // Use `eos` to use mainnet + Session, + createVAccount, +} from "@effectai/sdk"; + +// Set up session with wallet and chain +const session = new Session({ + actor: "account_name_here", + permission: "permission_here", + walletPlugin: new WalletPluginPrivateKey("your_private_key_here"), + chain: network, +}); + +// Create client to make authenticated transactions +const authClient = await createClient({ session }); + +// Create a new Effect Account +const account = "efxforce1112"; +const response = await createVAccount({ client: authClient, account }); +console.log(response); // => Transaction Details diff --git a/docs/snippets/getting-started-init.ts b/docs/snippets/getting-started-init.ts new file mode 100644 index 00000000..76eafb2e --- /dev/null +++ b/docs/snippets/getting-started-init.ts @@ -0,0 +1,8 @@ +import { + createClient, + jungle4 as network, + // eos as network , // Use `eos` to use mainnet +} from "@effectai/sdk"; + +// Create client +const client = await createClient({ network }); diff --git a/docs/snippets/getting-started-nonauth.ts b/docs/snippets/getting-started-nonauth.ts new file mode 100644 index 00000000..29acfc68 --- /dev/null +++ b/docs/snippets/getting-started-nonauth.ts @@ -0,0 +1,13 @@ +import { + createClient, + jungle4 as network, + // eos as network , // Use `eos` to use mainnet + getAccountById, +} from "@effectai/sdk"; + +// Create client to make unauthenticated transactions +const client = await createClient({ network }); + +// Retrieve data from Effect Network +const vAccount = await getAccountById({ client, accountId: 1 }); +console.log(vAccount); // => Account Details From 05071170d16bf97e2e5d3732b8e6dc29f6bf08f9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:28:24 -0400 Subject: [PATCH 61/84] Update campaign docs --- .../docs/tasks/campaigns/create-campaign.mdx | 28 ++----------------- .../tasks/campaigns/get-campaign-by-id.mdx | 8 ++---- .../docs/tasks/campaigns/get-campaigns.mdx | 9 ++---- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/docs/pages/docs/tasks/campaigns/create-campaign.mdx b/docs/pages/docs/tasks/campaigns/create-campaign.mdx index cc0a0bef..6c214b20 100644 --- a/docs/pages/docs/tasks/campaigns/create-campaign.mdx +++ b/docs/pages/docs/tasks/campaigns/create-campaign.mdx @@ -8,33 +8,9 @@ you need to add tasks to the campaign. You can do this by following the [Adding ## Usage -```ts -import { - createCampaign, - CreateCampaignArgs, - createClient -} from '@effectai/sdk' - -const myNewCampaign: CreateCampaignArgs["campaign"] = { - version: 1.0, - maxTaskTime: 100, - reward: 3.5, - title: "Labelstudio OCR (LAION)", - description: "You are contributing to a dataset for conversational style chatbots.", - instructions: "Some instructions here", - template: "

Template here

", - input_schema: null, - output_schema: null, - image: "", - category: "", - example_task: "", - estimated_time: 10, -}; - -const client = await createClient({ network: jungle4 }); -const result = await createCampaign({ client, campaign: myNewCampaign }); +```ts twoslash +// [!include ~/snippets/tasks/create-campaign.ts] ``` - ## Output ```json diff --git a/docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx b/docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx index f04f4413..429b3347 100644 --- a/docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx +++ b/docs/pages/docs/tasks/campaigns/get-campaign-by-id.mdx @@ -7,12 +7,10 @@ This function retrieves a campaign from a specified client with the given ID. ## Usage -```ts -import { createClient, getCampaignById, jungle4 } from "@effectai/sdk" -const client = createClient({ network: jungle4 }); -const id = 1; -const campaign = await getCampaignById({ client, id }); +```ts twoslash +// [!include ~/snippets/tasks/get-campaign-by-id.ts] + ``` ## Output diff --git a/docs/pages/docs/tasks/campaigns/get-campaigns.mdx b/docs/pages/docs/tasks/campaigns/get-campaigns.mdx index 6bab9762..d784ce0d 100644 --- a/docs/pages/docs/tasks/campaigns/get-campaigns.mdx +++ b/docs/pages/docs/tasks/campaigns/get-campaigns.mdx @@ -6,14 +6,9 @@ This function retrieves campaigns from a specified client with optional paramete ## Usage -```ts -import { createClient, getCampaigns, jungle4 } from "@effectai/sdk" - -const client = createCllient({ network: jungle4 }); -const campaigns = await getCampaigns({ client }); -console.log(campaigns); +```ts twoslash +// [!include ~/snippets/tasks/get-campaigns.ts] ``` - ## Output ```json From e0e8b5242accddcd3aa7372dada8924eead8b178 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:29:04 -0400 Subject: [PATCH 62/84] Update get-balance docs --- docs/pages/docs/token/get-balance.mdx | 9 ++------- docs/snippets/token/get-balance.ts | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 docs/snippets/token/get-balance.ts diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index a2921ba6..4bd74da7 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -10,13 +10,8 @@ Note the use of `balance.toString()` to convert the balance to a string. ## Usage -```ts -import { createClient, Name, getBalance, jungle4 } from '@effectai/sdk'; - -const client = createClient({ network: jungle4 }); -const actor = Name.from("forcedev1234"); -const balance = await getBalance({ client, actor }); -console.log(balance.toString()); +```ts twoslash +// [!include ~/snippets/token/get-balance.ts] ``` ## Output diff --git a/docs/snippets/token/get-balance.ts b/docs/snippets/token/get-balance.ts new file mode 100644 index 00000000..697184b4 --- /dev/null +++ b/docs/snippets/token/get-balance.ts @@ -0,0 +1,6 @@ +import { createClient, getBalance, jungle4 } from "@effectai/sdk"; + +const client = await createClient({ network: jungle4 }); +const actor = "forcedev1234"; +const balance = await getBalance({ client, actor }); +console.log(balance.toString()); From d9c7236683625e0ffbdc917bc2c58c03236f2a4b Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:29:18 -0400 Subject: [PATCH 63/84] Update get-price docs --- docs/pages/docs/token/get-price.mdx | 7 +++---- docs/snippets/token/get-price.ts | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 docs/snippets/token/get-price.ts diff --git a/docs/pages/docs/token/get-price.mdx b/docs/pages/docs/token/get-price.mdx index 1f109b70..ce7b6c53 100644 --- a/docs/pages/docs/token/get-price.mdx +++ b/docs/pages/docs/token/get-price.mdx @@ -9,10 +9,9 @@ It is not needed for this function to connect a client or a session. ## Usage -```ts -import { getPrice } from '@effectai/sdk'; -const price = await getPrice(); -console.log(price); +```ts twoslash + +// [!include ~/snippets/token/get-price.ts] ``` ## Output diff --git a/docs/snippets/token/get-price.ts b/docs/snippets/token/get-price.ts new file mode 100644 index 00000000..206f7aab --- /dev/null +++ b/docs/snippets/token/get-price.ts @@ -0,0 +1,3 @@ +import { getPrice } from "@effectai/sdk"; +const price = await getPrice(); +console.log(price); From 5534358e52be48c3f4caebcd36568cd6c96cf459 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:29:33 -0400 Subject: [PATCH 64/84] Update swap --- docs/pages/docs/token/swap.mdx | 26 ++---------------------- docs/snippets/token/swap.ts | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 docs/snippets/token/swap.ts diff --git a/docs/pages/docs/token/swap.mdx b/docs/pages/docs/token/swap.mdx index 0e527dc4..abaaab4c 100644 --- a/docs/pages/docs/token/swap.mdx +++ b/docs/pages/docs/token/swap.mdx @@ -14,30 +14,8 @@ Other wallet plugins can be used to sign transactions and can be found at: https ## Usage -```ts -import { createClient, Session, swap, eos as chain } from '@effectai/sdk'; -import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; - -const walletPlugin = new WalletPluginPrivateKey("your_private_key"); -const actor = "forcedev1234"; -const permission = "active"; - -// Create a session -const session = new Session({ actor, permission, walletPlugin, chain }); - -// Create client and connect session -const client = createClient({ session }); - -// Define the swap arguments -const swapArgs: SwapArgs = { - client, - amount: 4, - direction: "UsdtToEfx", // or "EfxToUsdt" -}; - -// Call the swap function -const response = await swap(swapArgs); -console.log(response); +```ts twoslash +// [!include ~/snippets/token/swap.ts] ``` ## Output diff --git a/docs/snippets/token/swap.ts b/docs/snippets/token/swap.ts new file mode 100644 index 00000000..3f3d6a42 --- /dev/null +++ b/docs/snippets/token/swap.ts @@ -0,0 +1,36 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as chain, + // eos as chain, + Session, + swap, + type SwapArgs, + getBalance, +} from "@effectai/sdk"; + +const actor = "actor-name"; +const permission = "permission-level"; + +// Create a session +const session = new Session({ + chain, + actor, + permission, + walletPlugin: new WalletPluginPrivateKey("your_private_key"), +}); + +// Create client and connect session +const client = await createClient({ session }); + +// Define the swap arguments +const swapArgs: SwapArgs = { + client, + amount: 4, // Define amount, up to 4 digits behind the decimal + direction: "UsdtToEfx", // or "EfxToUsdt" +}; + +const preBalance = await getBalance({ client, actor }); + +// Call the swap function +const response = await swap(swapArgs); From 98983693e40c509c74ac78de3b034b3709402255 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:29:55 -0400 Subject: [PATCH 65/84] Add swapArgs to index export --- src/exports/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exports/index.ts b/src/exports/index.ts index 4955db1b..7e001d7f 100644 --- a/src/exports/index.ts +++ b/src/exports/index.ts @@ -107,7 +107,7 @@ export { export { getPrice } from "./../actions/token/getPrice"; export { getBalance, type GetBalanceArgs } from "./../actions/token/getBalance"; -export { swap, swapDirection } from "./../actions/token/swap"; +export { swap, swapDirection, type SwapArgs } from "./../actions/token/swap"; export { getAvatar } from "./../actions/vaccount/getAvatar"; From bd063fb22c626fe1cbddcd657ff3f6e22a0f05d7 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:30:13 -0400 Subject: [PATCH 66/84] Update docs:dev script with `bun link` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ab0909e..36f6cb8d 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "changeset": "changeset", "changeset:public": "bun scripts/updateVersion.ts && bun build && changeset publish", "changeset:version": "changeset version && bun install --frozen-lockfile && bun scripts/updateVersion.ts", - "docs:dev": "cd docs && bun run dev", + "docs:dev": "bun link && cd docs && bun run dev", "docs:build": "cd docs && bun run build", "docs:preview": "cd docs && bun run preview" }, From 5c123cdb57887a1a10a6117daea44ffb3ae3cdae Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:31:41 -0400 Subject: [PATCH 67/84] Add TODO for swap function Would be usefull to throw error when balance is too low to execute swap --- src/actions/token/swap.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/actions/token/swap.ts b/src/actions/token/swap.ts index b32c64fd..10884db2 100644 --- a/src/actions/token/swap.ts +++ b/src/actions/token/swap.ts @@ -68,6 +68,7 @@ export type SwapArgs = { direction: "EfxToUsdt" | "UsdtToEfx"; }; +// TODO: Add throw error if balance too low export const swap = async ({ client, amount, direction }: SwapArgs) => { try { if (!client.session) { From 87fbdf8e2d3dfa4cd94be7756e46b4d64eab2727 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:33:22 -0400 Subject: [PATCH 68/84] Update package.json dependency with link to local `@effectai/sdk` --- docs/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/package.json b/docs/package.json index 044ce662..a349f5f3 100644 --- a/docs/package.json +++ b/docs/package.json @@ -7,6 +7,9 @@ "build": "vocs build --searchIndex false && vocs search-index", "preview": "vocs preview" }, + "dependencies": { + "@effectai/sdk": "link:@effectai/sdk" + }, "devDependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", From 68400c39a98f5935536ef05e9f398d32a1b204fd Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:34:48 -0400 Subject: [PATCH 69/84] Use code snippets for getting started guide --- docs/pages/docs/getting-started.mdx | 6 +++--- docs/snippets/{ => getting-started}/getting-started-auth.ts | 0 docs/snippets/{ => getting-started}/getting-started-init.ts | 0 .../{ => getting-started}/getting-started-nonauth.ts | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename docs/snippets/{ => getting-started}/getting-started-auth.ts (100%) rename docs/snippets/{ => getting-started}/getting-started-init.ts (100%) rename docs/snippets/{ => getting-started}/getting-started-nonauth.ts (100%) diff --git a/docs/pages/docs/getting-started.mdx b/docs/pages/docs/getting-started.mdx index 07e6f3a1..52443d66 100644 --- a/docs/pages/docs/getting-started.mdx +++ b/docs/pages/docs/getting-started.mdx @@ -37,7 +37,7 @@ You can read more about the options object in the [ClientOptions](#client-option Here is an example of how to create a client with a network configuration. ```ts twoslash -// [!include ~/snippets/getting-started-init.ts] +// [!include ~/snippets/getting-started/getting-started-init.ts] ``` @@ -51,7 +51,7 @@ and pass it as an argument to the functions you want to use. Here is an example of how to retrieve an Effect account by using its ID. ```ts twoslash -// [!include ~/snippets/getting-started-nonauth.ts] +// [!include ~/snippets/getting-started/getting-started-nonauth.ts] ``` ### 3. Set up wallet and session @@ -72,7 +72,7 @@ the actor, permission, and the blockchain netork. Last but not least we connect the session to the client, and the client will be ready to use. ```ts twoslash -// [!include ~/snippets/getting-started-auth.ts] +// [!include ~/snippets/getting-started/getting-started-auth.ts] ``` ## Conclusion diff --git a/docs/snippets/getting-started-auth.ts b/docs/snippets/getting-started/getting-started-auth.ts similarity index 100% rename from docs/snippets/getting-started-auth.ts rename to docs/snippets/getting-started/getting-started-auth.ts diff --git a/docs/snippets/getting-started-init.ts b/docs/snippets/getting-started/getting-started-init.ts similarity index 100% rename from docs/snippets/getting-started-init.ts rename to docs/snippets/getting-started/getting-started-init.ts diff --git a/docs/snippets/getting-started-nonauth.ts b/docs/snippets/getting-started/getting-started-nonauth.ts similarity index 100% rename from docs/snippets/getting-started-nonauth.ts rename to docs/snippets/getting-started/getting-started-nonauth.ts From c5f725294081bb433ed9550472f3aea483deda70 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:35:26 -0400 Subject: [PATCH 70/84] Use code snippets for create campaign guide --- .../collecting-data/create-a-campaign.mdx | 35 ++----------------- docs/snippets/tasks/create-campaign.ts | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 docs/snippets/tasks/create-campaign.ts diff --git a/docs/pages/docs/collecting-data/create-a-campaign.mdx b/docs/pages/docs/collecting-data/create-a-campaign.mdx index 44b7bdaa..b0ca4512 100644 --- a/docs/pages/docs/collecting-data/create-a-campaign.mdx +++ b/docs/pages/docs/collecting-data/create-a-campaign.mdx @@ -6,38 +6,9 @@ A campaign is a collection of tasks that need to be completed by workers. ### Creating a campaign -```ts [example.ts] -import { createCampaign } from '@effectai/effect-js' +```ts twoslash +// [!include ~/snippets/tasks/create-campaign.ts] -// get the actor from the session -const { actor } = client.session - -// example template -const template = '...' - -const campaign = await createCampaign({ - client, - data: { - title: 'My first campaign', - category: 'Image Labeling', // Category of the campaign e.g. Image Labeling, Audio Transcription etc. - description: 'This is a description of my first campaign', // Description of the campaign - estimated_time: 3600, // Estimated time to complete a task in seconds - example_task: 'This is an example task', - image: 'https://example.com/image.png', - instructions: 'This is the instructions for the workers', - input_schema: null, - output_schema: null, - template, - version: 1, - }, - campaign: { - owner: actor, - reward: { quantity: '1', contract: 'effecttokens' }, - max_task_time: 3600, - qualis: [], - payer: actor, - }, -}) ``` -Wooooho! You have created your first campaign. You can now view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data, you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide. \ No newline at end of file +Wooooho! You have created your first campaign. You can now view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data, you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide. diff --git a/docs/snippets/tasks/create-campaign.ts b/docs/snippets/tasks/create-campaign.ts new file mode 100644 index 00000000..f01c0bcd --- /dev/null +++ b/docs/snippets/tasks/create-campaign.ts @@ -0,0 +1,35 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createCampaign, + Session, + jungle4 as chain, + type CreateCampaignArgs, + createClient, +} from "@effectai/sdk"; + +const myNewCampaign: CreateCampaignArgs["campaign"] = { + version: 1.0, + maxTaskTime: 100, + reward: 3.5, + title: "Labelstudio OCR (LAION)", + description: "Description of the ttask here.", + instructions: "Some instructions here", + template: "

Template here

", + input_schema: null, + output_schema: null, + image: "", + category: "", + example_task: "", + estimated_time: 10, +}; + +const session = new Session({ + actor: "your-account", + permission: "permission-level", + chain, + walletPlugin: new WalletPluginPrivateKey("your-private-key"), +}); + +const client = await createClient({ session }); +const result = await createCampaign({ client, campaign: myNewCampaign }); +console.log(result); From e7753f528daae997aa15f541759357fadd9cef21 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:35:58 -0400 Subject: [PATCH 71/84] Add tasks code snippets --- docs/snippets/tasks/get-campaign-by-id.ts | 10 ++++++++++ docs/snippets/tasks/get-campaigns.ts | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 docs/snippets/tasks/get-campaign-by-id.ts create mode 100644 docs/snippets/tasks/get-campaigns.ts diff --git a/docs/snippets/tasks/get-campaign-by-id.ts b/docs/snippets/tasks/get-campaign-by-id.ts new file mode 100644 index 00000000..fc6dff59 --- /dev/null +++ b/docs/snippets/tasks/get-campaign-by-id.ts @@ -0,0 +1,10 @@ +import { + type Campaign, + type CampaignWithInfo, + createClient, + getCampaignById, + jungle4 as network, +} from "@effectai/sdk"; + +const client = await createClient({ network }); +const campaign = await getCampaignById({ client, id: 1 }); diff --git a/docs/snippets/tasks/get-campaigns.ts b/docs/snippets/tasks/get-campaigns.ts new file mode 100644 index 00000000..7c292bd3 --- /dev/null +++ b/docs/snippets/tasks/get-campaigns.ts @@ -0,0 +1,5 @@ +import { createClient, getCampaigns, jungle4 as network } from "@effectai/sdk"; + +const client = await createClient({ network }); +const campaigns = await getCampaigns({ client }); +console.log(campaigns); From e6d0a6d9121758c979ef5f2d6de1ccbfd25858e1 Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 15:36:27 -0400 Subject: [PATCH 72/84] Add code snippet for create account --- docs/snippets/vaccount/create-account.ts | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docs/snippets/vaccount/create-account.ts diff --git a/docs/snippets/vaccount/create-account.ts b/docs/snippets/vaccount/create-account.ts new file mode 100644 index 00000000..d7751b60 --- /dev/null +++ b/docs/snippets/vaccount/create-account.ts @@ -0,0 +1,36 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as chain, + // eos as chain, + Session, + createVAccount, + type CreateVAccountArgs, +} from "@effectai/sdk"; + +const actor = "actor-name"; +const permission = "permission-level"; + +// Create a session +const session = new Session({ + chain, + actor, + permission, + walletPlugin: new WalletPluginPrivateKey("your_private_key"), +}); + +// Create client and connect session +const client = await createClient({ session }); + +const [vacc] = await getVAccounts({ client, actor }); + +// Check pending payments +const pendingPayments = await getPendingPayments({ + client, + vAccountId: vacc.id, +}); + +// If there are claimable payments, claim them. +if (pendingPayments.totalEfxClaimable > 0) { + await claim({ client }); +} From 80d2481b389c264fc657ad6d15f86366b396285f Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 16:03:04 -0400 Subject: [PATCH 73/84] Add claim to docs --- docs/pages/docs/vaccount/claim.mdx | 55 ++++++++++++++++++++++++++++++ docs/sidebar.ts | 20 +++++------ docs/snippets/vaccount/claim.ts | 38 +++++++++++++++++++++ 3 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 docs/snippets/vaccount/claim.ts diff --git a/docs/pages/docs/vaccount/claim.mdx b/docs/pages/docs/vaccount/claim.mdx index e69de29b..75054196 100644 --- a/docs/pages/docs/vaccount/claim.mdx +++ b/docs/pages/docs/vaccount/claim.mdx @@ -0,0 +1,55 @@ +# claim + +## Description + +This function is used to claim the task reward that is locked in the escrow for the done tasks. +Every time a task is done, the reward is locked in the escrow until the timeout is reached. +After the timeout is reached, the reward can be claimed by the user who did the task. +The resulting EFX will be transferred to the user's VAccount. +The main difference between claim and payout, is where the funds are sent. + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/claim.ts] +``` + +## Output + +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session, so that only the user with their wallet can claim the rewards. + +## Returns + +**Type:** TransactionResult + +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 4e3bfa9d..8e732d37 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -38,30 +38,30 @@ export const sidebar = { { text: "vAccount", items: [ - { text: "TODO: claim", link: "/docs/tasks/vaccount/claim" }, + { text: "claim", link: "/docs/vaccount/claim" }, { text: "TODO: createAccount", - link: "/docs/tasks/vaccount/createAccount", + link: "/docs/vaccount/createAccount", }, - { text: "TODO: deposit", link: "/docs/tasks/vaccount/deposit" }, + { text: "TODO: deposit", link: "/docs/vaccount/deposit" }, { text: "TODO: getAccounts", - link: "/docs/tasks/vaccount/getAccounts", + link: "/docs/vaccount/getAccounts", }, { text: "TODO: getAvatar", - link: "/docs/tasks/vaccount/get-avatar", + link: "/docs/vaccount/get-avatar", }, { text: "TODO: getOrCreate", - link: "/docs/tasks/vaccount/get-or-create", + link: "/docs/vaccount/get-or-create", }, { text: "TODO: getPendingPayments", - link: "/docs/tasks/vaccount/get-pending-payments", + link: "/docs/vaccount/get-pending-payments", }, - { text: "TODO: payout", link: "/docs/tasks/vaccount/payout" }, - { text: "TODO: withdraw", link: "/docs/tasks/vaccount/withdraw" }, + { text: "TODO: payout", link: "/docs/vaccount/payout" }, + { text: "TODO: withdraw", link: "/docs/vaccount/withdraw" }, ], }, { @@ -69,7 +69,7 @@ export const sidebar = { items: [ { text: "getPrice", link: "/docs/token/get-price" }, { text: "getBalance", link: "/docs/token/get-balance" }, - { text: "TODO: transfer", link: "/docs/token/transfer" }, + { text: "transfer", link: "/docs/token/transfer" }, { text: "swap", link: "/docs/token/swap" }, ], }, diff --git a/docs/snippets/vaccount/claim.ts b/docs/snippets/vaccount/claim.ts new file mode 100644 index 00000000..5c81aed5 --- /dev/null +++ b/docs/snippets/vaccount/claim.ts @@ -0,0 +1,38 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as chain, + // eos as chain, + Session, + claim, + type ClaimArgs, + getPendingPayments, + getVAccounts, +} from "@effectai/sdk"; + +const actor = "actor-name"; +const permission = "permission-level"; + +// Create a session +const session = new Session({ + chain, + actor, + permission, + walletPlugin: new WalletPluginPrivateKey("your_private_key"), +}); + +// Create client and connect session +const client = await createClient({ session }); + +const [vacc] = await getVAccounts({ client, actor }); + +// Check pending payments +const pendingPayments = await getPendingPayments({ + client, + vAccountId: vacc.id, +}); + +// If there are claimable payments, claim them. +if (pendingPayments.totalEfxClaimable > 0) { + await claim({ client }); +} From e157602484f8a310d2761c985e0e58410425910f Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 16:33:39 -0400 Subject: [PATCH 74/84] Add payout docs --- docs/pages/docs/vaccount/payout.mdx | 59 +++++++++++++++++++++++++++++ docs/sidebar.ts | 2 +- docs/snippets/vaccount/payout.ts | 38 +++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 docs/snippets/vaccount/payout.ts diff --git a/docs/pages/docs/vaccount/payout.mdx b/docs/pages/docs/vaccount/payout.mdx index e69de29b..e7966bde 100644 --- a/docs/pages/docs/vaccount/payout.mdx +++ b/docs/pages/docs/vaccount/payout.mdx @@ -0,0 +1,59 @@ +# payout + +## Description + +This function is used to claim the task reward that is locked in the escrow for the done tasks. +Every time a task is done, the reward is locked in the escrow until the timeout is reached. +After the timeout is reached, the reward can be claimed by the user who did the task. +The resulting EFX will be transferred to the user's EOS account on the blockchain. + +The main difference between claim and payout, is where the funds are sent. + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/payout.ts] +``` + +## Output + +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### Actor +- **Description:** The actor name, from which the PendinPayments should be claimed and paid out. + +## Returns + +**Type:** TransactionResult + +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 8e732d37..39bc6aa7 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -60,7 +60,7 @@ export const sidebar = { text: "TODO: getPendingPayments", link: "/docs/vaccount/get-pending-payments", }, - { text: "TODO: payout", link: "/docs/vaccount/payout" }, + { text: "payout", link: "/docs/vaccount/payout" }, { text: "TODO: withdraw", link: "/docs/vaccount/withdraw" }, ], }, diff --git a/docs/snippets/vaccount/payout.ts b/docs/snippets/vaccount/payout.ts new file mode 100644 index 00000000..c957237a --- /dev/null +++ b/docs/snippets/vaccount/payout.ts @@ -0,0 +1,38 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as chain, + // eos as chain, + Session, + payout, + type PayoutArgs, + getPendingPayments, + getVAccounts, +} from "@effectai/sdk"; + +const actor = "actor-name"; +const permission = "permission-level"; + +// Create a session +const session = new Session({ + chain, + actor, + permission, + walletPlugin: new WalletPluginPrivateKey("your_private_key"), +}); + +// Create client and connect session +const client = await createClient({ session }); + +const [vacc] = await getVAccounts({ client, actor }); + +// Check pending payments, +// Not nessesary for this snippet, but helpful to know if there are any pending payments. +// This check is also already done in the payout function. +const pendingPayments = await getPendingPayments({ + client, + vAccountId: vacc.id, +}); + +// If there are claimable payments, claim and pay them out. +const result = await payout({ client, actor }); From 31295cdb93be02116fc8c20fdcbf9ba2c6ce556a Mon Sep 17 00:00:00 2001 From: David Britt Date: Sun, 12 May 2024 16:34:51 -0400 Subject: [PATCH 75/84] Fix link to glossary/transaction-result --- docs/pages/docs/tasks/campaigns/create-campaign.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/docs/tasks/campaigns/create-campaign.mdx b/docs/pages/docs/tasks/campaigns/create-campaign.mdx index 6c214b20..c4a7a869 100644 --- a/docs/pages/docs/tasks/campaigns/create-campaign.mdx +++ b/docs/pages/docs/tasks/campaigns/create-campaign.mdx @@ -62,4 +62,4 @@ response: { **Description:** Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. -Read more about the transaction response here: [[../glossary/transaction-result.mdx]] +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) From 3f6fe49885d0253f5ae8fd97a2edde52a0e73830 Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 00:35:31 -0400 Subject: [PATCH 76/84] Update quantity for withdraw() to use number instead of ExtendedAssetType --- src/actions/vaccount/withdraw.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/actions/vaccount/withdraw.ts b/src/actions/vaccount/withdraw.ts index 5a03c4e6..812c2902 100644 --- a/src/actions/vaccount/withdraw.ts +++ b/src/actions/vaccount/withdraw.ts @@ -1,13 +1,15 @@ -import type { - AnyAction, - ExtendedAssetType, - NameType, +import { + Asset, + ExtendedAsset, + type AnyAction, + type ExtendedAssetType, + type NameType, } from "@wharfkit/antelope"; import type { Client } from "../../exports"; export type WithdrawArgs = { client: Client; - quantity: ExtendedAssetType; + quantity: number; }; export const withdraw = async ({ client, quantity }: WithdrawArgs) => { @@ -17,11 +19,15 @@ export const withdraw = async ({ client, quantity }: WithdrawArgs) => { const { transact, actor, authorization } = client.session; const { contracts } = client.network.config.efx; + const quantityAsset = ExtendedAsset.from({ + quantity: Asset.from(quantity, "EFX"), + contract: contracts.token, + }); const action = withdrawAction({ from_id: client.session.vAccount.id, to_account: actor, - quantity, + quantity: quantityAsset, account: contracts.vaccount, authorization, memo: "", From b6783fa453427a4f65273a9268388dd305bc058d Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 00:36:57 -0400 Subject: [PATCH 77/84] Add withdraw docs --- docs/pages/docs/vaccount/withdraw.mdx | 56 +++++++++++++++++++++++++++ docs/sidebar.ts | 2 +- docs/snippets/vaccount/withdraw.ts | 31 +++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 docs/snippets/vaccount/withdraw.ts diff --git a/docs/pages/docs/vaccount/withdraw.mdx b/docs/pages/docs/vaccount/withdraw.mdx index e69de29b..87b656fc 100644 --- a/docs/pages/docs/vaccount/withdraw.mdx +++ b/docs/pages/docs/vaccount/withdraw.mdx @@ -0,0 +1,56 @@ +# withdraw + +## Description + +User are able to deposit funds into their vAccount or claim the funds from escrow and have them deposited in to their vAccount. +These funds can be withdrawn to the user's wallet by calling the withdraw action. + + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/withdraw.ts] +``` + +## Output + +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### Actor +- **Description:** The actor name, from which the PendinPayments should be claimed and paid out. + +## Returns + +**Type:** TransactionResult + +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 39bc6aa7..01a44819 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -61,7 +61,7 @@ export const sidebar = { link: "/docs/vaccount/get-pending-payments", }, { text: "payout", link: "/docs/vaccount/payout" }, - { text: "TODO: withdraw", link: "/docs/vaccount/withdraw" }, + { text: "withdraw", link: "/docs/vaccount/withdraw" }, ], }, { diff --git a/docs/snippets/vaccount/withdraw.ts b/docs/snippets/vaccount/withdraw.ts new file mode 100644 index 00000000..35fe6181 --- /dev/null +++ b/docs/snippets/vaccount/withdraw.ts @@ -0,0 +1,31 @@ +import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; +import { + createClient, + jungle4 as chain, + // eos as chain, + Session, + withdraw, + type WithdrawArgs, + getVAccounts, +} from "@effectai/sdk"; + +const actor = "actor-name"; +const permission = "permission-level"; + +// Create a session +const session = new Session({ + chain, + actor, + permission, + walletPlugin: new WalletPluginPrivateKey("your_private_key"), +}); + +// Create client and connect session +const client = await createClient({ session }); + +// Retrieve user balance +const [vacc] = await getVAccounts({ client, actor }); +console.log(vacc.balance); + +// If there are claimable payments, claim and pay them out. +const result = await withdraw({ client, quantity: 42 }); From e24b1ef55723a9d11498debe7fc3e86502eeccdb Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 00:44:46 -0400 Subject: [PATCH 78/84] Update transfer docs to use snippets --- docs/pages/docs/token/transfer.mdx | 25 +------------------------ docs/snippets/token/transfer.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 24 deletions(-) create mode 100644 docs/snippets/token/transfer.ts diff --git a/docs/pages/docs/token/transfer.mdx b/docs/pages/docs/token/transfer.mdx index f3e67e6e..a31071f4 100644 --- a/docs/pages/docs/token/transfer.mdx +++ b/docs/pages/docs/token/transfer.mdx @@ -10,30 +10,7 @@ This action allows users to transfer EFX tokens from one Effect account to anoth ## Usage ```ts -import { - getCampaigns, - createClient, - jungle4 as network - vTransfer -} from '@effectai/sdk' - -const client = createClient({ network }) -const accountName = Name.from(actor); - -const vAccount = await getOrCreateVAccount({ client, actor: accountName }); -const preBalanceVAccount = Number(vAccount.balance.quantity); - -const vAccountReceiver = await getOrCreateVAccount({ - client, - actor: receiver, -}); -const preBalanceReceiver = Number(vAccountReceiver.balance.quantity); - -const result = await vTransfer({ - client, - to_id: vAccountReceiver.id, - quantity, -}); +// [!include ~/snippets/token/transfer.ts] ``` ## Returns diff --git a/docs/snippets/token/transfer.ts b/docs/snippets/token/transfer.ts new file mode 100644 index 00000000..1341df50 --- /dev/null +++ b/docs/snippets/token/transfer.ts @@ -0,0 +1,20 @@ +import { + createClient, + jungle4 as network, + vTransfer, + getVAccounts, +} from "@effectai/sdk"; + +const client = await createClient({ network }); +const receiver = "receiver-account-name"; + +const [vAccountReceiver] = await getVAccounts({ + client, + actor: receiver, +}); + +const result = await vTransfer({ + client, + to_id: vAccountReceiver.id, + quantity: 12, +}); From 548525401100c1c2dff505e77daa513cced60b4e Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 00:56:13 -0400 Subject: [PATCH 79/84] Add deposit docs --- docs/pages/docs/vaccount/deposit.mdx | 59 ++++++++++++++++++++++++++++ docs/sidebar.ts | 2 +- docs/snippets/vaccount/deposit.ts | 12 ++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 docs/pages/docs/vaccount/deposit.mdx create mode 100644 docs/snippets/vaccount/deposit.ts diff --git a/docs/pages/docs/vaccount/deposit.mdx b/docs/pages/docs/vaccount/deposit.mdx new file mode 100644 index 00000000..fb23566e --- /dev/null +++ b/docs/pages/docs/vaccount/deposit.mdx @@ -0,0 +1,59 @@ +# deposit + +## Description + +User are able to deposit funds into their vAccount or claim the funds from escrow and have them deposited in to their vAccount. +Depositing funds into the vAccount is nessesary to be able to pay for creating campaigns, batches and tasks. + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/deposit.ts] +``` + +## Output + +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### vAccountId +- **Description:** The vAccount id, where the funds should be deposited. + + +### amount +- **Description:** The amount of funds to be deposited. + +## Returns + +**Type:** TransactionResult + +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 01a44819..bccaca37 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -43,7 +43,7 @@ export const sidebar = { text: "TODO: createAccount", link: "/docs/vaccount/createAccount", }, - { text: "TODO: deposit", link: "/docs/vaccount/deposit" }, + { text: "deposit", link: "/docs/vaccount/deposit" }, { text: "TODO: getAccounts", link: "/docs/vaccount/getAccounts", diff --git a/docs/snippets/vaccount/deposit.ts b/docs/snippets/vaccount/deposit.ts new file mode 100644 index 00000000..5fd47e98 --- /dev/null +++ b/docs/snippets/vaccount/deposit.ts @@ -0,0 +1,12 @@ +import { + createClient, + jungle4 as network, + getVAccounts, + deposit, + type DepositArgs, +} from "@effectai/sdk"; + +const client = await createClient({ network }); +const actor = "account-name"; +const [vAccount] = await getVAccounts({ client, actor }); +const result = await deposit({ client, vAccountId: vAccount.id, amount: 0.1 }); From 0e2c69b01ebca57f006bdf2fc782ce7c26bb3daf Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 01:06:47 -0400 Subject: [PATCH 80/84] Add create-account docs --- docs/pages/docs/vaccount/create-account.mdx | 59 +++++++++++++++++++++ docs/sidebar.ts | 4 +- docs/snippets/vaccount/create-account.ts | 18 +++---- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/docs/pages/docs/vaccount/create-account.mdx b/docs/pages/docs/vaccount/create-account.mdx index e69de29b..4c3581a4 100644 --- a/docs/pages/docs/vaccount/create-account.mdx +++ b/docs/pages/docs/vaccount/create-account.mdx @@ -0,0 +1,59 @@ +# createAccount + +## Description + +Next to having an EOS account, users will also need to create an Effect Network Virtual account, also known as a VAccount. +This virtual account is used to store the user's funds and is used to pay for services on the Effect Network. +The vAccount system is controled by the smart contract found at: [https://www.bloks.io/account/vaccount.efx](https://www.bloks.io/account/vaccount.efx) + +This function will create a new vAccount for the user, and will return the transaction response object. + + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/create-account.ts] +``` + +## Output + +```json +response: { + transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + processed: { + id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2", + block_num: 137520447, + block_time: "2024-05-01T03:55:31.500", + producer_block_id: null, + receipt: [Object ...], + elapsed: 4854, + net_usage: 176, + scheduled: false, + action_traces: [ + [Object ...] + ], + account_ram_delta: null, + except: null, + error_code: null, + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### Actor +- **Description:** The actor name, from which the PendinPayments should be claimed and paid out. + +## Returns + +**Type:** TransactionResult + +**Description:** +Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction. +Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx) + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index bccaca37..5e05a9ca 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -40,8 +40,8 @@ export const sidebar = { items: [ { text: "claim", link: "/docs/vaccount/claim" }, { - text: "TODO: createAccount", - link: "/docs/vaccount/createAccount", + text: "createAccount", + link: "/docs/vaccount/create-account", }, { text: "deposit", link: "/docs/vaccount/deposit" }, { diff --git a/docs/snippets/vaccount/create-account.ts b/docs/snippets/vaccount/create-account.ts index d7751b60..607b4745 100644 --- a/docs/snippets/vaccount/create-account.ts +++ b/docs/snippets/vaccount/create-account.ts @@ -6,6 +6,7 @@ import { Session, createVAccount, type CreateVAccountArgs, + getVAccounts, } from "@effectai/sdk"; const actor = "actor-name"; @@ -21,16 +22,9 @@ const session = new Session({ // Create client and connect session const client = await createClient({ session }); +const account = "account-name"; +const tx_result = await createVAccount({ client, account }); +console.log(tx_result); -const [vacc] = await getVAccounts({ client, actor }); - -// Check pending payments -const pendingPayments = await getPendingPayments({ - client, - vAccountId: vacc.id, -}); - -// If there are claimable payments, claim them. -if (pendingPayments.totalEfxClaimable > 0) { - await claim({ client }); -} +// Retrieve the created vaccount +const [vacc] = await getVAccounts({ client, actor: account }); From 27756a4fd4b8c0117cd43a20c0c7e25b0105f63b Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 01:17:36 -0400 Subject: [PATCH 81/84] Add get vaccounts doc --- docs/pages/docs/vaccount/get-accounts.mdx | 57 +++++++++++++++++++++++ docs/sidebar.ts | 4 +- docs/snippets/vaccount/get-accounts.ts | 14 ++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 docs/snippets/vaccount/get-accounts.ts diff --git a/docs/pages/docs/vaccount/get-accounts.mdx b/docs/pages/docs/vaccount/get-accounts.mdx index e69de29b..50429ca3 100644 --- a/docs/pages/docs/vaccount/get-accounts.mdx +++ b/docs/pages/docs/vaccount/get-accounts.mdx @@ -0,0 +1,57 @@ + +# getVaccounts + +## Description + +Next to having an EOS account, users will also need to create an Effect Network Virtual account, also known as a VAccount. +This virtual account is used to store the user's funds and is used to pay for services on the Effect Network. +The vAccount system is controled by the smart contract found at: [https://www.bloks.io/account/vaccount.efx](https://www.bloks.io/account/vaccount.efx) + +This function will return the vAccounts associated with the actor name provided. + + +## Usage + +```ts twoslash + +// [!include ~/snippets/vaccount/get-accounts.ts] +``` + +## Output + +```json +{ + id: 24, + nonce: 19, + address: [ "name", "forcedev1234" ], + balance: { + quantity: "2.0981 EFX", + contract: "efxtoken1112", + }, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### Actor +- **Description:** The actor name, from which the PendinPayments should be claimed and paid out. + +## Returns + +**Type:** Vaccount + +**Description:** +An object representing a Vaccount, containing the following fields: +- **id**: The id of the vAccount. +- **nonce**: The nonce of the vAccount. +- **address**: The address of the vAccount. +- **balance**: The balance of the vAccount, containing the following fields: + - **quantity**: The amount of EFX tokens in the vAccount. + - **contract**: The contract of the EFX tokens in the vAccount. + + + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 5e05a9ca..5b398124 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -45,8 +45,8 @@ export const sidebar = { }, { text: "deposit", link: "/docs/vaccount/deposit" }, { - text: "TODO: getAccounts", - link: "/docs/vaccount/getAccounts", + text: "getVAccounts", + link: "/docs/vaccount/get-accounts", }, { text: "TODO: getAvatar", diff --git a/docs/snippets/vaccount/get-accounts.ts b/docs/snippets/vaccount/get-accounts.ts new file mode 100644 index 00000000..52d98ab3 --- /dev/null +++ b/docs/snippets/vaccount/get-accounts.ts @@ -0,0 +1,14 @@ +import { + createClient, + jungle4 as network, + // eos as network, + getVAccounts, +} from "@effectai/sdk"; + +// Create client and connect session +const client = await createClient({ network }); + +const actor = "forcedev1234"; +// Retrieve the vAccounts +const [vacc] = await getVAccounts({ client, actor }); +console.log(vacc); From 76aa0fcce11de8bbb932dfdd22f316d7f24de36c Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 01:28:59 -0400 Subject: [PATCH 82/84] Add get pending paymets doc --- .../docs/vaccount/get-pending-payments.mdx | 54 +++++++++++++++++++ docs/sidebar.ts | 32 +++++------ .../snippets/vaccount/get-pending-payments.ts | 21 ++++++++ 3 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 docs/snippets/vaccount/get-pending-payments.ts diff --git a/docs/pages/docs/vaccount/get-pending-payments.mdx b/docs/pages/docs/vaccount/get-pending-payments.mdx index e69de29b..63257e37 100644 --- a/docs/pages/docs/vaccount/get-pending-payments.mdx +++ b/docs/pages/docs/vaccount/get-pending-payments.mdx @@ -0,0 +1,54 @@ +# getPendinPayments + +## Description + +Every time a user completes a task, EFX tokens are unlocked from the task, and put into escrow for the Vaccount. This function returns the pending payments for a given Vaccount. +Thus the Vaccount can claim the pending payments, and pay then out to the user when the unlock period has passed. + + +## Usage + +```ts twoslash +// [!include ~/snippets/vaccount/get-pending-payments.ts] +``` + +## Output + +```json +{ + pendingPayments: [], + claimablePayments: [], + totalEfxPending: 0, + totalEfxClaimable: 0, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### vAccountId +- **Description:** The id of the vAccount. + +## Returns + +**Type:** An object containing the following fields: + +- **pendingPayments** + - **Type:** Array of objects + - **Description:** An array of objects containing the pending payments for the Vaccount. + +- **claimablePayments** + - **Type:** Array of objects + - **Description:** An array of objects containing the claimable payments for the Vaccount. + +- **totalEfxPending** + - **Type:** Number + - **Description:** The total amount of EFX pending for the Vaccount. + +- **totalEfxClaimable** + - **Type:** Number + - **Description:** The total amount of EFX claimable for the Vaccount. + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 5b398124..781c11fc 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -48,16 +48,12 @@ export const sidebar = { text: "getVAccounts", link: "/docs/vaccount/get-accounts", }, + // { + // text: "TODO: getAvatar", + // link: "/docs/vaccount/get-avatar", + // }, { - text: "TODO: getAvatar", - link: "/docs/vaccount/get-avatar", - }, - { - text: "TODO: getOrCreate", - link: "/docs/vaccount/get-or-create", - }, - { - text: "TODO: getPendingPayments", + // text: "getPendingPayments", link: "/docs/vaccount/get-pending-payments", }, { text: "payout", link: "/docs/vaccount/payout" }, @@ -90,15 +86,15 @@ export const sidebar = { }, ], }, - { - text: "DAO", - items: [ - { - text: "TODO: getAccountAssets", - link: "/docs/tasks/dao/get-account-assets", - }, - ], - }, + // { + // text: "DAO", + // items: [ + // { + // text: "TODO: getAccountAssets", + // link: "/docs/tasks/dao/get-account-assets", + // }, + // ], + // }, ], }, { diff --git a/docs/snippets/vaccount/get-pending-payments.ts b/docs/snippets/vaccount/get-pending-payments.ts new file mode 100644 index 00000000..85d2aa21 --- /dev/null +++ b/docs/snippets/vaccount/get-pending-payments.ts @@ -0,0 +1,21 @@ +import { + createClient, + jungle4 as network, + // eos as network, + getVAccounts, + getPendingPayments, +} from "@effectai/sdk"; + +// Create client and connect session +const client = await createClient({ network }); + +const actor = "forcedev1234"; +// Retrieve the vAccounts +const [vacc] = await getVAccounts({ client, actor }); + +const pendingPayments = await getPendingPayments({ + client, + vAccountId: vacc.id, +}); + +console.log(pendingPayments); From e4fa0fee4f2a2cbb5036ff81f6e05a58133eff7f Mon Sep 17 00:00:00 2001 From: David Britt Date: Mon, 13 May 2024 01:28:59 -0400 Subject: [PATCH 83/84] Add get pending paymets doc --- .../docs/vaccount/get-pending-payments.mdx | 54 +++++++++++++++++++ docs/sidebar.ts | 32 +++++------ .../snippets/vaccount/get-pending-payments.ts | 21 ++++++++ 3 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 docs/snippets/vaccount/get-pending-payments.ts diff --git a/docs/pages/docs/vaccount/get-pending-payments.mdx b/docs/pages/docs/vaccount/get-pending-payments.mdx index e69de29b..63257e37 100644 --- a/docs/pages/docs/vaccount/get-pending-payments.mdx +++ b/docs/pages/docs/vaccount/get-pending-payments.mdx @@ -0,0 +1,54 @@ +# getPendinPayments + +## Description + +Every time a user completes a task, EFX tokens are unlocked from the task, and put into escrow for the Vaccount. This function returns the pending payments for a given Vaccount. +Thus the Vaccount can claim the pending payments, and pay then out to the user when the unlock period has passed. + + +## Usage + +```ts twoslash +// [!include ~/snippets/vaccount/get-pending-payments.ts] +``` + +## Output + +```json +{ + pendingPayments: [], + claimablePayments: [], + totalEfxPending: 0, + totalEfxClaimable: 0, +} +``` + +## Parameters + +### Client +- **Description:** The client object, **must** be connected with a Session. + +### vAccountId +- **Description:** The id of the vAccount. + +## Returns + +**Type:** An object containing the following fields: + +- **pendingPayments** + - **Type:** Array of objects + - **Description:** An array of objects containing the pending payments for the Vaccount. + +- **claimablePayments** + - **Type:** Array of objects + - **Description:** An array of objects containing the claimable payments for the Vaccount. + +- **totalEfxPending** + - **Type:** Number + - **Description:** The total amount of EFX pending for the Vaccount. + +- **totalEfxClaimable** + - **Type:** Number + - **Description:** The total amount of EFX claimable for the Vaccount. + + diff --git a/docs/sidebar.ts b/docs/sidebar.ts index 5b398124..a8c3391d 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -48,16 +48,12 @@ export const sidebar = { text: "getVAccounts", link: "/docs/vaccount/get-accounts", }, + // { + // text: "TODO: getAvatar", + // link: "/docs/vaccount/get-avatar", + // }, { - text: "TODO: getAvatar", - link: "/docs/vaccount/get-avatar", - }, - { - text: "TODO: getOrCreate", - link: "/docs/vaccount/get-or-create", - }, - { - text: "TODO: getPendingPayments", + text: "getPendingPayments", link: "/docs/vaccount/get-pending-payments", }, { text: "payout", link: "/docs/vaccount/payout" }, @@ -90,15 +86,15 @@ export const sidebar = { }, ], }, - { - text: "DAO", - items: [ - { - text: "TODO: getAccountAssets", - link: "/docs/tasks/dao/get-account-assets", - }, - ], - }, + // { + // text: "DAO", + // items: [ + // { + // text: "TODO: getAccountAssets", + // link: "/docs/tasks/dao/get-account-assets", + // }, + // ], + // }, ], }, { diff --git a/docs/snippets/vaccount/get-pending-payments.ts b/docs/snippets/vaccount/get-pending-payments.ts new file mode 100644 index 00000000..85d2aa21 --- /dev/null +++ b/docs/snippets/vaccount/get-pending-payments.ts @@ -0,0 +1,21 @@ +import { + createClient, + jungle4 as network, + // eos as network, + getVAccounts, + getPendingPayments, +} from "@effectai/sdk"; + +// Create client and connect session +const client = await createClient({ network }); + +const actor = "forcedev1234"; +// Retrieve the vAccounts +const [vacc] = await getVAccounts({ client, actor }); + +const pendingPayments = await getPendingPayments({ + client, + vAccountId: vacc.id, +}); + +console.log(pendingPayments); From f6f20e54a6889030c0dea5a7a20ae58b78b2989f Mon Sep 17 00:00:00 2001 From: djmbritt Date: Mon, 13 May 2024 05:45:11 +0000 Subject: [PATCH 84/84] chore: format --- biome.json | 11 ++--------- package.json | 15 +++------------ src/actions/vaccount/getOrCreate.test.ts | 2 +- src/actions/vaccount/payout.ts | 2 +- src/utils/keys.ts | 2 +- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/biome.json b/biome.json index a2258812..d986a83d 100644 --- a/biome.json +++ b/biome.json @@ -5,17 +5,10 @@ }, "formatter": { "enabled": true, - "ignore": [ - "dist", - "test" - ] + "ignore": ["dist", "test"] }, "linter": { - "ignore": [ - "dist", - "test", - "scripts" - ], + "ignore": ["dist", "test", "scripts"], "enabled": true, "rules": { "recommended": true diff --git a/package.json b/package.json index 36f6cb8d..d06e1d81 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,7 @@ "module": "./dist/exports/index.js", "browser": "dist/exports/index.js", "types": "./dist/exports/index.d.ts", - "files": [ - "dist" - ], + "files": ["dist"], "scripts": { "test": "bun --env-file=.env test", "test:watch": "bun --env-file=.env test --watch", @@ -30,12 +28,7 @@ "type": "git", "url": "git+https://github.com/effectai/effect-js.git" }, - "keywords": [ - "efx", - "AI", - "blockchain", - "microtasks" - ], + "keywords": ["efx", "AI", "blockchain", "microtasks"], "author": { "name": "Effect-AI", "url": "https://effect.network", @@ -67,7 +60,5 @@ "idb-keyval": "^6.2.1", "node-localstorage": "^3.0.5" }, - "trustedDependencies": [ - "@biomejs/biome" - ] + "trustedDependencies": ["@biomejs/biome"] } diff --git a/src/actions/vaccount/getOrCreate.test.ts b/src/actions/vaccount/getOrCreate.test.ts index 547a0710..403eedca 100644 --- a/src/actions/vaccount/getOrCreate.test.ts +++ b/src/actions/vaccount/getOrCreate.test.ts @@ -1,6 +1,6 @@ import { expect, test, describe } from "bun:test"; import { destructureEnv, testClientSession } from "../../../test/src/utils"; -import { type Account } from "../../exports"; +import type { Account } from "../../exports"; import { getOrCreateVAccount } from "./getOrCreate"; describe("GetOrCreate", async () => { diff --git a/src/actions/vaccount/payout.ts b/src/actions/vaccount/payout.ts index 4670e4c0..d9fd5704 100644 --- a/src/actions/vaccount/payout.ts +++ b/src/actions/vaccount/payout.ts @@ -1,4 +1,4 @@ -import { type AnyAction, ExtendedAsset, NameType } from "@wharfkit/antelope"; +import { type AnyAction, ExtendedAsset, type NameType } from "@wharfkit/antelope"; import type { Client } from "../../client"; import { VAccountError } from "../../errors"; import { useEFXContracts } from "../../utils/state"; diff --git a/src/utils/keys.ts b/src/utils/keys.ts index f0644900..675327c4 100644 --- a/src/utils/keys.ts +++ b/src/utils/keys.ts @@ -2,7 +2,7 @@ import { ABIEncoder, Checksum256, Name, - NameType, + type NameType, UInt32, UInt64, } from "@wharfkit/antelope";