Introducing SeaMonk - a payment gateway for smart-contracts, converting simple ADA transactions to smartcontract transactions

Thought this may be something others can find useful in allowing users to interact with them and their smartcontract(s) with simple ADA transactions…sort of a payment gateway for smart contracts, removing the need for special transactions by users.

Here’s the code: SeaMonk

My art partner and I started CypherMonks about a month ago in Cardano after I discovered this awesome community and when we came to Cardano with this project we made a commitment to handling all our own sales involving smart contracts in some way, and keeping everything on-site and in-house. For our first sale I found some nifty Python code by logicalmechanism on github and made some modifications to the python and the haskell, but the challenge was I now had a Python application I would need to send to the buyer to do the finalization.

After this I was going to do a token giveaway just for fun and for our early/first members to our community, and wanted a way to do this automatically, with a whitelist, and involve a smartcontract for token distribution. So I used a few functions from the original Python, adapted it, and developed a new application which acts as a sort of “payment gateway” between the user and the SmartContract…allowing for simple ADA transactions that meet some criteria to trigger a smartcontract exchange.

It’s a fairly straight-forward, here are the features:

  • Watch for an expected transaction amount and/or address combo…or any/all transactions…and perform the correct smart-contract transaction based on criteria and meeting the SC’s validator criteria.
  • Whitelist sender addresses with one-time or unlimited option set (either whitelisted sender is removed after a first transaction is done or they can make unlimited tx’s to the SeaMonk watched address)
  • Whole-wallet-whitelisting, if 1 address from Daedalus or Yoroi for example is whitelisted, all address for that user will be whitelisted, they don’t have to fund the whitelisted address specifically for the matching to work
  • Both an “expect” amount and a “price” amount can be set in settings and can be different amounts. This is useful when doing a single NFT sale, selling tokens for a specific price, or just if you’re using a simple smartcontract which would allow the entire token sum to be drained if someone just saw how to meet the simple validator requirements. For example, in our JUDE token giveaway we have for our early members, we are using a very simple SmartContract that just holds the tokens and if a transaction is in the tx-out with a specific amount and to a specific address, it allows any amount of JUDE to be taken. SeaMonk is performing our more complex requirements, but what if someone just directly does a transaction to our smartcontract? We setup the SC to require that a tx-out be sent to our watched/owned address in a larger amount of ADA then most people would want to spend on a new token in the amount of tokens we locked up. In other words, to take all the JUDE from the SC, someone would have to pay us. We then simply “pay ourselves” via SeaMonk by setting a price that’s higher then the expected amount for the giveaway…the participants just send 1.5 ADA to get JUDE + their ADA and fee returned to them (1.7 ADA is returned in each exchange), and another tx is made from our own watched wallet to our own watched wallet to go along with the SC transaction, meeting the validator requirements of amount of ADA to our address in order to spend any amount of JUDE. This also allows for reuse of a smartcontract for various unrelated exchanges, since you can set various dynamic things like whitelisting, against a statically/hard-coded smartcontract.
  • A return-ada amount can be set, to determine how much ADA to return to a user who does an exchange (example: if you want to cover their fee, SeaMonk can send them the token(s) from the smartcontract along with this specific amount of ADA, rather then just 1.4444 or something)
  • Token change is returned to the smartcontract for another transaction: So if you are doing a token exchange like a giveaway and have 4000 tokens to distribute in 290 per sender, SeaMonk takes care of this automatically based on the setting for Token Quantity. If just an NFT this would be 1 of course and no change, but if you were doing 4000 tokens in small chuncks you’d set the chunk amount, like 290, and change is returned to the SC in each smartcontract tx.
  • Minimal API activity - To perform the required lookups SeaMonk uses Blockfrost api, however it only uses it as necessary and as limited as possible. Meaning you will only ping the API 1 time per transaction hash, cutting down on your daily usage.
  • Testnet or Mainnet are easily used for testing etc.
  • Set collateral in your initial config to your liking
  • Adaptable for any smartcontract. I’ll be adding some features in the settings soon for setting Redeemer parameters, etc. so it’s more adaptable out of the box…for now some simple Python coding can get you there :slight_smile:

So in summary, it watches an address you own and have created on a live node, for a combination of criteria you put in the settings…or for all transactions of any amount, depending on how you configure it. The main options right now are: watch for an amount only; watch for an amount and a sending address; watch for a sending address only; watch for everything.

SeaMonk can be run continually in the background to do this matching/action functionality and also has two other main options for running: Deposit and Get Transactions…but first you configure on first run it will prompt and creates a profile.json file with your settings which you can reconfigure. Then you run it with the deposit option, which allows you to deposit your token(s) into the smartcontract ready for action. The get_transactions option tells SeaMonk to run in a very simple function I created which gets the incoming transactions to your watched wallet and records them. So in practice you would run two instances of SeaMonk: the get_transaction and the main app.

Anyway, just wanted to share it here if anyone is interested in a sort of “bridge the gap” application for utilizing smartcontracts without any special tools or transactions by users, just simple amount/sender-wallet criteria. And for the curios, the smart contract in mind when I developed this is an adaptation also from the afore-mentioned logicalmechanism, which just validates against an ADA amount sent to a specific address being present in the tx-outs. Here’s the source for that: simple swap smartcontract

2 Likes

Cool! Very useful features. Thanks for sharing this and for posting the detailed information.

1 Like

Glad to! And thank you for all your helpful answers throught the forum, you’ve been a big help in my learning curve!

Wow nice work @artistulla! I especially like the Whole-wallet-whitelisting functionality. I think most people using a wallet are not aware of their utxo distribution and just would send the desired ada from scattered addresses. I will further dive into the code on a later point.

1 Like

Hey thanks! the ‘sandbox’ branch is where I’m doing the most recent work now, adding profile capability for having multiple saved profiles…and have added auto-smartcontract-generation to the current state of the sandbox branch. This will generate a smartcontract on-the-fly according to the watched address hash and price, coding those into the SC for validation, so SeaMonk can be used as a total solution to create, deposit into, and automanage a simple swap smartcontract.

1 Like