Skip to content

Commit

Permalink
scripts progress
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbolog committed Sep 19, 2023
1 parent c2b7a9b commit 6c7c6d2
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 79 deletions.
84 changes: 23 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,67 +230,29 @@ Upgrades an existing instance of the contract using the same procedure explained

### Commit Pools Data

Will look in the `config.json` for uncomitted pools. Once a pool has been setup, it will be market as committed and ignored for further updates. If a pool must be updated, remove the "isCommitted" property and run the script again.

#### Pool Settings that must be provided:

- `name`: Ignored by the script, useful for keeping track of which pool does what
- `collectionTokenIdentifier`: The NFT/SFT collection token identifier of the pool
- `stakingModuleType`: One of the following values
- CodingDivisionSfts
- XBunnies
- Bloodshed
- Nosferatu
- VestaXDAO
- SnakesSfts
- `scoreConfiguration`: the scores based on which the reward is being distributed. Example of configuration:

```json
{
...
"scoreConfiguration": {
"All": {
"base": 10,
"granular": []
},
"XBunnies": {
"base": 5,
"granular": [
{
"nonces": [10, 11, 12],
"score": 10
},
{
"nonces": [210, 211, 212],
"score": 15
},
{
"nonces": [310, 311, 312, 313],
"score": 20
},
]
}
}
...
}
```
Creating or updating a pool happens using a .CSV configuration file.
All the data that needs to be set for a pool must be formatted accordingly and saved in a .CSV file. Once prompted, specify the full path of the file and let the script do it's magic.

The script doesn't check if the CSV data is already committed to the blockchain. Every line of the CSV will be executed as a transaction - **do not include data that is already been set unless you wish to spend more gas.**

Possible columns:

- token identifier
- nonce filters:
- Nonces: semi-column separated - 11;23;409;1223;etc
- Nonce range: start and end nonces, inclusive values, one per column
- score
- full set bonus score

#### Reward tokens

Each reward token must be registered as a pool reward if it's going to be distributed to a specific pool.
These tokens can be set under `"poolSettings[ENVIRONMENT][rewardTokens]"` as key-value pairs. Example:

```json
{
...
"rewardTokens": [
{
"tokenIdentifier": "REWARDTKN-123456",
"stakingModuleType": "XBunnies"
}
]
...
}
**.CSV header**

This is the parsing order and must be respected in order for the script to work properly. In case a nonce column does not apply, leave it empty.

> [!NOTE]
> You can both include/exclude the headers, the script will ask you for confirmation before executing.

```
Token Identifier;Nonces;Nonce Range Start;Nonce Range End;Score;Full Set Score
```
The same `"isCommitted"` logic is applied here as well.
You can check the scripts folder for a .CSV example used when initializing the subsidiaries.
27 changes: 21 additions & 6 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const loadNetworkConfig = () => {
const networkCfg = loadNetworkConfig();

const getPemAndAccount = async () => {
console.log(`Loading pem and account for ${process.env.ENVIRONMENT}...`);
console.log(`PEM Path: ${networkCfg.pem}`);
const apiProvider = new ApiNetworkProvider(networkCfg.api);
const pemContent = await loadPemContent(networkCfg.pem);
const account = await loadUserAccount(apiProvider, pemContent);
Expand Down Expand Up @@ -81,7 +79,7 @@ const getSmartContract = async () => {
});
};

const signAndSend = async (tx, walletPemContents) => {
const signAndSendExplicit = async (tx, walletPemContents) => {
const provider = getProxyProvider();
const signer = prepareUserSigner(walletPemContents);
const serializedTransaction = tx.serializeForSigning();
Expand Down Expand Up @@ -132,7 +130,7 @@ const deploy = async () => {
transaction.setNonce(account.getNonceThenIncrement());

console.log(`Deploying contract on ${process.env.ENVIRONMENT}...`);
const txResult = await signAndSend(transaction, pem);
const txResult = await signAndSendExplicit(transaction, pem);
const deployedAddress = deploymentTransactionResultHandler(txResult);

if (deployedAddress !== "") {
Expand Down Expand Up @@ -168,7 +166,7 @@ const upgrade = async () => {
transaction.setNonce(account.getNonceThenIncrement());

console.log(`Upgrading contract on ${process.env.ENVIRONMENT}...`);
const txResult = await signAndSend(transaction, pem);
const txResult = await signAndSendExplicit(transaction, pem);
const deployedAddress = deploymentTransactionResultHandler(txResult);

if (deployedAddress !== "") {
Expand Down Expand Up @@ -204,12 +202,29 @@ const buildDeployArgs = () => {
return args;
};

const signAndSendTx = async (txInteraction) => {
let { pem, account } = await getPemAndAccount();
let tx = txInteraction
.withChainID(networkCfg.chain)
.withSender(account.address)
.buildTransaction();

tx.setNonce(account.getNonceThenIncrement());
let txResult = await signAndSendExplicit(tx, pem);

return (
!txResult.status.isFailed() &&
!txResult.status.isInvalid() &&
!txResult.status.isPending()
);
};

module.exports = {
loadNetworkConfig,
getPemAndAccount,
getSmartContract,
resultsParser: Parser,
signAndSend,
signAndSendTx,
getProxyProvider,

deploy,
Expand Down
25 changes: 20 additions & 5 deletions scripts/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"address": {
"DEVNET": "erd1qqqqqqqqqqqqqpgq7z49p3gkskpl0f8x45scaly22pqnww2z6ppsm54eug"
"DEVNET": "erd1qqqqqqqqqqqqqpgqmzt9ntca4ffuf9j7rff5xx3pcfepasc36ppsv65tg4"
},
"deploymentArgs": {
"gasLimit": 85000000,
Expand Down Expand Up @@ -38,11 +38,15 @@
"SharesSfts": {
"granular": [
{
"nonces": [1],
"nonces": [
1
],
"score": 500
},
{
"nonces": [2],
"nonces": [
2
],
"score": 1
}
]
Expand Down Expand Up @@ -105,7 +109,18 @@
"base": 2,
"granular": [
{
"nonces": [388, 407, 25, 880, 274, 873, 1095, 175, 954, 1033],
"nonces": [
388,
407,
25,
880,
274,
873,
1095,
175,
954,
1033
],
"score": 160
}
]
Expand All @@ -117,4 +132,4 @@
},
"MAINNET": []
}
}
}
Loading

0 comments on commit 6c7c6d2

Please sign in to comment.