@symmetry-hq/temp-v3-sdk 0.0.1
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/dist/idl/idl.d.ts +8 -0
- package/dist/idl/idl.js +4958 -0
- package/dist/idl/types.d.ts +4955 -0
- package/dist/idl/types.js +2 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +60 -0
- package/dist/layouts/basket.d.ts +42 -0
- package/dist/layouts/basket.js +43 -0
- package/dist/layouts/config.d.ts +97 -0
- package/dist/layouts/config.js +102 -0
- package/dist/layouts/fraction.d.ts +6 -0
- package/dist/layouts/fraction.js +9 -0
- package/dist/layouts/oracle.d.ts +36 -0
- package/dist/layouts/oracle.js +37 -0
- package/dist/src/constants.d.ts +15 -0
- package/dist/src/constants.js +19 -0
- package/dist/src/idl/idl.d.ts +8 -0
- package/dist/src/idl/idl.js +4958 -0
- package/dist/src/idl/types.d.ts +4955 -0
- package/dist/src/idl/types.js +2 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/index.js +199 -0
- package/dist/src/instructions/accounts.d.ts +27 -0
- package/dist/src/instructions/accounts.js +110 -0
- package/dist/src/instructions/auction.d.ts +7 -0
- package/dist/src/instructions/auction.js +43 -0
- package/dist/src/instructions/automation/auction.d.ts +6 -0
- package/dist/src/instructions/automation/auction.js +40 -0
- package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
- package/dist/src/instructions/automation/claimBounty.js +44 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +15 -0
- package/dist/src/instructions/automation/priceUpdate.js +47 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +10 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/basket.d.ts +120 -0
- package/dist/src/instructions/basket.js +622 -0
- package/dist/src/instructions/bounty.d.ts +18 -0
- package/dist/src/instructions/bounty.js +81 -0
- package/dist/src/instructions/fee.d.ts +8 -0
- package/dist/src/instructions/fee.js +46 -0
- package/dist/src/instructions/globalConfig.d.ts +11 -0
- package/dist/src/instructions/globalConfig.js +43 -0
- package/dist/src/instructions/luts.d.ts +33 -0
- package/dist/src/instructions/luts.js +91 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +39 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +43 -0
- package/dist/src/instructions/management/claimFees.d.ts +7 -0
- package/dist/src/instructions/management/claimFees.js +47 -0
- package/dist/src/instructions/management/createBasket.d.ts +22 -0
- package/dist/src/instructions/management/createBasket.js +101 -0
- package/dist/src/instructions/management/edit.d.ts +34 -0
- package/dist/src/instructions/management/edit.js +192 -0
- package/dist/src/instructions/management/luts.d.ts +29 -0
- package/dist/src/instructions/management/luts.js +88 -0
- package/dist/src/instructions/pda.d.ts +26 -0
- package/dist/src/instructions/pda.js +110 -0
- package/dist/src/instructions/price.d.ts +17 -0
- package/dist/src/instructions/price.js +47 -0
- package/dist/src/instructions/user/deposit.d.ts +32 -0
- package/dist/src/instructions/user/deposit.js +168 -0
- package/dist/src/instructions/user/withdraw.d.ts +16 -0
- package/dist/src/instructions/user/withdraw.js +82 -0
- package/dist/src/layouts/basket.d.ts +41 -0
- package/dist/src/layouts/basket.js +43 -0
- package/dist/src/layouts/config.d.ts +133 -0
- package/dist/src/layouts/config.js +137 -0
- package/dist/src/layouts/fraction.d.ts +6 -0
- package/dist/src/layouts/fraction.js +9 -0
- package/dist/src/layouts/intents/bounty.d.ts +18 -0
- package/dist/src/layouts/intents/bounty.js +19 -0
- package/dist/src/layouts/intents/intent.d.ts +101 -0
- package/dist/src/layouts/intents/intent.js +113 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +56 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +63 -0
- package/dist/src/layouts/lookupTable.d.ts +7 -0
- package/dist/src/layouts/lookupTable.js +10 -0
- package/dist/src/layouts/oracle.d.ts +42 -0
- package/dist/src/layouts/oracle.js +43 -0
- package/dist/src/states/basket.d.ts +8 -0
- package/dist/src/states/basket.js +54 -0
- package/dist/src/states/intents/intent.d.ts +14 -0
- package/dist/src/states/intents/intent.js +90 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +8 -0
- package/dist/src/states/intents/rebalanceIntent.js +54 -0
- package/dist/src/states/oracles/clmm_oracle.d.ts +178 -0
- package/dist/src/states/oracles/clmm_oracle.js +546 -0
- package/dist/src/states/oracles/constants.d.ts +8 -0
- package/dist/src/states/oracles/constants.js +12 -0
- package/dist/src/states/oracles/oracle.d.ts +60 -0
- package/dist/src/states/oracles/oracle.js +237 -0
- package/dist/src/states/oracles/pythOracle.d.ts +39 -0
- package/dist/src/states/oracles/pythOracle.js +202 -0
- package/dist/src/states/oracles/pyth_oracle.d.ts +39 -0
- package/dist/src/states/oracles/pyth_oracle.js +202 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +178 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +546 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +139 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +420 -0
- package/dist/src/states/oracles/raydium_cpmm_oracle.d.ts +139 -0
- package/dist/src/states/oracles/raydium_cpmm_oracle.js +420 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/oracles/switchboard_oracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboard_oracle.js +1 -0
- package/dist/src/txUtils.d.ts +26 -0
- package/dist/src/txUtils.js +183 -0
- package/dist/states/basket.d.ts +8 -0
- package/dist/states/basket.js +57 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +39 -0
- package/package.json +30 -0
- package/src/constants.ts +24 -0
- package/src/index.ts +260 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/priceUpdate.ts +73 -0
- package/src/instructions/automation/rebalanceSwap.ts +60 -0
- package/src/instructions/management/addBounty.ts +56 -0
- package/src/instructions/management/admin.ts +65 -0
- package/src/instructions/management/claimFees.ts +59 -0
- package/src/instructions/management/createBasket.ts +148 -0
- package/src/instructions/management/edit.ts +255 -0
- package/src/instructions/management/luts.ts +134 -0
- package/src/instructions/pda.ts +160 -0
- package/src/instructions/user/deposit.ts +237 -0
- package/src/instructions/user/withdraw.ts +130 -0
- package/src/layouts/basket.ts +82 -0
- package/src/layouts/config.ts +301 -0
- package/src/layouts/fraction.ts +12 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +204 -0
- package/src/layouts/intents/rebalanceIntent.ts +111 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +96 -0
- package/src/states/basket.ts +56 -0
- package/src/states/intents/intent.ts +107 -0
- package/src/states/intents/rebalanceIntent.ts +57 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +260 -0
- package/src/states/oracles/pythOracle.ts +270 -0
- package/src/states/oracles/raydiumClmmOracle.ts +812 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +614 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/txUtils.ts +250 -0
- package/test.ts +30 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RaydiumCPMMOracle = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
+
const oracle_1 = require("./oracle");
|
|
20
|
+
const CPMM_PROGRAM_ID = new web3_js_1.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C");
|
|
21
|
+
const DEV_CPMM_PROGRAM_ID = new web3_js_1.PublicKey("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb");
|
|
22
|
+
var Side;
|
|
23
|
+
(function (Side) {
|
|
24
|
+
Side[Side["Base"] = 0] = "Base";
|
|
25
|
+
Side[Side["Quote"] = 1] = "Quote";
|
|
26
|
+
})(Side || (Side = {}));
|
|
27
|
+
var Quote;
|
|
28
|
+
(function (Quote) {
|
|
29
|
+
Quote[Quote["Usdc"] = 0] = "Usdc";
|
|
30
|
+
Quote[Quote["Wsol"] = 1] = "Wsol";
|
|
31
|
+
})(Quote || (Quote = {}));
|
|
32
|
+
class Observation {
|
|
33
|
+
constructor(params) {
|
|
34
|
+
this.timestamp = params.timestamp;
|
|
35
|
+
this.cum_t_0_price = params.cum_t_0_price;
|
|
36
|
+
this.cum_t_1_price = params.cum_t_1_price;
|
|
37
|
+
}
|
|
38
|
+
static decode(data, offset = 0) {
|
|
39
|
+
const timestamp = new anchor_1.BN(data.subarray(offset, offset + 8), "le");
|
|
40
|
+
const cum_t_0_price = new anchor_1.BN(data.subarray(offset + 8, offset + 24), 'le');
|
|
41
|
+
const cum_t_1_price = new anchor_1.BN(data.subarray(offset + 24, offset + 40), 'le');
|
|
42
|
+
return [
|
|
43
|
+
new Observation({
|
|
44
|
+
timestamp,
|
|
45
|
+
cum_t_0_price,
|
|
46
|
+
cum_t_1_price
|
|
47
|
+
}),
|
|
48
|
+
offset + 40
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
sub(other) {
|
|
52
|
+
if (!(other instanceof Observation)) {
|
|
53
|
+
throw new TypeError("Subtraction is only supported between Observation instances");
|
|
54
|
+
}
|
|
55
|
+
return new Observation({
|
|
56
|
+
timestamp: this.timestamp.sub(other.timestamp),
|
|
57
|
+
cum_t_0_price: this.cum_t_0_price.sub(other.cum_t_0_price),
|
|
58
|
+
cum_t_1_price: this.cum_t_1_price.sub(other.cum_t_1_price),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
add(other) {
|
|
62
|
+
if (!(other instanceof Observation)) {
|
|
63
|
+
throw new TypeError("Addition is only supported between Observation instances");
|
|
64
|
+
}
|
|
65
|
+
return new Observation({
|
|
66
|
+
timestamp: this.timestamp.add(other.timestamp),
|
|
67
|
+
cum_t_0_price: this.cum_t_0_price.add(other.cum_t_0_price),
|
|
68
|
+
cum_t_1_price: this.cum_t_1_price.add(other.cum_t_1_price),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
get_weighted_observation(time) {
|
|
72
|
+
const cum_t_0_price = this.cum_t_0_price.mul(time).div(this.timestamp);
|
|
73
|
+
const cum_t_1_price = this.cum_t_1_price.mul(time).div(this.timestamp);
|
|
74
|
+
return new Observation({
|
|
75
|
+
timestamp: time,
|
|
76
|
+
cum_t_0_price,
|
|
77
|
+
cum_t_1_price
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
adjust_to_timestamp(target_timestamp, observation_prev) {
|
|
81
|
+
// delta = self.sub(prev_observation)
|
|
82
|
+
const delta = this.sub(observation_prev);
|
|
83
|
+
// weighted_delta = delta.get_weighted_observation(target_timestamp - self.block_timestamp)
|
|
84
|
+
const timeForWeighted = target_timestamp.sub(this.timestamp);
|
|
85
|
+
const weighted_delta = delta.get_weighted_observation(timeForWeighted);
|
|
86
|
+
// return self.add(weighted_delta)
|
|
87
|
+
return this.add(weighted_delta);
|
|
88
|
+
}
|
|
89
|
+
get_twap(side) {
|
|
90
|
+
let cum_price = new anchor_1.BN(0);
|
|
91
|
+
if (side === Side.Base)
|
|
92
|
+
cum_price = this.cum_t_0_price;
|
|
93
|
+
else
|
|
94
|
+
cum_price = this.cum_t_1_price;
|
|
95
|
+
console.log("cum_price", cum_price.toString());
|
|
96
|
+
return cum_price.div(this.timestamp);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class ObservationState {
|
|
100
|
+
constructor(params) {
|
|
101
|
+
this.initialized = params.initialized;
|
|
102
|
+
this.observation_index = params.observation_index;
|
|
103
|
+
this.pool_id = params.pool_id;
|
|
104
|
+
this.observations = params.observations;
|
|
105
|
+
this.last_update_timestamp = params.last_update_timestamp;
|
|
106
|
+
this.padding = params.padding;
|
|
107
|
+
}
|
|
108
|
+
static decode(data, offset = 8) {
|
|
109
|
+
let cursor = offset;
|
|
110
|
+
const initialized = data.readUInt8(cursor) !== 0;
|
|
111
|
+
cursor += 1;
|
|
112
|
+
const observation_index = data.readUInt16LE(cursor);
|
|
113
|
+
cursor += 2;
|
|
114
|
+
const pool_id = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
115
|
+
cursor += 32;
|
|
116
|
+
const observations = [];
|
|
117
|
+
for (let i = 0; i < 100; i++) {
|
|
118
|
+
let obs;
|
|
119
|
+
[obs, cursor] = Observation.decode(data, cursor);
|
|
120
|
+
observations.push(obs);
|
|
121
|
+
}
|
|
122
|
+
const last_update_timestamp = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
123
|
+
cursor += 8;
|
|
124
|
+
const padding = [];
|
|
125
|
+
for (let i = 0; i < 4; i++) {
|
|
126
|
+
padding.push(new anchor_1.BN(data.subarray(cursor, cursor + 8), "le"));
|
|
127
|
+
cursor += 8;
|
|
128
|
+
}
|
|
129
|
+
return [
|
|
130
|
+
new ObservationState({
|
|
131
|
+
initialized,
|
|
132
|
+
observation_index,
|
|
133
|
+
pool_id,
|
|
134
|
+
observations,
|
|
135
|
+
last_update_timestamp,
|
|
136
|
+
padding
|
|
137
|
+
}),
|
|
138
|
+
cursor
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
class PoolState {
|
|
143
|
+
constructor(params) {
|
|
144
|
+
this.amm_config = params.amm_config;
|
|
145
|
+
this.pool_creator = params.pool_creator;
|
|
146
|
+
this.token_0_vault = params.token_0_vault;
|
|
147
|
+
this.token_1_vault = params.token_1_vault;
|
|
148
|
+
this.lp_mint = params.lp_mint;
|
|
149
|
+
this.token_0_mint = params.token_0_mint;
|
|
150
|
+
this.token_1_mint = params.token_1_mint;
|
|
151
|
+
this.token_0_program = params.token_0_program;
|
|
152
|
+
this.token_1_program = params.token_1_program;
|
|
153
|
+
this.observation_key = params.observation_key;
|
|
154
|
+
this.auth_bump = params.auth_bump; // u8
|
|
155
|
+
this.status = params.status; // u8
|
|
156
|
+
this.lp_mint_decimals = params.lp_mint_decimals; // u8
|
|
157
|
+
this.mint_0_decimals = params.mint_0_decimals; // u8
|
|
158
|
+
this.mint_1_decimals = params.mint_1_decimals; // u8
|
|
159
|
+
this.lp_supply = params.lp_supply; // u64
|
|
160
|
+
this.protocol_fees_token_0 = params.protocol_fees_token_0; // u64
|
|
161
|
+
this.protocol_fees_token_1 = params.protocol_fees_token_1; // u64
|
|
162
|
+
this.fund_fees_token_0 = params.fund_fees_token_0; // u64
|
|
163
|
+
this.fund_fees_token_1 = params.fund_fees_token_1; // u64
|
|
164
|
+
this.open_time = params.open_time; // u64
|
|
165
|
+
this.recent_epoch = params.recent_epoch; // u64
|
|
166
|
+
this.creator_fee_on = params.creator_fee_on; //u8
|
|
167
|
+
this.enable_creator_fee = params.enable_creator_fee;
|
|
168
|
+
this.padding1 = params.padding1; // [u8; 6]
|
|
169
|
+
this.creator_fees_token_0 = params.creator_fees_token_0; // u64
|
|
170
|
+
this.creator_fees_token_1 = params.creator_fees_token_1; // u64
|
|
171
|
+
this.padding = params.padding; // [u64; 28]
|
|
172
|
+
}
|
|
173
|
+
static decode(data, offset = 8) {
|
|
174
|
+
let cursor = offset;
|
|
175
|
+
const amm_config = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
176
|
+
cursor += 32;
|
|
177
|
+
const pool_creator = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
178
|
+
cursor += 32;
|
|
179
|
+
const token_0_vault = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
180
|
+
cursor += 32;
|
|
181
|
+
const token_1_vault = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
182
|
+
cursor += 32;
|
|
183
|
+
const lp_mint = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
184
|
+
cursor += 32;
|
|
185
|
+
const token_0_mint = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
186
|
+
cursor += 32;
|
|
187
|
+
const token_1_mint = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
188
|
+
cursor += 32;
|
|
189
|
+
const token_0_program = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
190
|
+
cursor += 32;
|
|
191
|
+
const token_1_program = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
192
|
+
cursor += 32;
|
|
193
|
+
const observation_key = new web3_js_1.PublicKey(data.subarray(cursor, cursor + 32));
|
|
194
|
+
cursor += 32;
|
|
195
|
+
const auth_bump = data.readUInt8(cursor);
|
|
196
|
+
cursor += 1;
|
|
197
|
+
const status = data.readUInt8(cursor);
|
|
198
|
+
cursor += 1;
|
|
199
|
+
const lp_mint_decimals = data.readUInt8(cursor);
|
|
200
|
+
cursor += 1;
|
|
201
|
+
const mint_0_decimals = data.readUInt8(cursor);
|
|
202
|
+
cursor += 1;
|
|
203
|
+
const mint_1_decimals = data.readUInt8(cursor);
|
|
204
|
+
cursor += 1;
|
|
205
|
+
const lp_supply = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
206
|
+
cursor += 8;
|
|
207
|
+
const protocol_fees_token_0 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
208
|
+
cursor += 8;
|
|
209
|
+
const protocol_fees_token_1 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
210
|
+
cursor += 8;
|
|
211
|
+
const fund_fees_token_0 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
212
|
+
cursor += 8;
|
|
213
|
+
const fund_fees_token_1 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
214
|
+
cursor += 8;
|
|
215
|
+
const open_time = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
216
|
+
cursor += 8;
|
|
217
|
+
const recent_epoch = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
218
|
+
cursor += 8;
|
|
219
|
+
const creator_fee_on = data.readUInt8(cursor);
|
|
220
|
+
cursor += 1;
|
|
221
|
+
const enable_creator_fee = !!data.readUInt8(cursor);
|
|
222
|
+
cursor += 1;
|
|
223
|
+
const padding1 = [];
|
|
224
|
+
for (let i = 0; i < 6; i++) {
|
|
225
|
+
padding1.push(data.readUInt8(cursor));
|
|
226
|
+
cursor += 1;
|
|
227
|
+
}
|
|
228
|
+
const creator_fees_token_0 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
229
|
+
cursor += 8;
|
|
230
|
+
const creator_fees_token_1 = new anchor_1.BN(data.subarray(cursor, cursor + 8), "le");
|
|
231
|
+
cursor += 8;
|
|
232
|
+
const padding = [];
|
|
233
|
+
for (let i = 0; i < 28; i++) {
|
|
234
|
+
padding.push(new anchor_1.BN(data.subarray(cursor, cursor + 8), "le"));
|
|
235
|
+
cursor += 8;
|
|
236
|
+
}
|
|
237
|
+
return [
|
|
238
|
+
new PoolState({
|
|
239
|
+
amm_config,
|
|
240
|
+
pool_creator,
|
|
241
|
+
token_0_vault,
|
|
242
|
+
token_1_vault,
|
|
243
|
+
lp_mint,
|
|
244
|
+
token_0_mint,
|
|
245
|
+
token_1_mint,
|
|
246
|
+
token_0_program,
|
|
247
|
+
token_1_program,
|
|
248
|
+
observation_key,
|
|
249
|
+
auth_bump,
|
|
250
|
+
status,
|
|
251
|
+
lp_mint_decimals,
|
|
252
|
+
mint_0_decimals,
|
|
253
|
+
mint_1_decimals,
|
|
254
|
+
lp_supply,
|
|
255
|
+
protocol_fees_token_0,
|
|
256
|
+
protocol_fees_token_1,
|
|
257
|
+
fund_fees_token_0,
|
|
258
|
+
fund_fees_token_1,
|
|
259
|
+
open_time,
|
|
260
|
+
recent_epoch,
|
|
261
|
+
creator_fee_on,
|
|
262
|
+
enable_creator_fee,
|
|
263
|
+
padding1,
|
|
264
|
+
creator_fees_token_0,
|
|
265
|
+
creator_fees_token_1,
|
|
266
|
+
padding,
|
|
267
|
+
}),
|
|
268
|
+
cursor,
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
class RaydiumCPMMOracle extends oracle_1.Oracle {
|
|
273
|
+
constructor(params) {
|
|
274
|
+
super(params.weight, params.conf_thresh_bps, params.staleness_thresh, params.volatility_thresh, params.min_liquidity, params.staleness_conf_rate_bps);
|
|
275
|
+
this.pool_id = params.pool_id;
|
|
276
|
+
this.quote_token = params.quote_token;
|
|
277
|
+
this.pool_state = params.pool_state;
|
|
278
|
+
this.side = params.side;
|
|
279
|
+
this.observation_state = params.observation_state;
|
|
280
|
+
}
|
|
281
|
+
static create(params) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
const { connection, pool_id } = params;
|
|
284
|
+
// Fetch pool_state
|
|
285
|
+
const poolAccountInfo = yield connection.getAccountInfo(new web3_js_1.PublicKey(pool_id));
|
|
286
|
+
if (!poolAccountInfo)
|
|
287
|
+
throw new Error("Pool account not found");
|
|
288
|
+
const [pool_state, _] = PoolState.decode(poolAccountInfo.data, 8);
|
|
289
|
+
// Fetch observation_state from pool_state
|
|
290
|
+
const obsPubkey = pool_state.observation_key;
|
|
291
|
+
const obsAccountInfo = yield connection.getAccountInfo(new web3_js_1.PublicKey(obsPubkey));
|
|
292
|
+
if (!obsAccountInfo)
|
|
293
|
+
throw new Error("Observation account not found");
|
|
294
|
+
const [observation_state, __] = ObservationState.decode(obsAccountInfo.data, 8);
|
|
295
|
+
return new RaydiumCPMMOracle({
|
|
296
|
+
pool_id: pool_id,
|
|
297
|
+
quote_token: params.quote_token,
|
|
298
|
+
pool_state: pool_state,
|
|
299
|
+
side: params.side,
|
|
300
|
+
observation_state: observation_state,
|
|
301
|
+
weight: params.weight,
|
|
302
|
+
conf_thresh_bps: params.conf_thresh_bps,
|
|
303
|
+
staleness_thresh: params.staleness_thresh,
|
|
304
|
+
volatility_thresh: params.volatility_thresh,
|
|
305
|
+
min_liquidity: params.min_liquidity,
|
|
306
|
+
staleness_conf_rate_bps: params.staleness_conf_rate_bps
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
set_side(side) {
|
|
311
|
+
this.side = side;
|
|
312
|
+
}
|
|
313
|
+
static derive_observation_key(poolId) {
|
|
314
|
+
const seeds = [
|
|
315
|
+
Buffer.from("observation"),
|
|
316
|
+
poolId.toBuffer(),
|
|
317
|
+
];
|
|
318
|
+
return web3_js_1.PublicKey.findProgramAddressSync(seeds, CPMM_PROGRAM_ID);
|
|
319
|
+
}
|
|
320
|
+
;
|
|
321
|
+
get_observation_at_index(index) {
|
|
322
|
+
return this.observation_state.observations[index];
|
|
323
|
+
}
|
|
324
|
+
get_observation_at_timestamp(timestamp, startIndex) {
|
|
325
|
+
let observationCurrent = this.get_observation_at_index(startIndex);
|
|
326
|
+
let index = startIndex;
|
|
327
|
+
// Loop backwards until we find the observation <= timestamp
|
|
328
|
+
while (observationCurrent.timestamp.gt(timestamp)) {
|
|
329
|
+
index = (index - 1 + 100) % 100;
|
|
330
|
+
observationCurrent = this.get_observation_at_index(index);
|
|
331
|
+
if (index === startIndex) {
|
|
332
|
+
throw Error("Observations do not go back far enough in time");
|
|
333
|
+
break; // looped all the way around
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Previous index for interpolation
|
|
337
|
+
const prevIndex = (index - 1 + 100) % 100;
|
|
338
|
+
const observationPrev = this.get_observation_at_index(prevIndex);
|
|
339
|
+
// Adjust current observation to the target timestamp
|
|
340
|
+
const result = observationCurrent.adjust_to_timestamp(timestamp, observationPrev);
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
get_delta_observations(currentTime) {
|
|
344
|
+
const obsIndex = this.observation_state.observation_index;
|
|
345
|
+
const observationCurrent = this.get_observation_at_timestamp(currentTime, obsIndex);
|
|
346
|
+
const observation30s = this.get_observation_at_timestamp(new anchor_1.BN(currentTime.sub(new anchor_1.BN(30))), obsIndex);
|
|
347
|
+
const delta30s = observationCurrent.sub(observation30s);
|
|
348
|
+
const observation2min = this.get_observation_at_timestamp(new anchor_1.BN(currentTime.sub(new anchor_1.BN(120))), obsIndex);
|
|
349
|
+
const delta2min = observationCurrent.sub(observation2min);
|
|
350
|
+
const observation5min = this.get_observation_at_timestamp(new anchor_1.BN(currentTime.sub(new anchor_1.BN(300))), obsIndex);
|
|
351
|
+
const delta5min = observationCurrent.sub(observation5min);
|
|
352
|
+
const observation20min = this.get_observation_at_timestamp(new anchor_1.BN(currentTime.sub(new anchor_1.BN(1200))), obsIndex);
|
|
353
|
+
const delta20min = observationCurrent.sub(observation20min);
|
|
354
|
+
return [delta30s, delta2min, delta5min, delta20min];
|
|
355
|
+
}
|
|
356
|
+
;
|
|
357
|
+
get_decimals() {
|
|
358
|
+
let dec;
|
|
359
|
+
if (this.side === Side.Base)
|
|
360
|
+
dec = this.pool_state.mint_0_decimals - this.pool_state.mint_1_decimals;
|
|
361
|
+
else
|
|
362
|
+
dec = this.pool_state.mint_1_decimals - this.pool_state.mint_0_decimals;
|
|
363
|
+
return dec;
|
|
364
|
+
}
|
|
365
|
+
get_twap_30sec(current_time) {
|
|
366
|
+
let observation = this.get_delta_observations(current_time)[0];
|
|
367
|
+
let twap_scaled = new decimal_js_1.default(observation.get_twap(this.side).toString()).div(2 ** 32);
|
|
368
|
+
let twap = new decimal_js_1.default(twap_scaled.toString()).div(10 ** this.get_decimals());
|
|
369
|
+
return twap;
|
|
370
|
+
}
|
|
371
|
+
get_twap_2min(current_time) {
|
|
372
|
+
let observation = this.get_delta_observations(current_time)[1];
|
|
373
|
+
let twap_scaled = new decimal_js_1.default(observation.get_twap(this.side).toString()).div(2 ** 32);
|
|
374
|
+
let twap = new decimal_js_1.default(twap_scaled.toString()).div(10 ** this.get_decimals());
|
|
375
|
+
return twap;
|
|
376
|
+
}
|
|
377
|
+
get_twap_5min(current_time) {
|
|
378
|
+
let observation = this.get_delta_observations(current_time)[2];
|
|
379
|
+
let twap_scaled = new decimal_js_1.default(observation.get_twap(this.side).toString()).div(2 ** 32);
|
|
380
|
+
let twap = new decimal_js_1.default(twap_scaled.toString()).div(10 ** this.get_decimals());
|
|
381
|
+
return twap;
|
|
382
|
+
}
|
|
383
|
+
get_twap_20min(current_time) {
|
|
384
|
+
let observation = this.get_delta_observations(current_time)[3];
|
|
385
|
+
let twap_scaled = new decimal_js_1.default(observation.get_twap(this.side).toString()).div(2 ** 32);
|
|
386
|
+
let twap = new decimal_js_1.default(twap_scaled.toString()).div(10 ** this.get_decimals());
|
|
387
|
+
return twap;
|
|
388
|
+
}
|
|
389
|
+
get_confidence(current_time) {
|
|
390
|
+
const twapNow = this.get_twap_30sec(current_time);
|
|
391
|
+
const diff2Min = twapNow.sub(this.get_twap_2min(current_time)).abs();
|
|
392
|
+
const diff5Min = twapNow.sub(this.get_twap_5min(current_time)).abs();
|
|
393
|
+
const diff20Min = twapNow.sub(this.get_twap_20min(current_time)).abs();
|
|
394
|
+
let max = diff2Min;
|
|
395
|
+
if (diff5Min.gt(max))
|
|
396
|
+
max = diff5Min;
|
|
397
|
+
if (diff20Min.gt(max))
|
|
398
|
+
max = diff20Min;
|
|
399
|
+
return max;
|
|
400
|
+
}
|
|
401
|
+
fetch() {
|
|
402
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
const currentTime = new anchor_1.BN(Math.floor(Date.now() / 1000)); // current UNIX timestamp in seconds
|
|
404
|
+
const confidence = this.get_confidence(currentTime);
|
|
405
|
+
// const liquidity = this.pool_state.liquidity; // assuming pool_state is already the decoded data
|
|
406
|
+
const price = this.get_twap_30sec(currentTime);
|
|
407
|
+
let errors = 0;
|
|
408
|
+
// if (confidence.mul(10_000).greaterThan(this.conf_thresh_bps!)) {
|
|
409
|
+
// errors |= ErrorCode.TOO_UNCERTAIN;
|
|
410
|
+
// }
|
|
411
|
+
// if (liquidity.lt(this.min_liquidity)) {
|
|
412
|
+
// errors |= ErrorCode.NOT_ENOUGH_LIQUIDITY;
|
|
413
|
+
// };
|
|
414
|
+
let err = new oracle_1.OracleErrors(errors);
|
|
415
|
+
let oracle_price = new oracle_1.OraclePrice(price, confidence, currentTime);
|
|
416
|
+
return new oracle_1.OracleResult(oracle_price, err);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
exports.RaydiumCPMMOracle = RaydiumCPMMOracle;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Signer, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
export declare const COMPUTE_UNITS = 1000000;
|
|
3
|
+
type TransactionSignature = string;
|
|
4
|
+
export interface VersionedTxs {
|
|
5
|
+
blockhash: string;
|
|
6
|
+
lastValidBlockHeight: number;
|
|
7
|
+
versionedTxs: VersionedTransaction[];
|
|
8
|
+
batches: number[];
|
|
9
|
+
}
|
|
10
|
+
export declare function delay(ms: number): Promise<void>;
|
|
11
|
+
export declare function getAddressLookupTableAccounts(connection: Connection, keys: PublicKey[]): Promise<AddressLookupTableAccount[]>;
|
|
12
|
+
export declare function getMultipleAddressLookupTableAccounts(connection: Connection, keys: PublicKey[][]): Promise<AddressLookupTableAccount[][]>;
|
|
13
|
+
export declare function wrapV0Transaction(blockhash: string, addressLookupTableAccounts: AddressLookupTableAccount[], payerPubkey: PublicKey, priorityFee: number, ixs: TransactionInstruction[]): VersionedTransaction;
|
|
14
|
+
export declare function sendV0Transaction(connection: Connection, tx: VersionedTransaction, blockhash: string, lastValidBlockHeight: number, simulateTransactions: boolean): Promise<TransactionSignature>;
|
|
15
|
+
export declare function prepareV0Transactions(params: {
|
|
16
|
+
connection: Connection;
|
|
17
|
+
payer: PublicKey;
|
|
18
|
+
priorityFee: number;
|
|
19
|
+
multipleIxs: TransactionInstruction[][];
|
|
20
|
+
multipleLookupTableAddresses: PublicKey[][];
|
|
21
|
+
signers: Keypair[][];
|
|
22
|
+
batches: number[];
|
|
23
|
+
}): Promise<VersionedTxs>;
|
|
24
|
+
export declare function sendV0Transactions(connection: Connection, txParams: VersionedTxs, simulateTransactions: boolean): Promise<TransactionSignature[]>;
|
|
25
|
+
export declare function signAndSendVtx(connection: Connection, signer: Signer, txs: VersionedTxs): Promise<TransactionSignature[]>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.COMPUTE_UNITS = void 0;
|
|
13
|
+
exports.delay = delay;
|
|
14
|
+
exports.getAddressLookupTableAccounts = getAddressLookupTableAccounts;
|
|
15
|
+
exports.getMultipleAddressLookupTableAccounts = getMultipleAddressLookupTableAccounts;
|
|
16
|
+
exports.wrapV0Transaction = wrapV0Transaction;
|
|
17
|
+
exports.sendV0Transaction = sendV0Transaction;
|
|
18
|
+
exports.prepareV0Transactions = prepareV0Transactions;
|
|
19
|
+
exports.sendV0Transactions = sendV0Transactions;
|
|
20
|
+
exports.signAndSendVtx = signAndSendVtx;
|
|
21
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
22
|
+
exports.COMPUTE_UNITS = 1000000;
|
|
23
|
+
function delay(ms) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function getAddressLookupTableAccounts(connection, keys) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const addressLookupTableAccountInfos = yield connection.getMultipleAccountsInfo(keys, "confirmed");
|
|
31
|
+
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
32
|
+
const addressLookupTableAddress = keys[index];
|
|
33
|
+
if (accountInfo) {
|
|
34
|
+
const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
|
|
35
|
+
key: new web3_js_1.PublicKey(addressLookupTableAddress),
|
|
36
|
+
state: web3_js_1.AddressLookupTableAccount.deserialize(accountInfo.data),
|
|
37
|
+
});
|
|
38
|
+
acc.push(addressLookupTableAccount);
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
41
|
+
}, new Array());
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
function getMultipleAddressLookupTableAccounts(connection, keys) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
let allLuts = [];
|
|
48
|
+
keys.forEach(luts => luts.forEach(lut => allLuts.push(lut.toBase58())));
|
|
49
|
+
allLuts = [...new Set(allLuts)];
|
|
50
|
+
const addressLookupTableAccounts = yield getAddressLookupTableAccounts(connection, allLuts.map(lut => new web3_js_1.PublicKey(lut)));
|
|
51
|
+
const map = {};
|
|
52
|
+
allLuts.forEach((pubkey, id) => map[pubkey] = addressLookupTableAccounts[id]);
|
|
53
|
+
return keys.map(luts => luts.map(lut => map[lut.toBase58()]));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function wrapV0Transaction(blockhash, addressLookupTableAccounts, payerPubkey, priorityFee, ixs) {
|
|
57
|
+
ixs = [
|
|
58
|
+
...ixs,
|
|
59
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
60
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }),
|
|
61
|
+
];
|
|
62
|
+
const txMessage = new web3_js_1.TransactionMessage({
|
|
63
|
+
payerKey: payerPubkey,
|
|
64
|
+
recentBlockhash: blockhash,
|
|
65
|
+
instructions: ixs,
|
|
66
|
+
});
|
|
67
|
+
let versionedTx = new web3_js_1.VersionedTransaction(txMessage.compileToV0Message(addressLookupTableAccounts));
|
|
68
|
+
try {
|
|
69
|
+
let tt = versionedTx.serialize().length;
|
|
70
|
+
if (tt > 1232) {
|
|
71
|
+
throw new Error("Transaction too large");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
throw new Error(e.message);
|
|
76
|
+
}
|
|
77
|
+
return versionedTx;
|
|
78
|
+
}
|
|
79
|
+
function sendV0Transaction(connection, tx, blockhash, lastValidBlockHeight, simulateTransactions) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
var _a;
|
|
82
|
+
const serializedTx = tx.serialize();
|
|
83
|
+
let txId = "Error";
|
|
84
|
+
if (simulateTransactions) {
|
|
85
|
+
txId = yield connection.sendRawTransaction(serializedTx, { preflightCommitment: "confirmed" }).catch(e => { console.log(e.message); return "Error"; });
|
|
86
|
+
console.log("Simulation txId:", txId);
|
|
87
|
+
for (let i = 0; i < 4; i++) {
|
|
88
|
+
yield delay(1000).then(() => connection.sendRawTransaction(serializedTx, { preflightCommitment: "confirmed" }).catch(() => { }));
|
|
89
|
+
}
|
|
90
|
+
if (txId === "Error")
|
|
91
|
+
throw new Error("Simulation failed");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
connection.sendRawTransaction(serializedTx, { preflightCommitment: "confirmed" })
|
|
95
|
+
.catch(e => { console.log(e.message); });
|
|
96
|
+
txId = yield connection.sendRawTransaction(serializedTx, { skipPreflight: true });
|
|
97
|
+
console.log("Sending tx:", txId);
|
|
98
|
+
for (let i = 0; i < 4; i++) {
|
|
99
|
+
yield delay(1000).then(() => connection.sendRawTransaction(serializedTx, { skipPreflight: true }).catch(() => { }));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let confirmation = null;
|
|
103
|
+
let result = null;
|
|
104
|
+
connection.confirmTransaction({
|
|
105
|
+
blockhash,
|
|
106
|
+
lastValidBlockHeight,
|
|
107
|
+
signature: txId,
|
|
108
|
+
}, "confirmed").then((res) => confirmation = res);
|
|
109
|
+
let iterations = 15;
|
|
110
|
+
while (confirmation === null && result === null && iterations > 0) {
|
|
111
|
+
yield delay(2500);
|
|
112
|
+
result = yield connection.getTransaction(txId, {
|
|
113
|
+
commitment: "confirmed",
|
|
114
|
+
maxSupportedTransactionVersion: 0,
|
|
115
|
+
});
|
|
116
|
+
if (result && result.meta && ((_a = result.meta) === null || _a === void 0 ? void 0 : _a.err)) {
|
|
117
|
+
console.log(result.meta.err);
|
|
118
|
+
throw new Error(txId);
|
|
119
|
+
}
|
|
120
|
+
iterations--;
|
|
121
|
+
}
|
|
122
|
+
if (result)
|
|
123
|
+
return txId;
|
|
124
|
+
//@ts-ignore
|
|
125
|
+
if (!confirmation || confirmation.value.err) {
|
|
126
|
+
//@ts-ignore
|
|
127
|
+
console.log(confirmation === null || confirmation === void 0 ? void 0 : confirmation.value.err);
|
|
128
|
+
throw new Error(txId);
|
|
129
|
+
}
|
|
130
|
+
return txId;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function prepareV0Transactions(params) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const { connection, payer, priorityFee, multipleIxs, multipleLookupTableAddresses, signers, batches } = params;
|
|
136
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash();
|
|
137
|
+
const multipleAddressLookupTableAccounts = yield getMultipleAddressLookupTableAccounts(connection, multipleLookupTableAddresses);
|
|
138
|
+
const txs = multipleIxs.map((ixs, index) => {
|
|
139
|
+
let tx = null;
|
|
140
|
+
try {
|
|
141
|
+
tx = wrapV0Transaction(blockhash, multipleAddressLookupTableAccounts[index], payer, priorityFee, ixs);
|
|
142
|
+
if (signers[index].length > 0)
|
|
143
|
+
tx.sign(signers[index]);
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
console.log("Error signing tx:", e.message);
|
|
147
|
+
}
|
|
148
|
+
return tx;
|
|
149
|
+
}).filter(tx => tx !== null);
|
|
150
|
+
return {
|
|
151
|
+
blockhash,
|
|
152
|
+
lastValidBlockHeight,
|
|
153
|
+
versionedTxs: txs,
|
|
154
|
+
batches,
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function sendV0Transactions(connection, txParams, simulateTransactions) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const { versionedTxs, blockhash, lastValidBlockHeight, batches } = txParams;
|
|
161
|
+
const signedTxs = versionedTxs;
|
|
162
|
+
let lastIndex = 0;
|
|
163
|
+
let txIds = [];
|
|
164
|
+
for (let i = 0; i < batches.length; i++) {
|
|
165
|
+
const ids = yield Promise.all(signedTxs.slice(lastIndex, lastIndex + batches[i]).map(signedTx => sendV0Transaction(connection, signedTx, blockhash, lastValidBlockHeight, simulateTransactions).catch(e => {
|
|
166
|
+
console.log("Transaction failed:", e.message);
|
|
167
|
+
return "Error";
|
|
168
|
+
})));
|
|
169
|
+
txIds = [...txIds, ...ids];
|
|
170
|
+
lastIndex += batches[i];
|
|
171
|
+
}
|
|
172
|
+
return txIds;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function signAndSendVtx(connection, signer, txs) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
for (let vtx of txs.versionedTxs) {
|
|
178
|
+
vtx.sign([signer]);
|
|
179
|
+
}
|
|
180
|
+
let tx = yield sendV0Transactions(connection, txs, false);
|
|
181
|
+
return tx;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { Basket } from "../layouts/basket";
|
|
3
|
+
export declare function fetchBasket(connection: Connection, basketAddress: PublicKey): Promise<Basket>;
|
|
4
|
+
export interface Filter {
|
|
5
|
+
filterType: "host" | "creator";
|
|
6
|
+
filterValue: PublicKey;
|
|
7
|
+
}
|
|
8
|
+
export declare function fetchBaskets(connection: Connection, filters: Filter[]): Promise<Basket[]>;
|