Skip to content

Advertisement Finance contract

Tiago Rosado edited this page Aug 22, 2018 · 12 revisions

Features

Functionality

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

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

Set Advertisement Storage contract address

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

To set an Advertisement 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 main Advertisement contract address

When it is necessary to upgrade 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 Advertisement contract is deployed, the Advertisement Finance contract owner just needs to call setAdsContractAddress function on Advertisement Finance contract, with the new Advertisement contract address. This function will verify if the new Advertisement contract is using the same Advertisement Storage contract address earlier registered on the Advertisement Finance contract.

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

Increase developer's balance

After the main Advertisement contract transfers developer's funds to the Advertisement Finance contract, it is necessary for the Advertisement contract to call increaseBalance function on Advertisement Finance. The increaseBalance function updates the developer's balance of AppCoins deposited on the Advertisement 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 Advertisement contract.

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

Pay to specific address

On the event of a user installing an app registered in a user acquisition campaign and latter fabric and submit a proof-of-attention of that app as described in the Advertisement contract wiki page. The main advertisement address will call pay function of the Advertisement Finance multiple times in order to transfer the correct amount of AppCoins for the user,OEM and appstore involved, corresponding to the reward defined by the developer during campaign creation.

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

Withdraw

When cancelling a campaign or in a event that a certain amount of AppCoins needs to be return to a developer it is required to call withdraw function for this to happen. The withdraw function requires the developer's address and the value of AppCoins to be returned to the developer.

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

Reset contract

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

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