Skip to content

Commit

Permalink
new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Oct 2, 2022
1 parent 7ac74ed commit 024efb0
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 444 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### [0.5.0](https://github.com/ElrondDevGuild/buildo-begins/releases/tag/v0.5.0) (2022-10-02)
- added `buildo-begins claim-developer-rewards` - Claim dev rewards from your smart contract. You have to use the owner's wallet address (PEM) when calling it
- added `buildo-begins change-owner-address` - You can change the owner address of the smart contract you own
- bump versions for erdjs related dependencies and dev dependencies

### [0.4.0](https://github.com/ElrondDevGuild/buildo-begins/releases/tag/v0.4.0) (2022-08-31)
- added some of the SFT operations (issue, roles, create), more soon
- updated dependencies (erdjs etc.)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Each command will display a set of self-explanatory prompts.
- `buildo-begins derive-pem` - derive PEM file from seed phrase
- `buildo-begins herotag` - create a herotag and assign it to addres and check addresses of existing ones
- `buildo-begins converters` - a set of converters based on excelent [Elrond Converters](http://207.244.241.38/elrond-converters/) but in the CLI, always at hand!
- `buildo-begins claim-developer-rewards` - Claim dev rewards from your smart contract. You have to use the owner's wallet address (PEM) when calling it
- `buildo-begins change-owner-address` - You can change the owner address of the smart contract you own

#### ESDT operations

Expand Down
915 changes: 483 additions & 432 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
},
"type": "module",
"types": "build/types",
"version": "0.4.0",
"version": "0.5.0",
"description": "Elrond blockchain CLI helper tools",
"main": "build/index.js",
"bin": {
"buildo-begins": "./build/index.js"
},
"scripts": {
"generate": "npm run build && node build/index.js",
"build": "rimraf build && node ./esbuild.config.js && tsc",
"dev:lint": "eslint src/** --fix",
"dev:prettier": "prettier --write 'src/**/*.{js,ts,json}'",
Expand All @@ -33,21 +32,21 @@
],
"devDependencies": {
"@types/keccak": "^3.0.1",
"@types/node": "^18.7.14",
"@types/node": "^18.7.23",
"@types/prompts": "^2.0.14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"esbuild": "^0.15.6",
"eslint": "^8.23.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"esbuild": "^0.15.10",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.8.2"
"typescript": "^4.8.4"
},
"dependencies": {
"@elrondnetwork/erdjs": "^11.0.0",
"@elrondnetwork/erdjs-network-providers": "^1.1.0",
"@elrondnetwork/erdjs": "^11.1.0",
"@elrondnetwork/erdjs-network-providers": "^1.1.1",
"@elrondnetwork/erdjs-walletcore": "^2.1.0",
"axios": "^0.27.2",
"bignumber.js": "^9.1.0",
Expand Down
73 changes: 73 additions & 0 deletions src/change-owner-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { areYouSureAnswer, setup, commonTxOperations } from './utils';
import prompts, { PromptObject } from 'prompts';
import { exit } from 'process';
import {
Transaction,
ContractCallPayloadBuilder,
ContractFunction,
Address,
TypedValue,
AddressValue,
} from '@elrondnetwork/erdjs';
import {
chain,
shortChainId,
commonBuiltInOpertationsGasLimit,
} from './config';

export const changeOwnerAddress = async () => {
const promptQuestion: PromptObject[] = [
{
type: 'text',
name: 'smartContractAddress',
message:
'Please provide the smart contract address where the wallet (PEM) you use is an owner.\n',
validate: (value) => (!value ? 'Required!' : true),
},
{
type: 'text',
name: 'newOwnerAddress',
message:
'Please provide the wallet address of the new smart contract owner.\n',
validate: (value) => (!value ? 'Required!' : true),
},
];

try {
const { smartContractAddress, newOwnerAddress } = await prompts(
promptQuestion
);

if (!smartContractAddress || !newOwnerAddress) {
console.log(
"You have to provide the smart contract address and the new owner's address!"
);
exit();
}

await areYouSureAnswer();

const { signer, userAccount, provider } = await setup();

const args: TypedValue[] = [new AddressValue(new Address(newOwnerAddress))];

const data = new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('ChangeOwnerAddress'))
.setArgs(args)
.build();

const tx = new Transaction({
data,
gasLimit: commonBuiltInOpertationsGasLimit,
receiver: new Address(smartContractAddress),
sender: signer.getAddress(),
value: 0,
chainID: shortChainId[chain],
});

await commonTxOperations(tx, userAccount, signer, provider);
} catch (e: any) {
console.log(e.message);
exit();
}
};
57 changes: 57 additions & 0 deletions src/claim-dev-rewards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { areYouSureAnswer, setup, commonTxOperations } from './utils';
import prompts, { PromptObject } from 'prompts';
import { exit } from 'process';
import {
Transaction,
ContractCallPayloadBuilder,
ContractFunction,
Address,
} from '@elrondnetwork/erdjs';
import {
chain,
shortChainId,
commonBuiltInOpertationsGasLimit,
} from './config';

export const claimDeveloperRewards = async () => {
const promptQuestion: PromptObject[] = [
{
type: 'text',
name: 'smartContractAddress',
message:
'Please provide the smart contract address where the wallet (PEM) you use is an owner.\n',
validate: (value) => (!value ? 'Required!' : true),
},
];

try {
const { smartContractAddress } = await prompts(promptQuestion);

if (!smartContractAddress) {
console.log('You have to provide the smart contract address!');
exit();
}

await areYouSureAnswer();

const { signer, userAccount, provider } = await setup();

const data = new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('ClaimDeveloperRewards'))
.build();

const tx = new Transaction({
data,
gasLimit: commonBuiltInOpertationsGasLimit,
receiver: new Address(smartContractAddress),
sender: signer.getAddress(),
value: 0,
chainID: shortChainId[chain],
});

await commonTxOperations(tx, userAccount, signer, provider);
} catch (e: any) {
console.log(e.message);
exit();
}
};
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ export const builtInSC =
// Predefined one time payment for token issuance (EGLD amount)
export const issueTokenPayment = '0.05';

export const commonOpertationsGasLimit = 60000000;
export const specialOpertationsGasLimit = 300000;
export const commonOpertationsGasLimit = 60_000_000;
export const commonBuiltInOpertationsGasLimit = 6_000_000;
export const specialOpertationsGasLimit = 3_000_00;
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import { converters } from './converters';
import { issueSft } from './sft/issue-sft';
import { setSpecialRolesSft } from './sft/set-special-roles-sft';
import { createSft } from './sft/create-sft';
import { claimDeveloperRewards } from './claim-dev-rewards';
import { changeOwnerAddress } from './change-owner-address';

const COMMANDS = {
derivePem: 'derive-pem',
herotag: 'herotag',
converters: 'converters',
claimDevRewards: 'claim-developer-rewards',
changeOwnerAddress: 'change-owner-address',
sendEgld: 'send-egld',
sendEsdt: 'send-esdt',
issueEsdt: 'issue-esdt',
Expand Down Expand Up @@ -120,6 +124,12 @@ switch (command) {
case COMMANDS.createSft:
createSft();
break;
case COMMANDS.claimDevRewards:
claimDeveloperRewards();
break;
case COMMANDS.changeOwnerAddress:
changeOwnerAddress();
break;
default:
break;
}

0 comments on commit 024efb0

Please sign in to comment.