From 2374d4a52d467b137e769cdc38802f81e440d957 Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Tue, 20 Feb 2024 11:21:44 -0300 Subject: [PATCH 1/6] feat: :sparkles: add icp provider and connect fnc --- src/icp/connect.spec.ts | 46 +++++++++++++++++++++++++++++++++++++++++ src/icp/connect.ts | 24 +++++++++++++++++++++ src/icp/index.ts | 27 ++++++++++++++++++++++++ src/icp/types.ts | 1 + src/index.ts | 1 + src/networks.ts | 7 +++++++ src/types.ts | 1 + src/web3-provider.ts | 3 +++ 8 files changed, 110 insertions(+) create mode 100644 src/icp/connect.spec.ts create mode 100644 src/icp/connect.ts create mode 100644 src/icp/index.ts create mode 100644 src/icp/types.ts diff --git a/src/icp/connect.spec.ts b/src/icp/connect.spec.ts new file mode 100644 index 0000000..8046a19 --- /dev/null +++ b/src/icp/connect.spec.ts @@ -0,0 +1,46 @@ +import { NoAvailableAccountsError, NoProviderAvailableError } from '@/errors'; +import { UserRejectedError } from '@/errors/user-rejected-error'; +import { describe, expect, it, vi } from 'vitest'; +import { web3Window } from '..'; +import { connect } from './connect'; + +vi.mock('@/types', () => ({ + web3Window: { + ic: { + requestConnect: vi.fn(), + plug: { + principalId: 'wil-123', + }, + }, + }, +})) + +const principalId = 'wil-123'; + +describe('Connect case', () => { + it('should successfully connects and retrieves an account', async () => { + web3Window.ic.requestConnect.mockResolvedValue(true) + const account = await connect() + + expect(account).toEqual(principalId) + }) + + it('should throws error when no provider is available', async () => { + web3Window.ic.requestConnect.mockResolvedValue(false) + + await expect(connect()).rejects.toThrow(NoProviderAvailableError) + }) + + it('should throws error when no accounts are available', async () => { + web3Window.ic.requestConnect.mockResolvedValue(true) + web3Window.ic.plug.principalId = undefined; + + await expect(connect()).rejects.toThrow(NoAvailableAccountsError) + }) + + it('should throws error when the user rejects the connection', async () => { + web3Window.ic.requestConnect.mockRejectedValue(new Error('The agent creation was rejected')) + + await expect(connect()).rejects.toThrow(UserRejectedError) + }) +}) diff --git a/src/icp/connect.ts b/src/icp/connect.ts new file mode 100644 index 0000000..aaad15a --- /dev/null +++ b/src/icp/connect.ts @@ -0,0 +1,24 @@ +import { NoAvailableAccountsError, NoProviderAvailableError } from '@/errors'; +import { UserRejectedError } from '@/errors/user-rejected-error'; +import { web3Window } from '@/types'; +import type { PrincipalAddress } from './types'; + +export async function connect(): Promise { + try { + const hasConnected = await web3Window.ic.requestConnect(); + if (!hasConnected) + throw new NoProviderAvailableError() + + const account: PrincipalAddress | undefined = web3Window.ic.plug.principalId; + if (!account || account.length === 0) + throw new NoAvailableAccountsError() + + return account + } + catch (error) { + if ((error as Error).message.toLowerCase().includes('the agent creation was rejected')) + throw new UserRejectedError() + + throw error + } +} diff --git a/src/icp/index.ts b/src/icp/index.ts new file mode 100644 index 0000000..d3f66f6 --- /dev/null +++ b/src/icp/index.ts @@ -0,0 +1,27 @@ +import type { ProviderEntity } from '@/entities/provider-entity'; +import type { Account, Balance } from '..'; +import { connect } from './connect'; + +export class InternetComputerProvider implements ProviderEntity { + async connect(): Promise { + const principalAddress = await connect() + + return [{ name: 'Principal Account', address: principalAddress }] + } + + getBalance(address: string): Promise { + throw new Error('Method not implemented.'); + } + + signMessage(address: string, message: string): Promise { + throw new Error('Method not implemented.'); + } + + signatureVerify(message: string, signature: string, address: string): boolean { + throw new Error('Method not implemented.'); + } + + joinPool(address: string, poolId: number, amount: number): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/icp/types.ts b/src/icp/types.ts new file mode 100644 index 0000000..a0ebd06 --- /dev/null +++ b/src/icp/types.ts @@ -0,0 +1 @@ +export type PrincipalAddress = string diff --git a/src/index.ts b/src/index.ts index 8fa2d24..f6b8194 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from './ada/index' +export * from './icp/index' export * from './networks' export * from './substrate/dot/index' export * from './substrate/ksm/index' diff --git a/src/networks.ts b/src/networks.ts index ab2afe6..d5371a6 100644 --- a/src/networks.ts +++ b/src/networks.ts @@ -19,12 +19,19 @@ export const Networks = { decimals: 5, minStakeAmount: 1, // TODO: Validate min stake amount }, + icp: { + id: 4, + name: 'Internet Computer', + decimals: 5, // TODO: Validate decimals + minStakeAmount: 1, // TODO: Validate min stake amount + }, } export enum Network { POLKADOT = 'dot', KUSAMA = 'ksm', CARDANO = 'ada', + INTERNET_COMPUTER = 'icp', } export type NetworkKey = keyof typeof Networks diff --git a/src/types.ts b/src/types.ts index 2c4bbb1..9752346 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,6 +20,7 @@ export type ProviderBuilderProps = T extends 'dot' | 'ksm' export type Web3Window = { injectedWeb3: any cardano: any + ic: any } & Window & typeof globalThis export const web3Window = (window as Web3Window) diff --git a/src/web3-provider.ts b/src/web3-provider.ts index 7ea3a8a..6cae52e 100644 --- a/src/web3-provider.ts +++ b/src/web3-provider.ts @@ -2,6 +2,7 @@ import { CardanoProvider } from './ada'; import type { CardanoProviderProps } from './ada/types'; import type { ProviderEntity } from './entities/provider-entity'; import { InvalidNetworkError } from './errors/invalid-network-error'; +import { InternetComputerProvider } from './icp'; import type { NetworkData, NetworkKey } from './networks'; import { getNetworkKeyById, isValidNetwork } from './networks'; import { PolkadotProvider } from './substrate/dot'; @@ -33,6 +34,8 @@ export class Web3Provider { return new KusamaProvider(props as SubstrateProviderProps) case 'ada': return new CardanoProvider(props as CardanoProviderProps) + case 'icp': + return new InternetComputerProvider() default: throw new InvalidNetworkError() } From 5265ae1e9b7d6ddd2c133013eb1ac02305ab8346 Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Tue, 20 Feb 2024 14:35:24 -0300 Subject: [PATCH 2/6] fix: :bug: fix request connect object key --- package.json | 2 +- src/icp/connect.spec.ts | 10 +++++----- src/icp/connect.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index cbbd004..25482e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web3-hub", - "version": "0.6.7", + "version": "0.7.8", "description": "Make web3 more easily with agnostic library", "source": "src/index.ts", "exports": { diff --git a/src/icp/connect.spec.ts b/src/icp/connect.spec.ts index 8046a19..7f68f20 100644 --- a/src/icp/connect.spec.ts +++ b/src/icp/connect.spec.ts @@ -7,8 +7,8 @@ import { connect } from './connect'; vi.mock('@/types', () => ({ web3Window: { ic: { - requestConnect: vi.fn(), plug: { + requestConnect: vi.fn(), principalId: 'wil-123', }, }, @@ -19,27 +19,27 @@ const principalId = 'wil-123'; describe('Connect case', () => { it('should successfully connects and retrieves an account', async () => { - web3Window.ic.requestConnect.mockResolvedValue(true) + web3Window.ic.plug.requestConnect.mockResolvedValue(true) const account = await connect() expect(account).toEqual(principalId) }) it('should throws error when no provider is available', async () => { - web3Window.ic.requestConnect.mockResolvedValue(false) + web3Window.ic.plug.requestConnect.mockResolvedValue(false) await expect(connect()).rejects.toThrow(NoProviderAvailableError) }) it('should throws error when no accounts are available', async () => { - web3Window.ic.requestConnect.mockResolvedValue(true) + web3Window.ic.plug.requestConnect.mockResolvedValue(true) web3Window.ic.plug.principalId = undefined; await expect(connect()).rejects.toThrow(NoAvailableAccountsError) }) it('should throws error when the user rejects the connection', async () => { - web3Window.ic.requestConnect.mockRejectedValue(new Error('The agent creation was rejected')) + web3Window.ic.plug.requestConnect.mockRejectedValue(new Error('The agent creation was rejected')) await expect(connect()).rejects.toThrow(UserRejectedError) }) diff --git a/src/icp/connect.ts b/src/icp/connect.ts index aaad15a..c6335a9 100644 --- a/src/icp/connect.ts +++ b/src/icp/connect.ts @@ -5,7 +5,7 @@ import type { PrincipalAddress } from './types'; export async function connect(): Promise { try { - const hasConnected = await web3Window.ic.requestConnect(); + const hasConnected = await web3Window.ic.plug.requestConnect(); if (!hasConnected) throw new NoProviderAvailableError() From 80c0a48e6d42e1acf18eaef79d271885bf7efbd4 Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Tue, 20 Feb 2024 14:43:22 -0300 Subject: [PATCH 3/6] fix: :bug: fix icp base decimals --- src/networks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networks.ts b/src/networks.ts index d5371a6..3825533 100644 --- a/src/networks.ts +++ b/src/networks.ts @@ -22,7 +22,7 @@ export const Networks = { icp: { id: 4, name: 'Internet Computer', - decimals: 5, // TODO: Validate decimals + decimals: 8, minStakeAmount: 1, // TODO: Validate min stake amount }, } From a4bc83ac60906f41719de08231b4ce153befe181 Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Thu, 22 Feb 2024 20:08:12 -0300 Subject: [PATCH 4/6] feat: :sparkles: add bond extra fnc to substrate --- src/entities/provider-entity.ts | 9 ++--- src/substrate/bond-extra.spec.ts | 56 ++++++++++++++++++++++++++++++++ src/substrate/bond-extra.ts | 31 ++++++++++++++++++ src/substrate/index.ts | 7 ++++ src/types.ts | 1 + 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/substrate/bond-extra.spec.ts create mode 100644 src/substrate/bond-extra.ts diff --git a/src/entities/provider-entity.ts b/src/entities/provider-entity.ts index 8245f6a..6c221ea 100644 --- a/src/entities/provider-entity.ts +++ b/src/entities/provider-entity.ts @@ -1,9 +1,10 @@ -import type { Account, Address, Balance } from '@/types' +import type { Account, Address, Balance, Hash } from '@/types' export interface ProviderEntity { connect(): Promise - getBalance(address: string): Promise - signMessage(address: string, message: string): Promise + getBalance(address: Address): Promise + signMessage(address: Address, message: string): Promise signatureVerify(message: string, signature: string, address: Address): boolean - joinPool(address: string, poolId: number, amount: number): Promise + joinPool(address: Address, poolId: number, amount: number): Promise + bondExtra(address: Address, amount: number): Promise } diff --git a/src/substrate/bond-extra.spec.ts b/src/substrate/bond-extra.spec.ts new file mode 100644 index 0000000..eb30184 --- /dev/null +++ b/src/substrate/bond-extra.spec.ts @@ -0,0 +1,56 @@ +import { InvalidNetworkError } from '@/errors/invalid-network-error' +import { UserRejectedError } from '@/errors/user-rejected-error' +import { Networks } from '@/networks' +import { web3FromAddress } from '@polkadot/extension-dapp' +import { describe, expect, it, vi } from 'vitest' +import { bondExtra } from './bond-extra' + +vi.mock('@/networks', () => ({ + Networks: { + validNetwork: { decimals: 10 }, + }, +})) + +vi.mock('@polkadot/extension-dapp', () => ({ + web3FromAddress: vi.fn(), +})) + +const address = 'wil123' +const amount = 100 +const validHash = 'hash123' + +describe('Bond Extra value case', () => { + it('should throw error for invalid password', async () => { + const api: any = { tx: { nominationPools: { bondExtra: vi.fn() } } } + await expect(bondExtra('invalidNetwork' as any, api, address, amount)).rejects.toThrow(InvalidNetworkError) + }) + + it('should call bondExtra function with correct params', async () => { + const injector = { signer: 'signer' }; + (web3FromAddress as any).mockResolvedValue(injector) + + const bondExtraMock = vi.fn().mockImplementation(() => ({ + signAndSend: vi.fn().mockResolvedValue({ toString: () => validHash }), + })) + + const api: any = { tx: { nominationPools: { bondExtra: bondExtraMock } } } + const hash = await bondExtra('validNetwork' as any, api, address, amount) + + expect(web3FromAddress).toHaveBeenCalledWith(address) + expect(bondExtraMock).toHaveBeenCalledWith({ + FreeBalance: 100 * 10 ** (Networks as any).validNetwork.decimals, + }) + expect(hash).toEqual(validHash) + }) + + it('should throw error when the tx is rejected by user', async () => { + (web3FromAddress as any).mockResolvedValue({ signer: 'signer' }) + + const bondExtraMock = vi.fn().mockImplementation(() => ({ + signAndSend: vi.fn().mockRejectedValue(new Error('Rejected by user')), + })) + const api: any = { tx: { nominationPools: { bondExtra: bondExtraMock } } } + + await expect(bondExtra('validNetwork' as any, api, address, amount)).rejects.toThrow(UserRejectedError) + }) +}) diff --git a/src/substrate/bond-extra.ts b/src/substrate/bond-extra.ts new file mode 100644 index 0000000..82ab173 --- /dev/null +++ b/src/substrate/bond-extra.ts @@ -0,0 +1,31 @@ +import { InvalidNetworkError } from '@/errors/invalid-network-error'; +import { UserRejectedError } from '@/errors/user-rejected-error'; +import type { Network } from '@/networks'; +import { Networks } from '@/networks'; +import type { Address } from '@/types'; +import type { ApiPromise } from '@polkadot/api'; +import { web3FromAddress } from '@polkadot/extension-dapp'; + +export async function bondExtra(network: Network, api: ApiPromise, address: Address, amount: number) { + try { + const selectedNetwork = Networks[network] + if (!selectedNetwork) + throw new InvalidNetworkError() + + const precision = Networks[network].decimals + const injector = await web3FromAddress(address) + const tx = api.tx.nominationPools.bondExtra({ + FreeBalance: amount * 10 ** precision, + }); + const signer = { signer: injector.signer } + + const hash = await tx.signAndSend(address, signer) + return hash.toString() + } + catch (error) { + if ((error as Error).message.toLowerCase().includes('rejected by user')) + throw new UserRejectedError() + + throw error + } +} diff --git a/src/substrate/index.ts b/src/substrate/index.ts index 0accd39..a354ff8 100644 --- a/src/substrate/index.ts +++ b/src/substrate/index.ts @@ -2,6 +2,7 @@ import type { ProviderEntity } from '@/entities/provider-entity'; import type { Network } from '@/networks'; import type { Account, Address, Balance } from '@/types'; import { ApiPromise, WsProvider } from '@polkadot/api'; +import { bondExtra } from './bond-extra'; import { connect } from './connect'; import { getBalance } from './get-balance'; import { joinPool } from './join-pool'; @@ -61,4 +62,10 @@ export class SubstrateProvider implements ProviderEntity { return joinPool(this.network, api, address, poolId, amount) } + + async bondExtra(address: string, amount: number): Promise { + const api = await this.createProvider() + + return bondExtra(this.network, api, address, amount) + } } diff --git a/src/types.ts b/src/types.ts index 9752346..da166ae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ import type { NetworkKey } from './networks' import type { SubstrateProviderProps } from './substrate/types' export type Address = string +export type Hash = string export interface Account { name?: string From 047a5cfc06c05f893df4d6ee1c53238fb981a5f5 Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Thu, 22 Feb 2024 20:28:36 -0300 Subject: [PATCH 5/6] feat: :sparkles: add claim payout to substrate --- package.json | 2 +- src/entities/provider-entity.ts | 1 + src/substrate/bond-extra.spec.ts | 6 ---- src/substrate/bond-extra.ts | 5 --- src/substrate/claim.spec.ts | 53 ++++++++++++++++++++++++++++++++ src/substrate/claim.ts | 21 +++++++++++++ src/substrate/index.ts | 12 ++++++++ src/substrate/join-pool.spec.ts | 9 ------ src/substrate/join-pool.ts | 5 --- 9 files changed, 88 insertions(+), 26 deletions(-) create mode 100644 src/substrate/claim.spec.ts create mode 100644 src/substrate/claim.ts diff --git a/package.json b/package.json index 25482e5..6d4371f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web3-hub", - "version": "0.7.8", + "version": "0.7.10", "description": "Make web3 more easily with agnostic library", "source": "src/index.ts", "exports": { diff --git a/src/entities/provider-entity.ts b/src/entities/provider-entity.ts index 6c221ea..0c0c85f 100644 --- a/src/entities/provider-entity.ts +++ b/src/entities/provider-entity.ts @@ -7,4 +7,5 @@ export interface ProviderEntity { signatureVerify(message: string, signature: string, address: Address): boolean joinPool(address: Address, poolId: number, amount: number): Promise bondExtra(address: Address, amount: number): Promise + claim(address: Address): Promise } diff --git a/src/substrate/bond-extra.spec.ts b/src/substrate/bond-extra.spec.ts index eb30184..27ba064 100644 --- a/src/substrate/bond-extra.spec.ts +++ b/src/substrate/bond-extra.spec.ts @@ -1,4 +1,3 @@ -import { InvalidNetworkError } from '@/errors/invalid-network-error' import { UserRejectedError } from '@/errors/user-rejected-error' import { Networks } from '@/networks' import { web3FromAddress } from '@polkadot/extension-dapp' @@ -20,11 +19,6 @@ const amount = 100 const validHash = 'hash123' describe('Bond Extra value case', () => { - it('should throw error for invalid password', async () => { - const api: any = { tx: { nominationPools: { bondExtra: vi.fn() } } } - await expect(bondExtra('invalidNetwork' as any, api, address, amount)).rejects.toThrow(InvalidNetworkError) - }) - it('should call bondExtra function with correct params', async () => { const injector = { signer: 'signer' }; (web3FromAddress as any).mockResolvedValue(injector) diff --git a/src/substrate/bond-extra.ts b/src/substrate/bond-extra.ts index 82ab173..5f7be43 100644 --- a/src/substrate/bond-extra.ts +++ b/src/substrate/bond-extra.ts @@ -1,4 +1,3 @@ -import { InvalidNetworkError } from '@/errors/invalid-network-error'; import { UserRejectedError } from '@/errors/user-rejected-error'; import type { Network } from '@/networks'; import { Networks } from '@/networks'; @@ -8,10 +7,6 @@ import { web3FromAddress } from '@polkadot/extension-dapp'; export async function bondExtra(network: Network, api: ApiPromise, address: Address, amount: number) { try { - const selectedNetwork = Networks[network] - if (!selectedNetwork) - throw new InvalidNetworkError() - const precision = Networks[network].decimals const injector = await web3FromAddress(address) const tx = api.tx.nominationPools.bondExtra({ diff --git a/src/substrate/claim.spec.ts b/src/substrate/claim.spec.ts new file mode 100644 index 0000000..3276e83 --- /dev/null +++ b/src/substrate/claim.spec.ts @@ -0,0 +1,53 @@ +import { UserRejectedError } from '@/errors/user-rejected-error'; +import { web3FromAddress } from '@polkadot/extension-dapp'; +import { describe, expect, it, vi } from 'vitest'; +import { claim } from './claim'; + +vi.mock('@polkadot/extension-dapp', () => ({ + web3FromAddress: vi.fn(), +})) + +const address = 'wil123' + +describe('Claim case', () => { + it('should successfully submit claim tx and return hash', async () => { + const injector = { signer: 'signer' }; + (web3FromAddress as any).mockResolvedValue(injector) + + const signAndSendMock = vi.fn().mockResolvedValue({ toString: () => 'hash123' }) + const claimPayoutMock = vi.fn().mockImplementation(() => ({ + signAndSend: signAndSendMock, + })) + + const api: any = { + tx: { + nominationPools: { + claimPayout: claimPayoutMock, + }, + }, + } + + const hash = await claim(api, address) + + expect(web3FromAddress).toHaveBeenCalledWith(address) + expect(claimPayoutMock).toHaveBeenCalled() + expect(signAndSendMock).toHaveBeenCalledWith(address, { signer: injector.signer }) + expect(hash).toBe('hash123') + }) + + it('should throw error when the user reject tx', async () => { + (web3FromAddress as any).mockResolvedValue({ signer: 'signer' }) + + const api: any = { + tx: { + nominationPools: { + claimPayout: vi.fn().mockImplementation(() => ({ + signAndSend: vi.fn().mockRejectedValue(new Error('Rejected by user')), + })), + }, + }, + } + + await expect(claim(api, address)).rejects.toThrow(UserRejectedError) + }) +}) diff --git a/src/substrate/claim.ts b/src/substrate/claim.ts new file mode 100644 index 0000000..d0f14f0 --- /dev/null +++ b/src/substrate/claim.ts @@ -0,0 +1,21 @@ +import { UserRejectedError } from '@/errors/user-rejected-error'; +import type { Address } from '@/types'; +import type { ApiPromise } from '@polkadot/api'; +import { web3FromAddress } from '@polkadot/extension-dapp'; + +export async function claim(api: ApiPromise, address: Address) { + try { + const injector = await web3FromAddress(address) + const tx = api.tx.nominationPools.claimPayout() + const signer = { signer: injector.signer } + + const hash = await tx.signAndSend(address, signer) + return hash.toString() + } + catch (error) { + if ((error as Error).message.toLowerCase().includes('rejected by user')) + throw new UserRejectedError() + + throw error + } +} diff --git a/src/substrate/index.ts b/src/substrate/index.ts index a354ff8..05d58a0 100644 --- a/src/substrate/index.ts +++ b/src/substrate/index.ts @@ -1,8 +1,11 @@ import type { ProviderEntity } from '@/entities/provider-entity'; +import { InvalidNetworkError } from '@/errors/invalid-network-error'; import type { Network } from '@/networks'; +import { Networks } from '@/networks'; import type { Account, Address, Balance } from '@/types'; import { ApiPromise, WsProvider } from '@polkadot/api'; import { bondExtra } from './bond-extra'; +import { claim } from './claim'; import { connect } from './connect'; import { getBalance } from './get-balance'; import { joinPool } from './join-pool'; @@ -18,6 +21,9 @@ export class SubstrateProvider implements ProviderEntity { rpcProvider: string constructor(network: Network, appName: string, rpcProvider: string) { + if (!Networks[network]) + throw new InvalidNetworkError() + this.network = network this.appName = appName this.rpcProvider = rpcProvider @@ -68,4 +74,10 @@ export class SubstrateProvider implements ProviderEntity { return bondExtra(this.network, api, address, amount) } + + async claim(address: string): Promise { + const api = await this.createProvider() + + return claim(api, address) + } } diff --git a/src/substrate/join-pool.spec.ts b/src/substrate/join-pool.spec.ts index 8fabece..7668254 100644 --- a/src/substrate/join-pool.spec.ts +++ b/src/substrate/join-pool.spec.ts @@ -1,4 +1,3 @@ -import { InvalidNetworkError } from '@/errors/invalid-network-error' import { MinAmountError } from '@/errors/min-amount-error' import { UserRejectedError } from '@/errors/user-rejected-error' import { web3FromAddress } from '@polkadot/extension-dapp' @@ -26,14 +25,6 @@ const address = 'wil123' const network = Network.POLKADOT describe('Join pool case', () => { - it('throws InvalidNetworkError for an unsupported network', async () => { - const poolId = 1 - const amount = 10 - - await expect(joinPool('invalidNetwork' as any, {} as any, address, poolId, amount)) - .rejects.toThrow(InvalidNetworkError); - }); - it('throws MinAmountError if the amount is below the minimum stake amount', async () => { const poolId = 1 const invalidAmount = 9 diff --git a/src/substrate/join-pool.ts b/src/substrate/join-pool.ts index 4efa296..ade81ee 100644 --- a/src/substrate/join-pool.ts +++ b/src/substrate/join-pool.ts @@ -1,4 +1,3 @@ -import { InvalidNetworkError } from '@/errors/invalid-network-error'; import { MinAmountError } from '@/errors/min-amount-error'; import { UserRejectedError } from '@/errors/user-rejected-error'; import type { Network } from '@/networks'; @@ -8,10 +7,6 @@ import { web3FromAddress } from '@polkadot/extension-dapp'; export async function joinPool(network: Network, api: ApiPromise, address: string, poolId: number, amount: number) { try { - const selectedNetwork = Networks[network] - if (!selectedNetwork) - throw new InvalidNetworkError() - if (amount < Networks[network].minStakeAmount) throw new MinAmountError() From 5c99d157a1d1bfbf2c8c9102851581b69343c76a Mon Sep 17 00:00:00 2001 From: Wil Macedo Date: Thu, 22 Feb 2024 20:33:07 -0300 Subject: [PATCH 6/6] fix: :bug: add new methods to other providers --- src/ada/index.ts | 8 ++++++++ src/icp/index.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ada/index.ts b/src/ada/index.ts index 6baa94a..c31060f 100644 --- a/src/ada/index.ts +++ b/src/ada/index.ts @@ -36,4 +36,12 @@ export class CardanoProvider implements ProviderEntity { async joinPool(address: string, poolId: number, amount: number): Promise { throw new Error('Method not implemented.'); } + + bondExtra(address: string, amount: number): Promise { + throw new Error('Method not implemented.'); + } + + claim(address: string): Promise { + throw new Error('Method not implemented.'); + } } diff --git a/src/icp/index.ts b/src/icp/index.ts index d3f66f6..b96f6d2 100644 --- a/src/icp/index.ts +++ b/src/icp/index.ts @@ -24,4 +24,12 @@ export class InternetComputerProvider implements ProviderEntity { joinPool(address: string, poolId: number, amount: number): Promise { throw new Error('Method not implemented.'); } + + bondExtra(address: string, amount: number): Promise { + throw new Error('Method not implemented.'); + } + + claim(address: string): Promise { + throw new Error('Method not implemented.'); + } }