code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_referral_program.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package steps 17 18 import ( 19 "fmt" 20 "time" 21 22 referralcfg "code.vegaprotocol.io/vega/core/integration/steps/referral" 23 "code.vegaprotocol.io/vega/core/referral" 24 "code.vegaprotocol.io/vega/core/types" 25 vgcrypto "code.vegaprotocol.io/vega/libs/crypto" 26 27 "github.com/cucumber/godog" 28 ) 29 30 func TheReferralProgram(referralProgramConfig *referralcfg.Config, referralProgramEngine *referral.Engine, table *godog.Table) error { 31 row := parseReferralProgram(table) 32 33 benefitTiersConfigName := row.BenefitTiers() 34 benefitTiers, err := referralProgramConfig.BenefitTiersConfigs.Get(benefitTiersConfigName) 35 if err != nil { 36 return fmt.Errorf("could not load benefit tiers configuration %q: %w", benefitTiersConfigName, err) 37 } 38 39 stakingTiersConfigName := row.StakingTiers() 40 stakingTiers, err := referralProgramConfig.StakingTiersConfigs.Get(stakingTiersConfigName) 41 if err != nil { 42 return fmt.Errorf("could not load staking tiers configuration %q: %w", stakingTiersConfigName, err) 43 } 44 45 referralProgramEngine.UpdateProgram(&types.ReferralProgram{ 46 ID: vgcrypto.RandomHash(), 47 EndOfProgramTimestamp: row.EndOfProgram(), 48 WindowLength: row.WindowLength(), 49 BenefitTiers: benefitTiers, 50 StakingTiers: stakingTiers, 51 }) 52 53 return nil 54 } 55 56 func parseReferralProgram(table *godog.Table) parseReferralProgramTable { 57 row := StrictParseFirstRow(table, []string{ 58 "end of program", 59 "window length", 60 "benefit tiers", 61 "staking tiers", 62 }, []string{ 63 "decimal places", 64 "position decimal places", 65 }) 66 return parseReferralProgramTable{ 67 row: row, 68 } 69 } 70 71 type parseReferralProgramTable struct { 72 row RowWrapper 73 } 74 75 func (r parseReferralProgramTable) EndOfProgram() time.Time { 76 return r.row.MustTime("end of program") 77 } 78 79 func (r parseReferralProgramTable) WindowLength() uint64 { 80 return r.row.MustU64("window length") 81 } 82 83 func (r parseReferralProgramTable) BenefitTiers() string { 84 return r.row.MustStr("benefit tiers") 85 } 86 87 func (r parseReferralProgramTable) StakingTiers() string { 88 return r.row.MustStr("staking tiers") 89 }