Nanoswap: trustless on-chain sales of metatokens

Expanding upon my idea for matched donations, I have created a generalized method for sales of metatokens (objects that can be transferred and tracked on the network e.g. an encoded NFT link) completely on-chain with zero trust needed. To begin, let me define some terms.

Offer: metatoken(s) being sold
Payment: NANO or other metatoken(s) being used to purchase the offer
A: account making the offer
B: account making the payment
Multisig: multi-signature account derived from accounts A and B
Abort/bail: trigger refund procedure or otherwise invalidate (e.g. change the agreed upon send block, create new unexpected frontier before send, etc) the swap

All multisig blocks will be created ahead of time, signed and stored off-chain by the owners of both A and B so either of them can publish the automated procedures. All multisig blocks are orphans until the conditions are met. The conditions should not be published until all multisig blocks are created and verified to be accurate.


(Edit: to clarify, this isn't an order of actions as much as it is an order of blocks. ALL multisig blocks need to be created and signed before A1 and B1 start the chain of events. The arrows merely indicate block prerequisites)
Successful swap: A1 -> M1, B1 -> M2+ -> M3+ -> M4+
Aborted swap: A1, M1, M2-
If B sends even though swap has been aborted, we continue: B1, M3- -> M4-

Both parties are capable of exiting the transaction and recovering funds without any way of scamming the other party up until multisig receives B payment. At that point, the swap is inevitable.

This procedure shows that NANO is capable of supporting tokens and NFTs, possibly much more.

Here is proof of concept of the swap. The 0.066812N transactions are identifiers for a Binance Smartchain NFT and the 1N transactions are the payment. All transactions were made with multisignature presigned blocks through an RPC, and the abort blocks were implemented but never executed.

Edit: this is far from fully scrutinized, and I have no idea how bulletproof it really is. Please let me know if you notice any vulnerabilities that it might have.

Edit 2: Currently there's a major issue of a fork. If A1, B1, and M1 are all confirmed, M2+ and M2- can be called simultaneously to create a fork. Solution at the moment is to just let the network figure out what it thinks should happen.

13 Likes

For those curious, here are the multisig blocks:

receive nft hash DE662A567BD131F4905E0DE99B4B7552F079368FD266C78C3F93DA754F5A44D2

{
"action": "process",
"json_block": "true",
"subtype": "open",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "0000000000000000000000000000000000000000000000000000000000000000",
"representative": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"balance": "66812000000000000000000000000",
"link": "EB8A61F31431EED46A064FECDDD7830C24812027F2453BC9E39A0D68845AFC98",
"link_as_account": "nano_3twce9sjaehgtjo1emzeuqdr8536i6i4hwk79h6y98iff447oz6rjfggb9h1",
"work": "17f75f33362ce01b",
"signature": ""
}
}

change rep hash 1BA394D387E2BA93FE796A4FDE6B4B353AF0342E7521EB3471F4592180432CB4

{
"action": "process",
"json_block": "true",
"subtype": "change",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "DE662A567BD131F4905E0DE99B4B7552F079368FD266C78C3F93DA754F5A44D2",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "66812000000000000000000000000",
"link": "0000000000000000000000000000000000000000000000000000000000000000",
"link_as_account": "nano_1111111111111111111111111111111111111111111111111111hifc8npp",
"work": "5127bf380e706a53",
"signature": ""
}
}

bail send FB6DE82BE28811F15126B87A1D67CAAB279095B2D21C145B6207CF2AB4E5F1FE

{
"action": "process",
"json_block": "true",
"subtype": "send",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "1BA394D387E2BA93FE796A4FDE6B4B353AF0342E7521EB3471F4592180432CB4",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "0",
"link": "9BD3C9B092C3531FDD647578C3241BFB247C4C74B56869F0840B7A5C48BFC7BE",
"link_as_account": "nano_38yms8rb7itm5zgpaxdrrek3qys6hj89bfdaf9raa4utdj6dzjxy5onfuttu",
"work": "793df7c208a55c62",
"signature": ""
}
}

