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

[Feature] Multi Offer #135

Merged
merged 15 commits into from
Sep 23, 2022
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: E0BF7F59CE58E05A3CCC9A8C8E6EF9CA68F0E8E78030805F0A9B949BF534566A
source_digest: 9171A59A0F735B5531F80C357F850D2E91F7C8887F6DDE36390713DBDCD4C41E
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/abis/Offer/take_offer.abi
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/Offer.mv
Binary file not shown.
791 changes: 769 additions & 22 deletions build/StarcoinFramework/docs/Offer.md

Large diffs are not rendered by default.

Binary file modified build/StarcoinFramework/source_maps/Offer.mvsm
Binary file not shown.
58 changes: 49 additions & 9 deletions integration-tests/offer/offer.exp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
processed 10 tasks
processed 17 tasks

task 4 'run'. lines 9-32:
task 4 'run'. lines 9-31:
{
"gas_used": 87526,
"gas_used": 140695,
"status": "Executed"
}

task 5 'run'. lines 36-49:
task 5 'run'. lines 35-47:
{
"gas_used": 25951,
"gas_used": 80018,
"status": {
"MoveAbort": {
"location": {
Expand All @@ -22,9 +22,9 @@ task 5 'run'. lines 36-49:
}
}

task 7 'run'. lines 53-65:
task 7 'run'. lines 51-63:
{
"gas_used": 26009,
"gas_used": 38916,
"status": {
"MoveAbort": {
"location": {
Expand All @@ -38,8 +38,48 @@ task 7 'run'. lines 53-65:
}
}

task 9 'run'. lines 69-82:
task 9 'run'. lines 67-79:
{
"gas_used": 92321,
"gas_used": 146388,
"status": "Executed"
}

task 10 'run'. lines 82-103:
{
"gas_used": 258865,
"status": "Executed"
}

task 11 'run'. lines 105-117:
{
"gas_used": 40121,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "Offer"
}
},
"abort_code": "26117"
}
}
}

task 13 'run'. lines 121-145:
{
"gas_used": 155351,
"status": "Executed"
}

task 14 'run'. lines 147-159:
{
"gas_used": 106491,
"status": "Executed"
}

task 16 'run'. lines 163-177:
{
"gas_used": 187043,
"status": "Executed"
}
103 changes: 99 additions & 4 deletions integration-tests/offer/offer.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ script {
assert!(Offer::address_of<Token<STC>>(Signer::address_of(&account)) == @bob, 1002);
}
}

// check: EXECUTED

//! block-prologue
Expand All @@ -45,10 +44,9 @@ script {
Account::deposit_to_self(&account, token);
}
}

// check: "Keep(ABORTED { code: 26117"

//# block --author alice
//# block --author alice --timestamp 86400000

//# run --signers carol
script {
Expand All @@ -64,7 +62,7 @@ script {
}
// check: "Keep(ABORTED { code: 25863"

//# block --author alice
//# block --author alice --timestamp 86405000

//# run --signers bob
script {
Expand All @@ -78,5 +76,102 @@ script {
Account::deposit_to_self(&account, token);
}
}
// check: EXECUTED


//# run --signers alice
script {
use StarcoinFramework::Account;
use StarcoinFramework::Offer;
use StarcoinFramework::STC::STC;
use StarcoinFramework::Signer;
use StarcoinFramework::Token::Token;

fun create_offer_v2(account: signer) {
let token = Account::withdraw<STC>(&account, 10000);
Offer::create_v2(&account, token, @bob, 5);
let token = Account::withdraw<STC>(&account, 10000);
Offer::create_v2(&account, token, @bob, 10);
let token = Account::withdraw<STC>(&account, 10000);
Offer::create(&account, token, @bob, 10);
// test Offer::exists_at_v2
assert!(Offer::exists_at_v2<Token<STC>>(Signer::address_of(&account)), 1001);
// test Offer::address_of_v2
assert!(Offer::address_of_v2<Token<STC>>(Signer::address_of(&account), 0) == @bob, 1002);
}
}
// check: EXECUTED

//# run --signers bob
script {
use StarcoinFramework::Account;
use StarcoinFramework::Offer;
use StarcoinFramework::Token::Token;
use StarcoinFramework::STC::STC;

fun redeem_offer_v2(account: signer) {
let token = Offer::redeem_v2<Token<STC>>(&account, @alice, 0);
jolestar marked this conversation as resolved.
Show resolved Hide resolved
Account::deposit_to_self(&account, token);
}
}
// check: "Keep(ABORTED { code: 26117"

//# block --author alice --timestamp 86410000

//# run --signers carol
script {
use StarcoinFramework::Offer;
use StarcoinFramework::Token::Token;
use StarcoinFramework::Vector;
use StarcoinFramework::Option;
use StarcoinFramework::STC::STC;

fun redeem_offer_v2(_account: signer) {
let op_offer_infos = Offer::get_offers_infos<Token<STC>>(@alice);
assert!(Option::is_some(&op_offer_infos), 101);
let offer_infos = Option::destroy_some(op_offer_infos);
let offers_length = Offer::get_offers_length<Token<STC>>(@alice);
assert!(Vector::length(&offer_infos) == 3, 102);
assert!(offers_length == 3,103);
let ( for, time_lock) = Offer::unpack_offer_info(Vector::remove(&mut offer_infos, 0));
assert!(for == @bob, 104);
assert!(time_lock == 86410, 105);

let op_idx = Offer::find_offer<Token<STC>>(@alice, @bob);
assert!(Option::is_some(&op_idx), 106);
assert!(Option::destroy_some(op_idx) == 0, 107);
}
}
// check: EXECUTED

//# run --signers bob
script {
use StarcoinFramework::Account;
use StarcoinFramework::Offer;
use StarcoinFramework::Token::Token;
use StarcoinFramework::STC::STC;

fun redeem_offer_v2(account: signer) {
let token = Offer::redeem_v2<Token<STC>>(&account, @alice, 0);
Account::deposit_to_self(&account, token);
}
}
// check: EXECUTED

//# block --author alice --timestamp 7862415000

//# run --signers alice
script {
use StarcoinFramework::Account;
use StarcoinFramework::Offer;
use StarcoinFramework::Token::Token;
use StarcoinFramework::STC::STC;

fun retake_offer(account: signer) {
let token = Offer::retake<Token<STC>>(&account, 1);
Account::deposit_to_self(&account, token);
let token = Offer::retake<Token<STC>>(&account, 0);
Account::deposit_to_self(&account, token);
}
}
// check: EXECUTED
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ task 2 'run'. lines 5-16:

task 4 'run'. lines 21-29:
{
"gas_used": 175833,
"gas_used": 198724,
"status": "Executed"
}

task 6 'run'. lines 35-45:
{
"gas_used": 40838,
"gas_used": 94617,
"status": "Executed"
}

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/treasury/split_linear_cap.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ task 2 'run'. lines 7-23:

task 4 'run'. lines 26-45:
{
"gas_used": 169006,
"gas_used": 191897,
"status": "Executed"
}

task 6 'run'. lines 48-59:
{
"gas_used": 43346,
"gas_used": 97125,
"status": "Executed"
}
Loading