From 9d9bbdb2adcd9da3afe3da9f46d957273f7110c0 Mon Sep 17 00:00:00 2001 From: alexbolog Date: Tue, 19 Sep 2023 15:50:45 +0300 Subject: [PATCH] added staking module type to scripts --- scripts/config.json | 2 +- scripts/index.js | 62 +++++++++++++++++++------ scripts/nft-staking-subsidiary-init.csv | 30 ++++++------ src/constants.rs | 1 + src/owner.rs | 8 +++- wasm/src/lib.rs | 5 +- 6 files changed, 73 insertions(+), 35 deletions(-) diff --git a/scripts/config.json b/scripts/config.json index a179cf1..a864c56 100644 --- a/scripts/config.json +++ b/scripts/config.json @@ -1,6 +1,6 @@ { "address": { - "DEVNET": "erd1qqqqqqqqqqqqqpgqmzt9ntca4ffuf9j7rff5xx3pcfepasc36ppsv65tg4" + "DEVNET": "erd1qqqqqqqqqqqqqpgqcgpuw44vrursrwsudzlx3k8w2r55nxdl6ppsuxm0z3" }, "deploymentArgs": { "gasLimit": 85000000, diff --git a/scripts/index.js b/scripts/index.js index d1648b6..99f4d9e 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -103,7 +103,7 @@ const handleRegisterNewStakingPool = async (tokenIdentifier, moduleType) => { let tx = contract.methodsExplicit .createPool([ new TokenIdentifierValue(tokenIdentifier), - new U8Value(moduleType), + new U8Value(parseInt(moduleType) + 1), ]) .withChainID("D") .withGasLimit(15_000_000); @@ -135,15 +135,17 @@ const handleConfigureScore = async (row) => { let columns = row.split(","); let tokenIdentifier = columns[0]; - let nonces = columns[1].length === 0 ? [] : columns[1].split(";"); - let nonceRangeStart = columns[2] === "" ? undefined : columns[2]; - let nonceRangeEnd = columns[3] === "" ? undefined : columns[3]; - let score = columns[4]; - let fullSetBonusScore = columns[5] === "" ? undefined : columns[5]; + let stakingModuleType = columns[1] === "" ? 1 : parseInt(columns[1]); + let nonces = columns[2].length === 0 ? [] : columns[2].split(";"); + let nonceRangeStart = columns[3] === "" ? undefined : columns[3]; + let nonceRangeEnd = columns[4] === "" ? undefined : columns[4]; + let score = columns[5]; + let fullSetBonusScore = columns[6] === "" ? undefined : columns[6]; process.stdout.write( getPoolRowMessage( tokenIdentifier, + stakingModuleType, nonces, nonceRangeStart, nonceRangeEnd, @@ -159,14 +161,24 @@ const handleConfigureScore = async (row) => { nonceRangeStart === undefined && nonceRangeEnd === undefined ) { - status = await sendSetBaseAssetScoreTx(tokenIdentifier, score); + status = await sendSetBaseAssetScoreTx( + tokenIdentifier, + stakingModuleType, + score + ); } if (nonces.length > 0) { - status = await sendSetNonceAssetScoreTx(tokenIdentifier, nonces, score); + status = await sendSetNonceAssetScoreTx( + tokenIdentifier, + stakingModuleType, + nonces, + score + ); } if (nonceRangeStart !== undefined && nonceRangeEnd !== undefined) { status = await sendSetNonceAssetScoreByRangeTx( tokenIdentifier, + stakingModuleType, nonceRangeStart, nonceRangeEnd, score @@ -176,6 +188,7 @@ const handleConfigureScore = async (row) => { if (fullSetBonusScore !== undefined) { let fullSetScoreResult = await sendSetFullSetBonusScoreTx( tokenIdentifier, + stakingModuleType, fullSetBonusScore ); status = status && fullSetScoreResult; @@ -185,6 +198,7 @@ const handleConfigureScore = async (row) => { process.stdout.write( getPoolRowMessage( tokenIdentifier, + stakingModuleType, nonces, nonceRangeStart, nonceRangeEnd, @@ -195,12 +209,16 @@ const handleConfigureScore = async (row) => { ); }; -const sendSetBaseAssetScoreTx = async (tokenIdentifier, score) => { +const sendSetBaseAssetScoreTx = async ( + tokenIdentifier, + stakingModuleType, + score +) => { let contract = await getSmartContract(); let tx = contract.methodsExplicit .setBaseAssetScore([ new TokenIdentifierValue(tokenIdentifier), - new U32Value(1), + new U32Value(stakingModuleType), new U32Value(score), ]) .withGasLimit(15_000_000); @@ -208,14 +226,19 @@ const sendSetBaseAssetScoreTx = async (tokenIdentifier, score) => { return await signAndSendTx(tx); }; -const sendSetNonceAssetScoreTx = async (tokenIdentifier, nonces, score) => { +const sendSetNonceAssetScoreTx = async ( + tokenIdentifier, + stakingModuleType, + nonces, + score +) => { let contract = await getSmartContract(); let noncesArg = nonces.map((nonce) => new U64Value(nonce)); let tx = contract.methodsExplicit .setNonceAssetScore( [ new TokenIdentifierValue(tokenIdentifier), - new U8Value(1), + new U8Value(stakingModuleType), new U32Value(score), ].concat(noncesArg) ) @@ -226,6 +249,7 @@ const sendSetNonceAssetScoreTx = async (tokenIdentifier, nonces, score) => { const sendSetNonceAssetScoreByRangeTx = async ( tokenIdentifier, + stakingModuleType, nonceRangeStart, nonceRangeEnd, score @@ -235,7 +259,7 @@ const sendSetNonceAssetScoreByRangeTx = async ( let tx = contract.methodsExplicit .setNonceAssetScoreByRange([ new TokenIdentifierValue(tokenIdentifier), - new U8Value(1), + new U8Value(stakingModuleType), new U32Value(score), new U64Value(nonceRangeStart), new U64Value(nonceRangeEnd), @@ -245,12 +269,16 @@ const sendSetNonceAssetScoreByRangeTx = async ( return await signAndSendTx(tx); }; -const sendSetFullSetBonusScoreTx = async (tokenIdentifier, score) => { +const sendSetFullSetBonusScoreTx = async ( + tokenIdentifier, + stakingModuleType, + score +) => { let contract = await getSmartContract(); let tx = contract.methodsExplicit .setFullSetScore([ new TokenIdentifierValue(tokenIdentifier), - new U8Value(1), + new U8Value(stakingModuleType), new U32Value(score), ]) .withGasLimit(15_000_000); @@ -260,6 +288,7 @@ const sendSetFullSetBonusScoreTx = async (tokenIdentifier, score) => { const getPoolRowMessage = ( tokenIdentifier, + stakingModuleType, nonces, nonceRangeStart, nonceRangeEnd, @@ -269,6 +298,9 @@ const getPoolRowMessage = ( ) => { let statusMessage = chalk.white("Setting up "); statusMessage += chalk.yellow(tokenIdentifier); + statusMessage += chalk.white(", module type "); + statusMessage += chalk.yellow(stakingModuleType); + if (nonces.length > 0) { statusMessage += chalk.white(" for "); statusMessage += chalk.yellow(nonces.join(", ")); diff --git a/scripts/nft-staking-subsidiary-init.csv b/scripts/nft-staking-subsidiary-init.csv index 1e951a5..a05f54d 100644 --- a/scripts/nft-staking-subsidiary-init.csv +++ b/scripts/nft-staking-subsidiary-init.csv @@ -1,15 +1,15 @@ -Token Identifier,Nonces,NonceRangeStart,NonceRangeEnd,Base Score,Full set bonus score, -DHCD-bc9963,,,,5,25, -VESTAXDAO-e6c48c,,,,1, -VESTAXDAO-e6c48c,2,,,2, -VESTAXDAO-e6c48c,1,,,4, -BLOODSHED-a62781,,,,1, -BLOODSHED-a62781,,555,1157,3, -BLOODSHED-a62781,,153,554,4, -BLOODSHED-a62781,,1,152,11, -NOSFERATU-2b0485,,,,2, -NOSFERATU-2b0485,,301,700,4, -NOSFERATU-2b0485,,101,300,8, -NOSFERATU-2b0485,,1,100,16, -DHXBUNNIES-862129,,,,2, -DHXBUNNIES-862129,388; 407; 25; 880; 274; 873; 1095; 175; 954; 1033,,,160, \ No newline at end of file +Token Identifier,TargetStakingModuleType,Nonces,NonceRangeStart,NonceRangeEnd,Base Score,Full set bonus score, +DHCD-bc9963,1,,,,5,25, +VESTAXDAO-e6c48c,1,,,,1, +VESTAXDAO-e6c48c,1,2,,,2, +VESTAXDAO-e6c48c,1,1,,,4, +BLOODSHED-a62781,1,,,,1, +BLOODSHED-a62781,1,,555,1157,3, +BLOODSHED-a62781,1,,153,554,4, +BLOODSHED-a62781,1,,1,152,11, +NOSFERATU-2b0485,1,,,,2, +NOSFERATU-2b0485,1,,301,700,4, +NOSFERATU-2b0485,1,,101,300,8, +NOSFERATU-2b0485,1,,1,100,16, +DHXBUNNIES-862129,1,,,,2, +DHXBUNNIES-862129,1,388; 407; 25; 880; 274; 873; 1095; 175; 954; 1033,,,160, \ No newline at end of file diff --git a/src/constants.rs b/src/constants.rs index d2a28fa..3e43753 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -11,3 +11,4 @@ pub const ERR_REWARD_ALREADY_DISTRIBUTED: &str = "Reward already distributed"; pub const ERR_INVALID_REWARD_TOKEN_ID: &str = "Invalid reward token id"; pub const ERR_COLLECTION_ALREADY_REGISTERED: &str = "Collection already registered"; pub const ERR_INVALID_STAKED_TOKEN_ID: &str = "Invalid token identifier"; +pub const ERR_CANNOT_REGISTER_AS_ALL: &str = "Cannot register as Module Type::All"; diff --git a/src/owner.rs b/src/owner.rs index 83947f5..21e8ef2 100644 --- a/src/owner.rs +++ b/src/owner.rs @@ -1,7 +1,7 @@ use crate::{ constants::{ - DEB_DENOMINATION, ERR_COLLECTION_ALREADY_REGISTERED, ERR_INVALID_REWARD_TOKEN_ID, - ERR_REWARD_ALREADY_DISTRIBUTED, + DEB_DENOMINATION, ERR_CANNOT_REGISTER_AS_ALL, ERR_COLLECTION_ALREADY_REGISTERED, + ERR_INVALID_REWARD_TOKEN_ID, ERR_REWARD_ALREADY_DISTRIBUTED, }, staking_modules::staking_module_type::StakingModuleType, utils::secure_rewards, @@ -172,6 +172,10 @@ pub trait OwnerModule: collection_token_identifier: TokenIdentifier, staking_module_type: StakingModuleType, ) { + require!( + &staking_module_type != &StakingModuleType::All, + ERR_CANNOT_REGISTER_AS_ALL + ); require!( self.stake_pool_type_configuration(&collection_token_identifier) .is_empty(), diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 83663f4..d23d946 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 34 +// Endpoints: 35 // Async Callback (empty): 1 -// Total number of exported functions: 36 +// Total number of exported functions: 37 #![no_std] @@ -51,6 +51,7 @@ multiversx_sc_wasm_adapter::endpoints! { distributeCompanyShareReward => distribute_company_share_reward updateDeb => update_deb createPool => register_new_staking_pool + overridePoolType => override_stake_pool_type setBaseAssetScore => set_base_asset_score setNonceAssetScore => set_nonce_asset_score setNonceAssetScoreByRange => set_nonce_asset_score_by_range