@triadxyz/triad-protocol 2.8.2-beta → 2.8.4-beta
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/index.js +3 -5
- package/dist/utils/swap.d.ts +1 -0
- package/dist/utils/swap.js +7 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -889,25 +889,23 @@ class TriadProtocolClient {
|
|
|
889
889
|
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
890
890
|
.div(adjustedPrice);
|
|
891
891
|
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
892
|
-
console.log('sharesToBuy', sharesToBuy.toNumber());
|
|
893
892
|
if (sharesToBuy.lte(new bn_js_1.default(0)))
|
|
894
893
|
continue;
|
|
895
894
|
const usdcAmount = sharesToBuy
|
|
896
895
|
.mul(adjustedPrice)
|
|
897
896
|
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
898
|
-
console.log('usdcAmount', usdcAmount.toNumber());
|
|
899
|
-
console.log('--------------------------------');
|
|
900
897
|
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
901
898
|
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
902
899
|
}
|
|
903
|
-
console.log('totalUSDCNeeded', totalUSDCNeeded.toNumber());
|
|
904
900
|
if (isTrdPayout && totalUSDCNeeded.gt(new bn_js_1.default(0))) {
|
|
901
|
+
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
902
|
+
const amountInTRD = totalUSDCNeeded.toNumber() / Math.pow(10, this.decimals) / price;
|
|
905
903
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
906
904
|
connection: this.program.provider.connection,
|
|
907
905
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
908
906
|
inToken: constants_1.TRD_MINT.toString(),
|
|
909
907
|
outToken: constants_1.USDC_MINT.toString(),
|
|
910
|
-
amount:
|
|
908
|
+
amount: amountInTRD
|
|
911
909
|
});
|
|
912
910
|
if (swapIxs.length === 0) {
|
|
913
911
|
return;
|
package/dist/utils/swap.d.ts
CHANGED
package/dist/utils/swap.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.swap = void 0;
|
|
15
|
+
exports.getPrice = exports.swap = void 0;
|
|
16
16
|
const index_1 = require("./pda/index");
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -42,6 +42,12 @@ const swap = ({ connection, wallet, inToken, outToken, amount }) => __awaiter(vo
|
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
44
|
exports.swap = swap;
|
|
45
|
+
const getPrice = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const response = yield axios_1.default.get(`https://lite-api.jup.ag/price/v3?ids=${token}`);
|
|
48
|
+
return (_b = (_a = response.data[token]) === null || _a === void 0 ? void 0 : _a.usdPrice) !== null && _b !== void 0 ? _b : 0;
|
|
49
|
+
});
|
|
50
|
+
exports.getPrice = getPrice;
|
|
45
51
|
const deserializeInstruction = (instruction) => {
|
|
46
52
|
return new web3_js_1.TransactionInstruction({
|
|
47
53
|
programId: new web3_js_1.PublicKey(instruction.programId),
|