Skip to content
Merged
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/aws/aws-sdk-go-v2 v0.17.0
github.com/code-payments/code-vm-indexer v1.2.0
github.com/code-payments/ocp-protobuf-api v0.2.0
github.com/code-payments/ocp-protobuf-api v0.2.1
github.com/emirpasic/gods v1.12.0
github.com/envoyproxy/protoc-gen-validate v1.2.1
github.com/golang/protobuf v1.5.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0=
github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8=
github.com/code-payments/ocp-protobuf-api v0.2.0 h1:XLDeVdPDjy+Y0xnvcu1KHf6JelWc4IgDQ4SOCRBJvzE=
github.com/code-payments/ocp-protobuf-api v0.2.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/code-payments/ocp-protobuf-api v0.2.1 h1:w/S9t8sfQ1e7Ziw1K9gVvE7WchwC1D3AWD3E8ZQg8Ts=
github.com/code-payments/ocp-protobuf-api v0.2.1/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
12 changes: 0 additions & 12 deletions ocp/common/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,6 @@ type LaunchpadCurrencyAccounts struct {
VaultBaseBump uint8
VaultMint *Account
VaultMintBump uint8
FeesBase *Account
FeesMint *Account
}

func GetLaunchpadCurrencyAccounts(metadataRecord *currency.MetadataRecord) (*LaunchpadCurrencyAccounts, error) {
Expand All @@ -568,14 +566,6 @@ func GetLaunchpadCurrencyAccounts(metadataRecord *currency.MetadataRecord) (*Lau
if err != nil {
return nil, err
}
feesBase, err := NewAccountFromPublicKeyString(metadataRecord.FeesCore)
if err != nil {
return nil, err
}
feesMint, err := NewAccountFromPublicKeyString(metadataRecord.FeesMint)
if err != nil {
return nil, err
}
return &LaunchpadCurrencyAccounts{
Mint: mint,
CurrencyConfig: currencyConfig,
Expand All @@ -586,8 +576,6 @@ func GetLaunchpadCurrencyAccounts(metadataRecord *currency.MetadataRecord) (*Lau
VaultBaseBump: metadataRecord.VaultCoreBump,
VaultMint: vaultMint,
VaultMintBump: metadataRecord.VaultMintBump,
FeesBase: feesBase,
FeesMint: feesMint,
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions ocp/currency/usd_market_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"time"

currency_lib "github.com/code-payments/ocp-server/currency"
"github.com/code-payments/ocp-server/ocp/common"
ocp_data "github.com/code-payments/ocp-server/ocp/data"
currency_lib "github.com/code-payments/ocp-server/currency"
"github.com/code-payments/ocp-server/solana/currencycreator"
)

Expand All @@ -32,10 +32,10 @@ func CalculateUsdMarketValue(ctx context.Context, data ocp_data.Provider, mint *
}

coreMintSellValueInQuarks, _ := currencycreator.EstimateSell(&currencycreator.EstimateSellArgs{
SellAmountInQuarks: quarks,
CurrentValueInQuarks: reserveRecord.CoreMintLocked,
ValueMintDecimals: uint8(common.CoreMintDecimals),
SellFeeBps: 0,
CurrentSupplyInQuarks: reserveRecord.SupplyFromBonding,
SellAmountInQuarks: quarks,
ValueMintDecimals: uint8(common.CoreMintDecimals),
SellFeeBps: 0,
})

coreMintSellValueInUnits := float64(coreMintSellValueInQuarks) / float64(coreMintQuarksPerUnit)
Expand Down
8 changes: 4 additions & 4 deletions ocp/currency/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ func validateCurrencyLaunchpadClientExchangeData(ctx context.Context, log *zap.L

// How much core mint would be received for a sell against the currency creator program?
coreMintSellValueInQuarks, _ := currencycreator.EstimateSell(&currencycreator.EstimateSellArgs{
SellAmountInQuarks: proto.Quarks,
CurrentValueInQuarks: reserveRecord.CoreMintLocked,
ValueMintDecimals: uint8(common.CoreMintDecimals),
SellFeeBps: 0,
CurrentSupplyInQuarks: reserveRecord.SupplyFromBonding,
SellAmountInQuarks: proto.Quarks,
ValueMintDecimals: uint8(common.CoreMintDecimals),
SellFeeBps: 0,
})

// Given the sell value, does it align with the native amount in the target currency
Expand Down
20 changes: 0 additions & 20 deletions ocp/data/currency/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ type MetadataRecord struct {
VaultCore string
VaultCoreBump uint8

FeesMint string
BuyFeeBps uint16

FeesCore string
SellFeeBps uint16

Alt string
Expand Down Expand Up @@ -128,14 +124,6 @@ func (m *MetadataRecord) Validate() error {
return errors.New("vault core bump is required")
}

if len(m.FeesMint) == 0 {
return errors.New("fees mint is required")
}

if m.BuyFeeBps != currencycreator.DefaultBuyFeeBps {
return errors.New("invalid buy fee bps")
}

if len(m.Name) == 0 {
return errors.New("fees core is required")
}
Expand Down Expand Up @@ -188,10 +176,6 @@ func (m *MetadataRecord) Clone() *MetadataRecord {
VaultCore: m.VaultCore,
VaultCoreBump: m.VaultCoreBump,

FeesMint: m.FeesMint,
BuyFeeBps: m.BuyFeeBps,

FeesCore: m.FeesCore,
SellFeeBps: m.SellFeeBps,

Alt: m.Alt,
Expand Down Expand Up @@ -229,10 +213,6 @@ func (m *MetadataRecord) CopyTo(dst *MetadataRecord) {
dst.VaultCore = m.VaultCore
dst.VaultCoreBump = m.VaultCoreBump

dst.FeesMint = m.FeesMint
dst.BuyFeeBps = m.BuyFeeBps

dst.FeesCore = m.FeesCore
dst.SellFeeBps = m.SellFeeBps

dst.Alt = m.Alt
Expand Down
25 changes: 5 additions & 20 deletions ocp/data/currency/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/jmoiron/sqlx"

"github.com/code-payments/ocp-server/ocp/data/currency"
q "github.com/code-payments/ocp-server/database/query"
"github.com/code-payments/ocp-server/ocp/data/currency"

pgutil "github.com/code-payments/ocp-server/database/postgres"
)
Expand Down Expand Up @@ -76,10 +76,6 @@ type metadataModel struct {
VaultCore string `db:"vault_core"`
VaultCoreBump uint8 `db:"vault_core_bump"`

FeesMint string `db:"fees_mint"`
BuyFeeBps uint16 `db:"buy_fee_bps"`

FeesCore string `db:"fees_core"`
SellFeeBps uint16 `db:"sell_fee_bps"`

Alt string `db:"alt"`
Expand Down Expand Up @@ -121,10 +117,6 @@ func toMetadataModel(obj *currency.MetadataRecord) (*metadataModel, error) {
VaultCore: obj.VaultCore,
VaultCoreBump: obj.VaultCoreBump,

FeesMint: obj.FeesMint,
BuyFeeBps: obj.BuyFeeBps,

FeesCore: obj.FeesCore,
SellFeeBps: obj.SellFeeBps,

Alt: obj.Alt,
Expand Down Expand Up @@ -163,10 +155,6 @@ func fromMetadataModel(obj *metadataModel) *currency.MetadataRecord {
VaultCore: obj.VaultCore,
VaultCoreBump: obj.VaultCoreBump,

FeesMint: obj.FeesMint,
BuyFeeBps: obj.BuyFeeBps,

FeesCore: obj.FeesCore,
SellFeeBps: obj.SellFeeBps,

Alt: obj.Alt,
Expand Down Expand Up @@ -258,9 +246,9 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error {
return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error {
err := tx.QueryRowxContext(ctx,
`INSERT INTO `+metadataTableName+`
(name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24)
RETURNING id, name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at`,
(name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
RETURNING id, name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at`,
m.Name,
m.Symbol,
m.Description,
Expand All @@ -278,9 +266,6 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error {
m.VaultMintBump,
m.VaultCore,
m.VaultCoreBump,
m.FeesMint,
m.BuyFeeBps,
m.FeesCore,
m.SellFeeBps,
m.Alt,
m.CreatedBy,
Expand Down Expand Up @@ -362,7 +347,7 @@ func dbGetAllExchangeRatesForRange(ctx context.Context, db *sqlx.DB, symbol stri
func dbGetMetadataByMint(ctx context.Context, db *sqlx.DB, mint string) (*metadataModel, error) {
res := &metadataModel{}
err := db.GetContext(ctx, res,
`SELECT id, name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, alt, created_by, created_at
`SELECT id, name, symbol, description, image_url, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at
FROM `+metadataTableName+`
WHERE mint = $1`,
mint,
Expand Down
4 changes: 0 additions & 4 deletions ocp/data/currency/postgres/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ const (
vault_core TEXT UNIQUE NOT NULL,
vault_core_bump INTEGER NOT NULL,

fees_mint TEXT NOT NULL,
buy_fee_bps INTEGER NOT NULL,

fees_core TEXT NOT NULL,
sell_fee_bps INTEGER NOT NULL,

alt TEXT NOT NULL,
Expand Down
9 changes: 1 addition & 8 deletions ocp/data/currency/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/code-payments/ocp-server/ocp/data/currency"
"github.com/code-payments/ocp-server/database/query"
"github.com/code-payments/ocp-server/ocp/data/currency"
"github.com/code-payments/ocp-server/solana/currencycreator"
)

Expand Down Expand Up @@ -143,10 +143,6 @@ func testMetadataRoundTrip(t *testing.T, s currency.Store) {
VaultCore: "A9NVHVuorNL4y2YFxdwdU3Hqozxw1Y1YJ81ZPxJsRrT4",
VaultCoreBump: 255,

FeesMint: "BfWacqZVHQt3VNwPugXAkLrApgCTnjgF6nQb7xEMqeDu",
BuyFeeBps: currencycreator.DefaultBuyFeeBps,

FeesCore: "5EcVYL8jHRKeeQqg6eYVBzc73ecH1PFzzaavoQBKRYy5",
SellFeeBps: currencycreator.DefaultSellFeeBps,

Alt: "EkAeTCceLWbmZrAzVZanDJBtHSnkAWndMFgmTnUnVLRR",
Expand Down Expand Up @@ -221,9 +217,6 @@ func assertEquivalentMetadataRecords(t *testing.T, obj1, obj2 *currency.Metadata
assert.Equal(t, obj1.VaultMintBump, obj2.VaultMintBump)
assert.Equal(t, obj1.VaultCore, obj2.VaultCore)
assert.Equal(t, obj1.VaultCoreBump, obj2.VaultCoreBump)
assert.Equal(t, obj1.FeesMint, obj2.FeesMint)
assert.Equal(t, obj1.BuyFeeBps, obj2.BuyFeeBps)
assert.Equal(t, obj1.FeesCore, obj2.FeesCore)
assert.Equal(t, obj1.SellFeeBps, obj2.SellFeeBps)
assert.Equal(t, obj1.Alt, obj2.Alt)
assert.Equal(t, obj1.CreatedBy, obj2.CreatedBy)
Expand Down
12 changes: 0 additions & 12 deletions ocp/rpc/transaction/swap_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,11 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([
&currencycreator.BuyAndDepositIntoVmInstructionAccounts{
Buyer: h.temporaryHolder.PublicKey().ToBytes(),
Pool: destinationCurrencyAccounts.LiquidityPool.PublicKey().ToBytes(),
Currency: destinationCurrencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
TargetMint: h.mint.PublicKey().ToBytes(),
BaseMint: common.CoreMintAccount.PublicKey().ToBytes(),
VaultTarget: destinationCurrencyAccounts.VaultMint.PublicKey().ToBytes(),
VaultBase: destinationCurrencyAccounts.VaultBase.PublicKey().ToBytes(),
BuyerBase: temporaryCoreMintAta.PublicKey().ToBytes(),
FeeTarget: destinationCurrencyAccounts.FeesMint.PublicKey().ToBytes(),
FeeBase: destinationCurrencyAccounts.FeesBase.PublicKey().ToBytes(),

VmAuthority: destinationVmConfig.Authority.PublicKey().ToBytes(),
Vm: destinationVmConfig.Vm.PublicKey().ToBytes(),
Expand Down Expand Up @@ -320,14 +317,11 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) (
&currencycreator.SellAndDepositIntoVmInstructionAccounts{
Seller: h.temporaryHolder.PublicKey().ToBytes(),
Pool: sourceCurrencyAccounts.LiquidityPool.PublicKey().ToBytes(),
Currency: sourceCurrencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
TargetMint: h.mint.PublicKey().ToBytes(),
BaseMint: common.CoreMintAccount.PublicKey().ToBytes(),
VaultTarget: sourceCurrencyAccounts.VaultMint.PublicKey().ToBytes(),
VaultBase: sourceCurrencyAccounts.VaultBase.PublicKey().ToBytes(),
SellerTarget: temporarySourceCurrencyAta.PublicKey().ToBytes(),
FeeTarget: sourceCurrencyAccounts.FeesMint.PublicKey().ToBytes(),
FeeBase: sourceCurrencyAccounts.FeesBase.PublicKey().ToBytes(),

VmAuthority: destinationVmConfig.Authority.PublicKey().ToBytes(),
Vm: destinationVmConfig.Vm.PublicKey().ToBytes(),
Expand Down Expand Up @@ -516,15 +510,12 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context
&currencycreator.SellTokensInstructionAccounts{
Seller: h.temporaryHolder.PublicKey().ToBytes(),
Pool: sourceCurrencyAccounts.LiquidityPool.PublicKey().ToBytes(),
Currency: sourceCurrencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
TargetMint: h.fromMint.PublicKey().ToBytes(),
BaseMint: common.CoreMintAccount.PublicKey().ToBytes(),
VaultTarget: sourceCurrencyAccounts.VaultMint.PublicKey().ToBytes(),
VaultBase: sourceCurrencyAccounts.VaultBase.PublicKey().ToBytes(),
SellerTarget: temporarySourceCurrencyAta.PublicKey().ToBytes(),
SellerBase: temporaryCoreMintAta.PublicKey().ToBytes(),
FeeTarget: sourceCurrencyAccounts.FeesMint.PublicKey().ToBytes(),
FeeBase: sourceCurrencyAccounts.FeesBase.PublicKey().ToBytes(),
},
&currencycreator.SellTokensInstructionArgs{
InAmount: h.amount,
Expand All @@ -536,14 +527,11 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context
&currencycreator.BuyAndDepositIntoVmInstructionAccounts{
Buyer: h.temporaryHolder.PublicKey().ToBytes(),
Pool: destinationCurrencyAccounts.LiquidityPool.PublicKey().ToBytes(),
Currency: destinationCurrencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
TargetMint: h.toMint.PublicKey().ToBytes(),
BaseMint: common.CoreMintAccount.PublicKey().ToBytes(),
VaultTarget: destinationCurrencyAccounts.VaultMint.PublicKey().ToBytes(),
VaultBase: destinationCurrencyAccounts.VaultBase.PublicKey().ToBytes(),
BuyerBase: temporaryCoreMintAta.PublicKey().ToBytes(),
FeeTarget: destinationCurrencyAccounts.FeesMint.PublicKey().ToBytes(),
FeeBase: destinationCurrencyAccounts.FeesBase.PublicKey().ToBytes(),

VmAuthority: destinationVmConfig.Authority.PublicKey().ToBytes(),
Vm: destinationVmConfig.Vm.PublicKey().ToBytes(),
Expand Down
3 changes: 0 additions & 3 deletions ocp/transaction/alt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ func GetAltForMint(ctx context.Context, data ocp_data.Provider, mint *common.Acc
vmConfig.Vm.PublicKey().ToBytes(),
vmConfig.Omnibus.PublicKey().ToBytes(),
mint.PublicKey().ToBytes(),
currencyAccounts.CurrencyConfig.PublicKey().ToBytes(),
currencyAccounts.LiquidityPool.PublicKey().ToBytes(),
currencyAccounts.VaultBase.PublicKey().ToBytes(),
currencyAccounts.VaultMint.PublicKey().ToBytes(),
currencyAccounts.FeesBase.PublicKey().ToBytes(),
currencyAccounts.FeesMint.PublicKey().ToBytes(),
common.CoreMintAccount.PublicKey().ToBytes(),
system.RentSysVar,
system.RecentBlockhashesSysVar,
Expand Down
Loading