stackswap-front-api-test-02 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/506.index.umd.js +1 -0
- package/dist/esm/index.d.ts +77 -0
- package/dist/esm/index.js +110 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/stackswap/config.d.ts +84 -0
- package/dist/esm/stackswap/config.js +123 -0
- package/dist/esm/stackswap/config.js.map +1 -0
- package/dist/esm/stackswap/main.d.ts +1 -0
- package/dist/esm/stackswap/main.js +5 -0
- package/dist/esm/stackswap/main.js.map +1 -0
- package/dist/esm/stackswap/manager/farm.manager.d.ts +37 -0
- package/dist/esm/stackswap/manager/farm.manager.js +220 -0
- package/dist/esm/stackswap/manager/farm.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/farm2.manager.d.ts +37 -0
- package/dist/esm/stackswap/manager/farm2.manager.js +294 -0
- package/dist/esm/stackswap/manager/farm2.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/governance.manager.d.ts +9 -0
- package/dist/esm/stackswap/manager/governance.manager.js +54 -0
- package/dist/esm/stackswap/manager/governance.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/launchpad.manager.d.ts +13 -0
- package/dist/esm/stackswap/manager/launchpad.manager.js +148 -0
- package/dist/esm/stackswap/manager/launchpad.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/lbtc.manager.d.ts +31 -0
- package/dist/esm/stackswap/manager/lbtc.manager.js +327 -0
- package/dist/esm/stackswap/manager/lbtc.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/multisig.manager.d.ts +11 -0
- package/dist/esm/stackswap/manager/multisig.manager.js +52 -0
- package/dist/esm/stackswap/manager/multisig.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/nft.manager.d.ts +52 -0
- package/dist/esm/stackswap/manager/nft.manager.js +244 -0
- package/dist/esm/stackswap/manager/nft.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/operator.manager.d.ts +17 -0
- package/dist/esm/stackswap/manager/operator.manager.js +86 -0
- package/dist/esm/stackswap/manager/operator.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/other.manager.d.ts +9 -0
- package/dist/esm/stackswap/manager/other.manager.js +48 -0
- package/dist/esm/stackswap/manager/other.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/pool.manager.d.ts +33 -0
- package/dist/esm/stackswap/manager/pool.manager.js +160 -0
- package/dist/esm/stackswap/manager/pool.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/poxl.manager.d.ts +16 -0
- package/dist/esm/stackswap/manager/poxl.manager.js +72 -0
- package/dist/esm/stackswap/manager/poxl.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/staking.manager.d.ts +25 -0
- package/dist/esm/stackswap/manager/staking.manager.js +234 -0
- package/dist/esm/stackswap/manager/staking.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/swap.manager.d.ts +35 -0
- package/dist/esm/stackswap/manager/swap.manager.js +291 -0
- package/dist/esm/stackswap/manager/swap.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/token.manager.d.ts +31 -0
- package/dist/esm/stackswap/manager/token.manager.js +126 -0
- package/dist/esm/stackswap/manager/token.manager.js.map +1 -0
- package/dist/esm/stackswap/util.d.ts +37 -0
- package/dist/esm/stackswap/util.js +240 -0
- package/dist/esm/stackswap/util.js.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.LICENSE.txt +10 -0
- package/dist/stackswap/config.d.ts +84 -0
- package/dist/stackswap/config.js +127 -0
- package/dist/stackswap/config.js.map +1 -0
- package/dist/stackswap/main.d.ts +1 -0
- package/dist/stackswap/main.js +7 -0
- package/dist/stackswap/main.js.map +1 -0
- package/dist/stackswap/manager/farm.manager.d.ts +37 -0
- package/dist/stackswap/manager/farm.manager.js +228 -0
- package/dist/stackswap/manager/farm.manager.js.map +1 -0
- package/dist/stackswap/manager/farm2.manager.d.ts +37 -0
- package/dist/stackswap/manager/farm2.manager.js +301 -0
- package/dist/stackswap/manager/farm2.manager.js.map +1 -0
- package/dist/stackswap/manager/governance.manager.d.ts +9 -0
- package/dist/stackswap/manager/governance.manager.js +61 -0
- package/dist/stackswap/manager/governance.manager.js.map +1 -0
- package/dist/stackswap/manager/launchpad.manager.d.ts +13 -0
- package/dist/stackswap/manager/launchpad.manager.js +152 -0
- package/dist/stackswap/manager/launchpad.manager.js.map +1 -0
- package/dist/stackswap/manager/lbtc.manager.d.ts +31 -0
- package/dist/stackswap/manager/lbtc.manager.js +334 -0
- package/dist/stackswap/manager/lbtc.manager.js.map +1 -0
- package/dist/stackswap/manager/multisig.manager.d.ts +11 -0
- package/dist/stackswap/manager/multisig.manager.js +56 -0
- package/dist/stackswap/manager/multisig.manager.js.map +1 -0
- package/dist/stackswap/manager/nft.manager.d.ts +52 -0
- package/dist/stackswap/manager/nft.manager.js +251 -0
- package/dist/stackswap/manager/nft.manager.js.map +1 -0
- package/dist/stackswap/manager/operator.manager.d.ts +17 -0
- package/dist/stackswap/manager/operator.manager.js +93 -0
- package/dist/stackswap/manager/operator.manager.js.map +1 -0
- package/dist/stackswap/manager/other.manager.d.ts +9 -0
- package/dist/stackswap/manager/other.manager.js +55 -0
- package/dist/stackswap/manager/other.manager.js.map +1 -0
- package/dist/stackswap/manager/pool.manager.d.ts +33 -0
- package/dist/stackswap/manager/pool.manager.js +168 -0
- package/dist/stackswap/manager/pool.manager.js.map +1 -0
- package/dist/stackswap/manager/poxl.manager.d.ts +16 -0
- package/dist/stackswap/manager/poxl.manager.js +79 -0
- package/dist/stackswap/manager/poxl.manager.js.map +1 -0
- package/dist/stackswap/manager/staking.manager.d.ts +25 -0
- package/dist/stackswap/manager/staking.manager.js +241 -0
- package/dist/stackswap/manager/staking.manager.js.map +1 -0
- package/dist/stackswap/manager/swap.manager.d.ts +35 -0
- package/dist/stackswap/manager/swap.manager.js +298 -0
- package/dist/stackswap/manager/swap.manager.js.map +1 -0
- package/dist/stackswap/manager/token.manager.d.ts +31 -0
- package/dist/stackswap/manager/token.manager.js +134 -0
- package/dist/stackswap/manager/token.manager.js.map +1 -0
- package/dist/stackswap/util.d.ts +37 -0
- package/dist/stackswap/util.js +259 -0
- package/dist/stackswap/util.js.map +1 -0
- package/package.json +43 -0
- package/src/index.ts +165 -0
- package/src/stackswap/config.ts +202 -0
- package/src/stackswap/main.ts +6 -0
- package/src/stackswap/manager/farm.manager.ts +310 -0
- package/src/stackswap/manager/farm2.manager.ts +407 -0
- package/src/stackswap/manager/governance.manager.ts +95 -0
- package/src/stackswap/manager/launchpad.manager.ts +190 -0
- package/src/stackswap/manager/lbtc.manager.ts +566 -0
- package/src/stackswap/manager/multisig.manager.ts +87 -0
- package/src/stackswap/manager/nft.manager.ts +311 -0
- package/src/stackswap/manager/operator.manager.ts +123 -0
- package/src/stackswap/manager/other.manager.ts +71 -0
- package/src/stackswap/manager/pool.manager.ts +188 -0
- package/src/stackswap/manager/poxl.manager.ts +99 -0
- package/src/stackswap/manager/staking.manager.ts +321 -0
- package/src/stackswap/manager/swap.manager.ts +351 -0
- package/src/stackswap/manager/token.manager.ts +156 -0
- package/src/stackswap/util.ts +269 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
|
|
2
|
+
import {StackswapAPI} from "../../index";
|
|
3
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
4
|
+
import {openContractCall} from "@stacks/connect";
|
|
5
|
+
import {
|
|
6
|
+
callReadOnlyFunction, contractPrincipalCV,
|
|
7
|
+
cvToValue,
|
|
8
|
+
FungibleConditionCode,
|
|
9
|
+
listCV,
|
|
10
|
+
makeStandardNonFungiblePostCondition, NonFungibleConditionCode, standardPrincipalCV,
|
|
11
|
+
TupleCV,
|
|
12
|
+
uintCV
|
|
13
|
+
} from "@stacks/transactions";
|
|
14
|
+
import BigNumber from "bignumber.js";
|
|
15
|
+
import axios from "axios";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export class NftManager {
|
|
19
|
+
stackswap : StackswapAPI;
|
|
20
|
+
|
|
21
|
+
constructor(stackswap: StackswapAPI) {
|
|
22
|
+
this.stackswap = stackswap;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getNFTAsset(tokenStr: string) {
|
|
26
|
+
// console.log(tokenStr);
|
|
27
|
+
const token_addr = tokenStr.split('.');
|
|
28
|
+
const url = this.stackswap.config.STACKS_API_URL() + '/v2/contracts/interface/' + token_addr[0] + '/' + token_addr[1];
|
|
29
|
+
const result = await axios.get(url);
|
|
30
|
+
// console.log(tokenStr,result);
|
|
31
|
+
if (result.data.non_fungible_tokens.length === 1) {
|
|
32
|
+
// console.log(tokenStr+'::'+result.data.non_fungible_tokens[0].name);
|
|
33
|
+
return tokenStr + '::' + result.data.non_fungible_tokens[0].name;
|
|
34
|
+
} else {
|
|
35
|
+
// TODO one contract with more than one ft
|
|
36
|
+
// console.log(tokenStr+'::'+result.data.non_fungible_tokens[0].name);
|
|
37
|
+
return tokenStr + '::' + result.data.non_fungible_tokens[0].name;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async getPostConditionFromAssetNFT(account: string, tokenStr: string, condition: NonFungibleConditionCode, id: string) {
|
|
41
|
+
const assetString = await this.getNFTAsset(tokenStr);
|
|
42
|
+
// console.log('account', account);
|
|
43
|
+
// console.log('condition', condition);
|
|
44
|
+
// console.log('assetString', assetString);
|
|
45
|
+
// console.log(' uintCV(id)', bufferCVFromString(id));
|
|
46
|
+
return makeStandardNonFungiblePostCondition(account, condition, assetString, uintCV(id));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async mintNFT(price: string | number, addr: string, callback: any = null){
|
|
50
|
+
const post_condition = [];
|
|
51
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_WSTX_DATA().addr, price, FungibleConditionCode.Equal));
|
|
52
|
+
const function_option : any = getWriteOptions(
|
|
53
|
+
this.stackswap, addr, 'mint', [
|
|
54
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()), callback
|
|
55
|
+
], post_condition, callback);
|
|
56
|
+
await openContractCall(function_option);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async mintNFT2(mint_fee: number, callback: any = null){
|
|
60
|
+
const post_condition = [];
|
|
61
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_WSTX_DATA().addr, mint_fee*1000000, FungibleConditionCode.Equal));
|
|
62
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
63
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STX_STSW_LP(), this.stackswap.config.BASE_STSW_DATA().addr,0, FungibleConditionCode.GreaterEqual));
|
|
64
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
65
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
66
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'mint', [
|
|
67
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
68
|
+
],post_condition, callback);
|
|
69
|
+
await openContractCall(function_option);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async batchSetMintPass(lists: TupleCV[], addr: string, callback: any = null){
|
|
73
|
+
const function_option : any = getWriteOptions(this.stackswap, addr, 'batch-set-mint-pass', [
|
|
74
|
+
listCV(lists),
|
|
75
|
+
],[], callback);
|
|
76
|
+
await openContractCall(function_option);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async listInUstx(id : number, price: string, comm : string = this.stackswap.config.CONTRACT_NAME_COMMISSION(), callback: any = null){
|
|
80
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(),'list-in-ustx', [
|
|
81
|
+
uintCV(id),
|
|
82
|
+
uintCV(price),
|
|
83
|
+
this.stackswap.getQualifiedAddress(comm),
|
|
84
|
+
],[], callback);
|
|
85
|
+
await openContractCall(function_option);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async unlistInUstx(id : number, callback: any = null){
|
|
89
|
+
|
|
90
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'unlist-in-ustx', [
|
|
91
|
+
uintCV(id),
|
|
92
|
+
],[], callback);
|
|
93
|
+
await openContractCall(function_option);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async buyInUstx(id : number, price: number, owner: string, comm : string = this.stackswap.config.CONTRACT_NAME_COMMISSION(), callback: any = null){
|
|
97
|
+
const post_condition = [];
|
|
98
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_WSTX_DATA().addr, new BigNumber(price).multipliedBy(1.075).toFixed(), FungibleConditionCode.LessEqual));
|
|
99
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
100
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STX_STSW_LP(), this.stackswap.config.BASE_STSW_DATA().addr,0, FungibleConditionCode.GreaterEqual));
|
|
101
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
102
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
103
|
+
// post_condition.push(await getPostConditionFromAssetNFT(owner, STACKSWAP_ADDRESS()+'.'+CONTRACT_NAME_AINFT(), NonFungibleConditionCode.DoesNotOwn, id));
|
|
104
|
+
post_condition.push(await this.getPostConditionFromAssetNFT(owner, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), NonFungibleConditionCode.DoesNotOwn, ''+id));
|
|
105
|
+
// console.log(await getNFTAsset(STACKSWAP_ADDRESS()+'.'+CONTRACT_NAME_AINFT()))
|
|
106
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'buy-in-ustx', [
|
|
107
|
+
uintCV(id),
|
|
108
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(),comm),
|
|
109
|
+
],post_condition, callback);
|
|
110
|
+
|
|
111
|
+
await openContractCall(function_option);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async reTouchNFT(id: number, amount: string, callback: any = null){
|
|
115
|
+
const post_condition = [];
|
|
116
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, amount, FungibleConditionCode.Equal));
|
|
117
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
118
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STX_STSW_LP(), this.stackswap.config.BASE_STSW_DATA().addr,0, FungibleConditionCode.GreaterEqual));
|
|
119
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
120
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
121
|
+
post_condition.push(await this.getPostConditionFromAssetNFT(this.stackswap.getSenderAddress(), this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), NonFungibleConditionCode.DoesNotOwn, ''+id));
|
|
122
|
+
|
|
123
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 're-touch', [
|
|
124
|
+
uintCV(id)
|
|
125
|
+
],post_condition, callback);
|
|
126
|
+
await openContractCall(function_option);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async regressNFT(id: number, price: string = '90000000', callback: any = null){
|
|
130
|
+
const post_condition = [];
|
|
131
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), this.stackswap.config.BASE_LBTC_DATA().addr, price, FungibleConditionCode.Equal));
|
|
132
|
+
post_condition.push(await this.getPostConditionFromAssetNFT(this.stackswap.getSenderAddress(), this.stackswap.config.STACKSWAP_ADDRESS()+'.'+this.stackswap.config.CONTRACT_NAME_AINFT(), NonFungibleConditionCode.DoesNotOwn, ''+id));
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'regress-token', [
|
|
136
|
+
uintCV(id)
|
|
137
|
+
],post_condition, callback);
|
|
138
|
+
await openContractCall(function_option);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async getNFTData( id: number){
|
|
142
|
+
const function_option:any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-nft-data', [
|
|
143
|
+
uintCV(id),
|
|
144
|
+
]);
|
|
145
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
146
|
+
const result = cvToValue(result_raw);
|
|
147
|
+
// console.log(result);
|
|
148
|
+
return result.value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async getOwner( id: number){
|
|
152
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-owner', [
|
|
153
|
+
uintCV(id),
|
|
154
|
+
]);
|
|
155
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
156
|
+
const result = cvToValue(result_raw);
|
|
157
|
+
try{
|
|
158
|
+
return result.value.value;
|
|
159
|
+
}catch (e) {
|
|
160
|
+
return ''
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getMintPass( contract: string){
|
|
165
|
+
const function_option : any = getReadOptions(this.stackswap, contract, 'get-mint-pass-balance', [
|
|
166
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
167
|
+
]);
|
|
168
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
169
|
+
const result = cvToValue(result_raw);
|
|
170
|
+
try{
|
|
171
|
+
return result;
|
|
172
|
+
}catch (e) {
|
|
173
|
+
return ''
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async getPassBalance( contract: string){
|
|
178
|
+
const function_option : any = getReadOptions(this.stackswap, contract, 'get-balance', [
|
|
179
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
180
|
+
]);
|
|
181
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
182
|
+
try{
|
|
183
|
+
// console.log('result_raw', result_raw);
|
|
184
|
+
// const result = cvToValue(result_raw);
|
|
185
|
+
// console.log(result);
|
|
186
|
+
// return result;
|
|
187
|
+
return cvToValue(result_raw);
|
|
188
|
+
}catch (e) {
|
|
189
|
+
return '0';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getReserveAmount( id: number){
|
|
194
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-reserve-amount', [
|
|
195
|
+
uintCV(id),
|
|
196
|
+
]);
|
|
197
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
198
|
+
const result = cvToValue(result_raw);
|
|
199
|
+
// console.log(result);
|
|
200
|
+
return result.value;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async getTokenURI( id: number){
|
|
204
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-token-uri', [
|
|
205
|
+
uintCV(id),
|
|
206
|
+
]);
|
|
207
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
208
|
+
const result = cvToValue(result_raw);
|
|
209
|
+
// console.log(result);
|
|
210
|
+
return result.value;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async getTotalList(){
|
|
214
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-total-list', [
|
|
215
|
+
]);
|
|
216
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
217
|
+
try{
|
|
218
|
+
const result = cvToValue(result_raw);
|
|
219
|
+
return result;
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async getMarketList(){
|
|
226
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-market-list', [
|
|
227
|
+
], );
|
|
228
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
229
|
+
try{
|
|
230
|
+
const result = cvToValue(result_raw);
|
|
231
|
+
return result;
|
|
232
|
+
} catch (e) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async getMarketListing( id: number){
|
|
238
|
+
const function_option : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_AINFT(), 'get-listing-in-ustx', [
|
|
239
|
+
uintCV(id),
|
|
240
|
+
]);
|
|
241
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
242
|
+
const result = cvToValue(result_raw);
|
|
243
|
+
try{
|
|
244
|
+
// console.log(result.value.price.value);
|
|
245
|
+
return result.value.price.value;
|
|
246
|
+
} catch (e) {
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async getPASSData(isGold: boolean) {
|
|
252
|
+
const contractaddr = isGold ? this.stackswap.config.CONTRACT_NAME_GOLD_PASS() : this.stackswap.config.CONTRACT_NAME_SILVER_PASS();
|
|
253
|
+
const temp =
|
|
254
|
+
{
|
|
255
|
+
id: 0,
|
|
256
|
+
name: 'loading...',
|
|
257
|
+
img_url: `loading...`,
|
|
258
|
+
json_url: isGold ? 'https://gateway.ipfs/ipfs/QmQtSMAPvKFEr11VfKio2NHqwayJk4CTUkfmkxgXTR7Q2w' : 'https://gateway.ipfs/ipfs/QmQMArAThFXsFtDUyBWBepThCUbANjomWSw9cnmLALLcaM',
|
|
259
|
+
desc: 'loading...',
|
|
260
|
+
attr:
|
|
261
|
+
{
|
|
262
|
+
},
|
|
263
|
+
price: 0,
|
|
264
|
+
owner: 'loading...',
|
|
265
|
+
locked_amt: 0,
|
|
266
|
+
addr : contractaddr,
|
|
267
|
+
contract_name : this.stackswap.config.STACKSWAP_ADDRESS() + '.' + contractaddr
|
|
268
|
+
};
|
|
269
|
+
const json_result = await axios.get(temp.json_url);
|
|
270
|
+
// console.log(json_result.data);
|
|
271
|
+
temp.desc = json_result.data.description;
|
|
272
|
+
temp.name = json_result.data.name;
|
|
273
|
+
temp.img_url = 'https://gateway.ipfs/ipfs/'+json_result.data.image.substr(7, json_result.data.image.length);
|
|
274
|
+
// temp.attr.reTouch = json_result.data.attributes[0].value;
|
|
275
|
+
// temp.price = await getMarketListing(source, id);
|
|
276
|
+
// temp.locked_amt = await getReserveAmount(source, id);
|
|
277
|
+
|
|
278
|
+
return temp
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async getNFTDataFromID(id_: number) {
|
|
282
|
+
const temp =
|
|
283
|
+
{
|
|
284
|
+
id: id_,
|
|
285
|
+
name: 'loading...',
|
|
286
|
+
img_url: `loading...`,
|
|
287
|
+
json_url: `https://gateway.ipfs/ipfs/Qmaa5RRUMa9HQRHWJw3HWG3i1NUmb5VgJXT9Zqqg5VHQjX/${id_}.json`,
|
|
288
|
+
desc: 'loading...',
|
|
289
|
+
attr:
|
|
290
|
+
{
|
|
291
|
+
reTouch: 0,
|
|
292
|
+
},
|
|
293
|
+
price: 0,
|
|
294
|
+
owner: 'loading...',
|
|
295
|
+
locked_amt: 0,
|
|
296
|
+
contract_name : this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_AINFT()
|
|
297
|
+
};
|
|
298
|
+
const json_result = await axios.get(`https://gateway.ipfs.io/ipfs/Qmaa5RRUMa9HQRHWJw3HWG3i1NUmb5VgJXT9Zqqg5VHQjX/${id_}.json`);
|
|
299
|
+
// console.log(json_result.data);
|
|
300
|
+
temp.img_url = 'https://gateway.ipfs.io/ipfs/'+json_result.data.image.substr(7, json_result.data.image.length);
|
|
301
|
+
temp.desc = json_result.data.description;
|
|
302
|
+
temp.name = json_result.data.name;
|
|
303
|
+
temp.attr.reTouch = json_result.data.attributes[0].value;
|
|
304
|
+
|
|
305
|
+
temp.price = await this.getMarketListing(id_);
|
|
306
|
+
temp.locked_amt = await this.getReserveAmount(id_);
|
|
307
|
+
|
|
308
|
+
return temp
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import {openContractCall} from "@stacks/connect";
|
|
4
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
5
|
+
import {
|
|
6
|
+
callReadOnlyFunction, contractPrincipalCV,
|
|
7
|
+
cvToValue,
|
|
8
|
+
FungibleConditionCode, listCV,
|
|
9
|
+
standardPrincipalCV, stringUtf8CV,
|
|
10
|
+
uintCV
|
|
11
|
+
} from "@stacks/transactions";
|
|
12
|
+
import {StackswapAPI} from "../../index";
|
|
13
|
+
|
|
14
|
+
export class OperatorManager {
|
|
15
|
+
stackswap: StackswapAPI;
|
|
16
|
+
|
|
17
|
+
constructor(stackswap: StackswapAPI) {
|
|
18
|
+
this.stackswap = stackswap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async collectSwapFees( token_x: any, token_y: any, token_liquidity: any, callback : any = null) {
|
|
22
|
+
const token_x_addr = token_x.split('.');
|
|
23
|
+
const token_y_addr = token_y.split('.');
|
|
24
|
+
const pair_addr = token_liquidity.split('.');
|
|
25
|
+
const options = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), 'collect-fees', [
|
|
26
|
+
contractPrincipalCV(token_x_addr[0], token_x_addr[1]), contractPrincipalCV(token_y_addr[0], token_y_addr[1]),
|
|
27
|
+
contractPrincipalCV(pair_addr[0], pair_addr[1]),
|
|
28
|
+
],[], callback);
|
|
29
|
+
|
|
30
|
+
openContractCall(options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async add_liquidity_dist( contract_name: string, token_x_amount: string, token_y_amount: string, callback : any = null) {
|
|
34
|
+
const options = getWriteOptions(this.stackswap, contract_name, 'add-liquidity', [
|
|
35
|
+
uintCV(token_x_amount), uintCV(token_y_amount)
|
|
36
|
+
], [], callback);
|
|
37
|
+
openContractCall(options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async invest_to_farm_dist( contract_name: string, callback : any = null) {
|
|
41
|
+
const options = getWriteOptions(this.stackswap, contract_name, 'invest-to-farm', [
|
|
42
|
+
uintCV(12)
|
|
43
|
+
], [], callback);
|
|
44
|
+
openContractCall(options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async STSWInvestTx(invest_amount:string, callback : any = null){
|
|
48
|
+
const invest_amount_str = new BigNumber(invest_amount).multipliedBy(10**6).toFixed(0).toString()
|
|
49
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, invest_amount_str, FungibleConditionCode.Equal)];
|
|
50
|
+
const options = getWriteOptions(this.stackswap, 'distributor0001', 'invest', [uintCV(invest_amount_str)], post_condition, callback);
|
|
51
|
+
const result_raw = await openContractCall(options);
|
|
52
|
+
return result_raw;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async farmClaimDistributor(round:string, callback : any = null){
|
|
56
|
+
const options = getWriteOptions(this.stackswap, 'distributor0001', 'claim-from-farm',
|
|
57
|
+
[ uintCV(round)], [], callback);
|
|
58
|
+
const result_raw = await openContractCall(options);
|
|
59
|
+
return result_raw;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async STSWAwdDistributor( amount: string, callback : any = null){
|
|
63
|
+
// const invest_amount_str = new BigNumber(amount).multipliedBy(10**6).toFixed(0).toString()
|
|
64
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.distributor0001', this.stackswap.config.BASE_STSW_DATA().addr, amount, FungibleConditionCode.Equal)];
|
|
65
|
+
const options = getWriteOptions(this.stackswap, 'distributor0001', 'awd-stsw',
|
|
66
|
+
[ standardPrincipalCV(this.stackswap.getSenderAddress()), uintCV(amount)], post_condition, callback);
|
|
67
|
+
const result_raw = await openContractCall(options);
|
|
68
|
+
return result_raw;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async STSWStaking( amount: string, month: string = '1', callback : any = null){
|
|
72
|
+
// const invest_amount_str = new BigNumber(amount).multipliedBy(10**6).toFixed(0).toString()
|
|
73
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, amount, FungibleConditionCode.Equal)];
|
|
74
|
+
const options = getWriteOptions(this.stackswap, this.stackswap.config.BASE_vSTSW_DATA().addr, 'stake-tokens',
|
|
75
|
+
[ uintCV(amount), uintCV(month)], post_condition, callback);
|
|
76
|
+
const result_raw = await openContractCall(options);
|
|
77
|
+
return result_raw;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// (ok (tuple (claimable_stsw u0) (claimed_lp u0) (claimed_stsw u0) (invested_lp u1209782750210) (invested_stx u355150000000)))
|
|
81
|
+
async distributorGetInvestor(){
|
|
82
|
+
const options = getReadOptions(this.stackswap, 'distributor0001', 'get-invester',
|
|
83
|
+
[ standardPrincipalCV(this.stackswap.getSenderAddress())]);
|
|
84
|
+
const result = await callReadOnlyFunction(options);
|
|
85
|
+
// console.log(cvToValue(result));
|
|
86
|
+
|
|
87
|
+
return cvToValue(result).value;
|
|
88
|
+
}
|
|
89
|
+
async distributorGetReclaim(){
|
|
90
|
+
const options : any = getReadOptions(this.stackswap, 'distributor0001', 'get-claimable-amount',
|
|
91
|
+
[ standardPrincipalCV(this.stackswap.getSenderAddress())]);
|
|
92
|
+
const result = await callReadOnlyFunction(options);
|
|
93
|
+
// console.log(cvToValue(result));
|
|
94
|
+
|
|
95
|
+
return cvToValue(result);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async distributorReclaimLP(amount:string, callback : any = null){
|
|
100
|
+
const amount_str = new BigNumber(amount).multipliedBy(10**6).toFixed(0).toString()
|
|
101
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.distributor0001', this.stackswap.config.STX_STSW_LP(), amount_str, FungibleConditionCode.Equal)];
|
|
102
|
+
const options = getWriteOptions(this.stackswap, 'distributor0001', 'reclaim-lp-tokens',
|
|
103
|
+
[ uintCV(amount_str)], post_condition, callback);
|
|
104
|
+
const result_raw = await openContractCall(options);
|
|
105
|
+
return result_raw;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async distributorClaimSTSW(amount:string, callback : any = null){
|
|
109
|
+
const amount_str = new BigNumber(amount).multipliedBy(10**6).toFixed(0).toString()
|
|
110
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS()+'.distributor0001', this.stackswap.config.BASE_STSW_DATA().addr, amount_str, FungibleConditionCode.Equal)];
|
|
111
|
+
const options = getWriteOptions(this.stackswap, 'distributor0001', 'claim-stsw-tokens',
|
|
112
|
+
[ uintCV(amount_str)], post_condition, callback);
|
|
113
|
+
const result_raw = await openContractCall(options);
|
|
114
|
+
return result_raw;
|
|
115
|
+
}
|
|
116
|
+
async propose( start_block: string, title: string, url: string, changes: any, callback : any = null){
|
|
117
|
+
|
|
118
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_GOVERNANCE(), 'propose', [
|
|
119
|
+
uintCV(start_block), stringUtf8CV(title), stringUtf8CV(url), listCV(changes)
|
|
120
|
+
],[], callback);
|
|
121
|
+
await openContractCall(function_option);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {openContractCall} from "@stacks/connect";
|
|
2
|
+
import {
|
|
3
|
+
bufferCV,
|
|
4
|
+
callReadOnlyFunction,
|
|
5
|
+
cvToValue,
|
|
6
|
+
FungibleConditionCode,
|
|
7
|
+
standardPrincipalCV,
|
|
8
|
+
tupleCV,
|
|
9
|
+
uintCV
|
|
10
|
+
} from "@stacks/transactions";
|
|
11
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
12
|
+
import {StackswapAPI} from "../../index";
|
|
13
|
+
import BigNumber from "bignumber.js";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export class OtherManager {
|
|
17
|
+
stackswap: StackswapAPI;
|
|
18
|
+
|
|
19
|
+
constructor(stackswap: StackswapAPI) {
|
|
20
|
+
this.stackswap = stackswap;
|
|
21
|
+
}
|
|
22
|
+
async getUserBeta01Data( contract_address: string) {
|
|
23
|
+
try{
|
|
24
|
+
const options = getReadOptions(this.stackswap, contract_address, 'get-user-rewards', [
|
|
25
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
26
|
+
]);
|
|
27
|
+
const result = await callReadOnlyFunction(options);
|
|
28
|
+
return cvToValue(result).value;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async claimUserBeta01Reward( contract_address: string, reward : string, callback : any = null) {
|
|
35
|
+
try{
|
|
36
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, contract_address, this.stackswap.config.BASE_STSW_DATA().addr, reward, FungibleConditionCode.Equal)];
|
|
37
|
+
|
|
38
|
+
const options = getWriteOptions(this.stackswap, contract_address, 'claim-reward', [
|
|
39
|
+
], post_condition, callback);
|
|
40
|
+
const result_raw = await openContractCall(options);
|
|
41
|
+
return result_raw;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async get_pox_info(){
|
|
48
|
+
const options = getReadOptions(this.stackswap, 'SP000000000000000000002Q6VF78.pox', 'get-pox-info',
|
|
49
|
+
[ ]);
|
|
50
|
+
const result = await callReadOnlyFunction(options);
|
|
51
|
+
// console.log(cvToValue(result).value);
|
|
52
|
+
return cvToValue(result).value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async stack_stx_to_pox(amount:string, poxAddress: any, start_burn_ht: string, lock_period: string, callback : any = null){
|
|
56
|
+
// const hashbytes = bufferCV(address.fromBase58Check(poxAddress).hash);
|
|
57
|
+
const addresss = tupleCV({
|
|
58
|
+
hashbytes: bufferCV(poxAddress),
|
|
59
|
+
version: bufferCV(new Buffer(1)),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const amount_str = new BigNumber(amount).multipliedBy(10**6).toFixed(0).toString()
|
|
63
|
+
// console.log(addresss);
|
|
64
|
+
const options = getWriteOptions(this.stackswap, 'SP000000000000000000002Q6VF78.pox', 'stack-stx',
|
|
65
|
+
[ uintCV(amount_str), addresss, uintCV(start_burn_ht), uintCV(lock_period)],[], callback);
|
|
66
|
+
const result_raw = await openContractCall(options);
|
|
67
|
+
return result_raw;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|