Skip to content

Commit

Permalink
added staking module type to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbolog committed Sep 19, 2023
1 parent 6c7c6d2 commit 9d9bbdb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion scripts/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"address": {
"DEVNET": "erd1qqqqqqqqqqqqqpgqmzt9ntca4ffuf9j7rff5xx3pcfepasc36ppsv65tg4"
"DEVNET": "erd1qqqqqqqqqqqqqpgqcgpuw44vrursrwsudzlx3k8w2r55nxdl6ppsuxm0z3"
},
"deploymentArgs": {
"gasLimit": 85000000,
Expand Down
62 changes: 47 additions & 15 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -176,6 +188,7 @@ const handleConfigureScore = async (row) => {
if (fullSetBonusScore !== undefined) {
let fullSetScoreResult = await sendSetFullSetBonusScoreTx(
tokenIdentifier,
stakingModuleType,
fullSetBonusScore
);
status = status && fullSetScoreResult;
Expand All @@ -185,6 +198,7 @@ const handleConfigureScore = async (row) => {
process.stdout.write(
getPoolRowMessage(
tokenIdentifier,
stakingModuleType,
nonces,
nonceRangeStart,
nonceRangeEnd,
Expand All @@ -195,27 +209,36 @@ 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);

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)
)
Expand All @@ -226,6 +249,7 @@ const sendSetNonceAssetScoreTx = async (tokenIdentifier, nonces, score) => {

const sendSetNonceAssetScoreByRangeTx = async (
tokenIdentifier,
stakingModuleType,
nonceRangeStart,
nonceRangeEnd,
score
Expand All @@ -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),
Expand All @@ -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);
Expand All @@ -260,6 +288,7 @@ const sendSetFullSetBonusScoreTx = async (tokenIdentifier, score) => {

const getPoolRowMessage = (
tokenIdentifier,
stakingModuleType,
nonces,
nonceRangeStart,
nonceRangeEnd,
Expand All @@ -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(", "));
Expand Down
30 changes: 15 additions & 15 deletions scripts/nft-staking-subsidiary-init.csv
Original file line number Diff line number Diff line change
@@ -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,
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,
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 6 additions & 2 deletions src/owner.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 3 additions & 2 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d9bbdb

Please sign in to comment.