@version 1
condition triggered_by: transaction, on: add_pool(token1_address, token2_address, pool_creation_address), as: [
type: "transfer",
content: (
valid? = false
token1_address = String.to_uppercase(token1_address)
token2_address = String.to_uppercase(token2_address)
pool_exists? = get_pool_addresses(token1_address, token2_address) != nil
if token1_address != token2_address && !pool_exists? do
# Could create a new function Chain.get_transactions(list_of_address)
pool_transaction = Chain.get_transaction(pool_creation_address)
# Ensure tokens exists and lp token definition is good
valid_token1? = valid_token?(token1_address)
valid_token2? = valid_token?(token2_address)
valid_definition? = false
if valid_token1? && valid_token2? && pool_transaction != nil && pool_transaction.type == "token" do
expected_content = Contract.call_function(
0x000086e60124c986ebcaa5affb7a3db8213072a132233fe61cf45651fdcf3c4cecea,
"get_lp_token_definition",
[token1_address, token2_address]
)
valid_definition? = Json.parse(pool_transaction.content) == Json.parse(expected_content)
end
valid_code? = false
pool_genesis_address = nil
if valid_definition? do
# Ensure code is valid
pool_genesis_address = Chain.get_genesis_address(pool_creation_address)
expected_code = Contract.call_function(
0x000086e60124c986ebcaa5affb7a3db8213072a132233fe61cf45651fdcf3c4cecea,
"get_pool_code",
[token1_address, token2_address, pool_genesis_address, pool_creation_address]
)
valid_code? = Code.is_same?(pool_transaction.code, expected_code)
end
if valid_code? do
# Ensure liquidity is provided to the pool
valid? = List.in?(transaction.recipients, pool_genesis_address)
end
end
valid?
)
]
actions triggered_by: transaction, on: add_pool(token1_address, token2_address, pool_creation_address) do
token1_address = String.to_uppercase(token1_address)
token2_address = String.to_uppercase(token2_address)
pool_genesis_address = Chain.get_genesis_address(pool_creation_address)
pool_id = get_pool_id(token1_address, token2_address)
pools = State.get("pools", Map.new())
pool_data = [
address: pool_genesis_address,
lp_token_address: pool_creation_address
]
pools = Map.set(pools, pool_id, pool_data)
State.set("pools", pools)
end
condition triggered_by: transaction, on: add_farm(lp_token, start_date, end_date, reward_token, farm_creation_address), as: [
address: (
# Farm can only be created by the master chain of the dex
# Transaction is not yet validated so we need to use previous address
# to get the genesis address
previous_address = Chain.get_previous_address(transaction)
Chain.get_genesis_address(previous_address) == 0x0000e46f8e90074ddf1dfc46385e07d826d35251f3a7b7ff65ad6f7e4b138aff7c10
),
content: (
lp_token = String.to_hex(lp_token)
reward_token = String.to_uppercase(reward_token)
farm_creation_address = String.to_hex(farm_creation_address)
# LP token should be listed on dex
lp_token_exists? = false
pools = State.get("pools", Map.new())
for pool in Map.values(pools) do
if String.to_hex(pool.lp_token_address) == lp_token do
lp_token_exists? = true
end
end
# Start date should be between 2 hours and 1 week from now
# End date should be between 1 month (30 days) and 1 year (365 days) from start date
valid_date? = false
if lp_token_exists? do
now = Time.now()
valid_start_date? = now + 7200 <= start_date && now + 604800 >= start_date
valid_end_date? = start_date + 2592000 <= end_date && start_date + 31536000 >= end_date
valid_date? = valid_start_date? && valid_end_date?
end
# Ensure farm code is valid
valid_code? = false
farm_genesis_address = nil
if valid_date? do
farm_transaction = Chain.get_transaction(farm_creation_address)
if farm_transaction != nil && farm_transaction.type == "contract" do
farm_genesis_address = Chain.get_genesis_address(farm_creation_address)
expected_code = Contract.call_function(
0x000086e60124c986ebcaa5affb7a3db8213072a132233fe61cf45651fdcf3c4cecea,
"get_farm_code",
[lp_token, start_date, end_date, reward_token, farm_genesis_address]
)
valid_code? = Code.is_same?(farm_transaction.code, expected_code)
end
end
# Ensure this transaction adds the reward token to the farm
valid_reward? = false
if valid_code? do
if reward_token == "UCO" do
valid_reward? = Map.get(transaction.uco_transfers, farm_genesis_address) != nil
else
transfers = Map.get(transaction.token_transfers, farm_genesis_address)
for transfer in transfers do
if transfer.token_address == reward_token do
valid_reward? = true
end
end
end
end
lp_token_exists? && valid_date? && valid_code? && valid_reward?
)
]
actions triggered_by: transaction, on: add_farm(lp_token, start_date, end_date, reward_token, farm_creation_address) do
farms = State.get("farms", [])
farm_genesis_address = Chain.get_genesis_address(farm_creation_address)
new_farm = [
lp_token_address: lp_token,
start_date: start_date,
end_date: end_date,
reward_token: reward_token,
address: farm_genesis_address
]
farms = List.prepend(farms, new_farm)
State.set("farms", farms)
end
condition triggered_by: transaction, on: update_code(new_code), as: [
previous_public_key: (
# Router code can only be updated from the master chain of the dex
# Transaction is not yet validated so we need to use previous address
# to get the genesis address
previous_address = Chain.get_previous_address()
Chain.get_genesis_address(previous_address) == 0x0000e46f8e90074ddf1dfc46385e07d826d35251f3a7b7ff65ad6f7e4b138aff7c10
),
code: Code.is_valid?(new_code)
]
actions triggered_by: transaction, on: update_code(new_code) do
Contract.set_type("contract")
Contract.set_code(new_code)
end
condition triggered_by: transaction, on: update_pools_code(), as: [
previous_public_key: (
# Pool code update can only be requested from the master chain of the dex
# Transaction is not yet validated so we need to use previous address
# to get the genesis address
previous_address = Chain.get_previous_address()
Chain.get_genesis_address(previous_address) == 0x0000e46f8e90074ddf1dfc46385e07d826d35251f3a7b7ff65ad6f7e4b138aff7c10
)
]
actions triggered_by: transaction, on: update_pools_code() do
pools = State.get("pools", Map.new())
if Map.size(pools) > 0 do
for pool_info in Map.values(pools) do
Contract.add_recipient address: pool_info.address, action: "update_code", args: []
end
Contract.set_type("transfer")
end
end
condition triggered_by: transaction, on: update_farms_code(), as: [
previous_public_key: (
# Pool code update can only be requested from the master chain of the dex
# Transaction is not yet validated so we need to use previous address
# to get the genesis address
previous_address = Chain.get_previous_address()
Chain.get_genesis_address(previous_address) == 0x0000e46f8e90074ddf1dfc46385e07d826d35251f3a7b7ff65ad6f7e4b138aff7c10
)
]
actions triggered_by: transaction, on: update_farms_code() do
farms = State.get("farms", [])
if List.size(farms) > 0 do
for farm in farms do
Contract.add_recipient address: farm.address, action: "update_code", args: []
end
Contract.set_type("transfer")
end
end
fun get_pool_id(token1_address, token2_address) do
if token1_address > token2_address do
temp = token1_address
token1_address = token2_address
token2_address = temp
end
"#{token1_address}/#{token2_address}"
end
fun valid_token?(token_address) do
valid? = false
if token_address == "UCO" do
valid? = true
else
tx = Chain.get_transaction(token_address)
# Transaction must have type token
# Token must be fungible
if tx != nil && tx.type == "token" do
token_definition = Json.parse(tx.content)
valid? = token_definition.type == "fungible"
end
end
valid?
end
export fun get_pool_addresses(token1_address, token2_address) do
token1_address = String.to_uppercase(token1_address)
token2_address = String.to_uppercase(token2_address)
if token1_address > token2_address do
temp = token1_address
token1_address = token2_address
token2_address = temp
end
pool_id = "#{token1_address}/#{token2_address}"
pools = State.get("pools", Map.new())
Map.get(pools, pool_id, nil)
end
export fun get_pool_list() do
pools = State.get("pools", Map.new())
list = []
for pool_id in Map.keys(pools) do
pool = Map.get(pools, pool_id)
pool = Map.set(pool, "tokens", pool_id)
list = List.prepend(list, pool)
end
list
end
export fun get_farm_list() do
State.get("farms", [])
end
Content (0 B)
{
"pools": {
"00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/0000E06BFF011D495E21EA9D5266435BBF2B5E721464132E4D24C404F51B0AFA8699": {
"address": "0000E691507E13F81CD7EC50453A95F447B778277653213278F20C42F74EBFF9046E",
"lp_token_address": "000035ACC0A03D7FDCB940F5F6E4DC65384033A9731B6B57C68D82DEA45C8B4EE622"
},
"0000E06BFF011D495E21EA9D5266435BBF2B5E721464132E4D24C404F51B0AFA8699/UCO": {
"address": "0000D5BC05EC984F531E27E74E2804AB1DF1DD856B821D37F87D5AD9FDE9F4440966",
"lp_token_address": "00004638E1D7397E8050826D1861194854F1105F568FCA616F99981507DAA5653EE7"
},
"0000E7367B119C45B5D92363E0E6C3E0067A6AD9E0B8C7CC7AB475AFFB010B24E380/UCO": {
"address": "0000F92743735B9D8E7CCA5617D37F93B5E4A6036DABF1CDE8DB77CD0633B0D8671C",
"lp_token_address": "000029C3AD030244EA5F0358D0F31D74E7DAE20DC9906ABED6C5775D5D73A1B2B4A6"
}
}
}
-
Secret shared with 1 key
Encoded secret
C92045717D25FA93468BD5B990E2970FC49B2317071EF146295CD9F76CD4852E8FA0E83A851095247CE7E84A6B59BCCAFF980C6C7F3667EB0AB0CFEF
Authorized keys
- 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F
Contract recipients (0)
Inputs (0)
Contract inputs (0)
Unspent outputs (1)
-
From 0000986D...A96FAt 2024-01-30 13:06:52 UTCAmount 0.00223864 UCO
Previous public key
000133068FD1CA5657CECF229D914B966C78990F13E16266C07261A199CA0A51054E
Previous signature
12C46FB41E8F5F7B55F04FFDA10BEEC3F733F1CF161E91B08B24CF7EC00504EA1C77751794CCA277C4B1768309AE0E5B28106D0608F13C12E03CF537BE8D580E
Origin signature
3046022100EEE23517E6743BA3998744C0B34254D16210A3BEC2643A3CC9D81B3F2ED03A95022100C41458ED15C7D5378C3C9ACDED9EC6A9CC01873DA73FD129D30FC2DE87FDF9DD
Proof of work
010204E9BB401A767B0C92D5DB139379AAB18E1B449B455F49E3A44F3466B2D38E59F0516B79493A528A95E5A74CF46F79CF12DEB73293458F6A4403D2B3E57D697347
Proof of integrity
00393CB0C34BB0971C8F5F34FA4801DF016E9BB704DD71056804708FABAED52D6E
Coordinator signature
0210F3C8F60E33BF2AF4AE3F21D50D80B6F8DA223965C4CDAAFD9DED783FCE978A9AC5CD6B1761594FB0F1515312173F48A21291719B119848145F7D6E03F508
Validator #1 public key
0001B01EEF96BA7E95FC844D456CE8868F18864519FC9532E1751C2035FD044DD5D0
Validator #1 signature
27B96ACBE17C1CD34FC5D713F65F9B5E0D269471A02C547BF946FC9F0148FD194B876F42E2481D27A810149199E986D10F7F1815289282139322947A4879170E
Validator #2 public key
000177BA744AC778DC2D51A1B7C622E7AC4BD1E1AA8DA2D0FCE71BAAB7DAD0E020E0
Validator #2 signature
D71F1E73EE8A031368EC36D01E2ADF39D561C669A1F50B667DCF2F5DD74ED35C791046F45D5A1D6C3EACCA667033B3D4DD73059ADF857CF20F57CF3AD9977102