Skip to content

Commit

Permalink
Removed and updated linter (UMAprotocol#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaree authored May 11, 2020
1 parent d9c0c05 commit 114f516
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"singleQuote": false,
"explicitTypes": "always"
}
},
{
"files": "*.md",
"options": {
"semi": false
}
}
]
}
61 changes: 31 additions & 30 deletions documentation/synthetic_tokens/tutorials/creating_from_truffle.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(npm bin)/truffle console --network test
This command should return “undefined”.

```js
const empCreator = await ExpiringMultiPartyCreator.deployed();
const empCreator = await ExpiringMultiPartyCreator.deployed()
```

4. Define the parameters for the synthetic tokens you would like to create.
Expand All @@ -45,36 +45,36 @@ Note that in this example, `priceFeedIdentifier`, `syntheticName`, and `syntheti
<!-- prettier-ignore -->
```js
const constructorParams = { expirationTimestamp: "1585699200", collateralAddress: TestnetERC20.address, priceFeedIdentifier: web3.utils.utf8ToHex("UMATEST"), syntheticName: "Test UMA Token", syntheticSymbol: "UMATEST", collateralRequirement: { rawValue: web3.utils.toWei("1.5") }, disputeBondPct: { rawValue: web3.utils.toWei("0.1") }, sponsorDisputeRewardPct: { rawValue: web3.utils.toWei("0.1") }, disputerDisputeRewardPct: { rawValue: web3.utils.toWei("0.1") }, minSponsorTokens: { rawValue: '100000000000000' }, timerAddress: '0x0000000000000000000000000000000000000000' }
};
}
```

5. Before the contract for the synthetic tokens can be created, the price identifier for the synthetic tokens must be registered with `IdentifierWhitelist`.
This is important to ensure that the UMA DVM can resolve any disputes for these synthetic tokens.

```js
const identifierWhitelist = await IdentifierWhitelist.deployed();
await identifierWhitelist.addSupportedIdentifier(constructorParams.priceFeedIdentifier);
const identifierWhitelist = await IdentifierWhitelist.deployed()
await identifierWhitelist.addSupportedIdentifier(constructorParams.priceFeedIdentifier)
```

6. We also need to register the `empCreator` factory with the `registry` to give it permission to create new expiring multiparty (emp) synthetic tokens.

```js
const registry = await Registry.deployed();
await registry.addMember(1, empCreator.address);
const registry = await Registry.deployed()
await registry.addMember(1, empCreator.address)
```

7. We also need to register the collateral token with the `collateralTokenWhitelist`.

```js
collateralTokenWhitelist = await AddressWhitelist.at(await empCreator.collateralTokenWhitelist());
await collateralTokenWhitelist.addToWhitelist(TestnetERC20.address);
collateralTokenWhitelist = await AddressWhitelist.at(await empCreator.collateralTokenWhitelist())
await collateralTokenWhitelist.addToWhitelist(TestnetERC20.address)
```

8. Now, we can create a new expiring multiparty synthetic token with the factory instance.

```js
const txResult = await empCreator.createExpiringMultiParty(constructorParams);
const emp = await ExpiringMultiParty.at(txResult.logs[0].args.expiringMultiPartyAddress);
const txResult = await empCreator.createExpiringMultiParty(constructorParams)
const emp = await ExpiringMultiParty.at(txResult.logs[0].args.expiringMultiPartyAddress)
```

## Create new tokens from an existing contract
Expand All @@ -85,15 +85,15 @@ const emp = await ExpiringMultiParty.at(txResult.logs[0].args.expiringMultiParty
Give permission to the empCreator to spend the collateral tokens on our behalf.

```js
const collateralToken = await TestnetERC20.deployed();
await collateralToken.allocateTo(accounts[0], web3.utils.toWei("10000"));
await collateralToken.approve(emp.address, web3.utils.toWei("10000"));
const collateralToken = await TestnetERC20.deployed()
await collateralToken.allocateTo(accounts[0], web3.utils.toWei("10000"))
await collateralToken.approve(emp.address, web3.utils.toWei("10000"))
```

2. We can now create a synthetic token position. We will deposit 150 units of collateral (the first argument) to create 100 units of synthetic tokens (the second argument).

```js
await emp.create({ rawValue: web3.utils.toWei("150") }, { rawValue: web3.utils.toWei("100") });
await emp.create({ rawValue: web3.utils.toWei("150") }, { rawValue: web3.utils.toWei("100") })
```

3. Let’s check that we now have synthetic tokens. We should have 100 synthetic tokens and 9,850 collateral tokens.
Expand All @@ -104,9 +104,9 @@ const syntheticToken = await SyntheticToken.at(await emp.tokenCurrency())(await
// collateral token balance
await syntheticToken.balanceOf(accounts[0])
)
.toString();
.toString()
// synthetic token balance
await emp.positions(accounts[0]);
await emp.positions(accounts[0])
// position information
```

