-
Notifications
You must be signed in to change notification settings - Fork 24
Added paymaster functions #213
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
Open
BogBogdan
wants to merge
10
commits into
OriginTrail:v8/kcs-integration
Choose a base branch
from
BogBogdan:kcs-integration-paymaster
base: v8/kcs-integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed75229
added paymaster functions
BogBogdan ca34321
paymaster-manager.js added
BogBogdan cdf0a1e
Fixed code ready for review
BogBogdan 8868bb3
Ran prettier on changed files and fixes
BogBogdan c41efbd
changes in deployPaymasterContract
BogBogdan b392907
added demo-paymaster
BogBogdan a0b84ea
new push
BogBogdan 935b638
new commit
BogBogdan 35f1327
new changes
BogBogdan b0e47c8
c
BogBogdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,112 @@ | ||
|
|
||
| export default class PaymasterOperationsManager { | ||
|
|
||
| constructor(services) { | ||
| this.blockchainService = services.blockchainService; | ||
| this.inputService = services.inputService; | ||
| this.validationService = services.validationService; | ||
| } | ||
|
|
||
| /** | ||
| * @async | ||
| * @param {BigInt} tokenAmount - The amount of tokens (Wei) to set the allowance. | ||
| * @param {Object} [options={}] - Additional options for increasing allowance - currently only blockchain option expected. | ||
| * @param {string} recipient - The address of the recipient (used for operations like withdrawal or funding). | ||
| * @returns {Object} Object containing hash of blockchain transaction and status. | ||
| */ | ||
|
|
||
| async deployPaymasterContract(options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
BogBogdan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| if(this.validationService.validateBlockchain(blockchain)) | ||
| { | ||
| const paymasterAddress = await this.blockchainService.deployPaymasterContract(blockchain); | ||
|
|
||
| return paymasterAddress; | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error deploying Paymaster contract:", error); | ||
| } | ||
| } | ||
|
|
||
| async addAllowedAddress(addresToBeWhitelested, options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
|
|
||
| if(this.validationService.validatePaymasterAdress(blockchain, addresToBeWhitelested)) | ||
BogBogdan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| await this.blockchainService.addAllowedAddress(blockchain, addresToBeWhitelested); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error adding allowed address:", error); | ||
| } | ||
| } | ||
|
|
||
| async removeAllowedAddress(addresToBeWhitelested, options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
|
|
||
|
|
||
| if(this.validationService.validatePaymasterAdress(blockchain, addresToBeWhitelested)) | ||
| { | ||
| await this.blockchainService.removeAllowedAddress(blockchain, addresToBeWhitelested); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error removing allowed address:", error); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| async fundPaymaster(tokenAmount, options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
|
|
||
| if(this.validationService.validatePaymasterToken(blockchain,tokenAmount)) | ||
| { | ||
| await this.blockchainService.fund(blockchain, tokenAmount); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error funding paymaster:", error); | ||
| } | ||
| } | ||
|
|
||
| async withdraw(recipient, tokenAmount, options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
|
|
||
| if(this.validationService.validatePaymasterTokenAdress(blockchain, tokenAmount, recipient)) | ||
| { | ||
| await this.blockchainService.withdraw(blockchain, recipient, tokenAmount); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error withdrawing:", error); | ||
| } | ||
| } | ||
|
|
||
| async coverCost(tokenAmount, options) { | ||
| try { | ||
|
|
||
| const blockchain = this.inputService.getBlockchain(options); | ||
|
|
||
| if(this.validationService.validatePaymasterToken(blockchain, tokenAmount)) | ||
| { | ||
| await this.blockchainService.coverCost(blockchain, tokenAmount); | ||
| } | ||
|
|
||
| } catch (error) { | ||
| console.error("Error covering cost:", error); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.