Skip to content

Extended Advertisement Finance contract

Tiago Rosado edited this page Oct 15, 2018 · 4 revisions

Features

Functionality

Extended Advertisement Finance contract is part of Extended Advertisement contract, as explain in the contract architecture section of Extended Advertisement contract. Most of the operations available in this contract are performed by a defined authorised address which will be the Extended Advertisement contract in most cases, although some operations can also be performed by the Extended Advertisement Finance contract owner.

Extended Advertisement Finance contract main function is to work as an upgradable deposit of funds to be used by Extended Advertisement's main contract. Thus, Extended Advertisement contract is responsible for transferring the respective Appcoins to this contract before updating the balance of a developer in Extended Advertisement Finance contract.

Set Advertisement Storage contract address

As a fail-safe mechanism for contract upgrades, an address of a contract inheriting from Base Storage Advertisement contract must be registered to Extended Advertisement Finance contract. This mechanism enables Extended Finance contract to check that a newer (Extended) Advertisement contract is using the same Storage contract as earlier defined. Thus, trying to ensure the balance of Extended Advertisement Finance contract remains consistent with the campaigns stored in Storage contract.

To set an Storage contract, it is required to call setAdsStorageAddress function on Advertisement Finance contract, with the correct Advertisement Storage contract address.

This operation can only be performed by the contract owner or by the main Advertisement Contract. This function also resets Advertisement Finance contract, thus returns remaining funds on Advertisment Finance contract to its owners.

Set Extended Advertisement contract address

When it is necessary to upgrade Extended Advertisement contract, the contract owner just needs to be sure the new Advertisement contract implements getAdvertisementStorageAddress function. This function will return the Advertisement Storage contract address in use by the new Advertisement contract and is mandatory for the upgrade to work.

After the new Extended Advertisement contract is deployed, the Extended Advertisement Finance contract owner just needs to call setAdsContractAddress function on Extended Finance contract, with the new Extended Advertisement contract address. This function will verify if the new Advertisement contract is using the same Storage contract address earlier registered on the Advertisement Finance contract.

In case of Storage address mismatch this function will be reverted and the upgrade will not be made.

Increase developer's balance

After the Extended Advertisement contract transfers developer's funds to the Extended Finance contract, it is necessary for the Extended Advertisement contract to call increaseBalance function on Extended Finance contract. The increaseBalance function updates the developer's balance of AppCoins deposited on the Extended Finance contract. This function is required to take as arguments the developer's address and the amount of AppCoins earlier deposited by the developer through the main Extended Advertisement contract.

This operation can only be performed by the address identified as belonging to the main Advertisement contract.

Pay to specific address

Considering the Extended AppCoins protocol, Extended Advertisement Finance contract has a pay function, however no transfer outside the Extended Finance contract is made. The Extended Finance contract simply internally transfers the value passed as argument in the pay function to the end user, however the user is required to call withdraw function to effectively transfer the funds from Extended Advertisement Finance contract to the user's wallet.

This operation can only be performed by the address identified as belonging to the Extended Advertisement contract.

Withdraw

When cancelling a campaign or when a user wants to retrieve his rewards from the Extended Finance Advertisement contract it is required to call withdraw function. The withdraw function requires the user's address and the value of AppCoins to be returned to the user.

This operation can only be performed by the contract owner or by the main Extended Advertisement Contract.

Reset contract

When calling setAdsStorageAddress function to upgrade the storage contract or when the Extended Advertisement contract updates the Storage contract used to store campaigns, the function reset is called in Extended Advertisement Finance contract. The reset function resets the Finance contract, thus every AppCoin deposited on the contract returns to the developers who deposited the coins for user acquisition campaigns or users who have not withdrawn their rewards. This function sets the contract's state to its initial state.

This operation can only be performed by the contract owner or by the Extended Advertisement Contract.