-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab8f73f
commit b0e9889
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* # Handle multisig payments | ||
* | ||
* ## Pay with a multisig | ||
* Imports | ||
*/ | ||
|
||
import { Contract, ContractTransaction, Signer } from 'ethers'; | ||
|
||
// TODO export this from @requestnetwork/payment-processor | ||
import { | ||
encodeApproveErc20, | ||
encodePayErc20Request, | ||
} from '@requestnetwork/payment-processor/dist/payment/erc20-proxy'; | ||
import { getRequestPaymentValues } from '@requestnetwork/payment-processor/dist/payment/utils'; | ||
import { ClientTypes } from '@requestnetwork/types'; | ||
|
||
/** | ||
* [Gnosis multisig](https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol) partial abi | ||
*/ | ||
const multisigAbi = [ | ||
'function submitTransaction(address _destination, uint _value, bytes _data) returns (uint)', | ||
]; | ||
|
||
/** | ||
* ### Pay ETH request | ||
*/ | ||
export const payEthWithMultisig = async ( | ||
request: ClientTypes.IRequestData, | ||
multisigAddress: string, | ||
signer: Signer, | ||
): Promise<ContractTransaction> => { | ||
const multisigContract = new Contract(multisigAddress, multisigAbi, signer); | ||
|
||
const { paymentAddress, paymentReference } = getRequestPaymentValues(request); | ||
return multisigContract.submitTransaction(paymentAddress, 0, paymentReference); | ||
}; | ||
|
||
/** | ||
* ### Approve ERC20 spending | ||
*/ | ||
export const approveErc20WithMultisig = async ( | ||
request: ClientTypes.IRequestData, | ||
multisigAddress: string, | ||
signer: Signer, | ||
): Promise<ContractTransaction> => { | ||
const multisigContract = new Contract(multisigAddress, multisigAbi, signer); | ||
const tokenAddress = request.currencyInfo.value; | ||
|
||
return multisigContract.submitTransaction(tokenAddress, 0, encodeApproveErc20(request, signer)); | ||
}; | ||
/** | ||
* ### Pay ERC20 request | ||
*/ | ||
export const payErc20WithMultisig = async ( | ||
request: ClientTypes.IRequestData, | ||
multisigAddress: string, | ||
signer: Signer, | ||
): Promise<ContractTransaction> => { | ||
const multisigContract = new Contract(multisigAddress, multisigAbi, signer); | ||
const tokenAddress = request.currencyInfo.value; | ||
|
||
return multisigContract.submitTransaction( | ||
tokenAddress, | ||
0, | ||
encodePayErc20Request(request, signer), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters