Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: option to allow mint to specific address with mintFor #1910

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions raiden-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
### Fixed

### Added
- [#1910] Add option to `mint` tokens for any address

### Changed
- [#1905] Fail early if not enough tokens to deposit

[#1905]: https://github.com/raiden-network/light-client/issues/1905
[#1910]: https://github.com/raiden-network/light-client/pull/1910

## [0.10.0] - 2020-07-13
### Fixed
Expand Down
19 changes: 14 additions & 5 deletions raiden-ts/src/raiden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ export class Raiden {
* Throws an error, if
* <ol>
* <li>Executed on main net</li>
* <li>`token` is not a valid address</li>
* <li>`token` or `options.to` is not a valid address</li>
* <li>Token could not be minted</li>
* </ol>
*
Expand All @@ -1029,12 +1029,13 @@ export class Raiden {
* Notice the beneficiary here is always the account that sends the transaction, as this is
* expectedly also the account that will pay for e.g. future deposits.
* Set this to true if one wants to force sending the transaction with the subkey
* @param options.to - Beneficiary, defaults to mainAddress or address
* @returns transaction
*/
public async mint(
token: string,
amount: BigNumberish,
{ subkey }: { subkey?: boolean } = {},
{ subkey, to }: { subkey?: boolean; to?: string } = {},
): Promise<Hash> {
// Check whether address is valid
assert(Address.is(token), [ErrorCodes.DTA_INVALID_ADDRESS, { token }], this.log.info);
Expand All @@ -1043,14 +1044,22 @@ export class Raiden {
// Check whether we are on a test network
assert(this.deps.network.chainId !== 1, ErrorCodes.RDN_MINT_MAINNET, this.log.info);

const { signer } = chooseOnchainAccount(this.deps, subkey ?? this.config.subkey);
const { signer, address } = chooseOnchainAccount(this.deps, subkey ?? this.config.subkey);
// Mint token
const customTokenContract = CustomTokenFactory.connect(token, signer);

const beneficiary = to ?? address;
assert(
Address.is(beneficiary),
[ErrorCodes.DTA_INVALID_ADDRESS, { beneficiary }],
this.log.info,
);

const value = decode(UInt(32), amount, ErrorCodes.DTA_INVALID_AMOUNT);
const receipt = await callAndWaitMined(
customTokenContract,
'mint',
[decode(UInt(32), amount)],
'mintFor',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm the docs say that the token contract can either define mint(address, uint256), mintFor(uint256, address) or increaseSupply(uint256, address). The last seem to be not relevant. But from the first two: what is the difference in behavior except the signature? Is there definition exclusive? Should we maybe check for both? Or is mintFor the only one that does what we want now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support all these interfaces. If you look into the source of the CustomToken contract, you'll see it supports just 2 minting methods: mint(uint256), which mints for self, and mintFor(uint256, address), which allows minting for a 3rd party. This is a _testing function, used only on our testnets, and these are always deployed with this contract. It'd be hard for the SDK to support multiple contracts interfaces, so we went with what is actually used.

[value, beneficiary],
ErrorCodes.RDN_MINT_FAILED,
{ log: this.log },
);
Expand Down
4 changes: 3 additions & 1 deletion raiden-ts/tests/e2e/raiden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,9 @@ describe('Raiden', () => {

test('should return transaction if minted successfully', async () => {
expect.assertions(1);
await expect(raiden.mint(token, 50)).resolves.toMatch(/^0x[0-9a-fA-F]{64}$/);
await expect(raiden.mint(token, 50, { to: raiden.address })).resolves.toMatch(
/^0x[0-9a-fA-F]{64}$/,
);
});
});

Expand Down