bancorprotocol / contracts_eos

Bancor Protocol Contracts for EOS
Other
113 stars 45 forks source link

Bancor table schema migration #64

Closed DenisCarriere closed 4 years ago

DenisCarriere commented 4 years ago

Converters

No significant changes, simply added scoped data to main scope get_self()

Will be used right away in new migration upgrade

Reserves

Removal of scopes requires the currency symbol code as scope and map objects for ratios & balances.

before

TABLE reserve_t {
    name contract;
    uint64_t ratio;
    asset balance;

    uint64_t primary_key() const { return balance.symbol.code().raw(); }
};

after

TABLE reserve_v2_t {
    symbol currency;
    map<symbol_code, uint64_t> ratios;
    map<symbol_code, extended_asset> balances;

    uint64_t primary_key() const { return currency.code().raw(); }
};

How to migrate

Once code is deployed, migrate action must be called on all the currently active converters, this will update the converters table to use the main scope and reserves.v2 table will be populated using reserves legacy table structure.

cleos push action bancorcnvrtr migrate '[["BNTEOS"]]' -p myaccount

image

TO-DO

DenisCarriere commented 4 years ago

@yudilevi modified table structure for converter_v2

Have a review, I've added two new flexible fields:

TABLE converter_v2_t {
    /**
     * @brief symbol of the smart token -- representing a share in the reserves of this converter
     * @details PRIMARY KEY for this table is `currency.code().raw()`
     */
    symbol currency;

    /**
     * @brief creator of the converter
     */
    name owner;

    /**
     * @brief conversion fee for this converter, applied on every hop
     */
    uint64_t fee;

    /**
     * @brief reserve weights relative to the other reserves
     * @example
     * {
     *   "key: "BNT",
     *   "value": 500000
     * }
     */
    map<symbol_code, uint64_t> reserve_weights;

    /**
     * @brief balances in each reserve
     * @example
     * {
     *   "key: "BNT",
     *   "value": "10000.0000 BNT"
     * }
     */
    map<symbol_code, extended_asset> reserve_balances;

    /**
     * @brief [optional] protocol features for converter
     * @example
     * {
     *   "key: "stake",
     *   "value": true
     * }
     */
    map<name, bool> protocol_features;

    /**
     * @brief [optional] additional metadata for converter
     * @example
     * {
     *   "key: "website",
     *   "value": "https://mywebsite.com"
     * }
     */
    map<name, string> metadata_json;
}
DenisCarriere commented 4 years ago

@yudilevi Added activate ACTION as a general purpose protocol_feature activation.

This replaces actions such as enablestake.

activate( const symbol_code currency, const name protocol_feature, const bool enabled )

cleos

$ cleos push action bancorcnvrtr activate '["BNTEOS", "stake", false]' -p myowner

Which will add a boolean values to the converters.protocol_features

[ { "key": "stake", "value": 1 } ]
DenisCarriere commented 4 years ago

Script to fetch scopes from bancorcnvrtr::converters

const { createDfuseClient } = require("@dfuse/client")
const { name, symbol_code } = require("eos-common");

global.fetch = require("node-fetch")
global.WebSocket = require("ws")

const client = createDfuseClient({ apiKey: process.env.DFUSE_API_KEY, network: "mainnet" })

async function main() {
    const results = await client.stateTableScopes("bancorcnvrtr", "converters");

    for ( const scope of results.scopes ) {
        const symcode = symbol_code( name(scope).value ).to_string();
        console.log(symcode);
    }
    client.release()
}

main();

Output

BNTVG
BNTET
BNTBOD
BNTUSD
BNTINF
BNTCHL
BNTAPP
BNTPXS
TCNBNT
BOSBNT
EOSBNT
TPTBNT
MEVBNT
BNTMPT
BNTSOV
BNTAPX
TESTAAA
BNTEDNA
TCNUSDB
BNTTRYB
BNTSEED
BNTPIXE
TESTING
BNTEIDO
BNTATMO
BNTGOVR
BNTSENS
BNTPEOS
BNTUSDT
BNTMEET
EOSABNT
PBTCBNT
AZZIBNT
GOVRBNT
SENSBNT
FASTBNT
EOSTBNT
UVUVBNT
KROWBNT
WIZZBNT
BNTCHEX