|
| 1 | +package currency |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/code-payments/code-server/pkg/solana/currencycreator" |
| 8 | +) |
| 9 | + |
| 10 | +type ExchangeRateRecord struct { |
| 11 | + Id uint64 |
| 12 | + Time time.Time |
| 13 | + Rate float64 |
| 14 | + Symbol string |
| 15 | +} |
| 16 | + |
| 17 | +type MultiRateRecord struct { |
| 18 | + Time time.Time |
| 19 | + Rates map[string]float64 |
| 20 | +} |
| 21 | + |
| 22 | +type MetadataRecord struct { |
| 23 | + Id uint64 |
| 24 | + |
| 25 | + Name string |
| 26 | + Symbol string |
| 27 | + |
| 28 | + Seed string |
| 29 | + |
| 30 | + Authority string |
| 31 | + |
| 32 | + Mint string |
| 33 | + MintBump uint8 |
| 34 | + Decimals uint8 |
| 35 | + |
| 36 | + CurrencyConfig string |
| 37 | + CurrencyConfigBump uint8 |
| 38 | + |
| 39 | + LiquidityPool string |
| 40 | + LiquidityPoolBump uint8 |
| 41 | + |
| 42 | + VaultMint string |
| 43 | + VaultMintBump uint8 |
| 44 | + |
| 45 | + VaultCore string |
| 46 | + VaultCoreBump uint8 |
| 47 | + |
| 48 | + FeesMint string |
| 49 | + BuyFeeBps uint16 |
| 50 | + |
| 51 | + FeesCore string |
| 52 | + SellFeeBps uint16 |
| 53 | + |
| 54 | + CreatedBy string |
| 55 | + CreatedAt time.Time |
| 56 | +} |
| 57 | + |
| 58 | +func (m *MetadataRecord) Validate() error { |
| 59 | + if len(m.Name) == 0 { |
| 60 | + return errors.New("name is required") |
| 61 | + } |
| 62 | + |
| 63 | + if len(m.Symbol) == 0 { |
| 64 | + return errors.New("symbol is required") |
| 65 | + } |
| 66 | + |
| 67 | + if len(m.Seed) == 0 { |
| 68 | + return errors.New("seed is required") |
| 69 | + } |
| 70 | + |
| 71 | + if len(m.Authority) == 0 { |
| 72 | + return errors.New("authority is required") |
| 73 | + } |
| 74 | + |
| 75 | + if len(m.Mint) == 0 { |
| 76 | + return errors.New("mint is required") |
| 77 | + } |
| 78 | + |
| 79 | + if m.MintBump == 0 { |
| 80 | + return errors.New("mint bump is required") |
| 81 | + } |
| 82 | + |
| 83 | + if m.Decimals != currencycreator.DefaultMintDecimals { |
| 84 | + return errors.New("invalid mint decimals") |
| 85 | + } |
| 86 | + |
| 87 | + if len(m.CurrencyConfig) == 0 { |
| 88 | + return errors.New("currency config is required") |
| 89 | + } |
| 90 | + |
| 91 | + if m.CurrencyConfigBump == 0 { |
| 92 | + return errors.New("currency config bump is required") |
| 93 | + } |
| 94 | + |
| 95 | + if len(m.LiquidityPool) == 0 { |
| 96 | + return errors.New("liquidity pool is required") |
| 97 | + } |
| 98 | + |
| 99 | + if m.LiquidityPoolBump == 0 { |
| 100 | + return errors.New("liquidity pool bump is required") |
| 101 | + } |
| 102 | + |
| 103 | + if len(m.VaultMint) == 0 { |
| 104 | + return errors.New("vault mint is required") |
| 105 | + } |
| 106 | + |
| 107 | + if m.VaultMintBump == 0 { |
| 108 | + return errors.New("vault mint bump is required") |
| 109 | + } |
| 110 | + |
| 111 | + if len(m.VaultCore) == 0 { |
| 112 | + return errors.New("vault core is required") |
| 113 | + } |
| 114 | + |
| 115 | + if m.VaultCoreBump == 0 { |
| 116 | + return errors.New("vault core bump is required") |
| 117 | + } |
| 118 | + |
| 119 | + if len(m.FeesMint) == 0 { |
| 120 | + return errors.New("fees mint is required") |
| 121 | + } |
| 122 | + |
| 123 | + if m.BuyFeeBps != currencycreator.DefaultBuyFeeBps { |
| 124 | + return errors.New("invalid buy fee bps") |
| 125 | + } |
| 126 | + |
| 127 | + if len(m.Name) == 0 { |
| 128 | + return errors.New("fees core is required") |
| 129 | + } |
| 130 | + |
| 131 | + if m.SellFeeBps != currencycreator.DefaultSellFeeBps { |
| 132 | + return errors.New("invalid buy sell bps") |
| 133 | + } |
| 134 | + |
| 135 | + if len(m.CreatedBy) == 0 { |
| 136 | + return errors.New("created by is required") |
| 137 | + } |
| 138 | + |
| 139 | + if m.CreatedAt.IsZero() { |
| 140 | + return errors.New("creation timestamp is required") |
| 141 | + } |
| 142 | + |
| 143 | + return nil |
| 144 | +} |
| 145 | + |
| 146 | +func (m *MetadataRecord) Clone() *MetadataRecord { |
| 147 | + return &MetadataRecord{ |
| 148 | + Id: m.Id, |
| 149 | + |
| 150 | + Name: m.Name, |
| 151 | + Symbol: m.Symbol, |
| 152 | + |
| 153 | + Seed: m.Seed, |
| 154 | + |
| 155 | + Authority: m.Authority, |
| 156 | + |
| 157 | + Mint: m.Mint, |
| 158 | + MintBump: m.MintBump, |
| 159 | + Decimals: m.Decimals, |
| 160 | + |
| 161 | + CurrencyConfig: m.CurrencyConfig, |
| 162 | + CurrencyConfigBump: m.CurrencyConfigBump, |
| 163 | + |
| 164 | + LiquidityPool: m.LiquidityPool, |
| 165 | + LiquidityPoolBump: m.LiquidityPoolBump, |
| 166 | + |
| 167 | + VaultMint: m.VaultMint, |
| 168 | + VaultMintBump: m.VaultMintBump, |
| 169 | + |
| 170 | + VaultCore: m.VaultCore, |
| 171 | + VaultCoreBump: m.VaultCoreBump, |
| 172 | + |
| 173 | + FeesMint: m.FeesMint, |
| 174 | + BuyFeeBps: m.BuyFeeBps, |
| 175 | + |
| 176 | + FeesCore: m.FeesCore, |
| 177 | + SellFeeBps: m.SellFeeBps, |
| 178 | + |
| 179 | + CreatedBy: m.CreatedBy, |
| 180 | + CreatedAt: m.CreatedAt, |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +func (m *MetadataRecord) CopyTo(dst *MetadataRecord) { |
| 185 | + dst.Id = m.Id |
| 186 | + |
| 187 | + dst.Name = m.Name |
| 188 | + dst.Symbol = m.Symbol |
| 189 | + |
| 190 | + dst.Seed = m.Seed |
| 191 | + |
| 192 | + dst.Authority = m.Authority |
| 193 | + |
| 194 | + dst.Mint = m.Mint |
| 195 | + dst.MintBump = m.MintBump |
| 196 | + dst.Decimals = m.Decimals |
| 197 | + |
| 198 | + dst.CurrencyConfig = m.CurrencyConfig |
| 199 | + dst.CurrencyConfigBump = m.CurrencyConfigBump |
| 200 | + |
| 201 | + dst.LiquidityPool = m.LiquidityPool |
| 202 | + dst.LiquidityPoolBump = m.LiquidityPoolBump |
| 203 | + |
| 204 | + dst.VaultMint = m.VaultMint |
| 205 | + dst.VaultMintBump = m.VaultMintBump |
| 206 | + |
| 207 | + dst.VaultCore = m.VaultCore |
| 208 | + dst.VaultCoreBump = m.VaultCoreBump |
| 209 | + |
| 210 | + dst.FeesMint = m.FeesMint |
| 211 | + dst.BuyFeeBps = m.BuyFeeBps |
| 212 | + |
| 213 | + dst.FeesCore = m.FeesCore |
| 214 | + dst.SellFeeBps = m.SellFeeBps |
| 215 | + |
| 216 | + dst.CreatedBy = m.CreatedBy |
| 217 | + dst.CreatedAt = m.CreatedAt |
| 218 | +} |
| 219 | + |
| 220 | +type ReserveRecord struct { |
| 221 | + Id uint64 |
| 222 | + Mint string |
| 223 | + SupplyFromBonding uint64 |
| 224 | + CoreMintLocked uint64 |
| 225 | + Time time.Time |
| 226 | +} |
| 227 | + |
| 228 | +func (m *ReserveRecord) Validate() error { |
| 229 | + if len(m.Mint) == 0 { |
| 230 | + return errors.New("mint is required") |
| 231 | + } |
| 232 | + |
| 233 | + if m.Time.IsZero() { |
| 234 | + return errors.New("timestamp is required") |
| 235 | + } |
| 236 | + |
| 237 | + return nil |
| 238 | +} |
| 239 | + |
| 240 | +func (m *ReserveRecord) Clone() *ReserveRecord { |
| 241 | + return &ReserveRecord{ |
| 242 | + Id: m.Id, |
| 243 | + Mint: m.Mint, |
| 244 | + SupplyFromBonding: m.SupplyFromBonding, |
| 245 | + CoreMintLocked: m.CoreMintLocked, |
| 246 | + Time: m.Time, |
| 247 | + } |
| 248 | +} |
| 249 | + |
| 250 | +func (m *ReserveRecord) CopyTo(dst *ReserveRecord) { |
| 251 | + dst.Id = m.Id |
| 252 | + dst.Mint = m.Mint |
| 253 | + dst.SupplyFromBonding = m.SupplyFromBonding |
| 254 | + dst.CoreMintLocked = m.CoreMintLocked |
| 255 | + dst.Time = m.Time |
| 256 | +} |
0 commit comments