post bail receive 554E2D8C1256137AB1D570FB2A8345FD884C5FAF263A36855C8777E6C601B3DE

{
"action": "process",
"json_block": "true",
"subtype": "receive",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "FB6DE82BE28811F15126B87A1D67CAAB279095B2D21C145B6207CF2AB4E5F1FE",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "1000000000000000000000000000000",
"link": "A260003BBEA753FFB8251DC7964114036465FC294FF3B7B331F8CC305C3381B9",
"link_as_account": "nano_3am111xuxbtmzyw4c9g9ks1ja1u6eqy4kmzmpysm5y8e83g591fsmet4u3uf",
"work": "8fc758420e30c9fb",
"signature": ""
}
}

post bail send

142CC2B224F573EA920A722EA0FA25EACB9B183ECF86A9A4E63C4A344D0D6F36

{
"action": "process",
"json_block": "true",
"subtype": "send",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "554E2D8C1256137AB1D570FB2A8345FD884C5FAF263A36855C8777E6C601B3DE",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "0",
"link": "457D6109B25603BEAF0D947E2D9871837B816EC788BF4436E8B33D6F6A840482",
"link_as_account": "nano_1jdxe66u6oi5qtqiu75y7pe951uui7qeh47zaiugjesxfxoaa364nt6p65fb",
"work": "4a5fb9e58c219457",
"signature": ""
}
}

prebail receive 31D87C92061AC5774E31C19F756E41FE768B644B740F5FA2DFA0CD27A409D878

{
"action": "process",
"json_block": "true",
"subtype": "receive",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "1BA394D387E2BA93FE796A4FDE6B4B353AF0342E7521EB3471F4592180432CB4",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "1066812000000000000000000000000",
"link": "A260003BBEA753FFB8251DC7964114036465FC294FF3B7B331F8CC305C3381B9",
"link_as_account": "nano_3am111xuxbtmzyw4c9g9ks1ja1u6eqy4kmzmpysm5y8e83g591fsmet4u3uf",
"work": "4de39623c3c47a1f",
"signature": ""
}
}

send nft
60360E86594DA3E60E28ED0B34EE1A26E3548B409A6B585C3A7343CD75BF0F50

{
"action": "process",
"json_block": "true",
"subtype": "send",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "31D87C92061AC5774E31C19F756E41FE768B644B740F5FA2DFA0CD27A409D878",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "1000000000000000000000000000000",
"link": "457D6109B25603BEAF0D947E2D9871837B816EC788BF4436E8B33D6F6A840482",
"link_as_account": "nano_1jdxe66u6oi5qtqiu75y7pe951uui7qeh47zaiugjesxfxoaa364nt6p65fb",
"work": "77dcf13b7100619b",
"signature": ""
}
}

send payment 6CCFCA47AA9365D304B99052990DD5EFE934398E2B8BAE8B1D0D5D9FCCF7C045

{
"action": "process",
"json_block": "true",
"subtype": "send",
"block": {
"type": "state",
"account": "nano_1u7xkacbwcbmrg8j73gg13f3ehixzgxqcx4fokqzugfriwweb887fwyzg5x9",
"previous": "60360E86594DA3E60E28ED0B34EE1A26E3548B409A6B585C3A7343CD75BF0F50",
"representative": "xrb_3qm87bd9qnbjyka7w5hbmf7qcnqih6uaznm8ry85z6ytgo9onj8k6hhdxzpo",
"balance": "0",
"link": "9BD3C9B092C3531FDD647578C3241BFB247C4C74B56869F0840B7A5C48BFC7BE",
"link_as_account": "nano_38yms8rb7itm5zgpaxdrrek3qys6hj89bfdaf9raa4utdj6dzjxy5onfuttu",
"work": "5dc526bb0381c46a",
"signature": ""
}
}

2 Likes