-
Notifications
You must be signed in to change notification settings - Fork 54
/
legacy.rs
140 lines (132 loc) · 4.85 KB
/
legacy.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! This module captures all the code needed to migrate from previous version.
use std::collections::HashMap;
use near_sdk::collections::{UnorderedMap, Vector, LookupMap, UnorderedSet};
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{AccountId, Balance, StorageUsage};
use crate::account_deposit::{Account, VAccount};
use crate::{StorageKey, VUnitShareCumulativeInfo};
use crate::pool::Pool;
use crate::RunningState;
/// Account deposits information and storage cost.
#[derive(BorshSerialize, BorshDeserialize, Default, Clone)]
pub struct AccountV1 {
/// Native NEAR amount sent to the exchange.
/// Used for storage right now, but in future can be used for trading as well.
pub near_amount: Balance,
/// Amounts of various tokens deposited to this account.
pub tokens: HashMap<AccountId, Balance>,
pub storage_used: StorageUsage,
}
impl AccountV1 {
pub fn into_current(&self, account_id: &AccountId) -> Account {
Account {
near_amount: self.near_amount,
legacy_tokens: self.tokens.clone(),
tokens: UnorderedMap::new(StorageKey::AccountTokens {
account_id: account_id.clone(),
}),
storage_used: self.storage_used,
shadow_records: UnorderedMap::new(StorageKey::ShadowRecord {
account_id: account_id.clone(),
})
}
}
}
#[derive(BorshSerialize, BorshDeserialize)]
pub struct AccountV2 {
/// Native NEAR amount sent to the exchange.
/// Used for storage right now, but in future can be used for trading as well.
pub near_amount: Balance,
/// Amounts of various tokens deposited to this account.
pub legacy_tokens: HashMap<AccountId, Balance>,
pub tokens: UnorderedMap<AccountId, Balance>,
pub storage_used: StorageUsage,
}
impl AccountV2 {
pub fn into_current(self, account_id: &AccountId) -> Account {
let AccountV2 {
near_amount,
legacy_tokens,
tokens,
storage_used
} = self;
Account {
near_amount,
legacy_tokens,
tokens,
storage_used,
shadow_records: UnorderedMap::new(StorageKey::ShadowRecord {
account_id: account_id.clone(),
})
}
}
}
#[derive(BorshDeserialize)]
pub struct ContractV1 {
/// Account of the owner.
pub owner_id: AccountId,
/// Exchange fee, that goes to exchange itself (managed by governance).
pub exchange_fee: u32,
/// Referral fee, that goes to referrer in the call.
pub referral_fee: u32,
/// List of all the pools.
pub pools: Vector<Pool>,
/// Accounts registered, keeping track all the amounts deposited, storage and more.
pub accounts: LookupMap<AccountId, VAccount>,
/// Set of whitelisted tokens by "owner".
pub whitelisted_tokens: UnorderedSet<AccountId>,
/// Set of guardians.
pub guardians: UnorderedSet<AccountId>,
/// Running state
pub state: RunningState,
/// Set of frozenlist tokens
pub frozen_tokens: UnorderedSet<AccountId>,
}
#[derive(BorshSerialize, BorshDeserialize)]
pub struct ContractV2 {
/// Account of the owner.
pub owner_id: AccountId,
/// Admin fee rate in total fee.
pub admin_fee_bps: u32,
/// List of all the pools.
pub pools: Vector<Pool>,
/// Accounts registered, keeping track all the amounts deposited, storage and more.
pub accounts: LookupMap<AccountId, VAccount>,
/// Set of whitelisted tokens by "owner".
pub whitelisted_tokens: UnorderedSet<AccountId>,
/// Set of guardians.
pub guardians: UnorderedSet<AccountId>,
/// Running state
pub state: RunningState,
/// Set of frozenlist tokens
pub frozen_tokens: UnorderedSet<AccountId>,
/// Map of referrals
pub referrals: UnorderedMap<AccountId, u32>,
}
#[derive(BorshSerialize, BorshDeserialize)]
pub struct ContractV3 {
/// Account of the owner.
pub owner_id: AccountId,
/// Account of the boost_farm contract.
pub boost_farm_id: AccountId,
/// Account of the burrowland contract.
pub burrowland_id: AccountId,
/// Admin fee rate in total fee.
pub admin_fee_bps: u32,
/// List of all the pools.
pub pools: Vector<Pool>,
/// Accounts registered, keeping track all the amounts deposited, storage and more.
pub accounts: LookupMap<AccountId, VAccount>,
/// Set of whitelisted tokens by "owner".
pub whitelisted_tokens: UnorderedSet<AccountId>,
/// Set of guardians.
pub guardians: UnorderedSet<AccountId>,
/// Running state
pub state: RunningState,
/// Set of frozenlist tokens
pub frozen_tokens: UnorderedSet<AccountId>,
/// Map of referrals
pub referrals: UnorderedMap<AccountId, u32>,
pub cumulative_info_record_interval_sec: u32,
pub unit_share_cumulative_infos: UnorderedMap<u64, VUnitShareCumulativeInfo>,
}