Smart Ordinals

Smart Ordinals

Turning stateless 1SatOrdinals into stateful smart contracts to leverage the benefits of stateful contracts, while keeping the statelessness simplicity of 1SatOrdinals tokens

The problem Smart Ordinals solves

The maing goal of this project is to show the potential of turning a staless UTXO script into a stateful one to lavarage the benefits of stateful UTXO scripts, while keeping the simplicity of the stateless ones.

To demonstrate the potential of this technique, we aim to solve the problem of executing on-chain token exchanges without the involvement of third parties.

Starting with 1SatOrdinals token, our solution allows the current token owner to encapulate his token into a stateful UTXO script that is an on-chain order lock with three possibilities:

1 - The order can be executed by any on-chain user that knows the order TXID;
2 - The order can be executed by a single on-chain user indicated at the creation of the order lock;
3 - The order can be cancelled by the owner of the token before it is bought by any other user;

Upon the execution of any of the three possibilities, the stateful script is turned again into a stateless 1SatOrdinals token assigned to the new ower in case of order execution, or to its former owner in case of order cancelation.

In cases 1 and 2, the payment for the token in satoshis goes directly to the former owner, while the 1SatOrdinals ownership goes to the user that first run the contract.

The technique allows for true peer-to-peer on-chain exchange between users without the need of third party exchages to perform the job.

Besides that, our solution also allows the user to create its own 1SatOrdinals or use the ones it has control over it with the following features:

1 - Create New 1SatOrdinals Tokens;
2 - Reshape (change content or re-inscribe) any 1SatOrdinals Token the user has control over it;
3 - Directly transfer the token ownership to another user;
4 - Melt the token, that is to undo the 1SatOrdinals token using its UTXO and unbounding its satoshi for any other user;

Our solution don´t make use of indexers, but can be easily integrated if necessary.

Challenges we ran into

For the project to work the way it does, we had to make some small modification on some sCrypt files:

These change were made so that we could easily perform some different operations and also to solve some issues that we got:

The new operations: a) to switch between compressed and uncompressed public key formats: privateKey.compAdd(compState); b) to tap the DER SIG of a transaction input: tx2.DERSEC()

Files with changes:

..\node_modules\bsv\index.d.ts
..\node_modules\bsv\lib\privatekey.js
..\node_modules\bsv\lib\transaction\transaction.js

To avoid execution stopping due to fee rate limits we modified file abstract-provider.js, lines 55 and 58 so that it would not throw exception anymore:

..\node_modules\scrypt-ts\dist\bsv\abstract-provider.js

To avoid paying high fee we changed all getFeePerKb() to 1 sat on all privider files:

..\node_modules\scrypt-ts\dist\providers\gorillapool-provider.js
..\node_modules\scrypt-ts\dist\providers\taal-provider.js
..\node_modules\scrypt-ts\dist\providers\whatsonchain-provider.js

These modifications forces us to use an custom version of the folders ..\node_modules\bsv and ..\node_modules\script-ts and therefore we make these two folders available in our main branch so that the user can change the content of

..\node_modules\bsv by the content of the folder ..\maoonchain\bsv
..\node_modules\scrypt-ts by the content of the folder ..\maoonchain\scrypt-ts

***Detailed instructions on how to setup the project:

git clone https://github.com/carlosamcruz/maoonchain cd maoonchain npm install

Delete Folders:

..\maoonchain\node_modules\bsv
..\maoonchain\node_modules\scrypt-ts

Copy custom folders:

..\maoonchain\bsv
..\maoonchain\scrypt-ts

Paste the two folder above inside node_modules:

..\maoonchain\node_modules

Finally compile the contract and start it

npx scrypt-cli@latest compile npm start

Discussion