@minswap/noodles-sdk 0.0.65-beta.2 → 0.0.65
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/832.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -20
- package/dist/index.js +1 -1
- package/dist/pay.cjs +1 -1
- package/package.json +4 -4
package/dist/pay.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{ADMIN_CAP_ID:()=>ADMIN_CAP_ID,BOOSTING_PACKAGE_ID:()=>BOOSTING_PACKAGE_ID,BoostingModule:()=>BoostingModule,CONFIG_ID:()=>CONFIG_ID,NoodlesPaySdk:()=>NoodlesPaySdk,SUBSCRIPTION_CONFIG:()=>SUBSCRIPTION_CONFIG,SubscriptionModule:()=>SubscriptionModule});const tiny_invariant_namespaceObject=require("@minswap/tiny-invariant");var tiny_invariant_default=__webpack_require__.n(tiny_invariant_namespaceObject);const transactions_namespaceObject=require("@mysten/sui/transactions"),utils_namespaceObject=require("@mysten/sui/utils"),BASE_BPS=1e4;function getSplitCoinsAfterFee(e,t){let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return[n.toString()];let a=n*i/BigInt(1e4);return[(n-a).toString(),a.toString()]}function getAmountAfterFee(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return n;let a=n*i/BigInt(1e4);return n-a}async function getNeededGasFee(e,t,n,i){t.setSenderIfNotSet(n);let a=await e.simulateTransaction({transaction:t,include:{effects:!0},checksEnabled:!1}),{gasUsed:s,status:r}=("Transaction"===a.$kind?a.Transaction:a.FailedTransaction).effects;if(!r.success)throw Error(`Transaction failed during simulation: ${r.error?.message??""}`);let d=BigInt(s.computationCost)+BigInt(s.storageCost)-BigInt(s.storageRebate),o=BigInt(1e4*Number(i));return d*(BigInt(1e4)+o)/BigInt(1e4)}const SUI_TYPE="0x2::sui::SUI",SUI_FULL_TYPE="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",USDC_TOKEN_TYPE="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",NATIVE_USDC_TOKEN_TYPE="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",SUI_METADATA_OBJECT_ID="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",CLOCK_OBJECT_ID="0x0000000000000000000000000000000000000000000000000000000000000006",SUI_ADDRESS_ZERO="0x0000000000000000000000000000000000000000000000000000000000000000";function isSuiCoinType(e){return"0x2::sui::SUI"===e||e===SUI_FULL_TYPE}const orderByKey=(e,t,n)=>{let i;if(e?.length){do{i=!1;for(let a=0;a<e.length-1;a++){let s=BigInt(e[a][t]),r=BigInt(e[a+1][t]);if("desc"===n?s<r:s>r){let t=e[a];e[a]=e[a+1],e[a+1]=t,i=!0}}}while(i);return e}},getCoinObjectIdsByAmount=async(e,t,n,i)=>{let a,s=[],r=!0;for(;r;)try{let n=await e.listCoins({owner:t,coinType:i,cursor:a});s=[...s,...n.objects.map(e=>({coinObjectId:e.objectId,version:e.version,digest:e.digest,balance:e.balance}))],r=n.hasNextPage,a=n.cursor}catch(e){console.error("Error fetching data:",e),r=!1}let d=orderByKey(s.map(e=>({...e,balance:e.balance})),"balance","desc")??[],o="0",c=[],u=[];for(let e of d)if(o=(BigInt(e.balance)+BigInt(o)).toString(10),c.push(e.coinObjectId),u.push(e),BigInt(o)>=BigInt(n))break;return{objectIds:c,balance:o,objectCoins:u}};async function addGasFee(e,t){let{inheritTx:n,sender:i,feeAmount:a,suiInputAmount:s}=e,r=n||new transactions_namespaceObject.Transaction;a>BigInt(0)&&r.setGasBudget(a);let{objectCoins:d}=await getCoinObjectIdsByAmount(t,i,(BigInt(s||"0")+a).toString(),SUI_FULL_TYPE);return r.setGasPayment(d.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),r}const BOOSTING_PACKAGE_ID="0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19",CONFIG_ID="0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb",ADMIN_CAP_ID="0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";class BoostingModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({objectId:CONFIG_ID,include:{json:!0}});tiny_invariant_default()(e.object.json,"Config object not found or has no content");let t=e.object.json,n=t.id.id,i=t.fee_receiver,a=t.tiers.fields.contents,s={};for(let e of a){let t=e.fields.key,n=e.fields.value.fields.duration,i=e.fields.value.fields.amount,a=e.fields.value.fields.point,r=e.fields.value.fields.original_amount;s[t]={duration:BigInt(n),amount:BigInt(i),point:BigInt(a),originalAmount:BigInt(r)}}return{id:n,receiverAddress:i,tiers:s}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:i}){let a=await this.getConfig();tiny_invariant_default()(t in a.tiers,"Invalid tier ID");let s=a.tiers[t].amount,r=i||new transactions_namespaceObject.Transaction,d=r.splitCoins(r.gas,[r.pure.u64(s)]);r.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(n)],arguments:[r.object(CONFIG_ID),r.pure.u64(t),d]}),r.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:o},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:i,originalAmount:a,amount:s,currentTx:r}){let d=r||new transactions_namespaceObject.Transaction;d.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::add_tier`,typeArguments:[],arguments:[d.object(CONFIG_ID),d.object(ADMIN_CAP_ID),d.pure.u64(t),d.pure.u64(i),d.pure.u64(n),d.pure.u64(a),d.pure.u64(s)]}),d.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:a,point:s,currentTx:r}){let d=r||new transactions_namespaceObject.Transaction;d.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_tier`,typeArguments:[],arguments:[d.object(CONFIG_ID),d.object(ADMIN_CAP_ID),d.pure.u64(t),d.pure.u64(n),d.pure.u64(i),d.pure.u64(s),d.pure.u64(a)]}),d.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:o},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::remove_tier`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.u64(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:i,currentTx:a}){let s=a||new transactions_namespaceObject.Transaction,r=s.splitCoins(s.gas,[s.pure.u64(n)]);s.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay_with_admin`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(i)],arguments:[s.object(ADMIN_CAP_ID),s.object(CONFIG_ID),s.pure.u64(t),s.pure.u64(n),r]}),s.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:d},this.sdk.suiClient)}}async function getSplitCoinForTx(e,t){let{account:n,amount:i,splits:a,coinType:s,inheritTx:r,inspecTransaction:d,isSponsored:o=!1}=e,c=r??new transactions_namespaceObject.Transaction,{objectIds:u,balance:_}=await getCoinObjectIdsByAmount(t,n,i,s);if(BigInt(_)<BigInt(i))throw Error(`Insufficient balance for type ${s}. Required: ${i}, Available: ${_}`);if(0===u.length)throw Error(`No coins found for type ${s} with sufficient balance. Required: ${i}`);let l=u[0];if((0,utils_namespaceObject.normalizeStructTag)(s)===(0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE)&&!o){let e;return d?(u.length>1&&c.mergeCoins(c.object(l),u.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(l),a)):e=c.splitCoins(c.gas,a),{tx:c,coinData:e}}u.length>1&&c.mergeCoins(c.object(l),u.slice(1).map(e=>c.object(e)));let I=c.splitCoins(c.object(l),a);return{tx:c,coinData:I}}const SUBSCRIPTION_CONFIG={prod:{packageId:"0x3dd678c250a667f1551bc4b9e35fd070896f4775dd2900d5cb2910d2aea0b068",configId:"0x3eb7bd15f61b7cc1a9fd36151e9c3d05aa37bfadb0a58c3a26a6c02c2e99f3ca",adminCapId:"0xf375fcb3d95934143766cab2028ab49441fa04ef2ce27c08c01004c455bcbad4",paymentCoinType:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"},staging:{packageId:"0xa83cd093ce5142649adae10d21fe87d55fa2df4e52a4292c77ba039bb12bfe67",configId:"0x19fb8f91946e58c068fa4238bdd7a531216a0c4dcfaa279a8a02c60cb02f6711",adminCapId:"0xd8139544d054702dfab6de4e9c55f162c8a6f30465935af56cffed99c5e1c2bd",paymentCoinType:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"}};class SubscriptionModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({objectId:SUBSCRIPTION_CONFIG[this.sdk.env].configId,include:{json:!0}});tiny_invariant_default()(e.object,"Config object not found"),tiny_invariant_default()(e.object.json,"Config object has no content");let t=e.object.json,n=t.id.id,i=t.fee_receiver,a=t.paused,s=t.accepted_payment_type,r=t.plans.fields.contents,d={};for(let e of r){let t=e.fields.key,n=e.fields.value.fields.id,i=e.fields.value.fields.price,a=e.fields.value.fields.month_interval,s=e.fields.value.fields.ptype;d[t]={id:BigInt(n),price:BigInt(i),monthInterval:a,planType:s}}return{id:n,plans:d,feeReceiverWallet:i,paused:a,acceptedPaymentType:s}}async buildSubscribeCyclePlanTx({walletAddress:e,planId:t,reference:n,paymentCoinType:i=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:a}){let s=await this.getConfig();tiny_invariant_default()(!s.paused,"Contract is paused"),tiny_invariant_default()(t in s.plans,"Invalid plan ID");let r=s.plans[t],d=r.price*BigInt(r.monthInterval),{tx:o,coinData:c}=await getSplitCoinForTx({account:e,amount:d.toString(),splits:[d.toString()],coinType:i,inheritTx:a},this.sdk.suiClient);o.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::subscribe_cycle_plan`,typeArguments:[i],arguments:[o.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),o.pure.u64(t),o.pure.string(n),c]}),o.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,o,e,0);return addGasFee({inheritTx:o,sender:e,feeAmount:u},this.sdk.suiClient)}async buildBuyMoreCUPlanTx({walletAddress:e,planId:t,reference:n,paidAmount:i,paymentCoinType:a=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused"),tiny_invariant_default()(t in r.plans,"Invalid plan ID");let{tx:d,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);d.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::buy_more_cu`,typeArguments:[a],arguments:[d.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),d.pure.u64(t),d.pure.string(n),d.pure.u64(i),o]}),d.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:c},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,reference:n,customAmount:i,paymentCoinType:a=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused");let{tx:d,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);d.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::subscribe_plan_with_admin`,typeArguments:[a],arguments:[d.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),d.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),d.pure.u64(t),d.pure.string(n),d.pure.u64(i),o]}),d.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:c},this.sdk.suiClient)}async buildAddPlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::add_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),r.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),r.pure.u64(t),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:d},this.sdk.suiClient)}async buildUpdatePlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::update_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),r.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),r.pure.u64(BigInt(t)),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:d},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::remove_plan`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.u64(BigInt(t))]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiverWalletTx({adminAddress:e,newFeeReceiverWallet:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::set_paused`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.bool(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetAcceptedPaymentTypeTx({adminAddress:e,paymentCoinType:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}}class NoodlesPaySdk{network;env;_suiClient;boostingModule;subscriptionModule;constructor(e,t="mainnet",n="prod"){this.network=t,this.env=n,this._suiClient=e,this.subscriptionModule=new SubscriptionModule(this),this.boostingModule=new BoostingModule(this)}get suiClient(){return this._suiClient}}for(var __rspack_i in exports.ADMIN_CAP_ID=__webpack_exports__.ADMIN_CAP_ID,exports.BOOSTING_PACKAGE_ID=__webpack_exports__.BOOSTING_PACKAGE_ID,exports.BoostingModule=__webpack_exports__.BoostingModule,exports.CONFIG_ID=__webpack_exports__.CONFIG_ID,exports.NoodlesPaySdk=__webpack_exports__.NoodlesPaySdk,exports.SUBSCRIPTION_CONFIG=__webpack_exports__.SUBSCRIPTION_CONFIG,exports.SubscriptionModule=__webpack_exports__.SubscriptionModule,__webpack_exports__)-1===["ADMIN_CAP_ID","BOOSTING_PACKAGE_ID","BoostingModule","CONFIG_ID","NoodlesPaySdk","SUBSCRIPTION_CONFIG","SubscriptionModule"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{ADMIN_CAP_ID:()=>ADMIN_CAP_ID,BOOSTING_PACKAGE_ID:()=>BOOSTING_PACKAGE_ID,BoostingModule:()=>BoostingModule,CONFIG_ID:()=>CONFIG_ID,NoodlesPaySdk:()=>NoodlesPaySdk,SUBSCRIPTION_CONFIG:()=>SUBSCRIPTION_CONFIG,SubscriptionModule:()=>SubscriptionModule});const tiny_invariant_namespaceObject=require("@minswap/tiny-invariant");var tiny_invariant_default=__webpack_require__.n(tiny_invariant_namespaceObject);const transactions_namespaceObject=require("@mysten/sui/transactions"),utils_namespaceObject=require("@mysten/sui/utils"),BASE_BPS=1e4;function getSplitCoinsAfterFee(e,t){let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return[n.toString()];let a=n*i/BigInt(1e4);return[(n-a).toString(),a.toString()]}function getAmountAfterFee(e,t){if(!t||0>=Number(t))return BigInt(e);let n=BigInt(e),i=BigInt(1e4*Number(t));if(i===BigInt(0))return n;let a=n*i/BigInt(1e4);return n-a}async function getNeededGasFee(e,t,n,i){t.setSenderIfNotSet(n);let a=await e.simulateTransaction({transaction:t,include:{effects:!0},checksEnabled:!1}),{gasUsed:s,status:r}=("Transaction"===a.$kind?a.Transaction:a.FailedTransaction).effects;if(!r.success)throw Error(`Transaction failed during simulation: ${r.error?.message??""}`);let d=BigInt(s.computationCost)+BigInt(s.storageCost)-BigInt(s.storageRebate),o=BigInt(1e4*Number(i));return d*(BigInt(1e4)+o)/BigInt(1e4)}const SUI_TYPE="0x2::sui::SUI",SUI_FULL_TYPE="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",USDC_TOKEN_TYPE="0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",NATIVE_USDC_TOKEN_TYPE="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",SUI_METADATA_OBJECT_ID="0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",CLOCK_OBJECT_ID="0x0000000000000000000000000000000000000000000000000000000000000006",SUI_ADDRESS_ZERO="0x0000000000000000000000000000000000000000000000000000000000000000";function isSuiCoinType(e){return"0x2::sui::SUI"===e||e===SUI_FULL_TYPE}const orderByKey=(e,t,n)=>{let i;if(e?.length){do{i=!1;for(let a=0;a<e.length-1;a++){let s=BigInt(e[a][t]),r=BigInt(e[a+1][t]);if("desc"===n?s<r:s>r){let t=e[a];e[a]=e[a+1],e[a+1]=t,i=!0}}}while(i);return e}},getCoinObjectIdsByAmount=async(e,t,n,i)=>{let a,s=[],r=!0;for(;r;)try{let n=await e.listCoins({owner:t,coinType:i,cursor:a});s=[...s,...n.objects.map(e=>({coinObjectId:e.objectId,version:e.version,digest:e.digest,balance:e.balance}))],r=n.hasNextPage,a=n.cursor}catch(e){console.error("Error fetching data:",e),r=!1}let d=orderByKey(s.map(e=>({...e,balance:e.balance})),"balance","desc")??[],o="0",c=[],u=[];for(let e of d)if(o=(BigInt(e.balance)+BigInt(o)).toString(10),c.push(e.coinObjectId),u.push(e),BigInt(o)>=BigInt(n))break;return{objectIds:c,balance:o,objectCoins:u}};async function addGasFee(e,t){let{inheritTx:n,sender:i,feeAmount:a,suiInputAmount:s}=e,r=n||new transactions_namespaceObject.Transaction;a>BigInt(0)&&r.setGasBudget(a);let{objectCoins:d}=await getCoinObjectIdsByAmount(t,i,(BigInt(s||"0")+a).toString(),SUI_FULL_TYPE);return r.setGasPayment(d.map(e=>({objectId:e.coinObjectId,version:e.version,digest:e.digest}))),r}const BOOSTING_PACKAGE_ID="0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19",CONFIG_ID="0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb",ADMIN_CAP_ID="0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";class BoostingModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({objectId:CONFIG_ID,include:{json:!0}});tiny_invariant_default()(e.object,"Config object not found"),tiny_invariant_default()(e.object.json,"Config object has no content");let t=e.object.json,n=t.id.id,i=t.fee_receiver,a=t.tiers.fields.contents,s={};for(let e of a){let t=e.fields.key,n=e.fields.value.fields.duration,i=e.fields.value.fields.amount,a=e.fields.value.fields.point,r=e.fields.value.fields.original_amount;s[t]={duration:BigInt(n),amount:BigInt(i),point:BigInt(a),originalAmount:BigInt(r)}}return{id:n,receiverAddress:i,tiers:s}}async buildPayBoostingTx({walletAddress:e,tierId:t,boostingCoinType:n,currentTx:i}){let a=await this.getConfig();tiny_invariant_default()(t in a.tiers,"Invalid tier ID");let s=a.tiers[t].amount,r=i||new transactions_namespaceObject.Transaction,d=r.splitCoins(r.gas,[r.pure.u64(s)]);r.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(n)],arguments:[r.object(CONFIG_ID),r.pure.u64(t),d]}),r.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:o},this.sdk.suiClient)}async buildAddTierTx({adminAddress:e,tierId:t,duration:n,point:i,originalAmount:a,amount:s,currentTx:r}){let d=r||new transactions_namespaceObject.Transaction;d.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::add_tier`,typeArguments:[],arguments:[d.object(CONFIG_ID),d.object(ADMIN_CAP_ID),d.pure.u64(t),d.pure.u64(i),d.pure.u64(n),d.pure.u64(a),d.pure.u64(s)]}),d.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:a,point:s,currentTx:r}){let d=r||new transactions_namespaceObject.Transaction;d.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_tier`,typeArguments:[],arguments:[d.object(CONFIG_ID),d.object(ADMIN_CAP_ID),d.pure.u64(t),d.pure.u64(n),d.pure.u64(i),d.pure.u64(s),d.pure.u64(a)]}),d.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:o},this.sdk.suiClient)}async buildRemoveTierTx({adminAddress:e,tierId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::remove_tier`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.u64(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiver({adminAddress:e,newReceiverAddress:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(CONFIG_ID),i.object(ADMIN_CAP_ID),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildPayBoostingWithAdminTx({walletAddress:e,tierId:t,customAmount:n,boostingCoinType:i,currentTx:a}){let s=a||new transactions_namespaceObject.Transaction,r=s.splitCoins(s.gas,[s.pure.u64(n)]);s.moveCall({target:`${BOOSTING_PACKAGE_ID}::boosting::pay_with_admin`,typeArguments:[(0,utils_namespaceObject.normalizeStructTag)(i)],arguments:[s.object(ADMIN_CAP_ID),s.object(CONFIG_ID),s.pure.u64(t),s.pure.u64(n),r]}),s.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:d},this.sdk.suiClient)}}async function getSplitCoinForTx(e,t){let{account:n,amount:i,splits:a,coinType:s,inheritTx:r,inspecTransaction:d,isSponsored:o=!1}=e,c=r??new transactions_namespaceObject.Transaction,{objectIds:u,balance:_}=await getCoinObjectIdsByAmount(t,n,i,s);if(BigInt(_)<BigInt(i))throw Error(`Insufficient balance for type ${s}. Required: ${i}, Available: ${_}`);if(0===u.length)throw Error(`No coins found for type ${s} with sufficient balance. Required: ${i}`);let l=u[0];if((0,utils_namespaceObject.normalizeStructTag)(s)===(0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE)&&!o){let e;return d?(u.length>1&&c.mergeCoins(c.object(l),u.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(l),a)):e=c.splitCoins(c.gas,a),{tx:c,coinData:e}}u.length>1&&c.mergeCoins(c.object(l),u.slice(1).map(e=>c.object(e)));let I=c.splitCoins(c.object(l),a);return{tx:c,coinData:I}}const SUBSCRIPTION_CONFIG={prod:{packageId:"0x3dd678c250a667f1551bc4b9e35fd070896f4775dd2900d5cb2910d2aea0b068",configId:"0x3eb7bd15f61b7cc1a9fd36151e9c3d05aa37bfadb0a58c3a26a6c02c2e99f3ca",adminCapId:"0xf375fcb3d95934143766cab2028ab49441fa04ef2ce27c08c01004c455bcbad4",paymentCoinType:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"},staging:{packageId:"0xa83cd093ce5142649adae10d21fe87d55fa2df4e52a4292c77ba039bb12bfe67",configId:"0x19fb8f91946e58c068fa4238bdd7a531216a0c4dcfaa279a8a02c60cb02f6711",adminCapId:"0xd8139544d054702dfab6de4e9c55f162c8a6f30465935af56cffed99c5e1c2bd",paymentCoinType:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"}};class SubscriptionModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({objectId:SUBSCRIPTION_CONFIG[this.sdk.env].configId,include:{json:!0}});tiny_invariant_default()(e.object,"Config object not found"),tiny_invariant_default()(e.object.json,"Config object has no content");let t=e.object.json,n=t.id.id,i=t.fee_receiver,a=t.paused,s=t.accepted_payment_type,r=t.plans.fields.contents,d={};for(let e of r){let t=e.fields.key,n=e.fields.value.fields.id,i=e.fields.value.fields.price,a=e.fields.value.fields.month_interval,s=e.fields.value.fields.ptype;d[t]={id:BigInt(n),price:BigInt(i),monthInterval:a,planType:s}}return{id:n,plans:d,feeReceiverWallet:i,paused:a,acceptedPaymentType:s}}async buildSubscribeCyclePlanTx({walletAddress:e,planId:t,reference:n,paymentCoinType:i=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:a}){let s=await this.getConfig();tiny_invariant_default()(!s.paused,"Contract is paused"),tiny_invariant_default()(t in s.plans,"Invalid plan ID");let r=s.plans[t],d=r.price*BigInt(r.monthInterval),{tx:o,coinData:c}=await getSplitCoinForTx({account:e,amount:d.toString(),splits:[d.toString()],coinType:i,inheritTx:a},this.sdk.suiClient);o.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::subscribe_cycle_plan`,typeArguments:[i],arguments:[o.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),o.pure.u64(t),o.pure.string(n),c]}),o.setSender(e);let u=await getNeededGasFee(this.sdk.suiClient,o,e,0);return addGasFee({inheritTx:o,sender:e,feeAmount:u},this.sdk.suiClient)}async buildBuyMoreCUPlanTx({walletAddress:e,planId:t,reference:n,paidAmount:i,paymentCoinType:a=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused"),tiny_invariant_default()(t in r.plans,"Invalid plan ID");let{tx:d,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);d.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::buy_more_cu`,typeArguments:[a],arguments:[d.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),d.pure.u64(t),d.pure.string(n),d.pure.u64(i),o]}),d.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:c},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,reference:n,customAmount:i,paymentCoinType:a=SUBSCRIPTION_CONFIG[this.sdk.env].paymentCoinType,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused");let{tx:d,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);d.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::subscription::subscribe_plan_with_admin`,typeArguments:[a],arguments:[d.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),d.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),d.pure.u64(t),d.pure.string(n),d.pure.u64(i),o]}),d.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,d,e,0);return addGasFee({inheritTx:d,sender:e,feeAmount:c},this.sdk.suiClient)}async buildAddPlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::add_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),r.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),r.pure.u64(t),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:d},this.sdk.suiClient)}async buildUpdatePlanTx({adminAddress:e,planId:t,planType:n,monthInterval:i,price:a,currentTx:s}){let r=s||new transactions_namespaceObject.Transaction;r.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::update_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),r.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),r.pure.u64(BigInt(t)),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let d=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:d},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::remove_plan`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.u64(BigInt(t))]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildUpdateFeeReceiverWalletTx({adminAddress:e,newFeeReceiverWallet:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.address(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::set_paused`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId),i.pure.bool(t)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}async buildSetAcceptedPaymentTypeTx({adminAddress:e,paymentCoinType:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_CONFIG[this.sdk.env].packageId}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(SUBSCRIPTION_CONFIG[this.sdk.env].configId),i.object(SUBSCRIPTION_CONFIG[this.sdk.env].adminCapId)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}}class NoodlesPaySdk{network;env;_suiClient;boostingModule;subscriptionModule;constructor(e,t="mainnet",n="prod"){this.network=t,this.env=n,this._suiClient=e,this.subscriptionModule=new SubscriptionModule(this),this.boostingModule=new BoostingModule(this)}get suiClient(){return this._suiClient}}for(var __rspack_i in exports.ADMIN_CAP_ID=__webpack_exports__.ADMIN_CAP_ID,exports.BOOSTING_PACKAGE_ID=__webpack_exports__.BOOSTING_PACKAGE_ID,exports.BoostingModule=__webpack_exports__.BoostingModule,exports.CONFIG_ID=__webpack_exports__.CONFIG_ID,exports.NoodlesPaySdk=__webpack_exports__.NoodlesPaySdk,exports.SUBSCRIPTION_CONFIG=__webpack_exports__.SUBSCRIPTION_CONFIG,exports.SubscriptionModule=__webpack_exports__.SubscriptionModule,__webpack_exports__)-1===["ADMIN_CAP_ID","BOOSTING_PACKAGE_ID","BoostingModule","CONFIG_ID","NoodlesPaySdk","SUBSCRIPTION_CONFIG","SubscriptionModule"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minswap/noodles-sdk",
|
|
3
|
-
"version": "0.0.65
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
"@rslib/core": "0.21.5",
|
|
32
32
|
"@types/bn.js": "5.2.0",
|
|
33
33
|
"@types/node": "24",
|
|
34
|
-
"tsx": "4.22.
|
|
34
|
+
"tsx": "4.22.2",
|
|
35
35
|
"typescript": "5.9.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@alphafi/alphalend-sdk": "2.0.1",
|
|
39
|
-
"@bluefin-exchange/bluefin7k-aggregator-sdk": "7.
|
|
39
|
+
"@bluefin-exchange/bluefin7k-aggregator-sdk": "7.2.0",
|
|
40
40
|
"@cetusprotocol/aggregator-sdk": "1.5.4",
|
|
41
41
|
"@cetusprotocol/cetus-sui-clmm-sdk": "5.4.0",
|
|
42
42
|
"@flowx-finance/sdk": "2.0.3",
|
|
43
43
|
"@interest-protocol/memez-fun-sdk": "19.1.0",
|
|
44
44
|
"@interest-protocol/sui-core-sdk": "1.0.0",
|
|
45
45
|
"@minswap/tiny-invariant": "1.2.0",
|
|
46
|
-
"@mysten/sui": "2.
|
|
46
|
+
"@mysten/sui": "2.15.0",
|
|
47
47
|
"@naviprotocol/astros-aggregator-sdk": "1.14.1",
|
|
48
48
|
"@pythnetwork/pyth-sui-js": "3.0.0",
|
|
49
49
|
"@scallop-io/sui-scallop-sdk": "3.0.2",
|