Skip to content

Commit

Permalink
Merge branch 'main' into estimate-gas-fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjatosba authored Apr 26, 2023
2 parents 8d8f581 + 277ed6b commit 2d47b2e
Show file tree
Hide file tree
Showing 15 changed files with 701 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Checklist before requesting a review

- [ ] I have added documentation to README
- [ ] I have performed a self-review of my code
- [ ] I have tested this new feature or change on devnet and verified that it works
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ config.austinPOAP.js
whitelist_addresses.csv
airdrop_addresses.csv
transfer.csv
owner_nft_count.csv

.env

Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,28 @@ yarn splits [group-address]

Now the address of the splits contract can be used for the `paymentAddress` (primary sales) and/or `royaltyPaymentAddress` (secondary sales) in `config.js` when creating a minter.

Coming soon:

To distribute funds from the splits contract, make sure you are either the `admin` or a member of the group, and run:
To distribute funds from the splits contract(defined in `config.js`), make sure you are either the `admin` or a member of the group, and run:

```sh
yarn splits-distribute
yarn distribute-splits
```

## Query Splits
This command will query the splits contract.
```sh
yarn query-splits <query-type>
```
### Possible query types:
- **member** [member-address] | |
*Query a member of the group with given address*
- **group** | |
*Query the group contract*
- **list-members** | |
*Query all members of the group*
- **admin** | |
*Query the admin of the group*

## Snapshot

Create a snapshot of owners of a vending collection:
Expand Down Expand Up @@ -203,6 +217,20 @@ yarn mint-for-file

_Note: Burned tokens will be minted to your account._

### Flexible Whitelist

Use a whitelist that has custom `per_address_limit` based on NFT ownership of a different collection. This requires using the flexible factory address, flexible minter code id, and flexible whitelist code id.

```sh
yarn minter --flex-vending
yarn vending-snapshot
yarn query-owner-nft-count
# creates owner-nft-count.csv with the number of NFTs owned by each address
yarn whitelist-flex
yarn whitelist-flex-file
yarn minter --whitelist [whitelist_address]
```

## Testnet

