Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testnet release: fixed config setting, and buying and selling ram algorithm #125

Merged
merged 10 commits into from
Nov 29, 2024
Merged
12 changes: 6 additions & 6 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ jobs:
run: ./contracts/tonomy/build.sh local

- name: Add eosio.boot contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.boot
path: ./contracts/eosio.boot

- name: Add eosio.bios contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.bios
path: ./contracts/eosio.bios

- name: Add built contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: tonomy
path: ./contracts/tonomy
Expand All @@ -55,7 +55,7 @@ jobs:

steps:
- name: Get built contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: tonomy
path: contracts/tonomy
Expand All @@ -78,13 +78,13 @@ jobs:
- uses: actions/checkout@v3

- name: Get eosio.boot contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.boot
path: contracts/eosio.boot

- name: Get eosio.bios contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.bios
path: contracts/eosio.bios
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/deploy-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ jobs:
run: ./contracts/tonomy/build.sh local

- name: Add eosio.boot contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.boot
path: ./contracts/eosio.boot

- name: Add eosio.bios contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.bios
path: ./contracts/eosio.bios

- name: Add built contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: tonomy
path: ./contracts/tonomy
Expand All @@ -56,7 +56,7 @@ jobs:

steps:
- name: Get built contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: tonomy
path: contracts/tonomy
Expand All @@ -79,13 +79,13 @@ jobs:
- uses: actions/checkout@v3

- name: Get eosio.boot contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.boot
path: contracts/eosio.boot

- name: Get eosio.bios contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.bios
path: contracts/eosio.bios
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ jobs:
run: ./contracts/tonomy/build.sh local

- name: Add eosio.boot contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.boot
path: ./contracts/eosio.boot

- name: Add eosio.bios contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: eosio.bios
path: ./contracts/eosio.bios

- name: Add built contracts to artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: tonomy
path: ./contracts/tonomy
Expand All @@ -49,13 +49,13 @@ jobs:
- uses: actions/checkout@v3

- name: Get eosio.boot contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.boot
path: contracts/eosio.boot

- name: Get eosio.bios contracts from cache
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: eosio.bios
path: contracts/eosio.bios
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"git.branchProtection": [
"master",
"main",
"testnet",
"development"
],
}
18 changes: 11 additions & 7 deletions contracts/tonomy/src/tonomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ namespace tonomysystem
else
{
// Singleton does not exist, set the values and also set other values to 0
config = resource_config{ram_price, ram_fee, total_ram_available, 0, 0, 0};
config = resource_config{ram_fee, ram_price, total_ram_available, 0, 0, 0};
}

// Save the modified or new config back to the singleton
Expand Down Expand Up @@ -428,8 +428,8 @@ namespace tonomysystem
// Read values from the table
double ram_price = config.ram_price;
double ram_fee = (1.0 + config.ram_fee);
uint64_t ram_purchase = (ram_price / ram_fee) * quant.amount;

double amount = static_cast<double>(quant.amount) / pow(10, quant.symbol.precision());
uint64_t ram_purchase = amount * ram_price / ram_fee;
eosio::check(config.total_ram_available >= config.total_ram_used + ram_purchase, "Not enough RAM available");

// modify the values and save them back to the table,
Expand All @@ -439,6 +439,7 @@ namespace tonomysystem
// Allocate the RAM
int64_t myRAM, myNET, myCPU;
eosio::get_resource_limits(app, myRAM, myNET, myCPU);
eosio::print("RAM: ", myRAM, " --> ", myRAM + ram_purchase);
eosio::set_resource_limits(app, myRAM + ram_purchase, myNET, myNET);

eosio::action(permission_level{dao_owner, "active"_n},
Expand Down Expand Up @@ -472,17 +473,20 @@ namespace tonomysystem
// Read values from the table
double ram_price = config.ram_price;
double ram_fee = (1.0 + config.ram_fee);
uint64_t ram_sold = ram_price * ram_fee * quant.amount;
double amount = static_cast<double>(quant.amount) / pow(10, quant.symbol.precision());
uint64_t ram_sold = ram_price * ram_fee * amount;

eosio::check(config.total_ram_used >= quant.amount, "Not enough RAM to sell");
// Modify the values and save them back to the table
config.total_ram_used -= quant.amount;
config.total_ram_used -= ram_sold;
eosio::check(config.total_ram_used >= 0, "Cannot have less than 0 RAM used");
resource_config_singleton.set(config, get_self());

// Deallocate the RAM
int64_t myRAM, myNET, myCPU;
eosio::get_resource_limits(app, myRAM, myNET, myCPU);
eosio::set_resource_limits(app, myRAM - quant.amount, myNET, myNET);
eosio::print("RAM: ", myRAM, " --> ", myRAM - ram_sold);
eosio::check(myRAM - ram_sold >= 0, "Account cannot have less than 0 RAM");
eosio::set_resource_limits(app, myRAM - ram_sold, myNET, myNET);

// Transfer token and sell RAM
// TODO should buy and sell from proxy counttract, otherwise cannot autorize to sell ram
Expand Down