Expand All @@ -115,8 +115,8 @@ await emp.positions(accounts[0]);
1. Because we are a token sponsor for this synthetic token contract, we can redeem some of the tokens we minted even before the synthetic token expires. Let's redeem half.

```js
await syntheticToken.approve(emp.address, web3.utils.toWei("10000"));
await emp.redeem({ rawValue: web3.utils.toWei("50") });
await syntheticToken.approve(emp.address, web3.utils.toWei("10000"))
await emp.redeem({ rawValue: web3.utils.toWei("50") })
```

2. Let’s check that our synthetic token balance has decreased and our collateral token balance has increased.
Expand All @@ -125,14 +125,14 @@ await emp.redeem({ rawValue: web3.utils.toWei("50") });
Our collateral token balance should increase to 9,925.

```js
(await collateralToken.balanceOf(accounts[0]))
.toString()(
// collateral token balance
await syntheticToken.balanceOf(accounts[0])
)
.toString();
// Print balance
const collateralBalance = await collateralToken.balanceOf(accounts[0])
collateralBalance.toString()
// collateral token balance
const syntheticBalance = await syntheticToken.balanceOf(accounts[0])
syntheticBalance.toString()
// synthetic token balance
await emp.positions(accounts[0]);
await emp.positions(accounts[0])
// position information
```

Expand All @@ -144,31 +144,32 @@ await emp.positions(accounts[0]);
```js
await emp
.deposit({ rawValue: web3.utils.toWei("10") })(await collateralToken.balanceOf(accounts[0]))
.toString();
.toString()
```

2. For a token sponsor to withdraw collateral from his position, there are typically 2 ways to do this.
Read this [explainer](../explainer.md) for more information.
In this scenario, because we are the only token sponsor, we will have to withdraw collateral the “slow” way. First, we need to request a withdrawal of 10 collateral tokens.

```js
await emp.requestWithdrawal({ rawValue: web3.utils.toWei("10") });
await emp.requestWithdrawal({ rawValue: web3.utils.toWei("10") })
```

3. Now, we need to simulate the withdrawal liveness period passing without a dispute of our withdrawal request.
Because we set this period to be 1000 when we parameterized and deployed the contract, let’s simulate 1001 of time elapsing.
Once the 1001 has elapsed, we can withdraw the amount we previously requested.

```js
await emp.setCurrentTime((await emp.getCurrentTime()).toNumber() + 1001);
await emp.withdrawPassedRequest();
await emp.setCurrentTime((await emp.getCurrentTime()).toNumber() + 1001)
await emp.withdrawPassedRequest()
```

4. Let’s now check that our collateral token balance has returned to 9,925.

```js
(await collateralToken.balanceOf(accounts[0])).toString();
// collateral token balance
const tokenBalance = await collateralToken.balanceOf(accounts[0])
tokenBalance.toString()
```

<!--
Expand Down

0 comments on commit 114f516

Please sign in to comment.