Add admin.utils to verify protocol payments and ERC-20 transfers - #42
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this does
Adds
admin.utils, so the backend can check what a mined transaction actually paid, and whether it's final, before issuing an eSIM. Nothing is signed or sent. Prices come back asbigintcents, the same format the contracts use (123456nis $1234.56).verifyProtocolPayment(tx, symbol, eSIMWallet): for protocol purchases. It returns each purchase'spaymentReference, price in cents, amount and vault, taken from the contracts' own events. It handles several purchases in one transaction. The symbol is passed as text ("USDC").verifyERC20Transfer(tx, token, sender, destination): for any ERC-20. It adds up direct transfers from sender to destination and returns the raw amount and cents (1 token counted as $1).Finality
A mined block on Base can still be reorged out, so both functions also return
finality,blockNumberandblockHash:latest: mined, but can still be revertedsafe: its batch is posted to L1 (about 1 min on mainnet)finalized: can't be reverted (about 19 min on mainnet)Issue eSIMs only on
finalized. Store the block hash and check again later if it's not final yet. A receipt passed in from a block that was reorged out throwsReceiptNotCanonicalError.Details
txcan be a hash or a receipt. Pass the hash when it came from a user.kokio-sdk/admin.Tests
latestchanging tofinalized, and a real reorg.Also
docs/admin/utils.md