CoreLedger Token Economy Operating System on ICP - DeFi, Notarization, Industry Use Cases

A while ago we started porting the CoreLedger Token Economy Operating System (TEOS) to Internet Computer.
In the second milestone of our grant we brought all on-chain logic into an ICP canister, including the patented Token WARP technology. You can find the documentation of the canister here.

The canister is here

Candid Interface can be found here

We are already using the Token WARP technology in a number of projects. Such as the redemption of Non-Fungible-Assets or the creation of a digital barter market.

If you want to try it out we have created a simple script.

init_vars() {
printf “Set variables…\n”
#variables needed for create_integration
INTEGRATION_ID=0
INTEGRATION_DEP_CODE=“0x12”

SUP_EXT_REF=0x42
LEDGER_ID=1

#Set Identity
#You need to create Identities upfront. Example:
#dfx identity new bob --storage-mode plaintext
#save the generated plaintext as variable...
DEFAULT_PRINCIPAL='(principal "ikze6-x7fno-rwwv6-qiq4v-dt6do-5wfss-qnn4d-crg6x-sq36k-7feso-fae")'
SUPER_PRINCIPAL='(principal "enelt-vu2ic-5z4vq-mt7jb-4lxpn-75hu7-2rm6l-akmq5-tlzog-st72l-cae")'
MEGA_PRINCIPAL='(principal "dimdt-vwpm3-tkwgu-c2nkv-txykr-atn2x-xras5-6xidt-wtti3-i4xr6-vqe")'
JOHN_PRINCIPAL='(principal "3sr6i-pockd-z3qay-cocbi-2in7x-q7ghc-zdyxt-yydcg-65zkw-3vxm6-qqe")'
BOB_PRINCIPAL='(principal "zdghm-x2htn-abrup-7oo44-kdr7w-a7hy5-q6yj3-z75mw-txdrs-2qvkq-vqe")'

}

Warp_1 (){
set +e
printf “\Warp_1: Warp with 1 hop, verify output…\n”

#########################################################################################

1. SET VARIABLES

#########################################################################################

#1.1 Set variables needed for ASSET CREATION
ASSET_ID_1=0xF94E2AD9DD5CBBC$RANDOM
UNIQUE_ASSET_ID_1="$ASSET_ID_1"000"$LEDGER_ID"
ASSET_ID_2=0xF94E2AD9DD5CBBC$RANDOM
UNIQUE_ASSET_ID_2="$ASSET_ID_2"000"$LEDGER_ID"
ASSET_HASH=0x9fd09c38c2a5ae0a0bcd617872b735e37909ccc05c956460be7d3d03d881a0dc 
BITWISE=false

#1.2 Set variables needed for SUPPLY CREATIOM
SUP_AMOUNT=100
SUP_EX_RATE=1000000000000000000000000000000000000			 			
TAKE_ALL=false
RECEIVER_ADDRESS=$BOB_PRINCIPAL
SUP_VALID_UNTIL=$(date -d "+10 days" +%s)000000000 #Today + 10 days (Sun Aug 1 00:00:00 CEST 2024 ->     1722463200000000000)
WARP_AMOUNT=100

#########################################################################################

2. CREATE ASSET

#########################################################################################

#2.1 Create and Activate two Assets and create Units for Identity "default" and "Bob"
dfx identity use default 	#Change identity to "default"
dfx canister call coreledger_backend led_base_activate_asset "($LEDGER_CONTRACT_ID, $ASSET_ID_1, $ASSET_HASH, $BITWISE, null)" #Create and activate Asset
dfx canister call coreledger_backend led_base_issue_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_1, 500)" #Create Units


dfx identity use bob 	#Change identity to "Bob"
dfx canister call coreledger_backend led_base_activate_asset "($LEDGER_CONTRACT_ID, $ASSET_ID_2, $ASSET_HASH, $BITWISE, null)" #Create and activate Asset
dfx canister call coreledger_backend led_base_issue_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_2, 500)" #Create Units

#########################################################################################

3. CREATE SUPPLY

#########################################################################################

tmp=$(dfx canister call coreledger_backend int_create_supply "(record { offered = $UNIQUE_ASSET_ID_2; desired = $UNIQUE_ASSET_ID_1; exchange_rate = $SUP_EX_RATE; max_amount = $SUP_AMOUNT; ext_ref = $SUP_EXT_REF; take_all = $TAKE_ALL; valid_until = $SUP_VALID_UNTIL })") #Create Supply
SUPPLY_ID=$(echo ${tmp} | cut -d ' ' -f 11)
dfx canister call coreledger_backend int_get_supply $SUPPLY_ID #Get SupplyID

#########################################################################################

4. WARP-TRADE

#########################################################################################

dfx identity use default #Change identity to "default"

#Check Balances of Assets for each User BEFORE Warp-Trade
printf "balance before warp:\n"
balance=$(dfx canister call coreledger_backend int_get_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_1)")
echo "int_get_tokens - Asset 1: " $balance

balance=$(dfx canister call coreledger_backend int_get_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_2)")
echo "int_get_tokens - Asset 2: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_1, $DEFAULT_PRINCIPAL)")
echo "Asset 1 - default user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_2, $DEFAULT_PRINCIPAL)")
echo "Asset 2 - default user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_1, $RECEIVER_ADDRESS)")
echo "Asset 1 - bob user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_2, $RECEIVER_ADDRESS)")
echo "Asset 2 - bob user: " $balance


#Run Trade
echo "run trade:" 
tmp=$(dfx canister call coreledger_backend int_run_warp "(record { input_amount = $WARP_AMOUNT; supplies = vec { $SUPPLY_ID } })") #Run WARP
WARP_TX_ID=$(echo ${tmp} | cut -d ' ' -f 6) #Get TransactionID of WARP


#Check Balances of Assets for each User AFTER Warp-Trade	
printf "balance after warp:\n"
balance=$(dfx canister call coreledger_backend int_get_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_1)")
echo "int_get_tokens - Asset 1: " $balance

balance=$(dfx canister call coreledger_backend int_get_tokens "($LEDGER_CONTRACT_ID, $ASSET_ID_2)")
echo "int_get_tokens - Asset 2: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_1, $DEFAULT_PRINCIPAL)")
echo "Asset 1 - default user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_2, $DEFAULT_PRINCIPAL)")
echo "Asset 2 - default user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_1, $RECEIVER_ADDRESS)")
echo "Asset 1 - bob user: " $balance

balance=$(dfx canister call coreledger_backend int_get_balance "($UNIQUE_ASSET_ID_2, $RECEIVER_ADDRESS)")
echo "Asset 2 - default user: " $balance

#Check Supply amount
balance=$(dfx canister call coreledger_backend int_get_supply $SUPPLY_ID)
echo "Supply amount was reduced: " $balance

}