Add reimbursement amount calculation, proposal code and tests
This commit is contained in:
parent
b6a52cf88d
commit
633981e687
@ -18,7 +18,6 @@
|
||||
git clone --recurse-submodules <proposal-repo-link>
|
||||
cd <proposal-name>
|
||||
npm install
|
||||
npm run init
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
1
data/amountInTorn.txt
Normal file
1
data/amountInTorn.txt
Normal file
@ -0,0 +1 @@
|
||||
uint256 public constant reimbursementAmount = 6226 ether;
|
1
lib/forge-std
Submodule
1
lib/forge-std
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 2f112697506eab12d433a65fdc31a639548fe365
|
@ -8,6 +8,7 @@
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"init": "cd lib && git clone --recurse-submodules https://github.com/foundry-rs/forge-std",
|
||||
"calculate": "ts-node --esm scripts/calculateReimbursement.ts",
|
||||
"test:windows": ".\\.env.bat && forge test",
|
||||
"test:linux": ". .env && forge test",
|
||||
"test:gas:windows": ".\\.env.bat && forge test --gas-report",
|
||||
@ -16,7 +17,8 @@
|
||||
"dependencies": {
|
||||
"@ensdomains/ens-contracts": "^0.0.21",
|
||||
"@openzeppelin/contracts": "^4.9.0",
|
||||
"@openzeppelin/upgrades-core": "^1.26.2"
|
||||
"@openzeppelin/upgrades-core": "^1.26.2",
|
||||
"node-fetch": "^3.3.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@gnosis.pm/ido-contracts": "^0.5.0",
|
||||
|
17
scripts/calculateReimbursement.ts
Normal file
17
scripts/calculateReimbursement.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
const rpcMonthlyPrice = 1000;
|
||||
const servicesMonthlyPrice = 600;
|
||||
const amountInUsd = (rpcMonthlyPrice + servicesMonthlyPrice) * 12;
|
||||
|
||||
const binanceApiLink = "https://api.binance.com/api/v3/ticker?symbol=TORNBUSD&windowSize=7d";
|
||||
const res = await fetch(binanceApiLink);
|
||||
const { weightedAvgPrice } = (await res.json()) as { weightedAvgPrice: string };
|
||||
|
||||
const amountInTorn = Math.floor((amountInUsd + (amountInUsd * 20) / 100) / Number(weightedAvgPrice));
|
||||
|
||||
fs.writeFileSync(path.join(".", "data", "amountInTorn.txt"), `uint256 public constant reimbursementAmount = ${amountInTorn} ether;`, {
|
||||
flag: "w+",
|
||||
});
|
@ -1,34 +0,0 @@
|
||||
type NodeVarObject = { [key: string]: string };
|
||||
type NodeVarArray = [string, string];
|
||||
|
||||
const solidityCodePadding = " ".repeat(8);
|
||||
const pad = (decl: string, padding: string = solidityCodePadding) => padding + decl + "\n";
|
||||
|
||||
class DeclCalculator {
|
||||
public constructor(
|
||||
private declType: string,
|
||||
private padding: string = solidityCodePadding,
|
||||
private transformator: Function = (
|
||||
() => (x: any) =>
|
||||
x
|
||||
)(),
|
||||
private variableNameChanger: Function = (
|
||||
() => (x: any) =>
|
||||
x
|
||||
)()
|
||||
) {}
|
||||
|
||||
private displayVariableName(varObj: NodeVarObject) {
|
||||
return Object.keys(varObj)[0];
|
||||
}
|
||||
|
||||
public calculateDecl = (varInfo: NodeVarObject | NodeVarArray, type: string = "bytes32") => {
|
||||
const solidityVariableName = this.variableNameChanger(Array.isArray(varInfo) ? varInfo[0] : this.displayVariableName(varInfo));
|
||||
const solidityVariableValue = this.transformator(Array.isArray(varInfo) ? varInfo[1] : Object.values(varInfo)[0]);
|
||||
const solidityDeclaration = `${this.declType || type} ${solidityVariableName} = ${solidityVariableValue};`;
|
||||
|
||||
return pad(solidityDeclaration, this.padding);
|
||||
};
|
||||
}
|
||||
|
||||
export { DeclCalculator };
|
@ -1,11 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { IGovernance } from "@interfaces/IGovernance.sol";
|
||||
|
||||
contract ExampleProposal {
|
||||
function executeProposal() public {
|
||||
/* ... */
|
||||
}
|
||||
}
|
15
src/ReimbursementProposal.sol
Normal file
15
src/ReimbursementProposal.sol
Normal file
@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
contract ReimbursementProposal {
|
||||
address public constant developerAddress = 0x9Ff3C1Bea9ffB56a78824FE29f457F066257DD58;
|
||||
IERC20 public constant TORN = IERC20(0x77777FeDdddFfC19Ff86DB637967013e6C6A116C);
|
||||
uint256 public constant reimbursementAmount = 6226 ether; // check scripts/calculateReimbursement.ts
|
||||
|
||||
function executeProposal() public {
|
||||
TORN.transfer(developerAddress, reimbursementAmount);
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
interface IGnosisSafe {
|
||||
enum Operation {
|
||||
Call,
|
||||
DelegateCall
|
||||
}
|
||||
|
||||
function NAME() external view returns (string memory);
|
||||
|
||||
function VERSION() external view returns (string memory);
|
||||
|
||||
function nonce() external view returns (uint256);
|
||||
|
||||
function domainSeparator() external view returns (bytes32);
|
||||
|
||||
function signedMessages(bytes32) external view returns (uint256);
|
||||
|
||||
function approvedHashes(address, bytes32) external view returns (uint256);
|
||||
|
||||
function setup(
|
||||
address[] calldata _owners,
|
||||
uint256 _threshold,
|
||||
address to,
|
||||
bytes calldata data,
|
||||
address fallbackHandler,
|
||||
address paymentToken,
|
||||
uint256 payment,
|
||||
address payable paymentReceiver
|
||||
) external;
|
||||
|
||||
function execTransaction(
|
||||
address to,
|
||||
uint256 value,
|
||||
bytes calldata data,
|
||||
Operation operation,
|
||||
uint256 safeTxGas,
|
||||
uint256 baseGas,
|
||||
uint256 gasPrice,
|
||||
address gasToken,
|
||||
address payable refundReceiver,
|
||||
bytes calldata signatures
|
||||
) external returns (bool success);
|
||||
|
||||
function requiredTxGas(address to, uint256 value, bytes calldata data, Operation operation)
|
||||
external
|
||||
returns (uint256);
|
||||
|
||||
function approveHash(bytes32 hashToApprove) external;
|
||||
|
||||
function signMessage(bytes calldata _data) external;
|
||||
|
||||
function isValidSignature(bytes calldata _data, bytes calldata _signature) external returns (bytes4);
|
||||
|
||||
function getMessageHash(bytes memory message) external view returns (bytes32);
|
||||
|
||||
function encodeTransactionData(
|
||||
address to,
|
||||
uint256 value,
|
||||
bytes memory data,
|
||||
Operation operation,
|
||||
uint256 safeTxGas,
|
||||
uint256 baseGas,
|
||||
uint256 gasPrice,
|
||||
address gasToken,
|
||||
address refundReceiver,
|
||||
uint256 _nonce
|
||||
) external view returns (bytes memory);
|
||||
|
||||
function getTransactionHash(
|
||||
address to,
|
||||
uint256 value,
|
||||
bytes memory data,
|
||||
Operation operation,
|
||||
uint256 safeTxGas,
|
||||
uint256 baseGas,
|
||||
uint256 gasPrice,
|
||||
address gasToken,
|
||||
address refundReceiver,
|
||||
uint256 _nonce
|
||||
) external view returns (bytes32);
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
enum ProposalState {
|
||||
Pending,
|
||||
Active,
|
||||
Defeated,
|
||||
Timelocked,
|
||||
AwaitingExecution,
|
||||
Executed,
|
||||
Expired
|
||||
}
|
||||
|
||||
struct Proposal {
|
||||
// Creator of the proposal
|
||||
address proposer;
|
||||
// target addresses for the call to be made
|
||||
address target;
|
||||
// The block at which voting begins
|
||||
uint256 startTime;
|
||||
// The block at which voting ends: votes must be cast prior to this block
|
||||
uint256 endTime;
|
||||
// Current number of votes in favor of this proposal
|
||||
uint256 forVotes;
|
||||
// Current number of votes in opposition to this proposal
|
||||
uint256 againstVotes;
|
||||
// Flag marking whether the proposal has been executed
|
||||
bool executed;
|
||||
// Flag marking whether the proposal voting time has been extended
|
||||
// Voting time can be extended once, if the proposal outcome has changed during CLOSING_PERIOD
|
||||
bool extended;
|
||||
}
|
||||
|
||||
interface IGovernance {
|
||||
function initialized() external view returns (bool);
|
||||
function initializing() external view returns (bool);
|
||||
function EXECUTION_DELAY() external view returns (uint256);
|
||||
function EXECUTION_EXPIRATION() external view returns (uint256);
|
||||
function QUORUM_VOTES() external view returns (uint256);
|
||||
function PROPOSAL_THRESHOLD() external view returns (uint256);
|
||||
function VOTING_DELAY() external view returns (uint256);
|
||||
function VOTING_PERIOD() external view returns (uint256);
|
||||
function CLOSING_PERIOD() external view returns (uint256);
|
||||
function VOTE_EXTEND_TIME() external view returns (uint256);
|
||||
function torn() external view returns (address);
|
||||
function proposals(uint256 index) external view returns (Proposal memory);
|
||||
function proposalCount() external view returns (uint256);
|
||||
function lockedBalance(address account) external view returns (uint256);
|
||||
function propose(address target, string memory description) external returns (uint256);
|
||||
function castVote(uint256 proposalId, bool support) external;
|
||||
function lock(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;
|
||||
function lockWithApproval(uint256 amount) external;
|
||||
function unlock(uint256 amount) external;
|
||||
function execute(uint256 proposalId) external payable;
|
||||
function state(uint256 proposalId) external view returns (ProposalState);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { ProposalUtils } from "./utils/ProposalUtils.sol";
|
||||
import { ExampleProposal } from "@root/ExampleProposal.sol";
|
||||
|
||||
import { console2 } from "@forge-std/console2.sol";
|
||||
|
||||
contract TestExampleProposal is ProposalUtils {
|
||||
modifier executeCurrentProposalBefore() {
|
||||
createAndExecuteProposal();
|
||||
_;
|
||||
}
|
||||
|
||||
function createAndExecuteProposal() public {
|
||||
address proposalAddress = address(new ExampleProposal()); /* your proposal initialization */
|
||||
|
||||
proposeAndExecute(proposalAddress);
|
||||
}
|
||||
|
||||
/* your tests */
|
||||
|
||||
function testProposal() public executeCurrentProposalBefore { }
|
||||
}
|
32
test/ReimbursementProposal.t.sol
Normal file
32
test/ReimbursementProposal.t.sol
Normal file
@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { ProposalUtils } from "./utils/ProposalUtils.sol";
|
||||
import { ReimbursementProposal } from "@root/ReimbursementProposal.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
import { console2 } from "@forge-std/console2.sol";
|
||||
|
||||
contract TestReimbursementProposal is ProposalUtils {
|
||||
address public constant developerAddress = 0x9Ff3C1Bea9ffB56a78824FE29f457F066257DD58;
|
||||
|
||||
function createAndExecuteProposal() public {
|
||||
address proposalAddress = address(new ReimbursementProposal());
|
||||
|
||||
proposeAndExecute(proposalAddress);
|
||||
}
|
||||
|
||||
function testFundsTransferred() public {
|
||||
IERC20 TORN = IERC20(tornTokenAddress);
|
||||
|
||||
uint256 amountBeforeProposalExecution = TORN.balanceOf(developerAddress);
|
||||
console2.log("Balance before execution: %s", amountBeforeProposalExecution / 1e18);
|
||||
|
||||
createAndExecuteProposal();
|
||||
|
||||
uint256 amountAfterProposalExecution = TORN.balanceOf(developerAddress);
|
||||
console2.log("Balance after execution: %s", amountAfterProposalExecution / 1e18);
|
||||
|
||||
require(amountAfterProposalExecution - amountBeforeProposalExecution == 6226 * 1e18);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user