diff --git a/contracts/FungibleTokenCustom.aes b/contracts/FungibleTokenCustom.aes index 2f38565..3279171 100644 --- a/contracts/FungibleTokenCustom.aes +++ b/contracts/FungibleTokenCustom.aes @@ -20,6 +20,12 @@ @compiler >= 4 +contract TokenSale = + stateful entrypoint set_token : () => unit + +contract WordRegistry = + stateful entrypoint add_token : (TokenSale, string) => unit + include "Option.aes" /// @title - Fungible token with all the extensions - burn, mint, allowances @@ -64,7 +70,7 @@ contract FungibleTokenFull = // Create a fungible token with // the following `name` `symbol` and `decimals` // and set the inital smart contract state - entrypoint init(name: string, decimals : int, symbol : string, owner : address) = + entrypoint init(name: string, decimals : int, symbol : string, token_sale : TokenSale, word_registry : WordRegistry) = // If the `name` lenght is less than 1 symbol abort the execution require(String.length(name) >= 1, "STRING_TOO_SHORT_NAME") // If the `symbol` length is less than 1 symbol abort the execution @@ -72,7 +78,9 @@ contract FungibleTokenFull = // If the provided value for `decimals` is negative abort the execution require_non_negative_value(decimals) - { owner = owner, + token_sale.set_token() + word_registry.add_token(token_sale, symbol) + { owner = token_sale.address, total_supply = 0, balances = {}, meta_info = { name = name, symbol = symbol, decimals = decimals }, diff --git a/contracts/TokenSale.aes b/contracts/TokenSale.aes index f84baa4..f122647 100644 --- a/contracts/TokenSale.aes +++ b/contracts/TokenSale.aes @@ -60,7 +60,8 @@ contract TokenSale = // require(vote_timeout == (60 / 3) * 24 * 7, "INCORRECT_VOTE_TIMEOUT") { token = None, votes = {}, spread = 0, vote_timeout = vote_timeout, bonding_curve = bonding_curve, description = description } - stateful entrypoint set_token(token : Token) : unit = + stateful entrypoint set_token() : unit = + let token : Token = Address.to_contract(Call.caller) require(!has_token(), "TOKEN_ALREADY_SET") put(state{ token = Some(token) }) diff --git a/contracts/WordRegistry.aes b/contracts/WordRegistry.aes index 631f4f1..ce6ca61 100644 --- a/contracts/WordRegistry.aes +++ b/contracts/WordRegistry.aes @@ -33,8 +33,7 @@ contract WordRegistry = { tokens = {}, owner = Call.caller } - stateful entrypoint add_token(token_sale : TokenSale) : unit = - let symbol = token_sale.get_token().meta_info().symbol + stateful entrypoint add_token(token_sale : TokenSale, symbol : string) : unit = require(!Map.member(symbol, state.tokens), "SYMBOL_ALREADY_EXISTENT") put(state{ tokens = state.tokens{ [symbol] = token_sale } }) diff --git a/test/tokenSaleVotingTest.js b/test/tokenSaleVotingTest.js index 5d1670d..1154081 100644 --- a/test/tokenSaleVotingTest.js +++ b/test/tokenSaleVotingTest.js @@ -12,6 +12,7 @@ const TOKEN_SALE_INTERFACE = readFileRelative('./contracts/interfaces/TokenSaleI const TOKEN = readFileRelative('./contracts/FungibleTokenCustom.aes', 'utf-8'); const TOKEN_VOTING = readFileRelative('./contracts/TokenVoting.aes', 'utf-8'); const TOKEN_VOTING_INTERFACE = readFileRelative('./contracts/interfaces/TokenVotingInterface.aes', 'utf-8'); +const WORD_REGISTRY = readFileRelative('./contracts/WordRegistry.aes', 'utf-8'); const BONDING_CURVE = require('sophia-bonding-curve/BondCurveLinear.aes') const config = { @@ -21,7 +22,7 @@ const config = { }; describe('Token- Sale and Voting Contracts', () => { - let client, sale, voting, token, bondingCurve; + let client, sale, voting, token, registry, bondingCurve; before(async () => { client = await Universal({ @@ -54,12 +55,16 @@ describe('Token- Sale and Voting Contracts', () => { assert.equal(init.result.returnType, 'ok'); }); + it('Deploy Registry', async () => { + registry = await client.getContractInstance(WORD_REGISTRY); + const init = await registry.methods.init(); + assert.equal(init.result.returnType, 'ok'); + }); + it('Deploy and set Token', async () => { token = await client.getContractInstance(TOKEN); - const init = await token.methods.init("Test Token", 0, "TT", sale.deployInfo.address.replace('ct_', 'ak_')); + const init = await token.methods.init("Test Token", 0, "TT", sale.deployInfo.address, registry.deployInfo.address); assert.equal(init.result.returnType, 'ok'); - const set = await sale.methods.set_token(token.deployInfo.address); - assert.equal(set.result.returnType, 'ok'); }); it('Deploy Voting Contract', async () => { diff --git a/test/wordRegistryTest.js b/test/wordRegistryTest.js index 467ae8b..48d6d35 100644 --- a/test/wordRegistryTest.js +++ b/test/wordRegistryTest.js @@ -52,11 +52,8 @@ describe('WordRegistry Contract', () => { it('Deploy and add Token', async () => { token = await client.getContractInstance(TOKEN); - const init = await token.methods.init("Test Token", 0, "TT", contract.deployInfo.address.replace('ct_', 'ak_')); + const init = await token.methods.init("Test Token", 0, "TT", sale.deployInfo.address, contract.deployInfo.address); assert.equal(init.result.returnType, 'ok'); - await sale.methods.set_token(token.deployInfo.address); - const set = await contract.methods.add_token(sale.deployInfo.address); - assert.equal(set.result.returnType, 'ok'); }); it('Get State', async () => {