Test your contract. Make sure it's visible in launchpad. Try minting and viewing the NFT in your profile.
Expand Down
9 changes: 9 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ module.exports = {
// { addr: 'stars1...', weight: 10 },
// ],
// groupContract: 'stars1...',
// // The contract address of your splits contract to distribute funds
// splitsContract: 'stars1...',

//// MINTER CONTRACT ////
// The base URI to be used to programmatically mint tokens
Expand Down Expand Up @@ -122,14 +124,21 @@ module.exports = {
vendingMinterCodeId: 275,
// The code ID for updatable vending minter
updatableVendingMinterCodeId: 1654,
// The code ID for vending flexible minter for use with whitelist flexible
flexibleVendingMinterCodeId: 2004,
// Addr for vending factory contract
vendingFactory:
'stars1j4qn9krchp5xs8nued4j4vcr4j654wxkhf7acy76734xe5fsz08sku28s2',
// Addr for updatable vending factory contract
updatableVendingFactory:
'stars1csq2m3gpca9syyq386v6rsfq5r3cp8llee9eyx5uj4wcmxcmg98sqx5xzg',
// Addr for flexible vending factory contract
flexibleVendingFactory:
'stars1ngtwljk0ewua5zazzmy8zmnje9pkl9wl5qf6snqsmghtkes30v7svgjgqw',
// The code ID for the whitelist contract
whitelistCodeId: 277,
// The code ID for the whitelist flexible contract
whitelistFlexCodeId: 2002,
// The marketplace contract address
// marketplace:
// 'stars18cszlvm6pze0x9sz32qnjq4vtd45xehqs8dq7cwy8yhq35wfnn3qgzs5gu',
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.8.2",
"license": "Apache-2.0",
"devDependencies": {
"@stargazezone/launchpad": "^0.25.1",
"@stargazezone/launchpad": "^2.3.3",
"@stargazezone/types": "^0.9.0",
"@types/inquirer": "^8.2.0",
"@types/mime": "^2.0.3",
Expand All @@ -24,6 +24,8 @@
},
"scripts": {
"account": "ts-node scripts/account.ts",
"add-member": "ts-node scripts/add-member.ts",
"airdrop-file": "ts-node scripts/airdrop-file.ts",
"base-minter": "ts-node scripts/base-minter.ts",
"minter": "ts-node scripts/minter.ts",
"mint": "ts-node scripts/mint.ts",
Expand All @@ -36,11 +38,15 @@
"pinata-clean": "ts-node scripts/pinata-clean.ts",
"query": "ts-node scripts/query.ts",
"query-minters": "ts-node scripts/query-minters.ts",
"query-owner-nft-count": "ts-node scripts/query-owner-nft-count.ts",
"shuffle": "ts-node scripts/shuffle.ts",
"update-metadata": "ts-node scripts/update-metadata.ts",
"query-mint-count": "ts-node scripts/query-mint-count.ts",
"ts": "tsc --noEmit --incremental",
"whitelist": "ts-node scripts/whitelist.ts",
"whitelist-flex": "ts-node scripts/whitelist-flex.ts",
"whitelist-flex-file": "ts-node scripts/whitelist-flex-file.ts",
"whitelist-file": "ts-node scripts/whitelist-file.ts",
"devops-pin": "ts-node devops/pin.ts",
"devops-rarity": "ts-node devops/rarity.ts",
"devops-launch": "ts-node devops/testnet-launch.ts",
Expand All @@ -49,9 +55,9 @@
"group": "ts-node scripts/splits.ts",
"splits": "ts-node scripts/splits.ts splits",
"splits-combo": "ts-node scripts/splits.ts combo",
"distribute-splits": "ts-node scripts/distribute-splits.ts",
"query-splits": "ts-node scripts/query-splits.ts query-splits",
"vending-snapshot": "ts-node scripts/vending-snapshot.ts",
"whitelist-file": "ts-node scripts/whitelist-file.ts",
"airdrop-file": "ts-node scripts/airdrop-file.ts",
"mint-for-file": "ts-node scripts/mint-for-file.ts",
"transfer-file": "ts-node scripts/transfer-file.ts"
}
Expand Down
35 changes: 35 additions & 0 deletions scripts/add-member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { toStars } from '../src/utils';
import { getClient } from '../src/client';

const config = require('../config');

async function addGroupMember(member: string, weight: number) {
const client = await getClient();

// @ts-ignore
const msg: ExecuteMsg = {
update_members: { add: [{ addr: toStars(member), weight: weight }] },
};

console.log('Adding member to cw4-group...');

const result = await client.execute(
config.account,
config.groupContract,
msg,
'auto'
);

const wasmEvent = result.logs[0].events.find((e) => e.type === 'wasm');
console.info(
'The `wasm` event emitted by the contract execution:',
wasmEvent
);
}

const args = process.argv.slice(2);
if (args[0] == 'add-member' && args.length == 3) {
addGroupMember(args[1], parseInt(args[2]));
} else {
console.log('Invalid arguments');
}
25 changes: 25 additions & 0 deletions scripts/distribute-splits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getClient } from '../src/client';
import { ExecuteMsg } from '@stargazezone/launchpad/src/Splits.types';


const config = require('../config');

let distrubute_splits= async ()=>{
const client = await getClient();
const msg: ExecuteMsg = {
distribute: {
},
};

const result = await client.execute(
config.account,
config.splitsContract,
msg,
'auto',
'distribute',
);
console.log('Distribute result:', result);

}

distrubute_splits();
12 changes: 12 additions & 0 deletions scripts/minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ async function create_updatable_vending_minter() {
create_minter(params);
}

async function create_flex_vending_minter() {
console.log('flexible vending minter');
let params = {
sg721CodeId: config.sg721BaseCodeId,
vendingMinterCodeId: config.flexibleVendingMinterCodeId,
vendingFactory: config.flexibleVendingFactory,
};
create_minter(params);
}

async function setWhitelist(whitelist: string) {
const client = await getClient();
const account = toStars(config.account);
Expand Down Expand Up @@ -426,6 +436,8 @@ if (args.length == 0) {
create_minter(undefined);
} else if (args.length == 1 && args[0] == '--updatable-vending') {
create_updatable_vending_minter();
} else if (args.length == 1 && args[0] == '--flex-vending') {
create_flex_vending_minter();
} else if (args.length == 2 && args[0] == '--whitelist') {
setWhitelist(args[1]);
} else if (args.length == 1 && args[0] == '--update-start-time') {
Expand Down
78 changes: 78 additions & 0 deletions scripts/query-owner-nft-count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// start with snapshot.csv
// output address and nft count to owner_nft_count.csv
// burned nfts count gets added towards config.account address

import { toStars } from '../src/utils';
import * as fs from 'fs';
import { appendFileSync } from 'fs';
import * as path from 'path';
import { parse } from 'csv-parse';

const config = require('../config');
const SNAPSHOT = 'snapshot.csv';

class TokenInfo {
owner: string;
tokenId: string;
constructor(tokenId = '', owner = '') {
this.owner = owner;
this.tokenId = tokenId;
}
}

class OwnerNftCount {
address: string;
count: number;
constructor(address = '', count = 0) {
this.address = address;
this.count = count;
}

saveAsCSV() {
const csv = `${this.address},${this.count}\n`;
try {
appendFileSync('./owner_nft_count.csv', csv);
} catch (err) {
console.error(err);
}
}
}

async function queryNftCount() {
const account = toStars(config.account);

const __dirname = process.cwd();
const csvFilePath = path.resolve(__dirname, './' + SNAPSHOT);
const headers = ['tokenId', 'owner'];
const fileContent = fs.readFileSync(csvFilePath, { encoding: 'utf-8' });
const owners = new Map();

await parse(
fileContent,
{
delimiter: ',',
columns: headers,
},
async (error, fileContents: TokenInfo[]) => {
if (error) {
throw error;
}
fileContents.map((row) => {
if (row.owner == 'burned') {
row.owner = account;
}
if (owners.has(row.owner)) {
owners.set(row.owner, owners.get(row.owner) + 1);
} else {
owners.set(row.owner, 1);
}
});
owners.forEach((count, addr) => {
const row = new OwnerNftCount(addr, count);
row.saveAsCSV();
});
}
);
}

queryNftCount();
70 changes: 70 additions & 0 deletions scripts/query-splits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { CosmWasmClient } from 'cosmwasm';
import { toStars } from '../src/utils';

const config = require('../config');
let splitsAddress= config.splitsContract;

async function querySplitsAdmin() {
const client = await CosmWasmClient.connect(config.rpcEndpoint);
const admin = await client.queryContractSmart(splitsAddress, {
admin: {},
});
console.log('admin:', admin);
}

async function querySplitsGroup() {
const client = await CosmWasmClient.connect(config.rpcEndpoint);
const group = await client.queryContractSmart(splitsAddress, {
group: {},
});
console.log('group:', group);
}

async function querySplitsMember(address: string) {
const client = await CosmWasmClient.connect(config.rpcEndpoint);
const member = await client.queryContractSmart(splitsAddress, {
member: {
address: toStars(address),
},
});
console.log('member:', member);
}

async function querySplitsListMembers() {
const client = await CosmWasmClient.connect(config.rpcEndpoint);
const members = await client.queryContractSmart(splitsAddress, {
list_members: {
},
});
console.log('members:', members);
}

if(!process.argv[3]){
console.log('No query type specified');
console.log('Query types: admin, group, member <member-address>, list-members');
process.exit(1);
}
else if(process.argv[3] === 'admin'){
querySplitsAdmin();
}
else if(process.argv[3] === 'group'){
querySplitsGroup();
}
else if(process.argv[3] === 'member'){
if(!process.argv[4]){
console.log('No address is specified');
process.exit(1);
}
querySplitsMember(process.argv[4]);
}
else if(process.argv[3] === 'list-members'){
querySplitsListMembers();
}
else{
console.log('Invalid query type');
process.exit(1);
}




Loading

0 comments on commit 2d47b2e

Please sign in to comment.