tupui / soroban-versioning

Tansu - Soroban Versioning
https://tansu.dev
Other
4 stars 3 forks source link

Soroban Domains and metadata #73

Open tupui opened 1 month ago

tupui commented 1 month ago

We are discussing with Soroban Domains (Enrique) to add link metadata to a domain. See this discussion:

https://discord.com/channels/897514728459468821/1213642853339766805/1293795340515934230

Hi there! I just pushed this: https://github.com/Creit-Tech/sorobandomains-sc/commit/ac335564b000a463359e5d76b2c05f1e9581b041

It's a new contract that works with the Registry contract and it has this interface:
pub trait KeyValueDBTrait {
    fn set_config(
        e: Env,
        adm: Address,
        registry: Address,
        fee: u128,
        currency: Address,
        treasury: Address,
    );
    fn upgrade(e: Env, hash: BytesN<32>);

    fn set(e: Env, node: BytesN<32>, key: Symbol, value: Value);
    fn get(e: Env, node: BytesN<32>, key: Symbol) -> Option<Value>;
    fn remove(e: Env, node: BytesN<32>, key: Symbol);
}

It follows the similar interface LocalStorage has in Javascript which basically allows you to set, get and remove a value from the storage. When setting a new value, the contract will fetch and request authorization from the domain owner (also when removing a key), as a protection it also checks the snapshot value of the domain when getting the value, this way it prevents contracts getting a value from a domain that recently changed its owner.

I haven't tested it yet, basically I just deployed it to testnet and add one value. By being a key-value storage, basically every project can define their own Keys but it will be good if we come with some pre-defined keys to use 
The testnet contract is: CDS6WQMDH6RTPFFWLPK3TPVBIH5TNMKUCNPXHZTDV2YYVHXPIAQEUXAX and you can see one example of the data saved here: https://stellar.expert/explorer/testnet/contract/CDS6WQMDH6RTPFFWLPK3TPVBIH5TNMKUCNPXHZTDV2YYVHXPIAQEUXAX/storage
let me know what you think
tupui commented 1 month ago

I could call Enrique's associated contract:

import base64
import soroban

contract_id = "CDS6WQMDH6RTPFFWLPK3TPVBIH5TNMKUCNPXHZTDV2YYVHXPIAQEUXAX"
seed_phrase = "..."

identity = soroban.Identity(seed_phrase=seed_phrase)

node = "IyTcSfr4OtAQzuAhGLgkRWbj+QZelKJpSo9X43f3J1w="
node = base64.b64decode(node)

args = [
    {"name": "node", "type": "bytes", "value": node},
    {"name": "key", "type": "symbol", "value": "Tansu"},
    {"name": "value", "type": "vec", "value": [
        {
            "type": "symbol",
            "value": "Bytes"
        },
        {
            "type": "bytes",
            "value": b"68efd0ae3ef8900a1d3ad53838aba85892b6e478"
        },
    ]},
]
args = soroban.Parameters(args=args)

soroban.invoke(
    contract_id=contract_id,
    function_name="set",
    args=args,
    source_account=identity,
)
tupui commented 4 weeks ago

There is some news

I have deployed the Key-Value contract to mainnet: https://stellar.expert/explorer/public/contract/CDH2T2CBGFPFNVRWFK4XJIRP6VOWSVTSDCRBCJ2TEIO22GADQP6RG3Y6

The contract follows the same logic from the one on testnet with the only difference that: the fee is paid in PSD instead of XLM.

Btw I also added the stellar.expert deployment flow so the contract code is shown on stellar.expert
 https://stellar.expert/explorer/public/contract/CDH2T2CBGFPFNVRWFK4XJIRP6VOWSVTSDCRBCJ2TEIO22GADQP6RG3Y6

I would like to propose a few keys as a standard:
## SEP-1 TOML file url
TOML = Value::String(TOML_URL)

## Optional, could help in verifying the content hasn't been tempered
TOML_HASH = Value::Bytes(TOML_SHA256_HASH)

## Projects like xlm.sh could use this key, that way they don't need to look for the CID elsewhere
WEBSITE_IPFS = Value::Bytes(IPFS_CID)