-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from tinymanorg/governance
Add `governance` and `lending pools` features
- Loading branch information
Showing
52 changed files
with
5,375 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from algosdk.v2client.algod import AlgodClient | ||
|
||
from tinyman.folks_lending.constants import ( | ||
TESTNET_FOLKS_POOL_MANAGER_APP_ID, | ||
TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID) | ||
from tinyman.folks_lending.transactions import \ | ||
prepare_add_liquidity_transaction_group | ||
from tinyman.folks_lending.utils import get_lending_pools | ||
from tinyman.v2.client import TinymanV2TestnetClient | ||
from tinyman.v2.constants import TESTNET_VALIDATOR_APP_ID_V2 | ||
|
||
algod = AlgodClient("", "https://testnet-api.algonode.network") | ||
account_sk, account_address = ('YOUR PRIVATE KEY HERE', 'YOUR ADDRESS HERE') | ||
client = TinymanV2TestnetClient(algod_client=algod, user_address=account_address) | ||
|
||
asset_1_id = 67395862 # USDC | ||
asset_2_id = 0 # Algo | ||
|
||
# Get f_asset ids | ||
|
||
folks_pools = get_lending_pools(algod, TESTNET_FOLKS_POOL_MANAGER_APP_ID) | ||
temp = dict() | ||
for folks_pool in folks_pools: | ||
temp[folks_pool['asset_id']] = folks_pool | ||
folks_pools = temp | ||
|
||
f_asset_1_id = folks_pools[asset_1_id]['f_asset_id'] | ||
f_asset_2_id = folks_pools[asset_2_id]['f_asset_id'] | ||
|
||
pool = client.fetch_pool(f_asset_1_id, f_asset_2_id, fetch=True) | ||
|
||
# Add liquidity | ||
|
||
txn_group = prepare_add_liquidity_transaction_group( | ||
sender=account_address, | ||
suggested_params=algod.suggested_params(), | ||
wrapper_app_id=TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID, | ||
tinyman_amm_app_id=TESTNET_VALIDATOR_APP_ID_V2, | ||
lending_app_1_id=folks_pools[asset_1_id]['pool_app_id'], | ||
lending_app_2_id=folks_pools[asset_2_id]['pool_app_id'], | ||
lending_manager_app_id=TESTNET_FOLKS_POOL_MANAGER_APP_ID, | ||
tinyman_pool_address=pool.address, | ||
asset_1_id=asset_1_id, | ||
asset_2_id=asset_2_id, | ||
f_asset_1_id=f_asset_1_id, | ||
f_asset_2_id=f_asset_2_id, | ||
liquidity_token_id=pool.pool_token_asset.id, | ||
asset_1_amount=10000, | ||
asset_2_amount=10000 | ||
) | ||
|
||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from algosdk import transaction | ||
from algosdk.v2client.algod import AlgodClient | ||
|
||
from tinyman.folks_lending.constants import ( | ||
TESTNET_FOLKS_POOL_MANAGER_APP_ID, | ||
TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID) | ||
from tinyman.folks_lending.transactions import \ | ||
prepare_asset_optin_transaction_group | ||
from tinyman.folks_lending.utils import get_lending_pools | ||
from tinyman.utils import TransactionGroup | ||
from tinyman.v2.client import TinymanV2TestnetClient | ||
|
||
algod = AlgodClient("", "https://testnet-api.algonode.network") | ||
account_sk, account_address = ('YOUR PRIVATE KEY HERE', 'YOUR ADDRESS HERE') | ||
client = TinymanV2TestnetClient(algod_client=algod, user_address=account_address) | ||
|
||
asset_1_id = 67396528 # goBTC | ||
asset_2_id = 0 # Algo | ||
|
||
# Get f_asset ids | ||
|
||
folks_pools = get_lending_pools(algod, TESTNET_FOLKS_POOL_MANAGER_APP_ID) | ||
temp = dict() | ||
for folks_pool in folks_pools: | ||
temp[folks_pool['asset_id']] = folks_pool | ||
folks_pools = temp | ||
|
||
f_asset_1_id = folks_pools[asset_1_id]['f_asset_id'] | ||
f_asset_2_id = folks_pools[asset_2_id]['f_asset_id'] | ||
|
||
pool = client.fetch_pool(f_asset_1_id, f_asset_2_id) | ||
|
||
# Opt-in to assets | ||
|
||
txns = [ | ||
transaction.AssetOptInTxn( | ||
sender=account_address, | ||
sp=algod.suggested_params(), | ||
index=asset_1_id | ||
), | ||
transaction.AssetOptInTxn( | ||
sender=account_address, | ||
sp=algod.suggested_params(), | ||
index=f_asset_1_id | ||
), | ||
transaction.AssetOptInTxn( | ||
sender=account_address, | ||
sp=algod.suggested_params(), | ||
index=f_asset_2_id | ||
) | ||
] | ||
|
||
if asset_2_id != 0: | ||
txns.append( | ||
transaction.AssetOptInTxn( | ||
sender=account_address, | ||
sp=algod.suggested_params(), | ||
index=asset_2_id | ||
) | ||
) | ||
txn_group = TransactionGroup(txns) | ||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) | ||
|
||
# Bootstrap pool. | ||
|
||
txn_group = pool.prepare_bootstrap_transactions( | ||
user_address=account_address, | ||
suggested_params=algod.suggested_params(), | ||
) | ||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) | ||
|
||
# Opt-in to pool token. | ||
|
||
pool = client.fetch_pool(f_asset_1_id, f_asset_2_id, fetch=True) | ||
|
||
txn_group = TransactionGroup([ | ||
transaction.AssetOptInTxn( | ||
sender=account_address, | ||
sp=algod.suggested_params(), | ||
index=pool.pool_token_asset.id | ||
) | ||
]) | ||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) | ||
|
||
# Send an asset_optin appcall. | ||
|
||
txn_group = prepare_asset_optin_transaction_group( | ||
sender=account_address, | ||
suggested_params=algod.suggested_params(), | ||
wrapper_app_id=TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID, | ||
assets_to_optin=[asset_1_id, asset_2_id, f_asset_1_id, f_asset_2_id, pool.pool_token_asset.id] | ||
) | ||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from algosdk.v2client.algod import AlgodClient | ||
|
||
from tinyman.folks_lending.constants import ( | ||
TESTNET_FOLKS_POOL_MANAGER_APP_ID, | ||
TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID) | ||
from tinyman.folks_lending.transactions import \ | ||
prepare_remove_liquidity_transaction_group | ||
from tinyman.folks_lending.utils import get_lending_pools | ||
from tinyman.v2.client import TinymanV2TestnetClient | ||
from tinyman.v2.constants import TESTNET_VALIDATOR_APP_ID_V2 | ||
|
||
algod = AlgodClient("", "https://testnet-api.algonode.network") | ||
account_sk, account_address = ('YOUR PRIVATE KEY HERE', 'YOUR ADDRESS HERE') | ||
client = TinymanV2TestnetClient(algod_client=algod, user_address=account_address) | ||
|
||
asset_1_id = 67395862 # USDC | ||
asset_2_id = 0 # Algo | ||
|
||
# Get f_asset ids | ||
|
||
folks_pools = get_lending_pools(algod, TESTNET_FOLKS_POOL_MANAGER_APP_ID) | ||
temp = dict() | ||
for folks_pool in folks_pools: | ||
temp[folks_pool['asset_id']] = folks_pool | ||
folks_pools = temp | ||
|
||
f_asset_1_id = folks_pools[asset_1_id]['f_asset_id'] | ||
f_asset_2_id = folks_pools[asset_2_id]['f_asset_id'] | ||
|
||
pool = client.fetch_pool(f_asset_1_id, f_asset_2_id, fetch=True) | ||
|
||
# Remove liquidity | ||
|
||
txn_group = prepare_remove_liquidity_transaction_group( | ||
sender=account_address, | ||
suggested_params=algod.suggested_params(), | ||
wrapper_app_id=TESTNET_FOLKS_WRAPPER_LENDING_POOL_APP_ID, | ||
tinyman_amm_app_id=TESTNET_VALIDATOR_APP_ID_V2, | ||
lending_app_1_id=folks_pools[asset_1_id]['pool_app_id'], | ||
lending_app_2_id=folks_pools[asset_2_id]['pool_app_id'], | ||
lending_manager_app_id=TESTNET_FOLKS_POOL_MANAGER_APP_ID, | ||
tinyman_pool_address=pool.address, | ||
asset_1_id=asset_1_id, | ||
asset_2_id=asset_2_id, | ||
f_asset_1_id=f_asset_1_id, | ||
f_asset_2_id=f_asset_2_id, | ||
liquidity_token_id=pool.pool_token_asset.id, | ||
liquidity_token_amount=1_000_000 | ||
) | ||
|
||
txn_group.sign_with_private_key(account_address, account_sk) | ||
txn_group.submit(algod, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from examples.v2.utils import get_algod | ||
from tinyman.governance.client import TinymanGovernanceTestnetClient | ||
|
||
from tinyman.governance.constants import TESTNET_TINY_ASSET_ID | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", | ||
} | ||
|
||
algod = get_algod() | ||
|
||
# Client | ||
governance_client = TinymanGovernanceTestnetClient( | ||
algod_client=algod, | ||
user_address=account["address"] | ||
) | ||
|
||
if not governance_client.asset_is_opted_in(TESTNET_TINY_ASSET_ID): | ||
txn_group = governance_client.prepare_asset_optin_transactions(TESTNET_TINY_ASSET_ID) | ||
txn_group.sign_with_private_key(address=account["address"], private_key=account["private_key"]) | ||
result = txn_group.submit(algod, wait=True) | ||
print("TXN:", result) | ||
|
||
print("Get some TINY token.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import time | ||
|
||
from examples.v2.utils import get_algod | ||
from tinyman.governance.client import TinymanGovernanceTestnetClient | ||
from tinyman.governance.constants import WEEK | ||
from tinyman.governance.vault.constants import MIN_LOCK_TIME | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", | ||
} | ||
|
||
algod = get_algod() | ||
|
||
# Client | ||
governance_client = TinymanGovernanceTestnetClient( | ||
algod_client=algod, | ||
user_address=account["address"] | ||
) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State before TXN:", account_state) | ||
|
||
end_timestamp_of_current_week = (int(time.time()) // WEEK + 1) * WEEK | ||
lock_end_timestamp = end_timestamp_of_current_week + MIN_LOCK_TIME | ||
|
||
# lock_end_timestamp = int(time.time()) + 100 | ||
|
||
txn_group = governance_client.prepare_create_lock_transactions( | ||
locked_amount=10_000_000, | ||
lock_end_time=lock_end_timestamp, | ||
) | ||
txn_group.sign_with_private_key(account["address"], account["private_key"]) | ||
txn_group.submit(algod, wait=True) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State after TXN:", account_state) | ||
|
||
tiny_power = governance_client.get_tiny_power() | ||
print("TINY POWER:", tiny_power) | ||
|
||
total_tiny_power = governance_client.get_total_tiny_power() | ||
print("Total TINY POWER:", total_tiny_power) | ||
print(f"User TINY Power %{(tiny_power / total_tiny_power) * 100}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from examples.v2.utils import get_algod | ||
from tinyman.governance.client import TinymanGovernanceTestnetClient | ||
|
||
from tinyman.governance.constants import WEEK | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", | ||
} | ||
|
||
algod = get_algod() | ||
|
||
# Client | ||
governance_client = TinymanGovernanceTestnetClient( | ||
algod_client=algod, | ||
user_address=account["address"] | ||
) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State before TXN:", account_state) | ||
|
||
new_lock_end_time = account_state.lock_end_time + 4 * WEEK | ||
txn_group = governance_client.prepare_extend_lock_end_time_transactions( | ||
new_lock_end_time=new_lock_end_time, | ||
) | ||
txn_group.sign_with_private_key(account["address"], account["private_key"]) | ||
txn_group.submit(algod, wait=True) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State after TXN:", account_state) | ||
|
||
tiny_power = governance_client.get_tiny_power() | ||
print("TINY POWER:", tiny_power) | ||
|
||
total_tiny_power = governance_client.get_total_tiny_power() | ||
print("Total TINY POWER:", total_tiny_power) | ||
print(f"User TINY Power %{(tiny_power / total_tiny_power) * 100}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from examples.v2.utils import get_algod | ||
from tinyman.governance.client import TinymanGovernanceTestnetClient | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", | ||
} | ||
|
||
algod = get_algod() | ||
|
||
# Client | ||
governance_client = TinymanGovernanceTestnetClient( | ||
algod_client=algod, | ||
user_address=account["address"] | ||
) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State before TXN:", account_state) | ||
|
||
txn_group = governance_client.prepare_increase_lock_amount_transactions( | ||
locked_amount=4000000000, | ||
) | ||
txn_group.sign_with_private_key(account["address"], account["private_key"]) | ||
txn_group.submit(algod, wait=True) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State after TXN:", account_state) | ||
|
||
tiny_power = governance_client.get_tiny_power() | ||
print("TINY POWER:", tiny_power) | ||
|
||
total_tiny_power = governance_client.get_total_tiny_power() | ||
print("Total TINY POWER:", total_tiny_power) | ||
print(f"User TINY Power %{(tiny_power / total_tiny_power) * 100}") |
39 changes: 39 additions & 0 deletions
39
examples/governance/04_increase_lock_amount_and_extend_lock_end_time.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from examples.v2.utils import get_algod | ||
from tinyman.governance.client import TinymanGovernanceTestnetClient | ||
|
||
from tinyman.governance.constants import WEEK | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", | ||
} | ||
|
||
algod = get_algod() | ||
|
||
# Client | ||
governance_client = TinymanGovernanceTestnetClient( | ||
algod_client=algod, | ||
user_address=account["address"] | ||
) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State before TXN:", account_state) | ||
|
||
txn_group = governance_client.prepare_increase_lock_amount_and_extend_lock_end_time_transactions( | ||
locked_amount=5_000_000_000, | ||
new_lock_end_time=account_state.lock_end_time + 4 * WEEK | ||
) | ||
txn_group.sign_with_private_key(account["address"], account["private_key"]) | ||
txn_group.submit(algod, wait=True) | ||
|
||
account_state = governance_client.fetch_account_state() | ||
print("Account State after TXN:", account_state) | ||
|
||
tiny_power = governance_client.get_tiny_power() | ||
print("TINY POWER:", tiny_power) | ||
|
||
total_tiny_power = governance_client.get_total_tiny_power() | ||
print("Total TINY POWER:", total_tiny_power) | ||
print(f"User TINY Power %{(tiny_power / total_tiny_power) * 100}") |
Oops, something went wrong.