@minswap/noodles-sdk 0.0.38-next.0 → 0.0.38-next.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/index.cjs +3317 -1
- package/dist/index.js +3152 -1
- package/dist/pay.cjs +905 -1
- package/dist/pay.js +829 -1
- package/package.json +1 -1
package/dist/pay.cjs
CHANGED
|
@@ -1 +1,905 @@
|
|
|
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,CONFIG_ID:()=>CONFIG_ID,BOOSTING_PACKAGE_ID:()=>BOOSTING_PACKAGE_ID,SUBSCRIPTION_PACKAGE_ID:()=>SUBSCRIPTION_PACKAGE_ID,SUBSCRIPTION_ADMIN_CAP_ID:()=>SUBSCRIPTION_ADMIN_CAP_ID,SUBSCRIPTION_CONFIG_ID:()=>SUBSCRIPTION_CONFIG_ID,SubscriptionModule:()=>SubscriptionModule,PAYMENT_COIN_TYPE:()=>PAYMENT_COIN_TYPE,BoostingModule:()=>BoostingModule,NoodlesPaySdk:()=>NoodlesPaySdk});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){let{effects:{gasUsed:a,status:s}}=await e.devInspectTransactionBlock({sender:n,transactionBlock:t});if("success"!==s.status)throw Error(`Transaction failed during dev inspect: ${s.error??""}`);let r=BigInt(a.computationCost)+BigInt(a.storageCost)-BigInt(a.storageRebate),_=BigInt(1e4*Number(i));return r*(BigInt(1e4)+_)/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";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.getCoins({owner:t,coinType:i,cursor:a});s=[...s,...n.data],r=n.hasNextPage,a=n.nextCursor}catch(e){console.error("Error fetching data:",e),r=!1}let _=orderByKey(s.map(e=>({...e,balance:e.balance})),"balance","desc")??[],o="0",c=[],u=[];for(let e of _)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;r.setGasBudget(a);let{objectCoins:_}=await getCoinObjectIdsByAmount(t,i,(BigInt(s||"0")+a).toString(),SUI_FULL_TYPE);return r.setGasPayment(_.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({id:CONFIG_ID,options:{showContent:!0}});tiny_invariant_default()(e.data?.content,"Config object not found or has no content"),tiny_invariant_default()(e.data?.content.dataType==="moveObject","Config object is not a Move object");let t=e.data.content.fields,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,_=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),_]}),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 _=r||new transactions_namespaceObject.Transaction;_.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::add_tier`,typeArguments:[],arguments:[_.object(CONFIG_ID),_.object(ADMIN_CAP_ID),_.pure.u64(t),_.pure.u64(i),_.pure.u64(n),_.pure.u64(a),_.pure.u64(s)]}),_.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:o},this.sdk.suiClient)}async buildUpdateTierTx({adminAddress:e,tierId:t,duration:n,amount:i,originalAmount:a,point:s,currentTx:r}){let _=r||new transactions_namespaceObject.Transaction;_.moveCall({target:`${BOOSTING_PACKAGE_ID}::config::update_tier`,typeArguments:[],arguments:[_.object(CONFIG_ID),_.object(ADMIN_CAP_ID),_.pure.u64(t),_.pure.u64(n),_.pure.u64(i),_.pure.u64(s),_.pure.u64(a)]}),_.setSender(e);let o=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,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 _=await getNeededGasFee(this.sdk.suiClient,s,e,0);return addGasFee({inheritTx:s,sender:e,feeAmount:_},this.sdk.suiClient)}}async function getSplitCoinForTx(e,t){let{account:n,amount:i,splits:a,coinType:s,inheritTx:r,inspecTransaction:_,isSponsored:o=!1}=e,c=r??new transactions_namespaceObject.Transaction,{objectIds:u}=await getCoinObjectIdsByAmount(t,n,i,s),d=u[0];if((0,utils_namespaceObject.normalizeStructTag)(s)===(0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE)&&!o){let e;return _?(u.length>1&&c.mergeCoins(c.object(d),u.slice(1).map(e=>c.object(e))),e=c.splitCoins(c.object(d),a)):e=c.splitCoins(c.gas,a),{tx:c,coinData:e}}u.length>1&&c.mergeCoins(c.object(d),u.slice(1).map(e=>c.object(e)));let l=c.splitCoins(c.object(d),a);return{tx:c,coinData:l}}const SUBSCRIPTION_PACKAGE_ID="0x5dd4286ec234c117bb9577d4eaed1885b70d73ab1d3dab2794d0ab9a2c06c4a1",SUBSCRIPTION_CONFIG_ID="0x095b941beff22213fe8ccb223e4d1c5b4ede4dcd7f82ca4bb18c9a45fd3d6e20",SUBSCRIPTION_ADMIN_CAP_ID="0xdc27fe8187131b7fc095fccd213b79f72312793152a2483d1f67199c390e256d",PAYMENT_COIN_TYPE="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";class SubscriptionModule{sdk;constructor(e){this.sdk=e}async getConfig(){let e=await this.sdk.suiClient.getObject({id:SUBSCRIPTION_CONFIG_ID,options:{showContent:!0}});tiny_invariant_default()(e.data,"Config object not found"),tiny_invariant_default()(e.data.content,"Config object has no content"),tiny_invariant_default()(e.data?.content.dataType==="moveObject","Config object is not a Move object");let t=e.data.content.fields,n=t.id.id,i=t.fee_receiver,a=t.paused,s=t.accepted_payment_type,r=t.plans.fields.contents,_={};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;_[t]={id:BigInt(n),price:BigInt(i),monthInterval:a,planType:s}}return{id:n,plans:_,feeReceiverWallet:i,paused:a,acceptedPaymentType:s}}async buildSubscribeCyclePlanTx({walletAddress:e,planId:t,reference:n,paymentCoinType:i=PAYMENT_COIN_TYPE,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].price,{tx:_,coinData:o}=await getSplitCoinForTx({account:e,amount:r.toString(),splits:[r.toString()],coinType:i,inheritTx:a},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_cycle_plan`,typeArguments:[i],arguments:[_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),o]}),_.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:c},this.sdk.suiClient)}async buildBuyMoreCUPlanTx({walletAddress:e,planId:t,reference:n,paidAmount:i,paymentCoinType:a=PAYMENT_COIN_TYPE,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:_,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::buy_more_cu`,typeArguments:[a],arguments:[_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),_.pure.u64(i),o]}),_.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,sender:e,feeAmount:c},this.sdk.suiClient)}async buildSubscribePlanWithAdminTx({walletAddress:e,planId:t,reference:n,customAmount:i,paymentCoinType:a=PAYMENT_COIN_TYPE,currentTx:s}){let r=await this.getConfig();tiny_invariant_default()(!r.paused,"Contract is paused");let{tx:_,coinData:o}=await getSplitCoinForTx({account:e,amount:i.toString(),splits:[i.toString()],coinType:a,inheritTx:s},this.sdk.suiClient);_.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_plan_with_admin`,typeArguments:[a],arguments:[_.object(SUBSCRIPTION_ADMIN_CAP_ID),_.object(SUBSCRIPTION_CONFIG_ID),_.pure.u64(t),_.pure.string(n),_.pure.u64(i),o]}),_.setSender(e);let c=await getNeededGasFee(this.sdk.suiClient,_,e,0);return addGasFee({inheritTx:_,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_PACKAGE_ID}::config::add_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG_ID),r.object(SUBSCRIPTION_ADMIN_CAP_ID),r.pure.u64(t),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let _=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:_},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_PACKAGE_ID}::config::update_plan`,typeArguments:[],arguments:[r.object(SUBSCRIPTION_CONFIG_ID),r.object(SUBSCRIPTION_ADMIN_CAP_ID),r.pure.u64(BigInt(t)),r.pure.u8(n),r.pure.u8(i),r.pure.u64(a)]}),r.setSender(e);let _=await getNeededGasFee(this.sdk.suiClient,r,e,0);return addGasFee({inheritTx:r,sender:e,feeAmount:_},this.sdk.suiClient)}async buildRemovePlanTx({adminAddress:e,planId:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::remove_plan`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID),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_PACKAGE_ID}::config::update_fee_receiver`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_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 buildSetPausedTx({adminAddress:e,paused:t,currentTx:n}){let i=n||new transactions_namespaceObject.Transaction;i.moveCall({target:`${SUBSCRIPTION_PACKAGE_ID}::config::set_paused`,typeArguments:[],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID),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_PACKAGE_ID}::config::set_accepted_payment_type`,typeArguments:[t],arguments:[i.object(SUBSCRIPTION_CONFIG_ID),i.object(SUBSCRIPTION_ADMIN_CAP_ID)]}),i.setSender(e);let a=await getNeededGasFee(this.sdk.suiClient,i,e,0);return addGasFee({inheritTx:i,sender:e,feeAmount:a},this.sdk.suiClient)}}const client_namespaceObject=require("@mysten/sui/client");class NoodlesPaySdk{_suiClient;boostingModule;subscriptionModule;constructor(){this._suiClient=new client_namespaceObject.SuiClient({url:(0,client_namespaceObject.getFullnodeUrl)("mainnet")}),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.PAYMENT_COIN_TYPE=__webpack_exports__.PAYMENT_COIN_TYPE,exports.SUBSCRIPTION_ADMIN_CAP_ID=__webpack_exports__.SUBSCRIPTION_ADMIN_CAP_ID,exports.SUBSCRIPTION_CONFIG_ID=__webpack_exports__.SUBSCRIPTION_CONFIG_ID,exports.SUBSCRIPTION_PACKAGE_ID=__webpack_exports__.SUBSCRIPTION_PACKAGE_ID,exports.SubscriptionModule=__webpack_exports__.SubscriptionModule,__webpack_exports__)-1===["ADMIN_CAP_ID","BOOSTING_PACKAGE_ID","BoostingModule","CONFIG_ID","NoodlesPaySdk","PAYMENT_COIN_TYPE","SUBSCRIPTION_ADMIN_CAP_ID","SUBSCRIPTION_CONFIG_ID","SUBSCRIPTION_PACKAGE_ID","SubscriptionModule"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
// webpack/runtime/compat_get_default_export
|
|
13
|
+
(() => {
|
|
14
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
15
|
+
__webpack_require__.n = (module) => {
|
|
16
|
+
var getter = module && module.__esModule ?
|
|
17
|
+
() => (module['default']) :
|
|
18
|
+
() => (module);
|
|
19
|
+
__webpack_require__.d(getter, { a: getter });
|
|
20
|
+
return getter;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
})();
|
|
24
|
+
// webpack/runtime/define_property_getters
|
|
25
|
+
(() => {
|
|
26
|
+
__webpack_require__.d = (exports, definition) => {
|
|
27
|
+
for(var key in definition) {
|
|
28
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
29
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
// webpack/runtime/has_own_property
|
|
35
|
+
(() => {
|
|
36
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
37
|
+
})();
|
|
38
|
+
// webpack/runtime/make_namespace_object
|
|
39
|
+
(() => {
|
|
40
|
+
// define __esModule on exports
|
|
41
|
+
__webpack_require__.r = (exports) => {
|
|
42
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
43
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
var __webpack_exports__ = {};
|
|
49
|
+
// ESM COMPAT FLAG
|
|
50
|
+
__webpack_require__.r(__webpack_exports__);
|
|
51
|
+
|
|
52
|
+
// EXPORTS
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
ADMIN_CAP_ID: () => (/* reexport */ ADMIN_CAP_ID),
|
|
55
|
+
CONFIG_ID: () => (/* reexport */ CONFIG_ID),
|
|
56
|
+
BOOSTING_PACKAGE_ID: () => (/* reexport */ BOOSTING_PACKAGE_ID),
|
|
57
|
+
SUBSCRIPTION_PACKAGE_ID: () => (/* reexport */ SUBSCRIPTION_PACKAGE_ID),
|
|
58
|
+
SUBSCRIPTION_ADMIN_CAP_ID: () => (/* reexport */ SUBSCRIPTION_ADMIN_CAP_ID),
|
|
59
|
+
SUBSCRIPTION_CONFIG_ID: () => (/* reexport */ SUBSCRIPTION_CONFIG_ID),
|
|
60
|
+
SubscriptionModule: () => (/* reexport */ SubscriptionModule),
|
|
61
|
+
PAYMENT_COIN_TYPE: () => (/* reexport */ PAYMENT_COIN_TYPE),
|
|
62
|
+
BoostingModule: () => (/* reexport */ BoostingModule),
|
|
63
|
+
NoodlesPaySdk: () => (/* reexport */ NoodlesPaySdk)
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
;// CONCATENATED MODULE: external "@minswap/tiny-invariant"
|
|
67
|
+
const tiny_invariant_namespaceObject = require("@minswap/tiny-invariant");
|
|
68
|
+
var tiny_invariant_default = /*#__PURE__*/__webpack_require__.n(tiny_invariant_namespaceObject);
|
|
69
|
+
;// CONCATENATED MODULE: external "@mysten/sui/transactions"
|
|
70
|
+
const transactions_namespaceObject = require("@mysten/sui/transactions");
|
|
71
|
+
;// CONCATENATED MODULE: external "@mysten/sui/utils"
|
|
72
|
+
const utils_namespaceObject = require("@mysten/sui/utils");
|
|
73
|
+
;// CONCATENATED MODULE: ./src/libs/math/fee.ts
|
|
74
|
+
const BASE_BPS = 10000;
|
|
75
|
+
function getSplitCoinsAfterFee(amount, fee) {
|
|
76
|
+
const amountNum = BigInt(amount);
|
|
77
|
+
const feeNum = BigInt(Number(fee) * BASE_BPS);
|
|
78
|
+
if (feeNum === BigInt(0)) {
|
|
79
|
+
return [
|
|
80
|
+
amountNum.toString()
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
const feeAmount = amountNum * feeNum / BigInt(BASE_BPS);
|
|
84
|
+
const remainingAmount = amountNum - feeAmount;
|
|
85
|
+
return [
|
|
86
|
+
remainingAmount.toString(),
|
|
87
|
+
feeAmount.toString()
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
function getAmountAfterFee(amount, fee) {
|
|
91
|
+
if (!fee || Number(fee) <= 0) {
|
|
92
|
+
return BigInt(amount);
|
|
93
|
+
}
|
|
94
|
+
const amountNum = BigInt(amount);
|
|
95
|
+
const feeNum = BigInt(Number(fee) * BASE_BPS);
|
|
96
|
+
if (feeNum === BigInt(0)) {
|
|
97
|
+
return amountNum;
|
|
98
|
+
}
|
|
99
|
+
const feeAmount = amountNum * feeNum / BigInt(BASE_BPS);
|
|
100
|
+
return amountNum - feeAmount;
|
|
101
|
+
}
|
|
102
|
+
async function getNeededGasFee(suiClient, tx, sender, bufferPercent) {
|
|
103
|
+
const { effects: { gasUsed, status } } = await suiClient.devInspectTransactionBlock({
|
|
104
|
+
sender,
|
|
105
|
+
transactionBlock: tx
|
|
106
|
+
});
|
|
107
|
+
if (status.status !== "success") {
|
|
108
|
+
throw new Error(`Transaction failed during dev inspect: ${status.error ?? ""}`);
|
|
109
|
+
}
|
|
110
|
+
const fee = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
111
|
+
const feeNum = BigInt(Number(bufferPercent) * BASE_BPS);
|
|
112
|
+
return fee * (BigInt(BASE_BPS) + feeNum) / BigInt(BASE_BPS);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
;// CONCATENATED MODULE: ./src/constant/sui.ts
|
|
116
|
+
const SUI_TYPE = "0x2::sui::SUI";
|
|
117
|
+
const SUI_FULL_TYPE = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
118
|
+
const USDC_TOKEN_TYPE = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
|
|
119
|
+
const NATIVE_USDC_TOKEN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
120
|
+
const SUI_METADATA_OBJECT_ID = "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3";
|
|
121
|
+
const CLOCK_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
122
|
+
function isSuiCoinType(coinType) {
|
|
123
|
+
return coinType === SUI_TYPE || coinType === SUI_FULL_TYPE;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
;// CONCATENATED MODULE: ./src/libs/getCoinOjectIdsByAmount.ts
|
|
127
|
+
const orderByKey = (array, key, sortBy)=>{
|
|
128
|
+
if (!array?.length) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let swapped;
|
|
132
|
+
do {
|
|
133
|
+
swapped = false;
|
|
134
|
+
for(let i = 0; i < array.length - 1; i++){
|
|
135
|
+
const a = BigInt(array[i][key]);
|
|
136
|
+
const b = BigInt(array[i + 1][key]);
|
|
137
|
+
if (sortBy === "desc" ? a < b : a > b) {
|
|
138
|
+
const temp = array[i];
|
|
139
|
+
array[i] = array[i + 1];
|
|
140
|
+
array[i + 1] = temp;
|
|
141
|
+
swapped = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}while (swapped);
|
|
145
|
+
return array;
|
|
146
|
+
};
|
|
147
|
+
const getCoinObjectIdsByAmount = async (suiClient, address, amount, coinType)=>{
|
|
148
|
+
let coinBalances = [];
|
|
149
|
+
let hasNextPage = true;
|
|
150
|
+
let nextCursor;
|
|
151
|
+
while(hasNextPage){
|
|
152
|
+
try {
|
|
153
|
+
const coins = await suiClient.getCoins({
|
|
154
|
+
owner: address,
|
|
155
|
+
coinType,
|
|
156
|
+
cursor: nextCursor
|
|
157
|
+
});
|
|
158
|
+
coinBalances = [
|
|
159
|
+
...coinBalances,
|
|
160
|
+
...coins.data
|
|
161
|
+
];
|
|
162
|
+
hasNextPage = coins.hasNextPage;
|
|
163
|
+
nextCursor = coins.nextCursor;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error("Error fetching data:", error);
|
|
166
|
+
hasNextPage = false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// sort coin balance before get object id
|
|
170
|
+
const coinObj = orderByKey(coinBalances.map((item)=>{
|
|
171
|
+
return {
|
|
172
|
+
...item,
|
|
173
|
+
balance: item.balance
|
|
174
|
+
};
|
|
175
|
+
}), "balance", "desc") ?? [];
|
|
176
|
+
let balance = "0";
|
|
177
|
+
const objectIds = [];
|
|
178
|
+
const objectCoins = [];
|
|
179
|
+
for (const coin of coinObj){
|
|
180
|
+
balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
|
|
181
|
+
objectIds.push(coin.coinObjectId);
|
|
182
|
+
objectCoins.push(coin);
|
|
183
|
+
if (BigInt(balance) >= BigInt(amount)) {
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
objectIds,
|
|
189
|
+
balance,
|
|
190
|
+
objectCoins
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
;// CONCATENATED MODULE: ./src/libs/addGasFee.ts
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
async function addGasFee(params, suiClient) {
|
|
199
|
+
const { inheritTx, sender, feeAmount, suiInputAmount } = params;
|
|
200
|
+
const tx = inheritTx || new transactions_namespaceObject.Transaction();
|
|
201
|
+
tx.setGasBudget(feeAmount);
|
|
202
|
+
const { objectCoins } = await getCoinObjectIdsByAmount(suiClient, sender, (BigInt(suiInputAmount || "0") + feeAmount).toString(), SUI_FULL_TYPE);
|
|
203
|
+
tx.setGasPayment(objectCoins.map((c)=>({
|
|
204
|
+
objectId: c.coinObjectId,
|
|
205
|
+
version: c.version,
|
|
206
|
+
digest: c.digest
|
|
207
|
+
})));
|
|
208
|
+
return tx;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
;// CONCATENATED MODULE: ./src/modules/boosting-module.ts
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
/** Sui package ID for the boosting protocol */ const BOOSTING_PACKAGE_ID = "0x25fa0eb553dd69fa6a8028f73a38f1df7f289fa88a58ed3d7dc5a5360155bb19";
|
|
217
|
+
/** Configuration object ID for boosting settings */ const CONFIG_ID = "0x8b1a8ac6e34688cd8f8f8e5fefa9d5fb9e1ff74d2f132f8e208ae5ac9cc530bb";
|
|
218
|
+
/** Admin capability object ID for privileged operations */ const ADMIN_CAP_ID = "0x13d101f44a0710a5475bec5f492a87b80e03d92d1cf540f26096f65850b23d26";
|
|
219
|
+
/**
|
|
220
|
+
* Module for managing boosting functionality in the Noodles SDK.
|
|
221
|
+
*
|
|
222
|
+
* This module provides methods for:
|
|
223
|
+
* - Paying boosting fees for different tiers
|
|
224
|
+
* - Managing boosting tiers (admin functions)
|
|
225
|
+
* - Retrieving boosting configuration
|
|
226
|
+
* - Updating fee receiver settings
|
|
227
|
+
*/ class BoostingModule {
|
|
228
|
+
/** Reference to the main SDK instance */ sdk;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a new BoostingModule instance.
|
|
231
|
+
*
|
|
232
|
+
* @param sdk - The main Noodles Pay SDK instance
|
|
233
|
+
*/ constructor(sdk){
|
|
234
|
+
this.sdk = sdk;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves the current boosting configuration from the blockchain.
|
|
238
|
+
*
|
|
239
|
+
* @returns Promise resolving to the current boosting configuration
|
|
240
|
+
* @throws Error if config object is not found or invalid
|
|
241
|
+
*/ async getConfig() {
|
|
242
|
+
const configObject = await this.sdk.suiClient.getObject({
|
|
243
|
+
id: CONFIG_ID,
|
|
244
|
+
options: {
|
|
245
|
+
showContent: true
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
tiny_invariant_default()(configObject.data?.content, "Config object not found or has no content");
|
|
249
|
+
tiny_invariant_default()(configObject.data?.content.dataType === "moveObject", "Config object is not a Move object");
|
|
250
|
+
const objectFields = configObject.data.content.fields;
|
|
251
|
+
const id = objectFields.id.id;
|
|
252
|
+
const feeReceiver = objectFields.fee_receiver;
|
|
253
|
+
const tiers = objectFields.tiers.fields.contents;
|
|
254
|
+
// Parse tier information from blockchain data
|
|
255
|
+
const tierMap = {};
|
|
256
|
+
for (const tier of tiers){
|
|
257
|
+
const key = tier.fields.key;
|
|
258
|
+
const duration = tier.fields.value.fields.duration;
|
|
259
|
+
const amount = tier.fields.value.fields.amount;
|
|
260
|
+
const point = tier.fields.value.fields.point;
|
|
261
|
+
const originalAmount = tier.fields.value.fields.original_amount;
|
|
262
|
+
tierMap[key] = {
|
|
263
|
+
duration: BigInt(duration),
|
|
264
|
+
amount: BigInt(amount),
|
|
265
|
+
point: BigInt(point),
|
|
266
|
+
originalAmount: BigInt(originalAmount)
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
id,
|
|
271
|
+
receiverAddress: feeReceiver,
|
|
272
|
+
tiers: tierMap
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Builds a transaction for paying boosting fees for a specific tier.
|
|
277
|
+
* The payment amount is determined by the tier configuration.
|
|
278
|
+
*
|
|
279
|
+
* @param request - Payment request parameters
|
|
280
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
281
|
+
* @throws Error if tier ID is invalid
|
|
282
|
+
*/ async buildPayBoostingTx({ walletAddress, tierId, boostingCoinType, currentTx }) {
|
|
283
|
+
const configObj = await this.getConfig();
|
|
284
|
+
tiny_invariant_default()(tierId in configObj.tiers, "Invalid tier ID");
|
|
285
|
+
const tier = configObj.tiers[tierId];
|
|
286
|
+
const paymentAmount = tier.amount;
|
|
287
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
288
|
+
const paymentCoin = tx.splitCoins(tx.gas, [
|
|
289
|
+
tx.pure.u64(paymentAmount)
|
|
290
|
+
]);
|
|
291
|
+
tx.moveCall({
|
|
292
|
+
target: `${BOOSTING_PACKAGE_ID}::boosting::pay`,
|
|
293
|
+
typeArguments: [
|
|
294
|
+
(0,utils_namespaceObject.normalizeStructTag)(boostingCoinType)
|
|
295
|
+
],
|
|
296
|
+
arguments: [
|
|
297
|
+
tx.object(CONFIG_ID),
|
|
298
|
+
tx.pure.u64(tierId),
|
|
299
|
+
paymentCoin
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
tx.setSender(walletAddress);
|
|
303
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, walletAddress, 0);
|
|
304
|
+
return addGasFee({
|
|
305
|
+
inheritTx: tx,
|
|
306
|
+
sender: walletAddress,
|
|
307
|
+
feeAmount: gasAmount
|
|
308
|
+
}, this.sdk.suiClient);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Builds a transaction for adding a new boosting tier.
|
|
312
|
+
*
|
|
313
|
+
* **Requires admin capability.**
|
|
314
|
+
*
|
|
315
|
+
* @param request - Add tier request parameters
|
|
316
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
317
|
+
*/ async buildAddTierTx({ adminAddress, tierId, duration, point, originalAmount, amount, currentTx }) {
|
|
318
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
319
|
+
tx.moveCall({
|
|
320
|
+
target: `${BOOSTING_PACKAGE_ID}::config::add_tier`,
|
|
321
|
+
typeArguments: [],
|
|
322
|
+
arguments: [
|
|
323
|
+
tx.object(CONFIG_ID),
|
|
324
|
+
tx.object(ADMIN_CAP_ID),
|
|
325
|
+
tx.pure.u64(tierId),
|
|
326
|
+
tx.pure.u64(point),
|
|
327
|
+
tx.pure.u64(duration),
|
|
328
|
+
tx.pure.u64(originalAmount),
|
|
329
|
+
tx.pure.u64(amount)
|
|
330
|
+
]
|
|
331
|
+
});
|
|
332
|
+
tx.setSender(adminAddress);
|
|
333
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
334
|
+
return addGasFee({
|
|
335
|
+
inheritTx: tx,
|
|
336
|
+
sender: adminAddress,
|
|
337
|
+
feeAmount: gasAmount
|
|
338
|
+
}, this.sdk.suiClient);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Builds a transaction for updating an existing boosting tier.
|
|
342
|
+
*
|
|
343
|
+
* **Requires admin capability.**
|
|
344
|
+
*
|
|
345
|
+
* @param request - Update tier request parameters
|
|
346
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
347
|
+
*/ async buildUpdateTierTx({ adminAddress, tierId, duration, amount, originalAmount, point, currentTx }) {
|
|
348
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
349
|
+
tx.moveCall({
|
|
350
|
+
target: `${BOOSTING_PACKAGE_ID}::config::update_tier`,
|
|
351
|
+
typeArguments: [],
|
|
352
|
+
arguments: [
|
|
353
|
+
tx.object(CONFIG_ID),
|
|
354
|
+
tx.object(ADMIN_CAP_ID),
|
|
355
|
+
tx.pure.u64(tierId),
|
|
356
|
+
tx.pure.u64(duration),
|
|
357
|
+
tx.pure.u64(amount),
|
|
358
|
+
tx.pure.u64(point),
|
|
359
|
+
tx.pure.u64(originalAmount)
|
|
360
|
+
]
|
|
361
|
+
});
|
|
362
|
+
tx.setSender(adminAddress);
|
|
363
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
364
|
+
return addGasFee({
|
|
365
|
+
inheritTx: tx,
|
|
366
|
+
sender: adminAddress,
|
|
367
|
+
feeAmount: gasAmount
|
|
368
|
+
}, this.sdk.suiClient);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Builds a transaction for removing a boosting tier.
|
|
372
|
+
*
|
|
373
|
+
* **Requires admin capability.**
|
|
374
|
+
*
|
|
375
|
+
* @param request - Remove tier request parameters
|
|
376
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
377
|
+
*/ async buildRemoveTierTx({ adminAddress, tierId, currentTx }) {
|
|
378
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
379
|
+
tx.moveCall({
|
|
380
|
+
target: `${BOOSTING_PACKAGE_ID}::config::remove_tier`,
|
|
381
|
+
typeArguments: [],
|
|
382
|
+
arguments: [
|
|
383
|
+
tx.object(CONFIG_ID),
|
|
384
|
+
tx.object(ADMIN_CAP_ID),
|
|
385
|
+
tx.pure.u64(tierId)
|
|
386
|
+
]
|
|
387
|
+
});
|
|
388
|
+
tx.setSender(adminAddress);
|
|
389
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
390
|
+
return addGasFee({
|
|
391
|
+
inheritTx: tx,
|
|
392
|
+
sender: adminAddress,
|
|
393
|
+
feeAmount: gasAmount
|
|
394
|
+
}, this.sdk.suiClient);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Builds a transaction for updating the fee receiver address.
|
|
398
|
+
*
|
|
399
|
+
* **Requires admin capability.**
|
|
400
|
+
*
|
|
401
|
+
* @param request - Update fee receiver request parameters
|
|
402
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
403
|
+
*/ async buildUpdateFeeReceiver({ adminAddress, newReceiverAddress, currentTx }) {
|
|
404
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
405
|
+
tx.moveCall({
|
|
406
|
+
target: `${BOOSTING_PACKAGE_ID}::config::update_fee_receiver`,
|
|
407
|
+
typeArguments: [],
|
|
408
|
+
arguments: [
|
|
409
|
+
tx.object(CONFIG_ID),
|
|
410
|
+
tx.object(ADMIN_CAP_ID),
|
|
411
|
+
tx.pure.address(newReceiverAddress)
|
|
412
|
+
]
|
|
413
|
+
});
|
|
414
|
+
tx.setSender(adminAddress);
|
|
415
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
416
|
+
return addGasFee({
|
|
417
|
+
inheritTx: tx,
|
|
418
|
+
sender: adminAddress,
|
|
419
|
+
feeAmount: gasAmount
|
|
420
|
+
}, this.sdk.suiClient);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Builds a transaction for paying boosting fees with admin privileges.
|
|
424
|
+
* Allows specifying a custom payment amount instead of using the tier's default amount.
|
|
425
|
+
*
|
|
426
|
+
* **Requires admin capability.**
|
|
427
|
+
*
|
|
428
|
+
* @param request - Admin payment request parameters
|
|
429
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
430
|
+
*/ async buildPayBoostingWithAdminTx({ walletAddress, tierId, customAmount, boostingCoinType, currentTx }) {
|
|
431
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
432
|
+
const paymentCoin = tx.splitCoins(tx.gas, [
|
|
433
|
+
tx.pure.u64(customAmount)
|
|
434
|
+
]);
|
|
435
|
+
tx.moveCall({
|
|
436
|
+
target: `${BOOSTING_PACKAGE_ID}::boosting::pay_with_admin`,
|
|
437
|
+
typeArguments: [
|
|
438
|
+
(0,utils_namespaceObject.normalizeStructTag)(boostingCoinType)
|
|
439
|
+
],
|
|
440
|
+
arguments: [
|
|
441
|
+
tx.object(ADMIN_CAP_ID),
|
|
442
|
+
tx.object(CONFIG_ID),
|
|
443
|
+
tx.pure.u64(tierId),
|
|
444
|
+
tx.pure.u64(customAmount),
|
|
445
|
+
paymentCoin
|
|
446
|
+
]
|
|
447
|
+
});
|
|
448
|
+
tx.setSender(walletAddress);
|
|
449
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, walletAddress, 0);
|
|
450
|
+
return addGasFee({
|
|
451
|
+
inheritTx: tx,
|
|
452
|
+
sender: walletAddress,
|
|
453
|
+
feeAmount: gasAmount
|
|
454
|
+
}, this.sdk.suiClient);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
;// CONCATENATED MODULE: ./src/libs/getSplitCoinForTx.ts
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
async function getSplitCoinForTx(params, suiClient) {
|
|
464
|
+
const { account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false } = params;
|
|
465
|
+
const tx = inheritTx ?? new transactions_namespaceObject.Transaction();
|
|
466
|
+
const { objectIds } = await getCoinObjectIdsByAmount(suiClient, account, amount, coinType);
|
|
467
|
+
const coinObjectId = objectIds[0];
|
|
468
|
+
if ((0,utils_namespaceObject.normalizeStructTag)(coinType) === (0,utils_namespaceObject.normalizeStructTag)(SUI_FULL_TYPE) && !isSponsored) {
|
|
469
|
+
let coin;
|
|
470
|
+
if (inspecTransaction) {
|
|
471
|
+
if (objectIds.length > 1) {
|
|
472
|
+
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item)=>tx.object(item)));
|
|
473
|
+
}
|
|
474
|
+
coin = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
475
|
+
} else {
|
|
476
|
+
coin = tx.splitCoins(tx.gas, splits);
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
tx,
|
|
480
|
+
coinData: coin
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
if (objectIds.length > 1) {
|
|
484
|
+
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item)=>tx.object(item)));
|
|
485
|
+
}
|
|
486
|
+
// split correct amount to swap
|
|
487
|
+
const coinData = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
488
|
+
return {
|
|
489
|
+
tx,
|
|
490
|
+
coinData
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
;// CONCATENATED MODULE: ./src/modules/subscription-module.ts
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
/** Sui package ID for the subscription protocol */ const SUBSCRIPTION_PACKAGE_ID = "0x5dd4286ec234c117bb9577d4eaed1885b70d73ab1d3dab2794d0ab9a2c06c4a1";
|
|
499
|
+
/** Configuration object ID for subscription settings */ const SUBSCRIPTION_CONFIG_ID = "0x095b941beff22213fe8ccb223e4d1c5b4ede4dcd7f82ca4bb18c9a45fd3d6e20";
|
|
500
|
+
/** Admin capability object ID for privileged operations */ const SUBSCRIPTION_ADMIN_CAP_ID = "0xdc27fe8187131b7fc095fccd213b79f72312793152a2483d1f67199c390e256d";
|
|
501
|
+
/** Payment coin type on SUI */ const PAYMENT_COIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
502
|
+
/**
|
|
503
|
+
* Module for managing subscription functionality in the Noodles SDK.
|
|
504
|
+
*
|
|
505
|
+
* This module provides methods for:
|
|
506
|
+
* - Subscribing to plans
|
|
507
|
+
* - Upgrading plans (immediate or next billing cycle)
|
|
508
|
+
* - Managing subscription plans (admin functions)
|
|
509
|
+
* - Retrieving subscription configuration
|
|
510
|
+
* - Updating fee receiver wallet and pause settings
|
|
511
|
+
*/ class SubscriptionModule {
|
|
512
|
+
/** Reference to the main SDK instance */ sdk;
|
|
513
|
+
/**
|
|
514
|
+
* Creates a new SubscriptionModule instance.
|
|
515
|
+
*
|
|
516
|
+
* @param sdk - The main Noodles Pay SDK instance
|
|
517
|
+
*/ constructor(sdk){
|
|
518
|
+
this.sdk = sdk;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Retrieves the current subscription configuration from the blockchain.
|
|
522
|
+
*
|
|
523
|
+
* @returns Promise resolving to the current subscription configuration
|
|
524
|
+
* @throws Error if config object is not found or invalid
|
|
525
|
+
*/ async getConfig() {
|
|
526
|
+
const configObject = await this.sdk.suiClient.getObject({
|
|
527
|
+
id: SUBSCRIPTION_CONFIG_ID,
|
|
528
|
+
options: {
|
|
529
|
+
showContent: true
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
tiny_invariant_default()(configObject.data, "Config object not found");
|
|
533
|
+
tiny_invariant_default()(configObject.data.content, "Config object has no content");
|
|
534
|
+
tiny_invariant_default()(configObject.data?.content.dataType === "moveObject", "Config object is not a Move object");
|
|
535
|
+
const objectFields = configObject.data.content.fields;
|
|
536
|
+
const id = objectFields.id.id;
|
|
537
|
+
const feeReceiverWallet = objectFields.fee_receiver;
|
|
538
|
+
const paused = objectFields.paused;
|
|
539
|
+
const acceptedPaymentType = objectFields.accepted_payment_type;
|
|
540
|
+
const plans = objectFields.plans.fields.contents;
|
|
541
|
+
// Parse plan information from blockchain data
|
|
542
|
+
const planMap = {};
|
|
543
|
+
for (const plan of plans){
|
|
544
|
+
const key = plan.fields.key;
|
|
545
|
+
const planId = plan.fields.value.fields.id;
|
|
546
|
+
const price = plan.fields.value.fields.price;
|
|
547
|
+
const monthInterval = plan.fields.value.fields.month_interval;
|
|
548
|
+
const planType = plan.fields.value.fields.ptype;
|
|
549
|
+
planMap[key] = {
|
|
550
|
+
id: BigInt(planId),
|
|
551
|
+
price: BigInt(price),
|
|
552
|
+
monthInterval: monthInterval,
|
|
553
|
+
planType: planType
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
id,
|
|
558
|
+
plans: planMap,
|
|
559
|
+
feeReceiverWallet: feeReceiverWallet,
|
|
560
|
+
paused,
|
|
561
|
+
acceptedPaymentType
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Builds a transaction for subscribing to a plan.
|
|
566
|
+
* The payment amount is determined by the plan configuration.
|
|
567
|
+
*
|
|
568
|
+
* @param request - Subscription request parameters
|
|
569
|
+
* @reference order_id generated from your backend to identify the purchase
|
|
570
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
571
|
+
* @throws Error if plan ID is invalid or contract is paused
|
|
572
|
+
*/ async buildSubscribeCyclePlanTx({ walletAddress, planId, reference, paymentCoinType = PAYMENT_COIN_TYPE, currentTx }) {
|
|
573
|
+
const configObj = await this.getConfig();
|
|
574
|
+
tiny_invariant_default()(!configObj.paused, "Contract is paused");
|
|
575
|
+
tiny_invariant_default()(planId in configObj.plans, "Invalid plan ID");
|
|
576
|
+
const plan = configObj.plans[planId];
|
|
577
|
+
const paymentAmount = plan.price;
|
|
578
|
+
// Get USDC coins from user's wallet
|
|
579
|
+
const { tx: txWithCoin, coinData } = await getSplitCoinForTx({
|
|
580
|
+
account: walletAddress,
|
|
581
|
+
amount: paymentAmount.toString(),
|
|
582
|
+
splits: [
|
|
583
|
+
paymentAmount.toString()
|
|
584
|
+
],
|
|
585
|
+
coinType: paymentCoinType,
|
|
586
|
+
inheritTx: currentTx
|
|
587
|
+
}, this.sdk.suiClient);
|
|
588
|
+
txWithCoin.moveCall({
|
|
589
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_cycle_plan`,
|
|
590
|
+
typeArguments: [
|
|
591
|
+
paymentCoinType
|
|
592
|
+
],
|
|
593
|
+
arguments: [
|
|
594
|
+
txWithCoin.object(SUBSCRIPTION_CONFIG_ID),
|
|
595
|
+
txWithCoin.pure.u64(planId),
|
|
596
|
+
txWithCoin.pure.string(reference),
|
|
597
|
+
coinData
|
|
598
|
+
]
|
|
599
|
+
});
|
|
600
|
+
txWithCoin.setSender(walletAddress);
|
|
601
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, txWithCoin, walletAddress, 0);
|
|
602
|
+
return addGasFee({
|
|
603
|
+
inheritTx: txWithCoin,
|
|
604
|
+
sender: walletAddress,
|
|
605
|
+
feeAmount: gasAmount
|
|
606
|
+
}, this.sdk.suiClient);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Builds a transaction for buying additional compute units (CU) for CUAddOn plans.
|
|
610
|
+
*
|
|
611
|
+
* @param request - Buy more CU request parameters
|
|
612
|
+
* @reference order_id generated from your backend to identify the purchase
|
|
613
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
614
|
+
* @throws Error if plan ID is invalid or contract is paused
|
|
615
|
+
*/ async buildBuyMoreCUPlanTx({ walletAddress, planId, reference, paidAmount, paymentCoinType = PAYMENT_COIN_TYPE, currentTx }) {
|
|
616
|
+
const configObj = await this.getConfig();
|
|
617
|
+
tiny_invariant_default()(!configObj.paused, "Contract is paused");
|
|
618
|
+
tiny_invariant_default()(planId in configObj.plans, "Invalid plan ID");
|
|
619
|
+
// Get USDC coins from user's wallet
|
|
620
|
+
const { tx: txWithCoin, coinData } = await getSplitCoinForTx({
|
|
621
|
+
account: walletAddress,
|
|
622
|
+
amount: paidAmount.toString(),
|
|
623
|
+
splits: [
|
|
624
|
+
paidAmount.toString()
|
|
625
|
+
],
|
|
626
|
+
coinType: paymentCoinType,
|
|
627
|
+
inheritTx: currentTx
|
|
628
|
+
}, this.sdk.suiClient);
|
|
629
|
+
txWithCoin.moveCall({
|
|
630
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::subscription::buy_more_cu`,
|
|
631
|
+
typeArguments: [
|
|
632
|
+
paymentCoinType
|
|
633
|
+
],
|
|
634
|
+
arguments: [
|
|
635
|
+
txWithCoin.object(SUBSCRIPTION_CONFIG_ID),
|
|
636
|
+
txWithCoin.pure.u64(planId),
|
|
637
|
+
txWithCoin.pure.string(reference),
|
|
638
|
+
txWithCoin.pure.u64(paidAmount),
|
|
639
|
+
coinData
|
|
640
|
+
]
|
|
641
|
+
});
|
|
642
|
+
txWithCoin.setSender(walletAddress);
|
|
643
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, txWithCoin, walletAddress, 0);
|
|
644
|
+
return addGasFee({
|
|
645
|
+
inheritTx: txWithCoin,
|
|
646
|
+
sender: walletAddress,
|
|
647
|
+
feeAmount: gasAmount
|
|
648
|
+
}, this.sdk.suiClient);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Builds a transaction for subscribing with admin privileges.
|
|
652
|
+
* Allows specifying a custom payment amount instead of using the plan's default price.
|
|
653
|
+
* Useful for promotions, discounts, or special cases.
|
|
654
|
+
*
|
|
655
|
+
* **Requires admin capability.**
|
|
656
|
+
*
|
|
657
|
+
* @param request - Admin subscription request parameters
|
|
658
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
659
|
+
* @throws Error if contract is paused
|
|
660
|
+
*/ async buildSubscribePlanWithAdminTx({ walletAddress, planId, reference, customAmount, paymentCoinType = PAYMENT_COIN_TYPE, currentTx }) {
|
|
661
|
+
const configObj = await this.getConfig();
|
|
662
|
+
tiny_invariant_default()(!configObj.paused, "Contract is paused");
|
|
663
|
+
// Get USDC coins from user's wallet
|
|
664
|
+
const { tx: txWithCoin, coinData } = await getSplitCoinForTx({
|
|
665
|
+
account: walletAddress,
|
|
666
|
+
amount: customAmount.toString(),
|
|
667
|
+
splits: [
|
|
668
|
+
customAmount.toString()
|
|
669
|
+
],
|
|
670
|
+
coinType: paymentCoinType,
|
|
671
|
+
inheritTx: currentTx
|
|
672
|
+
}, this.sdk.suiClient);
|
|
673
|
+
txWithCoin.moveCall({
|
|
674
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::subscription::subscribe_plan_with_admin`,
|
|
675
|
+
typeArguments: [
|
|
676
|
+
paymentCoinType
|
|
677
|
+
],
|
|
678
|
+
arguments: [
|
|
679
|
+
txWithCoin.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
680
|
+
txWithCoin.object(SUBSCRIPTION_CONFIG_ID),
|
|
681
|
+
txWithCoin.pure.u64(planId),
|
|
682
|
+
txWithCoin.pure.string(reference),
|
|
683
|
+
txWithCoin.pure.u64(customAmount),
|
|
684
|
+
coinData
|
|
685
|
+
]
|
|
686
|
+
});
|
|
687
|
+
txWithCoin.setSender(walletAddress);
|
|
688
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, txWithCoin, walletAddress, 0);
|
|
689
|
+
return addGasFee({
|
|
690
|
+
inheritTx: txWithCoin,
|
|
691
|
+
sender: walletAddress,
|
|
692
|
+
feeAmount: gasAmount
|
|
693
|
+
}, this.sdk.suiClient);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Builds a transaction for adding a new subscription plan.
|
|
697
|
+
*
|
|
698
|
+
* **Requires admin capability.**
|
|
699
|
+
*
|
|
700
|
+
* @param request - Add plan request parameters
|
|
701
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
702
|
+
*/ async buildAddPlanTx({ adminAddress, planId, planType, monthInterval, price, currentTx }) {
|
|
703
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
704
|
+
tx.moveCall({
|
|
705
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::add_plan`,
|
|
706
|
+
typeArguments: [],
|
|
707
|
+
arguments: [
|
|
708
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
709
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
710
|
+
tx.pure.u64(planId),
|
|
711
|
+
tx.pure.u8(planType),
|
|
712
|
+
tx.pure.u8(monthInterval),
|
|
713
|
+
tx.pure.u64(price)
|
|
714
|
+
]
|
|
715
|
+
});
|
|
716
|
+
tx.setSender(adminAddress);
|
|
717
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
718
|
+
return addGasFee({
|
|
719
|
+
inheritTx: tx,
|
|
720
|
+
sender: adminAddress,
|
|
721
|
+
feeAmount: gasAmount
|
|
722
|
+
}, this.sdk.suiClient);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Builds a transaction for updating an existing subscription plan.
|
|
726
|
+
*
|
|
727
|
+
* **Requires admin capability.**
|
|
728
|
+
*
|
|
729
|
+
* @param request - Update plan request parameters
|
|
730
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
731
|
+
*/ async buildUpdatePlanTx({ adminAddress, planId, planType, monthInterval, price, currentTx }) {
|
|
732
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
733
|
+
tx.moveCall({
|
|
734
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::update_plan`,
|
|
735
|
+
typeArguments: [],
|
|
736
|
+
arguments: [
|
|
737
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
738
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
739
|
+
tx.pure.u64(BigInt(planId)),
|
|
740
|
+
tx.pure.u8(planType),
|
|
741
|
+
tx.pure.u8(monthInterval),
|
|
742
|
+
tx.pure.u64(price)
|
|
743
|
+
]
|
|
744
|
+
});
|
|
745
|
+
tx.setSender(adminAddress);
|
|
746
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
747
|
+
return addGasFee({
|
|
748
|
+
inheritTx: tx,
|
|
749
|
+
sender: adminAddress,
|
|
750
|
+
feeAmount: gasAmount
|
|
751
|
+
}, this.sdk.suiClient);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Builds a transaction for removing a subscription plan.
|
|
755
|
+
*
|
|
756
|
+
* **Requires admin capability.**
|
|
757
|
+
*
|
|
758
|
+
* @param request - Remove plan request parameters
|
|
759
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
760
|
+
*/ async buildRemovePlanTx({ adminAddress, planId, currentTx }) {
|
|
761
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
762
|
+
tx.moveCall({
|
|
763
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::remove_plan`,
|
|
764
|
+
typeArguments: [],
|
|
765
|
+
arguments: [
|
|
766
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
767
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
768
|
+
tx.pure.u64(BigInt(planId))
|
|
769
|
+
]
|
|
770
|
+
});
|
|
771
|
+
tx.setSender(adminAddress);
|
|
772
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
773
|
+
return addGasFee({
|
|
774
|
+
inheritTx: tx,
|
|
775
|
+
sender: adminAddress,
|
|
776
|
+
feeAmount: gasAmount
|
|
777
|
+
}, this.sdk.suiClient);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Builds a transaction for updating the admin wallet address.
|
|
781
|
+
*
|
|
782
|
+
* **Requires admin capability.**
|
|
783
|
+
*
|
|
784
|
+
* @param request - Update admin wallet request parameters
|
|
785
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
786
|
+
*/ async buildUpdateFeeReceiverWalletTx({ adminAddress, newFeeReceiverWallet, currentTx }) {
|
|
787
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
788
|
+
tx.moveCall({
|
|
789
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::update_fee_receiver`,
|
|
790
|
+
typeArguments: [],
|
|
791
|
+
arguments: [
|
|
792
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
793
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
794
|
+
tx.pure.address(newFeeReceiverWallet)
|
|
795
|
+
]
|
|
796
|
+
});
|
|
797
|
+
tx.setSender(adminAddress);
|
|
798
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
799
|
+
return addGasFee({
|
|
800
|
+
inheritTx: tx,
|
|
801
|
+
sender: adminAddress,
|
|
802
|
+
feeAmount: gasAmount
|
|
803
|
+
}, this.sdk.suiClient);
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Builds a transaction for pausing or unpausing the contract.
|
|
807
|
+
*
|
|
808
|
+
* **Requires admin capability.**
|
|
809
|
+
*
|
|
810
|
+
* @param request - Set paused request parameters
|
|
811
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
812
|
+
*/ async buildSetPausedTx({ adminAddress, paused, currentTx }) {
|
|
813
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
814
|
+
tx.moveCall({
|
|
815
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::set_paused`,
|
|
816
|
+
typeArguments: [],
|
|
817
|
+
arguments: [
|
|
818
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
819
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID),
|
|
820
|
+
tx.pure.bool(paused)
|
|
821
|
+
]
|
|
822
|
+
});
|
|
823
|
+
tx.setSender(adminAddress);
|
|
824
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
825
|
+
return addGasFee({
|
|
826
|
+
inheritTx: tx,
|
|
827
|
+
sender: adminAddress,
|
|
828
|
+
feeAmount: gasAmount
|
|
829
|
+
}, this.sdk.suiClient);
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Builds a transaction to set the accepted payment coin type.
|
|
833
|
+
* Note: Only one payment type can be accepted at a time. Setting a new type replaces the previous one.
|
|
834
|
+
*
|
|
835
|
+
* **Requires admin capability.**
|
|
836
|
+
*
|
|
837
|
+
* @param request - Set accepted payment type request parameters
|
|
838
|
+
* @returns Promise resolving to a transaction ready for execution
|
|
839
|
+
*/ async buildSetAcceptedPaymentTypeTx({ adminAddress, paymentCoinType, currentTx }) {
|
|
840
|
+
const tx = currentTx || new transactions_namespaceObject.Transaction();
|
|
841
|
+
tx.moveCall({
|
|
842
|
+
target: `${SUBSCRIPTION_PACKAGE_ID}::config::set_accepted_payment_type`,
|
|
843
|
+
typeArguments: [
|
|
844
|
+
paymentCoinType
|
|
845
|
+
],
|
|
846
|
+
arguments: [
|
|
847
|
+
tx.object(SUBSCRIPTION_CONFIG_ID),
|
|
848
|
+
tx.object(SUBSCRIPTION_ADMIN_CAP_ID)
|
|
849
|
+
]
|
|
850
|
+
});
|
|
851
|
+
tx.setSender(adminAddress);
|
|
852
|
+
const gasAmount = await getNeededGasFee(this.sdk.suiClient, tx, adminAddress, 0);
|
|
853
|
+
return addGasFee({
|
|
854
|
+
inheritTx: tx,
|
|
855
|
+
sender: adminAddress,
|
|
856
|
+
feeAmount: gasAmount
|
|
857
|
+
}, this.sdk.suiClient);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
;// CONCATENATED MODULE: ./src/modules/pay-modules.ts
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
;// CONCATENATED MODULE: external "@mysten/sui/client"
|
|
866
|
+
const client_namespaceObject = require("@mysten/sui/client");
|
|
867
|
+
;// CONCATENATED MODULE: ./src/pay-sdk.ts
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
class NoodlesPaySdk {
|
|
871
|
+
_suiClient;
|
|
872
|
+
boostingModule;
|
|
873
|
+
subscriptionModule;
|
|
874
|
+
constructor(){
|
|
875
|
+
this._suiClient = new client_namespaceObject.SuiClient({
|
|
876
|
+
url: (0,client_namespaceObject.getFullnodeUrl)("mainnet")
|
|
877
|
+
});
|
|
878
|
+
this.subscriptionModule = new SubscriptionModule(this);
|
|
879
|
+
this.boostingModule = new BoostingModule(this);
|
|
880
|
+
}
|
|
881
|
+
get suiClient() {
|
|
882
|
+
return this._suiClient;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
;// CONCATENATED MODULE: ./src/exports/pay.ts
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
exports.ADMIN_CAP_ID = __webpack_exports__.ADMIN_CAP_ID;
|
|
891
|
+
exports.BOOSTING_PACKAGE_ID = __webpack_exports__.BOOSTING_PACKAGE_ID;
|
|
892
|
+
exports.BoostingModule = __webpack_exports__.BoostingModule;
|
|
893
|
+
exports.CONFIG_ID = __webpack_exports__.CONFIG_ID;
|
|
894
|
+
exports.NoodlesPaySdk = __webpack_exports__.NoodlesPaySdk;
|
|
895
|
+
exports.PAYMENT_COIN_TYPE = __webpack_exports__.PAYMENT_COIN_TYPE;
|
|
896
|
+
exports.SUBSCRIPTION_ADMIN_CAP_ID = __webpack_exports__.SUBSCRIPTION_ADMIN_CAP_ID;
|
|
897
|
+
exports.SUBSCRIPTION_CONFIG_ID = __webpack_exports__.SUBSCRIPTION_CONFIG_ID;
|
|
898
|
+
exports.SUBSCRIPTION_PACKAGE_ID = __webpack_exports__.SUBSCRIPTION_PACKAGE_ID;
|
|
899
|
+
exports.SubscriptionModule = __webpack_exports__.SubscriptionModule;
|
|
900
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
901
|
+
if(["ADMIN_CAP_ID","BOOSTING_PACKAGE_ID","BoostingModule","CONFIG_ID","NoodlesPaySdk","PAYMENT_COIN_TYPE","SUBSCRIPTION_ADMIN_CAP_ID","SUBSCRIPTION_CONFIG_ID","SUBSCRIPTION_PACKAGE_ID","SubscriptionModule"].indexOf(__rspack_i) === -1) {
|
|
902
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|