diff --git a/docs/api/classes/ColonyToken.md b/docs/api/classes/ColonyToken.md index 17cbbc5a..383aaffc 100644 --- a/docs/api/classes/ColonyToken.md +++ b/docs/api/classes/ColonyToken.md @@ -41,6 +41,31 @@ This does not deploy a new token, only connects to an exisiting one ## Methods +### allowance + +▸ **allowance**(`owner`, `spender`): `Promise`<`BigNumber`\> + +Returns the amount which `spender` is still allowed to withdraw from `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | +| `spender` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The allowance amount + +#### Inherited from + +[ERC20Token](ERC20Token.md).[allowance](ERC20Token.md#allowance) + +___ + ### approve ▸ **approve**(`amount`, `spender?`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"approve"``, { `guy?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> @@ -90,11 +115,35 @@ A transaction creator ___ +### balanceOf + +▸ **balanceOf**(`owner`): `Promise`<`BigNumber`\> + +Returns the account balance of another account with address `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The account balance of the corresponding address + +#### Inherited from + +[ERC20Token](ERC20Token.md).[balanceOf](ERC20Token.md#balanceof) + +___ + ### decimals ▸ **decimals**(): `Promise`<`number`\> -Gets the token's decimals +Returns the token's decimals #### Returns @@ -112,7 +161,7 @@ ___ ▸ **name**(): `Promise`<`string`\> -Gets the token's name +Returns the token's name #### Returns @@ -210,7 +259,7 @@ ___ ▸ **symbol**(): `Promise`<`string`\> -Gets the token's symbol +Returns the token's symbol #### Returns @@ -221,3 +270,90 @@ The token's symbol (e.g. CLNY) #### Inherited from [ERC20Token](ERC20Token.md).[symbol](ERC20Token.md#symbol) + +___ + +### totalSupply + +▸ **totalSupply**(): `Promise`<`BigNumber`\> + +Returns the total token supply + +#### Returns + +`Promise`<`BigNumber`\> + +The token's total supply + +#### Inherited from + +[ERC20Token](ERC20Token.md).[totalSupply](ERC20Token.md#totalsupply) + +___ + +### transfer + +▸ **transfer**(`to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens to address `to` from the currently used wallet + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | + +#### Inherited from + +[ERC20Token](ERC20Token.md).[transfer](ERC20Token.md#transfer) + +___ + +### transferFrom + +▸ **transferFrom**(`from`, `to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens from address `from` to address `to` + +The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `from` | `string` | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | + +#### Inherited from + +[ERC20Token](ERC20Token.md).[transferFrom](ERC20Token.md#transferfrom) diff --git a/docs/api/classes/ERC20Token.md b/docs/api/classes/ERC20Token.md index a643bad1..b7c0bc78 100644 --- a/docs/api/classes/ERC20Token.md +++ b/docs/api/classes/ERC20Token.md @@ -35,6 +35,27 @@ This does not deploy a new token, only connects to an exisiting one ## Methods +### allowance + +▸ **allowance**(`owner`, `spender`): `Promise`<`BigNumber`\> + +Returns the amount which `spender` is still allowed to withdraw from `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | +| `spender` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The allowance amount + +___ + ### approve ▸ **approve**(`amount`, `spender?`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"approve"``, { `guy?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> @@ -80,11 +101,31 @@ A transaction creator ___ +### balanceOf + +▸ **balanceOf**(`owner`): `Promise`<`BigNumber`\> + +Returns the account balance of another account with address `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The account balance of the corresponding address + +___ + ### decimals ▸ **decimals**(): `Promise`<`number`\> -Gets the token's decimals +Returns the token's decimals #### Returns @@ -98,7 +139,7 @@ ___ ▸ **name**(): `Promise`<`string`\> -Gets the token's name +Returns the token's name #### Returns @@ -112,10 +153,85 @@ ___ ▸ **symbol**(): `Promise`<`string`\> -Gets the token's symbol +Returns the token's symbol #### Returns `Promise`<`string`\> The token's symbol (e.g. CLNY) + +___ + +### totalSupply + +▸ **totalSupply**(): `Promise`<`BigNumber`\> + +Returns the total token supply + +#### Returns + +`Promise`<`BigNumber`\> + +The token's total supply + +___ + +### transfer + +▸ **transfer**(`to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens to address `to` from the currently used wallet + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | + +___ + +### transferFrom + +▸ **transferFrom**(`from`, `to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens from address `from` to address `to` + +The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `from` | `string` | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | diff --git a/docs/api/classes/ERC2612Token.md b/docs/api/classes/ERC2612Token.md index a1a5ca55..64f290b1 100644 --- a/docs/api/classes/ERC2612Token.md +++ b/docs/api/classes/ERC2612Token.md @@ -41,6 +41,31 @@ This does not deploy a new token, only connects to an exisiting one ## Methods +### allowance + +▸ **allowance**(`owner`, `spender`): `Promise`<`BigNumber`\> + +Returns the amount which `spender` is still allowed to withdraw from `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | +| `spender` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The allowance amount + +#### Inherited from + +[ERC20Token](ERC20Token.md).[allowance](ERC20Token.md#allowance) + +___ + ### approve ▸ **approve**(`amount`, `spender?`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"approve"``, { `guy?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> @@ -90,11 +115,35 @@ A transaction creator ___ +### balanceOf + +▸ **balanceOf**(`owner`): `Promise`<`BigNumber`\> + +Returns the account balance of another account with address `owner` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `owner` | `string` | + +#### Returns + +`Promise`<`BigNumber`\> + +The account balance of the corresponding address + +#### Inherited from + +[ERC20Token](ERC20Token.md).[balanceOf](ERC20Token.md#balanceof) + +___ + ### decimals ▸ **decimals**(): `Promise`<`number`\> -Gets the token's decimals +Returns the token's decimals #### Returns @@ -112,7 +161,7 @@ ___ ▸ **name**(): `Promise`<`string`\> -Gets the token's name +Returns the token's name #### Returns @@ -183,7 +232,7 @@ ___ ▸ **symbol**(): `Promise`<`string`\> -Gets the token's symbol +Returns the token's symbol #### Returns @@ -194,3 +243,90 @@ The token's symbol (e.g. CLNY) #### Inherited from [ERC20Token](ERC20Token.md).[symbol](ERC20Token.md#symbol) + +___ + +### totalSupply + +▸ **totalSupply**(): `Promise`<`BigNumber`\> + +Returns the total token supply + +#### Returns + +`Promise`<`BigNumber`\> + +The token's total supply + +#### Inherited from + +[ERC20Token](ERC20Token.md).[totalSupply](ERC20Token.md#totalsupply) + +___ + +### transfer + +▸ **transfer**(`to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens to address `to` from the currently used wallet + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transfer"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | + +#### Inherited from + +[ERC20Token](ERC20Token.md).[transfer](ERC20Token.md#transfer) + +___ + +### transferFrom + +▸ **transferFrom**(`from`, `to`, `value`): [`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +Transfers `value` amount of tokens from address `from` to address `to` + +The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `from` | `string` | +| `to` | `string` | +| `value` | `BigNumberish` | + +#### Returns + +[`TxCreator`](TxCreator.md)<`TokenERC20`, ``"transferFrom"``, { `dst?`: `string` ; `src?`: `string` ; `wad?`: `BigNumber` }, [`MetadataType`](../enums/MetadataType.md)\> + +A transaction creator + +#### Event data + +| Property | Type | Description | +| :------ | :------ | :------ | +| `src` | string | The address that transferred the tokens from their wallet | +| `dst` | string | Address of the recipient of the tokens | +| `wad` | BigNumber | Amount that was transferred | + +#### Inherited from + +[ERC20Token](ERC20Token.md).[transferFrom](ERC20Token.md#transferfrom) diff --git a/src/ColonyNetwork/ERC20Token.ts b/src/ColonyNetwork/ERC20Token.ts index a67633ab..bfa7186a 100644 --- a/src/ColonyNetwork/ERC20Token.ts +++ b/src/ColonyNetwork/ERC20Token.ts @@ -1,4 +1,7 @@ -import type { ApprovalEventObject } from '@colony/colony-js/events'; +import { + ApprovalEventObject, + TransferEventObject, +} from '@colony/colony-js/events'; import { ERC20Token as ERC20TokenType, @@ -49,7 +52,7 @@ export class ERC20Token { } /** - * Gets the token's name + * Returns the token's name * * @returns The token's name (e.g. Colony Network Token) */ @@ -58,7 +61,7 @@ export class ERC20Token { } /** - * Gets the token's symbol + * Returns the token's symbol * * @returns The token's symbol (e.g. CLNY) */ @@ -67,7 +70,7 @@ export class ERC20Token { } /** - * Gets the token's decimals + * Returns the token's decimals * * @returns The token's decimals (e.g. 18) */ @@ -75,6 +78,83 @@ export class ERC20Token { return this.tokenClient.decimals(); } + /** + * Returns the total token supply + * + * @returns The token's total supply + */ + async totalSupply() { + return this.tokenClient.totalSupply(); + } + + /** + * Returns the account balance of another account with address `owner` + * + * @returns The account balance of the corresponding address + */ + async balanceOf(owner: string) { + return this.tokenClient.balanceOf(owner); + } + + /** + * Returns the amount which `spender` is still allowed to withdraw from `owner` + * + * @returns The allowance amount + */ + async allowance(owner: string, spender: string) { + return this.tokenClient.allowance(owner, spender); + } + + /** + * Transfers `value` amount of tokens to address `to` from the currently used wallet + * + * @returns A transaction creator + * + * #### Event data + * + * | Property | Type | Description | + * | :------ | :------ | :------ | + * | `src` | string | The address that transferred the tokens from their wallet | + * | `dst` | string | Address of the recipient of the tokens | + * | `wad` | BigNumber | Amount that was transferred | + */ + transfer(to: string, value: BigNumberish) { + return this.colonyNetwork.createTxCreator( + this.tokenClient, + 'transfer', + [to, value], + async (receipt) => ({ + ...extractEvent('Transfer', receipt), + }), + ); + } + + /** + * Transfers `value` amount of tokens from address `from` to address `to` + * + * The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies + * + * @returns A transaction creator + * + * #### Event data + * + * | Property | Type | Description | + * | :------ | :------ | :------ | + * | `src` | string | The address that transferred the tokens from their wallet | + * | `dst` | string | Address of the recipient of the tokens | + * | `wad` | BigNumber | Amount that was transferred | + */ + transferFrom(from: string, to: string, value: BigNumberish) { + return this.colonyNetwork.createTxCreator( + this.tokenClient, + 'transferFrom', + [from, to, value], + async (receipt) => ({ + ...extractEvent('Transfer', receipt), + }), + ); + } + /** * Approve `amount` of the wallet owners holdings of the specified token *