Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contracts: fix 'r' bonding curve parameter to match specification #241

Merged
merged 15 commits into from Aug 28, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -14,7 +14,7 @@ contract KosuToken is ERC20, Authorizable {
string public symbol = "KOSU";
uint8 public decimals = 18;
uint private _weiPaid = 0;
uint32 constant private r = 850000; // ppm
uint32 constant private r = 290000; // ppm

/** @dev Initializes KosuToken with the authorizedAddresses shared permission contract to protect functions.
@notice Initializes KosuToken with the authorizedAddresses shared permission contract to protect functions.
@@ -22,14 +22,16 @@
"lint": "tslint -p .",
"truffle:clean": "shx rm -rf build/contracts",
"contracts:clean": "shx rm -rf generated-artifacts generated-wrappers",
"deliver:kosu:zaidan": "ts-node --files src/bin/deliver_tokens.ts --test-mnemonic --rpc-url=https://ethnet.zaidan.io/kosu",
"deliver:kosu:ci": "ts-node --files src/bin/deliver_tokens.ts --test-mnemonic --rpc-url=${WEB3_URI}",
"deploy:ropsten": "ts-node -T src/bin/migrate.ts --rpc-url=https://eth-ropsten.alchemyapi.io/jsonrpc/KUnSgCMXUSlgavPAznIBDCKhPhpgk8XA",
"deploy:kosu": "ts-node -T src/bin/migrate.ts --test-mnemonic --rpc-url=https://ethnet.zaidan.io/kosu && ts-node --files src/bin/deliver_tokens.ts --test-mnemonic --rpc-url=https://ethnet.zaidan.io/kosu && yarn prettier:deployedAddresses",
"deploy:kosu:ci": "ts-node -T src/bin/migrate.ts --test-mnemonic --rpc-url=${WEB3_URI} && ts-node --files src/bin/deliver_tokens.ts --test-mnemonic --rpc-url=${WEB3_URI} && yarn prettier:deployedAddresses",
"deploy:0x:kosu": "0x-migrate --rpc-url https://ethnet.zaidan.io/kosu --from 0x5409ED021D9299bf6814279A6A1411A7e866A631",
"deploy:0x:kosu:ci": "0x-migrate --rpc-url ${WEB3_URI} --from 0x5409ed021d9299bf6814279a6a1411a7e866a631",
"deploy:kosu:zaidan": "ts-node -T src/bin/migrate.ts --test-mnemonic --rpc-url=https://ethnet.zaidan.io/kosu && yarn prettier:deployedAddresses",
"deploy:kosu:ci": "ts-node -T src/bin/migrate.ts --test-mnemonic --rpc-url=${WEB3_URI} && yarn prettier:deployedAddresses",
"deploy:0x:zaidan": "0x-migrate --rpc-url https://ethnet.zaidan.io/kosu --from 0x5409ED021D9299bf6814279A6A1411A7e866A631",
"deploy:0x:ci": "0x-migrate --rpc-url ${WEB3_URI} --from 0x5409ed021d9299bf6814279a6a1411a7e866a631",
"migrate:ropsten": "run-s deploy:ropsten generate:readme",
"migrate:zaidan": "run-s deploy:kosu deploy:0x:kosu generate:readme",
"migrate:ci": "run-s deploy:kosu:ci deploy:0x:kosu:ci",
"migrate:zaidan": "run-s deploy:kosu:zaidan deploy:0x:zaidan generate:readme deliver:kosu:zaidan",
"migrate:ci": "run-s deploy:kosu:ci deploy:0x:ci deliver:kosu:ci",
"prettier:deployedAddresses": "prettier --write src/deployedAddresses.json --config ../../.prettierrc",
"ganache_rpc": "docker run --rm -p 8545:8545 ${npm_package_config_kosu_ganache_image}",
"ganache_rpc:detached": "docker run --rm -d -p 8545:8545 ${npm_package_config_kosu_ganache_image}",
@@ -13,6 +13,7 @@ export const TestValues = {
sixEther: new BigNumber(toWei("6")),
tenEther: new BigNumber(toWei("10")),
oneHundredEther: new BigNumber(toWei("100")),
fourHundredEther: new BigNumber(toWei("400")),
fiveHundredEther: new BigNumber(toWei("500")),
maxUint: new BigNumber(2).pow(new BigNumber(256)).minus(new BigNumber(1)),
};
@@ -59,6 +59,7 @@ before(async () => {
const ganacheSubprovider = new GanacheSubprovider({
mnemonic: process.env.npm_package_config_test_mnemonic,
network_id: 6175,
default_balance_ether: TestValues.fiveHundredEther.multipliedBy(10),
});
provider.addProvider(ganacheSubprovider);
}
@@ -95,7 +96,7 @@ before(async () => {
JSON.stringify(argumentsJson),
);
contracts.kosuToken.bondTokens.awaitTransactionSuccessAsync(TestValues.zero, {
value: TestValues.oneEther.times(85),
value: TestValues.oneEther.times(200),
});
if (!useGeth) {
web3.eth.personal.importRawKey(
@@ -4,7 +4,7 @@ import { fromWei } from "web3-utils";
import { artifacts, KosuTokenContract } from "..";

describe("KosuToken", () => {
let token, from;
let token, from, kosuToken;

before(async () => {
token = await KosuTokenContract.deployFrom0xArtifactAsync(
@@ -14,9 +14,16 @@ describe("KosuToken", () => {
"0x0000000000000000000000000000000000000000",
);
from = accounts[0];
kosuToken = contracts.kosuToken;
});

describe("bonding", () => {
describe("parameterization", () => {
it("should fail with incorrect initial deposit", async () => {
await web3Wrapper
.sendTransactionAsync({ to: token.address, value: TestValues.twoEther, from })
.then(txHash => web3Wrapper.awaitTransactionSuccessAsync(txHash)).should.eventually.be.rejected;
});

it("should have expected initial output with parameterization", async () => {
await web3Wrapper
.sendTransactionAsync({ to: token.address, value: TestValues.twoEther.div("10"), from })
@@ -40,20 +47,40 @@ describe("KosuToken", () => {
.should.eq(endingEther.toString());
});

it("should have expected tokens balance at given ether balance", async () => {
await web3Wrapper
.sendTransactionAsync({
to: token.address,
value: TestValues.fourHundredEther.minus(await web3Wrapper.getBalanceInWeiAsync(token.address)),
from,
})
.then(txHash => web3Wrapper.awaitTransactionSuccessAsync(txHash));

const finalBalance = await token.balanceOf.callAsync(from);
const finalSupply = await token.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);

"90635575928012811022820".should.eq(finalBalance.toString());
"90635575928012811022820".should.eq(finalSupply.toString());
TestValues.fourHundredEther.toString().should.eq(endingEther.toString());
});
});

describe("bonding", () => {
describe("fallback", () => {
it("should generate tokens with fallback function", async () => {
const startingBalance = await token.balanceOf.callAsync(from);
const startingSupply = await token.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const estimate = await token.estimateEtherToToken.callAsync(TestValues.oneEther);
const startingBalance = await kosuToken.balanceOf.callAsync(from);
const startingSupply = await kosuToken.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);
const estimate = await kosuToken.estimateEtherToToken.callAsync(TestValues.oneEther);

await web3Wrapper
.sendTransactionAsync({ to: token.address, value: TestValues.oneEther, from })
.sendTransactionAsync({ to: kosuToken.address, value: TestValues.oneEther, from })
.then(txHash => web3Wrapper.awaitTransactionSuccessAsync(txHash));

const finalBalance = await token.balanceOf.callAsync(from);
const finalSupply = await token.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const finalBalance = await kosuToken.balanceOf.callAsync(from);
const finalSupply = await kosuToken.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);

startingBalance
.plus(estimate)
@@ -71,17 +98,19 @@ describe("KosuToken", () => {
});

describe("bondTokens", () => {
it("should generate tokens with fallback function", async () => {
const startingBalance = await token.balanceOf.callAsync(from);
const startingSupply = await token.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const estimate = await token.estimateEtherToToken.callAsync(TestValues.oneEther);
it("should generate tokens with bondTokens", async () => {
const startingBalance = await kosuToken.balanceOf.callAsync(from);
const startingSupply = await kosuToken.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);
const estimate = await kosuToken.estimateEtherToToken.callAsync(TestValues.oneEther);

await token.bondTokens.awaitTransactionSuccessAsync(TestValues.zero, { value: TestValues.oneEther });
await kosuToken.bondTokens.awaitTransactionSuccessAsync(TestValues.zero, {
value: TestValues.oneEther,
});

const finalBalance = await token.balanceOf.callAsync(from);
const finalSupply = await token.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const finalBalance = await kosuToken.balanceOf.callAsync(from);
const finalSupply = await kosuToken.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);

startingBalance
.plus(estimate)
@@ -100,16 +129,16 @@ describe("KosuToken", () => {

describe("releaseTokens", () => {
it("should sell tokens on the curve", async () => {
const startingBalance = await token.balanceOf.callAsync(from);
const startingSupply = await token.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const estimate = await token.estimateTokenToEther.callAsync(TestValues.oneEther);
const startingBalance = await kosuToken.balanceOf.callAsync(from);
const startingSupply = await kosuToken.totalSupply.callAsync();
const startingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);
const estimate = await kosuToken.estimateTokenToEther.callAsync(TestValues.oneEther);

await token.releaseTokens.awaitTransactionSuccessAsync(TestValues.oneEther);
await kosuToken.releaseTokens.awaitTransactionSuccessAsync(TestValues.oneEther);

const finalBalance = await token.balanceOf.callAsync(from);
const finalSupply = await token.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(token.address);
const finalBalance = await kosuToken.balanceOf.callAsync(from);
const finalSupply = await kosuToken.totalSupply.callAsync();
const endingEther = await web3Wrapper.getBalanceInWeiAsync(kosuToken.address);

startingBalance
.minus(TestValues.oneEther)
@@ -126,6 +155,9 @@ describe("KosuToken", () => {
});

it("should empty the contract", async () => {
if ((await token.balanceOf.callAsync(from)).eq("0")) {
throw new Error(".only issue");
}
await token.releaseTokens.awaitTransactionSuccessAsync(await token.balanceOf.callAsync(from));

const finalBalance = await token.balanceOf.callAsync(from);
@@ -1484,7 +1484,7 @@ describe("ValidatorRegistry", async () => {
});

it("should burn up to all the staked balance", async () => {
const burn = new BigNumber(TestValues.oneEther).times(new BigNumber("-1"));
const burn = new BigNumber(TestValues.oneEther).times(new BigNumber("-5"));
const tokenBurnAmount = await kosuToken.estimateEtherToToken.callAsync(burn.multipliedBy("-1"));
await kosuToken.approve.awaitTransactionSuccessAsync(
treasury.address,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.