From 12f43ce06f5b15a64860146036a5055ab3209332 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:27:26 -0400 Subject: [PATCH 01/12] Update getbalance to retrieve balnce of usdt and eos --- src/actions/token/getBalance.ts | 28 +++++++++++++++++++++++----- src/constants/network.ts | 4 ++++ src/types/network.ts | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/actions/token/getBalance.ts b/src/actions/token/getBalance.ts index 8ee90fab..8705b716 100644 --- a/src/actions/token/getBalance.ts +++ b/src/actions/token/getBalance.ts @@ -9,18 +9,36 @@ export type GetBalanceArgs = { export const getBalance = async ({ client, actor, -}: GetBalanceArgs): Promise => { +}: GetBalanceArgs): Promise<{ + efxBalance: Asset; + usdtBalance: Asset; + eosBalance: Asset; +}> => { const { network, provider } = client; const { contracts } = network.config.efx; - const [balance] = await provider.v1.chain.get_currency_balance( + const [efxBalance] = await provider.v1.chain.get_currency_balance( contracts.token, actor, ); - if (!balance) { - throw new Error("No balance found"); + const [usdtBalance] = await provider.v1.chain.get_currency_balance( + contracts.usdt, + actor, + ); + + const [eosBalance] = await provider.v1.chain.get_currency_balance( + contracts.eostoken, + actor, + ); + + if (!efxBalance && !usdtBalance && eosBalance) { + throw new Error("No efxBalance found"); } - return balance; + return { + efxBalance, + usdtBalance, + eosBalance, + }; }; diff --git a/src/constants/network.ts b/src/constants/network.ts index 8b1728ae..89bbf3d3 100644 --- a/src/constants/network.ts +++ b/src/constants/network.ts @@ -14,6 +14,8 @@ export const jungle4: Network = { contracts: { tasks: "effecttasks2", token: "efxtoken1112", + usdt: "tethertether", + eostoken: "eosio.token", stake: "efxstake1111", feepool: "efxfeepool11", proposals: "efxproposals", @@ -39,6 +41,8 @@ export const eos: Network = { contracts: { tasks: "force.efx", token: "effecttokens", + usdt: "tethertether", + eostoken: "eosio.token", stake: "efxstakepool", feepool: "feepool.efx", proposals: "daoproposals", diff --git a/src/types/network.ts b/src/types/network.ts index 5c3068bd..aa10a367 100644 --- a/src/types/network.ts +++ b/src/types/network.ts @@ -17,6 +17,8 @@ export interface EfxConfig { contracts: { tasks: string; token: string; + usdt: string; + eostoken: string; stake: string; feepool: string; proposals: string; From d1cedfd4def8fc8aea0d72dad554bedd3c5129c9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:32:51 -0400 Subject: [PATCH 02/12] Update getBalance.test.ts --- src/actions/token/getBalance.test.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/actions/token/getBalance.test.ts b/src/actions/token/getBalance.test.ts index 207d1645..08ede2b1 100644 --- a/src/actions/token/getBalance.test.ts +++ b/src/actions/token/getBalance.test.ts @@ -5,16 +5,17 @@ import { eos, jungle4 } from "../../exports"; describe("getBalance", async () => { test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = await createClient({ network: jungle4 }); - const actor = "forcedev1234"; + const client = await createClient({ network: eos }); + const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); expect(balance).toBeDefined(); - expect(balance.toString()).toBeDefined(); - expect(balance.toString()).toContain("EFX"); + expect(balance.efxBalance).toBeDefined(); + expect(balance.usdtBalance).toBeDefined(); + expect(balance.eosBalance).toBeDefined(); }); test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = await createClient({ network: eos }); + const client = await createClient({ network: jungle4 }); const actor = "cryptonode99"; expect(async () => await getBalance({ client, actor })).toThrowError(); }); From 2957a8fc4e09b1b018fef57245f0be7edfd3e794 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:33:01 -0400 Subject: [PATCH 03/12] Remove token.test.ts --- src/actions/token/token.test.ts | 62 --------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/actions/token/token.test.ts diff --git a/src/actions/token/token.test.ts b/src/actions/token/token.test.ts deleted file mode 100644 index d0db7e59..00000000 --- a/src/actions/token/token.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, test, expect } from "bun:test"; -import { getPrice } from "./getPrice"; -import { getBalance } from "./getBalance"; -import { swap, type SwapArgs } from "./swap"; -import { createClient } from "../../client"; -import { eos, jungle4 } from "../../exports"; -import { testClientSession } from "../../../test/src/utils"; - -describe("getPrice", async () => { - 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 = 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."); -}); - -describe("Swap", async () => { - // 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(); - }); -}); From 4de1224c37041e31fb8299c540023f068713ffc9 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:55:30 -0400 Subject: [PATCH 04/12] Update getbalance docs --- docs/pages/docs/glossary/asset.mdx | 3 +-- docs/pages/docs/token/get-balance.mdx | 19 +++++++++++-------- docs/snippets/token/get-balance.ts | 12 ++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/pages/docs/glossary/asset.mdx b/docs/pages/docs/glossary/asset.mdx index b8636b02..06ff2378 100644 --- a/docs/pages/docs/glossary/asset.mdx +++ b/docs/pages/docs/glossary/asset.mdx @@ -17,5 +17,4 @@ An example for the `Asset` object is as follows: } ``` -Read more about the `Asset` object here: -https://wharfkit.com/docs/antelope/asset +Read more about the `Asset` type at the following link: https://wharfkit.com/docs/antelope/asset diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index 4bd74da7..9d4b035a 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -2,10 +2,11 @@ ## Description -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. +This function is used to return the blance of EFX, USDT, and EOS of an account on the EOS blockchain. +Namely the balance is what is available in the wallet of the user. + +There is a difference between the balance of EFX of an account that is available in the wallet of the user and the balance of EFX that is available in an Effect Network Virtual Account. +To retrieve the EFX balance of a user in their Virtual Account, use the [getVaccount](/docs/vaccount/get-accounts.mdx) ## Usage @@ -17,7 +18,9 @@ Note the use of `balance.toString()` to convert the balance to a string. ## Output ``` -"100.0000 EFX" +378332.1630 EFX +26.7212 USDT +31.3322 EOS ``` ## Parameters @@ -34,11 +37,11 @@ Note that the account name is a Name object that is created using the `Name.from ## Returns -**Type:** Asset +**Type:** `{ efxBalance: Asset; usdtBalance: Asset; eosBalance: Asset; }` **Description:** -Returns the balance of the account in the form of an Asset object. +Return an object with three properties: `efxBalance`, `usdtBalance`, and `eosBalance`, each of which is 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) +You can read more about the: [`Asset` here](/docs/glossary/asset). diff --git a/docs/snippets/token/get-balance.ts b/docs/snippets/token/get-balance.ts index 697184b4..a379583b 100644 --- a/docs/snippets/token/get-balance.ts +++ b/docs/snippets/token/get-balance.ts @@ -1,6 +1,10 @@ -import { createClient, getBalance, jungle4 } from "@effectai/sdk"; +import { createClient, eos, getBalance, jungle4 } from "@effectai/sdk"; -const client = await createClient({ network: jungle4 }); -const actor = "forcedev1234"; +const client = await createClient({ network: eos }); +const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); -console.log(balance.toString()); +console.log( + balance.efxBalance.toString(), + balance.usdtBalance.toString(), + balance.eosBalance.toString(), +); From b868e6bd95f7d5556553a09195956b605dbebd5e Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:32:51 -0400 Subject: [PATCH 05/12] Update getBalance.test.ts --- src/actions/token/getBalance.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/actions/token/getBalance.test.ts b/src/actions/token/getBalance.test.ts index 207d1645..50753444 100644 --- a/src/actions/token/getBalance.test.ts +++ b/src/actions/token/getBalance.test.ts @@ -5,16 +5,20 @@ import { eos, jungle4 } from "../../exports"; describe("getBalance", async () => { test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = await createClient({ network: jungle4 }); - const actor = "forcedev1234"; + const client = await createClient({ network: eos }); + const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); expect(balance).toBeDefined(); - expect(balance.toString()).toBeDefined(); - expect(balance.toString()).toContain("EFX"); + expect(balance.efxBalance).toBeDefined(); + expect(balance.usdtBalance).toBeDefined(); + expect(balance.eosBalance).toBeDefined(); + expect(balance.efxBalance).toBeGreaterThan(0); + expect(balance.usdtBalance).toBeGreaterThan(0); + expect(balance.eosBalance).toBeGreaterThan(0); }); test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = await createClient({ network: eos }); + const client = await createClient({ network: jungle4 }); const actor = "cryptonode99"; expect(async () => await getBalance({ client, actor })).toThrowError(); }); From 8e707e995f94f898b6c8b14f9e3e6a4ea5325a42 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:33:01 -0400 Subject: [PATCH 06/12] Remove token.test.ts --- src/actions/token/token.test.ts | 62 --------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/actions/token/token.test.ts diff --git a/src/actions/token/token.test.ts b/src/actions/token/token.test.ts deleted file mode 100644 index d0db7e59..00000000 --- a/src/actions/token/token.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, test, expect } from "bun:test"; -import { getPrice } from "./getPrice"; -import { getBalance } from "./getBalance"; -import { swap, type SwapArgs } from "./swap"; -import { createClient } from "../../client"; -import { eos, jungle4 } from "../../exports"; -import { testClientSession } from "../../../test/src/utils"; - -describe("getPrice", async () => { - 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 = 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."); -}); - -describe("Swap", async () => { - // 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(); - }); -}); From 7010d0986f90dfd66bd196c3dd3899b39e993525 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:55:30 -0400 Subject: [PATCH 07/12] Update getbalance docs --- docs/pages/docs/glossary/asset.mdx | 3 +-- docs/pages/docs/token/get-balance.mdx | 19 +++++++++++-------- docs/snippets/token/get-balance.ts | 12 ++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/pages/docs/glossary/asset.mdx b/docs/pages/docs/glossary/asset.mdx index b8636b02..06ff2378 100644 --- a/docs/pages/docs/glossary/asset.mdx +++ b/docs/pages/docs/glossary/asset.mdx @@ -17,5 +17,4 @@ An example for the `Asset` object is as follows: } ``` -Read more about the `Asset` object here: -https://wharfkit.com/docs/antelope/asset +Read more about the `Asset` type at the following link: https://wharfkit.com/docs/antelope/asset diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index 4bd74da7..9d4b035a 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -2,10 +2,11 @@ ## Description -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. +This function is used to return the blance of EFX, USDT, and EOS of an account on the EOS blockchain. +Namely the balance is what is available in the wallet of the user. + +There is a difference between the balance of EFX of an account that is available in the wallet of the user and the balance of EFX that is available in an Effect Network Virtual Account. +To retrieve the EFX balance of a user in their Virtual Account, use the [getVaccount](/docs/vaccount/get-accounts.mdx) ## Usage @@ -17,7 +18,9 @@ Note the use of `balance.toString()` to convert the balance to a string. ## Output ``` -"100.0000 EFX" +378332.1630 EFX +26.7212 USDT +31.3322 EOS ``` ## Parameters @@ -34,11 +37,11 @@ Note that the account name is a Name object that is created using the `Name.from ## Returns -**Type:** Asset +**Type:** `{ efxBalance: Asset; usdtBalance: Asset; eosBalance: Asset; }` **Description:** -Returns the balance of the account in the form of an Asset object. +Return an object with three properties: `efxBalance`, `usdtBalance`, and `eosBalance`, each of which is 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) +You can read more about the: [`Asset` here](/docs/glossary/asset). diff --git a/docs/snippets/token/get-balance.ts b/docs/snippets/token/get-balance.ts index 697184b4..a379583b 100644 --- a/docs/snippets/token/get-balance.ts +++ b/docs/snippets/token/get-balance.ts @@ -1,6 +1,10 @@ -import { createClient, getBalance, jungle4 } from "@effectai/sdk"; +import { createClient, eos, getBalance, jungle4 } from "@effectai/sdk"; -const client = await createClient({ network: jungle4 }); -const actor = "forcedev1234"; +const client = await createClient({ network: eos }); +const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); -console.log(balance.toString()); +console.log( + balance.efxBalance.toString(), + balance.usdtBalance.toString(), + balance.eosBalance.toString(), +); From 999ad21d265d72abad18aa776fae1b567a32f4ff Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:27:26 -0400 Subject: [PATCH 08/12] Update getbalance to retrieve balnce of usdt and eos --- src/actions/token/getBalance.ts | 28 +++++++++++++++++++++++----- src/constants/network.ts | 4 ++++ src/types/network.ts | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/actions/token/getBalance.ts b/src/actions/token/getBalance.ts index 8ee90fab..30a5b5d9 100644 --- a/src/actions/token/getBalance.ts +++ b/src/actions/token/getBalance.ts @@ -9,18 +9,36 @@ export type GetBalanceArgs = { export const getBalance = async ({ client, actor, -}: GetBalanceArgs): Promise => { +}: GetBalanceArgs): Promise<{ + efxBalance: Asset; + usdtBalance: Asset; + eosBalance: Asset; +}> => { const { network, provider } = client; const { contracts } = network.config.efx; - const [balance] = await provider.v1.chain.get_currency_balance( + const [efxBalance] = await provider.v1.chain.get_currency_balance( contracts.token, actor, ); - if (!balance) { - throw new Error("No balance found"); + const [usdtBalance] = await provider.v1.chain.get_currency_balance( + contracts.usdt, + actor, + ); + + const [eosBalance] = await provider.v1.chain.get_currency_balance( + contracts.eostoken, + actor, + ); + + if (!efxBalance && !usdtBalance && !eosBalance) { + throw new Error("No efxBalance found"); } - return balance; + return { + efxBalance, + usdtBalance, + eosBalance, + }; }; diff --git a/src/constants/network.ts b/src/constants/network.ts index 8b1728ae..89bbf3d3 100644 --- a/src/constants/network.ts +++ b/src/constants/network.ts @@ -14,6 +14,8 @@ export const jungle4: Network = { contracts: { tasks: "effecttasks2", token: "efxtoken1112", + usdt: "tethertether", + eostoken: "eosio.token", stake: "efxstake1111", feepool: "efxfeepool11", proposals: "efxproposals", @@ -39,6 +41,8 @@ export const eos: Network = { contracts: { tasks: "force.efx", token: "effecttokens", + usdt: "tethertether", + eostoken: "eosio.token", stake: "efxstakepool", feepool: "feepool.efx", proposals: "daoproposals", diff --git a/src/types/network.ts b/src/types/network.ts index 5c3068bd..aa10a367 100644 --- a/src/types/network.ts +++ b/src/types/network.ts @@ -17,6 +17,8 @@ export interface EfxConfig { contracts: { tasks: string; token: string; + usdt: string; + eostoken: string; stake: string; feepool: string; proposals: string; From 3ed66621872848d50bb6e16ac7281fe3f1ecd96e Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:32:51 -0400 Subject: [PATCH 09/12] Update getBalance.test.ts --- src/actions/token/getBalance.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/actions/token/getBalance.test.ts b/src/actions/token/getBalance.test.ts index 207d1645..50753444 100644 --- a/src/actions/token/getBalance.test.ts +++ b/src/actions/token/getBalance.test.ts @@ -5,16 +5,20 @@ import { eos, jungle4 } from "../../exports"; describe("getBalance", async () => { test("getBalance() should retrieve balance from user on mainnet", async () => { - const client = await createClient({ network: jungle4 }); - const actor = "forcedev1234"; + const client = await createClient({ network: eos }); + const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); expect(balance).toBeDefined(); - expect(balance.toString()).toBeDefined(); - expect(balance.toString()).toContain("EFX"); + expect(balance.efxBalance).toBeDefined(); + expect(balance.usdtBalance).toBeDefined(); + expect(balance.eosBalance).toBeDefined(); + expect(balance.efxBalance).toBeGreaterThan(0); + expect(balance.usdtBalance).toBeGreaterThan(0); + expect(balance.eosBalance).toBeGreaterThan(0); }); test("getBalance() should throw Error retrieving balance from unknown user.", async () => { - const client = await createClient({ network: eos }); + const client = await createClient({ network: jungle4 }); const actor = "cryptonode99"; expect(async () => await getBalance({ client, actor })).toThrowError(); }); From 0e09ce7be6269d6d1414d965552545f1dbd46ad8 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:33:01 -0400 Subject: [PATCH 10/12] Remove token.test.ts --- src/actions/token/token.test.ts | 62 --------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/actions/token/token.test.ts diff --git a/src/actions/token/token.test.ts b/src/actions/token/token.test.ts deleted file mode 100644 index d0db7e59..00000000 --- a/src/actions/token/token.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, test, expect } from "bun:test"; -import { getPrice } from "./getPrice"; -import { getBalance } from "./getBalance"; -import { swap, type SwapArgs } from "./swap"; -import { createClient } from "../../client"; -import { eos, jungle4 } from "../../exports"; -import { testClientSession } from "../../../test/src/utils"; - -describe("getPrice", async () => { - 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 = 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."); -}); - -describe("Swap", async () => { - // 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(); - }); -}); From ee9ca61760870794f4c9212f50dd32885401f967 Mon Sep 17 00:00:00 2001 From: David Britt Date: Wed, 15 May 2024 14:55:30 -0400 Subject: [PATCH 11/12] Update getbalance docs --- docs/pages/docs/glossary/asset.mdx | 3 +-- docs/pages/docs/token/get-balance.mdx | 19 +++++++++++-------- docs/snippets/token/get-balance.ts | 12 ++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/pages/docs/glossary/asset.mdx b/docs/pages/docs/glossary/asset.mdx index b8636b02..06ff2378 100644 --- a/docs/pages/docs/glossary/asset.mdx +++ b/docs/pages/docs/glossary/asset.mdx @@ -17,5 +17,4 @@ An example for the `Asset` object is as follows: } ``` -Read more about the `Asset` object here: -https://wharfkit.com/docs/antelope/asset +Read more about the `Asset` type at the following link: https://wharfkit.com/docs/antelope/asset diff --git a/docs/pages/docs/token/get-balance.mdx b/docs/pages/docs/token/get-balance.mdx index 4bd74da7..9d4b035a 100644 --- a/docs/pages/docs/token/get-balance.mdx +++ b/docs/pages/docs/token/get-balance.mdx @@ -2,10 +2,11 @@ ## Description -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. +This function is used to return the blance of EFX, USDT, and EOS of an account on the EOS blockchain. +Namely the balance is what is available in the wallet of the user. + +There is a difference between the balance of EFX of an account that is available in the wallet of the user and the balance of EFX that is available in an Effect Network Virtual Account. +To retrieve the EFX balance of a user in their Virtual Account, use the [getVaccount](/docs/vaccount/get-accounts.mdx) ## Usage @@ -17,7 +18,9 @@ Note the use of `balance.toString()` to convert the balance to a string. ## Output ``` -"100.0000 EFX" +378332.1630 EFX +26.7212 USDT +31.3322 EOS ``` ## Parameters @@ -34,11 +37,11 @@ Note that the account name is a Name object that is created using the `Name.from ## Returns -**Type:** Asset +**Type:** `{ efxBalance: Asset; usdtBalance: Asset; eosBalance: Asset; }` **Description:** -Returns the balance of the account in the form of an Asset object. +Return an object with three properties: `efxBalance`, `usdtBalance`, and `eosBalance`, each of which is 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) +You can read more about the: [`Asset` here](/docs/glossary/asset). diff --git a/docs/snippets/token/get-balance.ts b/docs/snippets/token/get-balance.ts index 697184b4..a379583b 100644 --- a/docs/snippets/token/get-balance.ts +++ b/docs/snippets/token/get-balance.ts @@ -1,6 +1,10 @@ -import { createClient, getBalance, jungle4 } from "@effectai/sdk"; +import { createClient, eos, getBalance, jungle4 } from "@effectai/sdk"; -const client = await createClient({ network: jungle4 }); -const actor = "forcedev1234"; +const client = await createClient({ network: eos }); +const actor = "cryptonode42"; const balance = await getBalance({ client, actor }); -console.log(balance.toString()); +console.log( + balance.efxBalance.toString(), + balance.usdtBalance.toString(), + balance.eosBalance.toString(), +); From 8382b39b473a465308c006affdf3a53748e8e154 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Thu, 30 May 2024 13:00:24 +0200 Subject: [PATCH 12/12] add changeset --- .changeset/soft-flies-kick.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-flies-kick.md diff --git a/.changeset/soft-flies-kick.md b/.changeset/soft-flies-kick.md new file mode 100644 index 00000000..df38a3ad --- /dev/null +++ b/.changeset/soft-flies-kick.md @@ -0,0 +1,5 @@ +--- +"@effectai/sdk": patch +--- + +update getBalance action to return eos, efx and usdt balance.