Skip to content

Commit

Permalink
Merge pull request #144 from staratlasmeta/v0.6.0
Browse files Browse the repository at this point in the history
V0.6.0
  • Loading branch information
Buzzec authored Aug 14, 2023
2 parents 52ab3e8 + 0304ab2 commit 65a3aef
Show file tree
Hide file tree
Showing 12 changed files with 5,543 additions and 3,137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
node-version: [ 16.11.1 ]
node-version: [ 16.17.1 ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.11.1]
node-version: [16.17.1]
steps:
- uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
16.17.1
8,608 changes: 5,481 additions & 3,127 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staratlas/factory",
"version": "0.5.3",
"version": "0.6.0",
"description": "Star Atlas Factory for constructing Transactions targeting Solana on-chain programs",
"repository": {
"type": "git",
Expand All @@ -20,6 +20,7 @@
"clean": "rm -rf dist",
"prepare": "npm run build",
"lint": "eslint src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "jest --detectOpenHandles --no-cache --silent",
"start": "tsc --watch",
"docs": "npx typedoc --out docs src",
Expand Down
4 changes: 2 additions & 2 deletions src/atlas-staking/instruction_builders/stakeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface StakeTokensParams extends BaseStakingParams {
stakeMint: web3.PublicKey;
registeredStake: web3.PublicKey;
stakingAccount: web3.PublicKey;
stakeQuantity: number;
stakeQuantity: BN;
}

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function stakeTokensInstruction({
};

const ix = await program.methods
.stakeTokens(new BN(stakeQuantity))
.stakeTokens(stakeQuantity)
.accounts({
user,
stakeMint,
Expand Down
4 changes: 4 additions & 0 deletions src/marketplace/instruction_builders/exchangeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ExchangeOrderParams extends BaseParams {
stakingProgramId: web3.PublicKey;
registeredStake: web3.PublicKey;
stakingAccount: web3.PublicKey;
extraAccounts?: web3.AccountMeta[];
}

/**
Expand All @@ -43,6 +44,7 @@ export interface ExchangeOrderParams extends BaseParams {
* @param stakingProgramId - Deployed program ID for the Staking program
* @param registeredStake - ATLAS staking `RegisteredStake` account
* @param stakingAccount - Seller's ATLAS staking account
* @param extraAccounts - Extra accounts, used for buddy link
*/
export async function createExchangeInstruction({
connection,
Expand All @@ -60,6 +62,7 @@ export async function createExchangeInstruction({
stakingProgramId,
registeredStake,
stakingAccount,
extraAccounts = [],
}: ExchangeOrderParams): Promise<FactoryReturn> {
const program = getMarketplaceProgram({ connection, programId });
const ixSet: FactoryReturn = {
Expand Down Expand Up @@ -175,6 +178,7 @@ export async function createExchangeInstruction({
stakingAccount,
feeReduction,
})
.remainingAccounts(extraAccounts)
.instruction();

ixSet.instructions.push(exchangeIx);
Expand Down
14 changes: 13 additions & 1 deletion src/marketplace/pda_getters/pda_getters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnchorProvider, Idl, Program, web3 } from '@project-serum/anchor';
import { PublicKey } from '@solana/web3.js';
import { RegisteredCurrencyItem } from '../types';
import { FeeExemptItem, RegisteredCurrencyItem } from '../types';
import * as Seeds from './seeds';
import { getGmIDL } from './../utils/getMarketplaceProgram';

Expand Down Expand Up @@ -117,3 +117,15 @@ export async function getFeeExemptAccount(
programId
);
}

export async function getAllFeeExemptAccounts(
connection: web3.Connection,
programId: web3.PublicKey
): Promise<FeeExemptItem[]> {
const provider = new AnchorProvider(connection, null, null);
const idl = getGmIDL(programId);
const program = new Program(idl as Idl, programId, provider);
const feeExemptAccounts = await program.account.feeReduction.all();

return feeExemptAccounts as FeeExemptItem[];
}
30 changes: 27 additions & 3 deletions src/marketplace/services/GmClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import {
getOpenOrdersForPlayerAndAsset,
getOpenOrdersForPlayerAndCurrency,
getAllRegisteredCurrencies,
getAllFeeExemptAccounts,
} from '../pda_getters';
import { OrderAccountItem } from '../types';
import { GmFeeExemption, OrderAccountItem } from '../types';
import { createTransactionFromInstructions } from './helpers';
import { getAssociatedTokenAddress } from '../../util';
import { Order, OrderSide } from '../models/Order';
import { GmRegisteredCurrency } from '../types';
import { ONE_MILLION } from './constants';
import { ONE_MILLION, TEN_THOUSAND } from './constants';
import { convertDecimalPriceToBn } from '../utils';
import { getStakingAccount } from '../../atlas-staking';

Expand Down Expand Up @@ -303,7 +304,8 @@ export class GmClientService {
/** Default to sell order values */
let orderMethod:
| typeof createInitializeBuyOrderInstruction
| typeof createInitializeSellOrderInstruction = createInitializeSellOrderInstruction;
| typeof createInitializeSellOrderInstruction =
createInitializeSellOrderInstruction;
let depositMint: PublicKey = itemMint;
let receiveMint: PublicKey = quoteMint;

Expand Down Expand Up @@ -514,4 +516,26 @@ export class GmClientService {
});
});
}

async getAllFeeExemptions(
connection: Connection,
programId: PublicKey
): Promise<GmFeeExemption[]> {
const result: GmFeeExemption[] = [];

const feeExemptAccounts = await getAllFeeExemptAccounts(
connection,
programId
);

for (const feeExemptAccount of feeExemptAccounts) {
result.push({
publicKey: feeExemptAccount.account.account.toString(),
feeReductionPercentageAsDecimal:
feeExemptAccount.account.discount.toNumber() / TEN_THOUSAND,
});
}

return result;
}
}
1 change: 1 addition & 0 deletions src/marketplace/services/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const ONE_MILLION = 1000000;
export const TEN_THOUSAND = 10000;
5 changes: 5 additions & 0 deletions src/marketplace/types/marketplace_accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export type RoyaltyTier = {

export type RoyaltyTiers = [RoyaltyTier];

export interface FeeExemptItem {
publicKey: web3.PublicKey;
account: FeeExemptInfo;
}

export enum GmLogs {
CancelOrderMemo = 'CancelOrderMemo',
ExchangeMemo = 'ExchangeMemo',
Expand Down
5 changes: 5 additions & 0 deletions src/marketplace/types/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ export type GmCurrencyLogEvent = {
royalty: BN;
timestamp: BN;
};

export type GmFeeExemption = {
publicKey: string;
feeReductionPercentageAsDecimal: number;
};

0 comments on commit 65a3aef

Please sign in to comment.