Skip to content

Latest commit

 

History

History
93 lines (57 loc) · 3.33 KB

2.md

File metadata and controls

93 lines (57 loc) · 3.33 KB

Task 2: Splitter Smart Contract

File with solution

Create a contract that is capable of accepting TON and tokens, and then distributing them to users according to their shires.

The contract can accept a total of four operations:

  • 0x368ddef3 -> Add User
  • 0x278205c8 -> Remove User
  • 0x68530b3 -> Split (TON)
  • 0x7362d09c -> Transfer Notification (Jetton)

TL-B:

add_user#368ddef3 query_id:uint64 address:MsgAddressInt share:uint32 = InternalMsgBody;
remove_user#278205c8 query_id:uint64 address:MsgAddressInt = InternalMsgBody;
split_ton#68530b3 query_id:uint64 amount:Coins = InternalMsgBody;
transfer_notification#701c09a6 query_id:uint64 amount:Coins = InternalMsgBody;

Contract storage

The contract must contain the following fields in its storage after deployment:

  • admin_address: MsgAddressInt
  • users: (HashmapE 267 uint32)

You can add new fields, but these fields must always be first and in the order, in the order specified here. In testing, these fields will be written on defloat, so you need to take that into account.

Add User

The contract should accept a message with op = 0x368ddef3 and the following fields:

  • query_id: uint64
  • address: MsgAddressInt
  • share: uint32

The contract accepts the message, checks that it came from the admin, and if so, adds the user to its storage. If the message did not come from the admin, the contract should throw error 120.

If the user is already in the storage, then it is necessary to update its share to a new one.

Remove User

The contract should accept a message with op = 0x278205c8 and the following fields:

  • query_id: uint64
  • address: MsgAddressInt

The contract accepts the message, checks that it came from the admin, and if so, it removes the user from its storage. If the message did not come from the admin, the contract should throw error 120.

If the user is not in the storage, it should throw error 121.

Split (TON).

The contract should accept a message with op = 0x5ffd4c63 and the following fields:

  • query_id: uint64
  • amount: Coins

The contract accepts the message, distributes the TON to users according to their shares. Transactions must be sent with mode = 1 and no body.

If there are no users, error 122 must be thrown

Transfer Notification (Jetton).

The contract should receive a message with op = 0x7362d09c and the following fields:

  • query_id: uint64
  • amount: Coins

If there are no users, then error 122 must be thrown.

The contract should send out to all users according to their amount of tokens. You should send messages to the address of your token jack jetton_address according to TEP-0074.

  • Message Value: 0.02 TON
  • Response address must be equal to the recipient address
  • Forward_amount = 1 nanoTON
  • Without custom_payload / without forward_payload.

Note: transfer_notification in this task does not conform to the TEP-0074 standard. This is done to simplify the task.

The contract must have the following GET methods:

  • get_users: returns a dictionary with 267 bit keys (user addresses) and the value is uint32, which means user share.
  • get_user_share(slice user_address): calculates and returns the user's share.

Optional

Formula for calculating the number of tokens: user_share * amount / total_share.