Skip to content

Commit

Permalink
sync glam
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Oct 8, 2024
1 parent febcf38 commit 5930f47
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,109 +3,37 @@
import software.sava.anchor.ProgramError;

public sealed interface GlamError extends ProgramError permits
GlamError.FundNotActive,
GlamError.InvalidShareClass,
GlamError.InvalidAssetSubscribe,
GlamError.InvalidPricingOracle,
GlamError.InvalidRemainingAccounts,
GlamError.InvalidTreasuryAccount,
GlamError.InvalidSignerAccount,
GlamError.InvalidAssetPrice,
GlamError.InvalidStableCoinPriceForSubscribe,
GlamError.SubscribeRedeemPaused,
GlamError.InvalidPolicyAccount {
GlamError.TransfersDisabled,
GlamError.AmountTooBig,
GlamError.LockUp {

static GlamError getInstance(final int errorCode) {
return switch (errorCode) {
case 6000 -> FundNotActive.INSTANCE;
case 6001 -> InvalidShareClass.INSTANCE;
case 6002 -> InvalidAssetSubscribe.INSTANCE;
case 6003 -> InvalidPricingOracle.INSTANCE;
case 6004 -> InvalidRemainingAccounts.INSTANCE;
case 6005 -> InvalidTreasuryAccount.INSTANCE;
case 6006 -> InvalidSignerAccount.INSTANCE;
case 6007 -> InvalidAssetPrice.INSTANCE;
case 6008 -> InvalidStableCoinPriceForSubscribe.INSTANCE;
case 6009 -> SubscribeRedeemPaused.INSTANCE;
case 6010 -> InvalidPolicyAccount.INSTANCE;
case 6000 -> TransfersDisabled.INSTANCE;
case 6001 -> AmountTooBig.INSTANCE;
case 6002 -> LockUp.INSTANCE;
default -> throw new IllegalStateException("Unexpected Glam error code: " + errorCode);
};
}

record FundNotActive(int code, String msg) implements GlamError {
record TransfersDisabled(int code, String msg) implements GlamError {

public static final FundNotActive INSTANCE = new FundNotActive(
6000, "Fund is not active"
public static final TransfersDisabled INSTANCE = new TransfersDisabled(
6000, "Policy violation: transfers disabled"
);
}

record InvalidShareClass(int code, String msg) implements GlamError {
record AmountTooBig(int code, String msg) implements GlamError {

public static final InvalidShareClass INSTANCE = new InvalidShareClass(
6001, "Share class not allowed to subscribe"
public static final AmountTooBig INSTANCE = new AmountTooBig(
6001, "Policy violation: amount too big"
);
}

record InvalidAssetSubscribe(int code, String msg) implements GlamError {
record LockUp(int code, String msg) implements GlamError {

public static final InvalidAssetSubscribe INSTANCE = new InvalidAssetSubscribe(
6002, "Asset not allowed to subscribe"
);
}

record InvalidPricingOracle(int code, String msg) implements GlamError {

public static final InvalidPricingOracle INSTANCE = new InvalidPricingOracle(
6003, "Invalid oracle for asset price"
);
}

record InvalidRemainingAccounts(int code, String msg) implements GlamError {

public static final InvalidRemainingAccounts INSTANCE = new InvalidRemainingAccounts(
6004, "Invalid accounts: the transaction is malformed"
);
}

record InvalidTreasuryAccount(int code, String msg) implements GlamError {

public static final InvalidTreasuryAccount INSTANCE = new InvalidTreasuryAccount(
6005, "Invalid treasury ata"
);
}

record InvalidSignerAccount(int code, String msg) implements GlamError {

public static final InvalidSignerAccount INSTANCE = new InvalidSignerAccount(
6006, "Invalid signer ata"
);
}

record InvalidAssetPrice(int code, String msg) implements GlamError {

public static final InvalidAssetPrice INSTANCE = new InvalidAssetPrice(
6007, "Invalid asset price"
);
}

record InvalidStableCoinPriceForSubscribe(int code, String msg) implements GlamError {

public static final InvalidStableCoinPriceForSubscribe INSTANCE = new InvalidStableCoinPriceForSubscribe(
6008, "Subscription not allowed: invalid stable coin price"
);
}

record SubscribeRedeemPaused(int code, String msg) implements GlamError {

public static final SubscribeRedeemPaused INSTANCE = new SubscribeRedeemPaused(
6009, "Fund is paused for subscription and redemption"
);
}

record InvalidPolicyAccount(int code, String msg) implements GlamError {

public static final InvalidPolicyAccount INSTANCE = new InvalidPolicyAccount(
6010, "Policy account is mandatory"
public static final LockUp INSTANCE = new LockUp(
6002, "Policy violation: lock-up period"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum EngineFieldName implements Borsh.Enum {
ExternalTreasuryAccounts,
LockUp,
DriftMarketIndexesPerp,
DriftMarketIndexesSpot;
DriftMarketIndexesSpot,
DriftOrderTypes;

public static EngineFieldName read(final byte[] _data, final int offset) {
return Borsh.read(EngineFieldName.values(), _data, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public record FundModel(PublicKey id,
IntegrationAcl[] integrationAcls,
int[] driftMarketIndexesPerp,
int[] driftMarketIndexesSpot,
int[] driftOrderTypes,
boolean isRawOpenfunds,
FundOpenfundsModel rawOpenfunds) implements Borsh {

Expand All @@ -42,6 +43,7 @@ public static FundModel createRecord(final PublicKey id,
final IntegrationAcl[] integrationAcls,
final int[] driftMarketIndexesPerp,
final int[] driftMarketIndexesSpot,
final int[] driftOrderTypes,
final boolean isRawOpenfunds,
final FundOpenfundsModel rawOpenfunds) {
return new FundModel(id,
Expand All @@ -59,6 +61,7 @@ public static FundModel createRecord(final PublicKey id,
integrationAcls,
driftMarketIndexesPerp,
driftMarketIndexesSpot,
driftOrderTypes,
isRawOpenfunds,
rawOpenfunds);
}
Expand Down Expand Up @@ -114,6 +117,8 @@ public static FundModel read(final byte[] _data, final int offset) {
i += Borsh.lenVector(driftMarketIndexesPerp);
final var driftMarketIndexesSpot = Borsh.readintVector(_data, i);
i += Borsh.lenVector(driftMarketIndexesSpot);
final var driftOrderTypes = Borsh.readintVector(_data, i);
i += Borsh.lenVector(driftOrderTypes);
final var isRawOpenfunds = _data[i] == 1;
++i;
final var rawOpenfunds = _data[i++] == 0 ? null : FundOpenfundsModel.read(_data, i);
Expand All @@ -132,6 +137,7 @@ public static FundModel read(final byte[] _data, final int offset) {
integrationAcls,
driftMarketIndexesPerp,
driftMarketIndexesSpot,
driftOrderTypes,
isRawOpenfunds,
rawOpenfunds);
}
Expand All @@ -154,6 +160,7 @@ public int write(final byte[] _data, final int offset) {
i += Borsh.writeVector(integrationAcls, _data, i);
i += Borsh.writeVector(driftMarketIndexesPerp, _data, i);
i += Borsh.writeVector(driftMarketIndexesSpot, _data, i);
i += Borsh.writeVector(driftOrderTypes, _data, i);
_data[i] = (byte) (isRawOpenfunds ? 1 : 0);
++i;
i += Borsh.writeOptional(rawOpenfunds, _data, i);
Expand All @@ -177,6 +184,7 @@ public int l() {
+ Borsh.lenVector(integrationAcls)
+ Borsh.lenVector(driftMarketIndexesPerp)
+ Borsh.lenVector(driftMarketIndexesSpot)
+ Borsh.lenVector(driftOrderTypes)
+ 1
+ (rawOpenfunds == null ? 1 : (1 + Borsh.len(rawOpenfunds)));
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencyResolutionManagement {
}
versionCatalogs {
libs {
from("software.sava:solana-version-catalog:0.2.29")
from("software.sava:solana-version-catalog:0.2.30")
}
}
}

0 comments on commit 5930f47

Please sign in to comment.